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