forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Logical Error with READ

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
kdangel



Joined: 31 Dec 2008
Posts: 6

PostPosted: Thu Jan 08, 2009 8:23 pm    Post subject: Logical Error with READ Reply with quote

I'm trying to read 4 values from a file into 4 REAL arrays.

4 FORMAT(7F12.3)
DO 20 I=3,11
JJ = I-1
READ(ICR,4) a(I), b(I), c(JJ), d(JJ)
20 CONTINUE

However, more than one element in the array is being updated at a time (or during one iteration through the loop). For instance, a(I)=file_value and a(I-2)=0. For each iteration, the (I-2) element is being assigned 0. It's really funky behavior that I can't figure out. Does anyone know the possible cause?

update: a(I-2) = d(JJ) AND d(JJ+2) = a(I) weird, why is the READ statement swapping these values?
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Fri Jan 09, 2009 12:11 pm    Post subject: Reply with quote

Not enough code in there for anyone to help. Where are the arrays declared? What sort of info is in the file?

Eddie
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Fri Jan 09, 2009 1:37 pm    Post subject: Reply with quote

I agree with Eddie, however, what the first iteration of this program will do is to read four values from the first line of the file, and it will only do this correctly if the data in the file is arranged:

1. in columns of 12 characters wide, or
2. each column is less than 12 characters and is separated with a comma and has decimal points present

When working out formats, I find it useful to use F for a fractional column,I for integer, X for space etc, and if two similar formats are adjacent, then alternate the case.
For example, the format expects 7F12.3 looks like with some examples under it:
Code:

ffffffff.fffFFFFFFFF.FFFffffffff.fffFFFFFFFF.FFFffffffff.fffFFFFFFFF.FFFffffffff.fff
  9               25           40            123
9,25,40,123
9.,25.,40.,123.

For the first example, you might expect results of 9, 25, 40 & 123, but you will probably get 90000, 25, 4 & 0.123
The second example overrides the spacing, but on reading pushes everthing right to the edge of each format and the result will be 0.009, 0.025, 0.040 & 0.123.
The third example also overidded the position of the decimal place and you will get the correct input. On input, it is better to use a wide format with zero decimal places, like 4F20.0, and override it with commas, the decimal places for whole numbers are not then required, but supplying a decimal place will also work for fractional values.

That said, the program only reads four values from each line as each sequential read starts at the start of a new line.

If the data in your file was for example, using values of the form "row.column" for easy identification of the results.

1.1, 1.2, 1.3, 1.4
2.1, 2.2, 2.3, 2.4
3.1, 3.2, 3.3, 3.4
.
.
.
.
.
9.1, 9.2, 9.3, 9.4

Then the arrays would be filled thus:
Code:

I    A(I)   B(I)   C(I)   D(I)
 1   undef  undef  undef  undef
 2   undef  undef  1.3    1.4
 3   1.1    1.2    2.3    2.4
 4   2.1    2.2    3.3    3.4
 5   3.1    3.2    4.3    4.4
 6   4.1    4.2    5.3    5.4
 7   5.1    5.2    6.3    6.4
 8   6.1    6.2    7.3    7.4
 9   7.1    7.2    8.3    8.4
10   8.1    8.2    9.3    9.4
11   9.1    9.2    undef  undef


The dimensions of A, B, C & D are assumed to be A(11), B(11), C(11) & D(11) or greater.

I hope this helps.

Regards

Ian
PS, forgot to say, instead of a format number in the read, use an asterisk.
Back to top
View user's profile Send private message Send e-mail
kdangel



Joined: 31 Dec 2008
Posts: 6

PostPosted: Tue Jan 13, 2009 1:39 am    Post subject: Reply with quote

I found the problem. Thank you.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group