Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No macros lite #174

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ FILE_PATTERNS = *.c \
*.py \
*.pyw \
*.f90 \
*.F90 \
*.f95 \
*.f03 \
*.f08 \
Expand Down
163 changes: 80 additions & 83 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/sh

############################################
# This is the "classic" Makefile for SPEC. #
############################################
Expand All @@ -9,138 +7,137 @@
# are defined there as well.
include SPECfile

# files to be preprocessed by m4
PREPROC=$(ALLSPEC:=_m.F90)

ROBJS=$(SPECFILES:=_r.o)
DOBJS=$(SPECFILES:=_d.o)

ROBJS_IO=$(IOFILES:=_r.o)
DOBJS_IO=$(IOFILES:=_d.o)
ROBJS_LEVEL_0=$(LEVEL_0:=_r.o)
DOBJS_LEVEL_0=$(LEVEL_0:=_d.o)

ROBJS_LEVEL_1=$(LEVEL_1:=_r.o)
DOBJS_LEVEL_1=$(LEVEL_1:=_d.o)

ROBJS_LEVEL_2=$(LEVEL_2:=_r.o)
DOBJS_LEVEL_2=$(LEVEL_2:=_d.o)

ROBJS_LEVEL_3=$(LEVEL_3:=_r.o)
DOBJS_LEVEL_3=$(LEVEL_3:=_d.o)

ROBJS_LEVEL_4=$(LEVEL_4:=_r.o)
DOBJS_LEVEL_4=$(LEVEL_4:=_d.o)

ROBJS_BASE=$(BASEFILES:=_r.o)
DOBJS_BASE=$(BASEFILES:=_d.o)

###############################################################################################################################################################

date:=$(shell date)
text:=$(shell date +%F)

###############################################################################################################################################################
# main executables

xspec: $(addsuffix _r.o,$(ALLFILES)) $(MACROS) Makefile
xspec: $(addsuffix _r.o,$(ALLFILES)) Makefile
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o xspec $(addsuffix _r.o,$(ALLFILES)) $(LINKS)

dspec: $(addsuffix _d.o,$(ALLFILES)) $(MACROS) Makefile
dspec: $(addsuffix _d.o,$(ALLFILES)) Makefile
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o dspec $(addsuffix _d.o,$(ALLFILES)) $(LINKS)

###############################################################################################################################################################
# inputlist needs special handling: expansion of DSCREENLIST and NSCREENLIST using awk (not anymore !!!)
# sfiles: contrib

inputlist_r.o: %_r.o: src/inputlist.f90 $(MACROS)
m4 -P $(MACROS) src/inputlist.f90 > inputlist_m.F90
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o inputlist_r.o -c inputlist_m.F90 $(LIBS)
@wc -l -L -w inputlist_m.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
%_r.o: src/%.f
$(FC) $(FLAGS) $(RFLAGS) -o $*_r.o -c src/$*.f
@wc -l -L -w src/$*.f | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

inputlist_d.o: %_d.o: src/inputlist.f90 $(MACROS)
m4 -P $(MACROS) src/inputlist.f90 > inputlist_m.F90
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o inputlist_d.o -c inputlist_m.F90 $(LIBS)
@wc -l -L -w inputlist_m.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
%_d.o: src/%.f
$(FC) $(FLAGS) $(DFLAGS) -o $*_d.o -c src/$*.f
@wc -l -L -w src/$*.f | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

###############################################################################################################################################################
# global needs special handling: expansion of CPUVARIABLE, BSCREENLIST and WSCREENLIST using awk (not anymore !!!)
# BASEFILES, depending on one another

global_r.o: %_r.o: inputlist_r.o src/global.f90 $(MACROS)
m4 -P $(MACROS) src/global.f90 > global_m.F90
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o global_r.o -c global_m.F90 $(LIBS)
@wc -l -L -w global_m.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
$(ROBJS_LEVEL_0): %_r.o: src/%.F90
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o $*_r.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

global_d.o: %_d.o: inputlist_d.o src/global.f90 $(MACROS)
m4 -P $(MACROS) src/global.f90 > global_m.F90
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o global_d.o -c global_m.F90 $(LIBS)
@wc -l -L -w global_m.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
$(DOBJS_LEVEL_0): %_d.o: src/%.F90
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o $*_d.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

###############################################################################################################################################################
$(ROBJS_LEVEL_1): %_r.o: src/%.F90 $(addsuffix _r.o,$(LEVEL_0))
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o $*_r.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

