Blame view

src/idl_extern/CMTotal_for_Dustemwrap/dxprint.pro 3.69 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
;+
; NAME:
;   DXPRINT
;
; AUTHOR:
;   Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770
;   craigm@lheamail.gsfc.nasa.gov
;
; PURPOSE:
;   Perform HELP equivalent at any point in IDL call stack
;
; CALLING SEQUENCE:
;   DXPRINT, X0, X1, ... [, LEVEL=LEVEL, FORMAT=FORMAT ]
;
; DESCRIPTION: 
;
;   DXPRINT prints the values of variables from any level in the IDL
;   call stack.
;
;   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.
;
; INPUTS:
;
;   Xi - variables to be printed, unquoted.  Non-string expressions
;        are printed, but of course refer to the deepest call level.
;
; KEYWORDS:
;
;   LEVEL - the call level to be examined, if not the current
;           debugging focus.
;
;   FORMAT - format string to be applied to data values.
;
;
; EXAMPLE:
;
;   dxprint, a, b
;
;   Print A and B from the current debugging focus level
;
; SEE ALSO:
;
;   DXUP, DXDOWN, DXHELP, DXPRINT
;
; MODIFICATION HISTORY:
;   Written, 15 Apr 2000
;   Corrected FORMAT statement, 30 Jun 2001
;
;  $Id: dxprint.pro,v 1.3 2001/06/30 19:56:04 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 dxprint, x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, format=format, $
             level=level0
@dxcommon.pro

  catch, catcherr
  if catcherr NE 0 then begin
      catch, /cancel
      return
  endif

  dxlreset

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

  ;; Temporary values are stored here
  s0 = 0 & s1 = 0 & s2 = 0 & s3 = 0 & s4 = 0 & s5 = 0 & s6 = 0
  s7 = 0 & s8 = 0 & s9 = 0

  cmd = 'print'  ;; This will be the ultimate print command
  lev = routine_names(/level)
  levnames = routine_names(variables=level)

  dxplevel, /current
  if n_params() EQ 0 then return
  for i = 0, n_params()-1 do begin

      ;; Retrieve the value of the variable
      ii = strtrim(i,2)
      name = ''
      if execute('name = routine_names(x'+ii+',arg_name=lev-1)') EQ 1 then $
        begin
          name = name(0)
          ;; Check to be sure there was an actual name
          if name EQ '' then begin
              print, 'WARNING: Argument X'+ii+' is not a variable name'
              goto, FAILED
          endif

          ;; Find the name in the level's variable list
          name = strupcase(name)
          wh = (where(name EQ levnames))(0)
          if wh LT 0 then begin
              print, 'WARNING: Variable '+name+' does not exist at level '+ $
                strtrim(level,2)
              goto, FAILED
          endif

          ;; Check for undefined
          sz = size(routine_names(name, fetch=level))
          if sz(sz(0)+1) EQ 0 then begin
              print, 'WARNING: Variable '+name+' is undefined'
              goto, FAILED
          endif

          ;; Retrieve the value, and place it in an "S" variable
          ss = routine_names(name, fetch=level)
          if execute('s'+ii+' = temporary(ss)') NE 1 then begin
              print, 'WARNING: Could not retrieve value of '+name
              goto, FAILED
          endif
          cmd = cmd + ', s'+ii
      endif else begin
          print, 'WARNING: Argument X'+ii+' could not be found'
          FAILED:
          cmd = cmd + ", ''"
      endelse
  endfor

  ;; Add formatting if needed, and then print
  if n_elements(format) GT 0 then cmd = cmd + ', format=format(0)'
  result = execute(cmd)

  return
end