Save file creation rules of the road [message #69827] |
Thu, 18 February 2010 03:30  |
Rob[2]
Messages: 11 Registered: May 2007
|
Junior Member |
|
|
Dear save file gurus,
I'm trying to create a distributable IDL save file via IDLDE > Project
> "Build Project". A save file was created without error -- some
initial complaints were issued, then automatically resolved. I then
restored this save file in a new IDL cli session. All expected
functions and procedures were listed, via "restore, /verbose" and
"help"; see below. However, an attempt to run one of the restored
procedures yielded the annoying "Variable is undefined:
SPIDR_ASCII_GET_META.... EXCEPTION..." I've experienced this before
and the hack I employed wasn't pretty. It involved compiling
(via .compile) all functions and procedures I thought I needed and
creating a save file somewhat manually, then a sacrificial lamb and a
kabuki dance. Thus, I suppose I've never really learned how to create
a proper save file with just the functionality I need. Can someone
point me in the right direction?
Debug follows:
Noting the below "help" after restore in new session, you can see for
yourself that "SPIDR_ASCII_GET_META" is defined:
Compiled Procedures:
$MAIN$ BAR_PLOT CALDAT CHECK_INIT DOC_LIBRARY
LEGEND LOADCT LOGGER LOG_DEBUG LOG_ERROR
LOG_FATAL LOG_INFO LOG_WARN MG_OPEN_URL
NGDC_BOILER PRINT_LOG_MESSAGE RESOLVE_ALL
SPIDR_CLIENT SPIDR_CRIB SPIDR_CRIB_IONO_7_DAYS
SPIDR_CRIB_IONO_EVENT SPIDR_CRIB_SENSOR_FUSION
Compiled Functions:
FGDC_TO_SIMPLE_STRUCT FILEPATH IS_STRUCT
IS_STRUCTURE JDAY_TO_TIME_8601
JDAY_TO_TIME_ARRAY JDAY_TO_UNIX_TIME JULDAY
LABEL_DATE MEAN MM MOMENT
SPIDR_ASCII_GET_META
SPIDR_ASCII_TO_STRUCTURE SPIDR_GET_DATA
SPIDR_GET_METADATA
STDDEV STRSPLIT TEST_SPIDR_ASCII_TO_STRUCTURE
TEST_SPIDR_GET_DATA TEST_SPIDR_GET_METADATA
TIME_8601_TO_ARRAY TIME_ARRAY_TO_8601 UNIQ
IDL> print, TEST_SPIDR_ASCII_TO_STRUCTURE()
% Variable is undefined: SPIDR_ASCII_GET_META.
% Execution halted at: SPIDR_ASCII_TO_STRUCTURE
% TEST_SPIDR_ASCII_TO_STRUCTURE
% $MAIN$
|
|
|
|
|
|
Re: SAVE [message #70880 is a reply to message #69827] |
Thu, 13 May 2010 14:29   |
Aram Panasenco
Messages: 41 Registered: April 2010
|
Member |
|
|
fgg wrote:
> Hi there,
>
> I'm running a procedure that has lines in it such as:
>
> (Scope_VarFetch('data', LEVEL=1, /ENTER)) = 1
>
> ... that are used to save variables to the main IDL level. I'd like to
> add a line at the end of this procedure to make it save all variables
> that were created in a *.sav file. Something like this:
>
> save, /variables, filename= '/Users/xxx/Desktop/example.sav'
>
> ... but it's not working. I'm getting in the *.sav file all other
> variables defined in the procedure, but the ones created using
> Scope_VarFetch. Any suggestions?
>
> PS: if I run the procedure first (without the save line in it) and
> then type the save line at the IDL prompt I get exactly what I want.
> Just wanted to know if it's possible to automate this process.
>
> Thank you!
Hello fgg,
scope_varfetch is a highly dangerous routine that you should only use if
there is absolutely no other alternative to implementing something
crucial (and there almost always is). Seeing as you are new, we can't
give you advice on how to use scope_varfetch because it will make your
program harder to write, more prone to errors, and, most importantly,
using scope_varfetch can interfere with other IDL programs, making your
program unusable (by you and others). Instead, can you tell us in more
detail what exactly you are trying to do so that we can show you a
better way to accomplish it. What tasks does your procedure aim to do?
~Aram Panasenco
|
|
|
|
|
|
Re: SAVE [message #70885 is a reply to message #69827] |
Thu, 13 May 2010 13:53   |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
On May 13, 4:05 pm, fgg <fabioguimaraesgoncal...@gmail.com> wrote:
> Hi there,
>
> I'm running a procedure that has lines in it such as:
>
> (Scope_VarFetch('data', LEVEL=1, /ENTER)) = 1
Isn't there an international convention, signed in
Geneva, against using such cruel practices in computer
programming code? I'd be very very careful with that...
Ciao,
Paolo
>
> ... that are used to save variables to the main IDL level. I'd like to
> add a line at the end of this procedure to make it save all variables
> that were created in a *.sav file. Something like this:
>
> save, /variables, filename= '/Users/xxx/Desktop/example.sav'
>
> ... but it's not working. I'm getting in the *.sav file all other
> variables defined in the procedure, but the ones created using
> Scope_VarFetch. Any suggestions?
>
> PS: if I run the procedure first (without the save line in it) and
> then type the save line at the IDL prompt I get exactly what I want.
> Just wanted to know if it's possible to automate this process.
>
> Thank you!
|
|
|
Re: SAVE [message #71015 is a reply to message #70873] |
Fri, 14 May 2010 13:22  |
fgg
Messages: 67 Registered: April 2010
|
Member |
|
|
Thanks a lot for the constructive comments! I was using SCOPE_VARFETCH
simply to export the variables to the main level... but I'm now
convinced that this is not a good practice. One of the suggestions I
got was to include parameters in my procedure, define the variables
within the procedure, and then call it specifying the parameters
similarly on the command line. Something like this:
pro xxx, a=a, b=b, c=c
This would add the variables of interest (a, b, and c) in main just
like SCOPE_VARFETCH does. I guess that's the usual way of doing this
and I would probably not end in jail =)... so, here we go.
Thanks again,
Fabio
|
|
|