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 ) || ( a < 0 || a > 1.0 ) )
335 (
int) r, (
int) g, (
int) b, (
double) a );
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 =
a;
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 *a = 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 ( a[i] < 0.0 || a[i] > 1.0 ) )
493 (
int) r[i], (
int) g[i], (
int) b[i], (
double) a[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 = a[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 ( a[i] < 0.0 || a[i] > 1.0 ) )
576 (
int) r[i], (
int) g[i], (
int) b[i], (
double) a[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 = a[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 ( ( pos[0] != 0 ) || ( pos[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 = pos[n];
696 plsc->cmap1cp[n].a = 1.0;
698 if ( alt_hue_path == NULL )
699 plsc->cmap1cp[n].alt_hue_path = 0;
701 plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
729 PLFLT h, l, s, r, g, b;
733 plabort(
"plscmap1la: Must specify at least two control points" );
737 if ( ( pos[0] != 0 ) || ( pos[npts - 1] != 1 ) )
739 plabort(
"plscmap1la: First, last control points must lie on boundary" );
745 plabort(
"plscmap1la: exceeded maximum number of control points" );
751 if ( plsc->cmap1 == NULL )
758 for ( n = 0; n < npts; n++ )
774 plsc->cmap1cp[n].h = h;
775 plsc->cmap1cp[n].l = l;
776 plsc->cmap1cp[n].s = s;
777 plsc->cmap1cp[n].p = pos[n];
778 plsc->cmap1cp[n].a = a[n];
780 if ( alt_hue_path == NULL )
781 plsc->cmap1cp[n].alt_hue_path = 0;
783 plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
801 PLFLT delta, dp, dh, dl, ds, da;
802 PLFLT h, l, s, p, r, g, b,
a;
806 for ( n = 0; n < plsc->ncp1 - 1; n++ )
808 if ( plsc->cmap1cp[n].p == plsc->cmap1cp[n + 1].p )
813 dp = plsc->cmap1cp[n + 1].p - plsc->cmap1cp[n].p;
814 dh = plsc->cmap1cp[n + 1].h - plsc->cmap1cp[n].h;
815 dl = plsc->cmap1cp[n + 1].l - plsc->cmap1cp[n].l;
816 ds = plsc->cmap1cp[n + 1].s - plsc->cmap1cp[n].s;
817 da = plsc->cmap1cp[n + 1].a - plsc->cmap1cp[n].a;
821 if ( plsc->cmap1cp[n].alt_hue_path )
822 dh = ( dh > 0 ) ? dh - 360 : dh + 360;
827 for ( i = 0; i < plsc->ncol1; i++ )
829 p = (double) i / ( plsc->ncol1 - 1.0 );
830 if ( ( p < plsc->cmap1cp[n].p ) ||
831 ( p > plsc->cmap1cp[n + 1].p ) )
836 delta = ( p - plsc->cmap1cp[n].p ) / dp;
840 h = plsc->cmap1cp[n].h + dh * delta;
841 l = plsc->cmap1cp[n].l + dl * delta;
842 s = plsc->cmap1cp[n].s + ds * delta;
843 a = plsc->cmap1cp[n].a + da * delta;
853 plsc->cmap1[i].r = (
unsigned char)
MAX( 0,
MIN( 255, (
int) ( 256. * r ) ) );
854 plsc->cmap1[i].g = (
unsigned char)
MAX( 0,
MIN( 255, (
int) ( 256. * g ) ) );
855 plsc->cmap1[i].b = (
unsigned char)
MAX( 0,
MIN( 255, (
int) ( 256. * b ) ) );
856 plsc->cmap1[i].a =
a;
860 if ( plsc->level > 0 )
881 if ( min_color > max_color || max_color < 0.0 || min_color > 1.0 )
883 plwarn(
"plscmap1_range called with invalid color range" );
886 if ( min_color < 0.0 )
888 plwarn(
"plscmap1_range called with a negative minimum color value" );
891 if ( max_color > 1.0 )
893 plwarn(
"plscmap1_range called with an out of range maximum color value" );
896 plsc->cmap1_min = min_color;
897 plsc->cmap1_max = max_color;
910 *min_color = plsc->cmap1_min;
911 *max_color = plsc->cmap1_max;
928 int ncol, size, imin, imax;
932 if ( ncol0 > 0 && plsc->ncol0 == ncol0 )
937 if ( plsc->ncol0 <= 0 && ncol0 <= 0 )
939 else if ( ncol0 <= 0 )
945 size = ncol * (int)
sizeof (
PLColor );
949 if ( plsc->cmap0 == NULL )
951 if ( ( plsc->cmap0 = (
PLColor *) calloc( 1, (
size_t) size ) ) == NULL )
953 plexit(
"c_plscmap0n: Insufficient memory" );
959 if ( ( plsc->cmap0 = (
PLColor *) realloc( plsc->cmap0, (
size_t) size ) ) == NULL )
961 plexit(
"c_plscmap0n: Insufficient memory" );
971 if ( plsc->level > 0 )
990 plsc->cmap0[i].r = r;
991 plsc->cmap0[i].g = g;
992 plsc->cmap0[i].b = b;
993 plsc->cmap0[i].a =
a;
994 plsc->cmap0[i].name =
name;
997 #define color_def( i, r, g, b, a, n ) \
998 if ( i >= imin && i <= imax ) color_set( i, r, g, b, a, n );
1013 unsigned int *r, *g, *b;
1019 for ( i = imin; i <=
MIN( ( number_colors - 1 ), imax ); i++ )
1021 "colors defined by default cmap0 palette file" );
1034 for ( i =
MAX( number_colors, imin ); i <= imax; i++ )
1036 "opaque red colour to mark not defined by palette file" );
1058 if ( ncol1 > 0 && plsc->ncol1 == ncol1 )
1063 if ( plsc->ncol1 <= 0 && ncol1 <= 0 )
1065 else if ( ncol1 <= 0 )
1070 size = (size_t) ncol *
sizeof (
PLColor );
1074 if ( plsc->ncol1 > 0 )
1076 if ( ( plsc->cmap1 = (
PLColor *) realloc( plsc->cmap1, size ) ) == NULL )
1078 plexit(
"c_plscmap1n: Insufficient memory" );
1083 if ( ( plsc->cmap1 = (
PLColor *) calloc( (
size_t) ncol,
sizeof (
PLColor ) ) ) == NULL )
1085 plexit(
"c_plscmap1n: Insufficient memory" );
1092 if ( plsc->ncp1 == 0 )
1114 PLFLT i[6], h[6], l[6], s[6], midpt = 0., vertex = 0.;
1128 if ( plsc->cmap0 != NULL )
1129 vertex = ( (
PLFLT) plsc->cmap0[0].r +
1130 (
PLFLT) plsc->cmap0[0].g +
1131 (
PLFLT) plsc->cmap0[0].b ) / 3. / 255.;
1173 if ( plsc->level > 0 )
1189 plsc->color = color;
1203 value(
double n1,
double n2,
double hue )
1207 while ( hue >= 360. )
1213 val = n1 + ( n2 - n1 ) * hue / 60.;
1214 else if ( hue < 180. )
1216 else if ( hue < 240. )
1217 val = n1 + ( n2 - n1 ) * ( 240. - hue ) / 60.;
1250 m2 = l * ( s + 1. );
1256 *p_r =
value( m1, m2, h + 120. );
1257 *p_g =
value( m1, m2, h );
1258 *p_b =
value( m1, m2, h - 120. );
1280 PLFLT h, l, s, d, rc, gc, bc, rgb_min, rgb_max;
1282 rgb_min =
MIN( r,
MIN( g, b ) );
1283 rgb_max =
MAX( r,
MAX( g, b ) );
1285 l = ( rgb_min + rgb_max ) / 2.0;
1287 if ( rgb_min == rgb_max )
1294 d = rgb_max - rgb_min;
1298 s = 0.5 * d / ( 1. - l );
1300 rc = ( rgb_max - r ) / d;
1301 gc = ( rgb_max - g ) / d;
1302 bc = ( rgb_max - b ) / d;
1306 else if ( g == rgb_max )
1314 else if ( h >= 360 )
1341 if ( fgets( buffer, length, fp ) == NULL )
1348 pchr = strchr( buffer,
'\n' );
1355 if ( fscanf( fp,
"%*[^\n]\n" ) == EOF && ferror( fp ) )
1362 pchr = strchr( buffer,
'\r' );
1369 pchr = buffer + strlen( buffer ) - 1;
1370 while ( pchr != buffer && *pchr ==
' ' )
1394 int *number_colors,
unsigned int **r,
unsigned int **g,
unsigned int **b,
double **
a )
1402 if ( strlen( filename ) == 0 )
1417 snprintf( msgbuf,
MSGLEN,
"Unable to open cmap0 file %s\n", filename );
1422 if ( !err && ( fscanf( fp,
"%d\n", number_colors ) != 1 || *number_colors < 1 ) )
1434 if ( ( ( *r = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1435 ( ( *g = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1436 ( ( *b = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1437 ( ( *a = (
double *) malloc( (
size_t) ( *number_colors ) *
sizeof (
double ) ) ) == NULL ) )
1440 plexit(
"cmap0_palette_read: insufficient memory" );
1443 for ( i = 0; i < *number_colors; i++ )
1452 if ( strlen( color_info ) == 7 )
1454 if ( sscanf( color_info,
"#%2x%2x%2x",
1455 (
unsigned int *) ( *r + i ), (
unsigned int *) ( *g + i ),
1456 (
unsigned int *) ( *b + i ) ) != 3 )
1463 else if ( strlen( color_info ) > 9 )
1465 if ( sscanf( color_info,
"#%2x%2x%2x %lf",
1466 (
unsigned int *) ( *r + i ), (
unsigned int *) ( *g + i ),
1467 (
unsigned int *) ( *b + i ), (
double *) ( *a + i ) ) != 4 )
1478 else if ( *( *a + i ) < 0. )
1482 else if ( *( *a + i ) > 1. )
1496 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap0 format data line. Line is %s\n",
1509 *number_colors = 16;
1510 if ( ( ( *r = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
int ) ) ) == NULL ) ||
1511 ( ( *g = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1512 ( ( *b = (
unsigned int *) malloc( (
size_t) ( *number_colors ) *
sizeof (
unsigned int ) ) ) == NULL ) ||
1513 ( ( *a = (
double *) malloc( (
size_t) ( *number_colors ) *
sizeof (
double ) ) ) == NULL ) )
1515 plexit(
"cmap0_palette_read: insufficient memory" );
1521 for ( i = 1; i < *number_colors; i++ )
1545 unsigned int *r, *g, *b;
1553 if ( number_colors > plsc->ncol0 )
1557 for ( i = 0; i < number_colors; i++ )
1576 #define fuzzy_range_check( value, min, max, fuzz, err_number ) \
1577 if ( value < ( min - fuzz ) || value > ( max + fuzz ) ) { \
1578 snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format data line. Error number is %d. Line is %s\n", err_number, color_info ); \
1582 } else if ( value < min ) { \
1584 } else if ( value > max ) { \
1602 int format_version, err;
1605 unsigned int r_i, g_i, b_i;
1606 int pos_i, alt_hue_path_i;
1607 double r_d, g_d, b_d, a_d, pos_d;
1608 PLFLT *r, *g, *b, *
a, *pos;
1609 PLINT *ri, *gi, *bi;
1618 if ( strlen( filename ) == 0 )
1633 snprintf( msgbuf,
MSGLEN,
"Unable to open cmap1 .pal file %s\n", filename );
1641 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1646 if ( strncmp( color_info,
"v2 ", 2 ) == 0 )
1649 if ( strncmp( &color_info[3],
"hls", 3 ) == 0 )
1651 else if ( strncmp( &color_info[3],
"rgb", 3 ) == 0 )
1655 snprintf( msgbuf,
MSGLEN,
"Invalid color space %s - assuming RGB\n", &color_info[3] );
1661 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1668 if ( sscanf( color_info,
"%d\n", &number_colors ) != 1 || number_colors < 2 )
1670 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of colors) %s\n", color_info );
1676 r = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1677 g = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1678 b = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1679 ri = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1680 gi = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1681 bi = (
PLINT *) malloc( (
size_t) number_colors *
sizeof (
PLINT ) );
1682 a = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1683 pos = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1684 alt_hue_path = (
PLBOOL *) malloc( (
size_t) number_colors *
sizeof (
PLBOOL ) );
1686 if ( format_version == 0 )
1688 int return_sscanf = -1, return_sscanf_old = 0;
1690 for ( i = 0; i < number_colors; i++ )
1694 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1700 color_info[
PALLEN - 1] =
'\0';
1701 return_sscanf = sscanf( color_info,
"#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &alt_hue_path_i );
1702 if ( return_sscanf < 4 || ( return_sscanf_old != 0 && return_sscanf != return_sscanf_old ) )
1704 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of items for version 1 of format) %s\n", color_info );
1709 return_sscanf_old = return_sscanf;
1712 r[i] = (
PLFLT) r_i / 255.;
1713 g[i] = (
PLFLT) g_i / 255.;
1714 b[i] = (
PLFLT) b_i / 255.;
1716 pos[i] = 0.01 * (
PLFLT) pos_i;
1721 if ( return_sscanf == 5 )
1724 alt_hue_path[i] = (
PLBOOL) alt_hue_path_i;
1727 if ( return_sscanf == 4 )
1730 free( alt_hue_path );
1731 alt_hue_path = NULL;
1737 for ( i = 0; i < number_colors; i++ )
1741 snprintf( msgbuf,
MSGLEN,
"Error reading cmap1 .pal file %s\n", filename );
1746 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 )
1748 snprintf( msgbuf,
MSGLEN,
"Unrecognized cmap1 format (wrong number of items for version 2 of format) %s\n", color_info );
1758 pos[i] = (
PLFLT) pos_d;
1775 alt_hue_path[i] = (
PLBOOL) alt_hue_path_i;
1784 c_plscmap1la( rgb, number_colors, pos, r, g, b, a, alt_hue_path );
1788 for ( i = 0; i < number_colors; i++ )
1790 ri[i] = (
PLINT) ( r[i] * 255.0 );
1791 gi[i] = (
PLINT) ( g[i] * 255.0 );
1792 bi[i] = (
PLINT) ( b[i] * 255.0 );
1806 r = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1807 g = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1808 b = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1809 pos = (
PLFLT *) malloc( (
size_t) number_colors *
sizeof (
PLFLT ) );
1829 free( alt_hue_path );
1850 if ( plsc->graphx == 1 )
1856 fprintf( stderr,
"\n*** PLPLOT WARNING ***\n" );
1857 if ( *errormsg !=
'\0' )
1858 fprintf( stderr,
"%s\n", errormsg );
1880 ( *abort_handler )( errormsg );
1882 if ( plsc->errcode != NULL )
1883 *( plsc->errcode ) = 1;
1885 if ( plsc->errmsg != NULL )
1887 sprintf( plsc->errmsg,
"\n*** PLPLOT ERROR, ABORTING OPERATION ***\n" );
1888 if ( *errormsg !=
'\0' )
1889 sprintf( plsc->errmsg,
"%s, aborting operation\n", errormsg );
1895 if ( plsc->graphx == 1 )
1901 fprintf( stderr,
"\n*** PLPLOT ERROR, ABORTING OPERATION ***\n" );
1902 if ( *errormsg !=
'\0' )
1903 fprintf( stderr,
"%s, aborting operation\n", errormsg );
1946 status = ( *exit_handler )( errormsg );
1949 if ( *errormsg !=
'\0' )
1951 fprintf( stderr,
"\n*** PLPLOT ERROR, IMMEDIATE EXIT ***\n" );
1952 fprintf( stderr,
"%s\n", errormsg );
1956 fprintf( stderr,
"Program aborted\n" );
1988 if ( plsc->level > 0 )
2003 static int ostate = 0;
2005 if ( !plsc->dev_xor )
2011 if ( plsc->level > 0 )
2016 ostate = plsc->plbuf_write;
2017 plsc->plbuf_write = 0;
2020 plsc->plbuf_write = ostate;
2033 if ( !plsc->dev_modeset )
2035 plwarn(
"plsdrawmode: Mode setting is not supported" );
2037 else if ( plsc->level > 0 )
2043 plwarn(
"plsdrawmode: Initialize PLplot first" );
2058 if ( !plsc->dev_modeset )
2060 plwarn(
"plgdrawmode: Mode getting is not supported" );
2063 else if ( plsc->level > 0 )
2069 plwarn(
"plsdrawmode: Initialize PLplot first" );
2085 if ( plsc->level > 0 )
2130 char *fs = NULL, *dn;
2148 #if defined ( PLPLOT_BIN_ENV )
2156 #endif // PLPLOT_BIN_ENV
2166 #if defined ( PLPLOT_HOME_ENV )
2174 #endif // PLPLOT_HOME_ENV
2178 #if defined ( BIN_DIR )
2187 fprintf( stderr,
"plFindCommand: cannot locate command: %s\n", fn );
2188 #if defined ( BIN_DIR )
2189 fprintf( stderr,
"bin dir=\"" BIN_DIR "\"\n" );
2220 if ( pdfs->
file != NULL )
2248 char *fs = NULL, *dn = NULL;
2256 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2262 #if defined ( PLPLOT_LIB_ENV )
2267 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2271 #endif // PLPLOT_LIB_ENV
2275 if ( ( file =
pdf_fopen( fn,
"rb" ) ) != NULL )
2277 pldebug(
"plLibOpenPdfstr",
"Found file %s in current directory.\n", fn );
2284 #if defined ( PLPLOT_HOME_ENV )
2289 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2293 #endif // PLPLOT_HOME_ENV/lib
2297 #if defined ( DATA_DIR )
2300 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2309 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2314 file = plMacLibOpen( fn );
2322 if ( ( file =
pdf_fopen( fs,
"rb" ) ) != NULL )
2327 pldebug(
"plLibOpenPdfstr",
"File %s not found.\n", fn );
2332 pldebug(
"plLibOpenPdfstr",
"Found file %s\n", fs );
2367 pldebug(
"plFindName",
"Trying to find %s\n", p );
2370 pldebug(
"plFindName",
"Readlink read %d chars at: %s\n", n, p );
2371 if ( buf[0] ==
'/' )
2375 strncpy( p, buf, (
size_t) n );
2377 pldebug(
"plFindName",
"Link is absolute: %s\n", p );
2383 cp = 1 + strrchr( p,
'/' );
2384 strncpy( cp, buf, (
size_t) n );
2386 pldebug(
"plFindName",
2387 "Link is relative: %s\n\tTotal path:%s\n", cp, p );
2394 #define S_ISREG( mode ) ( mode & S_IFREG )
2399 if ( errno == EINVAL || errno == ENXIO )
2401 pldebug(
"plFindName",
"%s may be the one...\n", p );
2402 if ( ( stat( p, &sbuf ) == 0 ) && S_ISREG( sbuf.st_mode ) )
2404 pldebug(
"plFindName",
"%s is a regular file\n", p );
2405 return ( access( p, X_OK ) );
2408 pldebug(
"plFindName",
"%s found but is not executable\n", p );
2409 return ( errno ? errno : -1 );
2435 plGetName(
const char *dir,
const char *subdir,
const char *filename,
char **filespec )
2442 lfilespec = strlen( dir ) + strlen( subdir ) + strlen( filename ) + 10;
2443 if ( ( *filespec = (
char *) malloc( lfilespec ) ) == NULL )
2445 plexit(
"plGetName: Insufficient memory" );
2448 strcpy( *filespec, dir );
2450 if ( *subdir !=
'\0' )
2453 strcat( *filespec, subdir );
2455 if ( *filename !=
'\0' )
2458 strcat( *filespec, filename );
2460 pldebug(
"plGetName",
"Length of full pathname of file to be found is %zu\n", lfilespec );
2461 pldebug(
"plGetName",
"Full pathname of file to be found is %s\n", *filespec );
2476 size_t ldirspec = strlen( dirspec );
2477 #if defined ( MSDOS ) || defined ( WIN32 )
2478 if ( dirspec[ldirspec - 1] !=
'\\' )
2479 strcat( dirspec,
"\\" );
2480 #elif defined ( macintosh )
2481 if ( dirspec[ldirspec - 1] !=
':' )
2482 strcat( dirspec,
":" );
2483 #else // unix is the default
2484 if ( dirspec[ldirspec - 1] !=
'/' )
2485 strcat( dirspec,
"/" );
2508 x = (double) ( i * ( pls->
ncol1 - 1 ) ) / (
double) ( ncol - 1 );
2513 if ( ir > pls->
ncol1 || il < 0 )
2514 fprintf( stderr,
"Invalid color\n" );
2516 else if ( ir == pls->
ncol1 || ( delta == 0. ) )
2518 newcolor->
r = pls->
cmap1[il].
r;
2519 newcolor->
g = pls->
cmap1[il].
g;
2520 newcolor->
b = pls->
cmap1[il].
b;
2521 newcolor->
a = pls->
cmap1[il].
a;
2525 newcolor->
r = (
unsigned char) ( ( 1. - delta ) * pls->
cmap1[il].
r + delta * pls->
cmap1[ir].
r );
2526 newcolor->
g = (
unsigned char) ( ( 1. - delta ) * pls->
cmap1[il].
g + delta * pls->
cmap1[ir].
g );
2527 newcolor->
b = (
unsigned char) ( ( 1. - delta ) * pls->
cmap1[il].
b + delta * pls->
cmap1[ir].
b );
2528 newcolor->
a = ( 1. - delta ) * pls->
cmap1[il].
a + delta * pls->
cmap1[ir].
a;
2542 #define MAX_NUM_TRIES 10
2546 int i = 0,
count = 0;
2550 while ( pls->
OutFile == NULL )
2564 fprintf( stdout,
"Enter graphics output file name: " );
2566 len = strlen( line );
2577 if ( !strcmp( pls->
FileName,
"-" ) )
2590 plexit(
"Too many tries." );
2593 fprintf( stderr,
"Can't open %s.\n", pls->
FileName );
2595 pldebug(
"plOpenFile",
"Opened %s\n", pls->
FileName );
2638 maxlen = strlen( pls->
BaseName ) + 10;
2641 if ( ( pls->
FileName = (
char *) malloc( maxlen ) ) == NULL )
2643 plexit(
"plP_getmember: Insufficient memory" );
2647 suffix = strstr( pls->
BaseName,
"%n" );
2652 if ( suffix == NULL )
2683 maxlen = 10 + strlen( fnam );
2684 if ( ( pls->
FileName = (
char *) malloc( maxlen ) ) == NULL )
2686 plexit(
"plP_sfnam: Insufficient memory" );
2689 suffix = strstr( fnam,
"%n" );
2691 if ( suffix == NULL )
2693 strncpy( pls->
FileName, fnam, maxlen - 1 );
2706 if ( ( pls->
BaseName = (
char *) malloc( maxlen ) ) == NULL )
2708 plexit(
"plP_sfnam: Insufficient memory" );
2711 strncpy( pls->
BaseName, fnam, maxlen - 1 );
2755 PLFLT xpmm_loc, ypmm_loc;
2773 plP_setpxl( xpmm_loc * plsc->caspfactor, ypmm_loc / plsc->caspfactor );
2805 switch ( orient % 4 )
2808 *px = xmin + ( y -
ymin );
2809 *py = ymin + ( xmax -
x );
2813 *px = xmin + ( xmax -
x );
2814 *py = ymin + ( ymax -
y );
2818 *px = xmin + ( ymax -
y );
2819 *py = ymin + ( x -
xmin );
2841 if ( pls->
dev != NULL )
2842 free( (
void *) pls->
dev );
2844 pls->
dev = calloc( 1, (
size_t)
sizeof (
PLDev ) );
2845 if ( pls->
dev == NULL )
2846 plexit(
"plAllocDev: cannot allocate memory\n" );
2867 gin->
pX = gin->
pY = -1;
2868 gin->
dX = gin->
dY = 0.;
2869 gin->
wX = gin->
wY = 0.;
2898 if ( sscanf( line,
"%d", &m ) == 1 )
2900 fprintf( stdout,
"No value or value out of range; please try again\n" );
2903 plexit(
"Too many tries." );
2934 if ( sscanf( line,
"%lf", &m1 ) == 1 )
2939 fprintf( stdout,
"No value or value out of range; please try again\n" );
2942 plexit(
"Too many tries." );
2960 char *dest = (
char *) malloc( ( strlen( src ) + 1 ) *
sizeof ( char ) );
2962 strcpy( dest, src );
2969 #ifndef PL_HAVE_SNPRINTF
2991 va_start( args, format );
2992 ret = vsprintf( buffer, fmt, args );
2997 plabort(
"plsnprintf: buffer overrun" );
3023 va_start( argptr, format );
3024 ret = vsscanf( buffer, fmt, args );
3030 #endif // PL_HAVE_SNPRINTF
3076 char * setlocale_ptr;
3077 char * saved_lc_numeric_locale;
3079 if ( !( saved_lc_numeric_locale = (
char *) malloc( 100 *
sizeof (
char ) ) ) )
3081 plexit(
"plsave_set_locale: out of memory" );
3085 if ( !( setlocale_ptr = setlocale( LC_NUMERIC, NULL ) ) )
3087 plexit(
"plsave_set_locale: LC_NUMERIC locale could not be determined for NULL locale.\n" );
3089 strncpy( saved_lc_numeric_locale, setlocale_ptr, 100 );
3090 saved_lc_numeric_locale[99] =
'\0';
3100 if ( !( setlocale( LC_NUMERIC,
"C" ) ) )
3102 plexit(
"plsave_set_locale: LC_NUMERIC locale could not be set to \"C\"" );
3104 return saved_lc_numeric_locale;
3128 if ( !( setlocale( LC_NUMERIC, saved_lc_numeric_locale ) ) )
3131 snprintf( msgbuf, 1024,
"plrestore_locale: LC_NUMERIC could not be restored to the default \"%s\" locale.\n", saved_lc_numeric_locale );
3134 free( saved_lc_numeric_locale );