-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconvert_codes.pro
79 lines (77 loc) · 2.04 KB
/
convert_codes.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
FUNCTION CONVERT_CODES,codein
;-----------------------------------------------------------------
;+
; NAME:
; CONVERT_CODES
;
; PURPOSE:
; Convert C-printf-Style format code to Fortran format code
;
; CATEGORY:
; PDS processing
;
; CALLING SEQUENCE:
; result = convert_codes(codein)
;
; INPUTS:
; codein - a string or string array of C-style format codes.
;
; OUTPUTS:
; Returns a string or string array of Fortran style format codes
; (for use in IDL readf and printf statements).
;
; PROCEDURES USED:
; Built-in, only.
;
; PACKAGE LOCATION:
; http://www.astro.umd.edu/~eshaya/PDS/pds4readxml.tar
;
; MODIFICATION HISTORY:
; Written by Ed Shaya / U. of Maryland [Nov. 7, 2013]
;
;-
;-----------------------------------------------------------------
; If first character is %-sign, remove it
ncodes = N_ELEMENTS(codein)
result = STRARR(ncodes)
FOR i = 0, ncodes-1 DO BEGIN
leftJustify = ''
plusPrefix = ''
code = codein[i]
; Remove '%' as first character
IF (STRPOS(code,'%') EQ 0) THEN code = STRMID(code,1)
; Last character determines datatype
datatype = STRMID(code,0,/reverse_offset)
; Remove last character from code
code = STRMID(code,0,strlen(code)-1)
; Check first two characters for "+-" flags
; Keep track of them, but remove from code
FOR J = 0, 1 DO BEGIN
IF (STRPOS(code,'-') EQ 0) THEN BEGIN
leftJustify = '-'
code = STRMID(code,1)
ENDIF
IF (STRPOS(code,'+') EQ 0) THEN BEGIN
plusPrefix = '+'
code = STRMID(code,1)
ENDIF
ENDFOR
CASE STRLOWCASE(datatype) OF
'f': datatype = 'F'
's': datatype = 'A'
'd': datatype = 'I'
'e': datatype = 'E'
'i': datatype = 'I'
'g': datatype = 'G'
'b': datatype = 'B'
'o': datatype = 'O'
'x': datatype = 'Z'
'z': datatype = 'Z'
ELSE: print, 'convert_codes: datatype not yet handled ', datatype
ENDCASE
; For character type (A), take numbers after the decimal place
IF (DATATYPE EQ 'A') THEN code = STRMID(code,STRPOS(code,'.')+1)
result[i] = datatype + plusPrefix + leftJustify + code
ENDFOR
RETURN, result
END