Subversion Repositories lagranto.wrf

Rev

Rev 2 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 10
1
      subroutine clscdf (cdfid, error)
1
      subroutine clscdf (cdfid, error)
2
c-----------------------------------------------------------------------
2
c-----------------------------------------------------------------------
3
c     Purpose:
3
c     Purpose:
4
c        This routine closes an open netCDF file.
4
c        This routine closes an open netCDF file.
5
c     Aguments :
5
c     Aguments :
6
c        cdfid  int  input   the id of the file to be closed.
6
c        cdfid  int  input   the id of the file to be closed.
7
c        error  int  output  indicates possible errors found in this
7
c        error  int  output  indicates possible errors found in this
8
c                            routine.
8
c                            routine.
9
c                            error = 0   no errors detected.
9
c                            error = 0   no errors detected.
10
c                            error = 1   error detected.
10
c                            error = 1   error detected.
11
c     History:
11
c     History:
12
c        Nov. 91  PPM  UW  Created.
12
c        Nov. 91  PPM  UW  Created.
13
c-----------------------------------------------------------------------
13
c-----------------------------------------------------------------------
14
 
14
 
15
      include "netcdf.inc"
15
      include "netcdf.inc"
16
 
16
 
17
c     Argument declarations.
17
c     Argument declarations.
18
      integer      cdfid, error
18
      integer      cdfid, error
19
 
19
 
20
c     Local variable declarations.
20
c     Local variable declarations.
21
      integer      ncopts
21
      integer      ncopts
22
 
22
 
23
c     Get current value of error options.
23
c     Get current value of error options.
24
      call ncgopt (ncopts)
24
      call ncgopt (ncopts)
25
 
25
 
26
c     Make sure netCDF errors do not abort execution.
26
c     Make sure netCDF errors do not abort execution.
27
      call ncpopt (NCVERBOS)
27
      call ncpopt (NCVERBOS)
28
 
28
 
29
c     Close requested file.
29
c     Close requested file.
30
      call ncclos (cdfid, error)
30
      call ncclos (cdfid, error)
31
 
31
 
32
c     Reset error options.
32
c     Reset error options.
33
      call ncpopt (ncopts)
33
      call ncpopt (ncopts)
34
 
34
 
35
      end
35
      end
36
 
36
 
37
 
37
 
38
      subroutine crecdf (filnam, cdfid, phymin, phymax, ndim, cfn, 
38
      subroutine crecdf (filnam, cdfid, phymin, phymax, ndim, cfn, 
39
     &                   error) 
39
     &                   error) 
40
c-----------------------------------------------------------------------
40
c-----------------------------------------------------------------------
41
c     Purpose:
41
c     Purpose:
42
c        This routine is called to create a netCDF file for use with 
42
c        This routine is called to create a netCDF file for use with 
43
c        the UWGAP plotting package.
43
c        the UWGAP plotting package.
44
c           Any netCDF file written to must be closed with the call
44
c           Any netCDF file written to must be closed with the call
45
c        'call clscdf(cdfid,error)', where cdfid and error are
45
c        'call clscdf(cdfid,error)', where cdfid and error are
46
c        as in the argumentlist below. 
46
c        as in the argumentlist below. 
47
c     Arguments:
47
c     Arguments:
48
c        filnam  char  input   the user-supplied netCDF file name.
48
c        filnam  char  input   the user-supplied netCDF file name.
49
c        cdfid   int   output  the file-identifier
49
c        cdfid   int   output  the file-identifier
50
c        phymin  real  input   the minimum physical dimension of the
50
c        phymin  real  input   the minimum physical dimension of the
51
c                              entire physical domain along each axis.
51
c                              entire physical domain along each axis.
52
c                              phymin is dimensioned (ndim)
52
c                              phymin is dimensioned (ndim)
53
c        phymax  real  input   the maximum physical dimension of the
53
c        phymax  real  input   the maximum physical dimension of the
54
c                              entire physical domain along each axis.
54
c                              entire physical domain along each axis.
55
c                              phymax is dimensioned (ndim)
55
c                              phymax is dimensioned (ndim)
56
c        ndim    int   input   the number of dimensions in the file
56
c        ndim    int   input   the number of dimensions in the file
57
c                              (i.e. number of elements in phymin,
57
c                              (i.e. number of elements in phymin,
58
c                              phymax)
58
c                              phymax)
59
c        cfn     char  input   constants file name 
59
c        cfn     char  input   constants file name 
60
c                              ('0' = no constants file).
60
c                              ('0' = no constants file).
61
c        error   int   output  indicates possible errors found in this
61
c        error   int   output  indicates possible errors found in this
62
c                              routine.
62
c                              routine.
63
c                              error = 0   no errors detected.
63
c                              error = 0   no errors detected.
64
c                              error = 1   error detected.
64
c                              error = 1   error detected.
65
c     History:
65
c     History:
66
c        Nov. 91  PPM  UW  Created cr3df.
66
c        Nov. 91  PPM  UW  Created cr3df.
67
c        Jan. 92  CS   UW  Created crecdf.
67
c        Jan. 92  CS   UW  Created crecdf.
68
c-----------------------------------------------------------------------
68
c-----------------------------------------------------------------------
69
 
69
 
70
      include "netcdf.inc"
70
      include "netcdf.inc"
71
 
71
 
72
c     Argument declarations.
72
c     Argument declarations.
73
      integer        MAXDIM
73
      integer        MAXDIM
74
      parameter      (MAXDIM=4)
74
      parameter      (MAXDIM=4)
75
      integer        ndim, error
75
      integer        ndim, error
76
      character *(*) filnam,cfn
76
      character *(*) filnam,cfn
77
      real           phymin(*), phymax(*)
77
      real           phymin(*), phymax(*)
78
 
78
 
79
c     Local variable declarations.
79
c     Local variable declarations.
80
      character *(20) attnam
80
      character *(20) attnam
81
      character *(1)  chrid(MAXDIM)
81
      character *(1)  chrid(MAXDIM)
82
      integer         cdfid, k, ibeg, iend, lenfil, ncopts
82
      integer         cdfid, k, ibeg, iend, lenfil, ncopts
83
      data            chrid/'x','y','z','a'/
83
      data            chrid/'x','y','z','a'/
84
 
84
 
85
c     Get current value of error options, and make sure netCDF-errors do
85
c     Get current value of error options, and make sure netCDF-errors do
86
c     not abort execution
86
c     not abort execution
87
      call ncgopt (ncopts)
87
      call ncgopt (ncopts)
88
      call ncpopt(NCVERBOS)
88
      call ncpopt(NCVERBOS)
89
 
89
 
90
c     Initially set error to indicate no errors.
90
c     Initially set error to indicate no errors.
91
      error = 0
91
      error = 0
92
 
92
 
93
c     create the netCDF file
93
c     create the netCDF file
94
      cdfid = nccre (trim(filnam), NCCLOB, error)
94
      cdfid = nccre (trim(filnam), NCCLOB, error)
95
      if (error.ne.0) go to 920
95
      if (error.ne.0) go to 920
96
 
96
 
97
c     define global attributes
97
c     define global attributes
98
      do k=1,ndim
98
      do k=1,ndim
99
        attnam(1:3)='dom'
99
        attnam(1:3)='dom'
100
        attnam(4:4)=chrid(k)
100
        attnam(4:4)=chrid(k)
101
        attnam(5:7)='min'
101
        attnam(5:7)='min'
102
        attnam=attnam(1:7)
102
        attnam=attnam(1:7)
103
        call ncapt(cdfid,NCGLOBAL,attnam,NCFLOAT,1,phymin(k),error)
103
        call ncapt(cdfid,NCGLOBAL,attnam,NCFLOAT,1,phymin(k),error)
104
        if (error.gt.0) goto 920
104
        if (error.gt.0) goto 920
105
 
105
 
106
        attnam(1:3)='dom'
106
        attnam(1:3)='dom'
107
        attnam(4:4)=chrid(k)
107
        attnam(4:4)=chrid(k)
108
        attnam(5:7)='max'
108
        attnam(5:7)='max'
109
        attnam=attnam(1:7)
109
        attnam=attnam(1:7)
110
        call ncapt(cdfid,NCGLOBAL,attnam,NCFLOAT,1,phymax(k),error)
110
        call ncapt(cdfid,NCGLOBAL,attnam,NCFLOAT,1,phymax(k),error)
111
        if (error.gt.0) goto 920
111
        if (error.gt.0) goto 920
112
      enddo
112
      enddo
113
 
113
 
114
c     define constants file name
114
c     define constants file name
115
      if (cfn.ne.'0') then
115
      if (cfn.ne.'0') then
116
        call ncaptc (cdfid, NCGLOBAL, 'constants_file_name',
116
        call ncaptc (cdfid, NCGLOBAL, 'constants_file_name',
117
c    &             NCCHAR, len_trim(cfn)+1, cfn // char(0) , error)
117
c    &             NCCHAR, len_trim(cfn)+1, cfn // char(0) , error)
118
     &             NCCHAR, len_trim(cfn), cfn , error)
118
     &             NCCHAR, len_trim(cfn), cfn , error)
119
        if (error.gt.0) goto 920
119
        if (error.gt.0) goto 920
120
      endif
120
      endif
121
 
121
 
122
c     End variable definitions.
122
c     End variable definitions.
123
      call ncendf (cdfid, error)
123
      call ncendf (cdfid, error)
124
      if (error.gt.0) goto 920
124
      if (error.gt.0) goto 920
125
 
125
 
126
c     normal exit
126
c     normal exit
127
      call ncpopt (ncopts)
127
      call ncpopt (ncopts)
128
      return
128
      return
129
 
129
 
130
c     error exit
130
c     error exit
131
 920  write (6, *) 'ERROR: An error occurred while attempting to ',
131
 920  write (6, *) 'ERROR: An error occurred while attempting to ',
132
     &             'create the data file in subroutine crecdf.'
132
     &             'create the data file in subroutine crecdf.'
133
      call ncpopt (ncopts)
133
      call ncpopt (ncopts)
134
      call ncclos (cdfid, error)
134
      call ncclos (cdfid, error)
135
      end
135
      end
136
 
136
 
137
      subroutine opncdf(filnam, cdfid,
137
      subroutine opncdf(filnam, cdfid,
138
     &                 phymin, phymax, ndim, varnam, nvar, cfn, error) 
138
     &                 phymin, phymax, ndim, varnam, nvar, cfn, error) 
139
c-----------------------------------------------------------------------
139
c-----------------------------------------------------------------------
140
c     Purpose:
140
c     Purpose:
141
c        This routine is called to open a netCDF file for read and write
141
c        This routine is called to open a netCDF file for read and write
142
c        with the UWGAP plotting package. 
142
c        with the UWGAP plotting package. 
143
c     Arguments:
143
c     Arguments:
144
c        filnam  char  input   the user-supplied netCDF file name.
144
c        filnam  char  input   the user-supplied netCDF file name.
145
c        cdfid   int   output  the file-identifier
145
c        cdfid   int   output  the file-identifier
146
c        phymin  real  output  the minimum physical dimension of the
146
c        phymin  real  output  the minimum physical dimension of the
147
c                              entire physical domain along each axis.
147
c                              entire physical domain along each axis.
148
c                              phymin is dimensioned (ndim)
148
c                              phymin is dimensioned (ndim)
149
c        phymax  real  output  the maximum physical dimension of the
149
c        phymax  real  output  the maximum physical dimension of the
150
c                              entire physical domain along each axis.
150
c                              entire physical domain along each axis.
151
c                              phymax is dimensioned (ndim)
151
c                              phymax is dimensioned (ndim)
152
c        ndim    int   output  the number of dimensions in the file
152
c        ndim    int   output  the number of dimensions in the file
153
c                              (i.e. number of elements in phymin,
153
c                              (i.e. number of elements in phymin,
154
c                              phymax)
154
c                              phymax)
155
c        varnam  char  output  an array containing the variable names.
155
c        varnam  char  output  an array containing the variable names.
156
c                              varnam is dimensioned (nvar).
156
c                              varnam is dimensioned (nvar).
157
c        nvar    int   output  the number of variables in the file
157
c        nvar    int   output  the number of variables in the file
158
c        cfn     char  output  constants file name 
158
c        cfn     char  output  constants file name 
159
c                              ('0'=no constants file).
159
c                              ('0'=no constants file).
160
c        error   int   output  indicates possible errors found in this
160
c        error   int   output  indicates possible errors found in this
161
c                              routine.
161
c                              routine.
162
c                              error = 0   no errors detected.
162
c                              error = 0   no errors detected.
163
c                              error = 1   error detected.
163
c                              error = 1   error detected.
164
c     History:
164
c     History:
165
c        Nov. 91  PPM  UW  Created cr3df.
165
c        Nov. 91  PPM  UW  Created cr3df.
166
c        Jan. 92  CS   UW  Created opncdf.
166
c        Jan. 92  CS   UW  Created opncdf.
167
c-----------------------------------------------------------------------
167
c-----------------------------------------------------------------------
168
 
168
 
169
      include "netcdf.inc"
169
      include "netcdf.inc"
170
 
170
 
171
c     Argument declarations.
171
c     Argument declarations.
172
      integer        MAXDIM
172
      integer        MAXDIM
173
      parameter      (MAXDIM=4)
173
      parameter      (MAXDIM=4)
174
      integer        ndim, nvar, error
174
      integer        ndim, nvar, error
175
      character *(*) filnam, varnam(*),cfn
175
      character *(*) filnam, varnam(*),cfn
176
      real           phymin(*), phymax(*)
176
      real           phymin(*), phymax(*)
177
 
177
 
178
c     Local variable declarations.
178
c     Local variable declarations.
179
      character *(20) attnam,vnam
179
      character *(20) attnam,vnam
180
      character *(1)  chrid(MAXDIM)
180
      character *(1)  chrid(MAXDIM)
181
      integer         cdfid, i,k
181
      integer         cdfid, i,k
182
      integer         ncopts, ndims,ngatts,recdim
182
      integer         ncopts, ndims,ngatts,recdim
183
      integer         nvdims,vartyp,nvatts,vardim(MAXDIM)
183
      integer         nvdims,vartyp,nvatts,vardim(MAXDIM)
184
      real            attval
184
      real            attval
185
      integer         lenstr
185
      integer         lenstr
186
      data            chrid/'x','y','z','a'/
186
      data            chrid/'x','y','z','a'/
187
      data            lenstr/80/
187
      data            lenstr/80/
188
 
188
 
189
c     Get current value of error options and make sure netCDF-errors do 
189
c     Get current value of error options and make sure netCDF-errors do 
190
c     not abort execution
190
c     not abort execution
191
      call ncgopt (ncopts)
191
      call ncgopt (ncopts)
192
      call ncpopt(NCVERBOS)
192
      call ncpopt(NCVERBOS)
193
 
193
 
194
c     Initially set error to indicate no errors.
194
c     Initially set error to indicate no errors.
195
      error = 0
195
      error = 0
196
 
196
 
197
c     open the netCDF file for write
197
c     open the netCDF file for write
198
      cdfid = ncopn (trim(filnam), NCWRITE, error)
198
      cdfid = ncopn (trim(filnam), NCWRITE, error)
199
      if (error.ne.0) then
199
      if (error.ne.0) then
200
c       try to open the netCDF file for read
200
c       try to open the netCDF file for read
201
        cdfid = ncopn (trim(filnam), NCNOWRIT, error)
201
        cdfid = ncopn (trim(filnam), NCNOWRIT, error)
202
        if (error.ne.0) go to 920
202
        if (error.ne.0) go to 920
203
      endif
203
      endif
204
 
204
 
205
c     inquire for number of variables
205
c     inquire for number of variables
206
      call ncinq(cdfid,ndims,nvar,ngatts,recdim,error)
