CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Main CFD Forum

Help: reading results in fortran

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   July 20, 2005, 22:00
Default Help: reading results in fortran
  #1
Quarkz
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
  Reply With Quote

Old   July 21, 2005, 02:05
Default Re: Help: reading results in fortran
  #2
Roddy
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
  Reply With Quote

Old   July 21, 2005, 02:10
Default Re: Help: reading results in fortran
  #3
diaw
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...
  Reply With Quote

Old   July 21, 2005, 09:26
Default Re: Help: reading results in fortran
  #4
A.S.
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.
  Reply With Quote

Old   July 21, 2005, 09:48
Default Re: Help: reading results in fortran
  #5
Quarkz
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
  Reply With Quote

Old   July 21, 2005, 10:57
Default Re: Help: reading results in fortran
  #6
A.S.
Guest
 
Posts: n/a
you mean to say third column of V only, then you have to give the format.
  Reply With Quote

Old   July 21, 2005, 11:14
Default Re: Help: reading results in fortran
  #7
Jim_Park
Guest
 
Posts: n/a
The first answer you got, from Roddy, is correct.
  Reply With Quote

Old   July 21, 2005, 14:17
Default Re: Help: reading results in fortran
  #8
Mani
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.
  Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison between C/C++ and Fortran? rick Main CFD Forum 45 September 6, 2011 00: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 08:28
FluentMesh conversion problemwaiting for help waynezw0618 OpenFOAM Other Meshers: ICEM, Star, Ansys, Pointwise, GridPro, Ansa, ... 12 December 1, 2006 00:12
Why Favoring Fortran over C/C++? Zi-Wei Chiou Main CFD Forum 35 September 26, 2001 09:34


All times are GMT -4. The time now is 18:33.