Subversion Repositories lagranto.ecmwf

Rev

Rev 15 | Rev 36 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15 Rev 19
Line 5... Line 5...
5
c     * whether to start from an isentropic or an isobaric         *
5
c     * whether to start from an isentropic or an isobaric         *
6
c     * surface. The starting points are equidistantly distributed *
6
c     * surface. The starting points are equidistantly distributed *
7
c     * Michael Sprenger / Autumn 2004                             *
7
c     * Michael Sprenger / Autumn 2004                             *
8
c     **************************************************************
8
c     **************************************************************
9
 
9
 
10
      implicit none
10
      use netcdf
11
 
11
 
-
 
12
      implicit none
12
 
13
 
13
c     --------------------------------------------------------------
14
c     --------------------------------------------------------------
14
c     Set parameters
15
c     Set parameters
15
c     --------------------------------------------------------------
16
c     --------------------------------------------------------------
16
 
17
 
Line 118... Line 119...
118
      real              tfrac,frac
119
      real              tfrac,frac
119
      real              radius,dist
120
      real              radius,dist
120
      character*80      string
121
      character*80      string
121
      character*80      selectstr
122
      character*80      selectstr
122
      character*80      umode_save
123
      character*80      umode_save
-
 
124
      character*80      maskname
-
 
125
      real              maskvalue
-
 
126
      character*2       maskoper
-
 
127
      integer           cdfid,varid,ierr
-
 
128
      integer           nmask
-
 
129
      integer           indx,indy
-
 
130
      character         ch1,ch2
-
 
131
      integer           len
123
      real,allocatable, dimension (:,:,:) :: fld0
132
      real,allocatable, dimension (:,:,:) :: fld0
124
      real,allocatable, dimension (:,:,:) :: fld1
133
      real,allocatable, dimension (:,:,:) :: fld1
125
      real,allocatable, dimension (:,:  ) :: sfc0
134
      real,allocatable, dimension (:,:  ) :: sfc0
126
      real,allocatable, dimension (:,:)   :: sfc1
135
      real,allocatable, dimension (:,:)   :: sfc1
-
 
136
      real,allocatable, dimension (:,:)   :: mask
127
 
137
 
128
c     Externals 
138
c     Externals 
129
      real              int_index3     ! 3d interpolation
139
      real              int_index3     ! 3d interpolation
130
      external          int_index3
140
      external          int_index3
131
      real              sdis           ! Speherical distance
141
      real              sdis           ! Speherical distance
Line 188... Line 198...
188
          read(10,*) lon1,lat1,radius
198
          read(10,*) lon1,lat1,radius
189
       elseif ( hmode.eq.'region.eqd' ) then        ! region: 2d equidistant
199
       elseif ( hmode.eq.'region.eqd' ) then        ! region: 2d equidistant
190
          read(10,*) iregion,ds 
200
          read(10,*) iregion,ds 
191
       elseif ( hmode.eq.'region.grid' ) then       ! iregion: 2d grid
201
       elseif ( hmode.eq.'region.grid' ) then       ! iregion: 2d grid
192
          read(10,*) iregion
202
          read(10,*) iregion
-
 
203
       elseif ( hmode.eq.'mask.grid' ) then         ! 0/1 masked - grid points
-
 
204
          read(10,*) hfile,maskname
-
 
205
       elseif ( hmode.eq.'mask.eqd' ) then         ! 0/1 masked - euqidistant points
-
 
206
          read(10,*) hfile,maskname,ds
193
       else
207
       else
194
          print*,' ERROR: horizontal mode not supported ',trim(hmode)
208
          print*,' ERROR: horizontal mode not supported ',trim(hmode)
195
          stop
209
          stop
196
       endif
210
       endif
197
 
211
 
Line 250... Line 264...
250
         tfrac=tfrac/timeinc
264
         tfrac=tfrac/timeinc
251
      else
265
      else
252
         tfrac=0.
266
         tfrac=0.
253
      endif
267
      endif
254
 
268
 
-
 
269
c     If a mask file is provided, no time interpolation is allowed
-
 
270
      if ( (hmode.eq.'mask.grid').or.(hmode.eq.'mask.eqd') ) then
-
 
271
         if ( abs(tfrac).gt.eps ) then
-
 
272
            print*,' ERROR: no intermediate times allowed for ',
-
 
273
     >             trim(hmode)
-
 
274
            stop
-
 
275
         endif
-
 
276
      endif
-
 
277
 
255
c     Read the region coordinates if needed
278
c     Read the region coordinates if needed
256
      if ( (hmode.eq.'region.eqd' ).or.
279
      if ( (hmode.eq.'region.eqd' ).or.
257
     >     (hmode.eq.'region.grid') ) then
280
     >     (hmode.eq.'region.grid') ) then
258
         
281
         
259
         open(10,file=regionf)
