Are Continuation Lines Allowed in Fortran90

new line in fortran90


Author Message

 new line in fortran90

Hi, i'm writing a small code (F90) intending to revise fortran programs in
F77.

How to determine if the character is the last one in a line?

In C, if '\n' is read, then we know that a new line will begin. What's it in
F90?

Thanks

Fri, 24 Oct 2003 21:24:23 GMT

 new line in fortran90

Not quite so easy...standard F77 line is

col 1-5 : line number (or C in col 1 for comment) (was "D" standard or
common extension?)
col 6   : continuation line indication
col 7-72: source
col 73-80: comment field (often used for card sequence number in olden
days of punch cards)

Many compilers had extensions that allowed longer source lines, however
(MS one on PC that comes to mind).

What did I forget? <G>

Quote:

> Hi, i'm writing a small code (F90) intending to revise fortran programs in
> F77.

> How to determine if the character is the last one in a line?

> In C, if '\n' is read, then we know that a new line will begin. What's it in
> F90?

> Thanks

Fri, 24 Oct 2003 23:55:58 GMT

 new line in fortran90

Thanks .
so it's impossible  to decide whether or not the end of a line is reached
with an F90 internal function like:
...
readStatus=fgetc(unit,charRead)
....

?? (where readStatus =0, successful or -1, EOF )

********
Actually, i want to upgrade the comment lines in F77 to F90 (from 'c', 'C',
or '* '  to '!'), that's why i have to determine whether or not the end of a
line is reached.

Have you got any other methods for this?

Thanks.

Quote:

> Not quite so easy...standard F77 line is

> col 1-5 : line number (or C in col 1 for comment) (was "D" standard or
> common extension?)
> col 6   : continuation line indication
> col 7-72: source
> col 73-80: comment field (often used for card sequence number in olden
> days of punch cards)

> Many compilers had extensions that allowed longer source lines, however
> (MS one on PC that comes to mind).

> What did I forget? <G>

> > Hi, i'm writing a small code (F90) intending to revise fortran programs
in
> > F77.

> > How to determine if the character is the last one in a line?

> > In C, if '\n' is read, then we know that a new line will begin. What's
it in
> > F90?

> > Thanks

Sat, 25 Oct 2003 02:37:25 GMT

 new line in fortran90

Quote:

> so it's impossible  to decide whether or not the end of a line is reached
> with an F90 internal function like:
> ...
>   readStatus=fgetc(unit,charRead)
> ....
> ?? (where readStatus =0, successful or -1, EOF )

> ********
> Actually, i want to upgrade the comment lines in F77 to F90 (from 'c', 'C',
> or '* '  to '!'), that's why i have to determine whether or not the end of a
> line is reached.

It's quite possible.  The direct analogue of the above C fgetc usage is
to use a non-advancing read.  You can then test for the end of line
using either EOR= or IOSTAT=.  See any F90 text for details of EOR=
and IOSTAT=.  Probably in a section on non-advancing I/O.

On the other hand, it seems like you are just making extra work
for yourself trying to write C in Fortran.  It can be done, but
why?

