source: trunk/mesoscale/LMD_MM_MARS/SRC/PREP_MARS/readmeteo_newphys.F90 @ 39

Last change on this file since 39 was 31, checked in by aslmd, 15 years ago

LMD_MM_MARS: teste compilation, scripts additionnels et initialisation nouvelle physique

File size: 37.7 KB
Line 
1program readmeteo
2
3implicit none
4include "netcdf.inc"
5
6!------------------------------------------------------------------------!
7! Readmeteo prepares an initial state for the WPS pre-processor of WRF   !
8!                                                                        !
9! Input is a diagfi.nc NETCDF file from a LMD/GCM simulation             !
10!                                                                        !
11! Outputs are WRFSI intermediate format files ready for metgrid.exe      !
12!       http://www.mmm.ucar.edu/wrf/OnLineTutorial/WPS/IM_si.htm         !
13!                                                                        !
14! **** Please create a WPSFEED folder (or a symbolic link) ****          !       
15!                                                                        !
16! A. Spiga - 16/04/2007                                                  !
17!            22/05/2007 : need to run zrecast as a preliminary           !
18!            07/06/2007 : external parameter file 'readmeteo.def         !
19!            30/07/2007 : manage additional variables (tsoil, emiss,...) !     
20!            19/10/2007 : no need to run zrecast at all (eta levels)     !   
21!               12/2007 : include co2ice and emissivity                  !
22!               02/2008 : include water vapor and ice                    !
23!               01/2010 : possible use of diagsoil for new physics       !
24!                                                                        !
25! spiga@lmd.jussieu.fr                                                   !     
26!------------------------------------------------------------------------!
27
28
29
30!***************************************************************************
31!***************************************************************************
32REAL, PARAMETER :: emiss_prescribed=0.95
33REAL, PARAMETER :: co2ice_prescribed=0.
34CHARACTER (LEN=3), PARAMETER :: ident='LMD'
35
36
37
38!***************************************************************************
39!***************************************************************************
40
41REAL :: ptop
42REAL, PARAMETER :: grav=3.72
43LOGICAL, PARAMETER :: blank=.false.
44
45
46
47!! Variables to be written in the output file
48!! *** NB: conformity with metgrid/src/read_met_module.F90
49CHARACTER (LEN=33) :: output
50INTEGER :: IFV
51CHARACTER (LEN=24) :: HDATE
52REAL :: XFCST
53CHARACTER (LEN=32) :: SOURCE
54CHARACTER (LEN=9) :: FIELD
55CHARACTER (LEN=25) :: UNITS
56CHARACTER (LEN=46) :: DESC
57REAL :: XLVL
58INTEGER :: NX,NY,IPROJ
59CHARACTER (LEN=8) :: STARTLOC
60REAL :: STARTLAT,STARTLON,DELTALAT,DELTALON
61REAL, POINTER, DIMENSION(:,:) :: SLAB
62
63!! Variables related to NETCDF format
64integer :: nid,nid2,nid3,nvarid,ierr,ierr2
65integer :: timedim,londim,latdim,altdim,altdim2
66integer :: rlatvdim,rlonudim
67integer :: timelen,lonlen,latlen,altlen,altlen2
68integer :: rlatvlen,rlonulen
69integer :: soillen,soildim
70integer :: nphys
71integer, dimension(4) :: corner,edges
72
73!! Intermediate data arrays
74integer :: k,l,m,n,p
75real, dimension(:), allocatable :: lat,lon,time,alt,aps,bps,levels
76real, dimension(:,:), allocatable :: vide,ones,ghtsfile
77real, dimension(:,:), allocatable :: interm
78real, dimension(:,:,:), allocatable :: gwparam
79real, dimension(:,:,:), allocatable :: psfile,tsfile
80real, dimension(:,:,:), allocatable :: emissfile,co2icefile
81real, dimension(:,:,:), allocatable :: tnsfile,unsfile,vnsfile
82real, dimension(:,:,:,:), allocatable :: tfile,ufile,vfile,rfile,hfile
83real, dimension(:,:,:,:), allocatable :: eta_gcm
84real, dimension(:,:,:,:), allocatable :: tfileorig,ufileorig,vfileorig
85real, dimension(:,:,:,:), allocatable :: tsoilfile, dsoilfile, isoilfile
86real, dimension(:,:,:,:), allocatable :: waterfile, watericefile
87
88!! Reading the parameter file
89integer :: tmp,increment,FILES
90integer :: tmp2,tmp3,tmp4
91character*1 :: answer
92character*4 :: str
93character*2 :: str2, str3, str4
94integer, dimension(:), allocatable :: time_out
95character*13, dimension(:), allocatable :: date_out
96character*19, dimension(:), allocatable :: date_out2
97!***************************************************************************
98!***************************************************************************
99
100
101!!---------------------
102!! Open the datafile
103!!---------------------
104ierr=NF_OPEN ("input_diagfi.nc",NF_NOWRITE,nid)
105IF (ierr.NE.NF_NOERR) THEN
106   write(*,*)'**** Please create a symbolic link called input_diagfi.nc'
107   CALL ABORT
108ENDIF
109
110
111!!--------------------------
112!! Ask for data references
113!!--------------------------
114!write(*,*) "Create n files. What is n ?"
115read(*,*) FILES
116allocate(time_out(FILES))
117allocate(date_out(FILES))
118allocate(date_out2(FILES))
119
120!write(*,*) ""
121!write(*,*) "INPUT: Diagfi time"
122!write(*,*) "list of n subscripts, separated by <Return>s"
123increment=1
124do while (increment.ne.FILES+1)
125    read(*,*) tmp
126    time_out(increment)=tmp
127    increment=increment+1
128enddo
129
130!write(*,*) ""
131!write(*,*) "OUTPUT: WRF time"
132!write(*,*) "fill 4 lines indicating"
133!write(*,*) "-year (4 digits)"
134!write(*,*) "-month (2 digits)"
135!write(*,*) "-day (2 digits)"
136!write(*,*) "-hour (2 digits)"
137increment=1
138do while (increment.ne.FILES+1)
139    read(*,*) str
140    read(*,*) str2
141    read(*,*) str3
142    read(*,*) str4
143    date_out(increment)=str//'-'//str2//'-'//str3//'_'//str4
144    date_out2(increment)=str//'-'//str2//'-'//str3//'_'//str4//':00:00'
145    !print *,date_out(increment)
146    !write(*,*) "ok? (y/n)"
147    read(*,*) answer
148    if (answer.eq.'n') then
149        !write(*,*) "please write again"
150    else
151        !write(*,*) "next one, please"   
152        increment=increment+1
153    endif
154enddo
155
156
157!!-------------------
158!! Get array sizes
159!!-------------------
160SELECT CASE(ident)
161CASE('LMD')
162ierr=NF_INQ_DIMID(nid,"Time",timedim)
163CASE('OXF')
164ierr=NF_INQ_DIMID(nid,"time",timedim)
165END SELECT
166ierr=NF_INQ_DIMLEN(nid,timedim,timelen)
167  write(*,*) "timelen: ",timelen
168
169SELECT CASE(ident)
170CASE('LMD')
171ierr=NF_INQ_DIMID(nid,"latitude",latdim)
172CASE('OXF')
173ierr=NF_INQ_DIMID(nid,"lat",latdim)
174END SELECT
175ierr=NF_INQ_DIMLEN(nid,latdim,latlen)
176  write(*,*) "latlen: ",latlen
177
178SELECT CASE(ident)
179CASE('LMD')
180ierr=NF_INQ_DIMID(nid,"longitude",londim)
181CASE('OXF')
182ierr=NF_INQ_DIMID(nid,"lon",londim)
183END SELECT
184ierr=NF_INQ_DIMLEN(nid,londim,lonlen)
185  write(*,*) "lonlen: ",lonlen
186
187SELECT CASE(ident)
188CASE('LMD')
189ierr=NF_INQ_DIMID(nid,"altitude",altdim)
190CASE('OXF')
191ierr=NF_INQ_DIMID(nid,"sigma",altdim)
192END SELECT
193ierr=NF_INQ_DIMLEN(nid,altdim,altlen)
194  write(*,*) "altlen: ",altlen
195
196
197
198!!-------------------------
199!! Allocate local arrays
200!!-------------------------
201allocate(eta_gcm(lonlen,latlen,altlen,timelen))
202allocate(tfile(lonlen,latlen,altlen,timelen))
203allocate(tsoilfile(lonlen,latlen,altlen,timelen))
204allocate(dsoilfile(lonlen,latlen,altlen,timelen))
205allocate(isoilfile(lonlen,latlen,altlen,timelen))
206allocate(tfileorig(lonlen,latlen,altlen,timelen))
207allocate(ufile(lonlen,latlen,altlen,timelen))
208allocate(ufileorig(lonlen,latlen,altlen,timelen))
209allocate(vfile(lonlen,latlen,altlen,timelen))
210allocate(vfileorig(lonlen,latlen,altlen,timelen))
211allocate(rfile(lonlen,latlen,altlen,timelen))
212allocate(hfile(lonlen,latlen,altlen,timelen)) 
213allocate(waterfile(lonlen,latlen,altlen,timelen))
214allocate(watericefile(lonlen,latlen,altlen,timelen))
215allocate(psfile(lonlen,latlen,timelen))
216allocate(tsfile(lonlen,latlen,timelen))
217allocate(tnsfile(lonlen,latlen,timelen))
218allocate(unsfile(lonlen,latlen,timelen))
219allocate(vnsfile(lonlen,latlen,timelen))
220allocate(emissfile(lonlen,latlen,timelen))
221allocate(co2icefile(lonlen,latlen,timelen))
222allocate(interm(lonlen,latlen))
223allocate(gwparam(lonlen,latlen,5))
224allocate(ghtsfile(lonlen,latlen))  !! no scan axis
225allocate(vide(lonlen,latlen))
226allocate(ones(lonlen,latlen))
227allocate(lat(latlen), lon(lonlen), alt(altlen), time(timelen))
228allocate(aps(altlen),bps(altlen),levels(altlen))
229
230tfile(:,:,:,:)=0
231tsoilfile(:,:,:,:)=0
232isoilfile(:,:,:,:)=0
233dsoilfile(:,:,:,:)=0
234tfileorig(:,:,:,:)=0
235ufileorig(:,:,:,:)=0
236vfileorig(:,:,:,:)=0
237ufile(:,:,:,:)=0
238vfile(:,:,:,:)=0
239rfile(:,:,:,:)=0
240hfile(:,:,:,:)=0
241waterfile(:,:,:,:)=0
242watericefile(:,:,:,:)=0
243psfile(:,:,:)=0
244tsfile(:,:,:)=0
245emissfile(:,:,:)=0
246co2icefile(:,:,:)=0
247tnsfile(:,:,:)=0
248unsfile(:,:,:)=0
249vnsfile(:,:,:)=0
250interm(:,:)=0
251gwparam(:,:,:)=0
252ghtsfile(:,:)=0
253vide(:,:)=0
254ones(:,:)=0
255
256
257!!-------------------
258!! Read dimensions
259!!-------------------
260
261print *,'>>> Read dimensions !'
262
263print *,'Time'
264SELECT CASE(ident)
265CASE('LMD')
266   ierr = NF_INQ_VARID (nid, "Time",nvarid)
267CASE('OXF')
268   ierr = NF_INQ_VARID (nid, "time",nvarid)
269END SELECT
270   IF (ierr .NE. NF_NOERR) THEN
271      PRINT *, "Error: Readmeteo <Time> not found"
272      stop
273   ENDIF
274#ifdef NC_DOUBLE
275   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, time)
276#else
277   ierr = NF_GET_VAR_REAL(nid, nvarid, time)
278#endif
279   print *,time(1),' ... to ... ',time(timelen)
280
281print *,'Latitude'
282SELECT CASE(ident)
283CASE('LMD')
284   ierr = NF_INQ_VARID (nid, "latitude",nvarid)
285CASE('OXF')
286   ierr = NF_INQ_VARID (nid, "lat",nvarid)
287END SELECT
288   IF (ierr .NE. NF_NOERR) THEN
289      PRINT *, "Error: Readmeteo <latitude> not found"
290      stop
291   ENDIF
292#ifdef NC_DOUBLE
293   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, lat)
294#else
295   ierr = NF_GET_VAR_REAL(nid, nvarid, lat)
296#endif
297   print *,lat(1),' ... to ... ',lat(latlen),' ... step: ',lat(latlen)-lat(latlen-1)
298
299print *,'Longitude'
300SELECT CASE(ident)
301CASE('LMD')
302   ierr = NF_INQ_VARID (nid, "longitude",nvarid)
303CASE('OXF')
304   ierr = NF_INQ_VARID (nid, "lon",nvarid)
305END SELECT
306   IF (ierr .NE. NF_NOERR) THEN
307      PRINT *, "Error: Readmeteo <longitude> not found"
308      stop
309   ENDIF
310#ifdef NC_DOUBLE
311   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, lon)
312#else
313   ierr = NF_GET_VAR_REAL(nid, nvarid, lon)
314#endif
315   print *,lon(1),' ... to ... ',lon(lonlen),' ... step: ',lon(lonlen)-lon(lonlen-1)
316
317SELECT CASE(ident)
318CASE('LMD')
319print *, 'Hybrid coordinates'
320   ierr = NF_INQ_VARID (nid, "aps", nvarid)
321   IF (ierr .NE. NF_NOERR) THEN
322      PRINT *, "Error: Readmeteo <aps> not found"
323      stop
324   ENDIF
325#ifdef NC_DOUBLE
326   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, aps)
327#else
328   ierr = NF_GET_VAR_REAL(nid, nvarid, aps)
329#endif
330   ierr = NF_INQ_VARID (nid, "bps", nvarid)
331   IF (ierr .NE. NF_NOERR) THEN
332      PRINT *, "Error: Readmeteo <bps> not found"
333      stop
334   ENDIF
335#ifdef NC_DOUBLE
336   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, bps)
337#else
338   ierr = NF_GET_VAR_REAL(nid, nvarid, bps)
339#endif
340   print *,aps(1),' ... to ... ',aps(altlen)
341   print *,bps(1),' ... to ... ',bps(altlen)
342CASE('OXF')
343   ierr = NF_INQ_VARID (nid, "sigma", nvarid)
344   IF (ierr .NE. NF_NOERR) THEN
345      PRINT *, "Error: Readmeteo <sigma> not found"
346      stop
347   ENDIF
348#ifdef NC_DOUBLE
349   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, bps)
350#else
351   ierr = NF_GET_VAR_REAL(nid, nvarid, bps)
352#endif
353   print *,bps(1),' ... to ... ',bps(altlen)
354END SELECT
355
356
357!!-------------------------------------------
358!! Reading 2D and 3D meteorological fields
359!!-------------------------------------------
360
361IF (blank .EQV. .false.) THEN
362
363print *,'>>> Read 2D optional fields !'
364
365print *,'Emissivity'
366   ierr = NF_INQ_VARID (nid,"emis",nvarid)
367IF (ierr .NE. NF_NOERR) THEN
368        PRINT *, '...warning: not found in diagfi !'
369        PRINT *, '...will be filled with a prescribed value', emiss_prescribed
370        emissfile(:,:,:)=emiss_prescribed
371ELSE
372#ifdef NC_DOUBLE
373        ierr = NF_GET_VAR_DOUBLE(nid, nvarid, emissfile)
374#else
375        ierr = NF_GET_VAR_REAL(nid, nvarid, emissfile)
376#endif
377ENDIF   
378
379print *,'CO2 ice'
380   ierr = NF_INQ_VARID (nid,"co2ice",nvarid)
381IF (ierr .NE. NF_NOERR) THEN
382        PRINT *, '...warning: not found in diagfi !'
383        PRINT *, '...will be filled with a prescribed value', co2ice_prescribed
384        co2icefile(:,:,:)=co2ice_prescribed
385ELSE
386#ifdef NC_DOUBLE
387        ierr = NF_GET_VAR_DOUBLE(nid, nvarid, co2icefile)
388#else
389        ierr = NF_GET_VAR_REAL(nid, nvarid, co2icefile)
390#endif
391ENDIF
392
393print *,'>>> Read 2D surface fields !'
394
395print *,'Surface Pressure'
396   ierr = NF_INQ_VARID (nid,"ps",nvarid)
397   IF (ierr .NE. NF_NOERR) THEN
398      PRINT *, "Error: Readmeteo <ps> not found"
399      stop
400   ENDIF
401#ifdef NC_DOUBLE
402   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, psfile)
403#else
404   ierr = NF_GET_VAR_REAL(nid, nvarid, psfile)
405#endif
406
407print *,'Ground Temperature'
408   ierr = NF_INQ_VARID (nid,"tsurf",nvarid)
409   IF (ierr .NE. NF_NOERR) THEN
410      PRINT *, "Error: Readmeteo <tsurf> not found"
411      stop
412   ENDIF
413#ifdef NC_DOUBLE
414   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tsfile)
415#else
416   ierr = NF_GET_VAR_REAL(nid, nvarid, tsfile)
417#endif
418
419
420!!"atmospheric" surface temperature is taken
421!!from original diagfi.nc first level
422!!... level is ~3-5 meters
423print *,'Near-Surface Temperature'
424   ierr = NF_INQ_VARID (nid,"temp",nvarid)
425   IF (ierr .NE. NF_NOERR) THEN
426      ierr = NF_INQ_VARID (nid,"t",nvarid)
427        IF (ierr .NE. NF_NOERR) THEN
428           PRINT *, "Error: Readmeteo <temp> not found"
429           stop
430        ENDIF
431   ENDIF
432#ifdef NC_DOUBLE
433   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tfileorig)
434#else
435   ierr = NF_GET_VAR_REAL(nid, nvarid, tfileorig)
436#endif
437   tnsfile=tfileorig(:,:,1,:)
438
439!!"atmospheric" surface u is taken
440!!from original diagfi.nc first level
441!!... level is ~3-5 meters
442print *,'Near-Surface Zonal Wind'
443   ierr = NF_INQ_VARID (nid,"u",nvarid)
444   IF (ierr .NE. NF_NOERR) THEN
445     PRINT *, "Error: Readmeteo <u> not found"
446     stop
447   ENDIF
448#ifdef NC_DOUBLE
449   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, ufileorig)
450#else
451   ierr = NF_GET_VAR_REAL(nid, nvarid, ufileorig)
452#endif
453   unsfile=ufileorig(:,:,1,:)
454
455!!"atmospheric" surface v is taken
456!!from original diagfi.nc first level
457!!... level is ~3-5 meters
458print *,'Near-Surface Meridional Wind'
459   ierr = NF_INQ_VARID (nid,"v",nvarid)
460   IF (ierr .NE. NF_NOERR) THEN
461     PRINT *, "Error: Readmeteo <v> not found"
462     stop
463   ENDIF
464#ifdef NC_DOUBLE
465   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, vfileorig)
466#else
467   ierr = NF_GET_VAR_REAL(nid, nvarid, vfileorig)
468#endif
469   vnsfile=vfileorig(:,:,1,:)
470
471SELECT CASE(ident)
472CASE('LMD')
473   print *,'Geopotential height at the ground'
474   ierr = NF_INQ_VARID (nid,"phisinit",nvarid)
475   IF (ierr .NE. NF_NOERR) THEN
476      PRINT *, "Error: Readmeteo <phisinit> not found"
477      stop
478   ENDIF
479#ifdef NC_DOUBLE
480   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, ghtsfile)
481#else
482   ierr = NF_GET_VAR_REAL(nid, nvarid, ghtsfile)
483#endif
484!**** from geopotential to geopotential height
485ghtsfile=ghtsfile/grav
486!****
487CASE('OXF')
488!
489! geopotential height ~ altimetry
490!
491print *,'Geopotential height at the ground from file mountain_new.nc'
492ierr=NF_OPEN("mountain_new.nc",NF_NOWRITE,nid3)
493    if (ierr.ne.NF_NOERR) then
494      write(*,*) "Error: Could not open that file either"
495      stop "Might as well stop here"
496    endif
497ierr=NF_INQ_VARID(nid3,"orography",nvarid)
498ierr=NF_GET_VAR_REAL(nid3,nvarid,ghtsfile)
499if (ierr.ne.NF_NOERR) then
500    stop "Error: Failed reading phisinit"
501endif
502ierr=NF_CLOSE(nid3)
503END SELECT
504
505
506print *,'>>> Read 3D meteorological fields ! - This may take some time ...'
507
508print *,'Temperature'
509   ierr = NF_INQ_VARID (nid,"temp",nvarid)
510   IF (ierr .NE. NF_NOERR) THEN
511      ierr = NF_INQ_VARID (nid,"t",nvarid)
512        IF (ierr .NE. NF_NOERR) THEN
513          PRINT *, "Error: Readmeteo <t> not found"
514          stop
515        ENDIF
516   ENDIF
517#ifdef NC_DOUBLE
518   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tfile)
519#else
520   ierr = NF_GET_VAR_REAL(nid, nvarid, tfile)
521#endif
522
523print *,'Zonal wind'   
524   ierr = NF_INQ_VARID (nid,"u",nvarid)
525   IF (ierr .NE. NF_NOERR) THEN
526      PRINT *, "Error: Readmeteo <u> not found"
527      stop
528   ENDIF
529#ifdef NC_DOUBLE
530   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, ufile)
531#else
532   ierr = NF_GET_VAR_REAL(nid, nvarid, ufile)
533#endif
534
535print *,'Meridional wind'
536   ierr = NF_INQ_VARID (nid,"v",nvarid)
537   IF (ierr .NE. NF_NOERR) THEN
538      PRINT *, "Error: Readmeteo <v> not found"
539      stop
540   ENDIF
541#ifdef NC_DOUBLE
542   ierr = NF_GET_VAR_DOUBLE(nid, nvarid, vfile)
543#else
544   ierr = NF_GET_VAR_REAL(nid, nvarid, vfile)
545#endif
546
547
548!!------------------------
549!! special water stuff
550!!------------------------
551    print *,'Water vapor'
552    ierr=NF_INQ_VARID(nid,"q02",nvarid)
553    if (ierr.ne.NF_NOERR) then
554      write(*,*) "...No q02 - Water vapor set to 0"
555      waterfile(:,:,:,:)=0. 
556    endif
557    ierr=NF_GET_VAR_REAL(nid,nvarid,waterfile)
558
559    print *,'Water ice'
560    ierr=NF_INQ_VARID(nid,"q01",nvarid)
561    if (ierr.ne.NF_NOERR) then
562      write(*,*) "...No q01 - Water ice set to 0" 
563      watericefile(:,:,:,:)=0.
564    endif
565    ierr=NF_GET_VAR_REAL(nid,nvarid,watericefile)
566!!------------------------
567!! special water stuff
568!!------------------------
569
570
571!SELECT CASE(ident)
572!CASE('LMD')
573
574    print *,'Soil temperatures'
575    ierr=NF_INQ_VARID(nid,"tsoil",nvarid)
576    if (ierr.ne.NF_NOERR) then
577        write(*,*) "...No tsoil - Soil temperatures set isothermal with surface temperature"
578        DO l=1,altlen
579                tsoilfile(:,:,l,:)=tsfile(:,:,:)
580        ENDDO
581    endif
582    ierr=NF_GET_VAR_REAL(nid,nvarid,tsoilfile)
583 
584!!!!!!!!
585!!!!!!!! new physics (but still compatible with old physics)
586
587    print *,'Soil depths'
588    ierr=NF_INQ_VARID(nid,"soildepth",nvarid)
589    if (ierr.ne.NF_NOERR) then
590        write(*,*) "...No soildepth - Set to default"  !!! see soil_settings in LMD physics
591        DO l=1,altlen
592                dsoilfile(1,1,l,:)=-999.
593        ENDDO
594    endif
595    ierr=NF_GET_VAR_REAL(nid,nvarid,dsoilfile(1,1,:,1))
596    print *, dsoilfile(1,1,:,1)
597    DO m=1,lonlen
598    DO n=1,latlen
599    DO p=1,timelen
600      dsoilfile(m,n,:,p) = dsoilfile(1,1,:,1)
601    ENDDO
602    ENDDO
603    ENDDO
604
605    print *,'Soil thermal inertia'
606    ierr=NF_INQ_VARID(nid,"inertiedat",nvarid)
607    if (ierr.ne.NF_NOERR) then
608        write(*,*) "...No soil therm. inert. - Set to -999"
609        DO l=1,altlen
610                isoilfile(:,:,l,:)=-999.
611        ENDDO
612    endif
613    ierr=NF_GET_VAR_REAL(nid,nvarid,isoilfile)
614
615!!!!!!!!
616!!!!!!!! new physics
617
618
619!END SELECT
620
621ierr=NF_CLOSE(nid)
622
623!!!!lott stuff
624!print *,'get lott'
625!ierr=NF_OPEN("init_lott.nc",NF_NOWRITE,nid3)
626!ierr=NF_INQ_VARID(nid3,"ZMEA",nvarid)
627!ierr=NF_GET_VAR_REAL(nid3,nvarid,interm)
628!gwparam(:,:,1)=interm(:,:)
629!ierr=NF_INQ_VARID(nid3,"ZSTD",nvarid)
630!ierr=NF_GET_VAR_REAL(nid3,nvarid,interm)
631!gwparam(:,:,2)=interm(:,:)
632!ierr=NF_INQ_VARID(nid3,"ZSIG",nvarid)
633!ierr=NF_GET_VAR_REAL(nid3,nvarid,interm)
634!gwparam(:,:,3)=interm(:,:)
635!ierr=NF_INQ_VARID(nid3,"ZGAM",nvarid)
636!ierr=NF_GET_VAR_REAL(nid3,nvarid,interm)
637!gwparam(:,:,4)=interm(:,:)
638!ierr=NF_INQ_VARID(nid3,"ZTHE",nvarid)
639!ierr=NF_GET_VAR_REAL(nid3,nvarid,interm)
640!gwparam(:,:,5)=interm(:,:)
641!ierr=NF_CLOSE(nid3)
642
643ENDIF
644
645
646!!-----------------------------
647!! Loop on the written files
648!! >>> what follows is pretty repetitive ...
649!!        gotta do something (one more loop?)
650!!-----------------------------
651
652!!! Equivalent eta levels for WRF interpolation in initialize_real
653!print *,'Computing equivalent eta levels'
654!       
655!       !ptop will be passed through RH(surface)
656!       ptop=MINVAL(aps(altlen)+bps(altlen)*psfile(:,:,:))
657!       print *, 'ptop', ptop
658!
659!print *, 'sample: equivalent eta levels at i=1,j=1'
660!DO k = 1,altlen
661!        levels(k)=-k
662!        eta_gcm(:,:,k,:)=(aps(k)+bps(k)*psfile(:,:,:)-ptop)/(psfile(:,:,:)-ptop)
663!        print *, eta_gcm(1,1,k,1)
664!END DO
665
666!!---better to pass pressure values
667!!---the eta treatment is done in module_initialize_real
668DO k = 1,altlen
669        levels(k)=-k
670        !!dummy decreasing levels
671END DO
672
673
674
675
676!! Dummy surface level is XLVL=200100.
677
678
679DO l=1,FILES
680
681
682!!---------------------------------------------
683!! Write file in intermediate format for WPS
684!! 1. Surface data
685!!---------------------------------------------
686
687!
688! These variables remain the same in the "loop"
689!
690HDATE=date_out(l)
691IFV=4
692XFCST=0.
693SOURCE=ident
694NX=lonlen
695NY=latlen
696ALLOCATE(SLAB(NX,NY))
697IPROJ=0
698STARTLOC='SWCORNER'
699STARTLAT=lat(1)
700STARTLON=lon(1)
701DELTALAT=lat(latlen)-lat(latlen-1)
702DELTALON=lon(lonlen)-lon(lonlen-1)
703!
704! Open the data destination file
705!
706output="./WPSFEED/"//ident//":"//date_out2(l)       
707open(UNIT=1,                    &
708        FILE=output,            &
709        STATUS='REPLACE',       &
710        FORM='UNFORMATTED',     &
711        ACCESS='SEQUENTIAL')
712
713!------------------------!   
714! >>> Write a variable   !
715!    ... Copy&Paste part !
716!------------------------!
717FIELD='T'
718UNITS='K'
719DESC='Atmospheric temperature'
720XLVL=200100.
721!SLAB=tsfile(:,:,time_out(l))
722!SLAB=tfileorig(:,:,1,time_out(l))
723SLAB=tnsfile(:,:,time_out(l))
724        ! And now put everything in the destination file
725        ! ... Header
726        write(1) IFV
727        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
728        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
729        ! ... Data
730        write(1) SLAB
731!print *,'The field '//DESC//' was written to '//output
732
733!------------------------!   
734! >>> Write a variable   !
735!    ... Copy&Paste part !
736!------------------------!
737FIELD='U'
738UNITS='m s{-1}'
739DESC='Zonal wind'
740XLVL=200100.
741!SLAB=ufile(:,:,1,time_out(l))
742!SLAB=ufileorig(:,:,1,time_out(l))
743SLAB=unsfile(:,:,time_out(l))
744        ! And now put everything in the destination file
745        ! ... Header
746        write(1) IFV
747        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
748        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
749        ! ... Data
750        write(1) SLAB
751!print *,'The field '//DESC//' was written to '//output
752
753!------------------------!   
754! >>> Write a variable   !
755!    ... Copy&Paste part !
756!------------------------!
757FIELD='V'
758UNITS='m s{-1}'
759DESC='Meridional wind'
760XLVL=200100.
761!SLAB=vfile(:,:,1,time_out(l))
762!SLAB=vfileorig(:,:,1,time_out(l))
763SLAB=vnsfile(:,:,time_out(l))
764        ! And now put everything in the destination file
765        ! ... Header
766        write(1) IFV
767        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
768        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
769        ! ... Data
770        write(1) SLAB
771!print *,'The field '//DESC//' was written to '//output
772
773!------------------------!   
774! >>> Write a variable   !
775!    ... Copy&Paste part !
776!------------------------!
777FIELD='RH'
778UNITS=''
779DESC='Customized 2D static field'
780XLVL=200100.
781!SLAB=co2icefile(:,:,time_out(l))
782SLAB=vide(:,:)
783!SLAB=vide(:,:)+ptop
784        ! And now put everything in the destination file
785        ! ... Header
786        write(1) IFV
787        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
788        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
789        ! ... Data
790        write(1) SLAB
791!print *,'The field '//DESC//' was written to '//output
792
793!------------------------!   
794! >>> Write a variable   !
795!    ... Copy&Paste part !
796!------------------------!
797FIELD='SOILHGT'
798UNITS='m'
799DESC='Terrain field of source analysis'  !Ground geopotential height
800XLVL=200100.
801SLAB=ghtsfile(:,:)
802        ! And now put everything in the destination file
803        ! ... Header
804        write(1) IFV
805        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
806        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
807        ! ... Data
808        write(1) SLAB
809!print *,'The field '//DESC//' was written to '//output
810
811!------------------------!   
812! >>> Write a variable   !
813!    ... Copy&Paste part !
814!------------------------!
815FIELD='PSFC'
816UNITS='Pa'
817DESC='Surface Pressure'
818XLVL=200100.
819SLAB=psfile(:,:,time_out(l))
820        ! And now put everything in the destination file
821        ! ... Header
822        write(1) IFV
823        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
824        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
825        ! ... Data
826        write(1) SLAB
827!print *,'The field '//DESC//' was written to '//output
828
829!------------------------!   
830! >>> Write a variable   !
831!    ... Copy&Paste part !
832!------------------------!
833FIELD='ST000010'
834UNITS=''
835DESC='Emissivity'
836XLVL=200100.
837SLAB=emissfile(:,:,time_out(l))
838        ! And now put everything in the destination file
839        ! ... Header
840        write(1) IFV
841        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
842        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
843        ! ... Data
844        write(1) SLAB
845!print *,'The field '//DESC//' was written to '//output
846
847!------------------------!   
848! >>> Write a variable   !
849!    ... Copy&Paste part !
850!------------------------!
851FIELD='ST010040'
852UNITS=''
853DESC='CO2 ice'
854XLVL=200100.
855SLAB=co2icefile(:,:,time_out(l))
856        ! And now put everything in the destination file
857        ! ... Header
858        write(1) IFV
859        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
860        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
861        ! ... Data
862        write(1) SLAB
863!print *,'The field '//DESC//' was written to '//output
864
865!------------------------!   
866! >>> Write a variable   !
867!    ... Copy&Paste part !
868!------------------------!
869FIELD='ST040100'
870UNITS=''
871DESC='ZMEA'
872XLVL=200100.
873!SLAB=vide(:,:)
874SLAB=gwparam(:,:,1)
875        ! And now put everything in the destination file
876        ! ... Header
877        write(1) IFV
878        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
879        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON 
880        ! ... Data
881        write(1) SLAB
882!print *,'The field '//DESC//' was written to '//output
883
884!------------------------!   
885! >>> Write a variable   !
886!    ... Copy&Paste part !
887!------------------------!
888FIELD='ST100200'
889UNITS=''
890DESC='ZSTD'
891XLVL=200100.
892!SLAB=vide(:,:)
893SLAB=gwparam(:,:,2)
894        ! And now put everything in the destination file
895        ! ... Header
896        write(1) IFV
897        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
898        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON 
899        ! ... Data
900        write(1) SLAB
901!print *,'The field '//DESC//' was written to '//output
902
903!------------------------!   
904! >>> Write a variable   !
905!    ... Copy&Paste part !
906!------------------------!
907FIELD='LANDSEA'
908UNITS='0/1 Flag'
909DESC='Land/Sea flag'
910XLVL=200100.
911SLAB=ones(:,:)
912        ! And now put everything in the destination file
913        ! ... Header
914        write(1) IFV
915        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
916        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON 
917        ! ... Data
918        write(1) SLAB
919!print *,'The field '//DESC//' was written to '//output
920
921!------------------------!   
922! >>> Write a variable   !
923!    ... Copy&Paste part !
924!------------------------!
925FIELD='SKINTEMP'
926UNITS='K'
927DESC='Ground temperature'
928XLVL=200100.
929!SLAB=vide(:,:)
930SLAB=tsfile(:,:,time_out(l))
931        ! And now put everything in the destination file
932        ! ... Header
933        write(1) IFV
934        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
935        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
936        ! ... Data
937        write(1) SLAB
938!print *,'The field '//DESC//' was written to '//output
939
940!------------------------!   
941! >>> Write a variable   !
942!    ... Copy&Paste part !
943!------------------------!
944FIELD='SM000010'
945UNITS=''
946DESC='ZSIG'
947XLVL=200100.
948!SLAB=vide(:,:)
949SLAB=gwparam(:,:,3)
950        ! And now put everything in the destination file
951        ! ... Header
952        write(1) IFV
953        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
954        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
955        ! ... Data
956        write(1) SLAB
957!print *,'The field '//DESC//' was written to '//output
958
959!------------------------!   
960! >>> Write a variable   !
961!    ... Copy&Paste part !
962!------------------------!
963FIELD='SM010040'
964UNITS=''
965DESC='ZGAM'
966XLVL=200100.
967!SLAB=vide(:,:)
968SLAB=gwparam(:,:,4)
969        ! And now put everything in the destination file
970        ! ... Header
971        write(1) IFV
972        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
973        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
974        ! ... Data
975        write(1) SLAB
976!print *,'The field '//DESC//' was written to '//output
977
978!------------------------!   
979! >>> Write a variable   !
980!    ... Copy&Paste part !
981!------------------------!
982FIELD='SM040100'
983UNITS=''
984DESC='ZTHE'
985XLVL=200100.
986!SLAB=vide(:,:)
987SLAB=gwparam(:,:,5)
988        ! And now put everything in the destination file
989        ! ... Header
990        write(1) IFV
991        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
992        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
993        ! ... Data
994        write(1) SLAB
995!print *,'The field '//DESC//' was written to '//output
996
997!------------------------!   
998! >>> Write a variable   !
999!    ... Copy&Paste part !
1000!------------------------!
1001FIELD='SM100200'
1002UNITS='fraction'
1003DESC='Relative humidity'
1004XLVL=200100.
1005SLAB=vide(:,:)
1006        ! And now put everything in the destination file
1007        ! ... Header
1008        write(1) IFV
1009        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1010        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1011        ! ... Data
1012        write(1) SLAB
1013!print *,'The field '//DESC//' was written to '//output
1014
1015
1016!------------------------!
1017! >>> Write a variable   !
1018!    ... Copy&Paste part !
1019!------------------------!
1020FIELD='HV'
1021UNITS='kg/kg'
1022DESC='Water vapor'
1023XLVL=200100.
1024SLAB=waterfile(:,:,1,time_out(l))
1025        ! And now put everything in the destination file
1026        ! ... Header
1027        write(1) IFV
1028        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1029        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1030        ! ... Data
1031        write(1) SLAB
1032!print *,'The field '//DESC//' was written to '//output
1033
1034!------------------------!
1035! >>> Write a variable   !
1036!    ... Copy&Paste part !
1037!------------------------!
1038FIELD='HI'
1039UNITS='kg/kg'
1040DESC='Water ice'
1041XLVL=200100.
1042SLAB=watericefile(:,:,1,time_out(l))
1043        ! And now put everything in the destination file
1044        ! ... Header
1045        write(1) IFV
1046        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1047        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1048        ! ... Data
1049        write(1) SLAB
1050!print *,'The field '//DESC//' was written to '//output
1051
1052!------------------------!
1053! >>> Write a variable   !
1054!    ... Copy&Paste part !
1055!------------------------!
1056FIELD='TSOIL'
1057UNITS='K'
1058DESC='Soil temperature'
1059XLVL=200100.
1060SLAB=tsoilfile(:,:,1,time_out(l))
1061        ! And now put everything in the destination file
1062        ! ... Header
1063        write(1) IFV
1064        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1065        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1066        ! ... Data
1067        write(1) SLAB
1068!print *,'The field '//DESC//' was written to '//output
1069
1070!------------------------!
1071! >>> Write a variable   !
1072!    ... Copy&Paste part !
1073!------------------------!
1074FIELD='DSOIL'
1075UNITS='m'
1076DESC='Soil depths'
1077XLVL=200100.
1078SLAB=dsoilfile(:,:,1,time_out(l))
1079        ! And now put everything in the destination file
1080        ! ... Header
1081        write(1) IFV
1082        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1083        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1084        ! ... Data
1085        write(1) SLAB
1086!print *,'The field '//DESC//' was written to '//output
1087
1088!------------------------!
1089! >>> Write a variable   !
1090!    ... Copy&Paste part !
1091!------------------------!
1092FIELD='ISOIL'
1093UNITS='tiu'
1094DESC='Soil thermal inertia'
1095XLVL=200100.
1096SLAB=isoilfile(:,:,1,time_out(l))
1097        ! And now put everything in the destination file
1098        ! ... Header
1099        write(1) IFV
1100        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1101        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1102        ! ... Data
1103        write(1) SLAB
1104!print *,'The field '//DESC//' was written to '//output
1105
1106
1107!!----------------------------------------------------
1108!! Write file in intermediate format for WPS
1109!! 2. 3D meteorological data
1110!! >>> same stuff, but handle vertical profile
1111!! >>> !! XLVL must be decreasing (pressure levels)
1112!!----------------------------------------------------
1113
1114!------------------------!   
1115! >>> Write a variable   !
1116!    ... Copy&Paste part !
1117!------------------------!
1118FIELD='T'
1119UNITS='K'
1120DESC='Atmospheric temperature'
1121DO k = 1,altlen
1122        XLVL=levels(k)
1123        SLAB=tfile(:,:,k,time_out(l))
1124                ! And now put everything in the destination file
1125                ! ... Header
1126        write(1) IFV
1127        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1128        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON 
1129                ! ... Data
1130                write(1) SLAB
1131END DO
1132!print *,'The field '//DESC//' was written to '//output
1133
1134!------------------------!   
1135! >>> Write a variable   !
1136!    ... Copy&Paste part !
1137!------------------------!
1138FIELD='U'
1139UNITS='m s{-1}'
1140DESC='Zonal wind'
1141DO k = 1,altlen
1142        XLVL=levels(k)
1143        SLAB=ufile(:,:,k,time_out(l))
1144                ! And now put everything in the destination file
1145                ! ... Header
1146        write(1) IFV
1147        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1148        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON 
1149                ! ... Data
1150                write(1) SLAB
1151END DO
1152!print *,'The field '//DESC//' was written to '//output
1153
1154!------------------------!   
1155! >>> Write a variable   !
1156!    ... Copy&Paste part !
1157!------------------------!
1158FIELD='V'
1159UNITS='m s{-1}'
1160DESC='Meridional wind'
1161DO k = 1,altlen
1162        XLVL=levels(k)
1163        SLAB=vfile(:,:,k,time_out(l))
1164                ! And now put everything in the destination file
1165                ! ... Header
1166        write(1) IFV
1167        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1168        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON 
1169                ! ... Data
1170                write(1) SLAB
1171END DO
1172!print *,'The field '//DESC//' was written to '//output
1173
1174!------------------------!   
1175! >>> Write a variable   !
1176!    ... Copy&Paste part !
1177!------------------------!
1178FIELD='RH'
1179UNITS=''
1180DESC='Customized 2D static field'
1181DESC='Eta-levels from the GCM'
1182DESC='Pressure values from the GCM'
1183DO k = 1,altlen
1184        XLVL=levels(k)
1185SELECT CASE(ident)
1186CASE('LMD')
1187        SLAB=aps(k)+bps(k)*psfile(:,:,time_out(l))
1188CASE('OXF')
1189        SLAB=bps(k)*psfile(:,:,time_out(l))
1190END SELECT
1191                ! And now put everything in the destination file
1192                ! ... Header
1193        write(1) IFV
1194        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1195        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON 
1196                ! ... Data
1197                write(1) SLAB
1198END DO
1199!print *,'The field '//DESC//' was written to '//output
1200
1201!------------------------!   
1202! >>> Write a variable   !
1203!    ... Copy&Paste part !
1204!------------------------!
1205FIELD='HGT'
1206UNITS='m'
1207DESC='Height'
1208DO k = 1,altlen
1209        XLVL=levels(k)
1210!!*******
1211!! PROVISOIRE: normalement, il faudrait la hauteur geopotentielle
1212!!*******
1213!!however, not used by initialize_real
1214SELECT CASE(ident)
1215CASE('LMD')
1216        SLAB=10000.*alog(610./(aps(k)+bps(k)*psfile(:,:,time_out(l))))
1217CASE('OXF')
1218        SLAB=10000.*alog(610./(bps(k)*psfile(:,:,time_out(l))))
1219END SELECT
1220                ! And now put everything in the destination file
1221                ! ... Header
1222        write(1) IFV
1223        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1224        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON 
1225                ! ... Data
1226                write(1) SLAB
1227END DO
1228!print *,'The field '//DESC//' was written to '//output
1229
1230!------------------------!
1231! >>> Write a variable   !
1232!    ... Copy&Paste part !
1233!------------------------!
1234FIELD='HV'
1235UNITS='kg/kg'
1236DESC='Water vapor'
1237DO k = 1,altlen
1238        XLVL=levels(k)
1239        SLAB=waterfile(:,:,k,time_out(l))
1240                ! And now put everything in the destination file
1241                ! ... Header
1242        write(1) IFV
1243        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1244        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1245                ! ... Data
1246                write(1) SLAB
1247END DO
1248!print *,'The field '//DESC//' was written to '//output
1249
1250!------------------------!
1251! >>> Write a variable   !
1252!    ... Copy&Paste part !
1253!------------------------!
1254FIELD='HI'
1255UNITS='kg/kg'
1256DESC='Water ice'
1257DO k = 1,altlen
1258        XLVL=levels(k)
1259        SLAB=watericefile(:,:,k,time_out(l))
1260                ! And now put everything in the destination file
1261                ! ... Header
1262        write(1) IFV
1263        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1264        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1265                ! ... Data
1266                write(1) SLAB
1267END DO
1268!print *,'The field '//DESC//' was written to '//output
1269
1270!------------------------!
1271! >>> Write a variable   !
1272!    ... Copy&Paste part !
1273!------------------------!
1274FIELD='TSOIL'
1275UNITS='K'
1276DESC='Soil temperature'
1277DO k = 1,altlen
1278        XLVL=levels(k)
1279        SLAB=tsoilfile(:,:,k,time_out(l))
1280                ! And now put everything in the destination file
1281                ! ... Header
1282        write(1) IFV
1283        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1284        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1285                ! ... Data
1286                write(1) SLAB
1287END DO
1288!print *,'The field '//DESC//' was written to '//output
1289
1290!------------------------!
1291! >>> Write a variable   !
1292!    ... Copy&Paste part !
1293!------------------------!
1294FIELD='DSOIL'
1295UNITS='m'
1296DESC='Soil depths'
1297DO k = 1,altlen
1298        XLVL=levels(k)
1299        SLAB=dsoilfile(:,:,k,time_out(l))
1300                ! And now put everything in the destination file
1301                ! ... Header
1302        write(1) IFV
1303        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1304        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1305                ! ... Data
1306                write(1) SLAB
1307END DO
1308!print *,'The field '//DESC//' was written to '//output
1309
1310!------------------------!
1311! >>> Write a variable   !
1312!    ... Copy&Paste part !
1313!------------------------!
1314FIELD='ISOIL'
1315UNITS='tiu'
1316DESC='Soil thermal inertia'
1317DO k = 1,altlen
1318        XLVL=levels(k)
1319        SLAB=isoilfile(:,:,k,time_out(l))
1320                ! And now put everything in the destination file
1321                ! ... Header
1322        write(1) IFV
1323        write(1) HDATE,XFCST,SOURCE,FIELD,UNITS,DESC,XLVL,NX,NY,IPROJ
1324        write(1) STARTLOC,STARTLAT,STARTLON,DELTALAT,DELTALON
1325                ! ... Data
1326                write(1) SLAB
1327END DO
1328!print *,'The field '//DESC//' was written to '//output
1329
1330print *,'****done file '//output, int(100.*float(l)/float(FILES)), ' % '
1331close(1)
1332
1333DEALLOCATE(SLAB)
1334
1335END DO !! end of the files loop
1336
1337
1338!!-------------------------
1339!! DeAllocate local arrays
1340!!-------------------------
1341deallocate(eta_gcm)
1342deallocate(tfile)
1343deallocate(tsoilfile)
1344deallocate(isoilfile)
1345deallocate(dsoilfile)
1346deallocate(tfileorig)
1347deallocate(ufile)
1348deallocate(ufileorig)
1349deallocate(vfile)
1350deallocate(vfileorig)
1351deallocate(rfile)
1352deallocate(hfile) 
1353deallocate(waterfile)
1354deallocate(watericefile)
1355deallocate(psfile)
1356deallocate(tsfile)
1357deallocate(tnsfile)
1358deallocate(unsfile)
1359deallocate(vnsfile)
1360deallocate(emissfile)
1361deallocate(co2icefile)
1362deallocate(ghtsfile)    !! no scan axis
1363deallocate(vide)
1364deallocate(ones)
1365deallocate(lat, lon, alt, time)
1366deallocate(aps,bps,levels)
1367
1368
1369print *, '------------------------'
1370print *, 'End of pre-WPS process !'
1371print *, '------------------------'
1372print *, 'Here is what you should set in namelist.wps:'
1373print *, " start_date = '"//date_out2(1)//"'"
1374print *, " end_date = '"//date_out2(FILES)//"'"
1375print *, '------------------------'
1376print *, 'Any date between those is ok'
1377print *, 'for example, second available date is ... '//date_out2(2)
1378print *, '------------------------'
1379
1380end
Note: See TracBrowser for help on using the repository browser.