Subversion Repositories lagranto.icon

Rev

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

Rev 3 Rev 5
1
      PROGRAM density
1
      PROGRAM density
2
 
2
 
3
      use netcdf
3
      use netcdf
4
 
4
 
5
      implicit none
5
      implicit none
6
 
6
 
7
c     ---------------------------------------------------------------------
7
c     ---------------------------------------------------------------------
8
c     Declaration of variables
8
c     Declaration of variables
9
c     ---------------------------------------------------------------------
9
c     ---------------------------------------------------------------------
10
      
10
      
11
c     Parameter and working arrays
11
c     Parameter and working arrays
12
      real                                    radius
12
      real                                    radius
13
      character*80                            runit
13
      character*80                            runit
14
      integer                                 nx,ny
14
      integer                                 nx,ny
15
      integer                                 nlonlat
15
      integer                                 nlonlat
16
      real                                    dlonlat
16
      real                                    dlonlat
17
      real                                    xmin,ymin,dx,dy
17
      real                                    xmin,ymin,dx,dy
18
      real                                    clon,clat
18
      real                                    clon,clat
19
      integer                                 ntime,nfield,ntra
19
      integer                                 ntime,nfield,ntra
20
      character*80                            inpfile
20
      character*80                            inpfile
21
      character*80                            outfile
21
      character*80                            outfile
22
      character*80                            mode
22
      character*80                            mode
23
      real                                    param
23
      real                                    param
24
      integer                                 opts,npts
24
      integer                                 opts,npts
25
      integer                                 step
25
      integer                                 step
26
      character*80                            gridtype
26
      character*80                            gridtype
27
      character*80                            field
27
      character*80                            field
28
      integer                                 crefile,crevar
28
      integer                                 crefile,crevar
29
      real                                    pollon,pollat,polgam
29
      real                                    pollon,pollat,polgam
30
      real,allocatable,    dimension (:,:) :: cnt,res,fld,area
30
      real,allocatable,    dimension (:,:) :: cnt,res,fld,area
31
      real,allocatable,    dimension (:)   :: traj
31
      real,allocatable,    dimension (:)   :: traj
32
      real,allocatable,    dimension (:)   :: olon,olat,otim,ofld
32
      real,allocatable,    dimension (:)   :: olon,olat,otim,ofld
33
      real,allocatable,    dimension (:)   :: nlon,nlat,ntim,nfld
33
      real,allocatable,    dimension (:)   :: nlon,nlat,ntim,nfld
34
 
34
 
35
c     Output format
35
c     Output format
36
      character*80                            outformat
36
      character*80                            outformat
37
 
37
 
38
c     Physical and mathematical constants
38
c     Physical and mathematical constants
39
      real                                    pi180
39
      real                                    pi180
40
      parameter                               (pi180=3.14159/180.)
40
      parameter                               (pi180=3.14159/180.)
41
      real                                    deltay
41
      real                                    deltay
42
      parameter                               (deltay=111.)
42
      parameter                               (deltay=111.)
43
      real                                    eps
43
      real                                    eps
44
      parameter                               (eps=0.001)
44
      parameter                               (eps=0.001)
45
 
45
 
46
c     Input trajectories (see iotra.f)
46
c     Input trajectories (see iotra.f)
47
      integer                                 inpmode
47
      integer                                 inpmode
48
      real,allocatable, dimension (:,:,:) ::  trainp     
48
      real,allocatable, dimension (:,:,:) ::  trainp     
49
      integer                                 reftime(6)      
49
      integer                                 reftime(6)      
50
      character*80                            varsinp(100)   
50
      character*80                            varsinp(100)   
51
      integer,allocatable, dimension (:) ::   sel_flag
51
      integer,allocatable, dimension (:) ::   sel_flag
52
      character*80                            sel_file
52
      character*80                            sel_file
53
      character*80                            sel_format
53
      character*80                            sel_format
54
 
54
 
55
c     Auxiliary variables
55
c     Auxiliary variables
56
      character*80                            cdfname,varname
56
      character*80                            cdfname,varname
57
      integer                                 i,j,k
57
      integer                                 i,j,k
58
      integer                                 stat
58
      integer                                 stat
59
      integer,allocatable, dimension (:,:) :: connect0
59
      integer,allocatable, dimension (:,:) :: connect0
60
      integer                                 connectval0
60
      integer                                 connectval0
61
      integer,allocatable, dimension (:,:) :: connect1
61
      integer,allocatable, dimension (:,:) :: connect1
62
      integer                                 connectval1
62
      integer                                 connectval1
63
      integer,allocatable, dimension (:,:) :: connect2
63
      integer,allocatable, dimension (:,:) :: connect2
64
      integer                                 connectval2
64
      integer                                 connectval2
65
      real                                    slat
65
      real                                    slat
66
      integer                                 ipre
66
      integer                                 ipre
67
      real                                    addvalue
67
      real                                    addvalue
68
      real                                    xmax,ymax
68
      real                                    xmax,ymax
69
      real ,allocatable, dimension (:)  ::    odist,ndist
69
      real ,allocatable, dimension (:)  ::    odist,ndist
70
      real                                    dt
70
      real                                    dt
71
      integer                                 fid
71
      integer                                 fid
72
      integer                                 dynamic_grid
72
      integer                                 dynamic_grid
73
      real                                    ycen,xcen
73
      real                                    ycen,xcen
74
      integer                                 indx,indy
74
      integer                                 indx,indy
75
      character*80                            unit
75
      character*80                            unit
76
      real                                    rlon0,rlat0,rlon,rlat
76
      real                                    rlon0,rlat0,rlon,rlat
77
      real                                    lon,lat
77
      real                                    lon,lat
78
      real                                    crot
78
      real                                    crot
79
      integer                                 count
79
      integer                                 count
80
      character*80                            longname, varunit
80
      character*80                            longname, varunit
81
      real                                    time
81
      real                                    time
82
      integer                                 ind
82
      integer                                 ind
83
      integer                                 ifield
83
      integer                                 ifield
84
      real                                    hhmm,frac
84
      real                                    hhmm,frac
85
      integer                                 ierr,ncID
85
      integer                                 ierr,ncID
86
      integer                                 rotflag
86
      integer                                 rotflag
87
 
87
 
88
c     External functions
88
c     External functions
89
      real         lmstolm,lmtolms
89
      real         lmstolm,lmtolms
90
      real         phstoph,phtophs
90
      real         phstoph,phtophs
91
      external     lmstolm,lmtolms,phstoph,phtophs
91
      external     lmstolm,lmtolms,phstoph,phtophs
92
      
92
      
93
      real         sdis
93
      real         sdis
94
      external     sdis
94
      external     sdis
95
 
95
 
96
c     ---------------------------------------------------------------------
96
c     ---------------------------------------------------------------------
97
c     Preparations
97
c     Preparations
98
c     ---------------------------------------------------------------------
98
c     ---------------------------------------------------------------------
99
 
99
 
100
c     Write start message
100
c     Write start message
101
      print*,'========================================================='
101
      print*,'========================================================='
102
      print*,'              *** START OF PROGRAM DENSITY ***'
102
      print*,'              *** START OF PROGRAM DENSITY ***'
103
      print*
103
      print*
104
 
104
 
105
c     Read input parameters
105
c     Read input parameters
106
      open(10,file='density.param')
106
      open(10,file='density.param')
107
       read(10,*) inpfile
107
       read(10,*) inpfile
108
       read(10,*) outfile
108
       read(10,*) outfile
109
       read(10,*) field
109
       read(10,*) field
110
       read(10,*) ntime,nfield,ntra
110
       read(10,*) ntime,nfield,ntra
111
       read(10,*) gridtype
111
       read(10,*) gridtype
112
       if ( gridtype.eq.'latlon' ) then 
112
       if ( gridtype.eq.'latlon' ) then 
113
          read(10,*) nx,ny,xmin,ymin,dx,dy
113
          read(10,*) nx,ny,xmin,ymin,dx,dy
114
       elseif ( gridtype.eq.'centered') then
114
       elseif ( gridtype.eq.'centered') then
115
          read(10,*) clon,clat,nlonlat,dlonlat
115
          read(10,*) clon,clat,nlonlat,dlonlat
116
       else
116
       else
117
          print*,' ERROR: unsupported grid type ',trim(gridtype)
117
          print*,' ERROR: unsupported grid type ',trim(gridtype)
118
          stop
118
          stop
119
       endif
119
       endif
120
       read(10,*) radius,runit
120
       read(10,*) radius,runit
121
       read(10,*) mode
121
       read(10,*) mode
122
       read(10,*) param
122
       read(10,*) param
123
       read(10,*) step
123
       read(10,*) step
124
       read(10,*) sel_file
124
       read(10,*) sel_file
125
       read(10,*) sel_format
125
       read(10,*) sel_format
126
       read(10,*) crefile
126
       read(10,*) crefile
127
       read(10,*) crevar
127
       read(10,*) crevar
128
       read(10,*) pollon,pollat
128
       read(10,*) pollon,pollat
129
      close(10)
129
      close(10)
130
 
130
 
131
c	  Set the flag for trajectory rotation
131
c	  Set the flag for trajectory rotation
132
      if ( abs(pollat-90.).gt.eps ) then
132
      if ( abs(pollat-90.).gt.eps ) then
133
          rotflag = 1
133
          rotflag = 1
134
      else
134
      else
135
          rotflag = 0
135
          rotflag = 0
136
      endif
136
      endif
137
 
137
 
138
c     Get the grid parameters if <crefile=0>
138
c     Get the grid parameters if <crefile=0>
139
      if ( crefile.eq.0 ) then
139
      if ( crefile.eq.0 ) then
140
 
140
 
141
           ierr = nf90_open  (trim(outfile), NF90_NOWRITE  , ncID)
141
           ierr = nf90_open  (trim(outfile), NF90_NOWRITE  , ncID)
142
 
142
 
143
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'grid'   ,gridtype ) 
143
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'grid'   ,gridtype ) 
144
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'clon'   ,clon     )
144
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'clon'   ,clon     )
145
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'clat'   ,clat     )
145
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'clat'   ,clat     )
146
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'nlonlat',nlonlat  )
146
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'nlonlat',nlonlat  )
147
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'dlonlat',dlonlat  )
147
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'dlonlat',dlonlat  )
148
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'nx'     ,nx       )
148
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'nx'     ,nx       )
149
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'ny'     ,ny       )
149
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'ny'     ,ny       )
150
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'dx'     ,dx       )
150
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'dx'     ,dx       )
151
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'dy'     ,dy       )
151
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'dy'     ,dy       )
152
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'xmin'   ,xmin     )
152
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'xmin'   ,xmin     )
153
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'ymin'   ,ymin     )
153
           ierr = nf90_get_att(ncID, NF90_GLOBAL, 'ymin'   ,ymin     )
154
 
154
 
155
           ierr = nf90_close(ncID)
155
           ierr = nf90_close(ncID)
156
 
156
 
157
           print*,'**** GRID PARAMETERS IMPORTED ',
157
           print*,'**** GRID PARAMETERS IMPORTED ',
158
     >            'FROM NETCDF FILE!!!! ****'
158
     >            'FROM NETCDF FILE!!!! ****'
159
           print*
159
           print*
160
           
160
           
161
      endif
161
      endif
162
 
162
 
163
c     Check for consistency
163
c     Check for consistency
164
      if ( (step.ne.0).and.(mode.ne.'keep') ) then
164
      if ( (step.ne.0).and.(mode.ne.'keep') ) then
165
         print*," ERROR: interpolation is only possible for all",
165
         print*," ERROR: interpolation is only possible for all",
166
     >                   ' time steps... Stop'
166
     >                   ' time steps... Stop'
167
         stop
167
         stop
168
      endif
168
      endif
169
 
169
 
170
c     Set the number of times (just code aesthetics)
170
c     Set the number of times (just code aesthetics)
171
      opts=ntime
171
      opts=ntime
172
 
172
 
173
c     Set grid parameters for centered grid
173
c     Set grid parameters for centered grid
174
      if ( gridtype.eq.'centered' ) then
174
      if ( gridtype.eq.'centered' ) then
175
         nx   = nlonlat
175
         nx   = nlonlat
176
         ny   = nlonlat
176
         ny   = nlonlat
177
         dx   = dlonlat
177
         dx   = dlonlat
178
         dy   = dlonlat
178
         dy   = dlonlat
179
         xmin = - real(nlonlat-1)/2. * dx
179
         xmin = - real(nlonlat-1)/2. * dx
180
         xmax = + real(nlonlat-1)/2. * dx
180
         xmax = + real(nlonlat-1)/2. * dx
181
         ymin = - real(nlonlat-1)/2. * dy
181
         ymin = - real(nlonlat-1)/2. * dy
182
         ymax = + real(nlonlat-1)/2. * dy
182
         ymax = + real(nlonlat-1)/2. * dy
183
      endif
183
      endif
184
      
184
      
185
c     Set the flag for dynamic grid adjustment
185
c     Set the flag for dynamic grid adjustment
186
      if ( (nx.eq.0).or.(ny.eq.0) ) then
186
      if ( (nx.eq.0).or.(ny.eq.0) ) then
187
         dynamic_grid = 1
187
         dynamic_grid = 1
188
      else
188
      else
189
         dynamic_grid = 0
189
         dynamic_grid = 0
190
      endif
190
      endif
191
 
191
 
192
c     Print status information
192
c     Print status information
193
      print*,'---- INPUT PARAMETERS -----------------------------------'
193
      print*,'---- INPUT PARAMETERS -----------------------------------'
194
      print* 
194
      print* 
195
      print*,'Input                : ',trim(inpfile)
195
      print*,'Input                : ',trim(inpfile)
196
      print*,'Output               : ',trim(outfile)
196
      print*,'Output               : ',trim(outfile)
197
      print*,'Field                : ',trim(field)
197
      print*,'Field                : ',trim(field)
198
      print*,'Trajectory           : ',ntime,nfield,ntra
198
      print*,'Trajectory           : ',ntime,nfield,ntra
199
      print*,'Grid type            : ',trim(gridtype)
199
      print*,'Grid type            : ',trim(gridtype)
200
      if ( dynamic_grid.eq.1 ) then
200
      if ( dynamic_grid.eq.1 ) then
201
         print*,'Grid                 : dynamic (see below)'
201
         print*,'Grid                 : dynamic (see below)'
202
      elseif ( gridtype.eq.'latlon' ) then
202
      elseif ( gridtype.eq.'latlon' ) then
203
         print*,'Grid   nlon,nlat     : ',nx,ny
203
         print*,'Grid   nlon,nlat     : ',nx,ny
204
         print*,'       lonmin,latmin : ',xmin,ymin
204
         print*,'       lonmin,latmin : ',xmin,ymin
205
         print*,'       dlon,dlat     : ',dx,dy
205
         print*,'       dlon,dlat     : ',dx,dy
206
      elseif ( gridtype.eq.'centered' ) then
206
      elseif ( gridtype.eq.'centered' ) then
207
         print*,'Grid   clon,clat     : ',clon,clat
207
         print*,'Grid   clon,clat     : ',clon,clat
208
         print*,'       nlonlat       : ',nlonlat
208
         print*,'       nlonlat       : ',nlonlat
209
         print*,'       dlonlat       : ',dlonlat
209
         print*,'       dlonlat       : ',dlonlat
210
      endif
210
      endif
211
      if ( rotflag.eq.0 ) then
211
      if ( rotflag.eq.0 ) then
212
          print*,'Pole lon/lat         : ',pollon,pollat
212
          print*,'Pole lon/lat         : ',pollon,pollat
213
      else
213
      else
214
          print*,'Pole lon/lat         : ',pollon,pollat,' (ROTATION)'
214
          print*,'Pole lon/lat         : ',pollon,pollat,' (ROTATION)'
215
      endif
215
      endif
216
      print*,'Filter radius        : ',radius,' ',trim(runit)
216
      print*,'Filter radius        : ',radius,' ',trim(runit)
217
      print*,'Mode                 : ',trim(mode)
217
      print*,'Mode                 : ',trim(mode)
218
      if ( ( mode.eq.'time'  ).or.
218
      if ( ( mode.eq.'time'  ).or.
219
     >     ( mode.eq.'space' ).or.
219
     >     ( mode.eq.'space' ).or.
220
     >     ( mode.eq.'grid' ) )
220
     >     ( mode.eq.'grid' ) )
221
     >then
221
     >then
222
         print*,'Parameter            : ',param
222
         print*,'Parameter            : ',param
223
      endif
223
      endif
224
      if ( step.eq.0 ) then
224
      if ( step.eq.0 ) then
225
         print*,'Time step            : all'
225
         print*,'Time step            : all'
226
      elseif (step.gt.0) then
226
      elseif (step.gt.0) then
227
         print*,'Time step            : ',step
227
         print*,'Time step            : ',step
228
      endif
228
      endif
229
      print*,'Selection file       : ',trim(sel_file)
229
      print*,'Selection file       : ',trim(sel_file)
230
      print*,'Selection format     : ',trim(sel_file)
230
      print*,'Selection format     : ',trim(sel_file)
