Commit 92080b54f0adea374892e3b25a8d99a5b432831e

Authored by Jean-Philippe Bernard
1 parent 7ad43aa5
Exists in master

removed

Showing 1 changed file with 0 additions and 293 deletions   Show diff stats
src/idl_misc/readcol.pro deleted
... ... @@ -1,293 +0,0 @@
1   -; -----------------------------------------------------------------------------
2   -;
3   -; Copyright (C) 1997-2008 Krzysztof M. Gorski, Eric Hivon, Anthony J. Banday
4   -;
5   -;
6   -;
7   -;
8   -;
9   -; This file is part of HEALPix.
10   -;
11   -; HEALPix is free software; you can redistribute it and/or modify
12   -; it under the terms of the GNU General Public License as published by
13   -; the Free Software Foundation; either version 2 of the License, or
14   -; (at your option) any later version.
15   -;
16   -; HEALPix is distributed in the hope that it will be useful,
17   -; but WITHOUT ANY WARRANTY; without even the implied warranty of
18   -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19   -; GNU General Public License for more details.
20   -;
21   -; You should have received a copy of the GNU General Public License
22   -; along with HEALPix; if not, write to the Free Software
23   -; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24   -;
25   -; For more information about HEALPix see http://healpix.jpl.nasa.gov
26   -;
27   -; -----------------------------------------------------------------------------
28   -pro readcol,name,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15, $
29   - v16,v17,v18,v19,v20,v21,v22,v23,v24,v25, $
30   - FORMAT = fmt, DEBUG=debug, SILENT=silent, SKIPLINE = skipline, $
31   - NUMLINE = numline, DELIMITER = delimiter, COMMENT = comment
32   -;+
33   -; NAME:
34   -; READCOL
35   -; PURPOSE:
36   -; Read a free-format ASCII file with columns of data into IDL vectors
37   -; EXPLANATION:
38   -; Lines of data not meeting the specified format (e.g. comments) are
39   -; ignored. Columns may be separated by commas or spaces.
40   -;
41   -; Use READFMT to read a fixed-format ASCII file. Use RDFLOAT for
42   -; much faster I/O (but less flexibility). Use FORPRINT to write
43   -; columns of data (inverse of READCOL).
44   -;
45   -; CALLING SEQUENCE:
46   -; READCOL, name, v1, [ v2, v3, v4, v5, ... v25 ,
47   -; DELIMITER= ,FORMAT = , /DEBUG , /SILENT , SKIPLINE = , NUMLINE =,
48   -; COMMENT= ]
49   -;
50   -; INPUTS:
51   -; NAME - Name of ASCII data file, scalar string. In VMS, an extension of
52   -; .DAT is assumed, if not supplied.
53   -;
54   -; OPTIONAL INPUT KEYWORDS:
55   -; FORMAT - scalar string containing a letter specifying an IDL type
56   -; for each column of data to be read. Allowed letters are
57   -; A - string data, B - byte, D - double precision, F- floating
58   -; point, I - integer, L - longword, Z - longword hexadecimal,
59   -; and X - skip a column.
60   -;
61   -; Columns without a specified format are assumed to be floating
62   -; point. Examples of valid values of FMT are
63   -;
64   -; 'A,B,I' ;First column to read as a character string, then
65   -; 1 column of byte data, 1 column integer data
66   -; 'L,L,L,L' ;Four columns will be read as longword arrays.
67   -; ' ' ;All columns are floating point
68   -;
69   -; If a FORMAT keyword string is not supplied, then all columns are
70   -; assumed to be floating point.
71   -;
72   -; /SILENT - Normally, READCOL will display each line that it skips over.
73   -; If SILENT is set and non-zero then these messages will be
74   -; suppressed.
75   -; /DEBUG - If this keyword is non-zero, then additional information is
76   -; printed as READCOL attempts to read and interpret the file.
77   -; DELIMITER - single character specifying delimiter used to separate
78   -; columns. Default is either a comma or a blank.
79   -; SKIPLINE - Scalar specifying number of lines to skip at the top of file
80   -; before reading. Default is to start at the first line.
81   -; NUMLINE - Scalar specifying number of lines in the file to read.
82   -; Default is to read the entire file
83   -; COMMENT - Scalar string : lines beginning with this string are ignored
84   -; (case sensitive)
85   -;
86   -; OUTPUTS:
87   -; V1,V2,V3,...V25 - IDL vectors to contain columns of data.
88   -; Up to 25 columns may be read. The type of the output vectors
89   -; are as specified by FORMAT.
90   -;
91   -; EXAMPLES:
92   -; Each row in a file position.dat contains a star name and 6 columns
93   -; of data giving an RA and Dec in sexigesimal format. Read into IDL
94   -; variables. (NOTE: The star names must not contain internal spaces.)
95   -;
96   -; IDL> FMT = 'A,I,I,F,I,I,F'
97   -; IDL> READCOL,'position.dat',F=FMT,name,hr,min,sec,deg,dmin,dsec
98   -;
99   -; The HR,MIN,DEG, and DMIN variables will be integer vectors.
100   -;
101   -; Alternatively, all except the first column could be specified as
102   -; floating point.
103   -;
104   -; IDL> READCOL,'position.dat',F='A',name,hr,min,sec,deg,dmin,dsec
105   -;
106   -; To read just the variables HR,MIN,SEC
107   -; IDL> READCOL,'position.dat',F='X,I,I,F',HR,MIN,SEC
108   -;
109   -; RESTRICTIONS:
110   -; This procedure is designed for generality and not for speed.
111   -; If a large ASCII file is to be read repeatedly, it may be worth
112   -; writing a specialized reader.
113   -;
114   -; Columns to be read as strings must not contain the delimiter character
115   -; (i.e. commas or spaces by default). Either change the default
116   -; delimiter with the DELIMITER keyword, or use READFMT to read such files.
117   -;
118   -; Numeric values are converted to specified format. For example,
119   -; the value 0.13 read with an 'I' format will be converted to 0.
120   -;
121   -; PROCEDURES CALLED
122   -; GETTOK(), NUMLINES(), REPCHR(), STRNUMBER(), ZPARCHECK
123   -;
124   -; REVISION HISTORY:
125   -; Written W. Landsman November, 1988
126   -; Modified J. Bloch June, 1991
127   -; (Fixed problem with over allocation of logical units.)
128   -; Added SKIPLINE and NUMLINE keywords W. Landsman March 92
129   -; Read a maximum of 25 cols. Joan Isensee, Hughes STX Corp., 15-SEP-93.
130   -; Call NUMLINES() function W. Landsman Feb. 1996
131   -; Added DELIMITER keyword W. Landsman Nov. 1999
132   -; Fix indexing typos (i for k) that mysteriously appeared W. L. Mar. 2000
133   -; Hexadecimal support added. MRG, RITSS, 15 March 2000.
134   -;
135   -; added keyword comment
136   -;-
137   - On_error,2 ;Return to caller
138   -
139   - if N_params() lt 2 then begin
140   - print,'Syntax - readcol, name, v1, [ v2, v3,...v25, '
141   - print,' FORMAT= ,/SILENT ,SKIPLINE =, NUMLINE = , /DEBUG]'
142   - return
143   - endif
144   -
145   -; Get number of lines in file
146   -
147   - nlines = NUMLINES( name )
148   - if nlines LT 0 then return
149   -
150   - if keyword_set(DEBUG) then $
151   - message,strupcase(name)+' contains ' + strtrim(nlines,2) + ' lines',/INF
152   -
153   - if not keyword_set( SKIPLINE ) then skipline = 0
154   - nlines = nlines - skipline
155   - if keyword_set( NUMLINE) then nlines = numline < nlines
156   -
157   - ncol = N_params() - 1 ;Number of columns of data expected
158   - vv = 'v' + strtrim( indgen(ncol)+1, 2)
159   - nskip = 0
160   -
161   - if N_elements(fmt) GT 0 then begin ;FORMAT string supplied?
162   -
163   - zparcheck, 'READCOL', fmt, 2, 7, 0, 'FORMAT string'
164   -; Remove blanks from format string
165   - frmt = strupcase(strcompress(fmt,/REMOVE))
166   - remchar, frmt, '(' ;Remove parenthesis from format
167   - remchar, frmt, ')'
168   -
169   -; Determine number of columns to skip ('X' format)
170   - pos = strpos(frmt, 'X', 0)
171   -
172   - while pos NE -1 do begin
173   - pos = strpos( frmt, 'X', pos+1)
174   - nskip = nskip + 1
175   - endwhile
176   -
177   - endif else begin ;Read everything as floating point
178   -
179   - frmt = 'F'
180   - if ncol GT 1 then for i = 1,ncol-1 do frmt = frmt + ',F'
181   - if not keyword_set( SILENT ) then message, $
182   - 'Format keyword not supplied - All columns assumed floating point',/INF
183   -
184   - endelse
185   -
186   - nfmt = ncol + nskip
187   - idltype = intarr(nfmt)
188   -
189   -; Create output arrays according to specified formats
190   -
191   - k = 0L ;Loop over output columns
192   - hex = bytarr(nfmt)
193   - for i = 0L, nfmt-1 do begin
194   -
195   - fmt1 = gettok( frmt, ',' )
196   - if fmt1 EQ '' then fmt1 = 'F' ;Default is F format
197   - case strmid(fmt1,0,1) of
198   - 'A': idltype[i] = 7
199   - 'D': idltype[i] = 5
200   - 'F': idltype[i] = 4
201   - 'I': idltype[i] = 2
202   - 'B': idltype[i] = 1
203   - 'L': idltype[i] = 3
204   - 'Z': begin
205   - idltype[i] = 3 ;Hexadecimal
206   - hex[i] = 1b
207   - end
208   - 'X': idltype[i] = 0 ;IDL type of 0 ==> to skip column
209   - ELSE: message,'Illegal format ' + fmt1 + ' in field ' + strtrim(i,2)
210   - endcase
211   -
212   -; Define output arrays
213   -
214   - if idltype[i] NE 0 then begin
215   - st = vv[k] + '= make_array(nlines,TYPE = idltype[i] )'
216   - tst = execute(st)
217   - k = k+1
218   - endif
219   -
220   - endfor
221   -
222   - openr, lun, name, /get_lun
223   - ngood = 0L
224   -
225   - temp = ' '
226   - if skipline GT 0 then $
227   - for i = 0, skipline-1 do readf, lun, temp ;Skip any lines
228   -
229   - if n_elements(comment) eq 0 then comment=''
230   - lencom = strlen(comment)
231   - for j = 0L, nlines-1 do begin
232   -
233   - readf, lun, temp
234   -;; if strlen(temp) LT ncol then begin ;Need at least 1 chr per output line
235   - if (strlen(temp) LT ncol) or (lencom gt 0 and strmid(temp,0,lencom) eq comment) then begin ; modified by EH
236   - ngood = ngood-1
237   - if not keyword_set(SILENT) then $
238   - message,'Skipping Line ' + strtrim(skipline+j+1,2),/INF
239   - goto, BADLINE
240   - endif
241   - if not keyword_set(delimiter) then begin
242   - temp = repchr(temp,',',' ') ;Replace comma delimiters by spaces
243   - delimiter = ' '
244   - endif
245   - k = 0
246   -
247   - for i = 0L,nfmt-1 do begin
248   -
249   - temp = strtrim(temp,1) ;Remove leading spaces
250   - var = gettok(temp,delimiter) ;Read next field
251   - if ( idltype[i] NE 0 ) then begin ;Expecting data?
252   -
253   - if ( idltype[i] NE 7 ) then begin ;Check for valid numeric data
254   - tst = strnumber(var,val,hex=hex[i]) ;Valid number?
255   - if tst EQ 0 then begin ;If not, skip this line
256   - if not keyword_set(SILENT) then $
257   - message,'Skipping Line ' + strtrim(skipline+j+1,2),/INF
258   - ngood = ngood-1
259   - goto, BADLINE
260   - endif
261   - st = vv[k] + '[ngood] = val'
262   -
263   - endif else $
264   - st = vv[k] + '[ngood] = strtrim(var,2)'
265   -
266   - tst = execute(st)
267   - k = k+1
268   -
269   - endif
270   -
271   - endfor
272   -
273   -BADLINE: ngood = ngood+1
274   -
275   - endfor
276   -
277   - free_lun,lun
278   - if ngood EQ 0 then begin
279   - message,'ERROR - No valid lines found for specified format',/INFORM
280   - return
281   - endif
282   -
283   - if not keyword_set(SILENT) then $
284   - message,strtrim(ngood,2) + ' valid lines read', /INFORM
285   -
286   -; Compress arrays to match actual number of valid lines
287   -
288   - for i = 0,ncol-1 do begin
289   - tst = execute(vv[i] + '='+ vv[i]+ '[0:ngood-1]')
290   - endfor
291   -
292   - return
293   - end