source: trunk/LMDZ.VENUS/Tools/io.F90 @ 3471

Last change on this file since 3471 was 1454, checked in by slebonnois, 9 years ago

SL: corrections in Titan and Venus tools

File size: 19.3 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,missing,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
231real :: missing ! missing value
232integer :: ierr1,ierr2,miss ! NetCDF routines return code
233
234! local
235integer tmpvarid ! temporarily store a variable ID
236
237ierr1=NF_INQ_VARID(infid,trim(text),tmpvarid)
238if (ierr1.ne.NF_NOERR) then
239  write(*,*) "Could not get ID for ",trim(text)
240else
241  write(*,*) "ID ok for ",trim(text)
242  ierr2=NF_GET_VAR_REAL(infid,tmpvarid,var)
243  miss=NF_GET_ATT_REAL(infid,tmpvarid,"missing_value",missing)
244endif
245
246return
247end
248
249!===========================================================================
250
251subroutine write_dim(outfid,dim1,dim2,dim3,dim4,lon,lat,plev,time,&
252                          lon_dimid,lat_dimid,alt_dimid,time_dimid)
253
254implicit none
255
256include "netcdf.inc" ! NetCDF definitions
257
258! arguments
259integer :: outfid ! NetCDF output file ID
260integer :: dim1,dim2,dim3,dim4 ! dim length of the 4D variable
261real,dimension(dim1) :: lon ! longitude
262real,dimension(dim2) :: lat ! latitude
263real,dimension(dim3) :: plev ! Pressure levels (Pa)
264real,dimension(dim4) :: time ! time
265integer lon_dimid,lat_dimid,alt_dimid,time_dimid ! NetCDF dimension IDs
266
267! local
268integer lon_varid,lat_varid,alt_varid,time_varid
269character (len=64) :: text ! to store some text
270integer ierr ! NetCDF routines return code
271
272
273!------------
274! longitude
275!------------
276
277ierr=NF_DEF_DIM(outfid,"longitude",dim1,lon_dimid)
278if (ierr.ne.NF_NOERR) stop "Error: Could not define longitude dimension"
279
280ierr=NF_DEF_VAR(outfid,"longitude",NF_REAL,1,lon_dimid,lon_varid)
281if (ierr.ne.NF_NOERR) stop "Error: Could not define longitude variable"
282
283! longitude attributes
284text='east longitude'
285ierr=NF_PUT_ATT_TEXT(outfid,lon_varid,'long_name',len_trim(text),text)
286if (ierr.ne.NF_NOERR) stop "Error: Problem writing long_name for longitude"
287
288text='degrees_east'
289ierr=NF_PUT_ATT_TEXT(outfid,lon_varid,'units',len_trim(text),text)
290if (ierr.ne.NF_NOERR) stop "Error: Problem writing units for longitude"
291
292!------------
293! latitude
294!------------
295
296ierr=NF_DEF_DIM(outfid,"latitude",dim2,lat_dimid)
297if (ierr.ne.NF_NOERR) stop "Error: Could not define latitude dimension"
298
299ierr=NF_DEF_VAR(outfid,"latitude",NF_REAL,1,lat_dimid,lat_varid)
300if (ierr.ne.NF_NOERR) stop "Error: Could not define latitude variable"
301
302! latitude attributes
303text='north latitude'
304ierr=NF_PUT_ATT_TEXT(outfid,lat_varid,'long_name',len_trim(text),text)
305if (ierr.ne.NF_NOERR) stop "Error: Problem writing long_name for latitude"
306
307text='degrees_north'
308ierr=NF_PUT_ATT_TEXT(outfid,lat_varid,'units',len_trim(text),text)
309if (ierr.ne.NF_NOERR) stop "Error: Problem writing units for latitude"
310
311!------------
312! pressure
313!------------
314
315ierr=NF_DEF_DIM(outfid,"presnivs",dim3,alt_dimid)
316if (ierr.ne.NF_NOERR) stop "Error: Could not define presnivs dimension"
317
318ierr=NF_DEF_VAR(outfid,"presnivs",NF_REAL,1,alt_dimid,alt_varid)
319if (ierr.ne.NF_NOERR) stop "Error: Could not define presnivs variable"
320
321!presnivs attributes
322text='Pressure levels'
323ierr=NF_PUT_ATT_TEXT(outfid,alt_varid,'long_name',len_trim(text),text)
324if (ierr.ne.NF_NOERR) stop "Error: Problem writing long_name for presnivs (p levels)"
325
326text='Pa'
327ierr=NF_PUT_ATT_TEXT(outfid,alt_varid,'units',len_trim(text),text)
328if (ierr.ne.NF_NOERR) stop "Error: Problem writing units for presnivs (p levels)"
329
330text='down'
331ierr=NF_PUT_ATT_TEXT(outfid,alt_varid,'positive',len_trim(text),text)
332if (ierr.ne.NF_NOERR) stop "Error: Problem writing positive for presnivs (p levels)"
333
334!------------
335! time
336!------------
337
338ierr=NF_DEF_DIM(outfid,"Time",dim4,time_dimid)
339if (ierr.ne.NF_NOERR) stop "Error: Could not define time dimension"
340
341ierr=NF_DEF_VAR(outfid,"Time",NF_REAL,1,time_dimid,time_varid)
342if (ierr.ne.NF_NOERR) stop "Error: Could not define Time variable"
343
344! time attributes
345text='Time'
346ierr=NF_PUT_ATT_TEXT(outfid,time_varid,'long_name',len_trim(text),text)
347if (ierr.ne.NF_NOERR) stop "Error: Problem writing long_name for Time"
348
349text='days since 0000-01-1 00:00:00'
350ierr=NF_PUT_ATT_TEXT(outfid,time_varid,'units',len_trim(text),text)
351if (ierr.ne.NF_NOERR) stop "Error: Problem writing units for Time"
352
353print*,"End of dim definitions"
354
355!------------
356! Switch out of NetCDF define mode
357!------------
358ierr=NF_ENDDEF(outfid)
359if (ierr.ne.NF_NOERR) stop "Error: Could not switch out of define mode"
360
361! Write longitude
362ierr=NF_PUT_VAR_REAL(outfid,lon_varid,lon)
363if (ierr.ne.NF_NOERR) stop "Error: Could not write longitude data to output file"
364
365! Write latitude
366ierr=NF_PUT_VAR_REAL(outfid,lat_varid,lat)
367if (ierr.ne.NF_NOERR) stop "Error: Could not write latitude data to output file"
368
369! Write pressure
370ierr=NF_PUT_VAR_REAL(outfid,alt_varid,plev)
371if (ierr.ne.NF_NOERR) stop "Error: Could not write presnivs data to output file"
372
373! Write time
374ierr=NF_PUT_VAR_REAL(outfid,time_varid,time)
375if (ierr.ne.NF_NOERR) stop "Error: Could not write Time data to output file"
376
377print*,"Writing dim OK"
378
379return
380end
381
382
383!===========================================================================
384
385subroutine write_var1d(outfid,datashape,dim1,&
386                       name,lgname,units,miss_val,var)
387
388implicit none
389
390include "netcdf.inc" ! NetCDF definitions
391
392! arguments
393integer :: outfid ! NetCDF output file ID
394integer :: dim1 ! dim length of the 1D variable
395integer :: datashape ! shape of datasets
396character (len=10) :: name   ! name of variable
397character (len=20) :: lgname ! long name of variable
398character (len=10) :: units  ! unit of variable
399real :: miss_val ! "missing value" to specify missing data
400real,dimension(dim1) :: var ! variable to read
401
402! local
403character (len=64) :: text ! to store some text
404integer ierr ! NetCDF routines return code
405integer varid
406
407!------------
408! Define variable
409!------------
410
411ierr=NF_REDEF(outfid)
412if (ierr.ne.NF_NOERR) stop "Error: Could not switch into define mode"
413
414ierr=NF_DEF_VAR(outfid,trim(name),NF_REAL,1,datashape,varid)
415if (ierr.ne.NF_NOERR) then
416      write(*,*) "Error: Could not define variable : ",name
417      stop
418endif
419
420! attributes
421ierr=NF_PUT_ATT_TEXT(outfid,varid,'long_name',len_trim(lgname),lgname)
422if (ierr.ne.NF_NOERR) then
423      write(*,*) "Error: Problem writing long_name for ",name
424      stop
425endif
426
427ierr=NF_PUT_ATT_TEXT(outfid,varid,'units',len_trim(units),units)
428if (ierr.ne.NF_NOERR) then
429      write(*,*) "Error: Problem writing units for ",name
430      stop
431endif
432
433ierr=NF_PUT_ATT_REAL(outfid,varid,'missing_value',NF_REAL,1,miss_val)
434if (ierr.ne.NF_NOERR) then
435      write(*,*) "Error: failed to write missing_value for ",name
436      stop
437endif
438
439print*,"End of var def : ",name
440
441!------------
442! Switch out of NetCDF define mode
443!------------
444ierr=NF_ENDDEF(outfid)
445if (ierr.ne.NF_NOERR) stop "Error: Could not switch out of define mode"
446
447ierr=NF_PUT_VAR_REAL(outfid,varid,var)
448if (ierr.ne.NF_NOERR) then
449      write(*,*) "Error: Could not write var ",name
450      stop
451endif
452
453print*,"Writing var OK : ",name
454
455return
456end
457
458!===========================================================================
459
460subroutine write_var2d(outfid,datashape,dim1,dim2,&
461                       name,lgname,units,miss_val,var)
462
463implicit none
464
465include "netcdf.inc" ! NetCDF definitions
466
467! arguments
468integer :: outfid ! NetCDF output file ID
469integer :: dim1,dim2 ! dim length of the 2D variable
470integer,dimension(2) :: datashape ! shape of datasets
471character (len=10) :: name   ! name of variable
472character (len=20) :: lgname ! long name of variable
473character (len=10) :: units  ! unit of variable
474real :: miss_val ! "missing value" to specify missing data
475real,dimension(dim1,dim2) :: var ! variable to read
476
477! local
478character (len=64) :: text ! to store some text
479integer ierr ! NetCDF routines return code
480integer varid
481
482!------------
483! Define variable
484!------------
485
486ierr=NF_REDEF(outfid)
487if (ierr.ne.NF_NOERR) stop "Error: Could not switch into define mode"
488
489ierr=NF_DEF_VAR(outfid,trim(name),NF_REAL,2,datashape,varid)
490if (ierr.ne.NF_NOERR) then
491      write(*,*) "Error: Could not define variable : ",name
492      stop
493endif
494
495! attributes
496ierr=NF_PUT_ATT_TEXT(outfid,varid,'long_name',len_trim(lgname),lgname)
497if (ierr.ne.NF_NOERR) then
498      write(*,*) "Error: Problem writing long_name for ",name
499      stop
500endif
501
502ierr=NF_PUT_ATT_TEXT(outfid,varid,'units',len_trim(units),units)
503if (ierr.ne.NF_NOERR) then
504      write(*,*) "Error: Problem writing units for ",name
505      stop
506endif
507
508ierr=NF_PUT_ATT_REAL(outfid,varid,'missing_value',NF_REAL,1,miss_val)
509if (ierr.ne.NF_NOERR) then
510      write(*,*) "Error: failed to write missing_value for ",name
511      stop
512endif
513
514print*,"End of var def : ",name
515
516!------------
517! Switch out of NetCDF define mode
518!------------
519ierr=NF_ENDDEF(outfid)
520if (ierr.ne.NF_NOERR) stop "Error: Could not switch out of define mode"
521
522ierr=NF_PUT_VAR_REAL(outfid,varid,var)
523if (ierr.ne.NF_NOERR) then
524      write(*,*) "Error: Could not write var ",name
525      stop
526endif
527
528print*,"Writing var OK : ",name
529
530return
531end
532
533!===========================================================================
534
535subroutine write_var3d(outfid,datashape,dim1,dim2,dim3,&
536                       name,lgname,units,miss_val,var)
537
538implicit none
539
540include "netcdf.inc" ! NetCDF definitions
541
542! arguments
543integer :: outfid ! NetCDF output file ID
544integer :: dim1,dim2,dim3 ! dim length of the 3D variable
545integer,dimension(3) :: datashape ! shape of datasets
546character (len=10) :: name   ! name of variable
547character (len=20) :: lgname ! long name of variable
548character (len=10) :: units  ! unit of variable
549real :: miss_val ! "missing value" to specify missing data
550real,dimension(dim1,dim2,dim3) :: var ! variable to read
551
552! local
553character (len=64) :: text ! to store some text
554integer ierr ! NetCDF routines return code
555integer varid
556
557!------------
558! Define variable
559!------------
560
561ierr=NF_REDEF(outfid)
562if (ierr.ne.NF_NOERR) stop "Error: Could not switch into define mode"
563
564ierr=NF_DEF_VAR(outfid,trim(name),NF_REAL,3,datashape,varid)
565if (ierr.ne.NF_NOERR) then
566      write(*,*) "Error: Could not define variable : ",name
567      stop
568endif
569
570! attributes
571ierr=NF_PUT_ATT_TEXT(outfid,varid,'long_name',len_trim(lgname),lgname)
572if (ierr.ne.NF_NOERR) then
573      write(*,*) "Error: Problem writing long_name for ",name
574      stop
575endif
576
577ierr=NF_PUT_ATT_TEXT(outfid,varid,'units',len_trim(units),units)
578if (ierr.ne.NF_NOERR) then
579      write(*,*) "Error: Problem writing units for ",name
580      stop
581endif
582
583ierr=NF_PUT_ATT_REAL(outfid,varid,'missing_value',NF_REAL,1,miss_val)
584if (ierr.ne.NF_NOERR) then
585      write(*,*) "Error: failed to write missing_value for ",name
586      stop
587endif
588
589print*,"End of var def : ",name
590
591!------------
592! Switch out of NetCDF define mode
593!------------
594ierr=NF_ENDDEF(outfid)
595if (ierr.ne.NF_NOERR) stop "Error: Could not switch out of define mode"
596
597ierr=NF_PUT_VAR_REAL(outfid,varid,var)
598if (ierr.ne.NF_NOERR) then
599      write(*,*) "Error: Could not write var ",name
600      stop
601endif
602
603print*,"Writing var OK : ",name
604
605return
606end
607
608!===========================================================================
609
610subroutine write_var4d(outfid,datashape,dim1,dim2,dim3,dim4,&
611                       name,lgname,units,miss_val,var)
612
613implicit none
614
615include "netcdf.inc" ! NetCDF definitions
616
617! arguments
618integer :: outfid ! NetCDF output file ID
619integer :: dim1,dim2,dim3,dim4 ! dim length of the 4D variable
620integer,dimension(4) :: datashape ! shape of datasets
621character (len=10) :: name   ! name of variable
622character (len=20) :: lgname ! long name of variable
623character (len=10) :: units  ! unit of variable
624real :: miss_val ! "missing value" to specify missing data
625real,dimension(dim1,dim2,dim3,dim4) :: var ! variable to read
626
627! local
628character (len=64) :: text ! to store some text
629integer ierr ! NetCDF routines return code
630integer varid
631
632!------------
633! Define variable
634!------------
635
636ierr=NF_REDEF(outfid)
637if (ierr.ne.NF_NOERR) stop "Error: Could not switch into define mode"
638
639ierr=NF_DEF_VAR(outfid,trim(name),NF_REAL,4,datashape,varid)
640if (ierr.ne.NF_NOERR) then
641      write(*,*) "Error: Could not define variable : ",name
642      stop
643endif
644
645! attributes
646ierr=NF_PUT_ATT_TEXT(outfid,varid,'long_name',len_trim(lgname),lgname)
647if (ierr.ne.NF_NOERR) then
648      write(*,*) "Error: Problem writing long_name for ",name
649      stop
650endif
651
652ierr=NF_PUT_ATT_TEXT(outfid,varid,'units',len_trim(units),units)
653if (ierr.ne.NF_NOERR) then
654      write(*,*) "Error: Problem writing units for ",name
655      stop
656endif
657
658ierr=NF_PUT_ATT_REAL(outfid,varid,'missing_value',NF_REAL,1,miss_val)
659if (ierr.ne.NF_NOERR) then
660      write(*,*) "Error: failed to write missing_value for ",name
661      stop
662endif
663
664print*,"End of var def : ",name
665
666!------------
667! Switch out of NetCDF define mode
668!------------
669ierr=NF_ENDDEF(outfid)
670if (ierr.ne.NF_NOERR) stop "Error: Could not switch out of define mode"
671
672ierr=NF_PUT_VAR_REAL(outfid,varid,var)
673if (ierr.ne.NF_NOERR) then
674      write(*,*) "Error: Could not write var ",name
675      stop
676endif
677
678print*,"Writing var OK : ",name
679
680return
681end
682
683
Note: See TracBrowser for help on using the repository browser.