44 #ifdef DJGPP // dos386/djgpp
51 #include <sys/types.h>
53 #ifdef PL_HAVE_UNISTD_H
62 #define BUFFER_SIZE 256
69 #define FUZZ_EPSILON 1.e-4
95 value(
double n1,
double n2,
double hue );
102 int *number_colors,
unsigned int **r,
unsigned int **g,
103 unsigned int **b,
double **a );
108 #if defined ( DJGPP )
110 #define PLLIBDEV "c:/plplot/lib"
113 #elif defined ( MSDOS )
115 #define PLLIBDEV "c:\\plplot\\lib"
123 #define PLLIBDEV "/usr/local/plplot/lib"
143 if ( plsc->level < 1 )
145 plabort(
"plcol0: Please call plinit first" );
148 if ( icol0 < 0 || icol0 >= plsc->ncol0 )
157 plsc->curcolor.r = plsc->cmap0[icol0].r;
158 plsc->curcolor.g = plsc->cmap0[icol0].g;
159 plsc->curcolor.b = plsc->cmap0[icol0].b;
160 plsc->curcolor.a = plsc->cmap0[icol0].a;
179 if ( plsc->level < 1 )
181 plabort(
"plcol1: Please call plinit first" );
184 if ( col1 < 0 || col1 > 1 ||
isnan( col1 ) )
192 icol1 = (
PLINT) ( col1 * plsc->ncol1 );
193 icol1 =
MIN( icol1, plsc->ncol1 - 1 );
196 plsc->curcolor.r = plsc->cmap1[plsc->icol1].r;
197 plsc->curcolor.g = plsc->cmap1[plsc->icol1].g;
198 plsc->curcolor.b = plsc->cmap1[plsc->icol1].b;
199 plsc->curcolor.a = plsc->cmap1[plsc->icol1].a;
284 if ( plsc->cmap0 == NULL )
286 if ( icol0 < 0 || icol0 >= plsc->ncol0 )
293 if ( ( r < 0 || r > 255 ) || ( g < 0 || g > 255 ) || ( b < 0 || b > 255 ) )
297 (
int) r, (
int) g, (
int) b );
320 if ( plsc->cmap0 == NULL )
322 if ( icol0 < 0 || icol0 >= plsc->ncol0 )
329 if ( ( r < 0 || r > 255 ) || ( g < 0 || g > 255 ) || ( b < 0 || b > 255 ) || ( alpha < 0. || alpha > 1.0 ) )
333 (
int) r, (
int) g, (
int) b, (
double) 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 )
406 if ( icol0 < 0 || icol0 > plsc->ncol0 )
414 *r = plsc->cmap0[icol0].r;
415 *g = plsc->cmap0[icol0].g;
416 *b = plsc->cmap0[icol0].b;
417 *alpha = plsc->cmap0[icol0].a;
440 for ( i = 0; i < plsc->ncol0; i++ )
442 if ( ( r[i] < 0 || r[i] > 255 ) ||
443 ( g[i] < 0 || g[i] > 255 ) ||
444 ( b[i] < 0 || b[i] > 255 ) )
448 (
int) r[i], (
int) g[i], (
int) b[i] );
453 plsc->cmap0[i].r = (
unsigned char) r[i];
454 plsc->cmap0[i].g = (
unsigned char) g[i];
455 plsc->cmap0[i].b = (
unsigned char) b[i];
456 plsc->cmap0[i].a = 1.0;
459 if ( plsc->level > 0 )
482 for ( i = 0; i < plsc->ncol0; i++ )
484 if ( ( r[i] < 0 || r[i] > 255 ) ||
485 ( g[i] < 0 || g[i] > 255 ) ||
486 ( b[i] < 0 || b[i] > 255 ) ||
487 ( alpha[i] < 0.0 || alpha[i] > 1.0 ) )
491 (
int) r[i], (
int) g[i], (
int) b[i], (
double) alpha[i] );
496 plsc->cmap0[i].r = (
unsigned char) r[i];
497 plsc->cmap0[i].g = (
unsigned char) g[i];
498 plsc->cmap0[i].b = (
unsigned char) b[i];
499 plsc->cmap0[i].a = alpha[i];
502 if ( plsc->level > 0 )
524 for ( i = 0; i < plsc->ncol1; i++ )
526 if ( ( r[i] < 0 || r[i] > 255 ) ||
527 ( g[i] < 0 || g[i] > 255 ) ||
528 ( b[i] < 0 || b[i] > 255 ) )
532 (
int) r[i], (
int) g[i], (
int) b[i] );
536 plsc->cmap1[i].r = (
unsigned char) r[i];
537 plsc->cmap1[i].g = (
unsigned char) g[i];
538 plsc->cmap1[i].b = (
unsigned char) b[i];
539 plsc->cmap1[i].a = 1.0;
542 if ( plsc->level > 0 )
565 for ( i = 0; i < plsc->ncol1; i++ )
567 if ( ( r[i] < 0 || r[i] > 255 ) ||
568 ( g[i] < 0 || g[i] > 255 ) ||
569 ( b[i] < 0 || b[i] > 255 ) ||
570 ( alpha[i] < 0.0 || alpha[i] > 1.0 ) )
574 (
int) r[i], (
int) g[i], (
int) b[i], (
double) alpha[i] );
578 plsc->cmap1[i].r = (
unsigned char) r[i];
579 plsc->cmap1[i].g = (
unsigned char) g[i];
580 plsc->cmap1[i].b = (
unsigned char) b[i];
581 plsc->cmap1[i].a = alpha[i];
584 if ( plsc->level > 0 )
645 PLFLT h, l, s, r, g, b;
649 plabort(
"plscmap1l: Must specify at least two control points" );
653 if ( ( intensity[0] != 0 ) || ( intensity[npts - 1] != 1 ) )
655 plabort(
"plscmap1l: First, last control points must lie on boundary" );
661 plabort(
"plscmap1l: exceeded maximum number of control points" );
667 if ( plsc->cmap1 == NULL )
674 for ( n = 0; n < npts; n++ )
690 plsc->cmap1cp[n].h = h;
691 plsc->cmap1cp[n].l = l;
692 plsc->cmap1cp[n].s = s;
693 plsc->cmap1cp[n].p = intensity[n];
694 plsc->cmap1cp[n].a = 1.0;
696 if ( alt_hue_path == NULL )
697 plsc->cmap1cp[n].alt_hue_path = 0;
700 plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
703 plsc->cmap1cp[n].alt_hue_path = 0;
731 PLFLT h, l, s, r, g, b;
735 plabort(
"plscmap1la: Must specify at least two control points" );
739 if ( ( intensity[0] != 0 ) || ( intensity[npts - 1] != 1 ) )
741 plabort(
"plscmap1la: First, last control points must lie on boundary" );
747 plabort(
"plscmap1la: exceeded maximum number of control points" );
753 if ( plsc->cmap1 == NULL )
760 for ( n = 0; n < npts; n++ )
776 plsc->cmap1cp[n].h = h;
777 plsc->cmap1cp[n].l = l;
778 plsc->cmap1cp[n].s = s;
779 plsc->cmap1cp[n].p = intensity[n];
780 plsc->cmap1cp[n].a = alpha[n];
782 if ( alt_hue_path == NULL )
783 plsc->cmap1cp[n].alt_hue_path = 0;
786 plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
789 plsc->cmap1cp[n].alt_hue_path = 0;
807 PLFLT delta, dp, dh, dl, ds, da;
808 PLFLT h, l, s, p, r, g, b, a;
812 for ( n = 0; n < plsc->ncp1 - 1; n++ )
814 if ( plsc->cmap1cp[n].p == plsc->cmap1cp[n + 1].p )
819 dp = plsc->cmap1cp[n + 1].p - plsc->cmap1cp[n].p;
820 dh = plsc->cmap1cp[n + 1].h - plsc->cmap1cp[n].h;
821 dl = plsc->cmap1cp[n + 1].l - plsc->cmap1cp[n].l;
822 ds = plsc->cmap1cp[n + 1].s - plsc->cmap1cp[n].s;
823 da = plsc->cmap1cp[n + 1].a - plsc->cmap1cp[n].a;
827 if ( plsc->cmap1cp[n].alt_hue_path )
828 dh = ( dh > 0 ) ? dh - 360 : dh + 360;
833 for ( i = 0; i < plsc->ncol1; i++ )
835 p = (double) i / ( plsc->ncol1 - 1.0 );
836 if ( ( p < plsc->cmap1cp[n].p ) ||
837 ( p > plsc->cmap1cp[n + 1].p ) )
842 delta = ( p - plsc->cmap1cp[n].p ) / dp;
846 h = plsc->cmap1cp[n].h + dh * delta;
847 l = plsc->cmap1cp[n].l + dl * delta;
848 s = plsc->cmap1cp[n].s + ds * delta;
849 a = plsc->cmap1cp[n].a + da * delta;
859 plsc->cmap1[i].r = (
unsigned char)
MAX( 0,
MIN( 255, (
int) ( 256. * r ) ) );
860 plsc->cmap1[i].g = (
unsigned char)
MAX( 0,
MIN( 255, (
int) ( 256. * g ) ) );
861 plsc->cmap1[i].b = (
unsigned char)
MAX( 0,
MIN( 255, (
int) ( 256. * b ) ) );
862 plsc->cmap1[i].a = a;
866 if ( plsc->level > 0 )
887 if ( min_color > max_color || max_color < 0.0 || min_color > 1.0 )
889 plwarn(
"plscmap1_range called with invalid color range" );
892 if ( min_color < 0.0 )
894 plwarn(
"plscmap1_range called with a negative minimum color value" );
897 if ( max_color > 1.0 )
899 plwarn(
"plscmap1_range called with an out of range maximum color value" );
902 plsc->cmap1_min = min_color;
903 plsc->cmap1_max = max_color;
916 *min_color = plsc->cmap1_min;
917 *max_color = plsc->cmap1_max;
934 int ncol, size, imin, imax;
938 if ( ncol0 > 0 && plsc->ncol0 == ncol0 )
943 if ( plsc->ncol0 <= 0 && ncol0 <= 0 )
945 else if ( ncol0 <= 0 )
951 size = ncol * (int)
sizeof (
PLColor );
955 if ( plsc->cmap0 == NULL )
957 if ( ( plsc->cmap0 = (
PLColor *) calloc( 1, (
size_t) size ) ) == NULL )
959 plexit(
"c_plscmap0n: Insufficient memory" );
965 if ( ( plsc->cmap0 = (
PLColor *) realloc( plsc->cmap0, (
size_t) size ) ) == NULL )
967 plexit(
"c_plscmap0n: Insufficient memory" );
977 if ( plsc->level > 0 )
996 plsc->cmap0[i].r = r;
997 plsc->cmap0[i].g = g;
998 plsc->cmap0[i].b = b;
999 plsc->cmap0[i].a = a;
1000 plsc->cmap0[i].name =
name;
1003 #define color_def( i, r, g, b, a, n ) \
1004 if ( i >= imin && i <= imax ) color_set( i, r, g, b, a, n );
1019 unsigned int *r, *g, *b;
1025 for ( i = imin; i <=
MIN( ( number_colors - 1 ), imax ); i++ )
1027 "colors defined by default cmap0 palette file" );
1040 for ( i =
MAX( number_colors, imin ); i <= imax; i++ )
1042 "opaque red colour to mark not defined by palette file" );
1064 if ( ncol1 > 0 && plsc->ncol1 == ncol1 )
1069 if ( plsc->ncol1 <= 0 && ncol1 <= 0 )
1071 else if ( ncol1 <= 0 )
1076 size = (size_t) ncol *
sizeof (
PLColor );
1080 if ( plsc->ncol1 > 0 )
1082 if ( ( plsc->cmap1 = (
PLColor *) realloc( plsc->cmap1, size ) ) == NULL )
1084 plexit(
"c_plscmap1n: Insufficient memory" );
1089 if ( ( plsc->cmap1 = (
PLColor *) calloc( (
size_t) ncol,
sizeof (
PLColor ) ) ) == NULL )
1091 plexit(
"c_plscmap1n: Insufficient memory" );
1098 if ( plsc->ncp1 == 0 )
1120 PLFLT i[6], h[6], l[6], s[6], midpt = 0., vertex = 0.;
1134 if ( plsc->cmap0 != NULL )
1135 vertex = ( (
PLFLT) plsc->cmap0[0].r +
1136 (
PLFLT) plsc->cmap0[0].g +
1137 (
PLFLT) plsc->cmap0[0].b ) / 3. / 255.;
1179 if ( plsc->level > 0 )
1195 plsc->color = color;
1209 value(
double n1,
double n2,
double hue )
1213 while ( hue >= 360. )
1219 val = n1 + ( n2 - n1 ) * hue / 60.;
1220 else if ( hue < 180. )
1222 else if ( hue < 240. )
1223 val = n1 + ( n2 - n1 ) * ( 240. - hue ) / 60.;
1256 m2 = l * ( s + 1. );
1262 *p_r =
value( m1, m2, h + 120. );
1263 *p_g =
value( m1, m2, h );
1264 *p_b =
value( m1, m2, h - 120. );
1286 PLFLT h, l, s, d, rc, gc, bc, rgb_min, rgb_max;
1288 rgb_min =
MIN( r,
MIN( g, b ) );
1289 rgb_max =
MAX( r,
MAX( g, b ) );
1291 l = ( rgb_min + rgb_max ) / 2.0;
1293 if ( rgb_min == rgb_max )
1300 d = rgb_max - rgb_min;
1304 s = 0.5 * d / ( 1. - l );
1306 rc = ( rgb_max - r ) / d;
1307 gc = ( rgb_max - g ) / d;
1308 bc = ( rgb_max - b ) / d;
1312 else if ( g == rgb_max )
1320 else if ( h >= 360 )
1347 if ( fgets( buffer, length, fp ) == NULL )
1354 pchr = strchr( buffer,
'\n' );
1361 if ( fscanf( fp,
"%*[^\n]\n" ) == EOF && ferror( fp ) )
1368 pchr = strchr( buffer,
'\r' );
1375 pchr = buffer + strlen( buffer ) - 1;
1376 while ( pchr != buffer && *pchr ==
' ' )
1400 int *number_colors,
unsigned int **r,
unsigned int **g,
unsigned int **b,
double **a )
1408 if ( strlen( filename ) == 0 )
1423 snprintf( msgbuf,
MSGLEN,
"Unable to open cmap0 file %s\n", filename );
1428 if ( !err && ( fscanf( fp,
"%d\n", number_colors ) != 1 || *number_colors < 1 ) )
1440 if ( ( ( *r = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1441 ( ( *g = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1442 ( ( *b = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1443 ( ( *a = (
double *) malloc( (
size_t) ( *number_colors ) *
sizeof (
double ) ) ) == NULL ) )
1446 plexit(
"cmap0_palette_read: insufficient memory" );
1449 for ( i = 0; i < *number_colors; i++ )
1458 if ( strlen( color_info ) == 7 )
1460 if ( sscanf( color_info,
"#%2x%2x%2x",
1461 (
unsigned int *) ( *r + i ), (
unsigned int *) ( *g + i ),
1462 (
unsigned int *) ( *b + i ) ) != 3 )
1469 else if ( strlen( color_info ) > 9 )
1471 if ( sscanf( color_info,
"#%2x%2x%2x %lf",
1472 (
unsigned int *) ( *r + i ), (
unsigned int *) ( *g + i ),
1473 (
unsigned int *) ( *b + i ), (
double *) ( *a + i ) ) != 4 )
1484 else if ( *( *a + i ) < 0. )
1488 else if ( *( *a + i ) > 1. )
1502 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap0 format data line. Line is %s\n",
1515 *number_colors = 16;
1516 if ( ( ( *r = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
int ) ) ) == NULL ) ||
1517 ( ( *g = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1518 ( ( *b = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1519 ( ( *a = (
double *) malloc( (
size_t) ( *number_colors ) *
sizeof (
double ) ) ) == NULL ) )
1521 plexit(
"cmap0_palette_read: insufficient memory" );
1527 for ( i = 1; i < *number_colors; i++ )
1551 unsigned int *r, *g, *b;
1559 if ( number_colors > plsc->ncol0 )
1563 for ( i = 0; i < number_colors; i++ )
1582 #define fuzzy_range_check( value, min, max, fuzz, err_number ) \
1583 if ( value < ( min - fuzz ) || value > ( max + fuzz ) ) { \
1584 snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format data line. Error number is %d. Line is %s\n", err_number, color_info ); \
1588 } else if ( value < min ) { \
1590 } else if ( value > max ) { \
1608 int format_version, err;
1611 unsigned int r_i, g_i, b_i;
1612 int pos_i, alt_hue_path_i;
1613 double r_d, g_d, b_d, a_d, pos_d;
1614 PLFLT *r, *g, *b, *a, *pos;
1615 PLINT *ri, *gi, *bi;
1624 if ( strlen( filename ) == 0 )
1639 snprintf( msgbuf,
MSGLEN,
"Unable to open cmap1 .pal file %s\n", filename );
1647 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1652 if ( strncmp( color_info,
"v2 ", 2 ) == 0 )
1655 if ( strncmp( &color_info[3],
"hls", 3 ) == 0 )
1657 else if ( strncmp( &color_info[3],
"rgb", 3 ) == 0 )
1661 snprintf( msgbuf,
MSGLEN,
"Invalid color space %s - assuming RGB\n", &color_info[3] );
1667 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1674 if ( sscanf( color_info,
"%d\n", &number_colors ) != 1 || number_colors < 2 )
1676 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of colors) %s\n", color_info );
1682 r = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1683 g = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1684 b = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1685 ri = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1686 gi = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1687 bi = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1688 a = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1689 pos = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1690 alt_hue_path = (
PLBOOL *) malloc( (
size_t) ( number_colors - 1 ) *
sizeof (
PLBOOL ) );
1692 if ( format_version == 0 )
1694 int return_sscanf = -1, return_sscanf_old = 0;
1696 for ( i = 0; i < number_colors; i++ )
1700 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1706 color_info[
PALLEN - 1] =
'\0';
1707 return_sscanf = sscanf( color_info,
"#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &alt_hue_path_i );
1708 if ( return_sscanf < 4 || ( return_sscanf_old != 0 && return_sscanf != return_sscanf_old ) )
1710 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of items for version 1 of format) %s\n", color_info );
1715 return_sscanf_old = return_sscanf;
1718 r[i] = (
PLFLT) r_i / 255.;
1719 g[i] = (
PLFLT) g_i / 255.;
1720 b[i] = (
PLFLT) b_i / 255.;
1722 pos[i] = 0.01 * (
PLFLT) pos_i;
1727 if ( ( return_sscanf == 5 ) && ( i != number_colors - 1 ) )
1730 alt_hue_path[i] = (
PLBOOL) alt_hue_path_i;
1733 if ( return_sscanf == 4 )
1736 free( alt_hue_path );
1737 alt_hue_path = NULL;
1743 for ( i = 0; i < number_colors; i++ )
1747 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1752 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 )
1754 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of items for version 2 of format) %s\n", color_info );
1764 pos[i] = (
PLFLT) pos_d;
1781 if ( i != number_colors - 1 )
1782 alt_hue_path[i] = (
PLBOOL) alt_hue_path_i;
1791 c_plscmap1la( rgb, number_colors, pos, r, g, b, a, alt_hue_path );
1795 for ( i = 0; i < number_colors; i++ )
1797 ri[i] = (
PLINT) ( r[i] * 255.0 );
1798 gi[i] = (
PLINT) ( g[i] * 255.0 );
1799 bi[i] = (
PLINT) ( b[i] * 255.0 );
1813 r = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1814 g = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1815 b = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1816 pos = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1836 free( alt_hue_path );
1857 if ( plsc->graphx == 1 )
1863 fprintf( stderr,
"\n*** PLPLOT WARNING ***\n" );
1864 if ( *errormsg !=
'\0' )
1865 fprintf( stderr,
"%s\n", errormsg );
1887 ( *abort_handler )( errormsg );
1889 if ( plsc->errcode != NULL )
1890 *( plsc->errcode ) = 1;
1892 if ( plsc->errmsg != NULL )
1894 sprintf( plsc->errmsg,
"\n*** PLPLOT ERROR, ABORTING OPERATION ***\n" );
1895 if ( *errormsg !=
'\0' )
1896 sprintf( plsc->errmsg,
"%s, aborting operation\n", errormsg );
1902 if ( plsc->graphx == 1 )
1908 fprintf( stderr,
"\n*** PLPLOT ERROR, ABORTING OPERATION ***\n" );
1909 if ( *errormsg !=
'\0' )
1910 fprintf( stderr,
"%s, aborting operation\n", errormsg );
1953 status = ( *exit_handler )( errormsg );
1956 if ( *errormsg !=
'\0' )
1958 fprintf( stderr,
"\n*** PLPLOT ERROR, IMMEDIATE EXIT ***\n" );
1959 fprintf( stderr,
"%s\n", errormsg );
1963 fprintf( stderr,
"Program aborted\n" );
1995 if ( plsc->level > 0 )
2010 static int ostate = 0;
2012 if ( !plsc->dev_xor )
2018 if ( plsc->level > 0 )
2023 ostate = plsc->plbuf_write;
2024 plsc->plbuf_write = 0;
2027 plsc->plbuf_write = ostate;
2040 if ( !plsc->dev_modeset )
2042 plwarn(
"plsdrawmode: Mode setting is not supported by this device" );
2044 else if ( plsc->level > 0 )
2050 plwarn(
"plsdrawmode: Initialize PLplot first" );
2065 if ( !plsc->dev_modeset )
2067 plwarn(
"plgdrawmode: Mode getting is not supported by this device" );
2070 else if ( plsc->level > 0 )
2076 plwarn(
"plsdrawmode: Initialize PLplot first" );
2092 if ( plsc->level > 0 )
2110 if ( plsc->level > 0 )
2138 char *fs = NULL, *dn;
2156 #if defined ( PLPLOT_BIN_ENV )
2164 #endif // PLPLOT_BIN_ENV
2174 #if defined ( PLPLOT_HOME_ENV )
2182 #endif // PLPLOT_HOME_ENV
2186 #if defined ( BIN_DIR )
2195 fprintf( stderr,
"plFindCommand: cannot locate command: %s\n", fn );
2196 #if defined ( BIN_DIR )
2197 fprintf( stderr,
"bin dir=\"" BIN_DIR "\"\n" );
2228 if ( pdfs->
file != NULL )
2256 char *fs = NULL, *dn = NULL;
2264 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2270 #if defined ( PLPLOT_LIB_ENV )
2275 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2279 #endif // PLPLOT_LIB_ENV
2283 if ( ( file =
pdf_fopen( fn,
"rb" ) ) != NULL )
2285 pldebug(
"plLibOpenPdfstr",
"Found file %s in current directory.\n", fn );
2292 #if defined ( PLPLOT_HOME_ENV )
2297 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2301 #endif // PLPLOT_HOME_ENV/lib
2305 #if defined ( DATA_DIR )
2308 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2317 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2322 file = plMacLibOpen( fn );
2330 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2335 pldebug(
"plLibOpenPdfstr",
"File %s not found.\n", fn );
2340 pldebug(
"plLibOpenPdfstr",
"Found file %s\n", fs );
2375 pldebug(
"plFindName",
"Trying to find %s\n", p );
2378 pldebug(
"plFindName",
"Readlink read %d chars at: %s\n", n, p );
2379 if ( buf[0] ==
'/' )
2383 strncpy( p, buf, (
size_t) n );
2385 pldebug(
"plFindName",
"Link is absolute: %s\n", p );
2391 cp = 1 + strrchr( p,
'/' );
2392 strncpy( cp, buf, (
size_t) n );
2394 pldebug(
"plFindName",
2395 "Link is relative: %s\n\tTotal path:%s\n", cp, p );
2402 #define S_ISREG( mode ) ( mode & S_IFREG )
2407 if ( errno == EINVAL || errno == ENXIO )
2409 pldebug(
"plFindName",
"%s may be the one...\n", p );
2410 if ( ( stat( p, &sbuf ) == 0 ) && S_ISREG( sbuf.st_mode ) )
2412 pldebug(
"plFindName",
"%s is a regular file\n", p );
2413 return (
access( p, X_OK ) );
2416 pldebug(
"plFindName",
"%s found but is not executable\n", p );
2417 return ( errno ? errno : -1 );
2452 lfilespec = strlen( dir ) + strlen( subdir ) + strlen( filename ) + 10;
2453 if ( ( *filespec = (
char *) malloc( lfilespec ) ) == NULL )
2455 plexit(
"plGetName: Insufficient memory" );
2458 strcpy( *filespec, dir );
2460 if ( *subdir !=
'\0' )
2463 strcat( *filespec, subdir );
2465 if ( *filename !=
'\0' )
2468 strcat( *filespec, filename );
2474 pldebug(
"plGetName",
"Maximum length of full pathname of file to be found is %lu\n", lfilespec - 1 );
2476 pldebug(
"plGetName",
"Maximum length of full pathname of file to be found is %zu\n", lfilespec - 1 );
2478 pldebug(
"plGetName",
"Full pathname of file to be found is %s\n", *filespec );
2493 size_t ldirspec = strlen( dirspec );
2494 #if defined ( MSDOS ) || defined ( WIN32 )
2495 if ( dirspec[ldirspec - 1] !=
'\\' )
2496 strcat( dirspec,
"\\" );
2497 #elif defined ( macintosh )
2498 if ( dirspec[ldirspec - 1] !=
':' )
2499 strcat( dirspec,
":" );
2500 #else // unix is the default
2501 if ( dirspec[ldirspec - 1] !=
'/' )
2502 strcat( dirspec,
"/" );
2525 x = (double) ( i * ( pls->
ncol1 - 1 ) ) / (
double) ( ncol - 1 );
2530 if ( ir > pls->
ncol1 || il < 0 )
2531 fprintf( stderr,
"Invalid color\n" );
2533 else if ( ir == pls->
ncol1 || ( delta == 0. ) )
2535 newcolor->
r = pls->
cmap1[il].
r;
2536 newcolor->
g = pls->
cmap1[il].
g;
2537 newcolor->
b = pls->
cmap1[il].
b;
2538 newcolor->
a = pls->
cmap1[il].
a;
2542 newcolor->
r = (
unsigned char) ( ( 1. - delta ) * pls->
cmap1[il].
r + delta * pls->
cmap1[ir].
r );
2543 newcolor->
g = (
unsigned char) ( ( 1. - delta ) * pls->
cmap1[il].
g + delta * pls->
cmap1[ir].
g );
2544 newcolor->
b = (
unsigned char) ( ( 1. - delta ) * pls->
cmap1[il].
b + delta * pls->
cmap1[ir].
b );
2545 newcolor->
a = ( 1. - delta ) * pls->
cmap1[il].
a + delta * pls->
cmap1[ir].
a;
2559 #define MAX_NUM_TRIES 10
2563 int i = 0, count = 0;
2567 while ( pls->
OutFile == NULL )
2581 fprintf( stdout,
"Enter graphics output file name: " );
2583 len = strlen( line );
2594 if ( !strcmp( pls->
FileName,
"-" ) )
2607 plexit(
"Too many tries." );
2610 fprintf( stderr,
"Can't open %s.\n", pls->
FileName );
2612 pldebug(
"plOpenFile",
"Opened %s\n", pls->
FileName );
2655 maxlen = strlen( pls->
BaseName ) + 10;
2658 if ( ( pls->
FileName = (
char *) malloc( maxlen ) ) == NULL )
2660 plexit(
"plP_getmember: Insufficient memory" );
2664 suffix = strstr( pls->
BaseName,
"%n" );
2669 if ( suffix == NULL )
2700 maxlen = 10 + strlen( fnam );
2701 if ( ( pls->
FileName = (
char *) malloc( maxlen ) ) == NULL )
2703 plexit(
"plP_sfnam: Insufficient memory" );
2706 suffix = strstr( fnam,
"%n" );
2708 if ( suffix == NULL )
2710 strncpy( pls->
FileName, fnam, maxlen - 1 );
2723 if ( ( pls->
BaseName = (
char *) malloc( maxlen ) ) == NULL )
2725 plexit(
"plP_sfnam: Insufficient memory" );
2728 strncpy( pls->
BaseName, fnam, maxlen - 1 );
2772 PLFLT xpmm_loc, ypmm_loc;
2790 plP_setpxl( xpmm_loc * plsc->caspfactor, ypmm_loc / plsc->caspfactor );
2822 switch ( orient % 4 )
2825 *px = xmin + ( y - ymin );
2826 *py = ymin + ( xmax - x );
2830 *px = xmin + ( xmax - x );
2831 *py = ymin + ( ymax - y );
2835 *px = xmin + ( ymax - y );
2836 *py = ymin + ( x - xmin );
2858 if ( pls->
dev != NULL )
2859 free( (
void *) pls->
dev );
2861 pls->
dev = calloc( 1, (
size_t)
sizeof (
PLDev ) );
2862 if ( pls->
dev == NULL )
2863 plexit(
"plAllocDev: cannot allocate memory\n" );
2884 gin->
pX = gin->
pY = -1;
2885 gin->
dX = gin->
dY = 0.;
2886 gin->
wX = gin->
wY = 0.;
2915 if ( sscanf( line,
"%d", &m ) == 1 )
2917 fprintf( stdout,
"No value or value out of range; please try again\n" );
2920 plexit(
"Too many tries." );
2951 if ( sscanf( line,
"%lf", &m1 ) == 1 )
2956 fprintf( stdout,
"No value or value out of range; please try again\n" );
2959 plexit(
"Too many tries." );
2977 char *dest = (
char *) malloc( ( strlen( src ) + 1 ) *
sizeof ( char ) );
2979 strcpy( dest, src );
2986 #ifndef PL_HAVE_SNPRINTF
3008 va_start( args, format );
3009 ret = vsprintf( buffer, format, args );
3014 plabort(
"plsnprintf: buffer overrun" );
3040 va_start( args, format );
3041 ret = vsscanf( buffer, format, args );
3047 #endif // PL_HAVE_SNPRINTF
3093 char * setlocale_ptr;
3094 char * saved_lc_numeric_locale;
3096 if ( !( saved_lc_numeric_locale = (
char *) malloc( 100 *
sizeof (
char ) ) ) )
3098 plexit(
"plsave_set_locale: out of memory" );
3102 if ( !( setlocale_ptr = setlocale( LC_NUMERIC, NULL ) ) )
3104 plexit(
"plsave_set_locale: LC_NUMERIC locale could not be determined for NULL locale.\n" );
3106 strncpy( saved_lc_numeric_locale, setlocale_ptr, 100 );
3107 saved_lc_numeric_locale[99] =
'\0';
3117 if ( !( setlocale( LC_NUMERIC,
"C" ) ) )
3119 plexit(
"plsave_set_locale: LC_NUMERIC locale could not be set to \"C\"" );
3121 return saved_lc_numeric_locale;
3145 if ( !( setlocale( LC_NUMERIC, saved_lc_numeric_locale ) ) )
3148 snprintf( msgbuf, 1024,
"plrestore_locale: LC_NUMERIC could not be restored to the default \"%s\" locale.\n", saved_lc_numeric_locale );
3151 free( saved_lc_numeric_locale );
static void color_set(PLINT i, U_CHAR r, U_CHAR g, U_CHAR b, PLFLT a, PLCHAR_VECTOR name)
void c_plscolbga(PLINT r, PLINT g, PLINT b, PLFLT alpha)
PLINT plGetInt(PLCHAR_VECTOR s)
void plexit(PLCHAR_VECTOR errormsg)
void plGetName(PLCHAR_VECTOR dir, PLCHAR_VECTOR subdir, PLCHAR_VECTOR filename, char **filespec)
void plP_esc(PLINT op, void *ptr)
#define PL_DEFAULT_CMAP1_FILE
void init_genrand(unsigned long s)
PLINT plFindName(char *p)
void c_plscmap1_range(PLFLT min_color, PLFLT max_color)
void plOpenFile(PLStream *pls)
void plCloseFile(PLStream *pls)
void plGetFam(PLStream *pls)
void c_plscmap1l(PLINT itype, PLINT npts, PLFLT_VECTOR intensity, PLFLT_VECTOR coord1, PLFLT_VECTOR coord2, PLFLT_VECTOR coord3, PLINT_VECTOR alt_hue_path)
void plP_getmember(PLStream *pls)
void plGinInit(PLGraphicsIn *gin)
PDFstrm * pdf_fopen(PLCHAR_VECTOR filename, PLCHAR_VECTOR mode)
const char * PLCHAR_VECTOR
void c_plcol0(PLINT icol0)
void plcol_interp(PLStream *pls, PLColor *newcolor, int i, int ncol)
static char * read_line(char *buffer, int length, FILE *fp)
void c_plscmap1n(PLINT ncol1)
void c_plgcolbg(PLINT *r, PLINT *g, PLINT *b)
char * plsave_set_locale(void)
void plabort(PLCHAR_VECTOR errormsg)
void plP_gpixmm(PLFLT *p_x, PLFLT *p_y)
#define color_def(i, r, g, b, a, n)
void c_plscmap1a(PLINT_VECTOR r, PLINT_VECTOR g, PLINT_VECTOR b, PLFLT_VECTOR alpha, PLINT ncol1)
void c_plspal0(PLCHAR_VECTOR filename)
void plsabort(void(*handler)(PLCHAR_VECTOR))
void c_plxormod(PLINT mode, PLINT *status)
void c_plseed(unsigned int seed)
void c_plgcol0a(PLINT icol0, PLINT *r, PLINT *g, PLINT *b, PLFLT *alpha)
void plFamInit(PLStream *pls)
PLDev * plAllocDev(PLStream *pls)
void c_plscmap0n(PLINT ncol0)
void plrestore_locale(char *saved_lc_numeric_locale)
void c_plspal1(PLCHAR_VECTOR filename, PLBOOL interpolate)
#define PL_DEFAULT_CMAP0_FILE
void plP_sfnam(PLStream *pls, PLCHAR_VECTOR fnam)
void plio_fgets(char *buf, int size, FILE *stream)
void c_plhlsrgb(PLFLT h, PLFLT l, PLFLT s, PLFLT *p_r, PLFLT *p_g, PLFLT *p_b)
void c_plscmap1(PLINT_VECTOR r, PLINT_VECTOR g, PLINT_VECTOR b, PLINT ncol1)
static void cmap0_palette_read(PLCHAR_VECTOR filename, int *number_colors, unsigned int **r, unsigned int **g, unsigned int **b, double **a)
void c_plcol1(PLFLT col1)
static void strcat_delim(char *dirspec)
int plsnprintf(char *buffer, int n, PLCHAR_VECTOR format,...)
char * plFindCommand(PLCHAR_VECTOR fn)
#define PL_DRAWMODE_UNKNOWN
void c_plrgbhls(PLFLT r, PLFLT g, PLFLT b, PLFLT *p_h, PLFLT *p_l, PLFLT *p_s)
void c_plscolbg(PLINT r, PLINT g, PLINT b)
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
void pl_cmd(PLINT op, void *ptr)
const PLINT * PLINT_VECTOR
void plsexit(int(*handler)(PLCHAR_VECTOR))
void c_plscmap0a(PLINT_VECTOR r, PLINT_VECTOR g, PLINT_VECTOR b, PLFLT_VECTOR alpha, PLINT ncol0)
static PLStream * pls[PL_NSTREAMS]
void c_plscol0a(PLINT icol0, PLINT r, PLINT g, PLINT b, PLFLT alpha)
void c_plgcolbga(PLINT *r, PLINT *g, PLINT *b, PLFLT *alpha)
static void(* abort_handler)(PLCHAR_VECTOR errormsg)
int plsnscanf(PLCHAR_VECTOR buffer, int n, PLCHAR_VECTOR format,...)
void c_plscolor(PLINT color)
static PLFLT value(double n1, double n2, double hue)
char PLDLLIMPEXP * plstrdup(PLCHAR_VECTOR src)
PLINT c_plgdrawmode(void)
static int(* exit_handler)(PLCHAR_VECTOR errormsg)
#define fuzzy_range_check(value, min, max, fuzz, err_number)
int pdf_close(PDFstrm *pdfs)
void c_plgcmap1_range(PLFLT *min_color, PLFLT *max_color)
FILE * plLibOpen(PLCHAR_VECTOR fn)
void plRotPhy(PLINT orient, PLINT xmin, PLINT ymin, PLINT xmax, PLINT ymax, PLINT *px, PLINT *py)
void c_pltext(void)
Switches to text screen.
static void plcmap0_def(int imin, int imax)
void c_plscmap0(PLINT_VECTOR r, PLINT_VECTOR g, PLINT_VECTOR b, PLINT ncol0)
void plwarn(PLCHAR_VECTOR errormsg)
int access(char *filename, int flag)
PLFLT plGetFlt(PLCHAR_VECTOR s)
void c_plscol0(PLINT icol0, PLINT r, PLINT g, PLINT b)
void c_plsdrawmode(PLINT mode)
void c_plgcol0(PLINT icol0, PLINT *r, PLINT *g, PLINT *b)
const PLFLT * PLFLT_VECTOR
static void plcmap1_def(void)
char PLDLLIMPEXP * plplotLibDir
PDFstrm * plLibOpenPdfstrm(PLCHAR_VECTOR fn)
void c_plscmap1la(PLINT itype, PLINT npts, PLFLT_VECTOR intensity, PLFLT_VECTOR coord1, PLFLT_VECTOR coord2, PLFLT_VECTOR coord3, PLFLT_VECTOR alpha, PLINT_VECTOR alt_hue_path)
double genrand_real1(void)