From: Dylan Sung on
Can anyone tell me how one can find the end of a line of text that comes
from a sequential file in f77? The trailing blanks when reading a line is
annoying, for instance

c234567
character*80 line
open(1,file='data.txt')
read(1,1)line
1 format(a)
stop
end

where the data in the text file is

abcde

and the rest is just blank, or sometimes, the line is longer than 'line' and
just gets truncated...

I want to find the end of the line without the truncation, is there a way to
do it?

Many thanks.

Dyl.

From: dpb on

Dylan Sung wrote:
> Can anyone tell me how one can find the end of a line of text that comes
> from a sequential file in f77? The trailing blanks when reading a line is
> annoying, for instance
>
....[using character*80 string ] ... where the data in the text file is
>
> abcde
>
> and the rest is just blank, or sometimes, the line is longer than 'line' and
> just gets truncated...
>
> I want to find the end of the line without the truncation, is there a way to
> do it?

....

In strict F77 you'll need to write a function that looks for the last
non-blank character in the string and use that length to manipulate the
string. This is a good reason to move to a later version of Fortran as
there now (w/ F90/56) an intrinsic TRIM() function. In words, the
function would take the character variable as its argument and,
starting from the end work it's way backwards to find the first
non-blank character. That location and the input length provide the
length of the string minus the trailing blanks.

If the input lines are longer than 80 characters, Fortran will truncate
the data on input as you note. The way around this is to make the
variable as long as the longest line expected.

From: Dylan Sung on

"dpb" <dpbozarth(a)swko.net> wrote in message
news:1159491699.177088.104290(a)e3g2000cwe.googlegroups.com...
>
> Dylan Sung wrote:
>
> If the input lines are longer than 80 characters, Fortran will truncate
> the data on input as you note. The way around this is to make the
> variable as long as the longest line expected.
>

I've been trying with character*2000 and longer, as sometimes, there isn't
any text wrapping from the original filename.txt file. Is there no intrinsic
function which looks for "end of line" or "carriage return" at all?

Cheers,
Dyl.

From: Arjen Markus on

Dylan Sung schreef:

> "dpb" <dpbozarth(a)swko.net> wrote in message
> news:1159491699.177088.104290(a)e3g2000cwe.googlegroups.com...
> >
> > Dylan Sung wrote:
> >
> > If the input lines are longer than 80 characters, Fortran will truncate
> > the data on input as you note. The way around this is to make the
> > variable as long as the longest line expected.
> >
>
> I've been trying with character*2000 and longer, as sometimes, there isn't
> any text wrapping from the original filename.txt file. Is there no intrinsic
> function which looks for "end of line" or "carriage return" at all?

With Fortran 90/95 you have the possibility to use non-advancing I/O:

read( 10, advance='no', size=noread, eor=200) string

The variable noread will hold the number of characters that was read.

The label specified with eor=200 indicates where to jump to if the end
of the record is encountered.

These features should give you all the information you want.

Regards,

Arjen

From: Gordon Sande on
On 2006-09-29 03:24:22 -0300, "Dylan Sung"
<dylanwhs.tsktsktsk(a)pacific.net.hk> said:

>
> "dpb" <dpbozarth(a)swko.net> wrote in message
> news:1159491699.177088.104290(a)e3g2000cwe.googlegroups.com...
>>
>> Dylan Sung wrote:
>>
>> If the input lines are longer than 80 characters, Fortran will truncate
>> the data on input as you note. The way around this is to make the
>> variable as long as the longest line expected.
>>
>
> I've been trying with character*2000 and longer, as sometimes, there
> isn't any text wrapping from the original filename.txt file. Is there
> no intrinsic function which looks for "end of line" or "carriage
> return" at all?
>
> Cheers,
> Dyl.

Your use of "text wrapping" suggests that there is some confusion on
what "text" is.

If you have a "word processor" and start to type in the middle of
the first line of a paragraph the last word of the first line will
suddenly jump to become the first word of the second line. That is
"text wrapping" and reflects the display conventions of that word
processor. If you were to use a long line, or smaller font, the
lines would break differently. Typically there is only a paragraph
break at the end of the paragraph. Paragraph break often convert into
line breaks represented by a line end of CR, LF, CRLF or whatever.
ASCII has a record separator (RS) for this purpose but it is rarely
used.

If you have a (programmers) "text processor" and start to type in
the middle of the first line the last word will get lost of the edge
of the display. No line wrapping. Every line will have a line end.

Fortran uses text as displayed by a text processor. It does not act
as a word processor.

Using a word processor to prepare text is a rather good way of falling
for this sort of trap. Some may have options to save even the "soft
returns" but if you knew about that option you would not be asking the
questions.