replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - READ 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 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: Wed Aug 20, 2008 11:13 am    Post subject: READ error Reply with quote

Hi,

I�m opening a file with arrays in this way:

2008-08-13 00:00:00,20.86,20.86,18.56,30.32,30.1,29.54,22.45,36.5,0,16.95

I create a read statement that reads all except seconds, the format is this one:

500 FORMAT(f4.0,4(1x,f2.0),3x,10(f5.2))

The point is, when I PRINT an array, it looks like this:
2008.00 8.0000 13.0000 0.0000 0.0000 0.0000 20.8600 0.0000 20.8600 0.0000 18.5600 0.0000 30.3200 0.0000 30.1000

THere is "0.0000" between numbers that appears magicly!!!, I can�t short it out by myself, any suggestion is welcomed!! Please!!!

thanks
best regards
Back to top
View user's profile Send private message Send e-mail
IanLambley



Joined: 17 Dec 2006
Posts: 506
Location: Sunderland

PostPosted: Wed Aug 20, 2008 8:57 pm    Post subject: Reply with quote

Try this:
Code:

      winapp
      integer*4 iyear,imonth,iday,ih,im,is
      real*4 data(10)
      open(unit=10,file='data.txt',status='old')
!line in data.txt contains:
!2008-08-13 00:00:00,20.86,20.86,18.56,30.32,30.1,29.54,22.45,36.5,0,16.95
      read(10,500)iyear,imonth,iday,ih,im,is,data
  500 format(i4,5(1x,i2),1x,10(f12.0))
      print *,iyear,imonth,iday,ih,im,is,data
      close(unit=10)
      end


First, the year, month, day, hours, minutes and seconds are really integer and in fixed format, hence the first integer part of the read format.


Reading these first items effectively positions the input pointer at the first comma, which is interpreted as being the end of the first REAL data item, so to overcome this, put in a 1x to align the free format (comma separated) read with the first fractional data item. I have then used larger F formats which appear to expect no decimal places. This can be important on some compilers, which use the actual alignment of the data and place it in the appropriate digit positions. This is however overwritten by the decimal point and the comma overrides the length of the characters being input. By putting f12.0, it allows up to 12 characters to be read and right aligns them in the field, resulting in a correct value if no decimal place is present. This was what I was taught to do back in 1973 on the ICL 1900 series computer and it still seems to work.

Regards

Ian
Back to top
View user's profile Send private message Send e-mail
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