source: LMDZ6/branches/contrails/libf/dyn3d/dynredem.f90 @ 5442

Last change on this file since 5442 was 5285, checked in by abarral, 8 weeks ago

As discussed internally, remove generic ONLY: ... for new _mod_h modules

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