Skip to content

Commit feb333d

Browse files
Feature/nml (#698)
update all the nml files in regtests and keep only the header of each namelist
1 parent 84c79ce commit feb333d

File tree

840 files changed

+11025
-99788
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

840 files changed

+11025
-99788
lines changed

model/tools/bash/loop_nml.sh

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
11
#!/bin/bash -e
22

3-
#input argument
4-
if [ $# -ne 2 ]
3+
#############################################################################
4+
# how to run it over regtests :
5+
#
6+
# for dir in $(find $PWD/../../../regtests/ -mindepth 1 -maxdepth 1 -type d -name "*t*"); do echo $dir; qsub -l walltime=04:00:00 -l mem=1G -v rpath="$dir",prog="ww3_grid",comment="header" -N grid loop_nml.sh; done
7+
#############################################################################
8+
9+
#shell argument
10+
if [ $# -eq 3 ]
11+
then
12+
rpath="$1"
13+
prog="$2"
14+
comment="$3"
15+
fi
16+
17+
if [ -z "$(echo $rpath)" ] || [ -z "$(echo $prog)" ] || [ -z "$(echo $comment)" ]
518
then
6-
echo "need 2 arguments :"
19+
echo "[ERROR] need 3 arguments :"
720
echo '$1 : root path where to find all inp files [~/WW3/regtests]'
821
echo '$2 : prog to which convert inp files [ww3_shel]'
22+
echo '$3 : include header or full comments [header|full]'
23+
echo 'or qsub -v rpath=XXX,prog=XXX,comment=XXX loop_nml.sh'
924
exit 1
1025
fi
1126

12-
rpath="$1"
13-
prog="$2"
27+
# bash environment
28+
if [ ! -z $(echo $BASH_SOURCE[0]) ] ; then
29+
cd "$( dirname "${BASH_SOURCE[0]}" )"
30+
fi
31+
32+
# pbs environment
33+
if [ ! -z $(echo $PBS_O_WORKDIR) ] ; then
34+
cd $PBS_O_WORKDIR
35+
fi
36+
37+
path_bash="$( cd $PWD && pwd )"
1438

15-
path_bash="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1639

1740
for file in $(find $rpath -name "${prog}*.inp*" ! -name "${prog}_clean.inp" )
1841
do
1942
echo 'file : '$file
20-
$path_bash/${prog}_inp2nml.sh $file
43+
$path_bash/${prog}_inp2nml.sh $file $comment
2144
done
2245

2346
echo ''

model/tools/bash/ww3_bounc_inp2nml.sh

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
prog="ww3_bounc"
44

5-
if [ $# -ne 1 ]
5+
if [ $# -ne 2 ]
66
then
7-
echo " [ERROR] need ${prog} input filename in argument [${prog}.inp]"
7+
echo '[ERROR] need 2 arguments : '
8+
echo "\$1 : ${prog} input filename in argument [${prog}.inp]"
9+
echo '$2 : include header or full comments [header|full]'
810
exit 1
911
fi
1012

1113
inp="$( cd "$( dirname "$1" )" && pwd )/$(basename $1)"
14+
comment="$2"
1215

1316
# check filename extension
1417
ext=$(echo $inp | awk -F '.' '{print $NF}')
@@ -17,18 +20,6 @@ if [ "$(echo $ext)" != 'inp' ] ; then
1720
exit 1
1821
fi
1922

20-
# commented because it is not working in all cases
21-
# link to temporary inp with regtest format
22-
#ext=$(echo $inp | awk -F"${prog}.inp." '{print $2}' || awk -F"${prog}.inp_" '{print $2}')
23-
#base=$(echo $inp | awk -F"${prog}\\..inp\\.." '{print $1}' | awk -F".inp.$ext" '{print $1}' || awk -F"${prog}\\..inp_" '{print $1}' | awk -F".inp_$ext" #'{print $1}')
24-
#if [ ! -z $(echo $ext) ] ; then
25-
# new_inp=${base}_${ext}.inp
26-
# echo "link $inp to $new_inp"
27-
# ln -sfn $inp $new_inp
28-
# old_inp=$inp
29-
# inp=$new_inp
30-
#fi
31-
3223
cd $( dirname $inp)
3324
cur_dir="../$(basename $(dirname $inp))"
3425

@@ -57,7 +48,7 @@ do
5748
continue
5849
fi
5950

60-
cleanline="$(echo $line | awk -F' ' '{print $1}' | cut -d \" -f2 | cut -d \' -f2)"
51+
cleanline="$(echo $line | awk -F' ' '{print $1}' | sed -e "s/\*//g" -e "s/\"//g" -e "s/\'//g")"
6152
if [ -z "$cleanline" ]
6253
then
6354
continue
@@ -73,6 +64,13 @@ done
7364
# get all values from clean inp file
7465

7566
readarray -t lines < "$cleaninp"
67+
numlines=${#lines[@]}
68+
69+
# remove carriage return characters
70+
for il in $(seq 0 $numlines)
71+
do
72+
lines[$il]=$(echo "$(echo ${lines[$il]} | sed 's/\r$//')")
73+
done
7674
il=0
7775

7876
mode="$(echo ${lines[$il]} | awk -F' ' '{print $1}' | cut -d \" -f2 | cut -d \' -f2)"
@@ -132,6 +130,7 @@ cat > $nmlfile << EOF
132130
EOF
133131

134132
# field namelist
133+
if [ "$comment" = "full" ]; then
135134
cat >> $nmlfile << EOF
136135
! -------------------------------------------------------------------- !
137136
! Define the input boundaries to preprocess via BOUND_NML namelist
@@ -145,6 +144,14 @@ cat >> $nmlfile << EOF
145144
! -------------------------------------------------------------------- !
146145
&BOUND_NML
147146
EOF
147+
else
148+
cat >> $nmlfile << EOF
149+
! -------------------------------------------------------------------- !
150+
! Define the input boundaries to preprocess via BOUND_NML namelist
151+
! -------------------------------------------------------------------- !
152+
&BOUND_NML
153+
EOF
154+
fi
148155

149156
if [ "${mode}" != "WRITE" ]; then echo " BOUND%MODE = '${mode}'" >> $nmlfile; fi
150157
if [ "$interp" != "2" ]; then echo " BOUND%INTERP = $interp" >> $nmlfile; fi
@@ -161,15 +168,6 @@ EOF
161168
echo "DONE : $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $nmlfile)"
162169
rm -f $cleaninp
163170

164-
# commented because it is not working in all cases
165-
#if [ ! -z $(echo $ext) ] ; then
166-
# unlink $new_inp
167-
# addon="$(echo $(basename $nmlfile) | awk -F"${prog}_" '{print $2}' | awk -F'.nml' '{print $1}' )"
168-
# new_nmlfile="${prog}.nml.$addon"
169-
# mv $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $nmlfile) $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $new_nmlfile)
170-
# echo "RENAMED : $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $new_nmlfile)"
171-
#fi
172-
173171
#------------------------------
174172

175173

model/tools/bash/ww3_bound_inp2nml.sh

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
prog="ww3_bound"
44

5-
if [ $# -ne 1 ]
5+
if [ $# -ne 2 ]
66
then
7-
echo " [ERROR] need ${prog} input filename in argument [${prog}.inp]"
7+
echo '[ERROR] need 2 arguments : '
8+
echo "\$1 : ${prog} input filename in argument [${prog}.inp]"
9+
echo '$2 : include header or full comments [header|full]'
810
exit 1
911
fi
1012

1113
inp="$( cd "$( dirname "$1" )" && pwd )/$(basename $1)"
14+
comment="$2"
1215

1316
# check filename extension
1417
ext=$(echo $inp | awk -F '.' '{print $NF}')
@@ -17,18 +20,6 @@ if [ "$(echo $ext)" != 'inp' ] ; then
1720
exit 1
1821
fi
1922

20-
# commented because it is not working in all cases
21-
# link to temporary inp with regtest format
22-
#ext=$(echo $inp | awk -F"${prog}.inp." '{print $2}' || awk -F"${prog}.inp_" '{print $2}')
23-
#base=$(echo $inp | awk -F"${prog}\\..inp\\.." '{print $1}' | awk -F".inp.$ext" '{print $1}' || awk -F"${prog}\\..inp_" '{print $1}' | awk -F".inp_$ext" #'{print $1}')
24-
#if [ ! -z $(echo $ext) ] ; then
25-
# new_inp=${base}_${ext}.inp
26-
# echo "link $inp to $new_inp"
27-
# ln -sfn $inp $new_inp
28-
# old_inp=$inp
29-
# inp=$new_inp
30-
#fi
31-
3223
cd $( dirname $inp)
3324
cur_dir="../$(basename $(dirname $inp))"
3425

@@ -57,7 +48,7 @@ do
5748
continue
5849
fi
5950

60-
cleanline="$(echo $line | awk -F' ' '{print $1}' | cut -d \" -f2 | cut -d \' -f2)"
51+
cleanline="$(echo $line | awk -F' ' '{print $1}' | sed -e "s/\*//g" -e "s/\"//g" -e "s/\'//g")"
6152
if [ -z "$cleanline" ]
6253
then
6354
continue
@@ -139,6 +130,7 @@ cat > $nmlfile << EOF
139130
EOF
140131

141132
# field namelist
133+
if [ "$comment" = "full" ]; then
142134
cat >> $nmlfile << EOF
143135
! -------------------------------------------------------------------- !
144136
! Define the input boundaries to preprocess via BOUND_NML namelist
@@ -152,6 +144,14 @@ cat >> $nmlfile << EOF
152144
! -------------------------------------------------------------------- !
153145
&BOUND_NML
154146
EOF
147+
else
148+
cat >> $nmlfile << EOF
149+
! -------------------------------------------------------------------- !
150+
! Define the input boundaries to preprocess via BOUND_NML namelist
151+
! -------------------------------------------------------------------- !
152+
&BOUND_NML
153+
EOF
154+
fi
155155

156156
if [ "${mode}" != "WRITE" ]; then echo " BOUND%MODE = '${mode}'" >> $nmlfile; fi
157157
if [ "$interp" != "2" ]; then echo " BOUND%INTERP = $interp" >> $nmlfile; fi
@@ -168,15 +168,6 @@ EOF
168168
echo "DONE : $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $nmlfile)"
169169
rm -f $cleaninp
170170

171-
# commented because it is not working in all cases
172-
#if [ ! -z $(echo $ext) ] ; then
173-
# unlink $new_inp
174-
# addon="$(echo $(basename $nmlfile) | awk -F"${prog}_" '{print $2}' | awk -F'.nml' '{print $1}' )"
175-
# new_nmlfile="${prog}.nml.$addon"
176-
# mv $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $nmlfile) $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $new_nmlfile)
177-
# echo "RENAMED : $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $new_nmlfile)"
178-
#fi
179-
180171
#------------------------------
181172

182173

0 commit comments

Comments
 (0)