Subversion Repositories lagranto.ecmwf

Rev

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

Rev 23 Rev 39
1
      PROGRAM getmima
1
      PROGRAM getmima
2
 
2
 
3
c     ***********************************************************************
3
c     ***********************************************************************
4
c     * Get minimum and maximum value of a varaiable on pressure            *
4
c     * Get minimum and maximum value of a varaiable on pressure            *
5
c     * or isentropic surface                                               *
5
c     * or isentropic surface                                               *
6
c     * Michael Sprenger / Spring, summer 2016                              *
6
c     * Michael Sprenger / Spring, summer 2016                              *
7
c     ***********************************************************************
7
c     ***********************************************************************
8
 
8
 
9
      use netcdf
9
      use netcdf
10
 
10
 
11
      implicit none
11
      implicit none
12
 
12
 
13
c     ----------------------------------------------------------------------
13
c     ----------------------------------------------------------------------
14
c     Declaration of parameters and variables
14
c     Declaration of parameters and variables
15
c     ----------------------------------------------------------------------
15
c     ----------------------------------------------------------------------
16
      
16
      
17
c     Interpolation method
17
c     Interpolation method
18
      integer   ipom
18
      integer   ipom
19
      parameter (ipom=0)    
19
      parameter (ipom=0)    
20
      
20
      
21
c     Flag for timecheck
21
c     Flag for timecheck
22
      character*80 timecheck
22
      character*80 timecheck
23
      parameter    (timecheck = 'no' )        
23
      parameter    (timecheck = 'no' )        
24
      
24
      
25
c     netCDF fields      
25
c     netCDF fields      
26
      real,allocatable, dimension (:,:)   :: sp,varf
26
      real,allocatable, dimension (:,:)   :: sp,varf
27
      real,allocatable, dimension (:,:,:) :: field,varl,tt,p3
27
      real,allocatable, dimension (:,:,:) :: field,varl,tt,p3
28
      real,allocatable, dimension (:)     :: ak,bk
28
      real,allocatable, dimension (:)     :: ak,bk
29
      integer                                stat
29
      integer                                stat
30
      character*80                           cdfnam,varnam
30
      character*80                           cdfnam,varnam
31
      character*80                           vnam(200)
31
      character*80                           vnam(200)
32
      integer                                nvars
32
      integer                                nvars
33
      integer	                             cdfid,ierr
33
      integer	                             cdfid,ierr
34
      real	                                 mdv
34
      real	                                 mdv
35
      real                                   stagz
35
      real                                   stagz
36
      
36
      
37
c     Grid description      
37
c     Grid description      
38
      real      xmin,xmax       ! Zonal grid extension
38
      real      xmin,xmax       ! Zonal grid extension
39
      real      ymin,ymax       ! Meridional grid extension
39
      real      ymin,ymax       ! Meridional grid extension
40
      integer   nx,ny,nz        ! Grid dimensions
40
      integer   nx,ny,nz        ! Grid dimensions
41
      real      dx,dy           ! Horizontal grid resolution
41
      real      dx,dy           ! Horizontal grid resolution
42
      real	    pollon,pollat   ! Pole position
42
      real	    pollon,pollat   ! Pole position
43
 
43
 
44
c     Output variables
44
c     Output variables
45
      real      min,max                      ! Minimum & maximum value
45
      real      min,max                      ! Minimum & maximum value
46
      real      lonmin,lonmax,latmin,latmax  ! Position of min & max
46
      real      lonmin,lonmax,latmin,latmax  ! Position of min & max
47
 
47
 
48
c     Auxiliary variables      
48
c     Auxiliary variables      
49
      integer        iargc
49
      integer        iargc
50
      character*(80) arg
50
      character*(80) arg
51
      real           rd
51
      real           rd
52
      integer        i,j
52
      integer        i,j
53
      integer        minindx,minindy,maxindx,maxindy
53
      integer        minindx,minindy,maxindx,maxindy
54
      character*80   tvar
54
      character*80   tvar
55
      character*1    mode
55
      character*1    mode
56
      character*80   clev
56
      character*80   clev
57
      real	         xphys,yphys
57
      real	         xphys,yphys
58
      real	         level
58
      real	         level
59
      integer        flag
59
      integer        flag
60
       
60
       
61
c     Externals      
61
c     Externals      
62
      real      lmstolm,phstoph
62
      real      lmstolm,phstoph
63
      external  lmstolm,phstoph
63
      external  lmstolm,phstoph
64
 
64
 
65
c     ----------------------------------------------------------------------
65
c     ----------------------------------------------------------------------
66
c     Preparation - argument handling, grid paraemters, memor allocation
66
c     Preparation - argument handling, grid paraemters, memor allocation
67
c     ----------------------------------------------------------------------
67
c     ----------------------------------------------------------------------
68
 
68
 
69
c     Check for sufficient requested arguments
69
c     Check for sufficient requested arguments
70
      if (iargc().lt.2) then
70
      if (iargc().lt.2) then
71
        print*,'USAGE: getmima filename var ',
71
        print*,'USAGE: getmima filename var ',
72
     >         '[lev in the form Pval or Tval]'
72
     >         '[lev in the form Pval or Tval]'
73
        call exit(1)
73
        call exit(1)
74
      endif
74
      endif
75
 
75
 
76
c     Read and transform input
76
c     Read and transform input
77
      call getarg(1,arg)
77
      call getarg(1,arg)
78
      cdfnam=trim(arg)
78
      cdfnam=trim(arg)
79
      call getarg(2,arg)
79
      call getarg(2,arg)
80
      varnam=trim(arg)
80
      varnam=trim(arg)
81
 
81
 
82
      if (iargc().eq.3) then
82
      if (iargc().eq.3) then
83
        call getarg(3,arg)
83
        call getarg(3,arg)
84
        mode=arg(1:1)
84
        mode=arg(1:1)
85
        clev=arg(2:len(arg)) 
85
        clev=arg(2:len(arg)) 
86
        call checkchar(clev,".",flag)
86
        call checkchar(clev,".",flag)
87
        if (flag.eq.0) clev=trim(clev)//"."
87
        if (flag.eq.0) clev=trim(clev)//"."
88
        read(clev,'(f10.2)') level
88
        read(clev,'(f10.2)') level
89
      else
89
      else
90
        mode='X'
90
        mode='X'
91
        level=0.
91
        level=0.
92
      endif
92
      endif
93
 
93
 
94
c     Init level type and minimum,maximum
94
c     Init level type and minimum,maximum
95
      min= 1.e19
95
      min= 1.e19
96
      max=-1.e19
96
      max=-1.e19
97
 
97
 
98
c     Open netCDF file      
98
c     Open netCDF file      
99
      call input_open (cdfid,cdfnam)
99
      call input_open (cdfid,cdfnam)
100
 
100
 
101
c     Get list of variables on file
101
c     Get list of variables on file
102
      call input_getvars (cdfid,vnam,nvars)
102
      call input_getvars (cdfid,vnam,nvars)
103
 
103
 
104
C     Get infos about data domain - in particular: dimensions
104
C     Get infos about data domain - in particular: dimensions
105
      nx       = 1
105
      nx       = 1
106
      ny       = 1
106
      ny       = 1
107
      nz       = 1
107
      nz       = 1
108
      call input_grid (-cdfid,varnam,xmin,xmax,ymin,ymax,dx,dy,nx,ny,
108
      call input_grid (-cdfid,varnam,xmin,xmax,ymin,ymax,dx,dy,nx,ny,
109
     >               0.,pollon,pollat,rd,rd,nz,rd,rd,rd,stagz,timecheck)
109
     >               0.,pollon,pollat,rd,rd,nz,rd,rd,stagz,timecheck)
110
 
110
 
111
C     Get memory for dynamic arrays
111
C     Get memory for dynamic arrays
112
      allocate(sp(nx,ny),stat=stat)
112
      allocate(sp(nx,ny),stat=stat)
113
      if (stat.ne.0) print*,'*** error allocating array sp ***'
113
      if (stat.ne.0) print*,'*** error allocating array sp ***'
114
      allocate(varf(nx,ny),stat=stat)
114
      allocate(varf(nx,ny),stat=stat)
