|
[Sponsors] |
May 19, 2006, 02:31 |
reading from line no x in fortran
|
#1 |
Guest
Posts: n/a
|
hi,
may i know if it is possible to start reading in an ascii file from line no. x e.g line 4 in fortran? hope someone can help. tks! |
|
May 19, 2006, 08:51 |
Re: reading from line no x in fortran
|
#2 |
Guest
Posts: n/a
|
You'll need to code up something to skip the first n-1 lines with dummy reads to read the nth line in. Something like
char*1 skip do i = 1, n-1 read (iunit,*) skip end do read (iunit,*) data you want |
|
May 19, 2006, 11:42 |
tks, what abt reading data on the same line?
|
#3 |
Guest
Posts: n/a
|
thanks ag,
that's just what i've been doing. ;-) btw, i've data which are situated on the same line, separated by space. i tried to read by: do i=1,n read (1,fmt=*) u(i) end do however using the above, i can only read in the 1st data of that line. moreover, different rows 've different no. of data. hence, it is not possible to use read (1,fmt=*) u(i),v(i)... and lastly, how abt if the data are arranged in this fashion: 1.12345678e1231.12345678e12312.... ie there are no space bet 2 nos although i know their length is fixed ie 1.12345678e123 thanks in advance! |
|
May 19, 2006, 13:20 |
Re: tks, what abt reading data on the same line?
|
#4 |
Guest
Posts: n/a
|
You can try guessing the # of variables and back up if an error is encountered. For example:
nvars=10 readin=.false. do while(.not.readin) read(iunit,*,err=5)(u(i),i=1,nvars) readin=.true. cycle 5 nvars=nvars-1 backspace(iunit) enddo This may not be the most elegant code but it should get the job done. In response to your second question, if you know the field width you can use a formatted read. For example, read(iunit,5)(u(i),i=1,10) 5 format(10(1pe14.8)) |
|
May 19, 2006, 13:23 |
Re: tks, what abt reading data on the same line?
|
#5 |
Guest
Posts: n/a
|
Sorry about the formatting, let's try that again:
nvars=10 readin=.false. do while(.not.readin) read(iunit,*,err=5)(u(i),i=1,nvars) readin=.true. cycle 5 nvars=nvars-1 backspace(iunit) enddo |
|
May 19, 2006, 17:18 |
Re: tks, what abt reading data on the same line?
|
#6 |
Guest
Posts: n/a
|
First Question regarding skipping first n lines of sequential formatted file to start reading on n+1'th line:
do i = 1, n read(1,*) end do If the file is unformatted, the read statement above would be replaced with read(1) Second Question regarding reading numbers separated with blanks but random number of numbers per line. "pc" has a good solution. In the special case where the numbers are all of the same type, and you know the total number "m" of numbers, simply use: read(1,*) (u(i), i = 1, m) Third Question regarding packed numbers with no separator. "pc" has the right answer. |
|
May 20, 2006, 11:23 |
Re: tks, what abt reading data on the same line?
|
#7 |
Guest
Posts: n/a
|
tks alot everyone. i'll try them a try!
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Gmsh] Problem with Gmsh | nishant_hull | OpenFOAM Meshing & Mesh Conversion | 23 | August 5, 2015 02:09 |
OpenFOAM 1.7.1 installation problem on OpenSUSE 11.3 | flakid | OpenFOAM Installation | 16 | December 28, 2010 08:48 |
Regarding FoamX running Kindly help out | hariya03 | OpenFOAM Pre-Processing | 0 | April 18, 2008 04:26 |
[blockMesh] Axisymmetrical mesh | Rasmus Gjesing (Gjesing) | OpenFOAM Meshing & Mesh Conversion | 10 | April 2, 2007 14:00 |
error while compiling the USER Sub routine | CFD user | CFX | 3 | November 25, 2002 15:16 |