SDDBlock.h

Classes

SDDBlock -- SDDBlock handles the IO and value extraction from SDD records (blocks). (full description)

class SDDBlock

Types

enum

STANDARD_RECORD_SIZE = 512

Interface

Public Members
SDDBlock(uInt n = 1, uInt bytesPerRecord = STANDARD_RECORD_SIZE)
SDDBlock(const SDDBlock& other)
~SDDBlock()
SDDBlock& operator=(const SDDBlock& other)
uInt nRecords() const
uInt nbytes() const
uInt bytesPerRecord() const
void resize(uInt nRecords, Bool forceSmaller = False, Bool copyElements = False)
void reshape(uInt nRecords, uInt bytesPerRecord, Bool forceSmaller = False, Bool copyElements = False)
uInt read(istream& in)
uInt read(istream& in, uInt nrecord, uInt startRecord = 0)
uInt readBytes(istream& in, uInt nbytes, uInt startOffset = 0)
uInt write(ostream& out) const
uInt write(ostream& out, uInt nrecord, uInt startRecord = 0) const
uInt writeBytes(ostream& out, uInt nbytes, uInt startOffset = 0) const
void copy(SDDBlock& outBlock, uInt ncopy, uInt outStart = 0, uInt inStart = 0) const
Char& operator[](uInt index)
const Char& operator[](uInt index) const
Short& asShort(uInt index)
const Short& asShort(uInt index) const
Int& asInt(uInt location)
const Int& asInt(uInt location) const
float& asfloat(uInt location)
const float& asfloat(uInt location) const
double& asdouble(uInt location)
const double& asdouble(uInt location) const
Private Members
void set_pointers()

Description

Prerequisite

Etymology

SDD stands for Single Dish Data. It is the data format that UniPOPS understands. It is also the on-line data format at the NRAO 12m. SDD files are organized in records or blocks. This class handles the io to and from those blocks. it is used by the other SDD classes.

Synopsis

SDDBlock is used primarily to handle the IO to and from an SDD file in units of an SDD record size. The standard rccord size if 512 bytes although this class can handle arbitrarily sized records so long as the size is an integer multiple of 8 bytes (the size of and IEEE double precision floating point number). The total size of an SDDBlock is an integer multiple of the record size (i.e. no fractional records are allowed). This class also aids in extracting values of different types from the block. This is not likely to be immediately portable. However, by isolating that conversion here, it should make any future ports easier. Since SDD files will only ever be written on Suns, its unlikely that this issue will be a problem.

The IO only involves iostreams and not fstream. It is intended that the public SDD classes handle all of the fstream specific operations and that this class does not need to do any seeks.

An SDDBlock is always at least 1 SDD record in size.

Example

This is a somewhat contrived example.
    // This istream would be initialized appropriately
    istream in;
    // construct an SDDBlock of 1 SDD record using the standard record size
    SDDBlock block;
    block.read(in, 1);
    // Extract the 5th double from the record, which indicates the size
    // of the full record to read in bytes, convert that to SDD records
    // read it in.   This would need some additional checks if partial
    // records might be indicated.
    double fullSize = block.asdouble(4);
    uInt nrecs = uInt(fullSize/block.bytesPerRecord());
    // read the remaining records
    block.read(in, (nrecs-1));
    

Motivation

SDD files are organized into units that are integer number of records (always of 512 bytes at this point in history, but they could theoretically be of a different size). It makes sense to have a class that the other SDD classes could use to deal with the data in those chunks.

Thrown Exceptions

To Do

Member Description

enum

SDD files have traditionally been composed of 512 byte records, but they are not not really required to be.

SDDBlock(uInt n = 1, uInt bytesPerRecord = STANDARD_RECORD_SIZE)

An SDDBlock with the indicated number of SDD records, each record having the indicated size in bytes, the whole thing filled with zeros.

SDDBlock(const SDDBlock& other)

copy constructor, this makes a true copy.

~SDDBlock()

SDDBlock& operator=(const SDDBlock& other)

assignment operator, this makes a true copy

uInt nRecords() const

return the size in SDD records

uInt nbytes() const

return the number of bytes

uInt bytesPerRecord() const

return the number of bytes per record

void resize(uInt nRecords, Bool forceSmaller = False, Bool copyElements = False)

resize this block to the indicated number of SDD records forceSmaller and copyElements work as with the Block class

void reshape(uInt nRecords, uInt bytesPerRecord, Bool forceSmaller = False, Bool copyElements = False)

reshape is like resize, except that the number of bytes per record can also change. The number of bytesPerRecord must be a multiple of 8.

uInt read(istream& in)

read from istream and fill until this SDDBlock is full or istream is exhausted return the number of records actually read

uInt read(istream& in, uInt nrecord, uInt startRecord = 0)

read nrecord records from istream, filling starting at the indicated record stop if istream is exhausted, return the number of records actually read

uInt readBytes(istream& in, uInt nbytes, uInt startOffset = 0)

read the indicated number of bytes from in, starting at the optionally indicated starting bytes offset, returns the number of bytes actually read

uInt write(ostream& out) const

write the entire SDDBlock to ostream, return the number of records written

uInt write(ostream& out, uInt nrecord, uInt startRecord = 0) const

write nrecord records to ostream, starting at the indicated record return the number of records written

uInt writeBytes(ostream& out, uInt nbytes, uInt startOffset = 0) const

write the indicated number of bytes to out, starting at the optionally indicated starting byte offset, returns the number of bytes actually written

void copy(SDDBlock& outBlock, uInt ncopy, uInt outStart = 0, uInt inStart = 0) const

copy ncopy character to another SDDBlock starting at outStart (characters) offset into and starting at inStart (characters) offset into this blcck

Char& operator[](uInt index)

index into the block

const Char& operator[](uInt index) const

Short& asShort(uInt index)

Index into the block as Shorts (0-based)

const Short& asShort(uInt index) const

Int& asInt(uInt location)

Index into the block as Ints (0-based)

const Int& asInt(uInt location) const

float& asfloat(uInt location)

Index into the block as floats (0-based)

const float& asfloat(uInt location) const

double& asdouble(uInt location)

Index into the block as doubles (0-based)

const double& asdouble(uInt location) const

void set_pointers()