Subversion Repositories lagranto.ecmwf

Rev

Rev 21 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21 Rev 23
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,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
            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
184
               min     = varf(i,j)
185
               min     = varf(i,j)
185
               minindx = i
186
               minindx = i
186
               minindy = j
187
               minindy = j
-
 
188
            endif
187
            elseif ((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
188
               max     = varf(i,j)
190
               max     = varf(i,j)
189
               maxindx = i
191
               maxindx = i
190
               maxindy = j
192
               maxindy = j
191
          endif
193
          endif
192
        enddo
194
        enddo
193
      enddo
195
      enddo
194
      lonmin = xmin + real(minindx-1) * dx
196
      lonmin = xmin + real(minindx-1) * dx
195
      latmin = ymin + real(minindy-1) * dy
197
      latmin = ymin + real(minindy-1) * dy
196
      lonmax = xmin + real(maxindx-1) * dx
198
      lonmax = xmin + real(maxindx-1) * dx
197
      latmax = ymin + real(maxindy-1) * dy
199
      latmax = ymin + real(maxindy-1) * dy
198
 
200
 
199
c     Rotate position to true longitude/latitude 
201
c     Rotate position to true longitude/latitude 
200
      if ((pollon.ne.0.).or.(pollat.ne.90.)) then
202
      if ((pollon.ne.0.).or.(pollat.ne.90.)) then
201
        xphys=lmstolm(latmin,lonmin,pollat,pollon)
203
        xphys=lmstolm(latmin,lonmin,pollat,pollon)
202
        yphys=phstoph(latmin,lonmin,pollat,pollon)
204
        yphys=phstoph(latmin,lonmin,pollat,pollon)
203
        lonmin=xphys
205
        lonmin=xphys
204
        latmin=yphys
206
        latmin=yphys
205
        xphys=lmstolm(latmax,lonmax,pollat,pollon)
207
        xphys=lmstolm(latmax,lonmax,pollat,pollon)
206
        yphys=phstoph(latmax,lonmax,pollat,pollon)
208
        yphys=phstoph(latmax,lonmax,pollat,pollon)
207
        lonmax=xphys
209
        lonmax=xphys
208
        latmax=yphys
210
        latmax=yphys
209
      endif
211
      endif
210
 
212
 
211
c     Write output
213
c     Write output
212
      write(*,101) min,max,lonmin,latmin,nint(level),
214
      write(*,101) min,max,lonmin,latmin,nint(level),
213
     >                     lonmax,latmax,nint(level)
215
     >                     lonmax,latmax,nint(level)
214
  101 format(2f10.3,2f8.2,i6,2f8.2,i6)
216
  101 format(2f10.3,2f8.2,i6,2f8.2,i6)
215
 
217
 
216
c     Close netCDF file
218
c     Close netCDF file
217
      call input_close(cdfid)
219
      call input_close(cdfid)
218
 
220
 
219
      end
221
      end
220
      
222
      
221
c     ----------------------------------------------------------------------
223
c     ----------------------------------------------------------------------
222
C     Interpolates the 3d variable var3d on the pressure surface defined
224
C     Interpolates the 3d variable var3d on the pressure surface defined
223
C     by lev of the variable varl. The interpolated field is
225
C     by lev of the variable varl. The interpolated field is
224
C     returned as var.
226
C     returned as var.
225
C     ipom determines the way of vertical interpolation:
227
C     ipom determines the way of vertical interpolation:
226
C       ipom=0 is for linear interpolation
228
C       ipom=0 is for linear interpolation
227
C       ipom=1 is for logarithmic interpolation
229
C       ipom=1 is for logarithmic interpolation
228
c     ----------------------------------------------------------------------
230
c     ----------------------------------------------------------------------
229
 
231
 
230
      subroutine vipo(var3d,varl,lev,var,nx,ny,nz,mdv,ipom)
232
      subroutine vipo(var3d,varl,lev,var,nx,ny,nz,mdv,ipom)
231
 
233
 
232
      integer   nx,ny,nz,ipom
234
      integer   nx,ny,nz,ipom
233
      real      lev,mdv
235
      real      lev,mdv
234
      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)
235
 
237
 
236
      integer   i,j,k
238
      integer   i,j,k
237
      real      kind
239
      real      kind
238
      real      int3dm
240
      real      int3dm
239
 
241
 
240
      do i=1,nx
242
      do i=1,nx
241
      do j=1,ny
243
      do j=1,ny
242
 
244
 
243
        do k=1,nz-1
245
        do k=1,nz-1
244
          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
245
            kind=float(k)+(varl(i,j,k)-lev)/
247
            kind=float(k)+(varl(i,j,k)-lev)/
246
     >                   (varl(i,j,k)-varl(i,j,k+1))
248
     >                   (varl(i,j,k)-varl(i,j,k+1))
247
            goto 100
249
            goto 100
248
          endif
250
          endif
249
        enddo
251
        enddo
250
 100    continue
252
 100    continue
251
 
253
 
252
        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)
253
 
255
 
254
      enddo
256
      enddo
255
      enddo
257
      enddo
256
 
258
 
257
      return
259
      return
258
      end
260
      end
259
      
261
      
260
c     ----------------------------------------------------------------------
262
c     ----------------------------------------------------------------------
261
C     Interpolates the 3d variable var3d on the isentropic surface defined
263
C     Interpolates the 3d variable var3d on the isentropic surface defined
262
C     by lev of the variable varl. The interpolated field is
264
C     by lev of the variable varl. The interpolated field is
263
C     returned as var.
265
C     returned as var.
264
C     ipom determines the way of vertical interpolation:
266
C     ipom determines the way of vertical interpolation:
265
C       ipom=0 is for linear interpolation
267
C       ipom=0 is for linear interpolation
266
C       ipom=1 is for logarithmic interpolation
268
C       ipom=1 is for logarithmic interpolation
267
c     ----------------------------------------------------------------------
269
c     ----------------------------------------------------------------------
268
 
270
 
269
      subroutine thipo(var3d,th3d,lev,var,nx,ny,nz,mdv,mode)
271
      subroutine thipo(var3d,th3d,lev,var,nx,ny,nz,mdv,mode)
270
 
272
 
