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

FORTRAN

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 12, 2006, 14:24
Default FORTRAN
  #1
Rose
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

  Reply With Quote

Old   June 12, 2006, 14:41
Default Re: FORTRAN
  #2
Renato.
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.
  Reply With Quote

Old   June 12, 2006, 14:42
Default Re: FORTRAN
  #3
Renato.
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

  Reply With Quote

Old   June 13, 2006, 11:25
Default Re: FORTRAN
  #4
Rose
Guest
 
Posts: n/a
Thanks, that worked.
  Reply With Quote

Old   June 13, 2006, 21:53
Default Re: FORTRAN
  #5
ztdep
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 !
  Reply With Quote

Old   June 14, 2006, 08:39
Default Re: FORTRAN
  #6
Rose
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
  Reply With Quote

Old   June 14, 2006, 11:23
Default Re: FORTRAN
  #7
Renato.
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.

  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
Fortran Compiler-CFX12.1 Araz CFX 13 March 27, 2017 05:37
Intrinsic Procedure 'ISNAN' in GNU FORTRAN 77 hawk Main CFD Forum 1 April 12, 2005 22:13
visual fortran Monica Main CFD Forum 1 August 28, 2004 20:45
Fortran77 or Fortran 90 Swapnil CFX 2 November 26, 2002 15:16
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 13:59.