cmsv_ptrsum.pro
3.45 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
;+
; NAME:
; CMSV_PTRSUM
;
; AUTHOR:
; Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770
; craigm@lheamail.gsfc.nasa.gov
;
; PURPOSE:
; Construct an inventory of heap data accessible to a variable
;
; CALLING SEQUENCE:
; CMSV_PTRSUM, VAR, LIST
;
; DESCRIPTION:
;
; This procedure constructs an inventory of heap data that is
; accessible to a single variable. It searches all array elements,
; recursively through structure tags, and by dereferencing pointers.
; Users can use this procedure to determine all heap variables that
; need to be saved to disk.
;
; This procedure is part of the CMSVLIB SAVE library for IDL by
; Craig Markwardt.
;
; ==================================================================
; Research Systems, Inc. has issued a separate license intended
; to resolve any potential conflict between this software and the
; IDL End User License Agreement. The text of that license
; can be found in the file LICENSE.RSI, included with this
; software library.
; ==================================================================
;
; INPUTS:
;
; VAR - the variable to be examined
;
; LIST - upon output, an array of pointers, each of which points to
; a heap variable accessible to VAR. If there are no heap
; data pointed to by VAR, then LIST returns a NULL value.
;
; KEYWORDS:
;
; NULL - if set, return the null value in LIST instead of the
; pointer list. VAR is ignored.
;
; HAS_OBJECTS - upon return, the value is 1 if VAR contains or
; points to an object reference, and 0 if not.
;
;
; EXAMPLE:
;
;
; SEE ALSO:
;
; CMRESTORE, SAVE, RESTORE, CMSVLIB
;
; MODIFICATION HISTORY:
; Written, 2000
; Documented, 24 Jan 2001
; Make version checks with correct precision, 19 Jul 2001, CM
; Added notification about RSI License, 13 May 2002, CM
;
; $Id: cmsv_ptrsum.pro,v 1.7 2002/05/13 06:41:10 craigm Exp $
;
;-
; Copyright (C) 2000-2001, 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 cmsv_ptrsum, data, result, null=null0, has_objects=hobj
forward_function ptr_new
common cmsv_ptrsum_data, version, null
if n_elements(version) EQ 0 then version = double(!version.release)
if version LT 5D then begin
result = 0L
return
endif
if n_elements(null) EQ 0 then null = ptr_new()
if keyword_set(null0) then begin
data = null
return
endif
pd = null
sz = size(data)
tp = sz(sz(0)+1)
if tp EQ 8 then begin
for i = 0L, n_tags(data(0))-1 do begin
cmsv_ptrsum, data.(i), x, has_objects=hobj
sz = size(data.(i))
if sz(sz(0)+1) EQ 11 then hobj = 1
if n_elements(x) GT 1 then pd = [pd, x] $
else if x(0) NE null then pd = [pd, x]
endfor
endif else if tp EQ 10 then begin
pd = [pd, data(*)]
for i = 0, n_elements(data)-1 do begin
wh = where(data(i) EQ pd, ct)
if ct EQ 0 then begin ;; Prevent cycles!!!
cmsv_ptrsum, *(data(i)), x
sz = size(*(data(i)))
if sz(sz(0)+1) EQ 11 then hobj = 1
if n_elements(x) GT 1 then pd = [pd, x] $
else if x(0) NE null then pd = [pd, x]
endif
endfor
endif
if n_elements(pd) GT 1 then pd = pd(uniq(pd, sort(pd)))
result = pd
return
end