1. File input.output

I would like to be able to SAVE a sequence of  floating point numbers(say a few
hundred) to a file in one PUTS and then retrieve
that data from file back into a sequence in one GETS.
Looking at the documentation of GETS it would seem that I can't.
Secondly will I be able to look at what's in the file using  Explorer to see if
I have filed the right information.
Really all I'm trying to do is to SAVE and LOAD a 'sequential file' reasonably
quickly.
Regards
Bob

new topic     » topic index » view message » categorize

2. Re: File input.output

> I would like to be able to SAVE a sequence of  floating point numbers(say a
> few hundred) to a file in one PUTS and then retrieve
> that data from file back into a sequence in one GETS.
> Looking at the documentation of GETS it would seem that I can't.
> Secondly will I be able to look at what's in the file using  Explorer to see
> if I have filed the right information.
> Really all I'm trying to do is to SAVE and LOAD a 'sequential file' reasonably
> quickly.
> Regards
> Bob

The easyest way to do this is to use print() and get():

----BEGIN CODE----
include get.e
constant data = {1.432,543.22,5278.13,99.2}
atom fn
sequence in
fn = open ("filename.ext","w") --open the file for writing
print(fn,data) --Output the data
close(fn) --Close the file
fn = open("filename.ext","r") --open the file for reading
in = get(fn) --Read the data into in
--in will not equal {erorr_status,data}
close(fn) --close the file
? in[2] --print the data to the screen
----END CODE----

Thomas Parslow (PatRat) ICQ #:26359483
Rat Software
http://www.ratsoft.freeserve.co.uk/
Please leave quoted text in place when replying

new topic     » goto parent     » topic index » view message » categorize

3. Re: File input.output

On 27 Aug 2000, at 17:23, bobspringett wrote:

> I would like to be able to SAVE a sequence of  floating point numbers(say a
> few hundred)
> to a file in one PUTS and then retrieve that data from file back into a
> sequence in one
> GETS. Looking at the documentation of GETS it would seem that I can't.
> Secondly will I be
> able to look at what's in the file using  Explorer to see if I have filed the
> right
> information. Really all I'm trying to do is to SAVE and LOAD a 'sequential
> file'
> reasonably quickly. Regards Bob
>

Explorer is the disk viewer, it's not a file viewer. If you mean Internet
Exploder, add the
<html> tags, and use the .htm or .html file extension, and IE will open the file
for
display when you click on it in Explorer. I use IE only for viewing text with
different
fonts, scaling, specific text placement, or tables, which may be good for
checking your
numbers, since you can easily scroll them, and display them in colors denoting a
range, such as too high = red, and too low = chartruse, and just right = green,
you
know, like bowls of porridge in The Three Bears....

Kat,
going to lay down now....

new topic     » goto parent     » topic index » view message » categorize

4. Re: File input.output

> On 27 Aug 2000, at 17:23, bobspringett wrote:
>
> > I would like to be able to SAVE a sequence of  floating point
numbers(say a few hundred)
> > to a file in one PUTS and then retrieve that data from file back into=
 a
sequence in one
> > GETS. Looking at the documentation of GETS it would seem that I can't.
Secondly will I be
> > able to look at what's in the file using  Explorer to see if I have
filed the right
> > information. Really all I'm trying to do is to SAVE and LOAD a
'sequential file'
> > reasonably quickly. Regards Bob

Hello Bob,

Although print() and get() will do the job, I recommend you to take a loo=
k
at bget.e by Gabri=EBl Boehme. You can find it in the Euphoria archives, =
and
it *is* much faster then these inbuild Euphoria functions, plus the
resulting datafiles are much smaller. And, BTW, it's 'stamped' too.
Data are save in 'binary' format. Only problem is that you cannot 'view'
binary files very easy, especially floating point numbers.

I use it in the following way, in a seperate loadsave.e include file:

-- loadsave.e file:

include bget.e

