source: trunk/LMDZ.TITAN/Tools/io.F90 @ 819

Last change on this file since 819 was 816, checked in by slebonnois, 12 years ago

SL: tools for postprocessing (Veznus and Titan); see DOC/documentation/vt-tools.pdf

File size: 19.2 KB
Line 
1subroutine get_iddim(infid,latid,latlength,lonid,lonlength, &
2                           altid,altlength,timid,timelength,lmdflag )
3
4implicit none
5
6include "netcdf.inc" ! NetCDF definitions
7
8! arguments
9integer infid ! NetCDF input file ID
10integer lonid,latid,altid,timid
11integer lonlength ! # of grid points along longitude
12integer latlength ! # of grid points along latitude
13integer altlength ! # of grid point along altitude (of input datasets)
14integer timelength ! # of points along time
15logical lmdflag ! true=LMD, false=CAM
16
17!local
18integer tmpdimid ! temporarily store a dimension ID
19integer ierr ! NetCDF routines return code
20
21! latitude
22ierr=NF_INQ_DIMID(infid,"latitude",tmpdimid)
23if (ierr.ne.NF_NOERR) then
24  write(*,*) "Could not get latitude dimension ID"
25  write(*,*) "  looking for lat dimension instead... "
26  ierr=NF_INQ_DIMID(infid,"lat",tmpdimid)
27  if (ierr.ne.NF_NOERR) then
28    stop "Error: Failed to get lat dimension ID"
29  else
30    ierr=NF_INQ_VARID(infid,"lat",latid)
31    if (ierr.ne.NF_NOERR) then
32      stop "Error: Failed to get lat ID"
33    else
34      ierr=NF_INQ_DIMLEN(infid,tmpdimid,latlength)
35      if (ierr.ne.NF_NOERR) stop "Error: Failed to get lat length"
36    endif
37  endif
38else
39  ierr=NF_INQ_VARID(infid,"latitude",latid)
40  if (ierr.ne.NF_NOERR) then
41    stop "Error: Failed to get latitude ID"
42  else
43    ierr=NF_INQ_DIMLEN(infid,tmpdimid,latlength)
44    if (ierr.ne.NF_NOERR) stop "Error: Failed to get latitude length"
45  endif
46endif
47
48! longitude
49ierr=NF_INQ_DIMID(infid,"longitude",tmpdimid)
50if (ierr.ne.NF_NOERR) then
51  write(*,*) "Could not get longitude dimension ID"
52  write(*,*) "  looking for lon dimension instead... "
53  ierr=NF_INQ_DIMID(infid,"lon",tmpdimid)
54  if (ierr.ne.NF_NOERR) then
55    stop "Error: Failed to get lon dimension ID"
56  else
57    ierr=NF_INQ_VARID(infid,"lon",lonid)
58    if (ierr.ne.NF_NOERR) then
59      stop "Error: Failed to get lon ID"
60    else
61      ierr=NF_INQ_DIMLEN(infid,tmpdimid,lonlength)
62      if (ierr.ne.NF_NOERR) stop "Error: Failed to get lon length"
63    endif
64  endif
65else
66  ierr=NF_INQ_VARID(infid,"longitude",lonid)
67  if (ierr.ne.NF_NOERR) then
68    stop "Error: Failed to get longitude ID"
69  else
70    ierr=NF_INQ_DIMLEN(infid,tmpdimid,lonlength)
71    if (ierr.ne.NF_NOERR) stop "Error: Failed to get longitude length"
72  endif
73endif
74
75lmdflag=.true.
76! altitude : pressure levels
77ierr=NF_INQ_DIMID(infid,"altitude",tmpdimid)
78if (ierr.ne.NF_NOERR) then
79  write(*,*) "Could not get altitude dimension ID"
80  write(*,*) "  looking for presnivs dimension instead... "
81  ierr=NF_INQ_DIMID(infid,"presnivs",tmpdimid)
82  if (ierr.ne.NF_NOERR) then
83    write(*,*) "Could not get presnivs dimension ID"
84    write(*,*) "  looking for lev dimension instead... "
85    ierr=NF_INQ_DIMID(infid,"lev",tmpdimid)
86    if (ierr.ne.NF_NOERR) then
87      stop "Error: Failed to get lev dimension ID"
88    else
89      ierr=NF_INQ_VARID(infid,"lev",altid)
90      if (ierr.ne.NF_NOERR) then
91        stop "Error: Failed to get lev ID"
92      else
93        ierr=NF_INQ_DIMLEN(infid,tmpdimid,altlength)
94        if (ierr.ne.NF_NOERR) stop "Error: Failed to get lev length"
95        lmdflag=.false.
96      endif
97    endif
98  else
99    ierr=NF_INQ_VARID(infid,"presnivs",altid)
100    if (ierr.ne.NF_NOERR) then
101      stop "Error: Failed to get presnivs ID"
102    else
103      ierr=NF_INQ_DIMLEN(infid,tmpdimid,altlength)
104      if (ierr.ne.NF_NOERR) stop "Error: Failed to get presnivs length"
105    endif
106  endif
107else
108  ierr=NF_INQ_VARID(infid,"altitude",altid)
109  if (ierr.ne.NF_NOERR) then
110    stop "Error: Failed to get altitude ID"
111  else
112    ierr=NF_INQ_DIMLEN(infid,tmpdimid,altlength)
113    if (ierr.ne.NF_NOERR) stop "Error: Failed to get altitude length"
114  endif
115endif
116
117! time
118ierr=NF_INQ_DIMID(infid,"Time",tmpdimid)
119if (ierr.ne.NF_NOERR) then
120  write(*,*) "Could not get Time dimension ID"
121  write(*,*) "  looking for time dimension instead... "
122  ierr=NF_INQ_DIMID(infid,"time",tmpdimid)
123 if (ierr.ne.NF_NOERR) then
124  write(*,*) "Could not get time dimension ID"
125  write(*,*) "  looking for time_counter dimension instead... "
126  ierr=NF_INQ_DIMID(infid,"time_counter",tmpdimid)
127  if (ierr.ne.NF_NOERR) then
128    stop "Error: Failed to get time_counter dimension ID"
129  else
130    ierr=NF_INQ_VARID(infid,"time_counter",timid)
131    if (ierr.ne.NF_NOERR) then
132      stop "Error: Failed to get time_counter ID"
133    else
134      ierr=NF_INQ_DIMLEN(infid,tmpdimid,timelength)
135      if (ierr.ne.NF_NOERR) stop "Error: Failed to get time_counter length"
136    endif
137  endif
138 else
139    ierr=NF_INQ_VARID(infid,"time",timid)
140    if (ierr.ne.NF_NOERR) then
141      stop "Error: Failed to get time ID"
142    else
143      ierr=NF_INQ_DIMLEN(infid,tmpdimid,timelength)
144      if (ierr.ne.NF_NOERR) stop "Error: Failed to get time length"
145    endif
146 endif
147else
148  ierr=NF_INQ_VARID(infid,"Time",timid)
149  if (ierr.ne.NF_NOERR) then
150    stop "Error: Failed to get Time ID"
151  else
152    ierr=NF_INQ_DIMLEN(infid,tmpdimid,timelength)
153    if (ierr.ne.NF_NOERR) stop "Error: Failed to get Time length"
154  endif
155endif
156
157return
158end
159
160!===========================================================================
161
162subroutine get_var2d(infid,dim1,dim2,text,var,ierr1,ierr2)
163
164implicit none
165
166include "netcdf.inc" ! NetCDF definitions
167
168! arguments
169integer :: infid ! NetCDF input file ID
170integer :: dim1,dim2 ! dim length of the 3D variable
171character (len=64) :: text ! name of variable to read
172real,dimension(dim1,dim2) :: var ! variable to read
173integer :: ierr1,ierr2 ! NetCDF routines return code
174
175! local
176integer tmpvarid ! temporarily store a variable ID
177
178ierr1=NF_INQ_VARID(infid,trim(text),tmpvarid)
179if (ierr1.ne.NF_NOERR) then
180  write(*,*) "Could not get ID for ",trim(text)
181else
182  write(*,*) "ID ok for ",trim(text)
183  ierr2=NF_GET_VAR_REAL(infid,tmpvarid,var)
184endif
185
186return
187end
188
189!===========================================================================
190
191subroutine get_var3d(infid,dim1,dim2,dim3,text,var,ierr1,ierr2)
192
193implicit none
194
195include "netcdf.inc" ! NetCDF definitions
196
197! arguments
198integer :: infid ! NetCDF input file ID
199integer :: dim1,dim2,dim3 ! dim length of the 3D variable
200character (len=64) :: text ! name of variable to read
201real,dimension(dim1,dim2,dim3) :: var ! variable to read
202integer :: ierr1,ierr2 ! NetCDF routines return code
203
204! local
205integer tmpvarid ! temporarily store a variable ID
206
207ierr1=NF_INQ_VARID(infid,trim(text),tmpvarid)
208if (ierr1.ne.NF_NOERR) then
209  write(*,*) "Could not get ID for ",trim(text)
210else
211  write(*,*) "ID ok for ",trim(text)
212  ierr2=NF_GET_VAR_REAL(infid,tmpvarid,var)
213endif
214
215return
216end
217
218!===========================================================================
219
220subroutine get_var4d(infid,dim1,dim2,dim3,dim4,text,var,ierr1,ierr2)
221
222implicit none
223
224include "netcdf.inc" ! NetCDF definitions
225
226! arguments
227integer :: infid ! NetCDF input file ID
228integer :: dim1,dim2,dim3,dim4 ! dim length of the 4D variable
229character (len=64) :: text ! name of variable to read
230real,dimension(dim1,dim2,dim3,dim4) :: var ! variable to read
231integer :: ierr1,ierr2 ! NetCDF routines return code
232
233! local
234integer tmpvarid ! temporarily store a variable ID
235
236ierr1=NF_INQ_VARID(infid,trim(text),tmpvarid)
237if (ierr1.ne.NF_NOERR) then
238  write(*,*) "Could not get ID for ",trim(text)
239else
240  write(*,*) "ID ok for ",trim(text)
241  ierr2=NF_GET_VAR_REAL(infid,tmpvarid,var)
242endif
243
244return
245end
246
247!===========================================================================
248
249subroutine write_dim(outfid,dim1,dim2,dim3,dim4,lon,lat,plev,time,&
250                          lon_dimid,lat_dimid,alt_dimid,time_dimid)
251
252implicit none
253
254include "netcdf.inc" ! NetCDF definitions
255
256! arguments
257integer :: outfid ! NetCDF output file ID
258integer :: dim1,dim2,dim3,dim4 ! dim length of the 4D variable
259real,dimension(dim1) :: lon ! longitude
260real,dimension(dim2) :: lat ! latitude
261real,dimension(dim3) :: plev ! Pressure levels (Pa)
262real,dimension(dim4) :: time ! time
263integer lon_dimid,lat_dimid,alt_dimid,time_dimid ! NetCDF dimension IDs
264
265! local
266integer lon_varid,lat_varid,alt_varid,time_varid
267character (len=64) :: text ! to store some text
268integer ierr ! NetCDF routines return code
269
270
271!------------
272! longitude
273!------------
274
275ierr=NF_DEF_DIM(outfid,"longitude",dim1,lon_dimid)
276if (ierr.ne.NF_NOERR) stop "Error: Could not define longitude dimension"
277
278ierr=NF_DEF_VAR(outfid,"longitude",NF_REAL,1,lon_dimid,lon_varid)
279if (ierr.ne.NF_NOERR) stop "Error: Could not define longitude variable"
280
281! longitude attributes
282text='east longitude'
283ierr=NF_PUT_ATT_TEXT(outfid,lon_varid,'long_name',len_trim(text),text)
284if (ierr.ne.NF_NOERR) stop "Error: Problem writing long_name for longitude"
285
286text='degrees_east'
287ierr=NF_PUT_ATT_TEXT(outfid,lon_varid,'units',len_trim(text),text)
288if (ierr.ne.NF_NOERR) stop "Error: Problem writing units for longitude"
289
290!------------
291! latitude
292!------------
293
294ierr=NF_DEF_DIM(outfid,"latitude",dim2,lat_dimid)
295if (ierr.ne.NF_NOERR) stop "Error: Could not define latitude dimension"
296
297ierr=NF_DEF_VAR(outfid,"latitude",NF_REAL,1,lat_dimid,lat_varid)
298if (ierr.ne.NF_NOERR) stop "Error: Could not define latitude variable"
299
300! latitude attributes
301text='north latitude'
302ierr=NF_PUT_ATT_TEXT(outfid,lat_varid,'long_name',len_trim(text),text)
303if (ierr.ne.NF_NOERR) stop "Error: Problem writing long_name for latitude"
304
305text='degrees_north'
306ierr=NF_PUT_ATT_TEXT(outfid,lat_varid,'units',len_trim(text),text)
307if (ierr.ne.NF_NOERR) stop "Error: Problem writing units for latitude"
308
309!------------
310! pressure
311!------------
312
313ierr=NF_DEF_DIM(outfid,"presnivs",dim3,alt_dimid)
314if (ierr.ne.NF_NOERR) stop "Error: Could not define presnivs dimension"
315
316ierr=NF_DEF_VAR(outfid,"presnivs",NF_REAL,1,alt_dimid,alt_varid)
317if (ierr.ne.NF_NOERR) stop "Error: Could not define presnivs variable"
318
319!presnivs attributes
320text='Pressure levels'
321ierr=NF_PUT_ATT_TEXT(outfid,alt_varid,'long_name',len_trim(text),text)
322if (ierr.ne.NF_NOERR) stop "Error: Problem writing long_name for presnivs (p levels)"
323
324text='Pa'
325ierr=NF_PUT_ATT_TEXT(outfid,alt_varid,'units',len_trim(text),text)
326if (ierr.ne.NF_NOERR) stop "Error: Problem writing units for presnivs (p levels)"
327
328text='down'
329ierr=NF_PUT_ATT_TEXT(outfid,alt_varid,'positive',len_trim(text),text)
330if (ierr.ne.NF_NOERR) stop "Error: Problem writing positive for presnivs (p levels)"
331
332!------------
333! time
334!------------
335
336ierr=NF_DEF_DIM(outfid,"Time",dim4,time_dimid)
337if (ierr.ne.NF_NOERR) stop "Error: Could not define time dimension"
338
339ierr=NF_DEF_VAR(outfid,"Time",NF_REAL,1,time_dimid,time_varid)
340if (ierr.ne.NF_NOERR) stop "Error: Could not define Time variable"
341
342! time attributes
343text='Time'
344ierr=NF_PUT_ATT_TEXT(outfid,time_varid,'long_name',len_trim(text),text)
345if (ierr.ne.NF_NOERR) stop "Error: Problem writing long_name for Time"
346
347text='days since 0000-01-1 00:00:00'
348ierr=NF_PUT_ATT_TEXT(outfid,time_varid,'units',len_trim(text),text)
349if (ierr.ne.NF_NOERR) stop "Error: Problem writing units for Time"
350
351print*,"End of dim definitions"
352
353!------------
354! Switch out of NetCDF define mode
355!------------
356ierr=NF_ENDDEF(outfid)
357if (ierr.ne.NF_NOERR) stop "Error: Could not switch out of define mode"
358
359! Write longitude
360ierr=NF_PUT_VAR_REAL(outfid,lon_varid,lon)
361if (ierr.ne.NF_NOERR) stop "Error: Could not write longitude data to output file"
362
363! Write latitude
364ierr=NF_PUT_VAR_REAL(outfid,lat_varid,lat)
365if (ierr.ne.NF_NOERR) stop "Error: Could not write latitude data to output file"
366
367! Write pressure
368ierr=NF_PUT_VAR_REAL(outfid,alt_varid,plev)
369if (ierr.ne.NF_NOERR) stop "Error: Could not write presnivs data to output file"
370
371! Write time
372ierr=NF_PUT_VAR_REAL(outfid,time_varid,time)
373if (ierr.ne.NF_NOERR) stop "Error: Could not write Time data to output file"
374
375print*,"Writing dim OK"
376
377return
378end
379
380
381!===========================================================================
382
383subroutine write_var1d(outfid,datashape,dim1,&
384                       name,lgname,units,miss_val,var)
385
386implicit none
387
388include "netcdf.inc" ! NetCDF definitions
389
390! arguments
391integer :: outfid ! NetCDF output file ID
392integer :: dim1 ! dim length of the 1D variable
393integer :: datashape ! shape of datasets
394character (len=10) :: name   ! name of variable
395character (len=20) :: lgname ! long name of variable
396character (len=10) :: units  ! unit of variable
397real :: miss_val ! "missing value" to specify missing data
398real,dimension(dim1) :: var ! variable to read
399
400! local
401character (len=64) :: text ! to store some text
402integer ierr ! NetCDF routines return code
403integer varid
404
405!------------
406! Define variable
407!------------
408
409ierr=NF_REDEF(outfid)
410if (ierr.ne.NF_NOERR) stop "Error: Could not switch into define mode"
411
412ierr=NF_DEF_VAR(outfid,trim(name),NF_REAL,1,datashape,varid)
413if (ierr.ne.NF_NOERR) then
414      write(*,*) "Error: Could not define variable : ",name
415      stop
416endif
417
418! attributes
419ierr=NF_PUT_ATT_TEXT(outfid,varid,'long_name',len_trim(lgname),lgname)
420if (ierr.ne.NF_NOERR) then
421      write(*,*) "Error: Problem writing long_name for ",name
422      stop
423endif
424
425ierr=NF_PUT_ATT_TEXT(outfid,varid,'units',len_trim(units),units)
426if (ierr.ne.NF_NOERR) then
427      write(*,*) "Error: Problem writing units for ",name
428      stop
429endif
430
431ierr=NF_PUT_ATT_REAL(outfid,varid,'missing_value',NF_REAL,1,miss_val)
432if (ierr.ne.NF_NOERR) then
433      write(*,*) "Error: failed to write missing_value for ",name
434      stop
435endif
436
437print*,"End of var def : ",name
438
439!------------
440! Switch out of NetCDF define mode
441!------------
442ierr=NF_ENDDEF(outfid)
443if (ierr.ne.NF_NOERR) stop "Error: Could not switch out of define mode"
444
445ierr=NF_PUT_VAR_REAL(outfid,varid,var)
446if (ierr.ne.NF_NOERR) then
447      write(*,*) "Error: Could not write var ",name
448      stop
449endif
450
451print*,"Writing var OK : ",name
452
453return
454end
455
456!===========================================================================
457
458subroutine write_var2d(outfid,datashape,dim1,dim2,&
459                       name,lgname,units,miss_val,var)
460
461implicit none
462
463include "netcdf.inc" ! NetCDF definitions
464
465! arguments
466integer :: outfid ! NetCDF output file ID
467integer :: dim1,dim2 ! dim length of the 2D variable
468integer,dimension(2) :: datashape ! shape of datasets
469character (len=10) :: name   ! name of variable
470character (len=20) :: lgname ! long name of variable
471character (len=10) :: units  ! unit of variable
472real :: miss_val ! "missing value" to specify missing data
473real,dimension(dim1,dim2) :: var ! variable to read
474
475! local
476character (len=64) :: text ! to store some text
477integer ierr ! NetCDF routines return code
478integer varid
479
480!------------
481! Define variable
482!------------
483
484ierr=NF_REDEF(outfid)
485if (ierr.ne.NF_NOERR) stop "Error: Could not switch into define mode"
486
487ierr=NF_DEF_VAR(outfid,trim(name),NF_REAL,2,datashape,varid)
488if (ierr.ne.NF_NOERR) then
489      write(*,*) "Error: Could not define variable : ",name
490      stop
491endif
492
493! attributes
494ierr=NF_PUT_ATT_TEXT(outfid,varid,'long_name',len_trim(lgname),lgname)
495if (ierr.ne.NF_NOERR) then
496      write(*,*) "Error: Problem writing long_name for ",name
497      stop
498endif
499
500ierr=NF_PUT_ATT_TEXT(outfid,varid,'units',len_trim(units),units)
501if (ierr.ne.NF_NOERR) then
502      write(*,*) "Error: Problem writing units for ",name
503      stop
504endif
505
506ierr=NF_PUT_ATT_REAL(outfid,varid,'missing_value',NF_REAL,1,miss_val)
507if (ierr.ne.NF_NOERR) then
508      write(*,*) "Error: failed to write missing_value for ",name
509      stop
510endif
511
512print*,"End of var def : ",name
513
514!------------
515! Switch out of NetCDF define mode
516!------------
517ierr=NF_ENDDEF(outfid)
518if (ierr.ne.NF_NOERR) stop "Error: Could not switch out of define mode"
519
520ierr=NF_PUT_VAR_REAL(outfid,varid,var)
521if (ierr.ne.NF_NOERR) then
522      write(*,*) "Error: Could not write var ",name
523      stop
524endif
525
526print*,"Writing var OK : ",name
527
528return
529end
530
531!===========================================================================
532
533subroutine write_var3d(outfid,datashape,dim1,dim2,dim3,&
534                       name,lgname,units,miss_val,var)
535
536implicit none
537
538include "netcdf.inc" ! NetCDF definitions
539
540! arguments
541integer :: outfid ! NetCDF output file ID
542integer :: dim1,dim2,dim3 ! dim length of the 3D variable
543integer,dimension(3) :: datashape ! shape of datasets
544character (len=10) :: name   ! name of variable
545character (len=20) :: lgname ! long name of variable
546character (len=10) :: units  ! unit of variable
547real :: miss_val ! "missing value" to specify missing data
548real,dimension(dim1,dim2,dim3) :: var ! variable to read
549
550! local
551character (len=64) :: text ! to store some text
552integer ierr ! NetCDF routines return code
553integer varid
554
555!------------
556! Define variable
557!------------
558
559ierr=NF_REDEF(outfid)
560if (ierr.ne.NF_NOERR) stop "Error: Could not switch into define mode"
561
562ierr=NF_DEF_VAR(outfid,trim(name),NF_REAL,3,datashape,varid)
563if (ierr.ne.NF_NOERR) then
564      write(*,*) "Error: Could not define variable : ",name
565      stop
566endif
567
568! attributes
569ierr=NF_PUT_ATT_TEXT(outfid,varid,'long_name',len_trim(lgname),lgname)
570if (ierr.ne.NF_NOERR) then
571      write(*,*) "Error: Problem writing long_name for ",name
572      stop
573endif
574
575ierr=NF_PUT_ATT_TEXT(outfid,varid,'units',len_trim(units),units)
576if (ierr.ne.NF_NOERR) then
577      write(*,*) "Error: Problem writing units for ",name
578      stop
579endif
580
581ierr=NF_PUT_ATT_REAL(outfid,varid,'missing_value',NF_REAL,1,miss_val)
582if (ierr.ne.NF_NOERR) then
583      write(*,*) "Error: failed to write missing_value for ",name
584      stop
585endif
586
587print*,"End of var def : ",name
588
589!------------
590! Switch out of NetCDF define mode
591!------------
592ierr=NF_ENDDEF(outfid)
593if (ierr.ne.NF_NOERR) stop "Error: Could not switch out of define mode"
594
595ierr=NF_PUT_VAR_REAL(outfid,varid,var)
596if (ierr.ne.NF_NOERR) then
597      write(*,*) "Error: Could not write var ",name
598      stop
599endif
600
601print*,"Writing var OK : ",name
602
603return
604end
605
606!===========================================================================
607
608subroutine write_var4d(outfid,datashape,dim1,dim2,dim3,dim4,&
609                       name,lgname,units,miss_val,var)
610
611implicit none
612
613include "netcdf.inc" ! NetCDF definitions
614
615! arguments
616integer :: outfid ! NetCDF output file ID
617integer :: dim1,dim2,dim3,dim4 ! dim length of the 4D variable
618integer,dimension(4) :: datashape ! shape of datasets
619character (len=10) :: name   ! name of variable
620character (len=20) :: lgname ! long name of variable
621character (len=10) :: units  ! unit of variable
622real :: miss_val ! "missing value" to specify missing data
623real,dimension(dim1,dim2,dim3,dim4) :: var ! variable to read
624
625! local
626character (len=64) :: text ! to store some text
627integer ierr ! NetCDF routines return code
628integer varid
629
630!------------
631! Define variable
632!------------
633
634ierr=NF_REDEF(outfid)
635if (ierr.ne.NF_NOERR) stop "Error: Could not switch into define mode"
636
637ierr=NF_DEF_VAR(outfid,trim(name),NF_REAL,4,datashape,varid)
638if (ierr.ne.NF_NOERR) then
639      write(*,*) "Error: Could not define variable : ",name
640      stop
641endif
642
643! attributes
644ierr=NF_PUT_ATT_TEXT(outfid,varid,'long_name',len_trim(lgname),lgname)
645if (ierr.ne.NF_NOERR) then
646      write(*,*) "Error: Problem writing long_name for ",name
647      stop
648endif
649
650ierr=NF_PUT_ATT_TEXT(outfid,varid,'units',len_trim(units),units)
651if (ierr.ne.NF_NOERR) then
652      write(*,*) "Error: Problem writing units for ",name
653      stop
654endif
655
656ierr=NF_PUT_ATT_REAL(outfid,varid,'missing_value',NF_REAL,1,miss_val)
657if (ierr.ne.NF_NOERR) then
658      write(*,*) "Error: failed to write missing_value for ",name
659      stop
660endif
661
662print*,"End of var def : ",name
663
664!------------
665! Switch out of NetCDF define mode
666!------------
667ierr=NF_ENDDEF(outfid)
668if (ierr.ne.NF_NOERR) stop "Error: Could not switch out of define mode"
669
670ierr=NF_PUT_VAR_REAL(outfid,varid,var)
671if (ierr.ne.NF_NOERR) then
672      write(*,*) "Error: Could not write var ",name
673      stop
674endif
675
676print*,"Writing var OK : ",name
677
678return
679end
680
681
Note: See TracBrowser for help on using the repository browser.