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

Last change on this file since 706 was 38, checked in by emillour, 14 years ago

Ajout du modè Martien (mon LMDZ.MARS.BETA, du 28/01/2011) dans le rértoire mars, pour pouvoir suivre plus facilement les modifs.
EM

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