%_r.o: src/%.f
$(FC) $(FLAGS) $(RFLAGS) -o $*_r.o -c src/$*.f
@wc -l -L -w src/$*.f | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
$(DOBJS_LEVEL_1): %_d.o: src/%.F90 $(addsuffix _d.o,$(LEVEL_0))
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o $*_d.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

%_d.o: src/%.f
$(FC) $(FLAGS) $(DFLAGS) -o $*_d.o -c src/$*.f
@wc -l -L -w src/$*.f | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
$(ROBJS_LEVEL_2): %_r.o: src/%.F90 mod_kinds_r.o $(addsuffix _r.o,$(LEVEL_1))
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o $*_r.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

###############################################################################################################################################################
$(DOBJS_LEVEL_2): %_d.o: src/%.F90 mod_kinds_d.o $(addsuffix _d.o,$(LEVEL_1))
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o $*_d.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

$(PREPROC): %_m.F90: src/%.f90 $(MACROS)
@awk -v file=$*.f90 '{ gsub("__LINE__", NR); gsub("__FILE__",file); print }' src/$*.f90 > $*_p.f90
m4 -P $(MACROS) $*_p.f90 > $*_m.F90
$(ROBJS_LEVEL_3): %_r.o: src/%.F90 mod_kinds_r.o $(addsuffix _r.o,$(LEVEL_2))
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o $*_r.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

$(DOBJS_LEVEL_3): %_d.o: src/%.F90 mod_kinds_d.o $(addsuffix _d.o,$(LEVEL_2))
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o $*_d.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

$(ROBJS_IO): %_r.o: %_m.F90 $(addsuffix _r.o,$(BASEFILES)) $(MACROS)
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o $*_r.o -c $*_m.F90 $(LIBS)
@wc -l -L -w $*_m.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
$(ROBJS_LEVEL_4): %_r.o: src/%.F90 mod_kinds_r.o $(addsuffix _r.o,$(LEVEL_3))
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o $*_r.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

$(DOBJS_IO): %_d.o: %_m.F90 $(addsuffix _d.o,$(BASEFILES)) $(MACROS)
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o $*_d.o -c $*_m.F90 $(LIBS)
@wc -l -L -w $*_m.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
$(DOBJS_LEVEL_4): %_d.o: src/%.F90 mod_kinds_d.o $(addsuffix _d.o,$(LEVEL_3))
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o $*_d.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

###############################################################################################################################################################
# SPECFILES: main physics part of SPEC

$(ROBJS): %_r.o: %_m.F90 $(addsuffix _r.o,$(BASEFILES)) $(addsuffix _r.o,$(IOFILES)) $(MACROS)
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o $*_r.o -c $*_m.F90 $(LIBS)
@wc -l -L -w $*_m.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
$(ROBJS): %_r.o: src/%.F90 $(addsuffix _r.o,$(BASEFILES))
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o $*_r.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

$(DOBJS): %_d.o: %_m.F90 $(addsuffix _d.o,$(BASEFILES)) $(addsuffix _d.o,$(IOFILES)) $(MACROS)
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o $*_d.o -c $*_m.F90 $(LIBS)
@wc -l -L -w $*_m.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
$(DOBJS): %_d.o: src/%.F90 $(addsuffix _d.o,$(BASEFILES))
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o $*_d.o -c src/$*.F90 $(LIBS)
@wc -l -L -w src/$*.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

###############################################################################################################################################################

xspech_r.o: src/xspech.f90 global_r.o sphdf5_r.o $(addsuffix _r.o,$(files)) $(MACROS)
@awk -v date='$(date)' -v pwd='$(PWD)' -v macros='$(MACROS)' -v fc='$(FC)' -v flags='$(FLAGS) $(CFLAGS) $(RFLAGS)' -v allfiles='$(ALLFILES)' \
'BEGIN{nfiles=split(allfiles,files," ")} \
{if($$2=="COMPILATION") {print " write(ounit,*)\" : compiled : date = "date" ; \"" ; \
print " write(ounit,*)\" : : srcdir = "pwd" ; \"" ; \
print " write(ounit,*)\" : : macros = "macros" ; \"" ; \
print " write(ounit,*)\" : : fc = "fc" ; \"" ; \
print " write(ounit,*)\" : : flags = "flags" ; \"" }} \
{if($$2=="SUMTIME") {for (i=1;i<=nfiles;i++) print " SUMTIME("files[i]")"}}\
{if($$2=="PRTTIME") {for (i=1;i<=nfiles;i++) print " PRTTIME("files[i]")"}}\
{print}' src/xspech.f90 > mspech.f90
m4 -P $(MACROS) mspech.f90 > xspech_m.F90
@rm -f mspech.f90
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o xspech_r.o -c xspech_m.F90 $(LIBS)
@wc -l -L -w xspech_m.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

