[BACK]Return to gnugraph.trm CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / term

Annotation of OpenXM_contrib/gnuplot/term/gnugraph.trm, Revision 1.1.1.3

1.1       maekawa     1: /*
1.1.1.3 ! ohara       2:  * $Id: gnugraph.trm,v 1.8.2.2 2000/05/07 16:39:49 lhecking Exp $
1.1       maekawa     3:  */
                      4:
                      5: /* GNUPLOT -- gnugraph.trm */
                      6:
                      7: /*[
                      8:  * Copyright 1993, 1998
                      9:  *
                     10:  * Permission to use, copy, and distribute this software and its
                     11:  * documentation for any purpose with or without fee is hereby granted,
                     12:  * provided that the above copyright notice appear in all copies and
                     13:  * that both that copyright notice and this permission notice appear
                     14:  * in supporting documentation.
                     15:  *
                     16:  * Permission to modify the software is granted, but not the right to
                     17:  * distribute the complete modified source code.  Modifications are to
                     18:  * be distributed as patches to the released version.  Permission to
                     19:  * distribute binaries produced by compiling modified sources is granted,
                     20:  * provided you
                     21:  *   1. distribute the corresponding source modifications from the
                     22:  *    released version in the form of a patch file along with the binaries,
                     23:  *   2. add special version identification to distinguish your version
                     24:  *    in addition to the base release version number,
                     25:  *   3. provide your name and address as the primary contact for the
                     26:  *    support of your modified version, and
                     27:  *   4. retain our contact information in regard to use of the base
                     28:  *    software.
                     29:  * Permission to distribute the released version of the source code along
                     30:  * with corresponding source modifications in the form of a patch file is
                     31:  * granted with same provisions 2 through 4 for binary distributions.
                     32:  *
                     33:  * This software is provided "as is" without express or implied warranty
                     34:  * to the extent permitted by applicable law.
                     35: ]*/
                     36:
                     37: /*
                     38:  * This file is included by ../term.c.
                     39:  *
                     40:  * This terminal driver supports:
                     41:  *  GNU plot(5) graphics language
                     42:  *
                     43:  * AUTHORS
                     44:  *  Tony Richardson from the unixplot.trm by Colin Kelley, Thomas Williams,
                     45:  *  and Russell Lang and from post.trm by Russell Lang.
                     46:  *
                     47:  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
                     48:  */
                     49:
                     50: /*
                     51:  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
                     52:  */
                     53:
                     54: /*
                     55:  * This version of the 'unixplot' driver produces device independent
                     56:  * output.  I've chosen parameter values so that the PostScript output
                     57:  * produced by plot2ps is 5" x 3".  You can use the 'set size' command
                     58:  * to get output up to 8.25" x 8.25", i.e. size values larger than
                     59:  * 1 are okay.
                     60:  */
                     61:
                     62: /*
                     63: Unixplot library writes to stdout.  A fix was put in place by
                     64: ..!arizona!naucse!jdc to let set term and set output redirect
                     65: stdout.  All other terminals write to gpoutfile.
                     66: */
                     67:
                     68: /* This is a device independent format, so the output should look
                     69:  * look "reasonable" on any output device.  I set things up there so
                     70:  * that the output of plot2ps is 5" x 3" (standard GNUPLOT size).
                     71:  * You can use GNUPLOT's size command to obtain plots to almost the
                     72:  * 8.25" x 8.25" limit.
                     73:  */
                     74:
                     75: #include "driver.h"
