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 | echo "if ( abs(gr_index_)>0 ) then" |
---|
317 | for var in $vars ; do |
---|
318 | local vardim=$( var_dims $var ) |
---|
319 | echo "call iotd_ecrit_seq('"$pre$var"',$klev_,'"$pre$var in $param"',' ',"$var$vardim")" |
---|
320 | done |
---|
321 | echo endif |
---|
322 | fi |
---|
323 | } |
---|
324 | |
---|
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 | } |
---|
338 | |
---|
339 | |
---|
340 | #----------------------------------------------------------------------------- |
---|
341 | # On nettoye les inclusions précédente dans les fichiers .F90 |
---|
342 | #----------------------------------------------------------------------------- |
---|
343 | |
---|
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 |
---|
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` |
---|
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 |
---|
356 | fi |
---|
357 | |
---|
358 | #----------------------------------------------------------------------------- |
---|
359 | # Analysis of the variables to be stored and there nature |
---|
360 | #----------------------------------------------------------------------------- |
---|
361 | |
---|
362 | extract_subroutine $param $paramfile # -> input file |
---|
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 | |
---|
373 | varin0=`grep inten.*.in input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
374 | varinout0=`grep inten.*.inout input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'` |
---|
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 |
---|
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 |
---|
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'` |
---|
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'` |
---|
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 |
---|
402 | |
---|
403 | #----------------------------------------------------------------------------- |
---|
404 | # Ecriture de la routine d'appel a la parametrisation en mode replay |
---|
405 | #----------------------------------------------------------------------------- |
---|
406 | |
---|
407 | if [ $nconly = false ] ; then |
---|
408 | |
---|
409 | cat > call_param_replay.F90 <<eod |
---|
410 | subroutine call_param_replay($klon,$klev) |
---|
411 | USE IOIPSL, ONLY : getin |
---|
412 | `echo_use_module $param $paramfile` |
---|
413 | IMPLICIT NONE |
---|
414 | integer :: ifin,irec,it,rec_length_replay=0,replay_irec0=1,replay_nt=1000 |
---|
415 | eod |
---|
416 | grep 'intent.*::' input | sed -e 's/ //g' -e 's/,intent(.*[nt])//'>> call_param_replay.F90 |
---|
417 | # duplicating declaration for inout variables |
---|
418 | |
---|
419 | for var in $varinout0 ; do |
---|
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 |
---|
421 | done |
---|
422 | # Initalisation, shared with dump_param1.sh |
---|
423 | dump_param_open "in" $varin0 >> call_param_replay.F90 |
---|
424 | for var in $varinout0 ; do |
---|
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 |
---|
426 | done |
---|
427 | |
---|
428 | cat >> call_param_replay.F90 <<eod |
---|
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 | |
---|
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 |
---|
447 | enddo |
---|
448 | return |
---|
449 | end |
---|
450 | eod |
---|
451 | |
---|
452 | fi # nconly = false |
---|
453 | |
---|
454 | #----------------------------------------------------------------------------- |
---|
455 | # Creating file dump_${param}_head.h |
---|
456 | #----------------------------------------------------------------------------- |
---|
457 | |
---|
458 | if [ $nconly = false ] ; then |
---|
459 | \rm $paraminc1 |
---|
460 | cat> $paraminc1 <<eod |
---|
461 | logical, save :: first_replay=.true. |
---|
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 |
---|
465 | eod |
---|
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 |
---|
470 | dump_param_open out $varin0 >> $paraminc1 |
---|
471 | cat>> $paraminc1 <<eod |
---|
472 | endif |
---|
473 | irec=irec+1 |
---|
474 | write(81,rec=irec) $varin |
---|
475 | endif |
---|
476 | first_replay=.false. |
---|
477 | eod |
---|
478 | |
---|
479 | iotd_calls 1 in_${prefix} $var_1D_inout |
---|
480 | iotd_calls 1 in_${prefix} $var_1D_inout >> $paraminc1 |
---|
481 | iotd_calls $klev in_${prefix} $var_2D_inout >> $paraminc1 |
---|
482 | fi # nconly = false |
---|
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 |
---|
489 | |
---|
490 | #----------------------------------------------------------------------------- |
---|
491 | # Creating file dump_${param}_nc_${prefix}.h |
---|
492 | #----------------------------------------------------------------------------- |
---|
493 | |
---|
494 | \rm $paraminc2 |
---|
495 | iotd_calls 1 "${prefix}" $var_1D >> $paraminc2 |
---|
496 | iotd_calls $klev "${prefix}" $var_2D >> $paraminc2 |
---|
497 | include_line "include \"$paraminc2\"" $param $paramfile "$where" |
---|
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 |
---|
501 | sed -i -e "/(81/s/,$klon/,1/" $paraminc1 |
---|
502 | fi |
---|
503 | |
---|
504 | #---------------------------------------------------------------------------- |
---|
505 | # dump_ini_module gere l'ecriture des variables d'interface de l'intialisation |
---|
506 | # du module en mode replay |
---|
507 | #----------------------------------------------------------------------------- |
---|
508 | |
---|
509 | if [ $nconly = false -a $param_ini != None ] ; then |
---|
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............................................... |
---|
517 | for var_ in $varinmod ; do echo "print*,'Interface $param_ini $var_',$var_" >> $iniinc ; done |
---|
518 | include_line "include \"$iniinc\"" $param_ini $inimod.F90 -before_return |
---|
519 | fi # nconly = false |
---|
520 | |
---|
521 | #----------------------------------------------------------------------------- |
---|
522 | # call_ini_replay.F90 gere l'initialisation du module en mode replay |
---|
523 | #----------------------------------------------------------------------------- |
---|
524 | if [ $nconly = false -a $param_ini != None ] ; then |
---|
525 | cat > call_ini_replay.F90 <<....eod............................................ |
---|
526 | subroutine call_ini_replay |
---|
527 | use $inimod |
---|
528 | IMPLICIT NONE |
---|
529 | ....eod............................................ |
---|
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........................................... |
---|
532 | open(90,file='$inimod.bin',form='unformatted') |
---|
533 | read(90) $varinmodv |
---|
534 | close(90) |
---|
535 | ....eod........................................... |
---|
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 |
---|
538 | cat >> call_ini_replay.F90 <<....eod........................................... |
---|
539 | return |
---|
540 | end |
---|
541 | ....eod........................................... |
---|
542 | fi # nconly = false |
---|