## C and C++

Moderators: None (Apply to moderate this forum)
Number of posts: 94611

This Forum Only

Help Converting a Simple Fortran Script to C Posted by Jumper4 on 4 Aug 2010 at 11:31 AM
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

Re: Help Converting a Simple Fortran Script to C Posted by quikcarl on 4 Aug 2010 at 9:15 PM
Everything seems fine except for the last line of
code.
``` The FORTRAN subroutine line (not script)
if (rlon.gt.360) rlon=rlon-360
//
// now the C code
//
if(rlon < 360.0) {  //-- change < to >
rlon = rlon - 360.0;
}
```

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic