26 SUBROUTINE calvor(UWND,VWND,ABSV)
31 use masks, only: gdlat, gdlon, dx, dy
33 use ctlblk_mod
, only: jsta_2l, jend_2u, spval, modelname, global, &
34 jsta, jend, im, jm, jsta_m, jend_m, gdsdegr
35 use gridspec_mod
, only: gridtype, dyval
36 use upp_math, only: dvdxdudy, ddvdx, ddudy, uuavg
42 REAL,
dimension(im,jsta_2l:jend_2u),
intent(in) :: uwnd, vwnd
43 REAL,
dimension(im,jsta_2l:jend_2u),
intent(inout) :: absv
45 real,
allocatable :: wrk1(:,:), wrk2(:,:), wrk3(:,:), cosl(:,:)
46 INTEGER,
allocatable :: ihe(:),ihw(:), ie(:),iw(:)
48 integer,
parameter :: npass2=2, npass3=3
49 integer i,j,ip1,im1,ii,iir,iil,jj,jmt2,imb2, npass, nn, jtem
50 real r2dx,r2dy,dvdx,dudy,uavg,tph1,tphi, tx1(im+2), tx2(im+2)
57 IF(modelname ==
'RAPR')
then
77 IF (modelname ==
'GFS' .or. global)
THEN
78 CALL exch(gdlat(1,jsta_2l))
80 allocate (wrk1(im,jsta:jend), wrk2(im,jsta:jend), &
81 & wrk3(im,jsta:jend), cosl(im,jsta_2l:jend_2u))
82 allocate(iw(im),ie(im))
103 cosl(i,j) = cos(gdlat(i,j)*dtr)
104 IF(cosl(i,j) >= small)
then
105 wrk1(i,j) = 1.0 / (erad*cosl(i,j))
109 if(i == im .or. i == 1)
then
110 wrk2(i,j) = 1.0 / ((360.+gdlon(ip1,j)-gdlon(im1,j))*dtr)
112 wrk2(i,j) = 1.0 / ((gdlon(ip1,j)-gdlon(im1,j))*dtr)
122 if(gdlat(1,j) > 0.)
then
125 if (ii > im) ii = ii - im
126 wrk3(i,j) = 1.0 / ((180.-gdlat(i,j+1)-gdlat(ii,j))*dtr)
131 if (ii > im) ii = ii - im
132 wrk3(i,j) = 1.0 / ((180.+gdlat(i,j+1)+gdlat(ii,j))*dtr)
136 elseif (j == jm)
then
137 if(gdlat(1,j) < 0.)
then
140 if (ii > im) ii = ii - im
141 wrk3(i,j) = 1.0 / ((180.+gdlat(i,j-1)+gdlat(ii,j))*dtr)
146 if (ii > im) ii = ii - im
147 wrk3(i,j) = 1.0 / ((180.-gdlat(i,j-1)-gdlat(ii,j))*dtr)
152 wrk3(i,j) = 1.0 / ((gdlat(i,j-1)-gdlat(i,j+1))*dtr)
165 if(gdlat(1,j) > 0.)
then
166 IF(cosl(1,j) >= small)
THEN
171 if (ii > im) ii = ii - im
172 if(vwnd(ip1,j)==spval .or. vwnd(im1,j)==spval .or. &
173 uwnd(ii,j)==spval .or. uwnd(i,j+1)==spval) cycle
174 absv(i,j) = ((vwnd(ip1,j)-vwnd(im1,j))*wrk2(i,j) &
175 & + (uwnd(ii,j)*cosl(ii,j) &
176 & + uwnd(i,j+1)*cosl(i,j+1))*wrk3(i,j)) * wrk1(i,j) &
184 if(vwnd(ip1,jj)==spval .or. vwnd(im1,jj)==spval .or. &
185 uwnd(i,j)==spval .or. uwnd(i,jj+1)==spval) cycle
186 absv(i,j) = ((vwnd(ip1,jj)-vwnd(im1,jj))*wrk2(i,jj) &
187 & - (uwnd(i,j)*cosl(i,j) &
188 - uwnd(i,jj+1)*cosl(i,jj+1))*wrk3(i,jj)) * wrk1(i,jj) &
193 IF(cosl(1,j) >= small)
THEN
198 if (ii > im) ii = ii - im
199 if(vwnd(ip1,j)==spval .or. vwnd(im1,j)==spval .or. &
200 uwnd(ii,j)==spval .or. uwnd(i,j+1)==spval) cycle
201 absv(i,j) = ((vwnd(ip1,j)-vwnd(im1,j))*wrk2(i,j) &
202 & - (uwnd(ii,j)*cosl(ii,j) &
203 & + uwnd(i,j+1)*cosl(i,j+1))*wrk3(i,j)) * wrk1(i,j) &
211 if(vwnd(ip1,jj)==spval .or. vwnd(im1,jj)==spval .or. &
212 uwnd(i,j)==spval .or. uwnd(i,jj+1)==spval) cycle
213 absv(i,j) = ((vwnd(ip1,jj)-vwnd(im1,jj))*wrk2(i,jj) &
214 & + (uwnd(i,j)*cosl(i,j) &
215 - uwnd(i,jj+1)*cosl(i,jj+1))*wrk3(i,jj)) * wrk1(i,jj) &
220 ELSE IF(j == jm)
THEN
221 if(gdlat(1,j) < 0.)
then
222 IF(cosl(1,j) >= small)
THEN
227 if (ii > im) ii = ii - im
228 if(vwnd(ip1,j)==spval .or. vwnd(im1,j)==spval .or. &
229 uwnd(i,j-1)==spval .or. uwnd(ii,j)==spval) cycle
230 absv(i,j) = ((vwnd(ip1,j)-vwnd(im1,j))*wrk2(i,j) &
231 & - (uwnd(i,j-1)*cosl(i,j-1) &
232 & + uwnd(ii,j)*cosl(ii,j))*wrk3(i,j)) * wrk1(i,j) &
240 if(vwnd(ip1,jj)==spval .or. vwnd(im1,jj)==spval .or. &
241 uwnd(i,jj-1)==spval .or. uwnd(i,j)==spval) cycle
242 absv(i,j) = ((vwnd(ip1,jj)-vwnd(im1,jj))*wrk2(i,jj) &
243 & - (uwnd(i,jj-1)*cosl(i,jj-1) &
244 & - uwnd(i,j)*cosl(i,j))*wrk3(i,jj)) * wrk1(i,jj) &
249 IF(cosl(1,j) >= small)
THEN
254 if (ii > im) ii = ii - im
255 if(vwnd(ip1,j)==spval .or. vwnd(im1,j)==spval .or. &
256 uwnd(i,j-1)==spval .or. uwnd(ii,j)==spval) cycle
257 absv(i,j) = ((vwnd(ip1,j)-vwnd(im1,j))*wrk2(i,j) &
258 & + (uwnd(i,j-1)*cosl(i,j-1) &
259 & + uwnd(ii,j)*cosl(ii,j))*wrk3(i,j)) * wrk1(i,j) &
267 if(vwnd(ip1,jj)==spval .or. vwnd(im1,jj)==spval .or. &
268 uwnd(i,jj-1)==spval .or. uwnd(i,j)==spval) cycle
269 absv(i,j) = ((vwnd(ip1,jj)-vwnd(im1,jj))*wrk2(i,jj) &
270 & + (uwnd(i,jj-1)*cosl(i,jj-1) &
271 & - uwnd(i,j)*cosl(i,j))*wrk3(i,jj)) * wrk1(i,jj) &
280 if(vwnd(ip1,j)==spval .or. vwnd(im1,j)==spval .or. &
281 uwnd(i,j-1)==spval .or. uwnd(i,j+1)==spval) cycle
282 absv(i,j) = ((vwnd(ip1,j)-vwnd(im1,j))*wrk2(i,j) &
283 & - (uwnd(i,j-1)*cosl(i,j-1) &
284 - uwnd(i,j+1)*cosl(i,j+1))*wrk3(i,j)) * wrk1(i,j) &
301 tx1(i-1) = 0.25 * (tx2(i-1) + tx2(i+1)) + 0.5*tx2(i)
313 call poleavg(im,jm,jsta,jend,small,cosl(1,jsta),spval,absv(1,jsta))
314 deallocate (wrk1, wrk2, wrk3, cosl, iw, ie)
318 IF (gridtype ==
'B')
THEN
322 CALL dvdxdudy(uwnd,vwnd)
324 IF(gridtype ==
'A')
THEN
328 tphi = (j-jmt2)*(dyval/gdsdegr)*dtr
330 IF(vwnd(i+1,j)<spval.AND.vwnd(i-1,j)<spval.AND. &
331 & uwnd(i,j+1)<spval.AND.uwnd(i,j-1)<spval)
THEN
336 IF(modelname ==
'RAPR')
then
337 absv(i,j) = dvdx - dudy + f(i,j)
339 absv(i,j) = dvdx - dudy + f(i,j) + uavg*tan(gdlat(i,j)*dtr)/erad
345 ELSE IF (gridtype ==
'E')
THEN
346 allocate(ihw(jsta_2l:jend_2u), ihe(jsta_2l:jend_2u))
355 tphi = (j-jmt2)*(dyval/1000.)*dtr
356 tphi = (j-jmt2)*(dyval/gdsdegr)*dtr
358 IF(vwnd(i+ihe(j),j) < spval.AND.vwnd(i+ihw(j),j) < spval .AND. &
359 & uwnd(i,j+1) < spval .AND.uwnd(i,j-1) < spval)
THEN
364 absv(i,j) = dvdx - dudy + f(i,j) + uavg*tan(tphi)/erad
369 ELSE IF (gridtype ==
'B')
THEN
373 tphi = (j-jmt2)*(dyval/gdsdegr)*dtr
375 if(vwnd(i, j)==spval .or. vwnd(i, j-1)==spval .or. &
376 vwnd(i-1,j)==spval .or. vwnd(i-1,j-1)==spval .or. &
377 uwnd(i, j)==spval .or. uwnd(i-1,j)==spval .or. &
378 uwnd(i,j-1)==spval .or. uwnd(i-1,j-1)==spval) cycle
383 absv(i,j) = dvdx - dudy + f(i,j) + uavg*tan(tphi)/erad
410 SUBROUTINE caldiv(UWND,VWND,DIV)
411 use masks, only: gdlat, gdlon
413 use ctlblk_mod
, only: jsta_2l, jend_2u, spval, modelname, global, &
414 jsta, jend, im, jm, jsta_m, jend_m, lm
415 use gridspec_mod
, only: gridtype
421 REAL,
dimension(im,jsta_2l:jend_2u,lm),
intent(in) :: uwnd,vwnd
422 REAL,
dimension(im,jsta:jend,lm),
intent(inout) :: div
424 real,
allocatable :: wrk1(:,:), wrk2(:,:), wrk3(:,:), cosl(:,:)
425 INTEGER,
allocatable :: ihe(:),ihw(:), ie(:),iw(:)
427 real :: dnpole, dspole, tem
428 integer i,j,ip1,im1,ii,iir,iil,jj,imb2, l
435 CALL exch(gdlat(1,jsta_2l))
437 allocate (wrk1(im,jsta:jend), wrk2(im,jsta:jend), &
438 & wrk3(im,jsta:jend), cosl(im,jsta_2l:jend_2u))
439 allocate(iw(im),ie(im))
456 cosl(i,j) = cos(gdlat(i,j)*dtr)
457 IF(cosl(i,j) >= small)
then
458 wrk1(i,j) = 1.0 / (erad*cosl(i,j))
462 if(i == im .or. i == 1)
then
463 wrk2(i,j) = 1.0 / ((360.+gdlon(ip1,j)-gdlon(im1,j))*dtr)
465 wrk2(i,j) = 1.0 / ((gdlon(ip1,j)-gdlon(im1,j))*dtr)
475 if(gdlat(1,j) > 0.)
then
478 if (ii > im) ii = ii - im
479 wrk3(i,j) = 1.0 / ((180.-gdlat(i,j+1)-gdlat(ii,j))*dtr)
484 if (ii > im) ii = ii - im
485 wrk3(i,j) = 1.0 / ((180.+gdlat(i,j+1)+gdlat(ii,j))*dtr)
488 elseif (j == jm)
then
489 if(gdlat(1,j) < 0.)
then
492 if (ii > im) ii = ii - im
493 wrk3(i,j) = 1.0 / ((180.+gdlat(i,j-1)+gdlat(ii,j))*dtr)
498 if (ii > im) ii = ii - im
499 wrk3(i,j) = 1.0 / ((180.-gdlat(i,j-1)-gdlat(ii,j))*dtr)
504 wrk3(i,j) = 1.0 / ((gdlat(i,j-1)-gdlat(i,j+1))*dtr)
517 CALL
exch_f(vwnd(1,jsta_2l,l))
522 if(gdlat(1,j) > 0.)
then
523 IF(cosl(1,j) >= small)
THEN
528 if (ii > im) ii = ii - im
529 div(i,j,l) = ((uwnd(ip1,j,l)-uwnd(im1,j,l))*wrk2(i,j) &
530 & - (vwnd(ii,j,l)*cosl(ii,j) &
531 & + vwnd(i,j+1,l)*cosl(i,j+1))*wrk3(i,j)) * wrk1(i,j)
539 div(i,j,l) = ((uwnd(ip1,jj,l)-uwnd(im1,jj,l))*wrk2(i,jj) &
540 & + (vwnd(i,j,l)*cosl(i,j) &
541 - vwnd(i,jj+1,l)*cosl(i,jj+1))*wrk3(i,jj)) * wrk1(i,jj)
546 IF(cosl(1,j) >= small)
THEN
551 if (ii > im) ii = ii - im
552 div(i,j,l) = ((uwnd(ip1,j,l)-uwnd(im1,j,l))*wrk2(i,j) &
553 & + (vwnd(ii,j,l)*cosl(ii,j) &
554 & + vwnd(i,j+1,l)*cosl(i,j+1))*wrk3(i,j)) * wrk1(i,j)
562 div(i,j,l) = ((uwnd(ip1,jj,l)-uwnd(im1,jj,l))*wrk2(i,jj) &
563 & - (vwnd(i,j,l)*cosl(i,j) &
564 - vwnd(i,jj+1,l)*cosl(i,jj+1))*wrk3(i,jj)) * wrk1(i,jj)
568 ELSE IF(j == jm)
THEN
569 if(gdlat(1,j) < 0.)
then
570 IF(cosl(1,j) >= small)
THEN
575 if (ii > im) ii = ii - im
576 div(i,j,l) = ((uwnd(ip1,j,l)-uwnd(im1,j,l))*wrk2(i,j) &
577 & + (vwnd(i,j-1,l)*cosl(i,j-1) &
578 & + vwnd(ii,j,l)*cosl(ii,j))*wrk3(i,j)) * wrk1(i,j)
586 div(i,j,l) = ((uwnd(ip1,jj,l)-uwnd(im1,jj,l))*wrk2(i,jj) &
587 & + (vwnd(i,jj-1,l)*cosl(i,jj-1) &
588 & - vwnd(i,j,l)*cosl(i,j))*wrk3(i,jj)) * wrk1(i,jj)
593 IF(cosl(1,j) >= small)
THEN
598 if (ii > im) ii = ii - im
599 div(i,j,l) = ((uwnd(ip1,j,l)-uwnd(im1,j,l))*wrk2(i,j) &
600 & - (vwnd(i,j-1,l)*cosl(i,j-1) &
601 & + vwnd(ii,j,l)*cosl(ii,j))*wrk3(i,j)) * wrk1(i,j)
609 div(i,j,l) = ((uwnd(ip1,jj,l)-uwnd(im1,jj,l))*wrk2(i,jj) &
610 & - (vwnd(i,jj-1,l)*cosl(i,jj-1) &
611 & - vwnd(i,j,l)*cosl(i,j))*wrk3(i,jj)) * wrk1(i,jj)
620 div(i,j,l) = ((uwnd(ip1,j,l)-uwnd(im1,j,l))*wrk2(i,j) &
621 & + (vwnd(i,j-1,l)*cosl(i,j-1) &
622 - vwnd(i,j+1,l)*cosl(i,j+1))*wrk3(i,j)) * wrk1(i,j)
624 if(div(i,j,l)>1.0)print*,
'Debug in CALDIV',i,j,uwnd(ip1,j,l),uwnd(im1,j,l), &
625 & wrk2(i,j),vwnd(i,j-1,l),cosl(i,j-1),vwnd(i,j+1,l),cosl(i,j+1), &
626 & wrk3(i,j),wrk1(i,j),div(i,j,l)
633 call poleavg(im,jm,jsta,jend,small,cosl(1,jsta),spval,div(1,jsta,l))
635 if(div(1,jsta,l)>1.0)print*,
'Debug in CALDIV',jsta,div(1,jsta,l)
640 deallocate (wrk1, wrk2, wrk3, cosl, iw, ie)
643 END SUBROUTINE caldiv
645 SUBROUTINE calgradps(PS,PSX,PSY)
661 use masks, only: gdlat, gdlon
663 use ctlblk_mod
, only: jsta_2l, jend_2u, spval, modelname, global, &
664 jsta, jend, im, jm, jsta_m, jend_m
665 use gridspec_mod
, only: gridtype
671 REAL,
dimension(im,jsta_2l:jend_2u),
intent(in) :: ps
672 REAL,
dimension(im,jsta_2l:jend_2u),
intent(inout) :: psx,psy
674 real,
allocatable :: wrk1(:,:), wrk2(:,:), wrk3(:,:), cosl(:,:)
675 INTEGER,
allocatable :: ihe(:),ihw(:), ie(:),iw(:)
677 integer i,j,ip1,im1,ii,iir,iil,jj,imb2
698 CALL exch(gdlat(1,jsta_2l))
700 allocate (wrk1(im,jsta:jend), wrk2(im,jsta:jend), &
701 & wrk3(im,jsta:jend), cosl(im,jsta_2l:jend_2u))
702 allocate(iw(im),ie(im))
719 cosl(i,j) = cos(gdlat(i,j)*dtr)
720 if(cosl(i,j) >= small)
then
721 wrk1(i,j) = 1.0 / (erad*cosl(i,j))
725 if(i == im .or. i == 1)
then
726 wrk2(i,j) = 1.0 / ((360.+gdlon(ip1,j)-gdlon(im1,j))*dtr)
728 wrk2(i,j) = 1.0 / ((gdlon(ip1,j)-gdlon(im1,j))*dtr)
738 if(gdlat(1,j) > 0.)
then
741 if (ii > im) ii = ii - im
742 wrk3(i,j) = 1.0 / ((180.-gdlat(i,j+1)-gdlat(ii,j))*dtr)
747 if (ii > im) ii = ii - im
748 wrk3(i,j) = 1.0 / ((180.+gdlat(i,j+1)+gdlat(ii,j))*dtr)
751 elseif (j == jm)
then
752 if(gdlat(1,j) < 0.)
then
755 if (ii > im) ii = ii - im
756 wrk3(i,j) = 1.0 / ((180.+gdlat(i,j-1)+gdlat(ii,j))*dtr)
761 if (ii > im) ii = ii - im
762 wrk3(i,j) = 1.0 / ((180.-gdlat(i,j-1)-gdlat(ii,j))*dtr)
767 wrk3(i,j) = 1.0 / ((gdlat(i,j-1)-gdlat(i,j+1))*dtr)
775 if(gdlat(1,j) > 0.)
then
776 IF(cosl(1,j) >= small)
THEN
781 if (ii > im) ii = ii - im
782 psx(i,j) = (ps(ip1,j)-ps(im1,j))*wrk2(i,j)*wrk1(i,j)
783 psy(i,j) = (ps(ii,j)-ps(i,j+1))*wrk3(i,j)/erad
790 psx(i,j) = (ps(ip1,jj)-ps(im1,jj))*wrk2(i,jj)*wrk1(i,jj)
791 psy(i,j) = (ps(i,j)-ps(i,jj+1))*wrk3(i,jj)/erad
795 IF(cosl(1,j) >= small)
THEN
800 if (ii > im) ii = ii - im
801 psx(i,j) = (ps(ip1,j)-ps(im1,j))*wrk2(i,j)*wrk1(i,j)
802 psy(i,j) = - (ps(ii,j)-ps(i,j+1))*wrk3(i,j)/erad
809 psx(i,j) = (ps(ip1,jj)-ps(im1,jj))*wrk2(i,jj)*wrk1(i,jj)
810 psy(i,j) = - (ps(i,j)-ps(i,jj+1))*wrk3(i,jj)/erad
814 ELSE IF(j == jm)
THEN
815 if(gdlat(1,j) < 0.)
then
816 IF(cosl(1,j) >= small)
THEN
821 if (ii > im) ii = ii - im
822 psx(i,j) = (ps(ip1,j)-ps(im1,j))*wrk2(i,j)*wrk1(i,j)
823 psy(i,j) = (ps(i,j-1)-ps(ii,j))*wrk3(i,j)/erad
830 psx(i,j) = (ps(ip1,jj)-ps(im1,jj))*wrk2(i,jj)*wrk1(i,jj)
831 psy(i,j) = (ps(i,jj-1)-ps(i,j))*wrk3(i,jj)/erad
835 IF(cosl(1,j) >= small)
THEN
840 if (ii > im) ii = ii - im
841 psx(i,j) = (ps(ip1,j)-ps(im1,j))*wrk2(i,j)*wrk1(i,j)
842 psy(i,j) = - (ps(i,j-1)-ps(ii,j))*wrk3(i,j)/erad
849 psx(i,j) = (ps(ip1,jj)-ps(im1,jj))*wrk2(i,jj)*wrk1(i,jj)
850 psy(i,j) = - (ps(i,jj-1)-ps(i,j))*wrk3(i,jj)/erad
858 psx(i,j) = (ps(ip1,j)-ps(im1,j))*wrk2(i,j)*wrk1(i,j)
859 psy(i,j) = (ps(i,j-1)-ps(i,j+1))*wrk3(i,j)/erad
861 if(psx(i,j)>100.0)print*,
'Debug in CALGRADPS: PSX',i,j,ps(ip1,j),ps(im1,j), &
863 & wrk2(i,j),wrk1(i,j),psx(i,j)
864 if(psy(i,j)>100.0)print*,
'Debug in CALGRADPS: PSY',i,j,ps(i,j-1),ps(i,j+1), &
866 & wrk3(i,j),erad,psy(i,j)
873 deallocate (wrk1, wrk2, wrk3, cosl, iw, ie)
877 END SUBROUTINE calgradps
dvdxdudy() computes dudy, dvdx, uwnd