source: trunk/LMDZ.MARS/libf/phymars/iniwritesoil.F90 @ 1528

Last change on this file since 1528 was 1528, checked in by emillour, 9 years ago

Mars GCM:

  • Got rid of references to "dimensions.h" from physics packages: use nbp_lon (=iim), nbp_lat (==jjp1) and nbp_lev from module mod_grid_phy_lmdz (in phy_common) instead.
  • Added "ioipsl_getin_p_mod.F90" (getin_p routine) in phy_common to correctly read in parameters from *.def files in a parallel environment.

EM

File size: 7.4 KB
Line 
1subroutine iniwritesoil(nid,ngrid,inertia,area)
2
3! initialization routine for 'writediagoil'. Here we create/define
4! dimensions (longitude, latitude, depth and time) and other fixed
5! (time-independent) parameters.
6
7use comsoil_h, only: mlayer, nsoilmx
8USE comcstfi_h, only: pi
9USE regular_lonlat_mod, ONLY: lon_reg, lat_reg
10use mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
11
12implicit none
13
14include"netcdf.inc"
15
16! Arguments:
17integer,intent(in) :: ngrid
18integer,intent(in) :: nid ! NetCDF output file ID
19real,intent(in) :: inertia(nbp_lon+1,nbp_lat,nsoilmx)
20real,intent(in) :: area(nbp_lon+1,nbp_lat) ! mesh area (m2)
21
22! Local variables:
23
24! NetCDF stuff:
25integer :: ierr ! NetCDF routines return code
26integer :: idim_rlatu ! ID of the 'latitude' dimension
27integer :: idim_rlonv ! ID of the 'longitude' dimension
28integer :: idim_depth ! ID of the 'depth' dimension
29integer :: idim_time  ! ID of the 'time' dimension
30integer :: varid ! to store NetCDF ID of a variable
31integer,dimension(3) :: dimids ! to store IDs of dimensions of a variable
32character(len=60) :: text ! to store some text
33real,dimension(nbp_lon+1,nbp_lat,nsoilmx) :: data3 ! to store 3D data
34integer :: i,j,l,ig0
35real :: lon_reg_ext(nbp_lon+1) ! extended longitudes
36
37! 1. Define the dimensions
38! Switch to NetCDF define mode
39ierr=NF_REDEF(nid)
40
41! Define the dimensions
42ierr=NF_DEF_DIM(nid,"longitude",nbp_lon+1,idim_rlonv)
43if (ierr.ne.NF_NOERR) then
44  write(*,*)"iniwritesoil: Error, could not define longitude dimension"
45endif
46ierr=NF_DEF_DIM(nid,"latitude",nbp_lat,idim_rlatu)
47if (ierr.ne.NF_NOERR) then
48  write(*,*)"iniwritesoil: Error, could not define latitude dimension"
49endif
50ierr=NF_DEF_DIM(nid,"depth",nsoilmx,idim_depth)
51! nsoilmx known from comsoil_h
52if (ierr.ne.NF_NOERR) then
53  write(*,*)"iniwritesoil: Error, could not define depth dimension"
54endif
55ierr=NF_DEF_DIM(nid,"time",NF_UNLIMITED,idim_time)
56if (ierr.ne.NF_NOERR) then
57  write(*,*)"iniwritesoil: Error, could not define time dimension"
58endif
59
60! Switch out of NetCDF define mode
61ierr=NF_ENDDEF(nid)
62
63! 2. Define (as variables) and write dimensions, as well as their attributes
64! 2.1. Longitude
65ierr=NF_REDEF(nid) ! switch to NetCDF define mode
66
67! Define the variable
68#ifdef NC_DOUBLE
69ierr=NF_DEF_VAR(nid,"longitude",NF_DOUBLE,1,idim_rlonv,varid)
70#else
71ierr=NF_DEF_VAR(nid,"longitude",NF_FLOAT,1,idim_rlonv,varid)
72#endif
73if (ierr.ne.NF_NOERR) then
74  write(*,*)"iniwritesoil: Error, could not define longitude variable"
75endif
76
77! Longitude attributes
78text="East longitude"
79ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
80text="degrees_east"
81ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
82
83lon_reg_ext(1:nbp_lon)=lon_reg(1:nbp_lon)
84!add extra redundant point (180 degrees, since lon_reg starts at -180
85lon_reg_ext(nbp_lon+1)=-lon_reg_ext(1)
86
87! Write longitude to file
88ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
89! Write
90#ifdef NC_DOUBLE
91ierr=NF_PUT_VAR_DOUBLE(nid,varid,lon_reg_ext*(180./pi))
92#else
93ierr=NF_PUT_VAR_REAL(nid,varid,lon_reg_ext*(180./pi))
94#endif
95! Note: rlonv is known from comgeom.h and pi from comcstfi.h
96if (ierr.ne.NF_NOERR) then
97  write(*,*)"iniwritesoil: Error, could not write longitude variable"
98endif
99
100! 2.2. Latitude
101ierr=NF_REDEF(nid) ! switch to NetCDF define mode
102
103! Define the variable
104#ifdef NC_DOUBLE
105ierr=NF_DEF_VAR(nid,"latitude",NF_DOUBLE,1,idim_rlatu,varid)
106#else
107ierr=NF_DEF_VAR(nid,"latitude",NF_FLOAT,1,idim_rlatu,varid)
108#endif
109if (ierr.ne.NF_NOERR) then
110  write(*,*)"iniwritesoil: Error, could not define latitude variable"
111endif
112
113! Latitude attributes
114text="North latitude"
115ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
116text="degrees_north"
117ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
118
119! Write latitude to file
120ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
121! Write
122#ifdef NC_DOUBLE
123ierr=NF_PUT_VAR_DOUBLE(nid,varid,lat_reg*(180./pi))
124#else
125ierr=NF_PUT_VAR_REAL(nid,varid,lat_reg*(180./pi))
126#endif
127if (ierr.ne.NF_NOERR) then
128  write(*,*)"iniwritesoil: Error, could not write longitude variable"
129endif
130
131! 2.3. Depth
132ierr=NF_REDEF(nid) ! switch to NetCDF define mode
133
134! Define the variable
135#ifdef NC_DOUBLE
136ierr=NF_DEF_VAR(nid,"depth",NF_DOUBLE,1,idim_depth,varid)
137#else
138ierr=NF_DEF_VAR(nid,"depth",NF_FLOAT,1,idim_depth,varid)
139#endif
140if (ierr.ne.NF_NOERR) then
141  write(*,*)"iniwritesoil: Error, could not define depth variable"
142endif
143
144! Depth attributes
145text="Soil mid-layer depth"
146ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
147text="m"
148ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
149text="down"
150ierr=NF_PUT_ATT_TEXT(nid,varid,"positive",len_trim(text),text)
151
152! Write depth to file
153ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
154! Write
155#ifdef NC_DOUBLE
156ierr=NF_PUT_VAR_DOUBLE(nid,varid,mlayer)
157#else
158ierr=NF_PUT_VAR_REAL(nid,varid,mlayer)
159#endif
160! Note mlayer(0:nsoilmx-1) known from comsoil_h
161if (ierr.ne.NF_NOERR) then
162  write(*,*)"iniwritesoil: Error, could not write depth variable"
163endif
164
165! 2.4. Time
166ierr=NF_REDEF(nid) ! switch to NetCDF define mode
167
168! Define the variable
169#ifdef NC_DOUBLE
170ierr=NF_DEF_VAR(nid,"time",NF_DOUBLE,1,idim_time,varid)
171#else
172ierr=NF_DEF_VAR(nid,"time",NF_FLOAT,1,idim_time,varid)
173#endif
174if (ierr.ne.NF_NOERR) then
175  write(*,*)"iniwritesoil: Error, could not define depth variable"
176endif
177
178! time attributes
179text="Time"
180ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
181text="days since 0000-01-01 00:00:00"
182ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
183
184ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
185! Note no need to write time variable here; it is done in writediagsoil.
186
187! 3. Other variables to be included
188
189! 3.1 mesh area surrounding each horizontal point
190ierr=NF_REDEF(nid) ! switch to NetCDF define mode
191
192! Define the variable
193dimids(1)=idim_rlonv ! ID of the 'longitude' dimension
194dimids(2)=idim_rlatu ! ID of the 'latitude' dimension
195#ifdef NC_DOUBLE
196ierr=NF_DEF_VAR(nid,"area",NF_DOUBLE,2,dimids,varid)
197#else
198ierr=NF_DEF_VAR(nid,"area",NF_FLOAT,2,dimids,varid)
199#endif
200if (ierr.ne.NF_NOERR) then
201  write(*,*)"iniwritesoil: Error, could not define area variable"
202endif
203
204! Area attributes
205text="Mesh area"
206ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
207text="m2"
208ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
209
210! Write area to file
211ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
212! Write
213#ifdef NC_DOUBLE
214ierr=NF_PUT_VAR_DOUBLE(nid,varid,area)
215#else
216ierr=NF_PUT_VAR_REAL(nid,varid,area)
217#endif
218if (ierr.ne.NF_NOERR) then
219  write(*,*)"iniwritesoil: Error, could not write area variable"
220endif
221
222! 3.2 Thermal inertia
223ierr=NF_REDEF(nid) ! switch to NetCDF define mode
224
225! Define the variable
226dimids(1)=idim_rlonv ! ID of the 'longitude' dimension
227dimids(2)=idim_rlatu ! ID of the 'latitude' dimension
228dimids(3)=idim_depth ! ID of the 'depth' dimension
229#ifdef NC_DOUBLE
230ierr=NF_DEF_VAR(nid,"th_inertia",NF_DOUBLE,3,dimids,varid)
231#else
232ierr=NF_DEF_VAR(nid,"th_inertia",NF_FLOAT,3,dimids,varid)
233#endif
234if (ierr.ne.NF_NOERR) then
235  write(*,*)"iniwritesoil: Error, could not define th_inertia variable"
236endif
237
238! Attributes
239text="Thermal inertia"
240ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
241text="J.s-1/2.m-2.K-1"
242ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
243
244! Write data2 to file
245ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
246! Write
247#ifdef NC_DOUBLE
248ierr=NF_PUT_VAR_DOUBLE(nid,varid,inertia)
249#else
250ierr=NF_PUT_VAR_REAL(nid,varid,inertia)
251#endif
252if (ierr.ne.NF_NOERR) then
253  write(*,*)"iniwritesoil: Error, could not write th_inertia variable"
254endif
255
256end subroutine iniwritesoil
Note: See TracBrowser for help on using the repository browser.