A "normal" Fortran formatted read will naturally read a whole record.
You have to go out of your way (by using advance="no") to do anything
else.  You did, I assume discover advance="no"?  If not, then how
were you thinking that you would get anything other than a whole
line per read?  It really sounds to me like you are using
advance="no" and then trying to undo the "damage" it has done to
you.  Either that or perhaps you are incorrectly assuming that
Fortran I/O normally acts like advance="no".  (It doesn't).

There are places where non-advancing input is useful.  This doesn't
sound like one of them.  If you were concerned about distinguishing
whether or not there were significant trailing blanks on a line, then
you'd need to use either advance="no" or a system-dependent trick
supported on some compilers (like Q format... I think that was it).

But since your input is F77 source code, then trailing blanks
shouldn't matter.  There are some compilers where trailing blanks
mattered for continued character literals...but that was quite
compiler-dependent; portable f77 code doesn't count on that.

So just read line at a time with something like

  read(lun,'(a)',...) line

where line is a character string long enough to hold the longest
allowable line.  That would be 72 characters for standard f77; you can
make it longer to accomodate common extensions.  You seldom (if ever)
see code longer than the f90 limit of 132 characters.

The character line(1:1) will always be the first character in each
line.  The length of the line (ignoring any possible trailing
blanks) is len_trim(line).

Seems to me like this is a lot more straightforward than using
non-advancing input to get characters one at a time so that you
can then paste the lines back together.

--
Richard Maine                       |  Good judgment comes from experience;
email: my last name at host.domain  |  experience comes from bad judgment.
host: altair, domain: dfrc.nasa.gov |        -- Mark Twain

Sat, 25 Oct 2003 02:45:33 GMT

 new line in fortran90

That's really GREAT.
Thanks a lot.

Quote:

> > so it's impossible  to decide whether or not the end of a line is
reached
> > with an F90 internal function like:
> > ...
> >   readStatus=fgetc(unit,charRead)
> > ....
> > ?? (where readStatus =0, successful or -1, EOF )

> > ********
> > Actually, i want to upgrade the comment lines in F77 to F90 (from 'c',
'C',
> > or '* '  to '!'), that's why i have to determine whether or not the end
of a
> > line is reached.

> It's quite possible.  The direct analogue of the above C fgetc usage is
> to use a non-advancing read.  You can then test for the end of line
> using either EOR= or IOSTAT=.  See any F90 text for details of EOR=
> and IOSTAT=.  Probably in a section on non-advancing I/O.

> On the other hand, it seems like you are just making extra work
> for yourself trying to write C in Fortran.  It can be done, but
> why?

> A "normal" Fortran formatted read will naturally read a whole record.
> You have to go out of your way (by using advance="no") to do anything
> else.  You did, I assume discover advance="no"?  If not, then how
> were you thinking that you would get anything other than a whole
> line per read?  It really sounds to me like you are using
> advance="no" and then trying to undo the "damage" it has done to
> you.  Either that or perhaps you are incorrectly assuming that
> Fortran I/O normally acts like advance="no".  (It doesn't).

> There are places where non-advancing input is useful.  This doesn't
> sound like one of them.  If you were concerned about distinguishing
> whether or not there were significant trailing blanks on a line, then
> you'd need to use either advance="no" or a system-dependent trick
> supported on some compilers (like Q format... I think that was it).

> But since your input is F77 source code, then trailing blanks
> shouldn't matter.  There are some compilers where trailing blanks
> mattered for continued character literals...but that was quite
> compiler-dependent; portable f77 code doesn't count on that.

> So just read line at a time with something like

>   read(lun,'(a)',...) line

> where line is a character string long enough to hold the longest
> allowable line.  That would be 72 characters for standard f77; you can
> make it longer to accomodate common extensions.  You seldom (if ever)
> see code longer than the f90 limit of 132 characters.

> The character line(1:1) will always be the first character in each
> line.  The length of the line (ignoring any possible trailing
> blanks) is len_trim(line).

> Seems to me like this is a lot more straightforward than using
> non-advancing input to get characters one at a time so that you
> can then paste the lines back together.

> --
> Richard Maine                       |  Good judgment comes from
experience;
> email: my last name at host.domain  |  experience comes from bad judgment.
> host: altair, domain: dfrc.nasa.gov |        -- Mark Twain

Sat, 25 Oct 2003 03:25:28 GMT

 new line in fortran90

No, in Fortran there is a \n at each source line in the source file, but
that is not <necessarily> the entire program source line.  There is a
possibility that a line is continued and also the possibility that there
is non-significant information in columns 73-80.  And, at least one
condition I did forget to mention, that many earlier compilers also
supported the "!" as a comment to EOL as well as "C" or "D" in column
1.  So it actually takes some parsing of the code to interpret it
correctly.  Also, continuation lines in F77 are indicated by a character
in col 6 (of the <continuing> line) as I mentioned, but in F90 free form
they are indicated by an "&" at the end of the <continued> line.  To
make a form that is compatible with both fixed and free form, an & in
col 73 of each line to be continued and also in col. 6 of each
continuing line is needed.

I had intended to add this to my previous post, but got an itchy trigger
finger <g>..

There are several free utilities to convert from F77 fixed format files
to free format files.  Look at www.fortran.com, their link to free
software has at least a couple.  f2f90 is one I remember by name.

Quote:

> Thanks .
> so it's impossible  to decide whether or not the end of a line is reached
> with an F90 internal function like:
> ...
>   readStatus=fgetc(unit,charRead)
> ....

> ?? (where readStatus =0, successful or -1, EOF )

> ********
> Actually, i want to upgrade the comment lines in F77 to F90 (from 'c', 'C',
> or '* '  to '!'), that's why i have to determine whether or not the end of a
> line is reached.

> Have you got any other methods for this?

> Thanks.

> > Not quite so easy...standard F77 line is

> > col 1-5 : line number (or C in col 1 for comment) (was "D" standard or
> > common extension?)
> > col 6   : continuation line indication
> > col 7-72: source
> > col 73-80: comment field (often used for card sequence number in olden
> > days of punch cards)

> > Many compilers had extensions that allowed longer source lines, however
> > (MS one on PC that comes to mind).

> > What did I forget? <G>

> > > Hi, i'm writing a small code (F90) intending to revise fortran programs
> in
> > > F77.

> > > How to determine if the character is the last one in a line?

> > > In C, if '\n' is read, then we know that a new line will begin. What's
> it in
> > > F90?

> > > Thanks

Sat, 25 Oct 2003 03:05:50 GMT

 new line in fortran90

Quote:

hongxun lee writes:
> How to determine if the character is the last one in a line?

Depends on what you consider a "character".  Let's assume that an
embedded blank is a character but a trailing blank is not.  In
FORTRAN 77, read the line into a character string, then starting
at the end, work backward until you find a non-blank character.

In Fortran 90, just use LEN_TRIM.

Sat, 25 Oct 2003 05:20:06 GMT

 new line in fortran90

Sounds a bit like you're trying to write a source form converter.
There's one at:

A source form convertor, convert.f90, is obtainable by ftp from
ftp.numerical.rl.ac.uk in the directory /pub/MandR. Latest
version is 1.5.

Regards,

Mike Metcalf

--

Sat, 25 Oct 2003 15:30:31 GMT

 new line in fortran90


| Hi, i'm writing a small code (F90) intending to revise fortran programs in
| F77.
|
| How to determine if the character is the last one in a line?
|
| In C, if '\n' is read, then we know that a new line will begin. What's it in
| F90?
|
| Thanks

There are many ways.
Most important: by default, each READ or WRITE statement ends the
current line and moves the "pointer" to the new line. This can
be overriden using READ/WRITE(..., ADVANCE="NO") (default is "Yes"):
WRITE(*,'(i5)') i1
WRITE(*,'(i5)') i2
will output to two lines.

Second, a slash in FORMAT specifier means new line:
WRITE(*,'(i5,/,i5)') i1, i2
causes i1 and i2 to be written in two records. Similarly, READ
with the same format will expect i1 and i2 to be in two lines.

Third, for writing, you can manually insert CHAR(13) (or CHAR(13)+CHAR(10)):
WRITE(*,'(i5,2a1,i5)') i1,CHAR(13),CHAR(10),i2
with the same effect.

Etc.

Jugoslav

Fri, 24 Oct 2003 23:41:57 GMT

 new line in fortran90

Quote:

> Third, for writing, you can manually insert CHAR(13) (or CHAR(13)+CHAR(10)):
> WRITE(*,'(i5,2a1,i5)') i1,CHAR(13),CHAR(10),i2
> with the same effect.

That, of course, is non-standard and system-dependent.  There exist systems
that will happily write the char(10) and/or char(13) characters without
them having any relationship to record structure.

This includes any system that doesn't use the ASCII character set (or
something ASCII-derived).  Among current systems, the IBM mainframes
are the notable example; plus there are many others of older vintage.

It also includes systems that represent text records using counted
lengths or anything other than a carriage return and/or line-feed at
the end.

--
Richard Maine                       |  Good judgment comes from experience;
email: my last name at host.domain  |  experience comes from bad judgment.
host: altair, domain: dfrc.nasa.gov |        -- Mark Twain

Sat, 25 Oct 2003 22:49:44 GMT

Powered by phpBB® Forum Software

turnersammis.blogspot.com

Source: http://computer-programming-forum.com/49-fortran/375b1abb784a1a89.htm

0 Response to "Are Continuation Lines Allowed in Fortran90"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel