home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / reldb / part02 < prev    next >
Encoding:
Internet Message Format  |  1989-09-17  |  68.4 KB

  1. Subject:  v20i005:  Relational database and graphing tools, Part02/03
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: hafro.is!gunnar (Gunnar Stefansson)
  7. Posting-number: Volume 20, Issue 5
  8. Archive-name: reldb/part02
  9.  
  10. #!/bin/sh
  11. # to extract, remove the header and type "sh filename"
  12. if `test ! -d ./doc`
  13. then
  14.   mkdir ./doc
  15.   echo "mkdir ./doc"
  16. fi
  17. if `test ! -s ./doc/math.1`
  18. then
  19. echo "writting ./doc/math.1"
  20. cat > ./doc/math.1 << '\Rogue\Monster\'
  21. .\" Man page for math(1)
  22. .TH MATH 1 "1. April 1989"
  23. .SH NAME
  24. math - Simple mathematical summaries of a table
  25. .SH SYNOPSIS
  26. .B math
  27. [
  28. .I < data
  29. ]
  30. .SH DESCRIPTION
  31. .B Math
  32. reads columnar data from the standard input and outputs a few
  33. summary statistics.
  34. .LP
  35. This is best explained by way of an example. Suppose the file
  36. .I data
  37. contains the lines:
  38. .nf
  39. x       y       z       v
  40. -       -       -       -
  41. 0       1       2       3
  42. 1               3       4
  43. 2       3       4       5
  44. 3       4       5       6
  45. 4       5       6       7
  46. .fi
  47. where exactly one tab-character separates the columns (note 
  48. that the second y-value is missing - denoted by two adjacent 
  49. tabs).
  50. .LP
  51. The command 
  52. .I math < data
  53. yields:
  54. .nf
  55. x       y       z       v       Type
  56. -       -       -       -       ----
  57. 5       4       5       5       Freq
  58. 10      13      20      25      Sum
  59. 2       3       4       5       Mean
  60. 1.58114 1.70783 1.58114 1.58114 Stddev
  61. 4       5       6       7       Maximum
  62. 0       1       2       3       Minimum
  63. .fi
  64. on the standard output.
  65. .LP
  66. The output should be self-explanatory.
  67. .SH "SEE ALSO"
  68. .BR reldb(1),\ compute(1).
  69. .SH BUGS
  70. .LP
  71. .I Math 
  72. assumes that two tabs in a row denotes a missing value.
  73. This is usually a correct assumption - an empty columns is 
  74. normally a missing
  75. value and should not be counted or used in a sum.
  76. .LP
  77. .I Math
  78. only does simple checks for the number of digits appropriate
  79. for output. Sometimes this yields messy output, although most cases should 
  80. be reasonable, as in the above example.
  81. .LP
  82. No checks for invalid data are made.
  83. \Rogue\Monster\
  84. else
  85.   echo "will not over write ./doc/math.1"
  86. fi
  87. if `test ! -s ./doc/testdb.1`
  88. then
  89. echo "writting ./doc/testdb.1"
  90. cat > ./doc/testdb.1 << '\Rogue\Monster\'
  91. .\" Man page for testdb(1)
  92. .TH TESTDB 1 "1. June 1989"
  93. .SH NAME
  94. testdb - test reldb programs
  95. .SH SYNOPSIS
  96. .B testdb
  97. .SH DESCRIPTION
  98. Testdb sets up a directory, testdb, as a subdirectory under the user's
  99. home directory and runs some of the 
  100. .I reldb
  101. programs. 
  102. .P
  103. See the output files for more information.
  104. .SH "SEE ALSO"
  105. .BR reldb(1),\ testgr(1).
  106. .SH BUGS
  107. Not all programs are tested.
  108. \Rogue\Monster\
  109. else
  110.   echo "will not over write ./doc/testdb.1"
  111. fi
  112. if `test ! -s ./doc/testgr.1`
  113. then
  114. echo "writting ./doc/testgr.1"
  115. cat > ./doc/testgr.1 << '\Rogue\Monster\'
  116. .\" Man page for testgr(1)
  117. .TH TESTGR 1 "1. June 1989"
  118. .SH NAME
  119. testgr - test plot  programs in reldb package
  120. .SH SYNOPSIS
  121. .B testgr
  122. .SH DESCRIPTION
  123. Testdb sets up a directory, testgr, as a subdirectory under the user's
  124. home directory and copies sample programs and datafiles into it.
  125. .P
  126. See the shell scripts, t1, t2 etc. for more information.
  127. .SH "SEE ALSO"
  128. .BR reldb(1),\ testdb(1).
  129. .SH BUGS
  130. No known bugs.
  131. \Rogue\Monster\
  132. else
  133.   echo "will not over write ./doc/testgr.1"
  134. fi
  135. if `test ! -d ./misc`
  136. then
  137.   mkdir ./misc
  138.   echo "mkdir ./misc"
  139. fi
  140. if `test ! -s ./misc/install`
  141. then
  142. echo "writting ./misc/install"
  143. cat > ./misc/install << '\Rogue\Monster\'
  144. \Rogue\Monster\
  145. else
  146.   echo "will not over write ./misc/install"
  147. fi
  148. if `test ! -s ./misc/Makefile`
  149. then
  150. echo "writting ./misc/Makefile"
  151. cat > ./misc/Makefile << '\Rogue\Monster\'
  152. BINDIR=../bin
  153. CFLAGS= -DDEBUG=0
  154. DESTFILES=$(BINDIR)/relprint $(BINDIR)/qscat
  155.  
  156. all:
  157.     @echo "Use make install to install the scripts"
  158.  
  159. install: $(DESTFILES)
  160.     touch install
  161. $(BINDIR)/relprint : relprint.sh
  162.     cp  relprint.sh $(BINDIR)/relprint
  163.     chmod +x $(BINDIR)/relprint
  164.  
  165. $(BINDIR)/qscat : qscat.sh
  166.     cp  qscat.sh $(BINDIR)/qscat
  167.     chmod +x $(BINDIR)/qscat
  168.  
  169. \Rogue\Monster\
  170. else
  171.   echo "will not over write ./misc/Makefile"
  172. fi
  173. if `test ! -s ./misc/relprint.sh`
  174. then
  175. echo "writting ./misc/relprint.sh"
  176. cat > ./misc/relprint.sh << '\Rogue\Monster\'
  177. #!/bin/sh
  178. # reldbprint -- prepares printing of reldb table using tbl.
  179. #
  180. # Usage: reldbprint title < reldb_table
  181.  
  182. trap "rm -f /tmp/tmp$$" 2 15
  183.  
  184. caption="$*"        # tablecaption
  185.  
  186. cat - > /tmp/tmp$$
  187. read head < /tmp/tmp$$        # first get the header line
  188.  
  189. echo '.TS'                # tell tbl this is a table
  190.  
  191. echo 'center doublebox;'    # and to draw a nice box around it
  192. set - $head
  193. captctrl=c            # Tbl header for caption
  194. line1=c                # Handle header for first column
  195. line3=l                # assume first col is label
  196. shift
  197. for i                # set up remaining tbl header lines of c's and n's
  198. do
  199.     captctrl=$captctrl"s"
  200.     line1=$line1"c"        # Want to center column headers
  201.     line3=$line3"n"        # Assume rest of cols are numbers
  202. done
  203. line3=$line3"."        # add the dot to end the tbl format
  204. echo $captctrl
  205.  
  206. echo $line1        # output the tbl format 
  207. echo $line3        # statements
  208. echo .sp .3c
  209. echo $caption        # then the table caption
  210. echo .sp .3c
  211. echo =            # double underline for caption
  212. echo .sp .1c
  213. echo "$head"        # next line of table data is the prelude header
  214. echo .sp .1c
  215. echo "_"        # underline the header in the table
  216. sed 1,2d < /tmp/tmp$$    # now for the body of the table=data file
  217. echo '.TE'        # and end the pretty little thing
  218.  
  219. rm -f /tmp/tmp$$
  220. \Rogue\Monster\
  221. else
  222.   echo "will not over write ./misc/relprint.sh"
  223. fi
  224. if `test ! -s ./misc/qscat.sh`
  225. then
  226. echo "writting ./misc/qscat.sh"
  227. cat > ./misc/qscat.sh << '\Rogue\Monster\'
  228. #!/bin/sh
  229. #
  230. # qscat : a quick-and-dirty shell script for turning
  231. #         Reldb files into files which can be run through grap(1)
  232. #         to produce reasonable plots.
  233. #         (I didn't say production-quality, but these are certainly a good
  234. #         start - just edit the output)
  235. echo '
  236. \!! rasterize=300
  237. .DF
  238. .ce
  239. \fB'$*'\fR
  240. .G1
  241. frame ht 2 wid 5
  242. '
  243. awk '
  244. NR==1{for(i=1;i<=NF;i++){
  245.     name[i]=$(i)
  246.     }
  247.     print "label bot ","\"",name[1],"\""
  248.       }
  249. NR==3{for(i=1;i<=NF;i++){
  250.         prev[i]=$(i)
  251.         if(i>1)print "\""name[i]"\" ljust at "$1","$(i)
  252.         if(i==2)print "bullet at "$1","$(i)
  253.         if(i==3)print "circle at "$1","$(i)
  254.         if(i==4)print "plus at "$1","$(i)
  255.         if(i==5)print "delta at "$1","$(i)
  256.         if(i==6)print "box at "$1","$(i)
  257.         if(i==7)print "star at "$1","$(i)
  258.         if(i>=8)print "plus at "$1","$(i)
  259.       }
  260.           }
  261.     NR>3{for(i=2;i<=NF;i++){
  262.         if(i==2){
  263.             print "line from "prev[1]","prev[i]" to "$1","$(i)
  264.             print "bullet at "$1","$(i)
  265.         }
  266.         if(i==3){
  267.             print "line dashed from "prev[1]","prev[i]" to "$1","$(i)
  268.             print "circle at "$1","$(i)
  269.         }
  270.         if(i==4){
  271.             print "line dotted from "prev[1]","prev[i]" to "$1","$(i)
  272.             print "plus at "$1","$(i)
  273.         }
  274.         if(i==5){
  275.             print "delta at "$1","$(i)
  276.             print "line dashed 0.1i from "prev[1]","prev[i]" to "$1","$(i)
  277.         }
  278.         if(i==6){
  279.             print "box at "$1","$(i)
  280.             print "line from "prev[1]","prev[i]" to "$1","$(i)
  281.         }
  282.         if(i==7){
  283.             print "star at "$1","$(i)
  284.             print "line from "prev[1]","prev[i]" to "$1","$(i)
  285.         }
  286.         if(i>=8){
  287.             print "plus at "$1","$(i)
  288.             print "line from "prev[1]","prev[i]" to "$1","$(i)
  289.         }
  290.         prev[i]=$(i)
  291.          }
  292.          prev[1]=$1
  293.        }'
  294.  
  295. echo '.G2
  296. .DE'
  297. \Rogue\Monster\
  298. else
  299.   echo "will not over write ./misc/qscat.sh"
  300. fi
  301. if `test ! -d ./plot1.src`
  302. then
  303.   mkdir ./plot1.src
  304.   echo "mkdir ./plot1.src"
  305. fi
  306. if `test ! -s ./plot1.src/Makefile`
  307. then
  308. echo "writting ./plot1.src/Makefile"
  309. cat > ./plot1.src/Makefile << '\Rogue\Monster\'
  310. INCLUDES=/usr/local/include
  311. CFLAGS=-I$(INCLUDES)
  312. OBJ=plotfilter.o xplot.o hpglplot.o graplot.o
  313. BINDIR=../bin
  314.  
  315. all: xplot hpglplot graplot plot.sh
  316.  
  317. xplot : $(OBJ)
  318.     cc $(XCCFLAGS) -o xplot plotfilter.o xplot.o -lXaw -lXt -lX11 -lm
  319. hpglplot : $(OBJ)
  320.     cc -o hpglplot plotfilter.o hpglplot.o -lm
  321. graplot: graplot.o plotfilter.o
  322.     cc -o graplot graplot.o plotfilter.o
  323. install: xplot graplot hpglplot plot.sh testgr.sh
  324.     cp xplot graplot hpglplot $(BINDIR)
  325.     cp plot.sh $(BINDIR)/plot
  326.     chmod +x $(BINDIR)/plot
  327.     cp testgr.sh $(BINDIR)/testgr
  328.     chmod +x $(BINDIR)/testgr
  329.     cp graplot $(BINDIR)
  330.     touch install
  331.  
  332. clean: 
  333.     rm -f $(OBJ) xplot hpglplot graplot
  334. \Rogue\Monster\
  335. else
  336.   echo "will not over write ./plot1.src/Makefile"
  337. fi
  338. if `test ! -s ./plot1.src/README`
  339. then
  340. echo "writting ./plot1.src/README"
  341. cat > ./plot1.src/README << '\Rogue\Monster\'
  342. This directory contains  :
  343.     xplot, a plot(1) filter for X11.
  344.     hpglplot, a plot(1) filter for hpgl.
  345.     graplot, a plot(1) filter for grap output.
  346.  
  347. Xplot is derived from sunplot which arrived on the net a while ago. This
  348. program will open an X window for the plot output. After running make,
  349. try 
  350.     scat -E -Lw < data | xplot =300x300+100+100
  351.  
  352. It seems impossible to do some of the things required for simple plots,
  353. if using plot(5) only. Things like rotation and centering of labels are
  354. essential. Hence we have enhanced the commands a bit, and the
  355. enhancements are used by scat only if a special option is used. The
  356. enclosed plot-filters support these extensions.
  357.  
  358. The hpgl-filter is a modified version of an hpgl-filter which arrived on
  359. the net. The modifications are simply to allow for rotation and
  360. centering. These modifications are the only reasons for reposting.
  361.  
  362. Graplot will take plot(5)-data and write output for the grap-program.
  363. This is extremely handy for putting into a troff-style paper.
  364.  
  365. I (gunnar@hafro) apologize for not having gotten formal permission from
  366. previous authors (notable Jim Constantine and Scott Sutherland)
  367. to publish this modification of their code.
  368. Their code was published on the net, however, and no E-mail 
  369. addresses remained in the files when I obtained them.
  370.  
  371. WARNING: There is a bug in xplot. For some strange reason, the window
  372. manager awm will crash when xplot is started without any coordinate
  373. options. This is easily solved by always using some coordinates,
  374. e.g. scat < data | plot -Tx =300x300+100+100 -- or as in the above example.
  375. If anyone finds the problem, please let me know. The problem does not
  376. seem to appear with uwm.
  377. \Rogue\Monster\
  378. else
  379.   echo "will not over write ./plot1.src/README"
  380. fi
  381. if `test ! -s ./plot1.src/hpglplot.c`
  382. then
  383. echo "writting ./plot1.src/hpglplot.c"
  384. cat > ./plot1.src/hpglplot.c << '\Rogue\Monster\'
  385.  
  386. #include <sgtty.h>
  387. #include <stdio.h>
  388. #include <math.h>
  389.  
  390. /* HP-GL plot(5) library                */
  391. /* - does NOT do line locking                */
  392. /* - aspect ratio is not maintained            */
  393. /* Jim Constantine                                */
  394. /* Copyright 1985 Sun Microsystems Inc.            */
  395. /* Extensions by asta@hafro.is (March, 1989)         */
  396. /* Prepared for redistribution by gunnar@hafro.is    */
  397. /* Notable features, which are really bugs: This 
  398.    program assumes it is writing to a device. That 
  399.    causes problems when writing to e.g. hpgl2ps filters.
  400.    Use of some special HPGL escape sequences may also cause
  401.    problems                        */
  402.  
  403. openpl()
  404. {
  405.     struct sgttyb   sgarg;
  406.     int local;
  407.  
  408.     ioctl( fileno(stdout), TIOCGETP, &sgarg);
  409.     ioctl( fileno(stdout), TIOCLGET, &local);
  410.     sgarg.sg_ispeed = sgarg.sg_ospeed = B9600;
  411.     sgarg.sg_erase = sgarg.sg_kill = '#';
  412.     sgarg.sg_flags = EVENP | ODDP;
  413.     local = LDECCTQ;
  414.     ioctl( fileno(stdout), TIOCSETP, &sgarg);
  415.     ioctl( fileno(stdout), TIOCLSET, &local);
  416.  
  417.     /*printf("IN;\033.P1:");        /* out - gs */
  418.     printf("IN;");
  419.     fflush(stdout);
  420.  
  421.     printf("PG;AP 3;CA 10;CC 20;SR 0.6,1.2;SP 1;\n");
  422.     fflush(stdout);
  423. }
  424.  
  425. move(x, y)
  426. {
  427.     printf("PU %d,%d;\n", x, y);
  428. }
  429.  
  430. line(x1, y1, x2, y2)
  431. {
  432.     printf("PU %d,%d PD %d,%d;\n", x1, y1, x2, y2);
  433. }
  434.  
  435. label(s)
  436.     char   *s;
  437. {
  438.     printf("LB%s\03;\n", s);
  439. }
  440.  
  441. erase()
  442. {
  443.     printf("PG;AF;\n");        /* feed page if paper has been writen on */
  444. }
  445.  
  446. point(x, y)
  447. {
  448.     printf("PU %d,%d PD PU;\n", x, y);
  449. }
  450.  
  451. cont(x, y)
  452. {
  453.     printf("PD %d,%d;\n", x, y);
  454. }
  455.  
  456. space(x1, y1, x2, y2)
  457. {
  458.     printf("SC %d,%d %d,%d;\n", x1, x2, y1, y2);
  459. }
  460.  
  461. arc(xc, yc, x1, y1, x2, y2)
  462. {
  463.     /* args are:  center, start, end */
  464.     float angle;
  465.  
  466.     angle = atan((float) (y2 - y1) / (float) (x2 - x1)) * 5.729578e+01;
  467.     if ((x2 - x1) < 0) angle = 180.0 + angle;
  468.     move(x2,y2);
  469.     printf("AA %d,%d;%6.3f\n", x1, y1, angle);
  470. }
  471.  
  472. circle(x, y, r)
  473. {
  474.     move(x,y);
  475.     printf("CI %d;\n",r);
  476. }
  477.  
  478. linemod(s)            /* line style */
  479.     char *s;
  480. {
  481.     switch(s[3]) {
  482.  
  483.     case 't': /* dotTed */
  484.     printf("LT 1;\n");
  485.     break;
  486.  
  487.     case 'i': /* solId */
  488.     default:
  489.     printf("LT ;\n");
  490.     break;
  491.  
  492.     case 'g': /* lonGdashed */
  493.     printf("LT 3;\n");
  494.     break;
  495.  
  496.     case 'r': /* shoRtdashed */
  497.     printf("LT 2;\n");
  498.     break;
  499.  
  500.     case 'd': /* dotDashed */
  501.     printf("LT 4;\n");
  502.     break;
  503.     }
  504. }
  505.  
  506. labelrotation(s)
  507.     char *s;
  508. {
  509.  
  510.     switch(s[1]) {
  511.  
  512.     case 'h': /* horizontal */
  513.     printf("DI 1,0;\n");
  514.     break;
  515.  
  516.     case 'v': /* vertical */
  517.     printf("DI 0,1;\n");
  518.     break;
  519.     } 
  520. }
  521.  
  522.  
  523. labelplace(s)
  524.     char *s;
  525. {
  526.  
  527.     switch(s[1]) {
  528.  
  529.     case 'u': /* center the label under the point */
  530.     printf("LO16;\n");
  531.     break;
  532.  
  533.     case 'o': /* center the label over the point */
  534.     printf("LO14;\n");
  535.     break;
  536.  
  537.     case 'l': /* center the label left at the point */
  538.     printf("LO18;\n");
  539.     break;
  540.  
  541.     case 'r': /* center the label right at the point */
  542.     printf("LO12;\n");
  543.     break;
  544.  
  545.     case 'c': /* center the label at the point */
  546.     printf("LO15;\n");
  547.     break;
  548.  
  549.     default: /* center the label at the point */
  550.     printf("LO15;\n");
  551.     break;
  552.     } 
  553. }
  554.  
  555. selectcolor(s)
  556.     char *s;
  557. {
  558.  
  559.     switch(s[1]) {
  560.  
  561.     case '1': /* select pen 1 */
  562.     printf("SP 1;\n");
  563.     break;
  564.  
  565.     case '2': /* select pen 2 */
  566.     printf("SP 2;\n");
  567.     break;
  568.  
  569.     case '3': /* select pen 3 */
  570.     printf("SP 3;\n");
  571.     break;
  572.  
  573.     case '4': /* select pen 4 */
  574.     printf("SP 4;\n");
  575.     break;
  576.  
  577.     case '5': /* select pen 5 */
  578.     printf("SP 5;\n");
  579.     break;
  580.  
  581.     case '6': /* select pen 6 */
  582.     printf("SP 6;\n");
  583.     break;
  584.  
  585.     case '7': /* select pen 7 */
  586.     printf("SP 7;\n");
  587.     break;
  588.  
  589.     case '8': /* select pen 8 */
  590.     printf("SP 8;\n");
  591.     break;
  592.  
  593.     default: /* select pen 1 */
  594.     printf("SP 1;\n");
  595.     break;
  596.     } 
  597. }
  598.  
  599. closepl()
  600. {
  601.     printf ("SP;NR;PG;\n");
  602. }
  603.  
  604. \Rogue\Monster\
  605. else
  606.   echo "will not over write ./plot1.src/hpglplot.c"
  607. fi
  608. if `test ! -s ./plot1.src/plotfilter.c`
  609. then
  610. echo "writting ./plot1.src/plotfilter.c"
  611. cat > ./plot1.src/plotfilter.c << '\Rogue\Monster\'
  612.  
  613. #include <stdio.h>
  614.  
  615. static char buf[256];
  616. int    argc_copy;
  617. char    **argv_copy;
  618.  
  619. main(argc, argv)
  620.     int  argc;
  621.     char **argv;
  622. {
  623.     int x1,y1,x2,y2,x3,y3;
  624.     int r;
  625.     char c;
  626.  
  627.     argc_copy = argc;
  628.     argv_copy = argv;
  629.  
  630.     openpl();
  631.  
  632.     while ((c = getc(stdin)) != EOF) {
  633.  
  634.     switch (c) {
  635.         case 'm':             /* move */
  636.         x1 = getint();
  637.         y1 = getint();
  638.         move(x1,y1);
  639.         break;
  640.  
  641.          case 'n':            /* cont */
  642.                 x1 = getint();
  643.                 y1 = getint();
  644.         cont(x1,y1); 
  645.         break;
  646.                         
  647.         case 'p':            /* point */
  648.         x1 = getint();
  649.         y1 = getint();
  650.         point(x1,y1);
  651.         break;
  652.  
  653.         case 'l':             /* line */
  654.         x1 = getint();
  655.         y1 = getint();
  656.         x2 = getint();
  657.         y2 = getint();
  658.         line(x1,y1,x2,y2);
  659.         break;
  660.  
  661.         case 't':             /* text */
  662.         string(buf);
  663.         label(buf);
  664.         break;
  665.  
  666.         case 'e':             /* erase */
  667.         erase();
  668.         break;
  669.  
  670.         case 's':             /* space */
  671.         x1 = getint();
  672.         y1 = getint();
  673.         x2 = getint();
  674.         y2 = getint();
  675.         space(x1,y1,x2,y2);
  676.         break;
  677.  
  678.         case 'a':             /* arc */
  679.         x1 = getint();
  680.         y1 = getint();
  681.         x2 = getint();
  682.         y2 = getint();
  683.         x3 = getint();
  684.         y3 = getint();
  685.         arc(x1,y1,x2,y3,x3,y3);
  686.         break;
  687.  
  688.         case 'c':             /* circle */
  689.         x1 = getint();
  690.         y1 = getint();
  691.         r  = getint();
  692.         circle(x1,y1,r);
  693.         break;
  694.  
  695.         case 'f':             /* linemod */
  696.         string(buf);
  697.         linemod(buf);
  698.         break;
  699.  
  700.         case 'r':             /* homemade labelrotation*/
  701.         string(buf);
  702.         labelrotation(buf);
  703.         break;
  704.  
  705.         case 'u':             /* homemade labelplace*/
  706.         string(buf);
  707.         labelplace(buf);
  708.         break;
  709.  
  710.         case 'z':             /* homemade colorfunction*/
  711.         string(buf);
  712.         selectcolor(buf);
  713.         break;
  714.  
  715.         default: 
  716.         fprintf(stderr, "%s: unknown command 0x%x", argv[0], c & 0xff);
  717.         if (c >= ' ')
  718.               fprintf(stderr, " '%c'\n", c);
  719.           else
  720.               fprintf(stderr, " '^%c'\n", c + '@');
  721.     }
  722.     }
  723.     closepl();
  724. }
  725.  
  726. getint()
  727. {    
  728.     /* get an integer stored in 2 ascii bytes. */
  729.     short   b1,
  730.             b2;
  731.     if ((b1 = getchar()) == EOF)
  732.     return (EOF);
  733.  
  734.     if ((b2 = getchar()) == EOF)
  735.     return (EOF);
  736.  
  737.     b2 = b2 << 8;
  738.     return (b2 | b1);
  739. }
  740.  
  741. string(s)
  742.     char *s;
  743. {
  744.     for (; *s = getchar(); s++) {
  745.     if (*s == '\n')
  746.         break;
  747.     }
  748.     *s = '\0';
  749.     return;
  750. }
  751. \Rogue\Monster\
  752. else
  753.   echo "will not over write ./plot1.src/plotfilter.c"
  754. fi
  755. if `test ! -s ./plot1.src/xplot.c`
  756. then
  757. echo "writting ./plot1.src/xplot.c"
  758. cat > ./plot1.src/xplot.c << '\Rogue\Monster\'
  759. /************************************************************************
  760.  *   Plot(5) interface library for XWindows                *
  761.  *                                    *
  762.  *   Asta G. March 1989                                                 *
  763.  *   Adapted from a code for suntools by:                               *
  764.  *                                    *
  765.  *       Scott Sutherland, November 1987                    *
  766.  *       Boston University Math Department                       *
  767.  *                                    *
  768.  *   This was adapted from a code by:                    *
  769.  *       Jim Constantine, Janurary 1986                    *
  770.  *   which was in turn based on work by:                *
  771.  *       Mike Caplinger, Rice University, September 1984.        *
  772.  ***********************************************************************/
  773.  
  774. #include <stdio.h>
  775. #include <X11/Xlib.h>
  776. #include <X11/Xutil.h>
  777. #include <X11/Xatom.h>
  778. #include <strings.h>
  779.  
  780. #define FONT    "6x13.snf"
  781. #define ARG_FONT                "font"
  782.  
  783.  
  784. /* plot stuff */
  785. float         xscale = 1.0, yscale = 1.0;
  786. float         xorig = 0.0, yorig = 0.0;
  787. int         x, y;
  788. int        use_labelplace=0;  /* 0=false, 1=true */
  789. char        *label_pl;
  790. int        xheight, yheight, width;
  791. int winX, winY, winW, winH;
  792.  
  793. /* xwindow stuff */
  794. XWMHints        xwmh = {
  795.     (InputHint|StateHint),      /* flags */
  796.     False,                       /* no input from keyboard */
  797.     NormalState,                /* initial_state */
  798.     0,                          /* icon pixmap */
  799.     0,                          /* icon window */
  800.     0, 0,                       /* icon location */
  801.     0,                          /* icon mask */
  802.     0,                          /* Window group */
  803. };
  804.  
  805. char *ProgramName;
  806.  
  807. void Usage ()
  808. {
  809.         fprintf (stderr, "usage:  %s [-options ...]\n\n", ProgramName);
  810.         fprintf (stderr, "where options include:\n");
  811.         fprintf (stderr, "    -geometry geom           size of window\n");
  812.         fprintf (stderr, "\n");
  813.         exit (1);
  814. }
  815.  
  816. extern    int argc_copy;
  817. extern    char **argv_copy;
  818.  
  819. char **ap;
  820. char *geom = NULL;
  821. Display    *dpy;            /* X server connection */
  822. Screen *scr;
  823. Window      win;            /* Window ID */
  824. GC          gc;             /* GC to draw with */
  825. char        *fontName;      /* Name of the font to use */
  826. XFontStruct *fontstruct;    /* Font descriptor */
  827. unsigned long fth, ftw, pad;     /* Font size parameters */
  828. unsigned long fg, bg, bd;   /* Pixel values */
  829. unsigned long bw;           /* Border width */
  830. XGCValues   gcv;            /* Struct for creating GC */
  831. XEvent      event;          /* Event received */
  832. XSizeHints  xsh;            /* Size hints for window manager */
  833. char       *geomSpec;       /* Window geometry string */
  834. XSetWindowAttributes xswa;  /* Temporary Set Window Attribute struct
  835. Window win;
  836.  
  837. /************************************************************************/
  838. /*            openpl                        */
  839. /************************************************************************/
  840. openpl() {
  841.  
  842.  /* Process arguments: */
  843.     ap = argv_copy;  
  844.     while (*++ap) {
  845.         if (!strncmp(*ap, "-g", 2)) {
  846.                 if (*++ap) {
  847.                         geom = *ap;
  848.                 } else
  849.                         Usage ();
  850.         } else if (**ap == '=')
  851.                         geom = *ap;
  852.     }
  853.  
  854.   /*
  855.      * Open the display using the $DISPLAY environment variable to locate
  856.      * the X server.  See Section 2.1.
  857.      */
  858.     if ((dpy = XOpenDisplay(NULL)) == NULL) {
  859.         fprintf(stderr, "%s: can't open %s\n", argv_copy[0], XDisplayName(NULL));
  860.         exit(1);
  861.     }
  862.      /* Select the font to use */
  863.     if ((fontName = XGetDefault(dpy, argv_copy[0], ARG_FONT)) == NULL) {
  864.         fontName = FONT;
  865.     }
  866.     if ((fontstruct = XLoadQueryFont(dpy, fontName)) == NULL) {
  867.         fprintf(stderr, "%s: display %s doesn't know font %s\n",
  868.                 argv_copy[0], DisplayString(dpy), fontName);
  869.         exit(1);
  870.     }
  871.     fth = fontstruct->max_bounds.ascent + fontstruct->max_bounds.descent;
  872. /*    fth = fontstruct->ascent + fontstruct->descent; */
  873.     ftw = fontstruct->max_bounds.width;
  874.  
  875.         /*
  876.      * Select colors for the border,  the window background,  and the
  877.      * foreground.
  878.      */
  879.     bd = BlackPixel(dpy, DefaultScreen(dpy));
  880.     bg = WhitePixel(dpy, DefaultScreen(dpy));
  881.     fg = BlackPixel(dpy, DefaultScreen(dpy)); 
  882.  
  883.     /*
  884.      * Set the border width of the window
  885.      */
  886.      bw = 3;
  887.  
  888.      /*
  889.      * Create the Window with the information in the XSizeHints, the
  890.      * border width,  and the border & background pixels. See Section 3.3.
  891.      */
  892.      scr = DefaultScreenOfDisplay(dpy);
  893.      xsh.width = 500;
  894.      xsh.height = 300;
  895.      xsh.x = 0; 
  896.      xsh.y = 0;
  897.      xsh.flags = (PPosition | PSize); 
  898.   
  899.      if (geom) {
  900.         XParseGeometry(geom, &xsh.x, &xsh.y, &xsh.width, &xsh.height);
  901.     xsh.flags = (USPosition | USSize);
  902.      }
  903.         
  904.      win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
  905.                       xsh.x, xsh.y, xsh.width, xsh.height,
  906.                       bw, bd, bg);
  907.       
  908.      /* 
  909.      * Set the standard properties for the window managers. See Section
  910.      * 9.1.
  911.      */
  912.     XSetStandardProperties(dpy, win, "", "", None, argv_copy, argc_copy,&xsh);
  913.     XSetWMHints(dpy, win, &xwmh);
  914.  
  915.         scr = DefaultScreenOfDisplay(dpy);
  916.                 
  917.  
  918.      /*
  919.      * Ensure that the window's colormap field points to the default
  920.      * colormap,  so that the window manager knows the correct colormap to
  921.      * use for the window.  See Section 3.2.9. Also,  set the window's Bit
  922.      * Gravity to reduce Expose events.
  923.      */
  924.      xswa.save_under=True;
  925.      xswa.backing_store = Always;
  926.      xswa.colormap = DefaultColormap(dpy, DefaultScreen(dpy));
  927.      xswa.bit_gravity = CenterGravity;
  928.      XChangeWindowAttributes(dpy, win, (CWSaveUnder | CWBackingStore | CWColormap | CWBitGravity),&xswa);
  929.  
  930.      /*
  931.      * Create the GC for plotting.  See Section 5.3.
  932.      */
  933.  
  934.      gcv.font = fontstruct->fid;
  935.      gcv.foreground = fg;
  936.      gcv.background = bg;
  937. /*     gcv.function=GXand;
  938.      gcv.plane_mask=BlackPixel(dpy,DefaultScreen(dpy)) ^
  939.                     WhitePixel(dpy,DefaultScreen(dpy));    */
  940.      gc = XCreateGC(dpy, win, (GCFont | GCForeground | GCBackground ), &gcv);
  941.  
  942.     /*
  943.      * Specify the event types we're interested in - only Exposures. See
  944.      * Sections 8.5 & 8.4.5.1
  945.      */
  946.     XSelectInput(dpy, win, ExposureMask);
  947.      
  948.     /*
  949.      * Map the window to make it visible.  See Section 3.5.
  950.      */
  951.     XMapWindow(dpy, win);     
  952.     XNextEvent(dpy, &event);
  953.    
  954. }
  955. /************************************************************************/
  956. /*            move                        */
  957. /************************************************************************/
  958. move(x1, y1) {
  959.     x = scalex(x1);
  960.     y = scaley(y1);
  961. }
  962. /************************************************************************/
  963. /*            cont                        */
  964. /************************************************************************/
  965. cont(x1, y1) {
  966.     x1 = scalex(x1);
  967.     y1 = scaley(y1);
  968.     XDrawLine(dpy, win, gc, x, y, x1, y1);
  969.     x = x1;
  970.     y = y1;
  971.     XFlush(dpy);
  972. }
  973. /************************************************************************/
  974. /*            point                        */
  975. /************************************************************************/
  976. point(x, y) {
  977.     x = scalex(x);
  978.     y = scaley(y);
  979.     XDrawRectangle(dpy, win, gc, x, y, 1, 1);
  980.     XFlush(dpy);
  981. }
  982. /************************************************************************/
  983. /*            line                        */
  984. /************************************************************************/
  985. line(x1, y1, x2, y2) {
  986.     x1 = scalex(x1);
  987.     y1 = scaley(y1);
  988.     x2 = scalex(x2);
  989.     y2 = scaley(y2);
  990.     XDrawLine(dpy, win, gc, x1, y1, x2, y2);
  991.     XFlush(dpy);
  992. }
  993. /************************************************************************/
  994. /*            circle                        */
  995. /*        Not implemented                        */
  996. /************************************************************************/
  997. circle(x1, y1, r) {
  998.       x1=scalex(x1-r);
  999.       y1=scaley(y1-r);
  1000.       width=scalex(2*r);
  1001.       XDrawArc(dpy,win,gc,x1,y1,width,width,0,23040);
  1002.       XFlush(dpy);
  1003. }
  1004. /************************************************************************/
  1005. /*            arc                        */
  1006. /*        Not implemented                        */
  1007. /************************************************************************/
  1008. arc(cx, cy, sx, sy, ex, ey) 
  1009. {
  1010. }
  1011. /************************************************************************/
  1012. /*            label                        */
  1013. /************************************************************************/
  1014. label(s)
  1015. char *s;
  1016. {
  1017.     if(!use_labelplace){
  1018.           XDrawString(dpy, win, gc, x, y, s, strlen(s));
  1019.           XFlush(dpy);
  1020.           }
  1021.     else {
  1022.         switch(*label_pl){
  1023.         case 'u':
  1024.                       x=x-XTextWidth(fontstruct,s,strlen(s))/2;
  1025.                       y=y+fth;
  1026.                       XDrawString(dpy, win, gc, x, y, s, strlen(s));
  1027.                       XFlush(dpy);
  1028.                       break;
  1029.  
  1030.         case 'o': /* center the label over the point */
  1031.                       x=x-XTextWidth(fontstruct,s,strlen(s))/2;
  1032.                       XDrawString(dpy, win, gc, x, y, s, strlen(s));
  1033.                       XFlush(dpy);
  1034.                       break;
  1035.         
  1036.         case 'l': /* center the label left at the point */
  1037.                       x=x-XTextWidth(fontstruct,s,strlen(s));
  1038. /*              y=y-fth/2+fontstruct->ascent; */
  1039.               y=y-fth/2+fontstruct->max_bounds.ascent;
  1040.                       XDrawString(dpy, win, gc, x, y, s, strlen(s));
  1041.                       XFlush(dpy);
  1042.                       break;
  1043.         
  1044.             case 'r': /* center the label right at the point */
  1045. /*              y=y+fth/2;  */
  1046.               y=y-fth/2+fontstruct->max_bounds.ascent;
  1047.                       XDrawString(dpy, win, gc, x, y, s, strlen(s));
  1048.                       XFlush(dpy);
  1049.                   break;
  1050.     
  1051.             case 'c': /* center the label at the point */
  1052.                       x=x-XTextWidth(fontstruct,s,strlen(s))/2;
  1053.               y=y-fth/2+fontstruct->max_bounds.ascent;
  1054. /*              y=y+fth/2;  */
  1055.                       XDrawString(dpy, win, gc, x, y, s, strlen(s));
  1056.                       XFlush(dpy);
  1057.                   break;
  1058.     
  1059.             default: /* center the label at the point */
  1060.                       x=x-XTextWidth(fontstruct,s,strlen(s))/2;
  1061.               y=y-fth/2+fontstruct->max_bounds.ascent;
  1062. /*              y=y+fth/2;   */
  1063.                   XDrawString(dpy, win, gc, x, y, s, strlen(s));
  1064.                   XFlush(dpy);
  1065.                   break;
  1066.       }
  1067.      }
  1068. }
  1069. /************************************************************************/
  1070. /*            labelplace -- a homemade function                        */
  1071. /************************************************************************/
  1072. labelplace(s)
  1073.     char *s;
  1074. {
  1075.      
  1076.     switch(s[1]) {
  1077.  
  1078.     case 'u': /* center the label under the point */
  1079.         use_labelplace=1;
  1080.         label_pl="u";
  1081.         break;
  1082.     
  1083.     case 'o': /* center the label over the point */
  1084.         use_labelplace=1;
  1085.         label_pl="o";
  1086.         break;
  1087.         
  1088.     case 'l': /* center the label left at the point */
  1089.         use_labelplace=1;
  1090.         label_pl="l";
  1091.         break;
  1092.         
  1093.     case 'r': /* center the label right at the point */
  1094.         use_labelplace=1;
  1095.         label_pl="r";
  1096.         break;
  1097.     
  1098.     case 'c': /* center the label at the point */
  1099.         use_labelplace=1;
  1100.         label_pl="c";
  1101.         break;
  1102.  
  1103.     default: /* center the label at the point */
  1104.         use_labelplace=1;
  1105.         label_pl="c";
  1106.         break;
  1107.     }
  1108. }
  1109.  
  1110. /************************************************************************/
  1111. /*            labelrotation  - a homemade function            */
  1112. /*            not implemented                  */
  1113. /************************************************************************/
  1114. labelrotation(s)
  1115.     char *s;
  1116. {
  1117.         
  1118.     switch(s[1]) {
  1119.  
  1120.     case 'h': /* horizontal */
  1121.         break;
  1122.  
  1123.     case 'v': /* vertical */
  1124.         break;
  1125.     }
  1126. }
  1127.  
  1128. /************************************************************************/
  1129. /*              selectcolor  - a homemade function              */
  1130. /*            not implemented                  */
  1131. /************************************************************************/
  1132. selectcolor(s)
  1133.     char *s;
  1134. {
  1135.     
  1136.     switch(s[1]) {
  1137.         
  1138.     case '1': /* select pen 1 */
  1139.         break;
  1140.         
  1141.     case '2': /* select pen 2 */
  1142.         break;
  1143.         
  1144.     case '3': /* select pen 3 */
  1145.         break;
  1146.  
  1147.     case '4': /* select pen 4 */
  1148.         break;
  1149.  
  1150.     case '5': /* select pen 5 */
  1151.         break;
  1152.  
  1153.     case '6': /* select pen 6 */
  1154.         break;
  1155.     
  1156.     case '7': /* select pen 7 */
  1157.         break;
  1158.     
  1159.     case '8': /* select pen 8 */
  1160.         break;
  1161.  
  1162.     default: /* select pen 1 */
  1163.         break;
  1164.     }
  1165. }    
  1166.  
  1167. /************************************************************************/
  1168. /*            erase                        */
  1169. /************************************************************************/
  1170. erase() {
  1171.     XClearWindow(dpy, win);
  1172.     XFlush(dpy);
  1173. }
  1174.  
  1175. /************************************************************************/
  1176. /*            linemod                        */
  1177. /*            Not implemented                    */
  1178. /************************************************************************/
  1179. linemod(s)
  1180. char *s;
  1181. {
  1182.  
  1183.     switch(s[3]) {
  1184.     case 't': /* dotTed */
  1185.         break;
  1186.  
  1187.     case 'i': /* solId */
  1188.     default:
  1189.         break;
  1190.  
  1191.     case 'g': /* lonGdashed */
  1192.         break;
  1193.  
  1194.     case 'r': /* shoRtdashed */
  1195.         break;
  1196.  
  1197.     case 'd': /* dotDashed */
  1198.         break;
  1199.  
  1200.     }
  1201. }
  1202. /************************************************************************/
  1203. /*            space                        */
  1204. /************************************************************************/
  1205. space(xorigi, yorigi, x1, y1) {
  1206.     xorig = xorigi;
  1207.     yorig = yorigi;
  1208.     xscale = ((float) xsh.width) / (x1 - xorig);
  1209.     yscale = ((float) xsh.height) / (y1 - yorig);
  1210. }
  1211.  
  1212. /************************************************************************/
  1213. /*            closepl                        */
  1214. /************************************************************************/
  1215. closepl() {
  1216.   XFlush(dpy);
  1217.   sleep(100000);
  1218.   return;
  1219. }
  1220.  
  1221. /************************************************************************/
  1222. /*            scalex                        */
  1223. /************************************************************************/
  1224. static scalex(xi) {
  1225.     float x;
  1226.  
  1227.     x = xi;
  1228.     x -= xorig;
  1229.     x = x * xscale;
  1230.     return((int) x);
  1231. }
  1232. /************************************************************************/
  1233. /*            scaley                        */
  1234. /************************************************************************/
  1235. static scaley(yi) {
  1236.     float y;
  1237.  
  1238.     y = yi;
  1239.     y -= yorig;
  1240.     y = y * yscale;
  1241.     y = xsh.height - y; /* origin at lower left. */
  1242.     return((int) y);
  1243. }
  1244.  
  1245. \Rogue\Monster\
  1246. else
  1247.   echo "will not over write ./plot1.src/xplot.c"
  1248. fi
  1249. if `test ! -s ./plot1.src/plot.sh`
  1250. then
  1251. echo "writting ./plot1.src/plot.sh"
  1252. cat > ./plot1.src/plot.sh << '\Rogue\Monster\'
  1253. #!/bin/sh
  1254. #
  1255. # plot -- plot filter; controls execution of filter for
  1256. #                      appropriate device.
  1257. #
  1258. # DOES NOT CONTAIN AT&T CODE.
  1259. #
  1260. # There are currently available PD filters for at least HPGL, X11
  1261. # and Postscript. The first two are included in the reldb distribution,
  1262. # as the xplot program is new and the hpglplot program has been extended
  1263. # somewhat to accept a few extended plot(5)-commands.
  1264. #
  1265. # These three filters would seem to suffice for a very large number
  1266. # of applications. Development of general utilities which use the
  1267. # plot(5) output format would therefore seem to be of potentially 
  1268. # great use.
  1269. #
  1270. #
  1271. case $1 in
  1272. -T*)    devarg=$1
  1273.     shift ;;
  1274. *)    echo "Usage: plot -Tfilter [otherargs]"
  1275.     exit 1 ;;
  1276. esac
  1277. case $devarg in
  1278. -Thpgl)        hpglplot $* ;;
  1279. -TX*|-Tx*)    xplot $* ;;
  1280. -Tps*)        psplot $* ;;
  1281. -Tgrap*)    graplot $* ;;
  1282. esac
  1283. exit 0
  1284. \Rogue\Monster\
  1285. else
  1286.   echo "will not over write ./plot1.src/plot.sh"
  1287. fi
  1288. if `test ! -s ./plot1.src/graplot.c`
  1289. then
  1290. echo "writting ./plot1.src/graplot.c"
  1291. cat > ./plot1.src/graplot.c << '\Rogue\Monster\'
  1292. #include <sgtty.h>
  1293. #include <stdio.h>
  1294. #include <math.h>
  1295.  
  1296. /* HP-GL plot(5) library                */
  1297. /* - does NOT do line locking                */
  1298. /* - aspect ratio is not maintained            */
  1299. /* Jim Constantine                                */
  1300. /* Copyright 1985 Sun Microsystems Inc.            */
  1301. /* Extensions by ingi@hafro.is (June, 1989)         */
  1302. /* Prepared for redistribution by gunnar@hafro.is    */
  1303. /* Notable features: This program is to be used to
  1304.    create troff files.  It can be used to print to a 
  1305.    device without putting the statements through a file.
  1306.    just use scat < file | graplot | lprenta8        */
  1307.  
  1308. static char stre[15];
  1309. static char just[10];
  1310. static char jus1[10];
  1311. static char tex1[10];
  1312. openpl()
  1313. {
  1314.     struct sgttyb   sgarg;
  1315.     int local;
  1316.     printf("\\!! rasterize=300\n");
  1317.     printf(".G1\n");
  1318.  
  1319.     printf("frame invis ht 4 wid 6.2\n");
  1320.     printf("X=1\nY=0\n");
  1321.     printf("draw solid\n");
  1322. }
  1323. move(X, Y)
  1324. {
  1325.     /* printf("move from X,Y to %d,%d\n",X,Y);*/
  1326.     printf("X=%d\n",X);
  1327.     printf("Y=%d\n",Y);
  1328. }
  1329.  
  1330. line(X1, Y1, X2, Y2)
  1331. {
  1332.     printf("line %s from %d,%d to %d,%d\n", stre,X1, Y1, X2, Y2);
  1333. }
  1334.  
  1335. label(s)
  1336.     char   *s;
  1337. {
  1338.     printf("\"%s\" %s at X%s,Y%s\n",s,tex1,just,jus1);
  1339. }
  1340.  
  1341. erase()
  1342. {
  1343.     printf("\n");        /* feed page if paper has been writen on */
  1344. }
  1345.  
  1346. point(X, Y)
  1347. {
  1348.     printf("line %s from %d,%d to %d,%d\n",stre, X,Y,X, Y);
  1349. }
  1350.  
  1351. cont(X, Y)
  1352. {
  1353.     printf("line %s from X,Y to %d,%d\n", stre,X, Y);
  1354.     printf("X=%d\n",X);
  1355.     printf("Y=%d\n",Y);
  1356. }
  1357.  
  1358. space(X1, Y1, X2, Y2)
  1359. {
  1360.     printf("ticks bot out .0001i from %d to %d by %d \"\"\n",X1,X2,X2);
  1361.     printf("ticks left out .0001i from %d to %d by %d \"\"\n",X1,X2,X2);
  1362. }
  1363.  
  1364. arc(Xc, Yc, X1, Y1, X2, Y2)
  1365. {
  1366.     /* args are:  center, start, end */
  1367.  }
  1368.  
  1369. circle(X, Y, r)
  1370. {
  1371. }
  1372.  
  1373. linemod(s)            /* line stYle */
  1374.     char *s;
  1375. {
  1376.     switch(s[3]) {
  1377.  
  1378.     case 't': /* dotTed */
  1379.     printf("new dotted\n");
  1380.     strcpy(stre,"dotted");
  1381.     break;
  1382.  
  1383.     case 'i': /* solId */
  1384.     default:
  1385.     printf("new solid\n");
  1386.     strcpy(stre,"solid");
  1387.     break;
  1388.  
  1389.     case 'g': /* lonGdashed */
  1390.     printf("new dashed\n");
  1391.     strcpy(stre,"dashed");
  1392.     break;
  1393.  
  1394.     case 'r': /* shoRtdashed */
  1395.     printf("new dashed .5i\n");
  1396.     strcpy(stre,"dashed .1i");
  1397.     break;
  1398.  
  1399.     case 'd': /* dotDashed */
  1400.     printf("new dashed .05i\n");
  1401.     strcpy(stre,"dashed .05i");
  1402.     break;
  1403.     }
  1404. }
  1405.  
  1406. labelrotation(s)
  1407.     char *s;
  1408. {
  1409.  
  1410.  /*   switch(s[1]) {
  1411.  
  1412.     case 'h': 
  1413.     printf("DI 1,0\n");
  1414.     
  1415.  
  1416.     case 'v': 
  1417.     printf("DI 0,1\n");
  1418.     
  1419.     } 
  1420. */}
  1421.  
  1422.  
  1423. labelplace(s)
  1424.     char *s;
  1425. {
  1426.  
  1427.     switch(s[1]) {
  1428.  
  1429.     case 'u': /* center the label under the point */
  1430.     strcpy(just,"-0");
  1431.     strcpy(jus1,"-0");
  1432.         strcpy(tex1,"below");
  1433.     break;
  1434.  
  1435.     case 'o': /* center the label over the point */
  1436.     strcpy(just,"-0");
  1437.     strcpy(jus1,"+0");
  1438.         strcpy(tex1,"above");
  1439.     break;
  1440.  
  1441.     case 'l': /* center the label left at the point */
  1442.     strcpy(jus1,"-0");
  1443.     strcpy(just,"-0");
  1444.     strcpy(tex1,"rjust");
  1445.     break;
  1446.  
  1447.     case 'r': /* center the label right at the point */
  1448.     strcpy(jus1,"-0");
  1449.     strcpy(just,"+0");
  1450.     strcpy(tex1,"ljust");
  1451.     break;
  1452.  
  1453.     case 'c': /* center the label at the point */
  1454.     strcpy(just,"-0");
  1455.     strcpy(jus1,"-0");
  1456.         strcpy(tex1,"");
  1457.     break;
  1458.  
  1459.     default: /* center the label at the point */
  1460.     strcpy(just,"-0");
  1461.     strcpy(jus1,"-0");
  1462.         strcpy(tex1,"");
  1463.     break;
  1464.     } 
  1465. }
  1466.  
  1467. selectcolor(s)
  1468.     char *s;
  1469. {
  1470.  
  1471.     /* switch(s[1]) {
  1472.  
  1473.     case '1': /* select pen 1 
  1474.     printf("SP 1\n");
  1475.     break;
  1476.  
  1477.     case '2': /* select pen 2 
  1478.     printf("SP 2\n");
  1479.     break;
  1480.  
  1481.     case '3': /* select pen 3 
  1482.     printf("SP 3\n");
  1483.     break;
  1484.  
  1485.     case '4': /* select pen 4 
  1486.     printf("SP 4\n");
  1487.     break;
  1488.  
  1489.     case '5': /* select pen 5 
  1490.     printf("SP 5\n");
  1491.     break;
  1492.  
  1493.     case '6': /* select pen 6 
  1494.     printf("SP 6\n");
  1495.     break;
  1496.  
  1497.     case '7': /* select pen 7 
  1498.     printf("SP 7\n");
  1499.     break;
  1500.  
  1501.     case '8': /* select pen 8 
  1502.     printf("SP 8\n");
  1503.     break;
  1504.  
  1505.     default: /* select pen 1 
  1506.     printf("SP 1\n");
  1507.     break;
  1508.     } */ 
  1509. }
  1510.  
  1511. closepl()
  1512. {
  1513.     printf (".G2\n");
  1514. }
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524. \Rogue\Monster\
  1525. else
  1526.   echo "will not over write ./plot1.src/graplot.c"
  1527. fi
  1528. if `test ! -d ./plot1.src/Junk`
  1529. then
  1530.   mkdir ./plot1.src/Junk
  1531.   echo "mkdir ./plot1.src/Junk"
  1532. fi
  1533. if `test ! -s ./plot1.src/Junk/graplot.c`
  1534. then
  1535. echo "writting ./plot1.src/Junk/graplot.c"
  1536. cat > ./plot1.src/Junk/graplot.c << '\Rogue\Monster\'
  1537. #include <sgtty.h>
  1538. #include <stdio.h>
  1539. #include <math.h>
  1540.  
  1541. /* HP-GL plot(5) library                */
  1542. /* - does NOT do line locking                */
  1543. /* - aspect ratio is not maintained            */
  1544. /* Jim Constantine                                */
  1545. /* Copyright 1985 Sun Microsystems Inc.            */
  1546. /* Extensions by ingi@hafro.is (June, 1989)         */
  1547. /* Prepared for redistribution by gunnar@hafro.is    */
  1548. /* Notable features: This program is to be used to
  1549.    create troff files.  It can be used to print to a 
  1550.    device without putting the statements through a file.
  1551.    just use scat < file | graplot | lprenta8        */
  1552.  
  1553. static char stre[15];
  1554. static char just[10];
  1555. static char jus1[10];
  1556. static char tex1[10];
  1557. openpl()
  1558. {
  1559.     struct sgttyb   sgarg;
  1560.     int local;
  1561.     printf("\\!! rasterize=300\n");
  1562.     printf(".G1\n");
  1563.  
  1564.     printf("frame invis ht 4 wid 6.2\n");
  1565.     printf("X=1\nY=0\n");
  1566.     printf("draw solid\n");
  1567. }
  1568. move(X, Y)
  1569. {
  1570.     /* printf("move from X,Y to %d,%d\n",X,Y);*/
  1571.     printf("X=%d\n",X);
  1572.     printf("Y=%d\n",Y);
  1573. }
  1574.  
  1575. line(X1, Y1, X2, Y2)
  1576. {
  1577.     printf("line %s from %d,%d to %d,%d\n", stre,X1, Y1, X2, Y2);
  1578. }
  1579.  
  1580. label(s)
  1581.     char   *s;
  1582. {
  1583.     printf("\"%s\" %s at X%s,Y%s\n",s,tex1,just,jus1);
  1584. }
  1585.  
  1586. erase()
  1587. {
  1588.     printf("\n");        /* feed page if paper has been writen on */
  1589. }
  1590.  
  1591. point(X, Y)
  1592. {
  1593.     printf("line %s from %d,%d to %d,%d\n",stre, X,Y,X, Y);
  1594. }
  1595.  
  1596. cont(X, Y)
  1597. {
  1598.     printf("line %s from X,Y to %d,%d\n", stre,X, Y);
  1599.     printf("X=%d\n",X);
  1600.     printf("Y=%d\n",Y);
  1601. }
  1602.  
  1603. space(X1, Y1, X2, Y2)
  1604. {
  1605.     printf("ticks bot out .0001i from %d to %d by %d \"\"\n",X1,X2,X2);
  1606.     printf("ticks left out .0001i from %d to %d by %d \"\"\n",X1,X2,X2);
  1607. }
  1608.  
  1609. arc(Xc, Yc, X1, Y1, X2, Y2)
  1610. {
  1611.     /* args are:  center, start, end */
  1612.  }
  1613.  
  1614. circle(X, Y, r)
  1615. {
  1616. }
  1617.  
  1618. linemod(s)            /* line stYle */
  1619.     char *s;
  1620. {
  1621.     switch(s[3]) {
  1622.  
  1623.     case 't': /* dotTed */
  1624.     printf("new dotted\n");
  1625.     strcpy(stre,"dotted");
  1626.     break;
  1627.  
  1628.     case 'i': /* solId */
  1629.     default:
  1630.     printf("new solid\n");
  1631.     strcpy(stre,"solid");
  1632.     break;
  1633.  
  1634.     case 'g': /* lonGdashed */
  1635.     printf("new dashed\n");
  1636.     strcpy(stre,"dashed");
  1637.     break;
  1638.  
  1639.     case 'r': /* shoRtdashed */
  1640.     printf("new dashed .5i\n");
  1641.     strcpy(stre,"dashed .1i");
  1642.     break;
  1643.  
  1644.     case 'd': /* dotDashed */
  1645.     printf("new dashed .05i\n");
  1646.     strcpy(stre,"dashed .05i");
  1647.     break;
  1648.     }
  1649. }
  1650.  
  1651. labelrotation(s)
  1652.     char *s;
  1653. {
  1654.  
  1655.  /*   switch(s[1]) {
  1656.  
  1657.     case 'h': 
  1658.     printf("DI 1,0\n");
  1659.     
  1660.  
  1661.     case 'v': 
  1662.     printf("DI 0,1\n");
  1663.     
  1664.     } 
  1665. */}
  1666.  
  1667.  
  1668. labelplace(s)
  1669.     char *s;
  1670. {
  1671.  
  1672.     switch(s[1]) {
  1673.  
  1674.     case 'u': /* center the label under the point */
  1675.     strcpy(just,"-0");
  1676.     strcpy(jus1,"-15");
  1677.         strcpy(tex1,"");
  1678.     break;
  1679.  
  1680.     case 'o': /* center the label over the point */
  1681.     strcpy(just,"-0");
  1682.     strcpy(jus1,"+15");
  1683.         strcpy(tex1,"");
  1684.     break;
  1685.  
  1686.     case 'l': /* center the label left at the point */
  1687.     strcpy(jus1,"-0");
  1688.     strcpy(just,"-0");
  1689.     strcpy(tex1,"rjust");
  1690.     break;
  1691.  
  1692.     case 'r': /* center the label right at the point */
  1693.     strcpy(jus1,"-0");
  1694.     strcpy(just,"+0");
  1695.     strcpy(tex1,"ljust");
  1696.     break;
  1697.  
  1698.     case 'c': /* center the label at the point */
  1699.     strcpy(just,"-0");
  1700.     strcpy(jus1,"-0");
  1701.         strcpy(tex1,"");
  1702.     break;
  1703.  
  1704.     default: /* center the label at the point */
  1705.     strcpy(just,"-0");
  1706.     strcpy(jus1,"-0");
  1707.         strcpy(tex1,"");
  1708.     break;
  1709.     } 
  1710. }
  1711.  
  1712. selectcolor(s)
  1713.     char *s;
  1714. {
  1715.  
  1716.     /* switch(s[1]) {
  1717.  
  1718.     case '1': /* select pen 1 
  1719.     printf("SP 1\n");
  1720.     break;
  1721.  
  1722.     case '2': /* select pen 2 
  1723.     printf("SP 2\n");
  1724.     break;
  1725.  
  1726.     case '3': /* select pen 3 
  1727.     printf("SP 3\n");
  1728.     break;
  1729.  
  1730.     case '4': /* select pen 4 
  1731.     printf("SP 4\n");
  1732.     break;
  1733.  
  1734.     case '5': /* select pen 5 
  1735.     printf("SP 5\n");
  1736.     break;
  1737.  
  1738.     case '6': /* select pen 6 
  1739.     printf("SP 6\n");
  1740.     break;
  1741.  
  1742.     case '7': /* select pen 7 
  1743.     printf("SP 7\n");
  1744.     break;
  1745.  
  1746.     case '8': /* select pen 8 
  1747.     printf("SP 8\n");
  1748.     break;
  1749.  
  1750.     default: /* select pen 1 
  1751.     printf("SP 1\n");
  1752.     break;
  1753.     } */ 
  1754. }
  1755.  
  1756. closepl()
  1757. {
  1758.     printf (".G2\n");
  1759. }
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769. \Rogue\Monster\
  1770. else
  1771.   echo "will not over write ./plot1.src/Junk/graplot.c"
  1772. fi
  1773. if `test ! -s ./plot1.src/testgr.sh`
  1774. then
  1775. echo "writting ./plot1.src/testgr.sh"
  1776. cat > ./plot1.src/testgr.sh << '\Rogue\Monster\'
  1777. #!/bin/sh
  1778. #
  1779. # testgr -- user script for testing reldb programs.
  1780. #
  1781.  
  1782. PLOTDIR=/usr/local/src/Reldb/testgr
  1783.  
  1784. if [ ! -d $PLOTDIR ]
  1785. then
  1786.     echo "I can't seem to find the test data and programs"
  1787.     echo "Please edit my PLOTDIR variable properly"
  1788.     echo "(It is now set to $PLOTDIR, which is incorrect)"
  1789.     exit 1
  1790. fi
  1791.  
  1792. # Go home first - no need to clutter discs
  1793. cd
  1794. if [ ! -d testgr ]
  1795. then
  1796.     mkdir testgr
  1797. fi
  1798. cd testgr
  1799. PWD=`pwd`
  1800. echo "Copying programs and data into $PWD - hold on ..."
  1801. cp $PLOTDIR/* .
  1802. echo "Now run the sample programs, for example 't1 | xplot =500x500+300+300'"
  1803. \Rogue\Monster\
  1804. else
  1805.   echo "will not over write ./plot1.src/testgr.sh"
  1806. fi
  1807. if `test ! -s ./plot1.src/install`
  1808. then
  1809. echo "writting ./plot1.src/install"
  1810. cat > ./plot1.src/install << '\Rogue\Monster\'
  1811. \Rogue\Monster\
  1812. else
  1813.   echo "will not over write ./plot1.src/install"
  1814. fi
  1815. if `test ! -d ./reldb.src`
  1816. then
  1817.   mkdir ./reldb.src
  1818.   echo "mkdir ./reldb.src"
  1819. fi
  1820. if `test ! -s ./reldb.src/addcol.sh`
  1821. then
  1822. echo "writting ./reldb.src/addcol.sh"
  1823. cat > ./reldb.src/addcol.sh << '\Rogue\Monster\'
  1824. #!/bin/sh
  1825. #
  1826. # addcol - add columns to a table
  1827. #
  1828. # Usage: addcol columns < data
  1829. #
  1830. # Author: gunnar@hafro.is
  1831. # Revisions: none yet ?
  1832. #
  1833. # NOTE: This seems to generate an invalid table -- extra tabs
  1834. #       should be added in the data part.
  1835.  
  1836. add=
  1837. for i 
  1838. do
  1839.     add=$add'    '$i
  1840. done
  1841. sed '1{
  1842. s/$/'"$add"'/
  1843. p
  1844. s/[^    ]/-/g
  1845. }
  1846. 2d' 
  1847. \Rogue\Monster\
  1848. else
  1849.   echo "will not over write ./reldb.src/addcol.sh"
  1850. fi
  1851. if `test ! -s ./reldb.src/addup.c`
  1852. then
  1853. echo "writting ./reldb.src/addup.c"
  1854. cat > ./reldb.src/addup.c << '\Rogue\Monster\'
  1855. /*
  1856.     Procedure addup.
  1857.  
  1858. Usage: addup p < data
  1859.  
  1860.     Typical input line : a(1) a(2) ... a(p) b(1) ... b(nb)
  1861.     Output : For each level of (a(1),...,a(p)), print
  1862.         the sum  of all the b's.
  1863.     The a's are referred to as the 'by'-variables;
  1864.     The b's are the 'on'-variables.
  1865.  
  1866. Revision history:
  1867.     Original author : 
  1868.             gunnar@hafro.is (sometime in 86)
  1869.     All sorts of additions
  1870.         Mainly incorrect string manipulations
  1871.         also some dubious use of intermixed float and double -
  1872.         now all double.
  1873.             gunnar@hafro.is (April, 1989)
  1874. General comments:
  1875.     This program is rarely used directly by a human.
  1876.     Rather, it is a piece of the subtotal program,
  1877.     - subtotal call first project to order the by-variables
  1878.     first and then pipes the output into addup.
  1879.     This is what's called quick-and-dirty programming,
  1880.     but it's a heck of a lot simpler than having to
  1881.     build project into subtotal.
  1882.                         */
  1883.  
  1884.  
  1885. #include <stdio.h>
  1886. #include <strings.h>
  1887.  
  1888. #ifndef DEBUG
  1889. #define DEBUG 0        /* Define positive for debug (can override in Makefile*/
  1890. #endif
  1891.  
  1892. #define MAXV 25        /* maximum number of a-variables */
  1893. #define MAXLIN 150    /* maximum line length */
  1894.  
  1895. int debug=DEBUG;    /* debug level*/
  1896. int p;            /* numerical equiv. of arguments = number of by-vbls*/
  1897. int nonvar;        /* number of on-variables */
  1898. int i;            /* index */
  1899. double x[MAXV];        /* input b-vbls (i.e. one line at a time) */
  1900.  
  1901. main(argc,argv)
  1902. int argc;
  1903. char *argv[];
  1904. {
  1905.     char line[MAXLIN];    /* input line */
  1906.     char oldline[MAXLIN];    /* previous input line */
  1907.     int c;
  1908.     double sum[MAXV];    /* vector of sums for a b-val*/
  1909.  
  1910.         /* read argument = # vbls into p */
  1911.     if(debug)
  1912.         fprintf(stderr,"Into addup-routine\n");
  1913.     if(argc==2 ){
  1914.             if(sscanf(argv[1], "%d", &p) != 1) {
  1915.             printf("usage: addup  p \n or: addup debuglevel p\n");
  1916.                     return(-1);
  1917.             }
  1918.     } else if (argc==3){
  1919.             if(sscanf(argv[1], "%d", &debug) != 1) {
  1920.             printf("usage: addup  p \n or: addup debuglevel p\n");
  1921.                     return(-1);
  1922.             }
  1923.             if(sscanf(argv[2], "%d", &p) != 1) {
  1924.             printf("usage: addup  p \n or: addup debuglevel p\n");
  1925.                     return(-1);
  1926.             }
  1927.     } else {
  1928.         printf("usage: addup  p \n or: addup debuglevel p\n");
  1929.                 return(-1);
  1930.     }
  1931.     if(debug>=2)
  1932.         fprintf(stderr,"Got argument:->%d<-\n",p);
  1933.     if(fgets(oldline,MAXLIN,stdin)==NULL){
  1934.         fprintf(stderr,"Cannot read first line of input\n");
  1935.         exit(1);
  1936.     }
  1937.     if(debug>=5)
  1938.         fprintf(stderr,"Got header:->%s<-\n",oldline);
  1939.     fputs(oldline,stdout);
  1940.     if(fgets(oldline,MAXLIN,stdin)==NULL){
  1941.         fprintf(stderr,"Cannot read second line of input\n");
  1942.         exit(1);
  1943.     }
  1944.     fputs(oldline,stdout);
  1945.     c=getline(oldline,p,x);
  1946.     nonvar=c;
  1947.     if(debug>=5){
  1948.         fprintf(stderr,"Got first dataline(on-part):->%s<-\n",oldline);
  1949.         fprintf(stderr,"\tGot sum-variable:->%d<-\n",x[0]);
  1950.         fprintf(stderr,"\t# on vars:%d\n",nonvar);
  1951.         }
  1952.     addup(sum);
  1953.     while(c!=EOF){
  1954.         c=getline(line,p,x);
  1955.         if(debug>=5){
  1956.             fprintf(stderr,"Got dataline(on-part):->%s<-\n",line);
  1957.             fprintf(stderr,"\tGot sum-variable:->%lf<-\n",x[0]);
  1958.             fprintf(stderr,"\t# on vars:%d\n",c);
  1959.         }
  1960.         if(    c!=EOF && 
  1961.             strlen(oldline)==strlen(line) && 
  1962.             !strcmp(oldline,line)    ){
  1963.  
  1964.             if(debug>=5){
  1965.                 fprintf(stderr,"Same by-columns-adding\n");
  1966.             }
  1967.             addup(sum);/* same a-vbls;add */
  1968.         }else{
  1969.             if(debug>=5){
  1970.                 fprintf(stderr,"New by-cols-print old line(%s):\n",oldline);
  1971.             }
  1972.             output(oldline,sum);    /* output */
  1973.             if(debug>=5){
  1974.                 fprintf(stderr,"\told line>%s< becomes >%s<",oldline,line);
  1975.             }
  1976.             (void)strcpy(oldline,line);    /* copy header */
  1977.             if(c!=EOF)
  1978.                 addup(sum);/* new and final a's*/
  1979.         }
  1980.     }
  1981.         return(0);
  1982. }
  1983.  
  1984. getline(line,p,x)
  1985. char line[MAXLIN];    /* remainder of input line (the b's=by-columns)*/
  1986. int p;            /* no of vbls */
  1987. double x[MAXV];        /* columns to be summed */
  1988. {
  1989.     int i=0;
  1990.     int count=1;
  1991.     int    c;
  1992.     char    tmplin[MAXLIN];
  1993.     if((c=getchar())==EOF)
  1994.         return(EOF);
  1995.     do {
  1996.         line[i++]=c;
  1997.         while((c=getchar())!='\t')    /* get 'by' part as a string */
  1998.             line[i++]=c;
  1999.         count++;
  2000.     }while(count<=p);
  2001.     line[i]='\0';
  2002.     if(debug>=5)fprintf(stderr,"Input:by-vbls >%s<\n",line);
  2003.     count=0;
  2004.     do {
  2005.         i=0;
  2006.         c=getchar();
  2007.         while(c!='\t'&&c!='\n'){
  2008.             tmplin[i++]=c;
  2009.             c=getchar();
  2010.         }
  2011.         tmplin[i]='\0';
  2012.         if(debug>=5)fprintf(stderr,"\t next on-vbl >%s<\n",tmplin);
  2013.         if(i!=0){
  2014.             sscanf(tmplin,"%lf",&x[count]);    /* get 'on' variables */
  2015.             if(debug>=5)fprintf(stderr,"\t on-vbl:%lf\n",x[count]);
  2016.         } else {
  2017.             if(debug>=5)fprintf(stderr,"\t empty on-vbl\n");
  2018.             x[count]=0.;
  2019.         }
  2020.         count++;
  2021.     } while(c!='\n');
  2022.     return(count);
  2023.  
  2024. }    /* getline */
  2025.  
  2026. addup(sum)
  2027. double sum[MAXV];    /* vector of sums */
  2028. {
  2029.     static int first=1;
  2030.     if(debug>=2)
  2031.         fprintf(stderr,"Adding up:\n");
  2032.     if(first){
  2033.         if(debug>=5)
  2034.             fprintf(stderr,"\tinit\n");
  2035.         for(i=0;i<nonvar;i++){
  2036.             sum[i]=0.;        /* initialize*/
  2037.         first=0;
  2038.         }
  2039.     }
  2040.     for(i=0;i<nonvar;i++){
  2041.         if(debug>=5)
  2042.             fprintf(stderr,"\tAdding %lf to %lf\n",x[i],sum[i]);
  2043.         sum[i]+=x[i];        /* sum for vbl i */
  2044.     }
  2045. }    /* addup */
  2046.     
  2047. output(oldline,sum)
  2048. char oldline[MAXLIN];    /* previous input line, a-values (on) */
  2049. double sum[MAXV];    /* vector of sums (b's-on vbls) for a fixed a-val*/
  2050. {
  2051.     for(i=0;i<MAXLIN&&oldline[i]!='\0'&oldline[i]!='\n';i++)
  2052.         printf("%c",oldline[i]);    /* print text in beg. of line */
  2053.     for(i=0;i<nonvar;i++){            /* cut down digits output */
  2054.         if((double)(int)sum[i] == sum[i])
  2055.             printf("    %ld",(long)sum[i]);
  2056.         else if((double)(int)sum[i]<sum[i]-.00001||sum[i]<1.)
  2057.             printf("    %lf",sum[i]);
  2058.         else
  2059.             printf("    %ld",(long)sum[i]);
  2060.         sum[i]=0;
  2061.     }
  2062.     printf("\n");
  2063. }
  2064. \Rogue\Monster\
  2065. else
  2066.   echo "will not over write ./reldb.src/addup.c"
  2067. fi
  2068. if `test ! -s ./reldb.src/invert.sh`
  2069. then
  2070. echo "writting ./reldb.src/invert.sh"
  2071. cat > ./reldb.src/invert.sh << '\Rogue\Monster\'
  2072. #!/bin/sh
  2073. #
  2074. # invert -- inverse of matrix command.
  2075. #
  2076. awk 'NR==1{for(i=1;i<=NF;i++)name[i]=$(i)}
  2077. NR==2{print name[1]"    col    data" ; print "----    ---    ----"}
  2078. NR>2{for(i=2;i<=NF;i++){OFS="    ";print $1,name[i],$(i)}}'
  2079. \Rogue\Monster\
  2080. else
  2081.   echo "will not over write ./reldb.src/invert.sh"
  2082. fi
  2083. if `test ! -s ./reldb.src/bplokk.sh`
  2084. then
  2085. echo "writting ./reldb.src/bplokk.sh"
  2086. cat > ./reldb.src/bplokk.sh << '\Rogue\Monster\'
  2087. #!/bin/sh
  2088. #
  2089. # Simple jointable -- first file must be sufficiently short so that
  2090. # a grep command can be set up from the whole file
  2091. GREP=`awk '
  2092. BEGIN {printf("egrep ")}
  2093. NR==3{FS="    ";printf("^%s",$1)}
  2094. NR>3{FS="    ";printf("|^%s",$1)}
  2095. END{print ""}'  < $1 `
  2096.  
  2097. # uncomment the following if you want to see what is going on
  2098. #echo $GREP
  2099.  
  2100. head -2 < $2
  2101. $GREP < $2
  2102. \Rogue\Monster\
  2103. else
  2104.   echo "will not over write ./reldb.src/bplokk.sh"
  2105. fi
  2106. if `test ! -s ./reldb.src/check.sh`
  2107. then
  2108. echo "writting ./reldb.src/check.sh"
  2109. cat > ./reldb.src/check.sh << '\Rogue\Monster\'
  2110. #!/bin/sh
  2111. #
  2112. # check - checks sanity of reldb tables.
  2113. #
  2114. # The initial sed-command simply places dots in between two
  2115. # adjacent tabs, to guarantee that they are regarded as two
  2116. # fields by awk.
  2117. for i 
  2118. do
  2119.     sed 's/        /    .    /g
  2120.     s/        /    .    /g' < $i |\
  2121.     awk 'BEGIN {FS="    "}
  2122.     NR==1{
  2123.         reclen=NF
  2124.         error=0}
  2125.     NR==2{
  2126.         if(NF!=reclen){
  2127.             print "Dashes do not match column heads"
  2128.             error=1
  2129.         }
  2130.     }
  2131.     NR>2 {
  2132.         if(NF!=reclen){
  2133.             print "Error in line number ",NR,"fields ",NF," headers ",reclen;error=1
  2134.         }
  2135.     }
  2136.     END {
  2137.         if(error==0)
  2138.         print "Table '$i' is ok"
  2139.     }'
  2140. done
  2141. \Rogue\Monster\
  2142. else
  2143.   echo "will not over write ./reldb.src/check.sh"
  2144. fi
  2145. if `test ! -s ./reldb.src/compute.c`
  2146. then
  2147. echo "writting ./reldb.src/compute.c"
  2148. cat > ./reldb.src/compute.c << '\Rogue\Monster\'
  2149. /* 
  2150.     compute.c -- implements the compute and select commands
  2151.  
  2152.     Pretty trivial program -- just reads the name-line and
  2153.     generates an awk-script saying 'name1=$1;name2=$2;...' and
  2154.     then the compute- or select-statement.
  2155.  
  2156. Author: gunnar@hafro (way back then; probably 1987)
  2157.     1989: I guess I shouldn't be writing to a string, but plead
  2158.     ignorance at the time...
  2159.  
  2160. */
  2161. #include <stdio.h>
  2162. #include <signal.h>
  2163. #define MAXLINE 1000
  2164. char    *skrarnafn="tmp.......";    /* temporary file for awk-command */
  2165. main(argc,argv)
  2166. int    argc;
  2167. char    *argv[];
  2168. {
  2169.     char    inpline[MAXLINE];    /* input line */
  2170.     char    *ptr;            /* pointer into input line */
  2171.     int    select;            /* =0 if compute, =1 if select */
  2172.     int    i=1;            /* field number */
  2173.     int    die();            /* procedure to deal with exit */
  2174.     FILE    *fp,*fopen(),*popen();
  2175.  
  2176.     signal(SIGINT,die);
  2177.     if(strcmp(argv[0],"select"))
  2178.         select=0;
  2179.     else
  2180.         select=1;
  2181.     sprintf(&skrarnafn[3],"%07d",getpid());
  2182.     if((fp=fopen(skrarnafn,"w"))==NULL)
  2183.         errlog("Cannot open temporary file\n");
  2184.     gets(inpline);
  2185.     puts(inpline);            /* echo 1st header line */
  2186.     fprintf(fp,"awk 'BEGIN {FS=\"    \";OFS=\"    \"}\n{");
  2187.     ptr=inpline;
  2188.     do {
  2189.         while(*ptr!='\t'&&*ptr!='\0'&&*ptr!='\n')
  2190.             putc(*ptr++,fp);
  2191.         fprintf(fp,"=$(%d);",i);
  2192.         if(*ptr=='\t')
  2193.             *ptr++;
  2194.         i++;
  2195.     } while(*ptr!='\n'&&*ptr!='\0');
  2196.     if(select)
  2197.         fprintf(fp,"if(%s)print ",argv[1]);    /* select stmnt */
  2198.     else
  2199.         fprintf(fp,"%s;print ",argv[1]);    /* compute stmnt */
  2200.     ptr=inpline;
  2201.     do {
  2202.         if(*ptr=='\t')
  2203.             putc(',',fp);
  2204.         else
  2205.             putc(*ptr,fp);
  2206.         ptr++;
  2207.     } while(*ptr!='\n'&&*ptr!='\0');
  2208.     fprintf(fp,"}'\n");
  2209.     fclose(fp);
  2210.     chmod(skrarnafn,0777);        /* make file executable */
  2211.     gets(inpline);
  2212.     puts(inpline);            /* echo 2nd header line */
  2213.     fflush(stdout);
  2214.     if((fp=popen(skrarnafn,"w"))==NULL)        /* start up awk */
  2215.         errlog("Cannot start up awk\n");
  2216.     while(gets(inpline)!=NULL){
  2217.         fputs(inpline,fp);
  2218.         fputc('\n',fp);
  2219.     }
  2220.     pclose(fp);
  2221.     wait(0);            /* wait for awk to finish */
  2222.     die();
  2223. }
  2224. errlog(s)
  2225. char *s;
  2226. {
  2227.     fprintf(stderr,"%s",s);
  2228.     exit(1);
  2229. }
  2230. die(){
  2231.     unlink(skrarnafn);
  2232.     exit(0);
  2233. }
  2234. \Rogue\Monster\
  2235. else
  2236.   echo "will not over write ./reldb.src/compute.c"
  2237. fi
  2238. if `test ! -s ./reldb.src/count.c`
  2239. then
  2240. echo "writting ./reldb.src/count.c"
  2241. cat > ./reldb.src/count.c << '\Rogue\Monster\'
  2242. /*
  2243.     Program to count the number of identical lines
  2244.                          */ 
  2245. #include <stdio.h>
  2246. #define MAXLIN 500
  2247. main(){
  2248.     int count;            /* counter for equal lines */
  2249.     char line[MAXLIN],prev[MAXLIN];    /* current and previous lines */
  2250.  
  2251.     fgets(line,MAXLIN,stdin);    /* get 2 reldb header lines */
  2252.     printf("count\t%s",line);    /* and prepend count header */
  2253.     fgets(line,MAXLIN,stdin);
  2254.     printf("-----\t%s",line);
  2255.     count=1;            /* initialize counter */
  2256.     fgets(prev,MAXLIN,stdin);
  2257.     while(fgets(line,MAXLIN,stdin)!=NULL){
  2258.         if(strcmp(line,prev)){    /* 1 = not same as before */
  2259.             printf("%d\t%s",count,prev);
  2260.             strcpy(prev,line);
  2261.             count=1;
  2262.         } else
  2263.             count++;
  2264.     }
  2265.     printf("%d\t%s",count,prev);
  2266. }
  2267. \Rogue\Monster\
  2268. else
  2269.   echo "will not over write ./reldb.src/count.c"
  2270. fi
  2271. if `test ! -s ./reldb.src/README`
  2272. then
  2273. echo "writting ./reldb.src/README"
  2274. cat > ./reldb.src/README << '\Rogue\Monster\'
  2275. This is reldb, a collection of programs to handle simple relational database
  2276. operations.
  2277.  
  2278. Shell scripts are stored with a .sh subscript, which is
  2279. stripped off upon install.
  2280.  
  2281. Edit the Makefile, in particular, set BINDIR to where you want
  2282. the binaries and scripts to go. Typing 'make' will compile and install.
  2283.  
  2284. Files:
  2285.  
  2286. Makefile        The Makefile (did you guess ?)
  2287. README            This file
  2288. addcol.sh        Script to add named columns to table
  2289. addup.c            Adds up some columns (part of subtotal).
  2290. bplokk.sh        Version of plokk for large numbers (even text).
  2291. check.sh        Checks sanity of named tables.
  2292. columnlist.sh        Lists names of columns in table.
  2293. compute.c        Computes new values into columns.
  2294. count.c            Counts repeated lines (c.f. uniq).
  2295. dataplotpre.sh        Reldb interface |Stat's dataplot.
  2296. dbdict.sh        Preliminary "data base dictionary"
  2297. dbe.add.sh        Add to database.
  2298. dbe.change.sh        Change table.
  2299. invert.sh        Inverse matrix command (invert).
  2300. joinle.c        Special join, good for length distributions.
  2301. jointable.sh        Reldb version of join.
  2302. math.sh            Compute simple statistics on table.
  2303. matrix.c        Go from (frequency,x,y) to matrix.
  2304. mulregpre.sh        Reldb interface to |Stat's regress program.
  2305. number.sh        Add a column with a linenumber (cf nl).
  2306. pairpre.sh        Reldb interface to |Stat's pair program.
  2307. plokk.c            Program to select lines according to list.
  2308. preplot.sh        Reldb interface to |Stat's dataplot.
  2309. project.c        Project columns out of a table.
  2310. recode.c        Recode a column according to list.
  2311. regress.c        Simple linear regression.
  2312. rename.sh        Rename columns.
  2313. see.sh            Display tabs etc.
  2314. sideview.sh        Display a table sideways.
  2315. sorttable.sh        Sort a table.
  2316. subtotal.c        Subtotal some columns.
  2317. union.sh        Append one table to another
  2318.  
  2319. Someone please suggest a better name for this "package".
  2320.  
  2321. The directory ../testdb contains some scripts to test the
  2322. scripts and programs. Go there and type 'make', possibly after modifying 
  2323. BINDIR in the Makefile.
  2324. \Rogue\Monster\
  2325. else
  2326.   echo "will not over write ./reldb.src/README"
  2327. fi
  2328. if `test ! -s ./reldb.src/dataplotpre.sh`
  2329. then
  2330. echo "writting ./reldb.src/dataplotpre.sh"
  2331. cat > ./reldb.src/dataplotpre.sh << '\Rogue\Monster\'
  2332. read x y
  2333. read dum
  2334. dataplot -n x$x -n y$y
  2335. \Rogue\Monster\
  2336. else
  2337.   echo "will not over write ./reldb.src/dataplotpre.sh"
  2338. fi
  2339. if `test ! -s ./reldb.src/dbdict.sh`
  2340. then
  2341. echo "writting ./reldb.src/dbdict.sh"
  2342. cat > ./reldb.src/dbdict.sh << '\Rogue\Monster\'
  2343. awk 'BEGIN{FS="    "}
  2344. NR==1{for(i=1;i<=NF;i++){
  2345.     ind[i]=$(i)
  2346.     lengd[i]=length($(i))
  2347.     }
  2348.     svidafj=NF;
  2349.      }
  2350. NR>2{for(i=1;i<=NF;i++)
  2351.     if(length($(i))>lengd[i])lengd[i]=length($(i));
  2352.     }
  2353. END{    print "Atridi    Lengd"
  2354.     print "------    -----"
  2355.     for(i=1;i<=svidafj;i++)
  2356.         print ind[i]"    "lengd[i]
  2357.    }' 
  2358. \Rogue\Monster\
  2359. else
  2360.   echo "will not over write ./reldb.src/dbdict.sh"
  2361. fi
  2362. if `test ! -s ./reldb.src/dbe.add.sh`
  2363. then
  2364. echo "writting ./reldb.src/dbe.add.sh"
  2365. cat > ./reldb.src/dbe.add.sh << '\Rogue\Monster\'
  2366. :
  2367. #
  2368. # dbe.add
  2369. #
  2370. # Usage: dbe.add file
  2371. #
  2372. # Type ctrl-C to quit
  2373. #
  2374. # Method:
  2375. #
  2376. # First read the reldb header fro the file
  2377. #
  2378. # Then go into an everlasting loop, reading each field from the
  2379. # terminal. After a record has been read, it is echo-ed to the end of the file.
  2380. #
  2381. read x < $1
  2382. while(true)
  2383. do
  2384.     record=""
  2385.     tput clear
  2386.     for fld in $x
  2387.     do
  2388.         echo "$fld : \c"
  2389.         read temp
  2390.         record="$record    $temp"
  2391.     done
  2392.     record=`echo "$record"|sed 's/^    //'`
  2393.     echo "$record" >> $1
  2394. done
  2395. \Rogue\Monster\
  2396. else
  2397.   echo "will not over write ./reldb.src/dbe.add.sh"
  2398. fi
  2399. if `test ! -s ./reldb.src/dbe.change.sh`
  2400. then
  2401. echo "writting ./reldb.src/dbe.change.sh"
  2402. cat > ./reldb.src/dbe.change.sh << '\Rogue\Monster\'
  2403. #!/bin/sh
  2404. # dbe.change
  2405. #
  2406. # Useage : dbe.add file
  2407. #
  2408. # Control-C is used to quit
  2409. #
  2410. # Method:
  2411. #
  2412. # First read the Prelude header from the file
  2413. #
  2414. # Loop over all records in the file.
  2415. #     Within each record, loop over all items in the record and 
  2416. #     ask whether this item should be modified.
  2417. #
  2418.  
  2419. # Exactly one of the following should be set:
  2420. #  TERMINATOR='\c'
  2421. INITIATOR='-n'
  2422. # Also set one of the following:
  2423. CLEAR=clear
  2424. #CLEAR=tput clear
  2425.  
  2426. trap "rm -f tempedit$$ tempoutput$$" 15 2 1 
  2427. cp $1 tempedit$$
  2428. lines=`wc -l < $1`
  2429. header=`sed '1{
  2430. s/ /_/g
  2431. q
  2432. }' < $1`
  2433. (
  2434.  
  2435. read dumline
  2436. echo "$dumline" > tempoutput$$
  2437. read dumline
  2438. echo "$dumline" >> tempoutput$$
  2439. line=2
  2440. while [ $line -lt $lines ]
  2441. do
  2442.     read inrec
  2443.     record=""
  2444.     $CLEAR
  2445.     for fld in $header
  2446.     do
  2447.         infield=`echo "$inrec" | sed 's/    .*//'`
  2448.         echo $INITIATOR "$fld (was $infield) : $TERMINATOR"
  2449.         read temp < /dev/tty
  2450.         if [ X"$temp" = X ]
  2451.         then
  2452.             record="$record    $infield"
  2453.         else
  2454.             record="$record    $temp"
  2455.         fi
  2456.         inrec=`echo "$inrec" | sed 's/^[^    ]*    //'`
  2457.     done
  2458.     record=`echo "$record"|sed 's/^    //'`
  2459.     echo "$record" >> tempoutput$$
  2460.     line=`expr $line + 1`
  2461. done
  2462. ) < tempedit$$ 
  2463. mv tempoutput$$ $1
  2464. rm -f tempedit$$
  2465. \Rogue\Monster\
  2466. else
  2467.   echo "will not over write ./reldb.src/dbe.change.sh"
  2468. fi
  2469. if `test ! -s ./reldb.src/joinle.c`
  2470. then
  2471. echo "writting ./reldb.src/joinle.c"
  2472. cat > ./reldb.src/joinle.c << '\Rogue\Monster\'
  2473. /* program to join many length distributions into one file.
  2474.     Just for fun, we compute these as a percentage distribution.
  2475.  
  2476.     Use: joinle files
  2477.  
  2478.     The only thing to watch out for is that lines may be
  2479.     missing in some files and the max/min-lengths will
  2480.     not be the same in all files.
  2481.  
  2482. Those not concerned with marine research might not be so hot
  2483. on length distributions -- let me know if you can transform this
  2484. into something more generally useful.
  2485. */
  2486. #include <stdio.h>
  2487. #define MAXFILES 50            /* max # of files */
  2488. #define MAXLEN=350            /* max fish length*/
  2489. #define MAXLINE 1000            /* max length of input line */
  2490. int matrix[MAXLEN][MAXFILES]; /*Matrix of length distributions */
  2491. main(argc,argv)
  2492. int argc;
  2493. char **argv;
  2494. {
  2495.     FILE *fp;
  2496.     FILE *fopen();
  2497.     char **filelist=argv;
  2498.     char *curfile;
  2499.     
  2500.     int minlen=999999;
  2501.     int maxlen= -999999;
  2502.     int le,colnr;            /* indices into file no & length */
  2503.     int fj;
  2504.     int debug=0;            /* -d gives debug */
  2505.     char inpline[MAXLINE];
  2506.  
  2507.     int totals[MAXFILES];
  2508.  
  2509.     curfile= *++filelist;
  2510.     if(!strncmp(*filelist,"-d",2)){
  2511.         debug=1;
  2512.         *filelist++;
  2513.         *argv++;
  2514.         argc--;
  2515.     }
  2516.  
  2517.     /* Now go through all the files */
  2518.  
  2519.     for(colnr=1;colnr<argc;colnr++) {
  2520.         /* first verify that the next argument is a file */
  2521.         curfile= *filelist;
  2522.         if(debug)fprintf(stderr,"Next file, %s", curfile);
  2523.         if(debug)fprintf(stderr,".a.");
  2524.         if((fp = fopen(*filelist++,"r"))==NULL){
  2525.             fprintf(stderr,"Cannot open named file, %s\n",curfile);
  2526.             exit(1);
  2527.         }
  2528.         totals[colnr]=0;
  2529.         if(debug)fprintf(stderr,".b.");
  2530.         if(debug)fprintf(stderr,"Reading input file %s",curfile);
  2531.         if(debug)fprintf(stderr,".c.");
  2532.         fgets(inpline,MAXLINE,fp);    /* skip header */
  2533.         fgets(inpline,MAXLINE,fp);    /* skip header */
  2534.         if(debug)fprintf(stderr,".d.");
  2535.         while(fgets(inpline,MAXLINE,fp)!=NULL){
  2536.             if(debug)fprintf(stderr,".e.");
  2537.             sscanf(inpline,"%d %d",&le,&fj);
  2538.             if(le<0 || le > MAXLEN){
  2539.                 fprintf(stderr,"Illegal length in file %s\n",*--filelist);
  2540.                 fprintf(stderr,"Line is %s\n",inpline);
  2541.                 exit(1);
  2542.             }
  2543.             if(le<minlen)minlen=le;
  2544.             if(le>maxlen)maxlen=le;
  2545.             matrix[le][colnr]=fj;
  2546.             totals[colnr]+=fj;
  2547.         }
  2548.         fclose(fp);
  2549.         if(debug)fprintf(stderr,"\n");
  2550.     }
  2551.     printf("le");
  2552.     for(colnr=1;colnr<argc;colnr++){
  2553.         printf("    %s",*++argv);
  2554.     }
  2555.     printf("\n");
  2556.     printf("--");
  2557.     for(colnr=1;colnr<argc;colnr++){
  2558.         printf("    --------");
  2559.     }
  2560.     printf("\n");
  2561.     for(le=minlen;le<=maxlen;le++){
  2562.         printf("%d",le);
  2563.         for(colnr=1;colnr<argc;colnr++){
  2564.             printf("    %.2lf",100.*(double)matrix[le][colnr]/
  2565.                 (double)totals[colnr]);
  2566.         }
  2567.         printf("\n");
  2568.     }
  2569. }
  2570. \Rogue\Monster\
  2571. else
  2572.   echo "will not over write ./reldb.src/joinle.c"
  2573. fi
  2574. if `test ! -s ./reldb.src/jointable.sh`
  2575. then
  2576. echo "writting ./reldb.src/jointable.sh"
  2577. cat > ./reldb.src/jointable.sh << '\Rogue\Monster\'
  2578. trap "rm tmp$$ haus$$" 2 14 15
  2579. opt=""
  2580. case $1 in
  2581.     '-n'|'-a1'|'-a2')
  2582.         opt=$1
  2583.         shift
  2584.         ;;
  2585. esac
  2586. sed 1q < $1 | tr '\012' '    '  >haus$$
  2587. sed 's/^[^    ]*    //
  2588. 1q' < $2 >>haus$$
  2589. sed 'p
  2590. s/[^    ]/-/g' < haus$$
  2591. sed '1,2d' < $2 >tmp$$
  2592. sed '1,2d' < $1 | join $opt -t"    " - tmp$$ 
  2593. rm tmp$$ haus$$
  2594.  
  2595. \Rogue\Monster\
  2596. else
  2597.   echo "will not over write ./reldb.src/jointable.sh"
  2598. fi
  2599. if `test ! -s ./reldb.src/math.sh`
  2600. then
  2601. echo "writting ./reldb.src/math.sh"
  2602. cat > ./reldb.src/math.sh << '\Rogue\Monster\'
  2603. #!/bin/sh
  2604. #
  2605. # math -- compute some statistics on a table.
  2606. #
  2607. # BUG: <tab><tab> is used as a zero -- should be missing
  2608.  
  2609. awk 'BEGIN {FS="    ";OFS="    "}
  2610. NR==1    {print $0"    Type";totf=NF}
  2611.      NR==2    {print $0"    ----";
  2612.           for(i=1;i<=NF;i++){
  2613.                 max[i]= -1e64;
  2614.                 min[i]=1e64;
  2615.         }}
  2616.      NR>2    {for(i=1;i<=NF;i++){
  2617.             if($(i)!=""){
  2618.                 sum[i]+=$(i);
  2619.                 sum2[i]+=$(i)*$(i);
  2620.                 freq[i]++;
  2621.                 if($(i)>max[i])
  2622.                     max[i]=$(i);
  2623.                 if($(i)<min[i])
  2624.                     min[i]=$(i);
  2625.             }
  2626.         }}
  2627.       END    {for(i=1;i<=totf;i++)
  2628.             printf("%d\t",freq[i]);
  2629.          printf("Freq\n");
  2630.                for(i=1;i<=totf;i++)
  2631.              if(sum[i]==int(sum[i]))
  2632.                 printf("%d\t",sum[i]);
  2633.             else
  2634.                 printf("%f\t",sum[i]);
  2635.          printf("Sum\n");
  2636.                for(i=1;i<=totf;i++){
  2637.             mean=sum[i]/freq[i]
  2638.             if(mean=int(mean))
  2639.                 printf("%d\t",sum[i]/freq[i]);
  2640.             else
  2641.                 printf("%f\t",sum[i]/freq[i]);
  2642.          }
  2643.          printf("Mean\n");
  2644.                for(i=1;i<=totf;i++){
  2645.             stdev=sqrt((sum2[i]-sum[i]*sum[i]/freq[i])/(freq[i]-1));
  2646.             if(stdev>1&&stdev<10)
  2647.                 printf("%.5f\t",stdev);
  2648.             else
  2649.                 printf("%f\t",stdev);
  2650.          }
  2651.          printf("Stddev\n");
  2652.                for(i=1;i<=totf;i++)
  2653.             if(max[i]==int(max[i]))
  2654.                 printf("%d\t",max[i]);
  2655.             else
  2656.                 printf("%f\t",max[i]);
  2657.          printf("Maximum\n");
  2658.                for(i=1;i<=totf;i++)
  2659.             if(min[i]==int(min[i]))
  2660.                 printf("%d\t",min[i]);
  2661.             else
  2662.                 printf("%f\t",min[i]);
  2663.          printf("Minimum\n");
  2664.         }
  2665. '
  2666. \Rogue\Monster\
  2667. else
  2668.   echo "will not over write ./reldb.src/math.sh"
  2669. fi
  2670. if `test ! -s ./reldb.src/matrix.c`
  2671. then
  2672. echo "writting ./reldb.src/matrix.c"
  2673. cat > ./reldb.src/matrix.c << '\Rogue\Monster\'
  2674. /*
  2675.     matrix:
  2676.  
  2677.     A program for setting up a simple frequency table,
  2678.     based on (count,x,y)-data
  2679.                                 */
  2680. #include <stdio.h>
  2681. #define MAXX 250
  2682. #define MAXY 50
  2683. #define MINX 0
  2684. #define MINY 0
  2685. #define MAXLIN 500
  2686. #define MAXNAM 10
  2687. main(argc,argv)
  2688. int argc;
  2689. char *argv[];
  2690. {
  2691.     char line[MAXLIN],xname[MAXNAM],yname[MAXNAM],dum[MAXNAM];
  2692.     char *format="\t%f";    /* Output table default format */
  2693.     
  2694.     static float freq[MAXX][MAXY];    /* the frequencies */
  2695.     float marg[MAXX];        /* marginal frequencies */
  2696.     int x,y;        /* input data : x,y, freq of x,y */
  2697.     float n;
  2698.     int testmarg=1;        /* =1=>skip empty lines =0=>print them*/
  2699.     int minx,maxx,miny,maxy;/* computed bounds on input data */
  2700.     
  2701.     while(--argc){
  2702.         if(argv[1][0]=='-'){
  2703.             if(argv[1][1]=='e')
  2704.                 testmarg=0;    /* print empty lines */
  2705.             else{
  2706.                 fprintf(stderr,"Incorrect argument to matrix\n");
  2707.                 fprintf(stderr,"Usage : matrix [-e] [format]\n");
  2708.                 fprintf(stderr,"         -e : print empty lines\n");
  2709.                 fprintf(stderr,"          format : C printf format, default : %s\n",format);
  2710.                 exit(1);
  2711.             }
  2712.         } else {
  2713.             format=argv[1];
  2714.         }
  2715.         argv++;
  2716.     }
  2717.     fgets(line,MAXLIN,stdin);    /* Reldb header line */
  2718.     sscanf(line,"%s %s %s",dum,xname,yname);/* get names of columns */
  2719.     fgets(line,MAXLIN,stdin);    /* Reldb dash-line */
  2720.  
  2721.     minx=MAXX;maxx=MINX;miny=MAXY;maxy=MINY;
  2722.     while(fgets(line,MAXLIN,stdin)!=NULL){
  2723.         sscanf(line,"%f %d %d",&n,&x,&y);
  2724.         if(x>=MAXX||y>=MAXY){
  2725.             fprintf(stderr,"Bound error : %s\n",line);
  2726.             continue;
  2727.         }
  2728.         ++x;++y;
  2729.         freq[x][y]+=n;
  2730.         marg[x]+=n;
  2731.         if(x>=maxx)maxx=x;
  2732.         if(y>=maxy)maxy=y;
  2733.         if(x<=minx)minx=x;
  2734.         if(y<=miny)miny=y;
  2735.     }
  2736.     printf("%s",xname);
  2737.     for(y=miny-1;y<maxy;){
  2738.         printf("\t%s%d",yname,y++);
  2739.     }
  2740.     printf("\n--");
  2741.     for(y=miny-1;y<maxy;y++){
  2742.         printf("\t----");
  2743.     }
  2744.     printf("\n");
  2745.     for(x=minx;x<=maxx;x++){
  2746.         if(marg[x]==0&&testmarg)
  2747.             continue;        /* skip empties */
  2748.         printf("%d",x-1);
  2749.         for(y=miny-1;y<maxy;){
  2750.             printf(format,freq[x][++y]);
  2751.         }
  2752.         printf("\n");
  2753.     }
  2754. } /* main */
  2755. \Rogue\Monster\
  2756. else
  2757.   echo "will not over write ./reldb.src/matrix.c"
  2758. fi
  2759. if `test ! -s ./reldb.src/columnlist.sh`
  2760. then
  2761. echo "writting ./reldb.src/columnlist.sh"
  2762. cat > ./reldb.src/columnlist.sh << '\Rogue\Monster\'
  2763. #!/bin/sh
  2764. #
  2765. # columnlist.sh
  2766. #
  2767. # trivial sed-command to list column names of a table.
  2768. #
  2769. sed '1s/    /\
  2770. /g
  2771. 1q'
  2772. \Rogue\Monster\
  2773. else
  2774.   echo "will not over write ./reldb.src/columnlist.sh"
  2775. fi
  2776. if `test ! -s ./reldb.src/mulregpre.sh`
  2777. then
  2778. echo "writting ./reldb.src/mulregpre.sh"
  2779. cat > ./reldb.src/mulregpre.sh << '\Rogue\Monster\'
  2780. #!/bin/sh
  2781. #
  2782. # neat little script for interfacing with |Stat's "regress"
  2783. read x
  2784. read dummy
  2785. /usr/stat/bin/regress -p $x
  2786. \Rogue\Monster\
  2787. else
  2788.   echo "will not over write ./reldb.src/mulregpre.sh"
  2789. fi
  2790. if `test ! -s ./reldb.src/number.sh`
  2791. then
  2792. echo "writting ./reldb.src/number.sh"
  2793. cat > ./reldb.src/number.sh << '\Rogue\Monster\'
  2794. #!/bin/sh
  2795. #
  2796. # number -- add a number column
  2797. awk '
  2798. NR == 1    {print "nr    "$0}
  2799. NR == 2    {print "--    "$0}
  2800. NR > 2    {print NR-2"    "$0}' < $1
  2801. \Rogue\Monster\
  2802. else
  2803.   echo "will not over write ./reldb.src/number.sh"
  2804. fi
  2805. if `test ! -s ./reldb.src/pairpre.sh`
  2806. then
  2807. echo "writting ./reldb.src/pairpre.sh"
  2808. cat > ./reldb.src/pairpre.sh << '\Rogue\Monster\'
  2809. :
  2810. # Reldb version of unixstat's (|Stat) pair
  2811. read x y
  2812. read dum
  2813. pair -p -x $y -y $y
  2814. \Rogue\Monster\
  2815. else
  2816.   echo "will not over write ./reldb.src/pairpre.sh"
  2817. fi
  2818. if `test ! -s ./reldb.src/plokk.c`
  2819. then
  2820. echo "writting ./reldb.src/plokk.c"
  2821. cat > ./reldb.src/plokk.c << '\Rogue\Monster\'
  2822. /* 
  2823.     Program to select lines according to values in the first column
  2824.     of each line.
  2825.  
  2826.     Usage : plokk fnam < file
  2827.  
  2828.     file = name of data file
  2829.  
  2830.     fnam = name of file containing values to be selected
  2831.                             */
  2832. #include <stdio.h>
  2833.  
  2834. main(argc,argv)
  2835. int argc;
  2836. char *argv[];
  2837. {
  2838.     char lina[1000];    /* input line*/
  2839.     int n;            /* first value in a data line */
  2840.     
  2841.     int select[5000];    /* 1=values to select 0=skip*/
  2842.     int nsel;        /* running value to select */
  2843.  
  2844.     FILE *fp,*fopen();
  2845.  
  2846.     if((fp=fopen(argv[1],"r"))==NULL){    /* open selection file */
  2847.         fprintf(stderr,"Usage : plokk selfil < datfil\n");
  2848.         exit(-1);
  2849.     }
  2850.  
  2851.     nsel=0;                    /* initialize selection */
  2852.     while(nsel<5000)
  2853.         select[nsel++]=0;
  2854.  
  2855.     fgets(lina,1000,fp);            /* read selection file */
  2856.     fgets(lina,1000,fp);
  2857.     while(fgets(lina,1000,fp)!=NULL){
  2858.         sscanf(lina,"%d",&nsel);
  2859.         if(nsel< -1 || nsel> 5000){
  2860.             fprintf(stderr,"plokk : index in selection file out of bounds %d\n",nsel);
  2861.             exit(1);
  2862.         }
  2863.         select[nsel+1]=1;
  2864.     }
  2865.     fclose(fp);
  2866.  
  2867.     fgets(lina,1000,stdin);
  2868.     printf("%s",lina);
  2869.     fgets(lina,1000,stdin);
  2870.     printf("%s",lina);
  2871.     while(fgets(lina,1000,stdin)!=NULL){    /* perform selection */
  2872.         sscanf(lina,"%d",&n);
  2873.         if(n< -1 || n > 5000){
  2874.             fprintf(stderr,"plokk : index in data file out of bounds %d\n",n);
  2875.             exit(1);
  2876.         }
  2877.         if(select[n+1])
  2878.             printf("%s",lina);
  2879.     }
  2880. }
  2881. \Rogue\Monster\
  2882. else
  2883.   echo "will not over write ./reldb.src/plokk.c"
  2884. fi
  2885. if `test ! -s ./reldb.src/preplot.sh`
  2886. then
  2887. echo "writting ./reldb.src/preplot.sh"
  2888. cat > ./reldb.src/preplot.sh << '\Rogue\Monster\'
  2889. #!/bin/sh
  2890. #
  2891. # neat little script for interfacing with |Stat's dataplot.
  2892. read x y
  2893. read dum
  2894. dataplot -n x$x -n y$y$ $*
  2895. \Rogue\Monster\
  2896. else
  2897.   echo "will not over write ./reldb.src/preplot.sh"
  2898. fi
  2899. if `test ! -s ./reldb.src/project.c`
  2900. then
  2901. echo "writting ./reldb.src/project.c"
  2902. cat > ./reldb.src/project.c << '\Rogue\Monster\'
  2903. /*
  2904.     project:
  2905.  
  2906.     Author; johanna@hafro.is (1987?)
  2907. */
  2908. #include <stdio.h>
  2909. #define MAXLINE 4096
  2910. main(argc,argv)
  2911.     int argc;
  2912.     char *argv[];
  2913. {
  2914.        int i;
  2915.        int h;
  2916.        int a;
  2917.        char line[MAXLINE];
  2918.        char tabv[1000][100];
  2919.        int posv[1000];
  2920.  
  2921.        i=0;
  2922.  
  2923.        argc--;
  2924.  
  2925.        header_lines(argc,argv);
  2926.        getline(line,MAXLINE,h,a);
  2927.        velja_dalka(tabv,line,&h,&a);
  2928.        gera_dalka(argc,argv,tabv,&h);
  2929.        cal_pos_val(argc,argv,tabv,posv);
  2930.        getline(line,MAXLINE,h,a);
  2931.        while((i = getline(line,MAXLINE,h,a)) > 0)
  2932.        {
  2933.           project_dalka(argc,posv,line);
  2934.        }
  2935.  
  2936.        exit(0);
  2937. }
  2938.  
  2939.  
  2940. header_lines(argc,argv)
  2941. int argc;
  2942. char *argv[];
  2943. {
  2944. int i;
  2945. int l;
  2946. int s;
  2947. int j;
  2948.  
  2949. i=j=s=l=0;
  2950.  
  2951. for(i=1;i <= argc;i++)
  2952.    {
  2953.     printf("%s",argv[i]);
  2954.     if(i==argc)
  2955.       printf("\n");
  2956.     else
  2957.       printf("\t");
  2958.    }
  2959. for(j=1;j <= argc;j++)
  2960.    {
  2961.     l=strlen(argv[j]);
  2962.     for(s=1;s <= l;s++)
  2963.         printf("-");
  2964.     if(j==argc)
  2965.        printf("\n");
  2966.     else
  2967.        printf("\t");
  2968.    }
  2969. }
  2970.  
  2971.  
  2972. velja_dalka(tabv,line,h,a)
  2973. char tabv[1000][100];
  2974. char line[MAXLINE];
  2975. int *h;
  2976. int *a;
  2977. {
  2978.     int i;
  2979.     int j;
  2980.  
  2981.     *h=0;
  2982.     i=0;
  2983.  
  2984.     do
  2985.     {
  2986.        j=0;
  2987.        while((line[i] != '\t') && (line[i] != '\n'))
  2988.        {
  2989.             tabv[*h][j]=line[i];
  2990.             j++;
  2991.             i++;
  2992.        }
  2993.        tabv[*h][j]='\0';
  2994.        (*h)++;
  2995.     }
  2996.     while(line[++i] != '\0');
  2997.     tabv[*h][0]='\0';
  2998.     --h;
  2999.     (*a)=(*h);
  3000. }
  3001.  
  3002.  
  3003.  
  3004. gera_dalka(argc,argv,tabv,h)
  3005. int argc;
  3006. char *argv[];
  3007. char tabv[1000][100];
  3008. int *h;
  3009. {
  3010.      int x;
  3011.      int y;
  3012.      char *strcpy();
  3013.  
  3014.      x=y=0;
  3015.      for(x=1;x <= argc;x++)
  3016.         {
  3017.           y=0;
  3018.           while((tabv[y][0] != '\0') && (strcmp(argv[x],tabv[y]) != 0))y++;
  3019.           if (strcmp(argv[x],tabv[y]) == 0)
  3020.           {
  3021.           }
  3022.           else
  3023.           {
  3024.              strcpy(tabv[y],argv[x]);
  3025.              (*h)++;
  3026.           }
  3027.         }
  3028. }
  3029.  
  3030.  
  3031.  
  3032. cal_pos_val(argc,argv,tabv,posv)
  3033. int argc;
  3034. char *argv[];
  3035. char tabv[1000][100];
  3036. int posv[1000];
  3037. {
  3038.     int k;
  3039.     int l;
  3040.  
  3041.     for(k=1;k <= argc;k++)
  3042.        {
  3043.          l=0;
  3044.  
  3045.          while((strcmp(argv[k],tabv[l]) != 0) && (l < 1000))l++;
  3046.  
  3047.          l++;
  3048.          posv[k]=l;
  3049.        }
  3050. }
  3051.  
  3052.  
  3053. project_dalka(argc,posv,line)
  3054. int argc;
  3055. int posv[1000];
  3056. char line[MAXLINE];
  3057. {
  3058.   int d;
  3059.   int t;
  3060.   int l;
  3061.   
  3062.   for (d=1;d <= argc;d++)
  3063.   {
  3064.       l=0;
  3065.       for (t=1;t < posv[d];t++)
  3066.       {
  3067.            while ((line[l] != '\t') && (line[l] != '\0')) l++;
  3068.                  l++;
  3069.       }
  3070.       while ((line[l] != '\t') && (line[l] != '\n'))
  3071.             putchar(line[l++]);
  3072.       if (d < argc)
  3073.           putchar('\t');
  3074.       else
  3075.           putchar('\n'); 
  3076.               
  3077.    }
  3078. }
  3079.  
  3080.  
  3081. getline(s,lim,h,a)
  3082. char s[];
  3083. int lim;
  3084. int h;
  3085. int a;
  3086. {
  3087.   int c;
  3088.   int i;
  3089.   int j;
  3090.   char *strcat();
  3091.  
  3092.   j=0;
  3093.   c=0;
  3094.   i=0;
  3095.  
  3096.   while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
  3097.       s[i++]=c;
  3098.  
  3099.   if (c == '\n')
  3100.       s[i++] = c;
  3101.   s[i] = '\0';
  3102.   for(j=a;j < h;j++)
  3103.      {
  3104.      strcat(s,"\t");
  3105.      }
  3106.  
  3107.   return(i);
  3108. }
  3109. \Rogue\Monster\
  3110. else
  3111.   echo "will not over write ./reldb.src/project.c"
  3112. fi
  3113. echo "Finished archive 2 of 3"
  3114. exit
  3115.  
  3116.