New programming languages

Moderators: None (Apply to moderate this forum)
Number of threads: 111
Number of posts: 329

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
reading text files in FORTRAN Posted by navid86 on 10 Aug 2009 at 1:41 PM
Hi, i have a simple question that I know is easy for most of u
I am not an expert programmer but even if u dont know FTN u may gimme a hint on the algorithm and I will figure that out how to do it in FTN

I have a file like

nx=300 ny=12 f=1e4

sad=34.2 nj=23 jb=234

and so on

now I want the code to read 300 and put it into a previous defined integer variable called nx and so on to the end of the file

should I read it character by character ??
how to go to next line??
how to ignore blanks while reading
what size should I use, as each time I may want to for instance, change the value of nx to 200

how to ignore blank lines

I appreciate if somebody can help me

Best,

inmiiz@yahoo.com
Report
Re: reading text files in FORTRAN Posted by Malcolm_McLean on 11 Aug 2009 at 5:48 AM
It's a complete nuisance, in Fortan 77 at least.
The short answer is that ypu can't, Fortran's format function only works on fixed length fields. By far the easiest solution will be to pad ypur input file with spaces and then just read in with a format.

Of course Fortran 77 is a Turing-complete programming language, which means that any computable function can be calculated if you try hard enough. So reading in as a character*1 string and processing character-by character will work (you jump to ypur integer / float prasing subroutine on hitting the first integer, and jump out of it on hitting the first non-number character).
It is extremely fiddly and almost certainly not worth your while.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.