From: <ai...@us...> - 2009-10-21 22:07:28
|
Revision: 10543 http://plplot.svn.sourceforge.net/plplot/?rev=10543&view=rev Author: airwin Date: 2009-10-21 22:07:16 +0000 (Wed, 21 Oct 2009) Log Message: ----------- Style all C source in examples. Modified Paths: -------------- trunk/examples/c/ext-cairo-test.c trunk/examples/c/extXdrawable_demo.c trunk/examples/c/plcdemos.h trunk/examples/c/plplotcanvas_animation.c trunk/examples/c/plplotcanvas_demo.c trunk/examples/c/test_plend.c trunk/examples/c/tutor.c trunk/examples/c/x01c.c trunk/examples/c/x02c.c trunk/examples/c/x03c.c trunk/examples/c/x04c.c trunk/examples/c/x05c.c trunk/examples/c/x06c.c trunk/examples/c/x07c.c trunk/examples/c/x08c.c trunk/examples/c/x09c.c trunk/examples/c/x10c.c trunk/examples/c/x11c.c trunk/examples/c/x12c.c trunk/examples/c/x13c.c trunk/examples/c/x14c.c trunk/examples/c/x15c.c trunk/examples/c/x16c.c trunk/examples/c/x17c.c trunk/examples/c/x18c.c trunk/examples/c/x19c.c trunk/examples/c/x20c.c trunk/examples/c/x21c.c trunk/examples/c/x22c.c trunk/examples/c/x23c.c trunk/examples/c/x24c.c trunk/examples/c/x25c.c trunk/examples/c/x26c.c trunk/examples/c/x27c.c trunk/examples/c/x28c.c trunk/examples/c/x29c.c trunk/examples/c/x30c.c trunk/examples/c/x31c.c trunk/examples/c/x32c.c trunk/examples/tk/xtk01.c trunk/examples/tk/xtk02.c trunk/examples/tk/xtk04.c trunk/scripts/style_source.sh Modified: trunk/examples/c/ext-cairo-test.c =================================================================== --- trunk/examples/c/ext-cairo-test.c 2009-10-21 21:29:41 UTC (rev 10542) +++ trunk/examples/c/ext-cairo-test.c 2009-10-21 22:07:16 UTC (rev 10543) @@ -5,23 +5,23 @@ #include <plplot.h> -int main(int argc, char *argv[]) +int main( int argc, char *argv[] ) { - cairo_surface_t *cairoSurface; - cairo_t *cairoContext; + cairo_surface_t *cairoSurface; + cairo_t *cairoContext; - cairoSurface = cairo_ps_surface_create("test.ps", 720, 540); - cairoContext = cairo_create(cairoSurface); + cairoSurface = cairo_ps_surface_create( "test.ps", 720, 540 ); + cairoContext = cairo_create( cairoSurface ); - plsdev("extcairo"); - plinit(); - pl_cmd(PLESC_DEVINIT, cairoContext); - plenv(0.0, 1.0, 0.0, 1.0, 1, 0); - pllab("x", "y", "title"); - plend(); + plsdev( "extcairo" ); + plinit(); + pl_cmd( PLESC_DEVINIT, cairoContext ); + plenv( 0.0, 1.0, 0.0, 1.0, 1, 0 ); + pllab( "x", "y", "title" ); + plend(); - cairo_destroy(cairoContext); - cairo_surface_destroy(cairoSurface); - exit(0); + cairo_destroy( cairoContext ); + cairo_surface_destroy( cairoSurface ); + exit( 0 ); } Modified: trunk/examples/c/extXdrawable_demo.c =================================================================== --- trunk/examples/c/extXdrawable_demo.c 2009-10-21 21:29:41 UTC (rev 10542) +++ trunk/examples/c/extXdrawable_demo.c 2009-10-21 22:07:16 UTC (rev 10543) @@ -1,30 +1,30 @@ /* - A simple GTK application demonstrating the use of the X Drawable - functionality of plplot's xcairo driver. - - Copyright (C) 2008 Jonathan Woithe <jw...@ph...> - - This file is part of PLplot. - - PLplot is free software; you can redistribute it and/or modify - it under the terms of the GNU General Library Public License as published - by the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - PLplot is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with PLplot; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - + * A simple GTK application demonstrating the use of the X Drawable + * functionality of plplot's xcairo driver. + * + * Copyright (C) 2008 Jonathan Woithe <jw...@ph...> + * + * This file is part of PLplot. + * + * PLplot is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Library Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * PLplot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with PLplot; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * */ /* Set to 0 to draw direct to an X Window, 1 to draw via a pixmap */ -#define TO_PIXMAP 1 - +#define TO_PIXMAP 1 + #include <stdio.h> #include <plplot.h> #include <gtk/gtk.h> @@ -34,167 +34,170 @@ /* Main menu structure */ static GtkItemFactoryEntry menu_items[] = { - { "/_File", NULL, NULL, 0, "<Branch>" }, - { "/File/_Quit", "<control>Q", gtk_main_quit, 0, NULL }, + { "/_File", NULL, NULL, 0, "<Branch>" }, + { "/File/_Quit", "<control>Q", gtk_main_quit, 0, NULL }, }; -#define APP_INITIAL_WIDTH 320 -#define APP_INITIAL_HEIGHT 200 +#define APP_INITIAL_WIDTH 320 +#define APP_INITIAL_HEIGHT 200 -typedef struct App { - GtkWidget *rootwindow; - GtkWidget *plotwindow; - GdkPixmap *plotwindow_pixmap; +typedef struct App +{ + GtkWidget *rootwindow; + GtkWidget *plotwindow; + GdkPixmap *plotwindow_pixmap; } App; App app; /* ======================================================================== */ -void setup_plot_drawable(App *app) { +void setup_plot_drawable( App *app ) +{ + struct + { + Display *display; + Drawable drawable; + } xinfo; -struct { - Display *display; - Drawable drawable; -} xinfo; + PLFLT x[3] = { 1, 3, 4 }; + PLFLT y[3] = { 3, 2, 5 }; -PLFLT x[3] = {1,3,4}; -PLFLT y[3] = {3,2,5}; + plsdev( "xcairo" ); + plsetopt( "drvopt", "external_drawable" ); + plinit(); - plsdev("xcairo"); - plsetopt("drvopt", "external_drawable"); - plinit(); - - #if TO_PIXMAP==1 + #if TO_PIXMAP == 1 /* Here we set up to draw to a pixmap */ - xinfo.display = GDK_PIXMAP_XDISPLAY(app->plotwindow_pixmap); - xinfo.drawable = GDK_PIXMAP_XID(app->plotwindow_pixmap); + xinfo.display = GDK_PIXMAP_XDISPLAY( app->plotwindow_pixmap ); + xinfo.drawable = GDK_PIXMAP_XID( app->plotwindow_pixmap ); #else /* Alternatively, we can do direct to a visible X Window */ - xinfo.display = GDK_WINDOW_XDISPLAY(app->plotwindow->window); - xinfo.drawable = GDK_WINDOW_XID(app->plotwindow->window); + xinfo.display = GDK_WINDOW_XDISPLAY( app->plotwindow->window ); + xinfo.drawable = GDK_WINDOW_XID( app->plotwindow->window ); #endif - pl_cmd(PLESC_DEVINIT, &xinfo); - plenv(0,5,0,5,0,0); + pl_cmd( PLESC_DEVINIT, &xinfo ); + plenv( 0, 5, 0, 5, 0, 0 ); - plline(3, x, y); - plend(); + plline( 3, x, y ); + plend(); } /* ======================================================================== */ -static gint ev_plotwindow_conf(GtkWidget *widget, GdkEventConfigure *ev, gpointer *data) { - - #if TO_PIXMAP==1 +static gint ev_plotwindow_conf( GtkWidget *widget, GdkEventConfigure *ev, gpointer *data ) +{ + #if TO_PIXMAP == 1 /* Allocate pixmap */ - if (app.plotwindow_pixmap) - gdk_pixmap_unref(app.plotwindow_pixmap); - app.plotwindow_pixmap = gdk_pixmap_new(widget->window, - widget->allocation.width,widget->allocation.height,-1); + if ( app.plotwindow_pixmap ) + gdk_pixmap_unref( app.plotwindow_pixmap ); + app.plotwindow_pixmap = gdk_pixmap_new( widget->window, + widget->allocation.width, widget->allocation.height, -1 ); /* Clear the pixmap to a sensible background colour */ - gdk_draw_rectangle(app.plotwindow_pixmap, - widget->style->black_gc, TRUE, 0, 0, - widget->allocation.width, widget->allocation.height); + gdk_draw_rectangle( app.plotwindow_pixmap, + widget->style->black_gc, TRUE, 0, 0, + widget->allocation.width, widget->allocation.height ); /* If drawing to a pixmap we can do a plot from the conf handler since * the pixmap is now realised (the window widget isn't). */ - setup_plot_drawable(&app); + setup_plot_drawable( &app ); #endif - return(TRUE); + return ( TRUE ); } -static gint ev_plotwindow_expose(GtkWidget *widget, GdkEventExpose *ev, gpointer *data) { - - #if TO_PIXMAP==1 - /* Dump the cached plot (created in the conf handler) to the window from +static gint ev_plotwindow_expose( GtkWidget *widget, GdkEventExpose *ev, gpointer *data ) +{ + #if TO_PIXMAP == 1 + /* Dump the cached plot (created in the conf handler) to the window from * the pixmap. We don't need to recreate the plot on each expose. */ - gdk_draw_pixmap(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - app.plotwindow_pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y, - ev->area.width, ev->area.height); + gdk_draw_pixmap( widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE( widget )], + app.plotwindow_pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y, + ev->area.width, ev->area.height ); #else - /* If drawing direct to an X Window, ensure GTK's double buffering - * is turned off for that window or else the plot will be overridden - * when the buffer is dumped to the screen. - */ - setup_plot_drawable(&app); + /* If drawing direct to an X Window, ensure GTK's double buffering + * is turned off for that window or else the plot will be overridden + * when the buffer is dumped to the screen. + */ + setup_plot_drawable( &app ); #endif - return(TRUE); + return ( TRUE ); } /* ======================================================================== */ -void init_app(App *app) { +void init_app( App *app ) +{ + GtkWidget *menubar; + GtkItemFactory *item_factory; + GtkAccelGroup *accel_group = gtk_accel_group_new(); + signed int nitems = sizeof ( menu_items ) / sizeof ( menu_items[0] ); -GtkWidget *menubar; -GtkItemFactory *item_factory; -GtkAccelGroup *accel_group = gtk_accel_group_new(); -signed int nitems = sizeof(menu_items) / sizeof(menu_items[0]); + GtkWidget *vbox, *hbox; -GtkWidget *vbox, *hbox; + /* Create the top-level root window */ + app->rootwindow = gtk_window_new( GTK_WINDOW_TOPLEVEL ); + gtk_signal_connect( GTK_OBJECT( app->rootwindow ), "delete_event", gtk_main_quit, + NULL ); - /* Create the top-level root window */ - app->rootwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_signal_connect(GTK_OBJECT(app->rootwindow), "delete_event", gtk_main_quit, - NULL); + /* A toplevel box to hold things */ + vbox = gtk_vbox_new( FALSE, 0 ); + gtk_container_add( GTK_CONTAINER( app->rootwindow ), vbox ); - /* A toplevel box to hold things */ - vbox = gtk_vbox_new(FALSE,0); - gtk_container_add(GTK_CONTAINER(app->rootwindow), vbox); + /* Construct the main menu structure */ + item_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "<main>", accel_group ); + gtk_item_factory_create_items( item_factory, nitems, menu_items, NULL ); + gtk_window_add_accel_group( GTK_WINDOW( app->rootwindow ), accel_group ); + menubar = gtk_item_factory_get_widget( item_factory, "<main>" ); + gtk_box_pack_start( GTK_BOX( vbox ), menubar, FALSE, FALSE, 0 ); + gtk_widget_show( menubar ); - /* Construct the main menu structure */ - item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR,"<main>",accel_group); - gtk_item_factory_create_items(item_factory, nitems, menu_items, NULL); - gtk_window_add_accel_group(GTK_WINDOW(app->rootwindow), accel_group); - menubar = gtk_item_factory_get_widget(item_factory,"<main>"); - gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0); - gtk_widget_show(menubar); + /* Fiddle with boxes to effect an indent from the edges of the root window */ + hbox = gtk_hbox_new( FALSE, 0 ); + gtk_box_pack_start( GTK_BOX( vbox ), hbox, TRUE, TRUE, 10 ); + vbox = gtk_vbox_new( FALSE, 10 ); + gtk_box_pack_start( GTK_BOX( hbox ), vbox, TRUE, TRUE, 10 ); - /* Fiddle with boxes to effect an indent from the edges of the root window */ - hbox = gtk_hbox_new(FALSE,0); - gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 10); - vbox = gtk_vbox_new(FALSE,10); - gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 10); + /* Add an area to plot into */ + app->plotwindow = gtk_drawing_area_new(); + app->plotwindow_pixmap = NULL; - /* Add an area to plot into */ - app->plotwindow = gtk_drawing_area_new(); - app->plotwindow_pixmap = NULL; - - #if TO_PIXMAP!=1 + #if TO_PIXMAP != 1 /* Turn off double buffering if we are plotting direct to the plotwindow * in setup_plot_drawable(). */ - GTK_WIDGET_UNSET_FLAGS(app->plotwindow, GTK_DOUBLE_BUFFERED); + GTK_WIDGET_UNSET_FLAGS( app->plotwindow, GTK_DOUBLE_BUFFERED ); #endif - /* By experiment, 3x3 seems to be the smallest size plplot can cope with. - * Here we utilise the side effect that gtk_widget_set_size_request() - * effectively sets the minimum size of the widget. - */ - gtk_widget_set_size_request(app->plotwindow,3,3); - gtk_box_pack_start(GTK_BOX(vbox), app->plotwindow, TRUE, TRUE, 0); + /* By experiment, 3x3 seems to be the smallest size plplot can cope with. + * Here we utilise the side effect that gtk_widget_set_size_request() + * effectively sets the minimum size of the widget. + */ + gtk_widget_set_size_request( app->plotwindow, 3, 3 ); + gtk_box_pack_start( GTK_BOX( vbox ), app->plotwindow, TRUE, TRUE, 0 ); - // Set the initial size of the application - gtk_window_set_default_size(GTK_WINDOW(app->rootwindow), APP_INITIAL_WIDTH,APP_INITIAL_HEIGHT); + // Set the initial size of the application + gtk_window_set_default_size( GTK_WINDOW( app->rootwindow ), APP_INITIAL_WIDTH, APP_INITIAL_HEIGHT ); - g_signal_connect(G_OBJECT(app->plotwindow), "configure_event", - G_CALLBACK(ev_plotwindow_conf), NULL); - g_signal_connect(G_OBJECT(app->plotwindow), "expose_event", - G_CALLBACK(ev_plotwindow_expose), NULL); + g_signal_connect( G_OBJECT( app->plotwindow ), "configure_event", + G_CALLBACK( ev_plotwindow_conf ), NULL ); + g_signal_connect( G_OBJECT( app->plotwindow ), "expose_event", + G_CALLBACK( ev_plotwindow_expose ), NULL ); - gtk_widget_show_all(app->rootwindow); + gtk_widget_show_all( app->rootwindow ); } /* ======================================================================== */ -int main(int argc, char *argv[]) { - gtk_init(&argc, &argv); - init_app(&app); - gtk_main(); - return 0; +int main( int argc, char *argv[] ) +{ + gtk_init( &argc, &argv ); + init_app( &app ); + gtk_main(); + return 0; } /* ======================================================================== */ Modified: trunk/examples/c/plcdemos.h =================================================================== --- trunk/examples/c/plcdemos.h 2009-10-21 21:29:41 UTC (rev 10542) +++ trunk/examples/c/plcdemos.h 2009-10-21 22:07:16 UTC (rev 10543) @@ -1,9 +1,9 @@ /* $Id$ + * + * Everything needed by the C demo programs. + * Created to avoid junking up plplot.h with this stuff. + */ - Everything needed by the C demo programs. - Created to avoid junking up plplot.h with this stuff. -*/ - #ifndef __PLCDEMOS_H__ #define __PLCDEMOS_H__ @@ -18,55 +18,55 @@ /* Actually M_PI seems to be more widely used so we deprecate PI. */ #ifndef PI -#define PI 3.1415926535897932384 +#define PI 3.1415926535897932384 #endif #ifndef M_PI -#define M_PI 3.1415926535897932384 +#define M_PI 3.1415926535897932384 #endif /* various utility macros */ #ifndef MAX -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#define MAX( a, b ) ((( a ) > ( b )) ? ( a ) : ( b )) #endif #ifndef MIN -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define MIN( a, b ) ((( a ) < ( b )) ? ( a ) : ( b )) #endif #ifndef ROUND -#define ROUND(a) (PLINT)((a)<0. ? ((a)-.5) : ((a)+.5)) +#define ROUND( a ) (PLINT) (( a ) < 0. ? (( a ) - .5 ) : (( a ) + .5 )) #endif /* Declarations for save string functions */ #ifdef PL_HAVE_SNPRINTF - /* In case only _snprintf is declared (as for Visual C++ and - Borland compiler toolset) we redefine the function names */ +/* In case only _snprintf is declared (as for Visual C++ and + * Borland compiler toolset) we redefine the function names */ #ifdef _PL_HAVE_SNPRINTF - #define snprintf _snprintf - #define snscanf _snscanf + #define snprintf _snprintf + #define snscanf _snscanf #endif /* _PL_HAVE_SNPRINTF */ #else /* !PL_HAVE_SNPRINTF */ - /* declare dummy functions which just call the unsafe - functions ignoring the size of the string */ - int plsnprintf( char *buffer, int n, const char *format, ... ); - int plsnscanf( const char *buffer, int n, const char *format, ... ); - #define snprintf plsnprintf - #define snscanf plsnscanf +/* declare dummy functions which just call the unsafe + * functions ignoring the size of the string */ +int plsnprintf( char *buffer, int n, const char *format, ... ); +int plsnscanf( const char *buffer, int n, const char *format, ... ); + #define snprintf plsnprintf + #define snscanf plsnscanf #endif /* PL_HAVE_SNPRINTF */ /* Add in missing isnan definition if required */ -#if defined(PL__HAVE_ISNAN) -# define isnan _isnan -# if defined(_MSC_VER) +#if defined ( PL__HAVE_ISNAN ) +# define isnan _isnan +# if defined ( _MSC_VER ) # include <float.h> # endif #endif -#if !defined(PL_HAVE_ISNAN) -# define isnan(x) ((x) != (x)) +#if !defined ( PL_HAVE_ISNAN ) +# define isnan( x ) (( x ) != ( x )) #endif -#endif /* __PLCDEMOS_H__ */ +#endif /* __PLCDEMOS_H__ */ Modified: trunk/examples/c/plplotcanvas_animation.c =================================================================== --- trunk/examples/c/plplotcanvas_animation.c 2009-10-21 21:29:41 UTC (rev 10542) +++ trunk/examples/c/plplotcanvas_animation.c 2009-10-21 22:07:16 UTC (rev 10543) @@ -33,12 +33,12 @@ * * * DESCRIPTION - * + * * This program demonstrates the use of the plplot canvas widget with gtk. * Two graphs are draw in a window. When the Execute button is pressed, * two different waves progress through the graph in real time. Plotting * to the two graphs is handled in two different threads. - * + * */ #include <glib.h> @@ -50,244 +50,252 @@ /* The number of time steps */ -#define STEPS 300 +#define STEPS 300 /* The number of points and period for the first wave */ -#define NPTS 100 -#define PERIOD 30 +#define NPTS 100 +#define PERIOD 30 /* The width and height for each plot widget */ -#define WIDTH 800 -#define HEIGHT 300 +#define WIDTH 800 +#define HEIGHT 300 /* Run the plots in different threads */ -GThread* thread0=NULL; -GThread* thread1=NULL; -typedef struct { - PlplotCanvas* canvas; - char* title; +GThread* thread0 = NULL; +GThread* thread1 = NULL; +typedef struct +{ + PlplotCanvas* canvas; + char * title; } ThreadData; -ThreadData data0,data1; -gint Nthreads = 0; /* Count the number of threads */ +ThreadData data0, data1; +gint Nthreads = 0; /* Count the number of threads */ /* Create two different canvases */ -PlplotCanvas *canvas0=NULL; -PlplotCanvas *canvas1=NULL; +PlplotCanvas *canvas0 = NULL; +PlplotCanvas *canvas1 = NULL; /* Create the x and y array */ static PLFLT x[NPTS], y[NPTS]; /* Lock on the gtkstate so that we don't try to plot after gtk_main_quit */ -#define GTKSTATE_CONTINUE (TRUE) -#define GTKSTATE_QUIT (FALSE) -G_LOCK_DEFINE_STATIC(gtkstate); +#define GTKSTATE_CONTINUE ( TRUE ) +#define GTKSTATE_QUIT (FALSE) +G_LOCK_DEFINE_STATIC( gtkstate ); static volatile int gtkstate = GTKSTATE_CONTINUE; /* setup_plot - preparation for plotting an animation to a canvas */ -void setup_plot(PlplotCanvas *canvas, char* title) +void setup_plot( PlplotCanvas *canvas, char* title ) { - /* Set up the viewport and window */ - plplot_canvas_vsta(canvas); - plplot_canvas_wind(canvas,x[0],x[NPTS-1],-2.,2.); + /* Set up the viewport and window */ + plplot_canvas_vsta( canvas ); + plplot_canvas_wind( canvas, x[0], x[NPTS - 1], -2., 2. ); - /* Set the pen width */ - plplot_canvas_wid(canvas,2); + /* Set the pen width */ + plplot_canvas_wid( canvas, 2 ); - /* The axes should be persistent, so that they don't have to be - * replotted every time (which would slow down the animation) - */ - plplot_canvas_use_persistence(canvas,TRUE); + /* The axes should be persistent, so that they don't have to be + * replotted every time (which would slow down the animation) + */ + plplot_canvas_use_persistence( canvas, TRUE ); - /* Draw the axes */ - plplot_canvas_col0(canvas,15); - plplot_canvas_box(canvas,"bcnst",0.,0,"bcnstv",0.,0); - plplot_canvas_lab(canvas,"(x)","(y)",title); + /* Draw the axes */ + plplot_canvas_col0( canvas, 15 ); + plplot_canvas_box( canvas, "bcnst", 0., 0, "bcnstv", 0., 0 ); + plplot_canvas_lab( canvas, "(x)", "(y)", title ); - /* Prepare for plotting */ - plplot_canvas_col0(canvas,plplot_canvas_get_stream_number(canvas)+8); + /* Prepare for plotting */ + plplot_canvas_col0( canvas, plplot_canvas_get_stream_number( canvas ) + 8 ); - /* The animated data should not be persistent */ - plplot_canvas_use_persistence(canvas,FALSE); + /* The animated data should not be persistent */ + plplot_canvas_use_persistence( canvas, FALSE ); } /* plot - draws a plot on a canvas */ -void plot(PlplotCanvas *canvas,gdouble offset,char* title) +void plot( PlplotCanvas *canvas, gdouble offset, char* title ) { - int i; - guint Nstream; - gdouble xmin,xmax,ymin,ymax; + int i; + guint Nstream; + gdouble xmin, xmax, ymin, ymax; - /* Get the stream number */ - Nstream = plplot_canvas_get_stream_number(canvas); + /* Get the stream number */ + Nstream = plplot_canvas_get_stream_number( canvas ); - /* Generate the sinusoid */ - for (i = 0; i < NPTS; i++) - y[i] = sin(2.*3.14*(x[i]+offset*(Nstream+1))/PERIOD/(PLFLT)(Nstream+1)); + /* Generate the sinusoid */ + for ( i = 0; i < NPTS; i++ ) + y[i] = sin( 2. * 3.14 * ( x[i] + offset * ( Nstream + 1 )) / PERIOD / (PLFLT) ( Nstream + 1 )); - /* Draw the line */ - plplot_canvas_line(canvas,NPTS, x, y); + /* Draw the line */ + plplot_canvas_line( canvas, NPTS, x, y ); - /* Advance the page to finalize the plot */ - plplot_canvas_adv(canvas,0); + /* Advance the page to finalize the plot */ + plplot_canvas_adv( canvas, 0 ); } /* Delete event callback */ -gint delete_event_local( GtkWidget *widget,GdkEvent *event,gpointer data ) { - return FALSE; +gint delete_event_local( GtkWidget *widget, GdkEvent *event, gpointer data ) +{ + return FALSE; } /* Destroy event calback */ -void destroy_local(GtkWidget *widget,gpointer data) { - G_LOCK(gtkstate); - gtkstate=GTKSTATE_QUIT; - G_UNLOCK(gtkstate); +void destroy_local( GtkWidget *widget, gpointer data ) +{ + G_LOCK( gtkstate ); + gtkstate = GTKSTATE_QUIT; + G_UNLOCK( gtkstate ); - gtk_main_quit (); + gtk_main_quit(); } -GThreadFunc plot_thread(ThreadData* data) { - int i; +GThreadFunc plot_thread( ThreadData* data ) +{ + int i; - Nthreads++; + Nthreads++; - /* Draw STEPS plots in succession */ - for(i=0;i<STEPS;i++) { - gdk_threads_enter(); + /* Draw STEPS plots in succession */ + for ( i = 0; i < STEPS; i++ ) + { + gdk_threads_enter(); - /* Lock the current gtk state */ - G_LOCK(gtkstate); - - /* Check to make sure gtk hasn't quit */ - if(gtkstate == GTKSTATE_QUIT){ - G_UNLOCK(gtkstate); - gdk_threads_leave(); - g_thread_exit(NULL); + /* Lock the current gtk state */ + G_LOCK( gtkstate ); + + /* Check to make sure gtk hasn't quit */ + if ( gtkstate == GTKSTATE_QUIT ) + { + G_UNLOCK( gtkstate ); + gdk_threads_leave(); + g_thread_exit( NULL ); + } + + /* Draw the plot */ + plot( data->canvas, i, data->title ); + + /* Release the lock */ + G_UNLOCK( gtkstate ); + gdk_threads_leave(); } - - /* Draw the plot */ - plot(data->canvas,i,data->title); - /* Release the lock */ - G_UNLOCK(gtkstate); - gdk_threads_leave(); - } - - Nthreads--; - g_thread_exit(NULL); + Nthreads--; + g_thread_exit( NULL ); } /* Start threads callback from execute button */ -void start_threads(GtkWidget *widget,gpointer data) +void start_threads( GtkWidget *widget, gpointer data ) { - GError **gerror; + GError **gerror; - /* Ignore call if threads are currently active */ - if(Nthreads) return; + /* Ignore call if threads are currently active */ + if ( Nthreads ) return; - /* Create the two plotting threads */ - data0.canvas = canvas0; - data0.title = "A phase-progressing wave"; - if((thread0=g_thread_create((GThreadFunc)plot_thread,&data0,TRUE,gerror))\ - ==NULL) { - fprintf(stderr,"Could not create thread"); - return; - } + /* Create the two plotting threads */ + data0.canvas = canvas0; + data0.title = "A phase-progressing wave"; + if (( thread0 = g_thread_create((GThreadFunc) plot_thread, &data0, TRUE, gerror )) \ + == NULL ) + { + fprintf( stderr, "Could not create thread" ); + return; + } - data1.canvas = canvas1; - data1.title = "Another phase-progressing wave"; - if((thread1=g_thread_create((GThreadFunc)plot_thread,&data1,TRUE,gerror))\ - ==NULL) { - fprintf(stderr,"Could not create thread"); - return; - } + data1.canvas = canvas1; + data1.title = "Another phase-progressing wave"; + if (( thread1 = g_thread_create((GThreadFunc) plot_thread, &data1, TRUE, gerror )) \ + == NULL ) + { + fprintf( stderr, "Could not create thread" ); + return; + } } -int main(int argc,char *argv[] ) +int main( int argc, char *argv[] ) { - int i; + int i; - GtkWidget *window; - GtkWidget *table; + GtkWidget *window; + GtkWidget *table; - GtkFrame *canvas0frame; - GtkFrame *canvas1frame; + GtkFrame *canvas0frame; + GtkFrame *canvas1frame; - GtkButton* button; - GtkBox* buttonbox; + GtkButton * button; + GtkBox * buttonbox; - GtkBox* vbox; + GtkBox * vbox; - /* Parse the options */ - plparseopts(&argc, (const char **) argv, PL_PARSE_FULL); + /* Parse the options */ + plparseopts( &argc, (const char **) argv, PL_PARSE_FULL ); - /* Initialize */ - g_thread_init(NULL); - gdk_threads_init(); - gtk_init(&argc, &argv); - g_type_init(); + /* Initialize */ + g_thread_init( NULL ); + gdk_threads_init(); + gtk_init( &argc, &argv ); + g_type_init(); - /* Initialize the x array */ - for(i=0;i<NPTS;i++) x[i] = (PLFLT)i; + /* Initialize the x array */ + for ( i = 0; i < NPTS; i++ ) x[i] = (PLFLT) i; - /* Create the first canvas, set its size, draw some axes on it, and - * place it in a frame - */ - canvas0 = plplot_canvas_new(TRUE); - plplot_canvas_set_size(canvas0,WIDTH,HEIGHT); - plplot_canvas_adv(canvas0,0); - setup_plot(canvas0,"A phase-progressing wave"); - plplot_canvas_adv(canvas0,0); /* Advance the page to finalize the plot */ - canvas0frame = GTK_FRAME(gtk_frame_new(NULL)); - gtk_frame_set_shadow_type(canvas0frame,GTK_SHADOW_ETCHED_OUT); - gtk_container_add(GTK_CONTAINER(canvas0frame),GTK_WIDGET(canvas0)); + /* Create the first canvas, set its size, draw some axes on it, and + * place it in a frame + */ + canvas0 = plplot_canvas_new( TRUE ); + plplot_canvas_set_size( canvas0, WIDTH, HEIGHT ); + plplot_canvas_adv( canvas0, 0 ); + setup_plot( canvas0, "A phase-progressing wave" ); + plplot_canvas_adv( canvas0, 0 ); /* Advance the page to finalize the plot */ + canvas0frame = GTK_FRAME( gtk_frame_new( NULL )); + gtk_frame_set_shadow_type( canvas0frame, GTK_SHADOW_ETCHED_OUT ); + gtk_container_add( GTK_CONTAINER( canvas0frame ), GTK_WIDGET( canvas0 )); - /* Create the second canvas, set its size, draw some axes on it, and - * place it in a frame - */ - canvas1 = plplot_canvas_new(TRUE); - plplot_canvas_set_size(canvas1,WIDTH,HEIGHT); - plplot_canvas_adv(canvas1,0); - setup_plot(canvas1,"Another phase-progressing wave"); - plplot_canvas_adv(canvas1,0); /* Advance the page to finalize the plot */ - canvas1frame = GTK_FRAME(gtk_frame_new(NULL)); - gtk_frame_set_shadow_type(canvas1frame,GTK_SHADOW_ETCHED_OUT); - gtk_container_add(GTK_CONTAINER(canvas1frame),GTK_WIDGET(canvas1)); + /* Create the second canvas, set its size, draw some axes on it, and + * place it in a frame + */ + canvas1 = plplot_canvas_new( TRUE ); + plplot_canvas_set_size( canvas1, WIDTH, HEIGHT ); + plplot_canvas_adv( canvas1, 0 ); + setup_plot( canvas1, "Another phase-progressing wave" ); + plplot_canvas_adv( canvas1, 0 ); /* Advance the page to finalize the plot */ + canvas1frame = GTK_FRAME( gtk_frame_new( NULL )); + gtk_frame_set_shadow_type( canvas1frame, GTK_SHADOW_ETCHED_OUT ); + gtk_container_add( GTK_CONTAINER( canvas1frame ), GTK_WIDGET( canvas1 )); - /* Create a button and put it in a box */ - button = GTK_BUTTON(gtk_button_new_from_stock(GTK_STOCK_EXECUTE)); - g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(start_threads), - NULL); - gtk_container_set_border_width(GTK_CONTAINER(button),10); - buttonbox = GTK_BOX(gtk_hbox_new(FALSE,0)); - gtk_box_pack_start(buttonbox,GTK_WIDGET(button),TRUE,FALSE,0); + /* Create a button and put it in a box */ + button = GTK_BUTTON( gtk_button_new_from_stock( GTK_STOCK_EXECUTE )); + g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( start_threads ), + NULL ); + gtk_container_set_border_width( GTK_CONTAINER( button ), 10 ); + buttonbox = GTK_BOX( gtk_hbox_new( FALSE, 0 )); + gtk_box_pack_start( buttonbox, GTK_WIDGET( button ), TRUE, FALSE, 0 ); - /* Create and fill the vbox with the widgets */ - vbox = GTK_BOX(gtk_vbox_new(FALSE,0)); - gtk_box_pack_start(vbox,GTK_WIDGET(canvas0frame),TRUE,FALSE,0); - gtk_box_pack_start(vbox,GTK_WIDGET(canvas1frame),TRUE,FALSE,10); - gtk_box_pack_start(vbox,GTK_WIDGET(buttonbox),TRUE,FALSE,0); + /* Create and fill the vbox with the widgets */ + vbox = GTK_BOX( gtk_vbox_new( FALSE, 0 )); + gtk_box_pack_start( vbox, GTK_WIDGET( canvas0frame ), TRUE, FALSE, 0 ); + gtk_box_pack_start( vbox, GTK_WIDGET( canvas1frame ), TRUE, FALSE, 10 ); + gtk_box_pack_start( vbox, GTK_WIDGET( buttonbox ), TRUE, FALSE, 0 ); - /* Create a new window */ - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - /* Set the border width of the window */ - gtk_container_set_border_width(GTK_CONTAINER(window),10); - - /* Connect the signal handlers to the window decorations */ - g_signal_connect(G_OBJECT(window),"delete_event", - G_CALLBACK(delete_event_local),NULL); - g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(destroy_local),NULL); - - /* Put the vbox into the window */ - gtk_container_add(GTK_CONTAINER(window),GTK_WIDGET(vbox)); - - /* Display everything */ - gtk_widget_show_all(window); - - /* Start the gtk main loop */ - gdk_threads_enter(); - gtk_main (); - gdk_threads_leave(); + /* Create a new window */ + window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); - return 0; + /* Set the border width of the window */ + gtk_container_set_border_width( GTK_CONTAINER( window ), 10 ); + + /* Connect the signal handlers to the window decorations */ + g_signal_connect( G_OBJECT( window ), "delete_event", + G_CALLBACK( delete_event_local ), NULL ); + g_signal_connect( G_OBJECT( window ), "destroy", G_CALLBACK( destroy_local ), NULL ); + + /* Put the vbox into the window */ + gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( vbox )); + + /* Display everything */ + gtk_widget_show_all( window ); + + /* Start the gtk main loop */ + gdk_threads_enter(); + gtk_main(); + gdk_threads_leave(); + + return 0; } Modified: trunk/examples/c/plplotcanvas_demo.c =================================================================== --- trunk/examples/c/plplotcanvas_demo.c 2009-10-21 21:29:41 UTC (rev 10542) +++ trunk/examples/c/plplotcanvas_demo.c 2009-10-21 22:07:16 UTC (rev 10543) @@ -1,6 +1,6 @@ /* * demo.c - Demonstrates the simplest use of the plplot canvas widget with gtk. - * + * * Copyright (C) 2004, 2005 Thomas J. Duck * All rights reserved. * @@ -36,73 +36,74 @@ #include <gtk/gtk.h> /* The width and height of the plplot canvas widget */ -#define WIDTH 1000 /* 500 */ -#define HEIGHT 600 /* 300 */ +#define WIDTH 1000 /* 500 */ +#define HEIGHT 600 /* 300 */ /* Delete event callback */ -gint delete_event_local( GtkWidget *widget,GdkEvent *event,gpointer data ) { - return FALSE; +gint delete_event_local( GtkWidget *widget, GdkEvent *event, gpointer data ) +{ + return FALSE; } /* Destroy event calback */ -void destroy_local(GtkWidget *widget,gpointer data) { - gtk_main_quit (); +void destroy_local( GtkWidget *widget, gpointer data ) +{ + gtk_main_quit(); } -int main(int argc,char *argv[] ) +int main( int argc, char *argv[] ) { + PlplotCanvas* canvas; + GtkWidget *window; - PlplotCanvas* canvas; - GtkWidget *window; + /* Parse the options */ + plparseopts( &argc, (const char **) argv, PL_PARSE_FULL ); - /* Parse the options */ - plparseopts(&argc, (const char **) argv, PL_PARSE_FULL); + /* The data to plot */ + double x[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + double y[11] = { 0, 0.1, 0.4, 0.9, 1.6, 2.6, 3.6, 4.9, 6.4, 8.1, 10 }; - /* The data to plot */ - double x[11] = {0,1,2,3,4,5,6,7,8,9,10}; - double y[11] = {0,0.1,0.4,0.9,1.6,2.6,3.6,4.9,6.4,8.1,10}; + /* Initialize gtk and the glib type system */ + gtk_init( &argc, &argv ); + g_type_init(); - /* Initialize gtk and the glib type system */ - gtk_init(&argc, &argv); - g_type_init(); + /* Create the canvas and set its size; during the creation process, + * the gcw driver is loaded into plplot, and plinit() is invoked. + */ + canvas = plplot_canvas_new( TRUE ); + plplot_canvas_set_size( canvas, WIDTH, HEIGHT ); - /* Create the canvas and set its size; during the creation process, - * the gcw driver is loaded into plplot, and plinit() is invoked. - */ - canvas=plplot_canvas_new(TRUE); - plplot_canvas_set_size(canvas,WIDTH,HEIGHT); + /* Create a new window and stuff the canvas into it */ + window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); + gtk_container_set_border_width( GTK_CONTAINER( window ), 10 ); + gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( canvas )); - /* Create a new window and stuff the canvas into it */ - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_container_set_border_width(GTK_CONTAINER(window),10); - gtk_container_add(GTK_CONTAINER(window),GTK_WIDGET(canvas)); + /* Connect the signal handlers to the window decorations */ + g_signal_connect( G_OBJECT( window ), "delete_event", + G_CALLBACK( delete_event_local ), NULL ); + g_signal_connect( G_OBJECT( window ), "destroy", G_CALLBACK( destroy_local ), NULL ); - /* Connect the signal handlers to the window decorations */ - g_signal_connect(G_OBJECT(window),"delete_event", - G_CALLBACK(delete_event_local),NULL); - g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(destroy_local),NULL); + /* Display everything */ + gtk_widget_show_all( window ); - /* Display everything */ - gtk_widget_show_all(window); + /* Draw on the canvas with Plplot */ + plplot_canvas_adv( canvas, 0 ); /* Advance to first page */ + plplot_canvas_col0( canvas, 15 ); /* Set color to black */ + plplot_canvas_wid( canvas, 2 ); /* Set the pen width */ + plplot_canvas_vsta( canvas ); /* Set the viewport */ + plplot_canvas_wind( canvas, 0., 10., 0., 10. ); /* Set the window */ + plplot_canvas_box( canvas, "bcnst", 0., 0, "bcnstv", 0., 0 ); /* Set the box */ + plplot_canvas_lab( canvas, "x-axis", "y-axis", "A Simple Plot" ); /* Draw some labels */ - /* Draw on the canvas with Plplot */ - plplot_canvas_adv(canvas,0); /* Advance to first page */ - plplot_canvas_col0(canvas,15); /* Set color to black */ - plplot_canvas_wid(canvas,2); /* Set the pen width */ - plplot_canvas_vsta(canvas); /* Set the viewport */ - plplot_canvas_wind(canvas,0.,10.,0.,10.); /* Set the window */ - plplot_canvas_box(canvas,"bcnst",0.,0,"bcnstv",0.,0); /* Set the box */ - plplot_canvas_lab(canvas,"x-axis","y-axis","A Simple Plot"); /* Draw some labels */ + /* Draw the line */ + plplot_canvas_col0( canvas, 1 ); /* Set the pen color */ + plplot_canvas_line( canvas, 11, x, y ); - /* Draw the line */ - plplot_canvas_col0(canvas,1); /* Set the pen color */ - plplot_canvas_line(canvas,11,x,y); + /* Advancing the page finalizes this plot */ + plplot_canvas_adv( canvas, 0 ); - /* Advancing the page finalizes this plot */ - plplot_canvas_adv(canvas,0); - - /* Start the gtk main loop */ - gtk_main(); - return 0; + /* Start the gtk main loop */ + gtk_main(); + return 0; } Modified: trunk/examples/c/test_plend.c =================================================================== --- trunk/examples/c/test_plend.c 2009-10-21 21:29:41 UTC (rev 10542) +++ trunk/examples/c/test_plend.c 2009-10-21 22:07:16 UTC (rev 10543) @@ -1,31 +1,30 @@ /* $Id$ + * + * plend and plend1 testing demo. + */ - plend and plend1 testing demo. -*/ - #include "plcdemos.h" /*--------------------------------------------------------------------------*\ * main * * Demonstrates absolute positioning of graphs on a page. -\*--------------------------------------------------------------------------*/ + \*--------------------------------------------------------------------------*/ int -main(int argc, const char *argv[]) +main( int argc, const char *argv[] ) { - /* Parse and process command line arguments */ - (void) plparseopts(&argc, argv, PL_PARSE_FULL); + (void) plparseopts( &argc, argv, PL_PARSE_FULL ); /* Initialize plplot */ plinit(); - plenv(0., 1., 0., 1., 1, 0); + plenv( 0., 1., 0., 1., 1, 0 ); plend(); plinit(); - plenv(0., 10., 0., 10., 1, 0); + plenv( 0., 10., 0., 10., 1, 0 ); plend(); - exit(0); + exit( 0 ); } Modified: trunk/examples/c/tutor.c =================================================================== --- trunk/examples/c/tutor.c 2009-10-21 21:29:41 UTC (rev 10542) +++ trunk/examples/c/tutor.c 2009-10-21 22:07:16 UTC (rev 10543) @@ -5,7 +5,7 @@ * This program is intended to be used as a template for creating simple * two-dimensional plotting programs which use the PLplot plotting * library. The program was written with an emphasis on trying to clearly - * illustrate how to use the PLplot library functions. + * illustrate how to use the PLplot library functions. * * This program reads data for M lines with N points each from an input * data file and plots them on the same graph using different symbols. It @@ -24,23 +24,23 @@ * * (The first line contains the integer values M and N. The succeeding * N lines contain the x-coordinate and the corresponding y-coordinates - * of each of the M lines.) + * of each of the M lines.) */ #include "plcdemos.h" static int -error(char *str); +error( char *str ); /* * You can select a different set of symbols to use when plotting the - * lines by changing the value of OFFSET. + * lines by changing the value of OFFSET. */ -#define OFFSET 2 +#define OFFSET 2 int -main(int argc, char *argv[]) +main( int argc, char *argv[] ) { /* ============== Begin variable definition section. ============= */ @@ -73,59 +73,63 @@ static char *legend[] = { - "Aardvarks", - "Gnus", - "Llamas", - NULL}; /* Make sure last element is NULL */ + "Aardvarks", + "Gnus", + "Llamas", + NULL + }; /* Make sure last element is NULL */ /* ============== Read in data from input file. ============= */ /* Parse and process command line arguments */ - (void) plparseopts(&argc, argv, PL_PARSE_FULL); + (void) plparseopts( &argc, argv, PL_PARSE_FULL ); /* First prompt the user for the input data file name */ - printf("Enter input data file name. "); - scanf("%s", filename); + printf( "Enter input data file name. " ); + scanf( "%s", filename ); /* and open the file. */ - datafile = fopen(filename, "r"); - if (datafile == NULL) /* error opening input file */ - error("Error opening input file."); + datafile = fopen( filename, "r" ); + if ( datafile == NULL ) /* error opening input file */ + error( "Error opening input file." ); /* Read in values of M and N */ - k = fscanf(datafile, "%d %d", &M, &N); - if (k != 2) /* something's wrong */ - error("Error while reading data file."); + k = fscanf( datafile, "%d %d", &M, &N ); + if ( k != 2 ) /* something's wrong */ + error( "Error while reading data file." ); /* Allocate memory for all the arrays. */ - x = (PLFLT *) malloc(N * sizeof(PLFLT)); - if (x == NULL) - error("Out of memory!"); - y = (PLFLT **) malloc(M * sizeof(PLFLT *)); - if (y == NULL) - error("Out of memory!"); - for (i = 0; i < M; i++) { - y[i] = (PLFLT *) malloc(N * sizeof(PLFLT)); - if (y[i] == NULL) - error("Out of memory!"); + x = (PLFLT *) malloc( N * sizeof ( PLFLT )); + if ( x == NULL ) + error( "Out of memory!" ); + y = (PLFLT **) malloc( M * sizeof ( PLFLT * )); + if ( y == NULL ) + error( "Out of memory!" ); + for ( i = 0; i < M; i++ ) + { + y[i] = (PLFLT *) malloc( N * sizeof ( PLFLT )); + if ( y[i] == NULL ) + error( "Out of memory!" ); } /* Now read in all the data. */ - for (i = 0; i < N; i++) { /* N points */ - k = fscanf(datafile, "%f", &x[i]); - if (k != 1) - error("Error while reading data file."); - for (j = 0; j < M; j++) { /* M lines */ - k = fscanf(datafile, "%f", &y[j][i]); - if (k != 1) - error("Error while reading data file."); - } + for ( i = 0; i < N; i++ ) /* N points */ + { + k = fscanf( datafile, "%f", &x[i] ); + if ( k != 1 ) + error( "Error while reading data file." ); + for ( j = 0; j < M; j++ ) /* M lines */ + { + k = fscanf( datafile, "%f", &y[j][i] ); + if ( k != 1 ) + error( "Error while reading data file." ); + } } /* ============== Graph the data. ============= */ @@ -133,19 +137,19 @@ /* Set graph to portrait orientation. (Default is landscape.) */ /* (Portrait is usually desired for inclusion in TeX documents.) */ - plsori(1); + plsori( 1 ); /* Initialize plplot */ plinit(); -/* +/* * We must call pladv() to advance to the first (and only) subpage. * You might want to use plenv() instead of the pladv(), plvpor(), * plwind() sequence. */ - pladv(0); + pladv( 0 ); /* * Set up the viewport. This is the window into which the data is @@ -158,7 +162,7 @@ * instead. */ - plvpor(0.15, 0.70, 0.5, 0.9); + plvpor( 0.15, 0.70, 0.5, 0.9 ); /* * We now need to define the size of the window in user coordinates. @@ -168,51 +172,54 @@ xmin = xmax = x[0]; ymin = ymax = y[0][0]; - for (i = 0; i < N; i++) { - if (x[i] < xmin) - xmin = x[i]; - if (x[i] > xmax) - xmax = x[i]; - for (j = 0; j < M; j++) { - if (y[j][i] < ymin) - ymin = y[j][i]; - if (y[j][i] > ymax) - ymax = y[j][i]; - } + for ( i = 0; i < N; i++ ) + { + if ( x[i] < xmin ) + xmin = x[i]; + if ( x[i] > xmax ) + xmax = x[i]; + for ( j = 0; j < M; j++ ) + { + if ( y[j][i] < ymin ) + ymin = y[j][i]; + if ( y[j][i] > ymax ) + ymax = y[j][i]; + } } -/* +/* * Now set the size of the window. Leave a small border around the * data. */ - xdiff = (xmax - xmin) / 20.; - ydiff = (ymax - ymin) / 20.; - plwind(xmin - xdiff, xmax + xdiff, ymin - ydiff, ymax + ydiff); + xdiff = ( xmax - xmin ) / 20.; + ydiff = ( ymax - ymin ) / 20.; + plwind( xmin - xdiff, xmax + xdiff, ymin - ydiff, ymax + ydiff ); -/* +/* * Call plbox() to draw the axes (see the PLPLOT manual for * information about the option strings.) */ - plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); + plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 ); -/* +/* * Label the axes and title the graph. The string "#gm" plots the * Greek letter mu, all the Greek letters are available, see the * PLplot manual. */ - pllab("Time (weeks)", "Height (#gmparsecs)", "Specimen Growth Rate"); + pllab( "Time (weeks)", "Height (#gmparsecs)", "Specimen Growth Rate" ); /* * Plot the data. plpoin() draws a symbol at each point. plline() * connects all the points. */ - for (i = 0; i < M; i++) { - plpoin(N, x, y[i], i + OFFSET); - plline(N, x, y[i]); + for ( i = 0; i < M; i++ ) + { + plpoin( N, x, y[i], i + OFFSET ); + plline( N, x, y[i] ); } /* @@ -222,59 +229,62 @@ */ leglen = 0; - for (i = 0; i < M; i++) { - if (legend[i] == NULL) - break; - j = strlen(legend[i]); - if (j > leglen) - leglen = j; + for ( i = 0; i < M; i++ ) + { + if ( legend[i] == NULL ) + break; + j = strlen( legend[i] ); + if ( j > leglen ) + leglen = j; } -/* +/* * Now build the string. The string consists of an element from the * legend string array, padded with spaces, followed by one of the * symbols used in plpoin above. */ - for (i = 0; i < M; i++) { - if (legend[i] == NULL) - break; - strcpy(string, legend[i]); - j = strlen(string); - if (j < leglen) { /* pad string with spaces */ - for (k = j; k < leglen; k++) - string[k] = ' '; - string[k] = '\0'; - } + for ( i = 0; i < M; i++ ) + { + if ( legend[i] == NULL ) + break; + strcpy( string, legend[i] ); + j = strlen( string ); + if ( j < leglen ) /* pad string with spaces */ + { + for ( k = j; k < leglen; k++ ) + string[k] = ' '; + string[k] = '\0'; + } - /* pad an extra space */ + /* pad an extra space */ - strcat(string, " "); - j = strlen(string); + strcat( string, " " ); + j = strlen( string ); - /* insert the ASCII value of the symbol plotted with plpoin() */ + /* insert the ASCII value of the symbol plotted with plpoin() */ - string[j] = i + OFFSET; - string[j + 1] = '\0'; + string[j] = i + OFFSET; + string[j + 1] = '\0'; - /* plot the string */ + /* plot the string */ - plmtex("rv", 1., 1. - (double) (i + 1) / (M + 1), 0., string); + plmtex( "rv", 1., 1. - (double) ( i + 1 ) / ( M + 1 ), 0., string ); } /* Tell plplot we are done with this page. */ - pladv(0); /* advance page */ + pladv( 0 ); /* advance page */ /* Don't forget to call plend() to finish off! */ plend(); - exit(0); + exit( 0 ); } static int -error(char *str) +error( char *str ) { - fprintf(stderr, "%s\n", str); - exit(1); + fprintf( stderr, "%s\n", str ); + exit( 1 ); } Modified: trunk/examples/c/x01c.c =================================================================== --- trunk/examples/c/x01c.c 2009-10-21 21:29:41 UTC (rev 10542) +++ trunk/examples/c/x01c.c 2009-10-21 22:07:16 UTC (rev 10543) @@ -1,27 +1,27 @@ /* $Id$ + * + * Simple line plot and multiple windows demo. + * + * Copyright (C) 2004 Rafael Laboissiere + * + * This file is part of PLplot. + * + * PLplot is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Library Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * PLplot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with PLplot; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ - Simple line plot and multiple windows demo. - - Copyright (C) 2004 Rafael Laboissiere - - This file is part of PLplot. - - PLplot is free software; you can redistribute it and/or modify - it under the terms of the GNU General Library Public License as published - by the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - PLplot is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with PLplot; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - #include "plcdemos.h" #include "plevent.h" #ifdef PL_HAVE_UNISTD_H @@ -30,67 +30,72 @@ /* Variables and data arrays used by plot generators */ -static PLFLT x[101], y[101]; -static PLFLT xscale, yscale, xoff, yoff, xs[6], ys[6]; +static PLFLT x[101], y[101]; +static PLFLT xscale, yscale, xoff, yoff, xs[6], ys[6]; static PLGraphicsIn gin; -static int locate_mode; -static int test_xor; -static int fontset = 1; -static char *f_name = NULL; +static int locate_mode; +static int test_xor; +static int fontset = 1; +static char *f_name = NULL; /* Options data structure definition. */ static PLOptionTable options[] = { -{ - "locate", /* Turns on test of API locate function */ - NULL, - NULL, - &locate_mode, - PL_OPT_BOOL, - "-locate", - "Turns on test of API locate function" }, -{ - "xor", /* Turns on test of xor function */ - NULL, - NULL, - &test_xor, - PL_OPT_BOOL, - "-xor", - "Turns on test of XOR" }, -{ - "font", /* For switching between font set 1 & 2 */ - NULL, - NULL, - &fontset, - PL_OPT_INT, - "-font number", - "Selects stroke font set (0 or 1, def:1)" }, -{ - "save", /* For saving in postscript */ - NULL, - NULL, - &f_name, - PL_OPT_STRING, - "-save filename", - "Save plot in color postscript `file'" }, -{ - NULL, /* option */ - NULL, /* handler */ - NULL, /* client data */ - NULL, /* address of variable to set */ - 0, /* mode flag */ - NULL, /* short syntax */ - NULL } /* long syntax */ + { + "locate", /* Turns on test of API locate function */ + NULL, + NULL, + &locate_mode, + PL_OPT_BOOL, + "-locate", + "Turns on test of API locate function" + }, + { + "xor", /* Turns on test of xor function */ + NULL, + NULL, + &test_xor, + PL_OPT_BOOL, + "-xor", + "Turns on test of XOR" + }, + { + "font", /* For switching between font set 1 & 2 */ + NULL, + NULL, + &fontset, + PL_OPT_INT, + "-font number", + "Selects stroke font set (0 or 1, def:1)" + }, + { + "save", /* For saving in postscript */ + NULL, + NULL, + &f_name, + PL_OPT_STRING, + "-save filename", + "Save plot in color postscript `file'" + }, + { + NULL, /* option */ + NULL, /* handler */ + NULL, /* client data */ + NULL, /* address of variable to set */ + 0, /* mode flag */ + NULL, /* short syntax */ + NULL + } /* long syntax */ }; -const char *notes[] = {"Make sure you get it right!", NULL}; +const char *notes[] = { "Make sure you get it right!", NULL }; /* Function prototypes */ -void plot1(int); -void plot2(void); -void plot3(void); +void plot1( int ); +void plot2( void ); +void plot3( void ); /*--------------------------------------------------------------------------*\ * main @@ -102,125 +107,129 @@ * - automatic axis rescaling to exponential notation * - placing the axes in the middle of the box * - gridded coordinate axes -\*--------------------------------------------------------------------------*/ + \*--------------------------------------------------------------------------*/ int -main(int argc, const char *argv[]) +main( int argc, const char *argv[] ) { PLINT digmax, cur_strm, new_strm; - char ver[80]; + char ver[80]; /* plplot initialization */ /* Parse and process command line arguments */ - plMergeOpts(options, "x01c options", notes); - plparseopts(&argc, argv, PL_PARSE_FULL); + plMergeOpts( options, "x01c options", notes ); + plparseopts( &argc, argv, PL_PARSE_FULL ); /* Get version number, just for kicks */ - plgver(ver); - fprintf(stdout, "PLplot library version: %s\n", ver); + plgver( ver ); + fprintf( stdout, "PLplot library version: %s\n", ver ); /* Initialize plplot */ /* Divide page into 2x2 plots */ /* Note: calling plstar replaces separate calls to plssub and plinit */ - plstar(2,2); + plstar( 2, 2 ); /* Select font set as per input flag */ - if (fontset) - plfontld(1); + if ( fontset ) + plfontld( 1 ); else - plfontld(0); + plfontld( 0 ); /* Set up the data */ /* Original case */ xscale = 6.; yscale = 1.; - xoff = 0.; - yoff = 0.; + xoff = 0.; + yoff = 0.; /* Do a plot */ - plot1(0); + plot1( 0 ); /* Set up the data */ xscale = 1.; yscale = 0.0014; - yoff = 0.0185; + yoff = 0.0185; /* Do a plot */ digmax = 5; - plsyax(digmax, 0); + plsyax( digmax, 0 ); - plot1(1); + plot1( 1 ); plot2(); plot3(); - /* - * Show how to save a plot: - * Open a new device, make it current, copy parameters, - * and replay the plot buffer - */ + /* + * Show how to save a plot: + * Open a new device, make it current, copy parameters, + * and replay the plot buffer + */ - if (f_name) { /* command line option '-save filename' */ + if ( f_name ) /* command line option '-save filename' */ - printf("The current plot was saved in color Postscript under the name `%s'.\n", f_name); - plgstrm(&cur_strm); /* get current stream */ - plmkstrm(&new_strm); /* create a new one */ + { + printf( "The current plot was saved in color Postscript under the name `%s'.\n", f_name ); + plgstrm( &cur_strm ); /* get current stream */ + plmkstrm( &new_strm ); /* create a new one */ - plsfnam(f_name); /* file name */ - plsdev("psc"); /* device type */ + plsfnam( f_name ); /* file name */ + plsdev( "psc" ); /* device type */ - plcpstrm(cur_strm, 0); /* copy old stream parameters to new stream */ - plreplot(); /* do the save by replaying the plot buffer */ - plend1(); /* finish the device */ + plcpstrm( cur_strm, 0 ); /* copy old stream parameters to new stream */ + plreplot(); /* do the save by replaying the plot buffer */ + plend1(); /* finish the device */ - plsstrm(cur_strm); /* return to previous stream */ + plsstrm( cur_strm ); /* return to previous stream */ } /* Let's get some user input */ - if (locate_mode) { - for (;;) { - if (! plGetCursor(&gin)) break; - if (gin.keysym == PLK_Escape) break; + if ( locate_mode ) + { + for (;; ) + { + if ( !plGetCursor( &gin )) break; + if ( gin.keysym == PLK_Escape ) break; - pltext(); - if (gin.keysym < 0xFF && isprint(gin.keysym)) - printf("subwin = %d, wx = %f, wy = %f, dx = %f, dy = %f, c = '%c'\n", - gin.subwindow, gin.wX, gin.wY, gin.dX, gin.dY, gin.keysym); - else - printf("subwin = %d, wx = %f, wy = %f, dx = %f, dy = %f, c = 0x%02x\n", - gin.subwindow, gin.wX, gin.wY, gin.dX, gin.dY, gin.keysym); + pltext(); + if ( gin.keysym < 0xFF && isprint( gin.keysym )) + printf( "subwin = %d, wx = %f, wy = %f, dx = %f, dy = %f, c = '%c'\n", + gin.subwindow, gin.wX, gin.wY, gin.dX, gin.dY, gin.keysym ); + else + printf( "subwin = %d, wx = %f, wy = %f, dx = %f, dy = %f, c = 0x%02x\n", + gin.subwindow, gin.wX, gin.wY, gin.dX, gin.dY, gin.keysym ); - plgra(); - } + plgra(); + } } /* Don't forget to call plend() to finish off! */ plend(); - exit(0); + exit( 0 ); } - /* =============================================================== */ +/* =============================================================== */ void -plot1(int do_test) +plot1( int do_test ) { - int i; + int i; PLFLT xmin, xmax, ymin, ymax; - for (i = 0; i < 60; i++) { - x[i] = xoff + xscale * (i + 1) / 60.0; - y[i] = yoff + yscale * pow(x[i], 2.); + for ( i = 0; i < 60; i++ ) + { + x[i] = xoff + xscale * ( i + 1 ) / 60.0; + y[i] = yoff + yscale * pow( x[i], 2. ); } xmin = x[0]; @@ -228,9 +237,10 @@ ymin = y[0]; ymax = y[59]; - for (i = 0; i < 6; i++) { - xs[i] = x[i * 10 + 3]; - ys[i] = y[i * 10 + 3]; + for ( i = 0; i < 6; i++ ) + { + xs[i] = x[i * 10 + 3]; + ys[i] = y[i * 10 + 3]; } /* Set up the viewport and window using PLENV. The range in X is @@ -238,117 +248,122 @@ * scaled separately (just = 0), and we just draw a labelled * box (axis = 0). */ - plcol0(1); - plenv(xmin, xmax, ymin, ymax, 0, 0); - plcol0(2); - pllab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2"); + plcol0( 1 ); + plenv( xmin, xmax, ymin, ymax, 0, 0 ); + plcol0( 2 ); + pllab( "(x)", "(y)", "#frPLplot Example 1 - y=x#u2" ); /* Plot the data points */ - plcol0(4); - plpoin(6, xs, ys, 9); + plcol0( 4 ); + plpoin( 6, xs, ys, 9 ); /* Draw the line through the data */ - plcol0(3); - plline(60, x, y); + plcol0( 3 ); + plline( 60, x, y ); /* xor mode enable erasing a line/point/text by replotting it again */ /* it does not work in double buffering mode, however */ - if (do_test && test_xor) { + if ( do_test && test_xor ) + { #ifdef PL_HAVE_USLEEP - PLINT st; - plxormod(1, &st); /* enter xor mode */ - if (st) { - for (i=0; i<60; i++) { - plpoin(1, x+i, y+i,9); /* draw a point */ - usleep(50000); /* wait a little */ - plflush(); /* force an update of the tk driver */ - plpoin(1, x+i, y+i,9); /* erase point */ - } - plxormod(0, &st); /* leave xor mode */ - } + PLINT st; + plxormod( 1, ... [truncated message content] |