|
[Sponsors] |
June 12, 2006, 15:24 |
FORTRAN
|
#1 |
Guest
Posts: n/a
|
Hi,
This is a very easy question for professional programmers and has nothing to do with CFD, but I appreciate it if you could give me some advice or let me know of an online reference: The 1st line of a file is: 24 struc.56 18 A B C I am trying to write a FORTRAN program that read this file. Problem is that I need to separate struc. from 56; ie, struc. in a character variable and 56 in an integer variable. So, what is important is 56 that should be put into a variable like N. How can I do that? Thank you. Rose |
|
June 12, 2006, 15:41 |
Re: FORTRAN
|
#2 |
Guest
Posts: n/a
|
How about using formatted input?
character :: cbuf*6, C1*2, C2*2, C3*2 open(9,file="myfile.txt") read(9,'(I3,A6,I2,X,I2,3A2)') i1, cbuf, i2, i3, C1, C2, C3 Cheers Renato. |
|
June 12, 2006, 15:42 |
Re: FORTRAN
|
#3 |
Guest
Posts: n/a
|
oops
I guess, some breaklines would be helpful ;-) character :: cbuf*6, C1*2, C2*2, C3*2 open(9,file="myfile.txt") read(9,'(I3,A6,I2,X,I2,3A2)') i1, cbuf, i2, i3, C1, C2, C3 |
|
June 13, 2006, 12:25 |
Re: FORTRAN
|
#4 |
Guest
Posts: n/a
|
Thanks, that worked.
|
|
June 13, 2006, 22:53 |
Re: FORTRAN
|
#5 |
Guest
Posts: n/a
|
since you have know the length of each part of the sentence ,i don't think it is difficulty to read it !
|
|
June 14, 2006, 09:39 |
Re: FORTRAN
|
#6 |
Guest
Posts: n/a
|
If it wasn't, what was the solution? Because, I have some cases like that. Any clue?
Is this easier in MATLAB? Thanks Rose |
|
June 14, 2006, 12:23 |
Re: FORTRAN
|
#7 |
Guest
Posts: n/a
|
You don't need to worry about it. Formatted input data is something very common in Fortran and any other programming languages. If you need to "break" data in a reading statement you only need to know the data type (integer, character, real*4, real*8) the data width (how many columns) and set the formatted input accordingly with the FORMAT command as I suggested in my first post.
Hope it helps you Regards Renato. ps.: Go through some Fortran user's guide on the session describing the FORMAT command that I'm sure you'll find a bunch of examples to guide you. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Fortran Compiler-CFX12.1 | Araz | CFX | 13 | March 27, 2017 06:37 |
Intrinsic Procedure 'ISNAN' in GNU FORTRAN 77 | hawk | Main CFD Forum | 1 | April 12, 2005 23:13 |
visual fortran | Monica | Main CFD Forum | 1 | August 28, 2004 21:45 |
Fortran77 or Fortran 90 | Swapnil | CFX | 2 | November 26, 2002 16:16 |
Why Favoring Fortran over C/C++? | Zi-Wei Chiou | Main CFD Forum | 35 | September 26, 2001 10:34 |