Ignore:
Timestamp:
Sep 11, 2024, 6:03:07 PM (2 months ago)
Author:
abarral
Message:

Encapsulate files in modules

File:
1 moved

Legend:

Unmodified
Added
Removed
  • LMDZ6/branches/Amaury_dev/libf/dyn3d/lmdz_dynredem.f90

    r5185 r5186  
    1 SUBROUTINE dynredem0(fichnom, iday_end, phis)
     1MODULE lmdz_dynredem
     2  IMPLICIT NONE; PRIVATE
     3  PUBLIC dynredem0, dynredem1
     4
     5
     6CONTAINS
     7
     8  SUBROUTINE dynredem0(fichnom, iday_end, phis)
     9
     10    !-------------------------------------------------------------------------------
     11    ! Write the NetCDF restart file (initialization).
     12    !-------------------------------------------------------------------------------
     13    USE IOIPSL
     14    USE lmdz_strings, ONLY: maxlen
     15    USE lmdz_infotrac, ONLY: nqtot, tracers
     16    USE netcdf, ONLY: nf90_create, nf90_def_dim, nf90_inq_varid, nf90_global, &
     17            nf90_close, nf90_put_att, nf90_unlimited, nf90_clobber, &
     18            nf90_64bit_offset
     19    USE dynredem_mod, ONLY: cre_var, put_var1, put_var2, err, modname, fil
     20    USE comvert_mod, ONLY: ap, bp, presnivs, pa, preff, nivsig, nivsigs
     21    USE comconst_mod, ONLY: cpp, daysec, dtvr, g, kappa, omeg, rad
     22    USE logic_mod, ONLY: fxyhypb, ysinus
     23    USE serre_mod, ONLY: clon, clat, grossismx, grossismy, dzoomx, dzoomy, &
     24            taux, tauy
     25    USE temps_mod, ONLY: annee_ref, day_ref, itau_dyn, itaufin, start_time
     26    USE ener_mod, ONLY: etot0, ptot0, ztot0, stot0, ang0
     27    USE lmdz_description, ONLY: descript
     28    USE lmdz_iniprint, ONLY: lunout, prt_level
     29    USE lmdz_comgeom2
     30
     31    USE lmdz_dimensions, ONLY: iim, jjm, llm, ndm
     32    USE lmdz_paramet
     33    IMPLICIT NONE
     34
     35
     36    !===============================================================================
     37    ! Arguments:
     38    CHARACTER(LEN = *), INTENT(IN) :: fichnom          !--- FILE NAME
     39    INTEGER, INTENT(IN) :: iday_end         !---
     40    REAL, INTENT(IN) :: phis(iip1, jjp1) !--- GROUND GEOPOTENTIAL
     41    !===============================================================================
     42    ! Local variables:
     43    INTEGER :: iq
     44    INTEGER, PARAMETER :: length = 100
     45    REAL :: tab_cntrl(length)                     !--- RUN PARAMETERS TABLE
     46    !   For NetCDF:
     47    CHARACTER(LEN = maxlen) :: unites
     48    INTEGER :: indexID
     49    INTEGER :: rlonuID, rlonvID, rlatuID, rlatvID
     50    INTEGER :: sID, sigID, nID, timID
     51    INTEGER :: yyears0, jjour0, mmois0
     52    REAL :: zjulian, hours
     53    !===============================================================================
     54    modname = 'dynredem0'; fil = fichnom
     55    CALL ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
     56    CALL ju2ymds(zjulian, yyears0, mmois0, jjour0, hours)
     57
     58    tab_cntrl(:) = 0.
     59    tab_cntrl(1) = REAL(iim)
     60    tab_cntrl(2) = REAL(jjm)
     61    tab_cntrl(3) = REAL(llm)
     62    tab_cntrl(4) = REAL(day_ref)
     63    tab_cntrl(5) = REAL(annee_ref)
     64    tab_cntrl(6) = rad
     65    tab_cntrl(7) = omeg
     66    tab_cntrl(8) = g
     67    tab_cntrl(9) = cpp
     68    tab_cntrl(10) = kappa
     69    tab_cntrl(11) = daysec
     70    tab_cntrl(12) = dtvr
     71    tab_cntrl(13) = etot0
     72    tab_cntrl(14) = ptot0
     73    tab_cntrl(15) = ztot0
     74    tab_cntrl(16) = stot0
     75    tab_cntrl(17) = ang0
     76    tab_cntrl(18) = pa
     77    tab_cntrl(19) = preff
     78
     79    !    .....    parameters for zoom    ......
     80    tab_cntrl(20) = clon
     81    tab_cntrl(21) = clat
     82    tab_cntrl(22) = grossismx
     83    tab_cntrl(23) = grossismy
     84
     85    IF (fxyhypb)   THEN
     86      tab_cntrl(24) = 1.
     87      tab_cntrl(25) = dzoomx
     88      tab_cntrl(26) = dzoomy
     89      tab_cntrl(27) = 0.
     90      tab_cntrl(28) = taux
     91      tab_cntrl(29) = tauy
     92    ELSE
     93      tab_cntrl(24) = 0.
     94      tab_cntrl(25) = dzoomx
     95      tab_cntrl(26) = dzoomy
     96      tab_cntrl(27) = 0.
     97      tab_cntrl(28) = 0.
     98      tab_cntrl(29) = 0.
     99      IF(ysinus)  tab_cntrl(27) = 1.
     100    END IF
     101    tab_cntrl(30) = REAL(iday_end)
     102    tab_cntrl(31) = REAL(itau_dyn + itaufin)
     103    ! start_time: start_time of simulation (not necessarily 0.)
     104    tab_cntrl(32) = start_time
     105
     106    !--- File creation
     107    CALL err(nf90_create(fichnom, IOR(nf90_clobber, nf90_64bit_offset), nid))
     108
     109    !--- Some global attributes
     110    CALL err(nf90_put_att(nid, nf90_global, "title", "Fichier demarrage dynamique"))
     111
     112    !--- Dimensions
     113    CALL err(nf90_def_dim(nid, "index", length, indexID))
     114    CALL err(nf90_def_dim(nid, "rlonu", iip1, rlonuID))
     115    CALL err(nf90_def_dim(nid, "rlatu", jjp1, rlatuID))
     116    CALL err(nf90_def_dim(nid, "rlonv", iip1, rlonvID))
     117    CALL err(nf90_def_dim(nid, "rlatv", jjm, rlatvID))
     118    CALL err(nf90_def_dim(nid, "sigs", llm, sID))
     119    CALL err(nf90_def_dim(nid, "sig", llmp1, sigID))
     120    CALL err(nf90_def_dim(nid, "temps", nf90_unlimited, timID))
     121
     122    !--- Define and save invariant fields
     123    CALL put_var1(nid, "controle", "Parametres de controle", [indexID], tab_cntrl)
     124    CALL put_var1(nid, "rlonu", "Longitudes des points U", [rlonuID], rlonu)
     125    CALL put_var1(nid, "rlatu", "Latitudes des points U", [rlatuID], rlatu)
     126    CALL put_var1(nid, "rlonv", "Longitudes des points V", [rlonvID], rlonv)
     127    CALL put_var1(nid, "rlatv", "Latitudes des points V", [rlatvID], rlatv)
     128    CALL put_var1(nid, "nivsigs", "Numero naturel des couches s", [sID], nivsigs)
     129    CALL put_var1(nid, "nivsig", "Numero naturel des couches sigma", [sigID], nivsig)
     130    CALL put_var1(nid, "ap", "Coefficient A pour hybride", [sigID], ap)
     131    CALL put_var1(nid, "bp", "Coefficient B pour hybride", [sigID], bp)
     132    CALL put_var1(nid, "presnivs", "", [sID], presnivs)
     133    ! covariant <-> contravariant <-> natural conversion coefficients
     134    CALL put_var2(nid, "cu", "Coefficient de passage pour U", [rlonuID, rlatuID], cu)
     135    CALL put_var2(nid, "cv", "Coefficient de passage pour V", [rlonvID, rlatvID], cv)
     136    CALL put_var2(nid, "aire", "Aires de chaque maille", [rlonvID, rlatuID], aire)
     137    CALL put_var2(nid, "phisinit", "Geopotentiel au sol", [rlonvID, rlatuID], phis)
     138
     139    !--- Define fields saved later
     140    WRITE(unites, "('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')") &
     141            yyears0, mmois0, jjour0
     142    CALL cre_var(nid, "temps", "Temps de simulation", [timID], unites)
     143    CALL cre_var(nid, "ucov", "Vitesse U", [rlonuID, rlatuID, sID, timID])
     144    CALL cre_var(nid, "vcov", "Vitesse V", [rlonvID, rlatvID, sID, timID])
     145    CALL cre_var(nid, "teta", "Temperature", [rlonvID, rlatuID, sID, timID])
     146    DO iq = 1, nqtot
     147      CALL cre_var(nid, tracers(iq)%name, tracers(iq)%longName, [rlonvID, rlatuID, sID, timID])
     148    END DO
     149    CALL cre_var(nid, "masse", "Masse d air", [rlonvID, rlatuID, sID, timID])
     150    CALL cre_var(nid, "ps", "Pression au sol", [rlonvID, rlatuID, timID])
     151    CALL err(nf90_close (nid))
     152
     153    WRITE(lunout, *)TRIM(modname) // ': iim,jjm,llm,iday_end', iim, jjm, llm, iday_end
     154    WRITE(lunout, *)TRIM(modname) // ': rad,omeg,g,cpp,kappa', rad, omeg, g, cpp, kappa
     155
     156  END SUBROUTINE dynredem0
    2157
    3158  !-------------------------------------------------------------------------------
    4   ! Write the NetCDF restart file (initialization).
     159
     160
    5161  !-------------------------------------------------------------------------------
    6   USE IOIPSL
    7   USE lmdz_strings, ONLY: maxlen
    8   USE lmdz_infotrac, ONLY: nqtot, tracers
    9   USE netcdf, ONLY: nf90_create, nf90_def_dim, nf90_inq_varid, nf90_global, &
    10           nf90_close, nf90_put_att, nf90_unlimited, nf90_clobber, &
    11           nf90_64bit_offset
    12   USE dynredem_mod, ONLY: cre_var, put_var1, put_var2, err, modname, fil
    13   USE comvert_mod, ONLY: ap, bp, presnivs, pa, preff, nivsig, nivsigs
    14   USE comconst_mod, ONLY: cpp, daysec, dtvr, g, kappa, omeg, rad
    15   USE logic_mod, ONLY: fxyhypb, ysinus
    16   USE serre_mod, ONLY: clon, clat, grossismx, grossismy, dzoomx, dzoomy, &
    17           taux, tauy
    18   USE temps_mod, ONLY: annee_ref, day_ref, itau_dyn, itaufin, start_time
    19   USE ener_mod, ONLY: etot0, ptot0, ztot0, stot0, ang0
    20   USE lmdz_description, ONLY: descript
    21   USE lmdz_iniprint, ONLY: lunout, prt_level
    22   USE lmdz_comgeom2
    23 
    24 USE lmdz_dimensions, ONLY: iim, jjm, llm, ndm
    25   USE lmdz_paramet
    26   IMPLICIT NONE
    27 
    28 
    29   !===============================================================================
    30   ! Arguments:
    31   CHARACTER(LEN = *), INTENT(IN) :: fichnom          !--- FILE NAME
    32   INTEGER, INTENT(IN) :: iday_end         !---
    33   REAL, INTENT(IN) :: phis(iip1, jjp1) !--- GROUND GEOPOTENTIAL
    34   !===============================================================================
    35   ! Local variables:
    36   INTEGER :: iq
    37   INTEGER, PARAMETER :: length = 100
    38   REAL :: tab_cntrl(length)                     !--- RUN PARAMETERS TABLE
    39   !   For NetCDF:
    40   CHARACTER(LEN = maxlen) :: unites
    41   INTEGER :: indexID
    42   INTEGER :: rlonuID, rlonvID, rlatuID, rlatvID
    43   INTEGER :: sID, sigID, nID, timID
    44   INTEGER :: yyears0, jjour0, mmois0
    45   REAL :: zjulian, hours
    46   !===============================================================================
    47   modname = 'dynredem0'; fil = fichnom
    48   CALL ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
    49   CALL ju2ymds(zjulian, yyears0, mmois0, jjour0, hours)
    50 
    51   tab_cntrl(:) = 0.
    52   tab_cntrl(1) = REAL(iim)
    53   tab_cntrl(2) = REAL(jjm)
    54   tab_cntrl(3) = REAL(llm)
    55   tab_cntrl(4) = REAL(day_ref)
    56   tab_cntrl(5) = REAL(annee_ref)
    57   tab_cntrl(6) = rad
    58   tab_cntrl(7) = omeg
    59   tab_cntrl(8) = g
    60   tab_cntrl(9) = cpp
    61   tab_cntrl(10) = kappa
    62   tab_cntrl(11) = daysec
    63   tab_cntrl(12) = dtvr
    64   tab_cntrl(13) = etot0
    65   tab_cntrl(14) = ptot0
    66   tab_cntrl(15) = ztot0
    67   tab_cntrl(16) = stot0
    68   tab_cntrl(17) = ang0
    69   tab_cntrl(18) = pa
    70   tab_cntrl(19) = preff
    71 
    72   !    .....    parameters for zoom    ......
    73   tab_cntrl(20) = clon
    74   tab_cntrl(21) = clat
    75   tab_cntrl(22) = grossismx
    76   tab_cntrl(23) = grossismy
    77 
    78   IF (fxyhypb)   THEN
    79     tab_cntrl(24) = 1.
    80     tab_cntrl(25) = dzoomx
    81     tab_cntrl(26) = dzoomy
    82     tab_cntrl(27) = 0.
    83     tab_cntrl(28) = taux
    84     tab_cntrl(29) = tauy
    85   ELSE
    86     tab_cntrl(24) = 0.
    87     tab_cntrl(25) = dzoomx
    88     tab_cntrl(26) = dzoomy
    89     tab_cntrl(27) = 0.
    90     tab_cntrl(28) = 0.
    91     tab_cntrl(29) = 0.
    92     IF(ysinus)  tab_cntrl(27) = 1.
    93   END IF
    94   tab_cntrl(30) = REAL(iday_end)
    95   tab_cntrl(31) = REAL(itau_dyn + itaufin)
    96   ! start_time: start_time of simulation (not necessarily 0.)
    97   tab_cntrl(32) = start_time
    98 
    99   !--- File creation
    100   CALL err(nf90_create(fichnom, IOR(nf90_clobber, nf90_64bit_offset), nid))
    101 
    102   !--- Some global attributes
    103   CALL err(nf90_put_att(nid, nf90_global, "title", "Fichier demarrage dynamique"))
    104 
    105   !--- Dimensions
    106   CALL err(nf90_def_dim(nid, "index", length, indexID))
    107   CALL err(nf90_def_dim(nid, "rlonu", iip1, rlonuID))
    108   CALL err(nf90_def_dim(nid, "rlatu", jjp1, rlatuID))
    109   CALL err(nf90_def_dim(nid, "rlonv", iip1, rlonvID))
    110   CALL err(nf90_def_dim(nid, "rlatv", jjm, rlatvID))
    111   CALL err(nf90_def_dim(nid, "sigs", llm, sID))
    112   CALL err(nf90_def_dim(nid, "sig", llmp1, sigID))
    113   CALL err(nf90_def_dim(nid, "temps", nf90_unlimited, timID))
    114 
    115   !--- Define and save invariant fields
    116   CALL put_var1(nid, "controle", "Parametres de controle", [indexID], tab_cntrl)
    117   CALL put_var1(nid, "rlonu", "Longitudes des points U", [rlonuID], rlonu)
    118   CALL put_var1(nid, "rlatu", "Latitudes des points U", [rlatuID], rlatu)
    119   CALL put_var1(nid, "rlonv", "Longitudes des points V", [rlonvID], rlonv)
    120   CALL put_var1(nid, "rlatv", "Latitudes des points V", [rlatvID], rlatv)
    121   CALL put_var1(nid, "nivsigs", "Numero naturel des couches s", [sID], nivsigs)
    122   CALL put_var1(nid, "nivsig", "Numero naturel des couches sigma", [sigID], nivsig)
    123   CALL put_var1(nid, "ap", "Coefficient A pour hybride", [sigID], ap)
    124   CALL put_var1(nid, "bp", "Coefficient B pour hybride", [sigID], bp)
    125   CALL put_var1(nid, "presnivs", "", [sID], presnivs)
    126   ! covariant <-> contravariant <-> natural conversion coefficients
    127   CALL put_var2(nid, "cu", "Coefficient de passage pour U", [rlonuID, rlatuID], cu)
    128   CALL put_var2(nid, "cv", "Coefficient de passage pour V", [rlonvID, rlatvID], cv)
    129   CALL put_var2(nid, "aire", "Aires de chaque maille", [rlonvID, rlatuID], aire)
    130   CALL put_var2(nid, "phisinit", "Geopotentiel au sol", [rlonvID, rlatuID], phis)
    131 
    132   !--- Define fields saved later
    133   WRITE(unites, "('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')") &
    134           yyears0, mmois0, jjour0
    135   CALL cre_var(nid, "temps", "Temps de simulation", [timID], unites)
    136   CALL cre_var(nid, "ucov", "Vitesse U", [rlonuID, rlatuID, sID, timID])
    137   CALL cre_var(nid, "vcov", "Vitesse V", [rlonvID, rlatvID, sID, timID])
    138   CALL cre_var(nid, "teta", "Temperature", [rlonvID, rlatuID, sID, timID])
    139   DO iq = 1, nqtot
    140     CALL cre_var(nid, tracers(iq)%name, tracers(iq)%longName, [rlonvID, rlatuID, sID, timID])
    141   END DO
    142   CALL cre_var(nid, "masse", "Masse d air", [rlonvID, rlatuID, sID, timID])
    143   CALL cre_var(nid, "ps", "Pression au sol", [rlonvID, rlatuID, timID])
    144   CALL err(nf90_close (nid))
    145 
    146   WRITE(lunout, *)TRIM(modname) // ': iim,jjm,llm,iday_end', iim, jjm, llm, iday_end
    147   WRITE(lunout, *)TRIM(modname) // ': rad,omeg,g,cpp,kappa', rad, omeg, g, cpp, kappa
    148 
    149 END SUBROUTINE dynredem0
    150 
    151 !-------------------------------------------------------------------------------
    152 
    153 
    154 !-------------------------------------------------------------------------------
    155 
    156 SUBROUTINE dynredem1(fichnom, time, vcov, ucov, teta, q, masse, ps)
    157 
    158   !-------------------------------------------------------------------------------
    159   ! Purpose: Write the NetCDF restart file (append).
    160   !-------------------------------------------------------------------------------
    161   USE lmdz_strings, ONLY: maxlen
    162   USE lmdz_infotrac, ONLY: nqtot, tracers, type_trac
    163   USE control_mod
    164   USE netcdf, ONLY: nf90_open, nf90_nowrite, nf90_get_var, nf90_inq_varid, &
    165           nf90_close, nf90_write, nf90_put_var, nf90_noerr
    166   USE dynredem_mod, ONLY: dynredem_write_u, dynredem_write_v, dynredem_read_u, &
    167           err, modname, fil, msg
    168   USE temps_mod, ONLY: itau_dyn, itaufin
    169   USE lmdz_description, ONLY: descript
    170   USE lmdz_iniprint, ONLY: lunout, prt_level
    171   USE lmdz_comgeom
    172 
    173 USE lmdz_dimensions, ONLY: iim, jjm, llm, ndm
    174   USE lmdz_paramet
    175   IMPLICIT NONE
    176 
    177 
    178   !===============================================================================
    179   ! Arguments:
    180   CHARACTER(LEN = *), INTENT(IN) :: fichnom              !-- FILE NAME
    181   REAL, INTENT(IN) :: time                         !-- TIME
    182   REAL, INTENT(IN) :: vcov(iip1, jjm, llm)          !-- V COVARIANT WIND
    183   REAL, INTENT(IN) :: ucov(iip1, jjp1, llm)          !-- U COVARIANT WIND
    184   REAL, INTENT(IN) :: teta(iip1, jjp1, llm)          !-- POTENTIAL TEMPERATURE
    185   REAL, INTENT(INOUT) :: q(iip1, jjp1, llm, nqtot)    !-- TRACERS
    186   REAL, INTENT(IN) :: masse(iip1, jjp1, llm)          !-- MASS PER CELL
    187   REAL, INTENT(IN) :: ps(iip1, jjp1)              !-- GROUND PRESSURE
    188   !===============================================================================
    189   ! Local variables:
    190   INTEGER :: iq, nid, vID, ierr, nid_trac, vID_trac
    191   INTEGER, SAVE :: nb = 0
    192   INTEGER, PARAMETER :: length = 100
    193   REAL :: tab_cntrl(length) ! tableau des parametres du run
    194   CHARACTER(LEN = maxlen) :: var, dum
    195   LOGICAL :: lread_inca
    196   !===============================================================================
    197 
    198   modname = 'dynredem1'; fil = fichnom
    199   CALL err(nf90_open(fil, nf90_write, nid), "open", fil)
    200 
    201   !--- Write/extend time coordinate
    202   nb = nb + 1
    203   var = "temps"
    204   CALL err(nf90_inq_varid(nid, var, vID), "inq", var)
    205   CALL err(nf90_put_var(nid, vID, [time]), "put", var)
    206   WRITE(lunout, *)TRIM(modname) // ": Saving for ", nb, time
    207 
    208   !--- Rewrite control table (itaufin undefined in dynredem0)
    209   var = "controle"
    210   CALL err(nf90_inq_varid(nid, var, vID), "inq", var)
    211   CALL err(nf90_get_var(nid, vID, tab_cntrl), "get", var)
    212   tab_cntrl(31) = DBLE(itau_dyn + itaufin)
    213   CALL err(nf90_inq_varid(nid, var, vID), "inq", var)
    214   CALL err(nf90_put_var(nid, vID, tab_cntrl), "put", var)
    215 
    216   !--- Save fields
    217   CALL dynredem_write_u(nid, "ucov", ucov, llm)
    218   CALL dynredem_write_v(nid, "vcov", vcov, llm)
    219   CALL dynredem_write_u(nid, "teta", teta, llm)
    220   CALL dynredem_write_u(nid, "masse", masse, llm)
    221   CALL dynredem_write_u(nid, "ps", ps, 1)
    222 
    223   !--- Tracers in file "start_trac.nc" (added by Anne)
    224   lread_inca = .FALSE.; fil = "start_trac.nc"
    225   IF(ANY(type_trac == ['inca', 'inco'])) INQUIRE(FILE = fil, EXIST = lread_inca)
    226   IF(lread_inca) CALL err(nf90_open(fil, nf90_nowrite, nid_trac), "open")
    227 
    228   !--- Save tracers
    229   DO iq = 1, nqtot; var = TRIM(tracers(iq)%name); ierr = -1
    230   IF(lread_inca) THEN                  !--- Possibly read from "start_trac.nc"
     162
     163  SUBROUTINE dynredem1(fichnom, time, vcov, ucov, teta, q, masse, ps)
     164
     165    !-------------------------------------------------------------------------------
     166    ! Purpose: Write the NetCDF restart file (append).
     167    !-------------------------------------------------------------------------------
     168    USE lmdz_strings, ONLY: maxlen
     169    USE lmdz_infotrac, ONLY: nqtot, tracers, type_trac
     170    USE control_mod
     171    USE netcdf, ONLY: nf90_open, nf90_nowrite, nf90_get_var, nf90_inq_varid, &
     172            nf90_close, nf90_write, nf90_put_var, nf90_noerr
     173    USE dynredem_mod, ONLY: dynredem_write_u, dynredem_write_v, dynredem_read_u, &
     174            err, modname, fil, msg
     175    USE temps_mod, ONLY: itau_dyn, itaufin
     176    USE lmdz_description, ONLY: descript
     177    USE lmdz_iniprint, ONLY: lunout, prt_level
     178    USE lmdz_comgeom
     179
     180    USE lmdz_dimensions, ONLY: iim, jjm, llm, ndm
     181    USE lmdz_paramet
     182    IMPLICIT NONE
     183
     184
     185    !===============================================================================
     186    ! Arguments:
     187    CHARACTER(LEN = *), INTENT(IN) :: fichnom              !-- FILE NAME
     188    REAL, INTENT(IN) :: time                         !-- TIME
     189    REAL, INTENT(IN) :: vcov(iip1, jjm, llm)          !-- V COVARIANT WIND
     190    REAL, INTENT(IN) :: ucov(iip1, jjp1, llm)          !-- U COVARIANT WIND
     191    REAL, INTENT(IN) :: teta(iip1, jjp1, llm)          !-- POTENTIAL TEMPERATURE
     192    REAL, INTENT(INOUT) :: q(iip1, jjp1, llm, nqtot)    !-- TRACERS
     193    REAL, INTENT(IN) :: masse(iip1, jjp1, llm)          !-- MASS PER CELL
     194    REAL, INTENT(IN) :: ps(iip1, jjp1)              !-- GROUND PRESSURE
     195    !===============================================================================
     196    ! Local variables:
     197    INTEGER :: iq, nid, vID, ierr, nid_trac, vID_trac
     198    INTEGER, SAVE :: nb = 0
     199    INTEGER, PARAMETER :: length = 100
     200    REAL :: tab_cntrl(length) ! tableau des parametres du run
     201    CHARACTER(LEN = maxlen) :: var, dum
     202    LOGICAL :: lread_inca
     203    !===============================================================================
     204
     205    modname = 'dynredem1'; fil = fichnom
     206    CALL err(nf90_open(fil, nf90_write, nid), "open", fil)
     207
     208    !--- Write/extend time coordinate
     209    nb = nb + 1
     210    var = "temps"
     211    CALL err(nf90_inq_varid(nid, var, vID), "inq", var)
     212    CALL err(nf90_put_var(nid, vID, [time]), "put", var)
     213    WRITE(lunout, *)TRIM(modname) // ": Saving for ", nb, time
     214
     215    !--- Rewrite control table (itaufin undefined in dynredem0)
     216    var = "controle"
     217    CALL err(nf90_inq_varid(nid, var, vID), "inq", var)
     218    CALL err(nf90_get_var(nid, vID, tab_cntrl), "get", var)
     219    tab_cntrl(31) = DBLE(itau_dyn + itaufin)
     220    CALL err(nf90_inq_varid(nid, var, vID), "inq", var)
     221    CALL err(nf90_put_var(nid, vID, tab_cntrl), "put", var)
     222
     223    !--- Save fields
     224    CALL dynredem_write_u(nid, "ucov", ucov, llm)
     225    CALL dynredem_write_v(nid, "vcov", vcov, llm)
     226    CALL dynredem_write_u(nid, "teta", teta, llm)
     227    CALL dynredem_write_u(nid, "masse", masse, llm)
     228    CALL dynredem_write_u(nid, "ps", ps, 1)
     229
     230    !--- Tracers in file "start_trac.nc" (added by Anne)
     231    lread_inca = .FALSE.; fil = "start_trac.nc"
     232    IF(ANY(type_trac == ['inca', 'inco'])) INQUIRE(FILE = fil, EXIST = lread_inca)
     233    IF(lread_inca) CALL err(nf90_open(fil, nf90_nowrite, nid_trac), "open")
     234
     235    !--- Save tracers
     236    DO iq = 1, nqtot; var = TRIM(tracers(iq)%name); ierr = -1
     237    IF(lread_inca) THEN                  !--- Possibly read from "start_trac.nc"
     238      fil = "start_trac.nc"
     239      ierr = nf90_inq_varid(nid_trac, var, vID_trac)
     240      dum = 'inq'; IF(ierr==nf90_noerr) dum = 'fnd'
     241      WRITE(lunout, *)msg(dum, var)
     242
     243      IF(ierr==nf90_noerr) CALL dynredem_read_u(nid_trac, var, q(:, :, :, iq), llm)
     244    END IF
     245    fil = fichnom
     246    CALL dynredem_write_u(nid, var, q(:, :, :, iq), llm)
     247    END DO
     248    CALL err(nf90_close(nid), "close")
    231249    fil = "start_trac.nc"
    232     ierr = nf90_inq_varid(nid_trac, var, vID_trac)
    233     dum = 'inq'; IF(ierr==nf90_noerr) dum = 'fnd'
    234     WRITE(lunout, *)msg(dum, var)
    235 
    236     IF(ierr==nf90_noerr) CALL dynredem_read_u(nid_trac, var, q(:, :, :, iq), llm)
    237   END IF
    238   fil = fichnom
    239   CALL dynredem_write_u(nid, var, q(:, :, :, iq), llm)
    240   END DO
    241   CALL err(nf90_close(nid), "close")
    242   fil = "start_trac.nc"
    243   IF(lread_inca) CALL err(nf90_close(nid_trac), "close")
    244 
    245 END SUBROUTINE dynredem1
    246 
     250    IF(lread_inca) CALL err(nf90_close(nid_trac), "close")
     251
     252  END SUBROUTINE dynredem1
     253
     254END MODULE lmdz_dynredem
Note: See TracChangeset for help on using the changeset viewer.