Hi,
I am trying to convert a simple FORTRAN script thats function is to
convert hrap coords to lat/lon coords. The Fortran script has been used widely and can be assumed to be running. The problem is my C script does not compute the correct (lat/lon) coordiniates. Given (61,429) it should output (38.2,-121.5), but it outputs (37.89,-238.82) (note lon of -238.82 is impossible)
I would greatly appreciate if those users with knowledge of both languages could compare both scripts (they are short) and offer some differences in my conversion to C.
C code is attached.
Fortran code is below:
Thanks in advance,
c**********************************************************************
subroutine hrap_to_latlon(hrap_x,hrap_y,rlon,rlat)
c**********************************************************************
c
c subroutine converts HRAP to lat-lon
c
c input variables
c
c hrap_x - global HRAP x-coordinate
c hrap_y - global HRAP y-coordinate
c
c output variables
c
c rlon - longitude in fractional degrees
c rlat - lattitude in fractional degrees
c
earthr=6371.2
stlon=105.
pi=3.141592654
raddeg=180./pi
xmesh=4.7625
tlat=60./raddeg
x=hrap_x-401.
y=hrap_y-1601.
rr=x*x+y*y
gi=((earthr*(1.+sin(tlat)))/xmesh)
gi=gi*gi
rlat=asin((gi-rr)/(gi+rr))*raddeg
ang=atan2(y,x)*raddeg
if(ang.lt.0.) ang=ang+360.
rlon=270.+stlon-ang
if(rlon.lt.0.) rlon=rlon+360.
if(rlon.gt.360.) rlon=rlon-360.
return
end