206
      call ncinq(cdfid,ndims,nvar,ngatts,recdim,error)
207
      if (error.eq.1) goto 920
207
      if (error.eq.1) goto 920
208
 
208
 
209
c     read the variables
209
c     read the variables
210
      do i=1,nvar
210
      do i=1,nvar
211
        call ncvinq(cdfid,i,varnam(i),vartyp,nvdims,vardim,
211
        call ncvinq(cdfid,i,varnam(i),vartyp,nvdims,vardim,
212
     &                         nvatts,error)
212
     &                         nvatts,error)
213
        if (vartyp.ne.NCFLOAT) error=1
213
        if (vartyp.ne.NCFLOAT) error=1
214
        if (error.gt.0) goto 920
214
        if (error.gt.0) goto 920
215
      enddo
215
      enddo
216
 
216
 
217
c     get global attributes
217
c     get global attributes
218
      k=0
218
      k=0
219
  100 continue
219
  100 continue
220
        k=k+1
220
        k=k+1
221
        attnam(1:3)='dom'
221
        attnam(1:3)='dom'
222
        attnam(4:4)=chrid(k)
222
        attnam(4:4)=chrid(k)
223
        attnam(5:7)='min'
223
        attnam(5:7)='min'
224
        attnam=attnam(1:7)
224
        attnam=attnam(1:7)
225
 
225
 
226
c       switch off error message
226
c       switch off error message
227
        call ncpopt(0)
227
        call ncpopt(0)
228
 
228
 
229
c       check whether dimension k is present
229
c       check whether dimension k is present
230
        call ncagt(cdfid,NCGLOBAL,attnam,attval,error)
230
        call ncagt(cdfid,NCGLOBAL,attnam,attval,error)
231
        if (error.gt.0) goto 110
231
        if (error.gt.0) goto 110
232
        phymin(k)=attval
232
        phymin(k)=attval
233
 
233
 
234
        attnam(1:3)='dom'
234
        attnam(1:3)='dom'
235
        attnam(4:4)=chrid(k)
235
        attnam(4:4)=chrid(k)
236
        attnam(5:7)='max'
236
        attnam(5:7)='max'
237
        attnam=attnam(1:7)
237
        attnam=attnam(1:7)
238
        call ncagt(cdfid,NCGLOBAL,attnam,attval,error)
238
        call ncagt(cdfid,NCGLOBAL,attnam,attval,error)
239
        if (error.gt.0) goto 920
239
        if (error.gt.0) goto 920
240
        phymax(k)=attval
240
        phymax(k)=attval
241
      if (k.lt.3) goto 100
241
      if (k.lt.3) goto 100
242
      k=k+1
242
      k=k+1
243
 
243
 
244
c     define ndim-parameter
244
c     define ndim-parameter
245
 110  continue
245
 110  continue
246
      ndim=k-1
246
      ndim=k-1
247
      error=0
247
      error=0
248
 
248
 
249
c     switch on error messages
249
c     switch on error messages
250
      call ncpopt(NCVERBOS)
250
      call ncpopt(NCVERBOS)
251
 
251
 
252
c     get constants file name
252
c     get constants file name
253
c      call ncagt(cdfid,NCGLOBAL,'constants_file_name',cfn,error)
253
c      call ncagt(cdfid,NCGLOBAL,'constants_file_name',cfn,error)
254
c     ! chrigel
254
c     ! chrigel
255
      call ncagtc(cdfid,NCGLOBAL,'constants_file_name',cfn,lenstr,error)
255
      call ncagtc(cdfid,NCGLOBAL,'constants_file_name',cfn,lenstr,error)
256
      if (error.gt.0) cfn='0'
256
      if (error.gt.0) cfn='0'
257
 
257
 
258
c     normal exit
258
c     normal exit
259
      call ncpopt (ncopts)
259
      call ncpopt (ncopts)
260
      return
260
      return
261
 
261
 
262
c     error exit
262
c     error exit
263
 920  write (6, *) 'ERROR: An error occurred while attempting to ',
263
 920  write (6, *) 'ERROR: An error occurred while attempting to ',
264
     &             'read the data file in subroutine opncdf.'
264
     &             'read the data file in subroutine opncdf.'
265
      call ncclos (cdfid, error)
265
      call ncclos (cdfid, error)
266
      call ncpopt (ncopts)
266
      call ncpopt (ncopts)
267
      end
267
      end
268
 
268
 
269
 
269
 
270
      subroutine readcdf(filnam, cdfid,
270
      subroutine readcdf(filnam, cdfid,
271
     &                 phymin, phymax, ndim, varnam, nvar, cfn, error) 
271
     &                 phymin, phymax, ndim, varnam, nvar, cfn, error) 
272
c-----------------------------------------------------------------------
272
c-----------------------------------------------------------------------
273
c     Purpose:
273
c     Purpose:
274
c        This routine is called to open a netCDF file for read 
274
c        This routine is called to open a netCDF file for read 
275
c        with the UWGAP plotting package. 
275
c        with the UWGAP plotting package. 
276
c     Arguments:
276
c     Arguments:
277
c        filnam  char  input   the user-supplied netCDF file name.
277
c        filnam  char  input   the user-supplied netCDF file name.
278
c        cdfid   int   output  the file-identifier
278
c        cdfid   int   output  the file-identifier
279
c        phymin  real  output  the minimum physical dimension of the
279
c        phymin  real  output  the minimum physical dimension of the
280
c                              entire physical domain along each axis.
280
c                              entire physical domain along each axis.
281
c                              phymin is dimensioned (ndim)
281
c                              phymin is dimensioned (ndim)
282
c        phymax  real  output  the maximum physical dimension of the
282
c        phymax  real  output  the maximum physical dimension of the
283
c                              entire physical domain along each axis.
283
c                              entire physical domain along each axis.
284
c                              phymax is dimensioned (ndim)
284
c                              phymax is dimensioned (ndim)
285
c        ndim    int   output  the number of dimensions in the file
285
c        ndim    int   output  the number of dimensions in the file
286
c                              (i.e. number of elements in phymin,
286
c                              (i.e. number of elements in phymin,
287
c                              phymax)
287
c                              phymax)
288
c        varnam  char  output  an array containing the variable names.
288
c        varnam  char  output  an array containing the variable names.
289
c                              varnam is dimensioned (nvar).
289
c                              varnam is dimensioned (nvar).
290
c        nvar    int   output  the number of variables in the file
290
c        nvar    int   output  the number of variables in the file
291
c        cfn     char  output  constants file name 
291
c        cfn     char  output  constants file name 
292
c                              ('0'=no constants file).
292
c                              ('0'=no constants file).
293
c        error   int   output  indicates possible errors found in this
293
c        error   int   output  indicates possible errors found in this
294
c                              routine.
294
c                              routine.
295
c                              error = 0   no errors detected.
295
c                              error = 0   no errors detected.
296
c                              error = 1   error detected.
296
c                              error = 1   error detected.
297
c     History:
297
c     History:
298
c        Nov. 91  PPM  UW  Created cr3df.
298
c        Nov. 91  PPM  UW  Created cr3df.
299
c        Jan. 92  CS   UW  Created opncdf.
299
c        Jan. 92  CS   UW  Created opncdf.
300
c-----------------------------------------------------------------------
300
c-----------------------------------------------------------------------
301
 
301
 
302
      include "netcdf.inc"
302
      include "netcdf.inc"
303
 
303
 
304
c     Argument declarations.
304
c     Argument declarations.
305
      integer        MAXDIM
305
      integer        MAXDIM
306
      parameter      (MAXDIM=4)
306
      parameter      (MAXDIM=4)
307
      integer        ndim, nvar, error
307
      integer        ndim, nvar, error
308
      character *(*) filnam, varnam(*),cfn
308
      character *(*) filnam, varnam(*),cfn
309
      real           phymin(*), phymax(*)
309
      real           phymin(*), phymax(*)
310
 
310
 
311
 
311
 
312
c     Local variable declarations.
312
c     Local variable declarations.
313
      character *(20) attnam
313
      character *(20) attnam
314
      character *(1)  chrid(MAXDIM)
314
      character *(1)  chrid(MAXDIM)
315
      integer         cdfid, i,k
315
      integer         cdfid, i,k
316
      integer         ncopts, ndims,ngatts,recdim
316
      integer         ncopts, ndims,ngatts,recdim
317
      integer         nvdims,vartyp,nvatts,vardim(MAXDIM)
317
      integer         nvdims,vartyp,nvatts,vardim(MAXDIM)
318
      real            attval
318
      real            attval
319
      integer         lenstr
319
      integer         lenstr
320
      data            chrid/'x','y','z','a'/
320
      data            chrid/'x','y','z','a'/
321
      data            lenstr/80/
321
      data            lenstr/80/
322
 
322
 
323
c     Get current value of error options.
323
c     Get current value of error options.
324
      call ncgopt (ncopts)
324
      call ncgopt (ncopts)
325
 
325
 
326
c     make sure netCDF-errors do not abort execution
326
c     make sure netCDF-errors do not abort execution
327
      call ncpopt(NCVERBOS)
327
      call ncpopt(NCVERBOS)
328
 
328
 
329
c     Initially set error to indicate no errors.
329
c     Initially set error to indicate no errors.
330
      error = 0
330
      error = 0
331
 
331
 
332
c     open the netCDF file for read
332
c     open the netCDF file for read
333
      cdfid = ncopn (trim(filnam), NCNOWRIT, error)
333
      cdfid = ncopn (trim(filnam), NCNOWRIT, error)
334
      if (error.ne.0) go to 920
334
      if (error.ne.0) go to 920
335
 
335
 
336
c     inquire for number of variables
336
c     inquire for number of variables
337
      call ncinq(cdfid,ndims,nvar,ngatts,recdim,error)
337
      call ncinq(cdfid,ndims,nvar,ngatts,recdim,error)
338
      if (error.eq.1) goto 920
338
      if (error.eq.1) goto 920
339
 
339
 
340
c     read the variables
340
c     read the variables
341
      do i=1,nvar
341
      do i=1,nvar
342
        call ncvinq(cdfid,i,varnam(i),vartyp,nvdims,vardim,
342
        call ncvinq(cdfid,i,varnam(i),vartyp,nvdims,vardim,
343
     &                         nvatts,error)
343
     &                         nvatts,error)
344
        if (vartyp.ne.NCFLOAT) error=1
344
        if (vartyp.ne.NCFLOAT) error=1
345
c       print *,varnam(i),nvdims,nvatts
345
c       print *,varnam(i),nvdims,nvatts
346
        if (error.gt.0) goto 920
346
        if (error.gt.0) goto 920
347
      enddo
347
      enddo
348
 
348
 
349
c     get global attributes
349
c     get global attributes
350
      k=0
350
      k=0
351
  100 continue
351
  100 continue
352
        k=k+1
352
        k=k+1
353
        attnam(1:3)='dom'
353
        attnam(1:3)='dom'
354
        attnam(4:4)=chrid(k)
354
        attnam(4:4)=chrid(k)
355
        attnam(5:7)='min'
355
        attnam(5:7)='min'
356
        attnam=attnam(1:7)
356
        attnam=attnam(1:7)
357
 
357
 
358
c       switch off error message
358
c       switch off error message
359
        call ncpopt(0)
359
        call ncpopt(0)
360
 
360
 
361
c       check whether dimension k is present
361
c       check whether dimension k is present
362
        call ncagt(cdfid,NCGLOBAL,attnam,attval,error)
362
        call ncagt(cdfid,NCGLOBAL,attnam,attval,error)
363
        if (error.gt.0) goto 110
363
        if (error.gt.0) goto 110
364
        phymin(k)=attval
364
        phymin(k)=attval
365
 
365
 
366
        attnam(1:3)='dom'
366
        attnam(1:3)='dom'
367
        attnam(4:4)=chrid(k)
367
        attnam(4:4)=chrid(k)
368
        attnam(5:7)='max'
368
        attnam(5:7)='max'
369
        attnam=attnam(1:7)
369
        attnam=attnam(1:7)
370
        call ncagt(cdfid,NCGLOBAL,attnam,attval,error)
370
        call ncagt(cdfid,NCGLOBAL,attnam,attval,error)
371
        if (error.gt.0) goto 920
371
        if (error.gt.0) goto 920
372
        phymax(k)=attval
372
        phymax(k)=attval
373
      if (k.lt.4) goto 100
373
      if (k.lt.4) goto 100
374
      k=k+1
374
      k=k+1
375
 
375
 
376
c     define ndim-parameter
376
c     define ndim-parameter
377
 110  continue
377
 110  continue
378
      ndim=k-1
378
      ndim=k-1
379
      error=0
379
      error=0
380
 
380
 
381
c     switch on error messages
381
c     switch on error messages
382
      call ncpopt(NCVERBOS)
382
      call ncpopt(NCVERBOS)
383
 
383
 
384
c     get constants file name
384
c     get constants file name
385
c      call ncagt(cdfid,NCGLOBAL,'constants_file_name',cfn,error)
385
c      call ncagt(cdfid,NCGLOBAL,'constants_file_name',cfn,error)
386
c     ! chrigel
386
c     ! chrigel
387
      call ncagtc(cdfid,NCGLOBAL,'constants_file_name',cfn,lenstr,error)
387
      call ncagtc(cdfid,NCGLOBAL,'constants_file_name',cfn,lenstr,error)
388
      if (error.gt.0) cfn='0'
388
      if (error.gt.0) cfn='0'
389
c     print *,cfn
389
c     print *,cfn
390
 
390
 
391
c     normal exit
391
c     normal exit
392
      call ncpopt (ncopts)
392
      call ncpopt (ncopts)
393
      return
393
      return
394
 
394
 
395
c     error exit
395
c     error exit
396
 920  write (6, *) 'ERROR: An error occurred while attempting to ',
396
 920  write (6, *) 'ERROR: An error occurred while attempting to ',
397
     &             'read the data file in subroutine opncdf.'
397
     &             'read the data file in subroutine opncdf.'
398
      call ncclos (cdfid, error)
398
      call ncclos (cdfid, error)
399
      call ncpopt (ncopts)
399
      call ncpopt (ncopts)
400
      end
400
      end
401
 
401
 
402
 
402
 
403
 
403
 
404
      subroutine getcdf (cdfid, varnam, ndim, misdat, 
404
      subroutine getcdf (cdfid, varnam, ndim, misdat, 
405
     &                       vardim, varmin, varmax, stag, dat, error)
405
     &                       vardim, varmin, varmax, stag, dat, error)
