1 | #!/bin/bash |
---|
2 | |
---|
3 | #set -vx |
---|
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 : |
---|
46 | # param_ini=wake_ini # nom de la subroutine d'intialisation |
---|
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 |
---|
54 | # * call_param_replay : sous programme d'appelle en boucle à la param |
---|
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 |
---|
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 | |
---|
76 | #----------------------------------------------------------------------------- |
---|
77 | # Reading rguments |
---|
78 | #----------------------------------------------------------------------------- |
---|
79 | nconly=false |
---|
80 | where=-before_return |
---|
81 | lonlat= |
---|
82 | |
---|
83 | if [ $# = 0 ] ; then $0 -h ; exit ; fi |
---|
84 | while (($# > 0)) |
---|
85 | do |
---|
86 | case $1 in |
---|
87 | -h|--help) cat <<........fin |
---|
88 | $0 [-nconly] [-ncvars var1,var2,...] [-pre prefix] [location_in_the_code] [-lonlat lon,lat] routine_name |
---|
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. |
---|
94 | The -nconly option can be used to equip other routines with nc output only |
---|
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) |
---|
101 | -lonlat longitude,latitude |
---|
102 | ........fin |
---|
103 | exit ;; |
---|
104 | -nconly) nconly=true ; shift ;; |
---|
105 | -before_line|-after_line|-before_call|-after_call) where="$1 $2" ; shift ; shift ;; |
---|
106 | -before_return|-after_declarations) where=$1 ; shift ;; |
---|
107 | -pre) prefix=$2 ; shift ; shift ;; |
---|
108 | -ncvars) ncvars="`echo $2 | sed -e 's/,/ /g'`" ; shift ; shift ;; |
---|
109 | -lonlat) lonlat=$2 ; shift ; shift ;; |
---|
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 | |
---|
115 | case $param in |
---|
116 | vdif_k|vdif_cd|vdif|my_25|vdif_dq) param_ini=vdif_ini ; inimod=simple_vdif_ini ; klon=ngrid ; klev=nlay ;; |
---|
117 | thermcell_main|thermcell_plume_6A|thermcell_env|thermcell_height|thermcell_dry|\ |
---|
118 | thermcell_closure|thermcell_height|thermcell_dq|thermcell_flux2|thermcell_down| \ |
---|
119 | thermcell_updown_dq|thermcell_dtke) \ |
---|
120 | param_ini=thermcell_ini ; inimod=lmdz_thermcell_ini ; klon=ngrid ; klev=nlay ;; |
---|
121 | wake|pkupper|wake_popdyn_1|wake_popdyn_2|vdif_kcay|ustarhb) param_ini=wake_ini ; inimod=lmdz_wake_ini ; klon=klon ; klev=klev ;; |
---|
122 | ratqs_main|ratqs_inter|ratqs_oro|ratqs_hetero|ratqs_tke) param_ini=ratqs_ini ; inimod=lmdz_ratqs_ini ; klon=klon ; klev=klev ;; |
---|
123 | lscp|fisrtilp) param_ini=lscp_ini ; inimod=lmdz_lscp_ini ; klon=klon ; klev=klev ;; |
---|
124 | *) echo Cas non prevu ; exit |
---|
125 | esac |
---|
126 | |
---|
127 | replay_comment="replay automatic include" |
---|
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` |
---|
132 | echo =================================================================================== |
---|
133 | echo Equiping $param contained in file $paramfile |
---|
134 | if [ `echo ${paramfile} | wc -w` != 1 ] ; then echo file $paramfile multiple ; $0 -h ; exit ; fi |
---|
135 | |
---|
136 | |
---|
137 | #----------------------------------------------------------------------------- |
---|
138 | # Transformer l'entete d'une subroutine en un call |
---|
139 | #----------------------------------------------------------------------------- |
---|
140 | |
---|
141 | function get_subroutine_arg(){ |
---|
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 |
---|
147 | } |
---|
148 | |
---|
149 | #----------------------------------------------------------------------------- |
---|
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 | #----------------------------------------------------------------------------- |
---|
191 | function dump_param_open(){ |
---|
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' |
---|
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 |
---|
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 >>> ' |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
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 |
---|
221 | tmp=tmp_extract_subroutine |
---|
222 | ( cpp $2 2>/dev/null ) | tr '[A-Z]' '[a-z]' > ${tmp} |
---|
223 | name_min=`echo $1 | tr '[A-Z]' '[a-z]'` |
---|
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 |
---|
229 | } |
---|
230 | |
---|
231 | |
---|
232 | #----------------------------------------------------------------------------- |
---|
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 | #----------------------------------------------------------------------------- |
---|
248 | function include_line(){ |
---|
249 | #----------------------------------------------------------------------------- |
---|
250 | # Including param_dump*.h in the parameterization |
---|
251 | #set -vx |
---|
252 | tmp=tmp_include_line |
---|
253 | line_to_be_included=$1 ; shift |
---|
254 | param_=$1 ; shift |
---|
255 | paramfile_=$1 ; shift |
---|
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 ` |
---|
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/="` |
---|
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 |
---|
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 ;; |
---|
276 | -before_end_module) targeted_line=$line_end_module ;; |
---|
277 | -before_line|-after_line) linestr=`echo $1 | sed -e "s/$wtype //"` ; targeted_line=`sed -n -e "/$linestr/=" ${tmp}2` ;; |
---|
278 | *) echo Cas non prevu 0 where=$where in include_file |
---|
279 | esac |
---|
280 | case $wtype in |
---|
281 | -after_declarations|-after_line) line0=$(( $line_subroutine - 1 )) ;; |
---|
282 | -before_return|-before_line) line0=$(( $line_subroutine - 2 )) ;; |
---|
283 | -before_end_module) line0=-1 ;; |
---|
284 | *) echo Cas non prevu 1 where=$where in include_file |
---|
285 | esac |
---|
286 | echo Including line $line0 + $targeted_line in $paramfile_ the line : $line_to_be_included |
---|
287 | linebefore_include=$(( $line0 + $targeted_line )) |
---|
288 | sed -i'' -e $linebefore_include"s/$/\n $line_to_be_included \! $replay_comment/" $paramfile_ |
---|
289 | fi |
---|
290 | } |
---|
291 | |
---|
292 | |
---|
293 | |
---|
294 | |
---|
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 | #----------------------------------------------------------------------------- |
---|
310 | function iotd_calls(){ |
---|
311 | #----------------------------------------------------------------------------- |
---|
312 | klev_=$1 ; shift |
---|
313 | pre=$1 ; shift |
---|
314 | if (( $# >> 0 )) ; then |
---|
315 | vars=$* |
---|
316 | for var in $vars ; do |
---|
317 | local vardim=$( var_dims $var ) |
---|
318 | echo "call iotd_ecrit_seq('"$pre$var"',$klev_,'"$pre$var in $param"',' ',"$var$vardim")" |
---|
319 | done |
---|
320 | fi |
---|
321 | } |
---|
322 | |
---|
323 | #----------------------------------------------------------------------------- |
---|
324 | function b_among_a() { |
---|
325 | #----------------------------------------------------------------------------- |
---|
326 | a="$1" |
---|
327 | b="$2" |
---|
328 | o="" |
---|
329 | for v in $a ; do |
---|
330 | for vv in $b ; do |
---|
331 | if [ "$v" = "$vv" ] ; then o="$o $v" ; fi |
---|
332 | done |
---|
333 | done |
---|
334 | echo $o |
---|
335 | } |
---|
336 | |
---|
337 | |
---|
338 | #----------------------------------------------------------------------------- |
---|
339 | # On nettoye les inclusions précédente dans les fichiers .F90 |
---|
340 | #----------------------------------------------------------------------------- |
---|
341 | |
---|
342 | if [ $nconly = false ] ; then |
---|
343 | for file in `grep "$replay_comment" *.F90 2> /dev/null | cut -d: -f1` ; do |
---|
344 | sed -i"" -e "/$replay_comment/d" $file |
---|
345 | done |
---|
346 | #line=`sed -n -e "/CALL "$param_ini"/=" physiq_mod.F90 | head -1` |
---|
347 | line=`sed -n -e "/CALL wake_ini/=" physiq_mod.F90 | head -1` |
---|
348 | if [[ "$lonlat" = "" ]] ; then |
---|
349 | pattern="CALL iophys_ini(pdtphys)" |
---|
350 | else |
---|
351 | pattern='call iotd_ini("phys.nc",1,1,klev,'$lonlat',presnivs,1,1,1,0.,pdtphys,calend)' |
---|
352 | fi |
---|
353 | sed -i"" -e "${line}s/^/ $pattern ! $replay_comment ! $replay_comment\n/" physiq_mod.F90 |
---|
354 | fi |
---|
355 | |
---|
356 | #----------------------------------------------------------------------------- |
---|
357 | # Analysis of the variables to be stored and there nature |
---|
358 | #----------------------------------------------------------------------------- |
---|
359 | |
---|
360 | extract_subroutine $param $paramfile # -> input file |
---|
361 | #var_get_dims ztv |
---|
362 | #var_dims ztv |
---|
363 | #exit |
---|
364 | # var_recl ztv |
---|
365 | # var_dims pplev |
---|
366 | # var_recl pplev |
---|
367 | # var_dims ngrid |
---|
368 | # var_recl ngrid |
---|
369 | # exit |
---|
370 | |
---|
371 | varin0=`grep inten.*.in input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
372 | varinout0=`grep inten.*.inout input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
373 | echo varin0 $varin0 |
---|
374 | varin_rec= ; for v in $varin0 ; do varin_rec="$varin_rec $v$( var_dims $v)" ; done |
---|
375 | varin=`echo $varin_rec | sed -e 's/ /,/g' -e "s/,,,/,/g" -e "s/,,/,/g"` |
---|
376 | #echo $varin $varin |
---|
377 | output=full # Attention, l'option full ne marche pas a cause de tableaux locaux undef |
---|
378 | nvar0D=0 ; nvar1D=0 ; nvar2D=0 |
---|
379 | case $output in |
---|
380 | light) search_str='real.*intent' ;; |
---|
381 | full) search_str='real' |
---|
382 | esac |
---|
383 | 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'` |
---|
384 | var_2D_inout=`grep -i "$search_str" input | grep intent.*inout | grep $klon | grep $klev | cut -d: -f3 | sed -e 's/!.*$//' -e 's/,/ /g'` |
---|
385 | 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'` |
---|
386 | 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'` |
---|
387 | var_1D=`grep -i "$search_str" input | grep $klon | sed -e 's/!.*$//' -e /$klev/d | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
388 | var_2D=`grep -i "$search_str" input | grep $klon | grep $klev | cut -d: -f3 | sed -e 's/!.*$//' -e 's/,/ /g'` |
---|
389 | if [ "$ncvars" != "" ] ; then |
---|
390 | var_1D=`b_among_a "$var_1D" "$ncvars"` |
---|
391 | var_2D=`b_among_a "$var_2D" "$ncvars"` |
---|
392 | fi |
---|
393 | echo Variables in and inout : $varin0 |
---|
394 | echo 1D variables "(all)" : $var_1D |
---|
395 | echo 2D variables "(all)" : $var_2D |
---|
396 | echo 1D variables "intent(inout)" : $var_1D_inout |
---|
397 | echo 2D variables "intent(inout)" : $var_2D_inout |
---|
398 | echo local 1D variables : $var_1D_noarg |
---|
399 | echo local 2D variables : $var_2D_noarg |
---|
400 | |
---|
401 | #----------------------------------------------------------------------------- |
---|
402 | # Ecriture de la routine d'appel a la parametrisation en mode replay |
---|
403 | #----------------------------------------------------------------------------- |
---|
404 | |
---|
405 | if [ $nconly = false ] ; then |
---|
406 | |
---|
407 | cat > call_param_replay.F90 <<eod |
---|
408 | subroutine call_param_replay($klon,$klev) |
---|
409 | USE IOIPSL, ONLY : getin |
---|
410 | `echo_use_module $param $paramfile` |
---|
411 | IMPLICIT NONE |
---|
412 | integer :: ifin,irec,it,rec_length_replay=0,replay_irec0=1,replay_nt=1000 |
---|
413 | eod |
---|
414 | grep 'intent.*::' input | sed -e 's/ //g' -e 's/,intent(.*[nt])//'>> call_param_replay.F90 |
---|
415 | # duplicating declaration for inout variables |
---|
416 | |
---|
417 | for var in $varinout0 ; do |
---|
418 | 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 |
---|
419 | done |
---|
420 | # Initalisation, shared with dump_param1.sh |
---|
421 | dump_param_open "in" $varin0 >> call_param_replay.F90 |
---|
422 | for var in $varinout0 ; do |
---|
423 | 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 |
---|
424 | done |
---|
425 | |
---|
426 | cat >> call_param_replay.F90 <<eod |
---|
427 | call getin('replay_nt',replay_nt) |
---|
428 | call getin('replay_irec0',replay_irec0) |
---|
429 | do it=1,replay_nt |
---|
430 | if (replay_irec0>=0) then |
---|
431 | irec=replay_irec0+it-1 |
---|
432 | else |
---|
433 | irec=-replay_irec0 |
---|
434 | endif |
---|
435 | print*,'Time step',it,', reading record',irec,'in dump_param.bin' |
---|
436 | read(82,rec=irec,iostat=ifin) $varin |
---|
437 | if (.NOT. ifin == 0 ) stop "Fin du fichier fort.82" |
---|
438 | eod |
---|
439 | |
---|
440 | block_Replay0 "it == 1" _Replay0 "" $varinout0 >> call_param_replay.F90 |
---|
441 | block_Replay0 "replay_irec0 < 0" "" _Replay0 $varinout0 >> call_param_replay.F90 |
---|
442 | get_subroutine_arg $param $paramfile | sed -e 's/subroutine/ call/' >> call_param_replay.F90 |
---|
443 | block_Replay0 "replay_irec0 < 0" _Replay0 "" $varinout0 >> call_param_replay.F90 |
---|
444 | cat >> call_param_replay.F90 <<eod |
---|
445 | enddo |
---|
446 | return |
---|
447 | end |
---|
448 | eod |
---|
449 | |
---|
450 | fi # nconly = false |
---|
451 | |
---|
452 | #----------------------------------------------------------------------------- |
---|
453 | # Creating file dump_${param}_head.h |
---|
454 | #----------------------------------------------------------------------------- |
---|
455 | |
---|
456 | if [ $nconly = false ] ; then |
---|
457 | \rm $paraminc1 |
---|
458 | cat> $paraminc1 <<eod |
---|
459 | logical, save :: first_replay=.true. |
---|
460 | integer, save :: rec_length_replay=0,irec=0,gr_index_=-1 |
---|
461 | !\$OMP THREADPRIVATE(first_replay,rec_length_replay,irec,gr_index_) |
---|
462 | integer, external :: grid_index |
---|
463 | eod |
---|
464 | if [ "$lonlat" != "" ] ; then echo "if (first_replay) gr_index_=grid_index($lonlat)" >> $paraminc1 ; fi |
---|
465 | echo "if ($klon==1) gr_index_=1" >> $paraminc1 |
---|
466 | echo "if (abs(gr_index_)>0) then" >> $paraminc1 |
---|
467 | echo "if (first_replay) then" >> $paraminc1 |
---|
468 | dump_param_open out $varin0 >> $paraminc1 |
---|
469 | cat>> $paraminc1 <<eod |
---|
470 | endif |
---|
471 | irec=irec+1 |
---|
472 | write(81,rec=irec) $( echo $varin | sed -e "s/,$klon/,1/" ) |
---|
473 | endif |
---|
474 | first_replay=.false. |
---|
475 | eod |
---|
476 | |
---|
477 | iotd_calls 1 in_${prefix} $var_1D_inout |
---|
478 | iotd_calls 1 in_${prefix} $var_1D_inout >> $paraminc1 |
---|
479 | iotd_calls $klev in_${prefix} $var_2D_inout >> $paraminc1 |
---|
480 | fi # nconly = false |
---|
481 | if [ "`grep $paraminc1 $paramfile`" = "" ] ; then |
---|
482 | # Not changing $paraminc1 if it is already included in the file |
---|
483 | # To allow adding new nc outputs in a routine equiped for replay |
---|
484 | for var in $var_1D_noarg $var_2D_noarg ; do echo $var=0. >> $paraminc1 ; done |
---|
485 | include_line "include \"$paraminc1\"" $param $paramfile -after_declarations |
---|
486 | fi |
---|
487 | |
---|
488 | #----------------------------------------------------------------------------- |
---|
489 | # Creating file dump_${param}_nc_${prefix}.h |
---|
490 | #----------------------------------------------------------------------------- |
---|
491 | |
---|
492 | \rm $paraminc2 |
---|
493 | iotd_calls 1 "${prefix}" $var_1D >> $paraminc2 |
---|
494 | iotd_calls $klev "${prefix}" $var_2D >> $paraminc2 |
---|
495 | include_line "include \"$paraminc2\"" $param $paramfile "$where" |
---|
496 | |
---|
497 | if [[ "$lonlat" != "" ]] ; then |
---|
498 | for file in $paraminc1 $paraminc2 ; do sed -i -e "s/1:$klon/gr_index_/g" -e '/rec_l/s/\*('$klon')//g' $file ; done |
---|
499 | fi |
---|
500 | |
---|
501 | #---------------------------------------------------------------------------- |
---|
502 | # dump_ini_module gere l'ecriture des variables d'interface de l'intialisation |
---|
503 | # du module en mode replay |
---|
504 | #----------------------------------------------------------------------------- |
---|
505 | |
---|
506 | if [ $nconly = false -a $param_ini != None ] ; then |
---|
507 | varinmod=`grep -i 'intent.in' $inimod.F90 | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
508 | varinmodv=`echo $varinmod | sed -e 's/ /,/g'` |
---|
509 | cat > $iniinc <<...eod............................................... |
---|
510 | open(90,file='$inimod.bin',form='unformatted') |
---|
511 | write(90) $varinmodv |
---|
512 | close(90) |
---|
513 | ...eod............................................... |
---|
514 | for var_ in $varinmod ; do echo "print*,'Interface $param_ini $var_',$var_" >> $iniinc ; done |
---|
515 | include_line "include \"$iniinc\"" $param_ini $inimod.F90 -before_return |
---|
516 | fi # nconly = false |
---|
517 | |
---|
518 | #----------------------------------------------------------------------------- |
---|
519 | # call_ini_replay.F90 gere l'initialisation du module en mode replay |
---|
520 | #----------------------------------------------------------------------------- |
---|
521 | if [ $nconly = false -a $param_ini != None ] ; then |
---|
522 | cat > call_ini_replay.F90 <<....eod............................................ |
---|
523 | subroutine call_ini_replay |
---|
524 | use $inimod |
---|
525 | IMPLICIT NONE |
---|
526 | ....eod............................................ |
---|
527 | grep -i intent.in $inimod.F90 | tr '[A-Z]' '[a-z]' | sed -e 's/,.*intent.i.*)//' >> call_ini_replay.F90 |
---|
528 | cat >> call_ini_replay.F90 <<....eod........................................... |
---|
529 | open(90,file='$inimod.bin',form='unformatted') |
---|
530 | read(90) $varinmodv |
---|
531 | close(90) |
---|
532 | ....eod........................................... |
---|
533 | #get_subroutine_arg $param_ini $inimod.F90 ; exit |
---|
534 | get_subroutine_arg $param_ini $inimod.F90 | sed -e 's/subroutine/call/' >> call_ini_replay.F90 |
---|
535 | cat >> call_ini_replay.F90 <<....eod........................................... |
---|
536 | return |
---|
537 | end |
---|
538 | ....eod........................................... |
---|
539 | fi # nconly = false |
---|