|
[Sponsors] |
July 20, 2005, 23:00 |
Help: reading results in fortran
|
#1 |
Guest
Posts: n/a
|
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 |
|
July 21, 2005, 03:05 |
Re: Help: reading results in fortran
|
#2 |
Guest
Posts: n/a
|
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 |
|
July 21, 2005, 03:10 |
Re: Help: reading results in fortran
|
#3 |
Guest
Posts: n/a
|
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... |
|
July 21, 2005, 10:26 |
Re: Help: reading results in fortran
|
#4 |
Guest
Posts: n/a
|
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. |
|
July 21, 2005, 10:48 |
Re: Help: reading results in fortran
|
#5 |
Guest
Posts: n/a
|
Hi,
I've been doing it. However, I was wondering if it's possible to just read 1 column of data in fortran. thanks |
|
July 21, 2005, 11:57 |
Re: Help: reading results in fortran
|
#6 |
Guest
Posts: n/a
|
you mean to say third column of V only, then you have to give the format.
|
|
July 21, 2005, 12:14 |
Re: Help: reading results in fortran
|
#7 |
Guest
Posts: n/a
|
The first answer you got, from Roddy, is correct.
|
|
July 21, 2005, 15:17 |
Re: Help: reading results in fortran
|
#8 |
Guest
Posts: n/a
|
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. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Comparison between C/C++ and Fortran? | rick | Main CFD Forum | 45 | September 6, 2011 01:52 |
Error reading transient results | Magnoli | CFX | 3 | March 4, 2010 09:29 |
A basic doubt on reading the iteration results | hariya03 | OpenFOAM Post-Processing | 0 | July 16, 2008 09:28 |
[Commercial meshers] FluentMesh conversion problem | waynezw0618 | OpenFOAM Meshing & Mesh Conversion | 12 | December 1, 2006 00:12 |
Why Favoring Fortran over C/C++? | Zi-Wei Chiou | Main CFD Forum | 35 | September 26, 2001 10:34 |