# include # include # include # include # include # include # include "dislin.h" int main ( int argc, char *argv[] ); void timestamp ( ); /******************************************************************************/ int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: humps_plot_dislin() makes a line plot of y=humps(x). Licensing: This code is distributed under the MIT license. Modified: 28 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_plot = "humps_plot_dislin.png"; int i; int m; float *x; float xmax; float xmin; float xstep; float *y; float ymax; float ymin; float ystep; timestamp ( ); printf ( "\n" ); printf ( "humps_plot_dislin():\n" ); printf ( " C version:\n" ); printf ( " dislin() plots y=humps(x).\n" ); /* Set M, the number of data pairs. */ m = 101; /* Set the X, Y data. */ xmin = 0.0; xmax = 2.0; x = ( float * ) malloc ( m * sizeof ( float ) ); y = ( float * ) malloc ( m * sizeof ( float ) ); ymin = DBL_MAX; ymax = - DBL_MAX; for ( i = 0; i < m; i++ ) { x[i] = ( ( m - 1 - i ) * xmin + ( i ) * xmax ) / ( m - 1 ); y[i] = 1.0 / ( pow ( x[i] - 0.3, 2 ) + 0.01 ) + 1.0 / ( pow ( x[i] - 0.9, 2 ) + 0.04 ) - 6.0; ymin = fmin ( ymin, y[i] ); ymax = fmax ( ymax, y[i] ); } /* 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 ( "x", "X" ); name ( "y=humps(x)", "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. */ xstep = ( xmax - xmin ) / 10; ystep = ( ymax - ymin ) / 10; graf ( xmin, xmax, xmin, xstep, ymin, ymax, ymin, ystep ); /* BEGIN LEVEL 2 COMMANDS. */ /* Define the title. */ titlin ( "y=humps(x)", 1 ); 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 "blue"; */ color ( "blue" ); /* Specify linewidth. */ linwid ( 15 ); /* Draw the curve. */ curve ( x, y, m ); /* 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 ( "humps_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 }