Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Help please with a small code conversion
I am trying to convert a piece of FORTRAN code to C++.

write(ifile,*) h(i,j)

Does this simply write to a file a entry from a Ith by Jth entry of a
matrix?  If so what does (ifile, *) do?  Does this make the entry
added to a file called (ifile)?

Also there is another line that has me stuck

implicit double precision(a-h,o-z)

I am not sure the significance of implicit.  How could I get the same
effect using c++?


Jason Spalding

Report this thread to moderator Post Follow-up to this message
Old Post
Jason
10-19-04 08:58 PM


Re: Help please with a small code conversion
jspaldin@umflint.edu (Jason) writes:

> I am trying to convert a piece of FORTRAN code to C++.
>
> write(ifile,*) h(i,j)
>
> Does this simply write to a file a entry from a Ith by Jth entry of a
> matrix?

Yes.  Specifically it writes to a file that had previously been opened and
associated with the unit number 'ifile' (which is an integer).  The opening
function will look something like:

open (unit=ifile,file='filename.dat', [other stuff here])

The '*' just tells it to write it out in whatever default format is associat
ed
with the type of h(i,j).

> implicit double precision(a-h,o-z)
> I am not sure the significance of implicit.

It says any variable whose name begins with the the letter a-h or o-z are to
be treated as if explicitly declared as double precision real numbers.

> How could I get the same effect using c++?

You don't.  You've got to declare your variables explicitly in C++.
--
Gareth Owen
Early to rise, and early to bed / Makes a man healthy but socially dead

Report this thread to moderator Post Follow-up to this message
Old Post
Gareth Owen
10-19-04 08:58 PM


Re: Help please with a small code conversion
On 19 Oct 2004 10:36:02 -0700, Jason wrote:
> I am trying to convert a piece of FORTRAN code to C++.

> write(ifile,*) h(i,j)

> Does this simply write to a file a entry from a Ith by Jth entry of a
> matrix?

Probably, but there's an outside chance that it could mean to call a
function named 'h' with arguments i and j.  In Fortran you can't tell the
difference except by looking to see how (or whether) h is declared.  If h
is not declared at all in that program unit, then it's a function.

>If so what does (ifile, *) do?  Does this make the entry
> added to a file called (ifile)?

Not quite; ifile is an integer variable whose value is the unit number
associated with the file (sort of like file descriptors in C).  The "*"
means that instead of specifying a format for the write, the program is
using "list directed output", which is somewhat similar in spirit to
using the "<<" output operator in C++, since the format is dictated by
the type of the item being written.

> Also there is another line that has me stuck

> implicit double precision(a-h,o-z)

The default specification in Fortran is

implicit real (a-h,o-z)
implicit integer (i-n)

which means you are allowed to have undeclared variables in Fortran, and
their types are inferred from the first letter of the name (hence the
saying:  "God is REAL, unless declared INTEGER.").  The purpose of the
implicit statement is to change the default type mapping.

> I am not sure the significance of implicit.  How could I get the same
> effect using c++?

You can't.  All variables must be given explicit types in C++.  Think of
it as insurance againt typos.


--
Dave Seaman
Judge Yohn's mistakes revealed in Mumia Abu-Jamal ruling.
<http://www.commoncouragepress.com/i...book&bookid=228>

Report this thread to moderator Post Follow-up to this message
Old Post
Dave Seaman
10-19-04 08:58 PM


RE: Help please with a small code conversion
In a previous article, jspaldin@umflint.edu (Jason) wrote:
>I am trying to convert a piece of FORTRAN code to C++.
>
>write(ifile,*) h(i,j)
>
>Does this simply write to a file a entry from a Ith by Jth entry of a
>matrix?  If so what does (ifile, *) do?  Does this make the entry
>added to a file called (ifile)?
>
>Also there is another line that has me stuck
>
>implicit double precision(a-h,o-z)
>
>I am not sure the significance of implicit.  How could I get the same
>effect using c++?
>
>
>Jason Spalding
implicit ... means that all variable names starting with
these letters (a,b,c,...,h and o,p,q,...,z) are typed
as double precision (8byte) floating
This includes function names.
Since (in F77 and earlier) integer vs real was determined
this way (i.e. i-n=integer, a-h,o-z=real) unless typed
explicitly, then provided this naming scheme was followed
in the program, it was easy to change to DP to choose
speed vs. accuracy. These days
co-processer is probably doing DP no matter what you choose
Chris

Report this thread to moderator Post Follow-up to this message
Old Post
meek@skyway.usask.ca
10-20-04 01:56 AM


Re: Help please with a small code conversion
>write(ifile,*) h(i,j)

Writes out one value of the 2D matrix h,
being the value indexed at I in the first
index and at j in the second.

something like (my C is rusty)
fprintf(<appropriate format>,h[j][i]);

