source: BOL/Replay/replay_equip.sh @ 5875

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

bug fix

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