231
      print*,'Flag <crefile>       : ',crefile
231
      print*,'Flag <crefile>       : ',crefile
232
      print*,'Flag <crevar>        : ',crevar
232
      print*,'Flag <crevar>        : ',crevar
233
 
233
 
234
c     Check whether mode is valid
234
c     Check whether mode is valid
235
      if ((mode.ne.'keep'  ).and.
235
      if ((mode.ne.'keep'  ).and.
236
     >    (mode.ne.'time'  ).and.
236
     >    (mode.ne.'time'  ).and.
237
     >    (mode.ne.'space' ).and.
237
     >    (mode.ne.'space' ).and.
238
     >    (mode.ne.'grid'  ))  
238
     >    (mode.ne.'grid'  ))  
239
     >then
239
     >then
240
         print*,' ERROR: Invalid mode ',trim(mode)
240
         print*,' ERROR: Invalid mode ',trim(mode)
241
         stop
241
         stop
242
      endif
242
      endif
243
 
243
 
244
c     Allocate memory for old and new (reparameterised) trajectory
244
c     Allocate memory for old and new (reparameterised) trajectory
245
      allocate(olon(ntime),stat=stat)
245
      allocate(olon(ntime),stat=stat)
246
      if (stat.ne.0) print*,'*** error allocating array olon ***'
246
      if (stat.ne.0) print*,'*** error allocating array olon ***'
247
      allocate(olat(ntime),stat=stat)
247
      allocate(olat(ntime),stat=stat)
248
      if (stat.ne.0) print*,'*** error allocating array olat ***'
248
      if (stat.ne.0) print*,'*** error allocating array olat ***'
249
      allocate(otim(ntime),stat=stat)
249
      allocate(otim(ntime),stat=stat)
250
      if (stat.ne.0) print*,'*** error allocating array otim ***'
250
      if (stat.ne.0) print*,'*** error allocating array otim ***'
251
      allocate(nlon(1000*ntime),stat=stat)
251
      allocate(nlon(1000*ntime),stat=stat)
252
      if (stat.ne.0) print*,'*** error allocating array nlon ***'
252
      if (stat.ne.0) print*,'*** error allocating array nlon ***'
253
      allocate(nlat(1000*ntime),stat=stat)
253
      allocate(nlat(1000*ntime),stat=stat)
254
      if (stat.ne.0) print*,'*** error allocating array nlat ***'
254
      if (stat.ne.0) print*,'*** error allocating array nlat ***'
255
      allocate(ntim(1000*ntime),stat=stat)
255
      allocate(ntim(1000*ntime),stat=stat)
256
      if (stat.ne.0) print*,'*** error allocating array ntim ***'
256
      if (stat.ne.0) print*,'*** error allocating array ntim ***'
257
      allocate(odist(ntime),stat=stat)
257
      allocate(odist(ntime),stat=stat)
258
      if (stat.ne.0) print*,'*** error allocating array odist ***'
258
      if (stat.ne.0) print*,'*** error allocating array odist ***'
259
      allocate(ndist(1000*ntime),stat=stat)
259
      allocate(ndist(1000*ntime),stat=stat)
260
      if (stat.ne.0) print*,'*** error allocating array ndist ***'
260
      if (stat.ne.0) print*,'*** error allocating array ndist ***'
261
      allocate(ofld(ntime),stat=stat)
261
      allocate(ofld(ntime),stat=stat)
262
      if (stat.ne.0) print*,'*** error allocating array ofld ***'
262
      if (stat.ne.0) print*,'*** error allocating array ofld ***'
263
      allocate(nfld(1000*ntime),stat=stat)
263
      allocate(nfld(1000*ntime),stat=stat)
264
      if (stat.ne.0) print*,'*** error allocating array nfld ***'
264
      if (stat.ne.0) print*,'*** error allocating array nfld ***'
265
 
265
 
266
c     Allocate memory for complete trajectory set
266
c     Allocate memory for complete trajectory set
267
      allocate(trainp(ntra,ntime,nfield),stat=stat)
267
      allocate(trainp(ntra,ntime,nfield),stat=stat)
268
      if (stat.ne.0) print*,'*** error allocating array trainp ***'
268
      if (stat.ne.0) print*,'*** error allocating array trainp ***'
269
      allocate(sel_flag(ntra),stat=stat)
269
      allocate(sel_flag(ntra),stat=stat)
270
      if (stat.ne.0) print*,'*** error allocating array sel_flag ***'
270
      if (stat.ne.0) print*,'*** error allocating array sel_flag ***'
271
 
271
 
272
c     Allocate memory for auxiliary fields
272
c     Allocate memory for auxiliary fields
273
      allocate(traj(nfield),stat=stat)
273
      allocate(traj(nfield),stat=stat)
274
      if (stat.ne.0) print*,'*** error allocating array traj ***'
274
      if (stat.ne.0) print*,'*** error allocating array traj ***'
275
 
275
 
276
c     Set the format of the input file
276
c     Set the format of the input file
277
      call mode_tra(inpmode,inpfile)
277
      call mode_tra(inpmode,inpfile)
278
      if (inpmode.eq.-1) inpmode=1
278
      if (inpmode.eq.-1) inpmode=1
279
 
279
 
280
c     Read the input trajectory file
280
c     Read the input trajectory file
281
      call ropen_tra(fid,inpfile,ntra,ntime,nfield,
281
      call ropen_tra(fid,inpfile,ntra,ntime,nfield,
282
     >                   reftime,varsinp,inpmode)
282
     >                   reftime,varsinp,inpmode)
283
      call read_tra (fid,trainp,ntra,ntime,nfield,inpmode)
283
      call read_tra (fid,trainp,ntra,ntime,nfield,inpmode)
284
      call close_tra(fid,inpmode)
284
      call close_tra(fid,inpmode)
285
 
285
 
286
c     Check that first four columns correspond to time,lon,lat,p
286
c     Check that first four columns correspond to time,lon,lat,p
287
      if ( (varsinp(1).ne.'time' ).or.
287
      if ( (varsinp(1).ne.'time' ).or.
288
     >     (varsinp(2).ne.'xpos' ).and.(varsinp(2).ne.'lon' ).or.
288
     >     (varsinp(2).ne.'xpos' ).and.(varsinp(2).ne.'lon' ).or.
289
     >     (varsinp(3).ne.'ypos' ).and.(varsinp(3).ne.'lat' ).or.
289
     >     (varsinp(3).ne.'ypos' ).and.(varsinp(3).ne.'lat' ).or.
290
     >     (varsinp(4).ne.'zpos' ).and.(varsinp(4).ne.'z'   ) )
290
     >     (varsinp(4).ne.'zpos' ).and.(varsinp(4).ne.'z'   ) )
291
     >then
291
     >then
292
         print*,' ERROR: problem with input trajectories ...'
292
         print*,' ERROR: problem with input trajectories ...'
293
         stop
293
         stop
294
      endif
294
      endif
295
      varsinp(1) = 'TIME'
295
      varsinp(1) = 'TIME'
296
      varsinp(2) = 'lon'
296
      varsinp(2) = 'lon'
297
      varsinp(3) = 'lat'
297
      varsinp(3) = 'lat'
298
      varsinp(4) = 'z'
298
      varsinp(4) = 'z'
299
 
299
 
300
c     Get the index of the field (if needed)
300
c     Get the index of the field (if needed)
301
      if ( field.ne.'nil' ) then
301
      if ( field.ne.'nil' ) then
302
         ifield = 0
302
         ifield = 0
303
         do i=1,nfield
303
         do i=1,nfield
304
            if ( varsinp(i).eq.field ) ifield = i
304
            if ( varsinp(i).eq.field ) ifield = i
305
         enddo
305
         enddo
306
         if ( ifield.eq.0 ) then
306
         if ( ifield.eq.0 ) then
307
            print*,' ERROR: field ',trim(field),' not found... Stop'
307
            print*,' ERROR: field ',trim(field),' not found... Stop'
308
            stop
308
            stop
309
         endif
309
         endif
310
      endif
310
      endif
311
 
311
 
312
c     Rotate coordinates - if pollat<>90
312
c     Rotate coordinates - if pollat<>90
313
      do i=1,ntra
313
      do i=1,ntra
314
        do j=1,ntime
314
        do j=1,ntime
315
 
315
 
316
            lon = trainp(i,j,2)
316
            lon = trainp(i,j,2)
317
            lat = trainp(i,j,3)
317
            lat = trainp(i,j,3)
318
 
318
 
319
            if ( rotflag.eq.1 ) then
319
            if ( rotflag.eq.1 ) then
320
               rlon = lmtolms(lat,lon,pollat,pollon)
320
               rlon = lmtolms(lat,lon,pollat,pollon)
321
               rlat = phtophs(lat,lon,pollat,pollon)
321
               rlat = phtophs(lat,lon,pollat,pollon)
322
            else
322
            else
323
               rlon = lon
323
               rlon = lon
324
               rlat = lat
324
               rlat = lat
325
            endif
325
            endif
326
 
326
 
327
            trainp(i,j,2) = rlon
327
            trainp(i,j,2) = rlon
328
            trainp(i,j,3) = rlat
328
            trainp(i,j,3) = rlat
329
 
329
 
330
        enddo
330
        enddo
331
      enddo
331
      enddo
332
 
332
 
333
c     Write some status information of the input trajectories
333
c     Write some status information of the input trajectories
334
      print*
334
      print*
335
      print*,'---- INPUT TRAJECTORIES ---------------------------------'
335
      print*,'---- INPUT TRAJECTORIES ---------------------------------'
336
      print*
336
      print*
337
      print*,' Reference time (year)  : ',reftime(1)
337
      print*,' Reference time (year)  : ',reftime(1)
338
      print*,'                (month) : ',reftime(2)
338
      print*,'                (month) : ',reftime(2)
339
      print*,'                (day)   : ',reftime(3)
339
      print*,'                (day)   : ',reftime(3)
340
      print*,'                (hour)  : ',reftime(4)
340
      print*,'                (hour)  : ',reftime(4)
341
      print*,'                (min)   : ',reftime(5)
341
      print*,'                (min)   : ',reftime(5)
342
      print*,' Time range (min)       : ',reftime(6)
342
      print*,' Time range (min)       : ',reftime(6)
343
      do i=1,nfield
343
      do i=1,nfield
344
         if ( i.ne.ifield ) then
344
         if ( i.ne.ifield ) then
345
            print*,' Var                    :',i,trim(varsinp(i))
345
            print*,' Var                    :',i,trim(varsinp(i))
346
         else
346
         else
347
            print*,' Var                    :',i,trim(varsinp(i)),
347
            print*,' Var                    :',i,trim(varsinp(i)),
348
     >                                        '       [ gridding ]'
348
     >                                        '       [ gridding ]'
349
         endif
349
         endif
350
      enddo
350
      enddo
351
      print*,' List of selected times'
351
      print*,' List of selected times'
352
      do i=1,ntime
352
      do i=1,ntime
353
         if ( (step.eq.0).or.(step.eq.i) ) then
353
         if ( (step.eq.0).or.(step.eq.i) ) then
354
            print*,'     ',i,'  -> ',trainp(1,i,1)
354
            print*,'     ',i,'  -> ',trainp(1,i,1)
355
         endif
355
         endif
356
      enddo
356
      enddo
357
      print*
357
      print*
358
 
358
 
359
c     Select flag: all trajectories are selected
359
c     Select flag: all trajectories are selected
360
      if ( sel_file.eq.'nil' ) then
360
      if ( sel_file.eq.'nil' ) then
361
 
361
 
362
         do i=1,ntra
362
         do i=1,ntra
363
            sel_flag(i) = 1
363
            sel_flag(i) = 1
364
         enddo
364
         enddo
365
 
365
 
366
c     Select flag: index file
366
c     Select flag: index file
367
      elseif ( sel_format.eq.'index' ) then
367
      elseif ( sel_format.eq.'index' ) then
368
 
368
 
369
         do i=1,ntra
369
         do i=1,ntra
370
            sel_flag(i) = 0
370
            sel_flag(i) = 0
371
         enddo
371
         enddo
372
         
372
         
373
         open(10,file=sel_file)
373
         open(10,file=sel_file)
374
 142      read(10,*,end=141) ind
374
 142      read(10,*,end=141) ind
375
          sel_flag(ind) = 1
375
          sel_flag(ind) = 1
376
          goto 142 
376
          goto 142 
377
 141     continue
377
 141     continue
378
         close(10)
378
         close(10)
379
 
379
 
380
c     Select flag: boolean file
380
c     Select flag: boolean file
381
      elseif ( sel_format.eq.'boolean' ) then
381
      elseif ( sel_format.eq.'boolean' ) then
382
       
382
       
383
         open(10,file=sel_file)
383
         open(10,file=sel_file)
384
          do i=1,ntra
384
          do i=1,ntra
385
            read(10,*) ind
385
            read(10,*) ind
386
            if ( ind.eq.1 ) sel_flag(i) = ind
386
            if ( ind.eq.1 ) sel_flag(i) = ind
387
          enddo
387
          enddo
388
         close(10)
388
         close(10)
389
         
389
         
390
      endif
390
      endif
391
 
391
 
392
c     Write status information
392
c     Write status information
393
      if ( sel_file.eq.'nil' ) then
393
      if ( sel_file.eq.'nil' ) then
394
          print*,' Selected trajectories  : all ',ntra          
394
          print*,' Selected trajectories  : all ',ntra          
395
       else
395
       else
396
          count = 0
396
          count = 0
397
          do i=1,ntra
397
          do i=1,ntra
398
             if ( sel_flag(i).eq.1 ) count = count + 1
398
             if ( sel_flag(i).eq.1 ) count = count + 1
399
          enddo
399
          enddo
400
          print*,' #selected trajectories : ',count,
400
          print*,' #selected trajectories : ',count,
401
     >            ' [ ',real(count)/real(ntra) * 100.,' % ] '
401
     >            ' [ ',real(count)/real(ntra) * 100.,' % ] '
402
       endif
402
       endif
403
       print*
403
       print*
404
 
404
 
405
c     ---------------------------------------------------------------------
405
c     ---------------------------------------------------------------------
406
c     Coordinate transformations and grid adjustment
406
c     Coordinate transformations and grid adjustment
407
c     ---------------------------------------------------------------------
407
c     ---------------------------------------------------------------------
408
 
408
 
409
c     Transform from lat/lon to rotated lat/lon, if requested
409
c     Transform from lat/lon to rotated lat/lon, if requested
410
      if ( gridtype.eq.'centered') then
410
      if ( gridtype.eq.'centered') then
411
 
411
 
412
         crot = 0.
412
         crot = 0.
413
 
413
 
414
         pollon=clon-180.
414
         pollon=clon-180.
415
         if (pollon.lt.-180.) pollon=pollon+360.
415
         if (pollon.lt.-180.) pollon=pollon+360.
416
         pollat=90.-clat
416
         pollat=90.-clat
417
         do i=1,ntra
417
         do i=1,ntra
418
            do j=1,ntime
418
            do j=1,ntime
419
               
419
               
420
               if ( sel_flag(i).eq.1 ) then
420
               if ( sel_flag(i).eq.1 ) then
421
 
421
 
422
c                Get lat/lon coordinates for trajectory point
422
c                Get lat/lon coordinates for trajectory point
423
                 lon = trainp(i,j,2)
423
                 lon = trainp(i,j,2)
424
                 lat = trainp(i,j,3)
424
                 lat = trainp(i,j,3)
425
 
425
 
426
c                First Rotation
426
c                First Rotation
427
                 pollon=clon-180.
427
                 pollon=clon-180.
428
                 if (pollon.lt.-180.) pollon=pollon+360.
428
                 if (pollon.lt.-180.) pollon=pollon+360.
429
                 pollat=90.-clat
429
                 pollat=90.-clat
430
                 rlon0=lmtolms(lat,lon,pollat,pollon)
430
                 rlon0=lmtolms(lat,lon,pollat,pollon)
431
                 rlat0=phtophs(lat,lon,pollat,pollon)            
431
                 rlat0=phtophs(lat,lon,pollat,pollon)            
432
 
432
 
433
c                Second rotation
433
c                Second rotation
434
                 pollon=-180.
434
                 pollon=-180.
435
                 pollat=90.+crot
435
                 pollat=90.+crot
436
                 rlon=90.+lmtolms(rlat0,rlon0-90.,pollat,pollon)
436
                 rlon=90.+lmtolms(rlat0,rlon0-90.,pollat,pollon)
437
                 rlat=phtophs(rlat0,rlon0-90.,pollat,pollon)   
437
                 rlat=phtophs(rlat0,rlon0-90.,pollat,pollon)   
438
 
438
 
439
c                Get rotated latitude and longitude
439
c                Get rotated latitude and longitude
440
 100             if (rlon.lt.xmin) then
440
 100             if (rlon.lt.xmin) then
441
                  rlon=rlon+360.
441
                  rlon=rlon+360.
442
                  goto 100
442
                  goto 100
443
                 endif
443
                 endif
444
 102             if (rlon.gt.(xmin+real(nx-1)*dx)) then
