Subversion Repositories lagranto.ecmwf

Rev

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

Rev 15 Rev 39
1
c     ****************************************************************
1
c     ****************************************************************
2
c     * This package provides IO routines for trajectories. A file   *
2
c     * This package provides IO routines for trajectories. A file   *
3
c     * is characterised by the filename <filename> and the file     *
3
c     * is characterised by the filename <filename> and the file     *
4
c     * identifier <fid>. Different modes <mode> are supported:      *
4
c     * identifier <fid>. Different modes <mode> are supported:      *
5
c     *     mode=1: ascii, sorted by trajectory;                     *
5
c     *     mode=1: ascii, sorted by trajectory;                     *
6
c     *     mode=2: ascii, sorted by time;                           *
6
c     *     mode=2: ascii, sorted by time;                           *
7
c     *     mode=3: fortran (unformatted)                            * 
7
c     *     mode=3: fortran (unformatted)                            * 
8
c     *     mode=4: IVE netcdf (for compatibiltzy reasons)           *
8
c     *     mode=4: IVE netcdf (for compatibiltzy reasons)           *
-
 
9
c     *     mode=5: KML                                              *
-
 
10
c     *     mode=6: as mode 1, but with pressure as realk number     *
9
c     * A trajectory set is given as 3d array <tra(ntra,ntim,ncol)>  *
11
c     * A trajectory set is given as 3d array <tra(ntra,ntim,ncol)>  *
10
c     * where <ntra> is the number of trajectories, <ntim> the       *
12
c     * where <ntra> is the number of trajectories, <ntim> the       *
11
c     * number of times of each trajectory and <ncol> the number of  *
13
c     * number of times of each trajectory and <ncol> the number of  *
12
c     * columns of the trajectory. The first 4 columns are: time,    *
14
c     * columns of the trajectory. The first 4 columns are: time,    *
13
c     * longitude, latitude, pressure. The other columns are traced  *
15
c     * longitude, latitude, pressure. The other columns are traced  *
14
c     * fields. The complete list of all columns is given in the     *
16
c     * fields. The complete list of all columns is given in the     *
15
c     * array <vars(ncol)>. Finally, the reference date is given in  *
17
c     * array <vars(ncol)>. Finally, the reference date is given in  *
16
c     * the array <time(6)=year,month,day,hour,time length of the    *
18
c     * the array <time(6)=year,month,day,hour,time length of the    *
17
c     * trajectory (hour,min)>.                                      *
19
c     * trajectory (hour,min)>.                                      *
18
c     *                                                              *
20
c     *                                                              *
19
c     * Author: Michael Sprenger, September 2008                     *
21
c     * Author: Michael Sprenger, September 2008                     *
20
c     ****************************************************************
22
c     ****************************************************************
21
 
23
 
22
c     ----------------------------------------------------------------
24
c     ----------------------------------------------------------------
23
c     Open a trajectory file for reading
25
c     Open a trajectory file for reading
24
c     ----------------------------------------------------------------
26
c     ----------------------------------------------------------------
25
      
27
      
26
      subroutine ropen_tra(fid,filename,ntra,ntim,ncol,time,vars,mode)
28
      subroutine ropen_tra(fid,filename,ntra,ntim,ncol,time,vars,mode)
27
 
29
 
28
      implicit none
30
      implicit none
29
      
31
      
30
c     Declaration of subroutine parameters
32
c     Declaration of subroutine parameters
31
      integer      fid
33
      integer      fid
32
      character*80 filename
34
      character*80 filename
33
      integer      mode
35
      integer      mode
34
      integer      ntra,ntim,ncol
36
      integer      ntra,ntim,ncol
35
      integer      time(6)
37
      integer      time(6)
36
      character*80 vars(ncol)
38
      character*80 vars(ncol)
37
 
39
 
38
c     Auxiliary variables
40
c     Auxiliary variables
39
      integer      vardim(4)
41
      integer      vardim(4)
40
      real         varmin(4),varmax(4),stag(4)
42
      real         varmin(4),varmax(4),stag(4)
41
      real         mdv
43
      real         mdv
42
      character*80 cfn
44
      character*80 cfn
43
      integer      ierr
45
      integer      ierr
44
      integer      i
46
      integer      i
45
      integer      nvars
47
      integer      nvars
46
 
48
 
47
c     Open file
49
c     Open file
48
      if (mode.eq.1) then
50
      if (mode.eq.1) then
49
         fid = 10
51
         fid = 10
50
         open(fid,file=filename)
52
         open(fid,file=filename)
51
      elseif (mode.eq.2) then
53
      elseif (mode.eq.2) then
52
         fid = 10
54
         fid = 10
53
         open(fid,file=filename)
55
         open(fid,file=filename)
54
      elseif (mode.eq.3) then
56
      elseif (mode.eq.3) then
55
         open(fid,file=filename,form='unformatted')
57
         open(fid,file=filename,form='unformatted')
56
      elseif (mode.eq.4) then
58
      elseif (mode.eq.4) then
57
         call cdfopn(filename,fid,ierr)
59
         call cdfopn(filename,fid,ierr)
58
      elseif (mode.eq.5) then
60
      elseif (mode.eq.5) then
59
         print*,' ERROR: Reading KML not supported'
61
         print*,' ERROR: Reading KML not supported'
60
         stop
62
         stop
-
 
63
      elseif (mode.eq.6) then
-
 
64
         fid = 10
-
 
65
         open(fid,file=filename)   
61
      endif
66
      endif
62
 
67
 
63
c     Read header information
68
c     Read header information
64
      call read_hea(fid,time,vars,ntra,ntim,ncol,mode)
69
      call read_hea(fid,time,vars,ntra,ntim,ncol,mode)
65
 
70
 
66
      end
71
      end
67
      
72
      
68
 
73
 
69
c     ----------------------------------------------------------------
74
c     ----------------------------------------------------------------
70
c     Open a trajectory file for wrinting
75
c     Open a trajectory file for wrinting
71
c     ----------------------------------------------------------------
76
c     ----------------------------------------------------------------
72
      
77
      
73
      subroutine wopen_tra(fid,filename,ntra,ntim,ncol,time,vars,mode)
78
      subroutine wopen_tra(fid,filename,ntra,ntim,ncol,time,vars,mode)
74
      
79
      
75
      implicit none
80
      implicit none
76
      
81
      
77
c     Declaration of subroutine parameters
82
c     Declaration of subroutine parameters
78
      integer      fid
83
      integer      fid
79
      character*80 filename
84
      character*80 filename
80
      integer      mode
85
      integer      mode
81
      integer      ntra,ntim,ncol
86
      integer      ntra,ntim,ncol
82
      integer      time(6) 
87
      integer      time(6) 
83
      character*80 vars(ncol)
88
      character*80 vars(ncol)
84
 
89
 
85
c     Auxiliary variables
90
c     Auxiliary variables
86
      integer      vardim(4)
91
      integer      vardim(4)
87
      real         varmin(4),varmax(4),stag(4)
92
      real         varmin(4),varmax(4),stag(4)
88
      real         mdv
93
      real         mdv
89
      character*80 cfn
94
      character*80 cfn
90
      integer      ierr
95
      integer      ierr
91
      integer      i
96
      integer      i
92
      character*80 varname
97
      character*80 varname
93
      real         rtime(6)
98
      real         rtime(6)
94
 
99
 
95
c     Open file
100
c     Open file
96
      if (mode.eq.1) then
101
      if (mode.eq.1) then
97
         fid = 10
102
         fid = 10
98
         open(fid,file=filename)
103
         open(fid,file=filename)
99
      elseif (mode.eq.2) then
104
      elseif (mode.eq.2) then
100
         fid = 10
