Subversion Repositories lagranto.wrf

Rev

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

Rev 8 Rev 11
Line 70... Line 70...
70
      character*80 radunit
70
      character*80 radunit
71
      real         rdummy
71
      real         rdummy
72
      real         rid,rjd,rkd
72
      real         rid,rjd,rkd
73
      real         xpos,ypos,zpos,ppos,lonpos,latpos
73
      real         xpos,ypos,zpos,ppos,lonpos,latpos
74
      real         lon1,lat1,lon2,lat2
74
      real         lon1,lat1,lon2,lat2
-
 
75
      integer      nfilter
75
 
76
 
76
c     Externals
77
c     Externals
77
      real         int_index3
78
      real         int_index3
78
      external     int_index3
79
      external     int_index3
79
      real         sdis
80
      real         sdis
Line 131... Line 132...
131
 
132
 
132
       if ( mode.eq.'-z2p.single'  ) then     ! convert single x/y/z -> x/y/p
133
       if ( mode.eq.'-z2p.single'  ) then     ! convert single x/y/z -> x/y/p
133
          read(10,*) xpos,ypos,zpos
134
          read(10,*) xpos,ypos,zpos
134
       endif
135
       endif
135
 
136
 
-
 
137
       if ( mode.eq.'-mapscale'  ) then       ! calculate mapping scale factors
-
 
138
          read(10,*) nfilter
-
 
139
       endif
-
 
140
 
136
      close(10)
141
      close(10)
137
 
142
 
138
c     Read the mapping file - except for mode '-create'
143
c     Read the mapping file - except for mode '-create'
139
      if ( mode.ne.'-create' ) then
144
      if ( mode.ne.'-create' ) then
140
 
145
 
Line 474... Line 479...
474
      if (stat.ne.0) print*,'*** error allocating array zz0         ***'
479
      if (stat.ne.0) print*,'*** error allocating array zz0         ***'
475
 
480
 
476
c     Get format of input and output file
481
c     Get format of input and output file
477
      call mode_tra(inpmode,inpfile)
482
      call mode_tra(inpmode,inpfile)
478
      call mode_tra(outmode,outfile)
483
      call mode_tra(outmode,outfile)
479
      if ( outmode.eq.-1 ) outmode = 1
484
      if ( outmode.eq.-1 ) outmode = inpmode
480
 
485
 
481
c     Read coordinates from file - Format (lon,lat,lev)
486
c     Read coordinates from file - Format (lon,lat,lev)
482
      if (inpmode.eq.-1) then
487
      if (inpmode.eq.-1) then
483
         fid = 10
488
         fid = 10
484
         npoints = 0
489
         npoints = 0
Line 571... Line 576...
571
      if (stat.ne.0) print*,'*** error allocating array zz0         ***'
576
      if (stat.ne.0) print*,'*** error allocating array zz0         ***'
572
 
577
 
573
c     Get format of input and output file
578
c     Get format of input and output file
574
      call mode_tra(inpmode,inpfile)
579
      call mode_tra(inpmode,inpfile)
575
      call mode_tra(outmode,outfile)
580
      call mode_tra(outmode,outfile)
576
      if ( outmode.eq.-1) outmode=1
581
      if ( outmode.eq.-1) outmode=inpmode
577
 
582
 
578
c     Read coordinates from file - Format (x,y,lev)
583
c     Read coordinates from file - Format (x,y,lev)
579
      if (inpmode.eq.-1) then
584
      if (inpmode.eq.-1) then
580
         fid = 10
585
         fid = 10
581
         npoints = 0
586
         npoints = 0
Line 742... Line 747...
742
      mpx(nx,ny) = mpx(nx-1,ny-1)
747
      mpx(nx,ny) = mpx(nx-1,ny-1)
743
      mpy(nx,ny) = mpy(nx-1,ny-1)
748
      mpy(nx,ny) = mpy(nx-1,ny-1)
744
      mpx( 1,ny) = mpx(   2,ny-1)
749
      mpx( 1,ny) = mpx(   2,ny-1)
745
      mpy( 1,ny) = mpy(   2,ny-1)