271
      integer   nx,ny,nz,mode
273
      integer   nx,ny,nz,mode
272
      real      lev,mdv
274
      real      lev,mdv
273
      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)
274
 
276
 
275
      integer   i,j,k
277
      integer   i,j,k
276
      real      kind
278
      real      kind
277
      real      int3dm
279
      real      int3dm
278
 
280
 
279
      do i=1,nx
281
      do i=1,nx
280
      do j=1,ny
282
      do j=1,ny
281
 
283
 
282
        do k=1,nz-1
284
        do k=1,nz-1
283
          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
284
            kind=float(k)+(th3d(i,j,k)-lev)/
286
            kind=float(k)+(th3d(i,j,k)-lev)/
285
     >                   (th3d(i,j,k)-th3d(i,j,k+1))
287
     >                   (th3d(i,j,k)-th3d(i,j,k+1))
286
            goto 100
288
            goto 100
287
          endif
289
          endif
288
        enddo
290
        enddo
289
 100    continue
291
 100    continue
290
 
292
 
291
        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)
292
 
294
 
293
      enddo
295
      enddo
294
      enddo
296
      enddo
295
 
297
 
296
      return
298
      return
297
      end
299
      end
298
      
300
      
299
c     ----------------------------------------------------------------------
301
c     ----------------------------------------------------------------------
300
c     Check whether character appears within string
302
c     Check whether character appears within string
301
c     ----------------------------------------------------------------------
303
c     ----------------------------------------------------------------------
302
 
304
 
303
      subroutine checkchar(string,char,flag)
305
      subroutine checkchar(string,char,flag)
304
 
306
 
305
      character*(*)     string
307
      character*(*)     string
306
      character*(1)     char
308
      character*(1)     char
307
      integer           n,flag
309
      integer           n,flag
308
 
310
 
309
      flag=0
311
      flag=0
310
      do n=1,len(string)
312
      do n=1,len(string)
311
        if (string(n:n).eq.char) then
313
        if (string(n:n).eq.char) then
312
          flag=n
314
          flag=n
313
          return
315
          return
314
        endif
316
        endif
315
      enddo
317
      enddo
316
      end
318
      end
317
      
319
      
318
c     ----------------------------------------------------------------------
320
c     ----------------------------------------------------------------------
319
c     3D interpolation
321
c     3D interpolation
320
c     ----------------------------------------------------------------------
322
c     ----------------------------------------------------------------------
321
      
323
      
322
      real function int3d(ar,n1,n2,n3,rid,rjd,rkd)
324
      real function int3d(ar,n1,n2,n3,rid,rjd,rkd)
323
 
325
 
324
c     Purpose:
326
c     Purpose:
325
c        This subroutine interpolates a 3d-array to an arbitrary
327
c        This subroutine interpolates a 3d-array to an arbitrary
326
c        location within the grid.
328
c        location within the grid.
327
c     Arguments:
329
c     Arguments:
328
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)
329
c        n1,n2,n3  int   input   dimensions of ar
331
c        n1,n2,n3  int   input   dimensions of ar
330
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
331
c     History:
333
c     History:
332
 
334
 
333
c     argument declarations
335
c     argument declarations
334
      integer   n1,n2,n3
336
      integer   n1,n2,n3
335
      real      ar(n1,n2,n3), rid,rjd,rkd
337
      real      ar(n1,n2,n3), rid,rjd,rkd
336
 
338
 
337
c     local declarations
339
c     local declarations
338
      integer   i,j,k,ip1,jp1,kp1,ih,jh,kh
340
      integer   i,j,k,ip1,jp1,kp1,ih,jh,kh
339
      real      frac0i,frac0j,frac0k,frac1i,frac1j,frac1k,ri,rj,rk
341
      real      frac0i,frac0j,frac0k,frac1i,frac1j,frac1k,ri,rj,rk
340
 
342
 
341
c     do linear interpolation
343
c     do linear interpolation
342
      ri=amax1(1.,amin1(float(n1),rid))
344
      ri=amax1(1.,amin1(float(n1),rid))
343
      rj=amax1(1.,amin1(float(n2),rjd))
345
      rj=amax1(1.,amin1(float(n2),rjd))
344
      rk=amax1(1.,amin1(float(n3),rkd))
346
      rk=amax1(1.,amin1(float(n3),rkd))
345
      ih=nint(ri)
347
      ih=nint(ri)
346
      jh=nint(rj)
348
      jh=nint(rj)
347
      kh=nint(rk)
349
      kh=nint(rk)
348
 
350
 
349
c     Check for interpolation in i
351
c     Check for interpolation in i
350
*     if (abs(float(ih)-ri).lt.1.e-3) then
352
*     if (abs(float(ih)-ri).lt.1.e-3) then
351
*       i  =ih
353
*       i  =ih
352
*       ip1=ih
354
*       ip1=ih
353
*     else
355
*     else
354
        i =min0(int(ri),n1-1)
356
        i =min0(int(ri),n1-1)
355
        ip1=i+1
357
        ip1=i+1
356
*     endif
358
*     endif
357
 
359
 
358
c     Check for interpolation in j
360
c     Check for interpolation in j
359
      if (abs(float(jh)-rj).lt.1.e-3) then
361
      if (abs(float(jh)-rj).lt.1.e-3) then
360
        j  =jh
362
        j  =jh
361
        jp1=jh
363
        jp1=jh
362
      else
364
      else
363
        j =min0(int(rj),n2-1)
365
        j =min0(int(rj),n2-1)
364
        jp1=j+1
366
        jp1=j+1
365
      endif
367
      endif
366
 
368
 
367
c     Check for interpolation in k
369
c     Check for interpolation in k
368
*     if (abs(float(kh)-rk).lt.1.e-3) then
370
*     if (abs(float(kh)-rk).lt.1.e-3) then
369
*       k  =kh
371
*       k  =kh
370
*       kp1=kh
372
*       kp1=kh
371
*     else
373
*     else
372
        k =min0(int(rk),n3-1)
374
        k =min0(int(rk),n3-1)
373
        kp1=k+1
375
        kp1=k+1
374
*     endif
376
*     endif
375
 
377
 
376
      if (k.eq.kp1) then
378
      if (k.eq.kp1) then
