Index: BOL/Replay/replay_equip.sh
===================================================================
--- BOL/Replay/replay_equip.sh	(revision 4681)
+++ BOL/Replay/replay_equip.sh	(revision 5033)
@@ -1,5 +1,5 @@
 #!/bin/bash
 
-#set -vx
+   #set -vx
 
 #=============================================================================
@@ -79,4 +79,5 @@
 nconly=false
 where=-before_return
+lonlat=
 
 if [ $# = 0 ] ; then $0 -h ; exit ; fi
@@ -85,5 +86,5 @@
    case $1 in
      -h|--help) cat <<........fin
-           $0 [-nconly] [-ncvars var1,var2,...] [-pre prefix] [location_in_the_code] routine_name
+           $0 [-nconly] [-ncvars var1,var2,...] [-pre prefix] [location_in_the_code] [-lonlat lon,lat] routine_name
            The prefix will be put on each variable stored in the nc file to avoid duplicate
                 variables names
@@ -91,4 +92,5 @@
            The prefix is used to prevent having twice the same name if the same variable is
               output at two locations in the code.
+           The -nconly option can be used to equip other routines with nc output only
            location_in_the_code can be : -before_return               (the default valuer)
                                          -after_declarations
@@ -97,4 +99,5 @@
                                          -before_call  "param_name"   (TO BE DONE)
                                          -after_call   "param_name"   (TO BE DONE)
+           -lonlat longitude,latitude
 ........fin
         exit ;;
@@ -104,4 +107,5 @@
      -pre) prefix=$2 ; shift ; shift ;;
      -ncvars) ncvars="`echo $2 | sed -e 's/,/ /g'`" ; shift ; shift ;;
+     -lonlat) lonlat=$2 ; shift ; shift ;;
      *) if (( $# > 1 )) ; then $0 -h ; exit ; fi ; param=`basename $1 .F90` ; shift
     esac
@@ -113,7 +117,7 @@
    thermcell_main|thermcell_plume_6A|thermcell_env|thermcell_height|thermcell_dry|\
       thermcell_closure|thermcell_height|thermcell_dq|thermcell_flux2|thermcell_down| \
-      thermcell_updown_dq) \
+      thermcell_updown_dq|thermcell_dtke) \
       param_ini=thermcell_ini ; inimod=lmdz_thermcell_ini ; klon=ngrid ; klev=nlay ;;
-   wake|wake_popdyn_1|wake_popdyn_2|vdif_kcay|ustarhb) param_ini=wake_ini ; inimod=lmdz_wake_ini ; klon=klon ; klev=klev ;;
+   wake|pkupper|wake_popdyn_1|wake_popdyn_2|vdif_kcay|ustarhb) param_ini=wake_ini ; inimod=lmdz_wake_ini ; klon=klon ; klev=klev ;;
    ratqs_main|ratqs_inter|ratqs_oro|ratqs_hetero|ratqs_tke) param_ini=ratqs_ini ; inimod=lmdz_ratqs_ini ; klon=klon ; klev=klev ;;
    lscp|fisrtilp) param_ini=lscp_ini ; inimod=lmdz_lscp_ini ; klon=klon ; klev=klev ;;
@@ -141,4 +145,45 @@
    line2=`tail -n +$line1 ${tmp} | sed -n -e '/)/=' | head -1`
    tail -n +$line1 ${tmp} | sed -n -e 1,${line2}p
+}
+
+#-----------------------------------------------------------------------------
+function var_get_dims(){
+#-----------------------------------------------------------------------------
+    local var=$1
+    local line=$( grep dimension input | grep '::.*'$var | grep -w $var | sed -e 's/ //g' )
+    local pattern='dimension\s*\(([a-z0-9,+]*)\)'
+    if [[ $line =~ $pattern ]] ; then
+        echo ${BASH_REMATCH[1]} | sed -e 's/,/ /g'
+    fi
+}
+#-----------------------------------------------------------------------------
+function var_dims(){
+#-----------------------------------------------------------------------------
+    local var=$1
+    local dims=$(var_get_dims $var)
+    if [[ "$dims" != "" ]] ; then
+       local dims_=
+       for d in $dims ; do
+           if [[ $d = $klon ]] ; then
+              dims_="${dims_} 1:$klon"
+           else
+              dims_="$dims_ :"
+           fi
+       done
+       echo \(${dims_}\) | sed -e 's/( /(/' -e 's/ /,/g'
+    fi
+    
+}
+#-----------------------------------------------------------------------------
+function var_recl(){
+#-----------------------------------------------------------------------------
+    local var=$1
+    local dims=$( var_get_dims $var )
+    if [[ "$dims" != "" ]] ; then
+       local dims_= ; for i in $dims ; do dims_="$dims_ ($i)" ; done
+       echo $dims_ | sed -e 's/ /*/'
+    else
+       echo 1
+    fi
 }
 
@@ -156,5 +201,9 @@
     esac
     echo '! <<< dump_param_open'