750
      mpy( 1,ny) = mpy(   2,ny-1)
746
 
751
 
-
 
752
c     Apply a diffuive filter
-
 
753
      do i=1,nfilter
-
 
754
         call filt2d (mpx,mpx,nx,ny,1.0,-999.,0,0,0,0)
-
 
755
         call filt2d (mpy,mpy,nx,ny,1.0,-999.,0,0,0,0)
-
 
756
      enddo
-
 
757
 
747
c     Write map factors to mapping file
758
c     Write map factors to mapping file
748
      cdfname = mapfile
759
      cdfname = mapfile
749
      varname = 'MAPSCALE_X'
760
      varname = 'MAPSCALE_X'
750
      call writecdf2D(cdfname,varname,mpx,0.,
761
      call writecdf2D(cdfname,varname,mpx,0.,
751
     >                dx,dy,xmin,ymin,nx,ny,1,0,1)
762
     >                dx,dy,xmin,ymin,nx,ny,1,0,1)
Line 774... Line 785...
774
      if (stat.ne.0) print*,'*** error allocating array zz0         ***'
785
      if (stat.ne.0) print*,'*** error allocating array zz0         ***'
775
 
786
 
776
c     Get format of input and output file
787
c     Get format of input and output file
777
      call mode_tra(inpmode,inpfile)
788
      call mode_tra(inpmode,inpfile)
778
      call mode_tra(outmode,outfile)
789
      call mode_tra(outmode,outfile)
779
      if ( outmode.eq.-1) outmode=1
790
      if ( outmode.eq.-1) outmode=inpmode
780
 
791
 
781
c     Read coordinates from file - Format (x,y,lev)
792
c     Read coordinates from file - Format (x,y,lev)
782
      if (inpmode.eq.-1) then
793
      if (inpmode.eq.-1) then
783
         fid = 10
794
         fid = 10
784
         npoints = 0
795
         npoints = 0
Line 887... Line 898...
887
      if (stat.ne.0) print*,'*** error allocating array zz0         ***'
898
      if (stat.ne.0) print*,'*** error allocating array zz0         ***'
888
 
899
 
889
c     Get format of input and output file
900
c     Get format of input and output file
890
      call mode_tra(inpmode,inpfile)
901
      call mode_tra(inpmode,inpfile)
891
      call mode_tra(outmode,outfile)
902
      call mode_tra(outmode,outfile)
892
      if ( outmode.eq.-1) outmode=1
903
      if ( outmode.eq.-1) outmode=inpmode
893
 
904
 
894
c     Read coordinates from file - Format (x,y,lev)
905
c     Read coordinates from file - Format (x,y,lev)
895
      if (inpmode.eq.-1) then
906
      if (inpmode.eq.-1) then
896
         fid = 10
907
         fid = 10
897
         npoints = 0
908
         npoints = 0
Line 1263... Line 1274...
1263
      real varmin(4),varmax(4),stag(4)
1274
      real varmin(4),varmax(4),stag(4)
1264
      integer ierr,cdfid,ndim,vardim(4)
1275
      integer ierr,cdfid,ndim,vardim(4)
1265
      character*80 cstname
1276
      character*80 cstname
1266
      real mdv
1277
      real mdv
1267
      integer i
1278
      integer i
-
 
1279
      integer nvars
-
 
1280
      character*80 vars(300)
1268
 
1281
 
1269
C     Definitions
1282
C     Definitions
1270
      varmin(1)=xmin
1283
      varmin(1)=xmin
1271
      varmin(2)=ymin
1284
      varmin(2)=ymin
1272
      varmin(3)=1050.
1285
      varmin(3)=1050.
Line 1291... Line 1304...
1291
         call crecdf(cdfname,cdfid,
1304
         call crecdf(cdfname,cdfid,
1292
     >        varmin,varmax,ndim,cstname,ierr)
1305
     >        varmin,varmax,ndim,cstname,ierr)
1293
         if (ierr.ne.0) goto 903
1306
         if (ierr.ne.0) goto 903
1294
      endif
1307
      endif
1295
 