global function load(sequence filename, sequence mode)
integer file
object data
    file =3D open(filename, mode)
    if file =3D -1 then
        data =3D {}
    else
        data =3D bget(file)
        if data[1] =3D GET_SUCCESS then
            data =3D data[2]
        end if
        close(file)
    end if
    return data
end function    -- load
-------------------------------------------------------------------------=
---
---
global procedure save(sequence data, sequence filename, sequence mode)
integer file
    file =3D open(filename, mode)
    if file =3D -1 then
        puts(1, "\nFout in outputfile!")
    else
        bprint(file, data)
        close(file)
    end if
end procedure   -- save

-- end of loadsave.e

Regards,    Ad

new topic     » goto parent     » topic index » view message » categorize

5. Re: File input.output

On Sun, 27 Aug 2000, BOB wrote:
> I would like to be able to SAVE a sequence of  floating point numbers(say a
> few hundred) to a file in one PUTS and then retrieve
> that data from file back into a sequence in one GETS.
> Looking at the documentation of GETS it would seem that I can't.
> Secondly will I be able to look at what's in the file using  Explorer to see
> if I have filed the right information.
> Really all I'm trying to do is to SAVE and LOAD a 'sequential file' reasonably
> quickly.
> Regards

It looks like you've gotten several answers, but based on your requirements,
I also to suggest  using print() and get().  It's quick and easy, and hard ato
break.

--  tested code:
include get.e
object numbers
 numbers = {1.23, 3.14159, 6, 8, -23.5, 12.99}

atom fn
fn = open("my.dat","w")
print(fn, numbers)
close(fn)

fn = open("my.dat","r")
numbers = get(fn)
close(fn)
if numbers[1] = GET_SUCCESS then
   numbers = numbers[2]
else
  puts(1,"ERROR READING FILE")
end if
? numbers

If you plan to store lots of strings in your files, you really need to
downloading Gabriel Boehme's PRINT.E - this small library causes the print()
function to write text in plain, human readable form, while still being
readable by Euphoria's get() function.

I have been using this method for many months in several commercial programs
without any  problems These programs typically read (modify) and write files of
about half a meg hundreds of times each day.

By the way, these files will be plain text, so probably NotePad or similar
would be just fine for viewing them.

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

6. Re: File input.output

Thanks very much Irv,
Regards
Bob
----- Original Message -----
From: irv <irv at ELLIJAY.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Sunday, August 27, 2000 9:42 PM
Subject: Re: File input.output


> On Sun, 27 Aug 2000, BOB wrote:
> > I would like to be able to SAVE a sequence of  floating point numbers(say a
> > few hundred) to a file in one PUTS and then retrieve
> > that data from file back into a sequence in one GETS.
> > Looking at the documentation of GETS it would seem that I can't.
> > Secondly will I be able to look at what's in the file using  Explorer to see
> > if I have filed the right information.
> > Really all I'm trying to do is to SAVE and LOAD a 'sequential file'
> > reasonably quickly.
> > Regards
>
> It looks like you've gotten several answers, but based on your requirements,
> I also to suggest  using print() and get().  It's quick and easy, and hard ato
> break.
>
> --  tested code:
> include get.e
> object numbers
>  numbers = {1.23, 3.14159, 6, 8, -23.5, 12.99}
>
> atom fn
> fn = open("my.dat","w")
> print(fn, numbers)
> close(fn)
>
> fn = open("my.dat","r")
> numbers = get(fn)
> close(fn)
> if numbers[1] = GET_SUCCESS then
>    numbers = numbers[2]
> else
>   puts(1,"ERROR READING FILE")
> end if
> ? numbers
>
> If you plan to store lots of strings in your files, you really need to
> downloading Gabriel Boehme's PRINT.E - this small library causes the print()
> function to write text in plain, human readable form, while still being
> readable by Euphoria's get() function.
>
> I have been using this method for many months in several commercial programs
> without any  problems These programs typically read (modify) and write files
> of
> about half a meg hundreds of times each day.
>
> By the way, these files will be plain text, so probably NotePad or similar
> would be just fine for viewing them.
>
> Regards,
> Irv

new topic     » goto parent     » topic index » view message » categorize

