For Programmers: Free Programming Magazines  


Home > Archive > Fortran > October 2004 > Help --- continued code conversion









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help --- continued code conversion
Jason

2004-10-20, 4:06 pm

I am trying to learn FORTRAN so that I can convert 200 lines of FORTRAN to C++.

----------------------------------------------------------------
program kmc

1. implicit double precision (a-h,o-z)
2. parameter(mmax = 300)
3. integer height(mmax*mmax),iper(0:mmax+1), idx(4), idy(4)
4. dimension rho(mmax,mmax)
5. data idx/1, 0, -1, 0/, idy/0, 1, 0, -1/
6. common/iseed/idum

----------------------------------------------------------------

//c++ code maybe
1. double a,b,c,d,e,f,g,h,o,p,q,r,s,t,u,v,w,x,y,z;

2. int mmax = 300;
3. int height[mmax][mmax];
int iper[mmax+1];
int idx[4];
int idy[4];
4. --------I am not sure how to handle this
5. idx[0] = 1; idx[1] = 0; idx[2] = -1; idx[3] = 0;
idy[0] = 0; idy[1] = 1; idy[2] = 0; idy[3] = -1;
6. --------I am not sure how to handle this

-------------------------------------------------------------------

Any suggestions?
James Van Buskirk

2004-10-20, 4:06 pm

"Jason" <jspaldin@umflint.edu> wrote in message
news:975427f0.0410201118.b431300@posting.google.com...

> I am trying to learn FORTRAN so that I can convert 200 lines of FORTRAN to

C++.

The first mistake -- you should be trying to find some way to
link the Fortran code to the C++.

> 1. double a,b,c,d,e,f,g,h,o,p,q,r,s,t,u,v,w,x,y,z;


No. Don't put in any superfluous declarations like this, just
declare variables by hand when the C++ compiler tells you they
are required. For only 200 lines of Fortran this is probably
the easiest method.

> 2. int mmax = 300;


No. Declare mmax as a const.

> 3. int height[mmax][mmax];


No. should be [mmax*mmax], a 1-d array.

> int iper[mmax+1];


No. Should be mmax+2.

> int idx[4];


No. int idx[4] = {1,0,-1,0};

> int idy[4];


See idx[4].

> 4. --------I am not sure how to handle this


double rho[mmax][mmax];

> 5. idx[0] = 1; idx[1] = 0; idx[2] = -1; idx[3] = 0;
> idy[0] = 0; idy[1] = 1; idy[2] = 0; idy[3] = -1;


See above note on initialization.

> 6. --------I am not sure how to handle this


Declare a global type with an instance called iseed.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Rich Townsend

2004-10-20, 4:06 pm

James Van Buskirk wrote:

<snip lots of good advice>

Not meaning to be rude to the original poster, but a similar result
could be achieved if he took the time and the effort to become competent
in C++ and Fortran. Give a man a fish etc etc...

cheers,

Rich

--
Dr Richard H D Townsend
Bartol Research Institute
University of Delaware

[ Delete VOID for valid email address ]
Richard E Maine

2004-10-20, 8:57 pm

"James Van Buskirk" <not_valid@comcast.net> writes:

>
> No. Don't put in any superfluous declarations like this,...


Besides, this is just plain an incorrect translation anyway.
Independent of whether this is a good idea or not, it is wrong.
As others have mentioned, there *ISN"T* a direct translation.
The implicit statement applies to all otherwise untyped names
beginning with the specified letters.

The "beginning with" part is important; it is not restricted to just
one-letter names.

The "otherwise untyped" part is also important. Just because you
have an implicit mapping doesn't mean that names necessarily get
that type - just names that are otherwise untyped.

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com