PLplot: pdfutils.c File Reference

PLplot 5.10.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions | Variables
pdfutils.c File Reference
`#include "plplotP.h"`

Go to the source code of this file.

## Macros
#define | NEED_PLDEBUG

## Functions
static void | print_ieeef (float *, U_LONG *)
static int | pdf_wrx (const U_CHAR *x, long nitems, PDFstrm *pdfs)
void | pdf_set (char *option, int value)
PDFstrm * | pdf_fopen (const char *filename, const char *mode)
PDFstrm * | pdf_bopen (U_CHAR *buffer, size_t bufmax)
PDFstrm * | pdf_finit (FILE *file)
int | pdf_close (PDFstrm *pdfs)
int | pdf_putc (int c, PDFstrm *pdfs)
int | pdf_getc (PDFstrm *pdfs)
int | pdf_ungetc (int c, PDFstrm *pdfs)
int | pdf_rdx (U_CHAR *x, long nitems, PDFstrm *pdfs)
int | pdf_wr_header (PDFstrm *pdfs, const char *header)
int | pdf_rd_header (PDFstrm *pdfs, char *header)
int | pdf_wr_string (PDFstrm *pdfs, const char *string)
int | pdf_rd_string (PDFstrm *pdfs, char *string, int nmax)
int | pdf_wr_1byte (PDFstrm *pdfs, U_CHAR s)
int | pdf_rd_1byte (PDFstrm *pdfs, U_CHAR *ps)
int | pdf_wr_2bytes (PDFstrm *pdfs, U_SHORT s)
int | pdf_rd_2bytes (PDFstrm *pdfs, U_SHORT *ps)
int | pdf_wr_2nbytes (PDFstrm *pdfs, U_SHORT *s, PLINT n)
int | pdf_rd_2nbytes (PDFstrm *pdfs, U_SHORT *s, PLINT n)
int | pdf_wr_4bytes (PDFstrm *pdfs, U_LONG s)
int | pdf_rd_4bytes (PDFstrm *pdfs, U_LONG *ps)
int | pdf_wr_ieeef (PDFstrm *pdfs, float f)
int | pdf_rd_ieeef (PDFstrm *pdfs, float *pf)
void | plAlloc2dGrid (PLFLT ***f, PLINT nx, PLINT ny)
void | plFree2dGrid (PLFLT **f, PLINT nx, PLINT PL_UNUSED(ny))
void | plMinMax2dGrid (const PLFLT *const *f, PLINT nx, PLINT ny, PLFLT *fnmax, PLFLT *fnmin)

## Variables
static int | debug = 0

## Detailed Description

These functions do the low-level reading/writing of portable data files. Data can be written to/read from either a file handle or memory buffer.

Definition in file pdfutils.c.

## Macro Definition Documentation

#define NEED_PLDEBUG

Definition at line 37 of file pdfutils.c.

## Function Documentation

PDFstrm* pdf_bopen | ( | U_CHAR * | buffer,
|  | size_t | bufmax
| ) |  |

Initializes a PDFstrm for reading/writing to a memory buffer. If buffer is NULL, a standard buffer is allocated.

Parameters

  buffer | User allocated memory, can be NULL.
  bufmax | Size of buffer, or the desired buffer.

Returns
  A PDFstrm structure.

Definition at line 152 of file pdfutils.c.

int pdf_close | ( | PDFstrm * | pdfs | ) |

Closes a PDFstrm. Used exactly like fclose().

Parameters

  pdfs | The file stream to close.

Returns
  0

Definition at line 238 of file pdfutils.c.

PDFstrm* pdf_finit | ( | FILE * | file | ) |

Initializes a PDFstrm for a file oriented device. Like pdf_fopen() but an existing file handle is specified.

Parameters

  file | A open file handle.

Returns
  A PDFstrm structure.

Definition at line 204 of file pdfutils.c.

PDFstrm* pdf_fopen | ( | const char * | filename,
|  | const char * | mode
| ) |  |

Initializes a PDFstrm for a file oriented device. Used exactly like fopen().

Parameters

  filename | The filename of the file to open.
  mode | File access mode, as would be used by fopen.

Definition at line 74 of file pdfutils.c.

int pdf_getc | ( | PDFstrm * | pdfs | ) |

Reads a single character.

Parameters

  pdfs | The stream to read the character from.

Returns
  The character read or EOF.

Definition at line 325 of file pdfutils.c.

