source: BOL/Replay/replay_equip.sh @ 5861

Last change on this file since 5861 was 5861, checked in by fhourdin, 3 weeks ago

F90 vs f90

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