[Next] [Previous] [Index]
Next: nc2pnm Previous: Installation Index: Contents

pnm2nc : Converter PNM to NetCDF


Synopsis

pnm2nc [-h] ncName [-v varName] [-t dataType] [name1 name2 ...]

Parameters

Parameters in [ ] are optional.
-h
Prints help information and quits.
ncName
Name of the NetCDF file to process - must be the first parameter.
varName
Name of the variable to create for the image(sequence).
dataType
Datatype of the new variable. Possible values: byte long
name1 name2 name3 ...
Names of the imagefiles to read. If no name is given then stdin is read.
Recognized formats: pbm ascii, pgm ascii, ppm ascii, pgm raw, ppm raw.

Discussion

The program pnm2nc opens an existing NetCDF file or creates a new file with the name ncName. It then opens the files name1, name2, etc and stores their data in one variable. The default for the variable name is name1. Another name can be specified with -v varName. If the variable allready exists, then the images are appended to that variable.

By default, 1- and 8-bit images are stored as byte and 24-bit images are stored as long values. This can be overruled with -t dataType.

Note:
Storing 8-bit greyscale values in a long variable is not the same as converting them to 24-bit colour values. The value is simply stored in the least significant byte of the long variable, whereas programs like xv or pgm2ppm multiply the value with 65793 to yield a 24-bit greyscale image.

Examples

pnm2nc Blocks.nc -v img -t long Blocks.pgm
Opens or creates Blocks.nc and stores the 8-bit values of Blocks.pgm as long values in the variable img.
pnm2nc rrr.nc Chest2.pgm
Opens or creates rrr.nc and stores the 8-bit values of Chest2.pgm as byte values in the variable Chest2.pgm.
find * -name '*.pgm' -exec pnm2nc foo.nc {} \;
Stores all files *.pgm in the NetCDF file foo.nc, each in a different variable.

Return Values

These values can be returned as exit status by pnm2nc:
PipsOk (0)
Program terminated normally.
PipsErrorFileRead (-1)
The image file could not be opened.
PipsErrorFileWrite (-2)
The NetCDF file could not be written or closed.
PipsNetcdfMissing (-4)
There haven't been specified any command line parameters.
PipsBadParameter (-5)
An unknown command line option; filenames must not start with a hyphen.
PipsSinglePara (-6)
The -v or -t option didn't have a name with it.
PipsImageType (-8)
The presented input file was not a PNM type (or it was pbmraw).

Restrictions and known bugs

Properties of the generated NetCDF files

A listing of a sample NetCDF file, produced with ncdump Blocks.nc, is given below:
netcdf Blocks {
dimensions:
        recDim = UNLIMITED ; // (1 currently)
        height_256 = 256 ;
        width_256 = 256 ;

variables:
        byte Blocks.pgm(recDim, height_256, width_256) ;
                Blocks.pgm:identifier = "pgm raw" ;
                Blocks.pgm:_FillValue = '\0' ;

// global attributes:
        :__history_WedDec71543541994 = "pnm2nc Blocks.nc Blocks.pgm " ;

data:

 Blocks.pgm =
  47, 77, 103, 89, 84, 107, 80, 104, 93, 88, 110, 94, 126,
  ... lot's of numbers deleted ...
    123, 125, 122, 124, 126 ;
}

Frank Heimes (Dr-Frank.Heimes@epost.de), 31 Jan 1995
Phone: +49 (721) 6091 - 424, FAX: +49 (721) 6091 - 233
http://members.tripod.de/DrFrankHeimes/pips/pnm2nc.html