-    for var in $* ; do echo 'rec_length_replay=rec_length_replay+kind('$var')*size(['$var'])' ; done
+    echo 'print*,"NOUVEAU REPLAY"'
+    for var in $* ; do
+        #echo 'rec_length_replay=rec_length_replay+kind('$var')*size(['$var'])'
+        echo 'rec_length_replay=rec_length_replay+kind('$var')*'$( var_recl $var )
+    done
     cat <<....eod
     open(${fort},file='dump_param_${inout}.bin',form='unformatted',access='direct',recl=rec_length_replay)  ! $replay_comment
@@ -266,5 +315,6 @@
        vars=$*
        for var in $vars ; do
-          echo "call iotd_ecrit_seq('"$pre$var"',$klev_,'"$pre$var in $param"',' ',"$var")"
+          local vardim=$( var_dims $var )
+          echo "call iotd_ecrit_seq('"$pre$var"',$klev_,'"$pre$var in $param"',' ',"$var$vardim")"
        done
     fi
@@ -296,5 +346,10 @@
    #line=`sed -n -e "/CALL "$param_ini"/=" physiq_mod.F90 | head -1`
    line=`sed -n -e "/CALL wake_ini/=" physiq_mod.F90 | head -1`
-   sed -i"" -e "${line}s/^/   CALL iophys_ini(pdtphys) ! $replay_comment  ! $replay_comment\n/" physiq_mod.F90
+   if [[ "$lonlat" = "" ]] ; then
+        pattern="CALL iophys_ini(pdtphys)"
+   else
+        pattern='call iotd_ini("phys.nc",1,1,klev,'$lonlat',presnivs,1,1,1,0.,pdtphys,calend)'
+   fi
+   sed -i"" -e "${line}s/^/   $pattern ! $replay_comment  ! $replay_comment\n/" physiq_mod.F90
 fi
 
@@ -304,7 +359,20 @@
 
 extract_subroutine $param $paramfile # -> input file
+#var_get_dims ztv
+#var_dims ztv
+#exit
+# var_recl ztv
+# var_dims pplev
+# var_recl pplev
+# var_dims ngrid
+# var_recl ngrid
+# exit
+
 varin0=`grep inten.*.in input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'`
 varinout0=`grep inten.*.inout input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'`
-varin=`echo $varin0 | sed -e 's/ /,/g' -e "s/,,,/,/g" -e "s/,,/,/g"`
+echo varin0 $varin0
+varin_rec= ; for v in $varin0 ; do varin_rec="$varin_rec $v$( var_dims $v)" ; done
+varin=`echo $varin_rec | sed -e 's/ /,/g' -e "s/,,,/,/g" -e "s/,,/,/g"`
+#echo $varin $varin
 output=full # Attention, l'option full ne marche pas a cause de tableaux locaux undef
 nvar0D=0 ; nvar1D=0 ; nvar2D=0
@@ -390,18 +458,25 @@
 cat> $paraminc1 <<eod
 logical, save :: first_replay=.true.
-integer, save :: rec_length_replay=0,irec=0
-if (first_replay) then
+integer, save :: rec_length_replay=0,irec=0,gr_index_=-1
+!\$OMP THREADPRIVATE(first_replay,rec_length_replay,irec,gr_index_)
+integer, external :: grid_index
 eod
+if [ "$lonlat" != "" ] ; then echo "if (first_replay) gr_index_=grid_index($lonlat)" >> $paraminc1 ; fi
+echo "if ($klon==1) gr_index_=1" >> $paraminc1
+echo "if (abs(gr_index_)>0) then" >> $paraminc1
+echo "if (first_replay) then" >> $paraminc1
 dump_param_open out $varin0 >> $paraminc1
 cat>> $paraminc1 <<eod
-first_replay=.false.
 endif
 irec=irec+1
-write(81,rec=irec) $varin
+write(81,rec=irec) $( echo $varin | sed -e "s/,$klon/,1/" )
+endif
+first_replay=.false.
 eod
+
+iotd_calls 1     in_${prefix} $var_1D_inout
 iotd_calls 1     in_${prefix} $var_1D_inout >> $paraminc1
 iotd_calls $klev in_${prefix} $var_2D_inout >> $paraminc1
 fi # nconly = false
-
 if [ "`grep $paraminc1 $paramfile`" = "" ] ; then
    # Not changing $paraminc1 if it is already included in the file
@@ -419,6 +494,10 @@
 iotd_calls $klev "${prefix}" $var_2D >> $paraminc2
 include_line "include \"$paraminc2\"" $param $paramfile "$where"
+
+if [[ "$lonlat" != "" ]] ; then
+    for file in $paraminc1 $paraminc2 ; do sed -i -e "s/1:$klon/gr_index_/g" -e '/rec_l/s/\*('$klon')//g'  $file ; done
+fi
   
-#-----------------------------------------------------------------------------
+#----------------------------------------------------------------------------
 # dump_ini_module gere l'ecriture des variables d'interface de l'intialisation
 # du module en mode replay