int pdf_putc | ( | int | c,
|  | PDFstrm * | pdfs
| ) |  |

Writes a single character.

Parameters

  c | The character to write.
  pdfs | The stream to write it to.

Returns
  The character written or EOF.

Definition at line 276 of file pdfutils.c.

int pdf_rd_1byte | ( | PDFstrm * | pdfs,
|  | U_CHAR * | ps
| ) |  |

Reads a single byte, storing into a U_CHAR.

Parameters

  pdfs | The stream to read the byte from.
  ps | Storage for the byte.

Returns
  0 if successful.

Definition at line 660 of file pdfutils.c.

int pdf_rd_2bytes | ( | PDFstrm * | pdfs,
|  | U_SHORT * | ps
| ) |  |

Reads a U_SHORT from two single bytes, low end first.

Parameters

  pdfs | The stream to read the two bytes from.
  ps | Pre-allocated storage for the two bytes.

Returns
  0 if successful.

Definition at line 710 of file pdfutils.c.

int pdf_rd_2nbytes | ( | PDFstrm * | pdfs,
|  | U_SHORT * | s,
|  | PLINT | n
| ) |  |

Reads n U_SHORT's from 2n single bytes, low end first.

Parameters

  pdfs | The stream to read the shorts from.
  s | Pre-allocated storage for the shorts.
  n | Size of s.

Returns
  0 if successful.

Definition at line 771 of file pdfutils.c.

int pdf_rd_4bytes | ( | PDFstrm * | pdfs,
|  | U_LONG * | ps
| ) |  |

Reads an unsigned long from 4 single bytes, low end first.

Parameters

  pdfs | The stream to read the unsigned long from.
  ps | Pre-allocated storage for the unsigned long.

Returns
  0 is successful.

Definition at line 832 of file pdfutils.c.

int pdf_rd_header | ( | PDFstrm * | pdfs,
|  | char * | header
| ) |  |

Reads a newline-terminated header string from PDFstrm *pdfs, and converts to a usual NULL-terminated string. 80 chars maximum assumed.

Parameters

  pdfs | The stream to read the header from.
  header | Pre-allocated storage for the header.

Returns
  0 if successful.

Definition at line 542 of file pdfutils.c.

int pdf_rd_ieeef | ( | PDFstrm * | pdfs,
|  | float * | pf
| ) |  |

Reads a float from a IEEE single precision (32 bit) format.

Parameters

  pdfs | The stream to read the float from.
  pf | Pre-allocated storage for the float.

Returns
  0 if successful.

Definition at line 992 of file pdfutils.c.

int pdf_rd_string | ( | PDFstrm * | pdfs,
|  | char * | string,
|  | int | nmax
| ) |  |

Reads a null-terminated string from PDFstrm *pdfs. A max of nmax chars are read.

Parameters

  pdfs | The stream to read the string from.
  string | Pre-allocated storage for the string.
  nmax | The size of string.

Returns
  0 if successful.

Definition at line 604 of file pdfutils.c.

int pdf_rdx | ( | U_CHAR * | x,
|  | long | nitems,
|  | PDFstrm * | pdfs
| ) |  |

Reads a record.

Parameters

  x | Storage for the data to read.
  nitems | The length of the x.
  pdfs | The stream to read it from.

Returns
  The number of bytes read.

Definition at line 464 of file pdfutils.c.

void pdf_set | ( | char * | option,
|  | int | value
| ) |  |

Set an option. Pretty sparse right now but you never know.

Parameters

  option | The option string.
  value | The value to set it to.

Definition at line 56 of file pdfutils.c.

int pdf_ungetc | ( | int | c,
|  | PDFstrm * | pdfs
| ) |  |

Push back the last command read.

Parameters

  c | The character to pushback.
  pdfs | The stream to push it back into.

Returns
  The character pushed back, or EOF.

Definition at line 365 of file pdfutils.c.

int pdf_wr_1byte | ( | PDFstrm * | pdfs,
|  | U_CHAR | s
| ) |  |

Writes a U_CHAR as a single byte.

Parameters

  pdfs | The stream to write the byte too.
  s | The byte to write.

Returns
  0 if successful.

Definition at line 636 of file pdfutils.c.

int pdf_wr_2bytes | ( | PDFstrm * | pdfs,
|  | U_SHORT | s
| ) |  |

Writes a U_SHORT as two single bytes, low end first.

Parameters

  pdfs | The stream to write the two bytes to.
  s | The two bytes to write.