406
c-----------------------------------------------------------------------
406
c-----------------------------------------------------------------------
407
c     Purpose:
407
c     Purpose:
408
c        This routine is called to get a variable and its attributes
408
c        This routine is called to get a variable and its attributes
409
c        from a netCDF file for use with the UWGAP plotting package. 
409
c        from a netCDF file for use with the UWGAP plotting package. 
410
c        It is assumed that the data is floating-point data. Prior to
410
c        It is assumed that the data is floating-point data. Prior to
411
c        calling this routine, the file must be opened with a call to
411
c        calling this routine, the file must be opened with a call to
412
c        opncdf.
412
c        opncdf.
413
c     Arguments:
413
c     Arguments:
414
c        cdfid   int   input   file-identifier
414
c        cdfid   int   input   file-identifier
415
c                              (can be obtained by calling routine 
415
c                              (can be obtained by calling routine 
416
c                              opncdf)
416
c                              opncdf)
417
c        varnam  char  input   the user-supplied variable name.
417
c        varnam  char  input   the user-supplied variable name.
418
c                              (can be obtained by calling routine 
418
c                              (can be obtained by calling routine 
419
c                              opncdf)
419
c                              opncdf)
420
c        ndim    int   output  the number of dimensions (ndim<=4)
420
c        ndim    int   output  the number of dimensions (ndim<=4)
421
c        misdat  real  output  missing data value for the variable. 
421
c        misdat  real  output  missing data value for the variable. 
422
c        vardim  int   output  the dimensions of the variable.
422
c        vardim  int   output  the dimensions of the variable.
423
c                              is dimensioned at least (ndim). 
423
c                              is dimensioned at least (ndim). 
424
c        varmin  real  output  the location in physical space of the
424
c        varmin  real  output  the location in physical space of the
425
c                              origin of each variable.
425
c                              origin of each variable.
426
c                              is dimensioned at least Min(ndim,3). 
426
c                              is dimensioned at least Min(ndim,3). 
427
c        varmax  real  output  the extent of each variable in physical
427
c        varmax  real  output  the extent of each variable in physical
428
c                              space.
428
c                              space.
429
c                              is dimensioned at least Min(ndim,3). 
429
c                              is dimensioned at least Min(ndim,3). 
430
c        stag    real  output  the grid staggering for each variable.
430
c        stag    real  output  the grid staggering for each variable.
431
c                              is dimensioned at least Min(ndim,3). 
431
c                              is dimensioned at least Min(ndim,3). 
432
c        dat     real  output  data-array dimensioned suffiecently 
432
c        dat     real  output  data-array dimensioned suffiecently 
433
c                              large, at least 
433
c                              large, at least 
434
c                              vardim(1)* ... vardim(ndim)
434
c                              vardim(1)* ... vardim(ndim)
435
c        error   int   output  indicates possible errors found in this
435
c        error   int   output  indicates possible errors found in this
436
c                              routine.
436
c                              routine.
437
c                              error = 0   no errors detected.
437
c                              error = 0   no errors detected.
438
c                              error = 1   error detected.
438
c                              error = 1   error detected.
439
c     History:
439
c     History:
440
c        Nov. 91  PPM  UW  Created cr3df.
440
c        Nov. 91  PPM  UW  Created cr3df.
441
c        Jan. 92  CS   UW  Created getcdf.
441
c        Jan. 92  CS   UW  Created getcdf.
442
c-----------------------------------------------------------------------
442
c-----------------------------------------------------------------------
443
 
443
 
444
      include "netcdf.inc"
444
      include "netcdf.inc"
445
 
445
 
446
c     Argument declarations.
446
c     Argument declarations.
447
      integer        MAXDIM
447
      integer        MAXDIM
448
      parameter      (MAXDIM=4)
448
      parameter      (MAXDIM=4)
449
      character *(*) varnam
449
      character *(*) varnam
450
      integer        vardim(*), ndim, error, cdfid
450
      integer        vardim(*), ndim, error, cdfid
451
      real           misdat,  stag(*), varmin(*), varmax(*), dat(*)
451
      real           misdat,  stag(*), varmin(*), varmax(*), dat(*)
452
 
452
 
453
c     Local variable declarations.
453
c     Local variable declarations.
454
      character *(20) dimnam(100),attnam
454
      character *(20) dimnam(100),attnam
455
      character *(1)  chrid(MAXDIM)
455
      character *(1)  chrid(MAXDIM)
456
      integer         id,i,k,corner(MAXDIM)
456
      integer         id,i,k,corner(MAXDIM)
457
      integer         ndims,nvars,ngatts,recdim,dimsiz(100)
457
      integer         ndims,nvars,ngatts,recdim,dimsiz(100)
458
      integer         vartyp,nvatts, ncopts
458
      integer         vartyp,nvatts, ncopts
459
      data            chrid/'x','y','z','a'/
459
      data            chrid/'x','y','z','a'/
460
      data            corner/1,1,1,1/
460
      data            corner/1,1,1,1/
461
 
461
 
462
c     Get current value of error options, and make sure netCDF-errors do 
462
c     Get current value of error options, and make sure netCDF-errors do 
463
c     not abort execution 
463
c     not abort execution 
464
      call ncgopt (ncopts)
464
      call ncgopt (ncopts)
465
      call ncpopt(NCVERBOS)
465
      call ncpopt(NCVERBOS)
466
 
466
 
467
c     Initially set error to indicate no errors.
467
c     Initially set error to indicate no errors.
468
      error = 0
468
      error = 0
469
 
469
 
470
c     inquire for number of dimensions
470
c     inquire for number of dimensions
471
      call ncinq(cdfid,ndims,nvars,ngatts,recdim,error)
471
      call ncinq(cdfid,ndims,nvars,ngatts,recdim,error)
472
      if (error.eq.1) goto 920
472
      if (error.eq.1) goto 920
473
 
473
 
474
c     read dimension-table
474
c     read dimension-table
475
      do i=1,ndims 
475
      do i=1,ndims 
476
        call ncdinq(cdfid,i,dimnam(i),dimsiz(i),error)
476
        call ncdinq(cdfid,i,dimnam(i),dimsiz(i),error)
477
        if (error.gt.0) goto 920
477
        if (error.gt.0) goto 920
478
      enddo
478
      enddo
479
 
479
 
480
c     get id of the variable
480
c     get id of the variable
481
      id=ncvid(cdfid,varnam,error)
481
      id=ncvid(cdfid,varnam,error)
482
      if (error.eq.1) goto 910
482
      if (error.eq.1) goto 910
483
 
483
 
484
c     inquire about variable
484
c     inquire about variable
485
      call ncvinq(cdfid,id,varnam,vartyp,ndim,vardim,nvatts,error)
485
      call ncvinq(cdfid,id,varnam,vartyp,ndim,vardim,nvatts,error)
486
      if (vartyp.ne.NCFLOAT) error=1
486
      if (vartyp.ne.NCFLOAT) error=1
487
      if (error.gt.0) goto 920
487
      if (error.gt.0) goto 920
488
 
488
 
489
c     Make sure ndim <= MAXDIM.
489
c     Make sure ndim <= MAXDIM.
490
      if (ndim.gt.MAXDIM) then
490
      if (ndim.gt.MAXDIM) then
491
         error = 1
491
         error = 1
492
         go to 900
492
         go to 900
493
      endif
493
      endif
494
 
494
 
495
c     get dimensions from dimension-table
495
c     get dimensions from dimension-table
496
      do k=1,ndim 
496
      do k=1,ndim 
497
        vardim(k)=dimsiz(vardim(k))
497
        vardim(k)=dimsiz(vardim(k))
498
      enddo
498
      enddo
499
 
499
 
500
c     get attributes
500
c     get attributes
501
      do k=1,min0(ndim,3)
501
      do k=1,min0(ndim,3)
502
c       get staggering
502
c       get staggering
503
        attnam(1:1)=chrid(k)
503
        attnam(1:1)=chrid(k)
504
        attnam(2:5)='stag'
504
        attnam(2:5)='stag'
505
        attnam=attnam(1:5)
505
        attnam=attnam(1:5)
506
        call ncagt(cdfid,id,attnam,stag(k),error)
506
        call ncagt(cdfid,id,attnam,stag(k),error)
507
        if (error.gt.0) goto 920
507
        if (error.gt.0) goto 920
508
c       get min postion
508
c       get min postion
509
        attnam(1:1)=chrid(k)
509
        attnam(1:1)=chrid(k)
510
        attnam(2:4)='min'
510
        attnam(2:4)='min'
511
        attnam=attnam(1:4)
511
        attnam=attnam(1:4)
512
        call ncagt(cdfid,id,attnam,varmin(k),error)
512
        call ncagt(cdfid,id,attnam,varmin(k),error)
513
        if (error.gt.0) goto 920
513
        if (error.gt.0) goto 920
514
c       get max position     
514
c       get max position     
515
        attnam(1:1)=chrid(k)
515
        attnam(1:1)=chrid(k)
516
        attnam(2:4)='max'
516
        attnam(2:4)='max'
517
        attnam=attnam(1:4)
517
        attnam=attnam(1:4)
518
        call ncagt(cdfid,id,attnam,varmax(k),error)
518
        call ncagt(cdfid,id,attnam,varmax(k),error)
519
        if (error.gt.0) goto 920     
519
        if (error.gt.0) goto 920     
520
      enddo
520
      enddo
521
 
521
 
522
c     get missing data value
522
c     get missing data value
523
      call ncagt(cdfid,id,'missing_data',misdat,error)
523
      call ncagt(cdfid,id,'missing_data',misdat,error)
524
      if (error.gt.0) goto 920     
524
      if (error.gt.0) goto 920     
525
 
525
 
526
c     get data
526
c     get data
527
      call ncvgt(cdfid,id,corner,vardim,dat,error)
527
      call ncvgt(cdfid,id,corner,vardim,dat,error)
528
      if (error.gt.0) goto 920
528
      if (error.gt.0) goto 920
529
 
529
 
530
c     normal exit
530
c     normal exit
531
      call ncpopt (ncopts)
531
      call ncpopt (ncopts)
532
      return
532
      return
533
 
533
 
534
 
534
 
535
c     Error exits.
535
c     Error exits.
536
 900  write (6, *) 'ERROR: When calling getcdf, the number of ',
536
 900  write (6, *) 'ERROR: When calling getcdf, the number of ',
537
     &             'variable dimensions must be less or equal 4.'
537
     &             'variable dimensions must be less or equal 4.'
538
      call ncpopt (ncopts)
538
      call ncpopt (ncopts)
539
      call ncclos (cdfid, error)
539
      call ncclos (cdfid, error)
540
      return
540
      return
541
 
541
 
542
 910  write (6, *) 'ERROR: The selected variable could not be found ',       
542
 910  write (6, *) 'ERROR: The selected variable could not be found ',       
543
     &             'in the file by getcdf.'
543
     &             'in the file by getcdf.'
544
      call ncpopt (ncopts)
544
      call ncpopt (ncopts)
545
      call ncclos (cdfid, error)
545
      call ncclos (cdfid, error)
546
      return
546
      return
547
 
547
 
548
 920  write (6, *) 'ERROR: An error occurred while attempting to ',
548
 920  write (6, *) 'ERROR: An error occurred while attempting to ',
549
     &             'read the data file in subroutine getcdf.'
549
     &             'read the data file in subroutine getcdf.'
550
      call ncpopt (ncopts)
550
      call ncpopt (ncopts)
551
      call ncclos (cdfid, error)
551
      call ncclos (cdfid, error)
552
      return
552
      return
553
 
553
 
554
      end
554
      end
555
 
555
 
556
 
556
 
557
      subroutine putcdf (cdfid, varnam, ndim, misdat, 
557
      subroutine putcdf (cdfid, varnam, ndim, misdat, 
558
     &                       vardim, varmin, varmax, stag, dat, error)
558
     &                       vardim, varmin, varmax, stag, dat, error)
559
c-----------------------------------------------------------------------
559
c-----------------------------------------------------------------------
560
c     Purpose:
560
c     Purpose:
561
c        This routine is called to put a variable and its attributes
561
c        This routine is called to put a variable and its attributes
562
c        onto a netCDF file for use with the UWGAP plotting package. 
562
c        onto a netCDF file for use with the UWGAP plotting package. 
563
c        It is assumed that the data is floating-point data. Prior to 
563
c        It is assumed that the data is floating-point data. Prior to 
564
c        calling this routine, the file must be created (crecdf) or
564
c        calling this routine, the file must be created (crecdf) or
565
c        opened (opncdf). 
565
c        opened (opncdf). 
566
c           Any netCDF file written to must be closed with the call
566
c           Any netCDF file written to must be closed with the call
567
c        call ncclos(cdfid,error), where cdfid and error are
567
c        call ncclos(cdfid,error), where cdfid and error are
568
c        as in the argumentlist below.
568
c        as in the argumentlist below.
569
c     Arguments:
569
c     Arguments:
570
c        cdfid   int   input   file-identifier
570
c        cdfid   int   input   file-identifier
571
c                              (can be obtained by calling routine 
571
c                              (can be obtained by calling routine 
572
c                              opncdf)
572
c                              opncdf)
573
c        varnam  char  input   the user-supplied variable name.
573
c        varnam  char  input   the user-supplied variable name.
574
c                              (can be obtained by calling routine 
574
c                              (can be obtained by calling routine 
575
c                              opncdf)
575
c                              opncdf)
576
c        ndim    int   input   the number of dimensions (ndim<=4)
576
c        ndim    int   input   the number of dimensions (ndim<=4)
577
c        misdat  real  input   missing data value for the variable. 
577
c        misdat  real  input   missing data value for the variable. 
578
c        vardim  int   input   the dimensions of the variable.
578
c        vardim  int   input   the dimensions of the variable.
579
c                              is dimensioned at least (ndim). 
579
c                              is dimensioned at least (ndim). 
580
c        varmin  real  input   the location in physical space of the
580
c        varmin  real  input   the location in physical space of the
581
c                              origin of each variable.
581
c                              origin of each variable.
582
c                              is dimensioned at least Min(ndim,3). 
582
c                              is dimensioned at least Min(ndim,3). 
583
c        varmax  real  input   the extent of each variable in physical
583
c        varmax  real  input   the extent of each variable in physical
584
c                              space.
584
c                              space.
585
c                              is dimensioned at least Min(ndim,3).  
585
c                              is dimensioned at least Min(ndim,3).  
586
c        stag    real  input   the grid staggering for each variable.
586
c        stag    real  input   the grid staggering for each variable.
587
c                              is dimensioned at least Min(ndim,3).  
587
c                              is dimensioned at least Min(ndim,3).  
588
c        dat     real  input   data-array dimensioned suffiecently 
588
c        dat     real  input   data-array dimensioned suffiecently 
589
c                              large, at least 
589
c                              large, at least 
590
c                              vardim(1)* ... vardim(ndim)
590
c                              vardim(1)* ... vardim(ndim)
591
c        error   int   output  indicates possible errors found in this
591
c        error   int   output  indicates possible errors found in this
592
c                              routine.
592
c                              routine.
593
c                              error = 0   no errors detected.
593
c                              error = 0   no errors detected.
594
c                              error = 1   error detected.
594
c                              error = 1   error detected.
595
c     History:
595
c     History:
596
c        Nov. 91  PPM  UW  Created cr3df, wr3df.
596
c        Nov. 91  PPM  UW  Created cr3df, wr3df.
597
c        Jan. 92  CS   UW  Created putcdf.
597
c        Jan. 92  CS   UW  Created putcdf.
598
c-----------------------------------------------------------------------
598
c-----------------------------------------------------------------------
599
 
599
 
600
      include "netcdf.inc"
600
      include "netcdf.inc"
601
 
601
 
602
c     Argument declarations.
602
c     Argument declarations.
603
      integer        MAXDIM
603
      integer        MAXDIM
604
      parameter      (MAXDIM=4)
604
      parameter      (MAXDIM=4)
605
      character *(*) varnam
605
      character *(*) varnam
606
      integer        vardim(*), ndim, error, cdfid
606
      integer        vardim(*), ndim, error, cdfid
607
      real           misdat,  stag(*), varmin(*), varmax(*), dat(*)
607
      real           misdat,  stag(*), varmin(*), varmax(*), dat(*)
608
 
608
 
609
c     Local variable declarations.
609
c     Local variable declarations.
610
      character *(20) dimnam,attnam,dimchk
610
      character *(20) dimnam,attnam,dimchk
611
      character *(1)  chrid(MAXDIM)
611
      character *(1)  chrid(MAXDIM)
612
      character *(20) dimnams(MAXNCDIM)
612
      character *(20) dimnams(MAXNCDIM)
613
      integer         dimvals(MAXNCDIM)
613
      integer         dimvals(MAXNCDIM)
614
      integer         numdims,numvars,numgats,dimulim
614
      integer         numdims,numvars,numgats,dimulim
615
      integer         id,did(MAXDIM),i,k,corner(MAXDIM)