444
 102             if (rlon.gt.(xmin+real(nx-1)*dx)) then
445
                  rlon=rlon-360.
445
                  rlon=rlon-360.
446
                  goto 102
446
                  goto 102
447
                 endif
447
                 endif
448
 
448
 
449
c                Set the new trajectory coordinates
449
c                Set the new trajectory coordinates
450
                 trainp(i,j,2) = rlon
450
                 trainp(i,j,2) = rlon
451
                 trainp(i,j,3) = rlat
451
                 trainp(i,j,3) = rlat
452
 
452
 
453
              endif
453
              endif
454
 
454
 
455
            enddo
455
            enddo
456
         enddo
456
         enddo
457
            
457
            
458
      endif
458
      endif
459
 
459
 
460
c     Dynamic grid adjustment
460
c     Dynamic grid adjustment
461
      if ( dynamic_grid.eq.1 ) then
461
      if ( dynamic_grid.eq.1 ) then
462
 
462
 
463
c        Get the grid parameters
463
c        Get the grid parameters
464
         xmin =  180.
464
         xmin =  180.
465
         ymin =   90.
465
         ymin =   90.
466
         xmax = -180.
466
         xmax = -180.
467
         ymax =  -90.
467
         ymax =  -90.
468
 
468
 
469
         do i=1,ntra
469
         do i=1,ntra
470
 
470
 
471
            if ( sel_flag(i).eq.1 ) then
471
            if ( sel_flag(i).eq.1 ) then
472
 
472
 
473
              if ( step.eq.0 ) then
473
              if ( step.eq.0 ) then
474
               do j=1,ntime
474
               do j=1,ntime
475
                  if ( trainp(i,j,2).lt.xmin) xmin =  trainp(i,j,2)
475
                  if ( trainp(i,j,2).lt.xmin) xmin =  trainp(i,j,2)
476
                  if ( trainp(i,j,2).gt.xmax) xmax =  trainp(i,j,2)
476
                  if ( trainp(i,j,2).gt.xmax) xmax =  trainp(i,j,2)
477
                  if ( trainp(i,j,3).lt.ymin) ymin =  trainp(i,j,3)
477
                  if ( trainp(i,j,3).lt.ymin) ymin =  trainp(i,j,3)
478
                  if ( trainp(i,j,3).gt.ymax) ymax =  trainp(i,j,3)
478
                  if ( trainp(i,j,3).gt.ymax) ymax =  trainp(i,j,3)
479
               enddo
479
               enddo
480
              else
480
              else
481
                if ( trainp(i,step,2).lt.xmin) xmin =  trainp(i,step,2)
481
                if ( trainp(i,step,2).lt.xmin) xmin =  trainp(i,step,2)
482
                if ( trainp(i,step,2).gt.xmax) xmax =  trainp(i,step,2)
482
                if ( trainp(i,step,2).gt.xmax) xmax =  trainp(i,step,2)
483
                if ( trainp(i,step,3).lt.ymin) ymin =  trainp(i,step,3)
483
                if ( trainp(i,step,3).lt.ymin) ymin =  trainp(i,step,3)
484
                if ( trainp(i,step,3).gt.ymax) ymax =  trainp(i,step,3)
484
                if ( trainp(i,step,3).gt.ymax) ymax =  trainp(i,step,3)
485
              endif
485
              endif
486
            
486
            
487
            endif
487
            endif
488
 
488
 
489
         enddo
489
         enddo
490
 
490
 
491
c        Get first guess for "optimal" grid
491
c        Get first guess for "optimal" grid
492
         nx = 400
492
         nx = 400
493
         ny = 400
493
         ny = 400
494
         dx = (xmax - xmin)/real(nx-1)
494
         dx = (xmax - xmin)/real(nx-1)
495
         dy = (ymax - ymin)/real(ny-1)
495
         dy = (ymax - ymin)/real(ny-1)
496
 
496
 
497
c        Make the grid spacing equal in zonal and meridional direction
497
c        Make the grid spacing equal in zonal and meridional direction
498
         if ( dx.gt.dy ) then
498
         if ( dx.gt.dy ) then
499
            
499
            
500
            dy = dx
500
            dy = dx
501
            ny = (ymax - ymin)/dy + 1
501
            ny = (ymax - ymin)/dy + 1
502
            if (ny.lt.nx/2)              ny = nx / 2
502
            if (ny.lt.nx/2)              ny = nx / 2
503
            if ( real(ny)*dy .ge. 180. ) ny = 180./dy + 1
503
            if ( real(ny)*dy .ge. 180. ) ny = 180./dy + 1
504
            ycen = 0.5* (ymin+ymax)
504
            ycen = 0.5* (ymin+ymax)
505
            ymin = ycen - 0.5 * real(ny/2) * dy
505
            ymin = ycen - 0.5 * real(ny/2) * dy
506
            if (ymin.le.-90.) ymin = -90.
506
            if (ymin.le.-90.) ymin = -90.
507
 
507
 
508
         else
508
         else
509
               
509
               
510
            dx = dy
510
            dx = dy
511
            nx = (xmax - xmin)/dx + 1
511
            nx = (xmax - xmin)/dx + 1
512
            if (nx.lt.ny/2)              nx = ny / 2
512
            if (nx.lt.ny/2)              nx = ny / 2
513
            if ( real(nx)*dx .ge. 360. ) nx = 360./dx + 1
513
            if ( real(nx)*dx .ge. 360. ) nx = 360./dx + 1
514
            xcen = 0.5* (xmin+xmax)
514
            xcen = 0.5* (xmin+xmax)
515
            xmin = xcen - 0.5 * real(nx/2) * dx
515
            xmin = xcen - 0.5 * real(nx/2) * dx
516
            if (xmin.le.-180.) xmin = -180.
516
            if (xmin.le.-180.) xmin = -180.
517
 
517
 
518
         endif
518
         endif
519
            
519
            
520
c        Write information
520
c        Write information
521
         print*
521
         print*
522
         print*,'---- DYNAMIC GRID ADJUSTMENT',
522
         print*,'---- DYNAMIC GRID ADJUSTMENT',
523
     >          ' ----------------------------'  
523
     >          ' ----------------------------'  
524
         print*
524
         print*
525
         print*,'Grid   nlon,nlat     : ',nx,ny
525
         print*,'Grid   nlon,nlat     : ',nx,ny
526
         print*,'       lonmin,latmin : ',xmin,ymin
526
         print*,'       lonmin,latmin : ',xmin,ymin
527
         print*,'       dlon,dlat     : ',dx,dy
527
         print*,'       dlon,dlat     : ',dx,dy
528
         print*
528
         print*
529
 
529
 
