~ubuntu-branches/ubuntu/dapper/ploticus/dapper

« back to all changes in this revision

Viewing changes to src/lib.c

  • Committer: Bazaar Package Importer
  • Author(s): James W. Penny
  • Date: 2004-04-04 22:12:00 UTC
  • mfrom: (0.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040404221200-822i126bwkfgsfx6
Tags: 2.20-3
* Add "late fix" for errbarfields.  Fix found in
  http://groups.yahoo.com/group/ploticus/message/691.
  Solves a problem with asymetric error bands.
* Add "late fix" for proc_axis.c.  Fix found in
  http://groups.yahoo.com/group/ploticus/message/722
  This solves a problem with cumulative rounding of 
  days in graphs with days stubs.
* Add  "late fix" version of chunk_area.  Fix from
  http://ploticus.sourceforge.net/download/chunk_area
  This solves a problem with dates with no day number,
  as mm/yyyy.
* Add "late fix" version of heatarea.pl.  Fix from
  http://ploticus.sourceforge.net/download/heatmap.pl
* Add "late fix" version of proc_getdata.c.  Fix found at
  http://ploticus.sourceforge.net/download/proc_getdata.c
  This permits comma delimited files with more than 255 characters
  per row to be processed.
* Add "late fix" version of proc_lineplot.c.  This is from
  http://ploticus.sourceforge.net/download/proc_lineplot.c
  It clips labels, and handles the degenerate case of no points
  in the range properly.
* Add pltestsuite to debian package as 
  /usr/share/doc/ploticus/examples
* Remove recommends of libming-fonts-openoffice. The package has been
  removed from debian.                         closes: Bug#240560
  

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
static int Supress_convmsg = 0;
9
9
static int N_convmsg = 0;
 
10
static int beginnum();
 
11
 
 
12
 
 
13
/* ====================== */
 
14
PL_lib_initstatic()
 
15
{
 
16
Supress_convmsg = 0;
 
17
N_convmsg = 0;
 
18
return( 0 );
 
19
}
 
20
 
10
21
 
11
22
/* ====================== */
12
23
/* DA - access D as a 2-D array; return as char *    */
13
24
char *
14
 
da( r, c )
 
25
PL_da( r, c )
15
26
int r, c;
16
27
{
17
28
int base;
18
 
base = StartD[Dsel];
19
 
if( r >= Nrecords[Dsel] ) { 
20
 
        fprintf( Errfp, "warning: %s data reference (rec=%d field=%d) is out of bounds\n", 
21
 
                Eprogname, r+1, c+1 ); 
22
 
        return( "" );
23
 
        }
24
 
if( c >= Nfields[Dsel] ) { 
25
 
        fprintf( Errfp, "warning: %s data reference (rec=%d field=%d) is out of bounds\n", 
26
 
                Eprogname, r+1, c+1 ); 
27
 
        return( "" );
28
 
        }
29
 
return( D[ base + ( r * Nfields[Dsel] ) + c ] );
 
29
base = PLD.dsfirstdf[ PLD.curds ];
 
30
if( r >= Nrecords ) { 
 
31
        fprintf( PLS.errfp, "warning: %s data reference (rec=%d field=%d) is out of bounds\n", 
 
32
                Eprogname, r+1, c+1 ); 
 
33
        return( "" );
 
34
        }
 
35
if( c >= Nfields ) { 
 
36
        fprintf( PLS.errfp, "warning: %s data reference (rec=%d field=%d) is out of bounds\n", 
 
37
                Eprogname, r+1, c+1 ); 
 
38
        return( "" );
 
39
        }
 
40
return( PLD.df[ base + ( r * Nfields ) + c ] );
30
41
}
31
42
/* ====================== */
32
43
/* FDA - access D as a 2-D array; return as double; 
33
44
   For non-plottables 0.0 is returned, but Econv_error may be called to see if 
34
45
   there was a conversion error */
35
 
double fda( r, c, ax )
 
46
double PL_fda( r, c, ax )
36
47
int r, c;
37
48
char ax;
38
49
{
43
54
/* NUM - convert string to double, and ensure that it is proper numeric
44
55
   Result is s converted to double.
45
56
   Return is 0 on ok, 1 on non-numeric. */
46
 
num( s, result )
 
57
PL_num( s, result )
47
58
char s[];
48
59
double *result;
49
60
{
60
71
 
61
72
/* ============================= */
62
73
/* GETCOORDS - extract a coordinate pair (two posex's) from val */
63
 
getcoords( parmname, val, x, y )
 
74
PL_getcoords( parmname, val, x, y )
64
75
char *parmname, *val;
65
76
double *x, *y;
66
77
{
79
90
 
80
91
/* ============================= */
81
92
/* GETBOX - extract two coordinate pairs (four posex's) from val */
82
 
getbox( parmname, val, x1, y1, x2, y2 )
 
93
PL_getbox( parmname, val, x1, y1, x2, y2 )
83
94
char *parmname, *val;
84
95
double *x1, *y1, *x2, *y2;
85
96
{
100
111
 
101
112
/* ================== */
102
113
/* GETRANGE - get a low/high range */
103
 
getrange( lineval, lo, hi, ax, deflo, defhi )
 
114
PL_getrange( lineval, lo, hi, ax, deflo, defhi )
104
115
char *lineval;
105
116
double *lo, *hi;
106
117
char ax;
132
143
   Shell expandable file name is ok.
133
144
   Returns 0 if ok, 1 if file not available */
134
145
 
135
 
file_to_buf( filename, mode, result, buflen )
 
146
PL_file_to_buf( filename, mode, result, buflen )
136
147
char *filename;
137
148
int mode; /* 1 = file   2 = command */
138
149
char *result;
159
170
 
160
171
/* ========================= */
161
172
/* SETFLOATVAR - set a DMS var to a double value */
162
 
setfloatvar( varname, f )
 
173
PL_setfloatvar( varname, f )
163
174
char *varname;
164
175
double f;
165
176
{
172
183
}
173
184
/* ========================= */
174
185
/* SETINTVAR - set a DMS var to an integer value */
175
 
setintvar( varname, n )
 
186
PL_setintvar( varname, n )
176
187
char *varname;
177
188
int n;
178
189
{
186
197
 
187
198
/* ========================== */
188
199
/* SETCHARVAR - set a DMS var to a char string value */
189
 
setcharvar( varname, s )
 
200
PL_setcharvar( varname, s )
190
201
char *varname;
191
202
char *s;
192
203
{
197
208
}
198
209
 
199
210
/* =========================== */
200
 
/* CONV_MSG - print a message to Errfp for a data item of invalid type */
201
 
conv_msg( row, col, aname )
 
211
/* CONV_MSG - print a message to errfp for a data item of invalid type */
 
212
PL_conv_msg( row, col, aname )
202
213
int row, col;
203
214
char *aname;
204
215
{
205
216
N_convmsg++;
206
217
if( Supress_convmsg ) return( 0 );
207
 
fprintf( Errfp, "%s warning, %s skipping unplottable '%s' (rec=%d field=%d)\n",
 
218
fprintf( PLS.errfp, "%s warning, %s skipping unplottable '%s' (rec=%d field=%d)\n",
208
219
        Eprogname, aname, da(row,col), row+1, col+1 );
209
220
return( 0 );
210
221
}
211
222
 
212
223
/* =========================== */
213
 
/* OTH_MSG - print a message to Errfp for a data item of invalid type */
214
 
oth_msg( msg )
 
224
/* OTH_MSG - print a message to errfp for a data item of invalid type */
 
225
PL_oth_msg( msg )
215
226
char *msg;
216
227
{
217
228
N_convmsg++;
218
229
if( Supress_convmsg ) return( 0 );
219
 
fprintf( Errfp, "%s %s\n", Eprogname, msg );
 
230
fprintf( PLS.errfp, "%s %s\n", Eprogname, msg );
220
231
return( 0 );
221
232
}
222
233
 
223
234
/* =========================== */
224
 
 
225
 
/* =========================== */
226
235
/* SUPPRESS_CONVMSG - suppress invalid type messages */
227
 
suppress_convmsg( mode )
 
236
PL_suppress_convmsg( mode )
228
237
int mode;
229
238
{
230
239
Supress_convmsg = mode;
233
242
 
234
243
/* ============================= */
235
244
/* ZERO_CONVMSGCOUNT - zero out the conv msg counter */
236
 
zero_convmsgcount()
 
245
PL_zero_convmsgcount()
237
246
{
238
247
N_convmsg = 0;
239
248
return( 0 );
240
249
}
241
250
/* ============================= */
242
251
/* REPORT_CONVMSGCOUNT - report on what the conv msg count is.. */
243
 
report_convmsgcount()
 
252
PL_report_convmsgcount()
244
253
{
245
254
return( N_convmsg );
246
255
}
249
258
 
250
259
/* ========================== */
251
260
/* SCALEBEENSET - return 1 if scaling has been set, 0 if not */
252
 
scalebeenset()
 
261
PL_scalebeenset()
253
262
{
254
263
if( EDXhi - EDXlo > 0.0000001 ) return( 1 );
255
264
else return( 0 );
256
265
}
257
266
 
258
 
/* ===================== */
259
 
/* CATITEM - add a new data item */
260
 
catitem( s, d, avail )
261
 
char *s;
262
 
int *d;
263
 
int *avail;
264
 
{
265
 
D[ (*d)++ ] = &Databuf[ *avail ];
266
 
strcpy( &Databuf[ (*avail) ], s );
267
 
(*avail) += (strlen( s ) + 1);
268
 
return( 0 );
269
 
}
 
267
 
270
268
 
271
269
/* ======================== */
272
 
/* DEFAULTINC - given a min and a max, estimate a reasonable default inc */
273
 
static double threshvals[40] = { 0.000001, 0.00001, 0.0001, 0.001, 0.002, 0.005,
274
 
        0.01, 0.02, 0.05, 
275
 
        0.1, 0.2, 0.5, 
276
 
        1.0, 2.0, 5.0, 
277
 
        10.0, 20.0, 50.0, 
278
 
        100.0, 200.0, 500.0, 
279
 
        1000.0, 2000.0, 5000.0, 
280
 
        10000.0, 20000.0, 50000.0, 
281
 
        100000.0, 200000.0, 500000.0, 
282
 
        1000000.0, 2000000.0, 5000000.0, 
283
 
        10000000.0, 20000000.0, 50000000.0 };
 
270
/* DEFAULTINC - given a min and a max, estimate a reasonable default inc 
 
271
 *
 
272
 * Improvements contributed by Dan Pelleg peldan@yahoo.com :
 
273
 *  we want to find a number that is:
 
274
 *   - the same order of magnitude of h, and greater than h
 
275
 *   - is either 1, 2, or 5, multiplied by the appropriate units
 
276
 *   - is the smallest such number
 
277
 *  For example, all numbers between 10000 and 19999 are mapped to 20000.
 
278
 *  Numbers 20000 - 49999 are mapped to 50000.
 
279
 *  Numbers 50000 - 99999 are mapped to 100000.
 
280
 *  Numbers 100000 - 199999 are mapped to 200000.   And so on.  
 
281
 *
 
282
 * Remaining scg code deleted 10/1/03...
 
283
 */
284
284
 
285
 
defaultinc( min, max, inc )
 
285
PL_defaultinc( min, max, inc )
286
286
double min, max, *inc;
287
287
{
288
288
double diff, h, fabs();
 
289
double ret, mult, mant;
289
290
int i;
290
291
 
291
292
diff = max - min;
292
293
diff = fabs( diff );
293
294
h = diff / 10.0;  /* we want to have about 10 tics on an axis.. */
294
295
 
295
 
for( i = 0; ; i++ ) {
296
 
        if( h < threshvals[i] ) break;
297
 
        if( threshvals[i] > 49999999.0 ) break;
298
 
        }
 
296
/* normalize and write h = mant * mult, for 1 <= mant 10 */
 
297
mult = pow( 10.0, floor( log10(h) ) );
 
298
mant = h / mult;
299
299
 
300
 
*inc = threshvals[i];
 
300
/* find the next step and multiply */
 
301
if(mant < 2.0) ret = 2.0 * mult;
 
302
else if(mant < 5.0) ret = 5.0 * mult;
 
303
else ret = 10.0 * mult;
 
304
*inc = ret;
301
305
return( 0 );
302
306
}
303
307
 
 
308
 
304
309
 
305
310
/* ======================== */
306
311
/* REWRITENUMS - rewrite numbers, supplying a spacer (comma in US)
308
313
        mode is presumed, decimal point is written as a comma, and
309
314
        large numbers are spaced using dot.   
310
315
 
 
316
        Numbers in scientific notation are returned unaltered.
 
317
 
311
318
        Parameter num is modified.
312
319
*/
313
320
 
314
 
rewritenums( num )
 
321
PL_rewritenums( num )
315
322
char *num;
316
323
{
317
324
int i, j, k, decplace, len;
318
325
char s[40], tmp[40];
319
326
 
320
 
if( Bignumspacer == '\0' ) return( 0 ); /* do nothing */
 
327
if( PLS.bignumspacer == '\0' ) return( 0 ); /* do nothing */
321
328
 
322
329
sscanf( num, "%s", s ); /* strip off any leading spaces */
323
330
 
325
332
k = -1;
326
333
decplace = -1;
327
334
for( i = 0, len = strlen( s ); i < len; i++ ) {
 
335
        if( s[i] == 'e' ) return( 0 ); /* scientific notation detected - leave it alone - scg 11/26/02 */
328
336
        /* remember the char where number begins.. */
329
 
        if( k < 0 && ( isdigit( s[i] ) || s[i] == '.' || s[i] == '-' ) ) k = i;
 
337
        if( k < 0 && beginnum( s, i ) ) k = i;
 
338
                /* ( isdigit( s[i] )  || (( s[i] == '.' || s[i] == '-' ) && isdigit( s[i+1]) ) ) ) k = i; */
330
339
        if( s[i] == '.' ) {
331
340
                decplace = i - k;
332
 
                if( Bignumspacer == '.' ) tmp[i] = ',';
 
341
                if( PLS.bignumspacer == '.' ) tmp[i] = ',';
333
342
                else tmp[i] = '.';
334
343
                }
335
344
        else tmp[i] = s[i];
336
345
        }
337
 
if( decplace < 0 ) decplace = i - k;
 
346
 
338
347
tmp[i] = '\0';
339
348
 
340
 
if( decplace > Bignumspacer_thres ) {   /* add spacers.. */
 
349
if( decplace < 0 ) {
 
350
        for( ; i >= 0; i-- ) if( isdigit( s[i] ) || s[i] == '.' ) { i++; break; } /* added scg 3/25/02 */
 
351
        decplace = i - k;
 
352
        }
 
353
 
 
354
if( decplace > PLS.bignumthres ) {   /* add spacers.. */
341
355
        /* process tmp; put result back in 's'.. */
342
356
        for( i = -1, j = 0, k = 0; i < decplace; k++ ) {
343
357
                /* just copy over any leading alpha portion.. */
344
 
                if( i < 0 && ( ! isdigit( tmp[k] ) && tmp[k] != '.' && tmp[k] != '-' ) ) {
 
358
                if( i < 0 && !beginnum( tmp, k ) ) {
 
359
                                /* ( ! isdigit( tmp[k] ) && tmp[k] != '.' && tmp[k] != '-' ) ) { */
345
360
                        s[j++] = tmp[k];
346
361
                        continue; /* scg 2/28/02 */
347
362
                        }
348
363
 
349
364
                i++;
350
365
                if( i > 0 && decplace-i > 0 && (decplace-i) % 3 == 0 ) {  /* insert 000 separator.. */
351
 
                        s[j++] = Bignumspacer;
352
 
                        s[j++] = tmp[k];
 
366
                        s[j++] = PLS.bignumspacer;
 
367
                        s[j++] = tmp[k]; 
353
368
                        }
354
 
                else s[j++] = tmp[k];
 
369
                else  s[j++] = tmp[k]; 
355
370
                }
356
371
        s[j] = '\0';
357
 
        strcat( s, &tmp[k] ); /* append decimal point and rightward */
 
372
        if( k < strlen( tmp ) ) strcat( s, &tmp[k] ); /* append decimal point and rightward */
358
373
        }
359
374
else strcpy( s, tmp );
360
375
 
362
377
return( 0 );
363
378
364
379
 
 
380
static int
 
381
beginnum( s, i )
 
382
char *s;
 
383
int i;
 
384
{
 
385
if( ( isdigit( s[i] )  || (( s[i] == '.' || s[i] == '-' ) && isdigit( s[i+1]) ) ) ) return( 1 );
 
386
else return( 0 );
 
387
}
 
388
 
365
389
/* ============================= */
366
390
/* CONVERTNL - change all occurrances of "\n" (backslash followed by n) to a newline character */
367
 
convertnl( str )
 
391
PL_convertnl( str )
368
392
char *str;
369
393
{
370
394
int i, j, len;
381
405
}
382
406
/* ============================== */
383
407
/* MEASURETEXT - count the number of lines present in txt and find the length of longest line. */
384
 
measuretext( txt, nlines, maxlen )
 
408
PL_measuretext( txt, nlines, maxlen )
385
409
char *txt;
386
410
int *nlines, *maxlen;
387
411
{
402
426
return( 0 );
403
427
}
404
428
 
405
 
/* =================================== */
406
 
/* STRIP_WS strip white-space off of front and end of string s */
407
 
strip_ws( s )
408
 
char s[];
 
429
 
 
430
/* ================================= */
 
431
/* DO_X_BUTTON */
 
432
 
 
433
PL_do_x_button( label )
 
434
char *label;
409
435
{
410
 
int i, j, len;
411
 
 
412
 
/* don't do anything if first and last characters are non-space.. */
413
 
if( !isspace( s[0] ) && !isspace( s[ strlen( s ) - 1 ] ) ) return( 0 );
414
 
 
415
 
 
416
 
/* find last significant char and put a null after it */
417
 
for( j = strlen( s ) -1; j >= 0; j-- )
418
 
        if( !GL_member( s[j], " \t\n" )) break;
419
 
s[j+1] = '\0';
420
 
/* find 1st significant char at position i */
421
 
for( i = 0, len = strlen( s ); i < len; i++ ) 
422
 
        if( !GL_member( s[i], " \t\n" )) break; 
423
 
strcpy( s, &s[i] );
 
436
double x, y;
 
437
int e;
 
438
#ifndef NOX11
 
439
while( 1 ) {
 
440
        if( PL_clickmap_getdemomode() ) clickmap_show( 'x' ); /* added scg 11/23/01 */
 
441
        Ecolor( "black" );
 
442
        Elinetype( 0, 0.5, 1.0 );
 
443
        Ecblock( 0.1, 0.1, 1.0, 0.3, "yellow", 0 );
 
444
        Emov( 0.5, 0.12 );
 
445
        Etextsize( 12 );
 
446
        Ecentext( label );
 
447
        Ecblockdress( 0.1, 0.1, 1.0, 0.3, 0.06, "0.6", "0.8", 0.0, "" );
 
448
        Esavewin();
 
449
        Egetkey( &x, &y, &e );
 
450
        if( e < 1000 || (y < 0.3 && x < 1.0 )) {
 
451
                Ecblock( 0.1, 0.1, 1.0, 0.3, "black", 0 ); 
 
452
                Eflush();
 
453
                if( e == 'q' ) PLS.skipout = 1; 
 
454
                break;
 
455
                }
 
456
        else if( PLS.usingcm ) fprintf( PLS.diagfp, "%g %g\n", x*2.54, y*2.54 ); /* in cm */
 
457
        else fprintf( PLS.diagfp, "%g %g\n", x, y ); /* mouse click location in inches from lower-left */
 
458
        }
 
459
#endif
424
460
}