Help Converting a Simple Fortran Script to C - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Help Converting a Simple Fortran Script to C

Posts: 1Member
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:

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
xmesh=4.7625
x=hrap_x-401.
y=hrap_y-1601.
rr=x*x+y*y
gi=((earthr*(1.+sin(tlat)))/xmesh)
gi=gi*gi
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

• Posts: 59Member
Everything seems fine except for the last line of
code.
[code] The FORTRAN subroutine line (not script)
if (rlon.gt.360) rlon=rlon-360
//
// now the C code
//
if(rlon < 360.0) { [b][color=Green]//-- change < to >[/color][/b]
rlon = rlon - 360.0;
}
[/code]