115
      if (stat.ne.0) print*,'*** error allocating array varf ***'
115
      if (stat.ne.0) print*,'*** error allocating array varf ***'
116
      allocate(varl(nx,ny,nz),stat=stat)
116
      allocate(varl(nx,ny,nz),stat=stat)
117
      if (stat.ne.0) print*,'*** error allocating array varl ***'
117
      if (stat.ne.0) print*,'*** error allocating array varl ***'
118
      allocate(tt(nx,ny,nz),stat=stat)
118
      allocate(tt(nx,ny,nz),stat=stat)
119
      if (stat.ne.0) print*,'*** error allocating array tt ***'
119
      if (stat.ne.0) print*,'*** error allocating array tt ***'
120
      allocate(field(nx,ny,nz),stat=stat)
120
      allocate(field(nx,ny,nz),stat=stat)
121
      if (stat.ne.0) print*,'*** error allocating array field ***'
121
      if (stat.ne.0) print*,'*** error allocating array field ***'
122
      allocate(ak(nz),stat=stat)
122
      allocate(ak(nz),stat=stat)
123
      if (stat.ne.0) print*,'*** error allocating array ak ***'
123
      if (stat.ne.0) print*,'*** error allocating array ak ***'
124
      allocate(bk(nz),stat=stat)
124
      allocate(bk(nz),stat=stat)
125
      if (stat.ne.0) print*,'*** error allocating array bk ***'
125
      if (stat.ne.0) print*,'*** error allocating array bk ***'
126
   
126
   
127
c     ----------------------------------------------------------------------
127
c     ----------------------------------------------------------------------
128
c     Load data
128
c     Load data
129
c     ----------------------------------------------------------------------
129
c     ----------------------------------------------------------------------
130
 
130
 
131
c     Get grid info for variable - non-constant part  (P, PS, AK, BK)   
131
c     Get grid info for variable - non-constant part  (P, PS, AK, BK)   
132
      call input_grid                               
132
      call input_grid                               
133
     >       (cdfid,varnam,xmin,xmax,ymin,ymax,dx,dy,nx,ny,
133
     >       (cdfid,varnam,xmin,xmax,ymin,ymax,dx,dy,nx,ny,
134
     >        0.,pollon,pollat,varl,sp,nz,ak,bk,stagz,timecheck)
134
     >        0.,pollon,pollat,varl,sp,nz,ak,bk,stagz,timecheck)
135
    
135
    
136
c     Load Variable    
136
c     Load Variable    
137
      call input_wind (cdfid,varnam,field,0.,stagz,mdv,
137
      call input_wind (cdfid,varnam,field,0.,stagz,mdv,
138
     >                 xmin,xmax,ymin,ymax,dx,dy,nx,ny,nz,timecheck)
138
     >                 xmin,xmax,ymin,ymax,dx,dy,nx,ny,nz,timecheck)
139
 
139
 
140
c     In case of isentropic level, read temperature
140
c     In case of isentropic level, read temperature
141
      if (mode.eq.'T') then
141
      if (mode.eq.'T') then
142
            tvar="T"
142
            tvar="T"
143
            do i=1,nvars
143
            do i=1,nvars
144
              if (vnam(i).eq."THETA") tvar="THETA"
144
              if (vnam(i).eq."THETA") tvar="THETA"
145
              if (vnam(i).eq."TH")    tvar="TH"
145
              if (vnam(i).eq."TH")    tvar="TH"
146
            enddo
146
            enddo
147
            if (tvar.eq.'T') then
147
            if (tvar.eq.'T') then
148
                 call input_wind (cdfid,tvar,tt,0.,stagz,mdv,xmin,xmax,
148
                 call input_wind (cdfid,tvar,tt,0.,stagz,mdv,xmin,xmax,
149
     >                            ymin,ymax,dx,dy,nx,ny,nz,timecheck)
149
     >                            ymin,ymax,dx,dy,nx,ny,nz,timecheck)
150
                 call pottemp(varl,tt,sp,nx,ny,nz,ak,bk)
150
                 call pottemp(varl,tt,sp,nx,ny,nz,ak,bk)
151
            else
151
            else
152
                 call input_wind (cdfid,tvar,tt,0.,stagz,mdv,xmin,xmax,
152
                 call input_wind (cdfid,tvar,tt,0.,stagz,mdv,xmin,xmax,
153
     >                            ymin,ymax,dx,dy,nx,ny,nz,timecheck)
153
     >                            ymin,ymax,dx,dy,nx,ny,nz,timecheck)
154
            endif
154
            endif
155
      endif
155
      endif
156
 
156
 
157
c     ----------------------------------------------------------------------
157
c     ----------------------------------------------------------------------
158
c     Do interpolation and get minimum, maximum
158
c     Do interpolation and get minimum, maximum
159
c     ----------------------------------------------------------------------
159
c     ----------------------------------------------------------------------
160
 
160
 
161
C     If required do interpolation on pressure or theta level
161
C     If required do interpolation on pressure or theta level
162
      if (mode.eq.'P') then
162
      if (mode.eq.'P') then
163
        call vipo(field,varl,level,varf,nx,ny,nz,mdv,ipom)
163
        call vipo(field,varl,level,varf,nx,ny,nz,mdv,ipom)
164
      elseif (mode.eq.'T') then
164
      elseif (mode.eq.'T') then
165
        call thipo(field,varl,level,varf,nx,ny,nz,mdv,ipom)
165
        call thipo(field,varl,level,varf,nx,ny,nz,mdv,ipom)
166
      elseif (mode.eq.'L') then
166
      elseif (mode.eq.'L') then
167
        do i=1,nx
167
        do i=1,nx
168
           do j=1,ny
168
           do j=1,ny
169
               varf(i,j) = field(i,j,nint(level))
169
               varf(i,j) = field(i,j,nint(level))
170
           enddo
170
           enddo
171
        enddo
171
        enddo
172
      elseif (mode.eq.'X') then
172
      elseif (mode.eq.'X') then
173
         do i=1,nx
173
         do i=1,nx
174
            do j=1,ny
174
            do j=1,ny
175
                varf(i,j) = field(i,j,1)
175
                varf(i,j) = field(i,j,1)
176
            enddo
176
            enddo
177
         enddo
177
         enddo
178
      endif
178
      endif
179
 
179
 
180
C     Determine minimum and maximum
180
C     Determine minimum and maximum
181
      do i=1,nx
181
      do i=1,nx
182
        do j=1,ny
182
        do j=1,ny
183
 
183
 
184
            if ((varf(i,j).ne.mdv).and.(varf(i,j).lt.min)) then
184
            if ((varf(i,j).ne.mdv).and.(varf(i,j).lt.min)) then
185
               min     = varf(i,j)
185
               min     = varf(i,j)
186
               minindx = i
186
               minindx = i
187
               minindy = j
187
               minindy = j
188
            endif
188
            endif
189
            if ((varf(i,j).ne.mdv).and.(varf(i,j).gt.max)) then
189
            if ((varf(i,j).ne.mdv).and.(varf(i,j).gt.max)) then
190
               max     = varf(i,j)
190
               max     = varf(i,j)
191
               maxindx = i
191
               maxindx = i
192
               maxindy = j
192
               maxindy = j
193
          endif
193
          endif
194
        enddo
194
        enddo
195
      enddo
195
      enddo
196
      lonmin = xmin + real(minindx-1) * dx
196
      lonmin = xmin + real(minindx-1) * dx
197
      latmin = ymin + real(minindy-1) * dy
197
      latmin = ymin + real(minindy-1) * dy
198
      lonmax = xmin + real(maxindx-1) * dx
198
      lonmax = xmin + real(maxindx-1) * dx
199
      latmax = ymin + real(maxindy-1) * dy
199
      latmax = ymin + real(maxindy-1) * dy
200
 
200
 
201
c     Rotate position to true longitude/latitude 
201
c     Rotate position to true longitude/latitude 
202
      if ((pollon.ne.0.).or.(pollat.ne.90.)) then
202
      if ((pollon.ne.0.).or.(pollat.ne.90.)) then
203
        xphys=lmstolm(latmin,lonmin,pollat,pollon)
203
        xphys=lmstolm(latmin,lonmin,pollat,pollon)
