Blame view

src/idl_extern/CMTotal_for_Dustemwrap/dxset.pro 3 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
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
119
120
;+
; NAME:
;   DXSET
;
; AUTHOR:
;   Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770
;   craigm@lheamail.gsfc.nasa.gov
;
; PURPOSE:
;   Sets IDL variable in a different IDL call level
;
; CALLING SEQUENCE:
;   DXSET, 'NAME', VALUE    ; quoted variable name (OR)
;   DXSET,  NAME,  VALUE    ; unquoted variable name
;
; DESCRIPTION: 
;
;   DXSET sets a variable value at any point in the IDL call stack.
;   The DXGET and DXSET routines allow any variable at any level to be
;   examined and changed.
;
;   The call level to be examined is determined by the current
;   debugging "focus."  By default this is the deepest level in the
;   call stack -- where the breakpoint occurred.  However, this level
;   can be changed by using the DXUP and DXDOWN procedures.
;
;   If the variable doesn't exist, then an error message is reported,
;   and the variable is not set.
;
; INPUTS:
;
;   NAME - the name of the variable, either quoted or unquoted.
;
;   VALUE - the new value of the variable.
;
; KEYWORDS:
;
;   LEVEL - the call level to be examined, if not the current
;           debugging focus.
;
; EXAMPLE:
;
;   dxset, 'a', 5
;
;   Set the value of the variable A to 5 in the currently debugged
;   call level.
;
; SEE ALSO:
;
;   DXGET, DXSET, DXUP, DXDOWN
;
; MODIFICATION HISTORY:
;   Written, 15 Apr 2000
;
;  $Id: dxset.pro,v 1.2 2001/02/09 04:57:18 craigm Exp $
;
;-
; Copyright (C) 2000, 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 dxset, vname, value, level=level0
@dxcommon.pro

  if n_params() LT 2 then begin
      USAGE_MESSAGE:
      print, "USAGE:"
      print, "  dxset, 'NAME', VALUE   ; named variable"
      print, "  dxset,  NAME,  VALUE   ; without quotes"
      return
  endif

  if n_elements(level0) EQ 0 then level0=dblevel
  level = floor(level0(0))

  pass = 1
  ;; Retrieve variable name
  sz = size(vname)
  if sz(sz(0)+1) EQ 7 then begin
      name = vname(0)
  endif else begin
      RETRY_NAME:
      thislev = routine_names(/level)
      name = routine_names(vname, arg_name=thislev-1)
      if n_elements(name) LT 1 then goto, USAGE_MESSAGE
      name = name(0)
  endelse
  if name EQ '' then begin
      if pass GE 2 then goto, NO_EXIST_ERROR
      goto, USAGE_MESSAGE
  endif
  name = strupcase(name)

  vars = routine_names(variables=level)
  wh = where(name EQ vars, ct)
  if ct EQ 0 then begin
      NO_EXIST_ERROR:
      if pass EQ 2 then begin
          if n_elements(name0) EQ 0 then name0 = name
          print, 'ERROR: Variable '+name0+' does not exist at level '+ $
            strtrim(level, 2)
          return
      endif
      name0 = name
      pass = pass + 1
      goto, RETRY_NAME
  endif

  catch, catcherr
  if catcherr NE 0 then begin
      catch, /cancel
      print, 'ERROR: '+name+' could not be set'
      return
  endif

  dummy = routine_names(name, value, store=level)
  return
end