377
c       no interpolation in k
379
c       no interpolation in k
378
        if ((i.eq.ip1).and.(j.eq.jp1)) then
380
        if ((i.eq.ip1).and.(j.eq.jp1)) then
379
c          no interpolation at all
381
c          no interpolation at all
380
           int3d=ar(i,j,k)
382
           int3d=ar(i,j,k)
381
c          print *,'int3d 00: ',rid,rjd,rkd,int3d
383
c          print *,'int3d 00: ',rid,rjd,rkd,int3d
382
        else
384
        else
383
c          horizontal interpolation only
385
c          horizontal interpolation only
384
           frac0i=ri-float(i)
386
           frac0i=ri-float(i)
385
           frac0j=rj-float(j)
387
           frac0j=rj-float(j)
386
           frac1i=1.-frac0i
388
           frac1i=1.-frac0i
387
           frac1j=1.-frac0j
389
           frac1j=1.-frac0j
388
           int3d = ar(i  ,j  ,k  ) * frac1i * frac1j
390
           int3d = ar(i  ,j  ,k  ) * frac1i * frac1j
389
     &           + ar(i  ,jp1,k  ) * frac1i * frac0j
391
     &           + ar(i  ,jp1,k  ) * frac1i * frac0j
390
     &           + ar(ip1,j  ,k  ) * frac0i * frac1j
392
     &           + ar(ip1,j  ,k  ) * frac0i * frac1j
391
     &           + ar(ip1,jp1,k  ) * frac0i * frac0j
393
     &           + ar(ip1,jp1,k  ) * frac0i * frac0j
392
c          print *,'int3d 10: ',rid,rjd,rkd,int3d
394
c          print *,'int3d 10: ',rid,rjd,rkd,int3d
393
        endif
395
        endif
394
      else 
396
      else 
395
        frac0k=rk-float(k)
397
        frac0k=rk-float(k)
396
        frac1k=1.-frac0k
398
        frac1k=1.-frac0k
397
        if ((i.eq.ip1).and.(j.eq.jp1)) then
399
        if ((i.eq.ip1).and.(j.eq.jp1)) then
398
c          vertical interpolation only
400
c          vertical interpolation only
399
           int3d = ar(i  ,j  ,k  ) * frac1k
401
           int3d = ar(i  ,j  ,k  ) * frac1k
400
     &           + ar(i  ,j  ,kp1) * frac0k
402
     &           + ar(i  ,j  ,kp1) * frac0k
401
c          print *,'int3d 01: ',rid,rjd,rkd,int3d
403
c          print *,'int3d 01: ',rid,rjd,rkd,int3d
402
        else
404
        else
403
c          full 3d interpolation
405
c          full 3d interpolation
404
           frac0i=ri-float(i)
406
           frac0i=ri-float(i)
405
           frac0j=rj-float(j)
407
           frac0j=rj-float(j)
406
           frac1i=1.-frac0i
408
           frac1i=1.-frac0i
407
           frac1j=1.-frac0j
409
           frac1j=1.-frac0j
408
           int3d = ar(i  ,j  ,k  ) * frac1i * frac1j * frac1k
410
           int3d = ar(i  ,j  ,k  ) * frac1i * frac1j * frac1k
409
     &           + ar(i  ,jp1,k  ) * frac1i * frac0j * frac1k 
411
     &           + ar(i  ,jp1,k  ) * frac1i * frac0j * frac1k 
410
     &           + ar(ip1,j  ,k  ) * frac0i * frac1j * frac1k
412
     &           + ar(ip1,j  ,k  ) * frac0i * frac1j * frac1k
411
     &           + ar(ip1,jp1,k  ) * frac0i * frac0j * frac1k
413
     &           + ar(ip1,jp1,k  ) * frac0i * frac0j * frac1k
412
     &           + ar(i  ,j  ,kp1) * frac1i * frac1j * frac0k
414
     &           + ar(i  ,j  ,kp1) * frac1i * frac1j * frac0k
413
     &           + ar(i  ,jp1,kp1) * frac1i * frac0j * frac0k 
415
     &           + ar(i  ,jp1,kp1) * frac1i * frac0j * frac0k 
414
     &           + ar(ip1,j  ,kp1) * frac0i * frac1j * frac0k
416
     &           + ar(ip1,j  ,kp1) * frac0i * frac1j * frac0k
415
     &           + ar(ip1,jp1,kp1) * frac0i * frac0j * frac0k
417
     &           + ar(ip1,jp1,kp1) * frac0i * frac0j * frac0k
416
c          print *,'int3d 11: ',rid,rjd,rkd,int3d
418
c          print *,'int3d 11: ',rid,rjd,rkd,int3d
417
        endif
419
        endif
418
      endif
420
      endif
419
      end
421
      end
420
      
422
      
421
c     ----------------------------------------------------------------------
423
c     ----------------------------------------------------------------------
422
c     3D interpolation including missing data check
424
c     3D interpolation including missing data check
423
c     ----------------------------------------------------------------------
425
c     ----------------------------------------------------------------------
424
  
426
  
425
      real function int3dm(ar,n1,n2,n3,rid,rjd,rkd,misdat)
427
      real function int3dm(ar,n1,n2,n3,rid,rjd,rkd,misdat)
426
 
428
 
427
c     Purpose:
429
c     Purpose:
428
c        This subroutine interpolates a 3d-array to an arbitrary
430
c        This subroutine interpolates a 3d-array to an arbitrary
429
c        location within the grid. The interpolation includes the 
431
c        location within the grid. The interpolation includes the 
430
c        testing of the missing data flag 'misdat'. 
432
c        testing of the missing data flag 'misdat'. 
431
c     Arguments:
433
c     Arguments:
432
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)
433
c        n1,n2,n3  int   input   dimensions of ar
435
c        n1,n2,n3  int   input   dimensions of ar
434
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
435
c        misdat    real  input   missing data flag (on if misdat<>0)
437
c        misdat    real  input   missing data flag (on if misdat<>0)
436
c     Warning:
438
c     Warning:
437
c        This routine has not yet been seriously tested
439
c        This routine has not yet been seriously tested
438
c     History:
440
c     History:
439
 
441
 
