[4337] | 1 | #!/bin/bash |
---|
| 2 | |
---|
[5033] | 3 | #set -vx |
---|
[4337] | 4 | |
---|
| 5 | #============================================================================= |
---|
| 6 | # F. Hourdin : 2022/05/03 |
---|
| 7 | # |
---|
| 8 | # Objet : |
---|
| 9 | # ----- |
---|
| 10 | # Script préparant les programes pour rejouer (replay) une paramétrisation |
---|
| 11 | # ou un morceau de paramétriation. |
---|
| 12 | # |
---|
| 13 | # |
---|
| 14 | # Applicabilité : |
---|
| 15 | # --------------- |
---|
| 16 | # Est fait pour rejouer des paramétisation de LMDZ organisées comme |
---|
| 17 | # des calcul sur des successions de colonnes indépendantes (boucle |
---|
| 18 | # interne en $klon) de $klev niveaux verticaux. |
---|
| 19 | # Demande que la paramétrisation répondent aux règles de codage suivantes : |
---|
| 20 | # 1) Les routines de calcul et les routines ou fonctions qu'elles appellent |
---|
| 21 | # n'ont que deux interfaces : A) les arguments d'entrée |
---|
| 22 | # B) le use d'un unique module |
---|
| 23 | # Entre autre, les dimensions de la paramétrisation sont passés |
---|
| 24 | # en argument, ce qui permet une allocation dynamique implicite |
---|
| 25 | # de toutes les variables. |
---|
| 26 | # 2) le module d'initialisation doit lui même être initialisé par |
---|
| 27 | # une unique routine pilotée entièrement par ses arguments. |
---|
| 28 | # 3) Toutes les variables d'interface doivent être déclarées intent in |
---|
| 29 | # out, ou inout |
---|
| 30 | # On appelera la paramétriation "param" et l'intialisation "param_ini" |
---|
| 31 | # mais les noms de fichiers sont en argument dans le script. |
---|
| 32 | # |
---|
| 33 | # |
---|
| 34 | # Principe : |
---|
| 35 | # ---------- |
---|
| 36 | # Dans une première simulation, on écrit dans un fichier binaire toutes |
---|
| 37 | # les variables "intent in/inout" de la routine d'initialisation et de la routine |
---|
| 38 | # de calcul. |
---|
| 39 | # |
---|
| 40 | # |
---|
| 41 | # En pratique : |
---|
| 42 | # ------------- |
---|
| 43 | # |
---|
| 44 | # Le script a comme argument le nom de la routine à traiter, nommée $param |
---|
| 45 | # Des correpspondances en déduisent : |
---|
[4656] | 46 | # param_ini=wake_ini # nom de la subroutine d'intialisation |
---|
[4337] | 47 | # inimod= # nom du module contenant $param_ini |
---|
| 48 | # klon=klon ; klev=klev # nom des dimensions horiz; vert utilisée |
---|
| 49 | # |
---|
| 50 | # Le fichier ${paramfile} contenant $param est detecté automatiquement |
---|
| 51 | # Le script crée 5 fichiers |
---|
| 52 | # * dump_param1.h : écriture de l'interface "in" de param (dump_param.bin fort.82) |
---|
| 53 | # * dump_param2.h : écriture des sorties de la routines dans phys.nc |
---|
[4378] | 54 | # * call_param_replay : sous programme d'appelle en boucle à la param |
---|
[5442] | 55 | # * dump_ini_module.${f90} : écriture de l'interface "in" de param_ini |
---|
| 56 | # * call_ini_replay.${f90} : lecture de l'interface "in" de param_ini |
---|
[4337] | 57 | # dans ${param_ini}_mod.bin. |
---|
| 58 | # Par ailleurs, un programme replay1d a été ajouté dans phylmd/dyn1d |
---|
| 59 | # qui appelle call_param_replay |
---|
| 60 | # Le script ajoute par ailleurs quelques lignes dans ${paramfile} et |
---|
[5442] | 61 | # ${param_ini}.${f90} |
---|
[4337] | 62 | # replay_clean.sh élimine toutes les lignes ajoutées |
---|
| 63 | # |
---|
| 64 | # |
---|
| 65 | # A travailler : |
---|
| 66 | # -------------- |
---|
| 67 | # * détecter automatiquement le fichier contenant l'intialisation |
---|
| 68 | # * détecter automatiquement les dimensions |
---|
| 69 | # * avoir un moyen de vérifier si les variables intent in et out sont |
---|
| 70 | # bien les bonnes. |
---|
| 71 | # * Initialisation plus simple de la routine getin_p |
---|
| 72 | # * Des choix sur la facon de controler l'initialisation et le pb des getin |
---|
| 73 | # |
---|
| 74 | #============================================================================= |
---|
| 75 | |
---|
[5442] | 76 | f90=f90 |
---|
| 77 | |
---|
[4346] | 78 | #----------------------------------------------------------------------------- |
---|
| 79 | # Reading rguments |
---|
| 80 | #----------------------------------------------------------------------------- |
---|
| 81 | nconly=false |
---|
[4347] | 82 | where=-before_return |
---|
[5033] | 83 | lonlat= |
---|
[4347] | 84 | |
---|
[4346] | 85 | if [ $# = 0 ] ; then $0 -h ; exit ; fi |
---|
| 86 | while (($# > 0)) |
---|
| 87 | do |
---|
| 88 | case $1 in |
---|
| 89 | -h|--help) cat <<........fin |
---|
[5033] | 90 | $0 [-nconly] [-ncvars var1,var2,...] [-pre prefix] [location_in_the_code] [-lonlat lon,lat] routine_name |
---|
[4347] | 91 | The prefix will be put on each variable stored in the nc file to avoid duplicate |
---|
| 92 | variables names |
---|
| 93 | If -ncvars is not specified, all the variables are output |
---|
| 94 | The prefix is used to prevent having twice the same name if the same variable is |
---|
| 95 | output at two locations in the code. |
---|
[5033] | 96 | The -nconly option can be used to equip other routines with nc output only |
---|
[4347] | 97 | location_in_the_code can be : -before_return (the default valuer) |
---|
| 98 | -after_declarations |
---|
| 99 | -before_line "line in code" |
---|
| 100 | -after_line "line in code" |
---|
| 101 | -before_call "param_name" (TO BE DONE) |
---|
| 102 | -after_call "param_name" (TO BE DONE) |
---|
[5033] | 103 | -lonlat longitude,latitude |
---|
[4346] | 104 | ........fin |
---|
| 105 | exit ;; |
---|
| 106 | -nconly) nconly=true ; shift ;; |
---|
[4347] | 107 | -before_line|-after_line|-before_call|-after_call) where="$1 $2" ; shift ; shift ;; |
---|
| 108 | -before_return|-after_declarations) where=$1 ; shift ;; |
---|
[4346] | 109 | -pre) prefix=$2 ; shift ; shift ;; |
---|
[4347] | 110 | -ncvars) ncvars="`echo $2 | sed -e 's/,/ /g'`" ; shift ; shift ;; |
---|
[5033] | 111 | -lonlat) lonlat=$2 ; shift ; shift ;; |
---|
[5442] | 112 | *) if (( $# > 1 )) ; then $0 -h ; exit ; fi ; param=`basename $1 .${f90}` ; shift |
---|
[4346] | 113 | esac |
---|
| 114 | done |
---|
| 115 | if [ "$param" = "" ] ; then $0 -h ; exit ; fi |
---|
| 116 | |
---|
[4337] | 117 | case $param in |
---|
[4681] | 118 | vdif_k|vdif_cd|vdif|my_25|vdif_dq) param_ini=vdif_ini ; inimod=simple_vdif_ini ; klon=ngrid ; klev=nlay ;; |
---|
[5449] | 119 | thermcell_plume_6A|thermcell_env|thermcell_height|thermcell_dry|\ |
---|
[4373] | 120 | thermcell_closure|thermcell_height|thermcell_dq|thermcell_flux2|thermcell_down| \ |
---|
[5033] | 121 | thermcell_updown_dq|thermcell_dtke) \ |
---|
[4656] | 122 | param_ini=thermcell_ini ; inimod=lmdz_thermcell_ini ; klon=ngrid ; klev=nlay ;; |
---|
[5033] | 123 | wake|pkupper|wake_popdyn_1|wake_popdyn_2|vdif_kcay|ustarhb) param_ini=wake_ini ; inimod=lmdz_wake_ini ; klon=klon ; klev=klev ;; |
---|
[5449] | 124 | surf_wind) param_ini=surf_wind_ini ; inimod=lmdz_surf_wind_ini ; klon=klon ; klev=nsrfwnd ;; |
---|
[4656] | 125 | ratqs_main|ratqs_inter|ratqs_oro|ratqs_hetero|ratqs_tke) param_ini=ratqs_ini ; inimod=lmdz_ratqs_ini ; klon=klon ; klev=klev ;; |
---|
[4668] | 126 | lscp|fisrtilp) param_ini=lscp_ini ; inimod=lmdz_lscp_ini ; klon=klon ; klev=klev ;; |
---|
[4337] | 127 | *) echo Cas non prevu ; exit |
---|
| 128 | esac |
---|
| 129 | |
---|
| 130 | replay_comment="replay automatic include" |
---|
[4346] | 131 | paraminc1=dump_replay_${param}_head.h |
---|
| 132 | paraminc2=dump_replay_${param}_nc_${prefix}.h |
---|
| 133 | iniinc=dump_replay_ini.h |
---|
[5442] | 134 | paramfile=`grep -i "subro.* ${param}[\ (]" *.${f90} | sed -e 's/ //g' | grep "${param}(" | cut -d: -f1` |
---|
[4347] | 135 | echo =================================================================================== |
---|
| 136 | echo Equiping $param contained in file $paramfile |
---|
[4346] | 137 | if [ `echo ${paramfile} | wc -w` != 1 ] ; then echo file $paramfile multiple ; $0 -h ; exit ; fi |
---|
[4337] | 138 | |
---|
[4346] | 139 | |
---|
[4337] | 140 | #----------------------------------------------------------------------------- |
---|
| 141 | # Transformer l'entete d'une subroutine en un call |
---|
| 142 | #----------------------------------------------------------------------------- |
---|
| 143 | |
---|
| 144 | function get_subroutine_arg(){ |
---|
[4668] | 145 | tmp=tmp_get_subroutine_arg |
---|
| 146 | cat $2 | tr '[A-Z]' '[a-z]' > ${tmp} |
---|
| 147 | line1=`sed -n -e '/subrou.*'\`echo $1 | tr '[A-Z]' '[a-z]'\`'.*(/=' ${tmp} | head -1 ` |
---|
| 148 | line2=`tail -n +$line1 ${tmp} | sed -n -e '/)/=' | head -1` |
---|
| 149 | tail -n +$line1 ${tmp} | sed -n -e 1,${line2}p |
---|
[4337] | 150 | } |
---|
| 151 | |
---|
| 152 | #----------------------------------------------------------------------------- |
---|
[5033] | 153 | function var_get_dims(){ |
---|
| 154 | #----------------------------------------------------------------------------- |
---|
| 155 | local var=$1 |
---|
| 156 | local line=$( grep dimension input | grep '::.*'$var | grep -w $var | sed -e 's/ //g' ) |
---|
| 157 | local pattern='dimension\s*\(([a-z0-9,+]*)\)' |
---|
| 158 | if [[ $line =~ $pattern ]] ; then |
---|
| 159 | echo ${BASH_REMATCH[1]} | sed -e 's/,/ /g' |
---|
| 160 | fi |
---|
| 161 | } |
---|
| 162 | #----------------------------------------------------------------------------- |
---|
| 163 | function var_dims(){ |
---|
| 164 | #----------------------------------------------------------------------------- |
---|
| 165 | local var=$1 |
---|
| 166 | local dims=$(var_get_dims $var) |
---|
| 167 | if [[ "$dims" != "" ]] ; then |
---|
| 168 | local dims_= |
---|
| 169 | for d in $dims ; do |
---|
| 170 | if [[ $d = $klon ]] ; then |
---|
| 171 | dims_="${dims_} 1:$klon" |
---|
| 172 | else |
---|
| 173 | dims_="$dims_ :" |
---|
| 174 | fi |
---|
| 175 | done |
---|
| 176 | echo \(${dims_}\) | sed -e 's/( /(/' -e 's/ /,/g' |
---|
| 177 | fi |
---|
| 178 | |
---|
| 179 | } |
---|
| 180 | #----------------------------------------------------------------------------- |
---|
| 181 | function var_recl(){ |
---|
| 182 | #----------------------------------------------------------------------------- |
---|
| 183 | local var=$1 |
---|
| 184 | local dims=$( var_get_dims $var ) |
---|
| 185 | if [[ "$dims" != "" ]] ; then |
---|
| 186 | local dims_= ; for i in $dims ; do dims_="$dims_ ($i)" ; done |
---|
| 187 | echo $dims_ | sed -e 's/ /*/' |
---|
| 188 | else |
---|
| 189 | echo 1 |
---|
| 190 | fi |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | #----------------------------------------------------------------------------- |
---|
[4337] | 194 | function dump_param_open(){ |
---|
[4591] | 195 | #----------------------------------------------------------------------------- |
---|
| 196 | # Opening an direct access file with one record per time-step |
---|
| 197 | # Each record has the size and contains the arguments in and inout of the |
---|
| 198 | # routine |
---|
| 199 | #----------------------------------------------------------------------------- |
---|
| 200 | inout=$1 ; shift |
---|
| 201 | case $inout in |
---|
| 202 | out) fort=81 ;; |
---|
| 203 | in) fort=82 |
---|
| 204 | esac |
---|
| 205 | echo '! <<< dump_param_open' |
---|
[5033] | 206 | echo 'print*,"NOUVEAU REPLAY"' |
---|
| 207 | for var in $* ; do |
---|
| 208 | #echo 'rec_length_replay=rec_length_replay+kind('$var')*size(['$var'])' |
---|
| 209 | echo 'rec_length_replay=rec_length_replay+kind('$var')*'$( var_recl $var ) |
---|
| 210 | done |
---|
[4591] | 211 | cat <<....eod |
---|
| 212 | open(${fort},file='dump_param_${inout}.bin',form='unformatted',access='direct',recl=rec_length_replay) ! $replay_comment |
---|
| 213 | ....eod |
---|
| 214 | echo '! dump_param_open >>> ' |
---|
[4337] | 215 | } |
---|
| 216 | |
---|
[4346] | 217 | |
---|
[4337] | 218 | #----------------------------------------------------------------------------- |
---|
| 219 | function extract_subroutine(){ |
---|
| 220 | #----------------------------------------------------------------------------- |
---|
| 221 | # $1 nom de la subroutine |
---|
| 222 | # $2 nom du fichier |
---|
| 223 | # input <- routine under treatment with small caps only |
---|
[4668] | 224 | tmp=tmp_extract_subroutine |
---|
| 225 | ( cpp $2 2>/dev/null ) | tr '[A-Z]' '[a-z]' > ${tmp} |
---|
[4337] | 226 | name_min=`echo $1 | tr '[A-Z]' '[a-z]'` |
---|
[4668] | 227 | line1=`sed -n -e "/subrou.*${name_min}.*(/=" ${tmp} | head -1 ` |
---|
| 228 | tail -n +$line1 ${tmp} > ${tmp}2 |
---|
| 229 | line2=`sed -n -e "/[Rr][Ee][Tt][Uu][Rr][Nn]/=" ${tmp}2 | head -1` |
---|
| 230 | head -$line2 ${tmp}2 > input |
---|
| 231 | \rm -f ${tmp} ${tmp}2 |
---|
[4337] | 232 | } |
---|
| 233 | |
---|
[4346] | 234 | |
---|
[4337] | 235 | #----------------------------------------------------------------------------- |
---|
[4591] | 236 | function echo_use_module(){ |
---|
| 237 | #----------------------------------------------------------------------------- |
---|
| 238 | # Regle tacite : l'instruction MODULE commence à la premiere colonne. |
---|
| 239 | # Existe-t-i une facon de la faire tomber ? |
---|
| 240 | # En enlevant tous les blanc dans le input sans doute ... |
---|
| 241 | param_=$1 ; shift |
---|
| 242 | paramfile_=$1 |
---|
| 243 | if [ ! -f $paramfile_ ] ; then echo plantage which_module ; exit 1 ; fi |
---|
| 244 | module=`grep '^[mM][oO][dD][uU][lL][eE] .*[a-Z]' $paramfile_ | head -1 | awk ' { print $2 } '` |
---|
| 245 | if [ "$module" != "" ] ; then |
---|
| 246 | echo USE $module, ONLY : $param_ |
---|
| 247 | fi |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | #----------------------------------------------------------------------------- |
---|
[4337] | 251 | function include_line(){ |
---|
| 252 | #----------------------------------------------------------------------------- |
---|
| 253 | # Including param_dump*.h in the parameterization |
---|
[4347] | 254 | #set -vx |
---|
[4668] | 255 | tmp=tmp_include_line |
---|
[4347] | 256 | line_to_be_included=$1 ; shift |
---|
| 257 | param_=$1 ; shift |
---|
| 258 | paramfile_=$1 ; shift |
---|
[4337] | 259 | name_min=`echo $param_ | tr [A-Z] [a-z]` |
---|
| 260 | line_subroutine=`cat $paramfile_ | tr '[A-Z]' '[a-z]' | sed -n -e "/subrou.*${name_min}.*(/=" | head -1 ` |
---|
[4668] | 261 | tail -n +$line_subroutine $paramfile_ > ${tmp} # file starting at the subroutine instruction |
---|
| 262 | line_return=`sed -n -e "/[Rr][Ee][Tt][Uu][Rr][Nn]/=" ${tmp} | head -1` |
---|
| 263 | head -$line_return ${tmp} > ${tmp}2 # file containing the routine |
---|
| 264 | sed -e 's/\!.*$//' ${tmp}2 > ${tmp}3 |
---|
| 265 | cpp ${tmp}2 > ${tmp}3 2>/dev/null |
---|
| 266 | cat ${tmp}3 | tr '[A-Z]' '[a-z]' > ${tmp}2_cpp # same after cpp filtering |
---|
| 267 | last_line_declaration2="`sed -n -e 's/\!.*$//' -e 's/^/ /' -e '/[\ ,]real[\ ,]/p' -e '/[\ ,]integer[\ ,]/p' -e '/[\ ,]logical[\ ,]/p' -e '/[\ ,]character[\ ,]/p' ${tmp}2_cpp | tail -1 | sed -e 's/ / /g' -e 's/ /.*/g'`" |
---|
| 268 | line_last_declaration=`cat ${tmp}2 | tr '[A-Z]' '[a-z]' | sed -n -e "/$last_line_declaration2/="` |
---|
[4591] | 269 | echo OK0 |
---|
| 270 | if [ "`grep -i 'end.*module' $paramfile_`" = "" ] ; then echo aka ; line_end_module=`wc -l $paramfile_ | awk ' { print $1 } '` ; else echo akb ; line_end_module=`sed -n -e '/[eE][nN][dD] .*[mM][oO][dD][uU][lL][eE]/=' $paramfile_` ; fi |
---|
| 271 | echo OK1 |
---|
| 272 | echo $line_end_module |
---|
[4347] | 273 | if [ "$line_last_declaration" = "" ] ; then echo line_last_declaration $line_last_declaration line $last_line_declaration2 ; exit ; fi |
---|
| 274 | if (( $# > 0 )) ; then |
---|
| 275 | wtype=`echo $1 | awk ' { print $1 } '` |
---|
| 276 | case $wtype in |
---|
| 277 | -after_declarations) targeted_line=$line_last_declaration ;; |
---|
| 278 | -before_return) targeted_line=$line_return ;; |
---|
[4591] | 279 | -before_end_module) targeted_line=$line_end_module ;; |
---|
[4668] | 280 | -before_line|-after_line) linestr=`echo $1 | sed -e "s/$wtype //"` ; targeted_line=`sed -n -e "/$linestr/=" ${tmp}2` ;; |
---|
[4591] | 281 | *) echo Cas non prevu 0 where=$where in include_file |
---|
[4347] | 282 | esac |
---|
| 283 | case $wtype in |
---|
| 284 | -after_declarations|-after_line) line0=$(( $line_subroutine - 1 )) ;; |
---|
| 285 | -before_return|-before_line) line0=$(( $line_subroutine - 2 )) ;; |
---|
[4591] | 286 | -before_end_module) line0=-1 ;; |
---|
| 287 | *) echo Cas non prevu 1 where=$where in include_file |
---|
[4347] | 288 | esac |
---|
[4591] | 289 | echo Including line $line0 + $targeted_line in $paramfile_ the line : $line_to_be_included |
---|
[4347] | 290 | linebefore_include=$(( $line0 + $targeted_line )) |
---|
| 291 | sed -i'' -e $linebefore_include"s/$/\n $line_to_be_included \! $replay_comment/" $paramfile_ |
---|
| 292 | fi |
---|
[4337] | 293 | } |
---|
| 294 | |
---|
| 295 | |
---|
[4346] | 296 | |
---|
| 297 | |
---|
[4337] | 298 | #----------------------------------------------------------------------------- |
---|
| 299 | function block_Replay0() { |
---|
| 300 | #----------------------------------------------------------------------------- |
---|
| 301 | condition=$1 ; shift |
---|
| 302 | suf1=$1 ; shift |
---|
| 303 | suf2=$1 ; shift |
---|
| 304 | if [ $# -gt 0 ] ; then |
---|
| 305 | vars=$* |
---|
| 306 | echo ' if ('$condition') then' |
---|
| 307 | for var in $vars ; do echo ' '$var$suf1=$var$suf2 ; done |
---|
| 308 | echo ' endif' |
---|
| 309 | fi |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | #----------------------------------------------------------------------------- |
---|
[4346] | 313 | function iotd_calls(){ |
---|
[4337] | 314 | #----------------------------------------------------------------------------- |
---|
[4347] | 315 | klev_=$1 ; shift |
---|
[4346] | 316 | pre=$1 ; shift |
---|
| 317 | if (( $# >> 0 )) ; then |
---|
| 318 | vars=$* |
---|
[5038] | 319 | echo "if ( abs(gr_index_)>0 ) then" |
---|
[4346] | 320 | for var in $vars ; do |
---|
[5033] | 321 | local vardim=$( var_dims $var ) |
---|
| 322 | echo "call iotd_ecrit_seq('"$pre$var"',$klev_,'"$pre$var in $param"',' ',"$var$vardim")" |
---|
[4346] | 323 | done |
---|
[5038] | 324 | echo endif |
---|
[4346] | 325 | fi |
---|
| 326 | } |
---|
| 327 | |
---|
[4347] | 328 | #----------------------------------------------------------------------------- |
---|
| 329 | function b_among_a() { |
---|
| 330 | #----------------------------------------------------------------------------- |
---|
| 331 | a="$1" |
---|
| 332 | b="$2" |
---|
| 333 | o="" |
---|
| 334 | for v in $a ; do |
---|
| 335 | for vv in $b ; do |
---|
| 336 | if [ "$v" = "$vv" ] ; then o="$o $v" ; fi |
---|
| 337 | done |
---|
| 338 | done |
---|
| 339 | echo $o |
---|
| 340 | } |
---|
[4337] | 341 | |
---|
[4347] | 342 | |
---|
[4337] | 343 | #----------------------------------------------------------------------------- |
---|
[5442] | 344 | # On nettoye les inclusions précédente dans les fichiers .${f90} |
---|
[4337] | 345 | #----------------------------------------------------------------------------- |
---|
| 346 | |
---|
[4346] | 347 | if [ $nconly = false ] ; then |
---|
[5442] | 348 | for file in `grep "$replay_comment" *.${f90} 2> /dev/null | cut -d: -f1` ; do |
---|
[4346] | 349 | sed -i"" -e "/$replay_comment/d" $file |
---|
| 350 | done |
---|
[4681] | 351 | #line=`sed -n -e "/CALL "$param_ini"/=" physiq_mod.F90 | head -1` |
---|
| 352 | line=`sed -n -e "/CALL wake_ini/=" physiq_mod.F90 | head -1` |
---|
[5033] | 353 | if [[ "$lonlat" = "" ]] ; then |
---|
[5449] | 354 | if [[ $klev == klev || $klev == nlay ]] ; then |
---|
| 355 | klev_=klev |
---|
| 356 | else |
---|
| 357 | klev_=$klev |
---|
| 358 | fi |
---|
| 359 | pattern="CALL iophys_ini(pdtphys,$klev_)" |
---|
[5033] | 360 | else |
---|
| 361 | pattern='call iotd_ini("phys.nc",1,1,klev,'$lonlat',presnivs,1,1,1,0.,pdtphys,calend)' |
---|
| 362 | fi |
---|
[5449] | 363 | |
---|
[5033] | 364 | sed -i"" -e "${line}s/^/ $pattern ! $replay_comment ! $replay_comment\n/" physiq_mod.F90 |
---|
[4346] | 365 | fi |
---|
[4337] | 366 | |
---|
| 367 | #----------------------------------------------------------------------------- |
---|
[4347] | 368 | # Analysis of the variables to be stored and there nature |
---|
[4337] | 369 | #----------------------------------------------------------------------------- |
---|
| 370 | |
---|
[4346] | 371 | extract_subroutine $param $paramfile # -> input file |
---|
[5033] | 372 | #var_get_dims ztv |
---|
| 373 | #var_dims ztv |
---|
| 374 | #exit |
---|
| 375 | # var_recl ztv |
---|
| 376 | # var_dims pplev |
---|
| 377 | # var_recl pplev |
---|
| 378 | # var_dims ngrid |
---|
| 379 | # var_recl ngrid |
---|
| 380 | # exit |
---|
| 381 | |
---|
[4337] | 382 | varin0=`grep inten.*.in input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
[4353] | 383 | varinout0=`grep inten.*.inout input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
[5033] | 384 | echo varin0 $varin0 |
---|
| 385 | varin_rec= ; for v in $varin0 ; do varin_rec="$varin_rec $v$( var_dims $v)" ; done |
---|
| 386 | varin=`echo $varin_rec | sed -e 's/ /,/g' -e "s/,,,/,/g" -e "s/,,/,/g"` |
---|
| 387 | #echo $varin $varin |
---|
[4337] | 388 | output=full # Attention, l'option full ne marche pas a cause de tableaux locaux undef |
---|
| 389 | nvar0D=0 ; nvar1D=0 ; nvar2D=0 |
---|
| 390 | case $output in |
---|
| 391 | light) search_str='real.*intent' ;; |
---|
| 392 | full) search_str='real' |
---|
| 393 | esac |
---|
[4346] | 394 | var_1D_inout=`grep -i "$search_str" input | grep intent.*inout | grep $klon | sed -e 's/!.*$//' -e /$klev/d | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
| 395 | var_2D_inout=`grep -i "$search_str" input | grep intent.*inout | grep $klon | grep $klev | cut -d: -f3 | sed -e 's/!.*$//' -e 's/,/ /g'` |
---|
[4337] | 396 | var_1D_noarg=`grep -i "$search_str" input | sed -e /intent/d | grep $klon | sed -e 's/!.*$//' -e /$klev/d | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
| 397 | var_2D_noarg=`grep -i "$search_str" input | sed -e /intent/d | grep $klon | grep $klev | cut -d: -f3 | sed -e 's/!.*$//' -e 's/,/ /g'` |
---|
| 398 | var_1D=`grep -i "$search_str" input | grep $klon | sed -e 's/!.*$//' -e /$klev/d | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
| 399 | var_2D=`grep -i "$search_str" input | grep $klon | grep $klev | cut -d: -f3 | sed -e 's/!.*$//' -e 's/,/ /g'` |
---|
[4347] | 400 | if [ "$ncvars" != "" ] ; then |
---|
| 401 | var_1D=`b_among_a "$var_1D" "$ncvars"` |
---|
| 402 | var_2D=`b_among_a "$var_2D" "$ncvars"` |
---|
| 403 | fi |
---|
| 404 | echo Variables in and inout : $varin0 |
---|
| 405 | echo 1D variables "(all)" : $var_1D |
---|
| 406 | echo 2D variables "(all)" : $var_2D |
---|
| 407 | echo 1D variables "intent(inout)" : $var_1D_inout |
---|
| 408 | echo 2D variables "intent(inout)" : $var_2D_inout |
---|
| 409 | echo local 1D variables : $var_1D_noarg |
---|
| 410 | echo local 2D variables : $var_2D_noarg |
---|
[4337] | 411 | |
---|
| 412 | #----------------------------------------------------------------------------- |
---|
| 413 | # Ecriture de la routine d'appel a la parametrisation en mode replay |
---|
| 414 | #----------------------------------------------------------------------------- |
---|
| 415 | |
---|
[4346] | 416 | if [ $nconly = false ] ; then |
---|
| 417 | |
---|
[5442] | 418 | cat > call_param_replay.${f90} <<eod |
---|
[4337] | 419 | subroutine call_param_replay($klon,$klev) |
---|
| 420 | USE IOIPSL, ONLY : getin |
---|
[4591] | 421 | `echo_use_module $param $paramfile` |
---|
[4337] | 422 | IMPLICIT NONE |
---|
[4360] | 423 | integer :: ifin,irec,it,rec_length_replay=0,replay_irec0=1,replay_nt=1000 |
---|
[4337] | 424 | eod |
---|
[5442] | 425 | grep 'intent.*::' input | sed -e 's/ //g' -e 's/,intent(.*[nt])//'>> call_param_replay.${f90} |
---|
[4337] | 426 | # duplicating declaration for inout variables |
---|
[4353] | 427 | |
---|
[4337] | 428 | for var in $varinout0 ; do |
---|
[5442] | 429 | sed -e 's/::/ :: /' -e 's/,/ , /g' -e 's/$/ /' input | grep 'intent.*inout.*::.* '$var' ' | sed -e 's/ //g' -e 's/,intent(.*[nt])//' | sed -e 's/::.*$/, allocatable, save :: '$var'_Replay0/' | sed -e 's/'$klon'/:/' -e 's/'${klev}'+1/:/' -e 's/'${klev}'/:/' >> call_param_replay.${f90} |
---|
[4337] | 430 | done |
---|
| 431 | # Initalisation, shared with dump_param1.sh |
---|
[5442] | 432 | dump_param_open "in" $varin0 >> call_param_replay.${f90} |
---|
[4337] | 433 | for var in $varinout0 ; do |
---|
[5442] | 434 | sed -e 's/::/ :: /' -e 's/,/ , /g' -e 's/$/ /' input | grep 'intent.*inout.*::.* '$var' ' | sed -e 's/intent(.*t)//' -e 's/^.*(/allocate('$var'_Replay0(/' -e 's/).*$/))/' >> call_param_replay.${f90} |
---|
[4337] | 435 | done |
---|
| 436 | |
---|
[5442] | 437 | cat >> call_param_replay.${f90} <<eod |
---|
[4337] | 438 | call getin('replay_nt',replay_nt) |
---|
| 439 | call getin('replay_irec0',replay_irec0) |
---|
| 440 | do it=1,replay_nt |
---|
| 441 | if (replay_irec0>=0) then |
---|
| 442 | irec=replay_irec0+it-1 |
---|
| 443 | else |
---|
| 444 | irec=-replay_irec0 |
---|
| 445 | endif |
---|
| 446 | print*,'Time step',it,', reading record',irec,'in dump_param.bin' |
---|
| 447 | read(82,rec=irec,iostat=ifin) $varin |
---|
| 448 | if (.NOT. ifin == 0 ) stop "Fin du fichier fort.82" |
---|
| 449 | eod |
---|
| 450 | |
---|
[5442] | 451 | block_Replay0 "it == 1" _Replay0 "" $varinout0 >> call_param_replay.${f90} |
---|
| 452 | block_Replay0 "replay_irec0 < 0" "" _Replay0 $varinout0 >> call_param_replay.${f90} |
---|
| 453 | get_subroutine_arg $param $paramfile | sed -e 's/subroutine/ call/' >> call_param_replay.${f90} |
---|
| 454 | block_Replay0 "replay_irec0 < 0" _Replay0 "" $varinout0 >> call_param_replay.${f90} |
---|
| 455 | cat >> call_param_replay.${f90} <<eod |
---|
[4337] | 456 | enddo |
---|
| 457 | return |
---|
| 458 | end |
---|
| 459 | eod |
---|
| 460 | |
---|
[4346] | 461 | fi # nconly = false |
---|
[4337] | 462 | |
---|
| 463 | #----------------------------------------------------------------------------- |
---|
[4346] | 464 | # Creating file dump_${param}_head.h |
---|
[4337] | 465 | #----------------------------------------------------------------------------- |
---|
| 466 | |
---|
[4347] | 467 | if [ $nconly = false ] ; then |
---|
[4337] | 468 | \rm $paraminc1 |
---|
| 469 | cat> $paraminc1 <<eod |
---|
[4360] | 470 | logical, save :: first_replay=.true. |
---|
[5033] | 471 | integer, save :: rec_length_replay=0,irec=0,gr_index_=-1 |
---|
| 472 | !\$OMP THREADPRIVATE(first_replay,rec_length_replay,irec,gr_index_) |
---|
| 473 | integer, external :: grid_index |
---|
[4337] | 474 | eod |
---|
[5033] | 475 | if [ "$lonlat" != "" ] ; then echo "if (first_replay) gr_index_=grid_index($lonlat)" >> $paraminc1 ; fi |
---|
| 476 | echo "if ($klon==1) gr_index_=1" >> $paraminc1 |
---|
| 477 | echo "if (abs(gr_index_)>0) then" >> $paraminc1 |
---|
| 478 | echo "if (first_replay) then" >> $paraminc1 |
---|
[4337] | 479 | dump_param_open out $varin0 >> $paraminc1 |
---|
| 480 | cat>> $paraminc1 <<eod |
---|
| 481 | endif |
---|
| 482 | irec=irec+1 |
---|
[5038] | 483 | write(81,rec=irec) $varin |
---|
[5033] | 484 | endif |
---|
| 485 | first_replay=.false. |
---|
[4337] | 486 | eod |
---|
[5033] | 487 | |
---|
| 488 | iotd_calls 1 in_${prefix} $var_1D_inout |
---|
[4346] | 489 | iotd_calls 1 in_${prefix} $var_1D_inout >> $paraminc1 |
---|
| 490 | iotd_calls $klev in_${prefix} $var_2D_inout >> $paraminc1 |
---|
| 491 | fi # nconly = false |
---|
[4347] | 492 | if [ "`grep $paraminc1 $paramfile`" = "" ] ; then |
---|
| 493 | # Not changing $paraminc1 if it is already included in the file |
---|
| 494 | # To allow adding new nc outputs in a routine equiped for replay |
---|
| 495 | for var in $var_1D_noarg $var_2D_noarg ; do echo $var=0. >> $paraminc1 ; done |
---|
| 496 | include_line "include \"$paraminc1\"" $param $paramfile -after_declarations |
---|
| 497 | fi |
---|
[4337] | 498 | |
---|
[4346] | 499 | #----------------------------------------------------------------------------- |
---|
| 500 | # Creating file dump_${param}_nc_${prefix}.h |
---|
| 501 | #----------------------------------------------------------------------------- |
---|
| 502 | |
---|
[4337] | 503 | \rm $paraminc2 |
---|
[4346] | 504 | iotd_calls 1 "${prefix}" $var_1D >> $paraminc2 |
---|
| 505 | iotd_calls $klev "${prefix}" $var_2D >> $paraminc2 |
---|
[4347] | 506 | include_line "include \"$paraminc2\"" $param $paramfile "$where" |
---|
[5033] | 507 | |
---|
| 508 | if [[ "$lonlat" != "" ]] ; then |
---|
| 509 | for file in $paraminc1 $paraminc2 ; do sed -i -e "s/1:$klon/gr_index_/g" -e '/rec_l/s/\*('$klon')//g' $file ; done |
---|
[5038] | 510 | sed -i -e "/(81/s/,$klon/,1/" $paraminc1 |
---|
[5033] | 511 | fi |
---|
[4337] | 512 | |
---|
[5033] | 513 | #---------------------------------------------------------------------------- |
---|
[4337] | 514 | # dump_ini_module gere l'ecriture des variables d'interface de l'intialisation |
---|
| 515 | # du module en mode replay |
---|
| 516 | #----------------------------------------------------------------------------- |
---|
| 517 | |
---|
[4656] | 518 | if [ $nconly = false -a $param_ini != None ] ; then |
---|
[5442] | 519 | varinmod=`grep -i 'intent.in' $inimod.${f90} | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
[4378] | 520 | varinmodv=`echo $varinmod | sed -e 's/ /,/g'` |
---|
| 521 | cat > $iniinc <<...eod............................................... |
---|
| 522 | open(90,file='$inimod.bin',form='unformatted') |
---|
| 523 | write(90) $varinmodv |
---|
| 524 | close(90) |
---|
| 525 | ...eod............................................... |
---|
[4668] | 526 | for var_ in $varinmod ; do echo "print*,'Interface $param_ini $var_',$var_" >> $iniinc ; done |
---|
[5442] | 527 | include_line "include \"$iniinc\"" $param_ini $inimod.${f90} -before_return |
---|
[4346] | 528 | fi # nconly = false |
---|
[4337] | 529 | |
---|
| 530 | #----------------------------------------------------------------------------- |
---|
[5442] | 531 | # call_ini_replay.${f90} gere l'initialisation du module en mode replay |
---|
[4337] | 532 | #----------------------------------------------------------------------------- |
---|
[4656] | 533 | if [ $nconly = false -a $param_ini != None ] ; then |
---|
[5442] | 534 | cat > call_ini_replay.${f90} <<....eod............................................ |
---|
[4591] | 535 | subroutine call_ini_replay |
---|
[4378] | 536 | use $inimod |
---|
| 537 | IMPLICIT NONE |
---|
| 538 | ....eod............................................ |
---|
[5442] | 539 | grep -i intent.in $inimod.${f90} | tr '[A-Z]' '[a-z]' | sed -e 's/,.*intent.i.*)//' >> call_ini_replay.${f90} |
---|
| 540 | cat >> call_ini_replay.${f90} <<....eod........................................... |
---|
[4378] | 541 | open(90,file='$inimod.bin',form='unformatted') |
---|
| 542 | read(90) $varinmodv |
---|
| 543 | close(90) |
---|
| 544 | ....eod........................................... |
---|
[5442] | 545 | #get_subroutine_arg $param_ini $inimod.${f90} ; exit |
---|
| 546 | get_subroutine_arg $param_ini $inimod.${f90} | sed -e 's/subroutine/call/' >> call_ini_replay.${f90} |
---|
| 547 | cat >> call_ini_replay.${f90} <<....eod........................................... |
---|
[4378] | 548 | return |
---|
| 549 | end |
---|
| 550 | ....eod........................................... |
---|
[4346] | 551 | fi # nconly = false |
---|