Changeset 5033 for BOL/Replay


Ignore:
Timestamp:
Jul 9, 2024, 1:42:07 PM (6 months ago)
Author:
fhourdin
Message:

Extraction 1D depuis le 3D

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BOL/Replay/replay_equip.sh

    r4681 r5033  
    11#!/bin/bash
    22
    3 #set -vx
     3   #set -vx
    44
    55#=============================================================================
     
    7979nconly=false
    8080where=-before_return
     81lonlat=
    8182
    8283if [ $# = 0 ] ; then $0 -h ; exit ; fi
     
    8586   case $1 in
    8687     -h|--help) cat <<........fin
    87            $0 [-nconly] [-ncvars var1,var2,...] [-pre prefix] [location_in_the_code] routine_name
     88           $0 [-nconly] [-ncvars var1,var2,...] [-pre prefix] [location_in_the_code] [-lonlat lon,lat] routine_name
    8889           The prefix will be put on each variable stored in the nc file to avoid duplicate
    8990                variables names
     
    9192           The prefix is used to prevent having twice the same name if the same variable is
    9293              output at two locations in the code.
     94           The -nconly option can be used to equip other routines with nc output only
    9395           location_in_the_code can be : -before_return               (the default valuer)
    9496                                         -after_declarations
     
    9799                                         -before_call  "param_name"   (TO BE DONE)
    98100                                         -after_call   "param_name"   (TO BE DONE)
     101           -lonlat longitude,latitude
    99102........fin
    100103        exit ;;
     
    104107     -pre) prefix=$2 ; shift ; shift ;;
    105108     -ncvars) ncvars="`echo $2 | sed -e 's/,/ /g'`" ; shift ; shift ;;
     109     -lonlat) lonlat=$2 ; shift ; shift ;;
    106110     *) if (( $# > 1 )) ; then $0 -h ; exit ; fi ; param=`basename $1 .F90` ; shift
    107111    esac
     
    113117   thermcell_main|thermcell_plume_6A|thermcell_env|thermcell_height|thermcell_dry|\
    114118      thermcell_closure|thermcell_height|thermcell_dq|thermcell_flux2|thermcell_down| \
    115       thermcell_updown_dq) \
     119      thermcell_updown_dq|thermcell_dtke) \
    116120      param_ini=thermcell_ini ; inimod=lmdz_thermcell_ini ; klon=ngrid ; klev=nlay ;;
    117    wake|wake_popdyn_1|wake_popdyn_2|vdif_kcay|ustarhb) param_ini=wake_ini ; inimod=lmdz_wake_ini ; klon=klon ; klev=klev ;;
     121   wake|pkupper|wake_popdyn_1|wake_popdyn_2|vdif_kcay|ustarhb) param_ini=wake_ini ; inimod=lmdz_wake_ini ; klon=klon ; klev=klev ;;
    118122   ratqs_main|ratqs_inter|ratqs_oro|ratqs_hetero|ratqs_tke) param_ini=ratqs_ini ; inimod=lmdz_ratqs_ini ; klon=klon ; klev=klev ;;
    119123   lscp|fisrtilp) param_ini=lscp_ini ; inimod=lmdz_lscp_ini ; klon=klon ; klev=klev ;;
     
    141145   line2=`tail -n +$line1 ${tmp} | sed -n -e '/)/=' | head -1`
    142146   tail -n +$line1 ${tmp} | sed -n -e 1,${line2}p
     147}
     148
     149#-----------------------------------------------------------------------------
     150function 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#-----------------------------------------------------------------------------
     160function 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#-----------------------------------------------------------------------------
     178function 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
    143188}
    144189
     
    156201    esac
    157202    echo '! <<< dump_param_open'
    158     for var in $* ; do echo 'rec_length_replay=rec_length_replay+kind('$var')*size(['$var'])' ; done
     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
    159208    cat <<....eod
    160209    open(${fort},file='dump_param_${inout}.bin',form='unformatted',access='direct',recl=rec_length_replay)  ! $replay_comment
     
    266315       vars=$*
    267316       for var in $vars ; do
    268           echo "call iotd_ecrit_seq('"$pre$var"',$klev_,'"$pre$var in $param"',' ',"$var")"
     317          local vardim=$( var_dims $var )
     318          echo "call iotd_ecrit_seq('"$pre$var"',$klev_,'"$pre$var in $param"',' ',"$var$vardim")"
    269319       done
    270320    fi
     
    296346   #line=`sed -n -e "/CALL "$param_ini"/=" physiq_mod.F90 | head -1`
    297347   line=`sed -n -e "/CALL wake_ini/=" physiq_mod.F90 | head -1`
    298    sed -i"" -e "${line}s/^/   CALL iophys_ini(pdtphys) ! $replay_comment  ! $replay_comment\n/" physiq_mod.F90
     348   if [[ "$lonlat" = "" ]] ; then
     349        pattern="CALL iophys_ini(pdtphys)"
     350   else
     351        pattern='call iotd_ini("phys.nc",1,1,klev,'$lonlat',presnivs,1,1,1,0.,pdtphys,calend)'
     352   fi
     353   sed -i"" -e "${line}s/^/   $pattern ! $replay_comment  ! $replay_comment\n/" physiq_mod.F90
    299354fi
    300355
     
    304359
    305360extract_subroutine $param $paramfile # -> input file
     361#var_get_dims ztv
     362#var_dims ztv
     363#exit
     364# var_recl ztv
     365# var_dims pplev
     366# var_recl pplev
     367# var_dims ngrid
     368# var_recl ngrid
     369# exit
     370
    306371varin0=`grep inten.*.in input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'`
    307372varinout0=`grep inten.*.inout input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'`
    308 varin=`echo $varin0 | sed -e 's/ /,/g' -e "s/,,,/,/g" -e "s/,,/,/g"`
     373echo varin0 $varin0
     374varin_rec= ; for v in $varin0 ; do varin_rec="$varin_rec $v$( var_dims $v)" ; done
     375varin=`echo $varin_rec | sed -e 's/ /,/g' -e "s/,,,/,/g" -e "s/,,/,/g"`
     376#echo $varin $varin
    309377output=full # Attention, l'option full ne marche pas a cause de tableaux locaux undef
    310378nvar0D=0 ; nvar1D=0 ; nvar2D=0
     
    390458cat> $paraminc1 <<eod
    391459logical, save :: first_replay=.true.
    392 integer, save :: rec_length_replay=0,irec=0
    393 if (first_replay) then
     460integer, save :: rec_length_replay=0,irec=0,gr_index_=-1
     461!\$OMP THREADPRIVATE(first_replay,rec_length_replay,irec,gr_index_)
     462integer, external :: grid_index
    394463eod
     464if [ "$lonlat" != "" ] ; then echo "if (first_replay) gr_index_=grid_index($lonlat)" >> $paraminc1 ; fi
     465echo "if ($klon==1) gr_index_=1" >> $paraminc1
     466echo "if (abs(gr_index_)>0) then" >> $paraminc1
     467echo "if (first_replay) then" >> $paraminc1
    395468dump_param_open out $varin0 >> $paraminc1
    396469cat>> $paraminc1 <<eod
    397 first_replay=.false.
    398470endif
    399471irec=irec+1
    400 write(81,rec=irec) $varin
     472write(81,rec=irec) $( echo $varin | sed -e "s/,$klon/,1/" )
     473endif
     474first_replay=.false.
    401475eod
     476
     477iotd_calls 1     in_${prefix} $var_1D_inout
    402478iotd_calls 1     in_${prefix} $var_1D_inout >> $paraminc1
    403479iotd_calls $klev in_${prefix} $var_2D_inout >> $paraminc1
    404480fi # nconly = false
    405 
    406481if [ "`grep $paraminc1 $paramfile`" = "" ] ; then
    407482   # Not changing $paraminc1 if it is already included in the file
     
    419494iotd_calls $klev "${prefix}" $var_2D >> $paraminc2
    420495include_line "include \"$paraminc2\"" $param $paramfile "$where"
     496
     497if [[ "$lonlat" != "" ]] ; then
     498    for file in $paraminc1 $paraminc2 ; do sed -i -e "s/1:$klon/gr_index_/g" -e '/rec_l/s/\*('$klon')//g'  $file ; done
     499fi
    421500 
    422 #-----------------------------------------------------------------------------
     501#----------------------------------------------------------------------------
    423502# dump_ini_module gere l'ecriture des variables d'interface de l'intialisation
    424503# du module en mode replay
Note: See TracChangeset for help on using the changeset viewer.