-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanarr.pro
68 lines (65 loc) · 2.11 KB
/
cleanarr.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
;------------------------------------------------------------------------------
; NAME: CLEANARR
;
; PURPOSE: To remove all unprintable characters from the given string
;
; CALLING SEQUENCE: Result = CLEANARR (textarr, [/SPACE])
;
; INPUTS:
; Text: array of scalar strings of characters to be cleaned
; OUTPUTS:
; Result: array of scalar string of characters removed of all unprintable
; characters
;
; OPTIONAL INPUTS:
; SPACE: removes all unprintable characters including all space chars.
;
; EXAMPLE:
; To remove all unprintable chars except space
; IDL> arr = ['the [tab]file','is [lf][cr]']
; IDL> word = CLEANARR (arr)
; IDL> print, word
; the file is
; To remove all unprintable chars including space
; IDL> word = CLEANARR (arr,/SPACE)
; IDL> print, word
; thefile is
;
; PROCEDURES USED: CLEAN
;
; MODIFICATION HISTORY:
; Written by: Puneet Khetarpal [October 2, 2003]
; For a complete list of modifications, see changelog.txt file.
;
;------------------------------------------------------------------------------
function cleanarr, textarr, SPACE = space
; determine whether space keyword is set:
space = keyword_set(space)
; determine the type and dimensions of textarr:
stat = size(textarr)
dim = stat[0]
if (dim eq 1) then begin ; clean array for 1-D array
i = long(0)
imax = stat[1] - 1
while (i le imax) do begin
textarr[i] = (space) ? clean(textarr[i], /space) : clean(textarr[i])
i += 1
endwhile
endif else if (dim eq 2) then begin ; clean array for 2-D array
i = long(0)
j = long(0)
imax = stat[1] - 1
jmax = stat[2] - 1
while (i le imax) do begin
while (j le jmax) do begin
textarr[i,j] = (space) ? clean(textarr[i,j], /space) : $
clean(textarr[i,j])
j += 1
endwhile
i += 1
endwhile
endif else if (dim eq 0) then begin ; clean array of scalar string
textarr = (space) ? clean(textarr, /space) : clean(textarr)
endif
return, textarr
end