Changeset 4347 for BOL/Replay


Ignore:
Timestamp:
Nov 11, 2022, 5:04:57 AM (2 years ago)
Author:
fhourdin
Message:

New functionalities, multi-routine netcdf output

The -nconly option can be used to equip other routines with nc output only
replay_equip.sh -h
to see the options

Location:
BOL/Replay
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • BOL/Replay/Readme

    r4344 r4347  
    3232  It equips the fortran routine before compilation.
    3333  The main documentation of the replay tools is in this script
     34  By default, it equips the code for binary output for replay and nc output
     35    for diangostics.
     36  The -nconly option can be used to equip other routines with nc output only
     37  replay_equip.sh -h
     38  to see the options
    3439
    3540* replay_param.sh
  • BOL/Replay/replay_clean.sh

    r4346 r4347  
    11#!/bin/bash
    22
     3
    34replay_comment="replay automatic include"
    4 \rm -f dump_replay*.h mcall_param_replay.F90 dump_ini_module.F90 get_ini_module.F90 input tmp tmp2
    5 for file in `grep "$replay_comment" *F90 | cut -d: -f1` ; do
    6    sed -i"" -e "/$replay_comment/d" $file
    7 done
     5if [ $# = 0 ] ; then
     6   \rm -f dump_replay*.h mcall_param_replay.F90 dump_ini_module.F90 get_ini_module.F90 input tmp tmp2
     7   for file in `grep "$replay_comment" *F90 | cut -d: -f1` ; do
     8      sed -i"" -e "/$replay_comment/d" $file
     9   done
     10else
     11   for file in $* ; do
     12       list_include=`grep $replay_comment $file | grep include | cut -d\" -f2`
     13       echo removing $list_include
     14       \rm -f $list_include
     15       \rm -f dump_replay_`basename $file .F90`_*h
     16       sed -i'' -e "/$replay_comment/d" $file
     17   done
     18fi
  • BOL/Replay/replay_equip.sh

    r4346 r4347  
    7878#-----------------------------------------------------------------------------
    7979nconly=false
     80where=-before_return
     81
    8082if [ $# = 0 ] ; then $0 -h ; exit ; fi
    8183while (($# > 0))
     
    8385   case $1 in
    8486     -h|--help) cat <<........fin
    85            $0 [-nconly] [-pre prefix] routine_name
    86            The prefix will be put on each variable stored in the nc file
     87           $0 [-nconly] [-ncvars var1,var2,...] [-pre prefix] [location_in_the_code] routine_name
     88           The prefix will be put on each variable stored in the nc file to avoid duplicate
     89                variables names
     90           If -ncvars is not specified, all the variables are output
     91           The prefix is used to prevent having twice the same name if the same variable is
     92              output at two locations in the code.
     93           location_in_the_code can be : -before_return               (the default valuer)
     94                                         -after_declarations
     95                                         -before_line  "line in code"
     96                                         -after_line   "line in code"
     97                                         -before_call  "param_name"   (TO BE DONE)
     98                                         -after_call   "param_name"   (TO BE DONE)
    8799........fin
    88100        exit ;;
    89101     -nconly) nconly=true ; shift ;;
     102     -before_line|-after_line|-before_call|-after_call) where="$1 $2" ; shift ; shift ;;
     103     -before_return|-after_declarations) where=$1 ; shift ;;
    90104     -pre) prefix=$2 ; shift ; shift ;;
     105     -ncvars) ncvars="`echo $2 | sed -e 's/,/ /g'`" ; shift ; shift ;;
    91106     *) if (( $# > 1 )) ; then $0 -h ; exit ; fi ; param=`basename $1 .F90` ; shift
    92107    esac
     
    107122iniinc=dump_replay_ini.h
    108123paramfile=`grep -i "subro.* ${param}[\ (]" *.F90 | sed -e 's/ //g' | grep "${param}(" | cut -d: -f1`
    109 echo La parametrisation $param est contenue dans le fichier $paramfile
     124echo ===================================================================================
     125echo Equiping $param contained in file $paramfile
    110126if [ `echo ${paramfile} | wc -w` != 1 ] ; then echo file $paramfile multiple  ; $0 -h ; exit ; fi
    111127
     
    149165   # $2 nom du fichier
    150166   # input <- routine under treatment with small caps only
    151    cpp $2 | tr '[A-Z]' '[a-z]' > tmp
     167   ( cpp $2 2>/dev/null ) | tr '[A-Z]' '[a-z]' > tmp
    152168   name_min=`echo $1 | tr '[A-Z]' '[a-z]'`
    153169   line1=`sed -n -e "/subrou.*${name_min}.*(/=" tmp | head -1 `
     
    163179#-----------------------------------------------------------------------------
    164180   # Including param_dump*.h in the parameterization
    165    line_to_be_included=$1
    166    param_=$2
    167    paramfile_=$3
    168    where=$4
     181   #set -vx
     182   line_to_be_included=$1  ; shift
     183   param_=$1 ; shift
     184   paramfile_=$1 ; shift
    169185   name_min=`echo $param_ | tr [A-Z] [a-z]`
    170    echo $name_min ...
    171186   line_subroutine=`cat $paramfile_ | tr '[A-Z]' '[a-z]' | sed -n -e "/subrou.*${name_min}.*(/=" | head -1 `
    172    echo LINE $line_subroutine
    173    tail -n +$line_subroutine $paramfile_ > tmp
     187   tail -n +$line_subroutine $paramfile_ > tmp # file starting at the subroutine instruction
    174188   line_return=`sed -n -e "/[Rr][Ee][Tt][Uu][Rr][Nn]/=" tmp | head -1`
    175    line_declarations=`head -$line_return tmp | tr '[A-Z]' '[a-z]' | sed -n -e 's/\!.*$//' -e "/[\ ,]real[\ ,]/=" -e "/[\ ,]integer[\ ,]/=" -e "/[\ ,]logical[\ ,]/=" -e "/[\ ,]character[\ ,]/=" | tail -1`
    176    echo lignes $line_subroutine $line_return $line_declarations
    177    case $where in
    178       after_declarations) linebefore_include=$(( $(( $line_subroutine + $line_declarations )) -1 )) ;;
    179       before_return)      linebefore_include=$(( $(( $line_subroutine + $line_return )) -2 )) ;;
    180       *)                  echo Cas non prevu where=$where in inclide_file
    181    esac
    182    # including lines in revers order
    183    sed -i'' -e $linebefore_include"s/$/\n $line_to_be_included \!  $replay_comment/" $paramfile_
     189   head -$line_return tmp > tmp2               # file containing the routine
     190   sed -e 's/\!.*$//' tmp2 > tmp3
     191   cpp tmp2 > tmp3 2>/dev/null
     192   cat tmp3 | tr '[A-Z]' '[a-z]' > tmp2_cpp   # same after cpp filtering
     193   last_line_declaration2="`sed -n -e 's/\!.*$//' -e 's/^/ /' -e '/[\ ,]real[\ ,]/p' -e '/[\ ,]integer[\ ,]/p' -e '/[\ ,]logical[\ ,]/p' -e '/[\ ,]character[\ ,]/p' tmp2_cpp | tail -1 | sed -e 's/  / /g' -e 's/ /.*/g'`"
     194   line_last_declaration=`cat tmp2 | tr '[A-Z]' '[a-z]' | sed -n -e "/$last_line_declaration2/="`
     195   if [ "$line_last_declaration" = "" ] ; then echo line_last_declaration $line_last_declaration line $last_line_declaration2  ; exit ; fi
     196   if (( $# > 0 )) ; then
     197      wtype=`echo $1 | awk ' { print $1 } '`
     198      case $wtype in
     199         -after_declarations)      targeted_line=$line_last_declaration ;;
     200         -before_return)           targeted_line=$line_return ;;
     201         -before_line|-after_line) linestr=`echo $1 | sed -e "s/$wtype //"` ; targeted_line=`sed -n -e "/$linestr/=" tmp2` ;;
     202         *)                  echo Cas non prevu 0 where=$where in inclide_file
     203      esac
     204      case $wtype in
     205         -after_declarations|-after_line)  line0=$(( $line_subroutine - 1 )) ;;
     206         -before_return|-before_line)      line0=$(( $line_subroutine - 2 )) ;;
     207         *)                  echo Cas non prevu 1 where=$where in inclide_file
     208      esac
     209      echo Including line $line0 in $paramfile_ the line : $line_to_be_included
     210      linebefore_include=$(( $line0 + $targeted_line ))
     211     sed -i'' -e $linebefore_include"s/$/\n $line_to_be_included \!  $replay_comment/" $paramfile_
     212   fi
    184213}
    185214
     
    204233function iotd_calls(){
    205234#-----------------------------------------------------------------------------
    206     klev=$1 ; shift
     235    klev_=$1 ; shift
    207236    pre=$1 ; shift
    208237    if (( $# >> 0 )) ; then
    209238       vars=$*
    210239       for var in $vars ; do
    211           echo "call iotd_ecrit_seq('"$pre$var"',1,'"$pre$var in $param"',' ',"$var")"
     240          echo "call iotd_ecrit_seq('"$pre$var"',$klev_,'"$pre$var in $param"',' ',"$var")"
    212241       done
    213242    fi
    214243}
    215244         
     245#-----------------------------------------------------------------------------
     246function b_among_a() {
     247#-----------------------------------------------------------------------------
     248   a="$1"
     249   b="$2"
     250   o=""
     251   for v in $a ; do
     252       for vv in $b ; do
     253           if [ "$v" = "$vv" ] ; then o="$o $v" ;  fi
     254       done
     255   done
     256   echo $o
     257}
     258
    216259
    217260#-----------------------------------------------------------------------------
     
    228271
    229272#-----------------------------------------------------------------------------
    230 # Liste des variables d'intent in pour stokage
     273# Analysis of the variables to be stored and there nature
    231274#-----------------------------------------------------------------------------
    232275
     
    235278varinout0=`grep inten.*.inout input | sed -e '/\!.*$/d' | cut -d: -f3 | sed -e 's/,/ /g'`
    236279varin=`echo $varin0 | sed -e 's/ /,/g' -e "s/,,,/,/g" -e "s/,,/,/g"`
    237 echo varin $varin0
    238280output=full # Attention, l'option full ne marche pas a cause de tableaux locaux undef
    239281nvar0D=0 ; nvar1D=0 ; nvar2D=0
     
    248290var_1D=`grep -i "$search_str" input | grep $klon | sed -e 's/!.*$//' -e /$klev/d | cut -d: -f3 | sed -e 's/,/ /g'`
    249291var_2D=`grep -i "$search_str" input | grep $klon | grep $klev | cut -d: -f3 | sed -e 's/!.*$//' -e 's/,/ /g'`
    250 echo varin  : $varin
    251 echo var_1D_inout : $var_1D_inout ; echo
    252 echo var_2D_inout : $var_2D_inout ; echo
    253 echo var_1D_noarg : $var_1D_noarg ; echo
    254 echo var_2D_noarg : $var_2D_noarg ; echo
    255 echo var_1D : $var_1D ; echo
    256 echo var_2D : $var_2D ; echo
     292if [ "$ncvars" != "" ] ; then
     293   var_1D=`b_among_a "$var_1D" "$ncvars"`
     294   var_2D=`b_among_a "$var_2D" "$ncvars"`
     295fi
     296echo Variables in and inout : $varin0
     297echo 1D variables "(all)" : $var_1D
     298echo 2D variables "(all)" : $var_2D
     299echo 1D variables "intent(inout)" : $var_1D_inout
     300echo 2D variables "intent(inout)" : $var_2D_inout
     301echo local 1D variables : $var_1D_noarg
     302echo local 2D variables : $var_2D_noarg
    257303
    258304#-----------------------------------------------------------------------------
     
    309355#-----------------------------------------------------------------------------
    310356
     357if [ $nconly = false ] ; then
    311358\rm $paraminc1
    312 if [ $nconly = false ] ; then
    313359cat> $paraminc1 <<eod
    314360logical, save :: first=.true.
     
    327373fi # nconly = false
    328374
    329 for var in $var_1D_noarg $var_2D_noarg ; do echo $var=0. >> $paraminc1 ; done
    330 include_line "include \"$paraminc1\"" $param $paramfile after_declarations
     375if [ "`grep $paraminc1 $paramfile`" = "" ] ; then
     376   # Not changing $paraminc1 if it is already included in the file
     377   # To allow adding new nc outputs in a routine equiped for replay
     378   for var in $var_1D_noarg $var_2D_noarg ; do echo $var=0. >> $paraminc1 ; done
     379   include_line "include \"$paraminc1\"" $param $paramfile -after_declarations
     380fi
    331381
    332382#-----------------------------------------------------------------------------
     
    337387iotd_calls 1     "${prefix}" $var_1D >> $paraminc2
    338388iotd_calls $klev "${prefix}" $var_2D >> $paraminc2
    339 include_line "include \"$paraminc2\"" $param $paramfile before_return
     389include_line "include \"$paraminc2\"" $param $paramfile "$where"
    340390 
    341391#-----------------------------------------------------------------------------
     
    352402close(90)
    353403eod
    354 include_line "include \"$iniinc\"" $paramini $inimod.F90  before_return
     404include_line "include \"$iniinc\"" $paramini $inimod.F90  -before_return
    355405fi # nconly = false
    356406
Note: See TracChangeset for help on using the changeset viewer.