Re: Requested change to "SAVE" procedure [message #82855] |
Tue, 22 January 2013 13:19  |
Haje Korth
Messages: 651 Registered: May 1997
|
Senior Member |
|
|
Sounds like a can of worms to me if command behavior from the command line is different from that executed in code. I would not touch that. Just my 2 cents.
On Tuesday, January 22, 2013 10:50:43 AM UTC-5, lef...@gmail.com wrote:
> I've been wanting this for a while:
>
>
>
> Sometimes I type save and (for a variety of reasons)overwrite an old idslave file that I didn't want to overwrite. What I'd like to see is the default behavior include a query to the user if a) no filename is provided (i.e. the idlsave.dat file is going to be used) and b) the command is issued from the command line. This should prevent accidental over-writes but not impact program behavior.
>
>
>
> What would be the negative implications of such a change? Are others interested in this modification?
>
>
>
> Exelisvis: Is this possible?
|
|
|
|
|
Re: Requested change to "SAVE" procedure [message #82868 is a reply to message #82867] |
Tue, 22 January 2013 08:51   |
Phillip Bitzer
Messages: 223 Registered: June 2006
|
Senior Member |
|
|
How about rolling your own? This certainly not complete, but feel free to change/modfy/improve from here. RIght now, it just tests if the file exists and issues an error. (BTW, you'll need Coyote's Error_message.pro to run it...or you could change the error handler).
Cheers,
Phillip
PRO mysave, var1, var2, var3, _extra = extra
compile_opt idl2
;error catcher:
CATCH, theError
IF theError NE 0 THEN BEGIN
CATCH, /cancel
ok = ERROR_MESSAGE(TRACEBACK=1, QUIET=1)
RETURN
ENDIF
IF N_TAGS(extra) NE 0 THEN BEGIN ;make sure some keywords were defined
ind = WHERE(STREGEX(TAG_NAMES(extra), '^f', /FOLD_CASE, /EXTRACT), count) ;find the filename tag
file = extra.(ind)
ENDIF ELSE file = 'idlsave.dat' ;this is the default of IDL's SAVE pro
IF FILE_TEST(file) THEN MESSAGE, 'File exists!'
save, var1, var2, var3, _extra=extra
END
;main level program for testing:
a = findgen(10)
mysave, a, f='hello.sav', /var
END
|
|
|
|
Re: Requested change to "SAVE" procedure [message #82934 is a reply to message #82867] |
Wed, 23 January 2013 09:33  |
Matthew
Messages: 18 Registered: February 2006
|
Junior Member |
|
|
> If "accidental" overwrites are that big of an issues for you, how come
> you are not checking that the file exists before you try to create it --
> and thus clobber existing ones?
The SAVE command works without any arguments. If SAVE is called without arguments, I would assume that the user wants a new file, not to overwrite existing files. In this case, a '-001' appended to the filename seems like the right move. Either that, or make FILENAME required.
If SAVE is called with the FILENAME keyword, then clobbering should take place. It is definitely the user's fault this time.
My two cents...
|
|
|