Subversion Repositories lagranto.um

Rev

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

Rev 3 Rev 4
1
      PROGRAM trainfo
1
      PROGRAM trainfo
2
      
2
      
3
c     ***********************************************************************
3
c     ***********************************************************************
4
c     * Get infos for a trajectory file                                     *
4
c     * Get infos for a trajectory file                                     *
5
c     * Michael Sprenger / Spring, summer 2010                              *
5
c     * Michael Sprenger / Spring, summer 2010                              *
6
c     ***********************************************************************
6
c     ***********************************************************************
7
 
7
 
8
      implicit none
8
      implicit none
9
      
9
      
10
c     ----------------------------------------------------------------------
10
c     ----------------------------------------------------------------------
11
c     Declaration of variables
11
c     Declaration of variables
12
c     ----------------------------------------------------------------------
12
c     ----------------------------------------------------------------------
13
 
13
 
14
c     Input file
14
c     Input file
15
      character*80                           inpfile     ! Input filename
15
      character*80                           inpfile     ! Input filename
16
      character*80                           mode        ! Mode
16
      character*80                           mode        ! Mode
17
 
17
 
18
c     Trajectories
18
c     Trajectories
19
      integer                                ntra        ! Number of trajectories
19
      integer                                ntra        ! Number of trajectories
20
      integer                                ntim        ! Number of times
20
      integer                                ntim        ! Number of times
21
      integer                                ncol        ! Number of columns
21
      integer                                ncol        ! Number of columns
22
      character*80                           vars(100)   ! Variable names
22
      character*80                           vars(100)   ! Variable names
23
      integer                                refdate(6)  ! Reference date
23
      integer                                refdate(6)  ! Reference date
24
      real,allocatable, dimension (:,:,:) :: tra         ! Trajectories (ntra,ntim,ncol)
24
      real,allocatable, dimension (:,:,:) :: tra         ! Trajectories (ntra,ntim,ncol)
25
 
25
 
26
c     Auxiliary variables
26
c     Auxiliary variables
27
      integer                                inpmode
27
      integer                                inpmode
28
      integer                                stat
28
      integer                                stat
29
      integer                                fid
29
      integer                                fid
30
      integer                                i,j,n
30
      integer                                i,j,n
31
      integer                                old(5)
31
      integer                                old(5)
32
      integer                                new(5)
32
      integer                                new(5)
33
      integer                                hour,min
33
      integer                                hour,min
34
      character*20                           datestr
34
      character*20                           datestr
35
      character*120                          str
35
      character*120                          str
36
      character*4                            str1
36
      character*4                            str1
37
      character*2                            str2,str3,str4,str5,str6
37
      character*2                            str2,str3,str4,str5,str6
38
 
38
 
39
c     ----------------------------------------------------------------------
39
c     ----------------------------------------------------------------------
40
c     Do the reformating
40
c     Do the reformating
41
c     ----------------------------------------------------------------------
41
c     ----------------------------------------------------------------------
42
 
42
 
43
c     Read parameters
43
c     Read parameters
44
      open(10,file='trainfo.param')
44
      open(10,file='trainfo.param')
45
       read(10,*) inpfile
45
       read(10,*) inpfile
46
       read(10,*) mode
46
       read(10,*) mode
47
      close(10)
47
      close(10)
48
      
48
      
49
c     Determine the formats
49
c     Determine the formats
50
      call mode_tra(inpmode,inpfile)
50
      call mode_tra(inpmode,inpfile)
51
      if (inpmode.eq.-1) inpmode=1
51
      if (inpmode.eq.-1) inpmode=1
52
 
52
 
53
c     Get the dimension of the trajectory file
53
c     Get the dimension of the trajectory file
54
      call info_tra(inpfile,ntra,ntim,ncol,inpmode)
54
      call info_tra(inpfile,ntra,ntim,ncol,inpmode)
55
 
55
 
56
c     Get haeder information
56
c     Get haeder information
57
      call ropen_tra(fid,inpfile,ntra,ntim,ncol,refdate,vars,inpmode)
57
      call ropen_tra(fid,inpfile,ntra,ntim,ncol,refdate,vars,inpmode)
58
      call close_tra(fid,inpmode)
