User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Programming question (fortran) Page [1]  
Wraith
All American
27257 Posts
user info
edit post

When I was at school I was pretty damn good with fortran but now at work I have come across something that I haven't quite encountered before. It is pissing the hell out of me because it is such a simple thing and I feel like the answer is right in front of me. Say I have a data file with numbers in it like as follows:

3 7 0 9 8 3 5 2

How can I determine how many numbers are in that row? I need to essentially put these into an array but I can't allocate it without knowing how many numbers there are to begin with. Any ideas? It seems like I've tried everything.

I essentially need it to move over a line instead of down a line when reading within a loop.

[Edited on August 7, 2007 at 3:00 PM. Reason : ]

8/7/2007 2:57:48 PM

sarijoul
All American
14208 Posts
user info
edit post

do you know that they're going to be a single digit?

8/7/2007 3:11:30 PM

Wraith
All American
27257 Posts
user info
edit post

No they won't be single digit, more than likely they will be at least 6 or 7 digits. I just used single digit in this thread for simplicity.

8/7/2007 3:15:10 PM

sarijoul
All American
14208 Posts
user info
edit post

if all the numbers are of the same length, then you could do a character read-in and then query the length and do the requisite math. and then you can step back (rewind or some such command) and then read the correct number of reals from the line.

8/7/2007 3:18:13 PM

sarijoul
All American
14208 Posts
user info
edit post

now that i think about it, they wouldn't even need to be the same length. you just have a character variable whose length is definitely going to be longer than the length. you then read in the line. trim the end (i think trim is the right name for that). then get the length. then you can eliminate the blank spaces between the numbers (again i don't remember the exact names for these functions). you can take the length again and the difference would give you the (number of elements - 1).

[Edited on August 7, 2007 at 3:35 PM. Reason : so i might be wrong about the second step. looking farther into it]

8/7/2007 3:22:31 PM

DirtyMonkey
All American
4269 Posts
user info
edit post

I've never used Fortran myself, but I did a quick search for string tokenizer and came across this program that might help:

ftp://ftp.simtel.net/pub/simtelnet/msdos/fortran/token.for

8/7/2007 3:39:29 PM

scud
All American
10804 Posts
user info
edit post

why fortran..... ?

you can do this in 1 line in pretty much any modern scripting language

Ruby:
irb(main):001:0> line = "3 7 0 9 3 5 2"
=> "3 7 0 9 3 5 2"
irb(main):002:0> line.split(" ").size
=> 7

8/7/2007 7:26:42 PM

humandrive
All American
18286 Posts
user info
edit post

count the number spaces?

if (char = " ") then
x=x+1
else
...

^or that.

[Edited on August 7, 2007 at 7:43 PM. Reason : didn't really read that.]

8/7/2007 7:42:35 PM

sarijoul
All American
14208 Posts
user info
edit post

^yeah, that's what i figured out yesterday after i was off tww, but you'd have to make sure that the next character isn't a space (because in normal formatted output, there are two spaces before positive numbers).

8/8/2007 10:14:56 AM

LimpyNuts
All American
16859 Posts
user info
edit post

what dirtymonkey posted is pretty much exactly what he wants.

8/8/2007 10:41:05 AM

 Message Boards » Tech Talk » Programming question (fortran) Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.