105
         fid = 10
101
         open(fid,file=filename)
106
         open(fid,file=filename)
102
      elseif (mode.eq.3) then
107
      elseif (mode.eq.3) then
103
         open(fid,file=filename,form='unformatted')
108
         open(fid,file=filename,form='unformatted')
104
      elseif (mode.eq.4) then
109
      elseif (mode.eq.4) then
105
         vardim(1)=ntra
110
         vardim(1)=ntra
106
         vardim(2)=1
111
         vardim(2)=1
107
         vardim(3)=1
112
         vardim(3)=1
108
         vardim(4)=1
113
         vardim(4)=1
109
         cfn      =trim(filename)//'_cst'
114
         cfn      =trim(filename)//'_cst'
110
         mdv      =-999.98999
115
         mdv      =-999.98999
111
         call crecdf(filename,fid,varmin,varmax,3,cfn,ierr)
116
         call crecdf(filename,fid,varmin,varmax,3,cfn,ierr)
112
      elseif (mode.eq.5) then
117
      elseif (mode.eq.5) then
113
         fid = 10
118
         fid = 10
114
         open(fid,file=filename)
119
         open(fid,file=filename)
-
 
120
      elseif (mode.eq.6) then
-
 
121
         fid = 10
-
 
122
         open(fid,file=filename)
115
      endif
123
      endif
116
 
124
 
117
c     Write header information
125
c     Write header information
118
      call write_hea(fid,time,vars,ntra,ntim,ncol,mode)
126
      call write_hea(fid,time,vars,ntra,ntim,ncol,mode)
119
 
127
 
120
      end
128
      end
121
 
129
 
122
 
130
 
123
c     ----------------------------------------------------------------
131
c     ----------------------------------------------------------------
124
c     Read a trajectory
132
c     Read a trajectory
125
c     ----------------------------------------------------------------
133
c     ----------------------------------------------------------------
126
 
134
 
127
      subroutine read_tra(fid,tra,ntra,ntim,ncol,mode)
135
      subroutine read_tra(fid,tra,ntra,ntim,ncol,mode)
128
 
136
 
129
      implicit none
137
      implicit none
130
 
138
 
131
c     Declaration of subroutine parameters
139
c     Declaration of subroutine parameters
132
      integer   fid
140
      integer   fid
133
      integer   ntim
141
      integer   ntim
134
      integer   ncol
142
      integer   ncol
135
      integer   ntra
143
      integer   ntra
136
      real      tra(ntra,ntim,ncol)
144
      real      tra(ntra,ntim,ncol)
137
      integer   mode
145
      integer   mode
138
 
146
 
139
c     Auxiliary variables
147
c     Auxiliary variables
140
      integer      i,j,n
148
      integer      i,j,n
141
      real         arr(ntra)
149
      real         arr(ntra)
142
      integer      ntimes
150
      integer      ntimes
143
      real         times(10000)
151
      real         times(10000)
144
      integer      ierr
152
      integer      ierr
145
      character*80 vars(ncol+2)
153
      character*80 vars(ncol+2)
146
      integer      nvars
154
      integer      nvars
147
 
155
 
148
c     Read ascii mode, sorted by trajectory (mode=1)
156
c     Read ascii mode, sorted by trajectory (mode=1)
149
      if (mode.eq.1) then
157
      if (mode.eq.1) then
150
         read(fid,*,end=100)
158
         read(fid,*,end=100)
151
         do n=1,ntra
159
         do n=1,ntra
152
            do i=1,ntim
160
            do i=1,ntim
153
               read(fid,*,end=110) (tra(n,i,j),j=1,ncol)
161
               read(fid,*,end=110) (tra(n,i,j),j=1,ncol)
154
            enddo
162
            enddo
155
         enddo
163
         enddo
156
 
164
 
157
c     Read ascii mode, sorted by time (mode=2)
165
c     Read ascii mode, sorted by time (mode=2)
158
      elseif (mode.eq.2) then
166
      elseif (mode.eq.2) then
159
         read(fid,*,end=100)
167
         read(fid,*,end=100)
160
         do i=1,ntim
168
         do i=1,ntim
161
            do n=1,ntra
169
            do n=1,ntra
162
               read(fid,*,end=100) (tra(n,i,j),j=1,ncol)
170
               read(fid,*,end=100) (tra(n,i,j),j=1,ncol)
163
            enddo
171
            enddo
164
         enddo
172
         enddo
165
 
173
 
166
c     Read fortran mode (mode=3)
174
c     Read fortran mode (mode=3)
167
      elseif (mode.eq.3) then
175
      elseif (mode.eq.3) then
168
         read(fid) tra
176
         read(fid) tra
169
 
177
 
170
c     Read IVE netcdf mode (mode=4)
178
c     Read IVE netcdf mode (mode=4)
171
      elseif (mode.eq.4) then
179
      elseif (mode.eq.4) then
172
          call gettimes(fid,times,ntimes,ierr)
180
          call gettimes(fid,times,ntimes,ierr)
173
          call getvars(fid,nvars,vars,ierr)
181
          call getvars(fid,nvars,vars,ierr)
174
          do i=1,ntim
182
          do i=1,ntim
175
             do j=1,ncol
183
             do j=1,ncol
176
                if (j.eq.1) then
184
                if (j.eq.1) then
177
                   do n=1,ntra
185
                   do n=1,ntra
178
                      tra(n,i,1)=times(i)
186
                      tra(n,i,1)=times(i)
179
                   enddo
187
                   enddo
180
                else
188
                else
181
                   call getdat(fid,vars(j),times(i),0,arr,ierr)
189
                   call getdat(fid,vars(j),times(i),0,arr,ierr)
182
                   do n=1,ntra
190
                   do n=1,ntra
183
                      tra(n,i,j)=arr(n)
191
                      tra(n,i,j)=arr(n)
184
                   enddo
192
                   enddo
185
                endif
193
                endif
186
            enddo
194
            enddo
187
         enddo
195
         enddo
-
 
196
         
-
 
197
c     Read ascii trajectory with pressure as real         
-
 
198
      elseif (mode.eq.6) then
-
 
199
         read(fid,*,end=100)
-
 
200
         do n=1,ntra
-
 
201
            do i=1,ntim
-
 
202
               read(fid,*,end=110) (tra(n,i,j),j=1,ncol)
-
 
203
            enddo
-
 
204
         enddo
188
 
205
 
189
      endif
206
      endif
190
 
207
 
191
      return
208
      return
192
 
209
 
193
c     End of file has been reached: set negative <fid>
210
c     End of file has been reached: set negative <fid>
194
 100  fid=-fid
211
 100  fid=-fid
195
      return
212
      return
196
 
213
 
197
c     Error: incomplete trajectory
214
c     Error: incomplete trajectory
198
 110  print*,'<read_tra>: Incomplete trajectory... Stop'
215
 110  print*,'<read_tra>: Incomplete trajectory... Stop'
199
      stop
216
      stop
200
      
217
      
201
      end
218
      end
202
 
219
 
203
 
220
 
204
c     ----------------------------------------------------------------
221
c     ----------------------------------------------------------------
205
c     Write a trajectory
222
c     Write a trajectory
206
c     ----------------------------------------------------------------
223
c     ----------------------------------------------------------------
207
 
224
 
208
      subroutine write_tra(fid,tra,ntra,ntim,ncol,mode)
225
      subroutine write_tra(fid,tra,ntra,ntim,ncol,mode)
209
 
226
 
210
      implicit none
227
      implicit none
211
 
228
 
212
c     Declaration of subroutine parameters
229
c     Declaration of subroutine parameters
213
      integer   fid
230
      integer   fid
214
      integer   ntim
231
      integer   ntim
