-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmtag.pro
103 lines (94 loc) · 2.7 KB
/
rmtag.pro
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;+
;
; NAME:
; REMOVE_TAGS
;
; PURPOSE:
; remove the specified tags from input structure
;
; CALLING SEQUENCE:
; remove_tags, oldstruct, tagnames, newstruct
;
; INPUTS:
; oldstruct: the original structure
; tagnames: the names of tags to be removed (can be an array)
;
; OPTIONAL INPUTS:
; NONE.
;
; KEYWORD PARAMETERS:
; NONE.
;
; OUTPUTS:
; newstruct: the new structure without tags.
;
; OPTIONAL OUTPUTS:
; NONE
;
; CALLED ROUTINES:
;
;
; PROCEDURE:
;
;
;
; REVISION HISTORY:
; ????? Judith Racusin
; 25-OCT-2000 Modified to handle arbitrary tag types. Also error
; handling. Erin Scott Sheldon
;
;
;-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PRO remove_tags, struct, tagnames, newstruct
IF n_params() EQ 0 THEN BEGIN
print,'Syntax - remove_tags, oldstruct, tagnames, newstruct'
print
print,'Use doc_library,"remove_tags" for more help.'
return
END
;; Figure out which tags get removed
tags=get_tags(struct)
n=n_elements(tags)
tagnames=strupcase(tagnames)
nt=n_elements(tagnames)
IF nt EQ 1 THEN BEGIN
t=where(tags NE tagnames[0],nw)
IF nw EQ n THEN BEGIN
print,'-----------------------------------------------------'
message,'Tag did not match, structure unchanged',/inf
print,'-----------------------------------------------------'
newstruct = struct
return
ENDIF
ENDIF ELSE BEGIN
match,tags,tagnames,m
IF m[0] EQ -1 THEN BEGIN
print,'-------------------------------------------------'
message,'No tags matched, structure unchanged',/inf
print,'-------------------------------------------------'
newstruct=struct
return
ENDIF
nm=n_elements(m)
IF nm EQ n THEN BEGIN
print,'-------------------------------------------------------------'
message,'This would remove all tags! structure unchanged',/inf
print,'-------------------------------------------------------------'
newstruct=struct
return
ENDIF
t=lindgen(n)
remove, m, t
ENDELSE
;; create new structure
tags=tags[t]
n=n_elements(tags)
newstruct=create_struct(tags[0],struct[0].(t[0]))
FOR i=1L, n-1 DO newstruct = create_struct(temporary(newstruct), $
tags[i], struct[0].(t[i]) )
newstruct=replicate( temporary(newstruct), n_elements(struct) )
struct_assign,struct,newstruct
return
END