# include # include # include # include # include # include "dislin.h" int main ( int argc, char *argv[] ); void timestamp ( ); /******************************************************************************/ int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: bulgaria_plot_dislin() makes a line plot of the Bulgarian population over time. Licensing: This code is distributed under the MIT license. Modified: 27 September 2024 Author: John Burkardt Reference: Helmut Michels, The Data Plotting Software DISLIN - version 10.4, Shaker Media GmbH, January 2010, ISBN13: 978-3-86858-517-9. */ { char *filename_data = "bulgaria_data.txt"; char *filename_plot = "bulgaria_plot_dislin.png"; FILE *input; int i; int m; float r; char *result; char str[80]; float *x; float xmax; float xmin; float xstep; float *y; float ymax; float ymin; float ystep; timestamp ( ); printf ( "\n" ); printf ( "bulgaria_plot_dislin():\n" ); printf ( " C version:\n" ); printf ( " dislin() plots Bulgarian population over time.\n" ); /* Get M, the number of data pairs. */ input = fopen ( filename_data, "r" ); m = 0; for ( ; ; ) { result = fgets ( str, 80, input ); if ( ! result ) { break; } m = m + 1; } fclose ( input ); /* Get the X, Y data. */ x = ( float * ) malloc ( m * sizeof ( float ) ); y = ( float * ) malloc ( m * sizeof ( float ) ); input = fopen ( filename_data, "r" ); for ( i = 0; i < m; i++ ) { fscanf ( input, "%g %g", &x[i], &y[i] ); } fclose ( input ); /* Specify the format of the output file. */ metafl ( "png" ); /* Indicate that new data overwrites old data. */ filmod ( "delete" ); /* Specify the name of the output graphics file. */ setfil ( filename_plot ); /* Choose the page size and orientation. 'USA' is 2160 plot units wide and 2790 plot units high. 'L' requests LANDSCAPE orientation. */ setpag ( "usal" ); /* For PNG output, reverse the default black background to white. */ scrmod ( "reverse" ); /* Open DISLIN. */ disini ( ); /* Plot a border around the page. */ pagera ( ); /* Use the SIMPLX font. */ simplx ( ); /* Set the axis origin 500 plot units to the right, and 1900 plot units DOWN. */ axspos ( 500, 1900 ); /* Define the X and Y sizes of the axis system in plot units. */ axslen ( 2190, 1260 ); /* Label the X and Y axes. */ name ( "Year", "X" ); name ( "Population", "Y" ); /* Don't use any digits after the decimal points on X and Y tick marks. */ labdig ( -1, "X" ); labdig ( -1, "Y" ); /* Relate the physical coordinates to the axes, and specify tick marks. */ xmin = x[0]; xmax = x[0]; for ( i = 1; i < m; i++ ) { xmin = fmin ( xmin, x[i] ); xmax = fmax ( xmax, x[i] ); } xstep = ( xmax - xmin ) / 10; ymin = 0.0; ymax = 10000000.0; ystep = ( ymax - ymin ) / 10; graf ( xmin, xmax, xmin, xstep, ymin, ymax, ymin, ystep ); /* BEGIN LEVEL 2 COMMANDS. */ /* Define the title. */ titlin ( "Bulgarian Population Over Time", 1 ); titlin ( "1887-2022", 2 ); title ( ); /* Add a grid, with one grid line for every tick mark in the X and Y axes. */ grid ( 1, 1 ); /* Set the drawing color to "red"; */ color ( "red" ); /* Use linewidth 3 */ linwid ( 15 ); /* Draw the curve. */ curve ( x, y, m ); /* Set color to "blue". */ color ( "blue" ); /* At every data point, draw a circle of radius r. */ r = 0.50; for ( i = 0; i < m; i++ ) { rlcirc ( x[i], y[i], r ); } /* End this graph. */ endgrf ( ); /* RETURN FROM LEVEL 2 TO LEVEL 1. */ printf ( " Graphics saved as '%s'\n", filename_plot ); /* Close DISLIN. */ disfin ( ); /* Free memory. */ free ( x ); free ( y ); /* Terminate. */ printf ( "\n" ); printf ( "bulgaria_plot_dislin():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 17 June 2014 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }