Computing.Net > Forums > Programming > read from a file... Fortran or C

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

read from a file... Fortran or C

Reply to Message Icon

Name: DaveA
Date: January 20, 2002 at 17:00:47 Pacific
Comment:

Hi there,

I'm trying to read data from a file that looks like this:

0 0 0 0 0 12 46 133.4 2374.4 123.3 12 9 0 0
0 0 0 0 0 etc etc...

Into a 2D-array in either C or Fortran (preferably Fortran, and F77).

The file has 128 numbers on each row (space separated) and is 128 lines deep, so I want a 128 x 128 2D array.

Anyone have any ideas? I have made a little progress, but I don't know enough about fgets (in C) or the READ command (in F77), or about string manipulation to get my head around it.

Many thanks,
Dave A



Sponsored Link
Ads by Google

Response Number 1
Name: Apple
Date: January 24, 2002 at 12:59:51 Pacific
Reply:

fgets will read a long of N characters UNTIL
it reaches a newline (\n). IE. this will
strip one line at a time from your file for
the command: fgets( string, 256, fp );
assuming no lines are greater than 256
characters long.

After that, it's just a matter of picking the
numbers off the front of the string and
finding the next space. Pointers are your
friends.


0

Response Number 2
Name: yassine
Date: March 25, 2002 at 08:17:29 Pacific
Reply:

read a matrix 2*2 by fortran 90

appreciate your help


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: read from a file... Fortran or C

Reading from a text file in C++ www.computing.net/answers/programming/reading-from-a-text-file-in-c/8983.html

Reading from a file and executing www.computing.net/answers/programming/reading-from-a-file-and-executing/19675.html

batch file - reading from a file www.computing.net/answers/programming/batch-file-reading-from-a-file/19110.html