source: LMDZ6/branches/LMDZ-tracers/libf/dyn3d/dynredem.F90 @ 4157

Last change on this file since 4157 was 3852, checked in by dcugnet, 4 years ago

Extension of the tracers management.

The tracers files can be:

1) "traceur.def": old format, with:

  • the number of tracers on the first line
  • one line for each tracer: <tracer name> <hadv> <vadv> [<parent name>]

2) "tracer.def": new format with one section each model component.
3) "tracer_<name>.def": new format with a single section.

The formats 2 and 3 reading is driven by the "type_trac" key, which can be a

coma-separated list of components.

  • Format 2: read the sections from the "tracer.def" file.
  • format 3: read one section each "tracer_<section name>.def" file.
  • the first line of a section is "&<section name>
  • the other lines start with a tracer name followed by <key>=<val> pairs.
  • the "default" tracer name is reserved ; the other tracers of the section inherit its <key>=<val>, except for the keys that are redefined locally.

This format helps keeping the tracers files compact, thanks to the "default"
special tracer and the three levels of factorization:

  • on the tracers names: a tracer name can be a coma-separated list of tracers => all the tracers of the list have the same <key>=<val> properties
  • on the parents names: the value of the "parent" property can be a coma-separated list of tracers => only possible for geographic tagging tracers
  • on the phases: the property "phases" is [g](l][s] (gas/liquid/solid)

Read information is stored in the vector "tracers(:)", of derived type "tra".

"isotopes_params.def" is a similar file, with one section each isotopes family.
It contains a database of isotopes properties ; if there are second generation
tracers (isotopes), the corresponding sections are read.

Read information is stored in the vector "isotopes(:)", of derived type "iso".

The "getKey" function helps to get the values of the parameters stored in
"tracers" or "isotopes".

