home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / math / ols / epp2tex.naw < prev    next >
Encoding:
Text File  |  1993-07-28  |  3.3 KB  |  135 lines

  1.  
  2. BEGIN {
  3.     serr = "/dev/tty";    # standard error
  4.     bs = "\\";        # used anytime I want a backslash
  5.     mc = "multicolumn";    # short form
  6.     bsmc = bs mc;    # short form
  7.  
  8.     fnum = 4; 
  9.     if (putfree==1) fnum++; if (putt==1) fnum++;
  10.         # how many fields/line is the generated table going to have?
  11.  
  12.     # Header:
  13.     print bs "documentstyle[11pt]{article}";
  14.     print bs "begin{document}"; print "";
  15.     print bs "begin{table}[h]";
  16.     print bs "centering";
  17.  
  18.     # Need to generate argument for \begin{tabular}
  19.     if (putfree==1) {
  20.         if (putt==1) llstring = "llcrrr";
  21.         else llstring = "llcrr";
  22.     } 
  23.     else {
  24.         if (putt==1) llstring = "llrrr";
  25.         else llstring = "llrr";
  26.     }
  27.     print bs "begin{tabular}{|" llstring "|} " bs "hline";
  28.  
  29.     # Headings at top of table:
  30.     print bsmc "{" fnum "} {|l|} {} " bs bs;
  31.     print "  " bsmc "{1} {|l} {} & {Parameter}";
  32.     if (putfree==1) print "& " bsmc "{1} {c}  {Free?}";
  33.     print "& " bsmc "{1} {c}  {Estimate}";
  34.     if (putt==0)    # no t-stat
  35.         print "& " bsmc "{1} {c|}  {Standard Error}" bs bs;
  36.     else {
  37.         print "& " bsmc "{1} {c}  {Standard Error}";
  38.         print "& " bsmc "{1} {c|}  {t-statistic} " bs bs;
  39.     }
  40.  
  41.     # horizantal line and a blank line:
  42.     print bsmc "{" fnum "}{|l|} {} " bs bs " " bs "hline";
  43.     print bsmc "{" fnum "}{|l|} {} " bs bs;
  44. }
  45.  
  46. # action on all lines:
  47. {taken = 0}    # this line has not yet been parsed.
  48.  
  49. # Look for captions
  50. ($1 ~ /[Cc][Aa]/) {
  51.     # collect together text of caption:
  52.     s = ""; for (i=2; i<=NF; i++) s = s $i " ";
  53.     # file it away into variable "captionstring"
  54.     captionstring = s;
  55.     # it's used in END
  56.     taken = 1;
  57.     # say I have parsed this line.
  58. }
  59.  
  60. # blank lines:
  61. ($1 ~ /[bB][lL]/) {
  62.     if (NF != 1) {
  63.         print "Error on line " NR ": only 1 field allowed." > serr;
  64.         goch=1; exit 1;
  65.     }
  66.     else
  67.         print bsmc "{" fnum "}{|l|} {} " bs bs;
  68.     taken = 1;
  69. }
  70.  
  71. # parameter estimates
  72. ($1 ~ /[eE][sS]/) {
  73.     label = $2;
  74.  
  75.     # parse "free":
  76.     free=-1;    # error code is -1
  77.     if (($3 ~ /[yY][eE][sS]/) || ($3 ~ /^[tT]/)) free=1;
  78.     if (($3 ~ /[nN][oO]/) || ($3 ~ /^[fF]/)) free = 0;
  79.     if (free == -1) {
  80.         print "Error in FREE parameter on line " NR > serr;
  81.         goch=1; exit 1;
  82.     }
  83.  
  84.     # Check number of fields on the line is ok.
  85.     expectfields = ((free == 0) ? 4 : 5);
  86.     if (NF != expectfields) {
  87.         print "Expect " expectfields " fields on line " NR > serr;
  88.         goch = 1; exit 1
  89.     }
  90.  
  91.     # Grab estimate, serror, compute t if needed.
  92.     theta = $4; 
  93.     se=""; if (free==1) se=$5;
  94.     t=""; if ((free==1) && (putt==1)) t = (1.0*theta)/(1.0*se);
  95.  
  96.     # Start creating the line to be emitted:
  97.     s = "{} & {" label "}";
  98.     if (putfree==1) s = s " & {" ((free==1) ? "Yes":"No") "}";
  99.     s = s " & {" theta "} & {" se "}";
  100.     
  101.     if (putt==1) s = s " & {" t "} " bs bs;
  102.     else s = s bs bs;
  103.  
  104.     print s;
  105.  
  106.     taken = 1;
  107. }
  108.  
  109. # comment lines:
  110. ($1 ~ /[cC][oO]/) {
  111.     s = ""; for (i=2; i<=NF; i++) s = s $i " ";
  112.     print bsmc "{" fnum "}{|l|} {{" bs "sf " s "}}" bs bs;
  113.     taken=1
  114. }
  115.  
  116. # if taken is still zero for this line, it's garbage.
  117. (taken == 0) {
  118.     print "Could not parse line " NR > serr;
  119.     goch = 1; exit 1;
  120. }
  121.  
  122. # Now close down things nicely and quit.
  123. END {
  124.     if (goch == 1) {
  125.         print "Fatal error... exiting" > serr
  126.         exit 1;
  127.     }
  128.     print bs mc "{" fnum "}{|l|} {}" bs bs bs "hline";
  129.     print bs "end{tabular}"
  130.     print bs "caption{" captionstring "}";
  131.     print bs "end{table}";
  132.     print bs "end{document}";
  133. }
  134.  
  135.