46 #ifdef DJGPP // dos386/djgpp
53 #include <sys/types.h>
55 #ifdef PL_HAVE_UNISTD_H
64 #define BUFFER_SIZE 256
71 #define FUZZ_EPSILON 1.e-4
97 value(
double n1,
double n2,
double hue );
104 int *number_colors,
unsigned int **r,
unsigned int **g,
105 unsigned int **b,
double **a );
110 #if defined ( DJGPP )
112 #define PLLIBDEV "c:/plplot/lib"
115 #elif defined ( MSDOS )
117 #define PLLIBDEV "c:\\plplot\\lib"
125 #define PLLIBDEV "/usr/local/plplot/lib"
145 if ( plsc->level < 1 )
147 plabort(
"plcol0: Please call plinit first" );
150 if ( icol0 < 0 || icol0 >= plsc->ncol0 )
159 plsc->curcolor.r = plsc->cmap0[icol0].r;
160 plsc->curcolor.g = plsc->cmap0[icol0].g;
161 plsc->curcolor.b = plsc->cmap0[icol0].b;
162 plsc->curcolor.a = plsc->cmap0[icol0].a;
181 if ( plsc->level < 1 )
183 plabort(
"plcol1: Please call plinit first" );
186 if ( col1 < 0 || col1 > 1 ||
isnan( col1 ) )
194 icol1 = (
PLINT) ( col1 * plsc->ncol1 );
195 icol1 =
MIN( icol1, plsc->ncol1 - 1 );
198 plsc->curcolor.r = plsc->cmap1[plsc->icol1].r;
199 plsc->curcolor.g = plsc->cmap1[plsc->icol1].g;
200 plsc->curcolor.b = plsc->cmap1[plsc->icol1].b;
201 plsc->curcolor.a = plsc->cmap1[plsc->icol1].a;
286 if ( plsc->cmap0 == NULL )
288 if ( icol0 < 0 || icol0 >= plsc->ncol0 )
295 if ( ( r < 0 || r > 255 ) || ( g < 0 || g > 255 ) || ( b < 0 || b > 255 ) )
299 (
int) r, (
int) g, (
int) b );
322 if ( plsc->cmap0 == NULL )
324 if ( icol0 < 0 || icol0 >= plsc->ncol0 )
331 if ( ( r < 0 || r > 255 ) || ( g < 0 || g > 255 ) || ( b < 0 || b > 255 ) || ( alpha < 0. || alpha > 1.0 ) )
335 (
int) r, (
int) g, (
int) b, (
double) alpha );
340 plsc->cmap0[icol0].r = (
unsigned char) r;
341 plsc->cmap0[icol0].g = (
unsigned char) g;
342 plsc->cmap0[icol0].b = (
unsigned char) b;
343 plsc->cmap0[icol0].a = alpha;
345 if ( plsc->level > 0 )
363 if ( plsc->cmap0 == NULL )
370 if ( icol0 < 0 || icol0 > plsc->ncol0 )
378 *r = plsc->cmap0[icol0].r;
379 *g = plsc->cmap0[icol0].g;
380 *b = plsc->cmap0[icol0].b;
400 if ( plsc->cmap0 == NULL )
408 if ( icol0 < 0 || icol0 > plsc->ncol0 )
416 *r = plsc->cmap0[icol0].r;
417 *g = plsc->cmap0[icol0].g;
418 *b = plsc->cmap0[icol0].b;
419 *alpha = plsc->cmap0[icol0].a;
442 for ( i = 0; i < plsc->ncol0; i++ )
444 if ( ( r[i] < 0 || r[i] > 255 ) ||
445 ( g[i] < 0 || g[i] > 255 ) ||
446 ( b[i] < 0 || b[i] > 255 ) )
450 (
int) r[i], (
int) g[i], (
int) b[i] );
455 plsc->cmap0[i].r = (
unsigned char) r[i];
456 plsc->cmap0[i].g = (
unsigned char) g[i];
457 plsc->cmap0[i].b = (
unsigned char) b[i];
458 plsc->cmap0[i].a = 1.0;
461 if ( plsc->level > 0 )
484 for ( i = 0; i < plsc->ncol0; i++ )
486 if ( ( r[i] < 0 || r[i] > 255 ) ||
487 ( g[i] < 0 || g[i] > 255 ) ||
488 ( b[i] < 0 || b[i] > 255 ) ||
489 ( alpha[i] < 0.0 || alpha[i] > 1.0 ) )
493 (
int) r[i], (
int) g[i], (
int) b[i], (
double) alpha[i] );
498 plsc->cmap0[i].r = (
unsigned char) r[i];
499 plsc->cmap0[i].g = (
unsigned char) g[i];
500 plsc->cmap0[i].b = (
unsigned char) b[i];
501 plsc->cmap0[i].a = alpha[i];
504 if ( plsc->level > 0 )
526 for ( i = 0; i < plsc->ncol1; i++ )
528 if ( ( r[i] < 0 || r[i] > 255 ) ||
529 ( g[i] < 0 || g[i] > 255 ) ||
530 ( b[i] < 0 || b[i] > 255 ) )
534 (
int) r[i], (
int) g[i], (
int) b[i] );
538 plsc->cmap1[i].r = (
unsigned char) r[i];
539 plsc->cmap1[i].g = (
unsigned char) g[i];
540 plsc->cmap1[i].b = (
unsigned char) b[i];
541 plsc->cmap1[i].a = 1.0;
544 if ( plsc->level > 0 )
567 for ( i = 0; i < plsc->ncol1; i++ )
569 if ( ( r[i] < 0 || r[i] > 255 ) ||
570 ( g[i] < 0 || g[i] > 255 ) ||
571 ( b[i] < 0 || b[i] > 255 ) ||
572 ( alpha[i] < 0.0 || alpha[i] > 1.0 ) )
576 (
int) r[i], (
int) g[i], (
int) b[i], (
double) alpha[i] );
580 plsc->cmap1[i].r = (
unsigned char) r[i];
581 plsc->cmap1[i].g = (
unsigned char) g[i];
582 plsc->cmap1[i].b = (
unsigned char) b[i];
583 plsc->cmap1[i].a = alpha[i];
586 if ( plsc->level > 0 )
647 PLFLT h, l, s, r, g, b;
651 plabort(
"plscmap1l: Must specify at least two control points" );
655 if ( ( intensity[0] != 0 ) || ( intensity[npts - 1] != 1 ) )
657 plabort(
"plscmap1l: First, last control points must lie on boundary" );
663 plabort(
"plscmap1l: exceeded maximum number of control points" );
669 if ( plsc->cmap1 == NULL )
676 for ( n = 0; n < npts; n++ )
692 plsc->cmap1cp[n].h = h;
693 plsc->cmap1cp[n].l = l;
694 plsc->cmap1cp[n].s = s;
695 plsc->cmap1cp[n].p = intensity[n];
696 plsc->cmap1cp[n].a = 1.0;
698 if ( alt_hue_path == NULL )
699 plsc->cmap1cp[n].alt_hue_path = 0;
702 plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
705 plsc->cmap1cp[n].alt_hue_path = 0;
733 PLFLT h, l, s, r, g, b;
737 plabort(
"plscmap1la: Must specify at least two control points" );
741 if ( ( intensity[0] != 0 ) || ( intensity[npts - 1] != 1 ) )
743 plabort(
"plscmap1la: First, last control points must lie on boundary" );
749 plabort(
"plscmap1la: exceeded maximum number of control points" );
755 if ( plsc->cmap1 == NULL )
762 for ( n = 0; n < npts; n++ )
778 plsc->cmap1cp[n].h = h;
779 plsc->cmap1cp[n].l = l;
780 plsc->cmap1cp[n].s = s;
781 plsc->cmap1cp[n].p = intensity[n];
782 plsc->cmap1cp[n].a = alpha[n];
784 if ( alt_hue_path == NULL )
785 plsc->cmap1cp[n].alt_hue_path = 0;
788 plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
791 plsc->cmap1cp[n].alt_hue_path = 0;
809 PLFLT delta, dp, dh, dl, ds, da;
810 PLFLT h, l, s, p, r, g, b, a;
814 for ( n = 0; n < plsc->ncp1 - 1; n++ )
816 if ( plsc->cmap1cp[n].p == plsc->cmap1cp[n + 1].p )
821 dp = plsc->cmap1cp[n + 1].p - plsc->cmap1cp[n].p;
822 dh = plsc->cmap1cp[n + 1].h - plsc->cmap1cp[n].h;
823 dl = plsc->cmap1cp[n + 1].l - plsc->cmap1cp[n].l;
824 ds = plsc->cmap1cp[n + 1].s - plsc->cmap1cp[n].s;
825 da = plsc->cmap1cp[n + 1].a - plsc->cmap1cp[n].a;
829 if ( plsc->cmap1cp[n].alt_hue_path )
830 dh = ( dh > 0 ) ? dh - 360 : dh + 360;
835 for ( i = 0; i < plsc->ncol1; i++ )
837 p = (double) i / ( plsc->ncol1 - 1.0 );
838 if ( ( p < plsc->cmap1cp[n].p ) ||
839 ( p > plsc->cmap1cp[n + 1].p ) )
844 delta = ( p - plsc->cmap1cp[n].p ) / dp;
848 h = plsc->cmap1cp[n].h + dh * delta;
849 l = plsc->cmap1cp[n].l + dl * delta;
850 s = plsc->cmap1cp[n].s + ds * delta;
851 a = plsc->cmap1cp[n].a + da * delta;
861 plsc->cmap1[i].r = (
unsigned char)
MAX( 0,
MIN( 255, (
int) ( 256. * r ) ) );
862 plsc->cmap1[i].g = (
unsigned char)
MAX( 0,
MIN( 255, (
int) ( 256. * g ) ) );
863 plsc->cmap1[i].b = (
unsigned char)
MAX( 0,
MIN( 255, (
int) ( 256. * b ) ) );
864 plsc->cmap1[i].a = a;
868 if ( plsc->level > 0 )
889 if ( min_color > max_color || max_color < 0.0 || min_color > 1.0 )
891 plwarn(
"plscmap1_range called with invalid color range" );
894 if ( min_color < 0.0 )
896 plwarn(
"plscmap1_range called with a negative minimum color value" );
899 if ( max_color > 1.0 )
901 plwarn(
"plscmap1_range called with an out of range maximum color value" );
904 plsc->cmap1_min = min_color;
905 plsc->cmap1_max = max_color;
918 *min_color = plsc->cmap1_min;
919 *max_color = plsc->cmap1_max;
936 int ncol, size, imin, imax;
940 if ( ncol0 > 0 && plsc->ncol0 == ncol0 )
945 if ( plsc->ncol0 <= 0 && ncol0 <= 0 )
947 else if ( ncol0 <= 0 )
953 size = ncol * (int)
sizeof (
PLColor );
957 if ( plsc->cmap0 == NULL )
959 if ( ( plsc->cmap0 = (
PLColor *) calloc( 1, (
size_t) size ) ) == NULL )
961 plexit(
"c_plscmap0n: Insufficient memory" );
967 if ( ( plsc->cmap0 = (
PLColor *) realloc( plsc->cmap0, (
size_t) size ) ) == NULL )
969 plexit(
"c_plscmap0n: Insufficient memory" );
979 if ( plsc->level > 0 )
998 plsc->cmap0[i].r = r;
999 plsc->cmap0[i].g = g;
1000 plsc->cmap0[i].b = b;
1001 plsc->cmap0[i].a = a;
1002 plsc->cmap0[i].name =
name;
1005 #define color_def( i, r, g, b, a, n ) \
1006 if ( i >= imin && i <= imax ) color_set( i, r, g, b, a, n );
1021 unsigned int *r, *g, *b;
1027 for ( i = imin; i <=
MIN( ( number_colors - 1 ), imax ); i++ )
1029 "colors defined by default cmap0 palette file" );
1042 for ( i =
MAX( number_colors, imin ); i <= imax; i++ )
1044 "opaque red colour to mark not defined by palette file" );
1066 if ( ncol1 > 0 && plsc->ncol1 == ncol1 )
1071 if ( plsc->ncol1 <= 0 && ncol1 <= 0 )
1073 else if ( ncol1 <= 0 )
1078 size = (size_t) ncol *
sizeof (
PLColor );
1082 if ( plsc->ncol1 > 0 )
1084 if ( ( plsc->cmap1 = (
PLColor *) realloc( plsc->cmap1, size ) ) == NULL )
1086 plexit(
"c_plscmap1n: Insufficient memory" );
1091 if ( ( plsc->cmap1 = (
PLColor *) calloc( (
size_t) ncol,
sizeof (
PLColor ) ) ) == NULL )
1093 plexit(
"c_plscmap1n: Insufficient memory" );
1100 if ( plsc->ncp1 == 0 )
1122 PLFLT i[6], h[6], l[6], s[6], midpt = 0., vertex = 0.;
1136 if ( plsc->cmap0 != NULL )
1137 vertex = ( (
PLFLT) plsc->cmap0[0].r +
1138 (
PLFLT) plsc->cmap0[0].g +
1139 (
PLFLT) plsc->cmap0[0].b ) / 3. / 255.;
1181 if ( plsc->level > 0 )
1197 plsc->color = color;
1211 value(
double n1,
double n2,
double hue )
1215 while ( hue >= 360. )
1221 val = n1 + ( n2 - n1 ) * hue / 60.;
1222 else if ( hue < 180. )
1224 else if ( hue < 240. )
1225 val = n1 + ( n2 - n1 ) * ( 240. - hue ) / 60.;
1258 m2 = l * ( s + 1. );
1264 *p_r =
value( m1, m2, h + 120. );
1265 *p_g =
value( m1, m2, h );
1266 *p_b =
value( m1, m2, h - 120. );
1288 PLFLT h, l, s, d, rc, gc, bc, rgb_min, rgb_max;
1290 rgb_min =
MIN( r,
MIN( g, b ) );
1291 rgb_max =
MAX( r,
MAX( g, b ) );
1293 l = ( rgb_min + rgb_max ) / 2.0;
1295 if ( rgb_min == rgb_max )
1302 d = rgb_max - rgb_min;
1306 s = 0.5 * d / ( 1. - l );
1308 rc = ( rgb_max - r ) / d;
1309 gc = ( rgb_max - g ) / d;
1310 bc = ( rgb_max - b ) / d;
1314 else if ( g == rgb_max )
1322 else if ( h >= 360 )
1349 if ( fgets( buffer, length, fp ) == NULL )
1356 pchr = strchr( buffer,
'\n' );
1363 if ( fscanf( fp,
"%*[^\n]\n" ) == EOF && ferror( fp ) )
1370 pchr = strchr( buffer,
'\r' );
1377 pchr = buffer + strlen( buffer ) - 1;
1378 while ( pchr != buffer && *pchr ==
' ' )
1402 int *number_colors,
unsigned int **r,
unsigned int **g,
unsigned int **b,
double **a )
1410 if ( strlen( filename ) == 0 )
1425 snprintf( msgbuf,
MSGLEN,
"Unable to open cmap0 file %s\n", filename );
1430 if ( !err && ( fscanf( fp,
"%d\n", number_colors ) != 1 || *number_colors < 1 ) )
1442 if ( ( ( *r = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1443 ( ( *g = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1444 ( ( *b = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1445 ( ( *a = (
double *) malloc( (
size_t) ( *number_colors ) *
sizeof (
double ) ) ) == NULL ) )
1448 plexit(
"cmap0_palette_read: insufficient memory" );
1451 for ( i = 0; i < *number_colors; i++ )
1460 if ( strlen( color_info ) == 7 )
1462 if ( sscanf( color_info,
"#%2x%2x%2x",
1463 (
unsigned int *) ( *r + i ), (
unsigned int *) ( *g + i ),
1464 (
unsigned int *) ( *b + i ) ) != 3 )
1471 else if ( strlen( color_info ) > 9 )
1473 if ( sscanf( color_info,
"#%2x%2x%2x %lf",
1474 (
unsigned int *) ( *r + i ), (
unsigned int *) ( *g + i ),
1475 (
unsigned int *) ( *b + i ), (
double *) ( *a + i ) ) != 4 )
1486 else if ( *( *a + i ) < 0. )
1490 else if ( *( *a + i ) > 1. )
1504 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap0 format data line. Line is %s\n",
1517 *number_colors = 16;
1518 if ( ( ( *r = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
int ) ) ) == NULL ) ||
1519 ( ( *g = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1520 ( ( *b = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1521 ( ( *a = (
double *) malloc( (
size_t) ( *number_colors ) *
sizeof (
double ) ) ) == NULL ) )
1523 plexit(
"cmap0_palette_read: insufficient memory" );
1529 for ( i = 1; i < *number_colors; i++ )
1553 unsigned int *r, *g, *b;
1561 if ( number_colors > plsc->ncol0 )
1565 for ( i = 0; i < number_colors; i++ )
1584 #define fuzzy_range_check( value, min, max, fuzz, err_number ) \
1585 if ( value < ( min - fuzz ) || value > ( max + fuzz ) ) { \
1586 snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format data line. Error number is %d. Line is %s\n", err_number, color_info ); \
1590 } else if ( value < min ) { \
1592 } else if ( value > max ) { \
1610 int format_version, err;
1613 unsigned int r_i, g_i, b_i;
1614 int pos_i, alt_hue_path_i;
1615 double r_d, g_d, b_d, a_d, pos_d;
1616 PLFLT *r, *g, *b, *a, *pos;
1617 PLINT *ri, *gi, *bi;
1626 if ( strlen( filename ) == 0 )
1641 snprintf( msgbuf,
MSGLEN,
"Unable to open cmap1 .pal file %s\n", filename );
1649 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1654 if ( strncmp( color_info,
"v2 ", 2 ) == 0 )
1657 if ( strncmp( &color_info[3],
"hls", 3 ) == 0 )
1659 else if ( strncmp( &color_info[3],
"rgb", 3 ) == 0 )
1663 snprintf( msgbuf,
MSGLEN,
"Invalid color space %s - assuming RGB\n", &color_info[3] );
1669 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1676 if ( sscanf( color_info,
"%d\n", &number_colors ) != 1 || number_colors < 2 )
1678 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of colors) %s\n", color_info );
1684 r = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1685 g = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1686 b = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1687 ri = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1688 gi = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1689 bi = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1690 a = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1691 pos = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1692 alt_hue_path = (
PLBOOL *) malloc( (
size_t) ( number_colors - 1 ) *
sizeof (
PLBOOL ) );
1694 if ( format_version == 0 )
1696 int return_sscanf = -1, return_sscanf_old = 0;
1698 for ( i = 0; i < number_colors; i++ )
1702 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1708 color_info[
PALLEN - 1] =
'\0';
1709 return_sscanf = sscanf( color_info,
"#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &alt_hue_path_i );
1710 if ( return_sscanf < 4 || ( return_sscanf_old != 0 && return_sscanf != return_sscanf_old ) )
1712 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of items for version 1 of format) %s\n", color_info );
1717 return_sscanf_old = return_sscanf;
1720 r[i] = (
PLFLT) r_i / 255.;
1721 g[i] = (
PLFLT) g_i / 255.;
1722 b[i] = (
PLFLT) b_i / 255.;
1724 pos[i] = 0.01 * (
PLFLT) pos_i;
1729 if ( ( return_sscanf == 5 ) && ( i != number_colors - 1 ) )
1732 alt_hue_path[i] = (
PLBOOL) alt_hue_path_i;
1735 if ( return_sscanf == 4 )
1738 free( alt_hue_path );
1739 alt_hue_path = NULL;
1745 for ( i = 0; i < number_colors; i++ )
1749 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1754 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 )
1756 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of items for version 2 of format) %s\n", color_info );
1766 pos[i] = (
PLFLT) pos_d;
1783 if ( i != number_colors - 1 )
1784 alt_hue_path[i] = (
PLBOOL) alt_hue_path_i;
1793 c_plscmap1la( rgb, number_colors, pos, r, g, b, a, alt_hue_path );
1797 for ( i = 0; i < number_colors; i++ )
1799 ri[i] = (
PLINT) ( r[i] * 255.0 );
1800 gi[i] = (
PLINT) ( g[i] * 255.0 );
1801 bi[i] = (
PLINT) ( b[i] * 255.0 );
1815 r = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1816 g = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1817 b = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1818 pos = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1838 free( alt_hue_path );
1859 if ( plsc->graphx == 1 )
1865 fprintf( stderr,
"\n*** PLPLOT WARNING ***\n" );
1866 if ( *errormsg !=
'\0' )
1867 fprintf( stderr,
"%s\n", errormsg );
1889 ( *abort_handler )( errormsg );
1891 if ( plsc->errcode != NULL )
1892 *( plsc->errcode ) = 1;
1894 if ( plsc->errmsg != NULL )
1896 sprintf( plsc->errmsg,
"\n*** PLPLOT ERROR, ABORTING OPERATION ***\n" );
1897 if ( *errormsg !=
'\0' )
1898 sprintf( plsc->errmsg,
"%s, aborting operation\n", errormsg );
1904 if ( plsc->graphx == 1 )
1910 fprintf( stderr,
"\n*** PLPLOT ERROR, ABORTING OPERATION ***\n" );
1911 if ( *errormsg !=
'\0' )
1912 fprintf( stderr,
"%s, aborting operation\n", errormsg );
1955 status = ( *exit_handler )( errormsg );
1958 if ( *errormsg !=
'\0' )
1960 fprintf( stderr,
"\n*** PLPLOT ERROR, IMMEDIATE EXIT ***\n" );
1961 fprintf( stderr,
"%s\n", errormsg );
1965 fprintf( stderr,
"Program aborted\n" );
1997 if ( plsc->level > 0 )
2012 static int ostate = 0;
2014 if ( !plsc->dev_xor )
2020 if ( plsc->level > 0 )
2025 ostate = plsc->plbuf_write;
2026 plsc->plbuf_write = 0;
2029 plsc->plbuf_write = ostate;
2042 if ( !plsc->dev_modeset )
2044 plwarn(
"plsdrawmode: Mode setting is not supported by this device" );
2046 else if ( plsc->level > 0 )
2052 plwarn(
"plsdrawmode: Initialize PLplot first" );
2067 if ( !plsc->dev_modeset )
2069 plwarn(
"plgdrawmode: Mode getting is not supported by this device" );
2072 else if ( plsc->level > 0 )
2078 plwarn(
"plsdrawmode: Initialize PLplot first" );
2094 if ( plsc->level > 0 )
2139 char *fs = NULL, *dn;
2157 #if defined ( PLPLOT_BIN_ENV )
2165 #endif // PLPLOT_BIN_ENV
2175 #if defined ( PLPLOT_HOME_ENV )
2183 #endif // PLPLOT_HOME_ENV
2187 #if defined ( BIN_DIR )
2196 fprintf( stderr,
"plFindCommand: cannot locate command: %s\n", fn );
2197 #if defined ( BIN_DIR )
2198 fprintf( stderr,
"bin dir=\"" BIN_DIR "\"\n" );
2229 if ( pdfs->
file != NULL )
2257 char *fs = NULL, *dn = NULL;
2265 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2271 #if defined ( PLPLOT_LIB_ENV )
2276 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2280 #endif // PLPLOT_LIB_ENV
2284 if ( ( file =
pdf_fopen( fn,
"rb" ) ) != NULL )
2286 pldebug(
"plLibOpenPdfstr",
"Found file %s in current directory.\n", fn );
2293 #if defined ( PLPLOT_HOME_ENV )
2298 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2302 #endif // PLPLOT_HOME_ENV/lib
2306 #if defined ( DATA_DIR )
2309 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2318 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2323 file = plMacLibOpen( fn );
2331 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2336 pldebug(
"plLibOpenPdfstr",
"File %s not found.\n", fn );
2341 pldebug(
"plLibOpenPdfstr",
"Found file %s\n", fs );
2376 pldebug(
"plFindName",
"Trying to find %s\n", p );
2379 pldebug(
"plFindName",
"Readlink read %d chars at: %s\n", n, p );
2380 if ( buf[0] ==
'/' )
2384 strncpy( p, buf, (
size_t) n );
2386 pldebug(
"plFindName",
"Link is absolute: %s\n", p );
2392 cp = 1 + strrchr( p,
'/' );
2393 strncpy( cp, buf, (
size_t) n );
2395 pldebug(
"plFindName",
2396 "Link is relative: %s\n\tTotal path:%s\n", cp, p );
2403 #define S_ISREG( mode ) ( mode & S_IFREG )
2408 if ( errno == EINVAL || errno == ENXIO )
2410 pldebug(
"plFindName",
"%s may be the one...\n", p );
2411 if ( ( stat( p, &sbuf ) == 0 ) && S_ISREG( sbuf.st_mode ) )
2413 pldebug(
"plFindName",
"%s is a regular file\n", p );
2414 return ( access( p, X_OK ) );
2417 pldebug(
"plFindName",
"%s found but is not executable\n", p );
2418 return ( errno ? errno : -1 );
2444 plGetName(
const char *dir,
const char *subdir,
const char *filename,
char **filespec )
2453 lfilespec = strlen( dir ) + strlen( subdir ) + strlen( filename ) + 10;
2454 if ( ( *filespec = (
char *) malloc( lfilespec ) ) == NULL )
2456 plexit(
"plGetName: Insufficient memory" );
2459 strcpy( *filespec, dir );
2461 if ( *subdir !=
'\0' )
2464 strcat( *filespec, subdir );
2466 if ( *filename !=
'\0' )
2469 strcat( *filespec, filename );
2471 pldebug(
"plGetName",
"Maximum length of full pathname of file to be found is %zu\n", lfilespec - 1 );
2472 pldebug(
"plGetName",
"Full pathname of file to be found is %s\n", *filespec );
2487 size_t ldirspec = strlen( dirspec );
2488 #if defined ( MSDOS ) || defined ( WIN32 )
2489 if ( dirspec[ldirspec - 1] !=
'\\' )
2490 strcat( dirspec,
"\\" );
2491 #elif defined ( macintosh )
2492 if ( dirspec[ldirspec - 1] !=
':' )
2493 strcat( dirspec,
":" );
2494 #else // unix is the default
2495 if ( dirspec[ldirspec - 1] !=
'/' )
2496 strcat( dirspec,
"/" );
2519 x = (double) ( i * ( pls->
ncol1 - 1 ) ) / (
double) ( ncol - 1 );
2524 if ( ir > pls->
ncol1 || il < 0 )
2525 fprintf( stderr,
"Invalid color\n" );
2527 else if ( ir == pls->
ncol1 || ( delta == 0. ) )
2529 newcolor->
r = pls->
cmap1[il].
r;
2530 newcolor->
g = pls->
cmap1[il].
g;
2531 newcolor->
b = pls->
cmap1[il].
b;
2532 newcolor->
a = pls->
cmap1[il].
a;
2536 newcolor->
r = (
unsigned char) ( ( 1. - delta ) * pls->
cmap1[il].
r + delta * pls->
cmap1[ir].
r );
2537 newcolor->
g = (
unsigned char) ( ( 1. - delta ) * pls->
cmap1[il].
g + delta * pls->
cmap1[ir].
g );
2538 newcolor->
b = (
unsigned char) ( ( 1. - delta ) * pls->
cmap1[il].
b + delta * pls->
cmap1[ir].
b );
2539 newcolor->
a = ( 1. - delta ) * pls->
cmap1[il].
a + delta * pls->
cmap1[ir].
a;
2553 #define MAX_NUM_TRIES 10
2557 int i = 0,
count = 0;
2561 while ( pls->
OutFile == NULL )
2575 fprintf( stdout,
"Enter graphics output file name: " );
2577 len = strlen( line );
2588 if ( !strcmp( pls->
FileName,
"-" ) )
2601 plexit(
"Too many tries." );
2604 fprintf( stderr,
"Can't open %s.\n", pls->
FileName );
2606 pldebug(
"plOpenFile",
"Opened %s\n", pls->
FileName );
2649 maxlen = strlen( pls->
BaseName ) + 10;
2652 if ( ( pls->
FileName = (
char *) malloc( maxlen ) ) == NULL )
2654 plexit(
"plP_getmember: Insufficient memory" );
2658 suffix = strstr( pls->
BaseName,
"%n" );
2663 if ( suffix == NULL )
2694 maxlen = 10 + strlen( fnam );
2695 if ( ( pls->
FileName = (
char *) malloc( maxlen ) ) == NULL )
2697 plexit(
"plP_sfnam: Insufficient memory" );
2700 suffix = strstr( fnam,
"%n" );
2702 if ( suffix == NULL )
2704 strncpy( pls->
FileName, fnam, maxlen - 1 );
2717 if ( ( pls->
BaseName = (
char *) malloc( maxlen ) ) == NULL )
2719 plexit(
"plP_sfnam: Insufficient memory" );
2722 strncpy( pls->
BaseName, fnam, maxlen - 1 );
2766 PLFLT xpmm_loc, ypmm_loc;
2784 plP_setpxl( xpmm_loc * plsc->caspfactor, ypmm_loc / plsc->caspfactor );
2816 switch ( orient % 4 )
2819 *px = xmin + ( y -
ymin );
2820 *py = ymin + ( xmax -
x );
2824 *px = xmin + ( xmax -
x );
2825 *py = ymin + ( ymax -
y );
2829 *px = xmin + ( ymax -
y );
2830 *py = ymin + ( x -
xmin );
2852 if ( pls->
dev != NULL )
2853 free( (
void *) pls->
dev );
2855 pls->
dev = calloc( 1, (
size_t)
sizeof (
PLDev ) );
2856 if ( pls->
dev == NULL )
2857 plexit(
"plAllocDev: cannot allocate memory\n" );
2878 gin->
pX = gin->
pY = -1;
2879 gin->
dX = gin->
dY = 0.;
2880 gin->
wX = gin->
wY = 0.;
2909 if ( sscanf( line,
"%d", &m ) == 1 )
2911 fprintf( stdout,
"No value or value out of range; please try again\n" );
2914 plexit(
"Too many tries." );
2945 if ( sscanf( line,
"%lf", &m1 ) == 1 )
2950 fprintf( stdout,
"No value or value out of range; please try again\n" );
2953 plexit(
"Too many tries." );
2971 char *dest = (
char *) malloc( ( strlen( src ) + 1 ) *
sizeof ( char ) );
2973 strcpy( dest, src );
2980 #ifndef PL_HAVE_SNPRINTF
3002 va_start( args, format );
3003 ret = vsprintf( buffer, format, args );
3008 plabort(
"plsnprintf: buffer overrun" );
3034 va_start( args, format );
3035 ret = vsscanf( buffer, format, args );
3041 #endif // PL_HAVE_SNPRINTF
3087 char * setlocale_ptr;
3088 char * saved_lc_numeric_locale;
3090 if ( !( saved_lc_numeric_locale = (
char *) malloc( 100 *
sizeof (
char ) ) ) )
3092 plexit(
"plsave_set_locale: out of memory" );
3096 if ( !( setlocale_ptr = setlocale( LC_NUMERIC, NULL ) ) )
3098 plexit(
"plsave_set_locale: LC_NUMERIC locale could not be determined for NULL locale.\n" );
3100 strncpy( saved_lc_numeric_locale, setlocale_ptr, 100 );
3101 saved_lc_numeric_locale[99] =
'\0';
3111 if ( !( setlocale( LC_NUMERIC,
"C" ) ) )
3113 plexit(
"plsave_set_locale: LC_NUMERIC locale could not be set to \"C\"" );
3115 return saved_lc_numeric_locale;
3139 if ( !( setlocale( LC_NUMERIC, saved_lc_numeric_locale ) ) )
3142 snprintf( msgbuf, 1024,
"plrestore_locale: LC_NUMERIC could not be restored to the default \"%s\" locale.\n", saved_lc_numeric_locale );
3145 free( saved_lc_numeric_locale );