Subversion Repositories lagranto.wrf

Rev

Details | Last modification | View Log | RSS feed

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