282
         open(10,file=regionf)
Line 352... Line 375...
352
     >         '      iregion                 : ',iregion
375
     >         '      iregion                 : ',iregion
353
        write(*,'(a30,4f10.2)')
376
        write(*,'(a30,4f10.2)')
354
     >         '      xcorner                 : ',(xcorner(i),i=1,4)
377
     >         '      xcorner                 : ',(xcorner(i),i=1,4)
355
        write(*,'(a30,4f10.2)')
378
        write(*,'(a30,4f10.2)')
356
     >         '      ycorner                 : ',(ycorner(i),i=1,4)
379
     >         '      ycorner                 : ',(ycorner(i),i=1,4)
-
 
380
      elseif ( hmode.eq.'mask.eqd' ) then
-
 
381
        write(*,'(a30,a15,a15,f10.2)')
-
 
382
     >         '      hfile,variable,ds       : ',trim(hfile),
-
 
383
     >                                            trim(maskname),
-
 
384
     >                                            ds
-
 
385
      elseif ( hmode.eq.'mask.grid' ) then
-
 
386
        write(*,'(a30,a15,a15)')
-
 
387
     >         '      hfile,variable          : ',trim(hfile),
-
 
388
     >                                            trim(maskname)
357
      endif
389
      endif
-
 
390
 
358
      print*
391
      print*
359
      print*,'  vmode                      : ',trim(vmode)
392
      print*,'  vmode                      : ',trim(vmode)
360
      if ( vmode.eq.'file') then 
393
      if ( vmode.eq.'file') then 
361
         print*,'      filename               : ',trim(vfile)
394
         print*,'      filename               : ',trim(vfile)
362
      elseif ( vmode.eq.'level' ) then 
395
      elseif ( vmode.eq.'level' ) then 
Line 367... Line 400...
367
      elseif ( vmode.eq.'profile') then 
400
      elseif ( vmode.eq.'profile') then 
368
         print*,'      lev1,lev2,n            : ',lev1,lev2,vn
401
         print*,'      lev1,lev2,n            : ',lev1,lev2,vn
369
      elseif ( vmode.eq.'grid') then 
402
      elseif ( vmode.eq.'grid') then 
370
         print*,'      lev1,lev2              : ',lev1,lev2
403
         print*,'      lev1,lev2              : ',lev1,lev2
371
      endif
404
      endif
-
 
405
 
372
      print* 
406
      print* 
373
      print*,'  umode                      : ',trim(umode)
407
      print*,'  umode                      : ',trim(umode)
374
      print*
408
      print*
375
      print*,'  time check                 : ',trim(timecheck)
409
      print*,'  time check                 : ',trim(timecheck)
376
      print*
410
      print*
377
 
411
 
-
 
412
c     <mask.grid> and <mask.eqd>: split variable into name, operator,value
-
 
413
      if ( (hmode.eq.'mask.grid').or.(hmode.eq.'mask.eqd') ) then
-
 
414
          len = len_trim(maskname)
-
 
415
          do i=1,len_trim(maskname)-1
-
 
416
            ch1 = maskname(i:i)
-
 
417
            ch2 = maskname(i+1:i+1)
-
 
418
 
-
 
419
            if ( (ch1.eq.'<').and.(ch2.eq.'>') ) then
-
 
420
               read(maskname(i+2:len),*) maskvalue
-
 
421
               maskname = maskname(1:i-1)
-
 
422
               maskoper = 'ne'
-
 
423
               goto 90
-
 
424
            elseif ( (ch1.eq.'<').and.(ch2.eq.'=') ) then
-
 
425
               read(maskname(i+2:len),*) maskvalue
-
 
426
               maskname = maskname(1:i-1)
-
 
427
               maskoper = 'le'
-
 
428
               goto 90
-
 
429
            elseif ( (ch1.eq.'>').and.(ch2.eq.'=') ) then
-
 
430
               read(maskname(i+2:len),*) maskvalue
-
 
431
               maskname = maskname(1:i-1)
-
 
432
               maskoper = 'ge'
-
 
433
               goto 90
-
 
434
            elseif ( (ch1.eq.'=').and.(ch2.eq.'=') ) then
-
 
435
               read(maskname(i+2:len),*) maskvalue
-
 
436
               maskname = maskname(1:i-1)
-
 
437
               maskoper = 'eq'
-
 
438
               goto 90
-
 
439
            elseif ( ch1.eq.'=' ) then
-
 
440
               read(maskname(i+1:len),*) maskvalue
-
 
441
               maskname = maskname(1:i-1)
-
 
442
               maskoper = 'eq'
-
 
443
               goto 90
-
 
444
            elseif ( ch1.eq.'>' ) then
-
 
445
               read(maskname(i+1:len),*) maskvalue
-
 
446
               maskname = maskname(1:i-1)