204
        yphys=phstoph(latmin,lonmin,pollat,pollon)
204
        yphys=phstoph(latmin,lonmin,pollat,pollon)
205
        lonmin=xphys
205
        lonmin=xphys
206
        latmin=yphys
206
        latmin=yphys
207
        xphys=lmstolm(latmax,lonmax,pollat,pollon)
207
        xphys=lmstolm(latmax,lonmax,pollat,pollon)
208
        yphys=phstoph(latmax,lonmax,pollat,pollon)
208
        yphys=phstoph(latmax,lonmax,pollat,pollon)
209
        lonmax=xphys
209
        lonmax=xphys
210
        latmax=yphys
210
        latmax=yphys
211
      endif
211
      endif
212
 
212
 
213
c     Write output
213
c     Write output
214
      write(*,101) min,max,lonmin,latmin,nint(level),
214
      write(*,101) min,max,lonmin,latmin,nint(level),
215
     >                     lonmax,latmax,nint(level)
215
     >                     lonmax,latmax,nint(level)
216
  101 format(2f10.3,2f8.2,i6,2f8.2,i6)
216
  101 format(2f10.3,2f8.2,i6,2f8.2,i6)
217
 
217
 
218
c     Close netCDF file
218
c     Close netCDF file
219
      call input_close(cdfid)
219
      call input_close(cdfid)
220
 
220
 
221
      end
221
      end
222
      
222
      
223
c     ----------------------------------------------------------------------
223
c     ----------------------------------------------------------------------
224
C     Interpolates the 3d variable var3d on the pressure surface defined
224
C     Interpolates the 3d variable var3d on the pressure surface defined
225
C     by lev of the variable varl. The interpolated field is
225
C     by lev of the variable varl. The interpolated field is
226
C     returned as var.
226
C     returned as var.
227
C     ipom determines the way of vertical interpolation:
227
C     ipom determines the way of vertical interpolation:
228
C       ipom=0 is for linear interpolation
228
C       ipom=0 is for linear interpolation
229
C       ipom=1 is for logarithmic interpolation
229
C       ipom=1 is for logarithmic interpolation
230
c     ----------------------------------------------------------------------
230
c     ----------------------------------------------------------------------
231
 
231
 
232
      subroutine vipo(var3d,varl,lev,var,nx,ny,nz,mdv,ipom)
232
      subroutine vipo(var3d,varl,lev,var,nx,ny,nz,mdv,ipom)
233
 
233
 
234
      integer   nx,ny,nz,ipom
234
      integer   nx,ny,nz,ipom
235
      real      lev,mdv
235
      real      lev,mdv
236
      real      var3d(nx,ny,nz),varl(nx,ny,nz),var(nx,ny)
236
      real      var3d(nx,ny,nz),varl(nx,ny,nz),var(nx,ny)
237
 
237
 
238
      integer   i,j,k
238
      integer   i,j,k
239
      real      kind
239
      real      kind
240
      real      int3dm
240
      real      int3dm
241
 
241
 
242
      do i=1,nx
242
      do i=1,nx
243
      do j=1,ny
243
      do j=1,ny
244
 
244
 
245
        do k=1,nz-1
245
        do k=1,nz-1
246
          if ((varl(i,j,k).ge.lev).and.(varl(i,j,k+1).le.lev)) then
246
          if ((varl(i,j,k).ge.lev).and.(varl(i,j,k+1).le.lev)) then
247
            kind=float(k)+(varl(i,j,k)-lev)/
247
            kind=float(k)+(varl(i,j,k)-lev)/
248
     >                   (varl(i,j,k)-varl(i,j,k+1))
248
     >                   (varl(i,j,k)-varl(i,j,k+1))
249
            goto 100
249
            goto 100
250
          endif
250
          endif
251
        enddo
251
        enddo
252
 100    continue
252
 100    continue
253
 
253
 
254
        var(i,j)=int3dm(var3d,nx,ny,nz,float(i),float(j),kind,mdv)
254
        var(i,j)=int3dm(var3d,nx,ny,nz,float(i),float(j),kind,mdv)
255
 
255
 
256
      enddo
256
      enddo
257
      enddo
257
      enddo
258
 
258
 
259
      return
259
      return
260
      end
260
      end
261
      
261
      
262
c     ----------------------------------------------------------------------
262
c     ----------------------------------------------------------------------
263
C     Interpolates the 3d variable var3d on the isentropic surface defined
263
C     Interpolates the 3d variable var3d on the isentropic surface defined
264
C     by lev of the variable varl. The interpolated field is
264
C     by lev of the variable varl. The interpolated field is
265
C     returned as var.
265
C     returned as var.
266
C     ipom determines the way of vertical interpolation:
266
C     ipom determines the way of vertical interpolation:
267
C       ipom=0 is for linear interpolation
267
C       ipom=0 is for linear interpolation
268
C       ipom=1 is for logarithmic interpolation
268
C       ipom=1 is for logarithmic interpolation
269
c     ----------------------------------------------------------------------
269
c     ----------------------------------------------------------------------
270
 
270
 
271
      subroutine thipo(var3d,th3d,lev,var,nx,ny,nz,mdv,mode)
271
      subroutine thipo(var3d,th3d,lev,var,nx,ny,nz,mdv,mode)
272
 
272
 
273
      integer   nx,ny,nz,mode
273
      integer   nx,ny,nz,mode
274
      real      lev,mdv
274
      real      lev,mdv
275
      real      var3d(nx,ny,nz),th3d(nx,ny,nz),var(nx,ny)
275
      real      var3d(nx,ny,nz),th3d(nx,ny,nz),var(nx,ny)
276
 
276
 
277
      integer   i,j,k
277
      integer   i,j,k
278
      real      kind
278
      real      kind
279
      real      int3dm
279
      real      int3dm
280
 
280
 
281
      do i=1,nx
281
      do i=1,nx
282
      do j=1,ny
282
      do j=1,ny
283
 
283
 
284
        do k=1,nz-1
284
        do k=1,nz-1
285
          if ((th3d(i,j,k).le.lev).and.(th3d(i,j,k+1).ge.lev)) then
285
          if ((th3d(i,j,k).le.lev).and.(th3d(i,j,k+1).ge.lev)) then
286
            kind=float(k)+(th3d(i,j,k)-lev)/
286
            kind=float(k)+(th3d(i,j,k)-lev)/
287
     >                   (th3d(i,j,k)-th3d(i,j,k+1))
287
     >                   (th3d(i,j,k)-th3d(i,j,k+1))
288
            goto 100
288
            goto 100
289
          endif
289
          endif
290
        enddo
290
        enddo
291
 100    continue
291
 100    continue
292
 
292
 
293
        var(i,j)=int3dm(var3d,nx,ny,nz,float(i),float(j),kind,mdv)
293
        var(i,j)=int3dm(var3d,nx,ny,nz,float(i),float(j),kind,mdv)
294
 
294
 
295
      enddo
295
      enddo
296
      enddo
296
      enddo
297
 
297
 
298
      return
298
      return
299
      end
299
      end
300
      
300
      
301
c     ----------------------------------------------------------------------
301
c     ----------------------------------------------------------------------
302
c     Check whether character appears within string
302
c     Check whether character appears within string
303
c     ----------------------------------------------------------------------
303
c     ----------------------------------------------------------------------
304
 
304
 
305
      subroutine checkchar(string,char,flag)
305
      subroutine checkchar(string,char,flag)
306
 
306
 
307
      character*(*)     string
307
      character*(*)     string
308
      character*(1)     char
308
      character*(1)     char
309
      integer           n,flag
309
      integer           n,flag
310
 
310
 
311
      flag=0
311
      flag=0
312
      do n=1,len(string)
312
      do n=1,len(string)
313
        if (string(n:n).eq.char) then
313
        if (string(n:n).eq.char) then
314
          flag=n
314
          flag=n
315
          return
315
          return
316
        endif
316
        endif
317
      enddo
317
      enddo
318
      end
318
      end
319
      
319
      
320
c     ----------------------------------------------------------------------
320
c     ----------------------------------------------------------------------
321
c     3D interpolation
321
c     3D interpolation
322
c     ----------------------------------------------------------------------
322
c     ----------------------------------------------------------------------
323
      