530
c     Write grid information for rotated grid (if not already done
530
c     Write grid information for rotated grid (if not already done
531
      elseif ( gridtype.eq.'centered') then
531
      elseif ( gridtype.eq.'centered') then
532
         
532
         
533
         print*
533
         print*
534
         print*,'---- GRID PARAMETERS -------',
534
         print*,'---- GRID PARAMETERS -------',
535
     >          ' ----------------------------'  
535
     >          ' ----------------------------'  
536
         print*
536
         print*
537
         print*,'Grid   nlon,nlat     : ',nx,ny
537
         print*,'Grid   nlon,nlat     : ',nx,ny
538
         print*,'       lonmin,latmin : ',xmin,ymin
538
         print*,'       lonmin,latmin : ',xmin,ymin
539
         print*,'       dlon,dlat     : ',dx,dy
539
         print*,'       dlon,dlat     : ',dx,dy
540
         print*
540
         print*
541
       
541
       
542
 
542
 
543
      endif
543
      endif
544
 
544
 
545
c     Set the grid boundaries
545
c     Set the grid boundaries
546
      xmax=xmin+real(nx-1)*dx
546
      xmax=xmin+real(nx-1)*dx
547
      ymax=ymin+real(ny-1)*dy
547
      ymax=ymin+real(ny-1)*dy
548
 
548
 
549
c     Allocate memory for output array and auxiliary gridding array 
549
c     Allocate memory for output array and auxiliary gridding array 
550
      allocate(cnt(nx,ny),stat=stat)
550
      allocate(cnt(nx,ny),stat=stat)
551
      if (stat.ne.0) print*,'*** error allocating array cnt  ***'
551
      if (stat.ne.0) print*,'*** error allocating array cnt  ***'
552
      allocate(res(nx,ny),stat=stat)
552
      allocate(res(nx,ny),stat=stat)
553
      if (stat.ne.0) print*,'*** error allocating array res  ***'
553
      if (stat.ne.0) print*,'*** error allocating array res  ***'
554
      allocate(fld(nx,ny),stat=stat)
554
      allocate(fld(nx,ny),stat=stat)
555
      if (stat.ne.0) print*,'*** error allocating array fld  ***'
555
      if (stat.ne.0) print*,'*** error allocating array fld  ***'
556
      allocate(area(nx,ny),stat=stat)
556
      allocate(area(nx,ny),stat=stat)
557
      if (stat.ne.0) print*,'*** error allocating array area ***'
557
      if (stat.ne.0) print*,'*** error allocating array area ***'
558
 
558
 
559
      allocate(connect0(nx,ny),stat=stat)
559
      allocate(connect0(nx,ny),stat=stat)
560
      if (stat.ne.0) print*,'*** error allocating array connect0 ***'
560
      if (stat.ne.0) print*,'*** error allocating array connect0 ***'
561
      allocate(connect1(nx,ny),stat=stat)
561
      allocate(connect1(nx,ny),stat=stat)
562
      if (stat.ne.0) print*,'*** error allocating array connect1 ***'
562
      if (stat.ne.0) print*,'*** error allocating array connect1 ***'
563
      allocate(connect2(nx,ny),stat=stat)
563
      allocate(connect2(nx,ny),stat=stat)
564
      if (stat.ne.0) print*,'*** error allocating array connect2 ***'
564
      if (stat.ne.0) print*,'*** error allocating array connect2 ***'
565
 
565
 
566
 
566
 
567
c     Init the output array
567
c     Init the output array
568
      do i=1,nx
568
      do i=1,nx
569
         do j=1,ny
569
         do j=1,ny
570
            connect0(i,j) = 0
570
            connect0(i,j) = 0
571
            connect1(i,j) = 0
571
            connect1(i,j) = 0
572
            connect2(i,j) = 0
572
            connect2(i,j) = 0
573
            cnt(i,j)      = 0.
573
            cnt(i,j)      = 0.
574
            res(i,j)      = 0.
574
            res(i,j)      = 0.
575
            fld(i,j)      = 0.
575
            fld(i,j)      = 0.
576
         enddo
576
         enddo
577
      enddo  
577
      enddo  
578
 
578
 
579
c     ---------------------------------------------------------------------
579
c     ---------------------------------------------------------------------
580
c     Gridding
580
c     Gridding
581
c     ---------------------------------------------------------------------
581
c     ---------------------------------------------------------------------
582
 
582
 
583
c     Write some status information 
583
c     Write some status information 
584
      print*,'---- GRIDDING -------------------------------------------'
584
      print*,'---- GRIDDING -------------------------------------------'
585
      print*
585
      print*
586
 
586
 
587
c     Loop over all entries of sampling table
587
c     Loop over all entries of sampling table
588
      connectval0 = 0
588
      connectval0 = 0
589
      connectval1 = 0
589
      connectval1 = 0
590
      connectval2 = 0
590
      connectval2 = 0
591
      count       = 0
591
      count       = 0
592
 
592
 
593
      do i=1,ntra
593
      do i=1,ntra
594
 
594
 
595
         if (mod(i,100).eq.0) print*,i,' of ',ntra
595
         if (mod(i,100).eq.0) print*,i,' of ',ntra
596
 
596
 
597
c        Skip all trajectories which are not selected
597
c        Skip all trajectories which are not selected
598
         if ( sel_flag(i).eq.0 ) goto 300
598
         if ( sel_flag(i).eq.0 ) goto 300
599
 
599
 
600
c        ------- Read a complete trajectory ---------------------------
600
c        ------- Read a complete trajectory ---------------------------
601
         do j=1,ntime
601
         do j=1,ntime
602
            otim(j) = trainp(i,j,1)
602
            otim(j) = trainp(i,j,1)
603
            olon(j) = trainp(i,j,2)
603
            olon(j) = trainp(i,j,2)
604
            olat(j) = trainp(i,j,3)
604
            olat(j) = trainp(i,j,3)
605
            if ( field.ne.'nil' ) then
605
            if ( field.ne.'nil' ) then
606
               ofld(j) =trainp(i,j,ifield)
606
               ofld(j) =trainp(i,j,ifield)
607
            endif
607
            endif
608
         enddo
608
         enddo
609
 
609
 
610
c        -------- Convert hh.m time into fractional time --------------
610
c        -------- Convert hh.m time into fractional time --------------
611
         do j=1,ntime
611
         do j=1,ntime
612
            hhmm    = otim(j)
612
            hhmm    = otim(j)
613
            call hhmm2frac (hhmm,frac)
613
            call hhmm2frac (hhmm,frac)
614
            otim(j) = frac
614
            otim(j) = frac
615
         enddo
615
         enddo
616
 
616
 
617
c        -------- Interpolation ---------------------------------------
617
c        -------- Interpolation ---------------------------------------
618
 
618
 
619
c        Keep the trajectory points as they are
619
c        Keep the trajectory points as they are
620
         if ( ( mode.eq.'keep').and.(step.eq.0) ) then
620
         if ( ( mode.eq.'keep').and.(step.eq.0) ) then
621
            npts=opts
621
            npts=opts
622
            do j=1,opts
622
            do j=1,opts
623
               ntim(j)=otim(j)
623
               ntim(j)=otim(j)
624
               nlon(j)=olon(j)
624
               nlon(j)=olon(j)
625
               nlat(j)=olat(j)
625
               nlat(j)=olat(j)
626
               if ( field.ne.'nil' ) then
626
               if ( field.ne.'nil' ) then
627
                  nfld(j)=ofld(j)
627
                  nfld(j)=ofld(j)
628
               endif
628
               endif
629
            enddo
629
            enddo
630
 
630
 
631
c        Select a single time step
631
c        Select a single time step
632
         elseif ( ( mode.eq.'keep').and.(step.gt.0) ) then
632
         elseif ( ( mode.eq.'keep').and.(step.gt.0) ) then
633
            npts    = 1
633
            npts    = 1
634
            ntim(1) = otim(step)
634
            ntim(1) = otim(step)
635
            nlon(1) = olon(step)
635
            nlon(1) = olon(step)
636
            nlat(1) = olat(step)
636
            nlat(1) = olat(step)
637
            if ( field.ne.'nil' ) then
637
            if ( field.ne.'nil' ) then
638
               nfld(1) = ofld(step)
638
               nfld(1) = ofld(step)
639
            endif
639
            endif
640
 
640
 
641
c        Perform a reparameterisation in time
641
c        Perform a reparameterisation in time
642
         else if ( (mode.eq.'time').and.(step.eq.0) ) then
642
         else if ( (mode.eq.'time').and.(step.eq.0) ) then
643
 
643
 
644
c           Get the new number of trajectory points
644
c           Get the new number of trajectory points
645
            npts=nint(abs(otim(opts)-otim(1))/param)+1
645
            npts=nint(abs(otim(opts)-otim(1))/param)+1
646
 
646
 
647
c           Handle date line problem
647
c           Handle date line problem
648
            do j=2,opts
648
            do j=2,opts
649
               if ( (olon(j-1)-olon(j)).gt.180. ) then
649
               if ( (olon(j-1)-olon(j)).gt.180. ) then
650
                  olon(j) = olon(j) + 360.
650
                  olon(j) = olon(j) + 360.
651
               else if ( (olon(j-1)-olon(j)).lt.-180. ) then
651
               else if ( (olon(j-1)-olon(j)).lt.-180. ) then
652
                  olon(j) = olon(j) - 360.
652
                  olon(j) = olon(j) - 360.
653
               endif
653
               endif
654
            enddo
654
            enddo
655
 
655
 
656
c           Cubic spline fitting
656
c           Cubic spline fitting
657
            call curvefit(otim,olon,opts,ntim,nlon,npts)
657
            call curvefit(otim,olon,opts,ntim,nlon,npts)
658
            call curvefit(otim,olat,opts,ntim,nlat,npts)
658
            call curvefit(otim,olat,opts,ntim,nlat,npts)
659
            if ( field.ne.'nil' ) then
659
            if ( field.ne.'nil' ) then
660
               call curvefit(otim,ofld,opts,ntim,nfld,npts)
660
               call curvefit(otim,ofld,opts,ntim,nfld,npts)
661
            endif
661
            endif
662
 
662
 
663
c           Reverse date line handling
663
c           Reverse date line handling
664
            do j=1,npts
664
            do j=1,npts
665
               if ( nlon(j).gt.xmax ) then
665
               if ( nlon(j).gt.xmax ) then
666
                  nlon(j) = nlon(j) -360.
666
                  nlon(j) = nlon(j) -360.
667
               else if ( nlon(j).lt.xmin ) then
667
               else if ( nlon(j).lt.xmin ) then
668
                  nlon(j) = nlon(j) +360.
668
                  nlon(j) = nlon(j) +360.
669
               endif
669
               endif
670
            enddo
670
            enddo
671
 
671
 
672
c        Perform a reparameterisation with equally spaced gridpoint
672
c        Perform a reparameterisation with equally spaced gridpoint
673
         elseif ( (mode.eq.'space').and.(step.eq.0) ) then
673
         elseif ( (mode.eq.'space').and.(step.eq.0) ) then
674
            
674
            
675
c           Calculate the distance and spacing
675
c           Calculate the distance and spacing
676
            odist(1) = 0.
676
            odist(1) = 0.
677
            unit     = 'km'
677
            unit     = 'km'
678
            do j=2,ntime
678
            do j=2,ntime
679
               odist(j)=odist(j-1) + 
679
               odist(j)=odist(j-1) + 
680
     >                  sdis(olon(j-1),olat(j-1),olon(j),olat(j),unit)
680
     >                  sdis(olon(j-1),olat(j-1),olon(j),olat(j),unit)
681
            enddo
681
            enddo
682
            
682
            
683
c           Determine the new number of trajectory points
683
c           Determine the new number of trajectory points
684
            npts=nint(odist(ntime)/param)+1
684
            npts=nint(odist(ntime)/param)+1
685
            if (npts.eq.0) then
685
            if (npts.eq.0) then
686
               npts=1.
686
               npts=1.
687
            endif
687
            endif
688
        
688
        
689
c           Handle date line problem
689
c           Handle date line problem
690
            do j=2,opts
690
            do j=2,opts
691
               if ( (olon(j-1)-olon(j)).gt.180. ) then
691
               if ( (olon(j-1)-olon(j)).gt.180. ) then
692
                  olon(j) = olon(j) + 360.
692
                  olon(j) = olon(j) + 360.
693
               else if ( (olon(j-1)-olon(j)).lt.-180. ) then
693
               else if ( (olon(j-1)-olon(j)).lt.-180. ) then
694
                  olon(j) = olon(j) - 360.
694
                  olon(j) = olon(j) - 360.
695
               endif
695
               endif
696
            enddo
696
            enddo
697
                  
697
                  
698
c           Cubic spline fitting
698
c           Cubic spline fitting
699
            call curvefit(odist,olon,opts,ndist,nlon,npts)
699
            call curvefit(odist,olon,opts,ndist,nlon,npts)
700
            call curvefit(odist,olat,opts,ndist,nlat,npts)
700
            call curvefit(odist,olat,opts,ndist,nlat,npts)
701
            call curvefit(odist,otim,opts,ndist,ntim,npts)
701
            call curvefit(odist,otim,opts,ndist,ntim,npts)
702
            if ( field.ne.'nil' ) then
702
            if ( field.ne.'nil' ) then
703
               call curvefit(odist,ofld,opts,ndist,nfld,npts)
703
               call curvefit(odist,ofld,opts,ndist,nfld,npts)
704
            endif
704
            endif
705
 
705
 
706
c           Reverse date line handling
706
c           Reverse date line handling
707
            do j=1,npts
707
            do j=1,npts
708
               if ( nlon(j).gt.xmax ) then
708
               if ( nlon(j).gt.xmax ) then
709
                  nlon(j) = nlon(j) -360.
709
                  nlon(j) = nlon(j) -360.
710
               else if ( nlon(j).lt.xmin ) then
710
               else if ( nlon(j).lt.xmin ) then
711
                  nlon(j) = nlon(j) +360.
711
                  nlon(j) = nlon(j) +360.
712
               endif
712
               endif
713
            enddo
713
            enddo
714
 
714
 
715
c        Perform a reparameterisation with equally spaced gridpoint
715
c        Perform a reparameterisation with equally spaced gridpoint
716
         elseif ( (mode.eq.'grid').and.(step.eq.0) ) then
716
         elseif ( (mode.eq.'grid').and.(step.eq.0) ) then
717
            
717
            
718
c           Calculate the distance and spacing
718
c           Calculate the distance and spacing
719
            odist(1) = 0.
719
            odist(1) = 0.
720
            unit     = 'deg'
720
            unit     = 'deg'
721
            do j=2,ntime
721
            do j=2,ntime
722
               odist(j)=odist(j-1) + 
722
               odist(j)=odist(j-1) + 
723
     >                  sdis(olon(j-1),olat(j-1),olon(j),olat(j),unit)
723
     >                  sdis(olon(j-1),olat(j-1),olon(j),olat(j),unit)
724
            enddo
724
            enddo
725
            
725
            
726
c           Determine the new number of trajectory points
726
c           Determine the new number of trajectory points
727
            npts=nint(odist(ntime)/param)+1
727
            npts=nint(odist(ntime)/param)+1
728
            if (npts.eq.0) then
728
            if (npts.eq.0) then
729
               npts=1.
729
               npts=1.
730
            endif
730
            endif
731
        
731
        
732
c           Handle date line problem
732
c           Handle date line problem
733
            do j=2,opts
733
            do j=2,opts
734
               if ( (olon(j-1)-olon(j)).gt.180. ) then
734
               if ( (olon(j-1)-olon(j)).gt.180. ) then
735
                  olon(j) = olon(j) + 360.
735
                  olon(j) = olon(j) + 360.
736
               else if ( (olon(j-1)-olon(j)).lt.-180. ) then
736
               else if ( (olon(j-1)-olon(j)).lt.-180. ) then
737
                  olon(j) = olon(j) - 360.
737
                  olon(j) = olon(j) - 360.
738
               endif
738
               endif
739
            enddo
739
            enddo
740
                  
740
                  
741
c           Cubic spline fitting
741
c           Cubic spline fitting
742
            call curvefit(odist,olon,opts,ndist,nlon,npts)
742
            call curvefit(odist,olon,opts,ndist,nlon,npts)
743
            call curvefit(odist,olat,opts,ndist,nlat,npts)
743
            call curvefit(odist,olat,opts,ndist,nlat,npts)
744
            call curvefit(odist,otim,opts,ndist,ntim,npts)
744
            call curvefit(odist,otim,opts,ndist,ntim,npts)
745
            if ( field.ne.'nil' ) then
745
            if ( field.ne.'nil' ) then
746
               call curvefit(odist,ofld,opts,ndist,nfld,npts)
746
               call curvefit(odist,ofld,opts,ndist,nfld,npts)
747
            endif
747
            endif
748
 
748
 
749
c           Reverse date line handling
749
c           Reverse date line handling
750
            do j=1,npts
750
            do j=1,npts
751
               if ( nlon(j).gt.xmax ) then
751
               if ( nlon(j).gt.xmax ) then
752
                  nlon(j) = nlon(j) -360.
752
                  nlon(j) = nlon(j) -360.
753
               else if ( nlon(j).lt.xmin ) then
753
               else if ( nlon(j).lt.xmin ) then
754
                  nlon(j) = nlon(j) +360.
754
                  nlon(j) = nlon(j) +360.
755
               endif
755
               endif
756
            enddo
756
            enddo
757
 
757
 
758
         endif
758
         endif
759
 
759
 
760
c        -------- Do the gridding -------------------------------------
760
c        -------- Do the gridding -------------------------------------
761
 
761
 
762
c        Gridding of trajectory
762
c        Gridding of trajectory
763
         do j=1,npts
763
         do j=1,npts
764
 
764
 
765
c           Check whether point is in data domain
765
c           Check whether point is in data domain
766
	    if ( (nlon(j).gt.xmin).and.(nlon(j).lt.xmax).and.
766
	    if ( (nlon(j).gt.xmin).and.(nlon(j).lt.xmax).and.
767
     >           (nlat(j).gt.ymin).and.(nlat(j).lt.ymax))
767
     >           (nlat(j).gt.ymin).and.(nlat(j).lt.ymax))
768
     >      then
768
     >      then
769
 
769
 
770
c              Increase counter for gridded points
770
c              Increase counter for gridded points
771
               count = count + 1
771
               count = count + 1
772
 
772
 
773
c              ----------------- Gridding: simple count -----------------
773
c              ----------------- Gridding: simple count -----------------
774
               connectval0 = connectval0+1
774
               connectval0 = connectval0+1
775
               
775
               
776
               addvalue    = 1.
776
               addvalue    = 1.
777
               
777
               
778
               call  gridding1
778
               call  gridding1
779
     >              (nlat(j),nlon(j),addvalue,
779
     >              (nlat(j),nlon(j),addvalue,
780
     >               radius,runit,connect0,connectval0,
780
     >               radius,runit,connect0,connectval0,
781
     >               cnt,nx,ny,xmin,ymin,dx,dy)
781
     >               cnt,nx,ny,xmin,ymin,dx,dy)
782
 
782
 
783
c              ----------------- Gridding: residence time ---------------
783
c              ----------------- Gridding: residence time ---------------
784
               connectval1 = connectval1+1
784
               connectval1 = connectval1+1
785
               
785
               
786
               if ( ntime.eq.1 ) then
786
               if ( ntime.eq.1 ) then
787
                  addvalue = 0.
787
                  addvalue = 0.
788
               elseif ( j.eq.1 )  then
788
               elseif ( j.eq.1 )  then
789
                  addvalue=abs(ntim(2)-ntim(1))
789
                  addvalue=abs(ntim(2)-ntim(1))
790
               else
790
               else
791
                  addvalue=abs(ntim(j)-ntim(j-1))
791
                  addvalue=abs(ntim(j)-ntim(j-1))
792
               endif
792
               endif
793
               
793
               
794
               call  gridding1
794
               call  gridding1
795
     >              (nlat(j),nlon(j),addvalue,
795
     >              (nlat(j),nlon(j),addvalue,
796
     >               radius,runit,connect1,connectval1,
796
     >               radius,runit,connect1,connectval1,
797
     >               res,nx,ny,xmin,ymin,dx,dy)
797
     >               res,nx,ny,xmin,ymin,dx,dy)
798
 
798
 
799
 
799
 
800
c              --------------- Gridding: field -------------------------
800
c              --------------- Gridding: field -------------------------
801
               if ( field.ne.'nil' ) then
801
               if ( field.ne.'nil' ) then
802
 
802
 
803
                   connectval2 = connectval2+1
803
                   connectval2 = connectval2+1
804
               
804
               
805
                   addvalue    = nfld(j)
805
                   addvalue    = nfld(j)
806
               
806
               
807
                   call  gridding1
807
                   call  gridding1
808
     >                  (nlat(j),nlon(j),addvalue,
808
     >                  (nlat(j),nlon(j),addvalue,
809
     >                  radius,runit,connect2,connectval2,
809
     >                  radius,runit,connect2,connectval2,
810
     >                  fld,nx,ny,xmin,ymin,dx,dy)
810
     >                  fld,nx,ny,xmin,ymin,dx,dy)
811
 
811
 
812
               endif
812
               endif
813
 
813
 
814
	    endif
814
	    endif
815
 
815
 
816
         enddo
816
         enddo
817
 
817
 
818
c        Exit point for loop over all trajectories
818
c        Exit point for loop over all trajectories
819
 300     continue
819
 300     continue
820
 
820
 
821
      enddo
821
      enddo
822
 
822
 
823
c     Write status information
823
c     Write status information
824
      print*
824
      print*
825
      print*,' # gridded points       : ',count
825
      print*,' # gridded points       : ',count
826
 
826
 
827
c     ---------------------------------------------------------------------
827
c     ---------------------------------------------------------------------
828
c     Unit conversions and output to netCDF file
828
c     Unit conversions and output to netCDF file
829
c     ---------------------------------------------------------------------
829
c     ---------------------------------------------------------------------
830
 
830
 
831
c     Write some status information 
831
c     Write some status information 
832
      print*
832
      print*
833
      print*,'---- WRITE OUTPUT ---------------------------------------'
833
      print*,'---- WRITE OUTPUT ---------------------------------------'
834
      print*
834
      print*
835
 
835
 
836
c     Area (in km^2)
836
c     Area (in km^2)
837
      do i=1,nx	         
837
      do i=1,nx	         
838
         do j=1,ny	
838
         do j=1,ny	
839
            slat=ymin+real(j-1)*dy
839
            slat=ymin+real(j-1)*dy
840
            if (abs(abs(slat)-90.).gt.eps) then
840
            if (abs(abs(slat)-90.).gt.eps) then
841
               area(i,j) = dy*dx*cos(pi180*slat)*deltay**2
841
               area(i,j) = dy*dx*cos(pi180*slat)*deltay**2
842
            else
842
            else
843
               area(i,j) = 0.
843
               area(i,j) = 0.
844
            endif
844
            endif
845
         enddo
845
         enddo
846
      enddo
846
      enddo
847
 
847
 
848
c     Normalise gridded field
848
c     Normalise gridded field
849
      if ( field.ne.'nil' ) then
849
      if ( field.ne.'nil' ) then
850
         do i=1,nx
850
         do i=1,nx
851
            do j=1,ny
851
            do j=1,ny
852
               if ( cnt(i,j).gt.0. ) then
852
               if ( cnt(i,j).gt.0. ) then
853
                  fld(i,j) = fld(i,j) / cnt(i,j)
853
                  fld(i,j) = fld(i,j) / cnt(i,j)
854
               endif
854
               endif
855
            enddo
855
            enddo
856
         enddo
856
         enddo
857
      endif
857
      endif
858
 
858
 
859
c     Set the time for the output netCDF files - if a composite is
859
c     Set the time for the output netCDF files - if a composite is
860
c     calculatd, then the time is set to 
860
c     calculatd, then the time is set to 
861
      if ( step.eq.0 ) then
861
      if ( step.eq.0 ) then
862
         time = -999.
862
         time = -999.
863
         print*,'   ... COMPOSITE OVER ALL TRAJECTORY TIMES (-999)'
863
         print*,'   ... COMPOSITE OVER ALL TRAJECTORY TIMES (-999)'
864
         print*
864
         print*
865
      else
865
      else
866
         time = trainp(1,step,1)
866
         time = trainp(1,step,1)
867
      endif
867
      endif
868
 
868
 
869
c     Write output to CF netCDF
869
c     Write output to CF netCDF
870
      cdfname  = outfile
870
      cdfname  = outfile
871
      
871
      
872
      varname  = 'COUNT'
872
      varname  = 'COUNT'
873
      longname = 'trajectory counts'
873
      longname = 'trajectory counts'
874
      varunit  = 'counts per grid point'
874
      varunit  = 'counts per grid point'
875
      call  writecdf2D_cf (cdfname,varname,longname,varunit,gridtype,
875
      call  writecdf2D_cf (cdfname,varname,longname,varunit,gridtype,
876
     >       clon,clat,nlonlat,dlonlat,cnt,time,dx,dy,xmin,ymin,nx,
876
     >       clon,clat,nlonlat,dlonlat,cnt,time,dx,dy,xmin,ymin,nx,
877
     >       ny,crefile,crefile,1,pollon,pollat)
877
     >       ny,crefile,crefile,1,pollon,pollat)
878
      write(*,'(a8,a10,a5,a10,a10,f7.2,a2)') 
878
      write(*,'(a8,a10,a5,a10,a10,f7.2,a2)') 
879
     >     '    ... ',trim(varname),' -> ',trim(cdfname),
879
     >     '    ... ',trim(varname),' -> ',trim(cdfname),
880
     >     ' [ time = ',time,' ]'    
880
     >     ' [ time = ',time,' ]'    
881
 
881
 
882
      varname  = 'RESIDENCE'
882
      varname  = 'RESIDENCE'
883
      longname = 'residence time'
883
      longname = 'residence time'
884
      varunit  = 'hours per grid point'
884
      varunit  = 'hours per grid point'
885
      call  writecdf2D_cf (cdfname,varname,longname,varunit,gridtype,
885
      call  writecdf2D_cf (cdfname,varname,longname,varunit,gridtype,
886
     >       clon,clat,nlonlat,dlonlat,res,time,dx,dy,xmin,ymin,nx,
886
     >       clon,clat,nlonlat,dlonlat,res,time,dx,dy,xmin,ymin,nx,
887
     >       ny,0,crefile,1,pollon,pollat)
887
     >       ny,0,crefile,1,pollon,pollat)
888
      write(*,'(a8,a10,a5,a10,a10,f7.2,a2)') 
888
      write(*,'(a8,a10,a5,a10,a10,f7.2,a2)') 
889
     >     '    ... ',trim(varname),' -> ',trim(cdfname),
889
     >     '    ... ',trim(varname),' -> ',trim(cdfname),
890
     >     ' [ time = ',time,' ]'    
890
     >     ' [ time = ',time,' ]'    
891
 
891
 
892
      varname  = 'AREA'
892
      varname  = 'AREA'
893
      longname = 'area corresponding to grid points'
893
      longname = 'area corresponding to grid points'
894
      varunit  = 'square kilometers'
894
      varunit  = 'square kilometers'
895
      call  writecdf2D_cf (cdfname,varname,longname,varunit,gridtype,
895
      call  writecdf2D_cf (cdfname,varname,longname,varunit,gridtype,
896
     >       clon,clat,nlonlat,dlonlat,area,time,dx,dy,xmin,ymin,nx,
896
     >       clon,clat,nlonlat,dlonlat,area,time,dx,dy,xmin,ymin,nx,
897
     >       ny,0,crefile,1,pollon,pollat)
897
     >       ny,0,crefile,1,pollon,pollat)
898
      write(*,'(a8,a10,a5,a10,a10,f7.2,a2)') 
898
      write(*,'(a8,a10,a5,a10,a10,f7.2,a2)') 
899
     >     '    ... ',trim(varname),' -> ',trim(cdfname),
899
     >     '    ... ',trim(varname),' -> ',trim(cdfname),
900
     >     ' [ time = ',time,' ]'    
900
     >     ' [ time = ',time,' ]'    
901
      
901
      
902
      if ( field.ne.'nil' ) then
902
      if ( field.ne.'nil' ) then
903
         varname  = field
903
         varname  = field
904
         longname = field
904
         longname = field
905
         varunit  = 'as on trajectory file'
905
         varunit  = 'as on trajectory file'
906
         call  writecdf2D_cf (cdfname,varname,longname,varunit,gridtype,
906
         call  writecdf2D_cf (cdfname,varname,longname,varunit,gridtype,
907
     >       clon,clat,nlonlat,dlonlat,fld,time,dx,dy,xmin,ymin,nx,
907
     >       clon,clat,nlonlat,dlonlat,fld,time,dx,dy,xmin,ymin,nx,
908
     >       ny,0,crevar,1,pollon,pollat)
908
     >       ny,0,crevar,1,pollon,pollat)
909
 
909
 
910
         write(*,'(a8,a10,a5,a10,a10,f7.2,a2)') 
910
         write(*,'(a8,a10,a5,a10,a10,f7.2,a2)') 
911
     >        '    ... ',trim(varname),' -> ',trim(cdfname),
911
     >        '    ... ',trim(varname),' -> ',trim(cdfname),
912
     >        ' [ time = ',time,' ]'    
912
     >        ' [ time = ',time,' ]'    
913
      endif
913
      endif
914
 
914
 
915
c     Write status information
915
c     Write status information
916
      print*
916
      print*
917
      print*,'              *** END OF PROGRAM DENSITY **'
917
      print*,'              *** END OF PROGRAM DENSITY **'
918
      print*,'========================================================='
918
      print*,'========================================================='
919
 
919
 
920
      end
920
      end
921
 
921
 
922
c     ********************************************************************
922
c     ********************************************************************
923
c     * GRIDDING SUBROUTINES                                             *
923
c     * GRIDDING SUBROUTINES                                             *
924
c     ********************************************************************
924
c     ********************************************************************
925
 
925
 
926
c     ---------------------------------------------------------------------
926
c     ---------------------------------------------------------------------
927
c     Gridding of one single data point (smoothing in km, deg, gridp)
927
c     Gridding of one single data point (smoothing in km, deg, gridp)
928
c     ---------------------------------------------------------------------
928
c     ---------------------------------------------------------------------
929
 
929
 
930
      subroutine gridding1 (lat,lon,addval,radius,unit,
930
      subroutine gridding1 (lat,lon,addval,radius,unit,
931
     >                      connect,connectval,
931
     >                      connect,connectval,
932
     >                      out,nx,ny,xmin,ymin,dx,dy)
932
     >                      out,nx,ny,xmin,ymin,dx,dy)
933
 
933
 
934
      implicit none
934
      implicit none
935
 
935
 
936
c     Declaration of subroutine parameters
936
c     Declaration of subroutine parameters
937
      real         lat,lon
937
      real         lat,lon
938
      integer      nx,ny
938
      integer      nx,ny
939
      real         xmin,ymin,dx,dy
939
      real         xmin,ymin,dx,dy
940
      real         out(nx,ny)
940
      real         out(nx,ny)
941
      real         radius
941
      real         radius
942
      character*80 unit
942
      character*80 unit
943
      integer      connectval
943
      integer      connectval
944
      integer      connect(nx,ny)
944
      integer      connect(nx,ny)
945
      real         addval
945
      real         addval
946
 
946
 
947
c     Auxiliary variables
947
c     Auxiliary variables
948
      integer   i,j,k
948
      integer   i,j,k
949
      integer   mu,md,nr,nl,n,m
949
      integer   mu,md,nr,nl,n,m
950
      integer   stackx(nx*ny),stacky(nx*ny)
950
      integer   stackx(nx*ny),stacky(nx*ny)
951
      integer   tab_x(nx*ny),tab_y(nx*ny)
951
      integer   tab_x(nx*ny),tab_y(nx*ny)
952
      real      tab_r(nx*ny)
952
      real      tab_r(nx*ny)
953
      integer   sp
953
      integer   sp
954
      real      lat2,lon2
954
      real      lat2,lon2
955
      real      dist,sum
955
      real      dist,sum
956
      real      xmax
956
      real      xmax
957
      integer   periodic
957
      integer   periodic
958
      integer   test
958
      integer   test
959
 
959
 
960
c     Numerical epsilon
960
c     Numerical epsilon
961
      real      eps
961
      real      eps
962
      parameter (eps=0.01)
962
      parameter (eps=0.01)
963
 
963
 
964
c     Externals
964
c     Externals
965
      real      sdis,weight
965
      real      sdis,weight
966
      external  sdis,weight
966
      external  sdis,weight
967
 
967
 
968
c     Check whether lat/lon point is valid
968
c     Check whether lat/lon point is valid
969
      xmax=xmin+real(nx-1)*dx
969
      xmax=xmin+real(nx-1)*dx
970
      if (lon.lt.xmin-eps) lon=lon+360.
970
      if (lon.lt.xmin-eps) lon=lon+360.
971
      if (lon.gt.xmax+eps) lon=lon-360.
971
      if (lon.gt.xmax+eps) lon=lon-360.
972
      if (abs(lat-90).lt.eps) lat=90.
972
      if (abs(lat-90).lt.eps) lat=90.
973
      if (abs(lat+90).lt.eps) lat=-90.
973
      if (abs(lat+90).lt.eps) lat=-90.
974
      if ((abs(lat).gt.(90.+eps)).or.
974
      if ((abs(lat).gt.(90.+eps)).or.
975
     >    (lon.lt.xmin-eps).or.(lon.gt.xmax+eps)) then
975
     >    (lon.lt.xmin-eps).or.(lon.gt.xmax+eps)) then
976
         print*,'Invalid lat/lon point ',lat,lon
976
         print*,'Invalid lat/lon point ',lat,lon
977
         return
977
         return
978
      endif
978
      endif
979
 
979
 
980
c     Set flag for periodic domain
980
c     Set flag for periodic domain
981
      if (abs(xmax-xmin-360.).lt.eps) then
981
      if (abs(xmax-xmin-360.).lt.eps) then
982
         periodic=1
982
         periodic=1
983
      else if (abs(xmax-xmin-360+dx).lt.eps) then
983
      else if (abs(xmax-xmin-360+dx).lt.eps) then
984
         periodic=2
984
         periodic=2
985
      else
985
      else
986
         periodic=0
986
         periodic=0
987
      endif
987
      endif
988
 
988
 
989
c     Get indices of one coarse grid point within search radius
989
c     Get indices of one coarse grid point within search radius
990
      i=nint((lon-xmin)/dx)+1
990
      i=nint((lon-xmin)/dx)+1
991
      if ((i.eq.nx).and.(periodic.eq.1)) i=1
991
      if ((i.eq.nx).and.(periodic.eq.1)) i=1
992
      j=nint((lat-ymin)/dy)+1
992
      j=nint((lat-ymin)/dy)+1
993
      lat2=ymin+real(j-1)*dy
993
      lat2=ymin+real(j-1)*dy
994
      lon2=xmin+real(i-1)*dx
994
      lon2=xmin+real(i-1)*dx
995
      dist=sdis(lon,lat,lon2,lat2,unit)
995
      dist=sdis(lon,lat,lon2,lat2,unit)
996
      if (dist.gt.radius) then
996
      if (dist.gt.radius) then
997
         print*,'1: Search radius is too small...'
997
         print*,'1: Search radius is too small...'
998
         stop
998
         stop
999
      endif
999
      endif
1000
 
1000
 
1001
c     Get connected points
1001
c     Get connected points
1002
      k=0
1002
      k=0
1003
      stackx(1)=i
1003
      stackx(1)=i
1004
      stacky(1)=j
1004
      stacky(1)=j
1005
      sp=1
1005
      sp=1
1006
      do while (sp.ne.0) 
1006
      do while (sp.ne.0) 
1007
         
1007
         
1008
c        Get an element from stack
1008
c        Get an element from stack
1009
         n=stackx(sp)
1009
         n=stackx(sp)
1010
         m=stacky(sp)
1010
         m=stacky(sp)
1011
         sp=sp-1
1011
         sp=sp-1
1012
                  
1012
                  
1013
c        Get distance from reference point
1013
c        Get distance from reference point
1014
         lat2=ymin+real(m-1)*dy
1014
         lat2=ymin+real(m-1)*dy
1015
         lon2=xmin+real(n-1)*dx
1015
         lon2=xmin+real(n-1)*dx
1016
         dist=sdis(lon,lat,lon2,lat2,unit)
1016
         dist=sdis(lon,lat,lon2,lat2,unit)
1017
 
1017
 
1018
c        Check whether distance is smaller than search radius: connected
1018
c        Check whether distance is smaller than search radius: connected
1019
         if (dist.lt.radius) then
1019
         if (dist.lt.radius) then
1020
 
1020
 
1021
c           Make entry in filter mask
1021
c           Make entry in filter mask
1022
            k=k+1
1022
            k=k+1
1023
            tab_x(k)=n
1023
            tab_x(k)=n
1024
            tab_y(k)=m
1024
            tab_y(k)=m
1025
            tab_r(k)=weight(dist,radius)
1025
            tab_r(k)=weight(dist,radius)
1026
 
1026
 
1027
c           Mark this point as visited
1027
c           Mark this point as visited
1028
            connect(n,m)=connectval
1028
            connect(n,m)=connectval
1029
                     
1029
                     
1030
c           Get coordinates of neighbouring points
1030
c           Get coordinates of neighbouring points
1031
            nr=n+1
1031
            nr=n+1
1032
            if ((nr.gt.nx)  .and.(periodic.eq.0)) nr=nx
1032
            if ((nr.gt.nx)  .and.(periodic.eq.0)) nr=nx
1033
            if ((nr.gt.nx-1).and.(periodic.eq.1)) nr=1
1033
            if ((nr.gt.nx-1).and.(periodic.eq.1)) nr=1
1034
            if ((nr.gt.nx)  .and.(periodic.eq.2)) nr=1
1034
            if ((nr.gt.nx)  .and.(periodic.eq.2)) nr=1
1035
            nl=n-1
1035
            nl=n-1
1036
            if ((nl.lt.1).and.(periodic.eq.0)) nl=1
1036
            if ((nl.lt.1).and.(periodic.eq.0)) nl=1
1037
            if ((nl.lt.1).and.(periodic.eq.1)) nl=nx-1
1037
            if ((nl.lt.1).and.(periodic.eq.1)) nl=nx-1
1038
            if ((nl.lt.1).and.(periodic.eq.2)) nl=nx
1038
            if ((nl.lt.1).and.(periodic.eq.2)) nl=nx
1039
            mu=m+1
1039
            mu=m+1
1040
            if (mu.gt.ny) mu=ny
1040
            if (mu.gt.ny) mu=ny
1041
            md=m-1
1041
            md=m-1
1042
            if (md.lt.1) md=1
1042
            if (md.lt.1) md=1
1043
 
1043
 
1044
c           Update stack
1044
c           Update stack
1045
            if (connect(nr,m).ne.connectval) then
1045
            if (connect(nr,m).ne.connectval) then
1046
               connect(nr,m)=connectval
1046
               connect(nr,m)=connectval
1047
               sp=sp+1
1047
               sp=sp+1
1048
               stackx(sp)=nr
1048
               stackx(sp)=nr
1049
               stacky(sp)=m
1049
               stacky(sp)=m
1050
            endif
1050
            endif
1051
            if (connect(nl,m).ne.connectval) then
1051
            if (connect(nl,m).ne.connectval) then
1052
               connect(nl,m)=connectval
1052
               connect(nl,m)=connectval
1053
               sp=sp+1
1053
               sp=sp+1
1054
               stackx(sp)=nl
1054
               stackx(sp)=nl
1055
               stacky(sp)=m
1055
               stacky(sp)=m
1056
            endif
1056
            endif
1057
            if (connect(n,mu).ne.connectval) then
1057
            if (connect(n,mu).ne.connectval) then
1058
               connect(n,mu)=connectval
1058
               connect(n,mu)=connectval
1059
               sp=sp+1
1059
               sp=sp+1
1060
               stackx(sp)=n
1060
               stackx(sp)=n
1061
               stacky(sp)=mu
1061
               stacky(sp)=mu
1062
            endif
1062
            endif
1063
            if (connect(n,md).ne.connectval) then
1063
            if (connect(n,md).ne.connectval) then
1064
               connect(n,md)=connectval
1064
               connect(n,md)=connectval
1065
               sp=sp+1
1065
               sp=sp+1
1066
               stackx(sp)=n
1066
               stackx(sp)=n
1067
               stacky(sp)=md
1067
               stacky(sp)=md
1068
            endif
1068
            endif
1069
         endif
1069
         endif
1070
         
1070
         
1071
      end do
1071
      end do
1072
 
1072
 
1073
      if (k.ge.1) then
1073
      if (k.ge.1) then
1074
         sum=0.
1074
         sum=0.
1075
         do i=1,k
1075
         do i=1,k
1076
            sum=sum+tab_r(i)
1076
            sum=sum+tab_r(i)
1077
         enddo
1077
         enddo
1078
         do i=1,k
1078
         do i=1,k
1079
            out(tab_x(i),tab_y(i))=out(tab_x(i),tab_y(i))+
1079
            out(tab_x(i),tab_y(i))=out(tab_x(i),tab_y(i))+
1080
     >                             addval*tab_r(i)/sum
1080
     >                             addval*tab_r(i)/sum
1081
 
1081
 
1082
            if ((tab_x(i).eq.1).and.(periodic.eq.1)) then
1082
            if ((tab_x(i).eq.1).and.(periodic.eq.1)) then
1083
               out(nx,tab_y(i))=out(nx,tab_y(i))+
1083
               out(nx,tab_y(i))=out(nx,tab_y(i))+
1084
     >                             addval*tab_r(i)/sum
1084
     >                             addval*tab_r(i)/sum
1085
            endif
1085
            endif
1086
         enddo
1086
         enddo
1087
      else
1087
      else
1088
         print*,'2: Search radius is too small...'
1088
         print*,'2: Search radius is too small...'
1089
         stop
1089
         stop
1090
      endif
1090
      endif
1091
 
1091
 
1092
      end
1092
      end
1093
 
1093
 
1094
 
1094
 
1095
c     ----------------------------------------------------------------------
1095
c     ----------------------------------------------------------------------
1096
c     Get spherical distance between lat/lon points
1096
c     Get spherical distance between lat/lon points
1097
c     ----------------------------------------------------------------------
1097
c     ----------------------------------------------------------------------
1098
            
1098
            
1099
      real function sdis(xp,yp,xq,yq,unit)
1099
      real function sdis(xp,yp,xq,yq,unit)
1100
 
1100
 
1101
c     Calculates spherical distance (in km) between two points given
1101
c     Calculates spherical distance (in km) between two points given
1102
c     by their spherical coordinates (xp,yp) and (xq,yq), respectively.
1102
c     by their spherical coordinates (xp,yp) and (xq,yq), respectively.
1103
 
1103
 
1104
      real         re
1104
      real         re
1105
      parameter    (re=6370.)
1105
      parameter    (re=6370.)
1106
      real         xp,yp,xq,yq,arg
1106
      real         xp,yp,xq,yq,arg
1107
      character*80 unit
1107
      character*80 unit
1108
      real         dlon
1108
      real         dlon
1109
 
1109
 
1110
      if ( unit.eq.'km' ) then
1110
      if ( unit.eq.'km' ) then
1111
 
1111
 
-
 
1112
         arg=sin(yp*pi180)*sin(yq*pi180)+cos(yp*pi180)*cos(yq*pi180)*
-
 
1113
     >       cos((xp-xq)*pi180)
1112
         arg=sind(yp)*sind(yq)+cosd(yp)*cosd(yq)*cosd(xp-xq)
1114
c         arg=sind(yp)*sind(yq)+cosd(yp)*cosd(yq)*cosd(xp-xq)
1113
         if (arg.lt.-1.) arg=-1.
1115
         if (arg.lt.-1.) arg=-1.
1114
         if (arg.gt.1.) arg=1.
1116
         if (arg.gt.1.) arg=1.
1115
         sdis=re*acos(arg)
1117
         sdis=re*acos(arg)
1116
         
1118
         
1117
      elseif ( unit.eq.'deg' ) then
1119
      elseif ( unit.eq.'deg' ) then
1118
 
1120
 
1119
         dlon = xp-xq
1121
         dlon = xp-xq
1120
         if ( dlon.gt. 180. ) dlon = dlon - 360.
1122
         if ( dlon.gt. 180. ) dlon = dlon - 360.
1121
         if ( dlon.lt.-180. ) dlon = dlon + 360.
1123
         if ( dlon.lt.-180. ) dlon = dlon + 360.
1122
         sdis = sqrt( dlon**2 + (yp-yq)**2 )
1124
         sdis = sqrt( dlon**2 + (yp-yq)**2 )
1123
 
1125
 
1124
      endif
1126
      endif
1125
      
1127
      
1126
 
1128
 
1127
c     Quick and dirty trick to avoid zero distances
1129
c     Quick and dirty trick to avoid zero distances
1128
      if (sdis.eq.0.) sdis=0.1
1130
      if (sdis.eq.0.) sdis=0.1
1129
 
1131
 
1130
      end
1132
      end
1131
 
1133
 
1132
c     ----------------------------------------------------------------------
1134
c     ----------------------------------------------------------------------
1133
c     Weight function for the filter mask
1135
c     Weight function for the filter mask
1134
c     ----------------------------------------------------------------------
1136
c     ----------------------------------------------------------------------
1135
 
1137
 
1136
      real function weight (r,radius)
1138
      real function weight (r,radius)
1137
 
1139
 
1138
c     Attribute to each distanc r its corresponding weight in the filter mask
1140
c     Attribute to each distanc r its corresponding weight in the filter mask
1139
 
1141
 
1140
      implicit none
1142
      implicit none
1141
 
1143
 
1142
c     Declaration of subroutine parameters
1144
c     Declaration of subroutine parameters
1143
      real r
1145
      real r
1144
      real radius
1146
      real radius
1145
 
1147
 
1146
c     Simple 0/1 mask
1148
c     Simple 0/1 mask
1147
      if (r.lt.radius) then
1149
      if (r.lt.radius) then
1148
         weight=exp(-r/radius)
1150
         weight=exp(-r/radius)
1149
      else
1151
      else
1150
         weight=0.
1152
         weight=0.
1151
      endif
1153
      endif
1152
 
1154
 
1153
      end
1155
      end
1154
 
1156
 
1155
 
1157
 
1156
c     ********************************************************************
1158
c     ********************************************************************
1157
c     * REPARAMETERIZATION SUBROUTINES                                   *
1159
c     * REPARAMETERIZATION SUBROUTINES                                   *
1158
c     ********************************************************************
1160
c     ********************************************************************
1159
 
1161
 
1160
c     -------------------------------------------------------------
1162
c     -------------------------------------------------------------
1161
c     Interpolation of the trajectory with a natural cubic spline
1163
c     Interpolation of the trajectory with a natural cubic spline
1162
c     -------------------------------------------------------------
1164
c     -------------------------------------------------------------
1163
 
1165
 
1164
      SUBROUTINE curvefit (time,lon,n,
1166
      SUBROUTINE curvefit (time,lon,n,
1165
     >                     sptime,splon,spn)
1167
     >                     sptime,splon,spn)
1166
 
1168
 
1167
c     Given the curve <time,lon> with <n> data points, fit a
1169
c     Given the curve <time,lon> with <n> data points, fit a
1168
c     cubic spline to this curve. The new curve is returned in 
1170
c     cubic spline to this curve. The new curve is returned in 
1169
c     <sptime,splon,spn> with <spn> data points. The parameter
1171
c     <sptime,splon,spn> with <spn> data points. The parameter
1170
c     <spn> specifies on entry the number of spline interpolated points
1172
c     <spn> specifies on entry the number of spline interpolated points
1171
c     along the curve.
1173
c     along the curve.
1172
      
1174
      
1173
      implicit none
1175
      implicit none
1174
 
1176
 
1175
c     Declaration of subroutine parameters
1177
c     Declaration of subroutine parameters
1176
      integer n
1178
      integer n
1177
      real time(n),lon(n)
1179
      real time(n),lon(n)
1178
      integer spn
1180
      integer spn
1179
      real sptime(spn),splon(spn)
1181
      real sptime(spn),splon(spn)
1180
 
1182
 
1181
c     Auxiliary variables
1183
c     Auxiliary variables
1182
      real y2ax(n)
1184
      real y2ax(n)
1183
      real dt
1185
      real dt
1184
      real s
1186
      real s
1185
      integer i
1187
      integer i
1186
      real order
1188
      real order
1187
 
1189
 
1188
c     Determine whether the input array is ascending or descending
1190
c     Determine whether the input array is ascending or descending
1189
      if (time(1).gt.time(n)) then
1191
      if (time(1).gt.time(n)) then
1190
         order=-1.
1192
         order=-1.
1191
      else
1193
      else
1192
         order= 1.
1194
         order= 1.
1193
      endif
1195
      endif
1194
 
1196
 
1195
c     Bring the time array into ascending order
1197
c     Bring the time array into ascending order
1196
      do i=1,n
1198
      do i=1,n
1197
         time(i)=order*time(i)
1199
         time(i)=order*time(i)
1198
      enddo
1200
      enddo
1199
 
1201
 
1200
c     Prepare the (natural) cubic spline interpolation
1202
c     Prepare the (natural) cubic spline interpolation
1201
      call spline (time,lon,n,1.e30,1.e30,y2ax)
1203
      call spline (time,lon,n,1.e30,1.e30,y2ax)
1202
      dt=(time(n)-time(1))/real(spn-1)
1204
      dt=(time(n)-time(1))/real(spn-1)
1203
      do i=1,spn
1205
      do i=1,spn
1204
         sptime(i)=time(1)+real(i-1)*dt
1206
         sptime(i)=time(1)+real(i-1)*dt
1205
      enddo
1207
      enddo
1206
      
1208
      
1207
c     Do the spline interpolation
1209
c     Do the spline interpolation
1208
      do i=1,spn
1210
      do i=1,spn
1209
         call splint(time,lon,y2ax,n,sptime(i),s)
1211
         call splint(time,lon,y2ax,n,sptime(i),s)
1210
         splon(i)=s
1212
         splon(i)=s
1211
      enddo
1213
      enddo
1212
 
1214
 
1213
c     Change the time arrays back
1215
c     Change the time arrays back
1214
      do i=1,spn
1216
      do i=1,spn
1215
         sptime(i)=order*sptime(i)
1217
         sptime(i)=order*sptime(i)
1216
      enddo
1218
      enddo
1217
      do i=1,n
1219
      do i=1,n
1218
         time(i)=order*time(i)
1220
         time(i)=order*time(i)
1219
      enddo
1221
      enddo
1220
 
1222
 
1221
      return
1223
      return
1222
      end
1224
      end
1223
 
1225
 
1224
c     -------------------------------------------------------------
1226
c     -------------------------------------------------------------
1225
c     Basic routines for spline interpolation (Numerical Recipes)
1227
c     Basic routines for spline interpolation (Numerical Recipes)
1226
c     -------------------------------------------------------------
1228
c     -------------------------------------------------------------
1227
 
1229
 
1228
      SUBROUTINE spline(x,y,n,yp1,ypn,y2)
1230
      SUBROUTINE spline(x,y,n,yp1,ypn,y2)
1229
      INTEGER n,NMAX
1231
      INTEGER n,NMAX
1230
      REAL yp1,ypn,x(n),y(n),y2(n)
1232
      REAL yp1,ypn,x(n),y(n),y2(n)
1231
      PARAMETER (NMAX=500)
1233
      PARAMETER (NMAX=500)
1232
      INTEGER i,k
1234
      INTEGER i,k
1233
      REAL p,qn,sig,un,u(NMAX)
1235
      REAL p,qn,sig,un,u(NMAX)
1234
      if (yp1.gt..99e30) then
1236
      if (yp1.gt..99e30) then
1235
        y2(1)=0.
1237
        y2(1)=0.
1236
        u(1)=0.
1238
        u(1)=0.
1237
      else
1239
      else
1238
        y2(1)=-0.5
1240
        y2(1)=-0.5
1239
        u(1)=(3./(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)
1241
        u(1)=(3./(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)
1240
      endif
1242
      endif
1241
      do 11 i=2,n-1
1243
      do 11 i=2,n-1
1242
        sig=(x(i)-x(i-1))/(x(i+1)-x(i-1))
1244
        sig=(x(i)-x(i-1))/(x(i+1)-x(i-1))
1243
        p=sig*y2(i-1)+2.
1245
        p=sig*y2(i-1)+2.
1244
        y2(i)=(sig-1.)/p
1246
        y2(i)=(sig-1.)/p
1245
        u(i)=(6.*((y(i+1)-y(i))/(x(i+
1247
        u(i)=(6.*((y(i+1)-y(i))/(x(i+
1246
     *1)-x(i))-(y(i)-y(i-1))/(x(i)-x(i-1)))/(x(i+1)-x(i-1))-sig*
1248
     *1)-x(i))-(y(i)-y(i-1))/(x(i)-x(i-1)))/(x(i+1)-x(i-1))-sig*
1247
     *u(i-1))/p
1249
     *u(i-1))/p
1248
11    continue
1250
11    continue
1249
      if (ypn.gt..99e30) then
1251
      if (ypn.gt..99e30) then
1250
        qn=0.
1252
        qn=0.
1251
        un=0.
1253
        un=0.
1252
      else
1254
      else
1253
        qn=0.5
1255
        qn=0.5
1254
        un=(3./(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))
1256
        un=(3./(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))
1255
      endif
1257
      endif
1256
      y2(n)=(un-qn*u(n-1))/(qn*y2(n-1)+1.)
1258
      y2(n)=(un-qn*u(n-1))/(qn*y2(n-1)+1.)
1257
      do 12 k=n-1,1,-1
1259
      do 12 k=n-1,1,-1
1258
        y2(k)=y2(k)*y2(k+1)+u(k)
1260
        y2(k)=y2(k)*y2(k+1)+u(k)
1259
12    continue
1261
12    continue
1260
      return
1262
      return
1261
      END
1263
      END
1262
 
1264
 
1263
      SUBROUTINE splint(xa,ya,y2a,n,x,y)
1265
      SUBROUTINE splint(xa,ya,y2a,n,x,y)
1264
      INTEGER n
1266
      INTEGER n
1265
      REAL x,y,xa(n),y2a(n),ya(n)
1267
      REAL x,y,xa(n),y2a(n),ya(n)
1266
      INTEGER k,khi,klo
1268
      INTEGER k,khi,klo
1267
      REAL a,b,h
1269
      REAL a,b,h
1268
      klo=1
1270
      klo=1
1269
      khi=n
1271
      khi=n
1270
1     if (khi-klo.gt.1) then
1272
1     if (khi-klo.gt.1) then
1271
        k=(khi+klo)/2
1273
        k=(khi+klo)/2
1272
        if(xa(k).gt.x)then
1274
        if(xa(k).gt.x)then
1273
          khi=k
1275
          khi=k
1274
        else
1276
        else
1275
          klo=k
1277
          klo=k
1276
        endif
1278
        endif
1277
      goto 1
1279
      goto 1
1278
      endif
1280
      endif
1279
      h=xa(khi)-xa(klo)
1281
      h=xa(khi)-xa(klo)
1280
      if (h.eq.0.) pause 'bad xa input in splint'
1282
c      if (h.eq.0.) pause 'bad xa input in splint'
-
 
1283
      if (h.eq.0.) then
-
 
1284
        write(*,*) 'bad xa input in splint'
-
 
1285
        read(*,*)
-
 
1286
      end if
1281
      a=(xa(khi)-x)/h
1287
      a=(xa(khi)-x)/h
1282
      b=(x-xa(klo))/h
1288
      b=(x-xa(klo))/h
1283
      y=a*ya(klo)+b*ya(khi)+((a**3-a)*y2a(klo)+(b**3-b)*y2a(khi))*(h**
1289
      y=a*ya(klo)+b*ya(khi)+((a**3-a)*y2a(klo)+(b**3-b)*y2a(khi))*(h**
1284
     *2)/6.
1290
     *2)/6.
1285
      return
1291
      return
1286
      END
1292
      END
1287
 
1293
 
1288
c     ********************************************************************
1294
c     ********************************************************************
1289
c     * INPUT / OUTPUT SUBROUTINES                                       *
1295
c     * INPUT / OUTPUT SUBROUTINES                                       *
1290
c     ********************************************************************
1296
c     ********************************************************************
1291
 
1297
 
1292
 
1298
 
1293
c     --------------------------------------------------------------------
1299
c     --------------------------------------------------------------------
1294
c     Subroutines to write the CF netcdf output file
1300
c     Subroutines to write the CF netcdf output file
1295
c     --------------------------------------------------------------------
1301
c     --------------------------------------------------------------------
1296
 
1302
 
1297
      subroutine writecdf2D_cf 
1303
      subroutine writecdf2D_cf 
1298
     >          (cdfname,varname,longname,unit,gridtype,clon,clat,
1304
     >          (cdfname,varname,longname,unit,gridtype,clon,clat,
1299
     >           nlonlat,dlonlat,arr,time,dx,dy,xmin,ymin,nx,ny,
1305
     >           nlonlat,dlonlat,arr,time,dx,dy,xmin,ymin,nx,ny,
1300
     >           crefile,crevar,cretime,pollon,pollat)
1306
     >           crefile,crevar,cretime,pollon,pollat)
1301
 
1307
 
1302
c     Create and write to the CF netcdf file <cdfname>. The variable
1308
c     Create and write to the CF netcdf file <cdfname>. The variable
1303
c     with name <varname> and with time <time> is written. The data
1309
c     with name <varname> and with time <time> is written. The data
1304
c     are in the two-dimensional array <arr>. The list <dx,dy,xmin,
1310
c     are in the two-dimensional array <arr>. The list <dx,dy,xmin,
1305
c     ymin,nx,ny> specifies the output grid. The flags <crefile> and
1311
c     ymin,nx,ny> specifies the output grid. The flags <crefile> and
1306
c     <crevar> determine whether the file and/or the variable should
1312
c     <crevar> determine whether the file and/or the variable should
1307
c     be created; correspondingly for the unlimited dimension <time>
1313
c     be created; correspondingly for the unlimited dimension <time>
1308
c     with the flag <cretime>.
1314
c     with the flag <cretime>.
1309
 
1315
 
1310
      USE netcdf
1316
      USE netcdf
1311
 
1317
 
1312
      IMPLICIT NONE
1318
      IMPLICIT NONE
1313
 
1319
 
1314
c     Declaration of input parameters
1320
c     Declaration of input parameters
1315
      character*80 cdfname
1321
      character*80 cdfname
1316
      character*80 varname,longname,unit
1322
      character*80 varname,longname,unit
1317
      integer      nx,ny
1323
      integer      nx,ny
1318
      real         arr(nx,ny)
1324
      real         arr(nx,ny)
1319
      real         dx,dy,xmin,ymin
1325
      real         dx,dy,xmin,ymin
1320
      real         time
1326
      real         time
1321
      integer      crefile,crevar,cretime
1327
      integer      crefile,crevar,cretime
1322
      character*80 gridtype
1328
      character*80 gridtype
1323
      real         clon,clat
1329
      real         clon,clat
1324
      integer      nlonlat
1330
      integer      nlonlat
1325
      real         dlonlat
1331
      real         dlonlat
1326
      real         pollon,pollat
1332
      real         pollon,pollat
1327
 
1333
 
1328
c     Local variables
1334
c     Local variables
1329
      integer      ierr
1335
      integer      ierr
1330
      integer      ncID
1336
      integer      ncID
1331
      integer      LonDimId,    varLonID
1337
      integer      LonDimId,    varLonID
1332
      integer      LatDimID,    varLatID
1338
      integer      LatDimID,    varLatID
1333
      integer      TimeDimID,   varTimeID
1339
      integer      TimeDimID,   varTimeID
1334
      real         longitude(nx)
1340
      real         longitude(nx)
1335
      real         latitude (ny)
1341
      real         latitude (ny)
1336
      real         timeindex
1342
      real         timeindex
1337
      integer      i
1343
      integer      i
1338
      integer      nvars,varids(100)
1344
      integer      nvars,varids(100)
1339
      integer      ndims,dimids(100)
1345
      integer      ndims,dimids(100)
1340
      real         timelist(1000)
1346
      real         timelist(1000)
1341
      integer      ntimes
1347
      integer      ntimes
1342
      integer      ind
1348
      integer      ind
1343
      integer      varID
1349
      integer      varID
1344
 
1350
 
1345
c     Quick an dirty solution for fieldname conflict
1351
c     Quick an dirty solution for fieldname conflict
1346
      if ( varname.eq.'time' ) varname = 'TIME'
1352
      if ( varname.eq.'time' ) varname = 'TIME'
1347
 
1353
 
1348
c     Initially set error to indicate no errors.
1354
c     Initially set error to indicate no errors.
1349
      ierr = 0
1355
      ierr = 0
1350
 
1356
 
1351
c     ---- Create the netCDF - skip if <crefile=0> ----------------------
1357
c     ---- Create the netCDF - skip if <crefile=0> ----------------------
1352
      if ( crefile.ne.1 ) goto 100
1358
      if ( crefile.ne.1 ) goto 100
1353
 
1359
 
1354
c     Create the file 
1360
c     Create the file 
1355
      ierr = nf90_create(trim(cdfname), NF90_CLOBBER, ncID)
1361
      ierr = nf90_create(trim(cdfname), NF90_CLOBBER, ncID)
1356
      
1362
      
1357
c     Define dimensions 
1363
c     Define dimensions 
1358
      ierr=nf90_def_dim(ncID,'longitude',nx            , LonDimID )
1364
      ierr=nf90_def_dim(ncID,'longitude',nx            , LonDimID )
1359
      ierr=nf90_def_dim(ncID,'latitude' ,ny            , LatDimID )
1365
      ierr=nf90_def_dim(ncID,'latitude' ,ny            , LatDimID )
1360
      ierr=nf90_def_dim(ncID,'time'     ,nf90_unlimited, TimeDimID)
1366
      ierr=nf90_def_dim(ncID,'time'     ,nf90_unlimited, TimeDimID)
1361
      
1367
      
1362
c     Define coordinate Variables 
1368
c     Define coordinate Variables 
1363
      ierr = nf90_def_var(ncID,'longitude',NF90_FLOAT,
1369
      ierr = nf90_def_var(ncID,'longitude',NF90_FLOAT,
1364
     >     (/ LonDimID /),varLonID)
1370
     >     (/ LonDimID /),varLonID)
1365
      ierr = nf90_put_att(ncID, varLonID, "standard_name","longitude")
1371
      ierr = nf90_put_att(ncID, varLonID, "standard_name","longitude")
1366
      ierr = nf90_put_att(ncID, varLonID, "units"      ,"degree_east")
1372
      ierr = nf90_put_att(ncID, varLonID, "units"      ,"degree_east")
1367
      
1373
      
1368
      ierr = nf90_def_var(ncID,'latitude',NF90_FLOAT,
1374
      ierr = nf90_def_var(ncID,'latitude',NF90_FLOAT,
1369
     >     (/ LatDimID /),varLatID)
1375
     >     (/ LatDimID /),varLatID)
1370
      ierr = nf90_put_att(ncID, varLatID, "standard_name", "latitude")
1376
      ierr = nf90_put_att(ncID, varLatID, "standard_name", "latitude")
1371
      ierr = nf90_put_att(ncID, varLatID, "units"    ,"degree_north")
1377
      ierr = nf90_put_att(ncID, varLatID, "units"    ,"degree_north")
1372
      
1378
      
1373
      ierr = nf90_def_var(ncID,'time',NF90_FLOAT, 
1379
      ierr = nf90_def_var(ncID,'time',NF90_FLOAT, 
1374
     >     (/ TimeDimID /), varTimeID)
1380
     >     (/ TimeDimID /), varTimeID)
1375
      ierr = nf90_put_att(ncID, varTimeID, "axis",            "T")
1381
      ierr = nf90_put_att(ncID, varTimeID, "axis",            "T")
1376
      ierr = nf90_put_att(ncID, varTimeID, "calendar", "standard")
1382
      ierr = nf90_put_att(ncID, varTimeID, "calendar", "standard")
1377
      ierr = nf90_put_att(ncID, varTimeID, "long_name",    "time")
1383
      ierr = nf90_put_att(ncID, varTimeID, "long_name",    "time")
1378
      ierr = nf90_put_att(ncID, varTimeID, "units",       "hours")
1384
      ierr = nf90_put_att(ncID, varTimeID, "units",       "hours")
1379
      
1385
      
1380
c     Write global attributes 
1386
c     Write global attributes 
1381
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'Conventions', 'CF-1.0')
1387
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'Conventions', 'CF-1.0')
1382
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'title',  
1388
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'title',  
1383
     >     'Trajectory Densities')
1389
     >     'Trajectory Densities')