440
c     argument declarations
442
c     argument declarations
441
      integer   n1,n2,n3
443
      integer   n1,n2,n3
442
      real      ar(n1,n2,n3), rid,rjd,rkd, misdat
444
      real      ar(n1,n2,n3), rid,rjd,rkd, misdat
443
 
445
 
444
c     local declarations
446
c     local declarations
445
      integer   i,j,k,ip1,jp1,kp1,ih,jh,kh
447
      integer   i,j,k,ip1,jp1,kp1,ih,jh,kh
446
      real      frac0i,frac0j,frac0k,frac1i,frac1j,frac1k,ri,rj,rk,int3d
448
      real      frac0i,frac0j,frac0k,frac1i,frac1j,frac1k,ri,rj,rk,int3d
447
 
449
 
448
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
449
      if (misdat.eq.0.) then
451
      if (misdat.eq.0.) then
450
        int3dm=int3d(ar,n1,n2,n3,rid,rjd,rkd)
452
        int3dm=int3d(ar,n1,n2,n3,rid,rjd,rkd)
451
        return
453
        return
452
      endif
454
      endif
453
 
455
 
454
c     do linear interpolation
456
c     do linear interpolation
455
      ri=amax1(1.,amin1(float(n1),rid))
457
      ri=amax1(1.,amin1(float(n1),rid))
456
      rj=amax1(1.,amin1(float(n2),rjd))
458
      rj=amax1(1.,amin1(float(n2),rjd))
457
      rk=amax1(1.,amin1(float(n3),rkd))
459
      rk=amax1(1.,amin1(float(n3),rkd))
458
      ih=nint(ri)
460
      ih=nint(ri)
459
      jh=nint(rj)
461
      jh=nint(rj)
460
      kh=nint(rk)
462
      kh=nint(rk)
461
 
463
 
462
c     Check for interpolation in i
464
c     Check for interpolation in i
463
*     if (abs(float(ih)-ri).lt.1.e-3) then
465
*     if (abs(float(ih)-ri).lt.1.e-3) then
464
*       i  =ih
466
*       i  =ih
465
*       ip1=ih
467
*       ip1=ih
466
*     else
468
*     else
467
        i =min0(int(ri),n1-1)
469
        i =min0(int(ri),n1-1)
468
        ip1=i+1
470
        ip1=i+1
469
*     endif
471
*     endif
470
 
472
 
471
c     Check for interpolation in j
473
c     Check for interpolation in j
472
*     if (abs(float(jh)-rj).lt.1.e-3) then
474
*     if (abs(float(jh)-rj).lt.1.e-3) then
473
*       j  =jh
475
*       j  =jh
474
*       jp1=jh
476
*       jp1=jh
475
*     else
477
*     else
476
        j =min0(int(rj),n2-1)
478
        j =min0(int(rj),n2-1)
477
        jp1=j+1
479
        jp1=j+1
478
*     endif
480
*     endif
479
 
481
 
480
c     Check for interpolation in k
482
c     Check for interpolation in k
481
*     if (abs(float(kh)-rk).lt.1.e-3) then
483
*     if (abs(float(kh)-rk).lt.1.e-3) then
482
*       k  =kh
484
*       k  =kh
483
*       kp1=kh
485
*       kp1=kh
484
*     else
486
*     else
485
        k =min0(int(rk),n3-1)
487
        k =min0(int(rk),n3-1)
486
        kp1=k+1
488
        kp1=k+1
487
*     endif
489
*     endif
488
 
490
 
489
      if (k.eq.kp1) then
491
      if (k.eq.kp1) then
490
c       no interpolation in k
492
c       no interpolation in k
491
        if ((i.eq.ip1).and.(j.eq.jp1)) then
493
        if ((i.eq.ip1).and.(j.eq.jp1)) then
492
c          no interpolation at all
494
c          no interpolation at all
493
           if (misdat.eq.ar(i,j,k)) then
495
           if (misdat.eq.ar(i,j,k)) then
494
             int3dm=misdat
496
             int3dm=misdat
495
           else
497
           else
496
             int3dm=ar(i,j,k)
498
             int3dm=ar(i,j,k)
497
           endif
499
           endif
498
c          print *,'int3dm 00: ',rid,rjd,rkd,int3dm
500
c          print *,'int3dm 00: ',rid,rjd,rkd,int3dm
499
        else
501
        else
500
c          horizontal interpolation only
502
c          horizontal interpolation only
501
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
503
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
502
     &         (misdat.eq.ar(i  ,jp1,k  )).or.
504
     &         (misdat.eq.ar(i  ,jp1,k  )).or.
503
     &         (misdat.eq.ar(ip1,j  ,k  )).or.
505
     &         (misdat.eq.ar(ip1,j  ,k  )).or.
504
     &         (misdat.eq.ar(ip1,jp1,k  ))) then
506
     &         (misdat.eq.ar(ip1,jp1,k  ))) then
505
             int3dm=misdat
507
             int3dm=misdat
506
           else
508
           else
507
             frac0i=ri-float(i)
509
             frac0i=ri-float(i)
508
             frac0j=rj-float(j)
510
             frac0j=rj-float(j)
509
             frac1i=1.-frac0i
511
             frac1i=1.-frac0i
510
             frac1j=1.-frac0j
512
             frac1j=1.-frac0j
511
             int3dm = ar(i  ,j  ,k  ) * frac1i * frac1j
513
             int3dm = ar(i  ,j  ,k  ) * frac1i * frac1j
512
     &              + ar(i  ,jp1,k  ) * frac1i * frac0j
514
     &              + ar(i  ,jp1,k  ) * frac1i * frac0j
513
     &              + ar(ip1,j  ,k  ) * frac0i * frac1j
515
     &              + ar(ip1,j  ,k  ) * frac0i * frac1j
514
     &              + ar(ip1,jp1,k  ) * frac0i * frac0j
516
     &              + ar(ip1,jp1,k  ) * frac0i * frac0j
515
c            print *,'int3dm 10: ',rid,rjd,rkd,int3dm
517
c            print *,'int3dm 10: ',rid,rjd,rkd,int3dm
516
           endif
518
           endif
517
        endif
519
        endif
518
      else 
520
      else 
519
        frac0k=rk-float(k)
