source: LMDZ6/trunk/libf/dyn3d/dynredem.f90 @ 5445

Last change on this file since 5445 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
RevLine 
[2293]1SUBROUTINE dynredem0(fichnom,iday_end,phis)
2!
3!-------------------------------------------------------------------------------
4! Write the NetCDF restart file (initialization).
5!-------------------------------------------------------------------------------
6  USE IOIPSL
[4063]7  USE strings_mod, ONLY: maxlen
8  USE infotrac, ONLY: nqtot, tracers
[5084]9  USE netcdf, ONLY: NF90_CREATE, NF90_DEF_DIM, NF90_INQ_VARID, NF90_GLOBAL,    &
[3803]10                    NF90_CLOSE,  NF90_PUT_ATT, NF90_UNLIMITED, NF90_CLOBBER,   &
11                    NF90_64BIT_OFFSET
[2299]12  USE dynredem_mod, ONLY: cre_var, put_var1, put_var2, err, modname, fil
[4064]13  USE comvert_mod,  ONLY: ap, bp, presnivs, pa, preff, nivsig, nivsigs
[2597]14  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, kappa, omeg, rad
[2603]15  USE logic_mod, ONLY: fxyhypb, ysinus
[2598]16  USE serre_mod, ONLY: clon,clat,grossismx,grossismy,dzoomx,dzoomy, &
[2600]17                              taux,tauy
[2601]18  USE temps_mod, ONLY: annee_ref, day_ref, itau_dyn, itaufin, start_time
[2622]19  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
[5281]20
[5271]21  USE dimensions_mod, ONLY: iim, jjm, llm, ndm
[5285]22  USE paramet_mod_h
[5281]23  USE comgeom2_mod_h
[5282]24  USE iniprint_mod_h
[5271]25IMPLICIT NONE
26
[5282]27  !===============================================================================
[2293]28! Arguments:
29  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
[5281]30  INTEGER,          INTENT(IN) :: iday_end         !---
[2293]31  REAL,             INTENT(IN) :: phis(iip1, jjp1) !--- GROUND GEOPOTENTIAL
32!===============================================================================
33! Local variables:
[4064]34  INTEGER :: iq
[2293]35  INTEGER, PARAMETER :: length=100
36  REAL    :: tab_cntrl(length)                     !--- RUN PARAMETERS TABLE
37!   For NetCDF:
[4046]38  CHARACTER(LEN=maxlen) :: unites
[2293]39  INTEGER :: indexID
40  INTEGER :: rlonuID, rlonvID, rlatuID, rlatvID
[4064]41  INTEGER :: sID, sigID, nID, timID
[2293]42  INTEGER :: yyears0, jjour0, mmois0
[4064]43  REAL    :: zjulian, hours
[2293]44!===============================================================================
[2299]45  modname='dynredem0'; fil=fichnom
[2293]46  CALL ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
47  CALL ju2ymds(zjulian, yyears0, mmois0, jjour0, hours)
48
[5267]49
[2293]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
[5281]71!    .....    parameters for zoom    ......
[2293]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
[3803]99  CALL err(NF90_CREATE(fichnom,IOR(NF90_CLOBBER,NF90_64BIT_OFFSET),nid))
[2293]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
[2299]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)
[2293]125! covariant <-> contravariant <-> natural conversion coefficients
[2299]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)
[2293]130
131!--- Define fields saved later
[4064]132  WRITE(unites,"('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')") &
[2293]133               yyears0,mmois0,jjour0
[2299]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])
[2293]138  DO iq=1,nqtot
[4046]139    CALL cre_var(nid,tracers(iq)%name,tracers(iq)%longName,[rlonvID,rlatuID,sID,timID])
[2293]140  END DO
[2299]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])
[2293]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!-------------------------------------------------------------------------------
[4063]160  USE strings_mod, ONLY: maxlen
[4389]161  USE infotrac, ONLY: nqtot, tracers, type_trac
[2293]162  USE control_mod
[5084]163  USE netcdf,   ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_GET_VAR, NF90_INQ_VARID,  &
[2299]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
[2601]167  USE temps_mod, ONLY: itau_dyn, itaufin
[5281]168
[5271]169  USE dimensions_mod, ONLY: iim, jjm, llm, ndm
[5285]170  USE paramet_mod_h
[5281]171  USE comgeom_mod_h
[5282]172  USE iniprint_mod_h
[5271]173IMPLICIT NONE
174
[5272]175
[5282]176  !===============================================================================
[2293]177! Arguments:
[2299]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
[2293]186!===============================================================================
187! Local variables:
[4064]188  INTEGER :: iq, nid, vID, ierr, nid_trac, vID_trac
[2293]189  INTEGER, SAVE :: nb=0
190  INTEGER, PARAMETER :: length=100
191  REAL               :: tab_cntrl(length) ! tableau des parametres du run
[4046]192  CHARACTER(LEN=maxlen) :: var, dum
[2299]193  LOGICAL            :: lread_inca
[2293]194!===============================================================================
[2299]195
196  modname='dynredem1'; fil=fichnom
[2293]197  CALL err(NF90_OPEN(fil,NF90_WRITE,nid),"open",fil)
198
199!--- Write/extend time coordinate
200  nb = nb + 1
[2299]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)
[2293]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)
[2299]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)
[2293]213
214!--- Save fields
[2299]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)
[2293]220
221!--- Tracers in file "start_trac.nc" (added by Anne)
[2299]222  lread_inca=.FALSE.; fil="start_trac.nc"
[4389]223  IF(ANY(type_trac == ['inca','inco'])) INQUIRE(FILE=fil,EXIST=lread_inca)
[2299]224  IF(lread_inca) CALL err(NF90_OPEN(fil,NF90_NOWRITE,nid_trac),"open")
[2293]225
[2299]226!--- Save tracers
[4046]227  DO iq=1,nqtot; var=TRIM(tracers(iq)%name); ierr=-1
[2299]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)
[2293]233
[2299]234
235      IF(ierr==NF90_NoErr) CALL dynredem_read_u(nid_trac,var,q(:,:,:,iq),llm)
[2293]236    END IF
[2299]237    fil=fichnom
238    CALL dynredem_write_u(nid,var,q(:,:,:,iq),llm)
[2293]239  END DO
[2299]240  CALL err(NF90_CLOSE(nid),"close")
241  fil="start_trac.nc"
242  IF(lread_inca) CALL err(NF90_CLOSE(nid_trac),"close")
[2293]243
244END SUBROUTINE dynredem1
245
Note: See TracBrowser for help on using the repository browser.