215
      integer   ncol
232
      integer   ncol
216
      integer   ntra
233
      integer   ntra
217
      real      tra(ntra,ntim,ncol)
234
      real      tra(ntra,ntim,ncol)
218
      integer   mode
235
      integer   mode
219
 
236
 
220
c     Auxiliary variables
237
c     Auxiliary variables
221
      integer      i,j,n
238
      integer      i,j,n
222
      real         arr(ntra)
239
      real         arr(ntra)
223
      integer      ierr
240
      integer      ierr
224
      real         time
241
      real         time
225
      character*80 vars(ncol+2)
242
      character*80 vars(ncol+2)
226
      integer      nvars
243
      integer      nvars
227
      character*20 lonstr,latstr,levstr
244
      character*20 lonstr,latstr,levstr
228
      character*80 outstr
245
      character*80 outstr
229
      real         ref_z(3000),ref_p(3000),ref_t(3000)
246
      real         ref_z(3000),ref_p(3000),ref_t(3000)
230
      real         lev
247
      real         lev
231
      character*80 path
248
      character*80 path
232
 
249
 
233
c     Write ascii mode, sorted by trajectory (mode=1)
250
c     Write ascii mode, sorted by trajectory (mode=1)
234
      if (mode.eq.1) then
251
      if (mode.eq.1) then
235
         do n=1,ntra
252
         do n=1,ntra
236
            write(fid,*)
253
            write(fid,*)
237
            do i=1,ntim
254
            do i=1,ntim
238
 
255
 
239
c              Avoid ugly *s or missing space in output
256
c              Avoid ugly *s or missing space in output
240
               do j=5,ncol
257
               do j=5,ncol
241
                  if ( abs(tra(n,i,j)).gt.9999.) then                     
258
                  if ( abs(tra(n,i,j)).gt.9999.) then                     
242
                     print*,'Format problem : ',tra(n,i,j),' -> -999.99'
259
                     print*,'Format problem : ',tra(n,i,j),' -> -999.99'
243
                     tra(n,i,j) = -999.99
260
                     tra(n,i,j) = -999.99
244
                  endif
261
                  endif
245
               enddo
262
               enddo
246
 
263
 
247
               write(fid,'(1f7.2,f9.2,f8.2,i6,100f10.3)') 
264
               write(fid,'(1f7.2,f9.2,f8.2,i6,100f10.3)') 
248
     >               (tra(n,i,j),j=1,3),             ! time, lon, lat
265
     >               (tra(n,i,j),j=1,3),             ! time, lon, lat
249
     >               nint(tra(n,i,4)),               ! p
266
     >               nint(tra(n,i,4)),               ! p
250
     >               (tra(n,i,j),j=5,ncol)           ! fields
267
     >               (tra(n,i,j),j=5,ncol)           ! fields
251
            enddo
268
            enddo
252
         enddo
269
         enddo
253
 
270
 
254
c     Write ascii mode, sorted by time (mode=2)
271
c     Write ascii mode, sorted by time (mode=2)
255
      elseif (mode.eq.2) then
272
      elseif (mode.eq.2) then
256
         do i=1,ntim
273
         do i=1,ntim
257
            write(fid,*)
274
            write(fid,*)
258
            do n=1,ntra
275
            do n=1,ntra
259
 
276
 
260
c              Avoid ugly *s or missing space in output
277
c              Avoid ugly *s or missing space in output
261
               do j=5,ncol
278
               do j=5,ncol
262
                  if ( abs(tra(n,i,j)).gt.9999.) then                     
279
                  if ( abs(tra(n,i,j)).gt.9999.) then                     
263
                     print*,'Format problem : ',tra(n,i,j),' -> -999.99'
280
                     print*,'Format problem : ',tra(n,i,j),' -> -999.99'
264
                     tra(n,i,j) = -999.99
281
                     tra(n,i,j) = -999.99
265
                  endif
282
                  endif
266
               enddo
283
               enddo
267
 
284
 
268
               write(fid,'(1f7.2,f9.2,f8.2,i6,100f10.3)') 
285
               write(fid,'(1f7.2,f9.2,f8.2,i6,100f10.3)') 
269
     >               (tra(n,i,j),j=1,3),             ! time, lon, lat
286
     >               (tra(n,i,j),j=1,3),             ! time, lon, lat
270
     >               nint(tra(n,i,4)),               ! p
287
     >               nint(tra(n,i,4)),               ! p
271
     >               (tra(n,i,j),j=5,ncol)           ! fields
288
     >               (tra(n,i,j),j=5,ncol)           ! fields
272
            enddo
289
            enddo
273
         enddo
290
         enddo
274
 
291
 
275
c     Write fortran mode (mode=3)
292
c     Write fortran mode (mode=3)
276
      elseif (mode.eq.3) then
293
      elseif (mode.eq.3) then
277
         write(fid) tra                              
294
         write(fid) tra                              
278
 
295
 
279
c     Write netcdf mode (mode=4)
296
c     Write netcdf mode (mode=4)
280
      elseif (mode.eq.4) then
297
      elseif (mode.eq.4) then
281
         call getvars(fid,nvars,vars,ierr)
298
         call getvars(fid,nvars,vars,ierr)
282
         do i=1,ntim
299
         do i=1,ntim
283
            time=tra(1,i,1)
300
            time=tra(1,i,1)
284
            do j=2,ncol
301
            do j=2,ncol
285
               do n=1,ntra
302
               do n=1,ntra
286
                  arr(n)=tra(n,i,j)
303
                  arr(n)=tra(n,i,j)
287
               enddo
304
               enddo
288
               call putdat(fid,vars(j),time,0,arr,ierr)
305
               call putdat(fid,vars(j),time,0,arr,ierr)
289
            enddo
306
            enddo
290
         enddo
307
         enddo
291
 
308
 
292
c     Write KML mode (mode=5)
309
c     Write KML mode (mode=5)
293
      elseif (mode.eq.5) then
310
      elseif (mode.eq.5) then
294
 
311
 
295
         call getenv('DYN_TOOLS',path)
312
         call getenv('DYN_TOOLS',path)
296
         path = trim(path)//'/lagranto.ecmwf/goodies/'
313
         path = trim(path)//'/lagranto.ecmwf/goodies/'
297
 
314
 