615
      integer         id,did(MAXDIM),i,k,corner(MAXDIM)
616
      integer         ncopts
616
      integer         ncopts
617
      integer         ibeg,iend
617
      integer         ibeg,iend
618
      data            chrid/'x','y','z','t'/
618
      data            chrid/'x','y','z','t'/
619
      data            corner/1,1,1,1/
619
      data            corner/1,1,1,1/
620
 
620
 
621
c     Get current value of error options.
621
c     Get current value of error options.
622
      call ncgopt (ncopts)
622
      call ncgopt (ncopts)
623
 
623
 
624
c     make sure netCDF-errors do not abort execution
624
c     make sure netCDF-errors do not abort execution
625
      call ncpopt(NCVERBOS)
625
      call ncpopt(NCVERBOS)
626
 
626
 
627
c     Initially set error to indicate no errors.
627
c     Initially set error to indicate no errors.
628
      error = 0
628
      error = 0
629
 
629
 
630
c     Make sure ndim <= MAXDIM.
630
c     Make sure ndim <= MAXDIM.
631
      if (ndim.gt.MAXDIM) then
631
      if (ndim.gt.MAXDIM) then
632
         error = 1
632
         error = 1
633
         go to 900
633
         go to 900
634
      endif
634
      endif
635
 
635
 
636
c     Read existing dimensions-declarations from the file
636
c     Read existing dimensions-declarations from the file
637
      call ncinq(cdfid,numdims,numvars,numgats,dimulim,error)
637
      call ncinq(cdfid,numdims,numvars,numgats,dimulim,error)
638
      if (error.ne.0) numdims=0
638
      if (error.ne.0) numdims=0
639
      if (numdims.gt.0) then
639
      if (numdims.gt.0) then
640
        do i=1,numdims
640
        do i=1,numdims
641
          call ncdinq(cdfid,i,dimnams(i),dimvals(i),error)
641
          call ncdinq(cdfid,i,dimnams(i),dimvals(i),error)
642
c          print *,dimnams(i),dimvals(i)
642
c          print *,dimnams(i),dimvals(i)
643
        enddo
643
        enddo
644
      endif
644
      endif
645
 
645
 
646
c     put file into define mode
646
c     put file into define mode
647
      call ncredf(cdfid,error)
647
      call ncredf(cdfid,error)
648
      if (error.ne.0) goto 920
648
      if (error.ne.0) goto 920
649
 
649
 
650
c     define the dimension
650
c     define the dimension
651
      do k=1,ndim
651
      do k=1,ndim
652
c       define the dimension-name
652
c       define the dimension-name
653
        dimnam(1:3)='dim'
653
        dimnam(1:3)='dim'
654
        dimnam(4:4)=chrid(k)
654
        dimnam(4:4)=chrid(k)
655
        dimnam(5:5)='_'
655
        dimnam(5:5)='_'
656
        dimnam(6:5+len_trim(varnam))=trim(varnam)
656
        dimnam(6:5+len_trim(varnam))=trim(varnam)
657
        dimnam=dimnam(1:5+len_trim(varnam))
657
        dimnam=dimnam(1:5+len_trim(varnam))
658
        did(k)=-1
658
        did(k)=-1
659
        if (numdims.gt.0) then
659
        if (numdims.gt.0) then
660
c         check if an existing dimension-declaration can be used
660
c         check if an existing dimension-declaration can be used
661
c         instead of defining a nuw dimension
661
c         instead of defining a nuw dimension
662
          do i=1,numdims
662
          do i=1,numdims
663
            dimchk=dimnams(i)
663
            dimchk=dimnams(i)
664
            if ((vardim(k).eq.dimvals(i)).and.
664
            if ((vardim(k).eq.dimvals(i)).and.
665
     &        (dimnam(1:4).eq.dimchk(1:4))) then 
665
     &        (dimnam(1:4).eq.dimchk(1:4))) then 
666
              did(k)=i
666
              did(k)=i
667
              goto 100
667
              goto 100
668
            endif
668
            endif
669
          enddo
669
          enddo
670
 100      continue
670
 100      continue
671
        endif
671
        endif
672
        if (did(k).lt.0) then
672
        if (did(k).lt.0) then
673
c         define the dimension
673
c         define the dimension
674
          did(k)=ncddef(cdfid,dimnam,vardim(k),error)
674
          did(k)=ncddef(cdfid,dimnam,vardim(k),error)
675
          if (error.ne.0) goto 920
675
          if (error.ne.0) goto 920
676
        endif
676
        endif
677
      enddo
677
      enddo
678
 
678
 
679
c     define variable
679
c     define variable
680
      id=ncvdef(cdfid,varnam,NCFLOAT,ndim,did,error)
680
      id=ncvdef(cdfid,varnam,NCFLOAT,ndim,did,error)
681
      if (error.ne.0) goto 920
681
      if (error.ne.0) goto 920
682
 
682
 
683
c     define attributes
683
c     define attributes
684
      do k=1,min0(ndim,3)
684
      do k=1,min0(ndim,3)
685
c       staggering
685
c       staggering
686
        attnam(1:1)=chrid(k)
686
        attnam(1:1)=chrid(k)
687
        attnam(2:5)='stag'
687
        attnam(2:5)='stag'
688
        attnam=attnam(1:5)
688
        attnam=attnam(1:5)
689
        call ncapt(cdfid,id,attnam,NCFLOAT,1,stag(k),error)
689
        call ncapt(cdfid,id,attnam,NCFLOAT,1,stag(k),error)
690
        if (error.gt.0) goto 920
690
        if (error.gt.0) goto 920
691
c       min postion
691
c       min postion
692
        attnam(1:1)=chrid(k)
692
        attnam(1:1)=chrid(k)
693
        attnam(2:4)='min'
693
        attnam(2:4)='min'
694
        attnam=attnam(1:4)
694
        attnam=attnam(1:4)
695
        call ncapt(cdfid,id,attnam,NCFLOAT,1,varmin(k),error)
695
        call ncapt(cdfid,id,attnam,NCFLOAT,1,varmin(k),error)
696
        if (error.gt.0) goto 920
696
        if (error.gt.0) goto 920
697
c       max position     
697
c       max position     
698
        attnam(1:1)=chrid(k)
698
        attnam(1:1)=chrid(k)
699
        attnam(2:4)='max'
699
        attnam(2:4)='max'
700
        attnam=attnam(1:4)
700
        attnam=attnam(1:4)
701
        call ncapt(cdfid,id,attnam,NCFLOAT,1,varmax(k),error)
701
        call ncapt(cdfid,id,attnam,NCFLOAT,1,varmax(k),error)
702
        if (error.gt.0) goto 920     
702
        if (error.gt.0) goto 920     
703
      enddo
703
      enddo
704
 
704
 
705
c     define missing data value
705
c     define missing data value
706
      call ncapt(cdfid,id,'missing_data',NCFLOAT,1,misdat,error)
706
      call ncapt(cdfid,id,'missing_data',NCFLOAT,1,misdat,error)
707
      if (error.gt.0) goto 920     
707
      if (error.gt.0) goto 920     
708
 
708
 
709
c     leave define mode
709
c     leave define mode
710
      call ncendf(cdfid,error)
710
      call ncendf(cdfid,error)
711
      if (error.gt.0) goto 920     
711
      if (error.gt.0) goto 920     
712
 
712
 
713
c     define data
713
c     define data
714
      call ncvpt(cdfid,id,corner,vardim,dat,error)
714
      call ncvpt(cdfid,id,corner,vardim,dat,error)
715
      if (error.gt.0) goto 920
715
      if (error.gt.0) goto 920
716
 
716
 
717
c     synchronyse output to disk and exit
717
c     synchronyse output to disk and exit
718
      call ncsnc (cdfid,error)
718
      call ncsnc (cdfid,error)
719
      call ncpopt (ncopts)
719
      call ncpopt (ncopts)
720
      return
720
      return
721
 
721
 
722
c     Error exits.
722
c     Error exits.
723
 900  write (6, *) 'ERROR: When calling putcdf, the number of ',
723
 900  write (6, *) 'ERROR: When calling putcdf, the number of ',
724
     &             'variable dimensions must be less or equal 4.'
724
     &             'variable dimensions must be less or equal 4.'
725
      call ncpopt (ncopts)
725
      call ncpopt (ncopts)
726
      call ncclos (cdfid, error)
726
      call ncclos (cdfid, error)
727
      return
727
      return
728
 
728
 
729
 920  write (6, *) 'ERROR: An error occurred while attempting to ',
729
 920  write (6, *) 'ERROR: An error occurred while attempting to ',
730
     &             'write the data file in subroutine putcdf.'
730
     &             'write the data file in subroutine putcdf.'
731
      call ncpopt (ncopts)
731
      call ncpopt (ncopts)
732
      call ncclos (cdfid, error)
732
      call ncclos (cdfid, error)
733
      return
733
      return
734
      end
734
      end
735
c
735
c
736
c
736
c
737
      subroutine getdef (cdfid, varnam, ndim, misdat, 
737
      subroutine getdef (cdfid, varnam, ndim, misdat, 
738
     &                              vardim, varmin, varmax, stag, error)
738
     &                              vardim, varmin, varmax, stag, error)
739
c-----------------------------------------------------------------------
739
c-----------------------------------------------------------------------
740
c     Purpose:
740
c     Purpose:
741
c        This routine is called to get the dimensions and attributes of 
741
c        This routine is called to get the dimensions and attributes of 
742
c        a variable from an IVE-NetCDF file for use with the IVE plotting
742
c        a variable from an IVE-NetCDF file for use with the IVE plotting
743
c        package. Prior to calling this routine, the file must be opened
743
c        package. Prior to calling this routine, the file must be opened
744
c        with a call to opncdf.
744
c        with a call to opncdf.
745
c     Arguments:
745
c     Arguments:
746
c        cdfid   int   input   file-identifier
746
c        cdfid   int   input   file-identifier
747
c                              (can be obtained by calling routine 
747
c                              (can be obtained by calling routine 
748
c                              opncdf)
748
c                              opncdf)
749
c        varnam  char  input   the user-supplied variable name.
749
c        varnam  char  input   the user-supplied variable name.
750
c                              (can be obtained by calling routine 
750
c                              (can be obtained by calling routine 
751
c                              opncdf)
751
c                              opncdf)
752
c        ndim    int   output  the number of dimensions (ndim<=4)
752
c        ndim    int   output  the number of dimensions (ndim<=4)
753
c        misdat  real  output  missing data value for the variable. 
753
c        misdat  real  output  missing data value for the variable. 
754
c        vardim  int   output  the dimensions of the variable.
754
c        vardim  int   output  the dimensions of the variable.
755
c                              Is dimensioned at least (ndim). 
755
c                              Is dimensioned at least (ndim). 
756
c        varmin  real  output  the location in physical space of the
756
c        varmin  real  output  the location in physical space of the
757
c                              origin of each variable. 
757
c                              origin of each variable. 
758
c                              Is dimensioned at least Min(3,ndim). 
758
c                              Is dimensioned at least Min(3,ndim). 
759
c        varmax  real  output  the extend of each variable in physical
759
c        varmax  real  output  the extend of each variable in physical
760
c                              space.
760
c                              space.
761
c                              Is dimensioned at least Min(3,ndim). 
761
c                              Is dimensioned at least Min(3,ndim). 
762
c        stag    real  output  the grid staggering for each variable.
762
c        stag    real  output  the grid staggering for each variable.
763
c                              Is dimensioned at least Min(3,ndim). 
763
c                              Is dimensioned at least Min(3,ndim). 
764
c        error   int   output  indicates possible errors found in this
764
c        error   int   output  indicates possible errors found in this
765
c                              routine.
765
c                              routine.
766
c                              error = 0   no errors detected.
766
c                              error = 0   no errors detected.
767
c                              error = 1   the variable is not on the file.
767
c                              error = 1   the variable is not on the file.
768
c                              error =10   other errors.
768
c                              error =10   other errors.
769
c     History:
769
c     History:
770
c       Apr. 93    Christoph Schaer (ETHZ)     Created.
770
c       Apr. 93    Christoph Schaer (ETHZ)     Created.
771
c-----------------------------------------------------------------------
771
c-----------------------------------------------------------------------
772
 
772
 
773
      include "netcdf.inc"
773
      include "netcdf.inc"
774
 
774
 
775
c     Argument declarations.
775
c     Argument declarations.
776
      integer        MAXDIM
776
      integer        MAXDIM
777
      parameter      (MAXDIM=4)
777
      parameter      (MAXDIM=4)
778
      character *(*) varnam
778
      character *(*) varnam
779
      integer        vardim(*), ndim, error, cdfid
779
      integer        vardim(*), ndim, error, cdfid
780
      real           misdat,  stag(*), varmin(*), varmax(*)
780
      real           misdat,  stag(*), varmin(*), varmax(*)
781
 
781
 
782
c     Local variable declarations.
782
c     Local variable declarations.
783
      character *(20) dimnam(MAXNCDIM),attnam,vnam
783
      character *(20) dimnam(MAXNCDIM),attnam,vnam
784
      character *(1)  chrid(MAXDIM)
784
      character *(1)  chrid(MAXDIM)
785
      integer         id,i,k
785
      integer         id,i,k
786
      integer         ndims,nvars,ngatts,recdim,dimsiz(MAXNCDIM)
786
      integer         ndims,nvars,ngatts,recdim,dimsiz(MAXNCDIM)
787
      integer         vartyp,nvatts, ncopts
787
      integer         vartyp,nvatts, ncopts
788
      data            chrid/'x','y','z','t'/
788
      data            chrid/'x','y','z','t'/
789
 
789
 
790
c     Get current value of error options.
790
c     Get current value of error options.
791
      call ncgopt (ncopts)
791
      call ncgopt (ncopts)
792
 
792
 
793
c     make sure NetCDF-errors do not abort execution
793
c     make sure NetCDF-errors do not abort execution
794
      call ncpopt(NCVERBOS)
794
      call ncpopt(NCVERBOS)
795
 
795
 
796
c     Initially set error to indicate no errors.
796
c     Initially set error to indicate no errors.
797
      error = 0
797
      error = 0
798
 
798
 
799
c     inquire for number of dimensions
799
c     inquire for number of dimensions
800
      call ncinq(cdfid,ndims,nvars,ngatts,recdim,error)
800
      call ncinq(cdfid,ndims,nvars,ngatts,recdim,error)
801
      if (error.eq.1) goto 920
801
      if (error.eq.1) goto 920
802
 
802
 
803
c     read dimension-table
803
c     read dimension-table
804
      do i=1,ndims 
804
      do i=1,ndims 
805
        call ncdinq(cdfid,i,dimnam(i),dimsiz(i),error)
805
        call ncdinq(cdfid,i,dimnam(i),dimsiz(i),error)
806
        if (error.gt.0) goto 920
806
        if (error.gt.0) goto 920
807
      enddo
807
      enddo
808
 
808
 
809
c     get id of the variable
809
c     get id of the variable
810
      id=ncvid(cdfid,varnam,error)
810
      id=ncvid(cdfid,varnam,error)
811
      if (error.eq.1) goto 910
811
      if (error.eq.1) goto 910
812
 
812
 
813
c     inquire about variable
813
c     inquire about variable
814
      call ncvinq(cdfid,id,vnam,vartyp,ndim,vardim,nvatts,error)
814
      call ncvinq(cdfid,id,vnam,vartyp,ndim,vardim,nvatts,error)
815
      if (vartyp.ne.NCFLOAT) error=1
815
      if (vartyp.ne.NCFLOAT) error=1
816
      if (error.gt.0) goto 920
816
      if (error.gt.0) goto 920
817
 
817
 
818
c     Make sure ndim <= MAXDIM.
818
c     Make sure ndim <= MAXDIM.
819
      if (ndim.gt.MAXDIM) then