Report this thread to moderator Post Follow-up to this message
Old Post
Kevin G. Rhoads
10-20-04 08:56 AM


Re: Help please with a small code conversion
m@skyway.usask.ca writes:

> it was easy to change to DP to choose speed vs. accuracy. These days
> co-processer is probably doing DP no matter what you choose

I'm not entirely sure what you mean by that... but I doubt it is
true.  What you may mean is that the speed of single and double
precision is often about the same...except for memory bandwidth
issues.

By the way, in my experience I have rarely seen implicit used as
an easy way to change speed vs accuracy tradeoffs.  I suppose it
could happen, but that's not the uses I see. Almost all the uses
I've seen have been for one of the reasons

1. The code needs double and the programmer doesn't like doing
explicit declarations.

2. The code was originally written for a machine where single
precision was 60 or 64 bits and has since been ported to a
machine where single is 32 bits (and isn't adequate).

In neither case is speed a relevant issue; no tradeoffs involved.

--
Richard Maine
email: my last name at domain
domain: summertriangle dot net

Report this thread to moderator Post Follow-up to this message
Old Post
Richard Maine
10-20-04 08:56 AM


Re: Help please with a small code conversion
"Richard Maine" <nospam@see.signature> wrote in message
news:87u0sqw76l.fsf@vega.site...
> m@skyway.usask.ca writes:

>                                              Almost all the uses
> I've seen have been for one of the reasons

I have a third reason, which is rather compelling for my purposes.
As you know, I prefer IMPLICIT NONE, but in automatically
generated code I use

implicit real(wp) x

so that all variables with names starting with 'x' will get
the kind type parameter wp inherited from the module in which
the subroutine is INCLUDed.  The reason for this is that I
don't know until the code has been generated what variable
names will be used, only that there will be several thousand.
To declare all these variables I would have to write both the
declarations and the code to separate files then combine them
in a separate final step.  The resulting code would have
hundreds to thousands of lines of declarations that would be
meaningless and unreadable.  I guard against unintentional
creation of variable names not starting with 'x' because the
host module has IMPLICIT NONE in force.  I think many
programmers would use an IMPLICIT statement to make the code
generator simpler in this context.  The code generator is at
http://home.comcast.net/~kmbtib/conv2b.f90 if you want to see
the kind of problem that leads me to use implicit typing.

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



Report this thread to moderator Post Follow-up to this message
Old Post
James Van Buskirk
10-20-04 08:56 AM


Re: Help please with a small code conversion
Richard Maine wrote:

> m@skyway.usask.ca writes:
 

> I'm not entirely sure what you mean by that... but I doubt it is
> true.  What you may mean is that the speed of single and double
> precision is often about the same...except for memory bandwidth
> issues.

The speed is the same because, at least for x87, the calculation
is usually done to full precision, independent of the actual size.
The result is truncated when stored.

In the olden days there were two reasons to use single precision,
speed and memory.  (When computers were slower and memory
was expensive.)

There are control register bits to change the fraction bits
computed by x87 processors, but I don't know any systems that
change them to match the operation being done.

-- glen



Report this thread to moderator Post Follow-up to this message
Old Post
glen herrmannsfeldt
10-20-04 08:56 AM


Re: Help please with a small code conversion
jspaldin@umflint.edu (Jason) wrote in message news:<975427f0.0410190936.4c1f7f38@posting.go
ogle.com>...
> I am trying to convert a piece of FORTRAN code to C++.
>
> write(ifile,*) h(i,j)
>
> Does this simply write to a file a entry from a Ith by Jth entry of a
> matrix?  If so what does (ifile, *) do?  Does this make the entry
> added to a file called (ifile)?
>
> Also there is another line that has me stuck
>
> implicit double precision(a-h,o-z)
>
> I am not sure the significance of implicit.  How could I get the same
> effect using c++?

Have you read any books or tutorials on FORTRAN 77? See
[url]http://dmoz.org/Computers/Programming/Languages/Fortran/Tutorials/Fortran_77/[/url
]
, especially the book by Clive Page.

Report this thread to moderator Post Follow-up to this message
Old Post
beliavsky@aol.com
10-20-04 08:56 AM


Re: Help please with a small code conversion
>There are control register bits to change the fraction bits
>computed by x87 processors, but I don't know any systems that
>change them to match the operation being done.

The run-time libraries usually set them to some default value.
More recently (last decade or so) WinXX systems tend to set
them also, as do just about all apps built with VC++ (the
RTL again).

But you are right, it is pretty much set and forget, not a
dynamic setting of the control for the operation at hand, not
unless you want to do it yourself.

Report this thread to moderator Post Follow-up to this message
Old Post
Kevin G. Rhoads
10-20-04 09:06 PM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:59 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.