323
      
324
      real function int3d(ar,n1,n2,n3,rid,rjd,rkd)
324
      real function int3d(ar,n1,n2,n3,rid,rjd,rkd)
325
 
325
 
326
c     Purpose:
326
c     Purpose:
327
c        This subroutine interpolates a 3d-array to an arbitrary
327
c        This subroutine interpolates a 3d-array to an arbitrary
328
c        location within the grid.
328
c        location within the grid.
329
c     Arguments:
329
c     Arguments:
330
c        ar        real  input   surface pressure, define as ar(n1,n2,n3)
330
c        ar        real  input   surface pressure, define as ar(n1,n2,n3)
331
c        n1,n2,n3  int   input   dimensions of ar
331
c        n1,n2,n3  int   input   dimensions of ar
332
c        ri,rj,rk  real  input   grid location to be interpolated to
332
c        ri,rj,rk  real  input   grid location to be interpolated to
333
c     History:
333
c     History:
334
 
334
 
335
c     argument declarations
335
c     argument declarations
336
      integer   n1,n2,n3
336
      integer   n1,n2,n3
337
      real      ar(n1,n2,n3), rid,rjd,rkd
337
      real      ar(n1,n2,n3), rid,rjd,rkd
338
 
338
 
339
c     local declarations
339
c     local declarations
340
      integer   i,j,k,ip1,jp1,kp1,ih,jh,kh
340
      integer   i,j,k,ip1,jp1,kp1,ih,jh,kh
341
      real      frac0i,frac0j,frac0k,frac1i,frac1j,frac1k,ri,rj,rk
341
      real      frac0i,frac0j,frac0k,frac1i,frac1j,frac1k,ri,rj,rk
342
 
342
 
343
c     do linear interpolation
343
c     do linear interpolation
344
      ri=amax1(1.,amin1(float(n1),rid))
344
      ri=amax1(1.,amin1(float(n1),rid))
345
      rj=amax1(1.,amin1(float(n2),rjd))
345
      rj=amax1(1.,amin1(float(n2),rjd))
346
      rk=amax1(1.,amin1(float(n3),rkd))
346
      rk=amax1(1.,amin1(float(n3),rkd))
347
      ih=nint(ri)
347
      ih=nint(ri)
348
      jh=nint(rj)
348
      jh=nint(rj)
349
      kh=nint(rk)
349
      kh=nint(rk)
350
 
350
 
351
c     Check for interpolation in i
351
c     Check for interpolation in i
352
*     if (abs(float(ih)-ri).lt.1.e-3) then
352
*     if (abs(float(ih)-ri).lt.1.e-3) then
353
*       i  =ih
353
*       i  =ih
354
*       ip1=ih
354
*       ip1=ih
355
*     else
355
*     else
356
        i =min0(int(ri),n1-1)
356
        i =min0(int(ri),n1-1)
357
        ip1=i+1
357
        ip1=i+1
358
*     endif
358
*     endif
359
 
359
 
360
c     Check for interpolation in j
360
c     Check for interpolation in j
361
      if (abs(float(jh)-rj).lt.1.e-3) then
361
      if (abs(float(jh)-rj).lt.1.e-3) then
362
        j  =jh
362
        j  =jh
363
        jp1=jh
363
        jp1=jh
364
      else
364
      else
365
        j =min0(int(rj),n2-1)
365
        j =min0(int(rj),n2-1)
366
        jp1=j+1
366
        jp1=j+1
367
      endif
367
      endif
368
 
368
 
369
c     Check for interpolation in k
369
c     Check for interpolation in k
370
*     if (abs(float(kh)-rk).lt.1.e-3) then
370
*     if (abs(float(kh)-rk).lt.1.e-3) then
371
*       k  =kh
371
*       k  =kh
372
*       kp1=kh
372
*       kp1=kh
373
*     else
373
*     else
374
        k =min0(int(rk),n3-1)
374
        k =min0(int(rk),n3-1)
375
        kp1=k+1
375
        kp1=k+1
376
*     endif
376
*     endif
377
 
377
 
378
      if (k.eq.kp1) then
378
      if (k.eq.kp1) then
379
c       no interpolation in k
379
c       no interpolation in k
380
        if ((i.eq.ip1).and.(j.eq.jp1)) then
380
        if ((i.eq.ip1).and.(j.eq.jp1)) then
381
c          no interpolation at all
381
c          no interpolation at all
382
           int3d=ar(i,j,k)
382
           int3d=ar(i,j,k)
383
c          print *,'int3d 00: ',rid,rjd,rkd,int3d
383
c          print *,'int3d 00: ',rid,rjd,rkd,int3d
384
        else
384
        else
385
c          horizontal interpolation only
385
c          horizontal interpolation only
386
           frac0i=ri-float(i)
386
           frac0i=ri-float(i)
387
           frac0j=rj-float(j)
387
           frac0j=rj-float(j)
388
           frac1i=1.-frac0i
388
           frac1i=1.-frac0i
389
           frac1j=1.-frac0j
389
           frac1j=1.-frac0j
390
           int3d = ar(i  ,j  ,k  ) * frac1i * frac1j
390
           int3d = ar(i  ,j  ,k  ) * frac1i * frac1j
391
     &           + ar(i  ,jp1,k  ) * frac1i * frac0j
391
     &           + ar(i  ,jp1,k  ) * frac1i * frac0j
392
     &           + ar(ip1,j  ,k  ) * frac0i * frac1j
392
     &           + ar(ip1,j  ,k  ) * frac0i * frac1j
393
     &           + ar(ip1,jp1,k  ) * frac0i * frac0j
393
     &           + ar(ip1,jp1,k  ) * frac0i * frac0j
394
c          print *,'int3d 10: ',rid,rjd,rkd,int3d
394
c          print *,'int3d 10: ',rid,rjd,rkd,int3d
395
        endif
395
        endif
396
      else 
396
      else 
397
        frac0k=rk-float(k)
397
        frac0k=rk-float(k)
398
        frac1k=1.-frac0k
398
        frac1k=1.-frac0k
399
        if ((i.eq.ip1).and.(j.eq.jp1)) then
399
        if ((i.eq.ip1).and.(j.eq.jp1)) then
400
c          vertical interpolation only
400
c          vertical interpolation only
401
           int3d = ar(i  ,j  ,k  ) * frac1k
401
           int3d = ar(i  ,j  ,k  ) * frac1k
402
     &           + ar(i  ,j  ,kp1) * frac0k
402
     &           + ar(i  ,j  ,kp1) * frac0k
403
c          print *,'int3d 01: ',rid,rjd,rkd,int3d
403
c          print *,'int3d 01: ',rid,rjd,rkd,int3d
404
        else
404
        else
405
c          full 3d interpolation
405
c          full 3d interpolation
406
           frac0i=ri-float(i)
406
           frac0i=ri-float(i)
407
           frac0j=rj-float(j)
407
           frac0j=rj-float(j)
408
           frac1i=1.-frac0i
408
           frac1i=1.-frac0i
409
           frac1j=1.-frac0j
409
           frac1j=1.-frac0j
410
           int3d = ar(i  ,j  ,k  ) * frac1i * frac1j * frac1k
410
           int3d = ar(i  ,j  ,k  ) * frac1i * frac1j * frac1k
411
     &           + ar(i  ,jp1,k  ) * frac1i * frac0j * frac1k 
411
     &           + ar(i  ,jp1,k  ) * frac1i * frac0j * frac1k 
412
     &           + ar(ip1,j  ,k  ) * frac0i * frac1j * frac1k
412
     &           + ar(ip1,j  ,k  ) * frac0i * frac1j * frac1k
413
     &           + ar(ip1,jp1,k  ) * frac0i * frac0j * frac1k
413
     &           + ar(ip1,jp1,k  ) * frac0i * frac0j * frac1k
414
     &           + ar(i  ,j  ,kp1) * frac1i * frac1j * frac0k
414
     &           + ar(i  ,j  ,kp1) * frac1i * frac1j * frac0k
415
     &           + ar(i  ,jp1,kp1) * frac1i * frac0j * frac0k 
