[pstricks] Opening a data file with postscript
Herbert Voss
Herbert.Voss at fu-berlin.de
Thu Sep 19 11:22:49 CEST 2024
Am 18.09.24 um 15:48 schrieb Poul Riis:
> What I want to do is to put the contents of my one-column-data file
> into a postscript array.
> In fact, if possible, I would be even better if one could make a
> version reading a data file with two columns.
>
> I can do it with datatools (file below) but I would like to make it
> simpler, if possible.
>
>
> \documentclass{article}
> \usepackage{datatool}
> \usepackage[x11names]{xcolor}
> \usepackage{pstricks-add}
> \usepackage{multido}
> \usepackage[top=1.5cm,bottom=1.5cm,left=1.5cm, right=1.5cm]{geometry}
>
> % Load the data with space as the separator
> \DTLsetseparator{ }
>
> % Load the database, specifying no header and defining the keys for
> columns
> \DTLloaddb[noheader,keys={xhubb,yhubb}]{hubbledat}{hubble.txt}
> \DTLloaddb[noheader,keys={xstel,ystel}]{stedat}{stellarium.txt}
> \DTLloaddb[noheader,keys={ngc}]{labelsdat}{labels.txt}
>
>
>
> \begin{document}
> \begin{center}
> %\psset{xunit=2.5cm,yunit=0.001cm} % Adjust x and y units
> %\readdata{\Hubble}{data1.dat}
> \begin{psgraph}[axesstyle=frame,ticksize=0
> -3pt,subticks=5,Dx=5,Dy=500,xAxisLabel={Afstand
> (Mpc)},yAxisLabel={Hastighed (km/s)},llx=-1cm,xAxisLabelPos={8cm,-1
> cm},yAxisLabelPos={-1.5cm,4 cm}](0,0)(0,-500)(25,1500){16cm}{12cm}%
> \multido{\nn=1+1}{4}{\psline[linestyle=dashed,linewidth=0.5pt](!\nn\space
> 5 mul -500)(!\nn\space 5 mul 1500)}
> \multido{\nn=1+1}{2}{\psline[linestyle=dashed,linewidth=0.5pt](!0
> \nn\space 500 mul )(!25 \nn\space 500 mul)}
> \psline(0,0)(25,0)
> \pstVerb{/mm 5 def}%
> \psline[linecolor=Blue1](!0 0)(!2.1 2.1 500 mul)%
> \psline[linecolor=Green3](!0 0)(!20 20 61.2 mul)%
> \DTLforeach{hubbledat}{\xhubb=xhubb,\yhubb=yhubb}{%
> \pscircle*[linecolor=Blue1](\xhubb,\yhubb){1.5pt}%
> }%
> \DTLforeach{stedat}{\xstel=xstel,\ystel=ystel}{%
> \pscircle*[linecolor=Green3](\xstel,\ystel){1.5pt}%
> }%
> \pstVerb{/hubblexarray [ }%
> \DTLforeach{hubbledat}{\xhubb=xhubb}{\pstVerb{\xhubb\space }}%
> \pstVerb{] def }%
for example:
\pstVerb{/hubblexarray [ (/tmp/hubble.txt) run ] def }%
% \pstVerb{/hubblexarray [ }%
% \DTLforeach{hubbledat}{\xhubb=xhubb}{\pstVerb{\xhubb\space }}%
% \pstVerb{] def }%
Herbert
>
> \pstVerb{/hubbleyarray [ }%
> \DTLforeach{hubbledat}{\yhubb=yhubb}{\pstVerb{\yhubb\space }}%
> \pstVerb{] def }%
>
> \pstVerb{/stelxarray [ }%
> \DTLforeach{stedat}{\xstel=xstel}{\pstVerb{\xstel\space }}%
> \pstVerb{] def }%
>
> \pstVerb{/stelyarray [ }%
> \DTLforeach{stedat}{\ystel=ystel}{\pstVerb{\ystel\space }}%
> \pstVerb{] def }%
>
> \pstVerb{/labelsarray [ }%
> \DTLforeach{labelsdat}{\ngc=ngc}{\pstVerb{\ngc\space }}%
> \pstVerb{] def }%
>
> \multido{\nn=0+1}{24}{%
> \psline[linestyle=dashed,linewidth=0.2pt](!hubblexarray \nn\space get
> hubbleyarray \nn\space get)(!stelxarray \nn\space get stelyarray
> \nn\space get)%
> \uput{3pt}[0]{0}(!stelxarray \nn\space get stelyarray \nn\space
> get){\psPrintValueNew[PSfont=Palatino-Roman,fontscale=6]{labelsarray
> \nn\space get}}%
> %\rput(!stelxarray \nn\space get stelyarray \nn\space get){!mm}%
> }%
> \end{psgraph}
> \end{center}
> \end{document}
>
> Den ons. 18. sep. 2024 kl. 11.36 skrev Herbert Voss
> <Herbert.Voss at fu-berlin.de>:
>
> Am 18.09.24 um 10:59 schrieb Poul Riis:
> >
> > However, I cannot make it work even if I have added your suggested
> > options for ps2pdf.
> > The following works perfectly but not when I uncomment the line
> with
> > /infilex:
>
> I suppose you want to run the commands from the external file.
> Then use the run command:
>
> \documentclass[a4paper,14pt]{article}
> \usepackage[x11names]{xcolor}
> \usepackage{pstricks-add}
>
> \begin{filecontents}[noheader,force]{hubble.txt}
> 200 0 moveto
> (Hello!) show
> 200 2 neg moveto
> 230 2 neg lineto
> 2 setlinewidth
> 1 0 0 setrgbcolor
> stroke
> \end{filecontents}
>
> \begin{document}
> foo
> \pstverb{
> /Times-Roman findfont 12 scalefont setfont
> 50 0 moveto
> (Hello!) show
> 50 2 neg moveto
> 80 2 neg lineto stroke
> 1 dict begin
> /showpage {} def
> (hubble.txt) run
> end
> }
> bar
>
> \end{document}
>
>
> works also with running lualatex to get directly the PDF
>
> Herbert
>
More information about the PSTricks
mailing list.