1384
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'source', 
1390
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'source', 
1385
     >     'Lagranto Trajectories')
1391
     >     'Lagranto Trajectories')
1386
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'institution', 
1392
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'institution', 
1387
     >     'ETH Zurich, IACETH')
1393
     >     'ETH Zurich, IACETH')
1388
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'grid',trim(gridtype) ) 
1394
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'grid',trim(gridtype) ) 
1389
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'clon',clon )
1395
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'clon',clon )
1390
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'clat',clat )
1396
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'clat',clat )
1391
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'nlonlat',nlonlat )
1397
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'nlonlat',nlonlat )
1392
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'dlonlat',dlonlat )
1398
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'dlonlat',dlonlat )
1393
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'nx',nx )
1399
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'nx',nx )
1394
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'ny',ny )
1400
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'ny',ny )
1395
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'dx',dx )
1401
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'dx',dx )
1396
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'dy',dy )
1402
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'dy',dy )
1397
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'xmin',xmin )
1403
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'xmin',xmin )
1398
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'ymin',ymin )
1404
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'ymin',ymin )
1399
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'pollon',pollon )
1405
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'pollon',pollon )
1400
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'pollat',pollat )
1406
      ierr = nf90_put_att(ncID, NF90_GLOBAL, 'pollat',pollat )
