comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Writing and reading multipage TeX tables in IDL.
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Writing and reading multipage TeX tables in IDL. [message #1286] Fri, 13 August 1993 00:51
dudley is currently offline  dudley
Messages: 8
Registered: August 1993
Junior Member
I'm finding the following routines to be pretty useful. They should
work for you if your running unix and have a similar version of TeX.

Chris.

function gethboxwd,str,font
;+
; NAME:
; gethboxwd
; PURPOSE:
; Invoke TeX to calculate the widths of a given array of text.
; CALLING SEQUENCE:
; RESULT = gethboxwd(strarr)
; INPUTS:
; str: string array of TeX format lines.
; font: a standard TeX font.
; OUTPUTS:
; Floating point array of widths in points.
;
;
; C.C. Dudley, Institute for Astronomy, Honolulu, HI August 1993
;-
s=size(str)
get_lun,unit
openw,unit,'qwert1001.tex'
printf,unit,'\font\myfont='+font
for i=0,s(1)-1 do printf,unit,'\myfont \setbox1=\hbox{'+str(i)+'} \showthe\wd1'
printf,unit,'\end'
close,unit
openw,unit,'qwert1000'
for i=0,s(1)-1 do printf,unit,' '
close,unit
;wait,5
spawn,'/usr/local/bin/tex qwert1001 < qwert1000',result
c=fltarr(s(1))
for i=1,s(1) do begin
b=strpos(result(3*i-1),'pt')
;print,b
d=strpos(result(3*i-1),'>')
c(i-1)=float(strmid(result(3*i-1),d+2,b-1))
endfor
spawn,'rm qwert100*'
;spawn,'rm scr.*'
close,unit
free_lun,unit
return,c
end
pro wtextab,outfile,data,font=font,head=head,title=title,nrow=nr ow
;+
; NAME:
; wtextab
; PURPOSE:
; Write out a 2-D array as an 'ApJ' style tex table.
; CALLING SEQUENCE:
; wtextab,'myfile',myarray(rows,columns)
; INPUTS:
; filename without '.tex' extension.
; 2-D array addressed first by row then by column.
; OPTIONAL:
; font= a standard tex font.
; head= a string array of column headers.
; title= a string
; nrow= integer number of rows per page.
; OUTPUTS:
; Four TeX files: eg myfile.tex containing the data.
; myfile_head.tex containing the table format.
; myfile_mid.tex if the table is multipaged.
; myfile_tail.tex to close the table.
; BUGS:
; This is a big cluge that works by running TeX from inside IDL to
; determine the size of table entries so that column widths will
; be uniform from page to page. It expects TeX to behave the way
; it does right here and now..... There is no scaling of paper size,
; you have to do that by hand.
; DISCLAIMER:
; This is an alpha test release of a poor program. If you modify
; this program please do not include horror stories of how badly it
; was written.
; OTHER PROGRAMS:
; function: gethboxwd runs TeX.
; procedure: rtextab reads TeX tables produced by this program.
;
; C.C. Dudley, Institute for Astronomy, Honolulu, HI August, 1993.
;-
s=size(data)
if n_elements(font) eq 0 then font='cmr9'
if n_elements(title) eq 0 then title='Table'
if n_elements(nrow) eq 0 then nrow=50
openw,1,outfile+'_head.tex'
printf,1,'\magnification = \magstep1'
printf,1,'\hsize=7truein \hoffset=-0.125truein'
printf,1,'\vsize=9.3truein \voffset=-0.75truecm'
printf,1,'\parindent=20pt'
printf,1,'\font\myfont='+font
printf,1,'\font\ninerm=cmr9'
printf,1,'\font\twelverm=cmr12'
printf,1,'\font\tenrm=cmr10'
printf,1,'\font\twelvebf=cmbx12'
if n_elements(head) eq 0 then begin
head=strarr(s(2))
for j=0,s(2)-1 do head(j)='column '+strtrim(string(j+1),2)
endif
printf,1,'\nopagenumbers'
printf,1,'{\myfont'
printf,1,'\midinsert'
printf,1,'$$\vbox{\offinterlineskip'
printf,1,'\halign{&# \cr'
printf,1,'\multispan{'+string(s(2)+1)+'}\hfil '+title+' \hfil \cr'
printf,1,'\noalign{\vskip3pt}'
printf,1,'\noalign{\hrule}'
printf,1,'\noalign{\vskip1pt}'
printf,1,'\noalign{\hrule}'
printf,1,'\noalign{\vskip3pt}'
c=fltarr(s(2))
n=intarr(s(2))
wide=n
d=gethboxwd(head,font)
for j=0,s(2)-1 do begin
c(j)=max(gethboxwd(string(data(*,j)),font),pos)
n(j)=pos
if c(j) gt d(j) then wide(j)=1
endfor

a='&'
for j=0,s(2)-1 do a=a+head(j)+'\hskip'+strtrim(string(max([c(j),d(j)])-d(j)),2 )+'pt \hfil &'
a=a+' \cr'
printf,1,a
printf,1,'\noalign{\vskip3pt}'
printf,1,'\noalign{\hrule}'
printf,1,'\noalign{\vskip3pt}'
close,1
openw,1,outfile+'_tail.tex'
printf,1,'\noalign{\hrule}'
printf,1,'}}$$'
printf,1,'\endinsert'
printf,1,'}'
printf,1,'\end'
close,1
if s(1) gt nrow then begin
openw,1,outfile+'_mid.tex'
printf,1,'\noalign{\hrule}'
printf,1,'}}$$'
printf,1,'\endinsert\vfil\eject'
printf,1,'}'
printf,1,'{\myfont'
printf,1,'\midinsert'
printf,1,'$$\vbox{\offinterlineskip'
printf,1,'\halign{&# \cr'
printf,1,'\multispan{'+string(s(2)+1)+'}\hfil '+title+' cont. \hfil \cr'
printf,1,'\noalign{\vskip3pt}'
printf,1,'\noalign{\hrule}'
printf,1,'\noalign{\vskip1pt}'
printf,1,'\noalign{\hrule}'
printf,1,'\noalign{\vskip3pt}'
a='&'
for j=0,s(2)-1 do a=a+head(j)+'\hskip'+strtrim(string(max([c(j),d(j)])-d(j)),2 )+'pt \hfil &'
a=a+' \cr'
printf,1,a
printf,1,'\noalign{\vskip3pt}'
printf,1,'\noalign{\hrule}'
printf,1,'\noalign{\vskip3pt}'
close,1
endif
openw,1,outfile+'.tex'
printf,1,'\input '+outfile+'_head.tex'
for k=0,s(1)/nrow do begin
for i=k*nrow,min([(k+1)*nrow-1,s(1)-1]) do begin
a='&'
for j=0,s(2)-1 do begin
a=a+' '+string(data(i,j))+' \hfil &'
endfor
a=a+' \cr'
printf,1,a
;printf,1,'\noalign{\vskip3pt} \noalign{\hrule} \noalign{\vskip1pt}'
printf,1,'\noalign{\vskip3pt}'
endfor
if k ne s(1)/nrow then printf,1,'\input '+outfile+'_mid.tex'
endfor
printf,1,'\input '+outfile+'_tail.tex'
close,1
end


pro rtextab,infile,llist
;+
; NAME:
; rtextab
; PURPOSE:
; Read a tex table written by wtextab into a 2-D strarr.
; CALLING SEQUENCE:
; rtextab,'myfile',result
; INPUTS:
; myfile is the name of a TeX table writen by wtextab without
; .tex extension.
; OUTPUTS:
; result is a 2-D string array of the table entries.
;
; C.C. Dudley, Institute for Astronomy, Honolulu, HI 1993
;-
openr, 1, strtrim(infile,2)+'.tex'
nrows=0
i=0
while (not eof(1)) do begin
a=''

readf,1,a
next=0
while strpos(a,'\cr',next) ne -1 do begin
next=strpos(a,'\cr',next)
next=next+1
nrows=nrows+1
endwhile
endwhile
print,nrows
close,1
b=strarr(nrows+1)
openr, 1, strtrim(infile,2)+'.tex'
rownum=0
readf,1,a
while (not eof(1)) do begin
a=''

readf,1,a
now=0
while strpos(a,'\cr',now) ne -1 do begin
next=strpos(a,'\cr',now)
b(rownum)=b(rownum)+strmid(a,now,next-now)
rownum=rownum+1
now=next+3
endwhile
b(rownum)=b(rownum)+strmid(a,now,strlen(a)-now)
endwhile
cmax=0

for i=0,nrows-1 do begin
now=0
rmax=0
while strpos(b(i),'&',now) ne -1 do begin
next=strpos(b(i),'&',now)
rmax=rmax+1
now=next+1
endwhile
if rmax gt cmax then cmax=rmax
endfor
print,cmax
c=strarr(nrows,cmax)
for i=0,nrows-1 do begin
now=0
rmax=0
j=0
while strpos(b(i),'&',now) ne -1 do begin
next=strpos(b(i),'&',now)
c(i,j)=strmid(b(i),now,next-now)
now=next+1
j=j+1
endwhile
if rmax gt cmax then cmax=rmax
endfor
for i=0,nrows-1 do for j=0,cmax-1 do if strpos(c(i,j),'\hfil') ne -1 then c(i,j)=strtrim(strmid(c(i,j),0,strpos(c(i,j),'\hfil')),2)
llist=c(*,1:cmax-1)
close,1
end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL or OpenLook "feature"?
Next Topic: Window Bug using Widgets

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:22:00 PDT 2025

Total time taken to generate the page: 0.00625 seconds