C and C++

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

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
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:

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



Attachment: lat_long_C.c (1009 Bytes | downloaded 97 times)
Report
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
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.