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

read in line / fortran

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 12, 2006, 09:06
Default read in line / fortran
  #1
jojo
Guest
 
Posts: n/a
Hi everybody,

I have a tricky question on Fortran.

What is the programming trick to read several numbers in line like:

123 234 345 456 789 678

I want to read the 'n' first numbers before going to the following line. Is it possible to control that in a n-loop? Basically there will be an outer loop based on the lines in the file (like usual) and an inner loop to control the number of columns read in each line.

Thanks a lot in advance.

jojo
  Reply With Quote

Old   September 12, 2006, 09:59
Default Re: read in line / fortran
  #2
Nico
Guest
 
Posts: n/a
This should work, 1000 being a number >n Write(1,'(1000i3)') (array(i),i=1,n) another way would be to concatenate n & 'i3' in a character.

Nico
  Reply With Quote

Old   September 12, 2006, 10:56
Default Re: read in line / fortran
  #3
Renato.
Guest
 
Posts: n/a
Well..., I would load the data in a buffer and store only what I want or read dummy arguments to make the read statement consistent for each line. Imagine a file with 10 lines, each line has 5 numbers and you like to store only the 1st., 3rd. and 5th. numbers, you could do something like:

do i=1,10 read(iin,*) n1, ntrash1, n3, ntrash2, n5 enddo

or

do i=1,10 read(iin,*) (ibuf(j),j=1,5) ! here you can select which value must be stored enddo

hope it helps you

Renato.

ps.: There's a format statement where you tell how many values must be read. I don't remember clearly, but it seems something like:

9 format(< n >i3)

here you can set "n" equal to the number of integer values that must be read.

  Reply With Quote

Old   September 13, 2006, 04:50
Default Re: read in line / fortran
  #4
HelpfulSoul
Guest
 
Posts: n/a
Neither of these solutions are particularly useful in the context of the stated problem as they both require that there be at least 5 numbers on every line rather than an unknown number - what happens if there are less (or more) than 5 ? This could be corrected using the IOSTAT to stop the program crashing out if there are too few numbers and making the required number of values very large compared to the expected number of values, but the implicit loop from the previous poster's solution is the way to go.

  Reply With Quote

Old   September 13, 2006, 09:30
Default Re: read in line / fortran
  #5
Gerrit
Guest
 
Posts: n/a
I doubt that I understood you well, but just in case...

DO iline=1,imxline,1

READ(1,*)(x(icolumn),icolumn=1,n,1) END DO
  Reply With Quote

Old   September 15, 2006, 09:41
Default Re: read in line / fortran
  #6
jojo
Guest
 
Posts: n/a
Thanks a lot everybody.

You have answered my question very well.
  Reply With Quote

Reply


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 Off
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
CFX11 + Fortran compiler ? Mohan CFX 20 March 30, 2011 18:56
How to read files in parallel using fortran and mpi quarkz Main CFD Forum 0 November 21, 2010 10:41
Installation OF1.5-dev ttdtud OpenFOAM Installation 46 May 5, 2009 02:32
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 14:00


All times are GMT -4. The time now is 09:52.