1401
 
1407
 
1402
c     Write coordinate data 
1408
c     Write coordinate data 
1403
      do i = 1,nx+1
1409
      do i = 1,nx+1
1404
         longitude(i) = xmin + real(i-1) * dx
1410
         longitude(i) = xmin + real(i-1) * dx
1405
      enddo
1411
      enddo
1406
      do i = 1,ny+1
1412
      do i = 1,ny+1
1407
         latitude(i)  = ymin + real(i-1) * dy
1413
         latitude(i)  = ymin + real(i-1) * dy
1408
      enddo
1414
      enddo
1409
      
1415
      
1410
c     Check whether the definition was successful
1416
c     Check whether the definition was successful
1411
      ierr = nf90_enddef(ncID)
1417
      ierr = nf90_enddef(ncID)
1412
      if (ierr.gt.0) then
1418
      if (ierr.gt.0) then
1413
         print*, 'An error occurred while attempting to ', 
1419
         print*, 'An error occurred while attempting to ', 
1414
     >        'finish definition mode.'
1420
     >        'finish definition mode.'
1415
         stop
1421
         stop
1416
      endif
1422
      endif
1417
      
1423
      
1418
c     Write coordinate data  
1424
c     Write coordinate data  
1419
      ierr = nf90_put_var(ncID,varLonID ,longitude)
