Blame view

src/idl_extern/CMTotal_for_Dustemwrap/profree.pro 1.81 KB
517b8f98   Annie Hughes   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
;+
; NAME:
;   PROFREE
;
; AUTHOR:
;   Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770
;   craigm@lheamail.gsfc.nasa.gov
;
; PURPOSE:
;   Free the pointers associated with an PRODIS abstract syntax tree
;
; CALLING SEQUENCE:
;   PROFREE, TREE
;   
; DESCRIPTION: 
;
;   PROFREE frees the memory and pointers associated with an abstract
;   syntax tree, as returned by PRODIS.  Users should use this
;   procedure when they are finished with an abstract syntax tree and
;   want to release its resources.  The procedure frees all pointers
;   in the tree recursively.
;
; INPUTS:
;
;   TREE - the abstract syntax tree to be freed.  Upon return the
;          contents of TREE will be undefined.
;  
;
; SEE ALSO:
;
;   PRODIS, PROREND, CMSAVEDIR, CMSVLIB
;
; MODIFICATION HISTORY:
;   Written, 2000-2002, CM
;   Documented, 19 Mar 2002, CM
;   
;
; $Id: profree.pro,v 1.3 2002/03/19 21:45:02 craigm Exp $
;
;-
; Copyright (C) 2000-2002, Craig Markwardt
; This software is provided as is without any warranty whatsoever.
; Permission to use, copy, modify, and distribute modified or
; unmodified copies is granted, provided this copyright and disclaimer
; are included unchanged.
;-

pro profree, tree
  if n_params() EQ 0 then begin
      message, 'USAGE:', /info
      message, '  PROFREE, TREE', /info
      return
  endif

  if n_elements(tree) EQ 0 then return

  sz = size(tree)
  if sz(sz(0)+1) NE 8 then return

  for i = 0, n_elements(tree)-1 do begin
      if tag_names(tree(i), /structure_name) EQ 'PDS_NODE' then begin
          for j = 0, 2 do begin
              if ptr_valid(tree(i).operands(j)) then $
                if n_elements(*tree(i).operands(j)) GT 0 then $
                profree, *tree(i).operands(j)
          endfor
          ptr_free, tree(i).operands
      endif
  endfor
  tree = 0
  dummy = temporary(tree)
end