source: trunk/LMDZ.MARS/libf/phymars/iniwrite.F @ 1266

Last change on this file since 1266 was 1266, checked in by aslmd, 11 years ago

LMDZ.MARS
IMPORTANT CHANGE

  • Remove all reference/use of nlayermx and dimphys.h
  • Made use of automatic arrays whenever arrays are needed with dimension nlayer
  • Remove lots of obsolete reference to dimensions.h
  • Converted iono.h and param_v4.h into corresponding modules

(with embedded subroutine to allocate arrays)
(no arrays allocated if thermosphere not used)

  • Deleted param.h and put contents into module param_v4_h
  • Adapted testphys1d, newstart, etc...
  • Made DATA arrays in param_read to be initialized by subroutine

fill_data_thermos in module param_v4_h

  • Optimized computations in paramfoto_compact (twice less dlog10 calculations)
  • Checked consistency before/after modification in debug mode
  • Checked performance is not impacted (same as before)
File size: 10.6 KB
Line 
1      SUBROUTINE iniwrite(nid,idayref,phis)
2
3      use comsoil_h, only: mlayer, nsoilmx
4      USE comcstfi_h
5      IMPLICIT NONE
6
7c=======================================================================
8c
9c   Auteur:  L. Fairhead  ,  P. Le Van, Y. Wanherdrick, F. Forget
10c   -------
11c
12c   Objet:
13c   ------
14c
15c   'Initialize' the diagfi.nc file: write down dimensions as well
16c   as time-independent fields (e.g: geopotential, mesh area, ...)
17c
18c=======================================================================
19c-----------------------------------------------------------------------
20c   Declarations:
21c   -------------
22
23#include "dimensions.h"
24#include "paramet.h"
25#include "comvert.h"
26#include "comgeom.h"
27#include "temps.h"
28#include "ener.h"
29#include "logic.h"
30#include "netcdf.inc"
31#include "description.h"
32#include "serre.h"
33
34c   Arguments:
35c   ----------
36
37      integer,intent(in) :: nid        ! NetCDF file ID
38      INTEGER*4,intent(in) :: idayref  ! date (initial date for this run)
39      real,intent(in) :: phis(ip1jmp1) ! surface geopotential
40
41c   Local:
42c   ------
43      INTEGER length,l
44      parameter (length = 100)
45      REAL tab_cntrl(length) ! run parameters are stored in this array
46      INTEGER ierr
47
48      integer :: nvarid,idim_index,idim_rlonu,idim_rlonv
49      integer :: idim_rlatu,idim_rlatv,idim_llmp1,idim_llm
50      integer :: idim_nsoilmx ! "subsurface_layers" dimension ID #
51      integer, dimension(2) :: id 
52c-----------------------------------------------------------------------
53
54      DO l=1,length
55         tab_cntrl(l)=0.
56      ENDDO
57      tab_cntrl(1)  = real(iim)
58      tab_cntrl(2)  = real(jjm)
59      tab_cntrl(3)  = real(llm)
60      tab_cntrl(4)  = real(idayref)
61      tab_cntrl(5)  = rad
62      tab_cntrl(6)  = omeg
63      tab_cntrl(7)  = g
64      tab_cntrl(8)  = mugaz
65      tab_cntrl(9)  = rcp
66      tab_cntrl(10) = daysec
67      tab_cntrl(11) = dtphys
68      tab_cntrl(12) = etot0
69      tab_cntrl(13) = ptot0
70      tab_cntrl(14) = ztot0
71      tab_cntrl(15) = stot0
72      tab_cntrl(16) = ang0
73
74      tab_cntrl(27) = hour_ini
75c
76c    ..........    P.Le Van  ( ajout le 8/04/96 )    .........
77c         .....        parametres  pour le zoom          ......   
78      tab_cntrl(17)  = clon
79      tab_cntrl(18)  = clat
80      tab_cntrl(19)  = grossismx
81      tab_cntrl(20)  = grossismy
82c
83c     .....   ajout  le 6/05/97 et le 15/10/97  .......
84c
85      IF ( fxyhypb )   THEN
86        tab_cntrl(21) = 1.
87        tab_cntrl(22) = dzoomx
88        tab_cntrl(23) = dzoomy
89      ELSE
90        tab_cntrl(21) = 0.
91        tab_cntrl(22) = dzoomx
92        tab_cntrl(23) = dzoomy
93        tab_cntrl(24) = 0.
94        IF( ysinus )  tab_cntrl(24) = 1.
95      ENDIF
96
97c    .........................................................
98
99! Define dimensions
100   
101      ierr = NF_REDEF (nid)
102
103      ierr = NF_DEF_DIM (nid, "index", length, idim_index)
104      ierr = NF_DEF_DIM (nid, "rlonu", iip1, idim_rlonu)
105      ierr = NF_DEF_DIM (nid, "latitude", jjp1, idim_rlatu)
106      ierr = NF_DEF_DIM (nid, "longitude", iip1, idim_rlonv)
107      ierr = NF_DEF_DIM (nid, "rlatv", jjm, idim_rlatv)
108      ierr = NF_DEF_DIM (nid, "interlayer", (llm+1), idim_llmp1)
109      ierr = NF_DEF_DIM (nid, "altitude", llm, idim_llm)
110      ierr = NF_DEF_DIM (nid,"subsurface_layers",nsoilmx,idim_nsoilmx)
111c
112      ierr = NF_ENDDEF(nid)
113
114c  Contol parameters for this run
115      ierr = NF_REDEF (nid)
116#ifdef NC_DOUBLE
117      ierr = NF_DEF_VAR (nid, "controle", NF_DOUBLE, 1,
118     .       idim_index,nvarid)
119#else
120      ierr = NF_DEF_VAR (nid, "controle", NF_FLOAT, 1,
121     .       idim_index,nvarid)
122#endif
123      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 18,
124     .                       "Control parameters")
125      ierr = NF_ENDDEF(nid)
126#ifdef NC_DOUBLE
127      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,tab_cntrl)
128#else
129      ierr = NF_PUT_VAR_REAL (nid,nvarid,tab_cntrl)
130#endif
131
132c --------------------------
133c  longitudes and latitudes
134      ierr = NF_REDEF (nid)
135#ifdef NC_DOUBLE
136      ierr = NF_DEF_VAR (nid, "rlonu", NF_DOUBLE, 1, idim_rlonu,nvarid)
137#else
138      ierr = NF_DEF_VAR (nid, "rlonu", NF_FLOAT, 1, idim_rlonu,nvarid)
139#endif
140      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 21,
141     .                       "Longitudes at u nodes")
142      ierr = NF_ENDDEF(nid)
143#ifdef NC_DOUBLE
144      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlonu/pi*180)
145#else
146      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlonu/pi*180)
147#endif
148c
149c --------------------------
150      ierr = NF_REDEF (nid)
151#ifdef NC_DOUBLE
152      ierr =NF_DEF_VAR(nid, "latitude", NF_DOUBLE, 1, idim_rlatu,nvarid)
153#else
154      ierr =NF_DEF_VAR (nid, "latitude", NF_FLOAT, 1, idim_rlatu,nvarid)
155#endif
156      ierr =NF_PUT_ATT_TEXT(nid,nvarid,'units',13,"degrees_north")
157      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"long_name", 14,
158     .      "North latitude")
159      ierr = NF_ENDDEF(nid)
160#ifdef NC_DOUBLE
161      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlatu/pi*180)
162#else
163      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlatu/pi*180)
164#endif
165c
166c --------------------------
167      ierr = NF_REDEF (nid)
168#ifdef NC_DOUBLE
169      ierr =NF_DEF_VAR(nid,"longitude", NF_DOUBLE, 1, idim_rlonv,nvarid)
170#else
171      ierr = NF_DEF_VAR(nid,"longitude", NF_FLOAT, 1, idim_rlonv,nvarid)
172#endif
173      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"long_name", 14,
174     .      "East longitude")
175      ierr = NF_PUT_ATT_TEXT(nid,nvarid,'units',12,"degrees_east")
176      ierr = NF_ENDDEF(nid)
177#ifdef NC_DOUBLE
178      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlonv/pi*180)
179#else
180      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlonv/pi*180)
181#endif
182c
183c --------------------------
184      ierr = NF_REDEF (nid)
185#ifdef NC_DOUBLE
186      ierr = NF_DEF_VAR (nid, "altitude", NF_DOUBLE, 1,
187     .       idim_llm,nvarid)
188#else
189      ierr = NF_DEF_VAR (nid, "altitude", NF_FLOAT, 1,
190     .       idim_llm,nvarid)
191#endif
192      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"long_name",10,"pseudo-alt")
193      ierr = NF_PUT_ATT_TEXT (nid,nvarid,'units',2,"km")
194      ierr = NF_PUT_ATT_TEXT (nid,nvarid,'positive',2,"up")
195
196      ierr = NF_ENDDEF(nid)
197#ifdef NC_DOUBLE
198      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pseudoalt)
199#else
200      ierr = NF_PUT_VAR_REAL (nid,nvarid,pseudoalt)
201#endif
202c
203c --------------------------
204      ierr = NF_REDEF (nid)
205#ifdef NC_DOUBLE
206      ierr = NF_DEF_VAR (nid, "rlatv", NF_DOUBLE, 1, idim_rlatv,nvarid)
207#else
208      ierr = NF_DEF_VAR (nid, "rlatv", NF_FLOAT, 1, idim_rlatv,nvarid)
209#endif
210      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 20,
211     .                       "Latitudes at v nodes")
212      ierr = NF_ENDDEF(nid)
213#ifdef NC_DOUBLE
214      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlatv/pi*180)
215#else
216      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlatv/pi*180)
217#endif
218c
219c --------------------------
220c  Vertical levels
221      call def_var(nid,"aps","hybrid pressure at midlayers ","Pa",
222     .            1,idim_llm,nvarid,ierr)
223#ifdef NC_DOUBLE
224      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,aps)
225#else
226      ierr = NF_PUT_VAR_REAL (nid,nvarid,aps)
227#endif
228
229      call def_var(nid,"bps","hybrid sigma at midlayers"," ",
230     .            1,idim_llm,nvarid,ierr)
231#ifdef NC_DOUBLE
232      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,bps)
233#else
234      ierr = NF_PUT_VAR_REAL (nid,nvarid,bps)
235#endif
236
237      call def_var(nid,"ap","hybrid pressure at interlayers","Pa",
238     .            1,idim_llmp1,nvarid,ierr)
239#ifdef NC_DOUBLE
240      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,ap)
241#else
242      ierr = NF_PUT_VAR_REAL (nid,nvarid,ap)
243#endif
244
245      call def_var(nid,"bp","hybrid sigma at interlayers"," ",
246     .            1,idim_llmp1,nvarid,ierr)
247#ifdef NC_DOUBLE
248      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,bp)
249#else
250      ierr = NF_PUT_VAR_REAL (nid,nvarid,bp)
251#endif
252
253!-------------------------------
254! (soil) depth variable mlayer() (known from comsoil_h)
255!-------------------------------
256      ierr=NF_REDEF (nid) ! Enter NetCDF (re-)define mode
257      ! define variable
258#ifdef NC_DOUBLE
259      ierr=NF_DEF_VAR(nid,"soildepth",NF_DOUBLE,1,idim_nsoilmx,nvarid)
260#else
261      ierr=NF_DEF_VAR(nid,"soildepth",NF_FLOAT,1,idim_nsoilmx,nvarid)
262#endif
263      ierr=NF_PUT_ATT_TEXT (nid,nvarid,"long_name", 20,
264     .                        "Soil mid-layer depth")
265      ierr=NF_PUT_ATT_TEXT (nid,nvarid,"units",1,"m")
266      ierr=NF_PUT_ATT_TEXT (nid,nvarid,"positive",4,"down")
267      ierr=NF_ENDDEF(nid) ! Leave NetCDF define mode
268      ! write variable
269#ifdef NC_DOUBLE
270      ierr=NF_PUT_VAR_DOUBLE (nid,nvarid,mlayer)
271#else
272      ierr=NF_PUT_VAR_REAL (nid,nvarid,mlayer)
273#endif
274
275c
276c --------------------------
277c  Mesh area and conversion coefficients cov. <-> contra. <--> natural
278
279      id(1)=idim_rlonu
280      id(2)=idim_rlatu
281c
282      ierr = NF_REDEF (nid)
283#ifdef NC_DOUBLE
284      ierr = NF_DEF_VAR (nid, "cu", NF_DOUBLE, 2, id,nvarid)
285#else
286      ierr = NF_DEF_VAR (nid, "cu", NF_FLOAT, 2, id,nvarid)
287#endif
288      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 40,
289     .             "Conversion coefficients cov <--> natural")
290      ierr = NF_ENDDEF(nid)
291#ifdef NC_DOUBLE
292      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,cu)
293#else
294      ierr = NF_PUT_VAR_REAL (nid,nvarid,cu)
295#endif
296c
297      id(1)=idim_rlonv
298      id(2)=idim_rlatv
299c
300c --------------------------
301      ierr = NF_REDEF (nid)
302#ifdef NC_DOUBLE
303      ierr = NF_DEF_VAR (nid, "cv", NF_DOUBLE, 2, id,nvarid)
304#else
305      ierr = NF_DEF_VAR (nid, "cv", NF_FLOAT, 2, id,nvarid)
306#endif
307      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 40,
308     .             "Conversion coefficients cov <--> natural")
309      ierr = NF_ENDDEF(nid)
310#ifdef NC_DOUBLE
311      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,cv)
312#else
313      ierr = NF_PUT_VAR_REAL (nid,nvarid,cv)
314#endif
315c
316      id(1)=idim_rlonv
317      id(2)=idim_rlatu
318c
319c --------------------------
320      ierr = NF_REDEF (nid)
321#ifdef NC_DOUBLE
322      ierr = NF_DEF_VAR (nid, "aire", NF_DOUBLE, 2, id,nvarid)
323#else
324      ierr = NF_DEF_VAR (nid, "aire", NF_FLOAT, 2, id,nvarid)
325#endif
326      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 9,
327     .                       "Mesh area")
328      ierr = NF_ENDDEF(nid)
329#ifdef NC_DOUBLE
330      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,aire)
331#else
332      ierr = NF_PUT_VAR_REAL (nid,nvarid,aire)
333#endif
334c
335c  Surface geopotential
336      id(1)=idim_rlonv
337      id(2)=idim_rlatu
338c
339      ierr = NF_REDEF (nid)
340#ifdef NC_DOUBLE
341      ierr = NF_DEF_VAR (nid, "phisinit", NF_DOUBLE, 2, id,nvarid)
342#else
343      ierr = NF_DEF_VAR (nid, "phisinit", NF_FLOAT, 2, id,nvarid)
344#endif
345      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 27,
346     .                       "Geopotential at the surface")
347      ierr = NF_ENDDEF(nid)
348#ifdef NC_DOUBLE
349      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,phis)
350#else
351      ierr = NF_PUT_VAR_REAL (nid,nvarid,phis)
352#endif
353c
354
355      write(*,*)'iniwrite: iim,jjm,llm,idayref',iim,jjm,llm,idayref
356      write(*,*)'iniwrite: rad,omeg,g,mugaz,rcp',
357     s rad,omeg,g,mugaz,rcp
358      write(*,*)'iniwrite: daysec,dtphys',daysec,dtphys
359
360      END
Note: See TracBrowser for help on using the repository browser.