[ncview] 10/31: Imported Upstream version 2.1.1
Sebastiaan Couwenberg
sebastic at moszumanska.debian.org
Sat Apr 18 00:43:40 UTC 2015
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository ncview.
commit c2bc40ba54a1aa90ed54fe790696308397fff49f
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Sat Apr 18 01:40:32 2015 +0200
Imported Upstream version 2.1.1
---
src/SciPlot.c | 65 +++---
src/SciPlot.h | 2 +-
src/SciPlotP.h | 2 +-
src/do_print.orig.c | 447 ----------------------------------------
src/epic_time.c | 5 +-
src/file_netcdf.c | 77 ++++---
src/handle_rc_file.c | 29 ++-
src/interface/cbar.c | 6 +-
src/interface/colormap_funcs.c | 8 +-
src/interface/display_info.c | 2 +-
src/interface/filesel.c | 6 +-
src/interface/plot_range.c | 4 +-
src/interface/plot_xy.c | 8 +-
src/interface/printer_options.c | 10 +-
src/interface/range.c | 14 +-
src/interface/set_options.c | 52 +++--
src/interface/x_interface.c | 52 ++---
src/ncview.c | 51 +++--
src/ncview.defines.h | 8 +-
src/ncview.protos.h | 10 +-
src/overlay.c | 8 +-
src/overlay.orig.c | 441 ---------------------------------------
src/udu.c | 16 +-
src/utCalendar2_cal.c | 9 +-
src/util.c | 26 +--
src/view.c | 27 ++-
26 files changed, 298 insertions(+), 1087 deletions(-)
diff --git a/src/SciPlot.c b/src/SciPlot.c
index 3b0f4b4..719ef83 100644
--- a/src/SciPlot.c
+++ b/src/SciPlot.c
@@ -188,10 +188,10 @@ SciPlotClassRec sciplotClassRec = {
WidgetClass sciplotWidgetClass = (WidgetClass)&sciplotClassRec;
void
-get_number_format( char *numberformat, int precision, real val )
+get_number_format( char *numberformat, size_t nflen, int precision, real val )
{
/*sprintf(numberformat,"%%.%df",precision);*/
- sprintf(numberformat,"%%%dg",precision);
+ snprintf(numberformat,nflen,"%%%dg",precision);
}
int
@@ -536,29 +536,30 @@ SciPlotFontDesc *pfd;
temp );
exit(-1);
}
- sprintf(str,"/%s findfont %d scalefont",
+ snprintf(str, str_len, "/%s findfont %d scalefont",
temp,
(flag&XtFONT_SIZE_MASK));
}
- else sprintf(str,"/Courier findfond 10 scalefont");
+ else snprintf(str,str_len,"/Courier findfond 10 scalefont");
}
static void
-FontX11String(flag,str)
+FontX11String(flag,str,slen)
int flag;
char *str;
+int slen;
{
SciPlotFontDesc *pfd;
pfd=FontDescLookup(flag);
if (pfd) {
- sprintf(str,"-*-%s-%s-%s-*-*-%d-*-*-*-*-*-*-*",
+ snprintf(str,slen,"-*-%s-%s-%s-*-*-%d-*-*-*-*-*-*-*",
pfd->X11,
(flag&XtFONT_BOLD?"bold":"medium"),
(flag&XtFONT_ITALIC?(pfd->PSUsesOblique?"o":"i"):"r"),
(flag&XtFONT_SIZE_MASK));
}
- else sprintf(str,"fixed");
+ else snprintf(str,slen,"fixed");
#ifdef DEBUG_SCIPLOT
printf("font string=%s\n",str);
#endif
@@ -572,7 +573,7 @@ SciPlotFont *pf;
char str[256],**list;
int num;
- FontX11String(pf->id,str);
+ FontX11String(pf->id,str,256);
list=XListFonts(XtDisplay(w),str,100,&num);
#ifdef DEBUG_SCIPLOT
if (1) {
@@ -587,7 +588,7 @@ int num;
if (num<=0) {
pf->id&=~XtFONT_ATTRIBUTE_MASK;
pf->id|=XtFONT_ATTRIBUTE_DEFAULT;
- FontX11String(pf->id,str);
+ FontX11String(pf->id,str,256);
list=XListFonts(XtDisplay(w),str,100,&num);
#ifdef DEBUG_SCIPLOT
if (1) {
@@ -603,7 +604,7 @@ int num;
if (num<=0) {
pf->id&=~XtFONT_NAME_MASK;
pf->id|=XtFONT_NAME_DEFAULT;
- FontX11String(pf->id,str);
+ FontX11String(pf->id,str,256);
list=XListFonts(XtDisplay(w),str,100,&num);
#ifdef DEBUG_SCIPLOT
if (1) {
@@ -619,7 +620,7 @@ int num;
if (num<=0) {
pf->id&=~XtFONT_SIZE_MASK;
pf->id|=XtFONT_SIZE_DEFAULT;
- FontX11String(pf->id,str);
+ FontX11String(pf->id,str,256);
list=XListFonts(XtDisplay(w),str,100,&num);
#ifdef DEBUG_SCIPLOT
if (1) {
@@ -2330,8 +2331,8 @@ int precision;
w->plot.x.MajorInc)*w->plot.x.MajorInc;
x=PlotX(w,val);
val /= w->plot.x.Scalefact;
- get_number_format( numberformat, precision, val );
- sprintf(label,numberformat,val);
+ get_number_format( numberformat, 160, precision, val );
+ snprintf(label,160,numberformat,val);
x+=FontnumTextWidth(w,w->plot.axisFont,label);
if ((int)x>w->core.width) {
xextra=ceil(x-w->core.width+w->plot.Margin);
@@ -2349,8 +2350,8 @@ int precision;
w->plot.y.MajorInc*1.0001)*w->plot.y.MajorInc;
y=PlotY(w,val);
val /= w->plot.y.Scalefact;
- get_number_format( numberformat, precision, val );
- sprintf(label,numberformat,val);
+ get_number_format( numberformat, 160, precision, val );
+ snprintf(label,160,numberformat,val);
#ifdef DEBUG_SCIPLOT
printf("ylabel=%s\n",label);
#endif
@@ -2363,8 +2364,8 @@ int precision;
else {
val=w->plot.PolarScale;
PlotRTDegrees(w,val,0.0,&x,&y);
- get_number_format( numberformat, w->plot.x.Precision, val );
- sprintf(label,numberformat,val);
+ get_number_format( numberformat, 160, w->plot.x.Precision, val );
+ snprintf(label,160,numberformat,val);
x+=FontnumTextWidth(w,w->plot.axisFont,label);
if ((int)x>w->core.width) {
xextra=x-w->core.width+w->plot.Margin;
@@ -2708,11 +2709,11 @@ char numberformat[16],label[512],tlabel[512];
if (w->plot.DrawMajorTics)
LineSet(w,x,y1+5,x,y1-5,w->plot.ForegroundColor,XtLINE_SOLID);
- get_number_format( numberformat, precision, val*w->plot.x.Scalefact );
+ get_number_format( numberformat, 16, precision, val*w->plot.x.Scalefact );
if( w->plot.XFmtCallback != NULL )
- (*(w->plot.XFmtCallback))((Widget)w,val,label);
+ (*(w->plot.XFmtCallback))((Widget)w,val,label,512);
else
- sprintf(label,numberformat,val*w->plot.x.Scalefact);
+ snprintf(label,512,numberformat,val*w->plot.x.Scalefact);
TextSet(w,x,w->plot.y.AxisPos,label,w->plot.ForegroundColor,
w->plot.axisFont);
@@ -2766,11 +2767,11 @@ char numberformat[16],label[512],tlabel[512];
if (w->plot.DrawMajorTics)
LineSet(w,x,y1+5,x,y1-5,w->plot.ForegroundColor,
XtLINE_SOLID);
- get_number_format( numberformat, precision, val*w->plot.x.Scalefact );
+ get_number_format( numberformat, 16, precision, val*w->plot.x.Scalefact );
if( w->plot.XFmtCallback != NULL )
- (*(w->plot.XFmtCallback))((Widget)w,val,label);
+ (*(w->plot.XFmtCallback))((Widget)w,val,label,512);
else
- sprintf(label,numberformat,val*w->plot.x.Scalefact);
+ snprintf(label,512,numberformat,val*w->plot.x.Scalefact);
TextSet(w,x,w->plot.y.AxisPos,label,w->plot.ForegroundColor,
w->plot.axisFont);
majorval=val;
@@ -2788,8 +2789,8 @@ char numberformat[16],label[512],tlabel[512];
if (w->plot.DrawMajorTics)
LineSet(w,x1+5,y,x1-5,y,w->plot.ForegroundColor,XtLINE_SOLID);
- get_number_format( numberformat, precision, val*w->plot.y.Scalefact );
- sprintf(label,numberformat,val*w->plot.y.Scalefact);
+ get_number_format( numberformat, 16, precision, val*w->plot.y.Scalefact );
+ snprintf(label,512,numberformat,val*w->plot.y.Scalefact);
VTextSet(w,w->plot.x.AxisPos,y,label,w->plot.ForegroundColor,
w->plot.axisFont);
@@ -2846,8 +2847,8 @@ char numberformat[16],label[512],tlabel[512];
if (w->plot.DrawMajorTics)
LineSet(w,x1-5,y,x1+5,y,w->plot.ForegroundColor,
XtLINE_SOLID);
- get_number_format( numberformat, precision, val*w->plot.y.Scalefact );
- sprintf(label,numberformat,val*w->plot.y.Scalefact);
+ get_number_format( numberformat, 16, precision, val*w->plot.y.Scalefact );
+ snprintf(label,512,numberformat,val*w->plot.y.Scalefact);
VTextSet(w,w->plot.x.AxisPos,y,label,w->plot.ForegroundColor,
w->plot.axisFont);
majorval=val;
@@ -2862,9 +2863,9 @@ char numberformat[16],label[512],tlabel[512];
w->plot.ForegroundColor,w->plot.labelFont);
if (w->plot.ShowYLabel) {
if( w->plot.y.Scale_expon == 0. )
- sprintf( tlabel, "%s", w->plot.ylabel );
+ snprintf( tlabel, 512, "%s", w->plot.ylabel );
else
- sprintf( tlabel, "%s/10**%d", w->plot.ylabel, -(w->plot.y.Scale_expon) );
+ snprintf( tlabel, 512, "%s/10**%d", w->plot.ylabel, -(w->plot.y.Scale_expon) );
VTextCenter(w,w->plot.x.LabelPos,
w->plot.y.Origin+(w->plot.y.Size/2.0),
tlabel,w->plot.ForegroundColor,
@@ -2978,8 +2979,8 @@ char numberformat[160],label[16];
CircleSet(w,x1,y1,x2-x1,w->plot.ForegroundColor,XtLINE_DOTTED);
if (w->plot.DrawMajorTics)
LineSet(w,x2,y2-5.0,x2,y2+5.0,w->plot.ForegroundColor,XtLINE_SOLID);
- get_number_format( numberformat, w->plot.x.Precision, tic );
- sprintf(label,numberformat,tic);
+ get_number_format( numberformat, 160, w->plot.x.Precision, tic );
+ snprintf(label,16,numberformat,tic);
TextSet(w,x2,y2+height,label,w->plot.ForegroundColor,w->plot.axisFont);
}
if (w->plot.ShowTitle)
@@ -3446,7 +3447,7 @@ SciPlotWidget w;
void
SciPlotAddXAxisCallback(wi,cb)
Widget wi;
-void (*cb)(Widget wi, float val, char *s);
+void (*cb)(Widget wi, float val, char *s, size_t slen);
{
SciPlotWidget w;
if (!XtIsSciPlot(wi)) return;
diff --git a/src/SciPlot.h b/src/SciPlot.h
index 5fe5f05..fb023c8 100644
--- a/src/SciPlot.h
+++ b/src/SciPlot.h
@@ -159,7 +159,7 @@ void SciPlotQueryXAxisValues( Widget w, int *nvals, float **values);
void SciPlotSetXAxisLabels(Widget wi,int nlabels, char **labels);
float SciPlotScreenToDataX(Widget wi,int xscreen);
float SciPlotScreenToDataY(Widget wi,int yscreen);
-void SciPlotAddXAxisCallback(Widget wi, void (*cb)(Widget,float,char*) );
+void SciPlotAddXAxisCallback(Widget wi, void (*cb)(Widget,float,char*,size_t) );
#undef P_
diff --git a/src/SciPlotP.h b/src/SciPlotP.h
index 2d122e2..3f875f7 100644
--- a/src/SciPlotP.h
+++ b/src/SciPlotP.h
@@ -220,7 +220,7 @@ typedef struct {
int titleFont;
int labelFont;
int axisFont;
- void (*XFmtCallback)(Widget w, float f, char *s);
+ void (*XFmtCallback)(Widget w, float f, char *s, size_t slen);
GC defaultGC;
GC dashGC;
diff --git a/src/do_print.orig.c b/src/do_print.orig.c
deleted file mode 100644
index 41eada3..0000000
--- a/src/do_print.orig.c
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
- * Ncview by David W. Pierce. A visual netCDF file viewer.
- * Copyright (C) 1993 through 2010 David W. Pierce
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as
- * published by the Free Software Foundation.
- *
- * This program 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 General Public License, version 3, for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * David W. Pierce
- * 6259 Caminito Carrean
- * San Diego, CA 92122
- * pierce at cirrus.ucsd.edu
- */
-
-/* define DEBUG */
-
-#include "ncview.includes.h"
-#include "ncview.defines.h"
-#include "ncview.protos.h"
-
-#define PAGE_WIDTH_INCHES 8.5
-#define PAGE_HEIGHT_INCHES 11.5
-#define PAGE_X_MARGIN 1.5 /* Inches */
-#define PAGE_UPPER_Y_MARGIN 2.0 /* Inches */
-#define PAGE_LOWER_Y_MARGIN 4.0 /* Inches */
-
-#define FONT_SIZE 11
-#define HEADER_FONT_SIZE 16
-#define FONT_NAME "Helvetica"
-#define LEADING 3
-
-#define DEFAULT_DEVICE DEVICE_PRINTER
-#define INCLUDE_OUTLINE TRUE
-#define INCLUDE_TITLE TRUE
-#define INCLUDE_AXIS_LABELS TRUE
-#define INCLUDE_EXTRA_INFO TRUE
-#define INCLUDE_ID TRUE
-#define TEST_ONLY FALSE
-
-#define ID_FONT_SIZE_SCALE 0.7 /* How much smaller ID font size is than regular */
-
-extern View *view;
-extern Options options;
-
-static PrintOptions printopts;
-
-static void print_header( FILE *out_file, float scale, size_t x, size_t y, size_t top_of_image );
-static void calc_scale( float *scale, size_t x, size_t y );
-static void set_font( FILE *outf, char *name, int size );
-static void do_outline( FILE *f, size_t x, size_t y );
-static void print_other_info( FILE *out_file, float output_scale, size_t x_size, size_t y_size,
- size_t center_x, size_t center_y, size_t top_of_image, size_t bot_of_image );
-
-/********************************************************************/
-
- void
-print_init()
-{
- printopts.page_width = PAGE_WIDTH_INCHES;
- printopts.page_height = PAGE_HEIGHT_INCHES;
- printopts.page_x_margin = PAGE_X_MARGIN;
- printopts.page_upper_y_margin = PAGE_UPPER_Y_MARGIN;
- printopts.page_lower_y_margin = PAGE_LOWER_Y_MARGIN;
- printopts.ppi = 72.0;
-
- printopts.leading = LEADING;
- printopts.font_size = FONT_SIZE;
- printopts.header_font_size = HEADER_FONT_SIZE;
-
- printopts.output_device = DEFAULT_DEVICE;
- printopts.include_outline = INCLUDE_OUTLINE;
- printopts.include_id = INCLUDE_ID;
- printopts.include_title = INCLUDE_TITLE;
- printopts.include_axis_labels = INCLUDE_AXIS_LABELS;
- printopts.include_extra_info = INCLUDE_EXTRA_INFO;
-
- printopts.test_only = TEST_ONLY;
-
- strcpy( printopts.font_name, FONT_NAME );
-
- printer_options_init(); /* this initializes the X-windows interface
- part of the pinter options panel */
-}
-
-/*************************************************************************/
-
- void
-do_print()
-{
- long i, j;
- size_t x_size, y_size, scaled_x_size, scaled_y_size, top_of_image, bot_of_image,
- center_x, center_y, left_of_image, right_of_image;
- char outfname[1024], tstr[1500];
- FILE *outf;
- float output_scale;
- int r, g, b, n_print;
- ncv_pixel pix;
-
-#ifdef DEBUG
- fprintf( stderr, "entering do_print()\n" );
-#endif
- x_size = *(view->variable->size + view->x_axis_id);
- y_size = *(view->variable->size + view->y_axis_id);
- view_get_scaled_size( options.blowup, x_size, y_size, &scaled_x_size, &scaled_y_size );
-
- sprintf( printopts.out_file_name, "ncview.%s.ps", view->variable->name );
- if( printer_options( &printopts ) == MESSAGE_CANCEL )
- return;
-
- if( printopts.output_device == DEVICE_PRINTER )
- strcpy( printopts.out_file_name, tmpnam(NULL) );
-
- if( warn_if_file_exits( printopts.out_file_name ) == MESSAGE_CANCEL )
- return;
-
- if( (outf = fopen(printopts.out_file_name, "w" )) == NULL ) {
- sprintf( tstr, "Error opening file %s for output!\n",
- outfname );
- in_error( tstr );
- return;
- }
-
- in_set_cursor_busy();
- calc_scale( &output_scale, scaled_x_size, scaled_y_size );
-
- /* These are all in absolute points in the default coordinate system */
- top_of_image = (size_t)(printopts.page_height*printopts.ppi -
- printopts.page_upper_y_margin*printopts.ppi);
- bot_of_image = top_of_image - (long)((float)scaled_y_size*output_scale);
- left_of_image = (size_t)(printopts.page_x_margin*printopts.ppi);
- right_of_image = left_of_image + (long)((float)scaled_x_size*output_scale);
- center_y = (top_of_image + bot_of_image)/2;
- center_x = (size_t)(((float)left_of_image + (float)right_of_image)/2.0);
-
- print_header( outf, output_scale, scaled_x_size, scaled_y_size, top_of_image );
-
- /***** dump out the color image *****/
- if( ! printopts.test_only ) {
- view_draw( FALSE ); /* Don't allow saveframes -- force reload of image data */
- n_print = 0;
- for( j=0; j<scaled_y_size; j++ ) {
- for( i=0; i<scaled_x_size; i++ ) {
- pix = *(view->pixels + j*scaled_x_size + i);
- pix_to_rgb( pix, &r, &g, &b );
- fprintf( outf, "%02x%02x%02x", (r>>8), (g>>8), (b>>8));
- n_print += 6;
- if( n_print > 70 ) {
- fprintf( outf, "\n" );
- n_print = 0;
- }
- }
- }
- fprintf( outf, "\n\n" );
- }
-
- /* Outline the color contour with lines */
- if( printopts.include_outline )
- do_outline( outf, scaled_x_size, scaled_y_size );
-
- fprintf( outf, "\n\ngrestore\n" );
-
- print_other_info( outf, output_scale, scaled_x_size, scaled_y_size, center_x, center_y,
- top_of_image, bot_of_image );
-
-#ifdef DEBUG
- fprintf( stderr, "exiting do_print()\n" );
-#endif
-}
-
-/*************************************************************************/
-
- static void
-print_other_info( FILE *outf, float output_scale, size_t x_size, size_t y_size,
- size_t center_x, size_t center_y,
- size_t top_of_image, size_t bot_of_image )
-{
- char *units, *x_dim_name, *x_dim_longname,
- *y_dim_name, *y_dim_longname, *x_units, *y_units,
- tstr[1500], tstr2[1000], *main_long_name, *main_units,
- *dim_name, *dim_longname;
- FDBlist *fdb;
- NCDim *d;
- int i, type, has_bounds;
- size_t *actual_place;
- time_t sec_since_1970;
- double temp_double, bound_min, bound_max;
-
-#ifdef DEBUG
- fprintf( stderr, "print_other_info: entering\n" );
-#endif
- x_dim_name = (*(view->variable->dim + view->x_axis_id))->name;
- x_dim_longname = fi_dim_longname( view->variable->first_file->id, x_dim_name );
- x_units = fi_dim_units( view->variable->first_file->id, x_dim_name );
-
- y_dim_name = (*(view->variable->dim + view->y_axis_id))->name;
- y_dim_longname = fi_dim_longname( view->variable->first_file->id, y_dim_name );
- y_units = fi_dim_units( view->variable->first_file->id, y_dim_name );
-
- main_long_name = fi_long_var_name( view->variable->first_file->id,
- view->variable->name );
- if( main_long_name == NULL )
- main_long_name = view->variable->name;
- main_units = fi_var_units( view->variable->first_file->id, view->variable->name );
-
- /***** Main variable name and units ******/
- if( printopts.include_title ) {
- sprintf( tstr, "%s", main_long_name );
- if( main_units != NULL ) {
- strcat( tstr, " (" );
- strcat( tstr, main_units );
- strcat( tstr, ")" );
- }
-
- /* move to the center, then half the string's width */
- set_font( outf, printopts.font_name, printopts.header_font_size );
- fprintf( outf, "%ld %ld moveto\n",
- center_x,
- top_of_image+printopts.font_size );
- fprintf( outf, "(%s) stringwidth pop -0.5 mul 0 rmoveto\n", tstr );
- fprintf( outf, "(%s) show\n", tstr );
- }
-
- /***** X axis title *****/
- if( printopts.include_axis_labels ) {
- set_font( outf, printopts.font_name, printopts.font_size );
- strcpy( tstr, x_dim_longname );
- if( x_units != NULL ) {
- strcat( tstr, " (" );
- strcat( tstr, x_units );
- strcat( tstr, ")" );
- }
- fprintf( outf, "%ld %ld moveto\n",
- center_x, bot_of_image-(long)(1.5*(float)printopts.font_size) );
- fprintf( outf, "(%s) stringwidth pop -0.5 mul 0 rmoveto\n", tstr );
- fprintf( outf, "(%s) show\n", tstr );
-
- /***** Y axis title *****/
- set_font( outf, printopts.font_name, printopts.font_size );
- strcpy( tstr, y_dim_longname );
- if( y_units != NULL ) {
- strcat( tstr, " (" );
- strcat( tstr, y_units );
- strcat( tstr, ")" );
- }
- fprintf( outf, "%ld %ld moveto\n",
- center_x - (long)((float)x_size*output_scale/2.0),
- center_y );
- fprintf( outf, "gsave 90 rotate 0 %d rmoveto\n",
- (int)((float)printopts.font_size*output_scale) );
- fprintf( outf, "(%s) stringwidth pop -0.5 mul 0 rmoveto\n", tstr );
- fprintf( outf, "(%s) show grestore\n", tstr );
- }
-
- /***************** Other information *******************/
- if( printopts.include_extra_info ) {
- set_font( outf, printopts.font_name, printopts.font_size );
- fprintf( outf, "%ld %ld moveto\n", (long)(printopts.page_x_margin*printopts.ppi),
- bot_of_image - 4*printopts.font_size );
-
- /**** File title ***/
- if( fi_title( view->variable->first_file->id ) != NULL ) {
- fprintf( outf, "gsave (%s) show grestore\n",
- fi_title( view->variable->first_file->id ) );
- fprintf( outf, "0 %d rmoveto\n",
- -(printopts.leading+printopts.font_size) );
- }
-
- /*** Range of data ***/
- sprintf( tstr, "Range of %s: %g to %g %s", main_long_name,
- view->variable->user_min, view->variable->user_max, main_units );
- fprintf( outf, "gsave (%s) show grestore\n", tstr );
- fprintf( outf, "0 %d rmoveto\n", -(printopts.leading+printopts.font_size) );
-
- /*** Range of X axis ***/
- d = *(view->variable->dim + view->x_axis_id);
- if( x_units == NULL )
- sprintf( tstr, "Range of %s: %g to %g",
- x_dim_longname, d->min, d->max);
- else
- sprintf( tstr, "Range of %s: %g to %g %s",
- x_dim_longname, d->min, d->max, x_units );
- fprintf( outf, "gsave (%s) show grestore\n", tstr );
- fprintf( outf, "0 %d rmoveto\n", -(printopts.leading+printopts.font_size) );
-
- /*** Range of Y axis ***/
- d = *(view->variable->dim + view->y_axis_id);
- if( options.invert_physical )
- sprintf( tstr, "Range of %s: %g to %g",
- y_dim_longname, d->max, d->min );
- else
- sprintf( tstr, "Range of %s: %g to %g",
- y_dim_longname, d->min, d->max );
- if( y_units != NULL ) {
- strcat( tstr, " " );
- strcat( tstr, y_units );
- }
- fprintf( outf, "gsave (%s) show grestore\n", tstr );
- fprintf( outf, "0 %d rmoveto\n", -(printopts.leading+printopts.font_size) );
-
- /*** Values of other dimensions ***/
- for(i=0; i<view->variable->n_dims; i++)
- if( (i != view->x_axis_id) &&
- (i != view->y_axis_id) &&
- (*(view->variable->dim+i) != NULL)) {
- dim_name = (*(view->variable->dim + i))->name;
- dim_longname = fi_dim_longname( view->variable->first_file->id, dim_name );
- units = fi_dim_units( view->variable->first_file->id, dim_name );
- type = fi_dim_value( view->variable, i, *(view->var_place+i),
- &temp_double, tstr2, &has_bounds, &bound_min, &bound_max );
- if( type == NC_DOUBLE )
- sprintf( tstr, "Current %s: %lg", dim_longname, temp_double );
- else
- sprintf( tstr, "Current %s: %s", dim_longname,
- tstr2 );
- if( units != NULL ) {
- strcat( tstr, " " );
- strcat( tstr, units );
- }
- fprintf( outf, "gsave (%s) show grestore\n", tstr );
- fprintf( outf, "0 %d rmoveto\n", -(printopts.leading+printopts.font_size) );
- }
-
- /*** Name of file ***/
- tstr[0] = '\0';
- actual_place = (size_t *)malloc( sizeof(size_t)*20 );
- virt_to_actual_place( view->variable, view->var_place, actual_place, &fdb );
- if( (fi_recdim_id( view->variable->first_file->id ) != view->x_axis_id ) &&
- (fi_recdim_id( view->variable->first_file->id ) != view->y_axis_id))
- sprintf( tstr, "Frame %ld in ",
- *(actual_place + view->scan_axis_id)+1 );
- strcat( tstr, "File " );
- strcat( tstr, fdb->filename );
- fprintf( outf, "gsave (%s) show grestore\n", tstr );
- fprintf( outf, "0 %ld rmoveto\n", -(printopts.leading+printopts.font_size) );
- }
-
- if( printopts.include_id ) {
- sec_since_1970 = time(NULL);
- sprintf( tstr, "%s %s", getlogin(), ctime(&sec_since_1970) );
- /* Make the id font a bit smaller */
- set_font( outf, printopts.font_name,
- (int)((float)printopts.font_size*ID_FONT_SIZE_SCALE) );
- fprintf( outf, "gsave %ld %ld translate 0 0 moveto\n",
- center_x + (long)((float)x_size*output_scale/2.0)
- + printopts.font_size + printopts.leading,
- bot_of_image );
- fprintf( outf, "90 rotate (%s) show grestore\n", tstr );
- }
-
- /****** All done! *****/
- fprintf( outf, "\n\nshowpage\n" );
- fclose( outf );
- if( printopts.output_device == DEVICE_PRINTER ) {
- sprintf( tstr, "lpr %s\n", printopts.out_file_name );
- system( tstr );
- unlink( printopts.out_file_name );
- }
-
- fprintf( stdout, "" );
- fflush( stdout );
- in_set_cursor_normal();
-#ifdef DEBUG
- fprintf( stderr, "print_other_info: exiting\n" );
-#endif
-}
-
- static void
-set_font( FILE *outf, char *name, int size )
-{
- fprintf( outf, "/%s findfont\n", name );
- fprintf( outf, "%d scalefont setfont\n", size );
-}
-
- static void
-calc_scale( float *scale, size_t x, size_t y )
-{
- size_t page_width, page_height;
- float scale_x, scale_y;
-
- page_width = (printopts.page_width-2.0*printopts.page_x_margin)*printopts.ppi;
- page_height = (printopts.page_height -
- (printopts.page_upper_y_margin + printopts.page_lower_y_margin)
- )*printopts.ppi;
-
- scale_x = page_width / (float)x;
- scale_y = page_height / (float)y;
-
- *scale = (scale_x < scale_y) ? scale_x : scale_y;
-}
-
- static void
-do_outline( FILE *f, size_t x, size_t y )
-{
- fprintf( f, "newpath\n" );
- fprintf( f, "0 0 moveto\n" );
- fprintf( f, "0 %d lineto\n", -y );
- fprintf( f, "%d %d lineto\n", x, -y );
- fprintf( f, "%d 0 lineto\n", x );
- fprintf( f, "0 0 lineto\n" );
- fprintf( f, "closepath stroke\n" );
-}
-
- static void
-print_header( FILE *f, float scale, size_t x, size_t y, size_t top_of_image )
-{
- fprintf( f, "%%!\n" );
- fprintf( f, "/picstr %ld string def\n", x*3 );
- fprintf( f, "gsave\n" );
-
- /* This sets the position of the output image on the page */
- fprintf( f, "%ld %ld translate\n",
- (long)(printopts.page_x_margin*printopts.ppi), top_of_image );
-
- /* This sets the size of the image */
- fprintf( f, "%f %f scale\n", scale, scale );
-
- if( printopts.test_only ) {
- fprintf( f, "newpath\n" );
- fprintf( f, "0 0 moveto\n" );
- fprintf( f, "0 %d lineto\n", -y );
- fprintf( f, "%d %d lineto\n", x, -y );
- fprintf( f, "%d 0 lineto\n", x );
- fprintf( f, "0 0 lineto\n" );
- fprintf( f, "%d %d lineto\n", x, -y );
- fprintf( f, "0 %d moveto\n", -y );
- fprintf( f, "%d 0 lineto\n", x );
- fprintf( f, "closepath stroke\n" );
- }
- else
- {
- fprintf( f, "%ld %ld 8\n", x, y );
- fprintf( f, "[1 0 0 -1 0 1]\n" );
- fprintf( f, "{currentfile picstr readhexstring pop}\n" );
- fprintf( f, "false 3\n" );
- fprintf( f, "colorimage\n\n" );
- }
-}
-
diff --git a/src/epic_time.c b/src/epic_time.c
index 8aadb49..348fcec 100644
--- a/src/epic_time.c
+++ b/src/epic_time.c
@@ -82,7 +82,7 @@ epic_calc_tgran( int fileid, NCDim *d )
/*************************************************************************/
void
-epic_fmt_time( char *temp_string, double new_dimval, NCDim *dim )
+epic_fmt_time( char *temp_string, size_t temp_string_len, double new_dimval, NCDim *dim )
{
long epic_time[2];
int mon, day, yr, hour, min;
@@ -95,7 +95,8 @@ epic_fmt_time( char *temp_string, double new_dimval, NCDim *dim )
epic_time[1] = 0L;
ep_time_to_mdyhms(epic_time, &mon, &day, &yr, &hour, &min, &sec);
- sprintf( temp_string, "%1d-%s-%04d %02d:%02d", day, months[mon-1],
+ snprintf( temp_string, temp_string_len, "%1d-%s-%04d %02d:%02d", day, months[mon-1],
yr, hour, min );
+ temp_string[ temp_string_len-1 ] = '\0';
}
diff --git a/src/file_netcdf.c b/src/file_netcdf.c
index bf0b8d2..7b20ada 100644
--- a/src/file_netcdf.c
+++ b/src/file_netcdf.c
@@ -44,6 +44,22 @@ int netcdf_get_att_util( int id, int varid, char *var_name, char *att_name, int
char *nc_type_to_string( nc_type type );
/*******************************************************************************************/
+void safe_strcat( char *dest, size_t dest_len, char *src )
+{
+ size_t nfree;
+
+ if( strlen(dest) >= (dest_len-1) ) {
+ dest[ dest_len-1 ] = '\0';
+ return;
+ }
+
+ nfree = (dest_len-1) - strlen(dest); /* Must be >= 1 */
+ strncat( dest, src, nfree );
+
+ dest[ dest_len-1 ] = '\0';
+}
+
+/*******************************************************************************************/
int netcdf_fi_confirm( char *name )
{
int ierr, fd;
@@ -837,7 +853,7 @@ nc_type netcdf_dim_value( int fileid, char *dim_name, size_t place,
char_place[0] = place;
do {
char_place[1] = i;
- err = nc_get_var1_schar( fileid, dimvar_id, char_place, (ret_val_char+i));
+ err = nc_get_var1_uchar( fileid, dimvar_id, char_place, (((unsigned char *)(ret_val_char))+i));
i++;
}
while
@@ -1378,10 +1394,11 @@ char *netcdf_att_string( int fileid, char *var_name )
nc_type datatype, type;
char att_name[MAX_NC_NAME], dummy_var_name[MAX_NC_NAME];
char *data, *ret_string, line[2000];
- size_t len;
+ size_t len, retval_len=10000;
- ret_string = (char *)malloc(10000);
- sprintf( ret_string, "Attributes for variable %s:\n------------------------------\n", var_name );
+ ret_string = (char *)malloc(retval_len);
+ snprintf( ret_string, retval_len, "Attributes for variable %s:\n------------------------------\n", var_name );
+ ret_string[retval_len-1] = '\0';
err = nc_inq_varid( fileid, var_name, &varid );
if( err != NC_NOERR ) {
@@ -1426,25 +1443,25 @@ char *netcdf_att_string( int fileid, char *var_name )
ncattget( fileid, varid, att_name, data );
- strcat( ret_string, att_name );
- strcat( ret_string, ": " );
+ safe_strcat( ret_string, retval_len, att_name );
+ safe_strcat( ret_string, retval_len, ": " );
for(i=0; i<len; i++) {
switch( datatype ) {
- case NC_BYTE: sprintf( line, "%d ", *((char *)data+i) ); break;
- case NC_CHAR: sprintf( line, "%c", *((char *)data+i) ); break;
- case NC_SHORT: sprintf( line, "%d ", *((short *)data+i) ); break;
- case NC_LONG: sprintf( line, "%ld ", (long)(*((nclong *)data+i)) ); break;
- case NC_FLOAT: sprintf( line, "%f ", *((float *)data+i) ); break;
- case NC_DOUBLE: sprintf( line, "%lf ", *((double *)data+i) ); break;
- case NC_NAT: sprintf( line, "(NC_NAT) "); break;
+ case NC_BYTE: snprintf( line, 1999, "%d ", *((char *)data+i) ); break;
+ case NC_CHAR: snprintf( line, 1999, "%c", *((char *)data+i) ); break;
+ case NC_SHORT: snprintf( line, 1999, "%d ", *((short *)data+i) ); break;
+ case NC_LONG: snprintf( line, 1999, "%ld ", (long)(*((nclong *)data+i)) ); break;
+ case NC_FLOAT: snprintf( line, 1999, "%f ", *((float *)data+i) ); break;
+ case NC_DOUBLE: snprintf( line, 1999, "%lf ", *((double *)data+i) ); break;
+ case NC_NAT: snprintf( line, 1999, "(NC_NAT) "); break;
}
- strcat( ret_string, line );
+ safe_strcat( ret_string, retval_len, line );
}
- strcat( ret_string, "\n" );
+ safe_strcat( ret_string, retval_len, "\n" );
}
- strcat( ret_string, netcdf_global_att_string( fileid ));
+ safe_strcat( ret_string, retval_len, netcdf_global_att_string( fileid ));
return( ret_string );
}
@@ -1455,6 +1472,7 @@ char *netcdf_global_att_string( int fileid )
nc_type datatype;
char att_name[MAX_NC_NAME];
char *data, *ret_string, line[2000];
+ size_t retval_len=10000;
err = nc_inq_natts( fileid, &n_atts );
if( err == -1 ) {
@@ -1468,8 +1486,9 @@ char *netcdf_global_att_string( int fileid )
return( ret_string );
}
- ret_string = (char *)malloc(10000);
- sprintf( ret_string, "\nGlobal attributes:\n--------------------------\n" );
+ ret_string = (char *)malloc(sizeof(char) * retval_len);
+ snprintf( ret_string, retval_len-1, "\nGlobal attributes:\n--------------------------\n" );
+ ret_string[retval_len-1] = '\0';
for( iatt=0; iatt<n_atts; iatt++ ) {
@@ -1493,22 +1512,22 @@ char *netcdf_global_att_string( int fileid )
ncattget( fileid, NC_GLOBAL, att_name, data );
- strcat( ret_string, att_name );
- strcat( ret_string, ": " );
+ safe_strcat( ret_string, retval_len, att_name);
+ safe_strcat( ret_string, retval_len, ": " );
for(i=0; i<len; i++) {
switch( datatype ) {
- case NC_BYTE: sprintf( line, "%d ", *((char *)data+i) ); break;
- case NC_CHAR: sprintf( line, "%c", *((char *)data+i) ); break;
- case NC_SHORT: sprintf( line, "%d ", *((short *)data+i) ); break;
- case NC_LONG: sprintf( line, "%ld ", (long)(*((nclong *)data+i)) ); break;
- case NC_FLOAT: sprintf( line, "%f ", *((float *)data+i) ); break;
- case NC_DOUBLE: sprintf( line, "%lf ", *((double *)data+i) ); break;
- case NC_NAT: sprintf( line, "(NC_NAT) "); break;
+ case NC_BYTE: snprintf( line, 1999, "%d ", *((char *)data+i) ); break;
+ case NC_CHAR: snprintf( line, 1999, "%c", *((char *)data+i) ); break;
+ case NC_SHORT: snprintf( line, 1999, "%d ", *((short *)data+i) ); break;
+ case NC_LONG: snprintf( line, 1999, "%ld ", (long)(*((nclong *)data+i)) ); break;
+ case NC_FLOAT: snprintf( line, 1999, "%f ", *((float *)data+i) ); break;
+ case NC_DOUBLE: snprintf( line, 1999, "%lf ", *((double *)data+i) ); break;
+ case NC_NAT: snprintf( line, 1999, "(NC_NAT) "); break;
}
- strcat( ret_string, line );
+ safe_strcat( ret_string, retval_len, line );
}
- strcat( ret_string, "\n" );
+ safe_strcat( ret_string, retval_len, "\n" );
}
return( ret_string );
diff --git a/src/handle_rc_file.c b/src/handle_rc_file.c
index f81728a..46a5b9a 100644
--- a/src/handle_rc_file.c
+++ b/src/handle_rc_file.c
@@ -3,6 +3,10 @@
#include <unistd.h>
#include <string.h>
+#include "ncview.includes.h"
+#include "ncview.defines.h"
+#include "ncview.protos.h"
+
#include "stringlist.h"
#define NCVIEW_STATE_FILE_VERSION 1
@@ -26,6 +30,22 @@ Scripps Insititution of Oceanography
*/
/*================================================================================
+ * Get the persistent state that we want to save to a file
+ * This generates and allocates space for a new stringlist, so when the calling routine
+ * is done with the stringlist (by saving it to a file, or example), then the calling
+ * routine must delete the stringlist as so:
+ *
+ * state_to_save = get_persistent_state();
+ * stringlist_delete_entire_list( state_to_save );
+ */
+ Stringlist *
+get_persistent_state()
+{
+ /* Only one module saves state info at the moment */
+ return( get_persistent_X_state() );
+}
+
+/*================================================================================
* Write the state to a disk file. Returns 0 on success, != 0 on error.
*/
int
@@ -66,8 +86,10 @@ write_state_to_file( Stringlist *state_to_save )
fprintf( stderr, "Error, temporary directory name is too long: %s\n", homedir );
return( -1 );
}
- sprintf( final_fname, "%s/.ncviewrc", homedir );
- sprintf( tmp_fname, "%s/.ncviewrc.XXXXXX", homedir );
+ snprintf( final_fname, 2000, "%s/.ncviewrc", homedir );
+ final_fname[1999] = '\0';
+ snprintf( tmp_fname, 2000, "%s/.ncviewrc.XXXXXX", homedir );
+ tmp_fname[1999] = '\0';
/* Make temporary file safely */
outfid = mkstemp( tmp_fname );
@@ -146,7 +168,8 @@ read_state_from_file( Stringlist **state )
fprintf( stderr, "Error, environmental variable $HOME is too long (has too many characters)\n" );
return( -81 );
}
- sprintf( final_fname, "%s/.ncviewrc", homedir );
+ snprintf( final_fname, 2000, "%s/.ncviewrc", homedir );
+ final_fname[1999] = '\0';
/* Open the file for reading */
if( (fin = fopen(final_fname, "r")) == NULL ) {
diff --git a/src/interface/cbar.c b/src/interface/cbar.c
index bca9ce5..3810a0a 100644
--- a/src/interface/cbar.c
+++ b/src/interface/cbar.c
@@ -181,7 +181,7 @@ void cbar_make( int width, int height, int n_extra_colors, float user_min, float
for( i=0; i<nlev; i++ ) {
if( options.debug ) fprintf( stderr, "cbar_make: drawing label %d of %d\n", i, nlev );
val = start + step*i;
- sprintf( tstr, "%g", val );
+ snprintf( tstr, 1020, "%g", val );
sw = string_width( tstr, cbar_raster->font );
xfrac = (val-user_min)/drange;
if( (xfrac>=0.) && (xfrac<=1.)) {
@@ -501,7 +501,7 @@ static my_Font *open_font( char *font_name )
char filename[132], *font_dir, *getenv(), *DEFAULT_FONT_DIR=".";
my_Font *ret_val;
- sprintf( filename, "%s/%s.bdf", DEFAULT_FONT_DIR, font_name );
+ snprintf( filename, 130, "%s/%s.bdf", DEFAULT_FONT_DIR, font_name );
if( (font_file = fopen( filename, "r" )) == NULL )
{
font_dir = getenv( "TITLE_FONT_DIR" );
@@ -513,7 +513,7 @@ static my_Font *open_font( char *font_name )
}
else
{
- sprintf( filename, "%s/%s.bdf",
+ snprintf( filename, 130, "%s/%s.bdf",
font_dir, font_name );
font_file = fopen( filename, "r" );
if( font_file == NULL )
diff --git a/src/interface/colormap_funcs.c b/src/interface/colormap_funcs.c
index f399475..c30ef34 100644
--- a/src/interface/colormap_funcs.c
+++ b/src/interface/colormap_funcs.c
@@ -300,7 +300,7 @@ void x_check_legal_colormap_loaded()
fprintf( stderr, "Error, colormap name is too long: %s\n", cm->name );
exit(-1);
}
- sprintf( cm_name, "CMAP_%s", cm->name );
+ snprintf( cm_name, 999, "CMAP_%s", cm->name );
sl = stringlist_match_string_exact( read_in_state, cm_name );
if( sl == NULL )
list_to_use[ n_list_to_use++ ] = cm;
@@ -398,10 +398,12 @@ void x_create_colormap( char *name, unsigned char r[256], unsigned char g[256],
fprintf( stderr, "Error, colormap name is too long: %s\n", name );
exit(-1);
}
- sprintf( sl_cmap_name, "CMAP_%s", name );
+ snprintf( sl_cmap_name, 1018, "CMAP_%s", name );
sl = stringlist_match_string_exact( read_in_state, sl_cmap_name );
if( sl == NULL ) {
+ /* People seem to find this message confusing
printf( "did not find color map %s in state file: enabling by default\n", sl_cmap_name );
+ */
cmaplist->enabled = 1;
}
else
@@ -745,7 +747,7 @@ colormap_options_to_stringlist( Stringlist **sl )
fprintf( stderr, "Error, colormap name too long -- max is 1000 chars (routine colormap_options_to_stringlist)\n" );
exit(-1);
}
- sprintf( cmap_name_ext, "CMAP_%s", cursor->name );
+ snprintf( cmap_name_ext, 1022, "CMAP_%s", cursor->name );
enabled = cursor->enabled;
if( (err = stringlist_add_string( sl, cmap_name_ext, &enabled, SLTYPE_INT )) != 0 ) {
fprintf( stderr, "colormap_options_to_stringlist: Error creating save state stringlist\n" );
diff --git a/src/interface/display_info.c b/src/interface/display_info.c
index 8cb6d60..38fde2e 100644
--- a/src/interface/display_info.c
+++ b/src/interface/display_info.c
@@ -56,7 +56,7 @@ x_display_stuff( char *s, char *var_name )
int index;
char window_title[132];
- sprintf( window_title, "Attributes of \"%s\"", var_name );
+ snprintf( window_title, 130, "Attributes of \"%s\"", var_name );
index = get_free_display_popup_index();
if( index < 0 )
diff --git a/src/interface/filesel.c b/src/interface/filesel.c
index 98626f9..2236591 100644
--- a/src/interface/filesel.c
+++ b/src/interface/filesel.c
@@ -340,14 +340,16 @@ fs_list_dir( Stringlist **files, Stringlist **dirs )
DIR *cwd;
struct dirent *dir_entry;
char *tchar;
+ size_t slen;
cwd = opendir( "." );
while( (dir_entry = readdir( cwd )) != NULL ) {
if( (strcmp( dir_entry->d_name, ".") != 0) &&
(strcmp( dir_entry->d_name, "..") != 0)) {
if( fs_is_a_directory( dir_entry->d_name )) {
- tchar = (char *)malloc( sizeof(char) * (strlen(dir_entry->d_name) + 5)); /* add space for NULL and trailing slash */
- sprintf( tchar, "%s/", dir_entry->d_name );
+ slen = strlen(dir_entry->d_name) + 6; /* add space for NULL and trailing slash */
+ tchar = (char *)malloc( sizeof(char) * slen );
+ snprintf( tchar, slen-1, "%s/", dir_entry->d_name );
stringlist_add_string_ordered( dirs, tchar, NULL, SLTYPE_NULL );
free( tchar );
}
diff --git a/src/interface/plot_range.c b/src/interface/plot_range.c
index ddce8ef..4a1252a 100644
--- a/src/interface/plot_range.c
+++ b/src/interface/plot_range.c
@@ -66,8 +66,8 @@ x_plot_range( float old_min, float old_max,
char plot_range_min_string[128], plot_range_max_string[128],
*tstr;
- sprintf( plot_range_min_string, "%g", old_min );
- sprintf( plot_range_max_string, "%g", old_max );
+ snprintf( plot_range_min_string, 127, "%g", old_min );
+ snprintf( plot_range_max_string, 127, "%g", old_max );
*new_min = old_min;
*new_max = old_max;
diff --git a/src/interface/plot_xy.c b/src/interface/plot_xy.c
index 2436535..292d0dc 100644
--- a/src/interface/plot_xy.c
+++ b/src/interface/plot_xy.c
@@ -86,7 +86,7 @@ static void xaxis_range_callback(Widget w, XtPointer client_data, XtPointer cal
static void yaxis_range_callback(Widget w, XtPointer client_data, XtPointer call_data);
static void plot_XY_xaxis_log_callback(Widget w, XtPointer client_data, XtPointer call_data);
static void plot_XY_yaxis_log_callback(Widget w, XtPointer client_data, XtPointer call_data);
-void plot_XY_format_x_axis( Widget w, float val, char *s );
+void plot_XY_format_x_axis( Widget w, float val, char *s, size_t slen );
static void xy_track_pointer( Widget w, XtPointer client_data, XEvent *event,
Boolean *continue_to_dispatch );
static int locked_plot( void );
@@ -469,7 +469,7 @@ plot_XY_dump_callback(Widget widget, XtPointer client_data, XtPointer call_data)
exit( -1 );
}
- sprintf( filename, "ncview.dump" );
+ snprintf( filename, 1022, "ncview.dump" );
message = x_dialog( "File to dump to:", filename, TRUE );
if( message != MESSAGE_OK )
return;
@@ -693,7 +693,7 @@ plot_XY_yaxis_log_callback(Widget w, XtPointer client_data, XtPointer call_data)
}
void
-plot_XY_format_x_axis( Widget w, float val, char *s )
+plot_XY_format_x_axis( Widget w, float val, char *s, size_t slen )
{
int i = 0;
while( (plot_XY_widget[i] != w) && (i < MAX_PLOT_XY) )
@@ -703,7 +703,7 @@ plot_XY_format_x_axis( Widget w, float val, char *s )
exit( -1 );
}
- view_plot_XY_fmt_x_val( val, pXY_dimindex[i], s );
+ view_plot_XY_fmt_x_val( val, pXY_dimindex[i], s, slen );
}
void
diff --git a/src/interface/printer_options.c b/src/interface/printer_options.c
index 8f11813..b14a5c4 100644
--- a/src/interface/printer_options.c
+++ b/src/interface/printer_options.c
@@ -106,22 +106,22 @@ printer_options( PrintOptions *po )
XtVaSetValues( po_outf_text_widget, XtNstring, po->out_file_name, NULL );
/*** Margins ***/
- sprintf( tstr, "%g", po->page_x_margin );
+ snprintf( tstr, 1022, "%g", po->page_x_margin );
XtVaSetValues( po_xmar_text_widget, XtNstring, tstr, NULL );
- sprintf( tstr, "%g", po->page_upper_y_margin );
+ snprintf( tstr, 1022, "%g", po->page_upper_y_margin );
XtVaSetValues( po_ymar_top_text_widget, XtNstring, tstr, NULL );
- sprintf( tstr, "%g", po->page_lower_y_margin );
+ snprintf( tstr, 1022, "%g", po->page_lower_y_margin );
XtVaSetValues( po_ymar_bot_text_widget, XtNstring, tstr, NULL );
/*** Fonts ***/
XtVaSetValues( po_font_name_text_widget, XtNstring, po->font_name, NULL );
- sprintf( tstr, "%d", po->header_font_size );
+ snprintf( tstr, 1022, "%d", po->header_font_size );
XtVaSetValues( po_font_headsize_text_widget, XtNstring, tstr, NULL );
- sprintf( tstr, "%d", po->font_size );
+ snprintf( tstr, 1022, "%d", po->font_size );
XtVaSetValues( po_font_size_text_widget, XtNstring, tstr, NULL );
/*** Includes ***/
diff --git a/src/interface/range.c b/src/interface/range.c
index 2ea744d..d7f33a0 100644
--- a/src/interface/range.c
+++ b/src/interface/range.c
@@ -92,8 +92,8 @@ x_range( float old_min, float old_max,
char range_min_string[128], range_max_string[128],
global_values_string[128], *tstr;
- sprintf( range_min_string, "%g", old_min );
- sprintf( range_max_string, "%g", old_max );
+ snprintf( range_min_string, 127, "%g", old_min );
+ snprintf( range_max_string, 127, "%g", old_max );
*new_min = old_min;
*new_max = old_max;
@@ -101,7 +101,7 @@ x_range( float old_min, float old_max,
XtVaSetValues( range_min_text_widget, XtNstring, range_min_string, NULL );
XtVaSetValues( range_max_text_widget, XtNstring, range_max_string, NULL );
- sprintf( global_values_string, "%g to %g", global_min, global_max );
+ snprintf( global_values_string, 127, "%g to %g", global_min, global_max );
global_min_max.min = global_min;
global_min_max.max = global_max;
XtVaSetValues( range_global_values_widget,
@@ -411,10 +411,10 @@ range_symmetric_callback( Widget w, XtPointer client_data, XtPointer call_data)
new_max = biggest;
- sprintf( tstr, "%g", new_min );
+ snprintf( tstr, 130, "%g", new_min );
XtVaSetValues( range_min_text_widget, XtNstring, tstr, NULL );
- sprintf( tstr, "%g", new_max );
+ snprintf( tstr, 130, "%g", new_max );
XtVaSetValues( range_max_text_widget, XtNstring, tstr, NULL );
}
@@ -427,9 +427,9 @@ reset_global_callback( Widget w, XtPointer client_data, XtPointer call_data)
global_min = global_min_max.min;
global_max = global_min_max.max;
- sprintf( tstr, "%g", global_min );
+ snprintf( tstr, 99, "%g", global_min );
XtVaSetValues( range_min_text_widget, XtNstring, tstr, NULL );
- sprintf( tstr, "%g", global_max );
+ snprintf( tstr, 99, "%g", global_max );
XtVaSetValues( range_max_text_widget, XtNstring, tstr, NULL );
}
diff --git a/src/interface/set_options.c b/src/interface/set_options.c
index 89449cd..ea7acf3 100644
--- a/src/interface/set_options.c
+++ b/src/interface/set_options.c
@@ -199,13 +199,9 @@ set_options( void )
handle_colormap_list_change();
/* Save persistent options in our state file */
- state_to_save = NULL; /* signal we want to create new stringlist */
- if( (err = colormap_options_to_stringlist( &state_to_save )) != 0 ) {
- sprintf( error_message, "Error %d while trying to save colormap options. Look in launching window to see more information.\n", err );
- in_error( error_message );
- }
+ state_to_save = get_persistent_state(); /* NOTE! NOT just the X state, entire state */
if( (err = write_state_to_file( state_to_save )) != 0 ) {
- sprintf( error_message, "Error %d while trying to save options file. Look in launching window to see more information.\n", err );
+ snprintf( error_message, 2000, "Error %d while trying to save options file. Look in launching window to see more information.\n", err );
in_error( error_message );
}
stringlist_delete_entire_list( state_to_save );
@@ -461,7 +457,7 @@ set_options_init()
for( ll=0; ll<n_colormaps; ll++ ) {
- sprintf( cmap_widget_name, "opt_cbsel_cmap_entry_widget_%04ld", ll );
+ snprintf( cmap_widget_name, 1000, "opt_cbsel_cmap_entry_widget_%04ld", ll );
opt_cbsel_cmap_entry_widget[ll] = XtVaCreateManagedWidget(
cmap_widget_name,
boxWidgetClass,
@@ -472,7 +468,7 @@ set_options_init()
NULL );
prev_widget = opt_cbsel_cmap_entry_widget[ll];
- sprintf( cmap_widget_name, "opt_cbsel_cmap_name_widget_%04ld", ll );
+ snprintf( cmap_widget_name, 1000, "opt_cbsel_cmap_name_widget_%04ld", ll );
opt_cbsel_name_widget[ll] = XtVaCreateManagedWidget(
cmap_widget_name,
labelWidgetClass,
@@ -482,7 +478,7 @@ set_options_init()
XtNwidth, CMAP_NAME_WIDTH,
NULL );
- sprintf( cmap_widget_name, "opt_cbsel_cmap_enable_widget_%04ld", ll );
+ snprintf( cmap_widget_name, 1000, "opt_cbsel_cmap_enable_widget_%04ld", ll );
opt_cbsel_enable_widget[ll] = XtVaCreateManagedWidget(
cmap_widget_name,
toggleWidgetClass,
@@ -494,7 +490,7 @@ set_options_init()
NULL );
XtAddCallback( opt_cbsel_enable_widget[ll], XtNcallback, cbsel_enable_callback, (XtPointer)ll );
- sprintf( cmap_widget_name, "opt_cbsel_cmap_top_widget_%04ld", ll );
+ snprintf( cmap_widget_name, 1000, "opt_cbsel_cmap_top_widget_%04ld", ll );
opt_cbsel_top_widget[ll] = XtVaCreateManagedWidget(
cmap_widget_name,
commandWidgetClass,
@@ -505,7 +501,7 @@ set_options_init()
NULL );
XtAddCallback( opt_cbsel_top_widget[ll], XtNcallback, cbsel_top_callback, (XtPointer)ll );
- sprintf( cmap_widget_name, "opt_cbsel_cmap_up_widget_%04ld", ll );
+ snprintf( cmap_widget_name, 1000, "opt_cbsel_cmap_up_widget_%04ld", ll );
opt_cbsel_up_widget[ll] = XtVaCreateManagedWidget(
cmap_widget_name,
commandWidgetClass,
@@ -516,7 +512,7 @@ set_options_init()
NULL );
XtAddCallback( opt_cbsel_up_widget[ll], XtNcallback, cbsel_up_callback, (XtPointer)ll );
- sprintf( cmap_widget_name, "opt_cbsel_cmap_down_widget_%04ld", ll );
+ snprintf( cmap_widget_name, 1000, "opt_cbsel_cmap_down_widget_%04ld", ll );
opt_cbsel_down_widget[ll] = XtVaCreateManagedWidget(
cmap_widget_name,
commandWidgetClass,
@@ -527,7 +523,7 @@ set_options_init()
NULL );
XtAddCallback( opt_cbsel_down_widget[ll], XtNcallback, cbsel_down_callback, (XtPointer)ll );
- sprintf( cmap_widget_name, "opt_cbsel_cmap_bottom_widget_%04ld", ll );
+ snprintf( cmap_widget_name, 1000, "opt_cbsel_cmap_bottom_widget_%04ld", ll );
opt_cbsel_bottom_widget[ll] = XtVaCreateManagedWidget(
cmap_widget_name,
commandWidgetClass,
@@ -538,7 +534,7 @@ set_options_init()
NULL );
XtAddCallback( opt_cbsel_bottom_widget[ll], XtNcallback, cbsel_bottom_callback, (XtPointer)ll );
- sprintf( cmap_widget_name, "opt_cbsel_cmap_cbar_widget_%04ld", ll );
+ snprintf( cmap_widget_name, 1000, "opt_cbsel_cmap_cbar_widget_%04ld", ll );
opt_cbsel_cbar_widget[ll] = XtVaCreateManagedWidget(
cmap_widget_name,
simpleWidgetClass,
@@ -1008,3 +1004,31 @@ static void cmaps_set_current( Cmaplist *cmlist )
NULL );
}
}
+
+/******************************************************************************************************
+ * We save persistent options in a stringlist, which gets written out to our .rc file. This
+ * routine generates the stringlist to save from the point of view of the X interface
+ * routines. I.e., it generates a stringlist with all the options that the X interface routines
+ * would like to save.
+ *
+ * This generates and allocates space for a new stringlist, so when the calling routine
+ * is done with the stringlist (by saving it to a file, or example), then the calling
+ * routine must delete the stringlist as so:
+ *
+ * state_to_save = get_persistent_X_state();
+ * stringlist_delete_entire_list( state_to_save );
+ */
+ Stringlist *
+get_persistent_X_state()
+{
+ Stringlist *state_to_save = NULL; /* signal we want to create new stringlist */
+ int err;
+ char error_message[ 2040 ];
+
+ if( (err = colormap_options_to_stringlist( &state_to_save )) != 0 ) {
+ snprintf( error_message, 2000, "Error %d while trying to save colormap options. Look in launching window to see more information.\n", err );
+ in_error( error_message );
+ }
+
+ return( state_to_save );
+}
diff --git a/src/interface/x_interface.c b/src/interface/x_interface.c
index c3b0972..5dcb0b2 100644
--- a/src/interface/x_interface.c
+++ b/src/interface/x_interface.c
@@ -469,7 +469,7 @@ void x_parse_args( int *p_argc, char **argv )
fallback_resources, /* for missing app-defaults file */
NULL ); /* terminate varargs list */
- sprintf( program_title, "Ncview %.2f\n", PROGRAM_VERSION );
+ snprintf( program_title, 130, "Ncview %s\n", PROGRAM_VERSION_STRING );
XtVaSetValues( topLevel, XtNtitle, program_title, NULL );
debug = 0;
@@ -1258,8 +1258,8 @@ void x_init_widgets_varsel_menu_inner( Widget parent, long *varlist, int nv, cha
NCVar *cursor;
int i_cursor, i;
- sprintf( temp, "(%d) %s vars", nv, tag );
- sprintf( var_menu_name, "var_menu_%s", tag );
+ snprintf( temp, 1020, "(%d) %s vars", nv, tag );
+ snprintf( var_menu_name, 1020, "var_menu_%s", tag );
varsel_menu_widget = XtVaCreateManagedWidget(
"varsel_menu",
@@ -1282,7 +1282,7 @@ void x_init_widgets_varsel_menu_inner( Widget parent, long *varlist, int nv, cha
cursor = cursor->next;
i_cursor++;
}
- sprintf( widget_name, "%s", cursor->name );
+ snprintf( widget_name, 1020, "%s", cursor->name );
list_of_sel_widgets[i] = XtVaCreateManagedWidget(
widget_name,
smeBSBObjectClass,
@@ -1383,7 +1383,7 @@ void x_init_widgets_varsel_list( Widget parent )
}
if( i == 0 ) {
/* The very first button box! */
- sprintf( widget_name, "varselbox_%1d", which_box+1 );
+ snprintf( widget_name, 127, "varselbox_%1d", which_box+1 );
*(var_selection_widget+which_box) = XtVaCreateManagedWidget(
widget_name,
boxWidgetClass,
@@ -1391,7 +1391,7 @@ void x_init_widgets_varsel_list( Widget parent )
XtNorientation, XtorientHorizontal,
XtNborderWidth, 0,
NULL);
- sprintf( widget_name, "varlist_label_%1d", which_box+1 );
+ snprintf( widget_name, 127, "varlist_label_%1d", which_box+1 );
varlist_label_widget = XtVaCreateManagedWidget(
widget_name,
labelWidgetClass,
@@ -1404,7 +1404,7 @@ void x_init_widgets_varsel_list( Widget parent )
}
else if( (i % app_data.n_vars_per_row) == 0 ) {
/* A new button box! */
- sprintf( widget_name, "box_%1d", which_box+1 );
+ snprintf( widget_name, 127, "box_%1d", which_box+1 );
*(var_selection_widget+which_box) = XtVaCreateManagedWidget(
widget_name,
boxWidgetClass,
@@ -1413,7 +1413,7 @@ void x_init_widgets_varsel_list( Widget parent )
XtNborderWidth, 0,
XtNfromVert, *(var_selection_widget + which_box - 1),
NULL);
- sprintf( widget_name, "varlist_label_%1d", which_box+1 );
+ snprintf( widget_name, 127, "varlist_label_%1d", which_box+1 );
varlist_label_widget = XtVaCreateManagedWidget(
widget_name,
labelWidgetClass,
@@ -1425,7 +1425,7 @@ void x_init_widgets_varsel_list( Widget parent )
which_box++;
}
- sprintf( widget_name, "varsel_%s", var->name );
+ snprintf( widget_name, 127, "varsel_%s", var->name );
state = False;
if( i == 0 ) /* first variable button */
*(varlist_widget+i) = XtVaCreateManagedWidget(
@@ -2433,13 +2433,13 @@ void x_indicate_active_dim( int dimension, char *dim_name )
char new_label[ 132 ];
if( dimension == DIMENSION_X )
- sprintf( new_label, "X:" );
+ snprintf( new_label, 130, "X:" );
else if( dimension == DIMENSION_Y )
- sprintf( new_label, "Y:" );
+ snprintf( new_label, 130, "Y:" );
else if( dimension == DIMENSION_SCAN )
- sprintf( new_label, "Scan:" );
+ snprintf( new_label, 130, "Scan:" );
else if( dimension == DIMENSION_NONE )
- sprintf( new_label, " " );
+ snprintf( new_label, 130, " " );
else
{
fprintf( stderr, "ncview: x_indicate_active_dim: unknown " );
@@ -2740,7 +2740,7 @@ void x_make_dim_button_util( int dimension, Stringlist *dim_list, char *prefix,
i = 0;
while( s != NULL )
{
- sprintf( widget_name, "%s%s", prefix, s->string );
+ snprintf( widget_name, 62, "%s%s", prefix, s->string );
if( i == 0 )
*(*dimlist_widget + i) = XtVaCreateManagedWidget(
widget_name,
@@ -2965,18 +2965,18 @@ void x_fill_dim_info( NCDim *d, int please_flip )
if( strcmp( widget_name, d->name ) == 0 ) {
if( please_flip )
- sprintf( temp_label, "%g", d->max );
+ snprintf( temp_label, 130, "%g", d->max );
else
- sprintf( temp_label, "%g", d->min );
+ snprintf( temp_label, 130, "%g", d->min );
XtVaSetValues( *(diminfo_min_widget+i),
XtNlabel, temp_label,
XtNwidth, app_data.dimlabel_width,
NULL );
if( please_flip )
- sprintf( temp_label, "%g", d->min );
+ snprintf( temp_label, 130, "%g", d->min );
else
- sprintf( temp_label, "%g", d->max );
+ snprintf( temp_label, 130, "%g", d->max );
XtVaSetValues( *(diminfo_max_widget+i),
XtNlabel, temp_label,
XtNwidth, app_data.dimlabel_width,
@@ -3098,7 +3098,7 @@ void x_init_dim_info( Stringlist *dims )
for( ll=0; ll<n_dims; ll++ )
{
- sprintf( widget_name, "diminfo_row_%1ld", ll );
+ snprintf( widget_name, 127, "diminfo_row_%1ld", ll );
if( ll == 0 )
*(diminfo_row_widget+ll) = XtVaCreateManagedWidget(
widget_name,
@@ -3120,7 +3120,7 @@ void x_init_dim_info( Stringlist *dims )
XtNwidth, bb_width,
NULL);
- sprintf( widget_name, "diminfo_dim_%1ld", ll );
+ snprintf( widget_name, 127, "diminfo_dim_%1ld", ll );
*(diminfo_dim_widget+ll) = XtVaCreateManagedWidget(
widget_name,
labelWidgetClass,
@@ -3131,7 +3131,7 @@ void x_init_dim_info( Stringlist *dims )
XtNborderWidth, 0,
NULL);
- sprintf( widget_name, "diminfo_name_%1ld", ll );
+ snprintf( widget_name, 127, "diminfo_name_%1ld", ll );
*(diminfo_name_widget+ll) = XtVaCreateManagedWidget(
widget_name,
labelWidgetClass,
@@ -3141,7 +3141,7 @@ void x_init_dim_info( Stringlist *dims )
XtNborderWidth, 0,
NULL);
- sprintf( widget_name, "diminfo_min_%1ld", ll );
+ snprintf( widget_name, 127, "diminfo_min_%1ld", ll );
*(diminfo_min_widget+ll) = XtVaCreateManagedWidget(
widget_name,
labelWidgetClass,
@@ -3151,7 +3151,7 @@ void x_init_dim_info( Stringlist *dims )
XtNborderWidth, 0,
NULL);
- sprintf( widget_name, "diminfo_cur_%1ld", ll );
+ snprintf( widget_name, 127, "diminfo_cur_%1ld", ll );
*(diminfo_cur_widget+ll) = XtVaCreateManagedWidget(
widget_name,
commandWidgetClass,
@@ -3175,7 +3175,7 @@ void x_init_dim_info( Stringlist *dims )
XtParseTranslationTable(
"Ctrl<Btn3Down>,<Btn3Up>: diminfo_cur_mod4()" ));
- sprintf( widget_name, "diminfo_max_%1ld", ll );
+ snprintf( widget_name, 127, "diminfo_max_%1ld", ll );
*(diminfo_max_widget+ll) = XtVaCreateManagedWidget(
widget_name,
labelWidgetClass,
@@ -3185,7 +3185,7 @@ void x_init_dim_info( Stringlist *dims )
XtNborderWidth, 0,
NULL);
- sprintf( widget_name, "diminfo_units_%1ld", ll );
+ snprintf( widget_name, 127, "diminfo_units_%1ld", ll );
*(diminfo_units_widget+ll) = XtVaCreateManagedWidget(
widget_name,
labelWidgetClass,
@@ -3529,7 +3529,7 @@ void dump_to_png( unsigned char *data, size_t width, size_t height, size_t frame
if( error_state == 1 ) return;
- sprintf( filename, "frame.%05ld.png", frameno );
+ snprintf( filename, 2047, "frame.%05ld.png", frameno );
frameno++;
/* Open binary output file */
diff --git a/src/ncview.c b/src/ncview.c
index 5cc4bd4..1f3be77 100644
--- a/src/ncview.c
+++ b/src/ncview.c
@@ -80,13 +80,21 @@ static int get_cmaps_from_dir( char *dir_name );
int
main( int argc, char **argv )
{
- Stringlist *input_files;
+ Stringlist *input_files, *state_to_save;
+ int err, found_state_file;
- /* Initialize misc constants, AND read in the previous
- * run's saved state file
- */
+ /* Initialize misc constants */
initialize_misc();
+ /* Read in our state file from a previous run of ncview
+ */
+ read_in_state = NULL; /* Note: a global var. Set to null to flag following routine to make a new stringlist */
+ err = read_state_from_file( &read_in_state );
+ if( err == 0 )
+ found_state_file = TRUE;
+ else
+ found_state_file = FALSE;
+
in_parse_args ( &argc, argv );
input_files = parse_options ( argc, argv );
determine_file_type ( input_files );
@@ -113,6 +121,17 @@ main( int argc, char **argv )
in_indicate_active_var( variables->name );
}
+ /* If we didn't find a state file (".ncviewrc") when we started up, then
+ * write a new one out now that we are all initialized
+ */
+ if( found_state_file == FALSE ) {
+ state_to_save = get_persistent_state();
+ if( (err = write_state_to_file( state_to_save )) != 0 ) {
+ fprintf( stderr, "Error %d while trying to save options file \"$HOME/.ncviewrc\".\n", err );
+ }
+ stringlist_delete_entire_list( state_to_save );
+ }
+
process_user_input();
return(0);
@@ -309,8 +328,6 @@ parse_options( int argc, char *argv[] )
void
initialize_misc()
{
- int err;
-
print_disclaimer();
udu_utinit( NULL );
@@ -349,12 +366,6 @@ initialize_misc()
framestore.frame = NULL;
framestore.valid = FALSE;
- /* Read in our state file from a previous run of ncview
- */
- read_in_state = NULL; /* flag to make a new stringlist */
- err = read_state_from_file( &read_in_state );
- if( err < 0 )
- printf( "Note: trying to read in the ncview initialization file $HOME/.ncviewrc resulted in error %d\n", err );
}
/***********************************************************************************************/
@@ -433,6 +444,11 @@ get_cmaps_from_dir( char *dir_name )
void
init_cmaps_from_data()
{
+/* the following are original colormaps from ncview */
+
+ init_cmap_from_data( "3gauss", cmap_3gauss );
+ init_cmap_from_data( "detail", cmap_detail );
+ init_cmap_from_data( "ssec", cmap_ssec );
/* A. Shchepetkin: new colormaps are added here */
@@ -447,18 +463,15 @@ init_cmaps_from_data()
init_cmap_from_data( "jet", cmap_jet );
init_cmap_from_data( "wheel", cmap_wheel );
-/* the following are original colormaps from ncview */
+/* the following are the rest of the original colormaps from ncview */
- init_cmap_from_data( "3gauss", cmap_3gauss );
init_cmap_from_data( "3saw", cmap_3saw );
init_cmap_from_data( "bw", cmap_bw );
init_cmap_from_data( "default", cmap_default );
- init_cmap_from_data( "detail", cmap_detail );
init_cmap_from_data( "extrema", cmap_extrema );
init_cmap_from_data( "helix", cmap_helix );
init_cmap_from_data( "helix2", cmap_helix2 );
init_cmap_from_data( "hotres", cmap_hotres );
- init_cmap_from_data( "ssec", cmap_ssec );
}
/***********************************************************************************************/
@@ -489,6 +502,7 @@ init_cmap_from_file( char *dir_name, char *file_name )
int i, nentries, r_entry, g_entry, b_entry;
char line[ 128 ], *long_file_name;
unsigned char r[256], g[256], b[256];
+ size_t slen;
if( options.debug )
fprintf( stderr, " ... initting cmap >%s<\n", file_name );
@@ -507,8 +521,9 @@ init_cmap_from_file( char *dir_name, char *file_name )
}
/* Read in the r, g, b values */
- long_file_name = (char *)malloc( sizeof(char)*( strlen(dir_name) + strlen(file_name) + 5 )); /* add space for intermediate slash and trailing NULL */
- sprintf( long_file_name, "%s/%s", dir_name, file_name );
+ slen = strlen(file_name) + strlen(dir_name) + 5; /* add space for intermediate slash and trailing NULL */
+ long_file_name = (char *)malloc( sizeof(char)*slen); /* add space for intermediate slash and trailing NULL */
+ snprintf( long_file_name, slen, "%s/%s", dir_name, file_name );
if( (cmap_file = fopen( long_file_name, "r" )) == NULL ) {
fprintf( stderr, "ncview.c: init_cmap_from_file: error " );
fprintf( stderr, "opening file %s\n", long_file_name );
diff --git a/src/ncview.defines.h b/src/ncview.defines.h
index a21dc9b..d117c55 100644
--- a/src/ncview.defines.h
+++ b/src/ncview.defines.h
@@ -1,6 +1,6 @@
/*
* Ncview by David W. Pierce. A visual netCDF file viewer.
- * Copyright (C) 1993 through 2010 by David W. Pierce
+ * Copyright (C) 1993 through 2011 by David W. Pierce
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
@@ -31,9 +31,9 @@
#include <udunits2.h>
#endif
-#define PROGRAM_ID "Ncview 2.1 David W. Pierce 19 July 2011"
-#define PROGRAM_VERSION 2.1
-#define APP_RES_VERSION 1.93
+#define PROGRAM_ID "Ncview 2.1.1 David W. Pierce 1 Aug 2011"
+#define PROGRAM_VERSION_STRING "2.1.1"
+#define APP_RES_VERSION 1.93
#ifndef TRUE
#define TRUE 1
diff --git a/src/ncview.protos.h b/src/ncview.protos.h
index a839c30..6fab2e0 100644
--- a/src/ncview.protos.h
+++ b/src/ncview.protos.h
@@ -127,7 +127,7 @@ void expand_data ( float *big_data, View *v, size_t array_size );
void check_ranges ( NCVar *var );
char *limit_string ( char *s );
int *gen_overlay ( View *v, char *overlay_fname );
-void fmt_time ( char *temp_string, double new_dimval, NCDim *dim, int include_granularity );
+void fmt_time ( char *temp_string, size_t temp_string_len, double new_dimval, NCDim *dim, int include_granularity );
int n_vars_in_list ( NCVar *v );
void set_blowup_type ( int new_type );
int n_strings_in_list ( Stringlist *s );
@@ -294,7 +294,7 @@ void set_max_from_curdata ( void );
void beep ( void );
void invalidate_all_saveframes( void );
void view_set_XY_plot_axis( String );
-void view_plot_XY_fmt_x_val( float val, int dimindex, char *s );
+void view_plot_XY_fmt_x_val( float val, int dimindex, char *s, size_t slen );
void view_change_dat ( size_t index, float new_val );
void view_get_scaled_size ( int blowup, size_t old_nx, size_t old_ny, size_t *new_nx, size_t *new_ny );
void view_change_transform( int delta );
@@ -321,6 +321,7 @@ int overlay_custom_n ( void );
void options_set_overlay_filename( char *fn );
void set_options_init();
void set_options( void );
+Stringlist *get_persistent_X_state();
/******************************************************************************
* in filesel.c
@@ -351,12 +352,12 @@ int x_plot_range( float old_min, float old_max, float *new_min, float *new_max,
void udu_utinit( char *path );
int udu_utistime( char *dimname, char *units );
int udu_calc_tgran( int fileid, NCVar *v, int dimid );
-void udu_fmt_time( char *temp_string, double new_dimval, NCDim *dim, int include_granularity );
+void udu_fmt_time( char *temp_string, size_t temp_string_len, double new_dimval, NCDim *dim, int include_granularity );
/******************************************************************************
* in epic_time.c
*/
-void epic_fmt_time( char *temp_string, double new_dimval, NCDim *dim );
+void epic_fmt_time( char *temp_string, size_t temp_string_len, double new_dimval, NCDim *dim );
int epic_istime0( int fileid, NCVar *v, NCDim *d );
int epic_calc_tgran( int fileid, NCDim *d );
@@ -415,6 +416,7 @@ int colormap_options_to_stringlist( Stringlist **sl );
*/
int write_state_to_file( Stringlist *state_to_save );
int read_state_from_file( Stringlist **state );
+Stringlist *get_persistent_state();
/******************************************************************************
* in file interface/util.c
diff --git a/src/overlay.c b/src/overlay.c
index 5af6c89..fc57509 100644
--- a/src/overlay.c
+++ b/src/overlay.c
@@ -321,7 +321,7 @@ gen_overlay( View *v, char *overlay_fname )
/* Open the overlay file */
if( (f = fopen(overlay_fname, "r")) == NULL ) {
- sprintf( err_mess, "Error: can't open overlay file named \"%s\"\n",
+ snprintf( err_mess, 1024, "Error: can't open overlay file named \"%s\"\n",
overlay_fname );
in_error( err_mess );
return( NULL );
@@ -330,21 +330,21 @@ gen_overlay( View *v, char *overlay_fname )
/* Make sure it is a valid overlay file
*/
if( fgets(line, 80, f) == NULL ) {
- sprintf( err_mess, "Error trying to read overlay file named \"%s\"\n",
+ snprintf( err_mess, 1024, "Error trying to read overlay file named \"%s\"\n",
overlay_fname );
in_error( err_mess );
return( NULL );
}
for( i=0; i<strlen(id_string); i++ )
if( line[i] != id_string[i] ) {
- sprintf( err_mess, "Error trying to read overlay file named \"%s\"\nFile does not start with \"%s version-num\"\n",
+ snprintf( err_mess, 1024, "Error trying to read overlay file named \"%s\"\nFile does not start with \"%s version-num\"\n",
overlay_fname, id_string );
in_error( err_mess );
return( NULL );
}
sscanf( line, "%*s %f", &version );
if( (version < 0.95) || (version > 1.05)) {
- sprintf( err_mess, "Error, overlay file has unknown version number: %f\nI am set up for version 1.0\n", version );
+ snprintf( err_mess, 1024, "Error, overlay file has unknown version number: %f\nI am set up for version 1.0\n", version );
in_error( err_mess );
return( NULL );
}
diff --git a/src/overlay.orig.c b/src/overlay.orig.c
deleted file mode 100644
index 7ae8168..0000000
--- a/src/overlay.orig.c
+++ /dev/null
@@ -1,441 +0,0 @@
-/*
- * Ncview by David W. Pierce. A visual netCDF file viewer.
- * Copyright (C) 1993 through 2010 David W. Pierce
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as
- * published by the Free Software Foundation.
- *
- * This program 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 General Public License, version 3, for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * David W. Pierce
- * 6259 Caminito Carrean
- * San Diego, CA 92122
- * pierce at cirrus.ucsd.edu
- */
-
-
-#include "ncview.includes.h"
-#include "ncview.defines.h"
-#include "ncview.protos.h"
-
-/* These are the arrays of coastline and outline data build into ncview
- * (i.e, they are NOT required to be loaded from an external directory)
- */
-#include "overlay_coasts_p08deg.h"
-#include "overlay_coasts_p8deg.h"
-#include "overlay_usa.h"
-
-/* Number and order of these must match the defines given in ncview.defines.h!
- * They are used as the labels for the radio buttons
- */
-char *my_overlay_names[] = { "None",
- "0.8 degree coastlines",
- "0.08 degree coastlines",
- "USA states",
- "custom" };
-
-extern View *view;
-extern Options options;
-
-static int my_current_overlay;
-
-static int gen_xform( float value, int n, float *dimvals );
-static int *gen_overlay_internal( View *v, float *data, long n );
-static void do_overlay_inner( View *v, float *data, long nvals, int suppress_screen_changes );
-
-/*====================================================================================
- * This routine is only called when the state of the overlay is being changed
- */
- void
-do_overlay( int n, char *custom_filename, int suppress_screen_changes )
-{
- if( view == NULL ) {
- x_error( "You must select a variable before turning on overlays" );
- return;
- }
-
- /* Free space for previous overlay */
- if( options.overlay->doit && (options.overlay->overlay != NULL ))
- free( options.overlay->overlay );
-
- switch(n) {
-
- case OVERLAY_NONE:
- options.overlay->doit = FALSE;
- if( ! suppress_screen_changes ) {
- view->data_status = VDS_INVALID;
- invalidate_all_saveframes();
- change_view( 0, FRAMES );
- }
- break;
-
- case OVERLAY_P8DEG:
- do_overlay_inner( view, overlay_coasts_p8deg, n_overlay_coasts_p8deg,
- suppress_screen_changes );
- break;
-
- case OVERLAY_P08DEG:
- do_overlay_inner( view, overlay_coasts_p08deg, n_overlay_coasts_p08deg,
- suppress_screen_changes );
- break;
-
- case OVERLAY_USA:
- do_overlay_inner( view, overlay_usa, n_overlay_usa,
- suppress_screen_changes );
- break;
-
- case OVERLAY_CUSTOM:
- if( (custom_filename == NULL) || (strlen(custom_filename) == 0)) {
- in_error( "Specified custom overlay filename is not a valid filename!\n" );
- return;
- }
- options.overlay->overlay = gen_overlay( view, custom_filename );
- if( options.overlay->overlay != NULL ) {
- options.overlay->doit = TRUE;
- if( ! suppress_screen_changes ) {
- invalidate_all_saveframes();
- change_view( 0, FRAMES );
- }
- }
- break;
-
- default:
- fprintf( stderr, "Error, do_overlay called with an unknown index = %d\n", n );
- exit(-1);
- }
-
- my_current_overlay = n;
-}
-
-/*=========================================================================================
- */
- void
-do_overlay_inner( View *v, float *data, long nvals, int suppress_screen_changes )
-{
- options.overlay->overlay = gen_overlay_internal( v, data, nvals );
- if( options.overlay->overlay != NULL ) {
- options.overlay->doit = TRUE;
- if( ! suppress_screen_changes ) {
- invalidate_all_saveframes();
- change_view( 0, FRAMES );
- }
- }
-}
-
-/*=========================================================================================
- * This is called just once, when ncview starts up. In particular,
- * it is NOT called every time we start a new overlay.
- */
- void
-overlay_init()
-{
- my_current_overlay = OVERLAY_NONE;
- options.overlay->overlay = NULL;
- options.overlay->doit = FALSE;
-}
-
-/*======================================================================================
- * NOTE: overlay_base_dir must already be allocated to length 'n'
- */
- void
-determine_overlay_base_dir( char *overlay_base_dir, int n )
-{
- char *dir;
-
- dir = (char *)getenv( "NCVIEWBASE" );
- if( dir == NULL ) {
-#ifdef NCVIEW_LIB_DIR
- if( strlen(NCVIEW_LIB_DIR) >= n ) {
- fprintf( stderr, "Error, routine determine_overlay_base_dir, string NCVIEW_LIB_DIR too long! Max=%d\n", n );
- exit(-1);
- }
- strcpy( overlay_base_dir, NCVIEW_LIB_DIR );
-#else
- strcpy( overlay_base_dir, "." );
-#endif
- }
- else
- {
- if( strlen(dir) >= n ) {
- fprintf( stderr, "Error, routine determine_overlay_base_dir, length of dir is too long! Max=%d\n", n );
- exit(-1);
- }
- strcpy( overlay_base_dir, dir );
- }
-}
-
-/******************************************************************************
- * Generate an overlay from data in an overlay file. There are 'nvals'
- * PAIRS of coordinates (for a shoreline, for example). data[0] is the
- * first X coordinate, data[1] is the first Y coordinate, data[2] is the
- * second X coordinate, etc.
- */
- int *
-gen_overlay_internal( View *v, float *data, long nvals )
-{
- NCDim *dim_x, *dim_y;
- size_t x_size, y_size, ii, jj, min_ii, min_jj, cursor_place[MAX_NC_DIMS];
- int *overlay, has_bnds, x_is_mapped, y_is_mapped;
- float x, y, *dimval_x_2d, *dimval_y_2d;
- long i, j, kk;
- nc_type dimval_type;
- double tval, bnds_min, bnds_max, dx, dy, dist, mindist;
- char cval[1024];
-
- dim_x = *(v->variable->dim + v->x_axis_id);
- dim_y = *(v->variable->dim + v->y_axis_id);
-
- x_size = *(v->variable->size + v->x_axis_id);
- y_size = *(v->variable->size + v->y_axis_id);
-
- overlay = (int *)malloc( x_size*y_size*sizeof(int) );
- if( overlay == NULL ) {
- in_error( "Malloc of overlay field failed\n" );
- return( NULL );
- }
- for( ii=0; ii<x_size*y_size; ii++ )
- *(overlay+ii) = 0;
-
- x_is_mapped = (v->variable->dim_map_info[ v->x_axis_id ] != NULL);
- y_is_mapped = (v->variable->dim_map_info[ v->y_axis_id ] != NULL);
- if( x_is_mapped || y_is_mapped ) {
-printf( "OVERLAY: is mapped %ld %ld %d\n", x_size, y_size, v->variable->n_dims );
- dimval_x_2d = (float *)malloc( x_size*y_size*sizeof(float) );
- dimval_y_2d = (float *)malloc( x_size*y_size*sizeof(float) );
- if( (dimval_x_2d==NULL) || (dimval_y_2d==NULL) ) {
- in_error( "Malloc of overlay (distance) field failed\n" );
- return( NULL );
- }
- for( ii=0; ii<v->variable->n_dims; ii++ )
- cursor_place[ii] = v->var_place[ii];
-
- /* Step 1. Get temporary arrays that hold full 2-D X and Y values */
-printf( "OVERLAY: step 1\n" );
- for( jj=0; jj<y_size; jj++ )
- for( ii=0; ii<x_size; ii++ ) {
- cursor_place[ v->x_axis_id ] = ii;
- cursor_place[ v->y_axis_id ] = jj;
-
- /* Get X value */
- dimval_type = fi_dim_value( v->variable, v->x_axis_id, ii, &tval, cval,
- &has_bnds, &bnds_min, &bnds_max, cursor_place );
- if( dimval_type == NC_DOUBLE )
- dimval_x_2d[ii + jj*x_size] = tval;
- else
- dimval_x_2d[ii + jj*x_size] = dim_x->values[ii];
-
- /* Get Y value */
- dimval_type = fi_dim_value( v->variable, v->y_axis_id, ii, &tval, cval,
- &has_bnds, &bnds_min, &bnds_max, cursor_place );
- if( dimval_type == NC_DOUBLE )
- dimval_y_2d[ii + jj*x_size] = tval;
- else
- dimval_y_2d[ii + jj*x_size] = dim_y->values[jj];
- }
-
- /* Step 2. For each point specified in the overlay file, get the CLOSEST
- * point in the 2-D X and Y arrays.
- */
-printf( "OVERLAY: step 2\n" );
- for( kk=0; kk<nvals; kk+=2 ) {
- x = data[kk];
- y = data[kk+1];
-
- mindist = 1.e99;
- for( jj=0; jj<y_size; jj++ )
- for( ii=0; ii<x_size; ii++ ) {
- dx = x - dimval_x_2d[ii+jj*x_size];
- dy = y - dimval_y_2d[ii+jj*x_size];
- dist = dx*dx + dy*dy;
- if( dist < mindist ) {
- mindist = dist;
- min_ii = ii; /* here, 'min' means MINIMUM DISTANCE, not min value of ii */
- min_jj = jj;
- }
- }
-
- /* Disallow points on the edges */
- if( (min_ii != 0) && (min_ii != x_size) && (min_jj != 0) && (min_jj != y_size))
- *(overlay + min_jj*x_size + min_ii) = 1;
- }
- free(dimval_x_2d);
- free(dimval_y_2d);
- }
- else
- {
- for( ii=0; ii<nvals; ii+=2 ) {
- x = data[ii];
- y = data[ii+1];
-
- i = gen_xform( x, x_size, dim_x->values );
- if( i == -2 )
- return( NULL );
- j = gen_xform( y, y_size, dim_y->values );
- if( j == -2 )
- return( NULL );
- if( (i > 0) && (j > 0))
- *(overlay + j*x_size + i) = 1;
- }
- }
-
- return( overlay );
-}
-
-/******************************************************************************
- * Generate an overlay from data in an overlay file.
- */
- int *
-gen_overlay( View *v, char *overlay_fname )
-{
- FILE *f;
- char err_mess[1024], line[80], *id_string="NCVIEW-OVERLAY";
- float x, y, version;
- long i, j;
- size_t x_size, y_size;
- int *overlay;
- NCDim *dim_x, *dim_y;
-
- /* Open the overlay file */
- if( (f = fopen(overlay_fname, "r")) == NULL ) {
- sprintf( err_mess, "Error: can't open overlay file named \"%s\"\n",
- overlay_fname );
- in_error( err_mess );
- return( NULL );
- }
-
- /* Make sure it is a valid overlay file
- */
- if( fgets(line, 80, f) == NULL ) {
- sprintf( err_mess, "Error trying to read overlay file named \"%s\"\n",
- overlay_fname );
- in_error( err_mess );
- return( NULL );
- }
- for( i=0; i<strlen(id_string); i++ )
- if( line[i] != id_string[i] ) {
- sprintf( err_mess, "Error trying to read overlay file named \"%s\"\nFile does not start with \"%s version-num\"\n",
- overlay_fname, id_string );
- in_error( err_mess );
- return( NULL );
- }
- sscanf( line, "%*s %f", &version );
- if( (version < 0.95) || (version > 1.05)) {
- sprintf( err_mess, "Error, overlay file has unknown version number: %f\nI am set up for version 1.0\n", version );
- in_error( err_mess );
- return( NULL );
- }
-
- dim_x = *(v->variable->dim + v->x_axis_id);
- dim_y = *(v->variable->dim + v->y_axis_id);
-
- x_size = *(v->variable->size + v->x_axis_id);
- y_size = *(v->variable->size + v->y_axis_id);
-
- overlay = (int *)malloc( x_size*y_size*sizeof(int) );
- if( overlay == NULL ) {
- in_error( "Malloc of overlay field failed\n" );
- return( NULL );
- }
- for( i=0; i<x_size*y_size; i++ )
- *(overlay+i) = 0;
-
- /* Read in the overlay file -- skip lines with first char of #,
- * they are comments.
- */
- while( fgets(line, 80, f) != NULL )
- if( line[0] != '#' ) {
- sscanf( line, "%f %f", &x, &y );
- i = gen_xform( x, x_size, dim_x->values );
- if( i == -2 )
- return( NULL );
- j = gen_xform( y, y_size, dim_y->values );
- if( j == -2 )
- return( NULL );
- if( (i > 0) && (j > 0))
- *(overlay + j*x_size + i) = 1;
- }
-
- return( overlay );
-}
-
-/******************************************************************************
- * Given the (dimensional) value from the overlay file, convert it to
- * the nearest index along the proper dimension that the point corresponds to.
- * 'n' is the length of array dimvals.
- *
- * For example, 'value' might be 160.0, and dimvals might go from 0.0 to 359.0
- * by 1.0, in which case n=360. Then, the returned value is the location in
- * array dimvals that is closest to 160.0, in this case, it will be 160.
- */
- int
-gen_xform( float value, int n, float *dimvals )
-{
- float min_dist, dist;
- int i, min_place;
-
- min_dist = 1.0e35;
- min_place = 0;
-
- /* See if off ends of dimvalues ... remember that it can be reversed */
- if( *dimvals > *(dimvals+n-1) ) {
- /* reversed */
- if( value > *dimvals )
- return( -1 );
- if( value < *(dimvals+n-1) )
- return( -1 );
- }
- else
- {
- if( value < *dimvals )
- return( -1 );
- if( value > *(dimvals+n-1) )
- return( -1 );
- }
-
- for( i=0; i<n; i++ ) {
- dist = fabs(*(dimvals+i) - value);
- if( dist < min_dist ) {
- min_dist = dist;
- min_place = i;
- }
- }
-
- return( min_place );
-}
-
-/****************************************************************************************/
- char **
-overlay_names( void )
-{
- return( my_overlay_names );
-}
-
-/****************************************************************************************/
- int
-overlay_current( void )
-{
- return( my_current_overlay );
-}
-
-/****************************************************************************************/
- int
-overlay_n_overlays( void )
-{
- return( OVERLAY_N_OVERLAYS );
-}
-
-/****************************************************************************************/
- int
-overlay_custom_n( void )
-{
- return( OVERLAY_CUSTOM );
-}
-
diff --git a/src/udu.c b/src/udu.c
index 38950f5..c9aef38 100644
--- a/src/udu.c
+++ b/src/udu.c
@@ -204,7 +204,7 @@ int udu_calc_tgran( int fileid, NCVar *v, int dimid )
}
/******************************************************************************/
-void udu_fmt_time( char *temp_string, double new_dimval, NCDim *dim, int include_granularity )
+void udu_fmt_time( char *temp_string, size_t temp_string_len, double new_dimval, NCDim *dim, int include_granularity )
{
static ut_unit *dataunits=NULL;
int year, month, day, hour, minute, debug;
@@ -219,7 +219,7 @@ void udu_fmt_time( char *temp_string, double new_dimval, NCDim *dim, int include
dim->name, dim->units, new_dimval );
if( ! valid_udunits_pkg ) {
- sprintf( temp_string, "%lg", new_dimval );
+ snprintf( temp_string, temp_string_len-1, "%lg", new_dimval );
return;
}
@@ -248,23 +248,23 @@ void udu_fmt_time( char *temp_string, double new_dimval, NCDim *dim, int include
case TGRAN_YEAR:
case TGRAN_MONTH:
case TGRAN_DAY:
- sprintf( temp_string, "%1d-%s-%04d", day, months[month-1], year );
+ snprintf( temp_string, temp_string_len-1, "%1d-%s-%04d", day, months[month-1], year );
break;
case TGRAN_HOUR:
case TGRAN_MIN:
- sprintf( temp_string, "%1d-%s-%04d %02d:%02d", day,
+ snprintf( temp_string, temp_string_len-1, "%1d-%s-%04d %02d:%02d", day,
months[month-1], year, hour, minute );
break;
default:
- sprintf( temp_string, "%1d-%s-%04d %02d:%02d:%02.0f",
+ snprintf( temp_string, temp_string_len-1, "%1d-%s-%04d %02d:%02d:%02.0f",
day, months[month-1], year, hour, minute, second );
}
}
else
{
- sprintf( temp_string, "%1d-%s-%04d %02d:%02d:%02.0f",
+ snprintf( temp_string, temp_string_len-1, "%1d-%s-%04d %02d:%02d:%02.0f",
day, months[month-1], year, hour, minute, second );
}
}
@@ -318,9 +318,9 @@ int udu_calc_tgran( int fileid, NCVar *v, int dimid )
return( 0 );
}
-void udu_fmt_time( char *temp_string, double new_dimval, NCDim *dim, int include_granularity )
+void udu_fmt_time( char *temp_string, size_t temp_string_len, double new_dimval, NCDim *dim, int include_granularity )
{
- sprintf( temp_string, "%g", new_dimval );
+ snprintf( temp_string, temp_string_len-1, "%g", new_dimval );
}
#endif
diff --git a/src/utCalendar2_cal.c b/src/utCalendar2_cal.c
index 0c9db9a..93c4ee8 100644
--- a/src/utCalendar2_cal.c
+++ b/src/utCalendar2_cal.c
@@ -429,8 +429,9 @@ static cv_converter *get_user_to_day_converter( ut_unit *uu, int y0, int mon0, i
ut_unit *udu_days;
cv_converter *conv_user_units_to_days;
- sprintf( daystr, "days since %04d-%02d-%02d %02d:%02d:%f",
+ snprintf( daystr, 1024, "days since %04d-%02d-%02d %02d:%02d:%f",
y0, mon0, d0, h0, min0, s0 );
+ daystr[1023] = '\0';
udu_days = ut_parse( ut_get_system(uu), daystr, UT_ASCII );
if( udu_days == NULL ) {
@@ -458,8 +459,9 @@ static cv_converter *get_day_to_user_converter( ut_unit *uu, int y0, int mon0, i
ut_unit *udu_days;
cv_converter *conv_days_to_user_units;
- sprintf( daystr, "days since %04d-%02d-%02d %02d:%02d:%f",
+ snprintf( daystr, 1024, "days since %04d-%02d-%02d %02d:%02d:%f",
y0, mon0, d0, h0, min0, s0 );
+ daystr[1023] = '\0';
udu_days = ut_parse( ut_get_system(uu), daystr, UT_ASCII );
if( udu_days == NULL ) {
@@ -532,8 +534,9 @@ static void initialize( ut_system *units_system )
*/
tval = 0.0;
ut_decode_time( tval, &y0lib, &mon0lib, &d0lib, &h0lib, &min0lib, &s0lib, &rez );
- sprintf( ustr, "seconds since %04d-%02d-%02d %02d:%02d:%f",
+ snprintf( ustr, 1024, "seconds since %04d-%02d-%02d %02d:%02d:%f",
y0lib, mon0lib, d0lib, h0lib, min0lib, s0lib );
+ ustr[1023] = '\0';
udu_ref_date = ut_parse( units_system, ustr, UT_ASCII );
if( udu_ref_date == NULL ) {
fprintf( stderr, "internal error in routine utCalendar2/initialize: could not parse origin string \"%s\"\n",
diff --git a/src/util.c b/src/util.c
index 708023d..5dc5488 100644
--- a/src/util.c
+++ b/src/util.c
@@ -265,7 +265,7 @@ data_to_pixels( View *v )
in_set_cursor_normal();
in_button_pressed( BUTTON_PAUSE, MOD_1 );
if( options.min_max_method == MIN_MAX_METHOD_EXHAUST ) {
- sprintf( error_message, "min and max both 0 for variable %s (checked all data)\nSetting range to (-1,1)",
+ snprintf( error_message, 1022, "min and max both 0 for variable %s (checked all data)\nSetting range to (-1,1)",
v->variable->name );
in_error( error_message );
v->variable->user_max = 1;
@@ -273,7 +273,7 @@ data_to_pixels( View *v )
v->variable->auto_set_no_range = 1;
return( data_to_pixels(v) );
}
- sprintf( error_message, "min and max both 0 for variable %s.\nI can check ALL the data instead of subsampling if that's OK,\nor just cancel viewing this variable.",
+ snprintf( error_message, 1022, "min and max both 0 for variable %s.\nI can check ALL the data instead of subsampling if that's OK,\nor just cancel viewing this variable.",
v->variable->name );
result = in_dialog( error_message, NULL, TRUE );
if( result == MESSAGE_OK ) {
@@ -283,7 +283,7 @@ data_to_pixels( View *v )
options.min_max_method = orig_minmax_method;
if( (v->variable->user_max == 0) &&
(v->variable->user_min == 0) ) {
- sprintf( error_message, "min and max both 0 for variable %s (checked all data)\nSetting range to (-1,1)",
+ snprintf( error_message, 1022, "min and max both 0 for variable %s (checked all data)\nSetting range to (-1,1)",
v->variable->name );
in_error( error_message );
v->variable->user_max = 1;
@@ -304,7 +304,7 @@ data_to_pixels( View *v )
if( (v->variable->user_max == v->variable->user_min) && (! options.autoscale) ) {
in_set_cursor_normal();
- sprintf( error_message, "min and max both %g for variable %s",
+ snprintf( error_message, 1022, "min and max both %g for variable %s",
v->variable->user_min, v->variable->name );
x_error( error_message );
if( ! data_has_mv( v->data, x_size*y_size, fill_value ) ) {
@@ -756,13 +756,13 @@ check_ranges( NCVar *var )
if( netcdf_min_max_option_set( var, &min, &max ) ) {
if( var->global_min < min ) {
- sprintf( temp_string, "Calculated minimum (%g) is less than\nvalid_range minimum (%g). Reset\nminimum to valid_range minimum?", var->global_min, min );
+ snprintf( temp_string, 1022, "Calculated minimum (%g) is less than\nvalid_range minimum (%g). Reset\nminimum to valid_range minimum?", var->global_min, min );
message = in_dialog( temp_string, NULL, TRUE );
if( message == MESSAGE_OK )
var->global_min = min;
}
if( var->global_max > max ) {
- sprintf( temp_string, "Calculated maximum (%g) is greater\nthan valid_range maximum (%g). Reset\nmaximum to valid_range maximum?", var->global_max, max );
+ snprintf( temp_string, 1022, "Calculated maximum (%g) is greater\nthan valid_range maximum (%g). Reset\nmaximum to valid_range maximum?", var->global_max, max );
message = in_dialog( temp_string, NULL, TRUE );
if( message == MESSAGE_OK )
var->global_max = max;
@@ -771,7 +771,7 @@ check_ranges( NCVar *var )
if( netcdf_min_option_set( var, &min ) ) {
if( var->global_min < min ) {
- sprintf( temp_string, "Calculated minimum (%g) is less than\nvalid_min minimum (%g). Reset\nminimum to valid_min value?", var->global_min, min );
+ snprintf( temp_string, 1022, "Calculated minimum (%g) is less than\nvalid_min minimum (%g). Reset\nminimum to valid_min value?", var->global_min, min );
message = in_dialog( temp_string, NULL, TRUE );
if( message == MESSAGE_OK )
var->global_min = min;
@@ -780,7 +780,7 @@ check_ranges( NCVar *var )
if( netcdf_max_option_set( var, &max ) ) {
if( var->global_max > max ) {
- sprintf( temp_string, "Calculated maximum (%g) is greater than\nvalid_max maximum (%g). Reset\nmaximum to valid_max value?", var->global_max, max );
+ snprintf( temp_string, 1022, "Calculated maximum (%g) is greater than\nvalid_max maximum (%g). Reset\nmaximum to valid_max value?", var->global_max, max );
message = in_dialog( temp_string, NULL, TRUE );
if( message == MESSAGE_OK )
var->global_max = max;
@@ -2071,7 +2071,7 @@ warn_if_file_exits( char *fname )
return( MESSAGE_OK );
fclose(f);
- sprintf( message, "OK to overwrite existing file %s?\n", fname );
+ snprintf( message, 1022, "OK to overwrite existing file %s?\n", fname );
retval = in_dialog( message, NULL, TRUE );
return( retval );
}
@@ -2152,7 +2152,7 @@ months_calc_tgran( int fileid, NCDim *d )
}
/******************************************************************************/
-void fmt_time( char *temp_string, double new_dimval, NCDim *dim, int include_granularity )
+void fmt_time( char *temp_string, size_t temp_string_len, double new_dimval, NCDim *dim, int include_granularity )
{
int year, month, day;
@@ -2163,10 +2163,10 @@ void fmt_time( char *temp_string, double new_dimval, NCDim *dim, int include_gra
}
if( dim->time_std == TSTD_UDUNITS )
- udu_fmt_time( temp_string, new_dimval, dim, include_granularity );
+ udu_fmt_time( temp_string, temp_string_len, new_dimval, dim, include_granularity );
else if( dim->time_std == TSTD_EPIC_0 )
- epic_fmt_time( temp_string, new_dimval, dim );
+ epic_fmt_time( temp_string, temp_string_len, new_dimval, dim );
else if( dim->time_std == TSTD_MONTHS ) {
/* Format for months standard */
@@ -2176,7 +2176,7 @@ void fmt_time( char *temp_string, double new_dimval, NCDim *dim, int include_gra
month = (month > 11) ? 11 : month;
day =
(int)( ((new_dimval-1.0) - year*12 - month) * 30.0) + 1;
- sprintf( temp_string, "%s %2d %4d", month_name[month],
+ snprintf( temp_string, temp_string_len-1, "%s %2d %4d", month_name[month],
day, year+1 );
}
diff --git a/src/view.c b/src/view.c
index 1ff72a1..7ef0f2c 100644
--- a/src/view.c
+++ b/src/view.c
@@ -491,18 +491,18 @@ set_scan_view( size_t scan_place )
temp_string, &has_bounds, &bound_min, &bound_max, view->var_place );
if( type == NC_DOUBLE ) {
if( dim->timelike && options.t_conv ) {
- fmt_time( temp_string, new_dimval, dim, 1 );
+ fmt_time( temp_string, 1024, new_dimval, dim, 1 );
strcat( view_place, temp_string );
if( has_bounds ) {
snprintf( temp_string, 1023, " (%d bnds:", has_bounds );
strcat( view_place, temp_string );
- fmt_time( temp_string, bound_min, dim, 0 );
+ fmt_time( temp_string, 1024, bound_min, dim, 0 );
strcat( view_place, temp_string );
strcat( view_place, " -> " );
- fmt_time( temp_string, bound_max, dim, 0 );
+ fmt_time( temp_string, 1024, bound_max, dim, 0 );
strcat( view_place, temp_string );
strcat( view_place, ")" );
@@ -1209,7 +1209,7 @@ view_change_cur_dim( char *dim_name, int modifier )
&has_bounds, &bound_min, &bound_max, view->var_place );
if( type == NC_DOUBLE ) {
if( dim->timelike && options.t_conv ) {
- fmt_time( temp_string, new_dimval, dim, 1 );
+ fmt_time( temp_string, 1024, new_dimval, dim, 1 );
}
else
snprintf( temp_string, 1023, "%lg", new_dimval );
@@ -2105,7 +2105,7 @@ view_report_position( int x, int y, unsigned int button_mask )
temp_string, &has_bounds, &bound_min, &bound_max, virt_cursor_pos );
if( type == NC_DOUBLE ) {
if( (xdim != NULL) && xdim->timelike && options.t_conv )
- fmt_time( xdim_str, new_dimval, xdim, 1 );
+ fmt_time( xdim_str, 79, new_dimval, xdim, 1 );
else
snprintf( xdim_str, 79, "%.7lg", new_dimval );
}
@@ -2116,7 +2116,7 @@ view_report_position( int x, int y, unsigned int button_mask )
temp_string, &has_bounds, &bound_min, &bound_max, virt_cursor_pos );
if( type == NC_DOUBLE ) {
if( (ydim != NULL) && ydim->timelike && options.t_conv )
- fmt_time( ydim_str, new_dimval, ydim, 1 );
+ fmt_time( ydim_str, 79, new_dimval, ydim, 1 );
else
snprintf( ydim_str, 79, "%.7lg", new_dimval );
}
@@ -2219,7 +2219,7 @@ view_report_position_vals( float xval, float yval, int plot_index )
/* If the X dimension is timelike, consider formatting that value */
if( (dim != NULL) && dim->timelike && options.t_conv ) {
- fmt_time( temp, xval, dim, 1 );
+ fmt_time( temp, 79, xval, dim, 1 );
snprintf( current_value_label, 79, "Current: x=%s, y=%g",
temp, yval );
}
@@ -2899,15 +2899,15 @@ plot_XY_sc( size_t *start, size_t *count )
/**************************************************************************************/
void
-view_plot_XY_fmt_x_val( float val, int dimindex, char *s )
+view_plot_XY_fmt_x_val( float val, int dimindex, char *s, size_t s_len )
{
NCDim *dim;
dim = *(view->variable->dim + dimindex);
if( dim->timelike && options.t_conv )
- fmt_time( s, val, dim, 1 );
+ fmt_time( s, s_len-1, val, dim, 1 );
else
- sprintf( s, "%g", val );
+ snprintf( s, s_len-1, "%g", val );
}
/**************************************************************************************/
@@ -3031,6 +3031,13 @@ view_change_transform( int delta )
/***************************************************************************/
void view_recompute_colorbar( void )
{
+ /* The user might ask to rearrange colormaps before any
+ * variable is selected. In that event, return
+ * immediately
+ */
+ if( (view == NULL) || (view->variable == NULL))
+ return;
+
if( options.debug ) {
fprintf( stderr, "view_recompute_colorbar: entering\n" );
fprintf( stderr, "view_recompute_colorbar: about to call x_create_colorbar with user_min=%f user_max=%f transform=%d\n",
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/ncview.git
More information about the Pkg-grass-devel
mailing list