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