CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   Help: reading results in fortran (http://www.cfd-online.com/Forums/main/9556-help-reading-results-fortran.html)

Quarkz July 20, 2005 22:00

Help: reading results in fortran
 
Hi,

I saw someone posting qns abt how to save results efficiently in fortran and I've a similar problem, except now is in reading of results.

supposed that i've a txt file which has results saved in 3 columns e.g. x, y and v. is there anyway I can selectively save only the values of v into an array e.g. v(n)?

Thanks

Roddy July 21, 2005 02:05

Re: Help: reading results in fortran
 
I would suggest that you read the three columns of data but store only the values of v into an array and let the other two columns be saved into two variables which you won't use later.

Well I know only a little bit of Fortran 77 :P

Example:

do 10 i=1,n

read(5,*) x,y,v(i)

10 continue

Using pointers might also be helpful: i.e saving x and y as pointer variables and dispose them when the loop has finished. Well I don't know anything about pointers in Fortran. Hope someone else has a better solution than mine.

>R

diaw July 21, 2005 02:10

Re: Help: reading results in fortran
 
You may need to know the format in whch the original data was written to the file. You can then read the data back using a 'read' with associated 'format' statement.

Look up file input/output commands for more details.

diaw...

A.S. July 21, 2005 09:26

Re: Help: reading results in fortran
 
In F90 you can read in free format,

Do n=1,10

Read(1,*)x(n),y(n),v(n) END DO

Hope it helps

A.S.

Quarkz July 21, 2005 09:48

Re: Help: reading results in fortran
 
Hi,

I've been doing it. However, I was wondering if it's possible to just read 1 column of data in fortran.

thanks

A.S. July 21, 2005 10:57

Re: Help: reading results in fortran
 
you mean to say third column of V only, then you have to give the format.

Jim_Park July 21, 2005 11:14

Re: Help: reading results in fortran
 
The first answer you got, from Roddy, is correct.

Mani July 21, 2005 14:17

Re: Help: reading results in fortran
 
Yes, you can. As A.S. said, you can skip columns under the condition that you know the format. More precisely, you would need to know the number of characters in each column that you want to skip. For example, if your first two columns consist of 10 characters, and the next one is some real value with format g10.7:

read(id,'(10x,g10.7)') v

will give you the number in the third column in variable v. I think it's clear that you can do that only by using the correct format. Without format, a text file has no easily accessible data structure, other than lines. If your data has been written in a formatted way, then you already know the format, and reading is really easy to do. However, if you don't like using formats, then you'll not get around reading all columns, as Roddy said.

Doing it either way, I am not sure if you can save much time.


All times are GMT -4. The time now is 22:40.