415
     &           + ar(i  ,jp1,kp1) * frac1i * frac0j * frac0k 
416
     &           + ar(ip1,j  ,kp1) * frac0i * frac1j * frac0k
416
     &           + ar(ip1,j  ,kp1) * frac0i * frac1j * frac0k
417
     &           + ar(ip1,jp1,kp1) * frac0i * frac0j * frac0k
417
     &           + ar(ip1,jp1,kp1) * frac0i * frac0j * frac0k
418
c          print *,'int3d 11: ',rid,rjd,rkd,int3d
418
c          print *,'int3d 11: ',rid,rjd,rkd,int3d
419
        endif
419
        endif
420
      endif
420
      endif
421
      end
421
      end
422
      
422
      
423
c     ----------------------------------------------------------------------
423
c     ----------------------------------------------------------------------
424
c     3D interpolation including missing data check
424
c     3D interpolation including missing data check
425
c     ----------------------------------------------------------------------
425
c     ----------------------------------------------------------------------
426
  
426
  
427
      real function int3dm(ar,n1,n2,n3,rid,rjd,rkd,misdat)
427
      real function int3dm(ar,n1,n2,n3,rid,rjd,rkd,misdat)
428
 
428
 
429
c     Purpose:
429
c     Purpose:
430
c        This subroutine interpolates a 3d-array to an arbitrary
430
c        This subroutine interpolates a 3d-array to an arbitrary
431
c        location within the grid. The interpolation includes the 
431
c        location within the grid. The interpolation includes the 
432
c        testing of the missing data flag 'misdat'. 
432
c        testing of the missing data flag 'misdat'. 
433
c     Arguments:
433
c     Arguments:
434
c        ar        real  input   surface pressure, define as ar(n1,n2,n3)
434
c        ar        real  input   surface pressure, define as ar(n1,n2,n3)
435
c        n1,n2,n3  int   input   dimensions of ar
435
c        n1,n2,n3  int   input   dimensions of ar
436
c        ri,rj,rk  real  input   grid location to be interpolated to
436
c        ri,rj,rk  real  input   grid location to be interpolated to
437
c        misdat    real  input   missing data flag (on if misdat<>0)
437
c        misdat    real  input   missing data flag (on if misdat<>0)
438
c     Warning:
438
c     Warning:
439
c        This routine has not yet been seriously tested
439
c        This routine has not yet been seriously tested
440
c     History:
440
c     History:
441
 
441
 
442
c     argument declarations
442
c     argument declarations
443
      integer   n1,n2,n3
443
      integer   n1,n2,n3
444
      real      ar(n1,n2,n3), rid,rjd,rkd, misdat
444
      real      ar(n1,n2,n3), rid,rjd,rkd, misdat
445
 
445
 
446
c     local declarations
446
c     local declarations
447
      integer   i,j,k,ip1,jp1,kp1,ih,jh,kh
447
      integer   i,j,k,ip1,jp1,kp1,ih,jh,kh
448
      real      frac0i,frac0j,frac0k,frac1i,frac1j,frac1k,ri,rj,rk,int3d
448
      real      frac0i,frac0j,frac0k,frac1i,frac1j,frac1k,ri,rj,rk,int3d
449
 
449
 
450
c     check if routine without missing data checking can be called instead
450
c     check if routine without missing data checking can be called instead
451
      if (misdat.eq.0.) then
451
      if (misdat.eq.0.) then
452
        int3dm=int3d(ar,n1,n2,n3,rid,rjd,rkd)
452
        int3dm=int3d(ar,n1,n2,n3,rid,rjd,rkd)
453
        return
453
        return
454
      endif
454
      endif
455
 
455
 
456
c     do linear interpolation
456
c     do linear interpolation
457
      ri=amax1(1.,amin1(float(n1),rid))
457
      ri=amax1(1.,amin1(float(n1),rid))
458
      rj=amax1(1.,amin1(float(n2),rjd))
458
      rj=amax1(1.,amin1(float(n2),rjd))
459
      rk=amax1(1.,amin1(float(n3),rkd))
459
      rk=amax1(1.,amin1(float(n3),rkd))
460
      ih=nint(ri)
460
      ih=nint(ri)
461
      jh=nint(rj)
461
      jh=nint(rj)
462
      kh=nint(rk)
462
      kh=nint(rk)
463
 
463
 
464
c     Check for interpolation in i
464
c     Check for interpolation in i
465
*     if (abs(float(ih)-ri).lt.1.e-3) then
465
*     if (abs(float(ih)-ri).lt.1.e-3) then
466
*       i  =ih
466
*       i  =ih
467
*       ip1=ih
467
*       ip1=ih
468
*     else
468
*     else
469
        i =min0(int(ri),n1-1)
469
        i =min0(int(ri),n1-1)
470
        ip1=i+1
470
        ip1=i+1
471
*     endif
471
*     endif
472
 
472
 
473
c     Check for interpolation in j
473
c     Check for interpolation in j
474
*     if (abs(float(jh)-rj).lt.1.e-3) then
474
*     if (abs(float(jh)-rj).lt.1.e-3) then
475
*       j  =jh
475
*       j  =jh
476
*       jp1=jh
476
*       jp1=jh
477
*     else
477
*     else
478
        j =min0(int(rj),n2-1)
478
        j =min0(int(rj),n2-1)
479
        jp1=j+1
479
        jp1=j+1
480
*     endif
480
*     endif
481
 
481
 
482
c     Check for interpolation in k
482
c     Check for interpolation in k
483
*     if (abs(float(kh)-rk).lt.1.e-3) then
483
*     if (abs(float(kh)-rk).lt.1.e-3) then
484
*       k  =kh
484
*       k  =kh
485
*       kp1=kh
485
*       kp1=kh
486
*     else
486
*     else
487
        k =min0(int(rk),n3-1)
487
        k =min0(int(rk),n3-1)
488
        kp1=k+1
488
        kp1=k+1
489
*     endif
489
*     endif
490
 
490
 
491
      if (k.eq.kp1) then
491
      if (k.eq.kp1) then
492
c       no interpolation in k
492
c       no interpolation in k
493
        if ((i.eq.ip1).and.(j.eq.jp1)) then
493
        if ((i.eq.ip1).and.(j.eq.jp1)) then
494
c          no interpolation at all
494
c          no interpolation at all
495
           if (misdat.eq.ar(i,j,k)) then
495
           if (misdat.eq.ar(i,j,k)) then
496
             int3dm=misdat
496
             int3dm=misdat
497
           else
497
           else
498
             int3dm=ar(i,j,k)
498
             int3dm=ar(i,j,k)
499
           endif
499
           endif
500
c          print *,'int3dm 00: ',rid,rjd,rkd,int3dm
500
c          print *,'int3dm 00: ',rid,rjd,rkd,int3dm
501
        else
501
        else
502
c          horizontal interpolation only
502
c          horizontal interpolation only
503
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
503
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
504
     &         (misdat.eq.ar(i  ,jp1,k  )).or.
504
     &         (misdat.eq.ar(i  ,jp1,k  )).or.
505
     &         (misdat.eq.ar(ip1,j  ,k  )).or.
505
     &         (misdat.eq.ar(ip1,j  ,k  )).or.
506
     &         (misdat.eq.ar(ip1,jp1,k  ))) then
506
     &         (misdat.eq.ar(ip1,jp1,k  ))) then
507
             int3dm=misdat
507
             int3dm=misdat
508
           else
508
           else
509
             frac0i=ri-float(i)
509
             frac0i=ri-float(i)
510
             frac0j=rj-float(j)
510
             frac0j=rj-float(j)
511
             frac1i=1.-frac0i
511
             frac1i=1.-frac0i
512
             frac1j=1.-frac0j
512
             frac1j=1.-frac0j
513
             int3dm = ar(i  ,j  ,k  ) * frac1i * frac1j
513
             int3dm = ar(i  ,j  ,k  ) * frac1i * frac1j
514
     &              + ar(i  ,jp1,k  ) * frac1i * frac0j
514
     &              + ar(i  ,jp1,k  ) * frac1i * frac0j
515
     &              + ar(ip1,j  ,k  ) * frac0i * frac1j
515
     &              + ar(ip1,j  ,k  ) * frac0i * frac1j