1308
 
-
 
1309
c     Check whether the variable is already on the file
-
 
1310
      call getvars(cdfid,nvars,vars,ierr)
-
 
1311
      if (ierr.ne.0) goto 906
-
 
1312
      do i=1,nvars
-
 
1313
         if ( vars(i).eq.varname ) crevar = 0
-
 
1314
      enddo
-
 
1315
 
1296
c     Write the data to the netcdf file, and close the file
1316
c     Write the data to the netcdf file, and close the file
1297
      if (crevar.eq.1) then
1317
      if (crevar.eq.1) then
1298
         call putdef(cdfid,varname,ndim,mdv,
1318
         call putdef(cdfid,varname,ndim,mdv,
1299
     >        vardim,varmin,varmax,stag,ierr)
1319
     >        vardim,varmin,varmax,stag,ierr)
1300
         if (ierr.ne.0) goto 904
1320
         if (ierr.ne.0) goto 904
Line 1403... Line 1423...
1403
      stop
1423
      stop
1404
      
1424
      
1405
      end
1425
      end
1406
 
1426
 
1407
 
1427
 
-
 
1428
c     -----------------------------------------------
-
 
1429
c     Diffusive filter
-
 
1430
c     -----------------------------------------------
-
 
1431
 
-
 
1432
      subroutine filt2d (a,af,nx,ny,fil,misdat,
-
 
1433
     &                   iperx,ipery,ispol,inpol)
1408
 
1434
 
-
 
1435
c     Apply a conservative diffusion operator onto the 2d field a,
-
 
1436
c     with full missing data checking.
-
 
1437
c
-
 
1438
c     a     real   inp  array to be filtered, dimensioned (nx,ny)
-
 
1439
c     af    real   out  filtered array, dimensioned (nx,ny), can be
-
 
1440
c                       equivalenced with array a in the calling routine
-
 
1441
c     f1    real        workarray, dimensioned (nx+1,ny)
-
 
1442
c     f2    real        workarray, dimensioned (nx,ny+1)
-
 
1443
c     fil   real   inp  filter-coeff., 0<afil<=1. Maximum filtering with afil=1
-
 
1444
c                       corresponds to one application of the linear filter.
-
 
1445
c     misdat real  inp  missing-data value, a(i,j)=misdat indicates that
-
 
1446
c                       the corresponding value is not available. The
-
 
1447
c                       misdat-checking can be switched off with with misdat=0.
-
 
1448
c     iperx int    inp  periodic boundaries in the x-direction (1=yes,0=no)
-
 
1449
c     ipery int    inp  periodic boundaries in the y-direction (1=yes,0=no)
-
 
1450
c     inpol int    inp  northpole at j=ny  (1=yes,0=no)
-
 
1451
c     ispol int    inp  southpole at j=1   (1=yes,0=no)
-
 
1452
c
-
 
1453
c     Christoph Schaer, 1993
-
 
1454
 
-
 
1455
c     argument declaration
-
 
1456
      integer     nx,ny
-
 
1457
      real        a(nx,ny),af(nx,ny),fil,misdat
-
 
1458
      integer     iperx,ipery,inpol,ispol
-
 
1459
 
-
 
1460
c     local variable declaration
-
 
1461
      integer     i,j,is
-
 
1462
      real        fh
-
 
1463
      real        f1(nx+1,ny),f2(nx,ny+1)
-
 
1464
 
-
 
1465
c     compute constant fh
-
 
1466
      fh=0.125*fil
-
 
1467
 
-
 
1468
c     compute fluxes in x-direction
-
 
1469
      if (misdat.eq.0.) then
-
 
1470
        do j=1,ny
-
 
1471
        do i=2,nx
-
 
1472
          f1(i,j)=a(i-1,j)-a(i,j)
-
 
1473
        enddo
-
 
1474
        enddo
-
 
1475
      else
-
 
1476
        do j=1,ny
-
 
1477
        do i=2,nx
-
 
1478
          if ((a(i,j).eq.misdat).or.(a(i-1,j).eq.misdat)) then
-
 
1479
            f1(i,j)=0.
