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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read, Sort, Write (Very Newbie)

Status
Not open for further replies.

iroger

Technical User
Feb 19, 2011
1
US
All- So the last time I wrote a program in Fortran was over 15 years ago. I have Chapman's book and trying to refresh my memory now. It's coming back to me, but slowly (old age).

So my problem. I have a file that contains a lot of information in sections and need strip out each section to another file. The sections starts with *NAME and ends with a * or $. Below is an example:

*NODE
600204 2.8416665 -0.132341 0.6456926
600205 2.8416665 -0.1343255 0.6204348
600206 2.8416665 -0.13631 0.595177
600207 2.8416665 -0.1618106 0.595177
600208 2.8416665 -0.1873112 0.595177
600209 2.8416665 -0.2128118 0.595177
600210 2.8416665 -0.2383125 0.595177
600211 2.8416665 -0.2638131 0.595177
600212 2.8416665 -0.2893137 0.595177
600213 2.8416665 -0.3148143 0.595177
600214 2.8416665 -0.3403149 0.595177
...
...
* !or may end with $

The file has multiple *NODE sections in different places in the file. How do I search for *NODE in a file, take that information in between, and write it to another file?

Any suggestion will be very helpful....

Roger
 
Depends on whether you've got literally "*NODE" or that you've got something like "*MyName"

My first guess is that you could scan de file for either the word "*NODE" or for the "*" just by reading strings and checking with the INDEX function.
Code:
CHARACTER(LEN=80) :: Line
...
OPEN(UNIT=11,FILE='inputfile.dat',STATUS='OLD')
   i=0
   DO WHILE(i==0)
      READ(11,ERR=100,END=100,FMT='(A80)')Line
      i=INDEX(Line,'*NODE') ! Returns 0 if '*NODE' is not found
   END DO
   100 CONTINUE
! Your cursor is now on the *NODE line, by which you know that in the
! next line you'll be able to read the data
! by READ(11,*)MyInt,real1,real2,real3
! Repeat the above in a loop for all *NODE's
CLOSE(11,STATUS='KEEP')

 
Dear All,


I have an urgent question. I have a list of data in "m" rows and "n" columns. The following shows the sample in wich x,y and z are REAL numbers.

y1 y2 y3 y4

x1 z1 z2 z3 z4
x2 z7 z8 z9 z10
x3 z13 z14 z15 z16
x4 z19 z20 z21 z22


I need to read these data in fortran 90 in such a way that the values of z are function of x and y, eg. F(x1,y1)=z1 or F(x3,y3)=z15. I could not use Read (1,*) command. It only reads data starting from the first column and after that goes to the second column. But I want to be read row by row i.e. first y(i), then second row reading x1 and corresponding z data for y(i)and x1.Would you please help me through this? Many thanks.
 
How about something like:
Code:
DO i=1,4,1
   READ(iunit,*)x(i),(z((i-1)*4+j),j=1,4,1)
END DO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top