516
     &              + ar(ip1,jp1,k  ) * frac0i * frac0j
516
     &              + ar(ip1,jp1,k  ) * frac0i * frac0j
517
c            print *,'int3dm 10: ',rid,rjd,rkd,int3dm
517
c            print *,'int3dm 10: ',rid,rjd,rkd,int3dm
518
           endif
518
           endif
519
        endif
519
        endif
520
      else 
520
      else 
521
        frac0k=rk-float(k)
521
        frac0k=rk-float(k)
522
        frac1k=1.-frac0k
522
        frac1k=1.-frac0k
523
        if ((i.eq.ip1).and.(j.eq.jp1)) then
523
        if ((i.eq.ip1).and.(j.eq.jp1)) then
524
c          vertical interpolation only
524
c          vertical interpolation only
525
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
525
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
526
     &         (misdat.eq.ar(i  ,j  ,kp1))) then
526
     &         (misdat.eq.ar(i  ,j  ,kp1))) then
527
             int3dm=misdat
527
             int3dm=misdat
528
           else
528
           else
529
             int3dm = ar(i  ,j  ,k  ) * frac1k
529
             int3dm = ar(i  ,j  ,k  ) * frac1k
530
     &              + ar(i  ,j  ,kp1) * frac0k
530
     &              + ar(i  ,j  ,kp1) * frac0k
531
c            print *,'int3dm 01: ',rid,rjd,rkd,int3dm
531
c            print *,'int3dm 01: ',rid,rjd,rkd,int3dm
532
           endif
532
           endif
533
        else
533
        else
534
c          full 3d interpolation
534
c          full 3d interpolation
535
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
535
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
536
     &         (misdat.eq.ar(i  ,jp1,k  )).or.
536
     &         (misdat.eq.ar(i  ,jp1,k  )).or.
537
     &         (misdat.eq.ar(ip1,j  ,k  )).or.
537
     &         (misdat.eq.ar(ip1,j  ,k  )).or.
538
     &         (misdat.eq.ar(ip1,jp1,k  )).or.
538
     &         (misdat.eq.ar(ip1,jp1,k  )).or.
539
     &         (misdat.eq.ar(i  ,j  ,kp1)).or.
539
     &         (misdat.eq.ar(i  ,j  ,kp1)).or.
540
     &         (misdat.eq.ar(i  ,jp1,kp1)).or.
540
     &         (misdat.eq.ar(i  ,jp1,kp1)).or.
541
     &         (misdat.eq.ar(ip1,j  ,kp1)).or.
541
     &         (misdat.eq.ar(ip1,j  ,kp1)).or.
542
     &         (misdat.eq.ar(ip1,jp1,kp1))) then
542
     &         (misdat.eq.ar(ip1,jp1,kp1))) then
543
             int3dm=misdat
543
             int3dm=misdat
544
           else
544
           else
545
             frac0i=ri-float(i)
545
             frac0i=ri-float(i)
546
             frac0j=rj-float(j)
546
             frac0j=rj-float(j)
547
             frac1i=1.-frac0i
547
             frac1i=1.-frac0i
548
             frac1j=1.-frac0j
548
             frac1j=1.-frac0j
549
             int3dm = ar(i  ,j  ,k  ) * frac1i * frac1j * frac1k
549
             int3dm = ar(i  ,j  ,k  ) * frac1i * frac1j * frac1k
550
     &              + ar(i  ,jp1,k  ) * frac1i * frac0j * frac1k
550
     &              + ar(i  ,jp1,k  ) * frac1i * frac0j * frac1k
551
     &              + ar(ip1,j  ,k  ) * frac0i * frac1j * frac1k
551
     &              + ar(ip1,j  ,k  ) * frac0i * frac1j * frac1k
552
     &              + ar(ip1,jp1,k  ) * frac0i * frac0j * frac1k
552
     &              + ar(ip1,jp1,k  ) * frac0i * frac0j * frac1k
553
     &              + ar(i  ,j  ,kp1) * frac1i * frac1j * frac0k
553
     &              + ar(i  ,j  ,kp1) * frac1i * frac1j * frac0k
554
     &              + ar(i  ,jp1,kp1) * frac1i * frac0j * frac0k
554
     &              + ar(i  ,jp1,kp1) * frac1i * frac0j * frac0k
555
     &              + ar(ip1,j  ,kp1) * frac0i * frac1j * frac0k
555
     &              + ar(ip1,j  ,kp1) * frac0i * frac1j * frac0k
556
     &              + ar(ip1,jp1,kp1) * frac0i * frac0j * frac0k
556
     &              + ar(ip1,jp1,kp1) * frac0i * frac0j * frac0k
557
c            print *,'int3dm 11: ',rid,rjd,rkd,int3dm
557
c            print *,'int3dm 11: ',rid,rjd,rkd,int3dm
558
           endif
558
           endif
559
        endif
559
        endif
560
      endif
560
      endif
561
      end
561
      end
562
 
562
 
563
c     ----------------------------------------------------------------------
563
c     ----------------------------------------------------------------------
564
c     Calculate potential temperature
564
c     Calculate potential temperature
565
c     ----------------------------------------------------------------------
565
c     ----------------------------------------------------------------------
566
 
566
 
567
      subroutine pottemp(pt,t,sp,ie,je,ke,ak,bk)
567
      subroutine pottemp(pt,t,sp,ie,je,ke,ak,bk)
568
 
568
 
569
c     argument declaration
569
c     argument declaration
570
      integer   ie,je,ke
570
      integer   ie,je,ke
571
      real      pt(ie,je,ke),t(ie,je,ke),sp(ie,je),
571
      real      pt(ie,je,ke),t(ie,je,ke),sp(ie,je),
572
     >     	ak(ke),bk(ke)
572
     >     	ak(ke),bk(ke)
573
 
573
 
574
c     variable declaration
574
c     variable declaration
575
      integer   i,j,k
575
      integer   i,j,k
576
      real      rdcp,tzero
576
      real      rdcp,tzero
577
      data      rdcp,tzero /0.286,273.15/
577
      data      rdcp,tzero /0.286,273.15/
578
 
578
 
579
c     statement-functions for the computation of pressure
579
c     statement-functions for the computation of pressure
580
      real      pp,psrf
580
      real      pp,psrf
581
      integer   is
581
      integer   is
582
      pp(is)=ak(is)+bk(is)*psrf
582
      pp(is)=ak(is)+bk(is)*psrf
583
 
583
 
584
c     computation of potential temperature
584
c     computation of potential temperature
585
      do i=1,ie
585
      do i=1,ie
586
      do j=1,je
586
      do j=1,je
587
        psrf=sp(i,j)
587
        psrf=sp(i,j)
588
        do k=1,ke
588
        do k=1,ke
589
c     distinction of temperature in K and deg C
589
c     distinction of temperature in K and deg C
590
          if (t(i,j,k).lt.100.) then
590
          if (t(i,j,k).lt.100.) then
591
            pt(i,j,k)=(t(i,j,k)+tzero)*( (1000./pp(k))**rdcp )
591
            pt(i,j,k)=(t(i,j,k)+tzero)*( (1000./pp(k))**rdcp )
592
          else
592
          else
593
            pt(i,j,k)=t(i,j,k)*( (1000./pp(k))**rdcp )
593
            pt(i,j,k)=t(i,j,k)*( (1000./pp(k))**rdcp )
594
          endif
594
          endif
595
        enddo
595
        enddo
596
      enddo
596
      enddo
597
      enddo
597
      enddo
598
      end
598
      end
599
      
599
      
600
c     ----------------------------------------------------------------------
600
c     ----------------------------------------------------------------------
601
c     Calculate 3D pressure
601
c     Calculate 3D pressure
602
c     ----------------------------------------------------------------------
602
c     ----------------------------------------------------------------------
603
 
603
 
604
      subroutine pres(pr,sp,ie,je,ke,ak,bk)
604
      subroutine pres(pr,sp,ie,je,ke,ak,bk)
605
 
605
 
606
c     argument declaration
606
c     argument declaration
607
      integer  ie,je,ke
607
      integer  ie,je,ke
608
      real,intent(OUT) :: pr(ie,je,ke)
