home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / vplot / part19 < prev    next >
Encoding:
Internet Message Format  |  1988-03-31  |  49.9 KB

  1. Subject:  v14i024:  Device-independant graphics system, with drivers
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Joe Dellinger <joe@hanauma.STANFORD.EDU>
  7. Posting-number: Volume 14, Issue 24
  8. Archive-name: vplot/part19
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 19 (of 24)."
  17. # Wrapped by rsalz@fig.bbn.com on Fri Mar 25 11:47:31 1988
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. if test -f 'Vplot_Kernel/Documentation/hacker.doc.1' -a "${1}" != "-c" ; then 
  20.   echo shar: Will not clobber existing file \"'Vplot_Kernel/Documentation/hacker.doc.1'\"
  21. else
  22. echo shar: Extracting \"'Vplot_Kernel/Documentation/hacker.doc.1'\" \(25049 characters\)
  23. sed "s/^X//" >'Vplot_Kernel/Documentation/hacker.doc.1' <<'END_OF_FILE'
  24. Hacker's guide to the innards of the Pen programs,
  25. X                    or
  26. What you need to know to support a new device well
  27. X
  28. X
  29. Joe Dellinger and Charles R. Karish
  30. X
  31. Stanford University School of Earth Sciences
  32. X
  33. INTRODUCTION
  34. The pen software package, developed by students in the Geophysics department
  35. at Stanford University over many years, allows graphical data produced by
  36. computer programs to be displayed on a wide variety of output devices,
  37. including terminals and hard copy devices. Both vector and raster output
  38. are supported. The filters allow the user to control the size, aspect ratio,
  39. and position on the page independent of the program which produces the data.
  40. Pen programs read files written in the vplot graphics metalanguage and
  41. write commands appropriate to the various output devices.
  42. The pen programs are all filters, and can be run in pipelines without
  43. loss of function. Only rudimentary provisions for interaction are provided.
  44. X
  45. Terminals now supported include color Tektronix and
  46. emulators (4105), monochrome Tektronix and emulators (4010)
  47. X(GraphOn, Selanar, Retrographics), Envision, DEC Regis (Gigi, VT125, VT220),
  48. Imagen, PostScript (e. g., Apple LaserWriter), Printronix printer,
  49. suntools, X, NEWS, and Rastertek.
  50. X
  51. FILES
  52. The source for the pen filters is located in .../vplot/filters and
  53. subdirectories. All include files (files ending in .h) are kept in
  54. X.../vplot/filters/include. Fonts are kept in
  55. X.../vplot/filters/include/vplotfonts. Each pen filter has an associated
  56. X device-dependent subroutine library, which is kept in a subdirectory of
  57. X.../vplot/filters. For example, the Envision pen filter ``envipen'' uses
  58. the directory .../vplot/filters/envilib.
  59. X
  60. PROGRAM STRUCTURE
  61. The philosophy behind vplot and pen has been to have users' programs write
  62. output in a device-independent language, and to present the results in a
  63. compatible manner on all devices. All the filters share a common
  64. user/operating system interface routine, called frontend, and a common
  65. vplot command interpreter, dovplot.c. Frontend consists of 3 parts:
  66. main_vplot, init_vplot, and proc_vplot. The routines in utillib.a
  67. are mostly low-level and device independent. Genlib.a is a set of generic
  68. routines which is capable of providing all or almost all of the functions
  69. needed to support a GKS vector output package. The programmer is free
  70. to use these routines in a device driver, or to substitute calls to
  71. high-level hardware capabilities. Loclib.a contains a subset of the 
  72. seplib library, including routines for writing/reading vplot and for
  73. receiving parameters from the command line and initialization
  74. files.
  75. X
  76. The heart of the device support system is the file <dev>conf.c
  77. where <dev> is the name of the device. Inspired by the file
  78. X/usr/sys/machine/conf.c which configures the UNIX operating system
  79. to accept peripheral devices, this file is composed of three parts:
  80. X1)    Declaration of the variables necessary to do self-documentation:
  81. X    char name[] = "Filter name";
  82. X    char *documentation[] = {...documentation...};
  83. X    int doclength = {sizeof documentation / sizeof documentation[0] };
  84. X
  85. X    You may wish to include ``gendoc.h'' as part of your
  86. X    documentation string.
  87. X
  88. X2)    Declaration of the routines which have been chosen/written
  89. X    to provide the various functions.
  90. X    All the routines named in part 3 must be declared, as well as all the
  91. X    routines which they may call.
  92. X
  93. X3)    Initialization of a structure of pointers to the routines which do
  94. X    the work. Since this structure is read directly by dovplot.c,
  95. X    it is vital that the all entries be filled in order.
  96. X    Each subroutine name can be one of three types:
  97. X
  98. X    a) A device-specific subroutine name such as ``envipoint''.
  99. X    (Note the first 4 characters of the name are a unique identifier
  100. X    for the device, and the rest of the name tells which routine in the
  101. X    table this is. The 4 letter identifier is usually tacked onto
  102. X    ``pen'' to give the pen filter name (such as ``envipen'') and onto
  103. X    ``lib'' to give the subdirectory name (such as ``envilib'').)
  104. X
  105. X    b) A generic subroutine name such as ``genpoint''.
  106. X    Generic subroutines simplify the device's work by handling
  107. X    things in software. They in turn call other, simpler, device
  108. X    routines. Generic routines are useful because by using them it
  109. X    is very easy to rapidly support all the primitives on a device.
  110. X    If the device can do things in hardware, however, it is usually
  111. X    preferable to write a device-specific routine to use that capability
  112. X    since that is much more efficient.
  113. X
  114. X    c) The do-nothing subroutine ``nulldev''.
  115. X    Nulldev is an all-purpose generic subroutine that simply
  116. X    returns. It can either be used as a place holder for routines
  117. X    your device doesn't use, or it can be used in cases where there
  118. X    is simply no reasonable way to handle that particular primitive
  119. X    on that device.
  120. X
  121. The usual procedure for creating a new driver has been to steal as
  122. much code as possible from a driver for a similar device,
  123. or from the generic library. For a Tektronix emulator, this can be as
  124. simple as checking that the mode changes are handled properly by dev.open
  125. and dev.close, and writing a devconf.c with the proper subroutine names.
  126. For a start, it should be possible to get a less-standard device going
  127. with devopen, devclose, and devplot routines, relying on generic routines
  128. for all other functions. Figure 1 contains the device structure for the
  129. Envision 220.
  130. X
  131. X---------------------------------------------------------------------------
  132. X
  133. struct device   dev =
  134. X{
  135. X /* control routines */
  136. X    enviopen,        /* open */
  137. X    envireset,        /* reset */
  138. X    envimessage,    /* message */
  139. X    envierase,        /* erase */
  140. X    enviclose,        /* close */
  141. X
  142. X /* high level output */
  143. X    genvector,        /* vector */
  144. X    genmarker,        /* marker */
  145. X    gentext,        /* text */
  146. X    genarea,        /* area */
  147. X    genraster1,        /* raster */
  148. X    envipoint,        /* point */
  149. X    enviattributes,    /* attributes */
  150. X
  151. X /* input */
  152. X    envigetpoint,    /* getpoint */
  153. X    geninteract,    /* interact */
  154. X
  155. X /* low level output */
  156. X    enviplot,        /* plot */
  157. X    envistartpoly,    /* startpoly */
  158. X    envimidpoly,    /* midpoly */
  159. X    enviendpoly        /* endpoly */
  160. X};
  161. X
  162. Figure 1: device structure for envipen
  163. X-----------------------------------------------------------------------------
  164. X
  165. VARIABLES
  166. The following variables are used to communicate information between
  167. dovplot and the device routines.
  168. X
  169. These variables must be initialized in either dev.open or dev.reset:
  170. X
  171. int dev_xmax, dev_ymax, dev_xmin, dev_ymin;
  172. X
  173. X    These variables should give the device coordinates of the lower-leftmost
  174. X    and upper-rightmost pixels on the device screen. It is assumed that
  175. X    the device X axis is horizontal and the device Y axis is vertical,
  176. X    and that dev_xmax > dev_xmin and dev_ymax > dev_ymin. If this is not
  177. X    true for your device, it is up to the device routines to transform
  178. X    the device coordinate system so it is true. (Examples of devices that
  179. X    do this are gigipen and ipen.)
  180. X
  181. float pixels_per_inch, aspect_ratio;
  182. X
  183. X    Pixels_per_inch gives the number of pixels per inch on the device
  184. X    in the horizontal direction. Aspect_ratio gives the height to width
  185. X    ratio of the pixels. (Aspect_ratio > 1 means that the pixels are tall
  186. X    and skinny, and thus that the resolution is less in the vertical
  187. X    direction than in the horizontal direction.)
  188. X
  189. int num_col;
  190. X
  191. X    Num_col is the number of settable colors that the device has.
  192. X    Colors that can't be reset from the host don't count.
  193. X    Currently num_col can be at most 256, because this is all
  194. X    the raster routines can handle (due to use of unsigned char's).
  195. X    If mono=y is set, init_vplot will set num_col to zero.
  196. X
  197. X-------------------
  198. X
  199. These variables are set by dovplot but may be reset in
  200. dev.open (NOT dev.reset) if the default
  201. value is not appropriate. For the most part, resetting these variables
  202. is for the purpose of making a device-dependent default;
  203. the user is given a chance to override the value the device sets them to.
  204. X
  205. int mono=NO;
  206. X
  207. X    If mono=NO, then the device is assumed to have color EVEN IF num_col is
  208. X    zero. If mono=YES, then the device is monochrome. (The user cannot
  209. X    override mono=YES, but can mono=NO.) See comments about the effects
  210. X    of mono and num_col on color in dev.attributes below, and on raster
  211. X    in dev.raster. Mono=YES forces num_col=0.
  212. X
  213. int invras=YES;
  214. X
  215. X    This variable is only used in the utility routine ``dither.c'', which
  216. X    dithers raster. Raster is only dithered if mono=YES and dither>0.
  217. X    Normally such devices draw in black on a white page, which is the
  218. X    reverse of what is normal for screen devices, and so invras=YES.
  219. X    If the background color is BLACK then invras should be NO.
  220. X
  221. int dither=1;
  222. X
  223. X    Default dithering style to use for this device. See vplotraster(9)
  224. X    for the different values to be explained.
  225. float greyc=1.;
  226. X    This variable is used only when dithering is being performed,
  227. X    and really should only be used for hardcopy devices. It alters
  228. X     the grey scale so that grey rasters come out on paper with the
  229. X    same nonlinear appearance that is perceived on display devices.
  230. X    See vplotraster(9) for a discussion of the parameter and how to
  231. X    use it.
  232. float pixc=1.;
  233. X    This variable is used only when dithering is being performed,
  234. X    and also should only be used for hardcopy devices. It alters the
  235. X    grey scale to correct for pixel overlap on the device, which 
  236. X    (if uncorrected) causes grey raster images to come out much darker
  237. X    on paper than on graphics displays. See vplotraster(9) for a 
  238. X    discussion of the parameter and how to use it.
  239. X
  240. int txfont=DEFAULT_FONT, txprec=DEFAULT_PREC;
  241. X
  242. X    Default text font, precision, and overlay mode. Text fonts of less
  243. X    than NUMGENFONT are reserved for genvector fonts. If you want the
  244. X    device to by default use some nice hardware font, you can reset
  245. X    txfont to the appropriate device-dependent font number.
  246. X    Alternatively, if the device is one in which plotting speed is not
  247. X    a problem, txfont can be set to DEFAULT_HARDCOPY_FONT.
  248. X    Txprec is pretty much ignored by genvector. Fancy output devices should
  249. X    set txprec to DEFAULT_HARDCOPY_PREC to enable ligatures. Txprec may
  250. X    be used by device-dependent text routines. Txprec must be in the range
  251. X    0 through 2.
  252. X
  253. float hshift=0., vshift=0.; int rotate=0;
  254. X
  255. X    These values are in addition to whatever the user may set from the
  256. X    command line. This provides a way for a device to rotate or translate
  257. X    all plots.
  258. X
  259. int shade=YES;
  260. X
  261. X    If shade=NO, then no attempt will be made by vplot to ask the device to
  262. X    shade the interiors of polygons due to the vplot `a' and `A' commands.
  263. X    Instead it will just outline them with vectors whenever it tries to
  264. X    fill a polygon. This option is for devices that CAN fill but are
  265. X    very slow to do so.
  266. X
  267. int wantras=YES;
  268. X
  269. X    If wantras=NO, then no attempt will be made by vplot to ask the
  270. X    device to handle raster due to the vplot `r' and `R' commands.
  271. X    Instead it will just shade the raster area solid white using dev.area.
  272. X    This option is for devices that CAN do raster but are very slow to
  273. X    do it.
  274. X
  275. float fatmult=1., patternmult=1.;
  276. X
  277. X    If fat lines are too slow, you can set fatmult=0. and disable line
  278. X    fattening. The user can still turn it on again by overriding with
  279. X    fatmult=1 from the command line. Patternmult can be used to scale up
  280. X    or down patterns by default on a specific device.
  281. X
  282. int endpause=NO;
  283. X
  284. X    If the device needs a pause at the end of the plot
  285. X    (via dev.close(CLOSE_PAUSE) and then dev.interact(INT_F_PAUSE))
  286. X    then endpause should be set to YES.
  287. X
  288. int allowecho=?;
  289. X
  290. X    Allowecho controls whether echoing is turned off for the duration of
  291. X    plotting. Allowecho=NO turns off echoing.
  292. X    If the dev.open sets allowecho, dovplot assumes that it knows what it's
  293. X    doing and leaves it alone. Otherwise,
  294. X    dovplot tries to decide whether allowecho should be YES or NO depending
  295. X    on where the output stream pltout goes. If after calling dev.open
  296. X    pltout and stderr point to the same place, then it assumes that
  297. X    allowecho should be NO. The user can force allowecho to be YES
  298. X    from the command line if the device or dovplot set it to be NO,
  299. X    but the user cannot force it to be NO.
  300. X
  301. int (*message)()=genmessage;
  302. X
  303. X    Dovplot decides where to send messages (such as error messages, for
  304. X    example) in the same way that it decides how to set allowecho.
  305. X    Before dev.open has been called, the device is not open and dev.message
  306. X    cannot be called. Instead, it is assumed that it is safe to send all
  307. X    messages to stderr by calling genmessage instead. After dev.open has
  308. X    been called, dovplot checks to see whether stderr and pltout point to
  309. X    the same place. If they do, then from then on all messages are routed to
  310. X    dev.message. However, if they do NOT point to the same place, then it is
  311. X    assumed that it is still safe to route them to stderr and messages are
  312. X    still handled by genmessage. If this logic is incorrect for your device
  313. X    you will need to reset this variable to dev.message in dev.open. So
  314. X    far the only devices for which dovplot's logic has been wrong have
  315. X    been virtual ones. The user cannot determine where messages are to
  316. X    be sent.
  317. X
  318. X----------------
  319. X
  320. These variables can usually be left at their default values, but may
  321. have to be reset for some devices. They cannot be changed by the user.
  322. X
  323. int need_end_erase=NO;
  324. X
  325. X    Some devices use the ``erase'' routine to do things such as write out
  326. X    a rasterized plot image as well as for erasing. For such devices it
  327. X    is convenient to have dev.erase called one last time before the device
  328. X    is closed (via dev.erase(ERASE_END)). To get this, set need_end_erase=YES.
  329. X
  330. int buffer_output=YES;
  331. X
  332. X    If for some reason buffering the output to your device is a bad thing to
  333. X    do, set buffer_output=NO. This only applies if you use the FILE *pltout
  334. X    that dovplot provides.
  335. X
  336. int smart_clip=NO;
  337. X
  338. X    If smart_clip=NO, then dovplot should do all clipping for you. If you
  339. X    can do your own clipping, then set smart_clip=YES. You must then
  340. X    handle dev.attributes(SET_WINDOW)!
  341. X
  342. int smart_raster=NO;
  343. X
  344. X    If you can stretch AND clip your own raster, then set smart_raster=YES.
  345. X    It is then up to you to do all the stretching and clipping (and possibly
  346. X    dithering) of raster in the dev.raster routine, as dovplot will not then
  347. X    do it for you.
  348. X
  349. X-------------------
  350. X
  351. These variables may be useful to refer to in dev.open, so that one pen filter
  352. can support multiple devices:
  353. X
  354. char callname[]="filename";
  355. char wstype[]="default";
  356. X
  357. X    Callname gives the name the person invoked to run this pen filter.
  358. X    (The leading path is stripped for you if present.) If the person
  359. X    has ``wstype=work_station_type'' as a command line option, then
  360. X    wstype will be set to the string "work_station_type". Otherwise,
  361. X    it will be set to "default". Note that the only routine that
  362. X    REALLY has to be defined in dev.conf is dev.open, and the only
  363. X    routines that REALLY have to be defined in dev.open are dev.close,
  364. X    dev.reset and dev.message. However, by the time dev.reset returns
  365. X    everything had better be defined. Thus you can decide inside
  366. X    dev.open which subroutines to plug into the device table, after
  367. X    looking at wstype and callname to tell you which device you are
  368. X    supporting.
  369. X
  370. X------------------------------------------------------------------------------
  371. X
  372. SUBROUTINES
  373. All sizes and locations are in device units unless stated otherwise.
  374. Dovplot() uses its notions of the vplot environment (resolution, origin)
  375. and the device resolution (pixel size and shape) to call with the appropriate
  376. values. Subroutines may write to the external FILE *pltout which dovplot
  377. initializes, which may be a terminal, a pipe, or a text file, or
  378. they may open their own output file if pltout is not appropriate.
  379. In general, if the user is redirecting stdout, then that's where the
  380. output should go and no plot should actually appear anywhere.
  381. If the user is not redirecting stdout, then the user wants a plot to appear
  382. on the appropriate device. Pen filters should not easily be made to
  383. dump binary garbage out onto your screen!
  384. X
  385. We will list each routine in the device table in order. We will also
  386. list all associated generic and utility routines at the same time.
  387. X
  388. Control routines
  389. X
  390. X===========================
  391. X
  392. dev.open()
  393. X
  394. Initialize device-dependent variables (see above)
  395. and emit hardware initialization strings.
  396. This routine is guaranteed to be the first called, and it is only
  397. called once.
  398. X
  399. X===========================
  400. X
  401. dev.reset()
  402. X
  403. Reset the terminal. It is guaranteed that this will be called once
  404. after the first call to dev.open before any other routine is called.
  405. The one exception is in case of certain errors, in which case dev.reset
  406. is never called and instead dev.close(NOTHING) followed by dev.close(DONE)
  407. are the only other calls after the initial dev.open call. (This is the
  408. X``No input?'' error, which you've probably seen.)
  409. X
  410. X===========================
  411. X
  412. dev.message(command, string)
  413. int command;
  414. char string[];
  415. X
  416. Choose a command from mesgcom.h to position the cursor, set the proper
  417. text mode, and print out a message.  Displaying a message will
  418. require several calls to dev.message, one per command.
  419. The meanings of the various commands are given by comments inside
  420. mesgcom.h.
  421. X
  422. Generic routines: genmessage.c
  423. Genmessage prints all messages to stderr. It doesn't try to do anything
  424. at all fancy, although it does beep as the best available completely
  425. device-independent way of ``highlighting text''. It beeps twice because
  426. some devices silently eat single beeps.
  427. X
  428. X===========================
  429. X
  430. dev.erase(command)
  431. int command;
  432. X
  433. Choose an erase mode from erasecom.h, and erase the screen.
  434. The meanings of the various commands are given by comments inside
  435. erasecom.h.
  436. X
  437. X===========================
  438. X
  439. dev.close(status)
  440. int status;
  441. X
  442. Choose a close status from closestat.h, and close the workstation.
  443. The meanings of the various commands are given by comments inside
  444. closestat.h.
  445. X
  446. High level output routines
  447. X
  448. X===========================
  449. X
  450. dev.vector(x1, y1, x2, y2, nfat, dashon)
  451. int x1, y1, x2, y2, nfat, dashon;
  452. X{
  453. X/* These can be declared by including extern.h */
  454. extern float dashsum, dashpos;
  455. extern float dashes[/* dashon*2 */];
  456. X
  457. Draw a (possibly) fat (possibly) dashed line from device coordinate
  458. X(x1,y1) to (x2,y2). The fatness of the line is given by nfat. Nfat=0
  459. means the thinnest possible line. Each increase of 1 means to fatten
  460. the line by one device pixel WIDTH (the height could be quite different,
  461. depending on the value of aspect_ratio). Nfat < 0 should be checked for,
  462. and no vector should be drawn at all in that case.
  463. X
  464. If dashon>0 then a dashed line should be drawn. The pattern consists
  465. of dashon dash-gap pairs. The pattern is defined in the array
  466. dashes[2*dashon]. (ie, dashes[0] is the first dash length, dashes[1]
  467. is the first gap length, dashes[2] is the second dash length, etc.)
  468. Dovplot will call dev.attributes(NEW_DASH,...) whenever the values
  469. in this array are changed. Note that just because a dashed pattern
  470. has been put in effect does not mean it will always be used on all
  471. calls to dev.vector. Dev.vector can still be asked to draw continuous
  472. lines (ie, those for which dashon=0) without warning at any time.
  473. Dashsum gives the total length of the dash-gap pattern
  474. X(ie, dashsum = summation i=0;i<dashon*2;i++ of dashes[i]).
  475. The position in the dash pattern at the start of the vector is given
  476. in dashpos (it is the responsibility of dev.vector to update dashpos
  477. after each vector is drawn. The only time dovplot ever touches it is to
  478. reset it back to zero.) Dashpos, dashsum, and dashes are all measured
  479. in INCHES. (You should get the same size dash pattern on different
  480. devices even if they have different-sized screens!) If you are not
  481. sure whether you have supported dashed lines correctly, try using
  482. dashvec (described below) to do the dashing and see if the results
  483. are compatible.
  484. X
  485. Just as in the case of dashing, dev.attributes(NEW_FAT,...) warns
  486. when the "current fatness" has been changed. But dev.vector can
  487. still be asked to draw a line with a different fatness (such as for
  488. a polygon border) without warning at any time.
  489. X
  490. Utility routines associated with dev.vector:
  491. X    These routines are meant to be called from a device-dependent
  492. dev.vector routine as utility functions.
  493. X
  494. fatvec(x1, y1, x2, y2, nfat, dashon)
  495. int x1, y1, x2, y2, nfat, dashon;
  496. X
  497. Fatvec should ONLY be called if nfat>0. Fatvec will apply Glenn Kroeger's
  498. line-fattening algorithm to the given fat vector, replacing it with several
  499. non-fat vectors. Fatvec will thus repeatedly call dev.vector with nfat=0.
  500. X(That's why it is important that your routine only call fatvec if nfat>0!)
  501. Fatvec ignores the dashon argument.
  502. X
  503. dashvec(x1, y1, x2, y2, nfat, dashon)
  504. int x1, y1, x2, y2, nfat, dashon;
  505. X
  506. Dashvec should ONLY be called if dashon>0. Dashvec will apply Joe Dellinger
  507. and Steve Cole's line-dashing algorithm to the given dashed vector, replacing
  508. it with several non-dashed vectors. Dashvec will thus repeatedly call
  509. dev.vector with dashon=0. (That's why it is important that your routine
  510. only call dashvec if dashon>0!) Dashvec ignores the nfat argument.
  511. X
  512. Note that if both dashvec and fatvec are called, dashvec must be called
  513. FIRST.
  514. X
  515. int clip(x1, y1, x2, y2)
  516. int *x1, *y1, *x2, *y2;
  517. X
  518. Clip will clip the vector {(x1,y1),(x2,y2)} to the bounds set by
  519. X{(xwmin,ywmin),(xwmax,ywmax)}. If the line is completely out of
  520. bounds and is clipped away to nothing, clip returns 1. Otherwise,
  521. clip returns 0. The standard way of using clip is:
  522. X
  523. X    if(clip(&x1,&y1,&x2,&y2)) return;
  524. X
  525. Generic routines for dev.vector: genvector.c
  526. This routine will do all required clipping, fattening, and dashing.
  527. It will also keep track of the previous position, and breaks up strings
  528. of vectors for you into moves and draws. (It does this in a tricky way,
  529. re-ordering the incoming vectors and even discarding moves that can be done
  530. with draws. The idea is to make the plot come out as efficiently as possible
  531. on the device.) It calls dev.plot(x,y,flag). No other routine calls
  532. dev.plot, so if you do not use genvector then dev.plot should be nulldev.
  533. X
  534. X===========================
  535. X
  536. dev.marker(npts, mtype, msize, coor)
  537. int npts, type, size;
  538. int coor[/* npts*2 */];
  539. X
  540. Draw npts symbols centered at device coordinates (coor[0],coor[1]),
  541. X(coor[2],coor[3]),...,(coor[npts*2-2],coor[npts*2-1]).
  542. X
  543. Mtype is an integer from 0 to whatever, defining the type of symbol to
  544. draw. Mtype of 0 through 5 is defined as in GKS:
  545. X0,1: Smallest possible dot on the device.
  546. X2: Plus sign
  547. X3: Asterisk
  548. X4: Circle
  549. X5: Cross
  550. X6-19: Reserved by GKS, but currently undefined.
  551. These are as used in Vplot:
  552. X20: Square
  553. X21: Triangle (flat side on bottom)
  554. X22: Diamond
  555. X23: 5-pointed Star
  556. X
  557. For values that make sense as ASCII, something that looks like the
  558. corresponding ASCII character should be used.
  559. For ridiculous values of mtype, at least plot a point.
  560. X
  561. Msize is the vertical height of the symbol in VERTICAL device units.
  562. X(Ie, msize says how many pixels tall the letter `A' should be.)
  563. X
  564. Generic routines: genmarker.c
  565. Genmarker calls dev.point, dev.text, or gentext.c as needed to produce
  566. the desired symbols. For ASCII symbols the current font is used, which
  567. could either be a device-dependent font or a gentext font depending on the
  568. font number. Marker types 2 through 23 are drawn using the MATH and
  569. MISC gentext fonts.
  570. X
  571. X===========================
  572. X
  573. dev.text(string, pathx, pathy, upx, upy);
  574. char *string;
  575. float pathx, pathy, upx, upy;
  576. X{
  577. X/* These can be defined by including vplot.h and extern.h */
  578. extern int txfont, txprec, txovly;
  579. struct txalign {int hor; int ver;};
  580. extern struct txalign txalign;
  581. extern int fat;
  582. extern int xold, yold;
  583. X
  584. Print the text in string at the point (xold,yold) in device coordinates.
  585. Upon return, xold and yold should be reset to point to the END of the text.
  586. X(IE, for the normal text justification mode (TH_LEFT, TV_BASE), if the
  587. dev.text routine is called twice in a row the two printed strings should
  588. fit together nicely, as if produced by one call to dev.text with the two
  589. strings concatenated.)
  590. X
  591. The text should have fatness `fat', as defined in the section for
  592. dev.vector above.
  593. X
  594. The text should be justified according to the values of txalign.hor
  595. X(for horizontal alignment) and txalign.ver (for vertical alignment.)
  596. See vplot.h and vplottext.mn for descriptions of how text justification
  597. should work and to enumerate the various justification modes. (Our modes
  598. follow GKS, but with a couple of extensions thrown in to handle symbols
  599. and mid-text font and size changes.)
  600. X
  601. The text font value to use is given by txfont. Device-dependent text fonts
  602. start at font number NUMGENFONT. For txfont less than this, dovplot will
  603. NOT automatically call gentext. Device-dependent text routines, except
  604. for certain special cases, should begin by:
  605. X
  606. X    if (txfont < NUMGENFONT)
  607. X    {
  608. X    gentext(...pass on all arguments here...);
  609. X    return;
  610. X    }
  611. X
  612. The text precision value can be used by device-dependent text routines
  613. to control the quality of text produced. (You should either follow the
  614. GKS conventions or simply produce good text and ignore this parameter.)
  615. The three different precisions are enumerated in vplot.h
  616. X
  617. The text overlay value controls whether or not an area is shaded out
  618. under the text before it is drawn, and whether or not a box should be
  619. drawn around it. The shading should be to the current background color,
  620. END_OF_FILE
  621. if test 25049 -ne `wc -c <'Vplot_Kernel/Documentation/hacker.doc.1'`; then
  622.     echo shar: \"'Vplot_Kernel/Documentation/hacker.doc.1'\" unpacked with wrong size!
  623. fi
  624. # end of 'Vplot_Kernel/Documentation/hacker.doc.1'
  625. fi
  626. if test -f 'Vplot_Kernel/filters/init_vplot.c' -a "${1}" != "-c" ; then 
  627.   echo shar: Will not clobber existing file \"'Vplot_Kernel/filters/init_vplot.c'\"
  628. else
  629. echo shar: Extracting \"'Vplot_Kernel/filters/init_vplot.c'\" \(23118 characters\)
  630. sed "s/^X//" >'Vplot_Kernel/filters/init_vplot.c' <<'END_OF_FILE'
  631. X/*
  632. X * Copyright 1987 the Board of Trustees of the Leland Stanford Junior
  633. X * University. Official permission to use this software is included in
  634. X * the documentation. It authorizes you to use this file for any
  635. X * non-commercial purpose, provided that this copyright notice is not
  636. X * removed and that any modifications made to this file are commented
  637. X * and dated in the style of my example below.
  638. X */
  639. X
  640. X/*
  641. X *
  642. X *  source file:   ./filters/init_vplot.c
  643. X *
  644. X * Joe Dellinger (SEP), Feb 18 1988
  645. X *    Inserted this sample edit history entry.
  646. X *    Please log any further modifications made to this file:
  647. X *
  648. X * Joe Dellinger, Feb 20 1988
  649. X *    #define GETPAR to be fetch if SEPlib version.
  650. X *
  651. X * Joe Dellinger Feb 24 1988
  652. X *     Moved gen_do_dovplot to genlib, where it belongs.
  653. X *    txfont, txprec, txovly, overlay defaults remembered.
  654. X * Joe Dellinger Feb 28 1988
  655. X *    Changed fatness to scale with size of screen and scale,
  656. X *    like any regular geometric attribute.
  657. X * Joe Dellinger Mar 4 1988
  658. X *    Fixed slight bug with fatness scaling and style=old.
  659. X */
  660. X
  661. X#include    <stdio.h>
  662. X#include    <math.h>
  663. X#include    <sys/ioctl.h>
  664. X#include    <sys/types.h>
  665. X#include    <sys/stat.h>
  666. X#include    <sgtty.h>
  667. X#include    <ctype.h>
  668. X#include    <strings.h>
  669. X
  670. X#include    <vplot.h>
  671. X
  672. X#include    "./include/params.h"    /* for machine dependencies */
  673. X#include    "./include/enum.h"
  674. X#include    "./include/err.h"
  675. X#include    "./include/attrcom.h"
  676. X#include    "./include/intcom.h"
  677. X#include    "./include/mesgcom.h"
  678. X#include    "./include/erasecom.h"
  679. X#include    "./include/closestat.h"
  680. X#include    "./include/pat.h"
  681. X#include    "./include/vertex.h"
  682. X#include    "./include/round.h"
  683. X#include    "./include/extern.h"
  684. X
  685. X#ifdef SEP
  686. X#define        GETPAR    fetch
  687. X#else
  688. X#define        GETPAR    getpar
  689. X#endif SEP
  690. X
  691. struct sgttyb   tty_clean_state;
  692. struct sgttyb   tty_plot_state;
  693. int             tty_clean_local_mode;
  694. int             tty_plot_local_mode;
  695. X
  696. X/* 
  697. X * The following variables must ALWAYS
  698. X * be set in the device open or device reset file.
  699. X * All their defaults are set to absurd values so that
  700. X * we'll crash quickly it they're not set as required.
  701. X */
  702. X/* Screen dimensions */
  703. int             dev_xmax = 0, dev_ymax = 0, dev_xmin = 0, dev_ymin = 0;
  704. X/* Number of pixels per inch in the horizontal (X) direction on the device */
  705. float           pixels_per_inch = 0.;
  706. X/* vertical height (on screen) / horizontal width for a single pixel */
  707. float           aspect_ratio = 0.;
  708. X/*
  709. X * Number of SETTABLE COLORS that the device has.
  710. X * Non settable colors don't count.
  711. X */
  712. int             num_col = -1;
  713. X
  714. X/*
  715. X * Other things that may need to be reset in dev.open
  716. X * (Can't reset them some of them in dev.reset, because the user may
  717. X * override from the command line.)
  718. X */
  719. X/* Does device need erase at end? */
  720. int             need_end_erase = NO;
  721. X/* should the output be buffered? */
  722. int             buffer_output = YES;
  723. X/* should the input be buffered? */
  724. int             buffer_input = YES;
  725. X/* should pipes be allowed for input? */
  726. int             allow_pipe = YES;
  727. X/* Can the device do its own clipping? (of vectors and polygons.) */
  728. int             smart_clip = NO;
  729. X/* Can the device stretch AND clip its own raster? */
  730. int             smart_raster = NO;
  731. X
  732. X/*
  733. X * These may be reset to device-dependent defaults.
  734. X */
  735. float           fatmult = 1.;
  736. float           patternmult = 1.;
  737. X
  738. X/*
  739. X * Look in extern.h for a better-organized list of the preceding.
  740. X * Here I have left things which are also filter options with the
  741. X * other filter options, even though they also belong in the above
  742. X * categories.
  743. X */
  744. X
  745. X/*
  746. X * flags and variables
  747. X */
  748. char            wstype[25];
  749. char            callname[25];
  750. int             xcenterflag, ycenterflag;
  751. int             ever_called = NO;
  752. int             first_time = YES;
  753. int             device_open = NO;    /* used by ERR */
  754. int             out_isatty = YES;    /* If NO, output is a file or pipe */
  755. int             nplots = 0;    /* number of plots made */
  756. X
  757. X/*
  758. X * coordinate variables
  759. X */
  760. int             xwmax, xwmin, ywmax, ywmin;    /* window */
  761. int             xnew, ynew;    /* new pen location */
  762. int             xold, yold;    /* old pen location */
  763. int             xorigin = 0, yorigin = 0;    /* global "origin" */
  764. char           *txbuffer;
  765. int             txbuflen, vxbuflen;
  766. struct vertex  *vxbuffer;
  767. int             xret, yret;
  768. float           mxx, mxy, myx, myy;
  769. X/*
  770. X * This is so the device can throw in a coordinate transformation
  771. X * for its convenience ON TOP OF whatever transformation the user
  772. X * wants.
  773. X */
  774. int             default_rotate = 0, default_hshift = 0, default_vshift = 0;
  775. X
  776. X/*
  777. X * attribute variables
  778. X */
  779. int             linestyle;
  780. int             cur_color = DEFAULT_COLOR;
  781. int             pat_color = DEFAULT_COLOR + 1;
  782. int             next_color;
  783. struct txalign  txalign;
  784. X
  785. int             txfont = DEFAULT_FONT;
  786. int             txprec = DEFAULT_PREC;
  787. int             txovly = OVLY_NORMAL;
  788. int             default_txfont, default_txprec, default_txovly;
  789. int             fat = 0;
  790. int             afat = 0;
  791. int             ipat = 0;    /* currently loaded pattern */
  792. struct pat      pat[NPAT + 1];
  793. float           dashsum = 0.;
  794. int             dashon = NO;    /* Dashed lines? */
  795. float           dashes[MAXDASH * 2];
  796. float           dashpos = 0.;    /* Position in current dashing pattern */
  797. int             color_set[MAX_COL + 1][_NUM_PRIM];
  798. extern int      greycorr ();
  799. int             num_col_8;
  800. X
  801. X
  802. X/*
  803. X * filter options - flags
  804. X */
  805. X/* Monochrome device? */
  806. int             mono = NO;
  807. X/*
  808. X * Invras determines the polarity of dithered raster.
  809. X * invras=n means raster works the same way as vectors; what is normally
  810. X * WHITE on most devices is BLACK on a hardcopy black and white device.
  811. X * invras=y is the proper default to make dithered images not come out as negatives
  812. X */
  813. int             invras = YES;
  814. int             window = YES;
  815. int             shade = YES;
  816. int             brake = NO;
  817. int             framewindows = NO;
  818. int             endpause = NO;
  819. int             allowecho = NEVER_SET;
  820. X/*
  821. X * setting allowecho NO (which may get done
  822. X * in dev.open) means that the output device
  823. X * is the user's terminal and echoing chars
  824. X * back at the user would insert nonsense
  825. X * into the plot stream.  In this case we
  826. X * explicitly shut down echoing and output
  827. X * translation until the end of the job.
  828. X * Arguably, output translation should be
  829. X * set/unset in dev.open or dev.reset as we may
  830. X * be plotting on a terminal not our own or
  831. X * the device filter may have built in
  832. X * workarounds for known output translation
  833. X * effects. I use it here as a safety measure.
  834. X */
  835. int             wantras = YES;
  836. X
  837. X/*
  838. X * filter options - enumerated
  839. X */
  840. int             style = NO_STYLE_YET;
  841. int             default_style = STYLE;
  842. int             rotate;
  843. int             size = RELATIVE;
  844. int             erase = FORCE_INITIAL | DO_LITERALS;
  845. X
  846. X/*
  847. X * filter options - valued
  848. X */
  849. int             xcenter, ycenter;    /* Vplot of point to force as center */
  850. int             fatbase = 0;
  851. int             epause = 0;    /* time to pause before erasing screen */
  852. int             overlay = 0;    /* 1=overlay 0=replace */
  853. int             default_overlay;
  854. X
  855. X/*
  856. X * 0 = none
  857. X * 1 = random
  858. X * 2 = Ordered
  859. X * 3 = Floyd-Steinberg
  860. X */
  861. int             dither = 1;    /* Dithering type */
  862. X
  863. int             xWmax, xWmin, yWmax, yWmin;
  864. float           hshift, vshift;    /* Allow global translation of plot */
  865. float           scale;    /* global scale */
  866. float           xscale;    /* global x-scale */
  867. float           yscale;    /* global y-scale */
  868. float           hdevscale;    /* Vplot units to device units for x */
  869. float           vdevscale;    /* Vplot units to device units for y */
  870. float           txscale;/* global text scale */
  871. float           mkscale;/* global marker scale */
  872. float           dashscale;    /* global dashed line scale */
  873. char            interact[MAXFLEN + 1] = "";    /* Where to store coordinate
  874. X                         * file */
  875. float           greyc = 1.;    /* Nonlinear correction */
  876. float           pixc = 1.;    /* Pixel overlap correction */
  877. X
  878. X/* filter options - resettable between plots */
  879. int             user_rotate;
  880. float           user_txscale;
  881. float           user_mkscale;
  882. float           user_dashscale;
  883. float           user_scale;
  884. float           user_xscale;
  885. float           user_yscale;
  886. int             user_size;
  887. float           user_hshift;
  888. float           user_vshift;
  889. int             user_xwmax_flag;
  890. float           user_xwmax;
  891. int             user_ywmax_flag;
  892. float           user_ywmax;
  893. int             user_xwmin_flag;
  894. float           user_xwmin;
  895. int             user_ywmin_flag;
  896. float           user_ywmin;
  897. X
  898. int             ifat = 0;
  899. float           fatmult_orig;
  900. X
  901. X/*
  902. X * file and terminal control variables
  903. X */
  904. int             pltoutfd, stderrfd, controlfd;
  905. extern int      genmessage ();
  906. int             (*message) () = genmessage;
  907. struct stat     stderrstat;
  908. struct stat     pltoutstat;
  909. FILE           *pltout, *pltin;
  910. FILE           *fopen ();
  911. FILE           *fdopen ();
  912. FILE           *controltty;
  913. char            outbuf[BUFSIZ];
  914. char           *getenv ();
  915. char           *malloc ();
  916. char           *realloc ();
  917. char            group_name[MAXFLEN + 1];
  918. int             group_number = 0;
  919. FILE           *pltinarray[MAXIN];
  920. char            pltinname[MAXIN][MAXFLEN + 1];
  921. char            pltname[MAXFLEN + 1] = "";
  922. int             infileno = 0;
  923. extern int      gen_do_dovplot ();
  924. int             (*genreader) () = gen_do_dovplot;
  925. X
  926. X/*
  927. X * Initialize and declare global variables.
  928. X * Use getpar and getenv to search for command-line options.
  929. X */
  930. X
  931. init_vplot ()
  932. X{
  933. char           *stringptr;
  934. int             ii;
  935. char            string[MAXFLEN + 1];
  936. float           ftemp;
  937. X
  938. X
  939. X    txbuffer = malloc (TXBUFLEN);
  940. X    txbuflen = TXBUFLEN;
  941. X/*
  942. X * Sun III lint complains about "pointer alignment problem" here,
  943. X * although the documentation makes it sound like that shouldn't
  944. X * be possible.
  945. X */
  946. X    vxbuffer = (struct vertex *) malloc (sizeof (struct vertex) * VXBUFLEN);
  947. X    vxbuflen = VXBUFLEN;
  948. X
  949. X    /*
  950. X     * If the device can't do color, it can set mono to YES If device is
  951. X     * mono, this overrides the user's insistence that it isn't. So GETPAR
  952. X     * before we call dev.open. 
  953. X     */
  954. X    GETPAR ("mono", "1", &mono);
  955. X
  956. X    strcpy (wstype, "default");
  957. X    if ((stringptr = getenv ("WSTYPE")) != NULL)
  958. X    strcpy (wstype, stringptr);
  959. X    /*
  960. X     * Don't want to accidentally get this from a history file. Must come for
  961. X     * the command line, so getpar, not GETPAR 
  962. X     */
  963. X    getpar ("wstype", "s", wstype);
  964. X
  965. X    /*
  966. X     * Initialize all patterns to be undefined. (device can create a
  967. X     * device-dependent default set if it wishes) 
  968. X     */
  969. X    for (ii = 0; ii <= NPAT; ii++)
  970. X    {
  971. X    pat[ii] .patbits = NULL;
  972. X    }
  973. X
  974. X/*
  975. X * The device-independent code MAY NOT actually read from
  976. X * the terminal itself. However, these variables are 
  977. X * declared so that the device-dependent routines can use
  978. X * them if they wish as a courtesy.
  979. X */
  980. X    controlfd = open ("/dev/tty", 0);
  981. X    controltty = fdopen (controlfd, "r");
  982. X
  983. X    /*
  984. X     * Call device open before doing anything else. this finalizes pltout 
  985. X     */
  986. X    dev.open ();
  987. X    device_open = YES;
  988. X
  989. X/*
  990. X * Beware trying to print out error messages until
  991. X * we've figured out where to connect the "message" routine!
  992. X */
  993. X
  994. X    if (buffer_output)
  995. X    setbuf (pltout, outbuf);
  996. X    else
  997. X    setbuf (pltout, (char *) NULL);
  998. X
  999. X    /*
  1000. X     * If graphics output going to control terminal, disable echoing and
  1001. X     * arrange for use of device's message routine 
  1002. X     */
  1003. X    pltoutfd = fileno (pltout);
  1004. X    stderrfd = fileno (stderr);
  1005. X    out_isatty = isatty (pltoutfd);
  1006. X
  1007. X    if (allowecho == NEVER_SET)
  1008. X    {
  1009. X    allowecho = YES;
  1010. X    if (out_isatty)
  1011. X    {
  1012. X        fstat (pltoutfd, &pltoutstat);
  1013. X        fstat (stderrfd, &stderrstat);
  1014. X#ifdef SEP
  1015. X        if ((pltoutstat.st_dev == stderrstat.st_dev))
  1016. X        /*
  1017. X         * Something in seplib makes the next 2 tests not work, I
  1018. X         * don't know why. Unfortunately, this means the SEP versions
  1019. X         * aren't as good about detecting the case of sending the
  1020. X         * output to a different terminal than the one you're logged
  1021. X         * in at. We should probably get this fixed sometime. - Joe
  1022. X         * D. 
  1023. X         */
  1024. X#else
  1025. X        if ((pltoutstat.st_dev == stderrstat.st_dev) &&
  1026. X        (pltoutstat.st_ino == stderrstat.st_ino) &&
  1027. X        (pltoutstat.st_rdev == stderrstat.st_rdev))
  1028. X#endif SEP
  1029. X        {
  1030. X        allowecho = NO;
  1031. X        message = dev.message;
  1032. X        }
  1033. X    }
  1034. X    }
  1035. X
  1036. X    /*
  1037. X     * process YES or NO option arguments. GETPAR means it could have come
  1038. X     * from a seplib history file, getpar means it had to come from the
  1039. X     * command line. Use "getpar" when having the right value of the
  1040. X     * parameter is critical because setting the value overrides frontend's
  1041. X     * judgement. 
  1042. X     */
  1043. X    getpar ("echo", "1", &allowecho);
  1044. X    if (!allowecho)
  1045. X    {
  1046. X    ioctl (pltoutfd, TIOCGETP, (char *) (&tty_clean_state));
  1047. X    bcopy ((char *) (&tty_clean_state), (char *) (&tty_plot_state),
  1048. X           sizeof (struct sgttyb));
  1049. X    ioctl (pltoutfd, TIOCLGET, (char *) (&tty_clean_local_mode));
  1050. X    tty_plot_local_mode = tty_clean_local_mode | LLITOUT;
  1051. X    ioctl (pltoutfd, TIOCLSET, (char *) (&tty_plot_local_mode));
  1052. X    tty_plot_state.sg_flags &= (~ECHO);
  1053. X    tty_plot_state.sg_flags &= (~LCASE);
  1054. X    tty_plot_state.sg_flags |= (CBREAK);
  1055. X    ioctl (pltoutfd, TIOCSETN, (char *) (&tty_plot_state));
  1056. X    }
  1057. X    getpar ("endpause", "1", &endpause);
  1058. X    GETPAR ("break", "1", &brake);
  1059. X    GETPAR ("shade", "1", &shade);
  1060. X    GETPAR ("wantras", "1", &wantras);
  1061. X    GETPAR ("window", "1", &window);
  1062. X    GETPAR ("frame", "1", &framewindows);
  1063. X    GETPAR ("overlay", "1", &overlay);
  1064. X    default_overlay = overlay;
  1065. X    GETPAR ("invras", "1", &invras);
  1066. X
  1067. X/*
  1068. X * Valued arguments
  1069. X */
  1070. X
  1071. X    getpar ("dither", "d", &dither);
  1072. X    getpar ("greyc", "f", &greyc);
  1073. X    getpar ("pixc", "f", &pixc);
  1074. X
  1075. X    GETPAR ("txfont", "d", &txfont);
  1076. X    GETPAR ("txprec", "d", &txprec);
  1077. X    GETPAR ("txovly", "d", &txovly);
  1078. X    default_txfont = txfont;
  1079. X    default_txprec = txprec;
  1080. X    default_txovly = txovly;
  1081. X
  1082. X    if (GETPAR ("erase", "s", string))
  1083. X    {
  1084. X    if ((string[0] == 'n') || (string[0] == 'N'))
  1085. X        erase = NO;
  1086. X    else
  1087. X    if ((string[0] == 'o') || (string[0] == 'O'))
  1088. X        erase = FORCE_INITIAL;
  1089. X    else
  1090. X    if ((string[0] == 'l') || (string[0] == 'L'))
  1091. X        erase = DO_LITERALS;
  1092. X    else
  1093. X        erase = FORCE_INITIAL | DO_LITERALS;
  1094. X    }
  1095. X
  1096. X    xcenter = 0;
  1097. X    ycenter = 0;
  1098. X    xcenterflag = NO;
  1099. X    ycenterflag = NO;
  1100. X    if (GETPAR ("xcenter", "f", &ftemp))
  1101. X    {
  1102. X    xcenterflag = YES;
  1103. X    xcenter = ROUND (ftemp * RPERIN);
  1104. X    }
  1105. X    if (GETPAR ("ycenter", "f", &ftemp))
  1106. X    {
  1107. X    ycenterflag = YES;
  1108. X    ycenter = ROUND (ftemp * RPERIN);
  1109. X    }
  1110. X
  1111. X    if ((stringptr = getenv ("PATTERNMULT")) != NULL)
  1112. X    {
  1113. X    sscanf (stringptr, "%f", &patternmult);
  1114. X    }
  1115. X    GETPAR ("patternmult", "f", &patternmult);
  1116. X
  1117. X    GETPAR ("interact", "s", interact);
  1118. X    GETPAR ("pause", "d", &epause);
  1119. X
  1120. X    if (interact[0] != '\0')
  1121. X    {
  1122. X    epause = 0;        /* interact makes it own sort of pausing */
  1123. X    endpause = NO;
  1124. X    }
  1125. X
  1126. X    /*
  1127. X     * Find the default style 
  1128. X     */
  1129. X    stringptr = NULL;
  1130. X    if (GETPAR ("style", "s", string))
  1131. X    stringptr = string;
  1132. X    else
  1133. X    stringptr = getenv ("PLOTSTYLE");
  1134. X    if (stringptr != NULL)
  1135. X    {
  1136. X    if ((stringptr[0] == 'r') || (stringptr[0] == 'R') ||
  1137. X        (stringptr[0] == 'm') || (stringptr[0] == 'M'))
  1138. X        default_style = ROTATED;
  1139. X    else
  1140. X    if ((stringptr[0] == 'o') || (stringptr[0] == 'O'))
  1141. X        default_style = OLD;
  1142. X    else
  1143. X    if ((stringptr[0] == 'a') || (stringptr[0] == 'A'))
  1144. X        default_style = ABSOLUTE;
  1145. X    else
  1146. X        default_style = STANDARD;
  1147. X    }
  1148. X
  1149. X/*
  1150. X * Options changeable between calls to dovplot
  1151. X * (By calling reset_parameters or reset())
  1152. X * Dovplot calls reset every time it starts. It only calls
  1153. X * reset_parameters the first time.
  1154. X *
  1155. X * Things in this category:
  1156. X * user_*
  1157. X * fatmult_orig, fatbase
  1158. X */
  1159. X
  1160. X    if ((stringptr = getenv ("FATMULT")) != NULL)
  1161. X    {
  1162. X    sscanf (stringptr, "%f", &fatmult);
  1163. X    }
  1164. X    GETPAR ("fatmult", "f", &fatmult);
  1165. X    fatmult_orig = fatmult;
  1166. X
  1167. X    user_rotate = 0;
  1168. X    GETPAR ("rotate", "d", &user_rotate);
  1169. X
  1170. X    user_txscale = 1.0;
  1171. X    user_mkscale = 1.0;
  1172. X    user_dashscale = 1.0;
  1173. X    GETPAR ("txscale", "f", &user_txscale);
  1174. X    GETPAR ("mkscale", "f", &user_mkscale);
  1175. X    GETPAR ("dashscale", "f", &user_dashscale);
  1176. X
  1177. X    user_scale = 1.0;
  1178. X    user_xscale = 1.0;
  1179. X    user_yscale = 1.0;
  1180. X    GETPAR ("scale", "f", &user_scale);
  1181. X    GETPAR ("xscale", "f", &user_xscale);
  1182. X    GETPAR ("yscale", "f", &user_yscale);
  1183. X
  1184. X    user_size = size;
  1185. X    if (GETPAR ("size", "s", string))
  1186. X    {
  1187. X    if ((string[0] == 'a') || (string[0] == 'A'))
  1188. X        user_size = ABSOLUTE;
  1189. X    else
  1190. X        user_size = RELATIVE;
  1191. X    }
  1192. X
  1193. X    user_hshift = 0.;
  1194. X    GETPAR ("hshift xshift", "f", &user_hshift);
  1195. X    user_vshift = 0.;
  1196. X    GETPAR ("vshift yshift", "f", &user_vshift);
  1197. X
  1198. X    user_xwmax_flag = GETPAR ("xwmax", "f", &user_xwmax);
  1199. X    user_ywmax_flag = GETPAR ("ywmax", "f", &user_ywmax);
  1200. X    user_xwmin_flag = GETPAR ("xwmin", "f", &user_xwmin);
  1201. X    user_ywmin_flag = GETPAR ("ywmin", "f", &user_ywmin);
  1202. X
  1203. X    GETPAR ("fat", "d", &fatbase);
  1204. X
  1205. X
  1206. X
  1207. X/*
  1208. X *  These parameters can simply be changed at any time with no
  1209. X *  need for re-initialization of anything else:
  1210. X *
  1211. X *  shade, wantras
  1212. X *
  1213. X */
  1214. X
  1215. X}
  1216. X
  1217. init_colors ()
  1218. X{
  1219. int             ii;
  1220. X
  1221. X    /*
  1222. X     * Set up the default color table 
  1223. X     */
  1224. X
  1225. X/*
  1226. X * First 7 colors are assumed to map to the standard 7 pen colors
  1227. X * on ALL devices, even those with no settable colors!
  1228. X */
  1229. X    for (ii = 0; ii < 8; ii++)
  1230. X    {
  1231. X    color_set[ii][STATUS] = SET;
  1232. X    color_set[ii][_RED] = MAX_GUN * ((ii & 2) / 2);
  1233. X    color_set[ii][_GREEN] = MAX_GUN * ((ii & 4) / 4);
  1234. X    color_set[ii][_BLUE] = MAX_GUN * ((ii & 1) / 1);
  1235. X    color_set[ii][_GREY] = greycorr ((int) ((MAX_GUN * ii) / 7));
  1236. X    }
  1237. X
  1238. X    if (mono)
  1239. X    {
  1240. X    /* Monochrome devices are assumed to have no settable colors */
  1241. X    num_col = 0;
  1242. X    }
  1243. X
  1244. X    num_col_8 = (num_col > 8) ? num_col : 8;
  1245. X
  1246. X    if (mono)
  1247. X    {
  1248. X    color_set[0][MAP] = 0;
  1249. X    for (ii = 1; ii <= MAX_COL; ii++)
  1250. X    {
  1251. X        color_set[ii][MAP] = 7;
  1252. X    }
  1253. X    for (ii = num_col_8; ii < 256; ii++)
  1254. X    {
  1255. X        color_set[ii][_GREY] = color_set[((ii - 8) % 7) + 1][_GREY];
  1256. X    }
  1257. X    /* Put a grey scale in the upper half of the color table */
  1258. X    for (ii = 256; ii <= MAX_COL; ii++)
  1259. X    {
  1260. X        color_set[ii][_GREY] = greycorr (ii - 256);
  1261. X    }
  1262. X    }
  1263. X    else
  1264. X    {
  1265. X    /*
  1266. X     * Unmapped colors shouldn't be mapped; ie, they map to themselves 
  1267. X     */
  1268. X    for (ii = 0; ii < num_col_8; ii++)
  1269. X    {
  1270. X        color_set[ii][MAP] = ii;
  1271. X    }
  1272. X    /*
  1273. X     * Colors outside the range of this terminal map cyclically back into
  1274. X     * colors 1 through 7 
  1275. X     */
  1276. X    for (ii = num_col_8; ii <= MAX_COL; ii++)
  1277. X    {
  1278. X        color_set[ii][MAP] = ((ii - 8) % 7) + 1;
  1279. X    }
  1280. X    }
  1281. X}
  1282. X
  1283. setstyle (new_style)
  1284. X    int             new_style;
  1285. X{
  1286. X    /*
  1287. X     * Check to see if the style has changed 
  1288. X     */
  1289. X    if (new_style == style)
  1290. X    return;
  1291. X
  1292. X    style = new_style;
  1293. X    reset_parameters ();
  1294. X}
  1295. X
  1296. reset_parameters ()
  1297. X{
  1298. float           inches;    /* scaling base for y axis */
  1299. float           screenheight, screenwidth;    /* true size of the screen */
  1300. int             ix, iy;
  1301. X
  1302. X    xorigin = 0;
  1303. X    yorigin = 0;
  1304. X
  1305. X    rotate = default_rotate;
  1306. X    rotate += user_rotate;
  1307. X
  1308. X    txscale = user_txscale;
  1309. X    mkscale = user_mkscale;
  1310. X    dashscale = user_dashscale;
  1311. X
  1312. X    scale = user_scale;
  1313. X    xscale = user_xscale;
  1314. X    yscale = user_yscale;
  1315. X
  1316. X    fatmult = fatmult_orig;
  1317. X
  1318. X    size = user_size;
  1319. X
  1320. X    switch (style)
  1321. X    {
  1322. X/*
  1323. X * The old standard on the machine erebus.
  1324. X * Pretty much dead now. Still useful for some old programs nobody's
  1325. X * wanted to update.
  1326. X */
  1327. X    case OLD:
  1328. X    txscale /= 3.;
  1329. X    fatmult /= 3.;
  1330. X    scale *= 3.;
  1331. X    inches = STANDARD_HEIGHT;
  1332. X    break;
  1333. X/*
  1334. X * The old standard on the machine mazama. A useful coordinate system
  1335. X * for geological sorts of plots. 
  1336. X * The Y axis goes the long way, across the screen, which is the device's
  1337. X * horizontal axis.
  1338. X */
  1339. X    case ROTATED:
  1340. X    rotate += 90;
  1341. X    inches = ROTATED_HEIGHT;
  1342. X    break;
  1343. X    case ABSOLUTE:
  1344. X    size = ABSOLUTE;
  1345. X    case STANDARD:
  1346. X    default:
  1347. X    inches = STANDARD_HEIGHT;
  1348. X    break;
  1349. X    }
  1350. X
  1351. X    if (rotate >= 0)
  1352. X    rotate = rotate % 360;
  1353. X    else
  1354. X    rotate = ((rotate % 360) + 360) % 360;
  1355. X
  1356. X    mxx = cos (2. * 3.14159 * rotate / 360.);
  1357. X    myy = cos (2. * 3.14159 * rotate / 360.);
  1358. X    mxy = sin (2. * 3.14159 * rotate / 360.);
  1359. X    myx = -sin (2. * 3.14159 * rotate / 360.);
  1360. X
  1361. X    if (size == ABSOLUTE)
  1362. X    {
  1363. X    vdevscale = pixels_per_inch / (float) (RPERIN * aspect_ratio);
  1364. X    hdevscale = pixels_per_inch / (float) RPERIN;
  1365. X    }
  1366. X    else
  1367. X    {
  1368. X    /*
  1369. X     * Fit the inches x inches unit square into a displayable box with
  1370. X     * aspect ratio SCREEN_RATIO 
  1371. X     */
  1372. X    screenwidth = (dev_xmax - dev_xmin) * pixels_per_inch;
  1373. X    screenheight =
  1374. X     (dev_ymax - dev_ymin) * pixels_per_inch * aspect_ratio;
  1375. X    if ((screenheight / screenwidth) > SCREEN_RATIO)
  1376. X    {
  1377. X        vdevscale = (SCREEN_RATIO * ((dev_xmax - dev_xmin) / aspect_ratio)) /
  1378. X         (inches * RPERIN);
  1379. X        hdevscale = vdevscale * aspect_ratio;
  1380. X    }
  1381. X    else
  1382. X    {
  1383. X        vdevscale = (dev_ymax - dev_ymin) / (inches * RPERIN);
  1384. X        hdevscale = vdevscale * aspect_ratio;
  1385. X    }
  1386. X    }
  1387. X
  1388. X    hshift = default_hshift;
  1389. X    vshift = default_vshift;
  1390. X
  1391. X    if (style == ROTATED)
  1392. X    {
  1393. X    vshift += dev_ymax - dev_ymin;
  1394. X    }
  1395. X
  1396. X    yscale *= scale;
  1397. X    xscale *= scale;
  1398. X    mkscale *= scale;
  1399. X
  1400. X/*
  1401. X * Set up fatness multiplication factor
  1402. X */
  1403. X    fatmult *= scale * hdevscale * RPERIN / FATPERIN;
  1404. X
  1405. X    /*
  1406. X     * The point (xcenter,ycenter) in vplot coordinates is to be centered in
  1407. X     * the screen. 
  1408. X     */
  1409. X    if (xcenterflag || ycenterflag)
  1410. X    {
  1411. X    vptodevxy (xcenter, ycenter, &ix, &iy);
  1412. X    if (xcenterflag)
  1413. X    {
  1414. X        hshift += (dev_xmax + dev_xmin) / 2 - ix;
  1415. X    }
  1416. X    if (ycenterflag)
  1417. X    {
  1418. X        vshift += (dev_ymax + dev_ymin) / 2 - iy;
  1419. X    }
  1420. X    }
  1421. X
  1422. X    hshift += user_hshift * pixels_per_inch;
  1423. X    vshift += user_vshift * pixels_per_inch / aspect_ratio;
  1424. X
  1425. X/* plot window parameters defaulted */
  1426. X/* to maximum size */
  1427. X
  1428. X    devtovpw (dev_xmin, dev_ymin, dev_xmax, dev_ymax,
  1429. X          &xWmin, &yWmin, &xWmax, &yWmax);
  1430. X
  1431. X    if (user_xwmax_flag)
  1432. X    xWmax = ROUND (user_xwmax * RPERIN);
  1433. X    if (user_ywmax_flag)
  1434. X    yWmax = ROUND (user_ywmax * RPERIN);
  1435. X    if (user_xwmin_flag)
  1436. X    xWmin = ROUND (user_xwmin * RPERIN);
  1437. X    if (user_ywmin_flag)
  1438. X    yWmin = ROUND (user_ywmin * RPERIN);
  1439. X
  1440. X    vptodevw (xWmin, yWmin, xWmax, yWmax, &xWmin, &yWmin, &xWmax, &yWmax);
  1441. X
  1442. X    wlimit (dev_xmin, dev_xmax, &xWmin, &xWmax);
  1443. X    wlimit (dev_ymin, dev_ymax, &yWmin, &yWmax);
  1444. X
  1445. X    xwmax = xWmax;        /* plot window parameters defaulted */
  1446. X    xwmin = xWmin;        /* to maximum size          */
  1447. X    ywmax = yWmax;
  1448. X    ywmin = yWmin;
  1449. X    reset_windows ();
  1450. X}
  1451. X
  1452. add_a_cor (filename, xcor, ycor)
  1453. X    char           *filename;
  1454. X    int             xcor, ycor;
  1455. X{
  1456. static int      first_time = YES;
  1457. static FILE    *outfp;
  1458. X
  1459. X    if (first_time == YES)
  1460. X    {
  1461. X    outfp = fopen (filename, "w");
  1462. X    if (outfp == NULL)
  1463. X    {
  1464. X        ERR (FATAL, name, "Can't open interact output file %s!", filename);
  1465. X    }
  1466. X    first_time = NO;
  1467. X    }
  1468. X    fprintf (outfp, "%f\t%f\n", (float) xcor / RPERIN, (float) ycor / RPERIN);
  1469. X}
  1470. X
  1471. wlimit (min, max, xmin, xmax)
  1472. X    int             min, max;
  1473. X    int            *xmin, *xmax;
  1474. X{
  1475. X    if (*xmin < min)
  1476. X    *xmin = min;
  1477. X
  1478. X    if (*xmax > max)
  1479. X    *xmax = max;
  1480. X}
  1481. X
  1482. END_OF_FILE
  1483. # end of 'Vplot_Kernel/filters/init_vplot.c'
  1484. fi
  1485. echo shar: End of archive 19 \(of 24\).
  1486. cp /dev/null ark19isdone
  1487. MISSING=""
  1488. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ; do
  1489.     if test ! -f ark${I}isdone ; then
  1490.     MISSING="${MISSING} ${I}"
  1491.     fi
  1492. done
  1493. if test "${MISSING}" = "" ; then
  1494.     echo You have unpacked all 24 archives.
  1495.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1496. else
  1497.     echo You still need to unpack the following archives:
  1498.     echo "        " ${MISSING}
  1499. fi
  1500. ##  End of shell archive.
  1501. exit 0
  1502.