It is currently Thu Mar 28, 2024 1:04 pm


All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Reading from file
PostPosted: Thu Aug 04, 2011 7:28 am 

Joined: Thu Jul 14, 2011 5:10 am
Posts: 2
Real Name: Pavel
Began Programming in MUMPS: 01 Jul 2011
Hi,
i have problem in MUMPS(GT.M implementation) with reading from file, i still have error on reading past EOF. Pls can you give me some example how to read whole file from disk?
Thank you.


Top
Offline Profile  
 
 Post subject: Re: Reading from file
PostPosted: Mon Aug 08, 2011 3:30 am 

Joined: Thu Jul 14, 2011 5:10 am
Posts: 2
Real Name: Pavel
Began Programming in MUMPS: 01 Jul 2011
Now i figure it out, like this:
Code:
input="/home/pavel/file"
o input:readonly
s i=1
f  u intput q:$zeof r line  d
. s ^data(i)=line
. s i=i+1

But why its still read one more line? So file has 10 lines, but in global i have 11 nodes? After that i have to kill last one.


Top
Offline Profile  
 
 Post subject: Re: Reading from file
PostPosted: Mon Aug 08, 2011 8:25 pm 
User avatar

Joined: Wed Nov 17, 2010 4:02 pm
Posts: 71
Location: Houston TX
Real Name: David Whitten
Began Programming in MUMPS: 06 Jan 1982
[code]
SET input="/home/pavel/file"
o input:readonly
s i=1
f u intput q:$zeof r line d
. s ^data(i)=line
. s i=i+1
[/code]

Your code above starts with i=1, and increments i to "get ready" for the next
time through the loop (when you will SET ^data(i) )
but when there is no data, you quit the loop, ending up with a value for i that
is one value too big.

If your code had been
[code]
SET input="/home/pavel/file"
o input:readonly
s i=0
f u intput q:$zeof r line d
. s i=i+1
. s ^data(i)=line
[/code]

You would have only incremented i just before it was used, and the value of the variable i
would track how many lines are filled, rather than one more than that.

Hope I didn't help you do a homework assignment, but it is simple enough that I think you could figure this out without my help, so I decided to help.

David
PS: I really don't think you had 11 nodes in the global. just i=11


Top
Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 22 guests


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net