Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skipping characters while reading from a text file.

Status
Not open for further replies.

DonPasqual

Technical User
Mar 22, 2010
3
CH
Hi there,

I have a problem with FORTRAN 77.
I'm trying to read some variables from a text file called fort.51
The first line of this file looks like this:

00005 06/25/1851 M= 4 1 SNBR= 1 NOT NAMED XING=1 SSS=1

There are several characters I need to skip.
My aim is to read all numbers and the name (here: NOT NAMED) to use it further.

My solution looks like this:

program testread

integer month,year,m,numbtot,numbyear,xing,sss,zahl
character(len=11) name
character(len=1) dummy1,dummy2
character(len=3) dummy3
character(len=5) dummy4,dummy5

read(51,100,err=999,end=998) zahl,month,dummy1,day,dummy2,
> year,dummy3,m,numbyear,dummy3
> numbtot,name,dummy4,xing,sss

100 format(i5,i3,A,i2,A,i4,A,i2,i3,1x,A,i4,1x,A,A,i1,A,i1)
...

I introduced some dummy characters to skip the unused characters with reading them.
there's an error after reading "month" and the following variables get a wrong value.

What did I do wrong? Is there another possibility to skip those slashes and unusable text parts?

Thanks,
Pascal
 
Do you know how many characters you wish to skip? If it is always the same use nX where n is the number of characters.

A is different from A1. A reads the rest of the line however long it is. A1 only reads 1 character.

At a guess your format should be
Code:
read(51,100,err=999,end=998)    zahl,month,day,
     >                year,m,numbyear,
     >                numbtot,name,xing,sss

100 format(i5,i3,1X,i2,1X,i4,3X,i2,i3,6x,i4,A11,5X,i1,5X,i1)
 
Thanks for your fast reply,

Unfortunately it still doesn't work.

As you suggested, I changed the code to:

100 format(i5,i3,1x,i2,1x,i4,3x,
> i2,i3,6x,i4,1x,A11,6x,i1,5x,i1)


If I print all variables with the error statement:

999 print*,'fehler',zahl,month,day,year,m,numbyear,numbtot,
> name,xing,sss


I get the output:

fehler 5 6 -1.13040848E-19 0 1634890866 1 -1 Spasscal/Fo 0 -1

It works until the first slash but then there's a error I cannot explain.

Thanks,
Pascal

 
Hi DonPasqual

When you print out "day" it clearly a real variable.
You have to define the variable "day" and integer.
Do that and try the program again.
 
Hmmm, I do always such stupid little faults!

Now it works perfectly.

Thank you gullipe and xwb

DonPasqual
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top