521
        frac0k=rk-float(k)
520
        frac1k=1.-frac0k
522
        frac1k=1.-frac0k
521
        if ((i.eq.ip1).and.(j.eq.jp1)) then
523
        if ((i.eq.ip1).and.(j.eq.jp1)) then
522
c          vertical interpolation only
524
c          vertical interpolation only
523
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
525
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
524
     &         (misdat.eq.ar(i  ,j  ,kp1))) then
526
     &         (misdat.eq.ar(i  ,j  ,kp1))) then
525
             int3dm=misdat
527
             int3dm=misdat
526
           else
528
           else
527
             int3dm = ar(i  ,j  ,k  ) * frac1k
529
             int3dm = ar(i  ,j  ,k  ) * frac1k
528
     &              + ar(i  ,j  ,kp1) * frac0k
530
     &              + ar(i  ,j  ,kp1) * frac0k
529
c            print *,'int3dm 01: ',rid,rjd,rkd,int3dm
531
c            print *,'int3dm 01: ',rid,rjd,rkd,int3dm
530
           endif
532
           endif
531
        else
533
        else
532
c          full 3d interpolation
534
c          full 3d interpolation
533
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
535
           if ((misdat.eq.ar(i  ,j  ,k  )).or.
534
     &         (misdat.eq.ar(i  ,jp1,k  )).or.
536
     &         (misdat.eq.ar(i  ,jp1,k  )).or.
535
     &         (misdat.eq.ar(ip1,j  ,k  )).or.
537
     &         (misdat.eq.ar(ip1,j  ,k  )).or.
536
     &         (misdat.eq.ar(ip1,jp1,k  )).or.
538
     &         (misdat.eq.ar(ip1,jp1,k  )).or.
537
     &         (misdat.eq.ar(i  ,j  ,kp1)).or.
539
     &         (misdat.eq.ar(i  ,j  ,kp1)).or.
538
     &         (misdat.eq.ar(i  ,jp1,kp1)).or.
540
     &         (misdat.eq.ar(i  ,jp1,kp1)).or.
539
     &         (misdat.eq.ar(ip1,j  ,kp1)).or.
541
     &         (misdat.eq.ar(ip1,j  ,kp1)).or.
540
     &         (misdat.eq.ar(ip1,jp1,kp1))) then
542
     &         (misdat.eq.ar(ip1,jp1,kp1))) then
541
             int3dm=misdat
543
             int3dm=misdat
542
           else
544
           else
543
             frac0i=ri-float(i)
545
             frac0i=ri-float(i)
544
             frac0j=rj-float(j)
546
             frac0j=rj-float(j)
545
             frac1i=1.-frac0i
547
             frac1i=1.-frac0i
546
             frac1j=1.-frac0j
548
             frac1j=1.-frac0j
547
             int3dm = ar(i  ,j  ,k  ) * frac1i * frac1j * frac1k
549
             int3dm = ar(i  ,j  ,k  ) * frac1i * frac1j * frac1k
548
     &              + ar(i  ,jp1,k  ) * frac1i * frac0j * frac1k
550
     &              + ar(i  ,jp1,k  ) * frac1i * frac0j * frac1k
549
     &              + ar(ip1,j  ,k  ) * frac0i * frac1j * frac1k
551
     &              + ar(ip1,j  ,k  ) * frac0i * frac1j * frac1k
550
     &              + ar(ip1,jp1,k  ) * frac0i * frac0j * frac1k
552
     &              + ar(ip1,jp1,k  ) * frac0i * frac0j * frac1k
551
     &              + ar(i  ,j  ,kp1) * frac1i * frac1j * frac0k
553
     &              + ar(i  ,j  ,kp1) * frac1i * frac1j * frac0k
552
     &              + ar(i  ,jp1,kp1) * frac1i * frac0j * frac0k
554
     &              + ar(i  ,jp1,kp1) * frac1i * frac0j * frac0k
553
     &              + ar(ip1,j  ,kp1) * frac0i * frac1j * frac0k
555
     &              + ar(ip1,j  ,kp1) * frac0i * frac1j * frac0k
554
     &              + ar(ip1,jp1,kp1) * frac0i * frac0j * frac0k
556
     &              + ar(ip1,jp1,kp1) * frac0i * frac0j * frac0k
555
c            print *,'int3dm 11: ',rid,rjd,rkd,int3dm
557
c            print *,'int3dm 11: ',rid,rjd,rkd,int3dm
556
           endif
558
           endif
557
        endif
559
        endif
558
      endif
560
      endif
559
      end
561
      end
560
 
562
 
561
c     ----------------------------------------------------------------------
563
c     ----------------------------------------------------------------------
562
c     Calculate potential temperature
564
c     Calculate potential temperature
563
c     ----------------------------------------------------------------------
565
c     ----------------------------------------------------------------------
564
 
566
 
565
      subroutine pottemp(pt,t,sp,ie,je,ke,ak,bk)
567
      subroutine pottemp(pt,t,sp,ie,je,ke,ak,bk)
566
 
568
 
567
c     argument declaration
569
c     argument declaration
568
      integer   ie,je,ke
570
      integer   ie,je,ke
569
      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),
570
     >     	ak(ke),bk(ke)
572
     >     	ak(ke),bk(ke)
571
 
573
 
572
c     variable declaration
574
c     variable declaration
573
      integer   i,j,k
575
      integer   i,j,k
574
      real      rdcp,tzero
576
      real      rdcp,tzero
575
      data      rdcp,tzero /0.286,273.15/
577
      data      rdcp,tzero /0.286,273.15/
576
 
578
 
577
c     statement-functions for the computation of pressure
579
c     statement-functions for the computation of pressure
578
      real      pp,psrf
580
      real      pp,psrf
579
      integer   is
581
      integer   is
580
      pp(is)=ak(is)+bk(is)*psrf
582
      pp(is)=ak(is)+bk(is)*psrf
581
 
583
 
582
c     computation of potential temperature
584
c     computation of potential temperature
583
      do i=1,ie
585
      do i=1,ie
584
      do j=1,je
586
      do j=1,je
585
        psrf=sp(i,j)
587
        psrf=sp(i,j)
586
        do k=1,ke
588
        do k=1,ke