819
      if (ndim.gt.MAXDIM) then
820
         error = 1
820
         error = 1
821
         go to 900
821
         go to 900
822
      endif
822
      endif
823
 
823
 
824
c     get dimensions from dimension-table
824
c     get dimensions from dimension-table
825
      do k=1,ndim 
825
      do k=1,ndim 
826
        vardim(k)=dimsiz(vardim(k))
826
        vardim(k)=dimsiz(vardim(k))
827
      enddo
827
      enddo
828
 
828
 
829
c     get attributes
829
c     get attributes
830
      do k=1,min0(3,ndim)
830
      do k=1,min0(3,ndim)
831
c       get min postion
831
c       get min postion
832
        attnam(1:1)=chrid(k)
832
        attnam(1:1)=chrid(k)
833
        attnam(2:4)='min'
833
        attnam(2:4)='min'
834
        attnam=attnam(1:4)
834
        attnam=attnam(1:4)
835
        call ncagt(cdfid,id,attnam,varmin(k),error)
835
        call ncagt(cdfid,id,attnam,varmin(k),error)
836
        if (error.gt.0) goto 920
836
        if (error.gt.0) goto 920
837
c       get max position     
837
c       get max position     
838
        attnam(1:1)=chrid(k)
838
        attnam(1:1)=chrid(k)
839
        attnam(2:4)='max'
839
        attnam(2:4)='max'
840
        attnam=attnam(1:4)
840
        attnam=attnam(1:4)
841
        call ncagt(cdfid,id,attnam,varmax(k),error)
841
        call ncagt(cdfid,id,attnam,varmax(k),error)
842
        if (error.gt.0) goto 920     
842
        if (error.gt.0) goto 920     
843
c       get staggering
843
c       get staggering
844
        attnam(1:1)=chrid(k)
844
        attnam(1:1)=chrid(k)
845
        attnam(2:5)='stag'
845
        attnam(2:5)='stag'
846
        attnam=attnam(1:5)
846
        attnam=attnam(1:5)
847
        call ncagt(cdfid,id,attnam,stag(k),error)
847
        call ncagt(cdfid,id,attnam,stag(k),error)
848
        if (error.gt.0) goto 920
848
        if (error.gt.0) goto 920
849
      enddo
849
      enddo
850
 
850
 
851
c     get missing data value
851
c     get missing data value
852
      call ncagt(cdfid,id,'missing_data',misdat,error)
852
      call ncagt(cdfid,id,'missing_data',misdat,error)
853
      if (error.gt.0) goto 920     
853
      if (error.gt.0) goto 920     
854
 
854
 
855
c     normal exit
855
c     normal exit
856
      call ncpopt (ncopts)
856
      call ncpopt (ncopts)
857
      return
857
      return
858
 
858
 
859
c     Error exits.
859
c     Error exits.
860
 900  write (6, *) '*ERROR*: When calling getcdf, the number of ',
860
 900  write (6, *) '*ERROR*: When calling getcdf, the number of ',
861
     &             'variable dimensions must be less or equal 4.'
861
     &             'variable dimensions must be less or equal 4.'
862
      call ncpopt (ncopts)
862
      call ncpopt (ncopts)
863
      call ncclos (cdfid, error)
863
      call ncclos (cdfid, error)
864
      return
864
      return
865
 
865
 
866
 910  write (6, *) '*ERROR*: The selected variable could not be found ',       
866
 910  write (6, *) '*ERROR*: The selected variable could not be found ',       
867
     &             'in the file by getcdf.'
867
     &             'in the file by getcdf.'
868
      call ncpopt (ncopts)
868
      call ncpopt (ncopts)
869
      call ncclos (cdfid, error)
869
      call ncclos (cdfid, error)
870
      return
870
      return
871
 
871
 
872
 920  write (6, *) '*ERROR*: An error occurred while attempting to ',
872
 920  write (6, *) '*ERROR*: An error occurred while attempting to ',
873
     &             'read the data file in subroutine getcdf.'
873
     &             'read the data file in subroutine getcdf.'
874
      call ncpopt (ncopts)
874
      call ncpopt (ncopts)
875
      call ncclos (cdfid, error)
875
      call ncclos (cdfid, error)
876
      end
876
      end
877
 
877
 
878
 
878
 
879
 
879
 
880
      subroutine getdat(cdfid, varnam, time, level, dat, error)
880
      subroutine getdat(cdfid, varnam, time, level, dat, error)
881
c-----------------------------------------------------------------------
881
c-----------------------------------------------------------------------
882
c     Purpose:
882
c     Purpose:
883
c        This routine is called to read the data of a variable
883
c        This routine is called to read the data of a variable
884
c        from an IVE-NetCDF file for use with the IVE plotting package. 
884
c        from an IVE-NetCDF file for use with the IVE plotting package. 
885
c        Prior to calling this routine, the file must be opened with 
885
c        Prior to calling this routine, the file must be opened with 
886
c        a call to opncdf (for extension) or crecdf (for creation) or
886
c        a call to opncdf (for extension) or crecdf (for creation) or
887
c        readcdf (for readonly).
887
c        readcdf (for readonly).
888
c     Arguments:
888
c     Arguments:
889
c        cdfid   int   input   file-identifier
889
c        cdfid   int   input   file-identifier
890
c                              (must be obtained by calling routine 
890
c                              (must be obtained by calling routine 
891
c                              opncdf,readcdf  or crecdf)
891
c                              opncdf,readcdf  or crecdf)
892
c        varnam  char  input   the user-supplied variable name (must 
892
c        varnam  char  input   the user-supplied variable name (must 
893
c                              previously be defined with a call to
893
c                              previously be defined with a call to
894
c                              putdef)
894
c                              putdef)
895
c        time    real  input   the user-supplied time-level of the
895
c        time    real  input   the user-supplied time-level of the
896
c                              data to be read from the file (the time-
896
c                              data to be read from the file (the time-
897
c                              levels stored in the file can be obtained
897
c                              levels stored in the file can be obtained
898
c                              with a call to gettimes). 
898
c                              with a call to gettimes). 
899
c        level   int   input   the horizontal level(s) to be read 
899
c        level   int   input   the horizontal level(s) to be read 
900
c                              to the NetCDF file. Suppose that the
900
c                              to the NetCDF file. Suppose that the
901
c                              variable is defined as (nx,ny,nz,nt).
901
c                              variable is defined as (nx,ny,nz,nt).
902
c                              level>0: the call reads the subdomain
902
c                              level>0: the call reads the subdomain
903
c                                       (1:nx,1:ny,level,itimes)
903
c                                       (1:nx,1:ny,level,itimes)
904
c                              level=0: the call reads the subdomain
904
c                              level=0: the call reads the subdomain
905
c                                       (1:nx,1:ny,1:nz,itimes)
905
c                                       (1:nx,1:ny,1:nz,itimes)
906
c                              Here itimes is the time-index corresponding
906
c                              Here itimes is the time-index corresponding
907
c                              to the value of 'time'. 
907
c                              to the value of 'time'. 
908
c        dat     real  output  data-array dimensioned sufficiently 
908
c        dat     real  output  data-array dimensioned sufficiently 
909
c                              large. The dimensions (nx,ny,nz)
909
c                              large. The dimensions (nx,ny,nz)
910
c                              of the variable must previously be defined
910
c                              of the variable must previously be defined
911
c                              with a call to putdef. No previous 
911
c                              with a call to putdef. No previous 
912
c                              definition of the time-dimension is
912
c                              definition of the time-dimension is
913
c                              required.
913
c                              required.
914
c        error   int   output  indicates possible errors found in this
914
c        error   int   output  indicates possible errors found in this
915
c                              routine.
915
c                              routine.
916
c                              error = 0   no errors detected.
916
c                              error = 0   no errors detected.
917
c                              error = 1   the variable is not present on
917
c                              error = 1   the variable is not present on
918
c                                          the file.
918
c                                          the file.
919
c                              error = 2   the value of 'time' is not
919
c                              error = 2   the value of 'time' is not
920
c                                          known.to the file.
920
c                                          known.to the file.
921
c                              error = 3   inconsistent value of level
921
c                              error = 3   inconsistent value of level
922
c                              error =10   another error.
922
c                              error =10   another error.
923
c     History:
923
c     History:
924
c       March 93    Heini Wernli (ETHZ)      Created wr2cdf.
924
c       March 93    Heini Wernli (ETHZ)      Created wr2cdf.
925
c       April 93    Bettina Messmer (ETHZ)   Created putdat.
925
c       April 93    Bettina Messmer (ETHZ)   Created putdat.
926
c       June  93    Christoph Schaer (ETHZ)  Created getdat
926
c       June  93    Christoph Schaer (ETHZ)  Created getdat
927
c       Sept. 07    Johannes Jenkner (ETHZ)  Integer and double times
927
c       Sept. 07    Johannes Jenkner (ETHZ)  Integer and double times
928
c-----------------------------------------------------------------------
928
c-----------------------------------------------------------------------
929
 
929
 
930
      include "netcdf.inc"
930
      include "netcdf.inc"
931
 
931
 
932
C     Declaration of local variables
932
C     Declaration of local variables
933
      character*(*) varnam
933
      character*(*) varnam
934
      character*(20) chars,dimnam
934
      character*(20) chars,dimnam
935
      integer cdfid
935
      integer cdfid
936
 
936
 
937
      real        dat(*)
937
      real        dat(*)
938
      real        misdat,varmin(3),varmax(3),stag(3)
938
      real        misdat,varmin(3),varmax(3),stag(3)
939
      real        time, timeval
939
      real        time, timeval
940
 
940
 
941
      integer     corner(4),edgeln(4),didtim,vardim(4),ndims
941
      integer     corner(4),edgeln(4),didtim,vardim(4),ndims
942
      integer     error, ierr
942
      integer     error, ierr
943
      integer     level,ntime
943
      integer     level,ntime
944
      integer     idtime,idvar,iflag
944
      integer     idtime,idvar,iflag
945
      integer     i
945
      integer     i
946
 
946
 
947
      integer     vtyp,dn,nat
947
      integer     vtyp,dn,nat
948
      integer     dims(4)
948
      integer     dims(4)
949
      integer     inttime
949
      integer     inttime
950
      double precision doubletime
950
      double precision doubletime
951
 
951
 
952
      call ncpopt(NCVERBOS)
952
      call ncpopt(NCVERBOS)
953
 
953
 
954
c     access the variable
954
c     access the variable
955
      call getdef (cdfid, trim(varnam), ndims, misdat, 
955
      call getdef (cdfid, trim(varnam), ndims, misdat, 
956
     &                           vardim, varmin, varmax, stag, ierr)
956
     &                           vardim, varmin, varmax, stag, ierr)
957
      if (ierr.ne.0) then
957
      if (ierr.ne.0) then
958
        print *,'*ERROR* in getdef in getdat'
958
        print *,'*ERROR* in getdef in getdat'
959
        error=1
959
        error=1
960
        return
960
        return
961
      endif
961
      endif
962
      idvar=ncvid(cdfid,trim(varnam),ierr)
962
      idvar=ncvid(cdfid,trim(varnam),ierr)
963
      if (ierr.ne.0) then
963
      if (ierr.ne.0) then
964
        print *,'*ERROR* in ncvid in getdat'
964
        print *,'*ERROR* in ncvid in getdat'
965
        error=1
965
        error=1
966
        return
966
        return
967
      endif
967
      endif
968
 
968
 
969
C     Get times-array
969
C     Get times-array
970
      didtim=ncdid(cdfid,'time',ierr)
970
      didtim=ncdid(cdfid,'time',ierr)
971
      if (ierr.ne.0) then
971
      if (ierr.ne.0) then
972
        print *,'*ERROR* didtim in getdat'
972
        print *,'*ERROR* didtim in getdat'
973
        error=10
973
        error=10
974
        return
974
        return
975
      endif
975
      endif
976
      call ncdinq(cdfid,didtim,chars,ntime,ierr)
976
      call ncdinq(cdfid,didtim,chars,ntime,ierr)
977
      if (ierr.ne.0) then
977
      if (ierr.ne.0) then
978
        print *,'*ERROR* in ncdinq in getdat'
978
        print *,'*ERROR* in ncdinq in getdat'
979
        error=10
979
        error=10
980
        return
980
        return
981
      endif
981
      endif
982
      idtime=ncvid(cdfid,'time',ierr)
982
      idtime=ncvid(cdfid,'time',ierr)
983
      if (ierr.ne.0) then
983
      if (ierr.ne.0) then
984
        print *,'*ERROR* in ncvid for time in getdat'
984
        print *,'*ERROR* in ncvid for time in getdat'
985
        error=10
985
        error=10
986
        return
986
        return
987
      endif
987
      endif
988
c     find appropriate time-index
988
c     find appropriate time-index
989
      iflag=0
989
      iflag=0
990
      call ncvinq(cdfid,idtime,dimnam,vtyp,dn,dims,natt,ierr)
990
      call ncvinq(cdfid,idtime,dimnam,vtyp,dn,dims,natt,ierr)
991
      do i=1,ntime
991
      do i=1,ntime
992
        if (vtyp.eq.5) then
992
        if (vtyp.eq.5) then
993
          call ncvgt1(cdfid,idtime,i,timeval,ierr)
993
          call ncvgt1(cdfid,idtime,i,timeval,ierr)
994
        elseif (vtyp.eq.4) then ! integer version 
994
        elseif (vtyp.eq.4) then ! integer version 
995
          call ncvgt1(cdfid,idtime,i,inttime,ierr) 
995
          call ncvgt1(cdfid,idtime,i,inttime,ierr) 
996
          timeval=real(inttime)
996
          timeval=real(inttime)
997
        elseif (vtyp.eq.6) then ! double precision version
997
        elseif (vtyp.eq.6) then ! double precision version
998
           call ncvgt1(cdfid,idtime,i,doubletime,ierr) 
998
           call ncvgt1(cdfid,idtime,i,doubletime,ierr) 
999
           timeval=real(doubletime)   
999
           timeval=real(doubletime)   
1000
        endif      
1000
        endif      
1001
        if (ierr.ne.0) print *,'*ERROR* in ncvgt1 in getdat'
1001
        if (ierr.ne.0) print *,'*ERROR* in ncvgt1 in getdat'
1002
        if (time.eq.timeval) iflag=i
1002
        if (time.eq.timeval) iflag=i
1003
      enddo
1003
      enddo
1004
      if (iflag.eq.0) then
1004
      if (iflag.eq.0) then
1005
        error=2
1005
        error=2
1006
        print *,'Error: Unknown time in getdat'
1006
        print *,'Error: Unknown time in getdat'
1007
        return
1007
        return
1008
      endif
1008
      endif
1009
 
1009
 
1010
C     Define data volume to be written (index space)
1010
C     Define data volume to be written (index space)
1011
      corner(1)=1
1011
      corner(1)=1
1012
      corner(2)=1
1012
      corner(2)=1
1013
      edgeln(1)=vardim(1)
1013
      edgeln(1)=vardim(1)
1014
      edgeln(2)=vardim(2)
1014
      edgeln(2)=vardim(2)
1015
      if (level.eq.0) then
1015
      if (level.eq.0) then
1016
        corner(3)=1
1016
        corner(3)=1
1017
        edgeln(3)=vardim(3)
1017
        edgeln(3)=vardim(3)
1018
      else if ((level.le.vardim(3)).and.(level.ge.1)) then
1018
      else if ((level.le.vardim(3)).and.(level.ge.1)) then
1019
        corner(3)=level
1019
        corner(3)=level
1020
        edgeln(3)=1
1020
        edgeln(3)=1
1021
      else
1021
      else
1022
        error=3
1022
        error=3
1023
        return
1023
        return
1024
      endif
