Skip to content

Commit

Permalink
Develop (#86)
Browse files Browse the repository at this point in the history
Merging Ifremer (umr-lops) trusted repo to the NOAA-EMC/WW3 auth repo.

* add WCOR to switch list
* add check on array index
* correct flag status to read time with new CF convention
when month and day are written on only one character : YYYY-M-D
* set log message into SCRIP comment to avoid misleading error
detection with gnu compiler
* correct bug due to misuse of NAME instead of UNIT for
reading data in input file
* remove linking inp file in conversion scripts
minor typing change in ww3_multi.nml and ww3_bounc.nml
* initialize pointer to avoid random value assignement
* remove exit statement to display full list
of output boundaries
* add check on NDSEN to avoid print on wrong IAPROC
* when creating new points file from input file,
add relative to points file instead of filename
* revert to version number to 7.00
* update matrix_datarmor
  • Loading branch information
mickaelaccensi authored and ajhenrique committed Oct 10, 2019
1 parent e0b61d0 commit 4bacd02
Show file tree
Hide file tree
Showing 73 changed files with 1,835 additions and 361 deletions.
49 changes: 33 additions & 16 deletions model/aux/bash/ww3_bounc_inp2nml.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
#!/bin/bash -e

prog="ww3_bounc"

if [ $# -ne 1 ]
then
echo ' [ERROR] need ww3_bounc input filename in argument [ww3_bounc.inp]'
echo " [ERROR] need ${prog} input filename in argument [${prog}.inp]"
exit 1
fi

# link to temporary inp with regtest format
inp="$( cd "$( dirname "$1" )" && pwd )/$(basename $1)"
if [ ! -z $(echo $inp | awk -F'ww3_bounc\\..inp.' '{print $2}') ] ; then
new_inp=$(echo $(echo $inp | awk -F'ww3_bounc\\..inp.' '{print $1}')ww3_bounc_$(echo $inp | awk -F'ww3_bounc\\..inp.' '{print $2}').inp)
ln -sfn $inp $new_inp
old_inp=$inp
inp=$new_inp

# check filename extension
ext=$(echo $inp | awk -F '.' '{print $NF}')
if [ "$(echo $ext)" != 'inp' ] ; then
echo "[ERROR] input file has no .inp extension. Please rename it before conversion"
exit 1
fi

# commented because it is not working in all cases
# link to temporary inp with regtest format
#ext=$(echo $inp | awk -F"${prog}.inp." '{print $2}' || awk -F"${prog}.inp_" '{print $2}')
#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}')
#if [ ! -z $(echo $ext) ] ; then
# new_inp=${base}_${ext}.inp
# echo "link $inp to $new_inp"
# ln -sfn $inp $new_inp
# old_inp=$inp
# inp=$new_inp
#fi

cd $( dirname $inp)
cur_dir="../$(basename $(dirname $inp))"

Expand All @@ -33,7 +46,7 @@ fi
#------------------------------
# clean up inp file from all $ lines

cleaninp="$cur_dir/ww3_bounc_clean.inp"
cleaninp="$cur_dir/${prog}_clean.inp"
rm -f $cleaninp

cat $inp | while read line
Expand Down Expand Up @@ -141,18 +154,22 @@ if [ "$spec_filename" != "spec.list" ]; then echo " BOUND%FILE = '$spe
cat >> $nmlfile << EOF
/
! -------------------------------------------------------------------- !
! WAVEWATCH III - end of namelist !
! -------------------------------------------------------------------- !
EOF
echo "DONE : $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $nmlfile)"
rm -f $cleaninp
if [ ! -z $(echo $old_inp | awk -F'ww3_bounc\\..inp\\..' '{print $2}') ] ; then
unlink $new_inp
addon="$(echo $(basename $nmlfile) | awk -F'ww3_bounc_' '{print $2}' | awk -F'\\..nml' '{print $1}' )"
new_nmlfile="ww3_bounc.nml.$addon"
mv $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $nmlfile) $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $new_nmlfile)
echo "RENAMED : $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $new_nmlfile)"
fi

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

#------------------------------


152 changes: 85 additions & 67 deletions model/aux/bash/ww3_grid_inp2nml.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
#!/bin/bash -e

prog="ww3_grid"

