source: LMDZ6/branches/Amaury_dev/libf/dyn3d/lmdz_dynredem.f90 @ 5218

Last change on this file since 5218 was 5192, checked in by abarral, 3 months ago

Remove obsolete lmdz_description.f90
Remove unused exner_hyb_m.F90 in 1D
Re-remove filtre from source in 1D makelmdz_fcm

File size: 10.3 KB
Line 
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_iniprint, ONLY: lunout, prt_level
28    USE lmdz_comgeom2
29
30    USE lmdz_dimensions, ONLY: iim, jjm, llm, ndm
31    USE lmdz_paramet
32    IMPLICIT NONE
33
34
35    !===============================================================================
36    ! Arguments:
37    CHARACTER(LEN = *), INTENT(IN) :: fichnom          !--- FILE NAME
38    INTEGER, INTENT(IN) :: iday_end         !---
39    REAL, INTENT(IN) :: phis(iip1, jjp1) !--- GROUND GEOPOTENTIAL
40    !===============================================================================
41    ! Local variables:
42    INTEGER :: iq
43    INTEGER, PARAMETER :: length = 100
44    REAL :: tab_cntrl(length)                     !--- RUN PARAMETERS TABLE
45    !   For NetCDF:
46    CHARACTER(LEN = maxlen) :: unites
47    INTEGER :: indexID
48    INTEGER :: rlonuID, rlonvID, rlatuID, rlatvID
49    INTEGER :: sID, sigID, nID, timID
50    INTEGER :: yyears0, jjour0, mmois0
51    REAL :: zjulian, hours
52    !===============================================================================
53    modname = 'dynredem0'; fil = fichnom
54    CALL ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
55    CALL ju2ymds(zjulian, yyears0, mmois0, jjour0, hours)
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, IOR(nf90_clobber, nf90_64bit_offset), 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, tracers(iq)%name, tracers(iq)%longName, [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
155  END SUBROUTINE dynredem0
156
157  !-------------------------------------------------------------------------------
158
159
160  !-------------------------------------------------------------------------------
161
162  SUBROUTINE dynredem1(fichnom, time, vcov, ucov, teta, q, masse, ps)
163
164    !-------------------------------------------------------------------------------
165    ! Purpose: Write the NetCDF restart file (append).
166    !-------------------------------------------------------------------------------
167    USE lmdz_strings, ONLY: maxlen
168    USE lmdz_infotrac, ONLY: nqtot, tracers, type_trac
169    USE control_mod
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
174    USE temps_mod, ONLY: itau_dyn, itaufin
175    USE lmdz_iniprint, ONLY: lunout, prt_level
176    USE lmdz_comgeom
177
178    USE lmdz_dimensions, ONLY: iim, jjm, llm, ndm
179    USE lmdz_paramet
180    IMPLICIT NONE
181
182
183    !===============================================================================
184    ! Arguments:
185    CHARACTER(LEN = *), INTENT(IN) :: fichnom              !-- FILE NAME
186    REAL, INTENT(IN) :: time                         !-- TIME
187    REAL, INTENT(IN) :: vcov(iip1, jjm, llm)          !-- V COVARIANT WIND
188    REAL, INTENT(IN) :: ucov(iip1, jjp1, llm)          !-- U COVARIANT WIND
189    REAL, INTENT(IN) :: teta(iip1, jjp1, llm)          !-- POTENTIAL TEMPERATURE
190    REAL, INTENT(INOUT) :: q(iip1, jjp1, llm, nqtot)    !-- TRACERS
191    REAL, INTENT(IN) :: masse(iip1, jjp1, llm)          !-- MASS PER CELL
192    REAL, INTENT(IN) :: ps(iip1, jjp1)              !-- GROUND PRESSURE
193    !===============================================================================
194    ! Local variables:
195    INTEGER :: iq, nid, vID, ierr, nid_trac, vID_trac
196    INTEGER, SAVE :: nb = 0
197    INTEGER, PARAMETER :: length = 100
198    REAL :: tab_cntrl(length) ! tableau des parametres du run
199    CHARACTER(LEN = maxlen) :: var, dum
200    LOGICAL :: lread_inca
201    !===============================================================================
202
203    modname = 'dynredem1'; fil = fichnom
204    CALL err(nf90_open(fil, nf90_write, nid), "open", fil)
205
206    !--- Write/extend time coordinate
207    nb = nb + 1
208    var = "temps"
209    CALL err(nf90_inq_varid(nid, var, vID), "inq", var)
210    CALL err(nf90_put_var(nid, vID, [time]), "put", var)
211    WRITE(lunout, *)TRIM(modname) // ": Saving for ", nb, time
212
213    !--- Rewrite control table (itaufin undefined in dynredem0)
214    var = "controle"
215    CALL err(nf90_inq_varid(nid, var, vID), "inq", var)
216    CALL err(nf90_get_var(nid, vID, tab_cntrl), "get", var)
217    tab_cntrl(31) = DBLE(itau_dyn + itaufin)
218    CALL err(nf90_inq_varid(nid, var, vID), "inq", var)
219    CALL err(nf90_put_var(nid, vID, tab_cntrl), "put", var)
220
221    !--- Save fields
222    CALL dynredem_write_u(nid, "ucov", ucov, llm)
223    CALL dynredem_write_v(nid, "vcov", vcov, llm)
224    CALL dynredem_write_u(nid, "teta", teta, llm)
225    CALL dynredem_write_u(nid, "masse", masse, llm)
226    CALL dynredem_write_u(nid, "ps", ps, 1)
227
228    !--- Tracers in file "start_trac.nc" (added by Anne)
229    lread_inca = .FALSE.; fil = "start_trac.nc"
230    IF(ANY(type_trac == ['inca', 'inco'])) INQUIRE(FILE = fil, EXIST = lread_inca)
231    IF(lread_inca) CALL err(nf90_open(fil, nf90_nowrite, nid_trac), "open")
232
233    !--- Save tracers
234    DO iq = 1, nqtot; var = TRIM(tracers(iq)%name); ierr = -1
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
241      IF(ierr==nf90_noerr) CALL dynredem_read_u(nid_trac, var, q(:, :, :, iq), llm)
242    END IF
243    fil = fichnom
244    CALL dynredem_write_u(nid, var, q(:, :, :, iq), llm)
245    END DO
246    CALL err(nf90_close(nid), "close")
247    fil = "start_trac.nc"
248    IF(lread_inca) CALL err(nf90_close(nid_trac), "close")
249
250  END SUBROUTINE dynredem1
251
252END MODULE lmdz_dynredem
Note: See TracBrowser for help on using the repository browser.