1024
      endif
1025
      corner(4)=iflag
1025
      corner(4)=iflag
1026
      edgeln(4)=1
1026
      edgeln(4)=1
1027
 
1027
 
1028
C     Read data from NetCDF file
1028
C     Read data from NetCDF file
1029
c      print *,'getdat vor Aufruf ncvgt'
1029
c      print *,'getdat vor Aufruf ncvgt'
1030
c      print *,'cdfid ',cdfid
1030
c      print *,'cdfid ',cdfid
1031
c      print *,'idvar ',idvar
1031
c      print *,'idvar ',idvar
1032
c      print *,'corner ',corner
1032
c      print *,'corner ',corner
1033
c      print *,'edgeln ',edgeln
1033
c      print *,'edgeln ',edgeln
1034
 
1034
 
1035
      call ncvgt(cdfid,idvar,corner,edgeln,dat,error)
1035
      call ncvgt(cdfid,idvar,corner,edgeln,dat,error)
1036
      if (error.ne.0) then
1036
      if (error.ne.0) then
1037
        print *, '*ERROR* in ncvgt in getdat'
1037
        print *, '*ERROR* in ncvgt in getdat'
1038
        error=10
1038
        error=10
1039
      endif
1039
      endif
1040
      end
1040
      end
1041
 
1041
 
1042
 
1042
 
1043
      subroutine putdat(cdfid, varnam, time, level, dat, error)
1043
      subroutine putdat(cdfid, varnam, time, level, dat, error)
1044
c-----------------------------------------------------------------------
1044
c-----------------------------------------------------------------------
1045
c     Purpose:
1045
c     Purpose:
1046
c        This routine is called to write the data of a variable
1046
c        This routine is called to write the data of a variable
1047
c        to an IVE-NetCDF file for use with the IVE plotting package. 
1047
c        to an IVE-NetCDF file for use with the IVE plotting package. 
1048
c        Prior to calling this routine, the file must be opened with 
1048
c        Prior to calling this routine, the file must be opened with 
1049
c        a call to opncdf (for extension) or crecdf (for creation), the 
1049
c        a call to opncdf (for extension) or crecdf (for creation), the 
1050
c        variable must be defined with a call to putdef.
1050
c        variable must be defined with a call to putdef.
1051
c     Arguments:
1051
c     Arguments:
1052
c        cdfid   int   input   file-identifier
1052
c        cdfid   int   input   file-identifier
1053
c                              (must be obtained by calling routine 
1053
c                              (must be obtained by calling routine 
1054
c                              opncdf or crecdf)
1054
c                              opncdf or crecdf)
1055
c        varnam  char  input   the user-supplied variable name (must 
1055
c        varnam  char  input   the user-supplied variable name (must 
1056
c                              previously be defined with a call to
1056
c                              previously be defined with a call to
1057
c                              putdef)
1057
c                              putdef)
1058
c        time    real  input   the user-supplied time-level of the
1058
c        time    real  input   the user-supplied time-level of the
1059
c                              data to be written to the file (the time-
1059
c                              data to be written to the file (the time-
1060
c                              levels stored in the file can be obtained
1060
c                              levels stored in the file can be obtained
1061
c                              with a call to gettimes). If 'time' is not
1061
c                              with a call to gettimes). If 'time' is not
1062
c                              yet known to the file, a knew time-level is
1062
c                              yet known to the file, a knew time-level is
1063
c                              allocated and appended to the times-array.
1063
c                              allocated and appended to the times-array.
1064
c        level   int input     the horizontal level(s) to be written 
1064
c        level   int input     the horizontal level(s) to be written 
1065
c                              to the NetCDF file. Suppose that the
1065
c                              to the NetCDF file. Suppose that the
1066
c                              variable is defined as (nx,ny,nz,nt).
1066
c                              variable is defined as (nx,ny,nz,nt).
1067
c                              level>0: the call writes the subdomain
1067
c                              level>0: the call writes the subdomain
1068
c                                       (1:nx,1:ny,level,itimes)
1068
c                                       (1:nx,1:ny,level,itimes)
1069
c                              level=0: the call writes the subdomain
1069
c                              level=0: the call writes the subdomain
1070
c                                       (1:nx,1:ny,1:nz,itimes)
1070
c                                       (1:nx,1:ny,1:nz,itimes)
1071
c                              Here itimes is the time-index corresponding
1071
c                              Here itimes is the time-index corresponding
1072
c                              to the value of 'time'. 
1072
c                              to the value of 'time'. 
1073
c        dat     real  output  data-array dimensioned sufficiently 
1073
c        dat     real  output  data-array dimensioned sufficiently 
1074
c                              large. The dimensions (nx,ny,nz)
1074
c                              large. The dimensions (nx,ny,nz)
1075
c                              of the variable must previously be defined
1075
c                              of the variable must previously be defined
1076
c                              with a call to putdef. No previous 
1076
c                              with a call to putdef. No previous 
1077
c                              definition of the time-dimension is
1077
c                              definition of the time-dimension is
1078
c                              required.
1078
c                              required.
1079
c        error   int output    indicates possible errors found in this
1079
c        error   int output    indicates possible errors found in this
1080
c                              routine.
1080
c                              routine.
1081
c                              error = 0   no errors detected.
1081
c                              error = 0   no errors detected.
1082
c                              error = 1   the variable is not present on
1082
c                              error = 1   the variable is not present on
1083
c                                          the file.
1083
c                                          the file.
1084
c                              error = 2   the value of 'time' is new, but
1084
c                              error = 2   the value of 'time' is new, but
1085
c                                          appending it would yield a non
1085
c                                          appending it would yield a non
1086
c                                          ascending times-array.
1086
c                                          ascending times-array.
1087
c                              error = 3   inconsistent value of level
1087
c                              error = 3   inconsistent value of level
1088
c                              error =10   another error.
1088
c                              error =10   another error.
1089
c     History:
1089
c     History:
1090
c       March 93    Heini Wernli (ETHZ)      Created wr2cdf.
1090
c       March 93    Heini Wernli (ETHZ)      Created wr2cdf.
1091
c       April 93    Bettina Messmer (ETHZ)   Created putdat.
1091
c       April 93    Bettina Messmer (ETHZ)   Created putdat.
1092
c-----------------------------------------------------------------------
1092
c-----------------------------------------------------------------------
1093
 
1093
 
1094
      include "netcdf.inc"
1094
      include "netcdf.inc"
1095
 
1095
 
1096
C     Declaration of local variables
1096
C     Declaration of local variables
1097
 
1097
 
1098
      character*(*) varnam
1098
      character*(*) varnam
1099
      character*(20) chars
1099
      character*(20) chars
1100
      integer cdfid
1100
      integer cdfid
1101
 
1101
 
1102
 
1102
 
1103
      real 	dat(*)
1103
      real 	dat(*)
1104
      real	misdat,varmin(3),varmax(3),stag(3)
1104
      real	misdat,varmin(3),varmax(3),stag(3)
1105
      real	time, timeval
1105
      real	time, timeval
1106
      data	stag/0.,0.,0./
1106
      data	stag/0.,0.,0./
1107
 
1107
 
1108
      integer	corner(4),edgeln(4),did(4),vardim(4),ndims
1108
      integer	corner(4),edgeln(4),did(4),vardim(4),ndims
1109
      integer	error, ierr
1109
      integer	error, ierr
1110
      integer	level,ntime
1110
      integer	level,ntime
1111
      integer	idtime,idvar,iflag
1111
      integer	idtime,idvar,iflag
1112
      integer	i
1112
      integer	i
1113
 
1113
 
1114
      call ncpopt(NCVERBOS)
1114
      call ncpopt(NCVERBOS)
1115
 
1115
 
1116
c     get definitions of data
1116
c     get definitions of data
1117
      call getdef (cdfid, trim(varnam), ndims, misdat, 
1117
      call getdef (cdfid, trim(varnam), ndims, misdat, 
1118
     &                           vardim, varmin, varmax, stag, ierr)
1118
     &                           vardim, varmin, varmax, stag, ierr)
1119
      if (ierr.ne.0)  print *,'*ERROR* in getdef in putdat'
1119
      if (ierr.ne.0)  print *,'*ERROR* in getdef in putdat'
1120
 
1120
 
1121
c     get id of variable
1121
c     get id of variable
1122
      idvar=ncvid(cdfid,trim(varnam),ierr)
1122
      idvar=ncvid(cdfid,trim(varnam),ierr)
1123
      if (ierr.ne.0) print *,'*ERROR* in ncvid in putdat'
1123
      if (ierr.ne.0) print *,'*ERROR* in ncvid in putdat'
1124
 
1124
 
1125
c     get times-array 
1125
c     get times-array 
1126
      did(4)=ncdid(cdfid,'time',ierr)
1126
      did(4)=ncdid(cdfid,'time',ierr)
1127
      if (ierr.ne.0) print *,'*ERROR* did(4) in putdat'
1127
      if (ierr.ne.0) print *,'*ERROR* did(4) in putdat'
1128
      call ncdinq(cdfid,did(4),chars,ntime,ierr)
1128
      call ncdinq(cdfid,did(4),chars,ntime,ierr)
1129
      if (ierr.ne.0) print *,'*ERROR* in ncdinq in putdat'
1129
      if (ierr.ne.0) print *,'*ERROR* in ncdinq in putdat'
1130
      idtime=ncvid(cdfid,'time',ierr)
1130
      idtime=ncvid(cdfid,'time',ierr)
1131
      if (ierr.ne.0) print *,'*ERROR* in ncvid in putdat'
1131
      if (ierr.ne.0) print *,'*ERROR* in ncvid in putdat'
1132
C     Check if a new time step is starting
1132
C     Check if a new time step is starting
1133
      iflag=0
1133
      iflag=0
1134
      do i=1,ntime
1134
      do i=1,ntime
1135
        call ncvgt1(cdfid,idtime,i,timeval,ierr)
1135
        call ncvgt1(cdfid,idtime,i,timeval,ierr)
1136
        if (ierr.ne.0) print *,'*ERROR* in ncvgt1 in putdat'
1136
        if (ierr.ne.0) print *,'*ERROR* in ncvgt1 in putdat'
1137
        if (time.eq.timeval) iflag=i
1137
        if (time.eq.timeval) iflag=i
1138
      enddo
1138
      enddo
1139
      if (iflag.eq.0) then		! new time step
1139
      if (iflag.eq.0) then		! new time step
1140
        ntime=ntime+1
1140
        ntime=ntime+1
1141
        iflag=ntime
1141
        iflag=ntime
1142
        idtime=ncvid(cdfid,'time',ierr)
1142
        idtime=ncvid(cdfid,'time',ierr)
1143
        if (ierr.ne.0) print *, '*ERROR* in ncvid in putdat'
1143
        if (ierr.ne.0) print *, '*ERROR* in ncvid in putdat'
1144
        call ncvpt1(cdfid,idtime,ntime,time,ierr)
1144
        call ncvpt1(cdfid,idtime,ntime,time,ierr)
1145
        if (ierr.ne.0) print *, '*ERROR* in ncvpt1 in putdat'
1145
        if (ierr.ne.0) print *, '*ERROR* in ncvpt1 in putdat'
1146
      endif
1146
      endif
1147
 
1147
 
1148
C     Define data volume to write on the NetCDF file in index space
1148
C     Define data volume to write on the NetCDF file in index space
1149
      corner(1)=1               ! starting corner of data volume
1149
      corner(1)=1               ! starting corner of data volume
1150
      corner(2)=1
1150
      corner(2)=1
1151
      edgeln(1)=vardim(1)       ! edge lengthes of data volume
1151
      edgeln(1)=vardim(1)       ! edge lengthes of data volume
1152
      edgeln(2)=vardim(2)
1152
      edgeln(2)=vardim(2)
1153
      if (level.eq.0) then
1153
      if (level.eq.0) then
1154
        corner(3)=1
1154
        corner(3)=1
1155
        edgeln(3)=vardim(3)
1155
        edgeln(3)=vardim(3)
1156
      else
1156
      else
1157
        corner(3)=level
1157
        corner(3)=level
1158
        edgeln(3)=1
1158
        edgeln(3)=1
1159
      endif
1159
      endif
1160
      corner(4)=iflag
1160
      corner(4)=iflag
1161
      edgeln(4)=1
1161
      edgeln(4)=1
1162
      
1162
      
1163
C     Put data on NetCDF file
1163
C     Put data on NetCDF file
1164
 
1164
 
1165
c      print *,'vor Aufruf ncvpt d.h. Daten schreiben in putdat '
1165
c      print *,'vor Aufruf ncvpt d.h. Daten schreiben in putdat '
1166
c      print *,'cdfid ',cdfid
1166
c      print *,'cdfid ',cdfid
1167
c      print *,'idvar ',idvar
1167
c      print *,'idvar ',idvar
1168
c      print *,'corner ',corner
1168
c      print *,'corner ',corner
1169
c      print *,'edgeln ',edgeln
1169
c      print *,'edgeln ',edgeln
1170
 
1170
 
1171
      call ncvpt(cdfid,idvar,corner,edgeln,dat,error)
1171
      call ncvpt(cdfid,idvar,corner,edgeln,dat,error)
1172
      if (error.ne.0) then
1172
      if (error.ne.0) then
1173
        print *, '*ERROR* in ncvpt in putdat - Put data on NetCDF file'
1173
        print *, '*ERROR* in ncvpt in putdat - Put data on NetCDF file'
1174
      endif
1174
      endif
1175
 
1175
 
1176
C     Synchronize output to disk and close the files
1176
C     Synchronize output to disk and close the files
1177
 
1177
 
1178
      call ncsnc(cdfid,ierr)
1178
      call ncsnc(cdfid,ierr)
1179
      if (ierr.ne.0) print *, '*ERROR* in ncsnc in putdat'
1179
      if (ierr.ne.0) print *, '*ERROR* in ncsnc in putdat'
1180
      end
1180
      end
1181
 
1181
 
1182
 
1182
 
1183
 
1183
 
1184
 
1184
 
1185
 
1185
 
1186
 
1186
 
1187
      subroutine putdef (cdfid, varnam, ndim, misdat, 
1187
      subroutine putdef (cdfid, varnam, ndim, misdat, 
1188
     &                            vardim, varmin, varmax, stag, error)
1188
     &                            vardim, varmin, varmax, stag, error)
