1 subroutine xytoll(rx,ry,lat,lon,stagger)
6 integer, intent(in) :: stagger
7 real, intent(in) :: rx, ry
8 real, intent(out) :: lat, lon
12 integer :: midcol,midrow,ncol,iadd1,iadd2,imt,jh2,knrow,krem,kv,nrow
13 real :: dphd,dlmd !Grid increments, degrees
14 real :: arg1,arg2,d2r,fctr,glatr,glatd,glond,pi, &
15 r2d,tlatd,tlond,tlatr,tlonr,tlm0,tph0
20 dphd = phi/real((jydim(current_nest_number)-1)/2)
21 dlmd = lambda/real(ixdim(current_nest_number)-1)
29 midrow = (jydim(current_nest_number)+1)/2
30 midcol = ixdim(current_nest_number)
32 if (stagger == HH) then
33 ncol = 2*ih-1+mod(jh+1,2)
34 tlatd = (jh-midrow)*dphd
35 tlond = (ncol-midcol)*dlmd
36 else if (stagger == VV) then
37 imt = 2*ixdim(current_nest_number)-1
44 iadd2 = ixdim(current_nest_number)-1
47 kv = (jh2+iadd1)*imt+iadd2+ih
53 if (krem <= ixdim(current_nest_number)-1) then
58 ncol = 2*(krem-ixdim(current_nest_number))+1
60 tlatd = (nrow-(jydim(current_nest_number)+1)/2)*dphd
61 tlond = (ncol-ixdim(current_nest_number))*dlmd
66 arg1 = sin(tlatr)*cos(tph0)+cos(tlatr)*sin(tph0)*cos(tlonr)
71 arg2 = dcos(tlatr)*dcos(tlonr)/(dcos(glatr)*dcos(tph0))-dtan(glatr)*dtan(tph0)
72 if (abs(arg2) > 1.) arg2 = abs(arg2)/arg2
74 if (tlond > 0.) fctr = -1.
76 glond = known_lon+fctr*dacos(arg2)*r2d