xspech_d.o: src/xspech.f90 global_d.o sphdf5_d.o $(addsuffix _d.o,$(files)) $(MACROS)
@awk -v date='$(date)' -v pwd='$(PWD)' -v macros='$(MACROS)' -v fc='$(FC)' -v flags='$(FLAGS) $(CFLAGS) $(DFLAGS)' -v allfiles='$(ALLFILES)' \
'BEGIN{nfiles=split(allfiles,files," ")} \
{if($$2=="COMPILATION") {print " write(ounit,*)\" : compiled : date = "date" ; \"" ; \
print " write(ounit,*)\" : : srcdir = "pwd" ; \"" ; \
print " write(ounit,*)\" : : macros = "macros" ; \"" ; \
print " write(ounit,*)\" : : fc = "fc" ; \"" ; \
print " write(ounit,*)\" : : flags = "flags" ; \"" }} \
{if($$2=="SUMTIME") {for (i=1;i<=nfiles;i++) print " SUMTIME("files[i]")"}}\
{if($$2=="PRTTIME") {for (i=1;i<=nfiles;i++) print " PRTTIME("files[i]")"}}\
{print}' src/xspech.f90 > mspech.f90
m4 -P $(MACROS) mspech.f90 > xspech_m.F90
@rm -f mspech.f90
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o xspech_d.o -c xspech_m.F90 $(LIBS)
@wc -l -L -w xspech_m.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
xspech_r.o: src/xspech.F90 $(ROBJS)
$(FC) $(FLAGS) $(CFLAGS) $(RFLAGS) -o xspech_r.o -c src/xspech.F90 $(LIBS)
@wc -l -L -w src/xspech.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

xspech_d.o: src/xspech.F90 $(DOBJS)
$(FC) $(FLAGS) $(CFLAGS) $(DFLAGS) -o xspech_d.o -c src/xspech.F90 $(LIBS)
@wc -l -L -w src/xspech.F90 | awk '{print $$4" has "$$1" lines, "$$2" words, and the longest line is "$$3" characters ;"}'
@echo ''

###############################################################################################################################################################

clean:
rm -f *.o *.mod *_p.f90 *_m.F90 .*.h *.pdf *.dvi *.out *.bbl *.toc .*.date ; rm -rf ./docs/html ./docs/latex
rm -f *.o *.mod *.pdf *.dvi *.out *.bbl *.toc .*.date *_m.F90
rm -rf ./docs/html ./docs/latex

###############################################################################################################################################################

Expand Down
18 changes: 10 additions & 8 deletions SPECfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

# basis of SPEC: input variables, global workspace, HDF5 output file writing
# these are split off since they require special treatment (needed by all others and/or special macros)
BASEFILES=inputlist global
IOFILES=sphdf5
LEVEL_0=mod_kinds
LEVEL_1=inputlist
LEVEL_2=global
LEVEL_3=h5utils
LEVEL_4=sphdf5

# (most of) physics part of SPEC
afiles=preset manual rzaxis packxi volume coords basefn memory
Expand All @@ -24,26 +27,25 @@ efiles=jo00aa pp00aa pp00ab bfield stzxyz
ffiles=hesian ra00aa numrec

# externally provided libraries
# below assumes the .f files are double precision; the CFLAGS = -r8 option is not required;
# below assumes the .f files are double precision
# the CFLAGS = -r8 option is not required
sfiles=dcuhre minpack iqpack rksuite i1mach d1mach ilut iters

###############################################################################################################################################################

BASEFILES=$(LEVEL_0) $(LEVEL_1) $(LEVEL_2) $(LEVEL_3) $(LEVEL_4)

# all of SPEC except BASEFILES
SPECFILES=$(afiles) $(bfiles) $(cfiles) $(dfiles) $(efiles) $(ffiles)

# all of "our" (vs. contributed) files needed for the "core" of SPEC
ALLSPEC=$(BASEFILES) $(IOFILES) $(SPECFILES)
ALLSPEC=$(BASEFILES) $(SPECFILES)

# *ALL* files needed for the main SPEC executable
ALLFILES=$(sfiles) $(ALLSPEC) xspech

###############################################################################################################################################################

MACROS=src/macros

###############################################################################################################################################################

# if want to use gfortran: make BUILD_ENV=gfortran (x/d)spec
# default: use Intel compiler
BUILD_ENV?=intel
Expand Down
Loading