-
 
447
               maskoper = 'gt'
-
 
448
               goto 90
-
 
449
            elseif ( ch1.eq.'<' ) then
-
 
450
               read(maskname(i+1:len),*) maskvalue
-
 
451
               maskname = maskname(1:i-1)
-
 
452
               maskoper = 'lt'
-
 
453
               goto 90
-
 
454
             endif
-
 
455
 
-
 
456
          enddo
-
 
457
      endif
-
 
458
 
-
 
459
  90  continue
-
 
460
 
378
c     ------------------------------------------------------------------
461
c     ------------------------------------------------------------------
379
c     Read grid parameters from inital files
462
c     Read grid parameters from inital files
380
c     ------------------------------------------------------------------
463
c     ------------------------------------------------------------------
381
 
464
 
382
c     Get the time of the first and second data file
465
c     Get the time of the first and second data file
Line 443... Line 526...
443
      if (stat.ne.0) print*,'*** error allocating array pv ***'
526
      if (stat.ne.0) print*,'*** error allocating array pv ***'
444
      allocate(pvs(nx,ny),stat=stat)
527
      allocate(pvs(nx,ny),stat=stat)
445
      if (stat.ne.0) print*,'*** error allocating array pvs **'
528
      if (stat.ne.0) print*,'*** error allocating array pvs **'
446
      allocate(in(nx,ny,nz),stat=stat)
529
      allocate(in(nx,ny,nz),stat=stat)
447
      if (stat.ne.0) print*,'*** error allocating array in ***'
530
      if (stat.ne.0) print*,'*** error allocating array in ***'
-
 
531
      allocate(mask(nx,ny),stat=stat)
-
 
532
      if (stat.ne.0) print*,'*** error allocating array mask ***'
448
 
533
 
449
c     Allocate memory for temporary arrays for time interpolation
534
c     Allocate memory for temporary arrays for time interpolation
450
      allocate(fld0(nx,ny,nz),stat=stat)
535
      allocate(fld0(nx,ny,nz),stat=stat)
451
      if (stat.ne.0) print*,'*** error allocating array tmp0 ***'
536
      if (stat.ne.0) print*,'*** error allocating array tmp0 ***'
452
      allocate(fld1(nx,ny,nz),stat=stat)
537
      allocate(fld1(nx,ny,nz),stat=stat)
Line 606... Line 691...
606
                pvs(i,j)=pv(i,j,1)
691
                pvs(i,j)=pv(i,j,1)
607
             enddo
692
             enddo
608
          enddo
693
          enddo
609
       endif
694
       endif
610
 
695
 
-
 
696
c     ------ Load 0/1 label (mask) ------------------------------------
-
 
697
      if ( (hmode.eq.'mask.grid').or.(hmode.eq.'mask.eqd') ) then
-
 
698
 
-
 
699
c         Explicit netCDF calls - no consistency check for grids!
-
 
700
          ierr = NF90_OPEN(hfile,nf90_nowrite, cdfid)
-
 
701
          IF ( ierr /= nf90_NoErr ) PRINT *,NF90_STRERROR(ierr)
-
 
702
          ierr = NF90_INQ_VARID(cdfid,maskname,varid)
-
 
703
          IF(ierr /= nf90_NoErr) PRINT *,NF90_STRERROR(ierr)
-
 
704
          ierr = nf90_get_var(cdfid,varid,mask)
-
 
705
          IF(ierr /= nf90_NoErr) PRINT *,NF90_STRERROR(ierr)
-
 
706
          ierr = NF90_CLOSE(cdfid)
-
 
707
          IF( ierr /= nf90_NoErr) PRINT *,NF90_STRERROR(ierr)
-
 
708
 
-
 
709
          nmask = 0
-
 
710
          do i=1,nx
-
 
711
            do j=1,ny
-
 
712
 
-
 
713
                if ( maskoper.eq.'eq' ) then
-
 
714
                   if ( abs(mask(i,j)-maskvalue).lt.eps ) then
-
 
715
                      nmask = nmask + 1
-
 
716
                      mask(i,j) = 1.
-
 
717
                   else
-
 
718
                      mask(i,j) = 0.
-
 
719
                   endif
-
 
720
                endif
-
 
721
 
-
 
722
                if ( maskoper.eq.'ne' ) then
-
 
723
                   if ( abs(mask(i,j)-maskvalue).gt.eps ) then
-
 
724
                      nmask = nmask + 1
-
 
725
                      mask(i,j) = 1.
-
 
726
                   else
-
 
727
                      mask(i,j) = 0.
-
 
728
                   endif
-
 
729
                endif
-
 
730
 
-
 
731
                if ( maskoper.eq.'gt' ) then
-
 
732
                   if ( mask(i,j).gt.maskvalue ) then
-
 
733
                      nmask = nmask + 1
-
 