298
         open(fid+1,file=trim(path)//'reformat.refprof')
315
         open(fid+1,file=trim(path)//'reformat.refprof')
299
           
316
           
300
           do n=1,6
317
           do n=1,6
301
              read(fid+1,*)
318
              read(fid+1,*)
302
           enddo
319
           enddo
303
           do n=1,3000
320
           do n=1,3000
304
              read(fid+1,*)  ref_z(n),ref_t(n),ref_p(n)
321
              read(fid+1,*)  ref_z(n),ref_t(n),ref_p(n)
305
              ref_p(n) = 0.01 * ref_p(n)
322
              ref_p(n) = 0.01 * ref_p(n)
306
           enddo
323
           enddo
307
 
324
 
308
         close(fid+1)
325
         close(fid+1)
309
 
326
 
310
         do n=1,ntra
327
         do n=1,ntra
311
           write(fid,"(A)") '<Placemark>'
328
           write(fid,"(A)") '<Placemark>'
312
           write(fid,"(A)") '<name>Absolute Extruded</name>'
329
           write(fid,"(A)") '<name>Absolute Extruded</name>'
313
           write(fid,"(A)") '<styleUrl>#yellowkLineGreenPoly</styleUrl>'
330
           write(fid,"(A)") '<styleUrl>#yellowkLineGreenPoly</styleUrl>'
314
           write(fid,"(A)") '<LineString>'
331
           write(fid,"(A)") '<LineString>'
315
           write(fid,"(A)") '<extrude>1</extrude>'
332
           write(fid,"(A)") '<extrude>1</extrude>'
316
           write(fid,"(A)") '<tessellate>1</tessellate>'
333
           write(fid,"(A)") '<tessellate>1</tessellate>'
317
           write(fid,"(A)") '<altitudeMode>absolute</altitudeMode>'
334
           write(fid,"(A)") '<altitudeMode>absolute</altitudeMode>'
318
           write(fid,"(A)") '<coordinates>'
335
           write(fid,"(A)") '<coordinates>'
319
 
336
 
320
           do i=1,ntim
337
           do i=1,ntim
321
             write(lonstr,*) tra(n,i,2)
338
             write(lonstr,*) tra(n,i,2)
322
             write(latstr,*) tra(n,i,3)
339
             write(latstr,*) tra(n,i,3)
323
             
340
             
324
             call binary(lev,tra(n,i,4),ref_z,ref_p)
341
             call binary(lev,tra(n,i,4),ref_z,ref_p)
325
             write(levstr,*) lev
342
             write(levstr,*) lev
326
 
343
 
327
             outstr = trim(adjustl(lonstr))//','//
344
             outstr = trim(adjustl(lonstr))//','//
328
     >                trim(adjustl(latstr))//','//
345
     >                trim(adjustl(latstr))//','//
329
     >                trim(adjustl(levstr))
346
     >                trim(adjustl(levstr))
330
 
347
 
331
             write(fid,"(A)") outstr
348
             write(fid,"(A)") outstr
332
 
349
 
333
           enddo
350
           enddo
334
 
351
 
335
           write(fid,*) '</coordinates>'
352
           write(fid,*) '</coordinates>'
336
           write(fid,*) '</LineString>'
353
           write(fid,*) '</LineString>'
337
           write(fid,*) '</Placemark>'
354
           write(fid,*) '</Placemark>'
338
         enddo
355
         enddo
-
 
356
         
-
 
357
c     Write ASCII trajectory with pressure as real         
-
 
358
      elseif (mode.eq.6) then
-
 
359
         do n=1,ntra
-
 
360
            write(fid,*)
-
 
361
            do i=1,ntim
339
 
362
 
-
 
363
c              Avoid ugly *s or missing space in output
-
 
364
               do j=5,ncol
-
 
365
                  if ( abs(tra(n,i,j)).gt.9999.) then                     
-
 
366
                     print*,'Format problem : ',tra(n,i,j),' -> -999.99'
-
 
367
                     tra(n,i,j) = -999.99
-
 
368
                  endif
-
 
369
               enddo
-
 
370
 
-
 
371
               write(fid,'(1f7.2,f9.2,f8.2,f8.2,100f10.3)') 
-
 
372
     >               (tra(n,i,j),j=1,3),             ! time, lon, lat
-
 
373
     >               tra(n,i,4),                     ! p
-
 
374
     >               (tra(n,i,j),j=5,ncol)           ! fields
-
 
375
            enddo
-
 
376
         enddo
340
      endif
377
      endif
341
 
378
 
342
      end
379
      end
343
 
380
 
344
 
381
 
345
c     ----------------------------------------------------------------
382
c     ----------------------------------------------------------------
346
c     Read header from trajectory file
383
c     Read header from trajectory file
347
c     ----------------------------------------------------------------
384
c     ----------------------------------------------------------------
348
 
385
 
349
      subroutine read_hea(fid,time,vars,ntra,ntim,ncol,mode)
386
      subroutine read_hea(fid,time,vars,ntra,ntim,ncol,mode)
350
 
387
 
351
      implicit none
388
      implicit none
352
      
389
      
353
c     Declaration of subroutine parameters
390
c     Declaration of subroutine parameters
354
      integer       fid
391
      integer       fid
355
      integer       time(6)
392
      integer       time(6)
356
      integer       ntra,ntim,ncol
393
      integer       ntra,ntim,ncol
357
      character*80  vars(ncol)
394
      character*80  vars(ncol)
358
      integer       mode
395
      integer       mode
359
 
396
 
360
c     Auxiliary variables
397
c     Auxiliary variables
361
      integer       i
398
      integer       i
362
      character     ch(500)
399
      character     ch(500)
363
      character*500 str
400
      character*500 str
364
      integer       ich(500)
401
      integer       ich(500)
365
      integer       isstr,ileft,iright
402
      integer       isstr,ileft,iright
366
      character*80  varname
403
      character*80  varname
367
      real          rtime(6)
404
      real          rtime(6)
368
      integer       ierr
405
      integer       ierr
369
      integer       nvars
406
      integer       nvars
370
      character*15  str1
407
      character*15  str1
371
      character     str2
408
      character     str2
372
      character*13  str3
409
      character*13  str3
373
      character*4   str4
410
      character*4   str4
374
      character*80  linestr
411
      character*80  linestr
375
      integer       itmp1,itmp2
412
      integer       itmp1,itmp2
376
 
413
 
377
c     Read ascii format (mode=1,2)
414
c     Read ascii format (mode=1,2,6)
378
      if ( (mode.eq.1).or.(mode.eq.2) ) then
415
      if ( (mode.eq.1).or.(mode.eq.2).or.(mode.eq.6) ) then
379
 
416
 
380
c        Read the time specification (old and new format)
417
c        Read the time specification (old and new format)
381
         read(fid,'(a80)') linestr
418
         read(fid,'(a80)') linestr
382
         
419
         
383
         if ( linestr(1:14).eq.'Reference date' ) then
420
         if ( linestr(1:14).eq.'Reference date' ) then
384
            read(linestr,'(a15,i4,i2,i2,a1,i2,i2,a13,i8,a4)') 
421
            read(linestr,'(a15,i4,i2,i2,a1,i2,i2,a13,i8,a4)') 
385
     >           str1,
422
     >           str1,
386
     >           time(1),time(2),time(3),str2,time(4),time(5),
423
     >           time(1),time(2),time(3),str2,time(4),time(5),
387
     >           str3,time(6),str4
424
     >           str3,time(6),str4
388
                       
425
                       
389
         elseif ( linestr(1:11).eq.'time period' ) then
426
         elseif ( linestr(1:11).eq.'time period' ) then
390
            read(linestr,'(a12,i4,i2,i2,a1,i2,a4,i6,a1,i2,a2)') 
427
            read(linestr,'(a12,i4,i2,i2,a1,i2,a4,i6,a1,i2,a2)') 
391
     >           str1,
428
     >           str1,
392
     >           time(1),time(2),time(3),str2,time(4),
429
     >           time(1),time(2),time(3),str2,time(4),
393
     >           str3,itmp1,str3,itmp2,str4
430
     >           str3,itmp1,str3,itmp2,str4
394
            time(5) = 0
431
            time(5) = 0
395
            time(6) = itmp1 * 60 + itmp2
432
            time(6) = itmp1 * 60 + itmp2
396
 
433
 
397
         endif
434
         endif
398
 
435
 
399
c        Skip the empty line and read field names
436
c        Skip the empty line and read field names
400
         read(fid,*)
437
         read(fid,*)
401
         read(fid,'(a500)',end=100) str
438
         read(fid,'(a500)',end=100) str
402
         do i=1,500
439
         do i=1,500
403
            ch(i)=str(i:i)
440
            ch(i)=str(i:i)
404
         enddo
441
         enddo
405
 
442
 
406
c        Split the input string
443
c        Split the input string
407
         isstr=0
444
         isstr=0
408
         nvars=0
445
         nvars=0
409
         do i=1,500
446
         do i=1,500
410
            if ( (isstr.eq.0).and.(ch(i).ne.' ') ) then
447
            if ( (isstr.eq.0).and.(ch(i).ne.' ') ) then
411
               isstr=1
448
               isstr=1
412
               ileft=i
449
               ileft=i
413
            elseif ( (isstr.eq.1).and.(ch(i).eq.' ') ) then
450
            elseif ( (isstr.eq.1).and.(ch(i).eq.' ') ) then
414
               isstr=0
451
               isstr=0
415
               iright=i-1
452
               iright=i-1
416
               nvars=nvars+1
453
               nvars=nvars+1
417
               vars(nvars)=str(ileft:iright)
454
               vars(nvars)=str(ileft:iright)
418
            endif
455
            endif
419
         enddo
456
         enddo
420
 
457
 
421
c        Skip the empty line
458
c        Skip the empty line
422
         read(fid,*,end=100)
459
         read(fid,*,end=100)
423
 
460
 
424
c     Read fortran mode (mode=3)
461
c     Read fortran mode (mode=3)
425
      elseif (mode.eq.3) then
462
      elseif (mode.eq.3) then
426
         read(fid) ntra,ntim,ncol
463
         read(fid) ntra,ntim,ncol
427
         read(fid) time
464
         read(fid) time
428
         read(fid) vars
465
         read(fid) vars
429
 
466
 
430
c     Read IVE netcdf mode (mode=4)
467
c     Read IVE netcdf mode (mode=4)
431
      elseif (mode.eq.4) then
468
      elseif (mode.eq.4) then
432
         call getvars(fid,nvars,vars,ierr)  
469
         call getvars(fid,nvars,vars,ierr)  
433
         varname='BASEDATE'
470
         varname='BASEDATE'
434
         call getdat(fid,varname,0.,0,rtime,ierr)
471
         call getdat(fid,varname,0.,0,rtime,ierr)
435
         do i=1,6
472
         do i=1,6
436
            time(i)=nint(rtime(i))
473
            time(i)=nint(rtime(i))
437
         enddo
474
         enddo
438
      endif
475
      endif
439
 
476
 
440
      return
477
      return
441
 
478
 
442
c     End of file has been reached
479
c     End of file has been reached
443
 100  fid=-fid
480
 100  fid=-fid
444
      return
481
      return
445
 
482
 
446
c     Excetion handling
483
c     Excetion handling
447
 110  print*,'<read_hea>: Unexspected time format.... Stop'
484
 110  print*,'<read_hea>: Unexspected time format.... Stop'
448
      stop
485
      stop
449
   
486
   
450
      end
487
      end
451
      
488
      
452
 
489
 
453
c     ----------------------------------------------------------------
490
c     ----------------------------------------------------------------
454
c     Write header to trajectory file (in ascii mode)
491
c     Write header to trajectory file (in ascii mode)
455
c     ----------------------------------------------------------------
492
c     ----------------------------------------------------------------
456
 
493
 
457
      subroutine write_hea(fid,time,vars,ntra,ntim,ncol,mode)
494
      subroutine write_hea(fid,time,vars,ntra,ntim,ncol,mode)
458
 
495
 
459
      implicit none
496
      implicit none
460
      
497
      
461
c     Declaration of subroutine parameters
498
c     Declaration of subroutine parameters
462
      integer       fid
499
      integer       fid
463
      integer       time(6)
500
      integer       time(6)
464
      integer       ntra,ntim,ncol
501
      integer       ntra,ntim,ncol
465
      character*80  vars(ncol)
502
      character*80  vars(ncol)
466
      integer       mode
503
      integer       mode
467
 
504
 
468
c     Auxiliary variables
505
c     Auxiliary variables
469
      integer       i
506
      integer       i
470
      character*500 str
507
      character*500 str
471
      character*4   str1
508
      character*4   str1
472
      character*2   str2,str3,str4,str5,str6
509
      character*2   str2,str3,str4,str5,str6
473
      integer       vardim(4)
510
      integer       vardim(4)
474
      real          varmin(4),varmax(4),stag(4)
511
      real          varmin(4),varmax(4),stag(4)
475
      real          mdv
512
      real          mdv
476
      integer       ierr
513
      integer       ierr
477
      character*80  varname
514
      character*80  varname
478
      real          rtime(6)
515
      real          rtime(6)
479
      integer       nvars
516
      integer       nvars
480
 
517
 
481
c     Write ascii format (mode=1,2)
518
c     Write ascii format (mode=1,2)
482
      if ( (mode.eq.1).or.(mode.eq.2) ) then
519
      if ( (mode.eq.1).or.(mode.eq.2) ) then
483
 
520
 
484
c        Get the strings for output
521
c        Get the strings for output
485
         write(str1,'(i4)') time(1)
522
         write(str1,'(i4)') time(1)
486
         write(str2,'(i2)') time(2)
523
         write(str2,'(i2)') time(2)
487
         write(str3,'(i2)') time(3)
524
         write(str3,'(i2)') time(3)
488
         write(str4,'(i2)') time(4)
525
         write(str4,'(i2)') time(4)
489
         write(str5,'(i2)') time(5)
526
         write(str5,'(i2)') time(5)
490
         if (time(2).eq. 0) str2(1:1)='0'
527
         if (time(2).eq. 0) str2(1:1)='0'
491
         if (time(3).eq. 0) str3(1:1)='0'
528
         if (time(3).eq. 0) str3(1:1)='0'
492
         if (time(4).eq. 0) str4(1:1)='0'
529
         if (time(4).eq. 0) str4(1:1)='0'
493
         if (time(5).eq. 0) str5(1:1)='0'
530
         if (time(5).eq. 0) str5(1:1)='0'
494
         if (time(2).lt.10) str2(1:1)='0'
531
         if (time(2).lt.10) str2(1:1)='0'
495
         if (time(3).lt.10) str3(1:1)='0'
532
         if (time(3).lt.10) str3(1:1)='0'
496
         if (time(4).lt.10) str4(1:1)='0'
533
         if (time(4).lt.10) str4(1:1)='0'
497
         if (time(5).lt.10) str5(1:1)='0'
534
         if (time(5).lt.10) str5(1:1)='0'
498
 
535
 
499
c        Write the time specification
536
c        Write the time specification
500
         write(fid,'(a15,a4,a2,a2,a1,a2,a2,a13,i8,a4)') 
537
         write(fid,'(a15,a4,a2,a2,a1,a2,a2,a13,i8,a4)') 
501
     >          'Reference date ',
538
     >          'Reference date ',
502
     >           str1,str2,str3,'_',str4,str5,
539
     >           str1,str2,str3,'_',str4,str5,
503
     >          ' / Time range',time(6), ' min'
540
     >          ' / Time range',time(6), ' min'
504
         write(fid,*)
541
         write(fid,*)
505
 
542
 
506
c        Write variable names
543
c        Write variable names
507
         str=''
544
         str=''
508
         do i=1,ncol
545
         do i=1,ncol
509
            varname = vars(i)
546
            varname = vars(i)
510
            vars(i) = varname(1:9)
547
            vars(i) = varname(1:9)
511
            str     = trim(str)//trim(vars(i))
548
            str     = trim(str)//trim(vars(i))
512
         enddo
549
         enddo
513
         write(fid,'(a6,a9,a8,a6,100a10)') (trim(vars(i)),i=1,ncol)
550
         write(fid,'(a6,a9,a8,a6,100a10)') (trim(vars(i)),i=1,ncol)
514
         write(fid,'(a6,a9,a8,a6,100a10)') 
551
         write(fid,'(a6,a9,a8,a6,100a10)') 
515
     >              '------','---------','--------','------',
552
     >              '------','---------','--------','------',
516
     >              ('----------',i=5,ncol)
553
     >              ('----------',i=5,ncol)
517
 
554
 
518
c     Write fortran mode (mode=3)
555
c     Write fortran mode (mode=3)
519
      elseif (mode.eq.3) then
556
      elseif (mode.eq.3) then
520
         write(fid) ntra,ntim,ncol
557
         write(fid) ntra,ntim,ncol
521
         write(fid) time
558
         write(fid) time
522
         write(fid) vars
559
         write(fid) vars
523
 
560
 
524
c     Write IVE netcdf format (mode=4)
561
c     Write IVE netcdf format (mode=4)
525
      elseif (mode.eq.4) then
562
      elseif (mode.eq.4) then
526
         vardim(1)=ntra
563
         vardim(1)=ntra
527
         vardim(2)=1
564
         vardim(2)=1
528
         vardim(3)=1
565
         vardim(3)=1
529
         vardim(4)=1
566
         vardim(4)=1
530
         mdv      =-999.98999
567
         mdv      =-999.98999
531
         do i=2,ncol
568
         do i=2,ncol
532
            call putdef(fid,vars(i),4,mdv,vardim,
569
            call putdef(fid,vars(i),4,mdv,vardim,
533
     >                  varmin,varmax,stag,ierr)
570
     >                  varmin,varmax,stag,ierr)
534
         enddo
571
         enddo
535
         varname='BASEDATE'
572
         varname='BASEDATE'
536
         vardim(1)=6
573
         vardim(1)=6
537
         call putdef(fid,varname,4,mdv,vardim,
574
         call putdef(fid,varname,4,mdv,vardim,
538
     >               varmin,varmax,stag,ierr)
575
     >               varmin,varmax,stag,ierr)
539
         do i=1,6
576
         do i=1,6
540
            rtime(i)=real(time(i))
577
            rtime(i)=real(time(i))
541
         enddo
578
         enddo
542
         call putdat(fid,varname,0.,0,rtime,ierr)
579
         call putdat(fid,varname,0.,0,rtime,ierr)
543
 
580
 
544
c     Write KML format (mode=5)
581
c     Write KML format (mode=5)
545
      elseif (mode.eq.5) then
582
      elseif (mode.eq.5) then
546
 
583
 
547
      write(fid,"(A)") '<?xml version="1.0" encoding="UTF-8"?>'
584
      write(fid,"(A)") '<?xml version="1.0" encoding="UTF-8"?>'
548
      write(fid,"(A)") '<kml xmlns="http://www.opengis.net/kml/2.2">'
585
      write(fid,"(A)") '<kml xmlns="http://www.opengis.net/kml/2.2">'
549
      write(fid,"(A)") '<Document>'
586
      write(fid,"(A)") '<Document>'
550
      write(fid,"(A)") '<name>Paths</name>'
587
      write(fid,"(A)") '<name>Paths</name>'
551
      write(fid,"(A)") '<Style id="yellowLineGreenPoly">'
588
      write(fid,"(A)") '<Style id="yellowLineGreenPoly">'
552
      write(fid,"(A)") '<LineStyle>'
589
      write(fid,"(A)") '<LineStyle>'
553
c      write(fid,*) '<color>7f00ffff</color>'    ! Yellow
590
c      write(fid,*) '<color>7f00ffff</color>'    ! Yellow
554
      write(fid,"(A)") '<color>500A0A0A</color>'     ! Black
591
      write(fid,"(A)") '<color>500A0A0A</color>'     ! Black
555
      write(fid,"(A)") '<width>4</width>'
592
      write(fid,"(A)") '<width>4</width>'
556
      write(fid,"(A)") '</LineStyle>'
593
      write(fid,"(A)") '</LineStyle>'
557
      write(fid,"(A)") '<PolyStyle>'
594
      write(fid,"(A)") '<PolyStyle>'
558
      write(fid,"(A)") '<color>7f00ff00</color>'
595
      write(fid,"(A)") '<color>7f00ff00</color>'
559
      write(fid,"(A)") '</PolyStyle>'
596
      write(fid,"(A)") '</PolyStyle>'
560
      write(fid,"(A)") '</Style>'
597
      write(fid,"(A)") '</Style>'
-
 
598
      
-
 
599
c     Write header for ASCII mode iwth real pressure      
-
 
600
      elseif ( mode.eq.6 ) then
-
 
601
 
-
 
602
c        Get the strings for output
-
 
603
         write(str1,'(i4)') time(1)
-
 
604
         write(str2,'(i2)') time(2)
-
 
605
         write(str3,'(i2)') time(3)
-
 
606
         write(str4,'(i2)') time(4)
-
 
607
         write(str5,'(i2)') time(5)
-
 
608
         if (time(2).eq. 0) str2(1:1)='0'
-
 
609
         if (time(3).eq. 0) str3(1:1)='0'
-
 
610
         if (time(4).eq. 0) str4(1:1)='0'
-
 
611
         if (time(5).eq. 0) str5(1:1)='0'
-
 
612
         if (time(2).lt.10) str2(1:1)='0'
-
 
613
         if (time(3).lt.10) str3(1:1)='0'
-
 
614
         if (time(4).lt.10) str4(1:1)='0'
-
 
615
         if (time(5).lt.10) str5(1:1)='0'
-
 
616
 
-
 
617
c        Write the time specification
-
 
618
         write(fid,'(a15,a4,a2,a2,a1,a2,a2,a13,i8,a4)') 
-
 
619
     >          'Reference date ',
-
 
620
     >           str1,str2,str3,'_',str4,str5,
-
 
621
     >          ' / Time range',time(6), ' min'
-
 
622
         write(fid,*)
-
 
623
 
-
 
624
c        Write variable names
-
 
625
         str=''
-
 
626
         do i=1,ncol
-
 
627
            varname = vars(i)
-
 
628
            vars(i) = varname(1:9)
-
 
629
            str     = trim(str)//trim(vars(i))
-
 
630
         enddo
-
 
631
         write(fid,'(a6,a9,a8,a8,100a10)') (trim(vars(i)),i=1,ncol)
-
 
632
         write(fid,'(a6,a9,a8,a8,100a10)') 
-
 
633
     >              '------','---------','--------','--------',
-
 
634
     >              ('----------',i=5,ncol)
561
 
635
 
562
      endif
636
      endif
563
 
637
 
564
      end
638
      end
565
      
639
      
566
      
640
      
567
c     ----------------------------------------------------------------
641
c     ----------------------------------------------------------------
568
c     Close a trajectory file
642
c     Close a trajectory file
569
c     ----------------------------------------------------------------
643
c     ----------------------------------------------------------------
570
      
644
      
571
      subroutine close_tra(fid,mode)
645
      subroutine close_tra(fid,mode)
572
 
646
 
573
      implicit none
647
      implicit none
574
      
648
      
575
c     Declaration of subroutine parameters
649
c     Declaration of subroutine parameters
576
      integer      fid
650
      integer      fid
577
      integer      mode
651
      integer      mode
578
      
652
      
579
c     Auxiliary variables
653
c     Auxiliary variables
580
      integer      ierr
654
      integer      ierr
581
 
655
 
582
c     Close file
656
c     Close file
583
      if (mode.eq.1) then
657
      if (mode.eq.1) then
584
         close(abs(fid))
658
         close(abs(fid))
585
 
659
 
586
      elseif (mode.eq.2) then
660
      elseif (mode.eq.2) then
587
         close(abs(fid))
661
         close(abs(fid))
588
 
662
 
589
      elseif (mode.eq.3) then
663
      elseif (mode.eq.3) then
590
         close(fid)
664
         close(fid)
591
 
665
 
592
      elseif (mode.eq.4) then
666
      elseif (mode.eq.4) then
593
         call clscdf(fid,ierr)
667
         call clscdf(fid,ierr)
594
 
668
 
595
      elseif (mode.eq.5) then
669
      elseif (mode.eq.5) then
596
          write(fid,"(A)") '</Document>'
670
          write(fid,"(A)") '</Document>'
597
          write(fid,"(A)") '</kml>'
671
          write(fid,"(A)") '</kml>'
598
         close(abs(fid))
672
         close(abs(fid))
-
 
673
         
-
 
674
      elseif (mode.eq.6) then
-
 
675
         close(abs(fid))
-
 
676
         
599
      endif
677
      endif
600
 
678
 
601
      end
679
      end
602
      
680
      
603
 
681
 
604
c     ----------------------------------------------------------------
682
c     ----------------------------------------------------------------
605
c     Determine the mode of a trajectory file
683
c     Determine the mode of a trajectory file
606
c     ----------------------------------------------------------------
684
c     ----------------------------------------------------------------
607
 
685
 
608
      subroutine mode_tra(mode,filename)
686
      subroutine mode_tra(mode,filename)
609
      
687
      
610
      implicit none
688
      implicit none
611
 
689
 
612
c     Declaration of subroutine parameters
690
c     Declaration of subroutine parameters
613
      integer        mode
691
      integer        mode
614
      character*80   filename
692
      character*80   filename
615
 
693
 
616
c     Auxiliary variables
694
c     Auxiliary variables
617
      integer        len
695
      integer        len
618
      character      char0,char1,char2,char3,char4
696
      character      char0,char1,char2,char3,char4
619
 
697
 
620
c     Get mode
698
c     Get mode
621
      mode=-1
699
      mode=-1
622
      
700
      
623
      len  = len_trim(filename)
701
      len  = len_trim(filename)
624
 
702
 
625
c     Mode specified by number
703
c     Mode specified by number
626
      char0 = filename((len-1):(len-1))
704
      char0 = filename((len-1):(len-1))
627
      char1 = filename(len:len)
705
      char1 = filename(len:len)
628
 
706
 
629
      if ( (char0.eq.'.').and.(char1.eq.'1') ) mode=1
707
      if ( (char0.eq.'.').and.(char1.eq.'1') ) mode=1
630
      if ( (char0.eq.'.').and.(char1.eq.'2') ) mode=2
708
      if ( (char0.eq.'.').and.(char1.eq.'2') ) mode=2
631
      if ( (char0.eq.'.').and.(char1.eq.'3') ) mode=3
709
      if ( (char0.eq.'.').and.(char1.eq.'3') ) mode=3
632
      if ( (char0.eq.'.').and.(char1.eq.'4') ) mode=4
710
      if ( (char0.eq.'.').and.(char1.eq.'4') ) mode=4
633
      if ( (char0.eq.'.').and.(char1.eq.'5') ) mode=5
711
      if ( (char0.eq.'.').and.(char1.eq.'5') ) mode=5
-
 
712
      if ( (char0.eq.'.').and.(char1.eq.'6') ) mode=6
634
 
713
 
635
      if ( mode.gt.0 ) return
714
      if ( mode.gt.0 ) return
636
 
715
 
637
c     Mode specified by appendix
716
c     Mode specified by appendix
638
      char0 = filename((len-3):(len-3))
717
      char0 = filename((len-3):(len-3))
639
      char1 = filename((len-2):(len-2))
718
      char1 = filename((len-2):(len-2))
640
      char2 = filename((len-1):(len-1))
719
      char2 = filename((len-1):(len-1))
641
      char3 = filename(len:len)
720
      char3 = filename(len:len)
642
      if ( (char1.eq.'.').and.(char2.eq.'l').and.(char3.eq.'s') ) mode=1
721
      if ( (char1.eq.'.').and.(char2.eq.'l').and.(char3.eq.'s') ) mode=1
643
      if ( (char1.eq.'.').and.(char2.eq.'t').and.(char3.eq.'i') ) mode=2
722
      if ( (char1.eq.'.').and.(char2.eq.'t').and.(char3.eq.'i') ) mode=2
644
      if ( (char1.eq.'.').and.(char2.eq.'d').and.(char3.eq.'u') ) mode=3
723
      if ( (char1.eq.'.').and.(char2.eq.'d').and.(char3.eq.'u') ) mode=3
645
      if ( (char1.eq.'.').and.(char2.eq.'n').and.(char3.eq.'c') ) mode=4
724
      if ( (char1.eq.'.').and.(char2.eq.'n').and.(char3.eq.'c') ) mode=4
646
 
725
 
647
      if ( (char0.eq.'.').and.(char1.eq.'k').and.
726
      if ( (char0.eq.'.').and.(char1.eq.'k').and.
648
     >                        (char2.eq.'m').and.
727
     >                        (char2.eq.'m').and.
649
     >                        (char3.eq.'l') ) mode = 5
728
     >                        (char3.eq.'l') ) mode = 5
650
 
729
 
-
 
730
      if ( (char1.eq.'.').and.(char2.eq.'r').and.(char3.eq.'p') ) mode=6
-
 
731
 
651
      end
732
      end
652
 
733
 
653
 
734
 
654
c     ----------------------------------------------------------------
735
c     ----------------------------------------------------------------
655
c     Get dimension of a trajectory file
736
c     Get dimension of a trajectory file
656
c     ----------------------------------------------------------------
737
c     ----------------------------------------------------------------
657
    
738
    
658
      subroutine info_tra(filename,ntra,ntim,ncol,mode)
739
      subroutine info_tra(filename,ntra,ntim,ncol,mode)
659
 
740
 
660
      implicit none
741
      implicit none
661
      
742
      
662
c     Declaration of subroutine parameters
743
c     Declaration of subroutine parameters
663
      integer      fid
744
      integer      fid
664
      character*80 filename
745
      character*80 filename
665
      integer      mode
746
      integer      mode
666
      integer      ntra,ntim,ncol
747
      integer      ntra,ntim,ncol
667
 
748
 
668
c     Auxiliary variables
749
c     Auxiliary variables
669
      integer       vardim(4)
750
      integer       vardim(4)
670
      real          varmin(4),varmax(4),stag(4)
751
      real          varmin(4),varmax(4),stag(4)
671
      real          mdv
752
      real          mdv
672
      character*80  cfn
753
      character*80  cfn
673
      integer       ierr
754
      integer       ierr
674
      integer       i,ndim
755
      integer       i,ndim
675
      integer       nvars
756
      integer       nvars
676
      integer       ntimes
757
      integer       ntimes
677
      real          times(100)
758
      real          times(100)
678
      character*500 str
759
      character*500 str
679
      integer       nline0,nline1,nline2
760
      integer       nline0,nline1,nline2
680
      integer       isstr,isok
761
      integer       isstr,isok
681
      character     ch
762
      character     ch
682
      character*80  vars(200)
763
      character*80  vars(200)
683
      integer       ios
764
      integer       ios
684
 
765
 
685
c     Open file
766
c     Open file
686
      if (mode.eq.1) then
767
      if (mode.eq.1) then
687
         fid=10
768
         fid=10
688
         open(fid,file=filename)
769
         open(fid,file=filename)
689
      elseif (mode.eq.2) then
770
      elseif (mode.eq.2) then
690
         fid=10
771
         fid=10
691
         open(fid,file=filename)
772
         open(fid,file=filename)
692
      elseif (mode.eq.3) then
773
      elseif (mode.eq.3) then
693
         fid=10
774
         fid=10
694
         open(fid,file=filename,form='unformatted')
775
         open(fid,file=filename,form='unformatted')
695
      elseif (mode.eq.4) then
776
      elseif (mode.eq.4) then
696
         call cdfopn(filename,fid,ierr)
777
         call cdfopn(filename,fid,ierr)
-
 
778
      elseif (mode.eq.6) then
-
 
779
         fid=10
-
 
780
         open(fid,file=filename)
697
      endif
781
      endif
698
 
782
 
699
c     Get dimension information
783
c     Get dimension information
700
      if ( (mode.eq.1).or.(mode.eq.2) ) then
784
      if ( (mode.eq.1).or.(mode.eq.2).or.(mode.eq.6) ) then
701
         read(fid,*)
785
         read(fid,*)
702
         read(fid,*)
786
         read(fid,*)
703
         read(fid,'(a500)') str
787
         read(fid,'(a500)') str
704
         read(fid,*)
788
         read(fid,*)
705
 
789
 
706
c        Get the number of columns
790
c        Get the number of columns
707
         isstr=0
791
         isstr=0
708
         ncol =0
792
         ncol =0
709
         do i=1,500
793
         do i=1,500
710
            ch = str(i:i)
794
            ch = str(i:i)
711
            if ( (isstr.eq.0).and.(ch.ne.' ') ) then
795
            if ( (isstr.eq.0).and.(ch.ne.' ') ) then
712
               isstr=1
796
               isstr=1
713
            elseif ( (isstr.eq.1).and.(ch.eq.' ') ) then
797
            elseif ( (isstr.eq.1).and.(ch.eq.' ') ) then
714
               isstr=0
798
               isstr=0
715
               ncol=ncol+1
799
               ncol=ncol+1
716
            endif
800
            endif
717
         enddo
801
         enddo
718
 
802
 
719
c        Init the dimensions for empty trajectory files
803
c        Init the dimensions for empty trajectory files
720
         ntra = 0
804
         ntra = 0
721
         ntim = 0
805
         ntim = 0
722
 
806
 
723
c        Get the first data block
807
c        Get the first data block
724
         nline0  = 5
808
         nline0  = 5
725
         nline1  = 5
809
         nline1  = 5
726
         read(fid,*,end=140,iostat=ios)
810
         read(fid,*,end=140,iostat=ios)
727
 100     read(fid,'(a500)',end=110,iostat=ios) str
811
 100     read(fid,'(a500)',end=110,iostat=ios) str
728
         if (str.ne.'') then
812
         if (str.ne.'') then
729
            nline1 = nline1 + 1
813
            nline1 = nline1 + 1
730
            goto 100
814
            goto 100
731
         endif
815
         endif
732
 110     continue
816
 110     continue
733
         
817
         
734
c        Get the total numbers of lines in the data block
818
c        Get the total numbers of lines in the data block
735
         nline2 = nline1
819
         nline2 = nline1
736
         if ( ios.eq.0 ) then
820
         if ( ios.eq.0 ) then
737
 120        read(fid,*,end=130)
821
 120        read(fid,*,end=130)
738
            nline2 = nline2 + 1
822
            nline2 = nline2 + 1
739
            goto 120
823
            goto 120
740
 130        nline2 = nline2 + 1
824
 130        nline2 = nline2 + 1
741
         endif
825
         endif
742
 
826
 
743
c        Set the dimensions
827
c        Set the dimensions
744
         if (mode.eq.1) then
828
         if (mode.eq.1) then
745
            ntim = nline1 - nline0
829
            ntim = nline1 - nline0
746
            ntra = (nline2-nline0+1)/(ntim+1)
830
            ntra = (nline2-nline0+1)/(ntim+1)
747
         else
831
         else
748
            ntra = nline1 - nline0
832
            ntra = nline1 - nline0
749
            ntim = (nline2-nline0+1)/(ntra+1)
833
            ntim = (nline2-nline0+1)/(ntra+1)
750
         endif
834
         endif
751
 
835
 
752
      elseif (mode.eq.3) then
836
      elseif (mode.eq.3) then
753
         read(fid) ntra,ntim,ncol
837
         read(fid) ntra,ntim,ncol
754
 
838
 
755
      elseif (mode.eq.4) then
839
      elseif (mode.eq.4) then
756
         call gettimes(fid,times,ntimes,ierr)
840
         call gettimes(fid,times,ntimes,ierr)
757
         call getvars(fid,nvars,vars,ierr)
841
         call getvars(fid,nvars,vars,ierr)
758
         call getdef(fid,trim(vars(2)),ndim,mdv,vardim,
842
         call getdef(fid,trim(vars(2)),ndim,mdv,vardim,
759
     >               varmin,varmax,stag,ierr)
843
     >               varmin,varmax,stag,ierr)
760
         ntra = vardim(1)
844
         ntra = vardim(1)
761
         ntim = ntimes
845
         ntim = ntimes
762
         ncol = nvars-1
846
         ncol = nvars-1
763
 
847
 
764
      endif
848
      endif
765
 
849
 
766
c     Close file
850
c     Close file
767
 140  continue
851
 140  continue
768
      if (mode.eq.1) then
852
      if (mode.eq.1) then
769
         close(fid)
853
         close(fid)
770
      elseif (mode.eq.2) then
854
      elseif (mode.eq.2) then
771
         close(fid)
855
         close(fid)
772
      elseif (mode.eq.3) then
856
      elseif (mode.eq.3) then
773
         close(fid)
857
         close(fid)
774
      elseif (mode.eq.4) then
858
      elseif (mode.eq.4) then
775
         call clscdf(fid,ierr)
859
         call clscdf(fid,ierr)
776
      endif
860
      endif
777
 
861
 
778
      end
862
      end
779
     
863
     
780
 
864
 
781
c     ----------------------------------------------------------------
865
c     ----------------------------------------------------------------
782
c     Binary search algorithm
866
c     Binary search algorithm
783
c     ----------------------------------------------------------------
867
c     ----------------------------------------------------------------
784
 
868
 
785
      subroutine binary (z,p,ref_z,ref_p)
869
      subroutine binary (z,p,ref_z,ref_p)
786
 
870
 
787
      implicit none
871
      implicit none
788
 
872
 
789
c     Declaration of subroutine parameters
873
c     Declaration of subroutine parameters
790
      real   z
874
      real   z
791
      real   p
875
      real   p
792
      real   ref_z(3000)
876
      real   ref_z(3000)
793
      real   ref_p(3000)
877
      real   ref_p(3000)
794
 
878
 
795
c     Auxiliary variables
879
c     Auxiliary variables
796
      integer i0,i1,im
880
      integer i0,i1,im
797
 
881
 
798
c     Binary search
882
c     Binary search
799
      i0 = 1
883
      i0 = 1
800
      i1 = 3000
884
      i1 = 3000
801
 100  continue
885
 100  continue
802
        im = (i0 + i1) / 2
886
        im = (i0 + i1) / 2
803
        if ( p.lt.ref_p(im) ) then
887
        if ( p.lt.ref_p(im) ) then
804
           i0 = im
888
           i0 = im
805
        else 
889
        else 
806
           i1 = im
890
           i1 = im
807
        endif
891
        endif
808
      if ( (i1-i0).gt.1 ) goto 100
892
      if ( (i1-i0).gt.1 ) goto 100
809
 
893
 
810
c     Linear interpolation in between
894
c     Linear interpolation in between
811
      z = ref_z(i0) + ( p - ref_p(i0) ) / ( ref_p(i1) - ref_p(i0) ) *
895
      z = ref_z(i0) + ( p - ref_p(i0) ) / ( ref_p(i1) - ref_p(i0) ) *
812
     >                ( ref_z(i1) - ref_z(i0) ) 
896
     >                ( ref_z(i1) - ref_z(i0) ) 
813
 
897
 
814
      end
898
      end
815
 
899
 
816
 
900
 
817
 
901
 
818
 
902
 
819
 
903