58
      call close_tra(fid,inpmode)
59
 
59
 
60
c     Write dimensions
60
c     Write dimensions
61
      if ( (mode.eq.'dim').or.(mode.eq.'all') ) then
61
      if ( (mode.eq.'dim').or.(mode.eq.'all') ) then
62
         print*,ntra,ntim,ncol
62
         print*,ntra,ntim,ncol
63
      endif
63
      endif
64
 
64
 
65
c     Write single dimensions
65
c     Write single dimensions
66
      if ( (mode.eq.'ntra').or.(mode.eq.'all') ) then
66
      if ( (mode.eq.'ntra').or.(mode.eq.'all') ) then
67
         print*,ntra
67
         print*,ntra
68
      endif
68
      endif
69
      if ( (mode.eq.'ntim').or.(mode.eq.'all') ) then
69
      if ( (mode.eq.'ntim').or.(mode.eq.'all') ) then
70
         print*,ntim
70
         print*,ntim
71
      endif
71
      endif
72
      if ( (mode.eq.'ncol').or.(mode.eq.'all') ) then
72
      if ( (mode.eq.'ncol').or.(mode.eq.'all') ) then
73
         print*,ncol
73
         print*,ncol
74
      endif
74
      endif
75
 
75
 
76
c     Write variable names
76
c     Write variable names
77
      if ( (mode.eq.'vars').or.(mode.eq.'all') ) then
77
      if ( (mode.eq.'vars').or.(mode.eq.'all') ) then
