PLplot  5.13.0
plctrl.c
Go to the documentation of this file.
1 // Misc. control routines, like begin, end, exit, change graphics/text
2 // mode, change color. Includes some spillage from plcore.c. If you
3 // don't know where it should go, put it here.
4 //
5 // Copyright (C) 2004 Joao Cardoso
6 // Copyright (C) 2004 Rafael Laboissiere
7 // Copyright (C) 2008 Hazen Babcock
8 // Copyright (C) 2009-2014 Alan W. Irwin
9 // Copyright (C) 2011 Hezekiah M. Carty
10 //
11 // This file is part of PLplot.
12 //
13 // PLplot is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU Library General Public License as published
15 // by the Free Software Foundation; either version 2 of the License, or
16 // (at your option) any later version.
17 //
18 // PLplot is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Library General Public License for more details.
22 //
23 // You should have received a copy of the GNU Library General Public License
24 // along with PLplot; if not, write to the Free Software
25 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 //
27 //
28 
34 
35 #define DEBUG
36 
37 #define NEED_PLDEBUG
38 #include "plplotP.h"
39 #ifdef macintosh
40 #include "mac.h"
41 // for plMacLibOpen prototype; used in plLibOpen
42 #endif
43 
44 #ifdef DJGPP // dos386/djgpp
45 #ifdef __unix
46 #undef __unix
47 #endif
48 #endif
49 
50 #ifdef __unix
51 #include <sys/types.h>
52 #include <sys/stat.h>
53 #ifdef PL_HAVE_UNISTD_H
54 #include <unistd.h>
55 #endif
56 #include <errno.h>
57 #endif
58 
59 // Random number generator (Mersenne Twister)
60 #include "mt19937ar.h"
61 
62 #define BUFFER_SIZE 256
63 #define COLLEN 30
64 #define PALLEN 160
65 #define MSGLEN 1024
66 
67 // small epsilon for fuzzy range checks that is still large enough to
68 // work even in the single precision floating point case.
69 #define FUZZ_EPSILON 1.e-4
70 
71 // Static functions
72 
73 // Used by any external init code to suggest a path
75 
76 static void
78 
79 static void
80 strcat_delim( char *dirspec );
81 
82 static int
83 ( *exit_handler )( PLCHAR_VECTOR errormsg );
84 
85 static void
86 ( *abort_handler )( PLCHAR_VECTOR errormsg );
87 
88 static void
89 plcmap0_def( int imin, int imax );
90 
91 static void
92 plcmap1_def( void );
93 
94 static PLFLT
95 value( double n1, double n2, double hue );
96 
97 static char *
98 read_line( char *buffer, int length, FILE *fp );
99 
100 static void
102  int *number_colors, unsigned int **r, unsigned int **g,
103  unsigned int **b, double **a );
104 
105 // An additional hardwired location for lib files.
106 // I have no plans to change these again, ever.
107 
108 #if defined ( DJGPP )
109 #ifndef PLLIBDEV
110 #define PLLIBDEV "c:/plplot/lib"
111 #endif
112 
113 #elif defined ( MSDOS )
114 #ifndef PLLIBDEV
115 #define PLLIBDEV "c:\\plplot\\lib"
116 #endif
117 
118 #else
119 
120 // Anything else is assumed to be Unix
121 
122 #ifndef PLLIBDEV
123 #define PLLIBDEV "/usr/local/plplot/lib"
124 #endif
125 
126 #endif
127 
128 //--------------------------------------------------------------------------
129 // Routines that deal with colors & color maps.
130 //--------------------------------------------------------------------------
131 
132 //--------------------------------------------------------------------------
133 // plcol0()
134 //
139 
140 void
141 c_plcol0( PLINT icol0 )
142 {
143  if ( plsc->level < 1 )
144  {
145  plabort( "plcol0: Please call plinit first" );
146  return;
147  }
148  if ( icol0 < 0 || icol0 >= plsc->ncol0 )
149  {
150  char buffer[BUFFER_SIZE];
151  snprintf( buffer, BUFFER_SIZE, "plcol0: Invalid color map entry: %d", (int) icol0 );
152  plabort( buffer );
153  return;
154  }
155 
156  plsc->icol0 = icol0;
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;
161 
162  plsc->curcmap = 0;
164 }
165 
166 //--------------------------------------------------------------------------
167 // plcol1()
168 //
173 
174 void
176 {
177  PLINT icol1;
178 
179  if ( plsc->level < 1 )
180  {
181  plabort( "plcol1: Please call plinit first" );
182  return;
183  }
184  if ( col1 < 0 || col1 > 1 || isnan( col1 ) )
185  {
186  char buffer[BUFFER_SIZE];
187  snprintf( buffer, BUFFER_SIZE, "plcol1: Invalid color map position: %f", (PLFLT) col1 );
188  plabort( buffer );
189  return;
190  }
191 
192  icol1 = (PLINT) ( col1 * plsc->ncol1 );
193  icol1 = MIN( icol1, plsc->ncol1 - 1 );
194 
195  plsc->icol1 = icol1;
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;
200 
201  plsc->curcmap = 1;
203 }
204 
205 //--------------------------------------------------------------------------
206 // plscolbg()
207 //
213 
214 void
216 {
217  plscol0( 0, r, g, b );
218 }
219 
220 //--------------------------------------------------------------------------
221 // plscolbga()
222 //
230 
231 //--------------------------------------------------------------------------
232 
233 void
234 c_plscolbga( PLINT r, PLINT g, PLINT b, PLFLT alpha )
235 {
236  plscol0a( 0, r, g, b, alpha );
237 }
238 
239 //--------------------------------------------------------------------------
240 // plgcolbg()
241 //
247 
248 void
250 {
251  plgcol0( 0, r, g, b );
252 }
253 
254 //--------------------------------------------------------------------------
255 // plgcolbga()
256 //
263 
264 void
265 c_plgcolbga( PLINT *r, PLINT *g, PLINT *b, PLFLT *alpha )
266 {
267  plgcol0a( 0, r, g, b, alpha );
268 }
269 
270 //--------------------------------------------------------------------------
271 // plscol0()
272 //
280 
281 void
282 c_plscol0( PLINT icol0, PLINT r, PLINT g, PLINT b )
283 {
284  if ( plsc->cmap0 == NULL )
285  plscmap0n( 0 );
286  if ( icol0 < 0 || icol0 >= plsc->ncol0 )
287  {
288  char buffer[BUFFER_SIZE];
289  snprintf( buffer, BUFFER_SIZE, "plscol0: Illegal color table value: %d", (int) icol0 );
290  plabort( buffer );
291  return;
292  }
293  if ( ( r < 0 || r > 255 ) || ( g < 0 || g > 255 ) || ( b < 0 || b > 255 ) )
294  {
295  char buffer[BUFFER_SIZE];
296  snprintf( buffer, BUFFER_SIZE, "plscol0: Invalid RGB color: %d, %d, %d",
297  (int) r, (int) g, (int) b );
298  plabort( buffer );
299  return;
300  }
301 
302  plscol0a( icol0, r, g, b, 1.0 );
303 }
304 
305 //--------------------------------------------------------------------------
306 // plscol0a()
307 //
316 
317 void
318 c_plscol0a( PLINT icol0, PLINT r, PLINT g, PLINT b, PLFLT alpha )
319 {
320  if ( plsc->cmap0 == NULL )
321  plscmap0n( 0 );
322  if ( icol0 < 0 || icol0 >= plsc->ncol0 )
323  {
324  char buffer[BUFFER_SIZE];
325  snprintf( buffer, BUFFER_SIZE, "plscol0a: Illegal color table value: %d", (int) icol0 );
326  plabort( buffer );
327  return;
328  }
329  if ( ( r < 0 || r > 255 ) || ( g < 0 || g > 255 ) || ( b < 0 || b > 255 ) || ( alpha < 0. || alpha > 1.0 ) )
330  {
331  char buffer[BUFFER_SIZE];
332  snprintf( buffer, BUFFER_SIZE, "plscol0a: Invalid RGB color: %d, %d, %d, %f",
333  (int) r, (int) g, (int) b, (double) alpha );
334  plabort( buffer );
335  return;
336  }
337 
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;
342 
343  if ( plsc->level > 0 )
345 }
346 
347 //--------------------------------------------------------------------------
348 // plgcol0()
349 //
357 
358 void
359 c_plgcol0( PLINT icol0, PLINT *r, PLINT *g, PLINT *b )
360 {
361  if ( plsc->cmap0 == NULL )
362  plscmap0n( 0 );
363 
364  *r = -1;
365  *g = -1;
366  *b = -1;
367 
368  if ( icol0 < 0 || icol0 > plsc->ncol0 )
369  {
370  char buffer[BUFFER_SIZE];
371  snprintf( buffer, BUFFER_SIZE, "plgcol0: Invalid color index: %d", (int) icol0 );
372  plabort( buffer );
373  return;
374  }
375 
376  *r = plsc->cmap0[icol0].r;
377  *g = plsc->cmap0[icol0].g;
378  *b = plsc->cmap0[icol0].b;
379 
380  return;
381 }
382 
383 //--------------------------------------------------------------------------
384 // plgcol0a()
385 //
394 
395 void
396 c_plgcol0a( PLINT icol0, PLINT *r, PLINT *g, PLINT *b, PLFLT *alpha )
397 {
398  if ( plsc->cmap0 == NULL )
399  plscmap0n( 0 );
400 
401  *r = -1;
402  *g = -1;
403  *b = -1;
404  *alpha = -1.0;
405 
406  if ( icol0 < 0 || icol0 > plsc->ncol0 )
407  {
408  char buffer[BUFFER_SIZE];
409  snprintf( buffer, BUFFER_SIZE, "plgcol0: Invalid color index: %d", (int) icol0 );
410  plabort( buffer );
411  return;
412  }
413 
414  *r = plsc->cmap0[icol0].r;
415  *g = plsc->cmap0[icol0].g;
416  *b = plsc->cmap0[icol0].b;
417  *alpha = plsc->cmap0[icol0].a;
418 
419  return;
420 }
421 
422 //--------------------------------------------------------------------------
423 // plscmap0()
424 //
432 
433 void
435 {
436  int i;
437 
438  plscmap0n( ncol0 );
439 
440  for ( i = 0; i < plsc->ncol0; i++ )
441  {
442  if ( ( r[i] < 0 || r[i] > 255 ) ||
443  ( g[i] < 0 || g[i] > 255 ) ||
444  ( b[i] < 0 || b[i] > 255 ) )
445  {
446  char buffer[BUFFER_SIZE];
447  snprintf( buffer, BUFFER_SIZE, "plscmap0: Invalid RGB color: %d, %d, %d",
448  (int) r[i], (int) g[i], (int) b[i] );
449  plabort( buffer );
450  return;
451  }
452 
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;
457  }
458 
459  if ( plsc->level > 0 )
461 }
462 
463 //--------------------------------------------------------------------------
464 // plscmap0a()
465 //
474 
475 void
477 {
478  int i;
479 
480  plscmap0n( ncol0 );
481 
482  for ( i = 0; i < plsc->ncol0; i++ )
483  {
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 ) )
488  {
489  char buffer[BUFFER_SIZE];
490  snprintf( buffer, BUFFER_SIZE, "plscmap0a: Invalid RGB color: %d, %d, %d, %f",
491  (int) r[i], (int) g[i], (int) b[i], (double) alpha[i] );
492  plabort( buffer );
493  return;
494  }
495 
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];
500  }
501 
502  if ( plsc->level > 0 )
504 }
505 
506 //--------------------------------------------------------------------------
507 // plscmap1()
508 //
516 
517 void
519 {
520  int i;
521 
522  plscmap1n( ncol1 );
523 
524  for ( i = 0; i < plsc->ncol1; i++ )
525  {
526  if ( ( r[i] < 0 || r[i] > 255 ) ||
527  ( g[i] < 0 || g[i] > 255 ) ||
528  ( b[i] < 0 || b[i] > 255 ) )
529  {
530  char buffer[BUFFER_SIZE];
531  snprintf( buffer, BUFFER_SIZE, "plscmap1: Invalid RGB color: %d, %d, %d",
532  (int) r[i], (int) g[i], (int) b[i] );
533  plabort( buffer );
534  return;
535  }
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;
540  }
541 
542  if ( plsc->level > 0 )
544 }
545 
546 //--------------------------------------------------------------------------
547 // plscmap1a()
548 //
557 
558 void
560 {
561  int i;
562 
563  plscmap1n( ncol1 );
564 
565  for ( i = 0; i < plsc->ncol1; i++ )
566  {
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 ) )
571  {
572  char buffer[BUFFER_SIZE];
573  snprintf( buffer, BUFFER_SIZE, "plscmap1a: Invalid RGB color: %d, %d, %d, %f",
574  (int) r[i], (int) g[i], (int) b[i], (double) alpha[i] );
575  plabort( buffer );
576  return;
577  }
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];
582  }
583 
584  if ( plsc->level > 0 )
586 }
587 
588 //--------------------------------------------------------------------------
589 // plscmap1l()
590 //
639 
640 void
641 c_plscmap1l( PLINT itype, PLINT npts, PLFLT_VECTOR intensity,
642  PLFLT_VECTOR coord1, PLFLT_VECTOR coord2, PLFLT_VECTOR coord3, PLINT_VECTOR alt_hue_path )
643 {
644  int n;
645 
646  if ( npts < 2 )
647  {
648  plabort( "plscmap1l: Must specify at least two control points" );
649  return;
650  }
651 
652  if ( ( intensity[0] != 0 ) || ( intensity[npts - 1] != 1 ) )
653  {
654  plabort( "plscmap1l: First, last control points must lie on boundary" );
655  return;
656  }
657 
658  if ( npts > PL_MAX_CMAP1CP )
659  {
660  plabort( "plscmap1l: exceeded maximum number of control points" );
661  return;
662  }
663 
664  // Allocate if not done yet
665 
666  if ( plsc->cmap1 == NULL )
667  plscmap1n( 0 );
668 
669  // Save control points
670 
671  plsc->cmap1cp_is_rgb = itype == 0 ? 0 : 1;
672  plsc->ncp1 = npts;
673 
674  for ( n = 0; n < npts; n++ )
675  {
676  plsc->cmap1cp[n].c1 = coord1[n];
677  plsc->cmap1cp[n].c2 = coord2[n];
678  plsc->cmap1cp[n].c3 = coord3[n];
679  plsc->cmap1cp[n].p = intensity[n];
680  plsc->cmap1cp[n].a = 1.0;
681 
682  if ( alt_hue_path == NULL )
683  plsc->cmap1cp[n].alt_hue_path = 0;
684  else if ( n != npts - 1 )
685  plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
686  else
687  // Note final element is unused, so we set to zero for completeness.
688  plsc->cmap1cp[n].alt_hue_path = 0;
689  }
690 
691  // Calculate and set color map
692 
693  plcmap1_calc();
694 }
695 
696 //--------------------------------------------------------------------------
697 // plscmap1la()
698 //
710 
711 void
712 c_plscmap1la( PLINT itype, PLINT npts, PLFLT_VECTOR intensity,
713  PLFLT_VECTOR coord1, PLFLT_VECTOR coord2, PLFLT_VECTOR coord3, PLFLT_VECTOR alpha, PLINT_VECTOR alt_hue_path )
714 {
715  int n;
716 
717  if ( npts < 2 )
718  {
719  plabort( "plscmap1la: Must specify at least two control points" );
720  return;
721  }
722 
723  if ( ( intensity[0] != 0 ) || ( intensity[npts - 1] != 1 ) )
724  {
725  plabort( "plscmap1la: First, last control points must lie on boundary" );
726  return;
727  }
728 
729  if ( npts > PL_MAX_CMAP1CP )
730  {
731  plabort( "plscmap1la: exceeded maximum number of control points" );
732  return;
733  }
734 
735 // Allocate if not done yet
736 
737  if ( plsc->cmap1 == NULL )
738  plscmap1n( 0 );
739 
740 // Save control points
741 
742  plsc->cmap1cp_is_rgb = itype == 0 ? 0 : 1;
743  plsc->ncp1 = npts;
744 
745  for ( n = 0; n < npts; n++ )
746  {
747  plsc->cmap1cp[n].c1 = coord1[n];
748  plsc->cmap1cp[n].c2 = coord2[n];
749  plsc->cmap1cp[n].c3 = coord3[n];
750  plsc->cmap1cp[n].p = intensity[n];
751  plsc->cmap1cp[n].a = alpha[n];
752 
753  if ( alt_hue_path == NULL )
754  plsc->cmap1cp[n].alt_hue_path = 0;
755  else if ( n != npts - 1 )
756  plsc->cmap1cp[n].alt_hue_path = alt_hue_path[n];
757  else
758  // Note final element is unused, so we set to zero for completeness.
759  plsc->cmap1cp[n].alt_hue_path = 0;
760  }
761 
762 // Calculate and set color map
763 
764  plcmap1_calc();
765 }
766 
767 //--------------------------------------------------------------------------
768 // plcmap1_calc()
769 //
771 
772 void
774 {
775  int i, n;
776  PLFLT delta, dp, dh, dl, ds, da, dr, dg, db;
777  PLFLT h, l, s, p, r, g, b, a;
778 
779 // Loop over all control point pairs
780  if ( !plsc->cmap1cp_is_rgb )
781  {
782  for ( n = 0; n < plsc->ncp1 - 1; n++ )
783  {
784  if ( plsc->cmap1cp[n].p == plsc->cmap1cp[n + 1].p )
785  continue;
786 
787  // Differences in p, h, l, s between ctrl pts
788 
789  dp = plsc->cmap1cp[n + 1].p - plsc->cmap1cp[n].p;
790  dh = plsc->cmap1cp[n + 1].c1 - plsc->cmap1cp[n].c1;
791  dl = plsc->cmap1cp[n + 1].c2 - plsc->cmap1cp[n].c2;
792  ds = plsc->cmap1cp[n + 1].c3 - plsc->cmap1cp[n].c3;
793  da = plsc->cmap1cp[n + 1].a - plsc->cmap1cp[n].a;
794 
795  // Adjust dh if we are to go around "the back side"
796 
797  if ( plsc->cmap1cp[n].alt_hue_path )
798  dh = ( dh > 0 ) ? dh - 360 : dh + 360;
799 
800  // Loop over all color cells. Only interested in cells located (in
801  // cmap1 space) between n_th and n+1_th control points
802 
803  for ( i = 0; i < plsc->ncol1; i++ )
804  {
805  p = (double) i / ( plsc->ncol1 - 1.0 );
806  if ( ( p < plsc->cmap1cp[n].p ) ||
807  ( p > plsc->cmap1cp[n + 1].p ) )
808  continue;
809 
810  // Interpolate based on position of color cell in cmap1 space
811 
812  delta = ( p - plsc->cmap1cp[n].p ) / dp;
813 
814  // Linearly interpolate to get color cell h, l, s values
815 
816  h = plsc->cmap1cp[n].c1 + dh * delta;
817  l = plsc->cmap1cp[n].c2 + dl * delta;
818  s = plsc->cmap1cp[n].c3 + ds * delta;
819  a = plsc->cmap1cp[n].a + da * delta;
820 
821  while ( h >= 360. )
822  h -= 360.;
823 
824  while ( h < 0. )
825  h += 360.;
826 
827  c_plhlsrgb( h, l, s, &r, &g, &b );
828 
829  plsc->cmap1[i].r = (unsigned char) MAX( 0, MIN( 255, (int) ( 256. * r ) ) );
830  plsc->cmap1[i].g = (unsigned char) MAX( 0, MIN( 255, (int) ( 256. * g ) ) );
831  plsc->cmap1[i].b = (unsigned char) MAX( 0, MIN( 255, (int) ( 256. * b ) ) );
832  plsc->cmap1[i].a = a;
833  }
834  }
835  }
836  else
837  {
838  for ( n = 0; n < plsc->ncp1 - 1; n++ )
839  {
840  if ( plsc->cmap1cp[n].p == plsc->cmap1cp[n + 1].p )
841  continue;
842 
843  // Differences in p, h, l, s between ctrl pts
844 
845  dp = plsc->cmap1cp[n + 1].p - plsc->cmap1cp[n].p;
846  dr = plsc->cmap1cp[n + 1].c1 - plsc->cmap1cp[n].c1;
847  dg = plsc->cmap1cp[n + 1].c2 - plsc->cmap1cp[n].c2;
848  db = plsc->cmap1cp[n + 1].c3 - plsc->cmap1cp[n].c3;
849  da = plsc->cmap1cp[n + 1].a - plsc->cmap1cp[n].a;
850 
851  // Loop over all color cells. Only interested in cells located (in
852  // cmap1 space) between n_th and n+1_th control points
853 
854  for ( i = 0; i < plsc->ncol1; i++ )
855  {
856  p = (double) i / ( plsc->ncol1 - 1.0 );
857  if ( ( p < plsc->cmap1cp[n].p ) ||
858  ( p > plsc->cmap1cp[n + 1].p ) )
859  continue;
860 
861  // Interpolate based on position of color cell in cmap1 space
862 
863  delta = ( p - plsc->cmap1cp[n].p ) / dp;
864 
865  // Linearly interpolate to get color cell h, l, s values
866 
867  r = plsc->cmap1cp[n].c1 + dr * delta;
868  g = plsc->cmap1cp[n].c2 + dg * delta;
869  b = plsc->cmap1cp[n].c3 + db * delta;
870  a = plsc->cmap1cp[n].a + da * delta;
871 
872  plsc->cmap1[i].r = (unsigned char) MAX( 0, MIN( 255, (int) ( 256. * r ) ) );
873  plsc->cmap1[i].g = (unsigned char) MAX( 0, MIN( 255, (int) ( 256. * g ) ) );
874  plsc->cmap1[i].b = (unsigned char) MAX( 0, MIN( 255, (int) ( 256. * b ) ) );
875  plsc->cmap1[i].a = a;
876  }
877  }
878  }
879 
880  if ( plsc->level > 0 )
882 }
883 
884 //--------------------------------------------------------------------------
896 //--------------------------------------------------------------------------
897 
898 void
899 c_plscmap1_range( PLFLT min_color, PLFLT max_color )
900 {
901  if ( min_color > max_color || max_color < 0.0 || min_color > 1.0 )
902  {
903  plwarn( "plscmap1_range called with invalid color range" );
904  return;
905  }
906  if ( min_color < 0.0 )
907  {
908  plwarn( "plscmap1_range called with a negative minimum color value" );
909  min_color = 0.0;
910  }
911  if ( max_color > 1.0 )
912  {
913  plwarn( "plscmap1_range called with an out of range maximum color value" );
914  max_color = 1.0;
915  }
916  plsc->cmap1_min = min_color;
917  plsc->cmap1_max = max_color;
918 }
919 
920 //--------------------------------------------------------------------------
925 //--------------------------------------------------------------------------
926 
927 void
928 c_plgcmap1_range( PLFLT *min_color, PLFLT *max_color )
929 {
930  *min_color = plsc->cmap1_min;
931  *max_color = plsc->cmap1_max;
932 }
933 
934 //--------------------------------------------------------------------------
935 // plscmap0n()
936 //
944 
945 void
947 {
948  int ncol, size, imin, imax;
949 
950 // No change
951 
952  if ( ncol0 > 0 && plsc->ncol0 == ncol0 )
953  return;
954 
955 // Handle all possible startup conditions
956 
957  if ( plsc->ncol0 <= 0 && ncol0 <= 0 )
958  ncol = 16;
959  else if ( ncol0 <= 0 )
960  ncol = plsc->ncol0;
961  else
962  ncol = ncol0;
963 
964  imax = ncol - 1;
965  size = ncol * (int) sizeof ( PLColor );
966 
967 // Allocate the space
968 
969  if ( plsc->cmap0 == NULL )
970  {
971  if ( ( plsc->cmap0 = (PLColor *) calloc( 1, (size_t) size ) ) == NULL )
972  {
973  plexit( "c_plscmap0n: Insufficient memory" );
974  }
975  imin = 0;
976  }
977  else
978  {
979  if ( ( plsc->cmap0 = (PLColor *) realloc( plsc->cmap0, (size_t) size ) ) == NULL )
980  {
981  plexit( "c_plscmap0n: Insufficient memory" );
982  }
983  imin = plsc->ncol0;
984  }
985 
986 // Fill in default entries
987 
988  plsc->ncol0 = ncol;
989  plcmap0_def( imin, imax );
990 
991  if ( plsc->level > 0 )
993 }
994 
995 //--------------------------------------------------------------------------
996 // color_set()
997 //
1006 
1007 void
1009 {
1010  plsc->cmap0[i].r = r;
1011  plsc->cmap0[i].g = g;
1012  plsc->cmap0[i].b = b;
1013  plsc->cmap0[i].a = a;
1014  plsc->cmap0[i].name = name;
1015 }
1016 
1017 #define color_def( i, r, g, b, a, n ) \
1018  if ( i >= imin && i <= imax ) color_set( i, r, g, b, a, n );
1019 
1020 //--------------------------------------------------------------------------
1021 // plcmap0_def()
1022 //
1028 
1029 void
1030 plcmap0_def( int imin, int imax )
1031 {
1032  int i;
1033  unsigned int *r, *g, *b;
1034  double *a;
1035  int number_colors;
1036  if ( imin <= imax )
1037  {
1038  cmap0_palette_read( "", &number_colors, &r, &g, &b, &a );
1039  for ( i = imin; i <= MIN( ( number_colors - 1 ), imax ); i++ )
1040  color_def( i, (U_CHAR) r[i], (U_CHAR) g[i], (U_CHAR) b[i], a[i],
1041  "colors defined by default cmap0 palette file" );
1042  free( r );
1043  free( g );
1044  free( b );
1045  free( a );
1046  }
1047  else
1048  {
1049  number_colors = 0;
1050  }
1051 
1052  // Initialize all colours undefined by the default colour palette file
1053  // to opaque red as a warning.
1054  for ( i = MAX( number_colors, imin ); i <= imax; i++ )
1055  color_def( i, 255, 0, 0, 1.0,
1056  "opaque red colour to mark not defined by palette file" );
1057 }
1058 
1059 //--------------------------------------------------------------------------
1060 // plscmap1n()
1061 //
1069 
1070 void
1072 {
1073  PLINT ncol;
1074  size_t size;
1075 
1076 // No change
1077 
1078  if ( ncol1 > 0 && plsc->ncol1 == ncol1 )
1079  return;
1080 
1081 // Handle all possible startup conditions
1082 
1083  if ( plsc->ncol1 <= 0 && ncol1 <= 0 )
1084  ncol = 128;
1085  else if ( ncol1 <= 0 )
1086  ncol = plsc->ncol1;
1087  else
1088  ncol = ncol1;
1089 
1090  size = (size_t) ncol * sizeof ( PLColor );
1091 
1092 // Allocate the space
1093 
1094  if ( plsc->ncol1 > 0 )
1095  {
1096  if ( ( plsc->cmap1 = (PLColor *) realloc( plsc->cmap1, size ) ) == NULL )
1097  {
1098  plexit( "c_plscmap1n: Insufficient memory" );
1099  }
1100  }
1101  else
1102  {
1103  if ( ( plsc->cmap1 = (PLColor *) calloc( (size_t) ncol, sizeof ( PLColor ) ) ) == NULL )
1104  {
1105  plexit( "c_plscmap1n: Insufficient memory" );
1106  }
1107  }
1108 
1109 // Fill in default entries
1110 
1111  plsc->ncol1 = ncol;
1112  if ( plsc->ncp1 == 0 )
1113  plcmap1_def();
1114  else
1115  plcmap1_calc();
1116 }
1117 
1118 //--------------------------------------------------------------------------
1119 // plcmap1_def()
1120 //
1130 
1131 void
1133 {
1134  PLFLT i[6], h[6], l[6], s[6], midpt = 0., vertex = 0.;
1135 
1136 // Positions of control points
1137 
1138  i[0] = 0; // left boundary
1139  i[1] = 0.44; // a little left of center
1140  i[2] = 0.50; // at center
1141  i[3] = 0.50; // at center
1142  i[4] = 0.56; // a little right of center
1143  i[5] = 1; // right boundary
1144 
1145 // For center control points, pick black or white, whichever is closer to bg
1146 // Be careful to pick just short of top or bottom else hue info is lost
1147 
1148  if ( plsc->cmap0 != NULL )
1149  vertex = ( (PLFLT) plsc->cmap0[0].r +
1150  (PLFLT) plsc->cmap0[0].g +
1151  (PLFLT) plsc->cmap0[0].b ) / 3. / 255.;
1152 
1153  if ( vertex < 0.5 )
1154  {
1155  vertex = 0.01;
1156  midpt = 0.10;
1157  }
1158  else
1159  {
1160  vertex = 0.99;
1161  midpt = 0.90;
1162  }
1163 
1164 // Set hue
1165 
1166  h[0] = 260; // low: blue-violet
1167  h[1] = 260; // only change as we go over vertex
1168  h[2] = 260; // only change as we go over vertex
1169  h[3] = 0; // high: red
1170  h[4] = 0; // high: red
1171  h[5] = 0; // keep fixed
1172 
1173 // Set lightness
1174 
1175  l[0] = 0.5; // low
1176  l[1] = midpt; // midpoint value
1177  l[2] = vertex; // bg
1178  l[3] = vertex; // bg
1179  l[4] = midpt; // midpoint value
1180  l[5] = 0.5; // high
1181 
1182 // Set saturation -- keep at maximum
1183 
1184  s[0] = 1;
1185  s[1] = 1;
1186  s[2] = 1;
1187  s[3] = 1;
1188  s[4] = 1;
1189  s[5] = 1;
1190 
1191  c_plscmap1l( 0, 6, i, h, l, s, NULL );
1192 
1193  if ( plsc->level > 0 )
1195 }
1196 
1197 //--------------------------------------------------------------------------
1198 // plscolor()
1199 //
1203 //--------------------------------------------------------------------------
1204 
1205 void
1207 {
1208  plsc->colorset = 1;
1209  plsc->color = color;
1210 }
1211 
1212 //--------------------------------------------------------------------------
1213 // void value()
1214 //
1220 //--------------------------------------------------------------------------
1221 
1222 PLFLT
1223 value( double n1, double n2, double hue )
1224 {
1225  PLFLT val;
1226 
1227  while ( hue >= 360. )
1228  hue -= 360.;
1229  while ( hue < 0. )
1230  hue += 360.;
1231 
1232  if ( hue < 60. )
1233  val = n1 + ( n2 - n1 ) * hue / 60.;
1234  else if ( hue < 180. )
1235  val = n2;
1236  else if ( hue < 240. )
1237  val = n1 + ( n2 - n1 ) * ( 240. - hue ) / 60.;
1238  else
1239  val = n1;
1240 
1241  return ( val );
1242 }
1243 
1244 //--------------------------------------------------------------------------
1245 // void c_plhlsrgb()
1246 //
1263 
1264 void
1265 c_plhlsrgb( PLFLT h, PLFLT l, PLFLT s, PLFLT *p_r, PLFLT *p_g, PLFLT *p_b )
1266 {
1267  PLFLT m1, m2;
1268 
1269  if ( l <= .5 )
1270  m2 = l * ( s + 1. );
1271  else
1272  m2 = l + s - l * s;
1273 
1274  m1 = 2 * l - m2;
1275 
1276  *p_r = value( m1, m2, h + 120. );
1277  *p_g = value( m1, m2, h );
1278  *p_b = value( m1, m2, h - 120. );
1279 }
1280 
1281 //--------------------------------------------------------------------------
1282 // void c_plrgbhls()
1283 //
1296 
1297 void
1298 c_plrgbhls( PLFLT r, PLFLT g, PLFLT b, PLFLT *p_h, PLFLT *p_l, PLFLT *p_s )
1299 {
1300  PLFLT h, l, s, d, rc, gc, bc, rgb_min, rgb_max;
1301 
1302  rgb_min = MIN( r, MIN( g, b ) );
1303  rgb_max = MAX( r, MAX( g, b ) );
1304 
1305  l = ( rgb_min + rgb_max ) / 2.0;
1306 
1307  if ( rgb_min == rgb_max )
1308  {
1309  s = 0;
1310  h = 0;
1311  }
1312  else
1313  {
1314  d = rgb_max - rgb_min;
1315  if ( l < 0.5 )
1316  s = 0.5 * d / l;
1317  else
1318  s = 0.5 * d / ( 1. - l );
1319 
1320  rc = ( rgb_max - r ) / d;
1321  gc = ( rgb_max - g ) / d;
1322  bc = ( rgb_max - b ) / d;
1323 
1324  if ( r == rgb_max )
1325  h = bc - gc;
1326  else if ( g == rgb_max )
1327  h = rc - bc + 2;
1328  else
1329  h = gc - rc - 2;
1330 
1331  h = h * 60;
1332  if ( h < 0 )
1333  h = h + 360;
1334  else if ( h >= 360 )
1335  h = h - 360;
1336  }
1337  *p_h = h;
1338  *p_l = l;
1339  *p_s = s;
1340 }
1341 
1342 //--------------------------------------------------------------------------
1343 // read_line()
1344 //
1354 
1355 static char *
1356 read_line( char *buffer, int length, FILE *fp )
1357 {
1358  char *pchr;
1359 
1360  // Read the string
1361  if ( fgets( buffer, length, fp ) == NULL )
1362  {
1363  return NULL;
1364  }
1365 
1366  // Sanitize the string we read - it may contain EOL characters
1367  // Make sure file reading starts at the next line
1368  pchr = strchr( buffer, '\n' );
1369  if ( pchr != NULL )
1370  {
1371  *pchr = '\0';
1372  }
1373  else
1374  {
1375  if ( fscanf( fp, "%*[^\n]\n" ) == EOF && ferror( fp ) )
1376  {
1377  return NULL;
1378  }
1379  }
1380 
1381 
1382  pchr = strchr( buffer, '\r' );
1383  if ( pchr != NULL )
1384  {
1385  *pchr = '\0';
1386  }
1387 
1388  // Remove trailing blanks
1389  pchr = buffer + strlen( buffer ) - 1;
1390  while ( pchr != buffer && *pchr == ' ' )
1391  {
1392  *pchr = '\0';
1393  pchr--;
1394  }
1395 
1396  return buffer;
1397 }
1398 
1399 //--------------------------------------------------------------------------
1400 // cmap0_palette_read()
1401 //
1411 
1412 void
1414  int *number_colors, unsigned int **r, unsigned int **g, unsigned int **b, double **a )
1415 {
1416  int i, err = 0;
1417  char color_info[COLLEN];
1418  char msgbuf[MSGLEN];
1419  FILE *fp;
1420  char * save_locale = plsave_set_locale();
1421 
1422  if ( strlen( filename ) == 0 )
1423  {
1425  if ( fp == NULL )
1426  {
1427  snprintf( msgbuf, MSGLEN, "Unable to open cmap0 file %s\n", PL_DEFAULT_CMAP0_FILE );
1428  plwarn( msgbuf );
1429  err = 1;
1430  }
1431  }
1432  else
1433  {
1434  fp = plLibOpen( filename );
1435  if ( fp == NULL )
1436  {
1437  snprintf( msgbuf, MSGLEN, "Unable to open cmap0 file %s\n", filename );
1438  plwarn( msgbuf );
1439  err = 1;
1440  }
1441  }
1442  if ( !err && ( fscanf( fp, "%d\n", number_colors ) != 1 || *number_colors < 1 ) )
1443  {
1444  fclose( fp );
1445  snprintf( msgbuf, MSGLEN, "Unrecognized cmap0 header\n" );
1446  plwarn( msgbuf );
1447  err = 1;
1448  }
1449 
1450  if ( !err )
1451  {
1452  // Allocate arrays to hold r, g, b, and a data for calling routine.
1453  // The caller must free these after it is finished with them.
1454  if ( ( ( *r = (unsigned int *) malloc( (size_t) ( *number_colors ) * sizeof ( unsigned int ) ) ) == NULL ) ||
1455  ( ( *g = (unsigned int *) malloc( (size_t) ( *number_colors ) * sizeof ( unsigned int ) ) ) == NULL ) ||
1456  ( ( *b = (unsigned int *) malloc( (size_t) ( *number_colors ) * sizeof ( unsigned int ) ) ) == NULL ) ||
1457  ( ( *a = (double *) malloc( (size_t) ( *number_colors ) * sizeof ( double ) ) ) == NULL ) )
1458  {
1459  fclose( fp );
1460  plexit( "cmap0_palette_read: insufficient memory" );
1461  }
1462 
1463  for ( i = 0; i < *number_colors; i++ )
1464  {
1465  if ( read_line( color_info, COLLEN, fp ) == NULL )
1466  {
1467  err = 1;
1468  break;
1469  }
1470 
1471  // Get the color data
1472  if ( strlen( color_info ) == 7 )
1473  {
1474  if ( sscanf( color_info, "#%2x%2x%2x",
1475  (unsigned int *) ( *r + i ), (unsigned int *) ( *g + i ),
1476  (unsigned int *) ( *b + i ) ) != 3 )
1477  {
1478  err = 1;
1479  break;
1480  }
1481  *( *a + i ) = 1.0;
1482  }
1483  else if ( strlen( color_info ) > 9 )
1484  {
1485  if ( sscanf( color_info, "#%2x%2x%2x %lf",
1486  (unsigned int *) ( *r + i ), (unsigned int *) ( *g + i ),
1487  (unsigned int *) ( *b + i ), (double *) ( *a + i ) ) != 4 )
1488  {
1489  err = 1;
1490  break;
1491  }
1492  // fuzzy range check.
1493  if ( *( *a + i ) < -FUZZ_EPSILON || *( *a + i ) > ( 1. + FUZZ_EPSILON ) )
1494  {
1495  err = 1;
1496  break;
1497  }
1498  else if ( *( *a + i ) < 0. )
1499  {
1500  *( *a + i ) = 0.;
1501  }
1502  else if ( *( *a + i ) > 1. )
1503  {
1504  *( *a + i ) = 1.;
1505  }
1506  }
1507  else
1508  {
1509  err = 1;
1510  break;
1511  }
1512  }
1513  fclose( fp );
1514  if ( err )
1515  {
1516  snprintf( msgbuf, MSGLEN, "Unrecognized cmap0 format data line. Line is %s\n",
1517  color_info );
1518  plwarn( msgbuf );
1519  free( *r );
1520  free( *g );
1521  free( *b );
1522  free( *a );
1523  }
1524  }
1525  // Fall back to opaque red on opaque white as visual warning of any
1526  // error above.
1527  if ( err )
1528  {
1529  *number_colors = 16;
1530  if ( ( ( *r = (unsigned int *) malloc( (size_t) ( *number_colors ) * sizeof ( int ) ) ) == NULL ) ||
1531  ( ( *g = (unsigned int *) malloc( (size_t) ( *number_colors ) * sizeof ( unsigned int ) ) ) == NULL ) ||
1532  ( ( *b = (unsigned int *) malloc( (size_t) ( *number_colors ) * sizeof ( unsigned int ) ) ) == NULL ) ||
1533  ( ( *a = (double *) malloc( (size_t) ( *number_colors ) * sizeof ( double ) ) ) == NULL ) )
1534  {
1535  plexit( "cmap0_palette_read: insufficient memory" );
1536  }
1537  **r = 255;
1538  **g = 255;
1539  **b = 255;
1540  **a = 1.;
1541  for ( i = 1; i < *number_colors; i++ )
1542  {
1543  *( *r + i ) = 255;
1544  *( *g + i ) = 0;
1545  *( *b + i ) = 0;
1546  *( *a + i ) = 1.0;
1547  }
1548  }
1549 
1550  plrestore_locale( save_locale );
1551 }
1552 
1553 //--------------------------------------------------------------------------
1554 // void c_plspal0(filename)
1555 //
1560 
1561 void
1563 {
1564  int i;
1565  unsigned int *r, *g, *b;
1566  double *a;
1567  int number_colors;
1568  cmap0_palette_read( filename, &number_colors, &r, &g, &b, &a );
1569  // Allocate default number of cmap0 colours if cmap0 allocation not
1570  // done already.
1571  plscmap0n( 0 );
1572  // Allocate sufficient cmap0 colours to contain present data.
1573  if ( number_colors > plsc->ncol0 )
1574  {
1575  plscmap0n( number_colors );
1576  }
1577  for ( i = 0; i < number_colors; i++ )
1578  {
1579  c_plscol0a( i, (PLINT) r[i], (PLINT) g[i], (PLINT) b[i], a[i] );
1580  }
1581  free( r );
1582  free( g );
1583  free( b );
1584  free( a );
1585 }
1586 
1596 #define fuzzy_range_check( value, min, max, fuzz, err_number ) \
1597  if ( value < ( min - fuzz ) || value > ( max + fuzz ) ) { \
1598  snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format data line. Error number is %d. Line is %s\n", err_number, color_info ); \
1599  plwarn( msgbuf ); \
1600  err = 1; \
1601  break; \
1602  } else if ( value < min ) { \
1603  value = min; \
1604  } else if ( value > max ) { \
1605  value = max; \
1606  }
1607 
1608 //--------------------------------------------------------------------------
1609 // void c_plspal1(filename)
1610 //
1616 
1617 void
1618 c_plspal1( PLCHAR_VECTOR filename, PLBOOL interpolate )
1619 {
1620  int i;
1621  int number_colors;
1622  int format_version, err;
1623  PLBOOL rgb;
1624  char color_info[PALLEN];
1625  unsigned int r_i, g_i, b_i;
1626  int pos_i, alt_hue_path_i;
1627  double r_d, g_d, b_d, a_d, pos_d;
1628  PLFLT *r, *g, *b, *a, *pos;
1629  PLINT *ri, *gi, *bi;
1630  PLBOOL *alt_hue_path;
1631  FILE *fp;
1632  char msgbuf[MSGLEN];
1633  char * save_locale = plsave_set_locale();
1634 
1635  rgb = TRUE;
1636  err = 0;
1637  format_version = 0;
1638  if ( strlen( filename ) == 0 )
1639  {
1641  if ( fp == NULL )
1642  {
1643  snprintf( msgbuf, MSGLEN, "Unable to open cmap1 .pal file %s\n", PL_DEFAULT_CMAP1_FILE );
1644  plwarn( msgbuf );
1645  goto finish;
1646  }
1647  }
1648  else
1649  {
1650  fp = plLibOpen( filename );
1651  if ( fp == NULL )
1652  {
1653  snprintf( msgbuf, MSGLEN, "Unable to open cmap1 .pal file %s\n", filename );
1654  plwarn( msgbuf );
1655  goto finish;
1656  }
1657  }
1658  // Check for new file format
1659  if ( read_line( color_info, PALLEN, fp ) == NULL )
1660  {
1661  snprintf( msgbuf, MSGLEN, "Error reading cmap1 .pal file %s\n", filename );
1662  plwarn( msgbuf );
1663  fclose( fp );
1664  goto finish;
1665  }
1666  if ( strncmp( color_info, "v2 ", 2 ) == 0 )
1667  {
1668  format_version = 1;
1669  if ( strncmp( &color_info[3], "hls", 3 ) == 0 )
1670  rgb = FALSE;
1671  else if ( strncmp( &color_info[3], "rgb", 3 ) == 0 )
1672  rgb = TRUE;
1673  else
1674  {
1675  snprintf( msgbuf, MSGLEN, "Invalid color space %s - assuming RGB\n", &color_info[3] );
1676  plwarn( msgbuf );
1677  rgb = TRUE;
1678  }
1679  if ( read_line( color_info, PALLEN, fp ) == NULL )
1680  {
1681  snprintf( msgbuf, MSGLEN, "Error reading cmap1 .pal file %s\n", filename );
1682  plwarn( msgbuf );
1683  fclose( fp );
1684  goto finish;
1685  }
1686  }
1687 
1688  if ( sscanf( color_info, "%d\n", &number_colors ) != 1 || number_colors < 2 )
1689  {
1690  snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format (wrong number of colors) %s\n", color_info );
1691  plwarn( msgbuf );
1692  fclose( fp );
1693  goto finish;
1694  }
1695 
1696  r = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
1697  g = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
1698  b = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
1699  ri = (PLINT *) malloc( (size_t) number_colors * sizeof ( PLINT ) );
1700  gi = (PLINT *) malloc( (size_t) number_colors * sizeof ( PLINT ) );
1701  bi = (PLINT *) malloc( (size_t) number_colors * sizeof ( PLINT ) );
1702  a = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
1703  pos = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
1704  alt_hue_path = (PLBOOL *) malloc( (size_t) ( number_colors - 1 ) * sizeof ( PLBOOL ) );
1705 
1706  if ( format_version == 0 )
1707  {
1708  int return_sscanf = -1, return_sscanf_old = 0;
1709  // Old tk file format
1710  for ( i = 0; i < number_colors; i++ )
1711  {
1712  if ( read_line( color_info, PALLEN, fp ) == NULL )
1713  {
1714  snprintf( msgbuf, MSGLEN, "Error reading cmap1 .pal file %s\n", filename );
1715  plwarn( msgbuf );
1716  fclose( fp );
1717  goto finish;
1718  }
1719  // Ensure string is null terminated if > 160 characters
1720  color_info[PALLEN - 1] = '\0';
1721  return_sscanf = sscanf( color_info, "#%2x%2x%2x %d %d", &r_i, &g_i, &b_i, &pos_i, &alt_hue_path_i );
1722  if ( return_sscanf < 4 || ( return_sscanf_old != 0 && return_sscanf != return_sscanf_old ) )
1723  {
1724  snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format (wrong number of items for version 1 of format) %s\n", color_info );
1725  plwarn( msgbuf );
1726  err = 1;
1727  break;
1728  }
1729  return_sscanf_old = return_sscanf;
1730  // For old format, input colours range from 0 to 255 and
1731  // need to be renormalized to the range from 0. to 1..
1732  r[i] = (PLFLT) r_i / 255.;
1733  g[i] = (PLFLT) g_i / 255.;
1734  b[i] = (PLFLT) b_i / 255.;
1735  a[i] = 1.0;
1736  pos[i] = 0.01 * (PLFLT) pos_i;
1737  fuzzy_range_check( r[i], 0., 1., FUZZ_EPSILON, 1 );
1738  fuzzy_range_check( g[i], 0., 1., FUZZ_EPSILON, 2 );
1739  fuzzy_range_check( b[i], 0., 1., FUZZ_EPSILON, 3 );
1740  fuzzy_range_check( pos[i], 0., 1., FUZZ_EPSILON, 4 );
1741  if ( ( return_sscanf == 5 ) && ( i != number_colors - 1 ) )
1742  {
1743  // Next to oldest tk format with alt_hue_path specified.
1744  alt_hue_path[i] = (PLBOOL) alt_hue_path_i;
1745  }
1746  }
1747  if ( return_sscanf == 4 )
1748  {
1749  // Oldest tk format. No alt_hue_path specified.
1750  free( alt_hue_path );
1751  alt_hue_path = NULL;
1752  }
1753  }
1754  else
1755  {
1756  // New floating point file version with support for alpha and alt_hue_path values
1757  for ( i = 0; i < number_colors; i++ )
1758  {
1759  if ( read_line( color_info, PALLEN, fp ) == NULL )
1760  {
1761  snprintf( msgbuf, MSGLEN, "Error reading cmap1 .pal file %s\n", filename );
1762  plwarn( msgbuf );
1763  fclose( fp );
1764  goto finish;
1765  }
1766  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 )
1767  {
1768  snprintf( msgbuf, MSGLEN, "Unrecognized cmap1 format (wrong number of items for version 2 of format) %s\n", color_info );
1769  plwarn( msgbuf );
1770  err = 1;
1771  break;
1772  }
1773 
1774  r[i] = (PLFLT) r_d;
1775  g[i] = (PLFLT) g_d;
1776  b[i] = (PLFLT) b_d;
1777  a[i] = (PLFLT) a_d;
1778  pos[i] = (PLFLT) pos_d;
1779  // Check that all rgba and pos data within range from 0. to
1780  // 1. except for the hls colour space case where the first
1781  // coordinate is checked within range from 0. to 360.
1782  if ( rgb )
1783  {
1784  fuzzy_range_check( r[i], 0., 1., FUZZ_EPSILON, 5 );
1785  }
1786  else
1787  {
1788  fuzzy_range_check( r[i], 0., 360., ( 360. * FUZZ_EPSILON ), 6 );
1789  }
1790  fuzzy_range_check( g[i], 0., 1., FUZZ_EPSILON, 7 );
1791  fuzzy_range_check( b[i], 0., 1., FUZZ_EPSILON, 8 );
1792  fuzzy_range_check( a[i], 0., 1., FUZZ_EPSILON, 9 );
1793  fuzzy_range_check( pos[i], 0., 1., FUZZ_EPSILON, 10 );
1794 
1795  if ( i != number_colors - 1 )
1796  alt_hue_path[i] = (PLBOOL) alt_hue_path_i;
1797  }
1798  }
1799  fclose( fp );
1800 
1801  if ( !err )
1802  {
1803  if ( interpolate )
1804  {
1805  c_plscmap1la( rgb, number_colors, pos, r, g, b, a, alt_hue_path );
1806  }
1807  else
1808  {
1809  for ( i = 0; i < number_colors; i++ )
1810  {
1811  ri[i] = (PLINT) ( r[i] * 255.0 );
1812  gi[i] = (PLINT) ( g[i] * 255.0 );
1813  bi[i] = (PLINT) ( b[i] * 255.0 );
1814  }
1815  c_plscmap1a( ri, gi, bi, a, number_colors );
1816  }
1817  }
1818  else
1819  {
1820  // Fall back to red scale as visual warning if some problem occurred
1821  // above.
1822  free( r );
1823  free( g );
1824  free( b );
1825  free( pos );
1826  number_colors = 2;
1827  r = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
1828  g = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
1829  b = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
1830  pos = (PLFLT *) malloc( (size_t) number_colors * sizeof ( PLFLT ) );
1831  r[0] = 0.;
1832  r[1] = 1.;
1833  g[0] = 0.;
1834  g[1] = 0.;
1835  b[0] = 0.;
1836  b[1] = 0.;
1837  pos[0] = 0.;
1838  pos[1] = 1.;
1839  c_plscmap1l( TRUE, number_colors, pos, r, g, b, NULL );
1840  }
1841 
1842  free( r );
1843  free( g );
1844  free( b );
1845  free( ri );
1846  free( gi );
1847  free( bi );
1848  free( a );
1849  free( pos );
1850  free( alt_hue_path );
1851 
1852 finish: plrestore_locale( save_locale );
1853 }
1854 
1855 //--------------------------------------------------------------------------
1856 // A grab-bag of various control routines.
1857 //--------------------------------------------------------------------------
1858 
1859 //--------------------------------------------------------------------------
1860 // void plwarn()
1861 //
1865 
1866 void
1868 {
1869  int was_gfx = 0;
1870 
1871  if ( plsc->graphx == 1 )
1872  {
1873  was_gfx = 1;
1874  pltext();
1875  }
1876 
1877  fprintf( stderr, "\n*** PLPLOT WARNING ***\n" );
1878  if ( *errormsg != '\0' )
1879  fprintf( stderr, "%s\n", errormsg );
1880 
1881  if ( was_gfx == 1 )
1882  plgra();
1883 }
1884 
1885 //--------------------------------------------------------------------------
1886 // void plabort()
1887 //
1896 
1897 void
1899 {
1900  if ( abort_handler != NULL )
1901  ( *abort_handler )( errormsg );
1902 
1903  if ( plsc->errcode != NULL )
1904  *( plsc->errcode ) = 1;
1905 
1906  if ( plsc->errmsg != NULL )
1907  {
1908  sprintf( plsc->errmsg, "\n*** PLPLOT ERROR, ABORTING OPERATION ***\n" );
1909  if ( *errormsg != '\0' )
1910  sprintf( plsc->errmsg, "%s, aborting operation\n", errormsg );
1911  }
1912  else
1913  {
1914  int was_gfx = 0;
1915 
1916  if ( plsc->graphx == 1 )
1917  {
1918  was_gfx = 1;
1919  pltext();
1920  }
1921 
1922  fprintf( stderr, "\n*** PLPLOT ERROR, ABORTING OPERATION ***\n" );
1923  if ( *errormsg != '\0' )
1924  fprintf( stderr, "%s, aborting operation\n", errormsg );
1925 
1926  if ( was_gfx == 1 )
1927  plgra();
1928  }
1929 }
1930 
1931 
1932 //--------------------------------------------------------------------------
1933 // void plsabort()
1934 //
1939 //--------------------------------------------------------------------------
1940 
1941 void
1942 plsabort( void ( *handler )( PLCHAR_VECTOR ) )
1943 {
1944  abort_handler = handler;
1945 }
1946 
1947 //--------------------------------------------------------------------------
1948 // void plexit()
1949 //
1959 //--------------------------------------------------------------------------
1960 
1961 void
1963 {
1964  int status = 1;
1965 
1966  if ( exit_handler != NULL )
1967  status = ( *exit_handler )( errormsg );
1968 
1969  plsc->nopause = 1;
1970  if ( *errormsg != '\0' )
1971  {
1972  fprintf( stderr, "\n*** PLPLOT ERROR, IMMEDIATE EXIT ***\n" );
1973  fprintf( stderr, "%s\n", errormsg );
1974  }
1975  plend();
1976 
1977  fprintf( stderr, "Program aborted\n" );
1978  exit( status );
1979 }
1980 
1981 //--------------------------------------------------------------------------
1982 // void plsexit()
1983 //
1988 //--------------------------------------------------------------------------
1989 
1990 void
1991 plsexit( int ( *handler )( PLCHAR_VECTOR ) )
1992 {
1993  exit_handler = handler;
1994 }
1995 
1996 //--------------------------------------------------------------------------
1997 // void plgra()
1998 //
2004 //--------------------------------------------------------------------------
2005 
2006 void
2007 c_plgra( void )
2008 {
2009  if ( plsc->level > 0 )
2010  plP_esc( PLESC_GRAPH, NULL );
2011 }
2012 
2013 //--------------------------------------------------------------------------
2014 // void plxormod()
2015 //
2020 
2021 void
2022 c_plxormod( PLINT mode, PLINT *status ) // xor mode
2023 {
2024  static int ostate = 0;
2025 
2026  if ( !plsc->dev_xor )
2027  {
2028  *status = 0;
2029  return;
2030  }
2031 
2032  if ( plsc->level > 0 )
2033  {
2034  plP_esc( PLESC_XORMOD, &mode );
2035  if ( mode )
2036  {
2037  ostate = plsc->plbuf_write;
2038  plsc->plbuf_write = 0;
2039  }
2040  else
2041  plsc->plbuf_write = ostate;
2042  }
2043  *status = 1;
2044 }
2045 
2046 //--------------------------------------------------------------------------
2051 void
2053 {
2054  if ( !plsc->dev_modeset )
2055  {
2056  plwarn( "plsdrawmode: Mode setting is not supported by this device" );
2057  }
2058  else if ( plsc->level > 0 )
2059  {
2060  plP_esc( PLESC_MODESET, &mode );
2061  }
2062  else
2063  {
2064  plwarn( "plsdrawmode: Initialize PLplot first" );
2065  }
2066  return;
2067 }
2068 
2069 //--------------------------------------------------------------------------
2074 PLINT
2076 {
2077  PLINT mode;
2078 
2079  if ( !plsc->dev_modeset )
2080  {
2081  plwarn( "plgdrawmode: Mode getting is not supported by this device" );
2082  mode = PL_DRAWMODE_UNKNOWN;
2083  }
2084  else if ( plsc->level > 0 )
2085  {
2086  plP_esc( PLESC_MODEGET, &mode );
2087  }
2088  else
2089  {
2090  plwarn( "plsdrawmode: Initialize PLplot first" );
2091  mode = PL_DRAWMODE_UNKNOWN;
2092  }
2093 
2094  return ( mode );
2095 }
2096 
2097 //--------------------------------------------------------------------------
2098 // void pltext()
2099 //
2101 //--------------------------------------------------------------------------
2102 
2103 void
2104 c_pltext( void )
2105 {
2106  if ( plsc->level > 0 )
2107  plP_esc( PLESC_TEXT, NULL );
2108 }
2109 
2110 //--------------------------------------------------------------------------
2111 // void pl_cmd()
2112 //
2119 //--------------------------------------------------------------------------
2120 
2121 void
2122 pl_cmd( PLINT op, void *ptr )
2123 {
2124  if ( plsc->level > 0 )
2125  plP_esc( op, ptr );
2126 }
2127 
2128 //--------------------------------------------------------------------------
2129 // char *plFindCommand
2130 //
2147 //--------------------------------------------------------------------------
2148 
2149 char *
2151 {
2152  char *fs = NULL, *dn;
2153 
2154  //*** see if in build tree **
2155  if ( plInBuildTree() == 1 )
2156  {
2157  plGetName( BUILD_DIR, "bindings/tk", fn, &fs );
2158  if ( !plFindName( fs ) )
2159  return fs;
2160  else
2161  {
2162  plGetName( SOURCE_DIR, "scripts", fn, &fs );
2163  if ( !plFindName( fs ) )
2164  return fs;
2165  }
2166  }
2167 
2168 // PLPLOT_BIN_ENV = $(PLPLOT_BIN)
2169 
2170 #if defined ( PLPLOT_BIN_ENV )
2171  if ( ( dn = getenv( PLPLOT_BIN_ENV ) ) != NULL )
2172  {
2173  plGetName( dn, "", fn, &fs );
2174  if ( !plFindName( fs ) )
2175  return fs;
2176  fprintf( stderr, PLPLOT_BIN_ENV "=\"%s\"\n", dn ); // what IS set?
2177  }
2178 #endif // PLPLOT_BIN_ENV
2179 
2180 // Current directory
2181 
2182  plGetName( ".", "", fn, &fs );
2183  if ( !plFindName( fs ) )
2184  return fs;
2185 
2186 // PLPLOT_HOME_ENV/bin = $(PLPLOT_HOME)/bin
2187 
2188 #if defined ( PLPLOT_HOME_ENV )
2189  if ( ( dn = getenv( PLPLOT_HOME_ENV ) ) != NULL )
2190  {
2191  plGetName( dn, "bin", fn, &fs );
2192  if ( !plFindName( fs ) )
2193  return fs;
2194  fprintf( stderr, PLPLOT_HOME_ENV "=\"%s\"\n", dn ); // what IS set?
2195  }
2196 #endif // PLPLOT_HOME_ENV
2197 
2198 // BIN_DIR
2199 
2200 #if defined ( BIN_DIR )
2201  plGetName( BIN_DIR, "", fn, &fs );
2202  if ( !plFindName( fs ) )
2203  return fs;
2204 #endif
2205 
2206 // Crapped out
2207 
2208  free_mem( fs );
2209  fprintf( stderr, "plFindCommand: cannot locate command: %s\n", fn );
2210 #if defined ( BIN_DIR )
2211  fprintf( stderr, "bin dir=\"" BIN_DIR "\"\n" ); // what WAS set?
2212 #endif // BIN_DIR
2213  return NULL;
2214 }
2215 
2216 //--------------------------------------------------------------------------
2217 // FILE *plLibOpen(fn)
2218 //
2230 //--------------------------------------------------------------------------
2231 
2232 FILE *
2234 {
2235  FILE *ret = NULL;
2236 
2237  PDFstrm *pdfs = plLibOpenPdfstrm( fn );
2238  if ( pdfs == NULL )
2239  {
2240  return NULL;
2241  }
2242  if ( pdfs->file != NULL )
2243  {
2244  ret = pdfs->file;
2245  pdfs->file = NULL;
2246  }
2247  pdf_close( pdfs );
2248  return ret;
2249 }
2250 
2251 //--------------------------------------------------------------------------
2252 // FILE *plLibOpenPdfstrm(fn)
2253 //
2265 //--------------------------------------------------------------------------
2266 PDFstrm *
2268 {
2269  PDFstrm *file;
2270  char *fs = NULL, *dn = NULL;
2271 
2272 //*** search build tree ***
2273 
2274  if ( plInBuildTree() == 1 )
2275  {
2276  plGetName( SOURCE_DIR, "data", fn, &fs );
2277 
2278  if ( ( file = pdf_fopen( fs, "rb" ) ) != NULL )
2279  goto done;
2280  }
2281 
2282 //*** search PLPLOT_LIB_ENV = $(PLPLOT_LIB) ***
2283 
2284 #if defined ( PLPLOT_LIB_ENV )
2285  if ( ( dn = getenv( PLPLOT_LIB_ENV ) ) != NULL )
2286  {
2287  plGetName( dn, "", fn, &fs );
2288 
2289  if ( ( file = pdf_fopen( fs, "rb" ) ) != NULL )
2290  goto done;
2291  fprintf( stderr, PLPLOT_LIB_ENV "=\"%s\"\n", dn ); // what IS set?
2292  }
2293 #endif // PLPLOT_LIB_ENV
2294 
2295 //*** search current directory ***
2296 
2297  if ( ( file = pdf_fopen( fn, "rb" ) ) != NULL )
2298  {
2299  pldebug( "plLibOpenPdfstr", "Found file %s in current directory.\n", fn );
2300  free_mem( fs );
2301  return ( file );
2302  }
2303 
2304 //*** search PLPLOT_HOME_ENV/lib = $(PLPLOT_HOME)/lib ***
2305 
2306 #if defined ( PLPLOT_HOME_ENV )
2307  if ( ( dn = getenv( PLPLOT_HOME_ENV ) ) != NULL )
2308  {
2309  plGetName( dn, "lib", fn, &fs );
2310 
2311  if ( ( file = pdf_fopen( fs, "rb" ) ) != NULL )
2312  goto done;
2313  fprintf( stderr, PLPLOT_HOME_ENV "=\"%s\"\n", dn ); // what IS set?
2314  }
2315 #endif // PLPLOT_HOME_ENV/lib
2316 
2317 //*** search installed location ***
2318 
2319 #if defined ( DATA_DIR )
2320  plGetName( DATA_DIR, "", fn, &fs );
2321 
2322  if ( ( file = pdf_fopen( fs, "rb" ) ) != NULL )
2323  goto done;
2324 #endif // DATA_DIR
2325 
2326 //*** search hardwired location ***
2327 
2328 #ifdef PLLIBDEV
2329  plGetName( PLLIBDEV, "", fn, &fs );
2330 
2331  if ( ( file = pdf_fopen( fs, "rb" ) ) != NULL )
2332  goto done;
2333 #endif // PLLIBDEV
2334 
2335 #ifdef macintosh
2336  file = plMacLibOpen( fn );
2337  if ( file != NULL )
2338  goto done;
2339 #endif // macintosh
2340 
2341  if ( plplotLibDir != NULL )
2342  {
2343  plGetName( plplotLibDir, "", fn, &fs );
2344  if ( ( file = pdf_fopen( fs, "rb" ) ) != NULL )
2345  goto done;
2346  }
2347 
2348 //*** not found, give up ***
2349  pldebug( "plLibOpenPdfstr", "File %s not found.\n", fn );
2350  free_mem( fs );
2351  return NULL;
2352 
2353 done:
2354  pldebug( "plLibOpenPdfstr", "Found file %s\n", fs );
2355  free_mem( fs );
2356  return ( file );
2357 }
2358 
2359 //--------------------------------------------------------------------------
2360 // PLINR plFindName
2361 //
2379 //--------------------------------------------------------------------------
2380 
2381 #ifdef __unix
2382 PLINT
2383 plFindName( char *p )
2384 {
2385  ssize_t n;
2386  char buf[PLPLOT_MAX_PATH], *cp;
2387  struct stat sbuf;
2388 
2389  pldebug( "plFindName", "Trying to find %s\n", p );
2390  while ( ( n = readlink( p, buf, PLPLOT_MAX_PATH ) ) > 0 )
2391  {
2392  pldebug( "plFindName", "Readlink read %d chars at: %s\n", n, p );
2393  if ( buf[0] == '/' )
2394  {
2395  // Link is an absolute path
2396 
2397  strncpy( p, buf, (size_t) n );
2398  p[n] = '\0';
2399  pldebug( "plFindName", "Link is absolute: %s\n", p );
2400  }
2401  else
2402  {
2403  // Link is relative to its directory; make it absolute
2404 
2405  cp = 1 + strrchr( p, '/' );
2406  strncpy( cp, buf, (size_t) n );
2407  cp[n] = '\0';
2408  pldebug( "plFindName",
2409  "Link is relative: %s\n\tTotal path:%s\n", cp, p );
2410  }
2411  }
2412 
2413 // This macro not defined on the NEC SX-3
2414 
2415 #ifdef SX
2416 #define S_ISREG( mode ) ( mode & S_IFREG )
2417 #endif
2418 
2419 // SGI machines return ENXIO instead of EINVAL Dubois 11/92
2420 
2421  if ( errno == EINVAL || errno == ENXIO )
2422  {
2423  pldebug( "plFindName", "%s may be the one...\n", p );
2424  if ( ( stat( p, &sbuf ) == 0 ) && S_ISREG( sbuf.st_mode ) )
2425  {
2426  pldebug( "plFindName", "%s is a regular file\n", p );
2427  return ( access( p, X_OK ) );
2428  }
2429  }
2430  pldebug( "plFindName", "%s found but is not executable\n", p );
2431  return ( errno ? errno : -1 );
2432 }
2433 
2434 #else
2435 PLINT
2436 plFindName( char *p )
2437 {
2438  return 1;
2439 }
2440 #endif
2441 
2442 //--------------------------------------------------------------------------
2443 // void plGetName()
2444 //
2454 //--------------------------------------------------------------------------
2455 
2456 void
2457 plGetName( PLCHAR_VECTOR dir, PLCHAR_VECTOR subdir, PLCHAR_VECTOR filename, char **filespec )
2458 {
2459  size_t lfilespec;
2460 
2461 // Malloc space for filespec
2462 
2463  free_mem( *filespec );
2464  // Be slightly generous since 3 (two delimiters + NULL byte) should be
2465  // enough.
2466  lfilespec = strlen( dir ) + strlen( subdir ) + strlen( filename ) + 10;
2467  if ( ( *filespec = (char *) malloc( lfilespec ) ) == NULL )
2468  {
2469  plexit( "plGetName: Insufficient memory" );
2470  }
2471 
2472  strcpy( *filespec, dir );
2473 
2474  if ( *subdir != '\0' )
2475  {
2476  strcat_delim( *filespec );
2477  strcat( *filespec, subdir );
2478  }
2479  if ( *filename != '\0' )
2480  {
2481  strcat_delim( *filespec );
2482  strcat( *filespec, filename );
2483  }
2484 #ifdef _WIN32
2485  // According to http://msdn.microsoft.com/en-us/library/vstudio/tcxf1dw6.aspx
2486  // and also Wine tests, Microsoft does not support the c99 standard %zu
2487  // format. Instead, %lu is recommended for size_t.
2488  pldebug( "plGetName", "Maximum length of full pathname of file to be found is %lu\n", lfilespec - 1 );
2489 #else
2490  pldebug( "plGetName", "Maximum length of full pathname of file to be found is %zu\n", lfilespec - 1 );
2491 #endif
2492  pldebug( "plGetName", "Full pathname of file to be found is %s\n", *filespec );
2493 }
2494 
2495 //--------------------------------------------------------------------------
2496 // void strcat_delim()
2497 //
2502 //--------------------------------------------------------------------------
2503 
2504 void
2505 strcat_delim( char *dirspec )
2506 {
2507  size_t ldirspec = strlen( dirspec );
2508 #if defined ( MSDOS ) || defined ( _WIN32 )
2509  if ( dirspec[ldirspec - 1] != '\\' )
2510  strcat( dirspec, "\\" );
2511 #elif defined ( macintosh )
2512  if ( dirspec[ldirspec - 1] != ':' )
2513  strcat( dirspec, ":" );
2514 #else // unix is the default
2515  if ( dirspec[ldirspec - 1] != '/' )
2516  strcat( dirspec, "/" );
2517 #endif
2518 }
2519 
2520 //--------------------------------------------------------------------------
2521 // plcol_interp()
2522 //
2531 //--------------------------------------------------------------------------
2532 
2533 void
2534 plcol_interp( PLStream *pls, PLColor *newcolor, int i, int ncol )
2535 {
2536  PLFLT x, delta;
2537  int il, ir;
2538 
2539  x = (double) ( i * ( pls->ncol1 - 1 ) ) / (double) ( ncol - 1 );
2540  il = (int) x;
2541  ir = il + 1;
2542  delta = x - il;
2543 
2544  if ( ir > pls->ncol1 || il < 0 )
2545  fprintf( stderr, "Invalid color\n" );
2546 
2547  else if ( ir == pls->ncol1 || ( delta == 0. ) )
2548  {
2549  newcolor->r = pls->cmap1[il].r;
2550  newcolor->g = pls->cmap1[il].g;
2551  newcolor->b = pls->cmap1[il].b;
2552  newcolor->a = pls->cmap1[il].a;
2553  }
2554  else
2555  {
2556  newcolor->r = (unsigned char) ( ( 1. - delta ) * pls->cmap1[il].r + delta * pls->cmap1[ir].r );
2557  newcolor->g = (unsigned char) ( ( 1. - delta ) * pls->cmap1[il].g + delta * pls->cmap1[ir].g );
2558  newcolor->b = (unsigned char) ( ( 1. - delta ) * pls->cmap1[il].b + delta * pls->cmap1[ir].b );
2559  newcolor->a = ( 1. - delta ) * pls->cmap1[il].a + delta * pls->cmap1[ir].a;
2560  }
2561 }
2562 
2563 //--------------------------------------------------------------------------
2564 // plOpenFile()
2565 //
2571 //--------------------------------------------------------------------------
2572 
2573 #define MAX_NUM_TRIES 10
2574 void
2576 {
2577  int i = 0, count = 0;
2578  size_t len;
2579  char line[BUFFER_SIZE];
2580 
2581  while ( pls->OutFile == NULL )
2582  {
2583 // Setting pls->FileName = NULL forces creation of a new family member
2584 // You should also free the memory associated with it if you do this
2585 
2586  if ( pls->family && pls->BaseName != NULL )
2587  plP_getmember( pls );
2588 
2589 // Prompt if filename still not known
2590 
2591  if ( pls->FileName == NULL )
2592  {
2593  do
2594  {
2595  fprintf( stdout, "Enter graphics output file name: " );
2596  plio_fgets( line, sizeof ( line ), stdin );
2597  len = strlen( line );
2598  if ( len )
2599  len--;
2600  line[len] = '\0'; // strip new-line
2601  count++; // count zero entries
2602  } while ( !len && count < MAX_NUM_TRIES );
2603  plP_sfnam( pls, line );
2604  }
2605 
2606 // If name is "-", send to stdout
2607 
2608  if ( !strcmp( pls->FileName, "-" ) )
2609  {
2610  pls->OutFile = stdout;
2611  pls->output_type = 1;
2612  break;
2613  }
2614 
2615 // Need this here again, for prompted family initialization
2616 
2617  if ( pls->family && pls->BaseName != NULL )
2618  plP_getmember( pls );
2619 
2620  if ( i++ > 10 )
2621  plexit( "Too many tries." );
2622 
2623  if ( ( pls->OutFile = fopen( pls->FileName, "wb+" ) ) == NULL )
2624  fprintf( stderr, "Can't open %s.\n", pls->FileName );
2625  else
2626  pldebug( "plOpenFile", "Opened %s\n", pls->FileName );
2627  }
2628 }
2629 
2630 //--------------------------------------------------------------------------
2631 // plCloseFile()
2632 //
2636 //--------------------------------------------------------------------------
2637 
2638 void
2640 {
2641  if ( pls->OutFile != NULL )
2642  {
2643  // Don't close if the output file was stdout
2644  if ( pls->FileName && strcmp( pls->FileName, "-" ) == 0 )
2645  return;
2646 
2647  fclose( pls->OutFile );
2648  pls->OutFile = NULL;
2649  }
2650 }
2651 
2652 //--------------------------------------------------------------------------
2653 // plP_getmember()
2654 //
2658 //--------------------------------------------------------------------------
2659 
2660 void
2662 {
2663  char tmp[BUFFER_SIZE];
2664  char prefix[BUFFER_SIZE];
2665  char * suffix;
2666  char num[BUFFER_SIZE];
2667  size_t maxlen;
2668 
2669  maxlen = strlen( pls->BaseName ) + 10;
2670  if ( pls->FileName == NULL )
2671  {
2672  if ( ( pls->FileName = (char *) malloc( maxlen ) ) == NULL )
2673  {
2674  plexit( "plP_getmember: Insufficient memory" );
2675  }
2676  }
2677 
2678  suffix = strstr( pls->BaseName, "%n" );
2679 
2680  snprintf( tmp, BUFFER_SIZE, "%%0%1ii", (int) pls->fflen );
2681  snprintf( num, BUFFER_SIZE, tmp, pls->member );
2682 
2683  if ( suffix == NULL )
2684  snprintf( pls->FileName, maxlen, "%s.%s", pls->BaseName, num );
2685  else
2686  {
2687  strncpy( prefix, pls->BaseName, BUFFER_SIZE - 1 );
2688  prefix [( suffix - pls->BaseName < BUFFER_SIZE ) ? ( suffix - pls->BaseName ) : BUFFER_SIZE - 1] = '\0';
2689  snprintf( pls->FileName, maxlen, "%s%s%s", prefix, num, suffix + 2 );
2690  }
2691 }
2692 
2693 //--------------------------------------------------------------------------
2694 // plP_sfnam()
2695 //
2701 //--------------------------------------------------------------------------
2702 
2703 void
2705 {
2706  char prefix[BUFFER_SIZE];
2707  char * suffix;
2708  size_t maxlen;
2709  pls->OutFile = NULL;
2710 
2711  if ( pls->FileName != NULL )
2712  free( (void *) pls->FileName );
2713 
2714  maxlen = 10 + strlen( fnam );
2715  if ( ( pls->FileName = (char *) malloc( maxlen ) ) == NULL )
2716  {
2717  plexit( "plP_sfnam: Insufficient memory" );
2718  }
2719 
2720  suffix = strstr( fnam, "%n" );
2721 
2722  if ( suffix == NULL )
2723  {
2724  strncpy( pls->FileName, fnam, maxlen - 1 );
2725  pls->FileName[maxlen - 1] = '\0';
2726  }
2727  else
2728  {
2729  strncpy( prefix, fnam, BUFFER_SIZE - 1 );
2730  prefix [( suffix - fnam ) < BUFFER_SIZE ? ( suffix - fnam ) : BUFFER_SIZE - 1] = '\0';
2731  snprintf( pls->FileName, maxlen, "%s%s", prefix, suffix + 2 );
2732  }
2733 
2734  if ( pls->BaseName != NULL )
2735  free( (void *) pls->BaseName );
2736 
2737  if ( ( pls->BaseName = (char *) malloc( maxlen ) ) == NULL )
2738  {
2739  plexit( "plP_sfnam: Insufficient memory" );
2740  }
2741 
2742  strncpy( pls->BaseName, fnam, maxlen - 1 );
2743  pls->BaseName[maxlen - 1] = '\0';
2744 }
2745 
2746 //--------------------------------------------------------------------------
2747 // plFamInit()
2748 //
2752 //--------------------------------------------------------------------------
2753 
2754 void
2756 {
2757  if ( pls->family )
2758  {
2759  pls->bytecnt = 0;
2760  if ( !pls->member )
2761  pls->member = 1;
2762  if ( !pls->finc )
2763  pls->finc = 1;
2764  if ( !pls->fflen )
2765  pls->fflen = 1;
2766  if ( !pls->bytemax )
2767  pls->bytemax = PL_FILESIZE_KB * 1000;
2768  }
2769 }
2770 
2771 //--------------------------------------------------------------------------
2772 // plGetFam()
2773 //
2781 //--------------------------------------------------------------------------
2782 
2783 void
2785 {
2786  PLFLT xpmm_loc, ypmm_loc;
2787  if ( pls->family )
2788  {
2789  if ( pls->bytecnt > pls->bytemax || pls->famadv )
2790  {
2791  PLINT local_page_status = pls->page_status;
2792  plP_tidy();
2793  pls->member += pls->finc;
2794  pls->famadv = 0;
2795  plP_init();
2796  // Restore page status (normally AT_BOP) that was changed
2797  // to AT_EOP by plP_init.
2798  pls->page_status = local_page_status;
2799 
2800  // Apply compensating factor to original xpmm and ypmm so that
2801  // character aspect ratio is preserved when overall aspect ratio
2802  // is changed.
2803  plP_gpixmm( &xpmm_loc, &ypmm_loc );
2804  plP_setpxl( xpmm_loc * plsc->caspfactor, ypmm_loc / plsc->caspfactor );
2805  return;
2806  }
2807  }
2808 }
2809 
2810 //--------------------------------------------------------------------------
2811 // plRotPhy()
2812 //
2825 //--------------------------------------------------------------------------
2826 
2827 void
2828 plRotPhy( PLINT orient, PLINT xmin, PLINT ymin, PLINT xmax, PLINT ymax,
2829  PLINT *px, PLINT *py )
2830 {
2831  int x, y;
2832 
2833  x = *px;
2834  y = *py;
2835 
2836  switch ( orient % 4 )
2837  {
2838  case 1:
2839  *px = xmin + ( y - ymin );
2840  *py = ymin + ( xmax - x );
2841  break;
2842 
2843  case 2:
2844  *px = xmin + ( xmax - x );
2845  *py = ymin + ( ymax - y );
2846  break;
2847 
2848  case 3:
2849  *px = xmin + ( ymax - y );
2850  *py = ymin + ( x - xmin );
2851  break;
2852 
2853  default:
2854  break; // do nothing
2855  }
2856 }
2857 
2858 //--------------------------------------------------------------------------
2859 // plAllocDev()
2860 //
2867 //--------------------------------------------------------------------------
2868 
2869 PLDev *
2871 {
2872  if ( pls->dev != NULL )
2873  free( (void *) pls->dev );
2874 
2875  pls->dev = calloc( 1, (size_t) sizeof ( PLDev ) );
2876  if ( pls->dev == NULL )
2877  plexit( "plAllocDev: cannot allocate memory\n" );
2878 
2879  return (PLDev *) pls->dev;
2880 }
2881 
2882 //--------------------------------------------------------------------------
2883 // plGinInit()
2884 //
2888 //--------------------------------------------------------------------------
2889 
2890 void
2892 {
2893  gin->type = 0;
2894  gin->state = 0;
2895  gin->keysym = 0;
2896  gin->button = 0;
2897  gin->string[0] = '\0';
2898  gin->pX = gin->pY = -1;
2899  gin->dX = gin->dY = 0.;
2900  gin->wX = gin->wY = 0.;
2901 }
2902 
2903 //--------------------------------------------------------------------------
2904 // plGetInt()
2905 //
2911 //--------------------------------------------------------------------------
2912 
2913 PLINT
2915 {
2916  int m;
2917  int i = 0;
2918  char line[BUFFER_SIZE];
2919 
2920  while ( i++ < 10 )
2921  {
2922  fputs( s, stdout );
2923  plio_fgets( line, sizeof ( line ), stdin );
2924 
2925 #ifdef MSDOS
2926  m = atoi( line );
2927  return ( m );
2928 #else
2929  if ( sscanf( line, "%d", &m ) == 1 )
2930  return ( m );
2931  fprintf( stdout, "No value or value out of range; please try again\n" );
2932 #endif
2933  }
2934  plexit( "Too many tries." );
2935  return ( 0 );
2936 }
2937 
2938 //--------------------------------------------------------------------------
2939 // plGetFlt()
2940 //
2946 //--------------------------------------------------------------------------
2947 
2948 PLFLT
2950 {
2951  PLFLT m;
2952  double m1;
2953  int i = 0;
2954  char line[BUFFER_SIZE];
2955 
2956  while ( i++ < 10 )
2957  {
2958  fputs( s, stdout );
2959  plio_fgets( line, sizeof ( line ), stdin );
2960 
2961 #ifdef MSDOS
2962  m = atof( line );
2963  return ( m );
2964 #else
2965  if ( sscanf( line, "%lf", &m1 ) == 1 )
2966  {
2967  m = (PLFLT) m1;
2968  return ( m );
2969  }
2970  fprintf( stdout, "No value or value out of range; please try again\n" );
2971 #endif
2972  }
2973  plexit( "Too many tries." );
2974  return ( 0. );
2975 }
2976 
2977 //--------------------------------------------------------------------------
2978 // plstrdup()
2979 //
2986 //--------------------------------------------------------------------------
2987 
2988 char PLDLLIMPEXP *
2990 {
2991  char *dest = (char *) malloc( ( strlen( src ) + 1 ) * sizeof ( char ) );
2992  if ( dest != NULL )
2993  strcpy( dest, src );
2994  else
2995  plabort( "Out of memory" );
2996 
2997  return dest;
2998 }
2999 
3000 #ifndef PL_HAVE_SNPRINTF
3001 //--------------------------------------------------------------------------
3002 // plsnprintf()
3003 //
3014 //--------------------------------------------------------------------------
3015 
3016 int
3017 plsnprintf( char *buffer, int n, PLCHAR_VECTOR format, ... )
3018 {
3019  int ret;
3020 
3021  va_list args;
3022  va_start( args, format );
3023  ret = vsprintf( buffer, format, args );
3024  va_end( args );
3025 
3026  // Check if overrun occured
3027  if ( ret > n - 1 )
3028  plabort( "plsnprintf: buffer overrun" );
3029 
3030  return ret;
3031 }
3032 
3033 //--------------------------------------------------------------------------
3034 // plsnscanf()
3035 //
3046 //--------------------------------------------------------------------------
3047 
3048 int
3050 {
3051  int ret;
3052 
3053  va_list args;
3054  va_start( args, format );
3055  ret = vsscanf( buffer, format, args );
3056  va_end( args );
3057 
3058  return ret;
3059 }
3060 
3061 #endif // PL_HAVE_SNPRINTF
3062 
3063 //--------------------------------------------------------------------------
3064 // plseed()
3065 //
3069 //--------------------------------------------------------------------------
3070 
3071 void
3072 c_plseed( unsigned int seed )
3073 {
3074  init_genrand( seed );
3075 }
3076 
3077 //--------------------------------------------------------------------------
3078 // plrandd()
3079 //
3082 //--------------------------------------------------------------------------
3083 
3084 PLFLT
3085 c_plrandd( void )
3086 {
3087  return (PLFLT) ( genrand_real1() );
3088 }
3089 
3090 //--------------------------------------------------------------------------
3091 // plsave_set_locale()
3092 //
3102 //--------------------------------------------------------------------------
3103 
3104 char *
3106 {
3107  char * setlocale_ptr;
3108  char * saved_lc_numeric_locale;
3109 
3110  if ( !( saved_lc_numeric_locale = (char *) malloc( 100 * sizeof ( char ) ) ) )
3111  {
3112  plexit( "plsave_set_locale: out of memory" );
3113  }
3114 
3115  //save original LC_NUMERIC locale for restore below.
3116  if ( !( setlocale_ptr = setlocale( LC_NUMERIC, NULL ) ) )
3117  {
3118  plexit( "plsave_set_locale: LC_NUMERIC locale could not be determined for NULL locale.\n" );
3119  }
3120  strncpy( saved_lc_numeric_locale, setlocale_ptr, 100 );
3121  saved_lc_numeric_locale[99] = '\0';
3122 
3123  // Do not use pldebug since get overflowed stack (infinite recursion)
3124  // if device is interactive (i.e., pls->termin is set).
3125  // comment out fprintf (unless there is some emergency debugging to do)
3126  // because output is too voluminous.
3127  //
3128  // fprintf(stderr, "plsave_set_locale: saved LC_NUMERIC locale is \"%s\"\n", saved_lc_numeric_locale);
3129  //
3130 
3131  if ( !( setlocale( LC_NUMERIC, "C" ) ) )
3132  {
3133  plexit( "plsave_set_locale: LC_NUMERIC locale could not be set to \"C\"" );
3134  }
3135  return saved_lc_numeric_locale;
3136 }
3137 
3138 //--------------------------------------------------------------------------
3139 // plrestore_locale()
3140 //
3146 //--------------------------------------------------------------------------
3147 
3148 void
3149 plrestore_locale( char *saved_lc_numeric_locale )
3150 {
3151  // Do not use pldebug since get overflowed stack (infinite recursion)
3152  // if device is interactive (i.e., pls->termin is set).
3153  // comment out fprintf (unless there is some emergency debugging to do)
3154  // because output is too voluminous.
3155  //
3156  // fprintf(stderr, "plrestore_locale: restored LC_NUMERIC locale is \"%s\"\n", saved_lc_numeric_locale);
3157  //
3158 
3159  if ( !( setlocale( LC_NUMERIC, saved_lc_numeric_locale ) ) )
3160  {
3161  char msgbuf[1024];
3162  snprintf( msgbuf, 1024, "plrestore_locale: LC_NUMERIC could not be restored to the default \"%s\" locale.\n", saved_lc_numeric_locale );
3163  plexit( msgbuf );
3164  }
3165  free( saved_lc_numeric_locale );
3166 }
3167 
#define PLSTATE_CMAP0
Definition: plplotP.h:366
static void color_set(PLINT i, U_CHAR r, U_CHAR g, U_CHAR b, PLFLT a, PLCHAR_VECTOR name)
Definition: plctrl.c:1008
static const char * name
Definition: tkMain.c:135
integer(kind=private_plint), parameter, private maxlen
Definition: plplot.f90:48
void c_plscolbga(PLINT r, PLINT g, PLINT b, PLFLT alpha)
Definition: plctrl.c:234
static int(* exit_handler)(PLCHAR_VECTOR errormsg)
Definition: plctrl.c:83
#define PLESC_XORMOD
Definition: plplot.h:290
PLINT plGetInt(PLCHAR_VECTOR s)
Definition: plctrl.c:2914
void plexit(PLCHAR_VECTOR errormsg)
Definition: plctrl.c:1962
void plGetName(PLCHAR_VECTOR dir, PLCHAR_VECTOR subdir, PLCHAR_VECTOR filename, char **filespec)
Definition: plctrl.c:2457
void plP_esc(PLINT op, void *ptr)
Definition: plcore.c:263
#define PL_DEFAULT_CMAP1_FILE
Definition: plplot_config.h:36
void init_genrand(unsigned long s)
Definition: mt19937ar.c:68
PLINT plFindName(char *p)
Definition: plctrl.c:2436
#define PL_FILESIZE_KB
Definition: plplotP.h:386
unsigned char b
Definition: plplot.h:539
void c_plscmap1_range(PLFLT min_color, PLFLT max_color)
Definition: plctrl.c:899
PLFLT dX
Definition: plplot.h:446
FILE * OutFile
Definition: plstrm.h:575
Definition: pdf.h:49
void plOpenFile(PLStream *pls)
Definition: plctrl.c:2575
#define FUZZ_EPSILON
Definition: plctrl.c:69
void plCloseFile(PLStream *pls)
Definition: plctrl.c:2639
void plGetFam(PLStream *pls)
Definition: plctrl.c:2784
void c_plscmap1l(PLINT itype, PLINT npts, PLFLT_VECTOR intensity, PLFLT_VECTOR coord1, PLFLT_VECTOR coord2, PLFLT_VECTOR coord3, PLINT_VECTOR alt_hue_path)
Definition: plctrl.c:641
void plP_getmember(PLStream *pls)
Definition: plctrl.c:2661
void plGinInit(PLGraphicsIn *gin)
Definition: plctrl.c:2891
#define SOURCE_DIR
PDFstrm * pdf_fopen(PLCHAR_VECTOR filename, PLCHAR_VECTOR mode)
Definition: pdfutils.c:74
const char * PLCHAR_VECTOR
Definition: plplot.h:247
void c_plcol0(PLINT icol0)
Definition: plctrl.c:141
void plcol_interp(PLStream *pls, PLColor *newcolor, int i, int ncol)
Definition: plctrl.c:2534
#define isnan(x)
Definition: plplotP.h:262
static char * read_line(char *buffer, int length, FILE *fp)
Definition: plctrl.c:1356
void plcmap1_calc(void)
Bin up cmap 1 space and assign colors to make inverse mapping easy.
Definition: plctrl.c:773
void c_plgra(void)
Definition: plctrl.c:2007
void c_plscmap1n(PLINT ncol1)
Definition: plctrl.c:1071
#define PLESC_TEXT
Definition: plplot.h:281
void c_plgcolbg(PLINT *r, PLINT *g, PLINT *b)
Definition: plctrl.c:249
#define MAX(a, b)
Definition: dsplint.c:28
void plP_tidy(void)
Definition: plcore.c:221
char * plsave_set_locale(void)
Definition: plctrl.c:3105
PLFLT a
Definition: plplot.h:540
#define PL_MAX_CMAP1CP
Definition: plstrm.h:521
#define plscmap1n
Definition: plplot.h:787
#define PLSTATE_COLOR0
Definition: plplotP.h:363
PLINT page_status
Definition: plstrm.h:665
void plabort(PLCHAR_VECTOR errormsg)
Definition: plctrl.c:1898
#define PLSTATE_COLOR1
Definition: plplotP.h:364
void plP_gpixmm(PLFLT *p_x, PLFLT *p_y)
Definition: plcore.c:4203
#define color_def(i, r, g, b, a, n)
Definition: plctrl.c:1017
#define PLPLOT_MAX_PATH
Definition: plplotP.h:446
void c_plscmap1a(PLINT_VECTOR r, PLINT_VECTOR g, PLINT_VECTOR b, PLFLT_VECTOR alpha, PLINT ncol1)
Definition: plctrl.c:559
void c_plspal0(PLCHAR_VECTOR filename)
Definition: plctrl.c:1562
void plsabort(void(*handler)(PLCHAR_VECTOR))
Definition: plctrl.c:1942
#define BUILD_DIR
Definition: plplot_config.h:24
PLColor * cmap1
Definition: plstrm.h:545
#define plend
Definition: plplot.h:698
void c_plxormod(PLINT mode, PLINT *status)
Definition: plctrl.c:2022
void c_plseed(unsigned int seed)
Definition: plctrl.c:3072
void c_plgcol0a(PLINT icol0, PLINT *r, PLINT *g, PLINT *b, PLFLT *alpha)
Definition: plctrl.c:396
void plFamInit(PLStream *pls)
Definition: plctrl.c:2755
PLDev * plAllocDev(PLStream *pls)
Definition: plctrl.c:2870
static int color
Definition: ps.c:78
int PLINT
Definition: plplot.h:176
#define MIN(a, b)
Definition: dsplint.c:29
PLINT PLBOOL
Definition: plplot.h:199
void c_plscmap0n(PLINT ncol0)
Definition: plctrl.c:946
void plrestore_locale(char *saved_lc_numeric_locale)
Definition: plctrl.c:3149
void c_plspal1(PLCHAR_VECTOR filename, PLBOOL interpolate)
Definition: plctrl.c:1618
unsigned char g
Definition: plplot.h:538
Definition: plsdef.c:27
PLINT bytemax
Definition: plstrm.h:570
#define PL_DEFAULT_CMAP0_FILE
Definition: plplot_config.h:33
void plP_sfnam(PLStream *pls, PLCHAR_VECTOR fnam)
Definition: plctrl.c:2704
void plio_fgets(char *buf, int size, FILE *stream)
Definition: plstdio.c:142
#define snprintf
Definition: plplotP.h:235
#define PLSTATE_CMAP1
Definition: plplotP.h:367
PLFLT c_plrandd(void)
Definition: plctrl.c:3085
char * BaseName
Definition: plstrm.h:576
void c_plhlsrgb(PLFLT h, PLFLT l, PLFLT s, PLFLT *p_r, PLFLT *p_g, PLFLT *p_b)
Definition: plctrl.c:1265
void c_plscmap1(PLINT_VECTOR r, PLINT_VECTOR g, PLINT_VECTOR b, PLINT ncol1)
Definition: plctrl.c:518
#define PLESC_MODESET
Definition: plplot.h:310
int type
Definition: plplot.h:439
#define TRUE
Definition: plplotP.h:176
#define PLESC_GRAPH
Definition: plplot.h:282
static void cmap0_palette_read(PLCHAR_VECTOR filename, int *number_colors, unsigned int **r, unsigned int **g, unsigned int **b, double **a)
Definition: plctrl.c:1413
char * FileName
Definition: plstrm.h:576
Definition: plstrm.h:40
void c_plcol1(PLFLT col1)
Definition: plctrl.c:175
#define FALSE
Definition: plplotP.h:177
static void strcat_delim(char *dirspec)
Definition: plctrl.c:2505
int plsnprintf(char *buffer, int n, PLCHAR_VECTOR format,...)
Definition: plctrl.c:3017
PLINT fflen
Definition: plstrm.h:570
char * plFindCommand(PLCHAR_VECTOR fn)
Definition: plctrl.c:2150
#define COLLEN
Definition: plctrl.c:63
#define MAX_NUM_TRIES
Definition: plctrl.c:2573
void c_plrgbhls(PLFLT r, PLFLT g, PLFLT b, PLFLT *p_h, PLFLT *p_l, PLFLT *p_s)
Definition: plctrl.c:1298
int plInBuildTree()
Definition: plcore.c:2862
static PLINT * buffer
Definition: plfill.c:74
void c_plscolbg(PLINT r, PLINT g, PLINT b)
Definition: plctrl.c:215
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
Definition: plcore.c:4212
#define PLLIBDEV
Definition: plctrl.c:123
void pl_cmd(PLINT op, void *ptr)
Definition: plctrl.c:2122
#define pltext
Definition: plplot.h:844
const PLINT * PLINT_VECTOR
Definition: plplot.h:245
#define plscol0a
Definition: plplot.h:790
void plsexit(int(*handler)(PLCHAR_VECTOR))
Definition: plctrl.c:1991
void c_plscmap0a(PLINT_VECTOR r, PLINT_VECTOR g, PLINT_VECTOR b, PLFLT_VECTOR alpha, PLINT ncol0)
Definition: plctrl.c:476
unsigned int keysym
Definition: plplot.h:441
#define BIN_DIR
Definition: plplot_config.h:21
static char buf[200]
Definition: tclAPI.c:873
PLINT famadv
Definition: plstrm.h:570
static PLStream * pls[PL_NSTREAMS]
Definition: plcore.h:88
void c_plscol0a(PLINT icol0, PLINT r, PLINT g, PLINT b, PLFLT alpha)
Definition: plctrl.c:318
#define PLESC_MODEGET
Definition: plplot.h:311
void c_plgcolbga(PLINT *r, PLINT *g, PLINT *b, PLFLT *alpha)
Definition: plctrl.c:265
PLINT family
Definition: plstrm.h:570
#define PLPLOT_HOME_ENV
Definition: plplotP.h:443
int plsnscanf(PLCHAR_VECTOR buffer, int n, PLCHAR_VECTOR format,...)
Definition: plctrl.c:3049
PLINT member
Definition: plstrm.h:570
void c_plscolor(PLINT color)
Definition: plctrl.c:1206
FILE * file
Definition: pdf.h:51
static PLFLT value(double n1, double n2, double hue)
Definition: plctrl.c:1223
PLFLT wX
Definition: plplot.h:447
char PLDLLIMPEXP * plstrdup(PLCHAR_VECTOR src)
Definition: plctrl.c:2989
void plP_state(PLINT op)
Definition: plcore.c:246
#define BUFFER_SIZE
Definition: plctrl.c:62
PLINT c_plgdrawmode(void)
Definition: plctrl.c:2075
#define fuzzy_range_check(value, min, max, fuzz, err_number)
Definition: plctrl.c:1596
float PLFLT
Definition: plplot.h:158
#define plscol0
Definition: plplot.h:789
int pdf_close(PDFstrm *pdfs)
Definition: pdfutils.c:238
#define MSGLEN
Definition: plctrl.c:65
#define plgcol0a
Definition: plplot.h:714
#define free_mem(a)
Definition: plplotP.h:182
void c_plgcmap1_range(PLFLT *min_color, PLFLT *max_color)
Definition: plctrl.c:928
#define PLPLOT_BIN_ENV
Definition: plplotP.h:440
FILE * plLibOpen(PLCHAR_VECTOR fn)
Definition: plctrl.c:2233
void plRotPhy(PLINT orient, PLINT xmin, PLINT ymin, PLINT xmax, PLINT ymax, PLINT *px, PLINT *py)
Definition: plctrl.c:2828
void c_pltext(void)
Switches to text screen.
Definition: plctrl.c:2104
static void plcmap0_def(int imin, int imax)
Definition: plctrl.c:1030
void c_plscmap0(PLINT_VECTOR r, PLINT_VECTOR g, PLINT_VECTOR b, PLINT ncol0)
Definition: plctrl.c:434
unsigned int state
Definition: plplot.h:440
unsigned char r
Definition: plplot.h:537
#define PLPLOT_LIB_ENV
Definition: plplotP.h:441
void plwarn(PLCHAR_VECTOR errormsg)
Definition: plctrl.c:1867
int access(char *filename, int flag)
Definition: plfreetype.c:70
#define plscmap0n
Definition: plplot.h:782
void plP_init(void)
Definition: plcore.c:135
#define plgcol0
Definition: plplot.h:713
PLFLT plGetFlt(PLCHAR_VECTOR s)
Definition: plctrl.c:2949
void c_plscol0(PLINT icol0, PLINT r, PLINT g, PLINT b)
Definition: plctrl.c:282
unsigned int button
Definition: plplot.h:442
void c_plsdrawmode(PLINT mode)
Definition: plctrl.c:2052
#define PLDLLIMPEXP
Definition: pldll.h:49
PLFLT dY
Definition: plplot.h:446
#define PALLEN
Definition: plctrl.c:64
static void(* abort_handler)(PLCHAR_VECTOR errormsg)
Definition: plctrl.c:86
void c_plgcol0(PLINT icol0, PLINT *r, PLINT *g, PLINT *b)
Definition: plctrl.c:359
#define DATA_DIR
Definition: plplot_config.h:27
PLINT ncol1
Definition: plstrm.h:539
const PLFLT * PLFLT_VECTOR
Definition: plplot.h:248
static void plcmap1_def(void)
Definition: plctrl.c:1132
char PLDLLIMPEXP * plplotLibDir
Definition: plctrl.c:74
PDFstrm * plLibOpenPdfstrm(PLCHAR_VECTOR fn)
Definition: plctrl.c:2267
PLFLT wY
Definition: plplot.h:447
PLINT finc
Definition: plstrm.h:570
void * dev
Definition: plstrm.h:594
char string[PL_MAXKEY]
Definition: plplot.h:444
PLINT bytecnt
Definition: plstrm.h:578
#define plgra
Definition: plplot.h:729
int output_type
Definition: plstrm.h:577
#define U_CHAR
Definition: pdf.h:26
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)
Definition: plctrl.c:712
double genrand_real1(void)
Definition: mt19937ar.c:181