-
 
1480
          else
-
 
1481
            f1(i,j)=a(i-1,j)-a(i,j)
-
 
1482
          endif
-
 
1483
        enddo
-
 
1484
        enddo
-
 
1485
      endif
-
 
1486
      if (iperx.eq.1) then
-
 
1487
c       do periodic boundaries in the x-direction
-
 
1488
        do j=1,ny
-
 
1489
          f1(1,j)=f1(nx,j)
-
 
1490
          f1(nx+1,j)=f1(2,j)
-
 
1491
        enddo
-
 
1492
      else
-
 
1493
c       set boundary-fluxes to zero
-
 
1494
        do j=1,ny
-
 
1495
          f1(1,j)=0.
-
 
1496
          f1(nx+1,j)=0.
-
 
1497
        enddo
-
 
1498
      endif
-
 
1499
 
-
 
1500
c     compute fluxes in y-direction
-
 
1501
      if (misdat.eq.0.) then
-
 
1502
        do j=2,ny
-
 
1503
        do i=1,nx
-
 
1504
          f2(i,j)=a(i,j-1)-a(i,j)
-
 
1505
        enddo
-
 
1506
        enddo
-
 
1507
      else
-
 
1508
        do j=2,ny
-
 
1509
        do i=1,nx
-
 
1510
          if ((a(i,j).eq.misdat).or.(a(i,j-1).eq.misdat)) then
-
 
1511
            f2(i,j)=0.
-
 
1512
          else
-
 
1513
            f2(i,j)=a(i,j-1)-a(i,j)
-
 
1514
          endif
-
 
1515
        enddo
-
 
1516
        enddo
-
 
1517
      endif
-
 
1518
c     set boundary-fluxes to zero
-
 
1519
      do i=1,nx
-
 
1520
        f2(i,1)=0.
-
 
1521
        f2(i,ny+1)=0.
-
 
1522
      enddo
-
 
1523
      if (ipery.eq.1) then
-
 
1524
c       do periodic boundaries in the x-direction
-
 
1525
        do i=1,nx
-
 
1526
          f2(i,1)=f2(i,ny)
-
 
1527
          f2(i,ny+1)=f2(i,2)
-
 
1528
        enddo
-
 
1529
      endif
-
 
1530
      if (iperx.eq.1) then
-
 
1531
        if (ispol.eq.1) then
-
 
1532
c         do south-pole
-
 
1533
          is=(nx-1)/2
-
 
1534
          do i=1,nx
-
 
1535
            f2(i,1)=-f2(mod(i-1+is,nx)+1,2)
-
 
1536
          enddo
-
 
1537
        endif
-
 
1538
        if (inpol.eq.1) then
-
 
1539
c         do north-pole
-
 
1540
          is=(nx-1)/2
-
 
1541
          do i=1,nx
-
 
1542
            f2(i,ny+1)=-f2(mod(i-1+is,nx)+1,ny)
-
 
1543
          enddo
-
 
1544
        endif
-
 
1545
      endif
-
 
1546
 
-
 
1547
c     compute flux-convergence -> filter
-
 
1548
      if (misdat.eq.0.) then
-
 
1549
        do j=1,ny
-
 
1550
        do i=1,nx
-
 
1551
            af(i,j)=a(i,j)+fh*(f1(i,j)-f1(i+1,j)+f2(i,j)-f2(i,j+1))
-
 
1552
        enddo
-
 
1553
        enddo
-
 
1554
      else
-
 
1555
        do j=1,ny
-
 
1556
        do i=1,nx
-
 
1557
          if (a(i,j).eq.misdat) then
-
 
1558
            af(i,j)=misdat
-
 
1559
          else
-
 
1560
            af(i,j)=a(i,j)+fh*(f1(i,j)-f1(i+1,j)+f2(i,j)-f2(i,j+1))
-
 
1561
          endif
-
 
1562
        enddo
-
 
1563
        enddo
-
 
1564
      endif
-
 
1565
      end
1409
 
1566
 
1410
 
1567
 
1411
 
1568
 
1412
 
1569
 
1413
 
1570