Ignore:
Timestamp:
Jan 21, 2026, 2:58:05 AM (4 days ago)
Author:
fhourdin
Message:

New version of replay.

Allowing to change input variables by modifying
phys.nc created by lmdz1d into replay_in.nc
Can be used to replace SCM values by LES.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BOL/Replay/replay_equip.sh

    r5863 r6040  
    11#!/bin/bash
    22
    3    #set -vx
     3#set -vx
    44
    55#=============================================================================
     
    7474#=============================================================================
    7575
    76 #-----------------------------------------------------------------------------
    77 # Reading rguments
    78 #-----------------------------------------------------------------------------
    7976nconly=false
    8077where=-before_return
     
    113110if [ "$param" = "" ] ; then $0 -h ; exit ; fi
    114111
     112#-----------------------------------------------------------------------------
     113function get_file_names {
     114#-----------------------------------------------------------------------------
    115115case $param in
    116116   vdif_k|vdif_cd|vdif|my_25|vdif_dq) param_ini=vdif_ini ; inimod=simple_vdif_ini ; klon=ngrid ; klev=nlay ;;
     
    128128set -u ; inimod_file=$( ls $inimod.[fF]90 ) ; set +u
    129129replay_comment="replay automatic include"
    130 paraminc1=dump_replay_${param}_head.h
    131 paraminc2=dump_replay_${param}_nc_${prefix}.h
     130dump_param_head=dump_replay_${param}_head.h
     131dump_param_nc=dump_replay_${param}_nc_${prefix}.h
    132132iniinc=dump_replay_ini.h
    133133echo "grep -i \"subro.* ${param}[\ (]\" *.[fF]90 | sed -e 's/ //g' | grep \"${param}(\" | cut -d: -f1"
     
    138138if [ `echo ${paramfile} | wc -w` != 1 ] ; then echo file $paramfile multiple  ; $0 -h ; exit ; fi
    139139
    140 
    141 #-----------------------------------------------------------------------------
    142 # Transformer l'entete d'une subroutine en un call
    143 #-----------------------------------------------------------------------------
    144 
     140}
     141
     142#-----------------------------------------------------------------------------
    145143function get_subroutine_arg(){
     144#-----------------------------------------------------------------------------
    146145   tmp=tmp_get_subroutine_arg$1
    147146   cat $2 | tr '[A-Z]' '[a-z]' > ${tmp}
     
    164163    fi
    165164}
     165
    166166#-----------------------------------------------------------------------------
    167167function var_dims(){
     
    180180       echo \(${dims_}\) | sed -e 's/( /(/' -e 's/ /,/g'
    181181    fi
    182    
    183 }
     182}
     183
    184184#-----------------------------------------------------------------------------
    185185function var_recl(){
     
    219219}
    220220
    221 
    222221#-----------------------------------------------------------------------------
    223222function extract_subroutine(){
     
    235234   \rm -f ${tmp} ${tmp}2
    236235}
    237 
    238236
    239237#-----------------------------------------------------------------------------
     
    297295}
    298296
    299 
    300 
    301 
    302297#-----------------------------------------------------------------------------
    303298function block_Replay0() {
     
    344339}
    345340
    346 
     341#-----------------------------------------------------------------------------
     342function get_all_inout_and_in_variables {
     343#-----------------------------------------------------------------------------
     344
     345varin0=`grep inten.*.in input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'`
     346varinout0=`grep inten.*.inout input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'`
     347echo varin0 $varin0
     348varin_rec= ; for v in $varin0 ; do varin_rec="$varin_rec $v$( var_dims $v)" ; done
     349varin=`echo $varin_rec | sed -e 's/ /,/g' -e "s/,,,/,/g" -e "s/,,/,/g"`
     350#echo $varin $varin
     351nvar0D=0 ; nvar1D=0 ; nvar2D=0
     352}
     353
     354#-----------------------------------------------------------------------------
     355function get_vars {
     356#-----------------------------------------------------------------------------
     357
     358# Extracting list of array variables, either 1D or 2D, and depending
     359# on their status : in, out, inout
     360
     361output=full # Attention, l'option full ne marche pas a cause de tableaux locaux undef
     362case $output in
     363   light) str_='real.*intent' ;;
     364   full) str_='real'
     365esac
     366
     367str_=real
     368case $1 in
     369   in|inout|out) filtre_='grep intent('$1')' ;;
     370   local) filtre_='sed -e /intent/d' ;;
     371   all) filtre_='grep '$str_ ;; # Pas très joli
     372   *) echo Pffff ; exit 1
     373esac
     374
     375if [ $2 = 1D ] ; then
     376    grep $str_ input | sed -e 's/ //g' | $filtre_ | grep $klon | sed -e 's/!.*$//' -e /$klev/d | cut -d: -f3 | sed -e 's/,/ /g'
     377else
     378    grep $str_ input | sed -e 's/ //g' | $filtre_ | grep $klon | grep $klev | cut -d: -f3 | sed -e 's/!.*$//' -e 's/,/ /g'
     379fi
     380
     381}
     382
     383#-----------------------------------------------------------------------------
     384function get_variable_lists {
     385#-----------------------------------------------------------------------------
     386var_1D_in=$( get_vars in 1D )
     387var_2D_in=$( get_vars in 2D )
     388
     389var_1D_inout=$( get_vars inout 1D )
     390var_2D_inout=$( get_vars inout 2D )
     391
     392var_1D=$( get_vars all 1D )
     393var_2D=$( get_vars all 2D )
     394
     395var_1D_local=$( get_vars local 1D )
     396var_2D_local=$( get_vars local 2D )
     397
     398if [ "$ncvars" != "" ] ; then
     399   var_1D=$( b_among_a "$var_1D" "$ncvars" )
     400   var_2D=$( b_among_a "$var_2D" "$ncvars" )
     401fi
     402
     403echo Variables in and inout : $varin0
     404echo 1D variables "(all)" : $var_1D
     405echo 2D variables "(all)" : $var_2D
     406echo 1D variables "intent(in)" : $var_1D_in
     407echo 2D variables "intent(in)" : $var_2D_in
     408echo 1D variables "intent(inout)" : $var_1D_inout
     409echo 2D variables "intent(inout)" : $var_2D_inout
     410echo local 1D variables : $var_1D_local
     411echo local 2D variables : $var_2D_local
     412}
     413
     414#-----------------------------------------------------------------------------
     415function clean_other_routines {
    347416#-----------------------------------------------------------------------------
    348417# On nettoye les inclusions précédente dans les fichiers .f90
    349 #-----------------------------------------------------------------------------
    350 
    351418if [ $nconly = false ] ; then
    352419   for file in `grep "$replay_comment" *.[fF]90 2> /dev/null | cut -d: -f1` ; do
     
    368435   sed -i"" -e "${line}s/^/   $pattern ! $replay_comment  ! $replay_comment\n/" physiq_mod.F90
    369436fi
    370 
    371 #-----------------------------------------------------------------------------
    372 # Analysis of the variables to be stored and there nature
    373 #-----------------------------------------------------------------------------
    374 
    375 extract_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 
    386 varin0=`grep inten.*.in input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'`
    387 varinout0=`grep inten.*.inout input | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'`
    388 echo varin0 $varin0
    389 varin_rec= ; for v in $varin0 ; do varin_rec="$varin_rec $v$( var_dims $v)" ; done
    390 varin=`echo $varin_rec | sed -e 's/ /,/g' -e "s/,,,/,/g" -e "s/,,/,/g"`
    391 #echo $varin $varin
    392 output=full # Attention, l'option full ne marche pas a cause de tableaux locaux undef
    393 nvar0D=0 ; nvar1D=0 ; nvar2D=0
    394 case $output in
    395    light) search_str='real.*intent' ;;
    396    full) search_str='real'
    397 esac
    398 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'`
    399 var_2D_inout=`grep -i "$search_str" input | grep intent.*inout | grep $klon | grep $klev | cut -d: -f3 | sed -e 's/!.*$//' -e 's/,/ /g'`
    400 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'`
    401 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'`
    402 var_1D=`grep -i "$search_str" input | grep $klon | sed -e 's/!.*$//' -e /$klev/d | cut -d: -f3 | sed -e 's/,/ /g'`
    403 var_2D=`grep -i "$search_str" input | grep $klon | grep $klev | cut -d: -f3 | sed -e 's/!.*$//' -e 's/,/ /g'`
    404 if [ "$ncvars" != "" ] ; then
    405    var_1D=`b_among_a "$var_1D" "$ncvars"`
    406    var_2D=`b_among_a "$var_2D" "$ncvars"`
    407 fi
    408 echo Variables in and inout : $varin0
    409 echo 1D variables "(all)" : $var_1D
    410 echo 2D variables "(all)" : $var_2D
    411 echo 1D variables "intent(inout)" : $var_1D_inout
    412 echo 2D variables "intent(inout)" : $var_2D_inout
    413 echo local 1D variables : $var_1D_noarg
    414 echo local 2D variables : $var_2D_noarg
    415 
    416 #-----------------------------------------------------------------------------
    417 # Ecriture de la routine d'appel a la parametrisation en mode replay
    418 #-----------------------------------------------------------------------------
    419 
    420 if [ $nconly = false ] ; then
     437}
     438
     439
     440#-----------------------------------------------------------------------------
     441function create_call_param_replay {
     442#-----------------------------------------------------------------------------
    421443
    422444cat > call_param_replay.f90 <<eod
    423445subroutine call_param_replay($klon,$klev)
    424 USE IOIPSL, ONLY : getin
    425 `echo_use_module $param  $paramfile`
     446use IOIPSL, only : getin
     447use netcdf
     448$( echo_use_module $param  $paramfile )
    426449IMPLICIT NONE
    427450integer :: ifin,irec,it,rec_length_replay=0,replay_irec0=1,replay_nt=1000
     451integer :: status,ncid,varid
     452real*4,dimension($klon,$klev) :: v2d
     453real*4,dimension($klon) :: v1d
    428454eod
    429455grep 'intent.*::' input | sed -e 's/ //g' -e 's/,intent(.*[nt])//'>> call_param_replay.f90
     
    451477   read(82,rec=irec,iostat=ifin) $varin
    452478   if (.NOT. ifin == 0 ) stop "Fin du fichier fort.82"
     479   status = nf90_open("replay_in.nc", nf90_nowrite, ncid)
     480   if (status == nf90_noerr) then
    453481eod
     482
     483for var in $var_2D_in $var_2D_inout ; do
     484   echo "status=nf90_inq_varid(ncid,\"$var\",varid)" >> call_param_replay.f90
     485   echo "status=nf90_get_var(ncid,varid,v2d,start=(/1,1,1,it/), count=(/1,1,$klev,it/))" >> call_param_replay.f90
     486   echo "$var(:,1:$klev)=v2d(:,1:$klev)"  >> call_param_replay.f90
     487done
     488
     489for var in $var_1D_in $var_1D_inout ; do
     490   echo "status=nf90_inq_varid(ncid,\"$var\",varid)" >> call_param_replay.f90
     491   echo "status=nf90_get_var(ncid, varid, v1d, start=(/1,1,it/), count=(/1,1,it/))" >> call_param_replay.f90
     492   echo "$var=v1d"  >> call_param_replay.f90
     493done
    454494
    455495block_Replay0 "it == 1"          _Replay0   ""       $varinout0 >> call_param_replay.f90
     
    457497get_subroutine_arg $param $paramfile | sed -e 's/subroutine/   call/' >> call_param_replay.f90
    458498block_Replay0 "replay_irec0 < 0" _Replay0   ""       $varinout0 >> call_param_replay.f90
     499
    459500cat >> call_param_replay.f90 <<eod
     501   end if
    460502enddo
    461503return
    462504end subroutine call_param_replay
    463505eod
    464 
    465 fi # nconly = false
    466 
    467 #-----------------------------------------------------------------------------
    468 # Creating file dump_${param}_head.h
    469 #-----------------------------------------------------------------------------
    470 
    471 if [ $nconly = false ] ; then
    472 \rm $paraminc1
    473 cat> $paraminc1 <<eod
     506}
     507
     508#-----------------------------------------------------------------------------
     509function create_dump_param_head {
     510#-----------------------------------------------------------------------------
     511\rm $dump_param_head
     512cat> $dump_param_head <<eod
    474513logical, save :: first_replay=.true.
    475514integer, save :: rec_length_replay=0,irec=0,gr_index_=-1
     
    477516integer, external :: grid_index
    478517eod
    479 if [ "$lonlat" != "" ] ; then echo "if (first_replay) gr_index_=grid_index($lonlat)" >> $paraminc1 ; fi
    480 echo "if ($klon==1) gr_index_=1" >> $paraminc1
    481 echo "if (abs(gr_index_)>0) then" >> $paraminc1
    482 echo "if (first_replay) then" >> $paraminc1
    483 dump_param_open out $varin0 >> $paraminc1
    484 cat>> $paraminc1 <<eod
     518if [ "$lonlat" != "" ] ; then echo "if (first_replay) gr_index_=grid_index($lonlat)" >> $dump_param_head ; fi
     519echo "if ($klon==1) gr_index_=1" >> $dump_param_head
     520echo "if (abs(gr_index_)>0) then" >> $dump_param_head
     521echo "if (first_replay) then" >> $dump_param_head
     522dump_param_open out $varin0 >> $dump_param_head
     523cat>> $dump_param_head <<eod
    485524endif
    486525irec=irec+1
     
    490529eod
    491530
    492 iotd_calls 1     in_${prefix} $var_1D_inout
    493 iotd_calls 1     in_${prefix} $var_1D_inout >> $paraminc1
    494 iotd_calls $klev in_${prefix} $var_2D_inout >> $paraminc1
    495 fi # nconly = false
    496 if [ "`grep $paraminc1 $paramfile`" = "" ] ; then
    497    # Not changing $paraminc1 if it is already included in the file
     531#iotd_calls 1     in_${prefix} $var_1D_inout
     532iotd_calls 1     in_${prefix} $var_1D_inout >> $dump_param_head
     533iotd_calls $klev in_${prefix} $var_2D_inout >> $dump_param_head
     534if [ "`grep $dump_param_head $paramfile`" = "" ] ; then
     535   # Not changing $dump_param_head if it is already included in the file
    498536   # 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
    501 fi
    502 
    503 #-----------------------------------------------------------------------------
    504 # Creating file dump_${param}_nc_${prefix}.h
    505 #-----------------------------------------------------------------------------
    506 
    507 \rm $paraminc2
    508 iotd_calls 1     "${prefix}" $var_1D >> $paraminc2
    509 iotd_calls $klev "${prefix}" $var_2D >> $paraminc2
    510 include_line "include \"$paraminc2\"" $param $paramfile "$where"
     537   for var in $var_1D_local $var_2D_local ; do echo $var=0. >> $dump_param_head ; done
     538   include_line "include \"$dump_param_head\"" $param $paramfile -after_declarations
     539fi
     540}
     541
     542#-----------------------------------------------------------------------------
     543function create_dump_param_nc {
     544#-----------------------------------------------------------------------------
     545
     546\rm $dump_param_nc
     547iotd_calls 1     "${prefix}" $var_1D >> $dump_param_nc
     548iotd_calls $klev "${prefix}" $var_2D >> $dump_param_nc
     549include_line "include \"$dump_param_nc\"" $param $paramfile "$where"
    511550
    512551if [[ "$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
    515 fi
    516  
    517 #----------------------------------------------------------------------------
    518 # dump_ini_module gere l'ecriture des variables d'interface de l'intialisation
    519 # du module en mode replay
    520 #-----------------------------------------------------------------------------
    521 
    522 if [ $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...............................................
     552    for file in $dump_param_head $dump_param_nc ; do sed -i -e "s/1:$klon/gr_index_/g" -e '/rec_l/s/\*('$klon')//g'  $file ; done
     553    sed -i -e "/(81/s/,$klon/,1/" $dump_param_head
     554fi
     555
     556}
     557
     558#-----------------------------------------------------------------------------
     559function create_call_ini_replay {
     560#-----------------------------------------------------------------------------
     561varinmod=`grep -i 'intent.in' $inimod_file | sed -e 's/\!.*$//' | cut -d: -f3 | sed -e 's/,/ /g'`
     562varinmodv=`echo $varinmod | sed -e 's/ /,/g'`
     563cat > $iniinc <<eod...............................................
    526564   open(90,file='$inimod.bin',form='unformatted')
    527565   write(90) $varinmodv
    528566   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
    532 fi # nconly = false
    533 
    534 #-----------------------------------------------------------------------------
    535 # call_ini_replay.f90 gere l'initialisation du module en mode replay
    536 #-----------------------------------------------------------------------------
    537 if [ $nconly = false -a $param_ini != None ] ; then
    538     cat > call_ini_replay.f90 <<....eod............................................
     567eod...............................................
     568for var_ in $varinmod ; do echo "print*,'Interface $param_ini $var_',$var_" >> $iniinc ; done
     569include_line "include \"$iniinc\"" $param_ini $inimod_file  -before_return
     570
     571cat > call_ini_replay.f90 <<eod............................................
    539572    subroutine call_ini_replay
    540573    use $inimod
    541574    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...........................................
     575eod............................................
     576grep -i intent.in $inimod_file  |  tr '[A-Z]' '[a-z]' | sed -e 's/,.*intent.i.*)//' >> call_ini_replay.f90
     577cat >> call_ini_replay.f90 <<eod...........................................
    545578    open(90,file='$inimod.bin',form='unformatted')
    546579    read(90) $varinmodv
    547580    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...........................................
     581eod...........................................
     582get_subroutine_arg $param_ini $inimod_file | sed -e 's/subroutine/call/' >> call_ini_replay.f90
     583cat >> call_ini_replay.f90 <<eod...........................................
    551584    return
    552585    end subroutine call_ini_replay
    553 ....eod...........................................
    554 fi # nconly = false
     586eod...........................................
     587}
     588
     589
     590#-----------------------------------------------------------------------------
     591#-----------------------------------------------------------------------------
     592# Starting here
     593#-----------------------------------------------------------------------------
     594#-----------------------------------------------------------------------------
     595
     596get_file_names
     597
     598if [ $nconly = false ] ; then
     599   clean_other_routines
     600fi
     601
     602# Extracting/formating the target subroutine in "input" file
     603extract_subroutine $param $paramfile
     604
     605# Getting all in and inout variables from "input"
     606get_all_inout_and_in_variables
     607
     608# Getting lists of 1D and 2D arrays selecting status and 1D and 2D
     609get_variable_lists
     610
     611# Specific of routines to be replayed
     612if [ $nconly = false ] ; then
     613   create_call_param_replay
     614   create_dump_param_head
     615   if [ $param_ini != None ] ; then
     616      create_call_ini_replay
     617   fi
     618fi
     619
     620# Netcdf outputs in all cases
     621create_dump_param_nc
     622
     623# Some cleaning
     624\rm -f input tmp_get* tmp_include* tmpline*
Note: See TracChangeset for help on using the changeset viewer.