Re: Help please with a small code conversion

From: Dave Seaman (dseaman_at_no.such.host)
Date: 10/19/04


Date: Tue, 19 Oct 2004 19:17:12 +0000 (UTC)

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/index.cfm?action=book&bookid=228>


Relevant Pages

  • Re: I have no idea what this line of code does: write()
    ... > harsh introduction as I'm having to do some debugging work on an ... > advanced physical simulation written in Fortran. ... OK, so the array element xlengthis getting written into the alfa ... specifier for the write -- basically, specifying how xlengthis ...
    (comp.lang.fortran)
  • Re: Timeline for F2003 compilers
    ... So you cannot conform fully to the Fortran standard AND necessarily be able to create a .net program, ... A common block object that has a POINTER, TARGET or derived type is restricted ... Specifying the target of a pointer assignment whose rightmost structure component does not have POINTER attribute is restricted in this version of Fortran for .NET. ...
    (comp.lang.fortran)
  • Re: Fortran module in a library
    ... handle specifying include directories? ... Pretty much the same way as Fortran does - by saying it is all ... "This International Standard does not specify ... implementatins of include where it used a syntax something like ...
    (comp.lang.fortran)
  • Re: Viability
    ... like adding up a bunch of numbers and multiply by .06 to determine ... implicit integer (a-h) ... The fortran wiki is probably the only reference you'd need. ... There's no liberal echo chamber in this country. ...
    (comp.lang.fortran)