Returns
  0 if successful.

Definition at line 684 of file pdfutils.c.

int pdf_wr_2nbytes | ( | PDFstrm * | pdfs,
|  | U_SHORT * | s,
|  | PLINT | n
| ) |  |

Writes n U_SHORT's as 2n single bytes, low end first.

Parameters

  pdfs | The stream to write the shorts to.
  s | An array of shorts.
  n | Size of s.

Returns
  0 if successful.

Definition at line 741 of file pdfutils.c.

int pdf_wr_4bytes | ( | PDFstrm * | pdfs,
|  | U_LONG | s
| ) |  |

Writes an unsigned long as four single bytes, low end first.

Parameters

  pdfs | The stream to write the unsigned long to.
  s | The unsigned long to write.

Returns
  0 if successful.

Definition at line 804 of file pdfutils.c.

int pdf_wr_header | ( | PDFstrm * | pdfs,
|  | const char * | header
| ) |  |

Writes a header string. Input string must be NULL-terminated. The written string is terminated by a new-line, not a NULL. This is done so you can type e.g. "% strings <file> | head" and get sensible output.

Parameters

  pdfs | The stream to which to write the header.
  header | The header.

Returns
  0 if there was no error.

Definition at line 509 of file pdfutils.c.

int pdf_wr_ieeef | ( | PDFstrm * | pdfs,
|  | float | f
| ) |  |

Writes a float in IEEE single precision (32 bit) format.

Parameters

  pdfs | The stream to write the float to.
  f | The float.

Returns
  0 if successful.

Definition at line 916 of file pdfutils.c.

int pdf_wr_string | ( | PDFstrm * | pdfs,
|  | const char * | string
| ) |  |

Writes a null-terminated string.

Parameters

  pdfs | The stream to write the string to.
  string | The string to write.

Returns
  0 if successful.

Definition at line 574 of file pdfutils.c.

static int pdf_wrx | ( | const U_CHAR * | x,
|  | long | nitems,
|  | PDFstrm * | pdfs
| ) |  |
| static

Writes a record.

Parameters

  x | The data to write.
  nitems | The length of x.
  pdfs | The stream to write it to.

Returns
  The number of bytes actually written.

Definition at line 411 of file pdfutils.c.

void plAlloc2dGrid | ( | PLFLT *** | f,
|  | PLINT | nx,
|  | PLINT | ny
| ) |  |

Allocates a block of memory for use as a 2-d grid of PLFLT's. Resulting array can be indexed as f[i][j] anywhere. This is to be used instead of PLFLT f[nx][ny], which is less useful. Note that this type of allocation is required by the PLplot functions which take a 2-d grids of PLFLT's as an argument, such as plcont() and plot3d(). Example usage:

PLFLT **z;

Alloc2dGrid(&z, XPTS, YPTS);

Parameters

  f | Location of the storage (address of a **).
  nx | Size of the grid in x.
  ny | Size of the grid in y.

Definition at line 1104 of file pdfutils.c.

void plFree2dGrid | ( | PLFLT ** | f,
|  | PLINT | nx,
|  | PLINT | PL_UNUSEDny
| ) |  |

Frees a block of memory allocated with Alloc2dGrid().

Parameters

  f | The [][] to the storage.
  nx | Size of the grid in x.
  PL_UNUSED( | ny) Not used.

Definition at line 1129 of file pdfutils.c.

void plMinMax2dGrid | ( | const PLFLT *const * | f,
|  | PLINT | nx,
|  | PLINT | ny,
|  | PLFLT * | fnmax,
|  | PLFLT * | fnmin
| ) |  |

Finds the maximum and minimum of a 2d matrix allocated with plAllc2dGrid(). NaN and +/- infinity values are ignored.

param f 2d matrix pointer. param nx Size of the grid in x. param ny Size of the grid in y. param fnmax Maximum value in the matrix. param fnmin Minimum value in the matrix.

Definition at line 1154 of file pdfutils.c.

static void print_ieeef | ( | float * | vx,
|  | U_LONG * | vy
| ) |  |
| static

Prints binary representation for numbers pointed to by arguments. The first argument is the original float, the second is the IEEE representation. They should be the same on any machine that uses IEEE floats.

Parameters

  vx | The original float?
  vy | The IEEE representation?

Definition at line 1048 of file pdfutils.c.

## Variable Documentation

int debug = 0
| static

Definition at line 43 of file pdfutils.c.