74 logical fexist, opened
75 integer fsize, ncid, error, id_dim, nx, ny
76 character(len=256) :: outgrid =
"none" 77 character(len=256) :: inputorog =
"none" 78 character(len=256) :: merge_file =
"none" 79 logical :: mask_only = .false.
80 integer :: mtnres,im,jm,nm,nr,nf0,nf1,efac,nw
90 print*,
"INPUTOROG= ", trim(inputorog)
91 print*,
"MASK_ONLY", mask_only
92 print*,
"MERGE_FILE ", trim(merge_file)
100 print*, mtnres,nm,nr,nf0,nf1,efac
101 nw=(nm+1)*((nr+1)*nm+2)
104 print *,
' Starting terr12 mtnlm7_slm30.f IMN,JMN:',imn,jmn
107 inquire(file=trim(outgrid), exist=fexist)
108 if(.not. fexist)
then 109 print*,
"FATAL ERROR: file "//trim(outgrid)
110 print*,
" does not exist." 114 inquire( ncid,opened=opened )
115 if( .NOT.opened )
exit 118 print*,
"READ outgrid=", trim(outgrid)
119 error=nf__open(trim(outgrid),nf_nowrite,fsize,ncid)
120 call netcdf_err(error,
'Open file '//trim(outgrid) )
121 error=nf_inq_dimid(ncid,
'nx', id_dim)
122 call netcdf_err(error,
'inquire dimension nx from file '//
124 error=nf_inq_dimlen(ncid,id_dim,nx)
125 call netcdf_err(error,
'inquire dimension nx length '//
126 &
'from file '//trim(outgrid) )
128 error=nf_inq_dimid(ncid,
'ny', id_dim)
129 call netcdf_err(error,
'inquire dimension ny from file '//
131 error=nf_inq_dimlen(ncid,id_dim,ny)
132 call netcdf_err(error,
'inquire dimension ny length '//
133 &
'from file '//trim(outgrid) )
136 print*,
"nx, ny, im, jm = ", nx, ny, im, jm
138 call netcdf_err(error,
'close file '//trim(outgrid) )
140 CALL tersub(imn,jmn,im,jm,nm,nr,nf0,nf1,nw,efac,
141 & outgrid,inputorog,mask_only,merge_file)
165 SUBROUTINE tersub(IMN,JMN,IM,JM,NM,NR,NF0,NF1,NW,EFAC,
166 & OUTGRID,INPUTOROG,MASK_ONLY,MERGE_FILE)
170 integer :: IMN,JMN,IM,JM,NM,NR,NF0,NF1,NW
171 character(len=*),
intent(in) :: OUTGRID
172 character(len=*),
intent(in) :: INPUTOROG
173 character(len=*),
intent(in) :: MERGE_FILE
175 logical,
intent(in) :: mask_only
177 real,
parameter :: MISSING_VALUE=-9999.
178 real,
PARAMETER :: PI=3.1415926535897931
179 integer,
PARAMETER :: NMT=14
181 integer :: efac,zsave1,zsave2
182 integer :: mskocn,notocn
183 integer :: i,j,nx,ny,ncid,js,jn,iw,ie,k,it,jt,error,id_dim
184 integer :: id_var,nx_in,ny_in,fsize,wgta,IN,INW,INE,IS,ISW,ISE
185 integer :: M,N,ios,istat,itest,jtest
186 integer :: i_south_pole,j_south_pole,i_north_pole,j_north_pole
187 integer :: maxc3,maxc4,maxc5,maxc6,maxc7,maxc8
191 integer,
allocatable :: JST(:),JEN(:),numi(:)
193 integer,
allocatable :: IST(:,:),IEN(:,:),ZSLMX(:,:)
194 integer,
allocatable :: ZAVG(:,:),ZSLM(:,:)
195 integer(1),
allocatable :: UMD(:,:)
196 integer(2),
allocatable :: glob(:,:)
198 integer,
allocatable :: IWORK(:,:,:)
200 real :: DEGRAD,maxlat, minlat,timef,tbeg,tend,tbeg1
201 real :: PHI,DELXN,slma,oroa,vara,var4a,xn,XS,FFF,WWW
202 real :: sumdif,avedif
204 real,
allocatable :: COSCLT(:),WGTCLT(:),RCLT(:),XLAT(:),DIFFX(:)
205 real,
allocatable :: XLON(:),ORS(:),oaa(:),ola(:),GLAT(:)
207 real,
allocatable :: GEOLON(:,:),GEOLON_C(:,:),DX(:,:)
208 real,
allocatable :: GEOLAT(:,:),GEOLAT_C(:,:),DY(:,:)
209 real,
allocatable :: SLM(:,:),ORO(:,:),VAR(:,:),ORF(:,:)
210 real,
allocatable :: land_frac(:,:),lake_frac(:,:)
211 real,
allocatable :: THETA(:,:),GAMMA(:,:),SIGMA(:,:),ELVMAX(:,:)
212 real,
allocatable :: VAR4(:,:),SLMI(:,:)
213 real,
allocatable :: WORK1(:,:),WORK2(:,:),WORK3(:,:),WORK4(:,:)
214 real,
allocatable :: WORK5(:,:),WORK6(:,:)
215 real,
allocatable :: tmpvar(:,:)
216 real,
allocatable :: slm_in(:,:), lon_in(:,:), lat_in(:,:)
217 real(4),
allocatable:: GICE(:,:),OCLSM(:,:)
219 real,
allocatable :: OA(:,:,:),OL(:,:,:),HPRIME(:,:,:)
220 real,
allocatable :: oa_in(:,:,:), ol_in(:,:,:)
222 logical :: grid_from_file,fexist,opened
223 logical :: SPECTR, FILTER
224 logical :: is_south_pole(IM,JM), is_north_pole(IM,JM)
230 allocate (jst(jm),jen(jm),numi(jm))
231 allocate (ist(im,jm),ien(im,jm),zslmx(2700,1350))
232 allocate (glob(imn,jmn))
235 allocate (cosclt(jm),wgtclt(jm),rclt(jm),xlat(jm),diffx(jm/2))
236 allocate (xlon(im),ors(nw),oaa(4),ola(4),glat(jmn))
238 allocate (zavg(imn,jmn))
239 allocate (zslm(imn,jmn))
240 allocate (umd(imn,jmn))
255 if (mskocn .eq. 1)
then 256 print *,
' Ocean Model LSM Present and ' 257 print *,
' Overrides OCEAN POINTS in LSM: mskocn=',mskocn
258 if (notocn .eq. 1)
then 259 print *,
' Ocean LSM Reversed: NOTOCN=',notocn
263 print *,
' Attempt to open/read UMD 30sec slmsk.' 265 error=nf__open(
"./landcover.umd.30s.nc",nf_nowrite,fsize,ncid)
266 call netcdf_err(error,
'Open file landcover.umd.30s.nc' )
267 error=nf_inq_varid(ncid,
'land_mask', id_var)
268 call netcdf_err(error,
'Inquire varid of land_mask')
269 error=nf_get_var_int1(ncid, id_var, umd)
270 call netcdf_err(error,
'Inquire data of land_mask')
271 error = nf_close(ncid)
273 print *,
' UMD lake, UMD(50,50)=',umd(50,50)
277 print *,
' Call read_g to read global topography' 297 print *,
' After read_g, glob(500,500)=',glob(500,500)
301 print*,
' IM, JM, NM, NR, NF0, NF1, EFAC' 302 print*, im,jm,nm,nr,nf0,nf1,efac
303 print *,
' imn,jmn,glob(imn,jmn)=',imn,jmn,glob(imn,jmn)
304 print *,
' UBOUND ZAVG=',ubound(zavg)
305 print *,
' UBOUND glob=',ubound(glob)
306 print *,
' UBOUND ZSLM=',ubound(zslm)
307 print *,
' UBOUND GICE=',imn+1,3601
308 print *,
' UBOUND OCLSM=',im,jm
339 if ( umd(i,j) .eq. 0 ) zslm(i,j) = 0
343 deallocate (zslmx,umd,glob)
365 print *,
' SPECTR=',spectr,
' ** with GICE-07 **' 367 CALL splat(4,jm,cosclt,wgtclt)
369 rclt(j) = acos(cosclt(j))
372 phi = rclt(j) * degrad
374 xlat(jm-j+1) = phi - 90.
377 CALL splat(0,jm,cosclt,wgtclt)
379 rclt(j) = acos(cosclt(j))
380 xlat(j) = 90.0 - rclt(j) * degrad
384 allocate (gice(imn+1,3601))
388 diffx(j) = xlat(j) - xlat(j-1)
389 sumdif = sumdif + diffx(j)
391 avedif=sumdif/(float(jm/2))
395 write (6,106) (xlat(j),j=jm,1,-1)
396 106
format( 10(f7.3,1x))
397 107
format( 10(f9.5,1x))
402 glat(j) = -90. + (j-1) * delxn + delxn * 0.5
405 &
' Before GICE ZAVG(1,2)=',zavg(1,2),zslm(1,2)
407 &
' Before GICE ZAVG(1,12)=',zavg(1,12),zslm(1,12)
409 &
' Before GICE ZAVG(1,52)=',zavg(1,52),zslm(1,52)
411 &
' Before GICE ZAVG(1,112)=',zavg(1,jmn-112),zslm(1,112)
416 error=nf__open(
"./topography.antarctica.ramp.30s.nc",
417 & nf_nowrite,fsize,ncid)
418 call netcdf_err(error,
'Opening RAMP topo file' )
419 error=nf_inq_varid(ncid,
'topo', id_var)
420 call netcdf_err(error,
'Inquire varid of RAMP topo')
421 error=nf_get_var_real(ncid, id_var, gice)
422 call netcdf_err(error,
'Inquire data of RAMP topo')
423 error = nf_close(ncid)
425 print *,
' GICE 30" Antarctica RAMP orog 43201x3601 read OK' 426 print *,
' Processing! ' 427 print *,
' Processing! ' 428 print *,
' Processing! ' 433 if( gice(i,j) .ne. -99. .and. gice(i,j) .ne. -1.0 )
then 434 if ( gice(i,j) .gt. 0.)
then 435 zavg(i,j) = int( gice(i,j) + 0.5 )
441 152
format(1x,
' ZAVG(i=',i4,
' j=',i4,
')=',i5,i3,
442 &
' orig:',i5,i4,
' Lat=',f7.3,f8.2,
'E',
' GICE=',f8.1)
448 allocate (oclsm(im,jm),slmi(im,jm))
455 if (mskocn .eq. 1)
then 459 open(25,form=
'formatted',iostat=istat)
462 print *,
' Ocean lsm file Open failure: mskocn,istat=',mskocn,istat
465 print *,
' Ocean lsm file Opened OK: mskocn,istat=',mskocn,istat
471 read(25,*,iostat=ios)oclsm
476 print *,
' Rd fail: Ocean lsm - continue, mskocn,ios=',mskocn,ios
479 print *,
' Rd OK: ocean lsm: mskocn,ios=',mskocn,ios
483 if ( mskocn .eq. 1 )
then 486 if ( notocn .eq. 0 )
then 487 slmi(i,j) = float(nint(oclsm(i,j)))
489 if ( nint(oclsm(i,j)) .eq. 0)
then 497 print *,
' OCLSM',oclsm(1,1),oclsm(50,50),oclsm(75,75),oclsm(im,jm)
498 print *,
' SLMI:',slmi(1,1),slmi(50,50),slmi(75,75),slmi(im,jm)
506 print *,
' Not using Ocean model land sea mask' 509 if (mskocn .eq. 1)
then 510 print *,
' LSM:',oclsm(1,1),oclsm(50,50),oclsm(75,75),oclsm(im,jm)
513 allocate (geolon(im,jm),geolon_c(im+1,jm+1),dx(im,jm))
514 allocate (geolat(im,jm),geolat_c(im+1,jm+1),dy(im,jm))
515 allocate (slm(im,jm),oro(im,jm),var(im,jm),var4(im,jm))
516 allocate (land_frac(im,jm),lake_frac(im,jm))
519 grid_from_file = .false.
520 is_south_pole = .false.
521 is_north_pole = .false.
526 if( trim(outgrid) .NE.
"none" )
then 527 grid_from_file = .true.
528 inquire(file=trim(outgrid), exist=fexist)
529 if(.not. fexist)
then 530 print*,
"FATAL ERROR: file "//trim(outgrid)
531 print*,
"does not exist." 535 inquire( ncid,opened=opened )
536 if( .NOT.opened )
exit 539 print*,
"outgrid=", trim(outgrid)
540 error=nf__open(trim(outgrid),nf_nowrite,fsize,ncid)
541 call netcdf_err(error,
'Open file '//trim(outgrid) )
542 error=nf_inq_dimid(ncid,
'nx', id_dim)
543 call netcdf_err(error,
'inquire dimension nx from file '//
547 print*,
"Read the grid from file "//trim(outgrid)
549 allocate(tmpvar(nx+1,ny+1))
551 error=nf_inq_varid(ncid,
'x', id_var)
552 call netcdf_err(error,
'inquire varid of x from file ' 554 error=nf_get_var_double(ncid, id_var, tmpvar)
555 call netcdf_err(error,
'inquire data of x from file ' 558 do j = 1,ny+1;
do i = 1,nx+1
559 if(tmpvar(i,j) .NE. missing_value)
then 560 if(tmpvar(i,j) .GT. 360) tmpvar(i,j) = tmpvar(i,j) - 360
561 if(tmpvar(i,j) .LT. 0) tmpvar(i,j) = tmpvar(i,j) + 360
565 geolon(1:im,1:jm) = tmpvar(2:nx:2,2:ny:2)
566 geolon_c(1:im+1,1:jm+1) = tmpvar(1:nx+1:2,1:ny+1:2)
568 error=nf_inq_varid(ncid,
'y', id_var)
569 call netcdf_err(error,
'inquire varid of y from file ' 571 error=nf_get_var_double(ncid, id_var, tmpvar)
572 call netcdf_err(error,
'inquire data of y from file ' 574 geolat(1:im,1:jm) = tmpvar(2:nx:2,2:ny:2)
575 geolat_c(1:im+1,1:jm+1) = tmpvar(1:nx+1:2,1:ny+1:2)
584 do j = 1, ny+1;
do i = 1, nx+1
585 if( tmpvar(i,j) > maxlat )
then 590 if( tmpvar(i,j) < minlat )
then 597 if(maxlat < 89.9 )
then 601 if(minlat > -89.9 )
then 605 print*,
"minlat=", minlat,
"maxlat=", maxlat
606 print*,
"north pole supergrid index is ",
607 & i_north_pole, j_north_pole
608 print*,
"south pole supergrid index is ",
609 & i_south_pole, j_south_pole
612 if(i_south_pole >0 .and. j_south_pole > 0)
then 613 if(mod(i_south_pole,2)==0)
then 614 do j = 1, jm;
do i = 1, im
615 if(i==i_south_pole/2 .and. (j==j_south_pole/2
616 & .or. j==j_south_pole/2+1) )
then 617 is_south_pole(i,j) = .true.
618 print*,
"south pole at i,j=", i, j
622 do j = 1, jm;
do i = 1, im
623 if((i==i_south_pole/2 .or. i==i_south_pole/2+1)
624 & .and. (j==j_south_pole/2 .or.
625 & j==j_south_pole/2+1) )
then 626 is_south_pole(i,j) = .true.
627 print*,
"south pole at i,j=", i, j
632 if(i_north_pole >0 .and. j_north_pole > 0)
then 633 if(mod(i_north_pole,2)==0)
then 634 do j = 1, jm;
do i = 1, im
635 if(i==i_north_pole/2 .and. (j==j_north_pole/2 .or.
636 & j==j_north_pole/2+1) )
then 637 is_north_pole(i,j) = .true.
638 print*,
"north pole at i,j=", i, j
642 do j = 1, jm;
do i = 1, im
643 if((i==i_north_pole/2 .or. i==i_north_pole/2+1)
644 & .and. (j==j_north_pole/2 .or.
645 & j==j_north_pole/2+1) )
then 646 is_north_pole(i,j) = .true.
647 print*,
"north pole at i,j=", i, j
654 allocate(tmpvar(nx,ny))
655 error=nf_inq_varid(ncid,
'area', id_var)
656 call netcdf_err(error,
'inquire varid of area from file ' 658 error=nf_get_var_double(ncid, id_var, tmpvar)
659 call netcdf_err(error,
'inquire data of area from file ' 664 dx(i,j) = sqrt(tmpvar(2*i-1,2*j-1)+tmpvar(2*i,2*j-1)
665 & +tmpvar(2*i-1,2*j )+tmpvar(2*i,2*j ))
691 write(6,*)
' Timer 1 time= ',tend-tbeg
693 if(grid_from_file)
then 696 IF (merge_file ==
'none')
then 698 & im,jm,imn,jmn,geolon_c,geolat_c)
701 print*,
'Read in external mask ',merge_file
706 print*,
'Computing mask only.' 714 CALL makemt2(zavg,zslm,oro,slm,var,var4,glat,
715 & im,jm,imn,jmn,geolon_c,geolat_c,
lake_frac,land_frac)
718 write(6,*)
' MAKEMT2 time= ',tend-tbeg
720 CALL makemt(zavg,zslm,oro,slm,var,var4,glat,
721 & ist,ien,jst,jen,im,jm,imn,jmn,xlat,numi)
724 call minmxj(im,jm,oro,
' ORO')
725 call minmxj(im,jm,slm,
' SLM')
726 call minmxj(im,jm,var,
' VAR')
727 call minmxj(im,jm,var4,
' VAR4')
743 allocate (theta(im,jm),gamma(im,jm),sigma(im,jm),elvmax(im,jm))
744 if(grid_from_file)
then 746 CALL makepc2(zavg,zslm,theta,gamma,sigma,glat,
747 1 im,jm,imn,jmn,geolon_c,geolat_c,slm)
749 write(6,*)
' MAKEPC2 time= ',tend-tbeg
751 CALL makepc(zavg,zslm,theta,gamma,sigma,glat,
752 1 ist,ien,jst,jen,im,jm,imn,jmn,xlat,numi)
755 call minmxj(im,jm,theta,
' THETA')
756 call minmxj(im,jm,gamma,
' GAMMA')
757 call minmxj(im,jm,sigma,
' SIGMA')
762 allocate (iwork(im,jm,4))
763 allocate (oa(im,jm,4),ol(im,jm,4),hprime(im,jm,14))
764 allocate (work1(im,jm),work2(im,jm),work3(im,jm),work4(im,jm))
765 allocate (work5(im,jm),work6(im,jm))
767 call minmxj(im,jm,oro,
' ORO')
768 print*,
"inputorog=", trim(inputorog)
769 if(grid_from_file)
then 770 if(trim(inputorog) ==
"none")
then 771 print*,
"calling MAKEOA2 to compute OA, OL" 773 CALL makeoa2(zavg,zslm,var,glat,oa,ol,iwork,elvmax,oro,
774 1 work1,work2,work3,work4,work5,work6,
775 2 im,jm,imn,jmn,geolon_c,geolat_c,
776 3 geolon,geolat,dx,dy,is_south_pole,is_north_pole)
778 write(6,*)
' MAKEOA2 time= ',tend-tbeg
781 error=nf__open(trim(inputorog),nf_nowrite,fsize,ncid)
782 call netcdf_err(error,
'Open file '//trim(inputorog) )
783 error=nf_inq_dimid(ncid,
'lon', id_dim)
784 call netcdf_err(error,
'inquire dimension lon from file '//
786 error=nf_inq_dimlen(ncid,id_dim,nx_in)
787 call netcdf_err(error,
'inquire dimension lon length '//
788 &
'from file '//trim(inputorog) )
789 error=nf_inq_dimid(ncid,
'lat', id_dim)
790 call netcdf_err(error,
'inquire dimension lat from file '//
792 error=nf_inq_dimlen(ncid,id_dim,ny_in)
793 call netcdf_err(error,
'inquire dimension lat length '//
794 &
'from file '//trim(inputorog) )
796 print*,
"extrapolate OA, OL from Gaussian grid with nx=",
797 & nx_in,
", ny=", ny_in
798 allocate(oa_in(nx_in,ny_in,4), ol_in(nx_in,ny_in,4))
799 allocate(slm_in(nx_in,ny_in) )
800 allocate(lon_in(nx_in,ny_in), lat_in(nx_in,ny_in) )
802 error=nf_inq_varid(ncid,
'oa1', id_var)
803 call netcdf_err(error,
'inquire varid of oa1 from file ' 804 & //trim(inputorog) )
805 error=nf_get_var_double(ncid, id_var, oa_in(:,:,1))
806 call netcdf_err(error,
'inquire data of oa1 from file ' 807 & //trim(inputorog) )
808 error=nf_inq_varid(ncid,
'oa2', id_var)
809 call netcdf_err(error,
'inquire varid of oa2 from file ' 810 & //trim(inputorog) )
811 error=nf_get_var_double(ncid, id_var, oa_in(:,:,2))
812 call netcdf_err(error,
'inquire data of oa2 from file ' 813 & //trim(inputorog) )
814 error=nf_inq_varid(ncid,
'oa3', id_var)
815 call netcdf_err(error,
'inquire varid of oa3 from file ' 816 & //trim(inputorog) )
817 error=nf_get_var_double(ncid, id_var, oa_in(:,:,3))
818 call netcdf_err(error,
'inquire data of oa3 from file ' 819 & //trim(inputorog) )
820 error=nf_inq_varid(ncid,
'oa4', id_var)
821 call netcdf_err(error,
'inquire varid of oa4 from file ' 822 & //trim(inputorog) )
823 error=nf_get_var_double(ncid, id_var, oa_in(:,:,4))
824 call netcdf_err(error,
'inquire data of oa4 from file ' 825 & //trim(inputorog) )
827 error=nf_inq_varid(ncid,
'ol1', id_var)
828 call netcdf_err(error,
'inquire varid of ol1 from file ' 829 & //trim(inputorog) )
830 error=nf_get_var_double(ncid, id_var, ol_in(:,:,1))
831 call netcdf_err(error,
'inquire data of ol1 from file ' 832 & //trim(inputorog) )
833 error=nf_inq_varid(ncid,
'ol2', id_var)
834 call netcdf_err(error,
'inquire varid of ol2 from file ' 835 & //trim(inputorog) )
836 error=nf_get_var_double(ncid, id_var, ol_in(:,:,2))
837 call netcdf_err(error,
'inquire data of ol2 from file ' 838 & //trim(inputorog) )
839 error=nf_inq_varid(ncid,
'ol3', id_var)
840 call netcdf_err(error,
'inquire varid of ol3 from file ' 841 & //trim(inputorog) )
842 error=nf_get_var_double(ncid, id_var, ol_in(:,:,3))
843 call netcdf_err(error,
'inquire data of ol3 from file ' 844 & //trim(inputorog) )
845 error=nf_inq_varid(ncid,
'ol4', id_var)
846 call netcdf_err(error,
'inquire varid of ol4 from file ' 847 & //trim(inputorog) )
848 error=nf_get_var_double(ncid, id_var, ol_in(:,:,4))
849 call netcdf_err(error,
'inquire data of ol4 from file ' 850 & //trim(inputorog) )
852 error=nf_inq_varid(ncid,
'slmsk', id_var)
853 call netcdf_err(error,
'inquire varid of slmsk from file ' 854 & //trim(inputorog) )
855 error=nf_get_var_double(ncid, id_var, slm_in)
856 call netcdf_err(error,
'inquire data of slmsk from file ' 857 & //trim(inputorog) )
859 error=nf_inq_varid(ncid,
'geolon', id_var)
860 call netcdf_err(error,
'inquire varid of geolon from file ' 861 & //trim(inputorog) )
862 error=nf_get_var_double(ncid, id_var, lon_in)
863 call netcdf_err(error,
'inquire data of geolon from file ' 864 & //trim(inputorog) )
866 error=nf_inq_varid(ncid,
'geolat', id_var)
867 call netcdf_err(error,
'inquire varid of geolat from file ' 868 & //trim(inputorog) )
869 error=nf_get_var_double(ncid, id_var, lat_in)
870 call netcdf_err(error,
'inquire data of geolat from file ' 871 & //trim(inputorog) )
874 do j=1,ny_in;
do i=1,nx_in
875 if(slm_in(i,j) == 2) slm_in(i,j) = 0
880 & //trim(inputorog) )
882 print*,
"calling MAKEOA3 to compute OA, OL" 883 CALL makeoa3(zavg,var,glat,oa,ol,iwork,elvmax,oro,slm,
884 1 work1,work2,work3,work4,work5,work6,
885 2 im,jm,imn,jmn,geolon_c,geolat_c,
886 3 geolon,geolat,nx_in,ny_in,
887 4 oa_in,ol_in,slm_in,lon_in,lat_in)
889 deallocate(oa_in,ol_in,slm_in,lon_in,lat_in)
893 CALL makeoa(zavg,var,glat,oa,ol,iwork,elvmax,oro,
894 1 work1,work2,work3,work4,
896 3 ist,ien,jst,jen,im,jm,imn,jmn,xlat,numi)
901 deallocate (zslm,zavg)
903 deallocate (work2,work3,work4,work5,work6)
909 call minmxj(im,jm,oa,
' OA')
910 call minmxj(im,jm,ol,
' OL')
911 call minmxj(im,jm,elvmax,
' ELVMAX')
912 call minmxj(im,jm,oro,
' ORO')
922 if (elvmax(i,j) .gt. 3000.) maxc3 = maxc3 +1
923 if (elvmax(i,j) .gt. 4000.) maxc4 = maxc4 +1
924 if (elvmax(i,j) .gt. 5000.) maxc5 = maxc5 +1
925 if (elvmax(i,j) .gt. 6000.) maxc6 = maxc6 +1
926 if (elvmax(i,j) .gt. 7000.) maxc7 = maxc7 +1
927 if (elvmax(i,j) .gt. 8000.) maxc8 = maxc8 +1
930 print *,
' MAXC3:',maxc3,maxc4,maxc5,maxc6,maxc7,maxc8
935 print *,
' ===> Replacing ELVMAX with ELVMAX-ORO <=== ' 936 print *,
' ===> if ELVMAX<=ORO replace with proxy <=== ' 937 print *,
' ===> the sum of mean orog (ORO) and std dev <=== ' 940 if (elvmax(i,j) .lt. oro(i,j) )
then 942 elvmax(i,j) = max( 3. * var(i,j),0.)
944 elvmax(i,j) = max( elvmax(i,j) - oro(i,j),0.)
956 if (elvmax(i,j) .gt. 3000.) maxc3 = maxc3 +1
957 if (elvmax(i,j) .gt. 4000.) maxc4 = maxc4 +1
958 if (elvmax(i,j) .gt. 5000.) maxc5 = maxc5 +1
959 if (elvmax(i,j) .gt. 6000.) maxc6 = maxc6 +1
960 if (elvmax(i,j) .gt. 7000.) maxc7 = maxc7 +1
961 if (elvmax(i,j) .gt. 8000.) maxc8 = maxc8 +1
964 print *,
' after MAXC 3-6 km:',maxc3,maxc4,maxc5,maxc6
966 call mnmxja(im,jm,elvmax,itest,jtest,
' ELVMAX')
971 print *,
' Testing at point (itest,jtest)=',itest,jtest
972 print *,
' SLM(itest,jtest)=',slm(itest,jtest),itest,jtest
973 print *,
' ORO(itest,jtest)=',oro(itest,jtest),itest,jtest
976 IF(slm(i,j).EQ.0.)
THEN 1006 IF (merge_file ==
'none')
then 1008 msk_ocn :
if ( mskocn .eq. 1 )
then 1012 if (abs(oro(i,j)) .lt. 1. )
then 1013 slm(i,j) = slmi(i,j)
1015 if ( slmi(i,j) .eq. 1. .and. slm(i,j) .eq. 1) slm(i,j) = 1
1016 if ( slmi(i,j) .eq. 0. .and. slm(i,j) .eq. 0) slm(i,j) = 0
1017 if ( slmi(i,j) .eq. 0. .and. slm(i,j) .eq. 1) slm(i,j) = 0
1018 if ( slmi(i,j) .eq. 0. .and. slm(i,j) .eq. 0) slm(i,j) = 0
1024 print *,
' SLM(itest,jtest)=',slm(itest,jtest),itest,jtest
1025 print *,
' ORO(itest,jtest)=',oro(itest,jtest),itest,jtest
1029 IF (merge_file ==
'none')
then 1032 iso_loop :
DO j=2,jm-1
1038 slma=slm(iw,j)+slm(ie,j)
1039 oroa=oro(iw,j)+oro(ie,j)
1040 vara=var(iw,j)+var(ie,j)
1041 var4a=var4(iw,j)+var4(ie,j)
1043 oaa(k)=oa(iw,j,k)+oa(ie,j,k)
1045 ola(k)=ol(iw,j,k)+ol(ie,j,k)
1049 IF(abs(xn-nint(xn)).LT.1.e-2)
THEN 1050 in=mod(nint(xn)-1,im)+1
1051 inw=mod(in+im-2,im)+1
1053 slma=slma+slm(inw,jn)+slm(in,jn)+slm(ine,jn)
1054 oroa=oroa+oro(inw,jn)+oro(in,jn)+oro(ine,jn)
1055 vara=vara+var(inw,jn)+var(in,jn)+var(ine,jn)
1056 var4a=var4a+var4(inw,jn)+var4(in,jn)+var4(ine,jn)
1058 oaa(k)=oaa(k)+oa(inw,jn,k)+oa(in,jn,k)+oa(ine,jn,k)
1059 ola(k)=ola(k)+ol(inw,jn,k)+ol(in,jn,k)+ol(ine,jn,k)
1065 slma=slma+slm(inw,jn)+slm(ine,jn)
1066 oroa=oroa+oro(inw,jn)+oro(ine,jn)
1067 vara=vara+var(inw,jn)+var(ine,jn)
1068 var4a=var4a+var4(inw,jn)+var4(ine,jn)
1070 oaa(k)=oaa(k)+oa(inw,jn,k)+oa(ine,jn,k)
1071 ola(k)=ola(k)+ol(inw,jn,k)+ol(ine,jn,k)
1076 IF(abs(xs-nint(xs)).LT.1.e-2)
THEN 1077 is=mod(nint(xs)-1,im)+1
1078 isw=mod(is+im-2,im)+1
1080 slma=slma+slm(isw,js)+slm(is,js)+slm(ise,js)
1081 oroa=oroa+oro(isw,js)+oro(is,js)+oro(ise,js)
1082 vara=vara+var(isw,js)+var(is,js)+var(ise,js)
1083 var4a=var4a+var4(isw,js)+var4(is,js)+var4(ise,js)
1085 oaa(k)=oaa(k)+oa(isw,js,k)+oa(is,js,k)+oa(ise,js,k)
1086 ola(k)=ola(k)+ol(isw,js,k)+ol(is,js,k)+ol(ise,js,k)
1092 slma=slma+slm(isw,js)+slm(ise,js)
1093 oroa=oroa+oro(isw,js)+oro(ise,js)
1094 vara=vara+var(isw,js)+var(ise,js)
1095 var4a=var4a+var4(isw,js)+var4(ise,js)
1097 oaa(k)=oaa(k)+oa(isw,js,k)+oa(ise,js,k)
1098 ola(k)=ola(k)+ol(isw,js,k)+ol(ise,js,k)
1109 IF(slm(i,j).EQ.0..AND.slma.EQ.wgta)
THEN 1110 print
'("SEA ",2F8.0," MODIFIED TO LAND",2F8.0," AT ",2I8)',
1111 & oro(i,j),var(i,j),oroa,vara,i,j
1120 ELSEIF(slm(i,j).EQ.1..AND.slma.EQ.0.)
THEN 1121 print
'("LAND",2F8.0," MODIFIED TO SEA ",2F8.0," AT ",2I8)',
1122 & oro(i,j),var(i,j),oroa,vara,i,j
1135 print *,
' after isolated points removed' 1136 call minmxj(im,jm,oro,
' ORO')
1137 print *,
' ORO(itest,jtest)=',oro(itest,jtest)
1138 print *,
' VAR(itest,jtest)=',var(itest,jtest)
1139 print *,
' VAR4(itest,jtest)=',var4(itest,jtest)
1140 print *,
' OA(itest,jtest,1)=',oa(itest,jtest,1)
1141 print *,
' OA(itest,jtest,2)=',oa(itest,jtest,2)
1142 print *,
' OA(itest,jtest,3)=',oa(itest,jtest,3)
1143 print *,
' OA(itest,jtest,4)=',oa(itest,jtest,4)
1144 print *,
' OL(itest,jtest,1)=',ol(itest,jtest,1)
1145 print *,
' OL(itest,jtest,2)=',ol(itest,jtest,2)
1146 print *,
' OL(itest,jtest,3)=',ol(itest,jtest,3)
1147 print *,
' OL(itest,jtest,4)=',ol(itest,jtest,4)
1148 print *,
' Testing at point (itest,jtest)=',itest,jtest
1149 print *,
' THETA(itest,jtest)=',theta(itest,jtest)
1150 print *,
' GAMMA(itest,jtest)=',gamma(itest,jtest)
1151 print *,
' SIGMA(itest,jtest)=',sigma(itest,jtest)
1152 print *,
' ELVMAX(itest,jtest)=',elvmax(itest,jtest)
1153 print *,
' EFAC=',efac
1160 oro(i,j) = oro(i,j) + efac*var(i,j)
1161 hprime(i,j,1) = var(i,j)
1162 hprime(i,j,2) = var4(i,j)
1163 hprime(i,j,3) = oa(i,j,1)
1164 hprime(i,j,4) = oa(i,j,2)
1165 hprime(i,j,5) = oa(i,j,3)
1166 hprime(i,j,6) = oa(i,j,4)
1167 hprime(i,j,7) = ol(i,j,1)
1168 hprime(i,j,8) = ol(i,j,2)
1169 hprime(i,j,9) = ol(i,j,3)
1170 hprime(i,j,10)= ol(i,j,4)
1171 hprime(i,j,11)= theta(i,j)
1172 hprime(i,j,12)= gamma(i,j)
1173 hprime(i,j,13)= sigma(i,j)
1174 hprime(i,j,14)= elvmax(i,j)
1178 call mnmxja(im,jm,elvmax,itest,jtest,
' ELVMAX')
1187 allocate (orf(im,jm))
1188 IF ( nf1 - nf0 .eq. 0 ) filter=.false.
1189 print *,
' NF1, NF0, FILTER=',nf1,nf0,filter
1193 CALL sptez(nr,nm,4,im,jm,ors,oro,-1)
1195 print *,
' about to apply spectral filter ' 1201 www=max(1.-fff*(n-nf0)**2,0.)
1202 ors(i+1)=ors(i+1)*www
1203 ors(i+2)=ors(i+2)*www
1209 CALL sptez(nr,nm,4,im,jm,ors,orf,+1)
1218 call mnmxja(im,jm,elvmax,itest,jtest,
' ELVMAX')
1219 print *,
' ELVMAX(',itest,jtest,
')=',elvmax(itest,jtest)
1220 print *,
' after spectral filter is applied' 1221 call minmxj(im,jm,oro,
' ORO')
1222 call minmxj(im,jm,orf,
' ORF')
1224 print *,
' after nearest neighbor interpolation applied ' 1225 call minmxj(im,jm,oro,
' ORO')
1226 call minmxj(im,jm,orf,
' ORF')
1227 call mnmxja(im,jm,elvmax,itest,jtest,
' ELVMAX')
1228 print *,
' ORO,ORF(itest,jtest),itest,jtest:',
1229 & oro(itest,jtest),orf(itest,jtest),itest,jtest
1230 print *,
' ELVMAX(',itest,jtest,
')=',elvmax(itest,jtest)
1236 if ( i .le. 21 .and. i .ge. 1 )
then 1237 if (j .eq. jm )
write(6,153)i,j,oro(i,j),elvmax(i,j),slm(i,j)
1238 153
format(1x,
' ORO,ELVMAX(i=',i4,
' j=',i4,
')=',2e14.5,f5.1)
1243 write(6,*)
' Timer 5 time= ',tend-tbeg
1247 xlon(i) = delxn*(i-1)
1249 IF(trim(outgrid) ==
"none")
THEN 1252 geolon(i,j) = xlon(i)
1253 geolat(i,j) = xlat(j)
1258 xlat(j) = geolat(1,j)
1261 xlon(i) = geolon(i,1)
1266 CALL write_netcdf(im,jm,slm,land_frac,oro,orf,hprime,1,1,
1267 1 geolon(1:im,1:jm),geolat(1:im,1:jm), xlon,xlat)
1269 write(6,*)
' WRITE_NETCDF time= ',tend-tbeg
1270 print *,
' wrote netcdf file out.oro.tile?.nc' 1272 print *,
' ===== Deallocate Arrays and ENDING MTN VAR OROG program' 1275 deallocate(jst,jen,numi)
1276 deallocate(cosclt,wgtclt,rclt,xlat,diffx,xlon,ors,oaa,ola,glat)
1280 deallocate (geolon,geolon_c,geolat,geolat_c)
1281 deallocate (slm,oro,var,orf,land_frac)
1282 deallocate (theta,gamma,sigma,elvmax)
1286 write(6,*)
' Total runtime time= ',tend-tbeg1
1319 SUBROUTINE makemt(ZAVG,ZSLM,ORO,SLM,VAR,VAR4,
1320 1 GLAT,IST,IEN,JST,JEN,IM,JM,IMN,JMN,XLAT,numi)
1321 dimension glat(jmn),xlat(jm)
1323 INTEGER ZAVG(IMN,JMN),ZSLM(IMN,JMN)
1324 DIMENSION ORO(IM,JM),SLM(IM,JM),VAR(IM,JM),VAR4(IM,JM)
1325 dimension ist(im,jm),ien(im,jm),jst(jm),jen(jm),numi(jm)
1329 print *,
' _____ SUBROUTINE MAKEMT ' 1336 glat(j) = -90. + (j-1) * delxn + delxn * 0.5
1346 faclon = delx / delxn
1347 ist(i,j) = faclon * float(i-1) - faclon * 0.5 + 1
1348 ien(i,j) = faclon * float(i) - faclon * 0.5 + 1
1352 IF (ist(i,j) .LE. 0) ist(i,j) = ist(i,j) + imn
1353 IF (ien(i,j) .LT. ist(i,j)) ien(i,j) = ien(i,j) + imn
1362 print *,
' DELX=',delx,
' DELXN=',delxn
1366 xxlat = (xlat(j)+xlat(j+1))/2.
1367 IF(flag.AND.glat(j1).GT.xxlat)
THEN 1375 jst(jm) = max(jst(jm-1) - (jen(jm-1)-jst(jm-1)),1)
1376 jen(1) = min(jen(2) + (jen(2)-jst(2)),jmn)
1394 DO ii1 = 1, ien(i,j) - ist(i,j) + 1
1395 i1 = ist(i,j) + ii1 - 1
1396 IF(i1.LE.0.) i1 = i1 + imn
1397 IF(i1.GT.imn) i1 = i1 - imn
1404 xland = xland + float(zslm(i1,j1))
1405 xwatr = xwatr + float(1-zslm(i1,j1))
1407 height = float(zavg(i1,j1))
1409 IF(height.LT.-990.) height = 0.0
1410 xl1 = xl1 + height * float(zslm(i1,j1))
1411 xs1 = xs1 + height * float(1-zslm(i1,j1))
1413 xw2 = xw2 + height ** 2
1424 IF(xnsum.GT.1.)
THEN 1429 slm(i,j) = float(nint(xland/xnsum))
1430 IF(slm(i,j).NE.0.)
THEN 1431 oro(i,j)= xl1 / xland
1433 oro(i,j)= xs1 / xwatr
1435 var(i,j)=sqrt(max(xw2/xnsum-(xw1/xnsum)**2,0.))
1436 DO ii1 = 1, ien(i,j) - ist(i,j) + 1
1437 i1 = ist(i,j) + ii1 - 1
1438 IF(i1.LE.0.) i1 = i1 + imn
1439 IF(i1.GT.imn) i1 = i1 - imn
1441 height = float(zavg(i1,j1))
1442 IF(height.LT.-990.) height = 0.0
1443 xw4 = xw4 + (height-oro(i,j)) ** 4
1446 IF(var(i,j).GT.1.)
THEN 1450 var4(i,j) = min(xw4/xnsum/var(i,j) **4,10.)
1455 WRITE(6,*)
"! MAKEMT ORO SLM VAR VAR4 DONE" 1480 SUBROUTINE get_index(IMN,JMN,npts,lonO,latO,DELXN,
1481 & jst,jen,ilist,numx)
1483 integer,
intent(in) :: IMN,JMN
1485 real,
intent(in) :: LONO(npts), LATO(npts)
1486 real,
intent(in) :: DELXN
1487 integer,
intent(out) :: jst,jen
1488 integer,
intent(out) :: ilist(IMN)
1489 integer,
intent(out) :: numx
1490 real minlat,maxlat,minlon,maxlon
1491 integer i2, ii, ist, ien
1493 minlat = minval(lato)
1494 maxlat = maxval(lato)
1495 minlon = minval(lono)
1496 maxlon = maxval(lono)
1497 ist = minlon/delxn+1
1498 ien = maxlon/delxn+1
1499 jst = (minlat+90)/delxn+1
1500 jen = (maxlat+90)/delxn
1505 if(jen>jmn) jen = jmn
1508 if((jst == 1 .OR. jen == jmn) .and.
1509 & (ien-ist+1 > imn/2) )
then 1514 else if( ien-ist+1 > imn/2 )
then 1520 ii = lono(i2)/delxn+1
1521 if(ii <0 .or. ii>imn) print*,
"ii=",ii,imn,lono(i2),delxn
1522 if( ii < imn/2 )
then 1524 else if( ii > imn/2 )
then 1528 if(ist<1 .OR. ist>imn)
then 1529 print*, .or.
"FATAL ERROR: ist<1 ist>IMN" 1532 if(ien<1 .OR. ien>imn)
then 1533 print*, .or.
"FATAL ERROR: iend<1 iend>IMN" 1537 numx = imn - ien + 1
1539 ilist(i2) = ien + (i2-1)
1548 ilist(i2) = ist + (i2-1)
1569 SUBROUTINE make_mask(zslm,SLM,land_frac,
1570 1 GLAT,IM,JM,IMN,JMN,lon_c,lat_c)
1572 real,
parameter :: D2R = 3.14159265358979/180.
1573 integer,
parameter :: MAXSUM=20000000
1574 integer im, jm, imn, jmn, jst, jen
1575 real GLAT(JMN), GLON(IMN)
1576 INTEGER ZSLM(IMN,JMN)
1577 real land_frac(IM,JM)
1579 real lon_c(IM+1,JM+1), lat_c(IM+1,JM+1)
1580 real LONO(4),LATO(4),LONI,LATI
1581 integer JM1,i,j,nsum,nsum_all,ii,jj,numx,i2
1583 real DELXN,XNSUM,XLAND,XWATR,XL1,XS1,XW1
1584 real XNSUM_ALL,XLAND_ALL,XWATR_ALL
1585 logical inside_a_polygon
1588 print *,
' _____ SUBROUTINE MAKE_MASK ' 1595 glat(j) = -90. + (j-1) * delxn + delxn * 0.5
1598 glon(i) = 0. + (i-1) * delxn + delxn * 0.5
1601 land_frac(:,:) = 0.0
1623 lono(1) = lon_c(i,j)
1624 lono(2) = lon_c(i+1,j)
1625 lono(3) = lon_c(i+1,j+1)
1626 lono(4) = lon_c(i,j+1)
1627 lato(1) = lat_c(i,j)
1628 lato(2) = lat_c(i+1,j)
1629 lato(3) = lat_c(i+1,j+1)
1630 lato(4) = lat_c(i,j+1)
1631 call get_index(imn,jmn,4,lono,lato,delxn,jst,jen,ilist,numx)
1632 do jj = jst, jen;
do i2 = 1, numx
1635 lati = -90 + jj*delxn
1637 xland_all = xland_all + float(zslm(ii,jj))
1638 xwatr_all = xwatr_all + float(1-zslm(ii,jj))
1639 xnsum_all = xnsum_all + 1.
1640 nsum_all = nsum_all+1
1641 if(nsum_all > maxsum)
then 1642 print*,
"FATAL ERROR: nsum_all is greater than MAXSUM," 1643 print*,
"increase MAXSUM." 1647 if(inside_a_polygon(loni*d2r,lati*d2r,4,
1648 & lono*d2r,lato*d2r))
then 1650 xland = xland + float(zslm(ii,jj))
1651 xwatr = xwatr + float(1-zslm(ii,jj))
1654 if(nsum > maxsum)
then 1655 print*,
"FATAL ERROR: nsum is greater than MAXSUM," 1656 print*,
"increase MAXSUM." 1663 IF(xnsum.GT.1.)
THEN 1667 land_frac(i,j) = xland/xnsum
1668 slm(i,j) = float(nint(xland/xnsum))
1669 ELSEIF(xnsum_all.GT.1.)
THEN 1670 land_frac(i,j) = xland_all/xnsum _all
1671 slm(i,j) = float(nint(xland_all/xnsum_all))
1673 print*,
"FATAL ERROR: no source points in MAKE_MASK." 1679 WRITE(6,*)
"! MAKE_MASK DONE" 1704 SUBROUTINE makemt2(ZAVG,ZSLM,ORO,SLM,VAR,VAR4,
1705 1 GLAT,IM,JM,IMN,JMN,lon_c,lat_c,lake_frac,land_frac)
1707 real,
parameter :: D2R = 3.14159265358979/180.
1708 integer,
parameter :: maxsum=20000000
1709 real,
dimension(:),
allocatable :: hgt_1d, hgt_1d_all
1710 integer IM, JM, IMN, JMN
1711 real GLAT(JMN), GLON(IMN)
1712 INTEGER ZAVG(IMN,JMN),ZSLM(IMN,JMN)
1713 real ORO(IM,JM),VAR(IM,JM),VAR4(IM,JM)
1714 real,
intent(in) :: SLM(IM,JM), lake_frac(im,jm),land_frac(im,jm)
1716 real lon_c(IM+1,JM+1), lat_c(IM+1,JM+1)
1717 real LONO(4),LATO(4),LONI,LATI
1719 integer JM1,i,j,nsum,nsum_all,ii,jj,i1,numx,i2
1721 real DELXN,XNSUM,XLAND,XWATR,XL1,XS1,XW1,XW2,XW4
1722 real XNSUM_ALL,XLAND_ALL,XWATR_ALL,HEIGHT_ALL
1723 real XL1_ALL,XS1_ALL,XW1_ALL,XW2_ALL,XW4_ALL
1724 logical inside_a_polygon
1729 print *,
' _____ SUBROUTINE MAKEMT2 ' 1730 allocate(hgt_1d(maxsum))
1731 allocate(hgt_1d_all(maxsum))
1738 glat(j) = -90. + (j-1) * delxn + delxn * 0.5
1741 glon(i) = 0. + (i-1) * delxn + delxn * 0.5
1781 lono(1) = lon_c(i,j)
1782 lono(2) = lon_c(i+1,j)
1783 lono(3) = lon_c(i+1,j+1)
1784 lono(4) = lon_c(i,j+1)
1785 lato(1) = lat_c(i,j)
1786 lato(2) = lat_c(i+1,j)
1787 lato(3) = lat_c(i+1,j+1)
1788 lato(4) = lat_c(i,j+1)
1789 call get_index(imn,jmn,4,lono,lato,delxn,jst,jen,ilist,numx)
1790 do jj = jst, jen;
do i2 = 1, numx
1793 lati = -90 + jj*delxn
1795 xland_all = xland_all + float(zslm(ii,jj))
1796 xwatr_all = xwatr_all + float(1-zslm(ii,jj))
1797 xnsum_all = xnsum_all + 1.
1798 height_all = float(zavg(ii,jj))
1799 nsum_all = nsum_all+1
1800 if(nsum_all > maxsum)
then 1801 print*,
"FATAL ERROR: nsum_all is greater than MAXSUM," 1802 print*,
"increase MAXSUM." 1805 hgt_1d_all(nsum_all) = height_all
1806 IF(height_all.LT.-990.) height_all = 0.0
1807 xl1_all = xl1_all + height_all * float(zslm(ii,jj))
1808 xs1_all = xs1_all + height_all * float(1-zslm(ii,jj))
1809 xw1_all = xw1_all + height_all
1810 xw2_all = xw2_all + height_all ** 2
1812 if(inside_a_polygon(loni*d2r,lati*d2r,4,
1813 & lono*d2r,lato*d2r))
then 1815 xland = xland + float(zslm(ii,jj))
1816 xwatr = xwatr + float(1-zslm(ii,jj))
1818 height = float(zavg(ii,jj))
1820 if(nsum > maxsum)
then 1821 print*,
"FATAL ERROR: nsum is greater than MAXSUM," 1822 print*,
"increase MAXSUM." 1825 hgt_1d(nsum) = height
1826 IF(height.LT.-990.) height = 0.0
1827 xl1 = xl1 + height * float(zslm(ii,jj))
1828 xs1 = xs1 + height * float(1-zslm(ii,jj))
1830 xw2 = xw2 + height ** 2
1834 IF(xnsum.GT.1.)
THEN 1840 IF(slm(i,j) .NE. 0. .OR. land_frac(i,j) > 0.)
THEN 1842 oro(i,j)= xl1 / xland
1844 oro(i,j)= xs1 / xwatr
1848 oro(i,j)= xs1 / xwatr
1850 oro(i,j)= xl1 / xland
1854 var(i,j)=sqrt(max(xw2/xnsum-(xw1/xnsum)**2,0.))
1856 xw4 = xw4 + (hgt_1d(i1) - oro(i,j)) ** 4
1859 IF(var(i,j).GT.1.)
THEN 1860 var4(i,j) = min(xw4/xnsum/var(i,j) **4,10.)
1863 ELSEIF(xnsum_all.GT.1.)
THEN 1866 IF(slm(i,j) .NE. 0. .OR. land_frac(i,j) > 0.)
THEN 1867 IF (xland_all > 0)
THEN 1868 oro(i,j)= xl1_all / xland_all
1870 oro(i,j)= xs1_all / xwatr_all
1873 IF (xwatr_all > 0)
THEN 1874 oro(i,j)= xs1_all / xwatr_all
1876 oro(i,j)= xl1_all / xland_all
1880 var(i,j)=sqrt(max(xw2_all/xnsum_all-
1881 & (xw1_all/xnsum_all)**2,0.))
1884 & (hgt_1d_all(i1) - oro(i,j)) ** 4
1887 IF(var(i,j).GT.1.)
THEN 1888 var4(i,j) = min(xw4_all/xnsum_all/var(i,j) **4,10.)
1891 print*,
"FATAL ERROR: no source points in MAKEMT2." 1897 IF (lake_frac(i,j) .EQ. 0. .AND. land_frac(i,j) .EQ. 0.)
THEN 1904 WRITE(6,*)
"! MAKEMT2 ORO SLM VAR VAR4 DONE" 1907 deallocate(hgt_1d_all)
1939 SUBROUTINE makepc(ZAVG,ZSLM,THETA,GAMMA,SIGMA,
1940 1 GLAT,IST,IEN,JST,JEN,IM,JM,IMN,JMN,XLAT,numi)
1944 parameter(rearth=6.3712e+6)
1945 dimension glat(jmn),xlat(jm),deltax(jmn)
1946 INTEGER ZAVG(IMN,JMN),ZSLM(IMN,JMN)
1947 DIMENSION ORO(IM,JM),SLM(IM,JM),HL(IM,JM),HK(IM,JM)
1948 DIMENSION HX2(IM,JM),HY2(IM,JM),HXY(IM,JM),HLPRIM(IM,JM)
1949 DIMENSION THETA(IM,JM),GAMMA(IM,JM),SIGMA2(IM,JM),SIGMA(IM,JM)
1950 dimension ist(im,jm),ien(im,jm),jst(jm),jen(jm),numi(jm)
1955 pi = 4.0 * atan(1.0)
1961 deltay = certh / float(jmn)
1962 print *,
'MAKEPC: DELTAY=',deltay
1965 glat(j) = -90. + (j-1) * delxn + delxn * 0.5
1966 deltax(j) = deltay * cos(glat(j)*pi/180.0)
1975 faclon = delx / delxn
1976 ist(i,j) = faclon * float(i-1) - faclon * 0.5
1977 ist(i,j) = ist(i,j) + 1
1978 ien(i,j) = faclon * float(i) - faclon * 0.5
1985 IF (ist(i,j) .LE. 0) ist(i,j) = ist(i,j) + imn
1986 IF (ien(i,j) .LT. ist(i,j)) ien(i,j) = ien(i,j) + imn
1988 if ( i .lt. 10 .and. j .lt. 10 )
1989 1 print*,
' I j IST IEN ',i,j,ist(i,j),ien(i,j)
1991 IF (ien(i,j) .LT. ist(i,j))
1992 1 print *,
' MAKEPC: IEN < IST: I,J,IST(I,J),IEN(I,J)',
1993 2 i,j,ist(i,j),ien(i,j)
1999 xxlat = (xlat(j)+xlat(j+1))/2.
2000 IF(flag.AND.glat(j1).GT.xxlat)
THEN 2007 jst(jm) = max(jst(jm-1) - (jen(jm-1)-jst(jm-1)),1)
2008 jen(1) = min(jen(2) + (jen(2)-jst(2)),jmn)
2010 print*,
' IST,IEN(1,1-numi(1,JM))',ist(1,1),ien(1,1),
2011 1 ist(numi(jm),jm),ien(numi(jm),jm), numi(jm)
2012 print*,
' JST,JEN(1,JM) ',jst(1),jen(1),jst(jm),jen(jm)
2041 DO ii1 = 1, ien(i,j) - ist(i,j) + 1
2042 i1 = ist(i,j) + ii1 - 1
2043 IF(i1.LE.0.) i1 = i1 + imn
2044 IF(i1.GT.imn) i1 = i1 - imn
2049 if (i1 - 1 .le. 0 ) i0 = i0 + imn
2050 if (i1 - 1 .gt. imn) i0 = i0 - imn
2053 if (i1 + 1 .le. 0 ) ip1 = ip1 + imn
2054 if (i1 + 1 .gt. imn) ip1 = ip1 - imn
2058 if ( i1 .eq. ist(i,j) .and. j1 .eq. jst(j) )
2059 1 print*,
' J, J1,IST,JST,DELTAX,GLAT ',
2060 2 j,j1,ist(i,j),jst(j),deltax(j1),glat(j1)
2061 if ( i1 .eq. ien(i,j) .and. j1 .eq. jen(j) )
2062 1 print*,
' J, J1,IEN,JEN,DELTAX,GLAT ',
2063 2 j,j1,ien(i,j),jen(j),deltax(j1),glat(j1)
2065 xland = xland + float(zslm(i1,j1))
2066 xwatr = xwatr + float(1-zslm(i1,j1))
2069 height = float(zavg(i1,j1))
2070 hi0 = float(zavg(i0,j1))
2071 hip1 = float(zavg(ip1,j1))
2073 IF(height.LT.-990.) height = 0.0
2074 if(hi0 .lt. -990.) hi0 = 0.0
2075 if(hip1 .lt. -990.) hip1 = 0.0
2077 xfp = 0.5 * ( hip1 - hi0 ) / deltax(j1)
2078 xfp2 = xfp2 + 0.25 * ( ( hip1 - hi0 )/deltax(j1) )** 2
2082 if ( j1 .ne. jst(jm) .and. j1 .ne. jen(1) )
then 2083 hj0 = float(zavg(i1,j1-1))
2084 hjp1 = float(zavg(i1,j1+1))
2085 if(hj0 .lt. -990.) hj0 = 0.0
2086 if(hjp1 .lt. -990.) hjp1 = 0.0
2088 yfp = 0.5 * ( hjp1 - hj0 ) / deltay
2089 yfp2 = yfp2 + 0.25 * ( ( hjp1 - hj0 )/deltay )**2
2095 elseif ( j1 .eq. jst(jm) )
then 2097 if (ijax .le. 0 ) ijax = ijax + imn
2098 if (ijax .gt. imn) ijax = ijax - imn
2100 hijax = float(zavg(ijax,j1))
2101 hi1j1 = float(zavg(i1,j1))
2102 if(hijax .lt. -990.) hijax = 0.0
2103 if(hi1j1 .lt. -990.) hi1j1 = 0.0
2105 yfp = 0.5 * ( ( 0.5 * ( hijax - hi1j1 ) ) )/deltay
2106 yfp2 = yfp2 + 0.25 * ( ( 0.5 * ( hijax - hi1j1) )
2112 elseif ( j1 .eq. jen(1) )
then 2114 if (ijax .le. 0 ) ijax = ijax + imn
2115 if (ijax .gt. imn) ijax = ijax - imn
2116 hijax = float(zavg(ijax,j1))
2117 hi1j1 = float(zavg(i1,j1))
2118 if(hijax .lt. -990.) hijax = 0.0
2119 if(hi1j1 .lt. -990.) hi1j1 = 0.0
2120 if ( i1 .lt. 5 )print *,
' S.Pole i1,j1 :',i1,j1,hijax,hi1j1
2122 yfp = 0.5 * (0.5 * ( hijax - hi1j1) )/deltay
2123 yfp2 = yfp2 + 0.25 * ( (0.5 * (hijax - hi1j1) )
2130 xfpyfp = xfpyfp + xfp * yfp
2131 xl1 = xl1 + height * float(zslm(i1,j1))
2132 xs1 = xs1 + height * float(1-zslm(i1,j1))
2142 IF(xnsum.GT.1.)
THEN 2143 slm(i,j) = float(nint(xland/xnsum))
2144 IF(slm(i,j).NE.0.)
THEN 2145 oro(i,j)= xl1 / xland
2146 hx2(i,j) = xfp2 / xland
2147 hy2(i,j) = yfp2 / xland
2148 hxy(i,j) = xfpyfp / xland
2150 oro(i,j)= xs1 / xwatr
2154 print *,
" I,J,i1,j1,HEIGHT:", i,j,i1,j1,height,
2156 print *,
" xfpyfp,xfp2,yfp2:",xfpyfp,xfp2,yfp2
2157 print *,
" HX2,HY2,HXY:",hx2(i,j),hy2(i,j),hxy(i,j)
2163 hk(i,j) = 0.5 * ( hx2(i,j) + hy2(i,j) )
2164 hl(i,j) = 0.5 * ( hx2(i,j) - hy2(i,j) )
2165 hlprim(i,j) = sqrt(hl(i,j)*hl(i,j) + hxy(i,j)*hxy(i,j))
2166 IF( hl(i,j).NE. 0. .AND. slm(i,j) .NE. 0. )
THEN 2168 theta(i,j) = 0.5 * atan2(hxy(i,j),hl(i,j)) * 180.0 / pi
2172 sigma2(i,j) = ( hk(i,j) + hlprim(i,j) )
2173 if ( sigma2(i,j) .GE. 0. )
then 2174 sigma(i,j) = sqrt(sigma2(i,j) )
2175 if (sigma2(i,j) .ne. 0. .and.
2176 & hk(i,j) .GE. hlprim(i,j) )
2177 1 gamma(i,j) = sqrt( (hk(i,j) - hlprim(i,j)) / sigma2(i,j) )
2183 print *,
" I,J,THETA,SIGMA,GAMMA,",i,j,theta(i,j),
2184 1 sigma(i,j),gamma(i,j)
2185 print *,
" HK,HL,HLPRIM:",hk(i,j),hl(i,j),hlprim(i,j)
2189 WRITE(6,*)
"! MAKE Principal Coord DONE" 2214 SUBROUTINE makepc2(ZAVG,ZSLM,THETA,GAMMA,SIGMA,
2215 1 GLAT,IM,JM,IMN,JMN,lon_c,lat_c,SLM)
2220 real,
parameter :: REARTH=6.3712e+6
2221 real,
parameter :: D2R = 3.14159265358979/180.
2222 integer :: im,jm,imn,jmn
2223 real :: GLAT(JMN),DELTAX(JMN)
2224 INTEGER ZAVG(IMN,JMN),ZSLM(IMN,JMN)
2225 real lon_c(IM+1,JM+1), lat_c(IM+1,JM+1)
2226 real,
intent(in) :: SLM(IM,JM)
2227 real HL(IM,JM),HK(IM,JM)
2228 real HX2(IM,JM),HY2(IM,JM),HXY(IM,JM),HLPRIM(IM,JM)
2229 real THETA(IM,JM),GAMMA(IM,JM),SIGMA2(IM,JM),SIGMA(IM,JM)
2230 real PI,CERTH,DELXN,DELTAY,XNSUM,XLAND
2231 real xfp,yfp,xfpyfp,xfp2,yfp2
2232 real hi0,hip1,hj0,hjp1,hijax,hi1j1
2233 real LONO(4),LATO(4),LONI,LATI
2234 integer i,j,i1,j1,i2,jst,jen,numx,i0,ip1,ijax
2236 logical inside_a_polygon
2241 pi = 4.0 * atan(1.0)
2246 deltay = certh / float(jmn)
2247 print *,
'MAKEPC2: DELTAY=',deltay
2250 glat(j) = -90. + (j-1) * delxn + delxn * 0.5
2251 deltax(j) = deltay * cos(glat(j)*d2r)
2285 lono(1) = lon_c(i,j)
2286 lono(2) = lon_c(i+1,j)
2287 lono(3) = lon_c(i+1,j+1)
2288 lono(4) = lon_c(i,j+1)
2289 lato(1) = lat_c(i,j)
2290 lato(2) = lat_c(i+1,j)
2291 lato(3) = lat_c(i+1,j+1)
2292 lato(4) = lat_c(i,j+1)
2293 call get_index(imn,jmn,4,lono,lato,delxn,jst,jen,ilist,numx)
2295 do j1 = jst, jen;
do i2 = 1, numx
2298 lati = -90 + j1*delxn
2299 inside :
if(inside_a_polygon(loni*d2r,lati*d2r,4,
2300 & lono*d2r,lato*d2r))
then 2305 if (i1 - 1 .le. 0 ) i0 = i0 + imn
2306 if (i1 - 1 .gt. imn) i0 = i0 - imn
2309 if (i1 + 1 .le. 0 ) ip1 = ip1 + imn
2310 if (i1 + 1 .gt. imn) ip1 = ip1 - imn
2312 xland = xland + float(zslm(i1,j1))
2315 hi0 = float(zavg(i0,j1))
2316 hip1 = float(zavg(ip1,j1))
2318 if(hi0 .lt. -990.) hi0 = 0.0
2319 if(hip1 .lt. -990.) hip1 = 0.0
2321 xfp = 0.5 * ( hip1 - hi0 ) / deltax(j1)
2322 xfp2 = xfp2 + 0.25 * ( ( hip1 - hi0 )/deltax(j1) )** 2
2326 if ( j1 .ne. 1 .and. j1 .ne. jmn )
then 2327 hj0 = float(zavg(i1,j1-1))
2328 hjp1 = float(zavg(i1,j1+1))
2329 if(hj0 .lt. -990.) hj0 = 0.0
2330 if(hjp1 .lt. -990.) hjp1 = 0.0
2332 yfp = 0.5 * ( hjp1 - hj0 ) / deltay
2333 yfp2 = yfp2 + 0.25 * ( ( hjp1 - hj0 )/deltay )**2
2339 elseif ( j1 .eq. 1 )
then 2341 if (ijax .le. 0 ) ijax = ijax + imn
2342 if (ijax .gt. imn) ijax = ijax - imn
2344 hijax = float(zavg(ijax,j1))
2345 hi1j1 = float(zavg(i1,j1))
2346 if(hijax .lt. -990.) hijax = 0.0
2347 if(hi1j1 .lt. -990.) hi1j1 = 0.0
2349 yfp = 0.5 * ( ( 0.5 * ( hijax - hi1j1 ) ) )/deltay
2350 yfp2 = yfp2 + 0.25 * ( ( 0.5 * ( hijax - hi1j1) )
2356 elseif ( j1 .eq. jmn )
then 2358 if (ijax .le. 0 ) ijax = ijax + imn
2359 if (ijax .gt. imn) ijax = ijax - imn
2360 hijax = float(zavg(ijax,j1))
2361 hi1j1 = float(zavg(i1,j1))
2362 if(hijax .lt. -990.) hijax = 0.0
2363 if(hi1j1 .lt. -990.) hi1j1 = 0.0
2364 if ( i1 .lt. 5 )print *,
' S.Pole i1,j1 :',i1,j1,
2367 yfp = 0.5 * (0.5 * ( hijax - hi1j1) )/deltay
2368 yfp2 = yfp2 + 0.25 * ( (0.5 * (hijax - hi1j1) )
2375 xfpyfp = xfpyfp + xfp * yfp
2386 xnsum_gt_1 :
IF(xnsum.GT.1.)
THEN 2387 IF(slm(i,j).NE.0.)
THEN 2389 hx2(i,j) = xfp2 / xland
2390 hy2(i,j) = yfp2 / xland
2391 hxy(i,j) = xfpyfp / xland
2393 hx2(i,j) = xfp2 / xnsum
2394 hy2(i,j) = yfp2 / xnsum
2395 hxy(i,j) = xfpyfp / xnsum
2400 print *,
" I,J,i1,j1:", i,j,i1,j1,
2402 print *,
" xfpyfp,xfp2,yfp2:",xfpyfp,xfp2,yfp2
2403 print *,
" HX2,HY2,HXY:",hx2(i,j),hy2(i,j),hxy(i,j)
2409 hk(i,j) = 0.5 * ( hx2(i,j) + hy2(i,j) )
2410 hl(i,j) = 0.5 * ( hx2(i,j) - hy2(i,j) )
2411 hlprim(i,j) = sqrt(hl(i,j)*hl(i,j) + hxy(i,j)*hxy(i,j))
2412 IF( hl(i,j).NE. 0. .AND. slm(i,j) .NE. 0. )
THEN 2414 theta(i,j) = 0.5 * atan2(hxy(i,j),hl(i,j)) / d2r
2418 sigma2(i,j) = ( hk(i,j) + hlprim(i,j) )
2419 if ( sigma2(i,j) .GE. 0. )
then 2420 sigma(i,j) = sqrt(sigma2(i,j) )
2421 if (sigma2(i,j) .ne. 0. .and.
2422 & hk(i,j) .GE. hlprim(i,j) )
2423 1 gamma(i,j) = sqrt( (hk(i,j) - hlprim(i,j)) / sigma2(i,j) )
2429 print *,
" I,J,THETA,SIGMA,GAMMA,",i,j,theta(i,j),
2430 1 sigma(i,j),gamma(i,j)
2431 print *,
" HK,HL,HLPRIM:",hk(i,j),hl(i,j),hlprim(i,j)
2436 WRITE(6,*)
"! MAKE Principal Coord DONE" 2482 SUBROUTINE makeoa(ZAVG,VAR,GLAT,OA4,OL,IOA4,ELVMAX,
2483 1 ORO,oro1,XNSUM,XNSUM1,XNSUM2,XNSUM3,XNSUM4,
2484 2 IST,IEN,JST,JEN,IM,JM,IMN,JMN,XLAT,numi)
2485 dimension glat(jmn),xlat(jm)
2486 INTEGER ZAVG(IMN,JMN)
2487 DIMENSION ORO(IM,JM),ORO1(IM,JM),ELVMAX(IM,JM),ZMAX(IM,JM)
2488 DIMENSION OA4(IM,JM,4),IOA4(IM,JM,4)
2489 DIMENSION IST(IM,jm),IEN(IM,jm),JST(JM),JEN(JM)
2490 DIMENSION XNSUM(IM,JM),XNSUM1(IM,JM),XNSUM2(IM,JM)
2491 dimension xnsum3(im,jm),xnsum4(im,jm)
2492 dimension var(im,jm),ol(im,jm,4),numi(jm)
2502 glat(j) = -90. + (j-1) * delxn + delxn * 0.5
2504 print *,
' IM=',im,
' JM=',jm,
' IMN=',imn,
' JMN=',jmn
2511 faclon = delx / delxn
2513 ist(i,j) = faclon * float(i-1) - faclon * 0.5
2514 ist(i,j) = ist(i,j) + 1
2515 ien(i,j) = faclon * float(i) - faclon * 0.5
2518 IF (ist(i,j) .LE. 0) ist(i,j) = ist(i,j) + imn
2519 IF (ien(i,j) .LT. ist(i,j)) ien(i,j) = ien(i,j) + imn
2521 if ( i .lt. 3 .and. j .lt. 3 )
2522 1print*,
' MAKEOA: I j IST IEN ',i,j,ist(i,j),ien(i,j)
2523 if ( i .lt. 3 .and. j .ge. jm-1 )
2524 1print*,
' MAKEOA: I j IST IEN ',i,j,ist(i,j),ien(i,j)
2527 print *,
'MAKEOA: DELXN,DELX,FACLON',delxn,delx,faclon
2528 print *,
' ***** ready to start JST JEN section ' 2533 xxlat = (xlat(j)+xlat(j+1))/2.
2534 IF(flag.AND.glat(j1).GT.xxlat)
THEN 2539 1print*,
' MAKEOA: XX j JST JEN ',j,jst(j),jen(j)
2543 1print*,
' MAKEOA: j JST JEN ',j,jst(j),jen(j)
2545 1print*,
' MAKEOA: j JST JEN ',j,jst(j),jen(j)
2554 jst(jm) = max(jst(jm-1) - (jen(jm-1)-jst(jm-1)),1)
2555 jen(1) = min(jen(2) + (jen(2)-jst(2)),jmn)
2556 print *,
' ***** JST(1) JEN(1) ',jst(1),jen(1)
2557 print *,
' ***** JST(JM) JEN(JM) ',jst(jm),jen(jm)
2562 elvmax(i,j) = oro(i,j)
2571 DO ii1 = 1, ien(i,j) - ist(i,j) + 1
2572 i1 = ist(i,j) + ii1 - 1
2574 IF(i1.LE.0.) i1 = i1 + imn
2575 IF (i1 .GT. imn) i1 = i1 - imn
2577 height = float(zavg(i1,j1))
2578 IF(height.LT.-990.) height = 0.0
2579 IF ( height .gt. oro(i,j) )
then 2580 if ( height .gt. zmax(i,j) )zmax(i,j) = height
2581 xnsum(i,j) = xnsum(i,j) + 1
2585 if ( i .lt. 5 .and. j .ge. jm-5 )
then 2586 print *,
' I,J,ORO(I,J),XNSUM(I,J),ZMAX(I,J):',
2587 1 i,j,oro(i,j),xnsum(i,j),zmax(i,j)
2598 oro1(i,j) = oro(i,j)
2599 elvmax(i,j) = zmax(i,j)
2632 hc = 1116.2 - 0.878 * var(i,j)
2634 DO ii1 = 1, ien(i,j) - ist(i,j) + 1
2635 i1 = ist(i,j) + ii1 - 1
2640 IF(i1.GT.imn) i1 = i1 - imn
2642 IF(float(zavg(i1,j1)) .GT. hc)
2643 1 xnsum1(i,j) = xnsum1(i,j) + 1
2644 xnsum2(i,j) = xnsum2(i,j) + 1
2648 inci = nint((ien(i,j)-ist(i,j)) * 0.5)
2649 isttt = min(max(ist(i,j)-inci,1),imn)
2650 ieddd = min(max(ien(i,j)-inci,1),imn)
2652 incj = nint((jen(j)-jst(j)) * 0.5)
2653 jsttt = min(max(jst(j)-incj,1),jmn)
2654 jeddd = min(max(jen(j)-incj,1),jmn)
2664 IF(float(zavg(i1,j1)) .GT. hc)
2665 1 xnsum3(i,j) = xnsum3(i,j) + 1
2666 xnsum4(i,j) = xnsum4(i,j) + 1
2692 IF (ii .GT. numi(j)) ii = ii - numi(j)
2693 xnpu = xnsum(i,j) + xnsum(i,j+1)
2694 xnpd = xnsum(ii,j) + xnsum(ii,j+1)
2695 IF (xnpd .NE. xnpu) oa4(ii,j+1,1) = 1. - xnpd / max(xnpu , 1.)
2696 ol(ii,j+1,1) = (xnsum3(i,j+1)+xnsum3(ii,j+1))/
2697 1 (xnsum4(i,j+1)+xnsum4(ii,j+1))
2712 IF (ii .GT. numi(j)) ii = ii - numi(j)
2713 xnpu = xnsum(i,j+1) + xnsum(ii,j+1)
2714 xnpd = xnsum(i,j) + xnsum(ii,j)
2715 IF (xnpd .NE. xnpu) oa4(ii,j+1,2) = 1. - xnpd / max(xnpu , 1.)
2716 ol(ii,j+1,2) = (xnsum3(ii,j)+xnsum3(ii,j+1))/
2717 1 (xnsum4(ii,j)+xnsum4(ii,j+1))
2723 IF (ii .GT. numi(j)) ii = ii - numi(j)
2724 xnpu = xnsum(i,j+1) + ( xnsum(i,j) + xnsum(ii,j+1) )*0.5
2725 xnpd = xnsum(ii,j) + ( xnsum(i,j) + xnsum(ii,j+1) )*0.5
2726 IF (xnpd .NE. xnpu) oa4(ii,j+1,3) = 1. - xnpd / max(xnpu , 1.)
2727 ol(ii,j+1,3) = (xnsum1(ii,j)+xnsum1(i,j+1))/
2728 1 (xnsum2(ii,j)+xnsum2(i,j+1))
2734 IF (ii .GT. numi(j)) ii = ii - numi(j)
2735 xnpu = xnsum(i,j) + ( xnsum(ii,j) + xnsum(i,j+1) )*0.5
2736 xnpd = xnsum(ii,j+1) + ( xnsum(ii,j) + xnsum(i,j+1) )*0.5
2737 IF (xnpd .NE. xnpu) oa4(ii,j+1,4) = 1. - xnpd / max(xnpu , 1.)
2738 ol(ii,j+1,4) = (xnsum1(i,j)+xnsum1(ii,j+1))/
2739 1 (xnsum2(i,j)+xnsum2(ii,j+1))
2745 ol(i,1,kwd) = ol(i,2,kwd)
2746 ol(i,jm,kwd) = ol(i,jm-1,kwd)
2754 oa4(i,j,kwd) = sign( min( abs(t), 1. ), t )
2769 t = abs( oa4(i,j,kwd) )
2773 ELSE IF(t .GT. 0. .AND. t .LE. 1.)
THEN 2776 ELSE IF(t .GT. 1. .AND. t .LE. 10.)
THEN 2779 ELSE IF(t .GT. 10. .AND. t .LE. 100.)
THEN 2782 ELSE IF(t .GT. 100. .AND. t .LE. 1000.)
THEN 2785 ELSE IF(t .GT. 1000. .AND. t .LE. 10000.)
THEN 2788 ELSE IF(t .GT. 10000.)
THEN 2796 WRITE(6,*)
"! MAKEOA EXIT" 2812 real dx, lat, degrad
2815 real,
parameter :: radius = 6371200
2817 get_lon_angle = 2*asin( sin(dx/radius*0.5)/cos(lat) )*degrad
2834 real,
parameter :: radius = 6371200
2876 SUBROUTINE makeoa2(ZAVG,zslm,VAR,GLAT,OA4,OL,IOA4,ELVMAX,
2877 1 ORO,oro1,XNSUM,XNSUM1,XNSUM2,XNSUM3,XNSUM4,
2878 2 IM,JM,IMN,JMN,lon_c,lat_c,lon_t,lat_t,dx,dy,
2879 3 is_south_pole,is_north_pole )
2881 real,
parameter :: MISSING_VALUE = -9999.
2882 real,
parameter :: d2r = 3.14159265358979/180.
2883 real,
PARAMETER :: R2D=180./3.14159265358979
2884 integer im,jm,imn,jmn
2886 INTEGER ZAVG(IMN,JMN),ZSLM(IMN,JMN)
2887 real ORO(IM,JM),ORO1(IM,JM),ELVMAX(IM,JM),ZMAX(IM,JM)
2889 integer IOA4(IM,JM,4)
2890 real lon_c(IM+1,JM+1), lat_c(IM+1,JM+1)
2891 real lon_t(IM,JM), lat_t(IM,JM)
2892 real dx(IM,JM), dy(IM,JM)
2893 logical is_south_pole(IM,JM), is_north_pole(IM,JM)
2894 real XNSUM(IM,JM),XNSUM1(IM,JM),XNSUM2(IM,JM)
2895 real XNSUM3(IM,JM),XNSUM4(IM,JM)
2896 real VAR(IM,JM),OL(IM,JM,4)
2897 integer i,j,ilist(IMN),numx,i1,j1,ii1
2899 real LONO(4),LATO(4),LONI,LATI
2900 real DELXN,HC,HEIGHT,XNPU,XNPD,T
2901 integer NS0,NS1,NS2,NS3,NS4,NS5,NS6
2902 logical inside_a_polygon
2903 real lon,lat,dlon,dlat,dlat_old
2904 real lon1,lat1,lon2,lat2
2905 real xnsum11,xnsum12,xnsum21,xnsum22
2906 real HC_11, HC_12, HC_21, HC_22
2907 real xnsum1_11,xnsum1_12,xnsum1_21,xnsum1_22
2908 real xnsum2_11,xnsum2_12,xnsum2_21,xnsum2_22
2909 real get_lon_angle, get_lat_angle, get_xnsum
2917 glat(j) = -90. + (j-1) * delxn + delxn * 0.5
2919 print *,
' IM=',im,
' JM=',jm,
' IMN=',imn,
' JMN=',jmn
2927 elvmax(i,j) = oro(i,j)
2935 oro1(i,j) = oro(i,j)
2936 elvmax(i,j) = zmax(i,j)
2948 hc = 1116.2 - 0.878 * var(i,j)
2949 lono(1) = lon_c(i,j)
2950 lono(2) = lon_c(i+1,j)
2951 lono(3) = lon_c(i+1,j+1)
2952 lono(4) = lon_c(i,j+1)
2953 lato(1) = lat_c(i,j)
2954 lato(2) = lat_c(i+1,j)
2955 lato(3) = lat_c(i+1,j+1)
2956 lato(4) = lat_c(i,j+1)
2957 call get_index(imn,jmn,4,lono,lato,delxn,jst,jen,ilist,numx)
2958 do j1 = jst, jen;
do ii1 = 1, numx
2961 lati = -90 + j1*delxn
2962 if(inside_a_polygon(loni*d2r,lati*d2r,4,
2963 & lono*d2r,lato*d2r))
then 2965 height = float(zavg(i1,j1))
2966 IF(height.LT.-990.) height = 0.0
2967 IF ( height .gt. oro(i,j) )
then 2968 if ( height .gt. zmax(i,j) )zmax(i,j) = height
2981 oro1(i,j) = oro(i,j)
2982 elvmax(i,j) = zmax(i,j)
3016 if(is_north_pole(i,j))
then 3017 print*,
"set oa1 = 0 and ol=0 at i,j=", i,j
3022 else if(is_south_pole(i,j))
then 3023 print*,
"set oa1 = 0 and ol=1 at i,j=", i,j
3031 dlon = get_lon_angle(dx(i,j), lat*d2r, r2d )
3032 dlat = get_lat_angle(dy(i,j), r2d)
3034 if( lat-dlat*0.5<-90.)
then 3035 print*,
"at i,j =", i,j, lat, dlat, lat-dlat*0.5
3036 print*,
"FATAL ERROR: lat-dlat*0.5<-90." 3039 if( lat+dlat*2 > 90.)
then 3042 print*,
"at i,j=",i,j,
" adjust dlat from ",
3043 & dlat_old,
" to ", dlat
3051 if(lat1<-90 .or. lat2>90)
then 3052 print*,
"at upper left i=,j=", i, j, lat, dlat,lat1,lat2
3054 xnsum11 = get_xnsum(lon1,lat1,lon2,lat2,imn,jmn,glat,
3062 if(lat1<-90 .or. lat2>90)
then 3063 print*,
"at lower left i=,j=", i, j, lat, dlat,lat1,lat2
3065 xnsum12 = get_xnsum(lon1,lat1,lon2,lat2,imn,jmn,glat,
3073 if(lat1<-90 .or. lat2>90)
then 3074 print*,
"at upper right i=,j=", i, j, lat, dlat,lat1,lat2
3076 xnsum21 = get_xnsum(lon1,lat1,lon2,lat2,imn,jmn,glat,
3084 if(lat1<-90 .or. lat2>90)
then 3085 print*,
"at lower right i=,j=", i, j, lat, dlat,lat1,lat2
3088 xnsum22 = get_xnsum(lon1,lat1,lon2,lat2,imn,jmn,glat,
3091 xnpu = xnsum11 + xnsum12
3092 xnpd = xnsum21 + xnsum22
3093 IF (xnpd .NE. xnpu) oa4(i,j,1) = 1. - xnpd / max(xnpu , 1.)
3095 xnpu = xnsum11 + xnsum21
3096 xnpd = xnsum12 + xnsum22
3097 IF (xnpd .NE. xnpu) oa4(i,j,2) = 1. - xnpd / max(xnpu , 1.)
3099 xnpu = xnsum11 + (xnsum12+xnsum21)*0.5
3100 xnpd = xnsum22 + (xnsum12+xnsum21)*0.5
3101 IF (xnpd .NE. xnpu) oa4(i,j,3) = 1. - xnpd / max(xnpu , 1.)
3103 xnpu = xnsum12 + (xnsum11+xnsum22)*0.5
3104 xnpd = xnsum21 + (xnsum11+xnsum22)*0.5
3105 IF (xnpd .NE. xnpu) oa4(i,j,4) = 1. - xnpd / max(xnpu , 1.)
3114 if(lat1<-90 .or. lat2>90)
then 3115 print*,
"at upper left i=,j=", i, j, lat, dlat,lat1,lat2
3117 call get_xnsum2(lon1,lat1,lon2,lat2,imn,jmn,glat,
3118 & zavg,delxn, xnsum1_11, xnsum2_11, hc_11)
3125 if(lat1<-90 .or. lat2>90)
then 3126 print*,
"at lower left i=,j=", i, j, lat, dlat,lat1,lat2
3128 call get_xnsum2(lon1,lat1,lon2,lat2,imn,jmn,glat,
3129 & zavg,delxn, xnsum1_12, xnsum2_12, hc_12)
3136 if(lat1<-90 .or. lat2>90)
then 3137 print*,
"at upper right i=,j=", i, j, lat, dlat,lat1,lat2
3139 call get_xnsum2(lon1,lat1,lon2,lat2,imn,jmn,glat,
3140 & zavg,delxn, xnsum1_21, xnsum2_21, hc_21)
3147 if(lat1<-90 .or. lat2>90)
then 3148 print*,
"at lower right i=,j=", i, j, lat, dlat,lat1,lat2
3150 call get_xnsum2(lon1,lat1,lon2,lat2,imn,jmn,glat,
3151 & zavg,delxn, xnsum1_22, xnsum2_22, hc_22)
3153 ol(i,j,3) = (xnsum1_22+xnsum1_11)/(xnsum2_22+xnsum2_11)
3154 ol(i,j,4) = (xnsum1_12+xnsum1_21)/(xnsum2_12+xnsum2_21)
3162 if(lat1<-90 .or. lat2>90)
then 3163 print*,
"at upper left i=,j=", i, j, lat, dlat,lat1,lat2
3165 call get_xnsum3(lon1,lat1,lon2,lat2,imn,jmn,glat,
3166 & zavg,delxn, xnsum1_11, xnsum2_11, hc_11)
3173 if(lat1<-90 .or. lat2>90)
then 3174 print*,
"at lower left i=,j=", i, j, lat, dlat,lat1,lat2
3177 call get_xnsum3(lon1,lat1,lon2,lat2,imn,jmn,glat,
3178 & zavg,delxn, xnsum1_12, xnsum2_12, hc_12)
3185 if(lat1<-90 .or. lat2>90)
then 3186 print*,
"at upper right i=,j=", i, j, lat, dlat,lat1,lat2
3188 call get_xnsum3(lon1,lat1,lon2,lat2,imn,jmn,glat,
3189 & zavg,delxn, xnsum1_21, xnsum2_21, hc_21)
3196 if(lat1<-90 .or. lat2>90)
then 3197 print*,
"at lower right i=,j=", i, j, lat, dlat,lat1,lat2
3200 call get_xnsum3(lon1,lat1,lon2,lat2,imn,jmn,glat,
3201 & zavg,delxn, xnsum1_22, xnsum2_22, hc_22)
3203 ol(i,j,1) = (xnsum1_11+xnsum1_21)/(xnsum2_11+xnsum2_21)
3204 ol(i,j,2) = (xnsum1_21+xnsum1_22)/(xnsum2_21+xnsum2_22)
3213 oa4(i,j,kwd) = sign( min( abs(t), 1. ), t )
3228 t = abs( oa4(i,j,kwd) )
3232 ELSE IF(t .GT. 0. .AND. t .LE. 1.)
THEN 3235 ELSE IF(t .GT. 1. .AND. t .LE. 10.)
THEN 3238 ELSE IF(t .GT. 10. .AND. t .LE. 100.)
THEN 3241 ELSE IF(t .GT. 100. .AND. t .LE. 1000.)
THEN 3244 ELSE IF(t .GT. 1000. .AND. t .LE. 10000.)
THEN 3247 ELSE IF(t .GT. 10000.)
THEN 3255 WRITE(6,*)
"! MAKEOA2 EXIT" 3271 real,
intent(in) :: theta1, phi1, theta2, phi2
3274 if(theta1 == theta2 .and. phi1 == phi2)
then 3279 dot = cos(phi1)*cos(phi2)*cos(theta1-theta2) + sin(phi1)*sin(phi2)
3280 if(dot > 1. ) dot = 1.
3281 if(dot < -1.) dot = -1.
3305 & bitmap_in,num_out, lon_out,lat_out, iindx, jindx )
3306 integer,
intent(in) :: im_in, jm_in, num_out
3307 real,
intent(in) :: geolon_in(im_in,jm_in)
3308 real,
intent(in) :: geolat_in(im_in,jm_in)
3309 logical*1,
intent(in) :: bitmap_in(im_in,jm_in)
3310 real,
intent(in) :: lon_out(num_out), lat_out(num_out)
3311 integer,
intent(out):: iindx(num_out), jindx(num_out)
3312 real,
parameter :: MAX_DIST = 1.e+20
3313 integer,
parameter :: NUMNBR = 20
3314 integer :: i_c,j_c,jstart,jend
3317 print*,
"im_in,jm_in = ", im_in, jm_in
3318 print*,
"num_out = ", num_out
3319 print*,
"max and min of lon_in is", minval(geolon_in),
3321 print*,
"max and min of lat_in is", minval(geolat_in),
3323 print*,
"max and min of lon_out is", minval(lon_out),
3325 print*,
"max and min of lat_out is", minval(lat_out),
3327 print*,
"count(bitmap_in)= ", count(bitmap_in), max_dist
3336 if(lat .LE. geolat_in(1,j) .and.
3337 & lat .GE. geolat_in(1,j+1))
then 3341 if(lat > geolat_in(1,1)) j_c = 1
3342 if(lat < geolat_in(1,jm_in)) j_c = jm_in
3345 jstart = max(j_c-numnbr,1)
3346 jend = min(j_c+numnbr,jm_in)
3351 do j = jstart, jend;
do i = 1,im_in
3352 if(bitmap_in(i,j) )
then 3355 & geolon_in(i,j), geolat_in(i,j))
3357 iindx(n) = i; jindx(n) = j
3362 if(iindx(n) ==0)
then 3363 print*,
"lon,lat=", lon,lat
3364 print*,
"jstart, jend=", jstart, jend, dist
3365 print*,
"FATAL ERROR in get mismatch_index: " 3366 print*,
"did not find nearest points." 3387 & num_out, data_out, iindx, jindx)
3388 integer,
intent(in) :: im_in, jm_in, num_out
3389 real,
intent(in) :: data_in(im_in,jm_in)
3390 real,
intent(out):: data_out(num_out)
3391 integer,
intent(in) :: iindx(num_out), jindx(num_out)
3394 data_out(n) = data_in(iindx(n),jindx(n))
3440 SUBROUTINE makeoa3(ZAVG,VAR,GLAT,OA4,OL,IOA4,ELVMAX,
3441 1 ORO,SLM,oro1,XNSUM,XNSUM1,XNSUM2,XNSUM3,XNSUM4,
3442 2 IM,JM,IMN,JMN,lon_c,lat_c,lon_t,lat_t,
3443 3 IMI,JMI,OA_IN,OL_IN,
3444 4 slm_in,lon_in,lat_in)
3452 real,
parameter :: MISSING_VALUE = -9999.
3453 real,
parameter :: d2r = 3.14159265358979/180.
3454 real,
PARAMETER :: R2D=180./3.14159265358979
3455 integer im,jm,imn,jmn,imi,jmi
3457 INTEGER ZAVG(IMN,JMN)
3459 real ORO(IM,JM),ORO1(IM,JM),ELVMAX(IM,JM),ZMAX(IM,JM)
3461 integer IOA4(IM,JM,4)
3462 real OA_IN(IMI,JMI,4), OL_IN(IMI,JMI,4)
3463 real slm_in(IMI,JMI)
3464 real lon_in(IMI,JMI), lat_in(IMI,JMI)
3465 real lon_c(IM+1,JM+1), lat_c(IM+1,JM+1)
3466 real lon_t(IM,JM), lat_t(IM,JM)
3467 real XNSUM(IM,JM),XNSUM1(IM,JM),XNSUM2(IM,JM)
3468 real XNSUM3(IM,JM),XNSUM4(IM,JM)
3469 real VAR(IM,JM),OL(IM,JM,4)
3470 integer i,j,ilist(IMN),numx,i1,j1,ii1
3472 real LONO(4),LATO(4),LONI,LATI
3473 real DELXN,HC,HEIGHT,T
3474 integer NS0,NS1,NS2,NS3,NS4,NS5,NS6
3475 logical inside_a_polygon
3477 integer int_opt, ipopt(20), kgds_input(200), kgds_output(200)
3478 integer count_land_output
3479 integer ij, ijmdl_output, iret, num_mismatch_land, num
3480 integer ibo(1), ibi(1)
3481 logical*1,
allocatable :: bitmap_input(:,:)
3482 logical*1,
allocatable :: bitmap_output(:,:)
3483 integer,
allocatable :: ijsav_land_output(:)
3484 real,
allocatable :: lats_land_output(:)
3485 real,
allocatable :: lons_land_output(:)
3486 real,
allocatable :: output_data_land(:,:)
3487 real,
allocatable :: lons_mismatch_output(:)
3488 real,
allocatable :: lats_mismatch_output(:)
3489 real,
allocatable :: data_mismatch_output(:)
3490 integer,
allocatable :: iindx(:), jindx(:)
3496 ijmdl_output = im*jm
3499 glat(j) = -90. + (j-1) * delxn + delxn * 0.5
3501 print *,
' IM=',im,
' JM=',jm,
' IMN=',imn,
' JMN=',jmn
3509 elvmax(i,j) = oro(i,j)
3517 oro1(i,j) = oro(i,j)
3518 elvmax(i,j) = zmax(i,j)
3527 hc = 1116.2 - 0.878 * var(i,j)
3528 lono(1) = lon_c(i,j)
3529 lono(2) = lon_c(i+1,j)
3530 lono(3) = lon_c(i+1,j+1)
3531 lono(4) = lon_c(i,j+1)
3532 lato(1) = lat_c(i,j)
3533 lato(2) = lat_c(i+1,j)
3534 lato(3) = lat_c(i+1,j+1)
3535 lato(4) = lat_c(i,j+1)
3536 call get_index(imn,jmn,4,lono,lato,delxn,jst,jen,ilist,numx)
3537 do j1 = jst, jen;
do ii1 = 1, numx
3540 lati = -90 + j1*delxn
3541 if(inside_a_polygon(loni*d2r,lati*d2r,4,
3542 & lono*d2r,lato*d2r))
then 3544 height = float(zavg(i1,j1))
3545 IF(height.LT.-990.) height = 0.0
3546 IF ( height .gt. oro(i,j) )
then 3547 if ( height .gt. zmax(i,j) )zmax(i,j) = height
3560 oro1(i,j) = oro(i,j)
3561 elvmax(i,j) = zmax(i,j)
3581 kgds_input(4) = 90000
3584 kgds_input(7) = -90000
3585 kgds_input(8) = nint(-360000./imi)
3586 kgds_input(9) = nint((360.0 / float(imi))*1000.0)
3588 kgds_input(10) = jmi /2
3589 kgds_input(12) = 255
3590 kgds_input(20) = 255
3597 kgds_output(4) = 90000
3599 kgds_output(6) = 128
3600 kgds_output(7) = -90000
3601 kgds_output(8) = nint(-360000./im)
3602 kgds_output(9) = nint((360.0 / float(im))*1000.0)
3604 kgds_output(10) = jm /2
3605 kgds_output(12) = 255
3606 kgds_output(20) = 255
3609 print*,
"sum(slm) = ", sum(slm)
3610 do ij = 1, ijmdl_output
3612 i = mod(ij-1,im) + 1
3613 if (slm(i,j) > 0.0)
then 3614 count_land_output=count_land_output+1
3617 allocate(bitmap_input(imi,jmi))
3618 bitmap_input=.false.
3619 print*,
"number of land input=", sum(slm_in)
3620 where(slm_in > 0.0) bitmap_input=.true.
3621 print*,
"count(bitmap_input)", count(bitmap_input)
3623 allocate(bitmap_output(count_land_output,1))
3624 allocate(output_data_land(count_land_output,1))
3625 allocate(ijsav_land_output(count_land_output))
3626 allocate(lats_land_output(count_land_output))
3627 allocate(lons_land_output(count_land_output))
3632 do ij = 1, ijmdl_output
3634 i = mod(ij-1,im) + 1
3635 if (slm(i,j) > 0.0)
then 3636 count_land_output=count_land_output+1
3637 ijsav_land_output(count_land_output)=ij
3638 lats_land_output(count_land_output)=lat_t(i,j)
3639 lons_land_output(count_land_output)=lon_t(i,j)
3648 bitmap_output = .false.
3649 output_data_land = 0.0
3650 call ipolates(int_opt, ipopt, kgds_input, kgds_output,
3651 & (imi*jmi), count_land_output,
3652 & 1, ibi, bitmap_input, oa_in(:,:,kwd),
3653 & count_land_output, lats_land_output,
3654 & lons_land_output, ibo,
3655 & bitmap_output, output_data_land, iret)
3657 print*,
'- FATAL ERROR IN IPOLATES ',iret
3661 num_mismatch_land = 0
3662 do ij = 1, count_land_output
3663 if (bitmap_output(ij,1))
then 3664 j = (ijsav_land_output(ij)-1)/im + 1
3665 i = mod(ijsav_land_output(ij)-1,im) + 1
3666 oa4(i,j,kwd)=output_data_land(ij,1)
3668 num_mismatch_land = num_mismatch_land + 1
3671 print*,
"num_mismatch_land = ", num_mismatch_land
3673 if(.not.
allocated(data_mismatch_output))
then 3674 allocate(lons_mismatch_output(num_mismatch_land))
3675 allocate(lats_mismatch_output(num_mismatch_land))
3676 allocate(data_mismatch_output(num_mismatch_land))
3677 allocate(iindx(num_mismatch_land))
3678 allocate(jindx(num_mismatch_land))
3681 do ij = 1, count_land_output
3682 if (.not. bitmap_output(ij,1))
then 3684 lons_mismatch_output(num) = lons_land_output(ij)
3685 lats_mismatch_output(num) = lats_land_output(ij)
3691 print*,
"before get_mismatch_index", count(bitmap_input)
3693 & lat_in*d2r,bitmap_input,num_mismatch_land,
3694 & lons_mismatch_output*d2r,lats_mismatch_output*d2r,
3698 data_mismatch_output = 0
3700 & num_mismatch_land,data_mismatch_output,iindx,jindx)
3703 do ij = 1, count_land_output
3704 if (.not. bitmap_output(ij,1))
then 3706 j = (ijsav_land_output(ij)-1)/im + 1
3707 i = mod(ijsav_land_output(ij)-1,im) + 1
3708 oa4(i,j,kwd) = data_mismatch_output(num)
3709 if(i==372 .and. j== 611)
then 3710 print*,
"ij=",ij, num, oa4(i,j,kwd),iindx(num),jindx(num)
3720 bitmap_output = .false.
3721 output_data_land = 0.0
3722 call ipolates(int_opt, ipopt, kgds_input, kgds_output,
3723 & (imi*jmi), count_land_output,
3724 & 1, ibi, bitmap_input, ol_in(:,:,kwd),
3725 & count_land_output, lats_land_output,
3726 & lons_land_output, ibo,
3727 & bitmap_output, output_data_land, iret)
3729 print*,
'- FATAL ERROR IN IPOLATES ',iret
3733 num_mismatch_land = 0
3734 do ij = 1, count_land_output
3735 if (bitmap_output(ij,1))
then 3736 j = (ijsav_land_output(ij)-1)/im + 1
3737 i = mod(ijsav_land_output(ij)-1,im) + 1
3738 ol(i,j,kwd)=output_data_land(ij,1)
3740 num_mismatch_land = num_mismatch_land + 1
3743 print*,
"num_mismatch_land = ", num_mismatch_land
3745 data_mismatch_output = 0
3747 & num_mismatch_land,data_mismatch_output,iindx,jindx)
3750 do ij = 1, count_land_output
3751 if (.not. bitmap_output(ij,1))
then 3753 j = (ijsav_land_output(ij)-1)/im + 1
3754 i = mod(ijsav_land_output(ij)-1,im) + 1
3755 ol(i,j,kwd) = data_mismatch_output(num)
3756 if(i==372 .and. j== 611)
then 3757 print*,
"ij=",ij, num, ol(i,j,kwd),iindx(num),jindx(num)
3765 deallocate(lons_mismatch_output,lats_mismatch_output)
3766 deallocate(data_mismatch_output,iindx,jindx)
3767 deallocate(bitmap_output,output_data_land)
3768 deallocate(ijsav_land_output,lats_land_output)
3769 deallocate(lons_land_output)
3775 oa4(i,j,kwd) = sign( min( abs(t), 1. ), t )
3790 t = abs( oa4(i,j,kwd) )
3794 ELSE IF(t .GT. 0. .AND. t .LE. 1.)
THEN 3797 ELSE IF(t .GT. 1. .AND. t .LE. 10.)
THEN 3800 ELSE IF(t .GT. 10. .AND. t .LE. 100.)
THEN 3803 ELSE IF(t .GT. 100. .AND. t .LE. 1000.)
THEN 3806 ELSE IF(t .GT. 1000. .AND. t .LE. 10000.)
THEN 3809 ELSE IF(t .GT. 10000.)
THEN 3817 WRITE(6,*)
"! MAKEOA3 EXIT" 3830 SUBROUTINE minmxj(IM,JM,A,title)
3833 real A(IM,JM),rmin,rmax
3844 if(a(i,j).ge.rmax)rmax=a(i,j)
3845 if(a(i,j).le.rmin)rmin=a(i,j)
3848 write(6,150)rmin,rmax,title
3849 150
format(
'rmin=',e13.4,2x,
'rmax=',e13.4,2x,a8,
' ')
3865 SUBROUTINE mnmxja(IM,JM,A,imax,jmax,title)
3868 real A(IM,JM),rmin,rmax
3869 integer i,j,IM,JM,imax,jmax
3879 if(a(i,j).ge.rmax)
then 3884 if(a(i,j).le.rmin)rmin=a(i,j)
3887 write(6,150)rmin,rmax,title
3888 150
format(
'rmin=',e13.4,2x,
'rmax=',e13.4,2x,a8,
' ')
3900 include
'netcdf.inc' 3902 integer*2,
intent(out) :: glob(360*120,180*120)
3904 integer :: ncid, error, id_var, fsize
3908 error=nf__open(
"./topography.gmted2010.30s.nc",
3909 & nf_nowrite,fsize,ncid)
3910 call netcdf_err(error,
'Open file topography.gmted2010.30s.nc' )
3911 error=nf_inq_varid(ncid,
'topo', id_var)
3912 call netcdf_err(error,
'Inquire varid of topo')
3913 error=nf_get_var_int2(ncid, id_var, glob)
3915 error = nf_close(ncid)
3918 call maxmin (glob,360*120*180*120,
'global0')
3930 subroutine maxmin(ia,len,tile)
3936 integer iaamax, iaamin, len, m, ja, kount
3937 integer(8) sum2,std,mean,isum
3938 integer i_count_notset,kount_9
3953 if ( ja .eq. -9999 )
then 3957 if ( ja .eq. -12345 ) i_count_notset=i_count_notset+1
3959 iaamax = max0( iaamax, ja )
3960 iaamin = min0( iaamin, ja )
3971 std = ifix(sqrt(float((sum2/(kount))-mean**2)))
3972 print*,tile,
' max=',iaamax,
' min=',iaamin,
' sum=',isum,
3973 &
' i_count_notset=',i_count_notset
3974 print*,tile,
' mean=',mean,
' std.dev=',std,
3975 &
' ko9s=',kount,kount_9,kount+kount_9
3988 SUBROUTINE minmaxj(IM,JM,A,title)
3991 real(kind=4) A(IM,JM),rmin,rmax,undef
3992 integer i,j,IM,JM,imax,jmax,imin,jmin,iundef
3993 character*8 title,chara
4009 if(a(i,j).ge.rmax)
then 4014 if(a(i,j).le.rmin)
then 4015 if ( a(i,j) .eq. undef )
then 4025 write(6,150)chara,rmin,imin,jmin,rmax,imax,jmax,iundef
4026 150
format(1x,a8,2x,
'rmin=',e13.4,2i6,2x,
'rmax=',e13.4,3i6)
4042 integer,
intent(in) :: siz
4043 real,
intent(in) :: lon(siz), lat(siz)
4044 real,
intent(out) :: x(siz), y(siz), z(siz)
4049 x(n) = cos(lat(n))*cos(lon(n))
4050 y(n) = cos(lat(n))*sin(lon(n))
4064 real,
parameter :: epsln30 = 1.e-30
4065 real,
parameter :: pi=3.1415926535897931
4066 real v1(3), v2(3), v3(3)
4069 real px, py, pz, qx, qy, qz, ddd;
4072 px = v1(2)*v2(3) - v1(3)*v2(2)
4073 py = v1(3)*v2(1) - v1(1)*v2(3)
4074 pz = v1(1)*v2(2) - v1(2)*v2(1)
4076 qx = v1(2)*v3(3) - v1(3)*v3(2);
4077 qy = v1(3)*v3(1) - v1(1)*v3(3);
4078 qz = v1(1)*v3(2) - v1(2)*v3(1);
4080 ddd = (px*px+py*py+pz*pz)*(qx*qx+qy*qy+qz*qz);
4081 if ( ddd <= 0.0 )
then 4084 ddd = (px*qx+py*qy+pz*qz) / sqrt(ddd);
4085 if( abs(ddd-1) < epsln30 ) ddd = 1;
4086 if( abs(ddd+1) < epsln30 ) ddd = -1;
4087 if ( ddd>1. .or. ddd<-1. )
then 4114 real,
parameter :: epsln10 = 1.e-10
4115 real,
parameter :: epsln8 = 1.e-8
4116 real,
parameter :: pi=3.1415926535897931
4117 real,
parameter :: range_check_criteria=0.05
4122 real lon2(npts), lat2(npts)
4123 real x2(npts), y2(npts), z2(npts)
4124 real lon1_1d(1), lat1_1d(1)
4125 real x1(1), y1(1), z1(1)
4126 real pnt0(3),pnt1(3),pnt2(3)
4128 real max_x2,min_x2,max_y2,min_y2,max_z2,min_z2
4130 call latlon2xyz(npts,lon2, lat2, x2, y2, z2);
4133 call latlon2xyz(1,lon1_1d, lat1_1d, x1, y1, z1);
4136 if( x1(1) > max_x2+range_check_criteria )
return 4138 if( x1(1)+range_check_criteria < min_x2 )
return 4140 if( y1(1) > max_y2+range_check_criteria )
return 4142 if( y1(1)+range_check_criteria < min_y2 )
return 4144 if( z1(1) > max_z2+range_check_criteria )
return 4146 if( z1(1)+range_check_criteria < min_z2 )
return 4154 if(abs(x1(1)-x2(i)) < epsln10 .and.
4155 & abs(y1(1)-y2(i)) < epsln10 .and.
4156 & abs(z1(1)-z2(i)) < epsln10 )
then 4161 if(ip1>npts) ip1 = 1
4171 anglesum = anglesum + angle
4174 if(abs(anglesum-2*pi) < epsln8)
then 4207 function get_xnsum(lon1,lat1,lon2,lat2,IMN,JMN,
4208 & glat,zavg,zslm,delxn)
4212 real,
intent(in) :: lon1,lat1,lon2,lat2,delxn
4213 integer,
intent(in) :: imn,jmn
4214 real,
intent(in) :: glat(jmn)
4215 integer,
intent(in) :: zavg(imn,jmn),zslm(imn,jmn)
4216 integer i, j, ist, ien, jst, jen, i1
4218 real xland,xwatr,xl1,xs1,slm,xnsum
4221 if( glat(j) .GT. lat1 )
then 4227 if( glat(j) .GT. lat2 )
then 4234 ist = lon1/delxn + 1
4236 if(ist .le.0) ist = ist + imn
4237 if(ien < ist) ien = ien + imn
4247 do i1 = 1, ien - ist + 1
4249 if( i .LE. 0) i = i + imn
4250 if( i .GT. imn) i = i - imn
4251 xland = xland + float(zslm(i,j))
4252 xwatr = xwatr + float(1-zslm(i,j))
4254 height = float(zavg(i,j))
4255 IF(height.LT.-990.) height = 0.0
4256 xl1 = xl1 + height * float(zslm(i,j))
4257 xs1 = xs1 + height * float(1-zslm(i,j))
4260 if( xnsum > 1.)
THEN 4261 slm = float(nint(xland/xnsum))
4273 if( i .LE. 0) i = i + imn
4274 if( i .GT. imn) i = i - imn
4275 height = float(zavg(i,j))
4276 IF(height.LT.-990.) height = 0.0
4310 subroutine get_xnsum2(lon1,lat1,lon2,lat2,IMN,JMN,
4311 & glat,zavg,delxn,xnsum1,xnsum2,HC)
4314 real,
intent(out) :: xnsum1,xnsum2,HC
4315 real lon1,lat1,lon2,lat2,delxn
4318 integer zavg(IMN,JMN)
4319 integer i, j, ist, ien, jst, jen, i1
4324 if( glat(j) .GT. lat1 )
then 4330 if( glat(j) .GT. lat2 )
then 4337 ist = lon1/delxn + 1
4339 if(ist .le.0) ist = ist + imn
4340 if(ien < ist) ien = ien + imn
4347 do i1 = 1, ien - ist + 1
4349 if( i .LE. 0) i = i + imn
4350 if( i .GT. imn) i = i - imn
4352 height = float(zavg(i,j))
4353 IF(height.LT.-990.) height = 0.0
4355 xw2 = xw2 + height ** 2
4358 var = sqrt(max(xw2/xnsum-(xw1/xnsum)**2,0.))
4359 hc = 1116.2 - 0.878 * var
4365 if( i .LE. 0) i = i + imn
4366 if( i .GT. imn) i = i - imn
4367 height = float(zavg(i,j))
4368 IF ( height .gt. hc ) xnsum1 = xnsum1 + 1
4403 subroutine get_xnsum3(lon1,lat1,lon2,lat2,IMN,JMN,
4404 & glat,zavg,delxn,xnsum1,xnsum2,HC)
4407 real,
intent(out) :: xnsum1,xnsum2
4408 real lon1,lat1,lon2,lat2,delxn
4411 integer zavg(IMN,JMN)
4412 integer i, j, ist, ien, jst, jen, i1
4419 if( glat(j) .GT. lat1 )
then 4425 if( glat(j) .GT. lat2 )
then 4432 ist = lon1/delxn + 1
4434 if(ist .le.0) ist = ist + imn
4435 if(ien < ist) ien = ien + imn
4442 if( i .LE. 0) i = i + imn
4443 if( i .GT. imn) i = i - imn
4444 height = float(zavg(i,j))
4445 IF ( height .gt. hc ) xnsum1 = xnsum1 + 1
4455 real function timef()
4456 character(8) :: date
4457 character(10) :: time
4458 character(5) :: zone
4459 integer,
dimension(8) :: values
4462 call date_and_time(date,time,zone,values)
4463 total=(3600*values(5))+(60*values(6))
4465 elapsed=float(total) + (1.0e-3*float(values(8)))
subroutine write_mask_netcdf(im, jm, slm, land_frac, ntiles, tile, geolon, geolat)
Write the land mask file.
subroutine read_mask(merge_file, slm, land_frac, lake_frac, im, jm)
Read the land mask file.
subroutine makemt(ZAVG, ZSLM, ORO, SLM, VAR, VAR4, GLAT, IST, IEN, JST, JEN, IM, JM, IMN, JMN, XLAT, numi)
Create the orography, land-mask, standard deviation of orography and the convexity on a model gaussia...
subroutine get_index(IMN, JMN, npts, lonO, latO, DELXN, jst, jen, ilist, numx)
Determine the location of a cubed-sphere point within the high-resolution orography data...
real function timef()
Get the date/time for the system clock.
subroutine netcdf_err(err, string)
Check NetCDF error code and output the error message.
real function get_lat_angle(dy, DEGRAD)
Convert the 'y' direction distance of a cubed-sphere grid point to the corresponding distance in lati...
subroutine mnmxja(IM, JM, A, imax, jmax, title)
Print out the maximum and minimum values of an array.
subroutine makepc2(ZAVG, ZSLM, THETA, GAMMA, SIGMA, GLAT, IM, JM, IMN, JMN, lon_c, lat_c, SLM)
Make the principle coordinates - slope of orography, anisotropy, angle of mountain range with respect...
subroutine tersub(IMN, JMN, IM, JM, NM, NR, NF0, NF1, NW, EFAC, OUTGRID, INPUTOROG, MASK_ONLY, MERGE_FILE)
Driver routine to compute terrain.
real function spherical_angle(v1, v2, v3)
Compute spherical angle.
subroutine minmaxj(IM, JM, A, title)
Print out the maximum and minimum values of an array and their i/j location.
program lake_frac
This program computes lake fraction and depth numbers for FV3 cubed sphere grid cells, from a high resolution lat/lon data set.
subroutine write_netcdf(im, jm, slm, land_frac, oro, orf, hprime, ntiles, tile, geolon, geolat, lon, lat)
Write out orography file in netcdf format.
subroutine makepc(ZAVG, ZSLM, THETA, GAMMA, SIGMA, GLAT, IST, IEN, JST, JEN, IM, JM, IMN, JMN, XLAT, numi)
Make the principle coordinates - slope of orography, anisotropy, angle of mountain range with respect...
subroutine get_xnsum3(lon1, lat1, lon2, lat2, IMN, JMN, glat, zavg, delxn, xnsum1, xnsum2, HC)
Count the number of high-resolution orography points that are higher than a critical value inside a m...
logical function inside_a_polygon(lon1, lat1, npts, lon2, lat2)
Check if a point is inside a polygon.
real function spherical_distance(theta1, phi1, theta2, phi2)
Compute a great circle distance between two points.
subroutine makeoa3(ZAVG, VAR, GLAT, OA4, OL, IOA4, ELVMAX, ORO, SLM, oro1, XNSUM, XNSUM1, XNSUM2, XNSUM3, XNSUM4, IM, JM, IMN, JMN, lon_c, lat_c, lon_t, lat_t, IMI, JMI, OA_IN, OL_IN, slm_in, lon_in, lat_in)
Create orographic asymmetry and orographic length scale on the model grid.
subroutine get_mismatch_index(im_in, jm_in, geolon_in, geolat_in, bitmap_in, num_out, lon_out, lat_out, iindx, jindx)
For unmapped land points, find the nearest land point on the input data and pass back its i/j index...
subroutine make_mask(zslm, SLM, land_frac, GLAT, IM, JM, IMN, JMN, lon_c, lat_c)
Create the land-mask, land fraction.
subroutine maxmin(ia, len, tile)
Print the maximum, mininum, mean and standard deviation of an array.
subroutine makemt2(ZAVG, ZSLM, ORO, SLM, VAR, VAR4, GLAT, IM, JM, IMN, JMN, lon_c, lat_c, lake_frac, land_frac)
Create the orography, land-mask, land fraction, standard deviation of orography and the convexity on ...
subroutine interpolate_mismatch(im_in, jm_in, data_in, num_out, data_out, iindx, jindx)
Replace unmapped model land points with the nearest land point on the input grid. ...
real function get_lon_angle(dx, lat, DEGRAD)
Convert the 'x' direction distance of a cubed-sphere grid point to the corresponding distance in long...
subroutine get_xnsum2(lon1, lat1, lon2, lat2, IMN, JMN, glat, zavg, delxn, xnsum1, xnsum2, HC)
Count the number of high-resolution orography points that are higher than a critical value inside a m...
subroutine makeoa2(ZAVG, zslm, VAR, GLAT, OA4, OL, IOA4, ELVMAX, ORO, oro1, XNSUM, XNSUM1, XNSUM2, XNSUM3, XNSUM4, IM, JM, IMN, JMN, lon_c, lat_c, lon_t, lat_t, dx, dy, is_south_pole, is_north_pole)
Create orographic asymmetry and orographic length scale on the model grid.
subroutine latlon2xyz(siz, lon, lat, x, y, z)
Convert from latitude and longitude to x,y,z coordinates.
subroutine minmxj(IM, JM, A, title)
Print out the maximum and minimum values of an array.
subroutine makeoa(ZAVG, VAR, GLAT, OA4, OL, IOA4, ELVMAX, ORO, oro1, XNSUM, XNSUM1, XNSUM2, XNSUM3, XNSUM4, IST, IEN, JST, JEN, IM, JM, IMN, JMN, XLAT, numi)
Create orographic asymmetry and orographic length scale on the model grid.
real function get_xnsum(lon1, lat1, lon2, lat2, IMN, JMN, glat, zavg, zslm, delxn)
Count the number of high-resolution orography points that are higher than the model grid box average ...
subroutine read_g(glob)
Read input global 30-arc second orography data.