7. Re: File input.output

Irv,
Had a further look at your suggestions. Couldn't quite understand the purpose of
the line numbers=numbers[2]. Seems as though your
saying the sequence numbers is now = the second item in numbers.
A further point. I've made up a short code along the lines of your suggestion
and a strange thing is happening. The codes generates
some floating point data which round limits to 2 decimal places, it saves O.K
and gives a length of 10.
However when I load the data into the sequence testData and print it a further
couple of braces has slipped in and the length is now
two.
I've omitted the round function and I still get the same thing happening. Would
you mind commenting on it for me please.
CODE:
--include misc.e
include file.e
include get.e
include print.e
include round.e
with trace
--trace(1)

sequence y
atom x

y={}
atom filenum
sequence testData
for i=1 to 10 do
x=rand(999)+i/9
x=round(x,2)
y=y & x
end for
filenum=open("c:\\euphoria\\tester.txt","w")
print(filenum,y)
close(filenum)
print(1,"Finished filing")
print(1,y)
 sleep(10)
 print(1,"                                                          ")
 filenum=open("c:\\euphoria\\tester.txt","r")
testData=get(filenum)
close(filenum)
print(1,testData)
print(1,"Finished loading and displaying")
sleep(10)
----- Original Message -----
From: irv <irv at ELLIJAY.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Sunday, August 27, 2000 9:42 PM
Subject: Re: File input.output


> On Sun, 27 Aug 2000, BOB wrote:
> > I would like to be able to SAVE a sequence of  floating point numbers(say a
> > few hundred) to a file in one PUTS and then retrieve
> > that data from file back into a sequence in one GETS.
> > Looking at the documentation of GETS it would seem that I can't.
> > Secondly will I be able to look at what's in the file using  Explorer to see
> > if I have filed the right information.
> > Really all I'm trying to do is to SAVE and LOAD a 'sequential file'
> > reasonably quickly.
> > Regards
>
> It looks like you've gotten several answers, but based on your requirements,
> I also to suggest  using print() and get().  It's quick and easy, and hard ato
> break.
>
> --  tested code:
> include get.e
> object numbers
>  numbers = {1.23, 3.14159, 6, 8, -23.5, 12.99}
>
> atom fn
> fn = open("my.dat","w")
> print(fn, numbers)
> close(fn)
>
> fn = open("my.dat","r")
> numbers = get(fn)
> close(fn)
> if numbers[1] = GET_SUCCESS then
>    numbers = numbers[2]
> else
>   puts(1,"ERROR READING FILE")
> end if
> ? numbers
>
> If you plan to store lots of strings in your files, you really need to
> downloading Gabriel Boehme's PRINT.E - this small library causes the print()
> function to write text in plain, human readable form, while still being
> readable by Euphoria's get() function.
>
> I have been using this method for many months in several commercial programs
> without any  problems These programs typically read (modify) and write files
> of
> about half a meg hundreds of times each day.
>
> By the way, these files will be plain text, so probably NotePad or similar
> would be just fine for viewing them.
>
> Regards,
> Irv

new topic     » goto parent     » topic index » view message » categorize

8. Re: File input.output

On Tue, 29 Aug 2000, you wrote:
> Irv,
> Had a further look at your suggestions. Couldn't quite understand the purpose
> of the line numbers=numbers[2]. Seems as though your
> saying the sequence numbers is now = the second item in numbers.

That's because it is. The first item in the return is an integer, equalling
either GET_SUCCESS (a good thing) GET_FAIL (not good at all), or
GET_EOF (no more objects in that file to read). Once you've examined the
first part to see if things worked ok, then you can either display an error
message, quit, create a new file, as appropriate, or just use the numbers
in the rest of your program.

 > A further point.
I've made up a short code along the lines of your suggestion and a strange
thing is happening. The codes generates > some floating point data which round
limits to 2 decimal places, it saves O.K and gives a length of 10. > However
when I load the data into the sequence .......