if [ $# -ne 1 ]
then
echo ' [ERROR] need ww3_grid input filename in argument [ww3_grid.inp]'
echo " [ERROR] need ${prog} input filename in argument [${prog}.inp]"
exit 1
fi

# link to temporary inp with regtest format
inp="$( cd "$( dirname "$1" )" && pwd )/$(basename $1)"
if [ ! -z $(echo $inp | awk -F'ww3_grid\\..inp.' '{print $2}') ] ; then
new_inp=$(echo $(echo $inp | awk -F'ww3_grid\\..inp\\..' '{print $1}')ww3_grid_$(echo $inp | awk -F'ww3_grid\\..inp\\..' '{print $2}').inp)
ln -sfn $inp $new_inp
old_inp=$inp
inp=$new_inp

# check filename extension
ext=$(echo $inp | awk -F '.' '{print $NF}')
if [ "$(echo $ext)" != 'inp' ] ; then
echo "[ERROR] input file has no .inp extension. Please rename it before conversion"
exit 1
fi

# commented because it is not working in all cases
# link to temporary inp with regtest format
#ext=$(echo $inp | awk -F"${prog}.inp." '{print $2}' || awk -F"${prog}.inp_" '{print $2}')
#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}')
#if [ ! -z $(echo $ext) ] ; then
# new_inp=${base}_${ext}.inp
# echo "link $inp to $new_inp"
# ln -sfn $inp $new_inp
# old_inp=$inp
# inp=$new_inp
#fi

cd $( dirname $inp)
cur_dir="../$(basename $(dirname $inp))"

Expand Down Expand Up @@ -52,7 +65,7 @@ declare -A oulnnp
#------------------------------
# clean up inp file from all $ lines

cleaninp="$cur_dir/ww3_grid_clean.inp"
cleaninp="$cur_dir/${prog}_clean.inp"
rm -f $cleaninp

cat $inp | while read line
Expand Down Expand Up @@ -241,7 +254,7 @@ depth_format="$(echo ${lines[$il]} | awk -F' ' '{print $7}' | cut -d \" -f2 | c
depth_from="$(echo ${lines[$il]} | awk -F' ' '{print $8}' | cut -d \" -f2 | cut -d \' -f2)"
depth_filename="$(echo ${lines[$il]} | awk -F' ' '{print $9}' | cut -d \" -f2 | cut -d \' -f2)"
echo 'depth : ' $depth_zlim $depth_dmin $depth_idf $depth_sf $depth_idla $depth_idfm $depth_format $depth_from $depth_filename
if [ "$depth_from" == 'UNIT' ]
if [ "$depth_from" == 'UNIT' ] || [ "$depth_idf" == '10' ]
then
foridepth=$cur_dir/${grdname}.depth
fdepth=$cur_dir/${grdname}.depth.new
Expand Down Expand Up @@ -355,7 +368,7 @@ then
obst_format="$(echo ${lines[$il]} | awk -F' ' '{print $4}' | cut -d \" -f2 | cut -d \' -f2)"
obst_filename="$(echo ${lines[$il]} | awk -F' ' '{print $5}' | cut -d \" -f2 | cut -d \' -f2)"
echo 'smc obst : ' $obst_idf $obst_idla $obst_idfm $obst_format $obst_filename
if [ "$obst_from" == 'UNIT' ]
if [ "$obst_from" == 'UNIT' ] || [ "$obst_idf" == '10' ]
then
foriobst=$cur_dir/${grdname}.obst
fobst=$cur_dir/${grdname}.obst.new
Expand Down Expand Up @@ -521,7 +534,7 @@ then
obst_from="$(echo ${lines[$il]} | awk -F' ' '{print $6}' | cut -d \" -f2 | cut -d \' -f2)"
obst_filename="$(echo ${lines[$il]} | awk -F' ' '{print $7}' | cut -d \" -f2 | cut -d \' -f2)"
echo 'obst : ' $obst_idf $obst_sf $obst_idla $obst_idfm $obst_format $obst_from $obst_filename
if [ "$obst_from" == 'UNIT' ]
if [ "$obst_from" == 'UNIT' ] || [ "$obst_idf" == '10' ]
then
foriobst=$cur_dir/${grdname}.obst
fobst=$cur_dir/${grdname}.obst.new
Expand Down Expand Up @@ -628,60 +641,63 @@ mask_format="$(echo ${lines[$il]} | awk -F' ' '{print $4}' | cut -d \" -f2 | cu
mask_from="$(echo ${lines[$il]} | awk -F' ' '{print $5}' | cut -d \" -f2 | cut -d \' -f2)"
mask_filename="$(echo ${lines[$il]} | awk -F' ' '{print $6}' | cut -d \" -f2 | cut -d \' -f2)"
echo 'mask : ' $mask_idf $mask_idla $mask_idfm $mask_format $mask_from $mask_filename
if [ "$mask_from" == 'UNIT' ]
if [ "$mask_from" == 'UNIT' ] || [ "$mask_from" == 'NAME' ]
then
forimask=$cur_dir/${grdname}.mask
fmask=$cur_dir/${grdname}.mask.new
mask_filename=$forimask
mask_from='NAME'
rm -f $fmask
num_total=0
iread=0
j=1
# unfold the array
while [ $num_total -lt $num_max ]; do
il=$(($il+1))
curline="$(echo ${lines[$il]} | sed -e 's/,/ /g')"
line_elem=$(echo $curline} | awk -F' ' '{print NF}')
for n_elem in $(seq 1 $line_elem); do
curelem=$(echo $curline | awk -F' ' "{print \$$n_elem}" | cut -d \" -f2 | cut -d \' -f2)
if [ ! -z "$(echo $curelem | grep '*')" ]; then
num_times=$(echo $curelem | awk -F'*' '{print $1}')
val_times=$(echo $curelem | awk -F'*' '{print $2}')
else
num_times=1
val_times=$curelem
fi
num_total=$(($num_total + $num_times))
for t in $(seq 1 $num_times); do
iread=$(($iread+1))
mask2d[$iread,$j]="$val_times"
# echo -n "$val_times " >> $fmask
if [ $iread -ge $nx ]; then
iread=0
j=$(($j+1))
# echo '' >> $fmask
if [ "$mask_idf" == '10' ]
then
forimask=$cur_dir/${grdname}.mask
fmask=$cur_dir/${grdname}.mask.new
mask_filename=$forimask
mask_from='NAME'
rm -f $fmask
num_total=0
iread=0
j=1
# unfold the array
while [ $num_total -lt $num_max ]; do
il=$(($il+1))
curline="$(echo ${lines[$il]} | sed -e 's/,/ /g')"
line_elem=$(echo $curline} | awk -F' ' '{print NF}')
for n_elem in $(seq 1 $line_elem); do
curelem=$(echo $curline | awk -F' ' "{print \$$n_elem}" | cut -d \" -f2 | cut -d \' -f2)
if [ ! -z "$(echo $curelem | grep '*')" ]; then
num_times=$(echo $curelem | awk -F'*' '{print $1}')
val_times=$(echo $curelem | awk -F'*' '{print $2}')
else
num_times=1
val_times=$curelem
fi
num_total=$(($num_total + $num_times))
for t in $(seq 1 $num_times); do
iread=$(($iread+1))
mask2d[$iread,$j]="$val_times"
# echo -n "$val_times " >> $fmask
if [ $iread -ge $nx ]; then
iread=0
j=$(($j+1))
# echo '' >> $fmask
fi
done
done
echo "${lines[$il]}" >> $fmask
done
echo "${lines[$il]}" >> $fmask
done
# save file
if [ -f $forimask ]
then
if [ -z "$(diff $forimask $fmask)" ]
# save file
if [ -f $forimask ]
then
echo $forimask ' and ' $fmask 'are same.'
echo 'delete ' $fmask
rm $fmask
if [ -z "$(diff $forimask $fmask)" ]
then
echo $forimask ' and ' $fmask 'are same.'
echo 'delete ' $fmask
rm $fmask
else
echo 'diff between :' $forimask ' and new file : ' $fmask
echo 'inp2nml conversion stopped'
exit 1
fi
else
echo 'diff between :' $forimask ' and new file : ' $fmask
echo 'inp2nml conversion stopped'
exit 1
echo 'mv '$fmask ' to ' $forimask
mv $fmask $forimask
fi
else
echo 'mv '$fmask ' to ' $forimask
mv $fmask $forimask
fi
elif [ "$mask_from" == 'PART' ]
then
Expand Down Expand Up @@ -709,7 +725,7 @@ then
slope_from="$(echo ${lines[$il]} | awk -F' ' '{print $6}' | cut -d \" -f2 | cut -d \' -f2)"
slope_filename="$(echo ${lines[$il]} | awk -F' ' '{print $7}' | cut -d \" -f2 | cut -d \' -f2)"
echo 'slope : ' $slope_idf $slope_sf $slope_idla $slope_idfm $slope_format $slope_from $slope_filename
if [ "$slope_from" == 'UNIT' ]
if [ "$slope_from" == 'UNIT' ] || [ "$slope_idf" == '10' ]
then
forislope=$cur_dir/${grdname}.slope
fslope=$cur_dir/${grdname}.slope.new
Expand Down Expand Up @@ -851,7 +867,7 @@ then
sed_from="$(echo ${lines[$il]} | awk -F' ' '{print $6}' | cut -d \" -f2 | cut -d \' -f2)"
sed_filename="$(echo ${lines[$il]} | awk -F' ' '{print $7}' | cut -d \" -f2 | cut -d \' -f2)"
echo 'sed : ' $sed_idf $sed_sf $sed_idla $sed_idfm $sed_format $sed_from $sed_filename
if [ "$sed_from" == 'UNIT' ]
if [ "$sed_from" == 'UNIT' ] || [ "$sed_idf" == '10' ]
then
forised=$cur_dir/${grdname}.sed
fsed=$cur_dir/${grdname}.sed.new
Expand Down Expand Up @@ -1984,13 +2000,15 @@ cat >> $nmlfile << EOF
EOF
echo "DONE : $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $nmlfile)"
rm -f $cleaninp
if [ ! -z $(echo $old_inp | awk -F'ww3_grid\\..inp\\..' '{print $2}') ] ; then
unlink $new_inp
addon="$(echo $(basename $nmlfile) | awk -F'ww3_grid_' '{print $2}' | awk -F'\\..nml' '{print $1}' )"
new_nmlfile="ww3_grid.nml.$addon"
mv $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $nmlfile) $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $new_nmlfile)
echo "RENAMED : $( cd "$( dirname "$nmlfile" )" && pwd )/$(basename $new_nmlfile)"
fi

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


Loading

0 comments on commit 4bacd02

Please sign in to comment.