source: LMDZ5/branches/IPSLCM5A2.1/libf/dyn3d/dynredem.F90 @ 5083

Last change on this file since 5083 was 2603, checked in by Ehouarn Millour, 8 years ago

Cleanup in the dynamics: turn logic.h into module logic_mod.F90
EM

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