734
                      mask(i,j) = 1.
-
 
735
                   else
-
 
736
                      mask(i,j) = 0.
-
 
737
                   endif
-
 
738
                endif
-
 
739
 
-
 
740
                if ( maskoper.eq.'lt' ) then
-
 
741
                   if ( mask(i,j).lt.maskvalue ) then
-
 
742
                      nmask = nmask + 1
-
 
743
                      mask(i,j) = 1.
-
 
744
                   else
-
 
745
                      mask(i,j) = 0.
-
 
746
                   endif
-
 
747
                endif
-
 
748
 
-
 
749
                if ( maskoper.eq.'ge' ) then
-
 
750
                   if ( mask(i,j).ge.maskvalue ) then
-
 
751
                      nmask = nmask + 1
-
 
752
                      mask(i,j) = 1.
-
 
753
                   else
-
 
754
                      mask(i,j) = 0.
-
 
755
                   endif
-
 
756
                endif
-
 
757
 
-
 
758
                if ( maskoper.eq.'le' ) then
-
 
759
                   if ( mask(i,j).le.maskvalue ) then
-
 
760
                      nmask = nmask + 1
-
 
761
                      mask(i,j) = 1.
-
 
762
                   else
-
 
763
                      mask(i,j) = 0.
-
 
764
                   endif
-
 
765
                endif
-
 
766
 
-
 
767
             enddo
-
 
768
          enddo
-
 
769
 
-
 
770
          print*
-
 
771
          print*,'  Mask read from file -> ',nmask,' 1-points'
-
 
772
          print*
-
 
773
 
-
 
774
      endif
-
 
775
 
611
c     Write some status information
776
c     Write some status information
612
      print*,'---- CONSTANT GRID PARAMETERS ---------------------------'
777
      print*,'---- CONSTANT GRID PARAMETERS ---------------------------'
613
      print*
778
      print*
614
      print*,'  xmin,xmax        : ',xmin,xmax
779
      print*,'  xmin,xmax        : ',xmin,xmax
615
      print*,'  ymin,ymax        : ',ymin,ymax
780
      print*,'  ymin,ymax        : ',ymin,ymax
Line 886... Line 1051...
886
                  lonlist(hn) = lon
1051
                  lonlist(hn) = lon
887
                  latlist(hn) = lat
1052
                  latlist(hn) = lat
888
               endif
1053
               endif
889
            enddo
1054
            enddo
890
         enddo
1055
         enddo
891
         
-
 
892
      endif
1056
      endif
893
 
1057
 
-
 
1058
c     mask: grid
-
 
1059
      if ( hmode.eq.'mask.grid' ) then
-
 
1060
         hn  = 0
-
 
1061
         do i=1,nx
-
 
1062
          do j=1,ny
-
 
1063
            if ( mask(i,j).gt.0.5 ) then
-
 
1064
               hn = hn +1
-
 
1065
               lonlist(hn) = xmin + real(i-1) * dx
-
 
1066
               latlist(hn) = ymin + real(j-1) * dy
-
 
1067
            endif
-
 
1068
          enddo
-
 
1069
         enddo
-
 
1070
      endif
-
 
1071
 
-
 
1072
c     mask: equidistant
-
 
1073
      if ( hmode.eq.'mask.eqd' ) then
-
 
1074
         hn  = 0
-
 
1075
         lat = -90.+dy
-
 
1076
         do while ( lat.le.ymax )
-
 
1077
           lon = -180.
-
 
1078
           do while ( lon.le.xmax )
-
 
1079
              indx = nint( (lon-xmin)/dx + 1. )
-
 
1080
              indy = nint( (lat-ymin)/dy + 1. )
-
 
1081
              if ( indx.lt. 1 ) indx =  1
-
 
1082
              if ( indy.lt. 1 ) indy =  1
-
 
1083
              if ( indx.gt.nx ) indx = nx
-
 
1084
              if ( indy.gt.ny ) indy = ny
-
 
1085
              if ( mask(indx,indy).gt.0.5 ) then
-
 
1086
                 hn          = hn+1
-
 
1087
                 lonlist(hn) = lon
-
 
1088
                 latlist(hn) = lat
-
 
1089
              endif
-
 
1090
              lon = lon+ds/(deltat*cos(pi180*lat))
-
 
1091
           enddo
-
 
1092
           lat = lat+ds/deltat
-
 
1093
        enddo
-
 
1094
      endif
-
 
1095
 
-
 
1096
 
894
c     ------ Get lev (vertical) coordinates -------------------------
1097
c     ------ Get lev (vertical) coordinates -------------------------
895
 
1098
 
896
c     Read level list from file
1099
c     Read level list from file
897
      if ( vmode.eq.'file' ) then
1100
      if ( vmode.eq.'file' ) then
898
         vn = 0
1101
         vn = 0