home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / splot122.zip / DOC / SAMPLES.TEX < prev    next >
Text File  |  1994-09-22  |  29KB  |  1,244 lines

  1. \chapter{Sample Programs} 
  2.  
  3. \index{example files}
  4. This chapter contains printouts of several example drawing or plotting files 
  5. with the corresponding 
  6. printed figure that the file generates. 
  7. These for the most part are contributed files of actual figures used in           
  8. publications.     
  9.                   
  10. \section{simple.spt}
  11.  
  12. {\tt
  13. \begin{verbatim}
  14. /* demo of simplest possible data */
  15. /* plotting using all the defaults */
  16.  
  17. #include <splot.h>
  18. double *data;
  19. main() 
  20.    {     
  21.    readdata("demo\data1.dat",data);
  22.    plotdata(data);  
  23.    label(LOWER,"Position");
  24.    label(LEFT,"Wavelength in !m!m");
  25.    text(6.20,22.98,"Mepsicron Calibration");
  26.    }
  27. \end{verbatim}
  28. }
  29.  
  30. \vspace*{2cm}
  31.  
  32. \special{psfile=simple.eps hscale=40 vscale=40 hoffset=250 voffset=-50}
  33.               
  34. \newpage
  35. \section{simple2.spt}                                    
  36.  
  37. {\tt
  38. \begin{verbatim}
  39. /* demo of simple data plotting but*/
  40. /* over riding some of the defaults */
  41.  
  42. #include <splot.h>
  43. double *data;
  44. main() 
  45.    {     
  46.    readdata("demo\data1.dat",data);
  47.    set(PLOTTYPE,SYMBOLS);
  48.    set(AXESCLIP,ON);
  49.    axes_box(11,16,-0.02,0.632,0.04,0.6335);
  50.    plotdata(data);  
  51.    label(LOWER,"Position");
  52.    label(LEFT,"Wavelength in !m!m");
  53.    text(6.20,22.98,"Mepsicron Calibration");
  54.    }
  55. \end{verbatim}
  56. }
  57.  
  58. \vspace*{1.5cm}
  59. \special{psfile=simple2.eps hscale=40 vscale=40 hoffset=250 voffset=-10}
  60.               
  61. \section{simple3.spt}
  62.  
  63. {\tt
  64. \begin{verbatim}
  65. /* demo of simple data plotting but*/
  66. /* over riding some more of the defaults */
  67.  
  68. #include <splot.h>
  69. double *data;
  70. main() 
  71.    {     
  72.    readdata("demo\data1.dat",data);
  73.    set(PLOTTYPE,SYM_LINES);
  74.    set(CURSYMBOL,ARROW);
  75.    set(AXESCLIP,ON);
  76.    axes_box(11,16,-0.02,0.632,0.04,0.6335);
  77.    tickmarks(YAXES,0.632,0.6325,0.633,0.6335);
  78.    tickmarks(XAXES);
  79.    ticklabel();
  80.    label(LOWER,"Position");
  81.    label(LEFT,"Wavelength in !m!m");
  82.    text(6.20,22.98,"Mepsicron Calibration");
  83.    set(FONTMULT,2);
  84.    plotdata(data);  
  85.    }
  86. \end{verbatim}
  87. }
  88.  
  89.               
  90. \vspace*{2cm}
  91. \special{psfile=simple3.eps hscale=40 vscale=40 hoffset=250 voffset=40}
  92.       
  93. \newpage                                                         
  94. \section{inverax.spt}                                    
  95.  
  96. {\tt
  97. \begin{verbatim}
  98. /* This file illustrates the use of inverse and log axes */
  99. \index{axes, log example}
  100. \index{axes, inverse example}
  101.  
  102. #include <splot.h>
  103. double *data;
  104. main() 
  105.    {     
  106.    set(LINEWIDTH,0.06);
  107.    set(CURSYMBOL,OSQUARE);
  108.    set(AXESCLIP,ON);
  109.    set(FONTASPECT,1.5);
  110.    set(AXESTYPE,INVXLOGY);
  111.    axes_box(12,15,1e20,0.001,4,10);
  112.    set(FONTWIDTH,0.8);
  113.    tickmarks();
  114.    ticklabel(BOTTOM,1e+20,"0",20,"50",10,"100",6.6666,"150"
  115.              ,5,"200",4,"250");
  116.    ticklabel(LEFT,1e-3,"10^11^",1e-2,"10^12^",1e-1,"10^13^",1,"10^14^",10,"10^15^");
  117.    set(XMULT,1);
  118.    set(FONTWIDTH,0.9);
  119.    label(BOTTOM,"1000/T");
  120.    label(LEFT,"CARRIER CONCENTRATION");
  121.    set(PLOTTYPE,SYMBOLS);
  122.    readdata("demo\tb4_2_2.dat",data);
  123.    plotdata(data);
  124.    }       
  125. \end{verbatim}
  126. }
  127.  
  128. \vspace*{7cm}                  
  129.  
  130. \special{psfile=inverax.eps hscale=40 vscale=40 hoffset=220 voffset=0}
  131.     
  132. \newpage
  133. \index{error bars, example}\index{fit line, example}
  134. \section{errorbar.spt}                                  
  135.  
  136. {\tt
  137. \begin{verbatim}
  138. #include <splot.h>
  139.  
  140. /* This example file illustrates the use of errorbars and straight */
  141. /* line fits to data. It also uses a small internal data array rather */
  142. /* than reading data in from a file */
  143.  
  144. double data[4][4] = {
  145.    1.2, 0.24, 0.1, 1,
  146.    2.0, 0.43, 0.1, 1, 
  147.    4.0, 0.52, 0.1, 1, 
  148.    6.0, 0.87, 0.1, 1}; 
  149.  
  150. double yint,slope;
  151.  
  152.  
  153. main()
  154.    {
  155.    set(LINEWIDTH,0.1);
  156.    set(PLOTTYPE,SYMBOLS);
  157.    axes_box(12,15,0,0,8,1.0);
  158.    tickmarks();
  159.    set(FONTWIDTH,0.5);
  160.    ticklabel();
  161.    set(FONTWIDTH,0.7);
  162.  
  163.    label(BOTTOM,"SiGe Well Width in (nm)");
  164.    label(LEFT,"Biexciton Lifetime in (!m!s)");
  165.  
  166.    text(10.03,22.56,"MBE SiGe Quantum Wells",CENTER);
  167.  
  168.    /* draw the data points  */
  169.    drawdata(data,0,1);
  170.  
  171.    /* put in the error bars for the x values */
  172.    errorbars(XVALS,data,0,1,3);
  173.    /* put in the error bars for the y values */
  174.    errorbars(YVALS,data,0,1,2);
  175.  
  176.    /* fit the best line to the data and return the slope and intercept */
  177.    fitline(data,0,1,&yint,&slope);
  178.    print(slope);
  179.    print(yint);
  180.    }
  181. \end{verbatim}
  182. }
  183.                                                               
  184. \vspace*{.1cm} 
  185. \special{psfile=errorbar.eps hscale=50 vscale=50 hoffset=210 voffset=120}
  186.              
  187. \newpage     
  188. \section{manyspec.spt } 
  189.  
  190. \vspace*{12cm}
  191. \special{psfile=manyspec.eps hscale=50 vscale=50 hoffset=50 voffset=-30}
  192.  
  193. \index{data, shifting example}
  194.              
  195. {\tt
  196. \begin{verbatim}
  197. #include <splot.h> 
  198. /* Created by Scott Wilson 02/05/93 */
  199. /* this splot file generates an xy 
  200.    plot of 5 data sets. Each curve  
  201.    has the same x scale and y scale 
  202.    but have been offset from each 
  203.    other in the y direction by an 
  204.    equal amount
  205. */
  206. /* define the data arrays */   
  207. double *pldata1, *pldata2, *pldata3, *pldata4, *pldata5;
  208. main()             
  209.   {                
  210.  
  211.    /* define a tic length  */
  212.    /* major and minor tics */
  213.                    
  214.    double majortic,minortic;
  215.    majortic=0.25;  
  216.    minortic=0.17;  
  217.                    
  218.    /* set up some default values */
  219.                    
  220.    set(FONTASPECT,1.2);
  221.    set(FONTWIDTH,0.8);
  222.    set(LINECOLOUR,BLACK);
  223.    set(AXESCLIP,ON);
  224.    set(LINEWIDTH,0.09);
  225.    set(PLOTTYPE,LINES);
  226.  
  227.    /* load in the data */
  228.  
  229.    readdata("demo\4kc.dat",pldata1);
  230.    readdata("demo\15kc.dat",pldata2);
  231.    readdata("demo\35kc.dat",pldata3);
  232.    readdata("demo\45kc.dat",pldata4);
  233.    readdata("demo\60kc.dat",pldata5);
  234.  
  235.    /* define an axis box */
  236.  
  237.    axes_box(13,19,7650,-3000,7950,125000);
  238.                    
  239.    /* set up some major tics*/ 
  240.  
  241.    set(TICKLENGTH,majortic);
  242.  
  243.    /* for the x-axis    */  
  244.  
  245.    tickmarks(XAXES,7700,7800,7900);
  246.  
  247.    /* for the y-axis    */  
  248.    /* note only denoting the zero point
  249.    for each curve */
  250.  
  251.    tickmarks(YAXES,0,5000,10000,15000,20000);
  252.  
  253.    /* set up some minor tics */                 
  254.  
  255.    set(LINEWIDTH,0.05);
  256.    set(TICKLENGTH,minortic);
  257.  
  258.    /* for the x axis */
  259.  
  260.    tickmarks(XAXES,7675,7725,7750,7775,7825,7850,7875,7925);
  261.  
  262.    /* place some ticklabels on the axes */
  263.  
  264.    ticklabel(BOTTOM);
  265.    ticklabel(RIGHT,0," 4K",5000,"15K",10000,"35K",15000,"45K",20000,"60K");
  266.  
  267.     /* place some labels on the axes */
  268.  
  269.    label(BOTTOM,"Photon Energy (cm^-1^)");
  270.    label(LEFT,"PL Intensity");             
  271.  
  272.    /* place some comments in the figure */
  273.  
  274.    text(3.98,21.11,"C_60_:^16^O_2_");
  275.    text(11.10,21.11,"!l!_ex_=710nm");
  276.  
  277.    /* put the data into the picture */
  278.  
  279.    drawdata(pldata1);
  280.          
  281.    set(YSHIFT,5000);
  282.    drawdata(pldata2);
  283.    set(YSHIFT,10000);
  284.    drawdata(pldata3);
  285.    set(YSHIFT,15000);
  286.    drawdata(pldata4);
  287.    set(YSHIFT,20000);
  288.    drawdata(pldata5);
  289.    }
  290. \end{verbatim}
  291. }
  292.  
  293. \newpage
  294. \index{axes, invisible example}
  295. \section{invisax.spt}                                                                   
  296.  
  297. \vspace*{16.5cm}
  298. \special{psfile=invisax.eps hscale=60 vscale=60 hoffset=50 voffset=-50}
  299.  
  300. {\tt
  301. \begin{verbatim}
  302. /* This example shows how invisible axes can be used to establish */
  303. /* an alternate coordinate system and still use the drawdata function */
  304. /* to draw the curves */
  305.  
  306. /*draws quantum wells and wave functions */
  307. #include <splot.h>
  308. double *data1;
  309. double *data2;
  310. double *data3;
  311. double *data4;
  312. double *data5;
  313. main() 
  314.    {     
  315.    set(LINECOLOUR,INVIS);
  316.    set(FONTWIDTH,0.6);
  317.    set(FONTASPECT,1.4);
  318.    set(LINEWIDTH,0.02);
  319.    /* read in data generated by Mathematica */
  320.    readdata("demo\cdqw_wfc.dat",data1);
  321.    readdata("demo\cdqw_wfc.da2",data2);
  322.    readdata("demo\cdqw_wfc.da3",data3);
  323.    readdata("demo\cdqw_wfc.da4",data4);
  324.    readdata("demo\cdqw_wfc.da5",data5);
  325.    /* drawing turned out too big so reduce the overall size */
  326.    scale(0.7,0.65);
  327.    gsave();
  328.    axes_box(8,15,-185,0.0,185,188.36);
  329.    set(LINECOLOUR,BLACK);
  330.    translate(-1.25,22.5);
  331.    /* even solns to cdqw */
  332.    /*   norm = 1.0/0.00009134 * 60.0; */ 
  333.    set(YMULT,656886.);
  334.    set(YSHIFT,9.13863);
  335.    drawdata(data1);
  336.    /*   norm = 1/.0002838 * 60.0;  */
  337.    set(YMULT,211416.);
  338.    set(YSHIFT,35.8858);
  339.    drawdata(data1,0,3);
  340.    /*   norm = 1/0.008109 * 60.0;*/
  341.    set(YMULT,7400.);
  342.    set(YSHIFT,77.0532);
  343.    drawdata(data3);
  344.    /* call subroutine to draw quantum well. Also sets coordinate scale to match*/
  345.    s_qw_box();
  346.    /* energy eigenvalues */
  347.    moveto(-190,9.13863);
  348.    lineto(190,9.13863);
  349.    moveto(-190,35.8858);
  350.    lineto(190,35.8858);
  351.    moveto(-190,77.0532);
  352.    lineto(190,77.0532);
  353.    stroke();
  354.    text(205,9.13863,"E_0_");
  355.    text(205,35.8858,"E_2_");
  356.    text(205,77.0532,"E_4_");
  357.    text(0,-15,"a) CDQW, even solutions",CENTER);
  358.    grestore();
  359.    /* odd solns to cdqw */
  360.    set(LINECOLOUR,INVIS);
  361.    gsave();
  362.    axes_box(8,15,-185,0.0,185,188.36);
  363.    set(LINECOLOUR,BLACK);
  364.    translate(11,22.5);
  365.    set(YMULT,656886.);
  366.    set(YSHIFT,9.14186);
  367.    drawdata(data1,0,2);
  368.    set(YMULT,211416.);
  369.    set(YSHIFT,35.9177);
  370.    drawdata(data1,0,4);
  371.    set(YMULT,7400.);
  372.    set(YSHIFT,77.4394);
  373.    drawdata(data3,0,2);
  374.    s_qw_box();
  375.    /* energy eigenvalues */
  376.    moveto(-190,9.14186);
  377.    lineto(190,9.14186);
  378.    moveto(-190,35.9177);
  379.    lineto(190,35.9177);
  380.    moveto(-190,77.4394);
  381.    lineto(190,77.4394);
  382.    stroke();
  383.    text(-227,9.14186,"E_1_");
  384.    text(-227,35.9177,"E_3_");
  385.    text(-227,77.4394,"E_5_");
  386.    text(217.,53.,"107meV",CENTER);
  387.    text(0,120,"9 nm",CENTER);
  388.    text(0,-15,"b) CDQW, odd solutions",CENTER);
  389.    grestore();
  390.    /*asymmetric coupled wells */
  391.    set(LINECOLOUR,INVIS);
  392.    gsave();
  393.    axes_box(8,15,-185,0.0,185,188.36);
  394.    set(LINECOLOUR,BLACK);
  395.    translate(5.5,2.5);
  396.    set(YMULT,1000.);
  397.    set(YSHIFT,90.23);
  398.    set(XSHIFT,-95.);
  399.    drawdata(data4,0,2);
  400.    a_qw_box();
  401.    moveto(-195,90.23);
  402.    lineto(190,90.23);
  403.    stroke();
  404.    text(215,90.23,"E_2_",CENTER);
  405.    text(280,90.23,"Resonance");
  406.    text(-270.,104.,"188 meV",CENTER);
  407.    grestore();   
  408.    set(LINECOLOUR,INVIS);
  409.    gsave();
  410.    axes_box(8,15,-185,0.0,185,188.36);
  411.    set(LINECOLOUR,BLACK);
  412.    translate(5.5,2.5);
  413.    set(XSHIFT,-95.);
  414.    set(YMULT,-80.0);
  415.    set(YSHIFT,10.29);
  416.    drawdata(data5);
  417.    set(YMULT,-80.0);
  418.    set(YSHIFT,40.81);
  419.    drawdata(data5,0,2);
  420.    set(YMULT,-275.0);
  421.    set(YSHIFT,154.16);
  422.    drawdata(data5,0,3);
  423.    set(YSHIFT,116.97);
  424.    set(YMULT,500.0);
  425.    a_qw_box(); 
  426.    moveto(-190,10.29);
  427.    lineto(190,10.29);
  428.    moveto(-190,40.81);
  429.    lineto(190,40.81);
  430.    moveto(-190,154.16);
  431.    lineto(190,154.16);
  432.    stroke();
  433.    text(215,10.29,"E_0_",CENTER);
  434.    text(215,40.81,"E_1_",CENTER);
  435.    text(215,154.16,"E_5_",CENTER);
  436.    text(0,200,"c) Asymmetric CDQW",CENTER);
  437.    grestore();
  438.    set(LINECOLOUR,BLACK);
  439.    set(FONTWIDTH,1.);
  440.    set(FONTASPECT,2.5);
  441.    moveto(20.91,36.9);
  442.    arrowto(20.0,36.9);
  443.    moveto(20.91,36.9);
  444.    arrowto(22.0,36.9);
  445.    moveto(25.5,33.02);
  446.    arrowto(25.5,36.53);
  447.    moveto(25.5,31.79);
  448.    arrowto(25.5,27.95);
  449.    moveto(9.9,16.90);
  450.    arrowto(9.9,23.02);
  451.    moveto(9.9,15.70);
  452.    arrowto(9.9,7.93);
  453.    moveto(21.4,15.14);
  454.    arrowto(20.8,15.14);
  455.    stroke();
  456.    }
  457.  
  458. int s_qw_box()
  459.    {
  460.    set(LINEWIDTH,0.06);
  461.    cmatch();
  462.    /* draw quantum well box */
  463.    moveto(-225.,107.27);
  464.    lineto(-145.,107.27);
  465.    lineto(-145.,0.);
  466.    lineto(-45.,0.);
  467.    lineto(-45.,107.27);
  468.    lineto(45.,107.27);
  469.    lineto(45.,0.);
  470.    lineto(145.,0.);
  471.    lineto(145.,107.27);
  472.    lineto(225.,107.27);
  473.    stroke();
  474.    set(LINEWIDTH,0.02);
  475.    }
  476.  
  477. int a_qw_box()
  478.    {
  479.    set(LINEWIDTH,0.06);
  480.    cmatch();
  481.    /* draw quantum well box */
  482.    moveto(-225.,188.36);
  483.    lineto(-145.,188.36);
  484.    lineto(-145.,0.);
  485.    lineto(-45.,0.);
  486.    lineto(-45.,188.36);
  487.    lineto(45.,188.36);
  488.    /* 188.36-107.27  */
  489.    lineto(45.,81.09);
  490.    lineto(145.,81.09);
  491.    lineto(145.,188.36);
  492.    lineto(225,188.36);
  493.    stroke();
  494.    set(LINEWIDTH,0.02);
  495.    }
  496. \end{verbatim}
  497. }
  498.  
  499. \newpage
  500. \section{landscap.spt}                                                            
  501.  
  502. \vspace*{0.1cm}
  503. \special{psfile=landscap.eps hscale=40 vscale=40 hoffset=230 voffset=-350}
  504.  
  505. {\tt
  506. \begin{verbatim}
  507. #include <splot.h>                                  
  508. double *data1,*data2;
  509. main() 
  510.    {   
  511.  
  512.    /* select landscape orientation */
  513.    set(PAGE_ROT,ON);
  514.    set(LINEWIDTH,0.09); 
  515.    axes_box(20,14,1.5088,0,1.515,1.03e8,3,3);
  516.  
  517.    set(TICKLENGTH,0.5);
  518.    tickmarks(XAXES,1.510,1.515);
  519.  
  520.    set(LINEWIDTH,0.06); 
  521.    set(FONTWIDTH,0.8);
  522.    /* use short squat letters for labels */
  523.    set(FONTASPECT,1.1);
  524.    set(FONT,COMPLEX);
  525.    ticklabel(LOWER,1.510,1.515);
  526.    set(FONTWIDTH,1.0);
  527.    label(LEFT,"Relative PL Intensity");
  528.    text(9.00,1.90,"Photon energy (eV)");
  529.    text(20.00,15.00,"12 T");
  530.    text(21.00,13.00,"a)");
  531.    text(21.00,7.00,"b)");
  532.    set(FONTWIDTH,0.70);
  533.    text(13.47,9.84,"2p_0_");
  534.    text(5.70,8.35,"3p_0_");
  535.    text(8.80,6.46,"2s");
  536.    text(4.80,5.40,"3d_0_");
  537.    text(3.82,5.30,"3s");
  538.    text(7.65,5.70,"3p_-_");
  539.    text(11.65,5.60,"3d_-1_");
  540.    set(FONTWIDTH,0.75);
  541.    text(13.65,16.10,"a");
  542.    text(14.70,14.60,"b");
  543.    text(16.25,13.75,"b*");
  544.    text(16.80,13.10,"c*");
  545.        
  546.    set(LINEWIDTH,0.05); 
  547.    set(TICKLENGTH,0.35);
  548.    tickmarks(XAXES,1.509,1.511,1.512,1.513,1.514,1.516);
  549.        
  550.    /* constrain plot to axes box */
  551.    set(AXESCLIP,ON);
  552.  
  553.    /* change x axis units to eV */
  554.    set(XMULT,0.1239842e-3);   
  555.        
  556.    /* plot first spectrum */
  557.    set(XSHIFT,0);     
  558.    set(YSHIFT,47e6);     
  559.    set(YMULT,300);
  560.    readdata("demo\fe21m23a.dat",data1);
  561.    set(YRANGE,0,99e6);
  562.    drawdata(data1,0,1);
  563.  
  564.    /* plot second spectrum shifted up */
  565.    set(YSHIFT, 7e6);     
  566.    set(YMULT,150);
  567.    readdata("demo\fe22v31a.dat",data2);
  568.    set(YRANGE,0,45e6);
  569.    drawdata(data2,0,1);
  570.    }                                                
  571. \end{verbatim}
  572. }
  573.  
  574. \newpage
  575. \section{intcalc.spt}
  576.  
  577. \vspace*{.1cm}
  578. \special{psfile=intcalc.eps hscale=40 vscale=40 hoffset=275 voffset=-450}
  579. \index{math, example}
  580.  
  581. {\tt
  582. \begin{verbatim}
  583. #include <splot.h>
  584.  
  585. /* This example file illustrates some of the internal math capabilities */ 
  586. /* In this case  x,y data points for several parabolas are calculated */
  587. /* and then drawn. Also the photon uses the sine function to draw a wave. */
  588. /* For the photon the data is not stored in an array, rather the calculated */ 
  589. /* values are added to offsets given as parameters to the photon subroutine */
  590.  
  591. /* make space for the to be generated data */
  592. double pdat[101][2];
  593.  
  594. main()
  595.    {
  596.    double x0,y0;
  597.  
  598.    x0 = 10;
  599.    y0 = 5.5;
  600.  
  601.    /* draw parabolas at x0,y0  to represent bands*/
  602.    siband(x0,y0);
  603.  
  604.    /* draw circles to represent holes in the valence band */
  605.    arc(x0 - 0.5,y0 - 0.25,0.25,0,360);
  606.    stroke();
  607.    arc(x0 + 0.5,y0 - 0.25,0.25,0,360);
  608.    stroke();
  609.  
  610.    /* draw electrons in the conduction band */
  611.    moveto(x0 + 4.25,y0 + 3.25);
  612.    rlineto(-0.5,0);
  613.    moveto(x0 - 4.25,y0 + 3.25);
  614.    rlineto(0.5,0);
  615.    stroke();
  616.  
  617.    /* draw arrows to indicate optical transitions */
  618.    moveto(x0 + 3.5,y0 + 2.75);
  619.    arrowto(x0 + 1,y0 + 0.25);
  620.    moveto(x0 - 3.5,y0 + 2.75);
  621.    arrowto(x0 - 1,y0 + 0.25);
  622.  
  623.    /* label the photon */
  624.    text(x0 + 5, y0,"h!w! = 2E_g_");
  625.    /* but bar through h */
  626.    moveto(x0 + 4.95,y0 + 0.16);
  627.    rlineto(0.3,0.3);
  628.    stroke();
  629.  
  630.    /* draw bands again but higher up */
  631.    x0 = 10;
  632.    y0 = 19;
  633.    siband(x0,y0);
  634.  
  635.    /* draw single hole */
  636.    arc(x0,y0 - 0.25,0.25,0,360);
  637.    stroke();
  638.  
  639.    /* draw single electron */
  640.    moveto(x0 + 4.25,y0 + 3.25);
  641.    rlineto(-0.5,0);
  642.    stroke();
  643.    moveto(x0 + 3.5,y0 + 2.75);
  644.    arrowto(x0 + 0.5,y0 + 0.25);
  645.  
  646.    /* label photon */
  647.    text(x0 + 5, y0,"h!w! = E_g_");
  648.    moveto(x0 + 4.95,y0 + 0.16);
  649.    rlineto(0.3,0.3);
  650.    stroke();                
  651.  
  652.    /* add titles */
  653.    text(10.0,25.15,"Infrared Luminescence",CENTER);
  654.    text(10.0,11.8,"Visible Luminescence",CENTER);
  655.    }
  656.  
  657. int siband(double x0,y0)
  658.    {
  659.  
  660.    /* draws strained SiGe band structure */
  661.    /* as a set of parabolas */
  662.    parab(x0,y0,0.1,-0.1);
  663.    parab(x0,y0 - 1.0,0.05,-0.3);
  664.    parab(x0 - 4.0,y0 + 3.0,0.05,0.3);
  665.    parab(x0 + 4.0,y0 + 3.0,0.05,0.3);
  666.  
  667.    /* draw axes */
  668.    moveto(x0,y0 - 4.0);
  669.    rlineto(0,0.3);
  670.    moveto(x0,y0 - 4.0);
  671.    rarrowto(6,0);
  672.    moveto(x0,y0 - 4.0);
  673.    rarrowto(-6,0);
  674.    stroke();
  675.    moveto(x0 - 7, y0);
  676.    rarrowto(0,3);
  677.    rarrowto(0,-3);
  678.    moveto(x0 - 7.25,y0);
  679.    rlineto(0.5,0);
  680.    moveto(x0 - 7.25,y0 + 3);
  681.    rlineto(0.5,0);
  682.    stroke();
  683.  
  684.    /* draw a photon */
  685.    photon(x0 + 4.5,y0 + 1.5,0.3,0.3);
  686.  
  687.    /* a k vector labels */
  688.    text(x0,y0 - 5,"0",CENTER);
  689.    text(x0 + 6,y0 - 5,"k");
  690.    text(x0 - 7.5,y0 + 1.5,"E_g_",RIGHT);
  691.    }
  692.  
  693. int parab(double x0,double y0,double dx,double a)
  694.    {
  695.    int i;
  696.    double x;
  697.    /* draws a parabola by generating */
  698.    /* a data array first */
  699.    for (i = 0; i <= 50;i++)
  700.       {
  701.       x = i * dx;
  702.       pdat[50 + i][1] = a * x * x + y0; 
  703.       pdat[50 - i][1] = a * x * x + y0; 
  704.       pdat[50 + i][0] = x0 + x;
  705.       pdat[50 - i][0] = x0 - x;
  706.       }
  707.    moveto(pdat[0][0],pdat[0][1]);
  708.    for (i = 0;i <= 100;i++)
  709.       {
  710.       lineto(pdat[i][0],pdat[i][1]);
  711.       }
  712.    stroke();
  713.    }
  714.  
  715. int photon(double x0,double y0,double xscale,double yscale)
  716.    {
  717.    double x,y;
  718.    int i;
  719.  
  720.    /* draw a photon using the sine function */
  721.    moveto(x0,y0);
  722.    for (i = 0;i < 50;i++)
  723.       {
  724.       x = i * 0.255;
  725.       y = sin(x);
  726.       lineto(x * xscale + x0,y * yscale + y0);
  727.       }
  728.    set(FONTMULT,2);    
  729.    rarrowto(2.5 * xscale,0);
  730.    set(FONTMULT,0.5);    
  731.    stroke();
  732.    }
  733. \end{verbatim}
  734. }
  735.  
  736. \newpage
  737. \section{linedraw.spt} 
  738.  
  739. \vspace*{16cm} 
  740. \special{psfile=linedraw.eps hscale=60 vscale=60 hoffset=1 voffset=0}
  741. \index{drawing, example}
  742.  
  743. {\tt
  744. \begin{verbatim}
  745. /* This file illustrates how to generate a line drawing of apparatus */ 
  746. /* It makes heavy use of gsave() and grestore() and axes transformations*/
  747. /* to draw elements repeatedly in different locations and/or orientations */
  748. /* This is just one way to do this. */
  749.  
  750. #include <splot.h>
  751.  
  752. main()
  753.    {
  754.    /* it turned out too big in the end so scale it back some */
  755.    scale(0.75,0.75);
  756.  
  757.    /* draw Dewar */
  758.    tail();
  759.    gsave();
  760.    /* draw a slightly bigger tail around the first */
  761.    scale(1.25,1.05);
  762.    translate(-1.05,-0.5); 
  763.    tail();
  764.    grestore();
  765.  
  766.    /* draw lenses */
  767.    newpath();
  768.    set(LINECOLOUR,BROWN);
  769.    gsave();
  770.    translate(12.79,10.85);
  771.    rotate(90);
  772.    scale(2,2);
  773.    lens();
  774.    grestore();
  775.    gsave();
  776.    translate(11.09,6.21);
  777.    scale(0.5,0.5);
  778.    lens();
  779.    grestore();
  780.  
  781.    /* draw the prism */
  782.    gsave();
  783.    translate(10.84,10.6);
  784.    prism();
  785.    grestore();
  786.  
  787.    /* draw helium level */
  788.    set(LINECOLOUR,BLUE);
  789.    moveto(2.44,8.08);
  790.    curveto(3.13,7.66,3.82,8.68,4.13,7.96);
  791.    curveto(4.89,8.38,5.32,7.72,5.89,8.20);
  792.    curveto(6.58,7.72,7.08,8.74,7.77,8.08);
  793.    stroke();
  794.  
  795.    /* draw 45 degree fold mirror */
  796.    set(LINECOLOUR,BLACK);
  797.    moveto(4.07,11.72);
  798.    lineto(5.64,10.15,5.44,9.95,3.64,11.72);
  799.    closepath();
  800.  
  801.    /* draw diamnond anvil cell */
  802.    moveto(3.38,11.72);
  803.    lineto(6.82,11.72,6.82,17.07,7.33,17.07,7.33,17.73,2.88,17.73,
  804.           2.88,17.07,3.38,17.07);
  805.    closepath();
  806.    moveto(3.82,17.72);
  807.    lineto(3.82,18,6.33,18,6.33,17.72);
  808.    stroke();
  809.  
  810.    /* draw plate and screws */
  811.    moveto(2.88,18.0);
  812.    lineto(7.33,18.0,7.33,18.76,2.88,18.76);
  813.    closepath();
  814.    stroke();
  815.    gsave();
  816.    translate(3.38,18.76);
  817.    screw(1.5);
  818.    translate(3.45,0);
  819.    screw(1.5);
  820.    grestore();
  821.  
  822.    /* draw heater */
  823.    gsave();
  824.    translate(7.0,13.03);
  825.    heater();
  826.    translate(-3.8,0);
  827.    heater();
  828.    grestore();
  829.  
  830.    /* draw slits */
  831.    gsave();
  832.    translate(21.8,11.0);
  833.    slit();
  834.    grestore();
  835.    gsave();
  836.    scale(1,-1);
  837.    translate(21.8,-10.6);
  838.    slit();
  839.    grestore();
  840.  
  841.    /* draw periscope */
  842.    moveto(22.82,10.45);
  843.    lineto(23.57,11.18);
  844.    rlineto(0,2, 0.75,0, 0,1.5, -2,0, 0,-1.5, 0.75,0, 0,-2, 0.5,0);
  845.    stroke();
  846.  
  847.    /* draw arrows */
  848.    moveto(25.66,14.07);
  849.    arrowto(25.66,14.79);
  850.    moveto(25.66,14.07);
  851.    arrowto(25.66,13.35);
  852.    stroke();
  853.  
  854.    /* draw screw drivers and light pipe */
  855.    moveto(4.76,18.76);
  856.    lineto(4.76,30.0);
  857.    moveto(5.45,18.76);
  858.    lineto(5.45,30.0);
  859.    stroke();
  860.    gsave();
  861.    translate(3.38,18.9);
  862.    driver();
  863.    translate(3.45,0);
  864.    driver();
  865.    grestore();
  866.  
  867.    /* white out some of the lines at */
  868.    /* the top that turned out too long */
  869.    white_box(1.17,29.67,8.61,31.20);
  870.    newpath();
  871.  
  872.    /* draw copper gasket */
  873.    gsave();
  874.    set(LINECOLOUR,GREEN);
  875.    set(LINEWIDTH,0.10);
  876.    moveto(4.57,13.7);
  877.    lineto(5.57,13.7);
  878.    stroke();
  879.    grestore();
  880.  
  881.    /* draw dashed lines in diamond cell */
  882.    set(LINESTYLE,0.5,0.25);
  883.    moveto(3.82,17.72);
  884.    lineto(3.82,12.60,6.33,12.60,6.33,17.72);
  885.    moveto(3.82,14.8);
  886.    lineto(6.33,14.8);
  887.    moveto(4.76,14.8);
  888.    lineto(4.76,18.76);
  889.    moveto(5.45,14.8);
  890.    lineto(5.45,18.76);
  891.    moveto(4.76,12.6);
  892.    lineto(4.38,11.72);
  893.    moveto(5.45,12.6);
  894.    lineto(5.83,11.72);
  895.    stroke();
  896.  
  897.    /* draw the sapphire anvils */
  898.    gsave();
  899.    translate(4.32,12.6);
  900.    anvil();
  901.    translate(1.5,2.2);
  902.    rotate(180);
  903.    anvil();
  904.    grestore();
  905.    stroke();
  906.  
  907.    /* draw light paths */
  908.    set(LINECOLOUR,MAGENTA);
  909.    moveto(5.1,13.57);
  910.    lineto(5.1,10.85,11.09,10.85,11.09,0.06);
  911.    moveto(13.35,12.9);
  912.    lineto(4.7,11.22,5.1,13.51,5.45,10.43,13.35,8.74);
  913.    moveto(13.35,12.9);
  914.    lineto(21.73,10.85,13.35,8.74);
  915.    stroke();
  916.  
  917.    /* add comments */
  918.    set(LINECOLOUR,BLACK);
  919.    set(LINESTYLE,0);
  920.    set(FONTWIDTH,1.0);
  921.    text(2.33,32.29,"High Pressure, Low Temperature Spectroscopy");
  922.    set(FONTWIDTH,0.6);
  923.    text(3.57,4.58,"Liquid He");
  924.    text(22.65,15.60,"CCD");
  925.    text(19.81,7.39,"Spectrometer");
  926.               text("   Slits");
  927.    text(9.5,16.7,"Sapphire Anvil Cell");
  928.    text(9.5,14,"Heater");
  929.    text(9.5,23.88,"Light Pipe");
  930.    text(9.5,27,"Screw Drivers");
  931.  
  932.    /* draw lines to labelled parts */
  933.    set(LINEWIDTH,0.01);
  934.    moveto(4.76,5.46);
  935.    lineto(5.68,6.91);
  936.    moveto(9.19,13.99);
  937.    lineto(7.27,13.75);
  938.    moveto(9.27,16.64);
  939.    lineto(7.02,16.16);
  940.    moveto(9.27,23.96);
  941.    lineto(5.68,23.64);
  942.    moveto(9.27,27.02);
  943.    lineto(7.27,26.38);
  944.    moveto(9.27,27.02);
  945.    lineto(3.76,26.78);
  946.    stroke();
  947.    }
  948.  
  949. int anvil()
  950.    {
  951.    /* draw a sapphire anvil */
  952.    newpath();
  953.    moveto(0,0);
  954.    rlineto(0,0.5,0.5,0.5,0.5,0,0.5,-0.5,0,-0.5);
  955.    stroke();
  956.    }
  957.  
  958. int screw(double len)
  959.    {
  960.    int i,j;
  961.    /* draw a screw using a loop for */
  962.    /* the threads */
  963.    newpath();
  964.    moveto(0,0);
  965.    rlineto(0.25,0,0,0.25,-0.5,0,0,-0.25);
  966.    closepath();
  967.    moveto(0.15,0);
  968.    rlineto(0,-len,-0.3,0,0,len);
  969.    moveto(-0.15,0);
  970.    j = (int) (len / 0.2);
  971.    for (i=0;i < j;i++)
  972.       {
  973.       rmoveto(0.3,0);
  974.       rlineto(-0.30,-0.20);
  975.       }
  976.    stroke();
  977.    }
  978.  
  979. int heater()
  980.    {
  981.    int i;
  982.    /* draw a heater using a loop */
  983.    /* for the windings */
  984.    double y = 0;
  985.    newpath();
  986.    moveto(0,0);
  987.    for (i=0;i < 5;i++)
  988.       {
  989.       moveto(0.1,y);
  990.       arcn(0,y,0.1,360,0);
  991.       y = y + 0.4;
  992.       }
  993.    stroke();
  994.    }
  995.  
  996. int slit()
  997.    {
  998.    /* draw a spectrometer slit */
  999.    newpath();
  1000.    moveto(0,0);
  1001.    rlineto(0,1.5,0.25,0,0,-1.25);
  1002.    closepath();
  1003.    stroke();
  1004.    }
  1005.  
  1006. int driver()
  1007.    {
  1008.    /* draw long screw drivers */
  1009.    newpath();
  1010.    moveto(0,0);
  1011.    rlineto(0.15,0,0,0.25,0.1,0,0,10.8);
  1012.    moveto(0,0);
  1013.    rlineto(-0.15,0,0,0.25,-0.1,0,0,10.8);
  1014.    stroke();
  1015.    }
  1016.  
  1017. int white_box(double x1,double y1,double x2,double y2)
  1018.    { 
  1019.    /* draw a white filled box for */
  1020.    /* white out purposes. The parametrs */
  1021.    /* passed in are the box corners */
  1022.    newpath();
  1023.    box(x1,y1,x2,y2);
  1024.    gsave();
  1025.    set(LINECOLOUR,WHITE);
  1026.    fill();
  1027.    grestore();
  1028.    }
  1029.  
  1030. int lens()
  1031.    {
  1032.    /* draw a spherical lens using arcs */
  1033.    newpath();
  1034.    arcn(0,-4,4,110,70);
  1035.    arcn(0,3.45,4,290,250);
  1036.    closepath();
  1037.    stroke();
  1038.    }
  1039.  
  1040. int prism()
  1041.    {
  1042.    /* draw a prism */
  1043.    newpath();
  1044.    moveto(0,0.5);
  1045.    rlineto(0,-0.5,0.5,0);
  1046.    closepath();
  1047.    stroke();
  1048.    }
  1049.  
  1050. int tail()
  1051.    {
  1052.    /* draw the dewar tail */
  1053.    set(LINECOLOUR,BLACK);
  1054.    moveto(2.44,30);
  1055.    lineto(2.44,6.33,7.77,6.33,7.77,30);
  1056.    stroke();
  1057.    /* draw windows */
  1058.    set(LINECOLOUR,BROWN);
  1059.    white_box(2.29,12.30,2.59,9.41);
  1060.    stroke();
  1061.    white_box(7.62,12.30,7.92,9.41);
  1062.    stroke();
  1063.    }
  1064. \end{verbatim}
  1065. }
  1066.  
  1067.   
  1068. \newpage
  1069.  
  1070. \section{multplot.spt}                                                   
  1071.  
  1072. \vspace*{17cm}
  1073. \special{psfile=multplot.eps hscale=60 vscale=60 hoffset=1 voffset=0}
  1074. \index{math, example}
  1075.  
  1076. {\tt
  1077. \begin{verbatim}
  1078. #include <splot.h>
  1079.  
  1080. int i,j;
  1081. double calc[11][4];
  1082. double *data;
  1083.  
  1084. double calc2[11][4];
  1085. double *data2;
  1086.  
  1087. double calc3[11][4];
  1088. double *data3;
  1089.  
  1090. main() 
  1091.    {   
  1092.    /* read in data files */
  1093.    readdata("demo\mult1.dat",data);
  1094.    readdata("demo\mult2.dat",data2);
  1095.    readdata("demo\mult3.dat",data3);
  1096.        
  1097.    /* average batch values */
  1098.    for (i = 0; i < 11;i++)
  1099.       {
  1100.       for (j = 0;j < 10;j++)
  1101.          {
  1102.          calc[i][0] += data[i * 10 + j][0];
  1103.          calc[i][1] += data[i * 10 + j][1];
  1104.          calc[i][2] += data[i * 10 + j][2];
  1105.          calc[i][3] += data[i * 10 + j][3];
  1106.          calc2[i][0] += data2[i * 10 + j][0];
  1107.          calc2[i][1] += data2[i * 10 + j][1];
  1108.          calc2[i][2] += data2[i * 10 + j][2];
  1109.          calc2[i][3] += data2[i * 10 + j][3];
  1110.          calc3[i][0] += data3[i * 10 + j][0];
  1111.          calc3[i][1] += data3[i * 10 + j][1];
  1112.          calc3[i][2] += data3[i * 10 + j][2];
  1113.          calc3[i][3] += data3[i * 10 + j][3];
  1114.          }
  1115.       calc[i][0] /= 10;
  1116.       calc[i][1] /= 10;
  1117.       calc[i][2] /= 10;
  1118.       calc[i][3] /= 10;
  1119.       calc2[i][0] /= 10;
  1120.       calc2[i][1] /= 10;
  1121.       calc2[i][2] /= 10;
  1122.       calc2[i][3] /= 10;
  1123.       calc3[i][0] /= 10;
  1124.       calc3[i][1] /= 10;
  1125.       calc3[i][2] /= 10;
  1126.       calc3[i][3] /= 10;
  1127.       }
  1128.  
  1129.    abox(8,6,5,19.25);
  1130.    ascale(YAXES,0,100);
  1131.    ascale(XAXES,calc,0);
  1132.  
  1133.    /* set(YMULT,10);*/
  1134.    set(FONTMULT,0.7);
  1135.    set(TICKLENGTH,-0.2);
  1136.        
  1137.    tickmarks();
  1138.    ticklabel();
  1139.  
  1140.    text(14.03,22.25,"1024 Data Items");
  1141.  
  1142.    set(PLOTTYPE,SYM_LINES);
  1143.    set(AXESCLIP,ON);
  1144.    set(CURSYMBOL,OSQUARE);
  1145.  
  1146.    set(LINECOLOUR,RED);
  1147.    set(LINESTYLE,SOLID);
  1148.    drawdata(calc,0,1);
  1149.  
  1150.    set(CURSYMBOL,CROSS);
  1151.    set(LINECOLOUR,BLACK);
  1152.    set(LINESTYLE,DASHED);
  1153.    drawdata(calc,0,2);
  1154.  
  1155.    set(CURSYMBOL,OCIRCLE);
  1156.    set(LINECOLOUR,GREEN);
  1157.    set(LINESTYLE,DOTTED);
  1158.    drawdata(calc,0,3);
  1159.  
  1160.    /* the second data set */
  1161.    set(LINECOLOUR,BLACK);
  1162.    set(LINESTYLE,SOLID);
  1163.  
  1164.    abox(8,6,5,11);
  1165.    ascale(YAXES,calc2,1);
  1166.    ascale(XAXES,calc2,0);
  1167.  
  1168.    tickmarks();
  1169.    ticklabel();
  1170.  
  1171.    label(LEFT,"Throughput (TPS)");
  1172.    text(14.03,14,"128 Data Items");
  1173.  
  1174.    set(CURSYMBOL,OSQUARE);
  1175.  
  1176.    set(LINECOLOUR,RED);
  1177.    set(LINESTYLE,SOLID);
  1178.    drawdata(calc2,0,1);
  1179.  
  1180.    set(CURSYMBOL,CROSS);
  1181.    set(LINECOLOUR,BLACK);
  1182.    set(LINESTYLE,DASHED);
  1183.    drawdata(calc2,0,2);
  1184.  
  1185.    set(CURSYMBOL,OCIRCLE);
  1186.    set(LINECOLOUR,GREEN);
  1187.    set(LINESTYLE,DOTTED);
  1188.    drawdata(calc2,0,3);
  1189.  
  1190.    /* the third data set */
  1191.    set(LINECOLOUR,BLACK);
  1192.    set(LINESTYLE,SOLID);
  1193.  
  1194.    abox(8,6,5,2.75);
  1195.    ascale(YAXES,0,10);
  1196.    ascale(XAXES,calc3,0);
  1197.  
  1198.    tickmarks();
  1199.    ticklabel();
  1200.  
  1201.    text(14.03,5.75,"16 Data Items");
  1202.  
  1203.    set(CURSYMBOL,OSQUARE);
  1204.  
  1205.    set(LINECOLOUR,RED);
  1206.    set(LINESTYLE,SOLID);
  1207.    moveto(5.76,24.5);
  1208.    symbol(OSQUARE);
  1209.    rlineto(1.5,0);
  1210.    symbol(OSQUARE);
  1211.    drawdata(calc3,0,1);
  1212.  
  1213.    set(CURSYMBOL,CROSS);
  1214.    set(LINECOLOUR,BLACK);
  1215.    set(LINESTYLE,DASHED);
  1216.    moveto(5.76,23.6);
  1217.    symbol(CROSS);
  1218.    rlineto(1.5,0);
  1219.    symbol(CROSS);
  1220.    drawdata(calc3,0,2);
  1221.  
  1222.    set(CURSYMBOL,OCIRCLE);
  1223.    set(LINECOLOUR,GREEN);
  1224.    set(LINESTYLE,DOTTED);
  1225.    moveto(5.76,22.7);
  1226.    symbol(OCIRCLE);
  1227.    rlineto(1.5,0);
  1228.    symbol(OCIRCLE);
  1229.    drawdata(calc3,0,3);
  1230.  
  1231.    set(LINECOLOUR,BLACK);
  1232.    set(LINESTYLE,SOLID);
  1233.  
  1234.    label(BOTTOM,"Multi Programming Level");
  1235.    text(7.53,24.5,"MTL");
  1236.    text(7.53,23.6,"TPL");
  1237.    text(7.53,22.7,"TSO");
  1238.    }
  1239. \end{verbatim}
  1240. }
  1241.  
  1242. \newpage
  1243.  
  1244.