comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Changing File Size with OPENU?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Changing File Size with OPENU? [message #10203] Tue, 28 October 1997 00:00
Peter Mason is currently offline  Peter Mason
Messages: 145
Registered: June 1996
Senior Member
On Tue, 28 Oct 1997, Peter Mason wrote:
<...>
> So, anyway, when changing from a read to a write (or vice versa) on the
> same file unit, you should always do something like:
> POINT_LUN, -lun, junk

Sorry, this won't work as it's just equivalent to C's ftell().
What you need is:
POINT_LUN,-lun,junk & POINT_LUN,lun,junk


Peter Mason
Re: Changing File Size with OPENU? [message #10210 is a reply to message #10203] Tue, 28 October 1997 00:00 Go to previous message
Jack Saba is currently offline  Jack Saba
Messages: 30
Registered: January 1996
Member
I get the same behavior under both IDL 4 and IDL 5.0.2. However, when I
removed the READU, and changed the point_lun to

POINT_LUN, LUN, 14400+2400

the final file size was the same as the initial file size.


--
Jack Saba <jack@magus.stx.com>


Wayne Landsman wrote:
>
> I always thought that when opening a file with OPENU that the file
> wouldn't
> change size, unless one wrote past the end of the file. But below I
> give an
> example of a file changing size, even though I never reached the end of
> the
> file.
>
> I suspect this might be a IDL (or Solaris 2.6) bug, because if I
> uncomment the
> ;print,fstat(lun) line below, then the file size stays unchanged. But
> I
> don't trust my thought process right now after spending 3 hours trying
> to track
> down this bug. Anybody know if the behaviour in the example below is
> expected?
>
> --Wayne Landsman
> landsman@mpb.gsfc.nasa.gov
>
> ; IDL Version 5.0.2 (sunos sparc)
>
> ;Create a 250000 byte file
>
> openw,lun,'tester.dat',/get_lun
> writeu,lun,bytarr(250000)
> close,lun
>
> ;Make sure it really is 250000 bytes
>
> spawn,'ls -l tester.dat'
> ;-rw-r--r-- 1 landsman 250000 Oct 26 08:13 tester.dat
>
> ;Now open file for update and move
> ; 14400 + 2400 + 230000 = 246800 bytes into the file
>
> openu,lun,'tester.dat'
> point_lun,lun,14400 ;Offset to 14400 bytes
> b = bytarr(2400)
> readu,lun,b ;Now read 2400 bytes
> ;print,fstat(lun)
> writeu,lun,bytarr(230000) ;Now write 230000 bytes
> free_lun,lun
> spawn,'ls -l tester.dat' ;And file has changed size!!
>
> -rw-r--r-- 1 landsman 254992 Oct 26 08:13 tester.dat
Re: Changing File Size with OPENU? [message #10212 is a reply to message #10203] Tue, 28 October 1997 00:00 Go to previous message
Peter Mason is currently offline  Peter Mason
Messages: 145
Registered: June 1996
Senior Member
On Mon, 27 Oct 1997, Wayne Landsman wrote:
> I always thought that when opening a file with OPENU that the file wouldn't
> change size, unless one wrote past the end of the file. But below I give an
> example of a file changing size, even though I never reached the end of the
> file.
>
> I suspect this might be a IDL (or Solaris 2.6) bug, because if I uncomment
> the ;print,fstat(lun) line below, then the file size stays unchanged.
> Anybody know if the behaviour in the example below is expected?
<example cut>


The size change also happens on Digital Unix 4.0A with IDL 4.0.1 (and earlier
versions).
I wasn't surprised by this behaviour in IDL, having first been totally freaked
out by it in the C world. (I found out about it the hard way.) In C, you
have to do a fseek() or fflush() in between changing from a read to a write
(or vice versa) on the same streamed file unit, otherwise things just go wrong.
(At least C documentation on fopen() usually points this out.)

IDL's normal I/O routines are based on C routines, and I guess that this is
why they have the same problem. (IDL's POINT_LUN is equivalent to a fseek().
Also, I guess that FSTAT() incorporates a seek.)
It would be nice if the IDL docs mentioned this somewhere.


So, anyway, when changing from a read to a write (or vice versa) on the
same file unit, you should always do something like:
POINT_LUN, -lun, junk
or, as you've tried, an FSTAT(),
or possibly FLUSH,lun.



Peter Mason
CSIRO division of Exploration and Mining
P.O Box 136, North Ryde, NSW, 2113, Australia
E-Mail: p.mason@syd.dem.csiro.au Tel: +61 2 9490-8883 Fax: 9490-8960/8921
Web: http://www.syd.dem.csiro.au/research/MMTG/
Re: Changing File Size with OPENU? [message #10215 is a reply to message #10203] Mon, 27 October 1997 00:00 Go to previous message
Wayne Landsman is currently offline  Wayne Landsman
Messages: 117
Registered: January 1997
Senior Member
William Thompson wrote:
>
> Wayne:
>
> I confirm this behaviour in IDL/v4.0.1 on a DEC Alpha workstation running
> OSF/v4, including the difference in behavior when the "print,fstat(lun)" line
> is uncommented. I can't see how a simple print statement to the terminal
> screen could be expected to affect file I/O, so it must be a bug.
>
> Have you tried writing something other than zeroes to the file? Do the bytes
> go where you expected them to, or to some other location. Is the file simply
> padded out with extra unwanted zeroes, with random values, or with data?
>
What appears to be happening is that the WRITEU statement does not
begin writing at the current position in the file, but first skips 8192
bytes. If I was working under VMS, with its complicated file
structure, I would blame this behaviour on some sort of record
boundary. But since it occurs with Unix files, there must be an
internal IDL bug in the way that WRITEU works on files opened with
OPENU.

--Wayne Landsman
landsman@mpb.gsfc.nasa.gov
Re: Changing File Size with OPENU? [message #10219 is a reply to message #10215] Mon, 27 October 1997 00:00 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
Wayne:

I confirm this behaviour in IDL/v4.0.1 on a DEC Alpha workstation running
OSF/v4, including the difference in behavior when the "print,fstat(lun)" line
is uncommented. I can't see how a simple print statement to the terminal
screen could be expected to affect file I/O, so it must be a bug.

Have you tried writing something other than zeroes to the file? Do the bytes
go where you expected them to, or to some other location. Is the file simply
padded out with extra unwanted zeroes, with random values, or with data?

Bill

============================================================ ===================
Wayne Landsman <landsman@mpb.gsfc.nasa.gov> writes:

> I always thought that when opening a file with OPENU that the file
> wouldn't
> change size, unless one wrote past the end of the file. But below I
> give an
> example of a file changing size, even though I never reached the end of
> the
> file.

> I suspect this might be a IDL (or Solaris 2.6) bug, because if I
> uncomment the
> ;print,fstat(lun) line below, then the file size stays unchanged. But
> I
> don't trust my thought process right now after spending 3 hours trying
> to track
> down this bug. Anybody know if the behaviour in the example below is
> expected?

> --Wayne Landsman
> landsman@mpb.gsfc.nasa.gov


> ; IDL Version 5.0.2 (sunos sparc)

> ;Create a 250000 byte file

> openw,lun,'tester.dat',/get_lun
> writeu,lun,bytarr(250000)
> close,lun

> ;Make sure it really is 250000 bytes

> spawn,'ls -l tester.dat'
> ;-rw-r--r-- 1 landsman 250000 Oct 26 08:13 tester.dat

> ;Now open file for update and move
> ; 14400 + 2400 + 230000 = 246800 bytes into the file

> openu,lun,'tester.dat'
> point_lun,lun,14400 ;Offset to 14400 bytes
> b = bytarr(2400)
> readu,lun,b ;Now read 2400 bytes
> ;print,fstat(lun)
> writeu,lun,bytarr(230000) ;Now write 230000 bytes
> free_lun,lun
> spawn,'ls -l tester.dat' ;And file has changed size!!

> -rw-r--r-- 1 landsman 254992 Oct 26 08:13 tester.dat
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Lost Functions
Next Topic: Re: Memory linits for Unix IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:21:34 PDT 2025

Total time taken to generate the page: 0.01013 seconds