78
         print*,(trim(vars(i))//' ',i=1,ncol)         
78
         print*,(trim(vars(i))//' ',i=1,ncol)         
79
      endif
79
      endif
80
 
80
 
81
c     Write reference date 
81
c     Write reference date 
82
      if ( (mode.eq.'refdate').or.(mode.eq.'all') ) then
82
      if ( (mode.eq.'refdate').or.(mode.eq.'all') ) then
83
         
83
         
84
c        Concatenate date string
84
c        Concatenate date string
85
         min = refdate(5)         
85
         min = refdate(5)         
86
         call datestring(datestr,
86
         call datestring(datestr,
87
     >             refdate(1),refdate(2),refdate(3),refdate(4) )
87
     >             refdate(1),refdate(2),refdate(3),refdate(4) )
88
         if ( min.eq.0 ) then
88
         if ( min.eq.0 ) then
89
            datestr = trim(datestr)//'00'
89
            datestr = trim(datestr)//'00'
90
         elseif (min.lt.10) then
90
         elseif (min.lt.10) then
91
            datestr = trim(datestr)//'0'//char(ichar('0')+min)
91
            datestr = trim(datestr)//'0'//char(ichar('0')+min)
92
         else
92
         else
93
            datestr = trim(datestr)//
93
            datestr = trim(datestr)//
94
     >                char(ichar('0')+int(min/10))//
94
     >                char(ichar('0')+int(min/10))//
95
     >                char(ichar('0')+mod(min,10))
95
     >                char(ichar('0')+mod(min,10))
96
         endif
96
         endif
97
                    
97
                    
98
c        Write date string
98
c        Write date string
99
         print*,trim(datestr)
99
         print*,trim(datestr)
100
 
100
 
101
      endif
101
      endif
102
 
102
 
103
c     Load all trajectory times if necessary
103
c     Load all trajectory times if necessary
104
      if ( (mode.eq.'all'      ).or.
104
      if ( (mode.eq.'all'      ).or.
105
     >     (mode.eq.'times'    ).or.
105
     >     (mode.eq.'times'    ).or.
106
     >     (mode.eq.'startdate').or.
106
     >     (mode.eq.'startdate').or.
107
     >     (mode.eq.'enddate'  ) )
107
     >     (mode.eq.'enddate'  ) )
108
     >then
108
     >then
109
         allocate(tra(ntra,ntim,ncol),stat=stat)
109
         allocate(tra(ntra,ntim,ncol),stat=stat)
110
         call ropen_tra(fid,inpfile,ntra,ntim,ncol,refdate,vars,inpmode)
110
         call ropen_tra(fid,inpfile,ntra,ntim,ncol,refdate,vars,inpmode)
111
         call read_tra (fid,tra,ntra,ntim,ncol,inpmode)
111
         call read_tra (fid,tra,ntra,ntim,ncol,inpmode)
112
         call close_tra(fid,inpmode)
112
         call close_tra(fid,inpmode)
113
      endif
113
      endif
114
 
114
 
115
c     Write list of all times
115
c     Write list of all times
116
      if ( (mode.eq.'times').or.(mode.eq.'all') ) then
116
      if ( (mode.eq.'times').or.(mode.eq.'all') ) then
117
         write(*,'(100f8.2)') (tra(1,i,1),i=1,ntim)
117
         write(*,'(100f8.2)') (tra(1,i,1),i=1,ntim)
118
      endif
118
      endif
119
 
119
 
120
c     Write time range
120
c     Write time range
121
      if ( (mode.eq.'timerange').or.(mode.eq.'all') ) then
121
      if ( (mode.eq.'timerange').or.(mode.eq.'all') ) then
122
         write(*,'(i6)') refdate(6)
122
         write(*,'(i6)') refdate(6)
123
      endif
123
      endif
124
      
124
      
125
c     Write firstdate (reference date + first time)
125
c     Write firstdate (reference date + first time)
126
      if ( (mode.eq.'startdate').or.(mode.eq.'all') ) then
126
      if ( (mode.eq.'startdate').or.(mode.eq.'all') ) then
127
         
127
         
128
c        Set the time shift of first time relative to reference date
128
c        Set the time shift of first time relative to reference date
129
         hour = int(tra(1,1,1))
129
         hour = int(tra(1,1,1))
130
         min  = mod(nint(100.*tra(1,1,1)),100) + refdate(5)
130
         min  = mod(nint(100.*tra(1,1,1)),100) + refdate(5)
131
         if (min.gt.60) then
131
         if (min.gt.60) then
132
            min  = min - 60
132
            min  = min - 60
133
            hour = hour + 1
133
            hour = hour + 1
134
         endif
134
         endif
135
         if (min.lt.0) then
135
         if (min.lt.0) then
136
            min  = min + 60
136
            min  = min + 60
137
            hour = hour - 1
137
            hour = hour - 1
138
         endif
138
         endif
139
         if (min.lt.0) then
139
         if (min.lt.0) then
140
            min  = min + 60
140
            min  = min + 60
141
            hour = hour - 1
141
            hour = hour - 1
142
         endif
142
         endif
143
 
143
 
144
c        Get new date (hours and minutes)
144
c        Get new date (hours and minutes)
145
         old(1) = refdate(1)
145
         old(1) = refdate(1)
146
         old(2) = refdate(2)
146
         old(2) = refdate(2)
147
         old(3) = refdate(3)
147
         old(3) = refdate(3)
148
         old(4) = refdate(4)
148
         old(4) = refdate(4)
149
         old(5) = 0
149
         old(5) = 0
150
         call newdate(old,real(hour),new)
150
         call newdate(old,real(hour),new)
151
 
151
 
152
c        Concatenate the date string
152
c        Concatenate the date string
153
         call datestring(datestr,
153
         call datestring(datestr,
154
     >             new(1),new(2),new(3),new(4) )
154
     >             new(1),new(2),new(3),new(4) )
155
         if ( min.eq.0 ) then
155
         if ( min.eq.0 ) then
156
            datestr = trim(datestr)//'00'
156
            datestr = trim(datestr)//'00'
157
         elseif (min.lt.10) then
157
         elseif (min.lt.10) then
158
            datestr = trim(datestr)//'0'//char(ichar('0')+min)
158
            datestr = trim(datestr)//'0'//char(ichar('0')+min)
159
         else
159
         else
160
            datestr = trim(datestr)//
160
            datestr = trim(datestr)//
161
     >                char(ichar('0')+int(min/10))//
161
     >                char(ichar('0')+int(min/10))//
162
     >                char(ichar('0')+mod(min,10))
162
     >                char(ichar('0')+mod(min,10))
163
         endif
163
         endif
164
                    
164
                    
165
c        Write date string
165
c        Write date string
166
         print*,trim(datestr)
166
         print*,trim(datestr)
167
 
167
 
168
      endif
168
      endif
169
 
169
 
170
c     Write enddate (reference date + last time)
170
c     Write enddate (reference date + last time)
171
      if ( (mode.eq.'enddate').or.(mode.eq.'all') ) then
171
      if ( (mode.eq.'enddate').or.(mode.eq.'all') ) then
172
         
172
         
173
c        Set the time shift of first time relative to reference date
173
c        Set the time shift of first time relative to reference date
174
         hour = int(tra(1,ntim,1))
174
         hour = int(tra(1,ntim,1))
175
         min  = mod(nint(100.*tra(1,ntim,1)),100) + refdate(5)
175
         min  = mod(nint(100.*tra(1,ntim,1)),100) + refdate(5)
176
         if (min.gt.60) then
176
         if (min.gt.60) then
177
            min  = min - 60
177
            min  = min - 60
178
            hour = hour + 1
178
            hour = hour + 1
179
         endif
179
         endif
180
         if (min.lt.0) then
180
         if (min.lt.0) then
181
            min  = min + 60
181
            min  = min + 60
182
            hour = hour - 1
182
            hour = hour - 1
183
         endif
183
         endif
184
         if (min.lt.0) then
184
         if (min.lt.0) then
185
            min  = min + 60
185
            min  = min + 60
186
            hour = hour - 1
186
            hour = hour - 1
187
         endif
187
         endif
188
 
188
 
189
c        Get new date (hours and minutes)
189
c        Get new date (hours and minutes)
190
         old(1) = refdate(1)
190
         old(1) = refdate(1)
191
         old(2) = refdate(2)
191
         old(2) = refdate(2)
192
         old(3) = refdate(3)
192
         old(3) = refdate(3)
193
         old(4) = refdate(4)
193
         old(4) = refdate(4)
194
         old(5) = 0
194
         old(5) = 0
195
         call newdate(old,real(hour),new)
195
         call newdate(old,real(hour),new)
196
 
196
 
197
c        Concatenate the date string
197
c        Concatenate the date string
198
         call datestring(datestr,
198
         call datestring(datestr,
199
     >             new(1),new(2),new(3),new(4) )
199
     >             new(1),new(2),new(3),new(4) )
200
         if ( min.eq.0 ) then
200
         if ( min.eq.0 ) then
201
            datestr = trim(datestr)//'00'
201
            datestr = trim(datestr)//'00'
202
         elseif (min.lt.10) then
202
         elseif (min.lt.10) then
203
            datestr = trim(datestr)//'0'//char(ichar('0')+min)
203
            datestr = trim(datestr)//'0'//char(ichar('0')+min)
204
         else
204
         else
205
            datestr = trim(datestr)//
205
            datestr = trim(datestr)//
206
     >                char(ichar('0')+int(min/10))//
206
     >                char(ichar('0')+int(min/10))//
207
     >                char(ichar('0')+mod(min,10))
207
     >                char(ichar('0')+mod(min,10))
208
         endif
208
         endif
209
                    
209
                    
210
c        Write date string
210
c        Write date string
211
         print*,trim(datestr)
211
         print*,trim(datestr)
212
 
212
 
213
      endif
213
      endif
214
 
214
 
215
c     Write trajectories to screen
215
c     Write trajectories to screen
216
      if ( (mode.eq.'list') ) then
216
      if ( (mode.eq.'list') ) then
217
 
217
 
218
c        Read the complete trajectory file
218
c        Read the complete trajectory file
219
         allocate(tra(ntra,ntim,ncol),stat=stat)
219
         allocate(tra(ntra,ntim,ncol),stat=stat)
220
         call ropen_tra(fid,inpfile,ntra,ntim,ncol,refdate,vars,inpmode)
220
         call ropen_tra(fid,inpfile,ntra,ntim,ncol,refdate,vars,inpmode)
221
         call read_tra (fid,tra,ntra,ntim,ncol,inpmode)
221
         call read_tra (fid,tra,ntra,ntim,ncol,inpmode)
222
         call close_tra(fid,inpmode)
222
         call close_tra(fid,inpmode)
223
 
223
 
224
c        Get the strings for output
224
c        Get the strings for output
225
         write(str1,'(i4)') refdate(1)
225
         write(str1,'(i4)') refdate(1)
226
         write(str2,'(i2)') refdate(2)
226
         write(str2,'(i2)') refdate(2)
227
         write(str3,'(i2)') refdate(3)
227
         write(str3,'(i2)') refdate(3)
228
         write(str4,'(i2)') refdate(4)
228
         write(str4,'(i2)') refdate(4)
229
         write(str5,'(i2)') refdate(5)
229
         write(str5,'(i2)') refdate(5)
230
         if (refdate(2).eq. 0) str2(1:1)='0'
230
         if (refdate(2).eq. 0) str2(1:1)='0'
231
         if (refdate(3).eq. 0) str3(1:1)='0'
231
         if (refdate(3).eq. 0) str3(1:1)='0'
232
         if (refdate(4).eq. 0) str4(1:1)='0'
232
         if (refdate(4).eq. 0) str4(1:1)='0'
233
         if (refdate(5).eq. 0) str5(1:1)='0'
233
         if (refdate(5).eq. 0) str5(1:1)='0'
234
         if (refdate(2).lt.10) str2(1:1)='0'
234
         if (refdate(2).lt.10) str2(1:1)='0'
235
         if (refdate(3).lt.10) str3(1:1)='0'
235
         if (refdate(3).lt.10) str3(1:1)='0'
236
         if (refdate(4).lt.10) str4(1:1)='0'
236
         if (refdate(4).lt.10) str4(1:1)='0'
237
         if (refdate(5).lt.10) str5(1:1)='0'
237
         if (refdate(5).lt.10) str5(1:1)='0'
238
 
238
 
239
c        Write the time specification
239
c        Write the time specification
240
         write(*,'(a15,a4,a2,a2,a1,a2,a2,a13,i8,a4)') 
240
         write(*,'(a15,a4,a2,a2,a1,a2,a2,a13,i8,a4)') 
241
     >          'Reference date ',
241
     >          'Reference date ',
242
     >           str1,str2,str3,'_',str4,str5,
242
     >           str1,str2,str3,'_',str4,str5,
243
     >          ' / Time range',refdate(6), ' min'
243
     >          ' / Time range',refdate(6), ' min'
244
         write(*,*)
244
         write(*,*)
245
 
245
 
246
c        Write variable names
246
c        Write variable names
247
         str=''
247
         str=''
248
         do i=1,ncol
248
         do i=1,ncol
249
            str=trim(str)//trim(vars(i))
249
            str=trim(str)//trim(vars(i))
250
         enddo
250
         enddo
251
         write(*,'(a6,a9,a8,a6,100a10)') (trim(vars(i)),i=1,ncol)
251
         write(*,'(a6,a9,a8,a6,100a10)') (trim(vars(i)),i=1,ncol)
252
         write(*,'(a6,a9,a8,a6,100a10)') 
252
         write(*,'(a6,a9,a8,a6,100a10)') 
253
     >              '------','---------','--------','------',
253
     >              '------','---------','--------','------',
254
     >              ('----------',i=5,ncol)
254
     >              ('----------',i=5,ncol)
255
 
255
 
256
         do n=1,ntra
256
         do n=1,ntra
257
            write(*,*)
257
            write(*,*)
258
            do i=1,ntim
258
            do i=1,ntim
259
               write(*,'(1f7.2,f9.2,f8.2,i6,100f10.3)') 
259
               write(*,'(1f7.2,f9.2,f8.2,i6,100f10.3)') 
260
     >               (tra(n,i,j),j=1,3),             ! time, lon, lat
260
     >               (tra(n,i,j),j=1,3),             ! time, lon, lat
261
     >               nint(tra(n,i,4)),               ! p
261
     >               nint(tra(n,i,4)),               ! p
262
     >               (tra(n,i,j),j=5,ncol)           ! fields
262
     >               (tra(n,i,j),j=5,ncol)           ! fields
263
            enddo
263
            enddo
264
         enddo
264
         enddo
265
 
265
 
266
      endif
266
      endif
267
         
267
         
268
 
268
 
269
      end
269
      end
270
 
270
 
271
 
271
 
272
      
272
      
273
 
273
 
274
      
274