1425
      ierr = nf90_put_var(ncID,varLonID ,longitude)
1420
      ierr = nf90_put_var(ncID,varLatID ,latitude )
1426
      ierr = nf90_put_var(ncID,varLatID ,latitude )
1421
      
1427
      
1422
c     Close netCDF file 
1428
c     Close netCDF file 
1423
      ierr = nf90_close(ncID)
1429
      ierr = nf90_close(ncID)
1424
      
1430
      
1425
 100  continue
1431
 100  continue
1426
 
1432
 
1427
c     ---- Define a new variable - skip if <crevar=0> -----------------------
1433
c     ---- Define a new variable - skip if <crevar=0> -----------------------
1428
 
1434
 
1429
      if ( crevar.ne.1 ) goto 110
1435
      if ( crevar.ne.1 ) goto 110
1430
      
1436
      
1431
c     Open the file for read(write access
1437
c     Open the file for read(write access
1432
      ierr = nf90_open  (trim(cdfname), NF90_WRITE  , ncID)
1438
      ierr = nf90_open  (trim(cdfname), NF90_WRITE  , ncID)
1433
 
1439
 
1434
c     Get the IDs for dimensions
1440
c     Get the IDs for dimensions
1435
      ierr = nf90_inq_dimid(ncID,'longitude', LonDimID )
1441
      ierr = nf90_inq_dimid(ncID,'longitude', LonDimID )
1436
      ierr = nf90_inq_dimid(ncID,'latitude' , LatDimID )
1442
      ierr = nf90_inq_dimid(ncID,'latitude' , LatDimID )
1437
      ierr = nf90_inq_dimid(ncID,'time'     , TimeDimID)
1443
      ierr = nf90_inq_dimid(ncID,'time'     , TimeDimID)
1438
 
1444
 
1439
c     Enter define mode
1445
c     Enter define mode
1440
      ierr = nf90_redef(ncID)
1446
      ierr = nf90_redef(ncID)
1441
 
1447
 
1442
c     Write definition and add attributes
1448
c     Write definition and add attributes
1443
      ierr = nf90_def_var(ncID,varname,NF90_FLOAT,
1449
      ierr = nf90_def_var(ncID,varname,NF90_FLOAT,
1444
     >                   (/ LonDimID, LatDimID, TimeDimID /),varID)
1450
     >                   (/ LonDimID, LatDimID, TimeDimID /),varID)
1445
      ierr = nf90_put_att(ncID, varID, "long_name" , longname )
1451
      ierr = nf90_put_att(ncID, varID, "long_name" , longname )
1446
      ierr = nf90_put_att(ncID, varID, "units"     , unit     ) 
1452
      ierr = nf90_put_att(ncID, varID, "units"     , unit     ) 
1447
      ierr = nf90_put_att(ncID, varID, '_FillValue', -999.99  ) 
1453
      ierr = nf90_put_att(ncID, varID, '_FillValue', -999.99  ) 
1448
 
1454
 
1449
c     Check whether definition was successful
1455
c     Check whether definition was successful
1450
      ierr = nf90_enddef(ncID)
1456
      ierr = nf90_enddef(ncID)
1451
      if (ierr.gt.0) then
1457
      if (ierr.gt.0) then
1452
         print*, 'An error occurred while attempting to ', 
1458
         print*, 'An error occurred while attempting to ', 
1453
     >           'finish definition mode.'
1459
     >           'finish definition mode.'
1454
         stop
1460
         stop
1455
      endif
1461
      endif
1456
 
1462
 
1457
c     Close netCDF file 
1463
c     Close netCDF file 
1458
      ierr = nf90_close(ncID)
1464
      ierr = nf90_close(ncID)
1459
 
1465
 
1460
 110  continue
1466
 110  continue
1461
 
1467
 
1462
c     ---- Create a new time (unlimited dimension) - skip if <cretime=0> ------
1468
c     ---- Create a new time (unlimited dimension) - skip if <cretime=0> ------
1463
 
1469
 
1464
      if ( cretime.ne.1 ) goto 120
1470
      if ( cretime.ne.1 ) goto 120
1465
 
1471
 
1466
c     Open the file for read/write access
1472
c     Open the file for read/write access
1467
      ierr = nf90_open  (trim(cdfname), NF90_WRITE, ncID)
1473
      ierr = nf90_open  (trim(cdfname), NF90_WRITE, ncID)
1468
      
1474
      
1469
c     Get the list of times on the netCDF file
1475
c     Get the list of times on the netCDF file
1470
      ierr = nf90_inq_dimid(ncID,'time', TimeDimID)
1476
      ierr = nf90_inq_dimid(ncID,'time', TimeDimID)
1471
      if ( ierr.ne.0 ) then
1477
      if ( ierr.ne.0 ) then
1472
         print*,'Time dimension is not defined on ',trim(cdfname),
1478
         print*,'Time dimension is not defined on ',trim(cdfname),
1473
     >          ' .... Stop'
1479
     >          ' .... Stop'
1474
         stop
1480
         stop
1475
      endif
1481
      endif
1476
      ierr = nf90_inquire_dimension(ncID, TimeDimID, len = ntimes)
1482
      ierr = nf90_inquire_dimension(ncID, TimeDimID, len = ntimes)
1477
      ierr = nf90_inq_varid(ncID,'time', varTimeID)
1483
      ierr = nf90_inq_varid(ncID,'time', varTimeID)
1478
      if ( ierr.ne.0 ) then
1484
      if ( ierr.ne.0 ) then
1479
         print*,'Variable time is not defined on ',trim(cdfname),
1485
         print*,'Variable time is not defined on ',trim(cdfname),
1480
     >          ' ... Stop'
1486
     >          ' ... Stop'
1481
         stop
1487
         stop
1482
      endif
1488
      endif
1483
      ierr = nf90_get_var(ncID,varTimeID,timelist(1:ntimes))
1489
      ierr = nf90_get_var(ncID,varTimeID,timelist(1:ntimes))
1484
 
1490
 
1485
c     Decide whether a new time must be written
1491
c     Decide whether a new time must be written
1486
      ind = 0
1492
      ind = 0
1487
      do i=1,ntimes
1493
      do i=1,ntimes
1488
         if ( time.eq.timelist(i) ) ind = i
1494
         if ( time.eq.timelist(i) ) ind = i
1489
      enddo
1495
      enddo
1490
 
1496
 
1491
c     Extend the time list if required 
1497
c     Extend the time list if required 
1492
      if ( ind.eq.0 ) then
1498
      if ( ind.eq.0 ) then
1493
         ntimes           = ntimes + 1
1499
         ntimes           = ntimes + 1
1494
         timelist(ntimes) = time
1500
         timelist(ntimes) = time
1495
         ierr = nf90_put_var(ncID,varTimeID,timelist(1:ntimes))
1501
         ierr = nf90_put_var(ncID,varTimeID,timelist(1:ntimes))
1496
      endif
1502
      endif
1497
 
1503
 
1498
c     Close netCDF file 
1504
c     Close netCDF file 
1499
      ierr = nf90_close(ncID)
1505
      ierr = nf90_close(ncID)
1500
 
1506
 
1501
 120  continue
1507
 120  continue
1502
 
1508
 
1503
c     ---- Write data --------------------------------------------------
1509
c     ---- Write data --------------------------------------------------
1504
 
1510
 
1505
c     Open the file for read/write access
1511
c     Open the file for read/write access
1506
      ierr = nf90_open  (trim(cdfname), NF90_WRITE , ncID)
1512
      ierr = nf90_open  (trim(cdfname), NF90_WRITE , ncID)
1507
 
1513
 
1508
c     Get the varID
1514
c     Get the varID
1509
      ierr = nf90_inq_varid(ncID,varname, varID )
1515
      ierr = nf90_inq_varid(ncID,varname, varID )
1510
      if (ierr.ne.0) then
1516
      if (ierr.ne.0) then
1511
         print*,'Variable ',trim(varname),' is not defined on ',
1517
         print*,'Variable ',trim(varname),' is not defined on ',
1512
     >          trim(cdfname)
1518
     >          trim(cdfname)
1513
         stop
1519
         stop
1514
      endif
1520
      endif
1515
 
1521
 
1516
c     Get the time index
1522
c     Get the time index
1517
      ierr = nf90_inq_dimid(ncID,'time', TimeDimID)
1523
      ierr = nf90_inq_dimid(ncID,'time', TimeDimID)
1518
      if ( ierr.ne.0 ) then
1524
      if ( ierr.ne.0 ) then
1519
         print*,'Time dimension is not defined on ',trim(cdfname),
1525
         print*,'Time dimension is not defined on ',trim(cdfname),
1520
     >          ' .... Stop'
1526
     >          ' .... Stop'
1521
         stop
1527
         stop
1522
      endif
1528
      endif
1523
      ierr = nf90_inquire_dimension(ncID, TimeDimID, len = ntimes)
1529
      ierr = nf90_inquire_dimension(ncID, TimeDimID, len = ntimes)
1524
      ierr = nf90_inq_varid(ncID,'time', varTimeID)
1530
      ierr = nf90_inq_varid(ncID,'time', varTimeID)
1525
      if ( ierr.ne.0 ) then
1531
      if ( ierr.ne.0 ) then
1526
         print*,'Variable time is not defined on ',trim(cdfname),
1532
         print*,'Variable time is not defined on ',trim(cdfname),
1527
     >          ' ... Stop'
1533
     >          ' ... Stop'
1528
         stop
1534
         stop
1529
      endif
1535
      endif
1530
      ierr = nf90_get_var(ncID,varTimeID,timelist(1:ntimes))
1536
      ierr = nf90_get_var(ncID,varTimeID,timelist(1:ntimes))
1531
      ind = 0
1537
      ind = 0
1532
      do i=1,ntimes
1538
      do i=1,ntimes
1533
         if ( time.eq.timelist(i) ) ind = i
1539
         if ( time.eq.timelist(i) ) ind = i
1534
      enddo
1540
      enddo
1535
      if (ind.eq.0) then
1541
      if (ind.eq.0) then
1536
         print*,'Time',time,' is not defined on the netCDF file',
1542
         print*,'Time',time,' is not defined on the netCDF file',
1537
     >          trim(cdfname),' ... Stop'
1543
     >          trim(cdfname),' ... Stop'
1538
         stop
1544
         stop
1539
      endif
1545
      endif
1540
 
1546
 
1541
c     Write data block      
1547
c     Write data block      
1542
      ierr = nf90_put_var(ncID,varID,arr,
1548
      ierr = nf90_put_var(ncID,varID,arr,
1543
     >                    start = (/ 1, 1, ind /), 
1549
     >                    start = (/ 1, 1, ind /), 
1544
     >                    count = (/ nx, ny, 1 /) )
1550
     >                    count = (/ nx, ny, 1 /) )
1545
 
1551
 
1546
c     Check whether writing was successful 
1552
c     Check whether writing was successful 
1547
      ierr = nf90_close(ncID)
1553
      ierr = nf90_close(ncID)
1548
      if (ierr.ne.0) then
1554
      if (ierr.ne.0) then
1549
         write(*,*) trim(nf90_strerror(ierr))
1555
         write(*,*) trim(nf90_strerror(ierr))
1550
         write(*,*) 'An error occurred while attempting to ', 
1556
         write(*,*) 'An error occurred while attempting to ', 
1551
     >              'close the netcdf file.'
1557
     >              'close the netcdf file.'
1552
         write(*,*) 'in clscdf_CF'
1558
         write(*,*) 'in clscdf_CF'
1553
      endif
1559
      endif
1554
 
1560
 
1555
      end
1561
      end
1556
 
1562
 
1557
 
1563
 
1558
c     ********************************************************************************
1564
c     ********************************************************************************
1559
c     * Transformation routine: LMSTOLM and PHSTOPH from library gm2em               *
1565
c     * Transformation routine: LMSTOLM and PHSTOPH from library gm2em               *
1560
c     ********************************************************************************
1566
c     ********************************************************************************
1561
 
1567
 
1562
      REAL FUNCTION LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
1568
      REAL FUNCTION LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
1563
C
1569
C
1564
C**** LMSTOLM  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
1570
C**** LMSTOLM  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
1565
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
1571
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
1566
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
1572
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
1567
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1573
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1568
C**   AUFRUF   :   LAM = LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
1574
C**   AUFRUF   :   LAM = LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
1569
C**   ENTRIES  :   KEINE
1575
C**   ENTRIES  :   KEINE
1570
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
1576
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
1571
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
1577
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
1572
C**                IM ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
1578
C**                IM ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
1573
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1579
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1574
C**   VERSIONS-
1580
C**   VERSIONS-
1575
C**   DATUM    :   03.05.90
1581
C**   DATUM    :   03.05.90
1576
C**
1582
C**
1577
C**   EXTERNALS:   KEINE
1583
C**   EXTERNALS:   KEINE
1578
C**   EINGABE-
1584
C**   EINGABE-
1579
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
1585
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
1580
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
1586
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
1581
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
1587
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
1582
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
1588
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
1583
C**   AUSGABE-
1589
C**   AUSGABE-
1584
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
1590
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
1585
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
1591
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
1586
C**
1592
C**
1587
C**   COMMON-
1593
C**   COMMON-
1588
C**   BLOECKE  :   KEINE
1594
C**   BLOECKE  :   KEINE
1589
C**
1595
C**
1590
C**   FEHLERBE-
1596
C**   FEHLERBE-
1591
C**   HANDLUNG :   KEINE
1597
C**   HANDLUNG :   KEINE
1592
C**   VERFASSER:   D.MAJEWSKI
1598
C**   VERFASSER:   D.MAJEWSKI
1593
 
1599
 
1594
      REAL        LAMS,PHIS,POLPHI,POLLAM
1600
      REAL        LAMS,PHIS,POLPHI,POLLAM
1595
 
1601
 
1596
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
1602
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
1597
 
1603
 
1598
      ZSINPOL = SIN(ZPIR18*POLPHI)
1604
      ZSINPOL = SIN(ZPIR18*POLPHI)
1599
      ZCOSPOL = COS(ZPIR18*POLPHI)
1605
      ZCOSPOL = COS(ZPIR18*POLPHI)
1600
      ZLAMPOL = ZPIR18*POLLAM
1606
      ZLAMPOL = ZPIR18*POLLAM
1601
      ZPHIS   = ZPIR18*PHIS
1607
      ZPHIS   = ZPIR18*PHIS
1602
      ZLAMS   = LAMS
1608
      ZLAMS   = LAMS
1603
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
1609
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
1604
      ZLAMS   = ZPIR18*ZLAMS
1610
      ZLAMS   = ZPIR18*ZLAMS
1605
 
1611
 
1606
      ZARG1   = SIN(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
1612
      ZARG1   = SIN(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
1607
     1                          ZCOSPOL*           SIN(ZPHIS)) -
1613
     1                          ZCOSPOL*           SIN(ZPHIS)) -
1608
     2          COS(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
1614
     2          COS(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
1609
      ZARG2   = COS(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
1615
      ZARG2   = COS(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
1610
     1                          ZCOSPOL*           SIN(ZPHIS)) +
1616
     1                          ZCOSPOL*           SIN(ZPHIS)) +
1611
     2          SIN(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
1617
     2          SIN(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
1612
      IF (ABS(ZARG2).LT.1.E-30) THEN
1618
      IF (ABS(ZARG2).LT.1.E-30) THEN
1613
        IF (ABS(ZARG1).LT.1.E-30) THEN
1619
        IF (ABS(ZARG1).LT.1.E-30) THEN
1614
          LMSTOLM =   0.0
1620
          LMSTOLM =   0.0
1615
        ELSEIF (ZARG1.GT.0.) THEN
1621
        ELSEIF (ZARG1.GT.0.) THEN
1616
              LMSTOLAM =  90.0
1622
              LMSTOLAM =  90.0
1617
            ELSE
1623
            ELSE
1618
              LMSTOLAM = -90.0
1624
              LMSTOLAM = -90.0
1619
            ENDIF
1625
            ENDIF
1620
      ELSE
1626
      ELSE
1621
        LMSTOLM = ZRPI18*ATAN2(ZARG1,ZARG2)
1627
        LMSTOLM = ZRPI18*ATAN2(ZARG1,ZARG2)
1622
      ENDIF
1628
      ENDIF
1623
 
1629
 
1624
      RETURN
1630
      RETURN
1625
      END
1631
      END
1626
 
1632
 
1627
 
1633
 
1628
      REAL FUNCTION PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
1634
      REAL FUNCTION PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
1629
C
1635
C
1630
C**** PHSTOPH  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
1636
C**** PHSTOPH  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
1631
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
1637
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
1632
C****                 ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
1638
C****                 ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
1633
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1639
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1634
C**   AUFRUF   :   PHI = PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
1640
C**   AUFRUF   :   PHI = PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
1635
C**   ENTRIES  :   KEINE
1641
C**   ENTRIES  :   KEINE
1636
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
1642
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
1637
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
1643
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
1638
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
1644
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
1639
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1645
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1640
C**   VERSIONS-
1646
C**   VERSIONS-
1641
C**   DATUM    :   03.05.90
1647
C**   DATUM    :   03.05.90
1642
C**
1648
C**
1643
C**   EXTERNALS:   KEINE
1649
C**   EXTERNALS:   KEINE
1644
C**   EINGABE-
1650
C**   EINGABE-
1645
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
1651
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
1646
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
1652
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
1647
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
1653
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
1648
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
1654
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
1649
C**   AUSGABE-
1655
C**   AUSGABE-
1650
C**   PARAMETER:   WAHRE GEOGRAPHISCHE BREITE ALS WERT DER FUNKTION
1656
C**   PARAMETER:   WAHRE GEOGRAPHISCHE BREITE ALS WERT DER FUNKTION
1651
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
1657
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
1652
C**
1658
C**
1653
C**   COMMON-
1659
C**   COMMON-
1654
C**   BLOECKE  :   KEINE
1660
C**   BLOECKE  :   KEINE
1655
C**
1661
C**
1656
C**   FEHLERBE-
1662
C**   FEHLERBE-
1657
C**   HANDLUNG :   KEINE
1663
C**   HANDLUNG :   KEINE
1658
C**   VERFASSER:   D.MAJEWSKI
1664
C**   VERFASSER:   D.MAJEWSKI
1659
 
1665
 
1660
      REAL        LAMS,PHIS,POLPHI,POLLAM
1666
      REAL        LAMS,PHIS,POLPHI,POLLAM
1661
 
1667
 
1662
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
1668
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
1663
 
1669
 
1664
      SINPOL = SIN(ZPIR18*POLPHI)
1670
      SINPOL = SIN(ZPIR18*POLPHI)
1665
      COSPOL = COS(ZPIR18*POLPHI)
1671
      COSPOL = COS(ZPIR18*POLPHI)
1666
      ZPHIS  = ZPIR18*PHIS
1672
      ZPHIS  = ZPIR18*PHIS
1667
      ZLAMS  = LAMS
1673
      ZLAMS  = LAMS
1668
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
1674
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
1669
      ZLAMS  = ZPIR18*ZLAMS
1675
      ZLAMS  = ZPIR18*ZLAMS
1670
      ARG     = COSPOL*COS(ZPHIS)*COS(ZLAMS) + SINPOL*SIN(ZPHIS)
1676
      ARG     = COSPOL*COS(ZPHIS)*COS(ZLAMS) + SINPOL*SIN(ZPHIS)
1671
 
1677
 
1672
      PHSTOPH = ZRPI18*ASIN(ARG)
1678
      PHSTOPH = ZRPI18*ASIN(ARG)
1673
 
1679
 
1674
      RETURN
1680
      RETURN
1675
      END
1681
      END
1676
 
1682
 
1677
 
1683
 
1678
      REAL FUNCTION LMTOLMS (PHI, LAM, POLPHI, POLLAM)
1684
      REAL FUNCTION LMTOLMS (PHI, LAM, POLPHI, POLLAM)
1679
C
1685
C
1680
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
1686
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
1681
C
1687
C
1682
C**** LMTOLMS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM
1688
C**** LMTOLMS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM
1683
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
1689
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
1684
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
1690
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
1685
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1691
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1686
C**   AUFRUF   :   LAM = LMTOLMS (PHI, LAM, POLPHI, POLLAM)
1692
C**   AUFRUF   :   LAM = LMTOLMS (PHI, LAM, POLPHI, POLLAM)
1687
C**   ENTRIES  :   KEINE
1693
C**   ENTRIES  :   KEINE
1688
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM AUF
1694
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM AUF
1689
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
1695
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
1690
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
1696
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
1691
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1697
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1692
C**   VERSIONS-
1698
C**   VERSIONS-
1693
C**   DATUM    :   03.05.90
1699
C**   DATUM    :   03.05.90
1694
C**
1700
C**
1695
C**   EXTERNALS:   KEINE
1701
C**   EXTERNALS:   KEINE
1696
C**   EINGABE-
1702
C**   EINGABE-
1697
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
1703
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
1698
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
1704
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
1699
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
1705
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
1700
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
1706
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
1701
C**   AUSGABE-
1707
C**   AUSGABE-
1702
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
1708
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
1703
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
1709
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
1704
C**
1710
C**
1705
C**   COMMON-
1711
C**   COMMON-
1706
C**   BLOECKE  :   KEINE
1712
C**   BLOECKE  :   KEINE
1707
C**
1713
C**
1708
C**   FEHLERBE-
1714
C**   FEHLERBE-
1709
C**   HANDLUNG :   KEINE
1715
C**   HANDLUNG :   KEINE
1710
C**   VERFASSER:   G. DE MORSIER
1716
C**   VERFASSER:   G. DE MORSIER
1711
 
1717
 
1712
      REAL        LAM,PHI,POLPHI,POLLAM
1718
      REAL        LAM,PHI,POLPHI,POLLAM
1713
 
1719
 
1714
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
1720
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
1715
 
1721
 
1716
      ZSINPOL = SIN(ZPIR18*POLPHI)
1722
      ZSINPOL = SIN(ZPIR18*POLPHI)
1717
      ZCOSPOL = COS(ZPIR18*POLPHI)
1723
      ZCOSPOL = COS(ZPIR18*POLPHI)
1718
      ZLAMPOL =     ZPIR18*POLLAM
1724
      ZLAMPOL =     ZPIR18*POLLAM
1719
      ZPHI    =     ZPIR18*PHI
1725
      ZPHI    =     ZPIR18*PHI
1720
      ZLAM    = LAM
1726
      ZLAM    = LAM
1721
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
1727
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
1722
      ZLAM    = ZPIR18*ZLAM
1728
      ZLAM    = ZPIR18*ZLAM
1723
 
1729
 
1724
      ZARG1   = - SIN(ZLAM-ZLAMPOL)*COS(ZPHI)
1730
      ZARG1   = - SIN(ZLAM-ZLAMPOL)*COS(ZPHI)
1725
      ZARG2   = - ZSINPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL)+ZCOSPOL*SIN(ZPHI)
1731
      ZARG2   = - ZSINPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL)+ZCOSPOL*SIN(ZPHI)
1726
      IF (ABS(ZARG2).LT.1.E-30) THEN
1732
      IF (ABS(ZARG2).LT.1.E-30) THEN
1727
        IF (ABS(ZARG1).LT.1.E-30) THEN
1733
        IF (ABS(ZARG1).LT.1.E-30) THEN
1728
          LMTOLMS =   0.0
1734
          LMTOLMS =   0.0
1729
        ELSEIF (ZARG1.GT.0.) THEN
1735
        ELSEIF (ZARG1.GT.0.) THEN
1730
              LMTOLMS =  90.0
1736
              LMTOLMS =  90.0
1731
            ELSE
1737
            ELSE
1732
              LMTOLMS = -90.0
1738
              LMTOLMS = -90.0
1733
            ENDIF
1739
            ENDIF
1734
      ELSE
1740
      ELSE
1735
        LMTOLMS = ZRPI18*ATAN2(ZARG1,ZARG2)
1741
        LMTOLMS = ZRPI18*ATAN2(ZARG1,ZARG2)
1736
      ENDIF
1742
      ENDIF
1737
 
1743
 
1738
      RETURN
1744
      RETURN
1739
      END
1745
      END
1740
 
1746
 
1741
 
1747
 
1742
      REAL FUNCTION PHTOPHS (PHI, LAM, POLPHI, POLLAM)
1748
      REAL FUNCTION PHTOPHS (PHI, LAM, POLPHI, POLLAM)
1743
C
1749
C
1744
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
1750
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
1745
C
1751
C
1746
C**** PHTOPHS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI
1752
C**** PHTOPHS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI
1747
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
1753
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
1748
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
1754
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
1749
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1755
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1750
C**   AUFRUF   :   PHI = PHTOPHS (PHI, LAM, POLPHI, POLLAM)
1756
C**   AUFRUF   :   PHI = PHTOPHS (PHI, LAM, POLPHI, POLLAM)
1751
C**   ENTRIES  :   KEINE
1757
C**   ENTRIES  :   KEINE
1752
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI AUF
1758
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI AUF
1753
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
1759
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
1754
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
1760
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
1755
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1761
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
1756
C**   VERSIONS-
1762
C**   VERSIONS-
1757
C**   DATUM    :   03.05.90
1763
C**   DATUM    :   03.05.90
1758
C**
1764
C**
1759
C**   EXTERNALS:   KEINE
1765
C**   EXTERNALS:   KEINE
1760
C**   EINGABE-
1766
C**   EINGABE-
1761
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
1767
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
1762
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
1768
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
1763
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
1769
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
1764
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
1770
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
1765
C**   AUSGABE-
1771
C**   AUSGABE-
1766
C**   PARAMETER:   ROTIERTE BREITE PHIS ALS WERT DER FUNKTION
1772
C**   PARAMETER:   ROTIERTE BREITE PHIS ALS WERT DER FUNKTION
1767
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
1773
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
1768
C**
1774
C**
1769
C**   COMMON-
1775
C**   COMMON-
1770
C**   BLOECKE  :   KEINE
1776
C**   BLOECKE  :   KEINE
1771
C**
1777
C**
1772
C**   FEHLERBE-
1778
C**   FEHLERBE-
1773
C**   HANDLUNG :   KEINE
1779
C**   HANDLUNG :   KEINE
1774
C**   VERFASSER:   G. DE MORSIER
1780
C**   VERFASSER:   G. DE MORSIER
1775
 
1781
 
1776
      REAL        LAM,PHI,POLPHI,POLLAM
1782
      REAL        LAM,PHI,POLPHI,POLLAM
1777
 
1783
 
1778
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
1784
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
1779
 
1785
 
1780
      ZSINPOL = SIN(ZPIR18*POLPHI)
1786
      ZSINPOL = SIN(ZPIR18*POLPHI)
1781
      ZCOSPOL = COS(ZPIR18*POLPHI)
1787
      ZCOSPOL = COS(ZPIR18*POLPHI)
1782
      ZLAMPOL = ZPIR18*POLLAM
1788
      ZLAMPOL = ZPIR18*POLLAM
1783
      ZPHI    = ZPIR18*PHI
1789
      ZPHI    = ZPIR18*PHI
1784
      ZLAM    = LAM
1790
      ZLAM    = LAM
1785
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
1791
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
1786
      ZLAM    = ZPIR18*ZLAM
1792
      ZLAM    = ZPIR18*ZLAM
1787
      ZARG    = ZCOSPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL) + ZSINPOL*SIN(ZPHI)
1793
      ZARG    = ZCOSPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL) + ZSINPOL*SIN(ZPHI)
1788
 
1794
 
1789
      PHTOPHS = ZRPI18*ASIN(ZARG)
1795
      PHTOPHS = ZRPI18*ASIN(ZARG)
1790
 
1796
 
1791
      RETURN
1797
      RETURN
1792
      END
1798
      END