Mostly, I think, this is a mixup using print() in the wrong places...
for example, print(1,testData) and print(1,"Finished loading..") is not
Euphoria syntax.  PRINT.E "bundles"  sequences and prints them to a file
in Euphoria readable format: Try running the following code, it shows the
various stages on the screen, so you can see how the data is "bundled"....

--tested code!
include file.e
include get.e
include print.e
include round.e

atom x,  filenum
sequence y, testData

-- create a sequence [array] of 10;
     y = repeat(0,10)
     for i = 1 to length(y) do
          x = rand(999)+i/9
     y[i] = round( x,2)
     end for
? y -- display it just in case;

-- write sequence to disk;
     filenum = open("tester.txt","w")
     print(filenum,y)
     close(filenum)

puts(1,"Saved this data to the file:\n")
?y -- just to verify;

-- read data back from disk;
    filenum=open("tester.txt","r")
    testData=get(filenum)
    close(filenum)

puts(1,"Displaying  data read from file: - note the {0, in front \n")
? testData -- take another look

if testData[1]  != GET_SUCCESS then abort(1) -- halt on error
else testData = testData[2]
end if

-- print one number per line, for clarity;
    for i = 1 to length(testData) do
       ? testData[i] -- you can replace these ? with printf() as desired
    end for

regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

9. Re: File input.output

Thanks Irv, very much. It's all slotted in now. What threw me was the extra bit
of formatting print.e was doing when writing to
file.
I was doing a length() on the sequence as it was 'get[ted]' from the file which
had now 2 subscripted items instead of the 1 when I sent it to file.
I'm grateful.
Regards
Bob
----- Original Message -----
From: irv <irv at ELLIJAY.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Tuesday, August 29, 2000 9:55 PM
Subject: Re: File input.output


> On Tue, 29 Aug 2000, you wrote:
> > Irv,
> > Had a further look at your suggestions. Couldn't quite understand the
> > purpose of the line numbers=numbers[2]. Seems as though
your
> > saying the sequence numbers is now = the second item in numbers.
>
> That's because it is. The first item in the return is an integer, equalling
> either GET_SUCCESS (a good thing) GET_FAIL (not good at all), or
> GET_EOF (no more objects in that file to read). Once you've examined the
> first part to see if things worked ok, then you can either display an error
> message, quit, create a new file, as appropriate, or just use the numbers
> in the rest of your program.
>
>  > A further point.
> I've made up a short code along the lines of your suggestion and a strange
> thing is happening. The codes generates > some floating point data which round
> limits to 2 decimal places, it saves O.K and gives a length of 10. > However
> when I load the data into the sequence .......
>
> Mostly, I think, this is a mixup using print() in the wrong places...
> for example, print(1,testData) and print(1,"Finished loading..") is not
> Euphoria syntax.  PRINT.E "bundles"  sequences and prints them to a file
> in Euphoria readable format: Try running the following code, it shows the
> various stages on the screen, so you can see how the data is "bundled"....
>
> --tested code!
> include file.e
> include get.e
> include print.e
> include round.e
>
> atom x,  filenum
> sequence y, testData
>
> -- create a sequence [array] of 10;
>      y = repeat(0,10)
>      for i = 1 to length(y) do
>           x = rand(999)+i/9
>      y[i] = round( x,2)
>      end for
> ? y -- display it just in case;
>
> -- write sequence to disk;
>      filenum = open("tester.txt","w")
>      print(filenum,y)
>      close(filenum)
>
> puts(1,"Saved this data to the file:\n")
> ?y -- just to verify;
>
> -- read data back from disk;
>     filenum=open("tester.txt","r")
>     testData=get(filenum)
>     close(filenum)
>
> puts(1,"Displaying  data read from file: - note the {0, in front \n")
> ? testData -- take another look
>
> if testData[1]  != GET_SUCCESS then abort(1) -- halt on error
> else testData = testData[2]
> end if
>
> -- print one number per line, for clarity;
>     for i = 1 to length(testData) do
>        ? testData[i] -- you can replace these ? with printf() as desired
>     end for
>
> regards,
> Irv

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu