58 if ( !strcmp( option,
"debug" ) )
87 #ifdef PLPLOT_USE_TCL_CHANNELS
96 for ( m = mode, p = new_mode; *m != 0; m++ )
110 pdfs->tclChan = Tcl_OpenFileChannel( NULL, filename, new_mode, 0 );
111 if ( pdfs->tclChan == NULL )
120 Tcl_SetChannelOption( NULL, pdfs->tclChan,
"-translation",
126 pdfs->
file = fopen( filename, mode );
127 if ( pdfs->
file == NULL )
163 #ifdef PLPLOT_USE_TCL_CHANNELS
164 pdfs->tclChan = NULL;
168 if ( buffer == NULL )
176 if ( pdfs->
buffer == NULL )
216 #ifdef PLPLOT_USE_TCL_CHANNELS
217 pdfs->tclChan = NULL;
244 if ( pdfs->
file != NULL )
246 fclose( pdfs->
file );
247 #ifdef PLPLOT_USE_TCL_CHANNELS
249 else if ( pdfs->tclChan != NULL )
251 Tcl_Close( NULL, pdfs->tclChan );
254 else if ( pdfs->
buffer != NULL )
256 free( (
void *) pdfs->
buffer );
258 free( (
void *) pdfs );
280 if ( pdfs->
file != NULL )
282 result = putc( c, pdfs->
file );
284 #ifdef PLPLOT_USE_TCL_CHANNELS
286 else if ( pdfs->tclChan != NULL )
288 result = Tcl_WriteChars( pdfs->tclChan, &c, 1 );
292 else if ( pdfs->
buffer != NULL )
297 "Increasing buffer to %d bytes\n", pdfs->
bufmax );
301 plexit(
"pdf_putc: Insufficient memory" );
304 pdfs->
buffer[pdfs->
bp++] = (
unsigned char) c;
308 plexit(
"pdf_putc: Illegal operation" );
329 if ( pdfs->
file != NULL )
331 result = getc( pdfs->
file );
333 #ifdef PLPLOT_USE_TCL_CHANNELS
335 else if ( pdfs->tclChan != NULL )
337 result = Tcl_Read( pdfs->tclChan, &result, 1 );
341 else if ( pdfs->
buffer != NULL )
347 plexit(
"pdf_getc: Illegal operation" );
369 if ( pdfs->
file != NULL )
371 result = ungetc( c, pdfs->
file );
374 #ifdef PLPLOT_USE_TCL_CHANNELS
376 else if ( pdfs->tclChan != NULL )
378 result = Tcl_Ungets( pdfs->tclChan, &c, 1, 0 );
383 else if ( pdfs->
buffer != NULL )
387 pdfs->
buffer[--pdfs->
bp] = (
unsigned char) c;
392 plexit(
"pdf_ungetc: Illegal operation" );
415 if ( pdfs->
file != NULL )
417 result = (int) fwrite( x, 1, (
size_t) nitems, pdfs->
file );
418 pdfs->
bp += (size_t) nitems;
419 #ifdef PLPLOT_USE_TCL_CHANNELS
421 else if ( pdfs->tclChan != NULL )
423 result = Tcl_Write( pdfs->tclChan, x, nitems );
427 else if ( pdfs->
buffer != NULL )
429 for ( i = 0; i < nitems; i++ )
434 "Increasing buffer to %d bytes\n", pdfs->
bufmax );
437 realloc( (
void *) ( pdfs->
buffer ), pdfs->
bufmax ) ) == NULL )
439 plexit(
"pdf_wrx: Insufficient memory" );
468 if ( pdfs->
file != NULL )
470 result = (int) fread( x, 1, (
size_t) nitems, pdfs->
file );
471 pdfs->
bp += (size_t) nitems;
472 #ifdef PLPLOT_USE_TCL_CHANNELS
474 else if ( pdfs->tclChan != NULL )
476 result = Tcl_ReadRaw( pdfs->tclChan, x, nitems );
480 else if ( pdfs->
buffer != NULL )
482 for ( i = 0; i < nitems; i++ )
515 for ( i = 0; i < 79; i++ )
517 if ( header[i] ==
'\0' )
519 if (
pdf_putc( header[i], pdfs ) == EOF )
522 if (
pdf_putc(
'\n', pdfs ) == EOF )
548 for ( i = 0; i < 79; i++ )
550 if ( ( c =
pdf_getc( pdfs ) ) == EOF )
553 header[i] = (char) c;
554 if ( header[i] ==
'\n' )
580 for ( i = 0; i <= (int) strlen(
string ); i++ )
582 if (
pdf_putc(
string[i], pdfs ) == EOF )
610 for ( i = 0; i < nmax; i++ )
612 if ( ( c =
pdf_getc( pdfs ) ) == EOF )
615 string[i] = (char) c;
641 if (
pdf_wrx( x, 1, pdfs ) != 1 )
691 if (
pdf_wrx( x, 2, pdfs ) != 2 )
746 for ( i = 0; i < n; i++ )
751 if (
pdf_wrx( x, 2, pdfs ) != 2 )
777 for ( i = 0; i < n; i++ )
813 if (
pdf_wrx( x, 4, pdfs ) != 4 )
841 *ps |= (
U_LONG) x[1] << 8;
842 *ps |= (
U_LONG) x[2] << 16;
843 *ps |= (
U_LONG) x[3] << 24;
918 double fdbl, fmant, f_new;
920 int istat, ex, e_new, e_off;
921 const int bias = 127;
931 fmant = frexp( fdbl, &ex );
938 fmant = fabs( fmant );
942 if ( e_new < 1 - bias )
944 e_off = e_new - ( 1 - bias );
946 f_tmp = (float) ( f_new * pow( (
double) 2.0, (double) e_off ) );
950 e_ieee = (
U_LONG) ( e_new + bias );
951 f_tmp = (float) ( f_new - 1 );
953 f_ieee = (
U_LONG) ( f_tmp * 8388608 );
958 fprintf( stderr,
"pdf_wr_ieeef: Warning -- overflow\n" );
962 s_ieee = s_ieee << 31;
963 e_ieee = e_ieee << 23;
965 value = s_ieee | e_ieee | f_ieee;
972 fprintf( stderr,
"Float value (written): %g\n", fsgl );
996 int istat, ex, bias = 127;
1002 s_ieee = ( value & (
U_LONG) 0x80000000 ) >> 31;
1003 e_ieee = ( value & (
U_LONG) 0x7F800000 ) >> 23;
1004 f_ieee = ( value & (
U_LONG) 0x007FFFFF );
1006 f_tmp = (double) f_ieee / 8388608.0;
1015 ex = (int) e_ieee - bias;
1016 f_new = 1.0 + f_tmp;
1019 fsgl = (float) ( f_new * pow( 2.0, (
double) ex ) );
1027 fprintf( stderr,
"Float value (read): %g\n", fsgl );
1057 for ( i = 0; i < 32; i++ )
1060 bitrep[32 - i - 1] =
'1';
1062 bitrep[32 - i - 1] =
'0';
1065 fprintf( stderr,
"Binary representation: " );
1066 fprintf( stderr,
"%s\n", bitrep );
1069 for ( i = 0; i < 32; i++ )
1072 bitrep[32 - i - 1] =
'1';
1074 bitrep[32 - i - 1] =
'0';
1077 fprintf( stderr,
"Converted representation: " );
1078 fprintf( stderr,
"%s\n\n", bitrep );
PDFstrm * pdf_finit(FILE *file)
int pdf_rdx(U_CHAR *x, long nitems, PDFstrm *pdfs)
int pdf_wr_4bytes(PDFstrm *pdfs, U_LONG s)
void plexit(PLCHAR_VECTOR errormsg)
PDFstrm * pdf_bopen(U_CHAR *buffer, size_t bufmax)
static void print_ieeef(float *, U_LONG *)
int pdf_wr_header(PDFstrm *pdfs, PLCHAR_VECTOR header)
int pdf_wr_string(PDFstrm *pdfs, PLCHAR_VECTOR string)
int pdf_wr_2bytes(PDFstrm *pdfs, U_SHORT s)
int pdf_wr_2nbytes(PDFstrm *pdfs, U_SHORT *s, PLINT n)
PDFstrm * pdf_fopen(PLCHAR_VECTOR filename, PLCHAR_VECTOR mode)
const char * PLCHAR_VECTOR
int pdf_rd_2bytes(PDFstrm *pdfs, U_SHORT *ps)
int pdf_getc(PDFstrm *pdfs)
int pdf_rd_ieeef(PDFstrm *pdfs, float *pf)
static int pdf_wrx(const U_CHAR *x, long nitems, PDFstrm *pdfs)
int pdf_ungetc(int c, PDFstrm *pdfs)
int pdf_putc(int c, PDFstrm *pdfs)
int pdf_rd_1byte(PDFstrm *pdfs, U_CHAR *ps)
int pdf_wr_ieeef(PDFstrm *pdfs, float f)
static PLFLT value(double n1, double n2, double hue)
int pdf_close(PDFstrm *pdfs)
int pdf_rd_string(PDFstrm *pdfs, char *string, int nmax)
int pdf_rd_header(PDFstrm *pdfs, char *header)
int pdf_rd_2nbytes(PDFstrm *pdfs, U_SHORT *s, PLINT n)
int pdf_rd_4bytes(PDFstrm *pdfs, U_LONG *ps)
int pdf_wr_1byte(PDFstrm *pdfs, U_CHAR s)
void pdf_set(char *option, int value)