608
      real,intent(OUT) :: pr(ie,je,ke)
609
      real,intent(IN)  :: sp(ie,je)
609
      real,intent(IN)  :: sp(ie,je)
610
      real,intent(IN)  :: ak(ke),bk(ke)
610
      real,intent(IN)  :: ak(ke),bk(ke)
611
 
611
 
612
c     variable declaration
612
c     variable declaration
613
      integer  i,j,k
613
      integer  i,j,k
614
 
614
 
615
c     computation pressure
615
c     computation pressure
616
      do i=1,ie
616
      do i=1,ie
617
      do j=1,je
617
      do j=1,je
618
      do k=1,ke
618
      do k=1,ke
619
        pr(i,j,k)=ak(k)+bk(k)*sp(i,j)
619
        pr(i,j,k)=ak(k)+bk(k)*sp(i,j)
620
      enddo
620
      enddo
621
      enddo
621
      enddo
622
      enddo
622
      enddo
623
      end
623
      end
624
      
624
      
625
c     ----------------------------------------------------------------------
625
c     ----------------------------------------------------------------------
626
c     Coordinate rotations from COSMO
626
c     Coordinate rotations from COSMO
627
c     ----------------------------------------------------------------------      
627
c     ----------------------------------------------------------------------      
628
      
628
      
629
      REAL FUNCTION PHTOPHS (PHI, LAM, POLPHI, POLLAM)
629
      REAL FUNCTION PHTOPHS (PHI, LAM, POLPHI, POLLAM)
630
C
630
C
631
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
631
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
632
C
632
C
633
C**** PHTOPHS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI
633
C**** PHTOPHS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI
634
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
634
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
635
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
635
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
636
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
636
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
637
C**   AUFRUF   :   PHI = PHTOPHS (PHI, LAM, POLPHI, POLLAM)
637
C**   AUFRUF   :   PHI = PHTOPHS (PHI, LAM, POLPHI, POLLAM)
638
C**   ENTRIES  :   KEINE
638
C**   ENTRIES  :   KEINE
639
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI AUF
639
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI AUF
640
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
640
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
641
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
641
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
642
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
642
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
643
C**   VERSIONS-
643
C**   VERSIONS-
644
C**   DATUM    :   03.05.90
644
C**   DATUM    :   03.05.90
645
C**
645
C**
646
C**   EXTERNALS:   KEINE
646
C**   EXTERNALS:   KEINE
647
C**   EINGABE-
647
C**   EINGABE-
648
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
648
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
649
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
649
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
650
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
650
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
651
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
651
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
652
C**   AUSGABE-
652
C**   AUSGABE-
653
C**   PARAMETER:   ROTIERTE BREITE PHIS ALS WERT DER FUNKTION
653
C**   PARAMETER:   ROTIERTE BREITE PHIS ALS WERT DER FUNKTION
654
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
654
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
655
C**
655
C**
656
C**   COMMON-
656
C**   COMMON-
657
C**   BLOECKE  :   KEINE
657
C**   BLOECKE  :   KEINE
658
C**
658
C**
659
C**   FEHLERBE-
659
C**   FEHLERBE-
660
C**   HANDLUNG :   KEINE
660
C**   HANDLUNG :   KEINE
661
C**   VERFASSER:   G. DE MORSIER
661
C**   VERFASSER:   G. DE MORSIER
662
 
662
 
663
      REAL        LAM,PHI,POLPHI,POLLAM
663
      REAL        LAM,PHI,POLPHI,POLLAM
664
 
664
 
665
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
665
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
666
 
666
 
667
      ZSINPOL = SIN(ZPIR18*POLPHI)
667
      ZSINPOL = SIN(ZPIR18*POLPHI)
668
      ZCOSPOL = COS(ZPIR18*POLPHI)
668
      ZCOSPOL = COS(ZPIR18*POLPHI)
669
      ZLAMPOL = ZPIR18*POLLAM
669
      ZLAMPOL = ZPIR18*POLLAM
670
      ZPHI    = ZPIR18*PHI
670
      ZPHI    = ZPIR18*PHI
671
      ZLAM    = LAM
671
      ZLAM    = LAM
672
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
672
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
673
      ZLAM    = ZPIR18*ZLAM
673
      ZLAM    = ZPIR18*ZLAM
674
      ZARG    = ZCOSPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL) + ZSINPOL*SIN(ZPHI)
674
      ZARG    = ZCOSPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL) + ZSINPOL*SIN(ZPHI)
675
 
675
 
676
      PHTOPHS = ZRPI18*ASIN(ZARG)
676
      PHTOPHS = ZRPI18*ASIN(ZARG)
677
 
677
 
678
      RETURN
678
      RETURN
679
      END
679
      END
680
      
680
      
681
      
681
      
682
      REAL FUNCTION PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
682
      REAL FUNCTION PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
683
C
683
C
684
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
684
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
685
C
685
C
686
C**** PHSTOPH  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
686
C**** PHSTOPH  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
687
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
687
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
688
C****                 ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
688
C****                 ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
689
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
689
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
690
C**   AUFRUF   :   PHI = PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
690
C**   AUFRUF   :   PHI = PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
691
C**   ENTRIES  :   KEINE
691
C**   ENTRIES  :   KEINE
692
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
692
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
693
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
693
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
694
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
694
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
695
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
695
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
696
C**   VERSIONS-
696
C**   VERSIONS-
697
C**   DATUM    :   03.05.90
697
C**   DATUM    :   03.05.90
698
C**
698
C**
699
C**   EXTERNALS:   KEINE
699
C**   EXTERNALS:   KEINE
700
C**   EINGABE-
700
C**   EINGABE-
701
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
701
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
702
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
702
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
703
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
703
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
704
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
704
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
705
C**   AUSGABE-
705
C**   AUSGABE-
706
C**   PARAMETER:   WAHRE GEOGRAPHISCHE BREITE ALS WERT DER FUNKTION
706
C**   PARAMETER:   WAHRE GEOGRAPHISCHE BREITE ALS WERT DER FUNKTION
707
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
707
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
708
C**
708
C**
709
C**   COMMON-
709
C**   COMMON-
710
C**   BLOECKE  :   KEINE
710
C**   BLOECKE  :   KEINE
711
C**
711
C**
712
C**   FEHLERBE-
712
C**   FEHLERBE-
713
C**   HANDLUNG :   KEINE
713
C**   HANDLUNG :   KEINE
714
C**   VERFASSER:   D.MAJEWSKI
714
C**   VERFASSER:   D.MAJEWSKI
715
 
715
 
716
      REAL        LAMS,PHIS,POLPHI,POLLAM
716
      REAL        LAMS,PHIS,POLPHI,POLLAM
717
 
717
 
718
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
718
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
719
 
719
 
720
      SINPOL = SIN(ZPIR18*POLPHI)
720
      SINPOL = SIN(ZPIR18*POLPHI)
721
      COSPOL = COS(ZPIR18*POLPHI)
721
      COSPOL = COS(ZPIR18*POLPHI)
722
      ZPHIS  = ZPIR18*PHIS
722
      ZPHIS  = ZPIR18*PHIS
723
      ZLAMS  = LAMS
723
      ZLAMS  = LAMS
724
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
724
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
725
      ZLAMS  = ZPIR18*ZLAMS
725
      ZLAMS  = ZPIR18*ZLAMS
726
      ARG     = COSPOL*COS(ZPHIS)*COS(ZLAMS) + SINPOL*SIN(ZPHIS)
726
      ARG     = COSPOL*COS(ZPHIS)*COS(ZLAMS) + SINPOL*SIN(ZPHIS)
727
 
727
 
728
      PHSTOPH = ZRPI18*ASIN(ARG)
728
      PHSTOPH = ZRPI18*ASIN(ARG)
729
 
729
 
730
      RETURN
730
      RETURN
731
      END
731
      END
732
      REAL FUNCTION LMTOLMS (PHI, LAM, POLPHI, POLLAM)
732
      REAL FUNCTION LMTOLMS (PHI, LAM, POLPHI, POLLAM)