587
c     distinction of temperature in K and deg C
589
c     distinction of temperature in K and deg C
588
          if (t(i,j,k).lt.100.) then
590
          if (t(i,j,k).lt.100.) then
589
            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 )
590
          else
592
          else
591
            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 )
592
          endif
594
          endif
593
        enddo
595
        enddo
594
      enddo
596
      enddo
595
      enddo
597
      enddo
596
      end
598
      end
597
      
599
      
598
c     ----------------------------------------------------------------------
600
c     ----------------------------------------------------------------------
599
c     Calculate 3D pressure
601
c     Calculate 3D pressure
600
c     ----------------------------------------------------------------------
602
c     ----------------------------------------------------------------------
601
 
603
 
602
      subroutine pres(pr,sp,ie,je,ke,ak,bk)
604
      subroutine pres(pr,sp,ie,je,ke,ak,bk)
603
 
605
 
604
c     argument declaration
606
c     argument declaration
605
      integer  ie,je,ke
607
      integer  ie,je,ke
606
      real,intent(OUT) :: pr(ie,je,ke)
608
      real,intent(OUT) :: pr(ie,je,ke)
607
      real,intent(IN)  :: sp(ie,je)
609
      real,intent(IN)  :: sp(ie,je)
608
      real,intent(IN)  :: ak(ke),bk(ke)
610
      real,intent(IN)  :: ak(ke),bk(ke)
609
 
611
 
610
c     variable declaration
612
c     variable declaration
611
      integer  i,j,k
613
      integer  i,j,k
612
 
614
 
613
c     computation pressure
615
c     computation pressure
614
      do i=1,ie
616
      do i=1,ie
615
      do j=1,je
617
      do j=1,je
616
      do k=1,ke
618
      do k=1,ke
617
        pr(i,j,k)=ak(k)+bk(k)*sp(i,j)
619
        pr(i,j,k)=ak(k)+bk(k)*sp(i,j)
618
      enddo
620
      enddo
619
      enddo
621
      enddo
620
      enddo
622
      enddo
621
      end
623
      end
622
      
624
      
623
c     ----------------------------------------------------------------------
625
c     ----------------------------------------------------------------------
624
c     Coordinate rotations from COSMO
626
c     Coordinate rotations from COSMO
625
c     ----------------------------------------------------------------------      
627
c     ----------------------------------------------------------------------      
626
      
628
      
627
      REAL FUNCTION PHTOPHS (PHI, LAM, POLPHI, POLLAM)
629
      REAL FUNCTION PHTOPHS (PHI, LAM, POLPHI, POLLAM)
628
C
630
C
629
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
631
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
630
C
632
C
631
C**** PHTOPHS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI
633
C**** PHTOPHS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI
632
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
634
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
633
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
635
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
634
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
636
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
635
C**   AUFRUF   :   PHI = PHTOPHS (PHI, LAM, POLPHI, POLLAM)
637
C**   AUFRUF   :   PHI = PHTOPHS (PHI, LAM, POLPHI, POLLAM)
636
C**   ENTRIES  :   KEINE
638
C**   ENTRIES  :   KEINE
637
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI AUF
639
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI AUF
638
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
640
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
639
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
641
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
640
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
642
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
641
C**   VERSIONS-
643
C**   VERSIONS-
642
C**   DATUM    :   03.05.90
644
C**   DATUM    :   03.05.90
643
C**
645
C**
644
C**   EXTERNALS:   KEINE
646
C**   EXTERNALS:   KEINE
645
C**   EINGABE-
647
C**   EINGABE-
646
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
648
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
647
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
649
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
648
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
650
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
649
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
651
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
650
C**   AUSGABE-
652
C**   AUSGABE-
651
C**   PARAMETER:   ROTIERTE BREITE PHIS ALS WERT DER FUNKTION
653
C**   PARAMETER:   ROTIERTE BREITE PHIS ALS WERT DER FUNKTION
652
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
654
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
653
C**
655
C**
654
C**   COMMON-
656
C**   COMMON-
655
C**   BLOECKE  :   KEINE
657
C**   BLOECKE  :   KEINE
656
C**
658
C**
657
C**   FEHLERBE-
659
C**   FEHLERBE-
658
C**   HANDLUNG :   KEINE
660
C**   HANDLUNG :   KEINE
659
C**   VERFASSER:   G. DE MORSIER
661
C**   VERFASSER:   G. DE MORSIER
660
 
662
 
661
      REAL        LAM,PHI,POLPHI,POLLAM
663
      REAL        LAM,PHI,POLPHI,POLLAM
662
 
664
 
663
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
665
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
664
 
666
 
665
      ZSINPOL = SIN(ZPIR18*POLPHI)
667
      ZSINPOL = SIN(ZPIR18*POLPHI)
666
      ZCOSPOL = COS(ZPIR18*POLPHI)
668
      ZCOSPOL = COS(ZPIR18*POLPHI)
667
      ZLAMPOL = ZPIR18*POLLAM
669
      ZLAMPOL = ZPIR18*POLLAM
668
      ZPHI    = ZPIR18*PHI
670
      ZPHI    = ZPIR18*PHI
669
      ZLAM    = LAM
671
      ZLAM    = LAM
670
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
672
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
671
      ZLAM    = ZPIR18*ZLAM
673
      ZLAM    = ZPIR18*ZLAM
672
      ZARG    = ZCOSPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL) + ZSINPOL*SIN(ZPHI)
674
      ZARG    = ZCOSPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL) + ZSINPOL*SIN(ZPHI)
673
 
675
 
674
      PHTOPHS = ZRPI18*ASIN(ZARG)
676
      PHTOPHS = ZRPI18*ASIN(ZARG)
675
 
677
 
676
      RETURN
678
      RETURN
677
      END
679
      END
678
      
680
      
679
      
681
      
680
      REAL FUNCTION PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
682
      REAL FUNCTION PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
