Skip to content

Commit

Permalink
Use CPP instead of Switches (NOAA-EMC#476)
Browse files Browse the repository at this point in the history
Use CPP ifdefs instead of switches for pre-processing and convert all code from ftn to F90 files. (ftn->src) 
The tools for converting ftn->src can be found in the model/tools directory.
  • Loading branch information
JessicaMeixner-NOAA authored Oct 19, 2021
1 parent cad636d commit dd31794
Show file tree
Hide file tree
Showing 190 changed files with 55,775 additions and 38,875 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ regtests/output
*~
model/bin/comp
model/bin/link
model/bin/ad3
model/bin/switch
model/bin/switch.old
model/bin/switch.old_DIST
Expand Down
4 changes: 2 additions & 2 deletions model/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ tmp_*
work*
nuopc*.mk
tools/makefile
ftn/makefile
ftn/makefile_*
src/makefile
src/makefile_*
83 changes: 15 additions & 68 deletions model/bin/ad3 → model/bin/ad3.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash
# --------------------------------------------------------------------------- #
# ad3 : Run fortran preprocessor w3adc of WAVEWATCH III on for a single #
# ad3 : Run fortran CPP preprocessor on a single WAVEWATCH III #
# source code file. Switches are set in the file 'switch', which #
# has to be in the "bin" directory. After the preprocessing the code #
# is compiled using the script comp in the "bin" directory. #
# #
# use : ad3 basename [itest [icomp]] #
# basename: name of source code file without the '.ftn' extension. #
# basename: name of source code file without the '.F90' extension. #
# file with .f or .f90 extension is not preprocessed. #
# file with .c extension uses standard cc compiler. #
# itest : test output switch. #
Expand All @@ -23,7 +23,6 @@
# 5 : compiler error. #
# #
# programs used : #
# w3adc : executable of proprocessing program. #
# comp : compiler script. #
# #
# remarks : #
Expand All @@ -32,20 +31,14 @@
# - The main WAVEWATCH directory ($main_dir) is obtained from the setup #
# file $ww3_env, as is the scratch directory ($temp_dir). The following #
# directories are used : #
# $main_dir/ftn : Raw FORTRAN file ($basename.ftn). If extension is #
# not .ftn, w3adc will be skipped. if the extension is #
# .c, then the simple cc compiler is used. The latter #
# is now used for profiling code only. #
# $main_dir/src : Raw FORTRAN file ($basename.F90). #
# $main_dir/bin : File with preprocessor switches 'switch', and #
# compiler script 'comp'. #
# $main_dir/obj : Final object modules ($basename.o). #
# $main_dir/mod : Final modules (*.mod). #
# #
# The following temporary files (in $temp_dir) are used and are removed #
# only if the corresponding step of ad3 is ompleted successfully : #
# w3adc.inp : input file for w3adc. #
# w3adc.out : output file for w3adc. #
# w3adc.err : eror file for w3adc. #
# comp.out : input file for comp. #
# comp.err : eror file for comp. #
# comp.stat : status file of compiler, containing number of errors #
Expand Down Expand Up @@ -104,12 +97,11 @@
source=$WWATCH3_SOURCE
list=$WWATCH3_LIST


# 1.d Set up paths etc. - - - - - - - - - - - - - - - - - - - - - - - - - - -

path_b="$main_dir/bin"
path_w="$( cd $temp_dir && pwd )"
path_i="$main_dir/ftn"
path_i="$main_dir/src"
path_o="$main_dir/obj"
path_m="$main_dir/mod"
path_e="$main_dir/exe"
Expand Down Expand Up @@ -141,7 +133,7 @@

# 1.e Test necessity of running w3adc - - - - - - - - - - - - - - - - - - - -

if [ -f $path_i/$name.ftn ]
if [ -f $path_i/$name.F90 ]
then
w3adc='yes'
idstr=
Expand Down Expand Up @@ -200,7 +192,6 @@
cd $path_w
rm -f $name.$fext
rm -f $name.l
ln -s $main_dir/bin/w3list . 2> /dev/null

# --------------------------------------------------------------------------- #
# 2. Run w3adc #
Expand All @@ -210,73 +201,31 @@
if [ "$w3adc" = 'yes' ]
then

echo "0 $compress" > w3adc.inp.$name
echo "'$path_i/$name.ftn' '$name.$fext'" >> w3adc.inp.$name
echo "'$sw_str'" >> w3adc.inp.$name

# 2.b Add NCEP/NCO docmentation - - - - - - - - - - - - - - - - - - - - - - -

# Obsolete feature, removed
# 2.b Run CPP preprocessor - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# 2.b Run w3adc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#Generate list of CPP Flags based on switches:
CPPFLAGS=()
for sw in $sw_str
do
CPPFLAGS+=("-DW3_$sw")
done

if [ "$itst" != '0' ]
then
echo '-- input file w3adc.inp -------------------------------------------'
cat w3adc.inp.$name
echo '-- end of file ----------------------------------------------------'
fi
CPPFLAGS+=("-D__WW3_SWITCHES__='$sw_str'")

$path_b/w3adc < w3adc.inp.$name > w3adc.out.$name 2> w3adc.err.$name
<comp_seq> "${CPPFLAGS[@]}" <cppad3procflag> <cppad3flag2> $path_i/$name.F90 <cppad3flag3> $name.F90
<cppad3flag4> mv $name.i $name.F90

# 2.c Test the output of w3adc - - - - - - - - - - - - - - - - - - - - - - - -

ad3_tst="`grep ERROR w3adc.out.$name`"
if [ -n "$ad3_tst" ]
then
echo ' *** w3adc error ***'
echo " $ad3_tst" ; exit 4
fi

if [ ! -f $name.$fext ]
then
echo ' *** w3adc error ***'
echo " file $name.$fext not found (1)."
cat w3adc.out.$name ; cat w3adc.err.$name ; exit 4
fi

if [ "`wc -l $name.$fext | awk '{ print $1}'`" -lt '2' ]
then
echo ' *** w3adc error ***'
echo " file $name.$fext not found (2)."
cat w3adc.out.$name ; cat w3adc.err.$name ; exit 4
fi

if [ "$itst" != '0' ]
then
cat w3adc.out.$name
fi

# 2.d Clean up - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

rm -f w3adc.*.$name

# 2.e Add switches in w3initmd - - - - - - - - - - - - - - - - - - - - - -

if [ "$name" = "w3initmd" ]
then
sw_1=''
cp $path_w/w3initmd.$fext $path_w/w3initmd.ft1
for line in 1 2 3
do
sw_1=`echo $sw_str | fold -w100 | sed -n "${line}p"`
sw_old="PUT_SW$line"
# echo $line $sw_1 $sw_old
sed -e "s/$sw_old/$sw_1/" $path_w/w3initmd.ft1 > $path_w/w3initmd.ft2
mv $path_w/w3initmd.ft2 $path_w/w3initmd.ft1
done
mv $path_w/w3initmd.ft1 $path_w/w3initmd.$fext
echo "'$path_w/$name.fts' '$name.$fext'" >> w3adc.inp
fi

else
Expand All @@ -298,7 +247,6 @@

if [ "$icmp" != '0' ]
then
rm -f w3list
exit 0
fi

Expand Down Expand Up @@ -420,7 +368,6 @@ then
# 3.e process output files - - - - - - - - - - - - - - - - - - - - - - - - - -

rm -f $name.o
rm -f w3list

if [ "$source" != 'yes' ]
then
Expand Down
145 changes: 0 additions & 145 deletions model/bin/ad3_test

This file was deleted.

4 changes: 2 additions & 2 deletions model/bin/all_switches
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# --------------------------------------------------------------------------- #
# all_switches : Make a list of all switches hat are found in the program #
# (.ftn) files of WAVEWATCH III. #
# (.F90) files of WAVEWATCH III. #
# #
# use : all_switches #
# #
Expand Down Expand Up @@ -38,7 +38,7 @@
# 2. Strip all switches from sources #
# --------------------------------------------------------------------------- #

cd $main_dir/ftn
cd $main_dir/src

all=`sed -n '/^!\/[[:alpha:]]/'p *.ftn | awk '{print $1}' | \
awk -F'!/' 'BEGIN{OFS="\n"}{$1=$1; print $0}' | \
Expand Down
Loading

0 comments on commit dd31794

Please sign in to comment.