pro tablecheck,name,col1,col2,col1array,col2array ;+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Given a machine readable table name and ;;;;; ;;;;; two column numbers, this program reads the ;;;;; ;;;;; format information in the meta-header and ;;;;; ;;;;; makes a plot of the two columns of data. ;;;;; ;;;;; The output is the info in the arrays. ;;;;; ;;;;; ;;;;; ;;;;; tablecheck,filename,col#1,col#2,arr1,arr2 ;;;;; ;;;;; ;;;;; ;;;;; Written by Greg Schwarz (AAS Journals staff ;;;;; ;;;;; scientist) on 8/16/00. ;;;;; ;;;;; ;;;;; ;;;;; 02/27/01 : Fixed a bug in the way the meta- ;;;;; ;;;;; data is read in. ;;;;; ;;;;; ;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;- dumI=' ' dumII=' ' tmp='' allformat='' first='y' irow=0.0 startpos=' ' endpos=' ' ;;;;; Columns have to be read in order. Check to see if col1 < col2. if(col1 ge col2) then message, 'The column number must increase in order!' close,/all openr,1,name print," " ;;;;; Read the first few lines into a dummy variable ;;;;; because this info is not needed. However, keep ;;;;; track of the number of lines. while(strpos(dumI,'Bytes Format') eq -1) do begin readf,1,dumI irow=irow+1.0 end readf,1,dumI irow=irow+1.0 icol=0 ;;;;; Read until you reach a '------' line terminator while(strpos(tmp,'-----------------') eq -1) do begin irow=irow+1.0 ;;;;; Extract out the 6-8th positions. ;;;;; If there is a number you have a column readf,1,f='(1x,a3,1x,a3,1x,a60)',startpos,endpos,tmp ;;;;; If startpos is --- then you are at the end ;;;;; so set the 9999 flag so it isn't counted if(startpos eq '---') then startpos = '9999' ;;;;; If starpos is blank then this is either a continuation ;;;;; line or a column that is only one digit wide. You can ;;;;; tell by checking if endpos is also blank. If it is a ;;;;; column then set startpos and endpos to the same value if(startpos eq ' ') then begin startpos = endpos if(endpos eq ' ') then startpos = '9999' endif if(fix(startpos) ge 1 and fix(startpos) le 999) then begin ;;;;; Add one to the column counter and squeeze out the blanks. ;;;;; Also take out any leading and trailing blanks icol=icol+1 less_blanks = strtrim(strcompress(tmp),2) ;;;;; Separate the non-location info by sorting into an array that is ;;;;; delimited by blank spaces. The first position is the format, ;;;;; the second is the units, the third is the name, and the last ;;;;; positions are the short description of the column components=str_sep(less_blanks,' ') ;;;;; Determine the length of the format by getting any numbers ;;;;; between (A|I|F|E) and a decimal point if( strmid(components(0),2,1) eq '.') then $ length = strmid(components(0),1,1) $ else length = strmid(components(0),1,2) ;;;;; Determine the column type (A|I|F|E) vtype = strmid(components(0),0,1) case vtype of 'A': idltype = 7 'I': idltype = 2 'F': idltype = 5 'E': idltype = 5 endcase print, "Column",strcompress(icol)," starts at ",startpos,$ ", with format ",components(0)," and has the name: ",components(2) ;;;;; If this is the first column then you have to do things ;;;;; slightly differently from the remaining columns if(first eq 'y') then begin allformat=components(0) previousendpos=endpos first = 'n' endif else begin ;;;;; calculate the number of 'x' you need to put in format num_blanks = strcompress(fix(startpos)-fix(previousendpos)-1) allformat=allformat+','+strmid(num_blanks,1)+'x,'+components(0) previousendpos=endpos endelse ;;;;; Check to see if this current column is one that the ;;;;; user requested. If so grab the info required like the ;;;;; column ending point, the array type, units, axis header. if(icol eq col1) then begin col1end=fix(endpos) idl1type=idltype xunits=components(1) xtit=components(2)+' ('+xunits+')' ;;;;; Have to check if this is the first column ;;;;; because things are formated differently then if(icol eq 1) then begin shortformat=components(0) endif else begin ;;;;; Get the correct number of x characters for skippping col1blanks=strcompress(fix(startpos)-1) shortformat=strmid(col1blanks,1)+'x,'+components(0) endelse endif ;;;;; Get the second column ifno if(icol eq col2) then begin idl2type=idltype yunits=components(1) ytit=components(2)+' ('+yunits+')' ;;;;; Get the correct number of x characters for skippping col2blanks=strcompress(fix(startpos)-col1end-1) shortformat=shortformat+','+strmid(col2blanks,1)+'x,'+components(0) endif endif end ;;;;; iskip is the end (maybe see below) of the meta-header iskip=irow print," " print,"There are",strcompress(iskip)," rows in the meta-header" print,"There are",strcompress(icol)," data columns in this file" print,"The total format of the file is: ",allformat print,"But the format for your columns is: ",shortformat print," " ;;;;; Continue reading the file to get the number of lines lastdash=0 while not eof(1) do begin readf,1,dumI irow=irow+1.0 ;;;;; If you encounter another '--------' (e.g. the end of a ;;;;; notes subsection) mark it because you don't want to ;;;;; read the previous information as data! if(strmid(dumI,0,6) eq '------') then begin lastdash=irow endif end close,/all ;;;;; If you found a '-------' line then reset iskip if(lastdash ne 0) then begin iskip=lastdash endif ;;;;; Use the data length and format information to create arrays col1array=make_array(irow-iskip,type=idl1type) tmp1=make_array(1,type=idl1type) col2array=make_array(irow-iskip,type=idl2type) tmp2=make_array(1,type=idl2type) openr,1,name ;;;;; Skip the meta-data information for k=1,iskip do readf,1,dumI ;;;;; This needs to be added so the format statement ;;;;; in the readf command will work correctly fmt='('+shortformat+')' ;;;;; Read the info into the correct arrays for k=0.0,irow-iskip-1.0 do begin readf,1,f=fmt,tmp1,tmp2 col1array(k)=tmp1 col2array(k)=tmp2 endfor close,/all ;;;;; Plot up the user columns. If the user wants to ;;;;; do a better plot they can make their own using ;;;;; the returned column arrays plot,col1array,col2array,psym=7,xtitle=xtit,ytitle=ytit,$ thick=2.0,xcharsize=1.25,ycharsize=1.25,xstyle=1,ystyle=1,$ charthick=1.5 return end