681
C
683
C
682
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
684
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
683
C
685
C
684
C**** PHSTOPH  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
686
C**** PHSTOPH  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
685
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
687
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
686
C****                 ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
688
C****                 ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
687
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
689
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
688
C**   AUFRUF   :   PHI = PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
690
C**   AUFRUF   :   PHI = PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)
689
C**   ENTRIES  :   KEINE
691
C**   ENTRIES  :   KEINE
690
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
692
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUER
691
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
693
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
692
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
694
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
693
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
695
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
694
C**   VERSIONS-
696
C**   VERSIONS-
695
C**   DATUM    :   03.05.90
697
C**   DATUM    :   03.05.90
696
C**
698
C**
697
C**   EXTERNALS:   KEINE
699
C**   EXTERNALS:   KEINE
698
C**   EINGABE-
700
C**   EINGABE-
699
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
701
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
700
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
702
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
701
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
703
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
702
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
704
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
703
C**   AUSGABE-
705
C**   AUSGABE-
704
C**   PARAMETER:   WAHRE GEOGRAPHISCHE BREITE ALS WERT DER FUNKTION
706
C**   PARAMETER:   WAHRE GEOGRAPHISCHE BREITE ALS WERT DER FUNKTION
705
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
707
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
706
C**
708
C**
707
C**   COMMON-
709
C**   COMMON-
708
C**   BLOECKE  :   KEINE
710
C**   BLOECKE  :   KEINE
709
C**
711
C**
710
C**   FEHLERBE-
712
C**   FEHLERBE-
711
C**   HANDLUNG :   KEINE
713
C**   HANDLUNG :   KEINE
712
C**   VERFASSER:   D.MAJEWSKI
714
C**   VERFASSER:   D.MAJEWSKI
713
 
715
 
714
      REAL        LAMS,PHIS,POLPHI,POLLAM
716
      REAL        LAMS,PHIS,POLPHI,POLLAM
715
 
717
 
716
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
718
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
717
 
719
 
718
      SINPOL = SIN(ZPIR18*POLPHI)
720
      SINPOL = SIN(ZPIR18*POLPHI)
719
      COSPOL = COS(ZPIR18*POLPHI)
721
      COSPOL = COS(ZPIR18*POLPHI)
720
      ZPHIS  = ZPIR18*PHIS
722
      ZPHIS  = ZPIR18*PHIS
721
      ZLAMS  = LAMS
723
      ZLAMS  = LAMS
722
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
724
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
723
      ZLAMS  = ZPIR18*ZLAMS
725
      ZLAMS  = ZPIR18*ZLAMS
724
      ARG     = COSPOL*COS(ZPHIS)*COS(ZLAMS) + SINPOL*SIN(ZPHIS)
726
      ARG     = COSPOL*COS(ZPHIS)*COS(ZLAMS) + SINPOL*SIN(ZPHIS)
725
 
727
 
726
      PHSTOPH = ZRPI18*ASIN(ARG)
728
      PHSTOPH = ZRPI18*ASIN(ARG)
727
 
729
 
728
      RETURN
730
      RETURN
729
      END
731
      END
730
      REAL FUNCTION LMTOLMS (PHI, LAM, POLPHI, POLLAM)
732
      REAL FUNCTION LMTOLMS (PHI, LAM, POLPHI, POLLAM)
731
C
733
C
732
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
734
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
733
C
735
C
734
C**** LMTOLMS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM
736
C**** LMTOLMS  -   FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM
735
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
737
C****                 AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
736
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
738
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
737
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
739
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
738
C**   AUFRUF   :   LAM = LMTOLMS (PHI, LAM, POLPHI, POLLAM)
740
C**   AUFRUF   :   LAM = LMTOLMS (PHI, LAM, POLPHI, POLLAM)
739
C**   ENTRIES  :   KEINE
741
C**   ENTRIES  :   KEINE
740
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM AUF
742
C**   ZWECK    :   UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM AUF
741
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
743
C**                EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IM
742
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
744
C**                ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
743
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
745
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
744
C**   VERSIONS-
746
C**   VERSIONS-
745
C**   DATUM    :   03.05.90
747
C**   DATUM    :   03.05.90
746
C**
748
C**
747
C**   EXTERNALS:   KEINE
749
C**   EXTERNALS:   KEINE
748
C**   EINGABE-
750
C**   EINGABE-
749
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
751
C**   PARAMETER:   PHI    REAL BREITE DES PUNKTES IM GEOGR. SYSTEM
750
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
752
C**                LAM    REAL LAENGE DES PUNKTES IM GEOGR. SYSTEM
751
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
753
C**                POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMS
752
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
754
C**                POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMS
753
C**   AUSGABE-
755
C**   AUSGABE-
754
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
756
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
755
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
757
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
756
C**
758
C**
757
C**   COMMON-
759
C**   COMMON-
758
C**   BLOECKE  :   KEINE
760
C**   BLOECKE  :   KEINE
759
C**
761
C**
760
C**   FEHLERBE-
762
C**   FEHLERBE-
761
C**   HANDLUNG :   KEINE
763
C**   HANDLUNG :   KEINE
762
C**   VERFASSER:   G. DE MORSIER
764
C**   VERFASSER:   G. DE MORSIER
763
 
765
 
764
      REAL        LAM,PHI,POLPHI,POLLAM
766
      REAL        LAM,PHI,POLPHI,POLLAM
765
 
767
 
766
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
768
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
767
 
769
 
768
      ZSINPOL = SIN(ZPIR18*POLPHI)
770
      ZSINPOL = SIN(ZPIR18*POLPHI)
769
      ZCOSPOL = COS(ZPIR18*POLPHI)
771
      ZCOSPOL = COS(ZPIR18*POLPHI)
770
      ZLAMPOL =     ZPIR18*POLLAM
772
      ZLAMPOL =     ZPIR18*POLLAM
771
      ZPHI    =     ZPIR18*PHI
773
      ZPHI    =     ZPIR18*PHI
772
      ZLAM    = LAM
774
      ZLAM    = LAM
773
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
775
      IF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0
774
      ZLAM    = ZPIR18*ZLAM
776
      ZLAM    = ZPIR18*ZLAM
775
 
777
 
776
      ZARG1   = - SIN(ZLAM-ZLAMPOL)*COS(ZPHI)
778
      ZARG1   = - SIN(ZLAM-ZLAMPOL)*COS(ZPHI)
777
      ZARG2   = - ZSINPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL)+ZCOSPOL*SIN(ZPHI)
