pro MYFTAB_EXT, file_or_fcb, columns, $ 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,$ ROWS=rows, EXTEN_NO = exten_no, nonfinite=nonfinite, wildcard=wildcard ;+ ; NAME: ; MYFTAB_EXT ; ; NB : This is IDL astrolib's FTAB_EXT procedure modified to allow ; its use on files of up to 500 columns (rather than 9) and ; ; !!! SEE BELOW FOR ORIGINAL READCOL DOCUMENTATION AND CREDITS !!! ; ; 06 Nov 2008 - Extended to 300 columns by Mattia Vaccari ; 14 Feb 2009 - NONFINITE keyword added by Mattia Vaccari ; 06 Mar 2009 - WILDCARD keyword added by Mattia Vaccari ; 13 Mar 2009 - WILDCARD keyword scope extended by Mattia Vaccari ; 17 Mar 2009 - Extended to 500 columns by Mattia Vaccari ; ; PURPOSE: ; Routine to extract columns from a FITS (binary or ASCII) table. ; ; CALLING SEQUENCE: ; MYFTAB_EXT, name_or_fcb, columns, v1, [v2,..,v500, ROWS=, EXTEN_NO=] ; ; INPUTS: ; name_or_fcb - either a scalar string giving the name of a FITS file ; containing a (binary or ASCII) table, or an IDL structure ; containing as file control block (FCB) returned by FITS_OPEN ; If MYFTAB_EXT is to be called repeatedly on the same file, then ; it is quicker to first open the file with FITS_OPEN, and then ; pass the FCB structure to FTAB_EXT ; columns - table columns to extract. Can be either ; (1) String with names separated by commas ; (2) Scalar or vector of column numbers ; ; OUTPUTS: ; v1,...,v500 - values for the columns. Up to 500 columns can be extracted ; ; OPTIONAL INPUT KEYWORDS: ; ROWS - scalar or vector giving row number(s) to extract ; Row numbers start at 0. If not supplied or set to ; -1 then values for all rows are returned ; EXTEN_NO - Extension number to process. If not set, then data is ; extracted from the first extension in the file (EXTEN_NO=1) ; NONFINITE - FLT(1) - if set, changes all numerical non-finite ; input elements into NONFINITE ; WILDCARD - FLT(N+1) if set, changes all numerical input elements equal to ; WILDCARD[0:N-1] into WILDCARD[N] (done *after* NONFINITE) ; NB : N must be at least 1, i.e. ; EXAMPLES: ; Read wavelength and flux vectors from the first extension of a ; FITS file, 'spec.fit'. Using FTAB_HELP,'spec.fit' we find that this ; information is in columns named 'WAVELENGTH' and 'FLUX' (in columns 1 ; and 2). To read the data ; ; IDL> myftab_ext,'spec.fit','wavelength,flux',w,f ; or ; IDL> myftab_ext,'spec.fit',[1,2],w,f ; ; PROCEDURES CALLED: ; FITS_READ, FITS_CLOSE, FTINFO, FTGET(), TBINFO, TBGET() ; ; HISTORY: ; version 1 W. Landsman August 1997 ; Converted to IDL V5.0 W. Landsman September 1997 ; Improve speed processing binary tables W. Landsman March 2000 ; Use new FTINFO calling sequence W. Landsman May 2000 ; Don't call fits_close if fcb supplied W. Landsman May 2001 ; Use STRSPLIT to parse column string W. Landsman July 2002 ; Cleanup pointers in TBINFO structure W. Landsman November 2003 ; Avoid EXECUTE() if V6.1 or later W. Landsamn December 2006 ;- on_error,2 compile_opt idl2 if n_params() LT 3 then begin print,'Syntax - MYFTAB_EXT, name, columns, v1, [v2,...,v500, ROWS=, EXTEN=]' return endif n_ext = n_params() - 2 strng = size(columns,/TNAME) EQ 'STRING' ;Is columns a string? if not keyword_set(exten_no) then exten_no = 1 sz = size(file_or_fcb) if sz[sz[0]+1] NE 8 then fits_open,file_or_fcb,fcb else fcb=file_or_fcb if fcb.nextend EQ 0 then message,'ERROR - FITS file contains no table extensions' if fcb.nextend LT exten_no then message,'ERROR - FITS file contains only ' + strtrim(fcb.nextend,2) + ' extensions' if n_elements(rows) NE 0 then begin minrow = min(rows, max = maxrow) naxis1 = fcb.axis[0,exten_no] first = naxis1*minrow last = naxis1*(maxrow+1)-1 xrow = rows - minrow fits_read,fcb,tab,htab,exten_no=exten_no,first=first,last=last,/no_pdu tab = reform(tab,naxis1,maxrow-minrow+1,/overwrite) endif else begin fits_read, fcb, tab, htab, exten_no=exten_no,/no_pdu xrow = -1 endelse if sz[sz[0]+1] NE 8 then fits_close,fcb else file_or_fcb.last_extension = exten_no ext_type = fcb.xtension[exten_no] case ext_type of 'A3DTABLE': binary = 1b 'BINTABLE': binary = 1b 'TABLE': binary = 0b else: message,'ERROR - Extension type of ' + ext_type + 'is not a FITS table format' endcase if strng then colnames= strsplit(columns,',',/EXTRACT) else colnames = columns if binary then tbinfo,htab,tb_str else ftinfo,htab,ft_str vv = 'v' + strtrim( indgen(n_ext)+1 , 2 ) for i = 0, n_ext-1 do begin if !VERSION.RELEASE GE '6.1' then begin if binary then (scope_varfetch(vv[i])) = TBGET( tb_str,tab,colnames[i],xrow,nulls) $ else (scope_varfetch(vv[i])) = FTGET( ft_str,tab,colnames[i],xrow,nulls) endif else begin if binary then v = TBGET( tb_str,tab,colnames[i],xrow,nulls) $ else v = FTGET( ft_str,tab,colnames[i],xrow,nulls) istat = execute( vv[i] + '=v' ) endelse endfor if binary then begin ptr_free, tb_str.tscal ptr_free, tb_str.tzero endif if keyword_set(nonfinite) then begin &$ for i = 0, n_ext-1 do begin &$ res=execute('v='+vv[i]) &$ s=size(v) & t=s[n_elements(s)-2] &$ if t ne 7 then begin &$ j=where(finite(v) eq 0,cnt) &$ if cnt gt 0 then res=execute(vv[i]+'[j]=nonfinite') &$ endif &$ endfor &$ endif if keyword_set(wildcard) then begin &$ nwc=n_elements(wildcard) &$ for k=0,nwc-2 do begin &$ wc=wildcard[k] &$ wcl=wildcard[nwc-1] &$ for i = 0, n_ext-1 do begin &$ res=execute('v='+vv[i]) &$ s=size(v) & t=s[n_elements(s)-2] &$ if t ne 7 then begin &$ j=where(v eq wc,cnt) &$ if cnt gt 0 then res=execute(vv[i]+'[j]=wcl') &$ endif &$ endfor &$ endfor &$ endif return end