Re: Deleting Variables [message #11614] |
Fri, 24 April 1998 00:00 |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
lundblad@ugastro.berkeley.edu (Nathan Lundblad) writes:
> How does one delete variable in IDL?
> I know _delvar_, but that only works on the
> main level of the program, and only one on
> variable. I want to purge everything.
> Also, how would one delete a common block?
I don't think one can delete an entire common block. However, here is simple
routine that can delete any variable, even those in subroutines or common
blocks. Actually, it sets them to undefined, which is almost the same thing.
Bill Thompson
============================================================ ===================
pro delvarx, p0,p1,p2,p3,p4,p5,p6,p7,p8,p9
;
;+
;
; Project: SSW
;
; Name: delvarx
;
; Purpose: delete variables for memory management (can call from routines)
;
; Input Parameters:
; p0,p1...p9 - variables to delete
;
; Calling Sequence:
; delvarx, a [,b,c,d,e,f,g,h,i,j] ;deletes named variables
; ;like idl delvar, but may be used
; ;from any calling level
;
; History:
; S.L.Freeland 25-feb-1993 ; Written
; slf, 8-mar-1993 ; bug fix
; slf, 25-mar-1993 ; made it work for non-scalers!
; slf, 15-jan-1997 ; Documentataion->SSW
;
;
; Method: uses execute and temporary function
;-
for i=0, n_params()-1 do begin ;for each parameter
param=strcompress("p" + string(i),/remove)
; only delete if defined on inpu (avoids error message)
exestat = execute("defined=n_elements(" + param + ")" )
if defined gt 0 then begin
exestat = execute(param + "=0")
exestat = execute("dvar=temporary(" + param + ")" )
endif
endfor
return
end
|
|
|
Re: Deleting Variables [message #11617 is a reply to message #11614] |
Fri, 24 April 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Nathan Lundblad (lundblad@ugastro.berkeley.edu) writes:
> How does one delete variable in IDL?
>
> I know _delvar_, but that only works on the
> main level of the program, and only one on
> variable. I want to purge everything.
If you wanted to get rid of all the IDL variables that
exist at the main IDL level, you could write a program
like this:
PRO Purge
END
When you want to get rid of all main-level variables,
you would type:
IDL> .RNew Purge
If you want to get rid of a single variable within an
IDL program module (i.e., NOT at the main level), you
can download the program UNDEFINE from my web page:
Undefine, variable
If you want to get rid of all the pointers and objects
you have accidentally deleted references to, you can
type this:
IDL> Heap_GC
If you just want to get rid of *everything* (including
common blocks, which can be deleted in no other way),
most of the experts use this trick:
IDL> Exit
:-)
Cheers,
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|