File size: 9.8 KB
RevLine 
[2293]1SUBROUTINE dynredem0(fichnom,iday_end,phis)
2!
3!-------------------------------------------------------------------------------
4! Write the NetCDF restart file (initialization).
5!-------------------------------------------------------------------------------
6#ifdef CPP_IOIPSL
7  USE IOIPSL
8#endif
[3852]9  USE infotrac, ONLY: nqtot, tracers
[2299]10  USE netcdf, ONLY: NF90_CREATE, NF90_DEF_DIM, NF90_INQ_VARID, NF90_GLOBAL,    &
[3851]11                    NF90_CLOSE,  NF90_PUT_ATT, NF90_UNLIMITED, NF90_CLOBBER,   &
12                    NF90_64BIT_OFFSET
[2299]13  USE dynredem_mod, ONLY: cre_var, put_var1, put_var2, err, modname, fil
[2600]14  USE comvert_mod, ONLY: ap,bp,aps,bps,presnivs,pseudoalt,pa,preff, &
15                              nivsig,nivsigs
[2597]16  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, kappa, omeg, rad
[2603]17  USE logic_mod, ONLY: fxyhypb, ysinus
[2598]18  USE serre_mod, ONLY: clon,clat,grossismx,grossismy,dzoomx,dzoomy, &
[2600]19                              taux,tauy
[2601]20  USE temps_mod, ONLY: annee_ref, day_ref, itau_dyn, itaufin, start_time
[2622]21  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
[2601]22 
[2293]23  IMPLICIT NONE
24  include "dimensions.h"
25  include "paramet.h"
26  include "comgeom2.h"
27  include "description.h"
28  include "iniprint.h"
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, l
37  INTEGER, PARAMETER :: length=100
38  REAL    :: tab_cntrl(length)                     !--- RUN PARAMETERS TABLE
39!   For NetCDF:
40  CHARACTER(LEN=30) :: unites
41  INTEGER :: indexID
42  INTEGER :: rlonuID, rlonvID, rlatuID, rlatvID
43  INTEGER :: sID, sigID, nID, vID, timID
44  INTEGER :: yyears0, jjour0, mmois0
[2299]45  REAL    :: zan0, zjulian, hours
[2293]46!===============================================================================
[2299]47  modname='dynredem0'; fil=fichnom
[2293]48#ifdef CPP_IOIPSL
49  CALL ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
50  CALL ju2ymds(zjulian, yyears0, mmois0, jjour0, hours)
51#else
52! set yyears0, mmois0, jjour0 to 0,1,1 (hours is not used)
53  yyears0=0
54  mmois0=1
55  jjour0=1
56#endif       
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
[3851]107  CALL err(NF90_CREATE(fichnom,IOR(NF90_CLOBBER,NF90_64BIT_OFFSET),nid))
[2293]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
[2299]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)
[2293]133! covariant <-> contravariant <-> natural conversion coefficients
[2299]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)
[2293]138
139!--- Define fields saved later
140  WRITE(unites,"('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')"),&
141               yyears0,mmois0,jjour0
[2299]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])
[2293]146  DO iq=1,nqtot
[3852]147    CALL cre_var(nid,tracers(iq)%name,tracers(iq)%lnam,[rlonvID,rlatuID,sID,timID])
[2293]148  END DO
[2299]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])
[2293]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
156END SUBROUTINE dynredem0
157!
158!-------------------------------------------------------------------------------
159
160
161!-------------------------------------------------------------------------------
162!
163SUBROUTINE dynredem1(fichnom,time,vcov,ucov,teta,q,masse,ps)
164!
165!-------------------------------------------------------------------------------
166! Purpose: Write the NetCDF restart file (append).
167!-------------------------------------------------------------------------------
[3852]168  USE infotrac, ONLY: nqtot, tracers, type_trac
[2293]169  USE control_mod
[2299]170  USE netcdf,   ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_GET_VAR, NF90_INQ_VARID,  &
171                      NF90_CLOSE, NF90_WRITE,   NF90_PUT_VAR, NF90_NoErr
172  USE dynredem_mod, ONLY: dynredem_write_u, dynredem_write_v, dynredem_read_u, &
173                          err, modname, fil, msg
[2601]174  USE temps_mod, ONLY: itau_dyn, itaufin
175 
[2293]176  IMPLICIT NONE
[2299]177  include "dimensions.h"
178  include "paramet.h"
179  include "description.h"
180  include "comgeom.h"
181  include "iniprint.h"
[2293]182!===============================================================================
183! Arguments:
[2299]184  CHARACTER(LEN=*), INTENT(IN) :: fichnom              !-- FILE NAME
185  REAL, INTENT(IN)    ::  time                         !-- TIME
186  REAL, INTENT(IN)    ::  vcov(iip1,jjm, llm)          !-- V COVARIANT WIND
187  REAL, INTENT(IN)    ::  ucov(iip1,jjp1,llm)          !-- U COVARIANT WIND
188  REAL, INTENT(IN)    ::  teta(iip1,jjp1,llm)          !-- POTENTIAL TEMPERATURE
189  REAL, INTENT(INOUT) ::     q(iip1,jjp1,llm,nqtot)    !-- TRACERS
190  REAL, INTENT(IN)    :: masse(iip1,jjp1,llm)          !-- MASS PER CELL
191  REAL, INTENT(IN)    ::    ps(iip1,jjp1)              !-- GROUND PRESSURE
[2293]192!===============================================================================
193! Local variables:
[2299]194  INTEGER :: l, iq, nid, vID, ierr, nid_trac, vID_trac
[2293]195  INTEGER, SAVE :: nb=0
196  INTEGER, PARAMETER :: length=100
197  REAL               :: tab_cntrl(length) ! tableau des parametres du run
[2299]198  CHARACTER(LEN=256) :: var, dum
199  LOGICAL            :: lread_inca
[2293]200!===============================================================================
[2299]201
202  modname='dynredem1'; fil=fichnom
[2293]203  CALL err(NF90_OPEN(fil,NF90_WRITE,nid),"open",fil)
204
205!--- Write/extend time coordinate
206  nb = nb + 1
[2299]207  var="temps"
208  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
209  CALL err(NF90_PUT_VAR(nid,vID,[time]),"put",var)
[2293]210  WRITE(lunout,*)TRIM(modname)//": Saving for ", nb, time
211
212!--- Rewrite control table (itaufin undefined in dynredem0)
213  var="controle"
214  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
[2299]215  CALL err(NF90_GET_VAR(nid,vID,tab_cntrl),"get",var)
216  tab_cntrl(31)=DBLE(itau_dyn + itaufin)
217  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
218  CALL err(NF90_PUT_VAR(nid,vID,tab_cntrl),"put",var)
[2293]219
220!--- Save fields
[2299]221  CALL dynredem_write_u(nid,"ucov" ,ucov ,llm)
222  CALL dynredem_write_v(nid,"vcov" ,vcov ,llm)
223  CALL dynredem_write_u(nid,"teta" ,teta ,llm)
224  CALL dynredem_write_u(nid,"masse",masse,llm)
225  CALL dynredem_write_u(nid,"ps"   ,ps   ,1)
[2293]226
227!--- Tracers in file "start_trac.nc" (added by Anne)
[3852]228  fil="start_trac.nc"
229  INQUIRE(FILE=fil, EXIST=lread_inca)
230  lread_inca = lread_inca .AND. type_trac == 'inca'
[2299]231  IF(lread_inca) CALL err(NF90_OPEN(fil,NF90_NOWRITE,nid_trac),"open")
[2293]232
[2299]233!--- Save tracers
[3852]234  DO iq=1,nqtot; var=tracers(iq)%name; ierr=-1
[2299]235    IF(lread_inca) THEN                  !--- Possibly read from "start_trac.nc"
236      fil="start_trac.nc"
237      ierr=NF90_INQ_VARID(nid_trac,var,vID_trac)
238      dum='inq'; IF(ierr==NF90_NoErr) dum='fnd'
239      WRITE(lunout,*)msg(dum,var)
240      IF(ierr==NF90_NoErr) CALL dynredem_read_u(nid_trac,var,q(:,:,:,iq),llm)
[2293]241    END IF
[2299]242    fil=fichnom
243    CALL dynredem_write_u(nid,var,q(:,:,:,iq),llm)
[2293]244  END DO
[2299]245  CALL err(NF90_CLOSE(nid),"close")
246  fil="start_trac.nc"
247  IF(lread_inca) CALL err(NF90_CLOSE(nid_trac),"close")
[2293]248
249END SUBROUTINE dynredem1
250
Note: See TracBrowser for help on using the repository browser.