733
C
733
C
734
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
734
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
735
C
735
C
736
C**** LMTOLMS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM
736
C**** LMTOLMS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM
737
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
737
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
738
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
738
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
739
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
739
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
740
C**   AUFRUF   :   LAM = LMTOLMS (PHI, LAM, POLPHI, POLLAM)
740
C**   AUFRUF   :   LAM = LMTOLMS (PHI, LAM, POLPHI, POLLAM)
741
C**   ENTRIES  :   KEINE
741
C**   ENTRIES  :   KEINE
742
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM AUF
742
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM AUF
743
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
743
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
744
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
744
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
745
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
745
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
746
C**   VERSIONS-
746
C**   VERSIONS-
747
C**   DATUM    :   03.05.90
747
C**   DATUM    :   03.05.90
748
C**
748
C**
749
C**   EXTERNALS:   KEINE
749
C**   EXTERNALS:   KEINE
750
C**   EINGABE-
750
C**   EINGABE-
751
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
751
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
752
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
752
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
753
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
753
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
754
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
754
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
755
C**   AUSGABE-
755
C**   AUSGABE-
756
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
756
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
757
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
757
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
758
C**
758
C**
759
C**   COMMON-
759
C**   COMMON-
760
C**   BLOECKE  :   KEINE
760
C**   BLOECKE  :   KEINE
761
C**
761
C**
762
C**   FEHLERBE-
762
C**   FEHLERBE-
763
C**   HANDLUNG :   KEINE
763
C**   HANDLUNG :   KEINE
764
C**   VERFASSER:   G. DE MORSIER
764
C**   VERFASSER:   G. DE MORSIER
765
 
765
 
766
      REAL        LAM,PHI,POLPHI,POLLAM
766
      REAL        LAM,PHI,POLPHI,POLLAM
767
 
767
 
768
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
768
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
769
 
769
 
770
      ZSINPOL = SIN(ZPIR18*POLPHI)
770
      ZSINPOL = SIN(ZPIR18*POLPHI)
771
      ZCOSPOL = COS(ZPIR18*POLPHI)
771
      ZCOSPOL = COS(ZPIR18*POLPHI)
772
      ZLAMPOL =     ZPIR18*POLLAM
772
      ZLAMPOL =     ZPIR18*POLLAM
773
      ZPHI    =     ZPIR18*PHI
773
      ZPHI    =     ZPIR18*PHI
774
      ZLAM    = LAM
774
      ZLAM    = LAM
775
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
775
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
776
      ZLAM    = ZPIR18*ZLAM
776
      ZLAM    = ZPIR18*ZLAM
777
 
777
 
778
      ZARG1   = - SIN(ZLAM-ZLAMPOL)*COS(ZPHI)
778
      ZARG1   = - SIN(ZLAM-ZLAMPOL)*COS(ZPHI)
779
      ZARG2   = - ZSINPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL)+ZCOSPOL*SIN(ZPHI)
779
      ZARG2   = - ZSINPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL)+ZCOSPOL*SIN(ZPHI)
780
      IF (ABS(ZARG2).LT.1.E-30) THEN
780
      IF (ABS(ZARG2).LT.1.E-30) THEN
781
        IF (ABS(ZARG1).LT.1.E-30) THEN
781
        IF (ABS(ZARG1).LT.1.E-30) THEN
782
          LMTOLMS =   0.0
782
          LMTOLMS =   0.0
783
        ELSEIF (ZARG1.GT.0.) THEN
783
        ELSEIF (ZARG1.GT.0.) THEN
784
              LMTOLMS =  90.0
784
              LMTOLMS =  90.0
785
            ELSE
785
            ELSE
786
              LMTOLMS = -90.0
786
              LMTOLMS = -90.0
787
            ENDIF
787
            ENDIF
788
      ELSE
788
      ELSE
789
        LMTOLMS = ZRPI18*ATAN2(ZARG1,ZARG2)
789
        LMTOLMS = ZRPI18*ATAN2(ZARG1,ZARG2)
790
      ENDIF
790
      ENDIF
791
 
791
 
792
      RETURN
792
      RETURN
793
      END
793
      END
794
      
794
      
795
      
795
      
796
      REAL FUNCTION LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
796
      REAL FUNCTION LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
797
C
797
C
798
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
798
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
799
C
799
C
800
C**** LMSTOLM  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
800
C**** LMSTOLM  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
801
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
801
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
802
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
802
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
803
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
803
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
804
C**   AUFRUF   :   LAM = LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
804
C**   AUFRUF   :   LAM = LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
805
C**   ENTRIES  :   KEINE
805
C**   ENTRIES  :   KEINE
806
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
806
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
807
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
807
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
808
C**                IM ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
808
C**                IM ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
809
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
809
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
810
C**   VERSIONS-
810
C**   VERSIONS-
811
C**   DATUM    :   03.05.90
811
C**   DATUM    :   03.05.90
812
C**
812
C**
813
C**   EXTERNALS:   KEINE
813
C**   EXTERNALS:   KEINE
814
C**   EINGABE-
814
C**   EINGABE-
815
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
815
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
816
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
816
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
817
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
817
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
818
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
818
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
819
C**   AUSGABE-
819
C**   AUSGABE-
820
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
820
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
821
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
821
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
822
C**
822
C**
823
C**   COMMON-
823
C**   COMMON-
824
C**   BLOECKE  :   KEINE
824
C**   BLOECKE  :   KEINE
825
C**
825
C**
826
C**   FEHLERBE-
826
C**   FEHLERBE-
827
C**   HANDLUNG :   KEINE
827
C**   HANDLUNG :   KEINE
828
C**   VERFASSER:   D.MAJEWSKI
828
C**   VERFASSER:   D.MAJEWSKI
829
 
829
 
830
      REAL        LAMS,PHIS,POLPHI,POLLAM
830
      REAL        LAMS,PHIS,POLPHI,POLLAM
831
 
831
 
832
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
832
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
833
 
833
 
834
      ZSINPOL = SIN(ZPIR18*POLPHI)
834
      ZSINPOL = SIN(ZPIR18*POLPHI)
835
      ZCOSPOL = COS(ZPIR18*POLPHI)
835
      ZCOSPOL = COS(ZPIR18*POLPHI)
836
      ZLAMPOL = ZPIR18*POLLAM
836
      ZLAMPOL = ZPIR18*POLLAM
837
      ZPHIS   = ZPIR18*PHIS
837
      ZPHIS   = ZPIR18*PHIS
838
      ZLAMS   = LAMS
838
      ZLAMS   = LAMS
839
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
839
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
840
      ZLAMS   = ZPIR18*ZLAMS
840
      ZLAMS   = ZPIR18*ZLAMS
841
 
841
 
842
      ZARG1   = SIN(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
842
      ZARG1   = SIN(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
843
     1                          ZCOSPOL*           SIN(ZPHIS)) -
843
     1                          ZCOSPOL*           SIN(ZPHIS)) -
844
     2          COS(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
844
     2          COS(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
845
      ZARG2   = COS(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
845
      ZARG2   = COS(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
846
     1                          ZCOSPOL*           SIN(ZPHIS)) +
846
     1                          ZCOSPOL*           SIN(ZPHIS)) +
847
     2          SIN(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
847
     2          SIN(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
848
      IF (ABS(ZARG2).LT.1.E-30) THEN
848
      IF (ABS(ZARG2).LT.1.E-30) THEN
849
        IF (ABS(ZARG1).LT.1.E-30) THEN
849
        IF (ABS(ZARG1).LT.1.E-30) THEN
850
          LMSTOLM =   0.0
850
          LMSTOLM =   0.0
851
        ELSEIF (ZARG1.GT.0.) THEN
851
        ELSEIF (ZARG1.GT.0.) THEN
852
              LMSTOLAM =  90.0
852
              LMSTOLAM =  90.0
853
            ELSE
853
            ELSE
854
              LMSTOLAM = -90.0
854
              LMSTOLAM = -90.0
855
            ENDIF
855
            ENDIF
856
      ELSE
856
      ELSE
857
        LMSTOLM = ZRPI18*ATAN2(ZARG1,ZARG2)
857
        LMSTOLM = ZRPI18*ATAN2(ZARG1,ZARG2)
858
      ENDIF
858
      ENDIF
859
 
859
 
860
      RETURN
860
      RETURN
861
      END
861
      END