/*
 *  Copyright (c) 1992, Mats Bergstr"om.
 *  See 'TGIFCRTL.license' for complete information.
 *
 *  TGIFCRTL-TEST - Program to test the TGIFCRTL.
 *      Draws an x^2 curve from x=0 to 5 with markers every 0.2, axes, 
 *      ticks, and grid-net.
 *
 *  Author: Mats Bergst"om, University of Lund, Sweden.
 *          (Mats.Bergstrom@kosufy.lu.se)
 *
 */

#include "TGIFCRTL.h"


int
main()
{
    TR_FILE *f;

    double x[100];
    double y[100];
    double rx, ry;
    int i;
    char s[80];

    f = TRopen("test.tgif");        /* Open an output file.                 */

    TRset_htrans(f,  30.0, 100.0,   /* Define transformation between        */
                      0.0,  5.0 );      /* user-space and the paper.        */
    TRset_vtrans(f, 150.0,  30.0,       /* First 2 values are paper coord's */
                      0.0, 30.0 );      /* and second 2 are the correspond'n*/
                                        /* user-space coordinates.          */

    TRgroup_begin(f);               /* Group level 1, ALL OBJECTS.          */

    TRgroup_begin(f);               /* Group level 2, Coordinate axes.      */

/* Draw X-axis */
    TRset_open_line(f,              /* Set graphics state for POLYLINE & ARC */
        4,LIS_SOLID,LIT_STRAIGHT);      /* Line: width, dash, style         */
    TRset_open_arrow(f,             /* Set graphics state for POLYLINE & ARC */
        ART_RIGHT,ARS_SCALE, 8, 1 );    /* Arrow: style, state, width,height*/
    TRline(f,                       /* Draw a sinle line segment.           */
        -0.1,  0.0,                     /* From.                            */
         6.0,  0.0 );                   /* To.                              */


    TRset_open_arrow(f,
        ART_PLAIN,ARS_SCALE, 8, 1 );

    TRset_text_text(f,              /* Set graphics state for text objects  */
        TXF_TIMES, TXS_ROMAN,           /* Text: style, type                */
            TXA_CENTER, TXP_24, TXR_0);     /* align, points, rotate.       */

    for ( rx = 0.0; rx < 5.1; rx += 1.0 ) {
        TRline(f, rx, 0.0, rx, -0.5 );
        sprintf(s,"%3.1f",rx);
        TRtext(f,                   /* Draw text.                           */
            rx, -1.0,                   /* position.                        */
            s );                        /* string.                          */
    };


/* Y-AXIS */
    TRset_open_arrow(f,             /* Set graphics state for POLYLINE & ARC */
        ART_RIGHT,ARS_SCALE, 8, 1 );    /* Arrow: style, state, width,height*/
    TRline(f,
        0.0, -0.5,  0.0, 30.0 );

    TRset_open_arrow(f,
        ART_PLAIN,ARS_SCALE, 8, 1 );
    TRset_text_text(f,
        TXF_TIMES, TXS_ROMAN,
            TXA_CENTER, TXP_24, TXR_270);

    for ( ry = 0.0; ry < 30.0; ry += 5.0 ) {
        TRline(f, 0.0, ry, -0.1, ry );
        sprintf(s,"%3.1f",ry);
        TRtext(f, -0.5, ry, s );
    };

    TRgroup_end(f);                     /* coordinate axes END.             */

/* GRID-NET */
    TRgroup_begin(f);                   /* Group level 2, Grid-net.         */

    TRset_open_line(f,
        1,LIS_DOTDOT,LIT_STRAIGHT);

    for ( rx = 1.0; rx < 5.1; rx += 1.0 ) {
        ry = rx*rx;
        TRline(f, rx, 0.0, rx, 27.0 );
        TRline(f, 0.0, ry, 5.5, ry );
    };

    TRgroup_end(f);                     /* Grid-net END.                    */


/* CURVE */
    for ( rx = 0.0, i=0;                /* Create the curve.                */
            rx < 5.0; 
            rx += 0.2, i++ ) {
        x[i] = rx;
        y[i] = rx*rx;
    };
    TRset_open_line(f,
        2,LIS_SOLID,LIT_STRAIGHT);
    TRpolyline(f,                       /* Draw the curve.                  */
        i,                                  /* No of verteces               */
        x, y );                             /* The coordinates.             */

/* MARKERS (use default graphics state for markers) */
    TRpolymark(f,                       /* Draw markers.                    */
        i,                                  /* No of points.                */
        x, y);

    TRgroup_end(f);                     /* ALL OBJECTS END.                 */

    TRclose(f);                         /* Close the output file.           */
}