1.1.1.2   maekawa    76:
1.1       maekawa    77: #ifdef TERM_REGISTER
                     78: register_term(unixplot)
                     79: #endif
                     80:
                     81: #ifdef TERM_PROTO
                     82: TERM_PUBLIC void UP_options __PROTO((void));
                     83: TERM_PUBLIC void UP_init __PROTO((void));
                     84: TERM_PUBLIC void UP_graphics __PROTO((void));
                     85: TERM_PUBLIC void UP_text __PROTO((void));
                     86: TERM_PUBLIC void UP_linetype __PROTO((int linetype));
                     87: TERM_PUBLIC void UP_move __PROTO((unsigned int x, unsigned int y));
                     88: TERM_PUBLIC void UP_vector __PROTO((unsigned int x, unsigned int y));
                     89: TERM_PUBLIC void UP_put_text __PROTO((unsigned int x, unsigned int y, char str[]));
                     90: TERM_PUBLIC int UP_text_angle __PROTO((int ang));
                     91: TERM_PUBLIC int UP_justify_text __PROTO((enum JUSTIFY mode));
                     92: TERM_PUBLIC void UP_reset __PROTO((void));
                     93: #define UP_XMAX 19859
                     94: #define UP_YMAX 11565
                     95: /* UP_VCHAR = ((UP_FONTSIZE*UP_YMAX)/(UP_YINCHES*72))
                     96:             = UP_FONTSIZE*UP_VFONTSC
                     97:    UP_HCHAR = ((UP_FONTSIZE/2)*UP_XMAX)/(UP_XINCHES*72))
                     98:             = UP_FONTSIZE*UP_HFONTSC
                     99: */
                    100:
                    101: #define UP_VFONTSC  53.5
                    102: #define UP_VCHAR    535                /* 10 * VFONTSC */
                    103: #define UP_HFONTSC  27.6
                    104: #define UP_HCHAR    276                /* 10 * HFONTSC */
                    105:
                    106: #define UP_VTIC (UP_YMAX/80)
                    107: #define UP_HTIC (UP_XMAX/80)
                    108: #endif /* TERM_PROTO */
                    109:
                    110: #ifndef TERM_PROTO_ONLY
                    111: #ifdef TERM_BODY
                    112:
1.1.1.3 ! ohara     113: #define DEFAULT_GNUGRAPHFONT "Courier"
        !           114:
        !           115: /* Name of font */
        !           116: char up_font[MAX_ID_LEN+1] = DEFAULT_GNUGRAPHFONT;
1.1       maekawa   117: int up_fontsize = 10;
                    118:
                    119: /* plot2ps produces a 8.25" x 8.25" square. */
                    120: #define UP_SCREENX 32768
                    121: #define UP_SCREENY 32768
                    122: #define UP_SCRXINC 8.25
                    123: #define UP_SCRYINC 8.25
                    124:
                    125: /* We want a 5" x 3" graph by default. */
                    126: #define UP_XINCHES 5
                    127: #define UP_YINCHES 3
                    128: /* UP_XMAX = (UP_SCREENX*UP_XINCHES)/UP_SCRXINC
                    129:    UP_YMAX (UP_SCREENY*UP_YINCHES)/UP_SCRYINC */
                    130:
                    131: #define UP_XLAST (UP_XMAX - 1)
                    132: #define UP_YLAST (UP_YMAX - 1)
                    133:
                    134: /* These offsets center plot2ps output in the middle of the page.  The
                    135:  * amount of resizing that can be done is limited. */
                    136: /*
                    137:  * #define UP_XOFF 6454
                    138:  * #define UP_YOFF 10601
                    139:  */
                    140:
                    141: /* These offsets give a 1" offset from the lower left corner.  This
                    142:  * gives a greater range of permissible values in GNUPLOT's size
                    143:  * command. */
                    144: #define UP_XOFF 3972
                    145: #define UP_YOFF 3972
                    146:
                    147: enum JUSTIFY up_justify = LEFT;
                    148:
1.1.1.3 ! ohara     149: #define ROTATE(angle) pl_textangle(90*angle)
1.1       maekawa   150:
                    151: /* We don't include plot.h from plotutils because of
                    152:  * the name clash with ../plot.h.
                    153:  */
