Sample GraphiC for Fortran Code

 

Sample GraphiC for Fortran Code:

 


Below is a copy of a simple Fortran program which generates an array of 300 data points and uses GraphiC to create a linear plot.

View the equivalent ‘C’ GraphiC program.

View the equivalent Visual Basic GraphiC program.

View the program output.

*****************************************************************************
*    (c) 1984-1993 by Scientific Endeavors Corporation.
*    All rights reserved.

*    This program plots a single curve on a set of 2-D linear axes. Except for
*    color(), sympick(), and grid(), this simple example program uses only
*    the minimum calls needed to produce a GraphiC plot.
****************************************************************************/


****************************************************************************
*    Main subroutine MUST be called Application
****************************************************************************/
    SUBROUTINE APPLICATION
    USE GRAPHIC

    INTEGER*4 i, nxdiv, nydiv, npts
    PARAMETER( NPTS=301)
    CHARACTER FONT_ID*10, FONT_CHAR*1
    REAL*4 x(npts), y(npts)

    CALL bgnplot(1, 'g', "sample.tkf")  ! Parameters: 1 - draw plot on screen
                                        !      'g' - graphics mode
                                        !"sample.tkf" - .TKF file name
    CALL startplot(WHITE)
    CALL metricunits(0)                        ! Ensure scaling in inch units
    FONT_CHAR = CHAR(CODE1)  ! CODE1 through CODE4 are pre-defined byte chars
    CALL font(1, "simplex.fnt", CODE1 )              ! Loads your chosen font
    CALL page(9.0, 6.884)                                ! Sets the page size
                              ! This is the same aspect ratio as 8191 by 6266
    CALL area2d(7.6, 5.5)                         ! Sets the area of the plot
    DO i = 1, npts                                            ! Generate data
        y(i) = .3 * i
        x(i) = (y(i) * y(i)) / 2.
    END DO

    CALL color(BLACK)                  ! Axis names and heading will be black
    FONT_ID = FONT_CHAR // "X-Axis"
    CALL xname(FONT_ID)
    CALL yname("Y-Axis")
    CALL heading("SAMPLE PLOT")
    CALL grid(9)                ! Draws grid through tick marks, 9 - fine dot
    nxdiv = 5                        ! Sets the desired # of x-axis divisions
    nydiv = 6                        ! Sets the desired # of y-axis divisions
    CALL color(GREEN)                                 ! Green axes and labels
    CALL scales(nxdiv, nydiv, x, y, npts)         ! Draws and scales the axes
    CALL color(RED)                                               ! Red curve
    CALL sympick(12)                                  ! Filled circle symbols
    CALL curve(x, y, npts, 10)

    CALL DATEIT(CODE1)
    I = endplot()       ! Finishes plot and waits for instructions to exit or
                          ! draw next plot. Resets file pointers and defaults
    CALL stopplot            ! Close files, return to text mode, exit program

    RETURN
    END

Leave a Reply

Your email address will not be published. Required fields are marked *