1189
c-----------------------------------------------------------------------
1189
c-----------------------------------------------------------------------
1190
c     Purpose:
1190
c     Purpose:
1191
c        This routine is called to define the dimensions and the
1191
c        This routine is called to define the dimensions and the
1192
c        attributes of a variable on an IVE-NetCDF file for use with the
1192
c        attributes of a variable on an IVE-NetCDF file for use with the
1193
c        IVE plotting package. Prior to calling this routine, the file must
1193
c        IVE plotting package. Prior to calling this routine, the file must
1194
c        be opened with a call to opncdf (extend an existing file) or
1194
c        be opened with a call to opncdf (extend an existing file) or
1195
c        crecdf (create a new file).
1195
c        crecdf (create a new file).
1196
c     Arguments:
1196
c     Arguments:
1197
c        cdfid   int   input   file-identifier
1197
c        cdfid   int   input   file-identifier
1198
c                              (can be obtained by calling routine 
1198
c                              (can be obtained by calling routine 
1199
c                              opncdf)
1199
c                              opncdf)
1200
c        varnam  char  input   the user-supplied variable name.
1200
c        varnam  char  input   the user-supplied variable name.
1201
c        ndim    int   input   the number of dimensions (ndim<=4). 
1201
c        ndim    int   input   the number of dimensions (ndim<=4). 
1202
c                              Upon ndim=4, the fourth dimension of the
1202
c                              Upon ndim=4, the fourth dimension of the
1203
c                              variable is specified as 'unlimited'
1203
c                              variable is specified as 'unlimited'
1204
c                              on the file (time-dimension). It can 
1204
c                              on the file (time-dimension). It can 
1205
c                              later be extended to arbitrary length.
1205
c                              later be extended to arbitrary length.
1206
c        misdat  real  input   missing data value for the variable. 
1206
c        misdat  real  input   missing data value for the variable. 
1207
c        vardim  int   input   the dimensions of the variable.
1207
c        vardim  int   input   the dimensions of the variable.
1208
c                              Is dimensioned at least Min(3,ndim). 
1208
c                              Is dimensioned at least Min(3,ndim). 
1209
c        varmin  real  input   the location in physical space of the
1209
c        varmin  real  input   the location in physical space of the
1210
c                              origin of each variable.
1210
c                              origin of each variable.
1211
c                              Is dimensioned at least Min(3,ndim). 
1211
c                              Is dimensioned at least Min(3,ndim). 
1212
c        varmax  real  input   the extent of each variable in physical
1212
c        varmax  real  input   the extent of each variable in physical
1213
c                              space.
1213
c                              space.
1214
c                              Is dimensioned at least Min(ndim). 
1214
c                              Is dimensioned at least Min(ndim). 
1215
c        stag    real  input   the grid staggering for each variable.
1215
c        stag    real  input   the grid staggering for each variable.
1216
c                              Is dimensioned at least Min(3,ndim). 
1216
c                              Is dimensioned at least Min(3,ndim). 
1217
c        error   int   output  indicates possible errors found in this
1217
c        error   int   output  indicates possible errors found in this
1218
c                              routine.
1218
c                              routine.
1219
c                              error = 0   no errors detected.
1219
c                              error = 0   no errors detected.
1220
c                              error =10   other errors detected.
1220
c                              error =10   other errors detected.
1221
c     History:
1221
c     History:
1222
c       Apr. 93    Christoph Schaer (ETHZ)     Created.
1222
c       Apr. 93    Christoph Schaer (ETHZ)     Created.
1223
c-----------------------------------------------------------------------
1223
c-----------------------------------------------------------------------
1224
 
1224
 
1225
      include "netcdf.inc"
1225
      include "netcdf.inc"
1226
 
1226
 
1227
c     Argument declarations.
1227
c     Argument declarations.
1228
      integer        MAXDIM
1228
      integer        MAXDIM
1229
      parameter      (MAXDIM=4)
1229
      parameter      (MAXDIM=4)
1230
      character *(*) varnam
1230
      character *(*) varnam
1231
      integer        vardim(*), ndim, error, cdfid
1231
      integer        vardim(*), ndim, error, cdfid
1232
      real           misdat,  stag(*), varmin(*), varmax(*)
1232
      real           misdat,  stag(*), varmin(*), varmax(*)
1233
 
1233
 
1234
c     Local variable declarations.
1234
c     Local variable declarations.
1235
      character *(20) dimnam,attnam,dimchk
1235
      character *(20) dimnam,attnam,dimchk
1236
      character *(1)  chrid(MAXDIM)
1236
      character *(1)  chrid(MAXDIM)
1237
      character *(20) dimnams(MAXNCDIM)
1237
      character *(20) dimnams(MAXNCDIM)
1238
      integer         dimvals(MAXNCDIM)
1238
      integer         dimvals(MAXNCDIM)
1239
      integer         numdims,numvars,numgats,dimulim
1239
      integer         numdims,numvars,numgats,dimulim
1240
      integer         id,did(MAXDIM),idtime,i,k,ierr
1240
      integer         id,did(MAXDIM),idtime,i,k,ierr
1241
      integer         ncopts
1241
      integer         ncopts
1242
      integer         ibeg,iend
1242
      integer         ibeg,iend
1243
      data            chrid/'x','y','z','t'/
1243
      data            chrid/'x','y','z','t'/
1244
 
1244
 
1245
c     Get current value of error options.
1245
c     Get current value of error options.
1246
      call ncgopt (ncopts)
1246
      call ncgopt (ncopts)
1247
 
1247
 
1248
c     make sure NetCDF-errors do not abort execution
1248
c     make sure NetCDF-errors do not abort execution
1249
      call ncpopt(NCVERBOS)
1249
      call ncpopt(NCVERBOS)
1250
 
1250
 
1251
c     Initially set error to indicate no errors.
1251
c     Initially set error to indicate no errors.
1252
      error = 0
1252
      error = 0
1253
 
1253
 
1254
c     Make sure ndim <= MAXDIM.
1254
c     Make sure ndim <= MAXDIM.
1255
      if (ndim.gt.MAXDIM) then
1255
      if (ndim.gt.MAXDIM) then
1256
         error = 10
1256
         error = 10
1257
         go to 900
1257
         go to 900
1258
      endif
1258
      endif
1259
 
1259
 
1260
c     Read existing dimensions-declarations from the file
1260
c     Read existing dimensions-declarations from the file
1261
      call ncinq(cdfid,numdims,numvars,numgats,dimulim,error)
1261
      call ncinq(cdfid,numdims,numvars,numgats,dimulim,error)
1262
      if (numdims.gt.0) then
1262
      if (numdims.gt.0) then
1263
        do i=1,numdims
1263
        do i=1,numdims
1264
          call ncdinq(cdfid,i,dimnams(i),dimvals(i),error)
1264
          call ncdinq(cdfid,i,dimnams(i),dimvals(i),error)
1265
c         print *,dimnams(i),dimvals(i)
1265
c         print *,dimnams(i),dimvals(i)
1266
        enddo
1266
        enddo
1267
      endif
1267
      endif
1268
 
1268
 
1269
c     put file into define mode
1269
c     put file into define mode
1270
      call ncredf(cdfid,error)
1270
      call ncredf(cdfid,error)
1271
      if (error.ne.0) goto 920
1271
      if (error.ne.0) goto 920
1272
 
1272
 
1273
c     define spatial dimensions
1273
c     define spatial dimensions
1274
      do k=1,min0(3,ndim)
1274
      do k=1,min0(3,ndim)
1275
c       define the default dimension-name
1275
c       define the default dimension-name
1276
        dimnam(1:3)='dim'
1276
        dimnam(1:3)='dim'
1277
        dimnam(4:4)=chrid(k)
1277
        dimnam(4:4)=chrid(k)
1278
        dimnam(5:5)='_'
1278
        dimnam(5:5)='_'
1279
        dimnam(6:5+len_trim(varnam))=trim(varnam)
1279
        dimnam(6:5+len_trim(varnam))=trim(varnam)
1280
        dimnam=dimnam(1:5+len_trim(varnam))
1280
        dimnam=dimnam(1:5+len_trim(varnam))
1281
        did(k)=-1
1281
        did(k)=-1
1282
        if (numdims.gt.0) then
1282
        if (numdims.gt.0) then
1283
c         check if an existing dimension-declaration can be used
1283
c         check if an existing dimension-declaration can be used
1284
c         instead of defining a new dimension
1284
c         instead of defining a new dimension
1285
          do i=1,numdims
1285
          do i=1,numdims
1286
            dimchk=dimnams(i)
1286
            dimchk=dimnams(i)
1287
            if ((vardim(k).eq.dimvals(i)).and.
1287
            if ((vardim(k).eq.dimvals(i)).and.
1288
     &        (dimnam(1:4).eq.dimchk(1:4))) then 
1288
     &        (dimnam(1:4).eq.dimchk(1:4))) then 
1289
              did(k)=i
1289
              did(k)=i
1290
              goto 100
1290
              goto 100
1291
            endif
1291
            endif
1292
          enddo
1292
          enddo
1293
 100      continue
1293
 100      continue
1294
        endif
1294
        endif
1295
        if (did(k).lt.0) then
1295
        if (did(k).lt.0) then
1296
c         define the dimension
1296
c         define the dimension
1297
          did(k)=ncddef(cdfid,dimnam,vardim(k),error)
1297
          did(k)=ncddef(cdfid,dimnam,vardim(k),error)
1298
          if (error.ne.0) goto 920
1298
          if (error.ne.0) goto 920
1299
        endif
1299
        endif
1300
      enddo
1300
      enddo
1301
 
1301
 
1302
c     define the times-array
1302
c     define the times-array
1303
      if (ndim.eq.4) then
1303
      if (ndim.eq.4) then
1304
c       define dimension and variable 'time'
1304
c       define dimension and variable 'time'
1305
        if (numdims.ge.4) then
1305
        if (numdims.ge.4) then
1306
          did(4)=ncdid(cdfid,'time',ierr)
1306
          did(4)=ncdid(cdfid,'time',ierr)
1307
          idtime=ncvid(cdfid,'time',ierr)
1307
          idtime=ncvid(cdfid,'time',ierr)
1308
        else
1308
        else
1309
c         this dimension must first be defined
1309
c         this dimension must first be defined
1310
          did(4) = ncddef (cdfid,'time',NCUNLIM,ierr)
1310
          did(4) = ncddef (cdfid,'time',NCUNLIM,ierr)
1311
          idtime = ncvdef (cdfid,'time',NCFLOAT,1,did(4),ierr)
1311
          idtime = ncvdef (cdfid,'time',NCFLOAT,1,did(4),ierr)
1312
        endif
1312
        endif
1313
      endif
1313
      endif
1314
 
1314
 
1315
c     define variable
1315
c     define variable
1316
      id=ncvdef(cdfid,varnam,NCFLOAT,ndim,did,error)
1316
      id=ncvdef(cdfid,varnam,NCFLOAT,ndim,did,error)
1317
      if (error.ne.0) goto 920
1317
      if (error.ne.0) goto 920
1318
 
1318
 
1319
c     define attributes
1319
c     define attributes
1320
      do k=1,min0(ndim,3)
1320
      do k=1,min0(ndim,3)
1321
c       min postion
1321
c       min postion
1322
        attnam(1:1)=chrid(k)
1322
        attnam(1:1)=chrid(k)
1323
        attnam(2:4)='min'
1323
        attnam(2:4)='min'
1324
        attnam=attnam(1:4)
1324
        attnam=attnam(1:4)
1325
        call ncapt(cdfid,id,attnam,NCFLOAT,1,varmin(k),error)
1325
        call ncapt(cdfid,id,attnam,NCFLOAT,1,varmin(k),error)
1326
        if (error.gt.0) goto 920
1326
        if (error.gt.0) goto 920
1327
c       max position     
1327
c       max position     
1328
        attnam(1:1)=chrid(k)
1328
        attnam(1:1)=chrid(k)
1329
        attnam(2:4)='max'
1329
        attnam(2:4)='max'
1330
        attnam=attnam(1:4)
1330
        attnam=attnam(1:4)
1331
        call ncapt(cdfid,id,attnam,NCFLOAT,1,varmax(k),error)
1331
        call ncapt(cdfid,id,attnam,NCFLOAT,1,varmax(k),error)
1332
        if (error.gt.0) goto 920     
1332
        if (error.gt.0) goto 920     
1333
c       staggering
1333
c       staggering
1334
        attnam(1:1)=chrid(k)
1334
        attnam(1:1)=chrid(k)
1335
        attnam(2:5)='stag'
1335
        attnam(2:5)='stag'
1336
        attnam=attnam(1:5)
1336
        attnam=attnam(1:5)
1337
        call ncapt(cdfid,id,attnam,NCFLOAT,1,stag(k),error)
1337
        call ncapt(cdfid,id,attnam,NCFLOAT,1,stag(k),error)
1338
        if (error.gt.0) goto 920
1338
        if (error.gt.0) goto 920
1339
      enddo
1339
      enddo
1340
 
1340
 
1341
c     define missing data value
1341
c     define missing data value
1342
      call ncapt(cdfid,id,'missing_data',NCFLOAT,1,misdat,error)
1342
      call ncapt(cdfid,id,'missing_data',NCFLOAT,1,misdat,error)
1343
      if (error.gt.0) goto 920     
1343
      if (error.gt.0) goto 920     
1344
 
1344
 
1345
c     leave define mode
1345
c     leave define mode
1346
      call ncendf(cdfid,error)
1346
      call ncendf(cdfid,error)
1347
      if (error.gt.0) goto 920     
1347
      if (error.gt.0) goto 920     
1348
 
1348
 
1349
c     synchronyse output to disk and exit
1349
c     synchronyse output to disk and exit
1350
      call ncsnc (cdfid,error)
1350
      call ncsnc (cdfid,error)
1351
      call ncpopt (ncopts)
1351
      call ncpopt (ncopts)
1352
      return
1352
      return
1353
 
1353
 
1354
c     Error exits.
1354
c     Error exits.
1355
 900  write (6, *) '*ERROR*: When calling putcdf, the number of ',
1355
 900  write (6, *) '*ERROR*: When calling putcdf, the number of ',
1356
     &             'variable dimensions must be less or equal 4.'
1356
     &             'variable dimensions must be less or equal 4.'
1357
      call ncpopt (ncopts)
1357
      call ncpopt (ncopts)
1358
      call ncclos (cdfid, error)
1358
      call ncclos (cdfid, error)
1359
      return
1359
      return
1360
 
1360
 
1361
 920  write (6, *) '*ERROR*: An error occurred while attempting to ',
1361
 920  write (6, *) '*ERROR*: An error occurred while attempting to ',
1362
     &             'write the data file in subroutine putcdf.'
1362
     &             'write the data file in subroutine putcdf.'
1363
      call ncpopt (ncopts)
1363
      call ncpopt (ncopts)
1364
      call ncclos (cdfid, error)
1364
      call ncclos (cdfid, error)
1365
      return
1365
      return
1366
      end
1366
      end
1367
 
1367
 
1368
 
1368
 
1369
      subroutine puttimes(cdfid,times,ntimes,ierr)
1369
      subroutine puttimes(cdfid,times,ntimes,ierr)
1370
C------------------------------------------------------------------------
1370
C------------------------------------------------------------------------
1371
C     Purpose:
1371
C     Purpose:
1372
C        Redefine all times on the specified NetCDF file
1372
C        Redefine all times on the specified NetCDF file
1373
C     Arguments: 
1373
C     Arguments: 
1374
C        cdfid  int  input   identifier for NetCDF file
1374
C        cdfid  int  input   identifier for NetCDF file
1375
C        times	real input   array contains all time values on the file,
1375
C        times	real input   array contains all time values on the file,
1376
C                            dimensioned at least times(ntimes)
1376
C                            dimensioned at least times(ntimes)
1377
C        ntimes int  input   number of times on the file
1377
C        ntimes int  input   number of times on the file
1378
C        error  int  output  errorflag 
1378
C        error  int  output  errorflag 
1379
C     History:
1379
C     History:
1380
C        Heini Wernli, ETHZ  
1380
C        Heini Wernli, ETHZ  
1381
C        Christoph Schaer, ETHZ
1381
C        Christoph Schaer, ETHZ
1382
C        Johannes Jenkner, ETHZ (adjustment for integer and double times)
1382
C        Johannes Jenkner, ETHZ (adjustment for integer and double times)
1383
C     Note:
1383
C     Note:
1384
C        This preliminary version does not define the times-array, but only
1384
C        This preliminary version does not define the times-array, but only
1385
C        overwrites or extends an existing times-array.
1385
C        overwrites or extends an existing times-array.
1386
C------------------------------------------------------------------------
1386
C------------------------------------------------------------------------
1387
 
1387
 
1388
      integer	ierr,i
1388
      integer	ierr,i
1389
      real times(*)
1389
      real times(*)
1390
      integer didtim,ntimes
1390
      integer didtim,ntimes
1391
 
1391
 
1392
      integer	cdfid,idtime,nfiltim
1392
      integer	cdfid,idtime,nfiltim
1393
      integer	ncdid,ncvid
1393
      integer	ncdid,ncvid
1394
 
