54 #ifdef DJGPP // dos386/djgpp
61 #include <sys/types.h>
63 #ifdef PL_HAVE_UNISTD_H
72 #define BUFFER_SIZE 256
79 #define FUZZ_EPSILON 1.e-4
108 value(
double n1,
double n2,
double hue );
115 int *number_colors,
unsigned int **r,
unsigned int **g,
116 unsigned int **b,
double **a );
121 #if defined ( DJGPP )
123 #define PLLIBDEV "c:/plplot/lib"
126 #elif defined ( MSDOS )
128 #define PLLIBDEV "c:\\plplot\\lib"
136 #define PLLIBDEV "/usr/local/plplot/lib"
156 if ( plsc->level < 1 )
158 plabort(
"plcol0: Please call plinit first" );
161 if ( icol0 < 0 || icol0 >= plsc->ncol0 )
170 plsc->curcolor.r = plsc->cmap0[icol0].r;
171 plsc->curcolor.g = plsc->cmap0[icol0].g;
172 plsc->curcolor.b = plsc->cmap0[icol0].b;
173 plsc->curcolor.a = plsc->cmap0[icol0].a;
192 if ( plsc->level < 1 )
194 plabort(
"plcol1: Please call plinit first" );
199 plwarn(
"plcol1: Invalid cmap1 index" );
200 fprintf( stderr,
"%s\n",
"Further information relevant to this warning:" );
201 fprintf( stderr,
"%s%e\n",
"Invalid index = ", col1 );
203 fprintf( stderr,
"%s%e\n",
"Corrected index = ", col1 );
206 icol1 = (
PLINT) ( col1 * plsc->ncol1 );
207 icol1 =
MIN( icol1, plsc->ncol1 - 1 );
210 plsc->curcolor.r = plsc->cmap1[plsc->icol1].r;
211 plsc->curcolor.g = plsc->cmap1[plsc->icol1].g;
212 plsc->curcolor.b = plsc->cmap1[plsc->icol1].b;
213 plsc->curcolor.a = plsc->cmap1[plsc->icol1].a;
298 if ( plsc->cmap0 == NULL )
300 if ( icol0 < 0 || icol0 >= plsc->ncol0 )
308 limit_rgba_range(
"plscol0: invalid cmap0 RGB color has been corrected", &r, &g, &b, NULL );
328 if ( plsc->cmap0 == NULL )
330 if ( icol0 < 0 || icol0 >= plsc->ncol0 )
337 limit_rgba_range(
"plscol0a: invalid cmap0 RGBA color has been corrected", &r, &g, &b, &alpha );
338 plsc->cmap0[icol0].r = (
unsigned char) r;
339 plsc->cmap0[icol0].g = (
unsigned char) g;
340 plsc->cmap0[icol0].b = (
unsigned char) b;
341 plsc->cmap0[icol0].a = alpha;
343 if ( plsc->level > 0 )
361 if ( plsc->cmap0 == NULL )
368 if ( icol0 < 0 || icol0 > plsc->ncol0 )
376 *r = plsc->cmap0[icol0].r;
377 *g = plsc->cmap0[icol0].g;
378 *b = plsc->cmap0[icol0].b;
398 if ( plsc->cmap0 == NULL )
401 if ( icol0 < 0 || icol0 > plsc->ncol0 )
404 snprintf(
buffer,
BUFFER_SIZE,
"plgcol0: Invalid color index: %d. Return opaque red as a warning of this condition.", (
int) icol0 );
414 *r = plsc->cmap0[icol0].r;
415 *g = plsc->cmap0[icol0].g;
416 *b = plsc->cmap0[icol0].b;
417 *alpha = plsc->cmap0[icol0].a;
437 PLINT nc_r, nc_g, nc_b;
441 for ( i = 0; i < plsc->ncol0; i++ )
448 limit_rgba_range(
"plscmap0: invalid cmap0 RGB color has been corrected", &nc_r, &nc_g, &nc_b, NULL );
449 plsc->cmap0[i].r = (
unsigned char) nc_r;
450 plsc->cmap0[i].g = (
unsigned char) nc_g;
451 plsc->cmap0[i].b = (
unsigned char) nc_b;
455 if ( plsc->level > 0 )
475 PLINT nc_r, nc_g, nc_b;
481 for ( i = 0; i < plsc->ncol0; i++ )
490 limit_rgba_range(
"plscmap0a: invalid cmap0 RGBA color has been corrected", &nc_r, &nc_g, &nc_b, &nc_alpha );
491 plsc->cmap0[i].r = (
unsigned char) nc_r;
492 plsc->cmap0[i].g = (
unsigned char) nc_g;
493 plsc->cmap0[i].b = (
unsigned char) nc_b;
494 plsc->cmap0[i].a = nc_alpha;
497 if ( plsc->level > 0 )
516 PLINT nc_r, nc_g, nc_b;
520 for ( i = 0; i < plsc->ncol1; i++ )
527 limit_rgba_range(
"plscmap1: invalid cmap1 RGB color has been corrected", &nc_r, &nc_g, &nc_b, NULL );
528 plsc->cmap1[i].r = (
unsigned char) nc_r;
529 plsc->cmap1[i].g = (
unsigned char) nc_g;
530 plsc->cmap1[i].b = (
unsigned char) nc_b;
534 if ( plsc->level > 0 )
554 PLINT nc_r, nc_g, nc_b;
559 for ( i = 0; i < plsc->ncol1; i++ )
568 limit_rgba_range(
"plscmap1a: invalid cmap1 RGBA color has been corrected", &nc_r, &nc_g, &nc_b, &nc_alpha );
569 plsc->cmap1[i].r = (
unsigned char) nc_r;
570 plsc->cmap1[i].g = (
unsigned char) nc_g;
571 plsc->cmap1[i].b = (
unsigned char) nc_b;
572 plsc->cmap1[i].a = nc_alpha;
575 if ( plsc->level > 0 )
639 plabort(
"plscmap1l: Must specify at least two control points" );
645 plabort(
"plscmap1l: First and last control points must correspond to minimum and maximum cmap1 color index" );
651 plabort(
"plscmap1l: exceeded maximum number of control points" );
657 if ( plsc->cmap1 == NULL )
662 plsc->cmap1cp_is_rgb = itype == 0 ? 0 : 1;
665 for ( n = 0; n < npts; n++ )
667 plsc->cmap1cp[n].c1 = coord1[n];
668 plsc->cmap1cp[n].c2 = coord2[n];
669 plsc->cmap1cp[n].c3 = coord3[n];
670 plsc->cmap1cp[n].p = intensity[n];
673 if ( alt_hue_path == NULL )
674 plsc->cmap1cp[n].alt_hue_path = 0;
675 else if ( n != npts - 1 )
676 plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
679 plsc->cmap1cp[n].alt_hue_path = 0;
710 plabort(
"plscmap1la: Must specify at least two control points" );
716 plabort(
"plscmap1la: First, last control points must lie on boundary" );
722 plabort(
"plscmap1la: exceeded maximum number of control points" );
728 if ( plsc->cmap1 == NULL )
733 plsc->cmap1cp_is_rgb = itype == 0 ? 0 : 1;
736 for ( n = 0; n < npts; n++ )
738 plsc->cmap1cp[n].c1 = coord1[n];
739 plsc->cmap1cp[n].c2 = coord2[n];
740 plsc->cmap1cp[n].c3 = coord3[n];
741 plsc->cmap1cp[n].p = intensity[n];
742 plsc->cmap1cp[n].a = alpha[n];
744 if ( alt_hue_path == NULL )
745 plsc->cmap1cp[n].alt_hue_path = 0;
746 else if ( n != npts - 1 )
747 plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
750 plsc->cmap1cp[n].alt_hue_path = 0;
767 PLFLT delta, dp, dh, dl, ds, da, dr, dg, db;
768 PLFLT h, l, s, p, r, g, b, a;
771 if ( !plsc->cmap1cp_is_rgb )
773 for ( n = 0; n < plsc->ncp1 - 1; n++ )
775 if ( plsc->cmap1cp[n].p == plsc->cmap1cp[n + 1].p )
780 dp = plsc->cmap1cp[n + 1].p - plsc->cmap1cp[n].p;
781 dh = plsc->cmap1cp[n + 1].c1 - plsc->cmap1cp[n].c1;
782 dl = plsc->cmap1cp[n + 1].c2 - plsc->cmap1cp[n].c2;
783 ds = plsc->cmap1cp[n + 1].c3 - plsc->cmap1cp[n].c3;
784 da = plsc->cmap1cp[n + 1].a - plsc->cmap1cp[n].a;
788 if ( plsc->cmap1cp[n].alt_hue_path )
789 dh = ( dh > 0 ) ? dh - 360 : dh + 360;
794 for ( i = 0; i < plsc->ncol1; i++ )
796 p = (double) i / ( plsc->ncol1 - 1.0 );
797 if ( ( p < plsc->cmap1cp[n].p ) ||
798 ( p > plsc->cmap1cp[n + 1].p ) )
803 delta = ( p - plsc->cmap1cp[n].p ) / dp;
807 h = plsc->cmap1cp[n].c1 + dh * delta;
808 l = plsc->cmap1cp[n].c2 + dl * delta;
809 s = plsc->cmap1cp[n].c3 + ds * delta;
810 a = plsc->cmap1cp[n].a + da * delta;
829 for ( n = 0; n < plsc->ncp1 - 1; n++ )
831 if ( plsc->cmap1cp[n].p == plsc->cmap1cp[n + 1].p )
836 dp = plsc->cmap1cp[n + 1].p - plsc->cmap1cp[n].p;
837 dr = plsc->cmap1cp[n + 1].c1 - plsc->cmap1cp[n].c1;
838 dg = plsc->cmap1cp[n + 1].c2 - plsc->cmap1cp[n].c2;
839 db = plsc->cmap1cp[n + 1].c3 - plsc->cmap1cp[n].c3;
840 da = plsc->cmap1cp[n + 1].a - plsc->cmap1cp[n].a;
845 for ( i = 0; i < plsc->ncol1; i++ )
847 p = (double) i / ( plsc->ncol1 - 1.0 );
848 if ( ( p < plsc->cmap1cp[n].p ) ||
849 ( p > plsc->cmap1cp[n + 1].p ) )
854 delta = ( p - plsc->cmap1cp[n].p ) / dp;
858 r = plsc->cmap1cp[n].c1 + dr * delta;
859 g = plsc->cmap1cp[n].c2 + dg * delta;
860 b = plsc->cmap1cp[n].c3 + db * delta;
861 a = plsc->cmap1cp[n].a + da * delta;
871 if ( plsc->level > 0 )
894 if ( min_color >= max_color || max_color <= MIN_PLFLT_CMAP1 || min_color >=
MAX_PLFLT_CMAP1 )
896 plwarn(
"plscmap1_range called with completely invalid color range so min_color = MIN_PLFLT_CMAP1 and max_color = MAX_PLFLT_CMAP1 used instead." );
904 plwarn(
"plscmap1_range called with min_color < MIN_PLFLT_CMAP1. min_color = MIN_PLFLT_CMAP1 < max_color is used instead." );
909 plwarn(
"plscmap1_range called with max_color > MAX_PLFLT_CMAP1. max_color = MAX_PLFLT_CMAP1 > min_color is used instead" );
912 plsc->cmap1_min = min_color;
913 plsc->cmap1_max = max_color;
926 *min_color = plsc->cmap1_min;
927 *max_color = plsc->cmap1_max;
944 int ncol, size, imin, imax;
948 if ( ncol0 > 0 && plsc->ncol0 == ncol0 )
953 if ( plsc->ncol0 <= 0 && ncol0 <= 0 )
955 else if ( ncol0 <= 0 )
961 size = ncol * (int)
sizeof (
PLColor );
965 if ( plsc->cmap0 == NULL )
967 if ( ( plsc->cmap0 = (
PLColor *) calloc( 1, (
size_t) size ) ) == NULL )
969 plexit(
"c_plscmap0n: Insufficient memory" );
975 if ( ( plsc->cmap0 = (
PLColor *) realloc( plsc->cmap0, (
size_t) size ) ) == NULL )
977 plexit(
"c_plscmap0n: Insufficient memory" );
987 if ( plsc->level > 0 )
1006 plsc->cmap0[i].r = r;
1007 plsc->cmap0[i].g = g;
1008 plsc->cmap0[i].b = b;
1009 plsc->cmap0[i].a = a;
1010 plsc->cmap0[i].name =
name;
1013 #define color_def( i, r, g, b, a, n ) \
1014 if ( i >= imin && i <= imax ) color_set( i, r, g, b, a, n );
1029 unsigned int *r, *g, *b;
1035 for ( i = imin; i <=
MIN( ( number_colors - 1 ), imax ); i++ )
1037 "colors defined by default cmap0 palette file" );
1050 for ( i =
MAX( number_colors, imin ); i <= imax; i++ )
1052 "opaque red colour to mark not defined by palette file" );
1074 if ( ncol1 > 0 && plsc->ncol1 == ncol1 )
1079 if ( plsc->ncol1 <= 0 && ncol1 <= 0 )
1081 else if ( ncol1 <= 0 )
1086 size = (size_t) ncol *
sizeof (
PLColor );
1090 if ( plsc->ncol1 > 0 )
1092 if ( ( plsc->cmap1 = (
PLColor *) realloc( plsc->cmap1, size ) ) == NULL )
1094 plexit(
"c_plscmap1n: Insufficient memory" );
1099 if ( ( plsc->cmap1 = (
PLColor *) calloc( (
size_t) ncol,
sizeof (
PLColor ) ) ) == NULL )
1101 plexit(
"c_plscmap1n: Insufficient memory" );
1108 if ( plsc->ncp1 == 0 )
1130 PLFLT i[6], h[6], l[6], s[6], midpt = 0., vertex = 0.;
1144 if ( plsc->cmap0 != NULL )
1145 vertex = ( (
PLFLT) plsc->cmap0[0].r +
1146 (
PLFLT) plsc->cmap0[0].g +
1189 if ( plsc->level > 0 )
1205 plsc->color =
color;
1219 value(
double n1,
double n2,
double hue )
1223 while ( hue >= 360. )
1229 val = n1 + ( n2 - n1 ) * hue / 60.;
1230 else if ( hue < 180. )
1232 else if ( hue < 240. )
1233 val = n1 + ( n2 - n1 ) * ( 240. - hue ) / 60.;
1266 m2 = l * ( s + 1. );
1272 *p_r =
value( m1, m2, h + 120. );
1273 *p_g =
value( m1, m2, h );
1274 *p_b =
value( m1, m2, h - 120. );
1296 PLFLT h, l, s, d, rc, gc, bc, rgb_min, rgb_max;
1298 rgb_min =
MIN( r,
MIN( g, b ) );
1299 rgb_max =
MAX( r,
MAX( g, b ) );
1301 l = ( rgb_min + rgb_max ) / 2.0;
1303 if ( rgb_min == rgb_max )
1310 d = rgb_max - rgb_min;
1314 s = 0.5 * d / ( 1. - l );
1316 rc = ( rgb_max - r ) / d;
1317 gc = ( rgb_max - g ) / d;
1318 bc = ( rgb_max - b ) / d;
1322 else if ( g == rgb_max )
1330 else if ( h >= 360 )
1357 if ( fgets(
buffer, length, fp ) == NULL )
1364 pchr = strchr(
buffer,
'\n' );
1371 if ( fscanf( fp,
"%*[^\n]\n" ) == EOF && ferror( fp ) )
1378 pchr = strchr(
buffer,
'\r' );
1386 while ( pchr !=
buffer && *pchr ==
' ' )
1410 int *number_colors,
unsigned int **r,
unsigned int **g,
unsigned int **b,
double **a )
1418 if ( strlen( filename ) == 0 )
1433 snprintf( msgbuf,
MSGLEN,
"Unable to open cmap0 file %s\n", filename );
1438 if ( !err && ( fscanf( fp,
"%d\n", number_colors ) != 1 || *number_colors < 1 ) )
1450 if ( ( ( *r = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1451 ( ( *g = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1452 ( ( *b = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1453 ( ( *a = (
double *) malloc( (
size_t) ( *number_colors ) *
sizeof (
double ) ) ) == NULL ) )
1456 plexit(
"cmap0_palette_read: insufficient memory" );
1459 for ( i = 0; i < *number_colors; i++ )
1468 if ( strlen( color_info ) == 7 )
1470 if ( sscanf( color_info,
"#%2x%2x%2x",
1471 (
unsigned int *) ( *r + i ), (
unsigned int *) ( *g + i ),
1472 (
unsigned int *) ( *b + i ) ) != 3 )
1479 else if ( strlen( color_info ) > 9 )
1481 if ( sscanf( color_info,
"#%2x%2x%2x %lf",
1482 (
unsigned int *) ( *r + i ), (
unsigned int *) ( *g + i ),
1483 (
unsigned int *) ( *b + i ), (
double *) ( *a + i ) ) != 4 )
1494 else if ( *( *a + i ) < 0. )
1498 else if ( *( *a + i ) > 1. )
1512 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap0 format data line. Line is %s\n",
1525 *number_colors = 16;
1526 if ( ( ( *r = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
int ) ) ) == NULL ) ||
1527 ( ( *g = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1528 ( ( *b = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1529 ( ( *a = (
double *) malloc( (
size_t) ( *number_colors ) *
sizeof (
double ) ) ) == NULL ) )
1531 plexit(
"cmap0_palette_read: insufficient memory" );
1537 for ( i = 1; i < *number_colors; i++ )
1561 unsigned int *r, *g, *b;
1569 if ( number_colors > plsc->ncol0 )
1573 for ( i = 0; i < number_colors; i++ )
1592 #define fuzzy_range_check( value, min, max, fuzz, err_number ) \
1593 if ( value < ( min - fuzz ) || value > ( max + fuzz ) ) { \
1594 snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format data line. Error number is %d. Line is %s\n", err_number, color_info ); \
1598 } else if ( value < min ) { \
1600 } else if ( value > max ) { \
1618 int format_version, err;
1621 unsigned int r_i, g_i, b_i;
1622 int pos_i, alt_hue_path_i;
1623 double r_d, g_d, b_d, a_d, pos_d;
1624 PLFLT *r, *g, *b, *a, *pos;
1625 PLINT *ri, *gi, *bi;
1634 if ( strlen( filename ) == 0 )
1649 snprintf( msgbuf,
MSGLEN,
"Unable to open cmap1 .pal file %s\n", filename );
1657 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1662 if ( strncmp( color_info,
"v2 ", 2 ) == 0 )
1665 if ( strncmp( &color_info[3],
"hls", 3 ) == 0 )
1667 else if ( strncmp( &color_info[3],
"rgb", 3 ) == 0 )
1671 snprintf( msgbuf,
MSGLEN,
"Invalid color space %s - assuming RGB\n", &color_info[3] );
1677 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1684 if ( sscanf( color_info,
"%d\n", &number_colors ) != 1 || number_colors < 2 )
1686 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of colors) %s\n", color_info );
1692 r = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1693 g = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1694 b = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1695 ri = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1696 gi = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1697 bi = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1698 a = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1699 pos = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1700 alt_hue_path = (
PLBOOL *) malloc( (
size_t) ( number_colors - 1 ) *
sizeof (
PLBOOL ) );
1702 if ( format_version == 0 )
1704 int return_sscanf = -1, return_sscanf_old = 0;
1706 for ( i = 0; i < number_colors; i++ )
1710 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1716 color_info[
PALLEN - 1] =
'\0';
1717 return_sscanf = sscanf( color_info,
"#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &alt_hue_path_i );
1718 if ( return_sscanf < 4 || ( return_sscanf_old != 0 && return_sscanf != return_sscanf_old ) )
1720 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of items for version 1 of format) %s\n", color_info );
1725 return_sscanf_old = return_sscanf;
1728 r[i] = (
PLFLT) r_i / 255.;
1729 g[i] = (
PLFLT) g_i / 255.;
1730 b[i] = (
PLFLT) b_i / 255.;
1732 pos[i] = 0.01 * (
PLFLT) pos_i;
1737 if ( ( return_sscanf == 5 ) && ( i != number_colors - 1 ) )
1740 alt_hue_path[i] = (
PLBOOL) alt_hue_path_i;
1743 if ( return_sscanf == 4 )
1746 free( alt_hue_path );
1747 alt_hue_path = NULL;
1753 for ( i = 0; i < number_colors; i++ )
1757 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1762 if ( sscanf( color_info,
"%lf %lf %lf %lf %lf %d", &pos_d, &r_d, &g_d, &b_d, &a_d, &alt_hue_path_i ) != 6 )
1764 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of items for version 2 of format) %s\n", color_info );
1774 pos[i] = (
PLFLT) pos_d;
1791 if ( i != number_colors - 1 )
1792 alt_hue_path[i] = (
PLBOOL) alt_hue_path_i;
1801 c_plscmap1la( rgb, number_colors, pos, r, g, b, a, alt_hue_path );
1805 for ( i = 0; i < number_colors; i++ )
1823 r = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1824 g = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1825 b = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1826 pos = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1846 free( alt_hue_path );
1867 if ( plsc->graphx == 1 )
1873 fprintf( stderr,
"\n*** PLPLOT WARNING ***\n" );
1874 if ( *errormsg !=
'\0' )
1875 fprintf( stderr,
"%s\n", errormsg );
1897 ( *abort_handler )( errormsg );
1899 if ( plsc->errcode != NULL )
1900 *( plsc->errcode ) = 1;
1902 if ( plsc->errmsg != NULL )
1904 sprintf( plsc->errmsg,
"\n*** PLPLOT ERROR, ABORTING OPERATION ***\n" );
1905 if ( *errormsg !=
'\0' )
1906 sprintf( plsc->errmsg,
"%s, aborting operation\n", errormsg );
1912 if ( plsc->graphx == 1 )
1918 fprintf( stderr,
"\n*** PLPLOT ERROR, ABORTING OPERATION ***\n" );
1919 if ( *errormsg !=
'\0' )
1920 fprintf( stderr,
"%s, aborting operation\n", errormsg );
1963 status = ( *exit_handler )( errormsg );
1966 if ( *errormsg !=
'\0' )
1968 fprintf( stderr,
"\n*** PLPLOT ERROR, IMMEDIATE EXIT ***\n" );
1969 fprintf( stderr,
"%s\n", errormsg );
1973 fprintf( stderr,
"Program aborted\n" );
2005 if ( plsc->level > 0 )
2020 static int ostate = 0;
2022 if ( !plsc->dev_xor )
2028 if ( plsc->level > 0 )
2033 ostate = plsc->plbuf_write;
2034 plsc->plbuf_write = 0;
2037 plsc->plbuf_write = ostate;
2050 if ( !plsc->dev_modeset )
2052 plwarn(
"plsdrawmode: Mode setting is not supported by this device" );
2054 else if ( plsc->level > 0 )
2060 plwarn(
"plsdrawmode: Initialize PLplot first" );
2075 if ( !plsc->dev_modeset )
2077 plwarn(
"plgdrawmode: Mode getting is not supported by this device" );
2080 else if ( plsc->level > 0 )
2086 plwarn(
"plsdrawmode: Initialize PLplot first" );
2102 if ( plsc->level > 0 )
2120 if ( plsc->level > 0 )
2148 char *fs = NULL, *dn;
2166 #if defined ( PLPLOT_BIN_ENV )
2174 #endif // PLPLOT_BIN_ENV
2184 #if defined ( PLPLOT_HOME_ENV )
2192 #endif // PLPLOT_HOME_ENV
2196 #if defined ( BIN_DIR )
2205 fprintf( stderr,
"plFindCommand: cannot locate command: %s\n", fn );
2206 #if defined ( BIN_DIR )
2207 fprintf( stderr,
"bin dir=\"" BIN_DIR "\"\n" );
2238 if ( pdfs->
file != NULL )
2266 char *fs = NULL, *dn = NULL;
2274 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2280 #if defined ( PLPLOT_LIB_ENV )
2285 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2289 #endif // PLPLOT_LIB_ENV
2293 if ( ( file =
pdf_fopen( fn,
"rb" ) ) != NULL )
2295 pldebug(
"plLibOpenPdfstr",
"Found file %s in current directory.\n", fn );
2302 #if defined ( PLPLOT_HOME_ENV )
2307 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2311 #endif // PLPLOT_HOME_ENV/lib
2315 #if defined ( DATA_DIR )
2318 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2327 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2332 file = plMacLibOpen( fn );
2340 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2345 pldebug(
"plLibOpenPdfstr",
"File %s not found.\n", fn );
2350 pldebug(
"plLibOpenPdfstr",
"Found file %s\n", fs );
2385 pldebug(
"plFindName",
"Trying to find %s\n", p );
2388 pldebug(
"plFindName",
"Readlink read %d chars at: %s\n", n, p );
2389 if (
buf[0] ==
'/' )
2393 strncpy( p,
buf, (
size_t) n );
2395 pldebug(
"plFindName",
"Link is absolute: %s\n", p );
2401 cp = 1 + strrchr( p,
'/' );
2402 strncpy( cp,
buf, (
size_t) n );
2404 pldebug(
"plFindName",
2405 "Link is relative: %s\n\tTotal path:%s\n", cp, p );
2412 #define S_ISREG( mode ) ( mode & S_IFREG )
2417 if ( errno == EINVAL || errno == ENXIO )
2419 pldebug(
"plFindName",
"%s may be the one...\n", p );
2420 if ( ( stat( p, &sbuf ) == 0 ) && S_ISREG( sbuf.st_mode ) )
2422 pldebug(
"plFindName",
"%s is a regular file\n", p );
2423 return (
access( p, X_OK ) );
2426 pldebug(
"plFindName",
"%s found but is not executable\n", p );
2427 return ( errno ? errno : -1 );
2462 lfilespec = strlen( dir ) + strlen( subdir ) + strlen( filename ) + 10;
2463 if ( ( *filespec = (
char *) malloc( lfilespec ) ) == NULL )
2465 plexit(
"plGetName: Insufficient memory" );
2468 strcpy( *filespec, dir );
2470 if ( *subdir !=
'\0' )
2473 strcat( *filespec, subdir );
2475 if ( *filename !=
'\0' )
2478 strcat( *filespec, filename );
2484 pldebug(
"plGetName",
"Maximum length of full pathname of file to be found is %lu\n", lfilespec - 1 );
2486 pldebug(
"plGetName",
"Maximum length of full pathname of file to be found is %zu\n", lfilespec - 1 );
2488 pldebug(
"plGetName",
"Full pathname of file to be found is %s\n", *filespec );
2503 size_t ldirspec = strlen( dirspec );
2504 #if defined ( MSDOS ) || defined ( _WIN32 )
2505 if ( dirspec[ldirspec - 1] !=
'\\' )
2506 strcat( dirspec,
"\\" );
2507 #elif defined ( macintosh )
2508 if ( dirspec[ldirspec - 1] !=
':' )
2509 strcat( dirspec,
":" );
2510 #else // unix is the default
2511 if ( dirspec[ldirspec - 1] !=
'/' )
2512 strcat( dirspec,
"/" );
2535 x = (double) ( i * (
pls->
ncol1 - 1 ) ) / (
double) ( ncol - 1 );
2541 fprintf( stderr,
"Invalid color\n" );
2543 else if ( ir ==
pls->
ncol1 || ( delta == 0. ) )
2552 newcolor->
r = (
unsigned char) ( ( 1. - delta ) *
pls->
cmap1[il].
r + delta *
pls->
cmap1[ir].
r );
2553 newcolor->
g = (
unsigned char) ( ( 1. - delta ) *
pls->
cmap1[il].
g + delta *
pls->
cmap1[ir].
g );
2554 newcolor->
b = (
unsigned char) ( ( 1. - delta ) *
pls->
cmap1[il].
b + delta *
pls->
cmap1[ir].
b );
2569 #define MAX_NUM_TRIES 10
2573 int i = 0, count = 0;
2591 fprintf( stdout,
"Enter graphics output file name: " );
2593 len = strlen(
line );
2617 plexit(
"Too many tries." );
2620 fprintf( stderr,
"Can't open %s.\n",
pls->
FileName );
2622 pldebug(
"plOpenFile",
"Opened %s\n",
pls->
FileName );
2670 plexit(
"plP_getmember: Insufficient memory" );
2679 if ( suffix == NULL )
2710 maxlen = 10 + strlen( fnam );
2713 plexit(
"plP_sfnam: Insufficient memory" );
2716 suffix = strstr( fnam,
"%n" );
2718 if ( suffix == NULL )
2735 plexit(
"plP_sfnam: Insufficient memory" );
2782 PLFLT xpmm_loc, ypmm_loc;
2800 plP_setpxl( xpmm_loc * plsc->caspfactor, ypmm_loc / plsc->caspfactor );
2832 switch ( orient % 4 )
2835 *px = xmin + ( y - ymin );
2836 *py = ymin + ( xmax - x );
2840 *px = xmin + ( xmax - x );
2841 *py = ymin + ( ymax - y );
2845 *px = xmin + ( ymax - y );
2846 *py = ymin + ( x - xmin );
2869 free( (
void *)
pls->
dev );
2871 pls->
dev = calloc( 1, (
size_t)
sizeof (
PLDev ) );
2873 plexit(
"plAllocDev: cannot allocate memory\n" );
2894 gin->
pX = gin->
pY = -1;
2895 gin->
dX = gin->
dY = 0.;
2896 gin->
wX = gin->
wY = 0.;
2925 if ( sscanf(
line,
"%d", &m ) == 1 )
2927 fprintf( stdout,
"No value or value out of range; please try again\n" );
2930 plexit(
"Too many tries." );
2961 if ( sscanf(
line,
"%lf", &m1 ) == 1 )
2966 fprintf( stdout,
"No value or value out of range; please try again\n" );
2969 plexit(
"Too many tries." );
2987 char *dest = (
char *) malloc( ( strlen( src ) + 1 ) *
sizeof ( char ) );
2989 strcpy( dest, src );
2996 #ifndef PL_HAVE_SNPRINTF
3018 va_start( args, format );
3019 ret = vsprintf(
buffer, format, args );
3024 plabort(
"plsnprintf: buffer overrun" );
3050 va_start( args, format );
3051 ret = vsscanf(
buffer, format, args );
3057 #endif // PL_HAVE_SNPRINTF
3103 char * setlocale_ptr;
3104 char * saved_lc_numeric_locale;
3106 if ( !( saved_lc_numeric_locale = (
char *) malloc( 100 *
sizeof (
char ) ) ) )
3108 plexit(
"plsave_set_locale: out of memory" );
3112 if ( !( setlocale_ptr = setlocale( LC_NUMERIC, NULL ) ) )
3114 plexit(
"plsave_set_locale: LC_NUMERIC locale could not be determined for NULL locale.\n" );
3116 strncpy( saved_lc_numeric_locale, setlocale_ptr, 100 );
3117 saved_lc_numeric_locale[99] =
'\0';
3127 if ( !( setlocale( LC_NUMERIC,
"C" ) ) )
3129 plexit(
"plsave_set_locale: LC_NUMERIC locale could not be set to \"C\"" );
3131 return saved_lc_numeric_locale;
3155 if ( !( setlocale( LC_NUMERIC, saved_lc_numeric_locale ) ) )
3158 snprintf( msgbuf, 1024,
"plrestore_locale: LC_NUMERIC could not be restored to the default \"%s\" locale.\n", saved_lc_numeric_locale );
3161 free( saved_lc_numeric_locale );
3170 ( alpha != NULL && (
isnan( *alpha ) || ( *alpha < MIN_PLFLT_ALPHA || *alpha >
MAX_PLFLT_ALPHA ) ) ) )
3173 fprintf( stderr,
"%s\n",
"Further information relevant to this warning:" );
3174 if ( alpha != NULL )
3176 fprintf( stderr,
"Invalid RGBA color: %d, %d, %d, %e\n", (
int) *r, (
int) *g, (
int) *b, (
double) *alpha );
3180 if (
isnan( *alpha ) )
3183 fprintf( stderr,
"Corrected RGBA color: %d, %d, %d, %e\n", (
int) *r, (
int) *g, (
int) *b, (
double) *alpha );
3188 fprintf( stderr,
"Invalid RGB color: %d, %d, %d\n", (
int) *r, (
int) *g, (
int) *b );
3192 fprintf( stderr,
"Corrected RGB color: %d, %d, %d\n", (
int) *r, (
int) *g, (
int) *b );