pro MYREADCOL, name, $ v1, v2, v3, v4, v5, v6, v7, v8, v9, v10,$ v11, v12, v13, v14, v15, v16, v17, v18, v19, v20,$ v21, v22, v23, v24, v25, v26, v27, v28, v29, v30,$ v31, v32, v33, v34, v35, v36, v37, v38, v39, v40,$ v41, v42, v43, v44, v45, v46, v47, v48, v49, v50,$ v51, v52, v53, v54, v55, v56, v57, v58, v59, v60,$ v61, v62, v63, v64, v65, v66, v67, v68, v69, v70,$ v71, v72, v73, v74, v75, v76, v77, v78, v79, v80,$ v81, v82, v83, v84, v85, v86, v87, v88, v89, v90,$ v91, v92, v93, v94, v95, v96, v97, v98, v99,v100,$ v101,v102,v103,v104,v105,v106,v107,v108,v109,v110,$ v111,v112,v113,v114,v115,v116,v117,v118,v119,v120,$ v121,v122,v123,v124,v125,v126,v127,v128,v129,v130,$ v131,v132,v133,v134,v135,v136,v137,v138,v139,v140,$ v141,v142,v143,v144,v145,v146,v147,v148,v149,v150,$ v151,v152,v153,v154,v155,v156,v157,v158,v159,v160,$ v161,v162,v163,v164,v165,v166,v167,v168,v169,v170,$ v171,v172,v173,v174,v175,v176,v177,v178,v179,v180,$ v181,v182,v183,v184,v185,v186,v187,v188,v189,v190,$ v191,v192,v193,v194,v195,v196,v197,v198,v199,v200,$ v201,v202,v203,v204,v205,v206,v207,v208,v209,v210,$ v211,v212,v213,v214,v215,v216,v217,v218,v219,v220,$ v221,v222,v223,v224,v225,v226,v227,v228,v229,v230,$ v231,v232,v233,v234,v235,v236,v237,v238,v239,v240,$ v241,v242,v243,v244,v245,v246,v247,v248,v249,v250,$ v251,v252,v253,v254,v255,v256,v257,v258,v259,v260,$ v261,v262,v263,v264,v265,v266,v267,v268,v269,v270,$ v271,v272,v273,v274,v275,v276,v277,v278,v279,v280,$ v281,v282,v283,v284,v285,v286,v287,v288,v289,v290,$ v291,v292,v293,v294,v295,v296,v297,v298,v299,v300,$ v301,v302,v303,v304,v305,v306,v307,v308,v309,v310,$ v311,v312,v313,v314,v315,v316,v317,v318,v319,v320,$ v321,v322,v323,v324,v325,v326,v327,v328,v329,v330,$ v331,v332,v333,v334,v335,v336,v337,v338,v339,v340,$ v341,v342,v343,v344,v345,v346,v347,v348,v349,v350,$ v351,v352,v353,v354,v355,v356,v357,v358,v359,v360,$ v361,v362,v363,v364,v365,v366,v367,v368,v369,v370,$ v371,v372,v373,v374,v375,v376,v377,v378,v379,v380,$ v381,v382,v383,v384,v385,v386,v387,v388,v389,v390,$ v391,v392,v393,v394,v395,v396,v397,v398,v399,v400,$ v401,v402,v403,v404,v405,v406,v407,v408,v409,v410,$ v411,v412,v413,v414,v415,v416,v417,v418,v419,v420,$ v421,v422,v423,v424,v425,v426,v427,v428,v429,v430,$ v431,v432,v433,v434,v435,v436,v437,v438,v439,v440,$ v441,v442,v443,v444,v445,v446,v447,v448,v449,v450,$ v451,v452,v453,v454,v455,v456,v457,v458,v459,v460,$ v461,v462,v463,v464,v465,v466,v467,v468,v469,v470,$ v471,v472,v473,v474,v475,v476,v477,v478,v479,v480,$ v481,v482,v483,v484,v485,v486,v487,v488,v489,v490,$ v491,v492,v493,v494,v495,v496,v497,v498,v499,v500,$ COMMENT = comment, FORMAT = fmt, DEBUG=debug, SILENT=silent, $ SKIPLINE = skipline, NUMLINE = numline, DELIMITER = delimiter, $ COMPRESS = compress ;+ ; NAME: ; MYREADCOL ; ; NB : This is IDL astrolib's READCOL procedure modified to allow ; its use on files of up to 250 columns (rather than 25) ; ; !!! SEE BELOW FOR ORIGINAL READCOL DOCUMENTATION AND CREDITS !!! ; ; 27 Oct 2004 - Extended to 50 columns by Mattia Vaccari ; 02 Dec 2004 - Extended to 250 columns by Mattia Vaccari ; 24 May 2008 - Added 'M' format for LONG64 by Mattia Vaccari ; 17 Mar 2009 - Extended to 500 columns by Mattia Vaccari ; 31 Oct 2009 - COMPRESS keyword added by Mattia Vaccari ; ; EXTRA KEYWORDS: ; COMPRESS - if set, assumes input file is compressed using gzip ; ; PURPOSE: ; Read a free-format ASCII file with columns of data into IDL vectors ; ; EXPLANATION: ; Lines of data not meeting the specified format (e.g. comments) are ; ignored. Columns may be separated by commas or spaces. ; ; Use READFMT to read a fixed-format ASCII file. Use RDFLOAT for ; much faster I/O (but less flexibility). Use FORPRINT to write ; columns of data (inverse of READCOL). ; ; CALLING SEQUENCE: ; MYREADCOL, name, v1, [ v2, v3, v4, v5, ... v500, COMMENT= ; DELIMITER= ,FORMAT = , /DEBUG , /SILENT , SKIPLINE = , NUMLINE = ] ; ; INPUTS: ; NAME - Name of ASCII data file, scalar string. In VMS, an extension of ; .DAT is assumed, if not supplied. ; ; OPTIONAL INPUT KEYWORDS: ; FORMAT - scalar string containing a letter specifying an IDL type ; for each column of data to be read. Allowed letters are ; A - string data, B - byte, D - double precision, F- floating ; point, I - integer, L - longword, Z - longword hexadecimal, ; and X - skip a column. ; ; Columns without a specified format are assumed to be floating ; point. Examples of valid values of FMT are ; ; 'A,B,I' ;First column to read as a character string, then ; 1 column of byte data, 1 column integer data ; 'L,L,L,L' ;Four columns will be read as longword arrays. ; ' ' ;All columns are floating point ; ; If a FORMAT keyword string is not supplied, then all columns are ; assumed to be floating point. ; ; /SILENT - Normally, MYREADCOL will display each line that it skips over. ; If SILENT is set and non-zero then these messages will be ; suppressed. ; /DEBUG - If this keyword is non-zero, then additional information is ; printed as MYREADCOL attempts to read and interpret the file. ; COMMENT - single character specifying comment signal. Any line ; beginning with this character will be skipped. Default is ; no comment lines. ; DELIMITER - single character specifying delimiter used to separate ; columns. Default is either a comma or a blank. ; SKIPLINE - Scalar specifying number of lines to skip at the top of file ; before reading. Default is to start at the first line. ; NUMLINE - Scalar specifying number of lines in the file to read. ; Default is to read the entire file ; ; OUTPUTS: ; V1,V2,V3,...,V250 - IDL vectors to contain columns of data. ; Up to 250 columns may be read. The type of the output vectors ; are as specified by FORMAT. ; ; EXAMPLES: ; Each row in a file position.dat contains a star name and 6 columns ; of data giving an RA and Dec in sexigesimal format. Read into IDL ; variables. (NOTE: The star names must not include the delimiter ; as a part of the name, no spaces or commas as default.) ; ; IDL> FMT = 'A,I,I,F,I,I,F' ; IDL> MYREADCOL,'position.dat',F=FMT,name,hr,min,sec,deg,dmin,dsec ; ; The HR,MIN,DEG, and DMIN variables will be integer vectors. ; ; Alternatively, all except the first column could be specified as ; floating point. ; ; IDL> MYREADCOL,'position.dat',F='A',name,hr,min,sec,deg,dmin,dsec ; ; To read just the variables HR,MIN,SEC ; IDL> MYREADCOL,'position.dat',F='X,I,I,F',HR,MIN,SEC ; ; RESTRICTIONS: ; This procedure is designed for generality and not for speed. ; If a large ASCII file is to be read repeatedly, it may be worth ; writing a specialized reader. ; ; Columns to be read as strings must not contain the delimiter character ; (i.e. commas or spaces by default). Either change the default ; delimiter with the DELIMITER keyword, or use READFMT to read such files. ; ; Numeric values are converted to specified format. For example, ; the value 0.13 read with an 'I' format will be converted to 0. ; ; PROCEDURES CALLED ; GETTOK(), NUMLINES(), REPCHR(), STRNUMBER() ; ; MINIMUM IDL VERSION: ; V5.3 (Uses STRSPLIT) ; ; REVISION HISTORY: ; Written W. Landsman November, 1988 ; Modified J. Bloch June, 1991 ; (Fixed problem with over allocation of logical units.) ; Added SKIPLINE and NUMLINE keywords W. Landsman March 92 ; Read a maximum of 25 cols. Joan Isensee, Hughes STX Corp., 15-SEP-93. ; Call NUMLINES() function W. Landsman Feb. 1996 ; Added DELIMITER keyword W. Landsman Nov. 1999 ; Fix indexing typos (i for k) that mysteriously appeared W. L. Mar. 2000 ; Hexadecimal support added. MRG, RITSS, 15 March 2000. ; Default is comma or space delimiters as advertised W.L. July 2001 ; Faster algorithm, use STRSPLIT if V5.3 or later W.L. May 2002 ;- On_error,2 ;Return to caller if N_params() lt 2 then begin print,'Syntax - MYREADCOL, name, v1, [ v2, v3,...v250, ' print,' FORMAT= ,/SILENT ,SKIPLINE =, NUMLINE = , /DEBUG]' return endif ; Get number of lines in file nlines = NUMLINES( name ) if nlines LT 0 then return if keyword_set(DEBUG) then $ message,'File ' + name+' contains ' + strtrim(nlines,2) + ' lines',/INF if not keyword_set( SKIPLINE ) then skipline = 0 nlines = nlines - skipline if keyword_set( NUMLINE) then nlines = numline < nlines ncol = N_params() - 1 ;Number of columns of data expected vv = 'v' + strtrim( indgen(ncol)+1, 2) nskip = 0 if N_elements(fmt) GT 0 then begin ;FORMAT string supplied? if size(fmt,/tname) NE 'STRING' then $ message,'ERROR - Supplied FORMAT keyword must be a scalar string' ; Remove blanks from format string frmt = strupcase(strcompress(fmt,/REMOVE)) remchar, frmt, '(' ;Remove parenthesis from format remchar, frmt, ')' ; Determine number of columns to skip ('X' format) pos = strpos(frmt, 'X', 0) while pos NE -1 do begin pos = strpos( frmt, 'X', pos+1) nskip = nskip + 1 endwhile endif else begin ;Read everything as floating point frmt = 'F' if ncol GT 1 then for i = 1,ncol-1 do frmt = frmt + ',F' if not keyword_set( SILENT ) then message, $ 'Format keyword not supplied - All columns assumed floating point',/INF endelse nfmt = ncol + nskip idltype = intarr(nfmt) ; Create output arrays according to specified formats k = 0L ;Loop over output columns hex = bytarr(nfmt) for i = 0L, nfmt-1 do begin fmt1 = gettok( frmt, ',' ) if fmt1 EQ '' then fmt1 = 'F' ;Default is F format case strmid(fmt1,0,1) of 'A': idltype[i] = 7 'D': idltype[i] = 5 'F': idltype[i] = 4 'I': idltype[i] = 2 'B': idltype[i] = 1 'L': idltype[i] = 3 ; 'M': idltype[i] = 12 ; UINT ; 'M': idltype[i] = 13 ; ULONG 'M': idltype[i] = 14 ; LONG64 ; 'M': idltype[i] = 15 ; ULONG64 'Z': begin idltype[i] = 3 ;Hexadecimal hex[i] = 1b end 'X': idltype[i] = 0 ;IDL type of 0 ==> to skip column ELSE: message,'Illegal format ' + fmt1 + ' in field ' + strtrim(i,2) endcase ; Define output arrays if idltype[i] GT 0 then begin st = vv[k] + '= make_array(nlines,TYPE = idltype[i] )' tst = execute(st) k = k+1 endif endfor goodcol = where(idltype) idltype = idltype[goodcol] check_numeric = (idltype NE 7) openr, lun, name, /get_lun, compress=compress ngood = 0L temp = ' ' if !VERSION.RELEASE GE '5.6' then skip_lun,lun,skipline, /lines else $ if skipline GT 0 then $ for i = 0, skipline-1 do readf, lun, temp ;Skip any lines noset_delimiter = not keyword_set(delimiter) if noset_delimiter then delimiter = ' ' for j = 0L, nlines-1 do begin readf, lun, temp if strlen(temp) LT ncol then begin ;Need at least 1 chr per output line ngood = ngood-1 if not keyword_set(SILENT) then $ message,'Skipping Line ' + strtrim(skipline+j+1,2),/INF goto, BADLINE endif if noset_delimiter then $ temp = repchr(temp,',',' ') ;Replace any comma delimiters by spaces k = 0 temp = strtrim(temp,1) ;Remove leading spaces if keyword_set(comment) then if strmid(temp,0,1) EQ comment then begin ngood = ngood-1 if keyword_set(DEBUG) then $ message,'Skipping Comment Line ' + strtrim(skipline+j+1,2),/INF goto, BADLINE endif var = strsplit(strcompress(temp),delimiter,/extract) if N_elements(var) LT nfmt then begin if not keyword_set(SILENT) then $ message,'Skipping Line ' + strtrim(skipline+j+1,2),/INF ngood = ngood-1 goto, BADLINE ;Enough columns? endif var = var[goodcol] for i = 0L,ncol-1 do begin if check_numeric[i] then begin ;Check for valid numeric data tst = strnumber(var[i],val,hex=hex[i]) ;Valid number? if tst EQ 0 then begin ;If not, skip this line if not keyword_set(SILENT) then $ message,'Skipping Line ' + strtrim(skipline+j+1,2),/INF ngood = ngood-1 goto, BADLINE endif st = vv[k] + '[ngood] = val' endif else $ st = vv[k] + '[ngood] = var[i]' tst = execute(st) k = k+1 endfor BADLINE: ngood = ngood+1 endfor free_lun,lun if ngood EQ 0 then begin message,'ERROR - No valid lines found for specified format',/INFORM return endif if not keyword_set(SILENT) then $ message,strtrim(ngood,2) + ' valid lines read', /INFORM ; Compress arrays to match actual number of valid lines for i = 0,ncol-1 do begin tst = execute(vv[i] + '='+ vv[i]+ '[0:ngood-1]') endfor return end