1394
 
1395
      integer   vtyp,dn,nat
1395
      integer   vtyp,dn,nat
1396
      integer dims(4)
1396
      integer dims(4)
1397
 
1397
 
1398
      idtime=ncvid(cdfid,'time',ierr)   ! inquire id for time array
1398
      idtime=ncvid(cdfid,'time',ierr)   ! inquire id for time array
1399
      if (ierr.ne.0) return
1399
      if (ierr.ne.0) return
1400
      didtim=ncdid(cdfid,'time',ierr)	! inquire id for time dimension
1400
      didtim=ncdid(cdfid,'time',ierr)	! inquire id for time dimension
1401
      if (ierr.ne.0) return
1401
      if (ierr.ne.0) return
1402
 
1402
 
1403
      call ncdinq(cdfid,didtim,'time',nfiltim,ierr)   ! inquire # of times
1403
      call ncdinq(cdfid,didtim,'time',nfiltim,ierr)   ! inquire # of times
1404
      if (ierr.ne.0) return
1404
      if (ierr.ne.0) return
1405
 
1405
 
1406
      call ncvinq(cdfid,idtime,dimnam,vtyp,dn,dims,natt,ierr)
1406
      call ncvinq(cdfid,idtime,dimnam,vtyp,dn,dims,natt,ierr)
1407
 
1407
 
1408
      if (nfiltim.lt.ntimes) then
1408
      if (nfiltim.lt.ntimes) then
1409
        print *,'Warning: puttimes is extending times-array'
1409
        print *,'Warning: puttimes is extending times-array'
1410
      else if (nfiltim.gt.ntimes) then
1410
      else if (nfiltim.gt.ntimes) then
1411
        print *,'Warning: puttimes does not cover range of times-array'
1411
        print *,'Warning: puttimes does not cover range of times-array'
1412
      endif
1412
      endif
1413
 
1413
 
1414
      if (vtyp.eq.5) then
1414
      if (vtyp.eq.5) then
1415
        do i=1,ntimes
1415
        do i=1,ntimes
1416
          call ncvpt1(cdfid,idtime,i,times(i),ierr)
1416
          call ncvpt1(cdfid,idtime,i,times(i),ierr)
1417
          if (ierr.ne.0) return
1417
          if (ierr.ne.0) return
1418
        enddo
1418
        enddo
1419
      elseif (vtyp.eq.4) then ! integer version  
1419
      elseif (vtyp.eq.4) then ! integer version  
1420
        do i=1,ntimes
1420
        do i=1,ntimes
1421
          call ncvpt1(cdfid,idtime,i,int(times(i)),ierr) 
1421
          call ncvpt1(cdfid,idtime,i,int(times(i)),ierr) 
1422
          if (ierr.ne.0) return
1422
          if (ierr.ne.0) return
1423
        enddo
1423
        enddo
1424
      elseif (vtyp.eq.6) then ! double precision version
1424
      elseif (vtyp.eq.6) then ! double precision version
1425
        do i=1,ntimes
1425
        do i=1,ntimes
1426
          call ncvgt1(cdfid,idtime,i,dble(times(i)),ierr) 
1426
          call ncvgt1(cdfid,idtime,i,dble(times(i)),ierr) 
1427
          if (ierr.ne.0) return
1427
          if (ierr.ne.0) return
1428
        enddo        
1428
        enddo        
1429
      else
1429
      else
1430
        return
1430
        return
1431
      endif
1431
      endif
1432
 
1432
 
1433
      end
1433
      end
1434
 
1434
 
1435
 
1435
 
1436
 
1436
 
1437
      subroutine gettimes(cdfid,times,ntimes,ierr)
1437
      subroutine gettimes(cdfid,times,ntimes,ierr)
1438
C------------------------------------------------------------------------
1438
C------------------------------------------------------------------------
1439
C     Purpose:
1439
C     Purpose:
1440
C        Get all times on the specified NetCDF file
1440
C        Get all times on the specified NetCDF file
1441
C     Arguments: 
1441
C     Arguments: 
1442
C        cdfid  int  input   identifier for NetCDF file
1442
C        cdfid  int  input   identifier for NetCDF file
1443
C        times	real output  array contains all time values on the file,
1443
C        times	real output  array contains all time values on the file,
1444
C                            dimensioned at least times(ntimes)
1444
C                            dimensioned at least times(ntimes)
1445
C        ntimes int  output  number of times on the file
1445
C        ntimes int  output  number of times on the file
1446
C        error  int  output  errorflag 
1446
C        error  int  output  errorflag 
1447
C     History:
1447
C     History:
1448
C        Heini Wernli, ETHZ  
1448
C        Heini Wernli, ETHZ  
1449
C        Johannes Jenkner, ETHZ (adjustment for integer and double times)
1449
C        Johannes Jenkner, ETHZ (adjustment for integer and double times)
1450
C------------------------------------------------------------------------
1450
C------------------------------------------------------------------------
1451
 
1451
 
1452
      include "netcdf.inc"
1452
      include "netcdf.inc"
1453
 
1453
 
1454
      integer	ierr,i
1454
      integer	ierr,i
1455
      real times(*)
1455
      real times(*)
1456
      integer didtim,ntimes
1456
      integer didtim,ntimes
1457
 
1457
 
1458
      integer	cdfid,idtime
1458
      integer	cdfid,idtime
1459
      integer	ncopts
1459
      integer	ncopts
1460
      character*(20) dimnam
1460
      character*(20) dimnam
1461
 
1461
 
1462
      integer   vtyp,dn,nat
1462
      integer   vtyp,dn,nat
1463
      integer dims(4)
1463
      integer dims(4)
1464
 
1464
 
1465
      integer,dimension(:),allocatable :: inttimes
1465
      integer,dimension(:),allocatable :: inttimes
1466
      double precision,dimension(:),allocatable :: doubletimes
1466
      double precision,dimension(:),allocatable :: doubletimes
1467
 
1467
 
1468
c     Get current value of error options, and make sure netCDF-errors do 
1468
c     Get current value of error options, and make sure netCDF-errors do 
1469
c     not abort execution
1469
c     not abort execution
1470
      call ncgopt (ncopts)
1470
      call ncgopt (ncopts)
1471
      call ncpopt(NCVERBOS)
1471
      call ncpopt(NCVERBOS)
1472
 
1472
 
1473
      didtim=ncdid(cdfid,'time',ierr)	! inquire id for time dimension
1473
      didtim=ncdid(cdfid,'time',ierr)	! inquire id for time dimension
1474
      if (ierr.ne.0) goto 900
1474
      if (ierr.ne.0) goto 900
1475
      idtime=ncvid(cdfid,'time',ierr)   ! inquire id for time array
1475
      idtime=ncvid(cdfid,'time',ierr)   ! inquire id for time array
1476
      if (ierr.ne.0) goto 900
1476
      if (ierr.ne.0) goto 900
1477
      call ncdinq(cdfid,didtim,dimnam,ntimes,ierr)      ! inquire # of times
1477
      call ncdinq(cdfid,didtim,dimnam,ntimes,ierr)      ! inquire # of times
1478
      if (ierr.ne.0) goto 900
1478
      if (ierr.ne.0) goto 900
1479
  
1479
  
1480
      call ncvinq(cdfid,idtime,dimnam,vtyp,dn,dims,natt,ierr)
1480
      call ncvinq(cdfid,idtime,dimnam,vtyp,dn,dims,natt,ierr)
1481
 
1481
 
1482
      if (vtyp.eq.5) then
1482
      if (vtyp.eq.5) then
1483
        do i=1,ntimes
1483
        do i=1,ntimes
1484
          call ncvgt1(cdfid,idtime,i,times(i),ierr) ! get times
1484
          call ncvgt1(cdfid,idtime,i,times(i),ierr) ! get times
1485
          if (ierr.ne.0) goto 900
1485
          if (ierr.ne.0) goto 900
1486
        enddo   
1486
        enddo   
1487
      elseif (vtyp.eq.4) then ! integer version  
1487
      elseif (vtyp.eq.4) then ! integer version  
1488
        allocate(inttimes(ntimes))
1488
        allocate(inttimes(ntimes))
1489
        do i=1,ntimes
1489
        do i=1,ntimes
1490
          call ncvgt1(cdfid,idtime,i,inttimes(i),ierr) ! get times
1490
          call ncvgt1(cdfid,idtime,i,inttimes(i),ierr) ! get times
1491
          if (ierr.ne.0) goto 900
1491
          if (ierr.ne.0) goto 900
1492
        enddo
1492
        enddo
1493
        times(1:ntimes)=real(inttimes(1:ntimes))
1493
        times(1:ntimes)=real(inttimes(1:ntimes))
1494
      elseif (vtyp.eq.6) then ! double precision version
1494
      elseif (vtyp.eq.6) then ! double precision version
1495
        allocate(doubletimes(ntimes))
1495
        allocate(doubletimes(ntimes))
1496
        do i=1,ntimes
1496
        do i=1,ntimes
1497
          call ncvgt1(cdfid,idtime,i,doubletimes(i),ierr) ! get times
1497
          call ncvgt1(cdfid,idtime,i,doubletimes(i),ierr) ! get times
1498
          if (ierr.ne.0) goto 900
1498
          if (ierr.ne.0) goto 900
1499
        enddo
1499
        enddo
1500
        times(1:ntimes)=real(doubletimes(1:ntimes))        
1500
        times(1:ntimes)=real(doubletimes(1:ntimes))        
1501
      else
1501
      else
1502
        goto 900
1502
        goto 900
1503
      endif
1503
      endif
1504
 
1504
 
1505
c     normal exit
1505
c     normal exit
1506
      call ncpopt (ncopts)
1506
      call ncpopt (ncopts)
1507
      return
1507
      return
1508
 
1508
 
1509
c     error exit
1509
c     error exit
1510
 900  ntimes=1
1510
 900  ntimes=1
1511
      times(1)=0.
1511
      times(1)=0.
1512
      call ncpopt (ncopts)
1512
      call ncpopt (ncopts)
1513
      end
1513
      end
1514
 
1514
 
1515
 
1515
 
1516
 
1516
 
1517
 
1517
 
1518
      subroutine cpp_crecdf(filnam,filnam_len,cdfid,phymin,phymax,ndim,
1518
      subroutine cpp_crecdf(filnam,filnam_len,cdfid,phymin,phymax,ndim,
1519
     &     cfn,cfn_len,error)
1519
     &     cfn,cfn_len,error)
1520
C------------------------------------------------------------------------
1520
C------------------------------------------------------------------------
1521
C     Purpose:
1521
C     Purpose:
1522
C        allows to call crecdf from c++
1522
C        allows to call crecdf from c++
1523
C     Arguments: 
1523
C     Arguments: 
1524
C        see crecdf
1524
C        see crecdf
1525
C        additionally: fname_len and cfn_len, the length of the 
1525
C        additionally: fname_len and cfn_len, the length of the 
1526
C           strings
1526
C           strings
1527
C        
1527
C        
1528
C        
1528
C        
1529
C     History:
1529
C     History:
1530
C        981221  Mark A. Liniger ETHZ
1530
C        981221  Mark A. Liniger ETHZ
1531
C        
1531
C        
1532
C     Note:
1532
C     Note:
1533
C        
1533
C        
1534
C        
1534
C        
1535
C------------------------------------------------------------------------
1535
C------------------------------------------------------------------------
1536
      integer        filnam_len,ndim,cfn_len,error,cdfid
1536
      integer        filnam_len,ndim,cfn_len,error,cdfid
1537
      character *(*) filnam,cfn
1537
      character *(*) filnam,cfn
1538
      real           phymin(*),phymax(*)
1538
      real           phymin(*),phymax(*)
1539
 
1539
 
1540
      call crecdf (filnam(1:filnam_len),cdfid,phymin,phymax,ndim,
1540
      call crecdf (filnam(1:filnam_len),cdfid,phymin,phymax,ndim,
1541
     &     cfn(1:cfn_len),error)
1541
     &     cfn(1:cfn_len),error)
1542
 
1542
 
1543
      end
1543
      end
1544
 
1544
 
1545
 
1545
 
1546
      subroutine cpp_putdef(cdfid,varnam,varnam_len,ndim,misdat,
1546
      subroutine cpp_putdef(cdfid,varnam,varnam_len,ndim,misdat,
1547
     &     vardim,varmin,varmax,stag,error)
1547
     &     vardim,varmin,varmax,stag,error)
1548
C------------------------------------------------------------------------
1548
C------------------------------------------------------------------------
1549
C     Purpose:
1549
C     Purpose:
1550
C        allows to call putdef from c++
1550
C        allows to call putdef from c++
1551
C     Arguments: 
1551
C     Arguments: 
1552
C        see crecdf
1552
C        see crecdf
1553
C        additionally: varnam_len, the length of the 
1553
C        additionally: varnam_len, the length of the 
1554
C           strings
1554
C           strings
1555
C        
1555
C        
1556
C        
1556
C        
1557
C     History:
1557
C     History:
1558
C        981221  Mark A. Liniger ETHZ
1558
C        981221  Mark A. Liniger ETHZ
1559
C        
1559
C        
1560
C     Note:
1560
C     Note:
1561
C        
1561
C        
1562
C        
1562
C        
1563
C------------------------------------------------------------------------
1563
C------------------------------------------------------------------------
1564
      integer        varnam_len,ndim,error,vardim(*),cdfid
1564
      integer        varnam_len,ndim,error,vardim(*),cdfid
1565
      character *(*) varnam
1565
      character *(*) varnam
1566
      real           misdat,stag(*),varmin(*),varmax(*)
1566
      real           misdat,stag(*),varmin(*),varmax(*)
1567
 
1567
 
1568
      call putdef (cdfid, varnam(1:varnam_len), ndim, misdat, 
1568
      call putdef (cdfid, varnam(1:varnam_len), ndim, misdat, 
1569
     &     vardim, varmin, varmax, stag, error)
1569
     &     vardim, varmin, varmax, stag, error)
1570
 
1570
 
1571
      end
1571
      end
1572
 
1572
 
1573
 
1573
 
1574
      subroutine cpp_putdat(cdfid, varnam,varnam_len, 
1574
      subroutine cpp_putdat(cdfid, varnam,varnam_len, 
1575
     &     time, level, dat, error)
1575
     &     time, level, dat, error)
1576
C------------------------------------------------------------------------
1576
C------------------------------------------------------------------------
1577
C     Purpose:
1577
C     Purpose:
1578
C        allows to call putdef from c++
1578
C        allows to call putdef from c++
1579
C     Arguments: 
1579
C     Arguments: 
1580
C        see crecdf
1580
C        see crecdf
1581
C        additionally: varnam_len, the length of the 
1581
C        additionally: varnam_len, the length of the 
1582
C           strings
1582
C           strings
1583
C        
1583
C        
1584
C        
1584
C        
1585
C     History:
1585
C     History:
1586
C        981221  Mark A. Liniger ETHZ
1586
C        981221  Mark A. Liniger ETHZ
1587
C        
1587
C        
1588
C     Note:
1588
C     Note:
1589
C        
1589
C        
1590
C        
1590
C        
1591
C------------------------------------------------------------------------
1591
C------------------------------------------------------------------------
1592
      integer        varnam_len,cdfid,error,level
1592
      integer        varnam_len,cdfid,error,level
1593
      character *(*) varnam
1593
      character *(*) varnam
1594
      real           dat(*)
1594
      real           dat(*)
1595
      real           time
1595
      real           time
1596
 
1596
 
1597
      call putdat(cdfid, varnam(1:varnam_len), time, level, dat, error)
1597
      call putdat(cdfid, varnam(1:varnam_len), time, level, dat, error)
1598
 
1598
 
1599
 
1599
 
1600
 
1600
 
1601
      end
1601
      end