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