779
      ZARG2   = - ZSINPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL)+ZCOSPOL*SIN(ZPHI)
778
      IF (ABS(ZARG2).LT.1.E-30) THEN
780
      IF (ABS(ZARG2).LT.1.E-30) THEN
779
        IF (ABS(ZARG1).LT.1.E-30) THEN
781
        IF (ABS(ZARG1).LT.1.E-30) THEN
780
          LMTOLMS =   0.0
782
          LMTOLMS =   0.0
781
        ELSEIF (ZARG1.GT.0.) THEN
783
        ELSEIF (ZARG1.GT.0.) THEN
782
              LMTOLMS =  90.0
784
              LMTOLMS =  90.0
783
            ELSE
785
            ELSE
784
              LMTOLMS = -90.0
786
              LMTOLMS = -90.0
785
            ENDIF
787
            ENDIF
786
      ELSE
788
      ELSE
787
        LMTOLMS = ZRPI18*ATAN2(ZARG1,ZARG2)
789
        LMTOLMS = ZRPI18*ATAN2(ZARG1,ZARG2)
788
      ENDIF
790
      ENDIF
789
 
791
 
790
      RETURN
792
      RETURN
791
      END
793
      END
792
      
794
      
793
      
795
      
794
      REAL FUNCTION LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
796
      REAL FUNCTION LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
795
C
797
C
796
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
798
C%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%
797
C
799
C
798
C**** LMSTOLM  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
800
C**** LMSTOLM  -   FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
799
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
801
C****                 EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
800
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
802
C****                 IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HAT
801
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
803
C****                 DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
802
C**   AUFRUF   :   LAM = LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
804
C**   AUFRUF   :   LAM = LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)
803
C**   ENTRIES  :   KEINE
805
C**   ENTRIES  :   KEINE
804
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
806
C**   ZWECK    :   BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUER
805
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
807
C**                EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)
806
C**                IM ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
808
C**                IM ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HAT
807
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
809
C**                DIE WAHREN KOORDINATEN (POLPHI, POLLAM)
808
C**   VERSIONS-
810
C**   VERSIONS-
809
C**   DATUM    :   03.05.90
811
C**   DATUM    :   03.05.90
810
C**
812
C**
811
C**   EXTERNALS:   KEINE
813
C**   EXTERNALS:   KEINE
812
C**   EINGABE-
814
C**   EINGABE-
813
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
815
C**   PARAMETER:   PHIS     REAL   GEOGR. BREITE DES PUNKTES IM ROT.SYS.
814
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
816
C**                LAMS     REAL   GEOGR. LAENGE DES PUNKTES IM ROT.SYS.
815
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
817
C**                POLPHI   REAL   WAHRE GEOGR. BREITE DES NORDPOLS
816
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
818
C**                POLLAM   REAL   WAHRE GEOGR. LAENGE DES NORDPOLS
817
C**   AUSGABE-
819
C**   AUSGABE-
818
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
820
C**   PARAMETER:   WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTION
819
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
821
C**                ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)
820
C**
822
C**
821
C**   COMMON-
823
C**   COMMON-
822
C**   BLOECKE  :   KEINE
824
C**   BLOECKE  :   KEINE
823
C**
825
C**
824
C**   FEHLERBE-
826
C**   FEHLERBE-
825
C**   HANDLUNG :   KEINE
827
C**   HANDLUNG :   KEINE
826
C**   VERFASSER:   D.MAJEWSKI
828
C**   VERFASSER:   D.MAJEWSKI
827
 
829
 
828
      REAL        LAMS,PHIS,POLPHI,POLLAM
830
      REAL        LAMS,PHIS,POLPHI,POLLAM
829
 
831
 
830
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
832
      DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /
831
 
833
 
832
      ZSINPOL = SIN(ZPIR18*POLPHI)
834
      ZSINPOL = SIN(ZPIR18*POLPHI)
833
      ZCOSPOL = COS(ZPIR18*POLPHI)
835
      ZCOSPOL = COS(ZPIR18*POLPHI)
834
      ZLAMPOL = ZPIR18*POLLAM
836
      ZLAMPOL = ZPIR18*POLLAM
835
      ZPHIS   = ZPIR18*PHIS
837
      ZPHIS   = ZPIR18*PHIS
836
      ZLAMS   = LAMS
838
      ZLAMS   = LAMS
837
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
839
      IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
838
      ZLAMS   = ZPIR18*ZLAMS
840
      ZLAMS   = ZPIR18*ZLAMS
839
 
841
 
840
      ZARG1   = SIN(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
842
      ZARG1   = SIN(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
841
     1                          ZCOSPOL*           SIN(ZPHIS)) -
843
     1                          ZCOSPOL*           SIN(ZPHIS)) -
842
     2          COS(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
844
     2          COS(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
843
      ZARG2   = COS(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
845
      ZARG2   = COS(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS)  +
844
     1                          ZCOSPOL*           SIN(ZPHIS)) +
846
     1                          ZCOSPOL*           SIN(ZPHIS)) +
845
     2          SIN(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
847
     2          SIN(ZLAMPOL)*           SIN(ZLAMS)*COS(ZPHIS)
846
      IF (ABS(ZARG2).LT.1.E-30) THEN
848
      IF (ABS(ZARG2).LT.1.E-30) THEN
847
        IF (ABS(ZARG1).LT.1.E-30) THEN
849
        IF (ABS(ZARG1).LT.1.E-30) THEN
848
          LMSTOLM =   0.0
850
          LMSTOLM =   0.0
849
        ELSEIF (ZARG1.GT.0.) THEN
851
        ELSEIF (ZARG1.GT.0.) THEN
850
              LMSTOLAM =  90.0
852
              LMSTOLAM =  90.0
851
            ELSE
853
            ELSE
852
              LMSTOLAM = -90.0
854
              LMSTOLAM = -90.0
853
            ENDIF
855
            ENDIF
854
      ELSE
856
      ELSE
855
        LMSTOLM = ZRPI18*ATAN2(ZARG1,ZARG2)
857
        LMSTOLM = ZRPI18*ATAN2(ZARG1,ZARG2)
856
      ENDIF
858
      ENDIF
857
 
859
 
858
      RETURN
860
      RETURN
859
      END
861
      END