-
Notifications
You must be signed in to change notification settings - Fork 1
/
v_listpds.pro
166 lines (151 loc) · 6.23 KB
/
v_listpds.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Function V_ListPDS, Dimen0, COUNT=count, SILENT = silent, NODELIMITER = Nodelimiter, KEEP_SPACES=keep_spaces
;+ $Id: v_listpds.pro,v 1.10 2013/11/05 13:31:27 sophie Exp $
;
; NAME:
; V_ListPDS
;
; PURPOSE:
; Extract values from a list in a PDS label, and return them in an array
;
; CALLING SEQUENCE:
; result = V_ListPDS(DIMEN)
;
; INPUTS:
; Dimen = Value found in PDS label for keywords such as CORE_ITEMS
; Should look like '(n1,n2,n3,...)' or '{n1,n2,n3,...}'
; Normally an output of v_pdspar routine. Unchanged on output
;
; OUTPUTS:
; result = A N-element integer vector with values in order of apparition.
; Returns -1 (scalar) if Dimen is not correctly formatted.
; Values are converted to digits if possible.
;
; OPTIONAL OUTPUTS:
; COUNT - Optional keyword to return the number of values found
; in the string. Equals -1 if Dimen is not correctly formatted.
; (no longer used)
;
; WARNING:
; Print a message if the list is uncomplete, ie does not end with a ')'
; This may means that the list of values written on several lines, and
; should be provided completely (or that the list is followed by a unit).
;
; KEYWORDS:
; SILENT - Disable warning messages
; NODELIMITER - If set, removes string delimiters (double quotes) around
; _single_ values extracted from a list
; KEEP_SPACES - don't remove internal spaces, OK to process lists of strings
; - default is to remove all spaces in each element
;
; EXAMPLES:
; To extract axes names of a Qube (values from AXIS_NAME list):
;
; IDL> Nax = v_listpds(v_pdspar(h, 'AXIS_NAME'))
;
; MODIFICATION HISTORY:
; Written: Stephane Erard, IAS, Sept. 2000
; Updated, SE, Nov 2000 :
; - Always returns a vector of integers if values are bytes
; Updated, SE, LESIA, June 2005:
; - Returns input argument if not a list, but maintains error code
; Updated, SE, LESIA, Nov 2007:
; - Now supports PDS lists in round brackets (not ordered), mainly
; to process SOFTWARE_VERSION_ID
; Updated, SE, LESIA, Nov 2012:
; - No longer print message if scalar
; Updated, SE, LESIA, March 2017:
; - Added NODELIMITER option to remove quotes from individual values
; Updated, SE, LESIA, July 2017:
; - Added KEEP_SPACES option (for PDS slib)
;-
;
;###########################################################################
;
; LICENSE
;
; Copyright (c) 1999-2008, StŽphane Erard, CNRS - Observatoire de Paris
; All rights reserved.
; Non-profit redistribution and non-profit use in source and binary forms,
; with or without modification, are permitted provided that the following
; conditions are met:
;
; Redistributions of source code must retain the above copyright
; notice, this list of conditions, the following disclaimer, and
; all the modifications history.
; Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions, the following disclaimer and all the
; modifications history in the documentation and/or other materials
; provided with the distribution.
; Neither the name of the CNRS and Observatoire de Paris nor the
; names of its contributors may be used to endorse or promote products
; derived from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
;--------------------------------------------------------------------
KEEP_SPACES = keyword_set(KEEP_SPACES)
Dimen=strcompress(Dimen0, remove=~KEEP_SPACES)
debut=strmid(dimen,0,1)
length = strlen(dimen)-1
fin=strmid(dimen,length,1)
if debut EQ '{' then begin ; process round brackets
StrPut, dimen, '(', 0
Pos = StrPos(dimen, '}', 0)
StrPut, dimen, ')', Pos
debut=strmid(dimen,0,1)
fin=strmid(dimen,length,1)
endif
if debut NE '(' then goto, perdu
if fin NE ')' then begin
length = length +1
pb =1
if NOT keyword_set(silent) then message, $
'WARNING - Uncomplete list of values ('+dimen+')', /INF
endif
dimen = strmid(dimen,1,length-1)
if (!version.release GE 5.3) then begin
Dim = strtrim(strsplit(dimen, ',', /extract), 2)
count = (size(dim))(1)
endif else begin
Dim=strarr(100)
count = 0
while length GT 0 do begin
count= count+1
rightp = strpos(dimen,',')
if rightp EQ -1 then rightp = strlen(dimen)
Dim(count-1) = strmid(dimen,0,rightp)
length = strlen(dimen) - rightp
dimen = strmid(dimen,rightp+1,length)
endwhile
Dim = Dim(0:count-1)
endelse
a = v_str2num(Dim(0), type=type)
if type EQ 1 then type = 2
Dim0 = Make_array(count, type=type)
For i=0, count-1 do Dim0(i) = v_str2num(Dim(i))
If keyword_set(NODELIMITER) then begin
for i=0, count-1 do begin
bid = (strsplit(Dim0(i), '"', /extract, count=nbid))(0)
if nbid EQ 1 then Dim0(i) = bid
endfor
Endif
return, Dim0
perdu:
; Dim0 = [-1] ; returns nothing if arg is not a list
; count = -1
!ERR = -1
Dim0 = Dimen0
count = 1
; if NOT keyword_set(silent) then message, $
; 'WARNING - Value ('+dimen+') is not a list', /INF
return, Dim0
END