replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Read format error
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 

Read format error

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



Joined: 22 May 2008
Posts: 20

PostPosted: Thu Sep 04, 2008 5:28 pm    Post subject: Read format error Reply with quote

Hi,

I found the following problem:
I�m reading an array of data like:
10180
10209.5
10229.1
10239

In the FORMAT statement I specified f7.1
the point is that I read and I get the following result:
1018.0
10209.5
10229.1
1023.9

Is like with that format, always writes with decimal even when it�s not,
what should I do to short it out???
Thanks very much

Best regards
RCA
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8252
Location: Salford, UK

PostPosted: Thu Sep 04, 2008 10:36 pm    Post subject: Reply with quote

I am not sure why you are getting this result.
Perhaps in reality the are some leading spaces in the field.

Anyway, the usual approach is to use "list-directed" input which
means using an asterisk in place of the format string.
Back to top
View user's profile Send private message AIM Address
JohnCampbell



Joined: 16 Feb 2006
Posts: 2620
Location: Sydney

PostPosted: Fri Sep 05, 2008 1:01 am    Post subject: Reply with quote

Use format f7.0. This should fix the problem of implied decimal points.
You should also check the use of bz or bn, as this would have changed the interpretation of 10180.

Try the following example:
character string*7, fmt*10
real x
!
string = '10180 '
!
fmt = '(bz,f7.0)'; read (string, fmt=fmt) x; write (*,*) x, ' ', fmt
fmt = '(bz,f7.1)'; read (string, fmt=fmt) x; write (*,*) x, ' ', fmt
fmt = '(bn,f7.0)'; read (string, fmt=fmt) x; write (*,*) x, ' ', fmt
fmt = '(bn,f7.1)'; read (string, fmt=fmt) x; write (*,*) x, ' ', fmt
end
Back to top
View user's profile Send private message
kingkastle



Joined: 22 May 2008
Posts: 20

PostPosted: Fri Sep 05, 2008 9:56 am    Post subject: Reply with quote

Umm, I see,
I undertand but the problem is that I have a matrix of around 8000x15 data.., there is not a method to automatice this problem.
I think I should talk with the data provider in order to get the data always with decimal, even when is .0

Paul, I used the *, but the program crashs,
I �m reading a file like:
2008-09-01 00:05:25,-1,-1,-1,-1,-1,-1,10.597,5940,-1,-1,-1
2008-09-01 00:05:38,6191.58,127.864,-1,-1,-1,-1,10.6544,5970,-1,-1,-1
2008-09-01 00:05:51,6201,186.879,-1,-1,-1,-1,12.6394,5940,-1,-1,-1
2008-09-01 00:06:04,6211.25,206.55,-1,-1,-1,-1,15.3091,5970,-1,-1,-1

And I use the format:
(i4, 4(1x,i2),4x,7f9.2,4f9.2)

It�s a difficult problem, as you can see, there is INTEGER and REAL in the same position:
-1
6191.58
6201
6211.25

The "-1" don�t mind, becasue means no data and I created and statment that turn it to "0.00" when is read "-0.01" ( In this formtat, fortran reads ---0.01 insted of -1), but the "6201" is a real problem, because reads "620.1" and I�m doing some averages....
I will talk with the data provider, I think there is not a automaticaly way to short it out

Thanks very much for your responses

Warmest regards
RCA
Back to top
View user's profile Send private message Send e-mail
kingkastle



Joined: 22 May 2008
Posts: 20

PostPosted: Fri Sep 05, 2008 10:42 am    Post subject: Reply with quote

I don�t know how or why, but I tried the format:

(i4, 4(1x,i2),4x,7f9.0,4f9.0)

As Campbell suggested and YES!!!!!!!!!!!, finally solves the problem!!!!!

But I don�t understand why solves

Eternally grateful for your support!!!!
best regards
RCA
Back to top
View user's profile Send private message Send e-mail
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Fri Sep 05, 2008 11:16 am    Post subject: Reply with quote

RCA,

I would read each line as a character string, then process this string as follows:-

The date and time part is of a constant length and format, so this can be read using a fixed format on an internal read. After reading the date and time fill this part of the character string with spaces. Then using a simple loop check each character of the remaining string to see if they are a comma or not, and replace commas with a space. Finally use the free format * to read the rest of the string.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support 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