Ignore:
Timestamp:
Jul 11, 2021, 11:39:01 PM (3 years ago)
Author:
dcugnet
Message:

In readTracFiles: the separator between the tracer name and its phase is no longer hardcoded and equal to "-",
but is a parameter ("phases_sep") which default value is "_".
Few more fixes.

Location:
LMDZ6/branches/LMDZ-tracers/libf
Files:
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • LMDZ6/branches/LMDZ-tracers/libf/dyn3d/dynetat0.F90

    r3890 r3957  
    66! Purpose: Initial state reading.
    77!-------------------------------------------------------------------------------
     8  USE readTracFiles_mod, ONLY: known_phases, old_phases, nphases, phases_sep
    89  USE infotrac,    ONLY: nqtot, niso, tracers, iTraPha, tnat, alpha_ideal, tra
    910  USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQ_VARID, NF90_NoErr, &
     
    1718  USE serre_mod, ONLY: clon, clat, grossismx, grossismy
    1819  USE temps_mod, ONLY: annee_ref, day_ini, day_ref, itau_dyn, start_time
    19   USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
     20  USE ener_mod,  ONLY: etot0, ptot0, ztot0, stot0, ang0
    2021
    2122  IMPLICIT NONE
     
    3738!===============================================================================
    3839! Local variables:
    39   CHARACTER(LEN=256) :: sdum, var, modname, oldH2O(3), newH2O(3)
     40  CHARACTER(LEN=256) :: sdum, var, modname, oldH2O
    4041  INTEGER, PARAMETER :: length=100
    41   INTEGER :: iq, fID, vID, idecal, ix!, iml, jml, lml, nqt
     42  INTEGER :: iq, fID, vID, idecal, ix, ip
    4243  REAL    :: time, tab_cntrl(length)               !--- RUN PARAMS TABLE
    43  TYPE(tra), POINTER :: tr
     44  TYPE(tra), POINTER :: tr
    4445!-------------------------------------------------------------------------------
    4546  modname="dynetat0"
    46   oldH2O=['H2Ov ','H2Ol ','H2Oi ']
    47   newH2O=['H2O-g','H2O-l','H2O-s']
    4847
    4948!--- Initial state file opening
     
    107106  CALL check_dim(jm,jjm,'jm','jm')
    108107  CALL check_dim(lllm,llm,'lm','lllm')
    109   CALL get_var1("rlonu",rlonu)
    110   CALL get_var1("rlatu",rlatu)
    111   CALL get_var1("rlonv",rlonv)
    112   CALL get_var1("rlatv",rlatv)
    113   CALL get_var2("cu"   ,cu)
    114   CALL get_var2("cv"   ,cv)
    115   CALL get_var2("aire" ,aire)
     108  CALL get_var1("rlonu", rlonu)
     109  CALL get_var1("rlatu", rlatu)
     110  CALL get_var1("rlonv", rlonv)
     111  CALL get_var1("rlatv", rlatv)
     112  CALL get_var2("cu",       cu)
     113  CALL get_var2("cv",       cv)
     114  CALL get_var2("aire",   aire)
    116115  var="temps"
    117116  IF(NF90_INQ_VARID(fID,var,vID)/=NF90_NoErr) THEN
     
    121120  END IF
    122121  CALL err(NF90_GET_VAR(fID,vID,time),"get",var)
    123   CALL get_var2("phisinit",phis)
    124   CALL get_var3("ucov",ucov)
    125   CALL get_var3("vcov",vcov)
    126   CALL get_var3("teta",teta)
    127   CALL get_var3("masse",masse)
    128   CALL get_var2("ps",ps)
     122  CALL get_var2("phisinit", phis)
     123  CALL get_var3("ucov",     ucov)
     124  CALL get_var3("vcov",     vcov)
     125  CALL get_var3("teta",     teta)
     126  CALL get_var3("masse",   masse)
     127  CALL get_var2("ps",         ps)
    129128
    130129!--- Tracers
     
    132131    tr => tracers(iq)
    133132    var = tr%name
    134     IF(NF90_INQ_VARID(fID,var,vID)==NF90_NoErr) THEN
    135       CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var); CYCLE
     133    ix = strIdx([('H2O'//phases_sep//known_phases(ip:ip), ip=1, nphases)], var)
     134    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr) THEN
     135      CALL get_var3(var, q(:,:,:,iq))
    136136#ifdef INCA
    137     ELSE IF(var == "O3") THEN          !--- INCA and O3 missing: take OX instead
    138       WRITE(lunout,*) 'Tracer O3 is missing - it is initialized to OX'
    139         IF(NF90_INQ_VARID(fID,"OX",vID) == NF90_NoErr) THEN
    140            CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var); CYCLE
    141         END IF
     137    ELSE IF(NF90_INQ_VARID(fID, 'OX', vID) == NF90_NoErr .AND. var == 'O3') THEN
     138      WRITE(lunout,*)TRIM(modname)//': Tracer <O3> is missing => initialized to OX'
     139      CALL get_var3('OX', q(:,:,:,iq))
    142140#endif
    143     ELSE                               !--- Old file, water: H2Ov/l/i instead of H2O-g/-l/-s
    144       ix = strIdx(newH2O, var)         !--- Current tracer is water (new name) ?
    145       IF(ix /= 0) THEN                 !--- Then read the field, using the old name.
    146         IF(NF90_INQ_VARID(fID,oldH2O(ix),vID) == NF90_NoErr) THEN
    147            CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var); CYCLE
    148         END IF
     141    ELSE IF(ix /= 0) THEN              !--- Old file, water: H2Ov/l/i instead of H2O_g/_l/_s
     142      oldH2O = 'H2O'//old_phases(ix:ix)
     143      IF(NF90_INQ_VARID(fID, oldH2O, vID) == NF90_NoErr) THEN
     144        WRITE(lunout,*)TRIM(modname)//': Tracer <'//TRIM(var)//'> is missing => initialized to '//TRIM(oldH2O)
     145        CALL get_var3(oldH2O, q(:,:,:,iq))
     146      END IF
     147    ELSE
     148      WRITE(lunout,*)TRIM(modname)//': Tracer <'//TRIM(var)//'> is missing => initialized to zero'
     149      q(:,:,:,iq)=0.
     150      !--- CRisi: for isotopes, theoretical initialization using very simplified Rayleigh distillation law
     151      IF(niso > 0 .AND. tr%iso_num > 0) THEN
     152        IF(tr%iso_zon == 0) q(:,:,:,iq) = q(:,:,:,tr%iprnt)         *        tnat(tr%iso_num)  &
     153                                        *(q(:,:,:,tr%iprnt)/30.e-3)**(alpha_ideal(tr%iso_num)-1)
     154        IF(tr%iso_zon == 1) q(:,:,:,iq) = q(:,:,:,iTraPha(tr%iso_num,tr%iso_pha))
    149155      END IF
    150156    END IF
    151     WRITE(lunout,*)TRIM(modname)//": Tracer <"//TRIM(var)//"> is missing"
    152     WRITE(lunout,*)"         It is hence initialized to zero"
    153     q(:,:,:,iq)=0.
    154     !--- CRisi: for isotops, theoretical initialization using very simplified
    155     !           Rayleigh distillation las.
    156     IF(niso > 0 .AND. tr%iso_num > 0) THEN
    157       IF(tr%iso_zon == 0) q(:,:,:,iq) = q(:,:,:,tr%iprnt)         *        tnat(tr%iso_num)  &
    158                                       *(q(:,:,:,tr%iprnt)/30.e-3)**(alpha_ideal(tr%iso_num)-1)
    159       IF(tr%iso_zon == 1) q(:,:,:,iq) = q(:,:,:,iTraPha(tr%iso_num,tr%iso_pha))
    160     END IF
    161157  END DO
    162 
    163158  CALL err(NF90_CLOSE(fID),"close",fichnom)
    164159  day_ini=day_ini+INT(time)
     
    176171    s1='value of '//TRIM(str1)//' ='
    177172    s2=' read in starting file differs from parametrized '//TRIM(str2)//' ='
    178     WRITE(sdum,'(10x,a,i4,2x,a,i4)'),TRIM(ADJUSTL(s1)),n1,TRIM(ADJUSTL(s2)),n2
     173    WRITE(sdum,'(10x,a,i4,2x,a,i4)'),TRIM(s1),n1,TRIM(s2),n2
    179174    CALL ABORT_gcm(TRIM(modname),TRIM(sdum),1)
    180175  END IF
     
    182177
    183178
    184 SUBROUTINE get_var1(var,v)
     179SUBROUTINE get_var1(var, v)
    185180  CHARACTER(LEN=*), INTENT(IN)  :: var
    186181  REAL,             INTENT(OUT) :: v(:)
     
    190185
    191186
    192 SUBROUTINE get_var2(var,v)
     187SUBROUTINE get_var2(var, v)
    193188  CHARACTER(LEN=*), INTENT(IN)  :: var
    194189  REAL,             INTENT(OUT) :: v(:,:)
     
    198193
    199194
    200 SUBROUTINE get_var3(var,v)
     195SUBROUTINE get_var3(var, v)
    201196  CHARACTER(LEN=*), INTENT(IN)  :: var
    202197  REAL,             INTENT(OUT) :: v(:,:,:)
     
    206201
    207202
    208 SUBROUTINE err(ierr,typ,nam)
     203SUBROUTINE err(ierr, typ, nam)
    209204  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
    210205  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
  • LMDZ6/branches/LMDZ-tracers/libf/dyn3d_common/infotrac.F90

    r3891 r3957  
    11MODULE infotrac
    22
    3   USE       strings_mod, ONLY: msg, find, strIdx,  strFind,  strHead, dispTable, testFile, cat, get_in,  &
     3  USE       strings_mod, ONLY: msg, find, strIdx,  strFind,  strHead, dispTable, testFile, cat, get_in,   &
    44                              fmsg, test, int2str, strParse, strTail, strReduce, strStack, modname
    5   USE readTracFiles_mod, ONLY: readTracersFiles, getKey_init, nphases, delPhase, aliasTracer, &
    6                         tran0, readIsotopesFile, getKey, known_phases, addPhase, indexUpdate, initIsotopes
     5  USE readTracFiles_mod, ONLY: readTracersFiles, getKey_init, nphases, delPhase, old_phases, aliasTracer, &
     6            phases_sep, tran0, readIsotopesFile, getKey, known_phases, addPhase, indexUpdate, initIsotopes
    77  USE trac_types_mod,    ONLY: tra, iso, kys
    88
     
    4545!  |--------------------+----------------------+-----------------+---------------+----------------------------|
    4646!  | water in different |    water tagging     |  water isotopes | other tracers | additional tracers moments |
    47 !  | phases: H2O-[gls]  |      isotopes        |                 |               |  for higher order schemes  |
     47!  | phases: H2O_[gls]  |      isotopes        |                 |               |  for higher order schemes  |
    4848!  |--------------------+----------------------+-----------------+---------------+----------------------------|
    4949!  |                    |                      |                 |               |                            |
     
    184184  CHARACTER(LEN=2)   ::   suff(9)                                    !--- Suffixes for schemes of order 3 or 4 (Prather)
    185185  CHARACTER(LEN=3)   :: descrq(30)                                   !--- Advection scheme description tags
    186   CHARACTER(LEN=4)  :: oldH2O(3)                                    !--- Old water name for the three phases
     186  CHARACTER(LEN=256) :: oldH2O(3)                                    !--- Old water name for the three phases
    187187  CHARACTER(LEN=256) :: newH2O                                       !--- New water name
    188188  CHARACTER(LEN=256) :: msg1, msg2                                   !--- Strings for messages
     
    283283      IF(planet_type=='earth') THEN                                  !--- Default for Earth
    284284        nqo = 2; nbtr = 2
    285         tracers(:)%name = ['H2O-g','H2O-l','RN   ','PB   ']
    286         tracers(:)%prnt = [tran0  ,tran0  ,tran0  ,tran0  ]
    287         tracers(:)%igen = [1      ,1      ,1      ,1      ]
    288         hadv            = [14     ,10     ,10     ,10     ]
    289         vadv            = [14     ,10     ,10     ,10     ]
     285        tracers(:)%name = ['H2O'//phases_sep//'g', 'H2O'//phases_sep//'l', 'RN   ', 'PB   ']
     286        tracers(:)%prnt = [tran0, tran0, tran0, tran0]
     287        tracers(:)%igen = [1    , 1    , 1    , 1    ]
     288        hadv            = [14   , 10   , 10   , 10   ]
     289        vadv            = [14   , 10   , 10   , 10   ]
    290290      ELSE                                                           !--- Default for other planets
    291291        nqo = 0; nbtr = 1
     
    329329        DO ip = 1, SIZE(oldH2O)
    330330          ix = strIdx(tracers(:)%name,oldH2O(ip))                    !--- Old name of water in a specific phase (ix/=0)
     331          newH2O = 'H2O'//phases_sep//known_phases(ip:ip)            !--- Corresponding new name
     332          IF(ix == 0) ix = strIdx(tracers(:)%name,newH2O)            !--- New name in an old format file (to be avoided...)
    331333          IF(ix == 0) CYCLE
    332           newH2O = 'H2O-'//known_phases(ip:ip)                       !--- Corresponding new name
    333334          nqo = nqo+1; tracers(ix)%name = newH2O                     !--- One more water phase ; replace old name with one
    334335          tracers(strFind(tracers(:)%nam1,oldH2O(ip)))%nam1 = newH2O
     
    341342    CASE DEFAULT                                                     !=== FOUND NEW STYLE TRACERS CONFIG FILE(S)
    342343    !--------------------------------------------------------------------------------------------------------------------------
    343       nqo    = 2; IF(ANY(tracers(:)%name == 'H2O-s')) nqo=3
     344      nqo    = 2; IF(ANY(tracers(:)%name == 'H2O'//phases_sep//'s')) nqo=3
    344345      nqtrue = SIZE(tracers, DIM=1)
    345346      nbtr   = nqtrue - nqo
     
    353354  IF(.NOT.ALLOCATED(conv_flg)) conv_flg = [(1, it=1, nbtr)]
    354355  IF(.NOT.ALLOCATED( pbl_flg))  pbl_flg = [(1, it=1, nbtr)]
     356!print*,'nqo, nbtr = ',nqo,nbtr
     357!stop
    355358
    356359#ifdef CPP_StratAer
     
    466469
    467470    !--- iadv = 14 IS ONLY VALID FOR WATER VAPOUR
    468     IF(fmsg(iad==14 .AND. t1%name(1:5)/='H2O-g', 'WARNING ! '//TRIM(msg1)//', found for "' &
     471    IF(fmsg(iad==14 .AND. t1%name(1:5)/='H2O'//phases_sep//'g', 'WARNING ! '//TRIM(msg1)//', found for "' &
    469472                 //TRIM(t1%name)//'" but only valid for water vapour ! Setting iadv=10 for "'//TRIM(t1%name)//'".')) t1%iadv=10
    470473  END DO
  • LMDZ6/branches/LMDZ-tracers/libf/dyn3dmem/dynetat0_loc.F90

    r3891 r3957  
    77!-------------------------------------------------------------------------------
    88  USE parallel_lmdz
    9   USE infotrac, ONLY: nqtot, niso, tracers, iTraPha, tnat, alpha_ideal, tra
    10   USE netcdf, ONLY: NF90_OPEN,  NF90_INQUIRE_DIMENSION, NF90_INQ_VARID,        &
    11       NF90_NOWRITE, NF90_CLOSE, NF90_INQUIRE_VARIABLE,  NF90_GET_VAR, NF90_NoErr
     9  USE readTracFiles_mod, ONLY: known_phases, old_phases, nphases, phases_sep
     10  USE infotrac,    ONLY: nqtot, niso, tracers, iTraPha, tnat, alpha_ideal, tra
     11  USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQ_VARID, NF90_INQUIRE_DIMENSION, &
     12           NF90_INQUIRE, NF90_CLOSE, NF90_GET_VAR, NF90_NoErr,     NF90_INQUIRE_VARIABLE
     13  USE strings_mod, ONLY: strIdx
    1214  USE control_mod, ONLY: planet_type
    1315  USE assert_eq_m, ONLY: assert_eq
    1416  USE comvert_mod, ONLY: pa,preff
    15   USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, &
    16                           omeg, rad
     17  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, omeg, rad
    1718  USE logic_mod, ONLY: fxyhypb, ysinus
    1819  USE serre_mod, ONLY: clon, clat, grossismx, grossismy
    19   USE temps_mod, ONLY: annee_ref,day_ref,itau_dyn, &
    20                        start_time,day_ini,hour_ini
    21   USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
    22  
     20  USE temps_mod, ONLY: annee_ref, day_ini, day_ref, itau_dyn, start_time
     21  USE ener_mod,  ONLY: etot0, ptot0, ztot0, stot0, ang0
     22
    2323  IMPLICIT NONE
    2424  include "dimensions.h"
     
    3939!===============================================================================
    4040! Local variables:
    41   CHARACTER(LEN=256) :: sdum, var, modname
     41  CHARACTER(LEN=256) :: sdum, var, modname, oldH2O
    4242  INTEGER, PARAMETER :: length=100
    43   INTEGER :: iq, fID, vID, idecal, ierr
     43  INTEGER :: iq, fID, vID, idecal, ix, ip, ierr
    4444  REAL    :: time, tab_cntrl(length)               !--- RUN PARAMS TABLE
    45   REAL,             ALLOCATABLE :: vcov_glo(:,:),masse_glo(:,:),   ps_glo(:)
    46   REAL,             ALLOCATABLE :: ucov_glo(:,:),    q_glo(:,:), phis_glo(:)
    47   REAL,             ALLOCATABLE :: teta_glo(:,:)
    4845  TYPE(tra), POINTER :: tr
    4946!-------------------------------------------------------------------------------
     
    110107  CALL check_dim(jm,jjm,'jm','jm')
    111108  CALL check_dim(lllm,llm,'lm','lllm')
    112   CALL get_var1("rlonu",rlonu)
    113   CALL get_var1("rlatu",rlatu)
    114   CALL get_var1("rlonv",rlonv)
    115   CALL get_var1("rlatv",rlatv)
    116   CALL get_var1("cu"  ,cu)
    117   CALL get_var1("cv"  ,cv)
    118   CALL get_var1("aire",aire)
     109  CALL get_var1("rlonu", rlonu)
     110  CALL get_var1("rlatu", rlatu)
     111  CALL get_var1("rlonv", rlonv)
     112  CALL get_var1("rlatv", rlatv)
     113  CALL get_var1("cu",       cu)
     114  CALL get_var1("cv",       cv)
     115  CALL get_var1("aire",   aire)
    119116
    120117  var="temps"
     
    125122  END IF
    126123  CALL err(NF90_GET_VAR(fID,vID,time),"get",var)
    127 
    128   ALLOCATE(phis_glo(ip1jmp1))
    129   CALL get_var1("phisinit",phis_glo)
    130   phis (ijb_u:ije_u)  =phis_glo(ijb_u:ije_u);    DEALLOCATE(phis_glo)
    131 
    132   ALLOCATE(ucov_glo(ip1jmp1,llm))
    133   CALL get_var2("ucov",ucov_glo)
    134   ucov (ijb_u:ije_u,:)=ucov_glo(ijb_u:ije_u,:);  DEALLOCATE(ucov_glo)
    135 
    136   ALLOCATE(vcov_glo(ip1jm,llm))
    137   CALL get_var2("vcov",vcov_glo)
    138   vcov (ijb_v:ije_v,:)=vcov_glo(ijb_v:ije_v,:);  DEALLOCATE(vcov_glo)
    139 
    140   ALLOCATE(teta_glo(ip1jmp1,llm))
    141   CALL get_var2("teta",teta_glo)
    142   teta (ijb_u:ije_u,:)=teta_glo(ijb_u:ije_u,:);  DEALLOCATE(teta_glo)
    143 
    144   ALLOCATE(masse_glo(ip1jmp1,llm))
    145   CALL get_var2("masse",masse_glo)
    146   masse(ijb_u:ije_u,:)=masse_glo(ijb_u:ije_u,:); DEALLOCATE(masse_glo)
    147  
    148   ALLOCATE(ps_glo(ip1jmp1))
    149   CALL get_var1("ps",ps_glo)
    150   ps   (ijb_u:ije_u)  =   ps_glo(ijb_u:ije_u);   DEALLOCATE(ps_glo)
     124  CALL get_var1("phisinit", phis, ijb_u, ije_u, ip1jmp1)
     125  CALL get_var2("ucov",     ucov, ijb_u, ije_u, ip1jmp1)
     126  CALL get_var2("vcov",     vcov, ijb_v, ije_v, ip1jm)
     127  CALL get_var2("teta",     teta, ijb_u, ije_u, ip1jmp1)
     128  CALL get_var2("masse",   masse, ijb_u, ije_u, ip1jmp1)
     129  CALL get_var1("ps",         ps, ijb_u, ije_u, ip1jmp1)
    151130
    152131!--- Tracers
    153   ALLOCATE(q_glo(ip1jmp1,llm))
    154132  DO iq=1,nqtot
    155133    tr => tracers(iq)
    156134    var = tr%name
    157     IF(NF90_INQ_VARID(fID,var,vID)==NF90_NoErr) THEN
    158       CALL get_var2(var ,q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:); CYCLE
     135    ix = strIdx([('H2O'//phases_sep//known_phases(ip:ip), ip=1, nphases)], var)
     136    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr) THEN
     137      CALL get_var2(var, q(:,:,iq), ijb_u, ije_u, ip1jmp1)
    159138#ifdef INCA
    160     ELSE IF(NF90_INQ_VARID(fID,"OX",vID) == NF90_NoErr .AND. var == 'O3') THEN
    161       WRITE(lunout,*) 'Tracer O3 is missing - it is initialized to OX'
    162       CALL get_var2("OX",q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:); CYCLE
     139    ELSE IF(NF90_INQ_VARID(fID, 'OX', vID) == NF90_NoErr .AND. var == 'O3') THEN
     140      WRITE(lunout,*)TRIM(modname)//': Tracer <O3> is missing => initialized to OX'
     141      CALL get_var2('OX', q(:,:,iq), ijb_u, ije_u, ip1jmp1)
    163142#endif
    164     END IF
    165     WRITE(lunout,*)TRIM(modname)//": Tracer <"//TRIM(var)//"> is missing"
    166     WRITE(lunout,*)"         It is hence initialized to zero"
    167     q(ijb_u:ije_u,:,iq)=0.
    168    !--- CRisi: for isotops, theoretical initialization using very simplified
    169    !           Rayleigh distillation las.
    170     IF(niso > 0 .AND. tr%iso_num > 0) THEN
    171       IF(tr%iso_zon == 0) q(:,:,iq) = q(:,:,tr%iprnt)         *        tnat(tr%iso_num) &
    172                                    * (q(:,:,tr%iprnt)/30.e-3)**(alpha_ideal(tr%iso_num)-1)
    173       IF(tr%iso_zon == 1) q(:,:,iq) = q(:,:,iTraPha(tr%iso_num,tr%iso_pha))
     143    ELSE IF(ix /= 0) THEN              !--- Old file, water: H2Ov/l/i instead of H2O-g/-l/-s
     144      oldH2O = 'H2O'//old_phases(ix:ix)
     145      IF(NF90_INQ_VARID(fID, oldH2O, vID) == NF90_NoErr) THEN
     146        WRITE(lunout,*)TRIM(modname)//': Tracer <'//TRIM(var)//'> is missing => initialized to '//TRIM(oldH2O)
     147        CALL get_var2(oldH2O, q(:,:,iq), ijb_u, ije_u, ip1jmp1)
     148      END IF
     149    ELSE
     150      WRITE(lunout,*)TRIM(modname)//': Tracer <'//TRIM(var)//'> is missing => initialized to zero'
     151      q(ijb_u:ije_u,:,iq)=0.
     152      !--- CRisi: for isotopes, theoretical initialization using very simplified Rayleigh distillation law
     153      IF(niso > 0 .AND. tr%iso_num > 0) THEN
     154        IF(tr%iso_zon == 0) q(:,:,iq) = q(:,:,tr%iprnt)         *        tnat(tr%iso_num) &
     155                                      *(q(:,:,tr%iprnt)/30.e-3)**(alpha_ideal(tr%iso_num)-1)
     156        IF(tr%iso_zon == 1) q(:,:,iq) = q(:,:,iTraPha(tr%iso_num,tr%iso_pha))
     157      END IF
    174158    END IF
    175159  END DO
    176   DEALLOCATE(q_glo)
    177160  CALL err(NF90_CLOSE(fID),"close",fichnom)
    178161  day_ini=day_ini+INT(time)
     
    190173    s1='value of '//TRIM(str1)//' ='
    191174    s2=' read in starting file differs from parametrized '//TRIM(str2)//' ='
    192     WRITE(sdum,'(10x,a,i4,2x,a,i4)'),s1,n1,s2,n2
     175    WRITE(sdum,'(10x,a,i4,2x,a,i4)'),TRIM(s1),n1,TRIM(s2),n2
    193176    CALL ABORT_gcm(TRIM(modname),TRIM(sdum),1)
    194177  END IF
     
    196179
    197180
    198 SUBROUTINE get_var1(var,v)
    199   CHARACTER(LEN=*), INTENT(IN)  :: var
    200   REAL,             INTENT(OUT) :: v(:)
    201   REAL,             ALLOCATABLE :: w2(:,:), w3(:,:,:)
    202   INTEGER :: nn(3), dids(3), k, nd, ntot
    203 
    204   CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
    205   ierr=NF90_INQUIRE_VARIABLE(fID,vID,ndims=nd)
    206   IF(nd==1) THEN
    207     CALL err(NF90_GET_VAR(fID,vID,v),"get",var); RETURN
    208   END IF
    209   ierr=NF90_INQUIRE_VARIABLE(fID,vID,dimids=dids)
    210   DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO
    211   ntot=PRODUCT(nn(1:nd))
    212   SELECT CASE(nd)
    213     CASE(2); ALLOCATE(w2(nn(1),nn(2)))
    214       CALL err(NF90_GET_VAR(fID,vID,w2),"get",var)
    215       v=RESHAPE(w2,[ntot]); DEALLOCATE(w2)
    216     CASE(3); ALLOCATE(w3(nn(1),nn(2),nn(3)))
    217       CALL err(NF90_GET_VAR(fID,vID,w3),"get",var)
    218       v=RESHAPE(w3,[ntot]); DEALLOCATE(w3)
    219   END SELECT
     181SUBROUTINE get_var1(var, v, ib, ie, n_glo)
     182  CHARACTER(LEN=*),  INTENT(IN)  :: var
     183  REAL,              INTENT(OUT) :: v(:)
     184  INTEGER, OPTIONAL, INTENT(IN)  :: ib, ie, n_glo
     185  REAL, ALLOCATABLE :: w(:,:,:,:), v_glo(:)
     186  INTEGER :: nn(4), dids(4), k, nd, ntot
     187  CALL err(NF90_INQ_VARID(fID, var, vID), "inq", var)
     188  ierr = NF90_INQUIRE_VARIABLE(fID, vID, dimids=dids, ndims=nd)
     189  nn(:) = 1; DO k=1,nd; ierr = NF90_INQUIRE_DIMENSION(fID, dids(k), len=nn(k)); END DO
     190  ntot = PRODUCT(nn(1:nd))
     191  ALLOCATE(w(nn(1), nn(2), nn(3), nn(4)))
     192  CALL err(NF90_GET_VAR(fID, vID, w), "get", var)
     193  ALLOCATE(v_glo(ntot)); v_glo=RESHAPE(w, [ntot]); DEALLOCATE(w)
     194  IF(PRESENT(n_glo).AND.PRESENT(ib).AND.PRESENT(ie)) THEN
     195    IF(ntot/=n_glo) CALL abort_gcm(TRIM(modname), 'Shape mismatch for "'//TRIM(var)//'"')
     196    v(ib:ie) = v_glo(ib:ie)
     197  ELSE
     198    v(:) = v_glo(:)
     199  END IF
     200  DEALLOCATE(v_glo)
    220201END SUBROUTINE get_var1
    221202
    222203
    223 SUBROUTINE get_var2(var,v)
     204SUBROUTINE get_var2(var, v, ib, ie, n_glo)
    224205  CHARACTER(LEN=*), INTENT(IN)  :: var
    225206  REAL,             INTENT(OUT) :: v(:,:)
    226   REAL,             ALLOCATABLE :: w4(:,:,:,:)
    227   INTEGER :: nn(4), dids(4), k, nd
    228   CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
    229   ierr=NF90_INQUIRE_VARIABLE(fID,vID,dimids=dids,ndims=nd)
    230   DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO
    231   ALLOCATE(w4(nn(1),nn(2),nn(3),nn(4)))
    232   CALL err(NF90_GET_VAR(fID,vID,w4),"get",var)
    233   v=RESHAPE(w4,[nn(1)*nn(2),nn(3)]); DEALLOCATE(w4)
     207  INTEGER,          INTENT(IN)  :: ib, ie, n_glo
     208  REAL, ALLOCATABLE :: w(:,:,:,:), v_glo(:,:)
     209  INTEGER :: nn(4), dids(4), k, nd, nh, nv, tid
     210  CALL err(NF90_INQ_VARID(fID, var, vID), "inq", var)
     211  ierr = NF90_INQUIRE_VARIABLE(fID, vID, dimids=dids, ndims=nd)
     212  nn(:) = 1; DO k=1,nd; ierr = NF90_INQUIRE_DIMENSION(fID, dids(k), len=nn(k)); END DO
     213  IF(NF90_INQUIRE(fID, unlimitedDimId=tid) == NF90_NOERR) THEN
     214    nh = PRODUCT(nn(1:nd-2)); nv = nn(nd-1); nn(nd) = 1
     215  ELSE
     216    nh = PRODUCT(nn(1:nd-1)); nv = nn(nd)
     217  END IF
     218  ALLOCATE(w(nn(1), nn(2), nn(3), nn(4)))
     219  CALL err(NF90_GET_VAR(fID, vID, w), "get", var)
     220  ALLOCATE(v_glo(nh, nv)); v_glo = RESHAPE(w, [nh, nv]); DEALLOCATE(w)
     221  IF(nh/=n_glo .OR. nv/=llm) CALL abort_gcm(TRIM(modname), 'Shape mismatch for "'//TRIM(var)//'"')
     222  v(ib:ie,:) = v_glo(ib:ie,:)
     223  DEALLOCATE(v_glo)
    234224END SUBROUTINE get_var2
    235225
    236226
    237 SUBROUTINE err(ierr,typ,nam)
     227SUBROUTINE err(ierr, typ, nam)
    238228  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
    239229  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
  • LMDZ6/branches/LMDZ-tracers/libf/dyn3dmem/vlspltqs_loc.F

    r3891 r3957  
    481481      INTEGER ijbm,ijem
    482482
     483      tr => tracers(iq)
    483484      ijb=ij_begin-2*iip1
    484485      ije=ij_end+2*iip1 
  • LMDZ6/branches/LMDZ-tracers/libf/misc/readTracFiles_mod.f90

    r3891 r3957  
    1414  PUBLIC :: getKey_init, getKey, setDirectKeys                            !--- FUNCTIONS TO GET KEYS FROM tracers & isotopes
    1515
    16   PUBLIC :: known_phases, nphases, phases_names, delPhase, addPhase       !--- PHASES RELATED VARIABLES AND ROUTINES
     16  PUBLIC :: known_phases, old_phases, nphases, phases_names, phases_sep, &!--- VARIABLES RELATED TO THE PHASES
     17            delPhase, addPhase                                            !--- ROUTINES TO ADD/REMOVE PHASE TO/FROM A NAME
    1718
    1819  PUBLIC :: tran0, idxAncestor, ancestor                                  !--- GEN 0 TRACER + TOOLS FOR GENERATIONS
     
    3435  !--- SOME PARAMETERS THAT ARE NOT LIKELY TO CHANGE OFTEN
    3536  CHARACTER(LEN=256), SAVE      :: tran0        = 'air'              !--- Default transporting fluid
     37  CHARACTER(LEN=256), PARAMETER :: old_phases   = 'vli'              !--- Old phases for water (no separator)
    3638  CHARACTER(LEN=256), PARAMETER :: known_phases = 'gls'              !--- Known phases initials
    3739  INTEGER,            PARAMETER :: nphases = LEN_TRIM(known_phases)  !--- Number of phases
    3840  CHARACTER(LEN=256), SAVE      :: phases_names(nphases) &           !--- Known phases names
    3941                                 = ['gaseous', 'liquid ', 'solid  ']
     42  CHARACTER(LEN=1),   SAVE      :: phases_sep  =  '_'                !--- Phase separator
    4043  LOGICAL,            SAVE      :: tracs_merge = .TRUE.              !--- Merge/stack tracers lists
    4144  LOGICAL,            SAVE      :: lSortByGen  = .TRUE.              !--- Sort by growing generation
     
    7982  CHARACTER(LEN=256),     ALLOCATABLE ::  s(:), sections(:), trac_files(:)
    8083  CHARACTER(LEN=256)   :: str, fname, mesg
    81   INTEGER              :: is, nsec, ierr, it, ntrac, ns
     84  INTEGER              :: is, nsec, ierr, it, ntrac, ns, ip
    8285  LOGICAL, ALLOCATABLE :: ll(:), lGen3(:)
    8386!------------------------------------------------------------------------------------------------------------------------------
     
    97100  IF(.NOT.testFile('traceur.def') .AND. nsec==1) fType = 1           !--- OLD STYLE FILE
    98101  IF(.NOT.testFile('tracer.def'))                fType = 2           !--- NEW STYLE ; SINGLE  FILE, SEVERAL SECTIONS
    99   IF(ALL(ll))                               fType = 3                !--- NEW STYLE ; SEVERAL FILES, SINGLE SECTION USED
     102  IF(ALL(ll))                                    fType = 3           !--- NEW STYLE ; SEVERAL FILES, SINGLE SECTION USED
    100103  IF(ANY(ll) .AND. fType/=3) THEN                                    !--- MISSING FILES
    101104    IF(test(checkList(trac_files, .NOT.ll, 'Failed reading tracers description', 'files', 'missing'), lerr)) RETURN
     
    129132      CALL msg(ns == 3 .AND. it == 1, 'This file is for air tracers only')
    130133      CALL msg(ns == 4 .AND. it == 1, 'This files specifies the transporting fluid')
    131       SELECT CASE(s(3))                                              !--- name and phase of the tracer
    132         CASE('H2Ov'); tracs(it)%name = 'H2O-g'; tracs(it)%phas = 'g'
    133         CASE('H2Ol'); tracs(it)%name = 'H2O-l'; tracs(it)%phas = 'l'
    134         CASE('H2Oi'); tracs(it)%name = 'H2O-s'; tracs(it)%phas = 's'
    135         CASE DEFAULT; tracs(it)%name = s(3)   ; tracs(it)%phas = 'g'
    136       END SELECT
     134      tracs(it)%name = s(3); tracs(it)%phas = known_phases(1:1)      !--- Default: name, gazeous phase "g"
     135      DO ip = 1, nphases                                             !--- Deal with old water names
     136        IF(s(3) /= 'H2O'//old_phases(ip:ip)) CYCLE
     137        tracs(it)%phas = known_phases(ip:ip); tracs(it)%name = 'H2O'//phases_sep//TRIM(tracs(it)%phas)
     138      END DO
    137139      tracs(it)%prnt = tran0                                         !--- Default transporting fluid: Air
    138140      IF(ns == 4) tracs(it)%prnt = s(4)                              !--- Transporting fluid name
     
    549551        trn=TRIM(tr(iq)%name); nam=trn                               !--- Tracer name (regular case)
    550552        IF(lTg) nam = TRIM(tr(iq)%prnt)                              !--- Parent name (tagging case)
    551         IF(lEx) nam = TRIM(nam)//'-'//pha(ip:ip)                     !--- Phase extension needed
     553        IF(lEx) nam = TRIM(nam)//phases_sep//pha(ip:ip)              !--- Phase extension needed
    552554        IF(lTg) nam = TRIM(nam)//'_'//TRIM(trn)                      !--- <parent>_<name> for tags
    553555        ttr(it) = tr(iq)                                             !--- Same <key>=<val> pairs
     
    556558        ttr(it)%phas = pha(ip:ip)                                    !--- Single phase entry
    557559        IF(lEx.AND.tr(iq)%igen>1) THEN
    558           ttr(it)%prnt = TRIM(ttr(it)%prnt)//'-'//pha(ip:ip)
    559           ttr(it)%nam1 = TRIM(ttr(it)%nam1)//'-'//pha(ip:ip)
     560          ttr(it)%prnt = TRIM(ttr(it)%prnt)//phases_sep//pha(ip:ip)
     561          ttr(it)%nam1 = TRIM(ttr(it)%nam1)//phases_sep//pha(ip:ip)
    560562        END IF
    561563        it=it+1
     
    698700      tnam = t1(iq)%name                                             !--- Original name
    699701      IF(COUNT(t1%name == tnam) == 1) CYCLE                          !--- Current tracer is not duplicated: finished
    700       tnam_new = TRIM(tnam)//'-'//TRIM(sections(is)%name)            !--- Same with section extension
     702      tnam_new = TRIM(tnam)//phases_sep//TRIM(sections(is)%name)     !--- Same with section extension
    701703      nq = SUM(nt(1:is-1))                                           !--- Number of tracers in previous sections
    702704      ns = nt(is)                                                    !--- Number of tracers in the current section
     
    12311233  i = INDEX(s, '_'); l = LEN_TRIM(s)
    12321234  IF(i == 0) THEN
    1233     IF(s(l-1:l-1)=='-' .AND. INDEX(known_phases,s(l:l)) /= 0) out = s(1:l-2)
     1235    IF(s(l-1:l-1)==phases_sep .AND. INDEX(known_phases,s(l:l)) /= 0) out = s(1:l-2)
    12341236  ELSE; i=i-1
    1235     IF(s(i-1:i-1)=='-' .AND. INDEX(known_phases,s(i:i)) /= 0) out = s(1:i-2)//s(i+1:l)
     1237    IF(s(i-1:i-1)==phases_sep .AND. INDEX(known_phases,s(i:i)) /= 0) out = s(1:i-2)//s(i+1:l)
    12361238  END IF
    12371239END FUNCTION delPhase
     
    12441246  IF(s == '') RETURN
    12451247  i = INDEX(s, '_'); l = LEN_TRIM(s)
    1246   IF(i == 0) out =  TRIM(s)//'-'//pha
    1247   IF(i /= 0) out = s(1:i-1)//'-'//pha//'_'//s(i+1:l)
     1248  IF(i == 0) out =  TRIM(s)//phases_sep//pha
     1249  IF(i /= 0) out = s(1:i-1)//phases_sep//pha//'_'//s(i+1:l)
    12481250END FUNCTION addPhase_1
    12491251!------------------------------------------------------------------------------------------------------------------------------
  • LMDZ6/branches/LMDZ-tracers/libf/misc/strings_mod.F90

    r3892 r3957  
    186186
    187187!==============================================================================================================================
    188 !=== Extract first or last element of a string "str" delimited by separator "sep" =============================================
    189 !==============================================================================================================================
    190 CHARACTER(LEN=256) FUNCTION strHead_1(str,sep) RESULT(out)
     188!=== Extract the substring in front of the last (first if lFirst==TRUE) occurrence of separator "sep" in "str" ================
     189!==============================================================================================================================
     190CHARACTER(LEN=256) FUNCTION strHead_1(str,sep,lFirst) RESULT(out)
    191191  CHARACTER(LEN=*),           INTENT(IN) :: str
    192192  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
     193  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
     194  LOGICAL :: lf
     195  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
    193196  IF(PRESENT(sep)) THEN
    194     out = str(1:INDEX(str,sep,.TRUE.)-1)
     197    out = str(1:INDEX(str,sep,.NOT.lf)-1)
    195198  ELSE
    196     out = str(1:INDEX(str,'/',.TRUE.)-1)
     199    out = str(1:INDEX(str,'/',.NOT.lf)-1)
    197200  END IF
    198201  IF(out == '') out = str
    199202END FUNCTION strHead_1
    200203!==============================================================================================================================
    201 CHARACTER(LEN=256) FUNCTION strTail_1(str,sep) RESULT(out)
    202   CHARACTER(LEN=*),           INTENT(IN) :: str
    203   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
    204   IF(PRESENT(sep)) THEN
    205     out = str(INDEX(str,sep,.TRUE.)+LEN(sep):LEN_TRIM(str))
    206   ELSE
    207     out = str(INDEX(str,'/',.TRUE.)+1:LEN_TRIM(str))
    208   END IF
    209   IF(out == '') out = str
    210 END FUNCTION strTail_1
    211 !==============================================================================================================================
    212 FUNCTION strHead_m(str,sep) RESULT(out)
     204FUNCTION strHead_m(str,sep,lFirst) RESULT(out)
    213205  CHARACTER(LEN=256),        ALLOCATABLE :: out(:)
    214206  CHARACTER(LEN=*),           INTENT(IN) :: str(:)
    215207  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
     208  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
     209  LOGICAL :: lf
    216210  INTEGER :: k
     211  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
    217212  IF(PRESENT(sep)) THEN
    218     out = [(strHead_1(str(k),sep), k=1, SIZE(str))]
     213    out = [(strHead_1(str(k),sep,.NOT.lf),    k=1, SIZE(str))]
    219214  ELSE
    220     out = [(strHead_1(str(k)),    k=1, SIZE(str))]
     215    out = [(strHead_1(str(k),lFirst=.NOT.lf), k=1, SIZE(str))]
    221216  END IF
    222217
    223218END FUNCTION strHead_m
    224219!==============================================================================================================================
    225 FUNCTION strTail_m(str,sep) RESULT(out)
     220!=== Extract the substring following the last (first if lFirst==TRUE) occurrence of separator "sep" in "str" ==================
     221!==============================================================================================================================
     222CHARACTER(LEN=256) FUNCTION strTail_1(str,sep,lFirst) RESULT(out)
     223  CHARACTER(LEN=*),           INTENT(IN) :: str
     224  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
     225  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
     226  LOGICAL :: lf
     227  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
     228  IF(PRESENT(sep)) THEN
     229    out = str(INDEX(str,sep,.NOT.lf)+LEN(sep):LEN_TRIM(str))
     230  ELSE
     231    out = str(INDEX(str,'/',.NOT.lf)+1:LEN_TRIM(str))
     232  END IF
     233  IF(out == '') out = str
     234END FUNCTION strTail_1
     235!==============================================================================================================================
     236FUNCTION strTail_m(str,sep,lFirst) RESULT(out)
    226237  CHARACTER(LEN=256),        ALLOCATABLE :: out(:)
    227238  CHARACTER(LEN=*),           INTENT(IN) :: str(:)
    228239  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
     240  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
     241  LOGICAL :: lf
    229242  INTEGER :: k
     243  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
    230244  IF(PRESENT(sep)) THEN
    231     out = [(strTail_1(str(k),sep), k=1, SIZE(str))]
     245    out = [(strTail_1(str(k),sep,.NOT.lf),    k=1, SIZE(str))]
    232246  ELSE
    233     out = [(strTail_1(str(k)),    k=1, SIZE(str))]
     247    out = [(strTail_1(str(k),lFirst=.NOT.lf), k=1, SIZE(str))]
    234248  END IF
    235249END FUNCTION strTail_m
  • LMDZ6/branches/LMDZ-tracers/libf/phylmd/phyetat0.F90

    r3891 r3957  
    575575USE dimphy, only: klon
    576576USE print_control_mod, ONLY: lunout
    577 
     577USE readTracFiles_mod, ONLY: known_phases, old_phases, nphases, phases_sep
     578USE strings_mod,       ONLY: strIdx
    578579IMPLICIT NONE
    579580
     
    588589! Local variables
    589590LOGICAL found
     591INTEGER :: ix, ip
     592CHARACTER(LEN=256) :: oldname
    590593
    591594   CALL get_field(name, field, found)
     595   ix = strIdx([('trs_H2O'//phases_sep//known_phases(ip:ip), ip=1, nphases)], name)
     596   IF (.NOT. found .AND. ix /= 0) THEN           !--- Old file, water: H2Ov/l/i instead of H2O_g/_l/_s
     597      oldname = 'trs_H2O'//old_phases(ix:ix)
     598      CALL get_field(oldname, field, found)
     599   END IF
    592600   IF (.NOT. found) THEN
    593601     WRITE(lunout,*) "phyetat0: Le champ <",TRIM(name),"> est absent"
    594602     WRITE(lunout,*) "Depart legerement fausse. Mais je continue"
    595603     field(:,:)=default
     604   ELSE IF(ix /= 0) THEN
     605     WRITE(lunout,*)"phyetat0: Le champ <",TRIM(name),"> est absent => initialisation a <"//TRIM(oldname)//">"
    596606   ENDIF
    597607   WRITE(lunout,*) TRIM(name), descr, MINval(field),MAXval(field)
Note: See TracChangeset for help on using the changeset viewer.