Re: Simple File I/O [message #58388 is a reply to message #58350] |
Mon, 28 January 2008 17:38  |
Gary
Messages: 4 Registered: January 2008
|
Junior Member |
|
|
Thank for your advice. As always, very educational for the newbie such
as my self. As it turns out, I over complicated the problem for
myself. As the program is a GUI, I added a pointer to the info
structure which points to the original image. I simply dereferenced it
to a variable which was the written to the file. B/C I'm the only
person using this bit of code, and know precisely the file parameters,
I simply read in the file as part of a separate event. I guess you
could liken it to a simple jig or template in wood working. I'm sure
if I'm asked to generalize the operation, I'll make use of your TVREAD
and be back for more help. Thanks again.
-g
On Jan 25, 9:11 pm, David Fanning <n...@dfanning.com> wrote:
> Gary writes:
>> This questions stems, as much as anything, from my newness to
>> programming in general. I would like to take a pixmap my code
>> generates, save it as a file for later use, and then read it in later
>> after having restarted the code. Thus far, I've tried simply using
>> writeu and readu. The error comes when readu is reached producing the
>> error, readu: end of file encountered. I use TVRD() to generate a
>> float array from the pixmap then writeu this to a file.
>
> TVRD() doesn't generate floats. It generates bytes, and probably
> not in the way you are expecting, to be honest. So, even if this
> works, I don't think you will be happy with the results. Do you
> mean you are *casting* the results of TVRD() into floats?
>
>> This produces a file of byte format?
>
> Huh!?
>
>> On the other end, I generate a float array hard
>> coded to the same size as the original pixmap, and simply use readu
>> into the float array, whereupon I get the end of file encountered
>> error.
>
> When you make a float array, you tell IDL to read 4 bytes for each
> floating value. Since I am certain you have a byte array, you are
> running past the end of the file, which is why you are getting this
> error. You are trying to read four times as many bytes as there
> are in the file.
>
>> I think I'm missing something between the conversion between
>> the original float array to bytes and then back again.
>
> The original array was in bytes to begin with. But if you hope
> to recover your window, you will probably (unless you have an
> ancient computer) want to read a 3 by x by y array out of that
> window. If you do it the way you appear to be doing it, your
> window when it is restored will look nothing like it did when
> you saved it.
>
> I would use TVREAD and save the data in a TIFF file. Then just
> read the data from the TIFF file to recover it.
>
> http://www.dfanning.com/programs/tvread.pro
>
>> Also, fstat
>> tells me that there are four extra bytes to the number of cells in the
>> original array. 460x920 = 423200 cells, but fstat gives a file size of
>> 423204 bytes. I'm guessing its really simple and I'm just missing it.
>> Any and all help much appreciated.
>
> I don't know. Let's solve the other problems first, then deal with
> this. :-)
>
> Cheers,
>
> David
>
>
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|