1.1.1.3 ! ohara     154: extern int pl_openpl __PROTO((void));
        !           155: extern int pl_space __PROTO((int, int, int, int));
        !           156: extern int pl_fontname __PROTO((const char *));
        !           157: extern int pl_fontsize __PROTO((int));
        !           158: extern int pl_erase __PROTO((void));
        !           159: extern int pl_linemod __PROTO((const char *));
        !           160: extern int pl_move __PROTO((int, int));
        !           161: extern int pl_cont __PROTO((int, int));
        !           162: extern int pl_alabel __PROTO((int, int, const char *));
        !           163: extern int pl_textangle __PROTO((int));
        !           164: extern int pl_closepl __PROTO((void));
        !           165: /* T.Walter added: */
        !           166: extern int pl_parampl __PROTO((const char *parameter, void *value));
        !           167: extern int pl_newpl __PROTO((const char *type, FILE *infile, FILE *outfile, FILE *errfile));
        !           168: extern int pl_selectpl __PROTO((int handle));
        !           169: extern int pl_deletepl __PROTO((int handle));
        !           170: extern double pl_ffontsize __PROTO((double size));
1.1       maekawa   171:
                    172: TERM_PUBLIC void UP_options()
                    173: {
                    174:     if (!END_OF_COMMAND) {
                    175:        if (almost_equals(c_token, "d$efault")) {
                    176:            strcpy(up_font, "Courier");
                    177:            up_fontsize = 10;
                    178:            term->v_char = (unsigned int) (up_fontsize * UP_VFONTSC);
                    179:            term->h_char = (unsigned int) (up_fontsize * UP_HFONTSC);
                    180:            c_token++;
                    181:        }
                    182:     }
                    183:     if (!END_OF_COMMAND && isstring(c_token)) {
                    184:        quote_str(up_font, c_token, MAX_ID_LEN);
                    185:        c_token++;
                    186:     }
                    187:     if (!END_OF_COMMAND) {
                    188:        /* We have font size specified */
                    189:        struct value a;
                    190:        up_fontsize = (int) real(const_express(&a));
                    191:        term->v_char = (unsigned int) (up_fontsize * UP_VFONTSC);
                    192:        term->h_char = (unsigned int) (up_fontsize * UP_HFONTSC);
                    193:     }
                    194:     sprintf(term_options, "\"%s\" %d", up_font, up_fontsize);
                    195: }
                    196:
                    197: TERM_PUBLIC void UP_init()
                    198: {
1.1.1.3 ! ohara     199:     pl_openpl();
        !           200:     pl_space(0, 0, UP_SCREENX - 1, UP_SCREENY - 1);
        !           201:     pl_fontname(up_font);
1.1       maekawa   202: /*
                    203: #ifdef GNU_PLOTUTILS
                    204:        fontsize((int)((up_fontsize / 72.0 * 8.0) * (UP_SCREENY-1)));
                    205: #else
                    206: */
1.1.1.3 ! ohara     207:     pl_fontsize(up_fontsize);
1.1       maekawa   208: /*
                    209: #endif
                    210: */
                    211: }
                    212:
                    213:
                    214: TERM_PUBLIC void UP_graphics()
                    215: {
1.1.1.3 ! ohara     216:     pl_erase();
1.1       maekawa   217: }
                    218:
                    219:
                    220: TERM_PUBLIC void UP_text()
                    221: {
                    222:     /* Flush here so that output will be complete. */
                    223:     fflush(stdout);
                    224: }
                    225:
                    226:
                    227: TERM_PUBLIC void UP_linetype(linetype)
                    228: int linetype;
                    229: {
                    230:     static char *lt[2+5] = { "solid", "longdashed", "solid", "dotted",
                    231:                             "shortdashed", "dotdashed", "longdashed"};
                    232:
                    233:     if (linetype >= 5)
                    234:        linetype %= 5;
1.1.1.3 ! ohara     235:     pl_linemod(lt[linetype + 2]);
1.1       maekawa   236: }
                    237:
                    238:
                    239: TERM_PUBLIC void UP_move(x, y)
                    240: unsigned int x, y;
                    241: {
1.1.1.3 ! ohara     242:     pl_move(x + UP_XOFF, y + UP_YOFF);
1.1       maekawa   243: }
                    244:
                    245:
                    246: TERM_PUBLIC void UP_vector(x, y)
                    247: unsigned int x, y;
                    248: {
1.1.1.3 ! ohara     249:     pl_cont(x + UP_XOFF, y + UP_YOFF);
1.1       maekawa   250: }
                    251:
                    252:
                    253: TERM_PUBLIC void UP_put_text(x, y, str)
                    254: unsigned int x, y;
                    255: char str[];
                    256: {
                    257:     UP_move(x, y);             /* Don't adjust x and y! It's done in UP_move. */
                    258:     switch (up_justify) {
                    259:     case LEFT:
1.1.1.3 ! ohara     260:        pl_alabel('l', 'c', str);
1.1       maekawa   261:        break;
                    262:     case CENTRE:
1.1.1.3 ! ohara     263:        pl_alabel('c', 'c', str);
1.1       maekawa   264:        break;
                    265:     case RIGHT:
1.1.1.3 ! ohara     266:        pl_alabel('r', 'c', str);
1.1       maekawa   267:        break;
                    268:     }
                    269:
                    270: }
                    271:
                    272: TERM_PUBLIC int UP_text_angle(ang)
                    273: int ang;
                    274: {
                    275:     ROTATE(ang);
                    276:     return TRUE;
                    277: }
                    278:
                    279: TERM_PUBLIC int UP_justify_text(mode)
                    280: enum JUSTIFY mode;
                    281: {
                    282:     up_justify = mode;
                    283:     return TRUE;
                    284: }
                    285:
                    286: TERM_PUBLIC void UP_reset()
                    287: {
1.1.1.3 ! ohara     288:     pl_closepl();
1.1       maekawa   289: }
                    290:
                    291: #endif /* TERM_BODY */
                    292:
                    293: #ifdef TERM_TABLE
                    294:
                    295: TERM_TABLE_START(unixplot_driver)
                    296:     "unixplot", "GNU plot(1) format [\042fontname\042 font_size]",
                    297:     UP_XMAX, UP_YMAX, UP_VCHAR, UP_HCHAR,
                    298:     UP_VTIC, UP_HTIC, UP_options, UP_init, UP_reset,
                    299:     UP_text, null_scale, UP_graphics, UP_move, UP_vector,
                    300:     UP_linetype, UP_put_text, UP_text_angle,
                    301:     UP_justify_text, line_and_point, do_arrow, set_font_null
                    302: TERM_TABLE_END(unixplot_driver)
                    303:
                    304: #undef LAST_TERM
                    305: #define LAST_TERM unixplot_driver
                    306:
                    307: #endif /* TERM_TABLE */
                    308: #endif /* TERM_PROTO_ONLY */
                    309:
                    310: #ifdef TERM_HELP
                    311: START_HELP(unixplot)
                    312: "1 unixplot",
                    313: "?commands set terminal unixplot",
                    314: "?set terminal unixplot",
                    315: "?set term unixplot",
                    316: "?terminal unixplot",
                    317: "?term unixplot",
                    318: "?unixplot",
                    319: " The `unixplot` driver produces device-independent output in the GNU plot",
                    320: " graphics language.  The default size of the PostScript results generated by",
                    321: " \"plot2ps\" is 5 x 3 inches; this can be increased up to about 8.25 x 8.25 by",
                    322: " `set size`.",
                    323: "",
                    324: " Syntax:",
                    325: "       set terminal unixplot {\"<fontname>\"} {<fontsize>}",
                    326: "",
                    327: " which defaults to 10-point \"Courier\".",
                    328: "",
                    329: " There is a non-GNU version of the `unixplot` driver which cannot be compiled",
                    330: " unless this version is left out."
                    331: END_HELP(unixplot)
                    332: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>