package de.desy.tine.definitions;
import de.desy.tine.bitfieldUtils.TBitfield;
import de.desy.tine.structUtils.TStructRegistry;
import de.desy.tine.types.*;
/**
* TINE data format types
*/
public final class TFormat
{
public static final short CF_DOUBLE = 0;
public static final short CF_INT16 = 1;
public static final short CF_SHORT = 1;
public static final short CF_BYTE = 2;
public static final short CF_INT8 = 2;
public static final short CF_INT32 = 3;
public static final short CF_LONG = 3;
public static final short CF_TEXT = 4;
public static final short CF_CHAR = 4;
public static final short CF_FLOAT = 5;
public static final short CF_INT64 = 6;
public static final short CF_DLONG = 6;
public static final short CF_STRUCT = 7;
public static final short CF_NAME8 = 8;
public static final short CF_NAME16 = 9;
public static final short CF_NAME16FI = 10;
public static final short CF_NAMEFI = 10;
public static final short CF_BIT = 11;
public static final short CF_HITTS = 12;
public static final short CF_NAME32 = 13;
public static final short CF_FLTINT = 14;
public static final short CF_LNGINT = 15;
public static final short CF_INTINT = 15;
public static final short CF_DBLINT = 16;
public static final short CF_SHTINT = 17;
public static final short CF_INTFLTINT = 18;
public static final short CF_TDS = 18;
public static final short CF_NAME48 = 19;
public static final short CF_NAME8I = 20;
public static final short CF_NAME16I = 21;
public static final short CF_NAME32I = 22;
public static final short CF_NAME48I = 23;
public static final short CF_USTRING = 24;
public static final short CF_FLTFLTINT = 25;
public static final short CF_XYS = 25;
public static final short CF_FLTINTINT = 26;
public static final short CF_FIS = 26;
public static final short CF_FILTER = 27;
public static final short CF_INTFLTFLTFLT = 27;
public static final short CF_IFFF = 27;
public static final short CF_SPECTRUM = 28;
public static final short CF_ADDRESS = 29;
public static final short CF_IIII = 29;
public static final short CF_INTINTINTINT = 29;
public static final short CF_WINDOW = 30;
public static final short CF_TTII = 30;
public static final short CF_POINT = 31;
public static final short CF_FF = 31;
public static final short CF_XY = 31;
public static final short CF_FLTFLT = 31;
public static final short CF_TDSI = 32;
public static final short CF_INTFLTSHTSHT = 32;
public static final short CF_BOOLEAN = 33;
public static final short CF_IIFF = 34;
public static final short CF_INTINTFLTFLT = 34;
public static final short CF_FWINDOW = 34;
public static final short CF_FIFI = 35;
public static final short CF_FLTINTFLTINT = 35;
public static final short CF_NAME64 = 36;
public static final short CF_NAME64I = 37;
public static final short CF_INTDBL = 38;
public static final short CF_FLTDBL = 39;
public static final short CF_DBLDBL = 40;
public static final short CF_NAMEDBLDBL = 41;
public static final short CF_NAME16DBLDBL = 41;
public static final short CF_NAME16DD = 41;
public static final short CF_NAMEII = 42;
public static final short CF_NAME16II = 42;
public static final short CF_III = 43;
public static final short CF_INTINTINT = 43;
public static final short CF_NAME32DBLDBL = 44;
public static final short CF_NAME64DBLDBL = 45;
public static final short CF_UNAME = 46;
public static final short CF_IFFFNAME = 46;
public static final short CF_XML = 47;
public static final short CF_DBLDBLDBL = 48;
public static final short CF_NAME64DBLDBLDBL = 49;
public static final short CF_CHAR64DBLDBLDBL = 49;
public static final short CF_STRING64DBLDBLDBL = 49;
public static final short CF_BITFIELD8 = 50;
public static final short CF_BITFIELD16 = 51;
public static final short CF_BITFIELD32 = 52;
public static final short CF_BITFIELD64 = 53;
public static final short CF_NAME64DBL = 54;
public static final short CF_CHAR64DBL = 54;
public static final short CF_STRING64DBL = 54;
public static final short CF_IMAGE = 55;
public static final short CF_HISTORY = 56;
public static final short CF_STRING = 57;
public static final short CF_ASPECTRUM = 58;
public static final short CF_AIMAGE = 59;
public static final short CF_KEYVALUE = 60;
public static final short CF_DBLTIME = 61;
public static final short CF_NAME64TIME = 62;
public static final short CF_MDA = 63;
public static final short CF_DEFAULT = 254;
public static final short CF_NULL = 255;
public static final String[] availableFormats = {"NULL", "BYTE", "BOOLEAN", "INT16", "INT32", "INT64","FLOAT", "DOUBLE",
"BITFIELD8", "BITFIELD16", "BITFIELD32", "BITFIELD64",
"STRUCT", "TEXT", "XML", "NAME8", "NAME16", "NAME32", "NAME48", "NAME64", "INTINT", "FLTINT", "FLTFLT","DBLDBL",
"NAME8I", "NAME16I", "NAME32I", "NAME48I", "NAME64I", "NAME64DBL",
"INTFLTINT", "INTINTINT", "USTRING", "UNAME", "DBLDBLDBL",
"SPECTRUM", "WINDOW", "FWINDOW", "ADDRESS", "NAME16FI", "NAME16II", "NAME16DBLDBL", "NAME32DBLDBL",
"NAME64DBLDBL", "NAME64DBLDBLDBL","FILTER", "FLTFLTINT", "IMAGE", "HISTORY",
"STRING", "ASPECTRUM", "AIMAGE","KEYVALUE","DBLTIME","NAME64TIME", "MDA"};
public static short makeStdFormatCode(int dataFormat)
{
return (short)(512 + (dataFormat % 256));
}
public static short makeStdFormatCode(String dataFormatString)
{
short dataFormat = getFormatCode(dataFormatString);
return (short)(512 + (dataFormat % 256));
}
public static short makeByteFormatCode(int dataFormat)
{
return (short)(dataFormat % 256);
}
/**
* @param dataFormat is the targeted format
* @return true if the format is a 'simple' type, that is
* composed of single element type (which might be fixed-length string)
*/
public static boolean isSimpleFormat(short dataFormat)
{
if (dataFormat <= CF_NAME16) return true;
if (dataFormat == CF_NAME32) return true;
if (dataFormat == CF_NAME48) return true;
if (dataFormat == CF_NAME64) return true;
if (dataFormat == CF_BIT) return true;
if (dataFormat == CF_BOOLEAN) return true;
if (dataFormat == CF_XML) return true;
return false;
}
public static boolean isAllowedSaveAndRestoreFormat(short dataFormat)
{
switch (dataFormat)
{
case CF_BYTE:
case CF_INT16:
case CF_INT32:
case CF_INT64:
case CF_BOOLEAN:
case CF_FLOAT:
case CF_DOUBLE:
case CF_TEXT:
case CF_NAME8:
case CF_NAME16:
case CF_NAME32:
case CF_NAME48:
case CF_NAME64:
case CF_INTINT:
case CF_INTINTINT:
case CF_INTINTINTINT:
case CF_FLTINT:
case CF_FLTFLT:
case CF_DBLDBL:
case CF_DBLDBLDBL:
case CF_NAME64DBL:
case CF_TDS:
case CF_NAME8I:
case CF_NAME16I:
case CF_NAME32I:
case CF_NAME48I:
case CF_NAME64I:
case CF_NAME16FI:
case CF_NAME16II:
case CF_NAME16DBLDBL:
case CF_NAME32DBLDBL:
case CF_NAME64DBLDBL:
case CF_FLTFLTINT:
case CF_FLTINTINT:
case CF_IFFF:
case CF_INTINTFLTFLT:
case CF_FLTINTFLTINT:
case CF_USTRING:
return true;
case CF_SPECTRUM:
case CF_STRUCT:
case CF_ASPECTRUM:
case CF_AIMAGE:
case CF_IMAGE:
case CF_HISTORY:
case CF_MDA:
return false;
default:
break;
}
return false;
}
public static int getSegments(short dataFormat)
{
if (isSimpleFormat(dataFormat)) return 1;
switch (dataFormat)
{
case CF_BITFIELD8:
case CF_BITFIELD16:
case CF_BITFIELD32:
case CF_BITFIELD64:
return 1;
case CF_NAME8I:
case CF_NAME16I:
case CF_NAME32I:
case CF_NAME48I:
case CF_NAME64I:
case CF_NAME64DBL:
case CF_FLTINT:
case CF_INTINT:
case CF_DBLDBL:
case CF_FLTFLT:
return 2;
case CF_NAME16FI:
case CF_NAME16II:
case CF_INTFLTINT:
case CF_FLTINTINT:
case CF_FLTFLTINT:
case CF_INTINTINT:
case CF_DBLDBLDBL:
case CF_NAME16DBLDBL:
case CF_NAME32DBLDBL:
case CF_NAME64DBLDBL:
return 3;
case CF_ADDRESS:
case CF_FILTER:
case CF_WINDOW:
case CF_FWINDOW:
case CF_FLTINTFLTINT:
case CF_NAME64DBLDBLDBL:
return 4;
case CF_USTRING:
case CF_UNAME:
return 5;
default:
break;
}
return 1;
}
/**
* Determines whether the given format is plotable in a trend
* chart (value vs time).
* @param dataFormat is the tine format to be examined
* @return <code>true</code> or <code>false</code>.
*/
public static boolean isPlotable(short dataFormat)
{
switch (dataFormat)
{
case CF_IMAGE:
case CF_STRUCT:
case CF_STRING:
case CF_KEYVALUE:
case CF_XML:
case CF_CHAR:
case CF_NAME8:
case CF_NAME16:
case CF_NAME32:
case CF_NAME48:
case CF_NAME64:
return false;
default:
if (isBitfield(dataFormat)) return false;
return true;
}
}
/**
* Determines whether the given format contains a string type
* variable (either fixed-capacity or free)
* @param dataFormat is the tine format to be examined
* @return <code>true</code> or <code>false</code>.
*/
public static boolean containsString(short dataFormat)
{
switch (dataFormat)
{
case CF_STRING:
case CF_KEYVALUE:
case CF_NAME8:
case CF_NAME16:
case CF_NAME32:
case CF_NAME48:
case CF_NAME64:
case CF_NAME8I:
case CF_NAME16I:
case CF_NAME32I:
case CF_NAME48I:
case CF_NAME64I:
case CF_NAME64DBL:
case CF_NAME16FI:
case CF_NAME16II:
case CF_NAME16DBLDBL:
case CF_NAME32DBLDBL:
case CF_NAME64DBLDBL:
case CF_NAME64DBLDBLDBL:
case CF_USTRING:
case CF_UNAME:
return true;
default:
break;
}
return false;
}
/**
* Determines whether the given format begins with a string type
* variable (either fixed-capacity or free)
* @param dataFormat is the tine format to be examined
* @return <code>true</code> or <code>false</code>.
*/
public static boolean beginsWithString(short dataFormat)
{
switch (dataFormat)
{
case CF_STRING:
case CF_KEYVALUE:
case CF_NAME8:
case CF_NAME16:
case CF_NAME32:
case CF_NAME48:
case CF_NAME64:
case CF_NAME8I:
case CF_NAME16I:
case CF_NAME32I:
case CF_NAME48I:
case CF_NAME64I:
case CF_NAME64DBL:
case CF_NAME16FI:
case CF_NAME16II:
case CF_NAME16DBLDBL:
case CF_NAME32DBLDBL:
case CF_NAME64DBLDBL:
case CF_NAME64DBLDBLDBL:
return true;
default:
break;
}
return false;
}
/**
* Determines whether the given format ends with a string type
* variable (either fixed-capacity or free)
* @param dataFormat is the tine format to be examined
* @return <code>true</code> or <code>false</code>.
*/
public static boolean endsWithString(short dataFormat)
{
switch (dataFormat)
{
case CF_STRING:
case CF_KEYVALUE:
case CF_NAME8:
case CF_NAME16:
case CF_NAME32:
case CF_NAME48:
case CF_NAME64:
case CF_USTRING:
case CF_UNAME:
return true;
default:
break;
}
return false;
}
/**
* @param dataFormat is the targeted format
* @return <code>true</code> if the format is a fixed-length string type
*/
public static boolean isName(short dataFormat)
{
switch (dataFormat)
{
case CF_NAME8:
case CF_NAME16:
case CF_NAME32:
case CF_NAME48:
case CF_NAME64: return true;
default: return false;
}
}
/**
* @param dataFormat is the targeted format
* @return <code>true</code> if the format is a bitfield data type
*/
public static boolean isBitfield(short dataFormat)
{
switch (dataFormat)
{
case CF_BITFIELD8:
case CF_BITFIELD16:
case CF_BITFIELD32:
case CF_BITFIELD64: return true;
default: return false;
}
}
/**
* @param dataFormat is the targeted format
* @return <code>true</code> if the format is a structure
*/
public static boolean isStructFormat(short dataFormat)
{
return dataFormat == CF_STRUCT;
}
/**
* @param dataFormat is the targeted format
* @return <code>true</code> if the format represents a simple number type
*/
public static boolean isNumberFormat(short dataFormat)
{
switch (dataFormat)
{
case TFormat.CF_FLOAT:
case TFormat.CF_DOUBLE:
case TFormat.CF_DLONG:
case TFormat.CF_LONG:
case TFormat.CF_SHORT:
case TFormat.CF_BYTE:
return true;
default:
return false;
}
}
/**
* @param dataFormat is the targeted format
* @return <code>true</code> if the format represents a compound type with a
* timestamp as the last element
*/
public static boolean isTimeFormat(short dataFormat)
{
switch (dataFormat)
{
case TFormat.CF_DBLTIME:
case TFormat.CF_NAME64TIME:
return true;
default:
return false;
}
}
/**
* @param dataFormat is the targeted format
* @return <code>true</code> if the format is a tagged structure
*/
public static boolean isTaggedStruct(short dataFormat,String dataTag)
{
if (dataFormat != CF_STRUCT) return false;
if (!TStructRegistry.contains(dataTag)) return false;
return true;
}
/**
* determines whether the given format is a compound data type
*
* @param dataFormat is the targeted format
* @return <code>true</code> if the format is composed of more than a
* single entity (a TCompoundDataObject composed of at least a doublet).
*/
public static boolean isCompoundFormat(short dataFormat)
{
if (dataFormat <= CF_STRUCT) return false;
if (dataFormat == CF_BIT) return false;
if (dataFormat == CF_BOOLEAN) return false;
if (dataFormat == CF_XML) return false;
if (dataFormat == CF_STRING) return false;
if (dataFormat == CF_KEYVALUE) return false;
return true;
}
/**
* makes an array of compound data type objects according to the input given
*
* @param dataFormat is the targeted format (must refer to a TCompoundDataObject type)
* @param dataTag is the targeted data tag (if applicable)
* @param arrayLength is the size of the array to generate
* @return an array of TCompoundDataObject objects.
*/
public static TCompoundDataObject[] makeCompoundDataObjectArray(short dataFormat,String dataTag,int arrayLength)
{
// int size = TFormat.formatSizeOf(dataFormat);
switch (dataFormat)
{
case CF_NAME8:
{
NAME8[] tco = new NAME8[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME8();
return tco;
}
case CF_NAME16:
{
NAME16[] tco = new NAME16[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME16();
return tco;
}
case CF_NAME16FI:
{
NAME16FI[] tco = new NAME16FI[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME16FI();
return tco;
}
case CF_NAME32:
{
NAME32[] tco = new NAME32[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME32();
return tco;
}
case CF_FLTINT:
{
FLTINT[] tco = new FLTINT[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new FLTINT();
return tco;
}
case CF_INTINT:
{
INTINT[] tco = new INTINT[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new INTINT();
return tco;
}
case CF_INTFLTINT:
{
INTFLTINT[] tco = new INTFLTINT[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new INTFLTINT();
return tco;
}
case CF_NAME48:
{
NAME8[] tco = new NAME8[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME8();
return tco;
}
case CF_NAME16I:
{
NAME16I[] tco = new NAME16I[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME16I();
return tco;
}
case CF_NAME32I:
{
NAME32I[] tco = new NAME32I[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME32I();
return tco;
}
case CF_NAME48I:
{
NAME48I[] tco = new NAME48I[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME48I();
return tco;
}
case CF_USTRING:
{
USTRING[] tco = new USTRING[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new USTRING();
return tco;
}
case CF_FLTFLTINT:
{
FLTFLTINT[] tco = new FLTFLTINT[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new FLTFLTINT();
return tco;
}
case CF_FLTINTINT:
{
FLTINTINT[] tco = new FLTINTINT[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new FLTINTINT();
return tco;
}
case CF_FILTER:
{
FILTER[] tco = new FILTER[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new FILTER();
return tco;
}
case CF_SPECTRUM:
{
SPECTRUM[] tco = new SPECTRUM[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new SPECTRUM();
return tco;
}
case CF_ADDRESS:
{
ADDRESS[] tco = new ADDRESS[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new ADDRESS();
return tco;
}
case CF_WINDOW:
{
WINDOW[] tco = new WINDOW[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new WINDOW();
return tco;
}
case CF_POINT:
{
POINT[] tco = new POINT[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new POINT();
return tco;
}
case CF_FWINDOW:
{
INTINTFLTFLT[] tco = new INTINTFLTFLT[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new INTINTFLTFLT();
return tco;
}
// case CF_FLTINTFLTINT:
// {
// FLTINTFLTINT[] tco = new FLTINTFLTINT[arrayLength];
// for (int i=0; i<arrayLength; i++) tco[i] = new FLTINTFLTINT();
// return tco;
// }
case CF_NAME64:
{
NAME64[] tco = new NAME64[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME64();
return tco;
}
case CF_NAME64I:
{
NAME64I[] tco = new NAME64I[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME64I();
return tco;
}
case CF_DBLDBL:
{
DBLDBL[] tco = new DBLDBL[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new DBLDBL();
return tco;
}
case CF_NAME16DBLDBL:
{
NAME16DBLDBL[] tco = new NAME16DBLDBL[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME16DBLDBL();
return tco;
}
case CF_NAME16II:
{
NAME16II[] tco = new NAME16II[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME16II();
return tco;
}
case CF_INTINTINT:
{
INTINTINT[] tco = new INTINTINT[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new INTINTINT();
return tco;
}
case CF_NAME32DBLDBL:
{
NAME32DBLDBL[] tco = new NAME32DBLDBL[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME32DBLDBL();
return tco;
}
case CF_NAME64DBLDBL:
{
NAME64DBLDBL[] tco = new NAME64DBLDBL[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME64DBLDBL();
return tco;
}
case CF_UNAME:
{
UNAME[] tco = new UNAME[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new UNAME();
return tco;
}
case CF_DBLDBLDBL:
{
DBLDBLDBL[] tco = new DBLDBLDBL[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new DBLDBLDBL();
return tco;
}
case CF_NAME64DBLDBLDBL:
{
NAME64DBLDBLDBL[] tco = new NAME64DBLDBLDBL[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME64DBLDBLDBL();
return tco;
}
case CF_BITFIELD8:
case CF_BITFIELD16:
case CF_BITFIELD32:
case CF_BITFIELD64:
{
TBitfield[] tco = new TBitfield[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new TBitfield(dataTag,dataFormat);
return tco;
}
case CF_NAME64DBL:
{
NAME64DBL[] tco = new NAME64DBL[arrayLength];
for (int i=0; i<arrayLength; i++) tco[i] = new NAME64DBL();
return tco;
}
// case CF_IMAGE:
// {
// IMAGE[] tco = new IMAGE[arrayLength];
// for (int i=0; i<arrayLength; i++) tco[i] = new IMAGE();
// return tco;
// }
default:
break;
}
return null;
}
/**
* @param dataFormat is the targeted format
* @return the associated bit field format if applicable
* For instance CF_INT16 returns CF_BITFIELD16.
*/
public static short getBitfieldFormat(short dataFormat)
{
switch (dataFormat)
{
case CF_BITFIELD8:
case CF_BYTE:
return CF_BITFIELD8;
case CF_BITFIELD16:
case CF_SHORT:
return CF_BITFIELD16;
case CF_BITFIELD32:
case CF_LONG:
return CF_BITFIELD32;
case CF_BITFIELD64:
case CF_DLONG:
return CF_BITFIELD64;
default: return CF_NULL;
}
}
/**
* @param dataFormat is the targeted format
* @return the associated integer format type if applicable.
* For instance CF_BITFIELD16 returns CF_INT16.
*/
public static short getIntegerFormat(short dataFormat)
{
switch (dataFormat)
{
case CF_BITFIELD8:
case CF_BYTE:
return CF_BYTE;
case CF_BITFIELD16:
case CF_SHORT:
return CF_SHORT;
case CF_BITFIELD32:
case CF_LONG:
return CF_LONG;
case CF_BITFIELD64:
case CF_DLONG:
return CF_DLONG;
default: return CF_NULL;
}
}
/**
* @param dataFormat is the targeted format
* @return <code>true</code> if the given format represents a NAME-Integer pair
*/
public static boolean isNameInt(short dataFormat)
{
switch (dataFormat)
{
case CF_NAME8I:
case CF_NAME16I:
case CF_NAME32I:
case CF_NAME48I:
case CF_NAME64I: return true;
default: return false;
}
}
private static final int IMAGE_HDR_SIZE = 188;
private static final int SPECTRUM_HDR_SIZE = 96;
private static final int HISTORY_HDR_SIZE = 16;
private static final int MDA_HDR_SIZE = 376;
public static int getHistoryHeaderSize() { return HISTORY_HDR_SIZE; }
/**
* @param dataFormat is the targeted format data type
* @return the header size (in bytes) of the input format
* (non-null only for CF_IMAGE and CF_SPECTRUM)
*/
public static int getFormatHeaderSize(short dataFormat)
{
switch (dataFormat)
{
case CF_AIMAGE:
case CF_IMAGE: return IMAGE_HDR_SIZE;
case CF_ASPECTRUM:
case CF_SPECTRUM: return SPECTRUM_HDR_SIZE;
case CF_MDA: return MDA_HDR_SIZE;
default: return 0;
}
}
/**
* @param dataFormat is the targeted format data type
* @return the location of the data body within the corresponding
* data object.
*/
public static int getFormatBodyStart(short dataFormat)
{
switch (dataFormat)
{
case CF_AIMAGE:
case CF_IMAGE: return IMAGE_HDR_SIZE;
case CF_ASPECTRUM: return SPECTRUM_HDR_SIZE; //?
case CF_SPECTRUM: return 0;
default: return 0;
}
}
/**
* Determines the carried format type according to the
* format type given.
*
* This is largely equal to the input format itself. However
* some formats (CF_SPECTRUM, CF_IMAGE) imply a carried format.
*
* @param dataFormat is the targeted format data type
* @return the carried format type
*/
public static short getFormatDataType(short dataFormat)
{
int df = dataFormat % 256;
switch (df)
{
case CF_AIMAGE:
case CF_IMAGE: return CF_BYTE;
case CF_ASPECTRUM:
case CF_SPECTRUM: return CF_FLOAT;
default: return (short)df;
}
}
/**
* @param dataFormat is the targeted format
* @return true if the given format has an associated header
* (e.g. CF_IMAGE, CF_SPECTRUM)
*/
public static boolean hasHeader(short dataFormat)
{
switch (dataFormat)
{
case CF_AIMAGE:
case CF_IMAGE:
case CF_ASPECTRUM:
case CF_SPECTRUM:
case CF_MDA:
return true;
default:
return false;
}
}
/**
* Determines whether the input format is of variable length
* (one of CF_STRING, CF_AIMAGE, CF_IMAGE, CF_ASPECTRUM)
*
* Formats of variable length imply that an array of such entities do
* not have a known total length in bytes as the size of each element
* is variable.
*
* @param dataFormat is the format to be examined
* @return <code>true</code> if the format data type is of variable length
*/
public static boolean isVariableLength(short dataFormat)
{
switch (dataFormat)
{
case CF_STRING:
case CF_KEYVALUE:
case CF_AIMAGE:
case CF_IMAGE:
case CF_ASPECTRUM:
return true;
default:
return false;
}
}
/**
* Determines whether the given format is a variable length type
* @param dataFormat is the tine format to be examined
* @return <code>true</code> or <code>false</code>.
*/
public static boolean isVariableLengthString(short dataFormat)
{
switch (dataFormat)
{
case CF_STRING:
case CF_KEYVALUE:
return true;
default:
return false;
}
}
/**
* Determines whether the input format is of adjustable length
* (one of CF_STRING, CF_AIMAGE, CF_ASPECTRUM)
*
* Formats of adjustable length as in the case of variable length types
* imply that an array of such entities do
* not have a known total length in bytes as the size of each element
* is variable. In addition, the transport mechanism is allowed to adjust
* the size of the transfered data. This is the same list of types as
* the variable length types, except for the exclusion of CF_IMAGE.
* An adjustable image type (CF_AIMAGE) will pass a reference of the adjusted image
* to the caller whereas a non-adjustable image (CF_IMAGE) will copy
* the image bytes into the caller's buffer (truncating if necessary).
*
* @param dataFormat is the format to be examined
* @return <code>true</code> if the format data type is of adjustable length
*/
public static boolean isAdjustableLength(short dataFormat)
{
switch (dataFormat)
{
case CF_STRING:
case CF_KEYVALUE:
case CF_AIMAGE:
case CF_ASPECTRUM: return true;
default: return false;
}
}
/**
* @param dataFormat is the targeted format
* @return <code>true</code> if the format data type represents a string
*/
public static boolean isString(short dataFormat)
{
switch (dataFormat)
{
case CF_TEXT:
case CF_USTRING:
case CF_UNAME:
case CF_NAME8:
case CF_NAME16:
case CF_NAME32:
case CF_NAME48:
case CF_NAME64: return true;
default: return false;
}
}
public static boolean isSimpleString(short dataFormat)
{
switch (dataFormat)
{
case CF_TEXT:
case CF_NAME8:
case CF_NAME16:
case CF_NAME32:
case CF_NAME48:
case CF_NAME64: return true;
default: return false;
}
}
/** Returns true if the input formats can be converted
*
* @param dataFormat1 is the first of the format pair
* @param dataFormat2 is the second of the format pair
* @param input specifies whether the conversion concerns input
* data (true) or not.
*
* @return true if the input formats can be converted
* */
public static boolean formatsCanMap(short dataFormat1, short dataFormat2,boolean input)
{
if (dataFormat1 == dataFormat2) return true;
switch (dataFormat1)
{
case CF_BYTE:
if (input) break; // input formats must match from here on
if (dataFormat2 == CF_TEXT) return true;
break;
case CF_BOOLEAN:
case CF_LONG:
case CF_DLONG:
case CF_SHORT:
case CF_FLOAT:
case CF_DOUBLE:
switch (dataFormat2)
{
case CF_FLOAT: case CF_DOUBLE:
case CF_LONG: case CF_SHORT: case CF_DLONG:
case CF_BOOLEAN:
return true;
default:
break;
}
break;
case CF_DBLDBL:
case CF_INTINT:
case CF_FLTINT:
if (input) break; // compound input formats must match
switch (dataFormat2)
{
case CF_INTINT: case CF_FLTINT: case CF_DBLDBL:
case CF_FLOAT: case CF_DOUBLE: case CF_LONG: case CF_DLONG:
return true;
default:
break;
}
break;
case CF_TEXT:
case CF_NAME64:
case CF_NAME48:
case CF_NAME32:
case CF_NAME16:
case CF_NAME8:
case CF_STRING:
switch (dataFormat2)
{
case CF_NAME8: case CF_NAME16: case CF_NAME32: case CF_NAME48:
case CF_NAME64: case CF_USTRING: case CF_TEXT: case CF_STRING:
return true;
default:
break;
}
if (input) break; // input formats must match from here on
if (dataFormat2 == CF_BYTE) return true;
break;
case CF_NAME64I:
case CF_NAME48I:
case CF_NAME32I:
case CF_NAME16I:
if (input) break; // compound input formats must match
switch (dataFormat2)
{
case CF_NAME16I: case CF_NAME32I: case CF_NAME48I: case CF_NAME64I:
case CF_NAME16: case CF_NAME32: case CF_NAME48: case CF_NAME64:
return true;
default:
break;
}
break;
case CF_NAME16DBLDBL:
case CF_NAME32DBLDBL:
case CF_NAME64DBLDBL:
if (input) break; // compound input formats must match
switch (dataFormat2)
{
case CF_NAME16DBLDBL: case CF_NAME32DBLDBL: case CF_NAME64DBLDBL:
return true;
default:
break;
}
// case CF_STRING:
case CF_KEYVALUE:
if (dataFormat2 == CF_KEYVALUE ||
dataFormat2 == CF_STRING) return true;
}
return false;
}
/**
* The size in bytes of the specified data format
* @param dataFormat
* is the tine data type for which the size in bytes is desired
* @return the size in bytes of the specified data format
*/
public static int formatSizeOf(short dataFormat)
{
short df = dataFormat >= 0 ? dataFormat : (short) (256 + dataFormat);
if (df >= 512) df -= 512;
switch (df)
{
case TFormat.CF_NULL:
return 0;
case TFormat.CF_HISTORY:
case TFormat.CF_MDA:
case TFormat.CF_BIT:
case TFormat.CF_STRUCT:
case TFormat.CF_TEXT:
case TFormat.CF_XML:
case TFormat.CF_BYTE:
case TFormat.CF_BITFIELD8:
case TFormat.CF_AIMAGE:
case TFormat.CF_IMAGE:
case TFormat.CF_KEYVALUE:
case TFormat.CF_STRING:
return 1;
case TFormat.CF_BITFIELD16:
case TFormat.CF_SHORT:
return 2;
case TFormat.CF_BITFIELD32:
case TFormat.CF_BOOLEAN:
case TFormat.CF_LONG:
case TFormat.CF_FLOAT:
return 4;
case TFormat.CF_BITFIELD64:
case TFormat.CF_DLONG:
case TFormat.CF_DOUBLE:
return 8;
case TFormat.CF_NAME8:
return 8;
case TFormat.CF_NAME16:
return 16;
case TFormat.CF_NAME32:
return 32;
case TFormat.CF_NAME48:
return 48;
case TFormat.CF_NAME64:
return 64;
case TFormat.CF_FLTINT:
case TFormat.CF_INTINT:
case TFormat.CF_FLTFLT:
return 8;
case TFormat.CF_DBLINT: //TODO: get rid of this format
return 12;
case TFormat.CF_FLTFLTINT:
case TFormat.CF_FLTINTINT:
case TFormat.CF_INTINTINT:
return 12;
case TFormat.CF_WINDOW:
case TFormat.CF_FIFI:
case TFormat.CF_ADDRESS:
case TFormat.CF_IFFF:
case TFormat.CF_FWINDOW:
return 16;
case TFormat.CF_NAME16II:
return 24;
case TFormat.CF_NAME16FI:
return 24;
case TFormat.CF_NAME16I:
return 20;
case TFormat.CF_NAME32I:
return 36;
case TFormat.CF_NAME48I:
return 52;
case TFormat.CF_NAME64I:
return 68;
case CF_NAME64TIME:
case CF_NAME64DBL:
return 72;
case TFormat.CF_NAME16DBLDBL:
return 32;
case TFormat.CF_NAME32DBLDBL:
return 48;
case TFormat.CF_NAME64DBLDBL:
return 80;
case TFormat.CF_NAME64DBLDBLDBL:
return 88;
case TFormat.CF_INTDBL://TODO: get rid of this format
return 12;
case TFormat.CF_FLTDBL://TODO: get rid of this format
return 12;
case TFormat.CF_DBLTIME:
case TFormat.CF_DBLDBL:
return 16;
case TFormat.CF_DBLDBLDBL:
return 24;
case TFormat.CF_ASPECTRUM:
case TFormat.CF_SPECTRUM:
return 4;
case TFormat.CF_TDS:
return 12;
case TFormat.CF_TDSI:
return 16;
case TFormat.CF_USTRING:
return 96;
case TFormat.CF_UNAME:
return 32;
default:
return -1;
}
}
/**
* The string representation of the specified data format
* @param dataFormat
* is the tine data type for which the string representation is
* desired
* @return The string representation of the specified data format
*/
public static String toString(short dataFormat)
{
short df = dataFormat >= 0 ? dataFormat : (short) (256 + dataFormat);
if (df >= 512) df -= 512;
switch (df)
{
case TFormat.CF_NULL: return "NULL";
case TFormat.CF_BIT: return "BIT";
case TFormat.CF_STRUCT: return "STRUCT";
case TFormat.CF_TEXT: return "TEXT";
case TFormat.CF_BYTE: return "BYTE";
case TFormat.CF_SHORT: return "INT16";
case TFormat.CF_LONG: return "INT32";
case TFormat.CF_DLONG: return "INT64";
case TFormat.CF_FLOAT: return "FLOAT";
case TFormat.CF_DOUBLE: return "DOUBLE";
case TFormat.CF_NAME8: return "NAME8";
case TFormat.CF_NAME16: return "NAME16";
case TFormat.CF_NAME32: return "NAME32";
case TFormat.CF_NAME48: return "NAME48";
case TFormat.CF_NAME64: return "NAME64";
case TFormat.CF_FLTINT: return "FLTINT";
case TFormat.CF_INTINT: return "INTINT";
case TFormat.CF_DBLINT: return "DBLINT";
case TFormat.CF_FLTFLT: return "FLTFLT";
case TFormat.CF_FIFI: return "FIFI";
case TFormat.CF_FLTFLTINT: return "FLTFLTINT";
case TFormat.CF_FLTINTINT: return "FLTINTINT";
case TFormat.CF_DBLDBLDBL: return "DBLDBLDBL";
case TFormat.CF_ADDRESS: return "ADDRESS";
case TFormat.CF_WINDOW: return "WINDOW";
case TFormat.CF_BOOLEAN: return "BOOLEAN";
case TFormat.CF_FWINDOW: return "WINDOW";
case TFormat.CF_NAME16FI: return "NAMEFI";
case TFormat.CF_NAME16II: return "NAMEII";
case TFormat.CF_NAME16I: return "NAME16I";
case TFormat.CF_NAME32I: return "NAME32I";
case TFormat.CF_NAME48I: return "NAME48I";
case TFormat.CF_NAME64I: return "NAME64I";
case TFormat.CF_NAME64DBL: return "NAME64DBL";
case TFormat.CF_NAME64TIME: return "NAME64TIME";
case TFormat.CF_INTDBL: return "INTDBL";
case TFormat.CF_FLTDBL: return "FLTDBL";
case TFormat.CF_DBLDBL: return "DBLDBL";
case TFormat.CF_DBLTIME: return "DBLTIME";
case TFormat.CF_ASPECTRUM: return "ASPECTRUM";
case TFormat.CF_SPECTRUM: return "SPECTRUM";
case TFormat.CF_TDS: return "TDS";
case TFormat.CF_TDSI: return "TDSI";
case TFormat.CF_USTRING: return "USTRING";
case TFormat.CF_UNAME: return "UNAME";
case TFormat.CF_IFFF: return "FILTER";
case TFormat.CF_III: return "INTINTINT";
case TFormat.CF_NAME16DBLDBL: return "NAME16DBLDBL";
case TFormat.CF_NAME32DBLDBL: return "NAME32DBLDBL";
case TFormat.CF_NAME64DBLDBL: return "NAME64DBLDBL";
case TFormat.CF_NAME64DBLDBLDBL: return "NAME64DBLDBLDBL";
case TFormat.CF_XML: return "XML";
case TFormat.CF_BITFIELD8: return "BITFIELD8";
case TFormat.CF_BITFIELD16: return "BITFIELD16";
case TFormat.CF_BITFIELD32: return "BITFIELD32";
case TFormat.CF_BITFIELD64: return "BITFIELD64";
case TFormat.CF_IMAGE: return "IMAGE";
case TFormat.CF_AIMAGE: return "AIMAGE";
case TFormat.CF_HISTORY: return "HISTORY";
case TFormat.CF_STRING: return "STRING";
case TFormat.CF_KEYVALUE: return "KEYVALUE";
case TFormat.CF_MDA: return "MDA";
default:
return "unknown";
}
}
/**
* Parses an input format string and extracts the given data tag.
*
* @param dataFormatString is the data format string which is to be parsed
* @return the data format tag (if found) or an empty string.
*/
public static String getFormatTag(String dataFormatString)
{
if (dataFormatString == null) return null;
int p = dataFormatString.indexOf(".");
if (p < 1) return "";
String fmt = dataFormatString.substring(0, p).toUpperCase();
if (fmt.startsWith("STRUCT") || fmt.startsWith("BITFIELD"))
{
return dataFormatString.substring(p+1);
}
return "";
}
/**
* Parses an input format string and extracts the given array type.
*
* @param dataFormatString is the data format string which is to be parsed
* @return the array type
*/
public static short getFormatArrayType(String dataFormatString)
{
if (dataFormatString == null) return TArrayType.AT_UNKNOWN;
int p = dataFormatString.indexOf(".");
if (p < 1) return TArrayType.AT_UNKNOWN;
String fmt = dataFormatString.substring(0, p).toUpperCase();
if (fmt.startsWith("STRUCT") || fmt.startsWith("BITFIELD"))
{
return TArrayType.AT_UNKNOWN;
}
return TArrayType.getType(dataFormatString.substring(p+1));
}
/**
* The format code of the specified String
* @param dataFormatString
* is the string representation for which the tine data type is desired
* @return the format code of the specified String
*/
public static short getFormatCode(String dataFormatString)
{
String dfs = dataFormatString.toUpperCase();
if (dfs.compareTo("NULL") == 0) return TFormat.CF_NULL;
if (dfs.startsWith("BITFIELD8")) return TFormat.CF_BITFIELD8;
if (dfs.startsWith("BITFIELD16")) return TFormat.CF_BITFIELD16;
if (dfs.startsWith("BITFIELD32")) return TFormat.CF_BITFIELD32;
if (dfs.startsWith("BITFIELD64")) return TFormat.CF_BITFIELD64;
if (dfs.startsWith("BIT")) return TFormat.CF_BIT;
if (dfs.startsWith("STRUCT")) return TFormat.CF_STRUCT;
if (dfs.startsWith("TEXT")) return TFormat.CF_TEXT;
if (dfs.startsWith("BYTE")) return TFormat.CF_BYTE;
if (dfs.startsWith("INT8")) return TFormat.CF_BYTE;
if (dfs.startsWith("SHORT")) return TFormat.CF_SHORT;
if (dfs.startsWith("INT16")) return TFormat.CF_SHORT;
if (dfs.startsWith("LONG")) return TFormat.CF_LONG;
if (dfs.startsWith("INT32")) return TFormat.CF_LONG;
if (dfs.startsWith("UINT32")) return TFormat.CF_LONG;
if (dfs.startsWith("DLONG")) return TFormat.CF_DLONG;
if (dfs.startsWith("INT64")) return TFormat.CF_DLONG;
if (dfs.startsWith("FLOAT")) return TFormat.CF_FLOAT;
if (dfs.startsWith("DOUBLE")) return TFormat.CF_DOUBLE;
if (dfs.startsWith("NAME16FI")) return TFormat.CF_NAME16FI;
if (dfs.startsWith("STRING16FI")) return TFormat.CF_NAME16FI;
if (dfs.startsWith("CHAR16FI")) return TFormat.CF_NAME16FI;
if (dfs.startsWith("NAMEFI")) return TFormat.CF_NAME16FI;
if (dfs.startsWith("NAME16II")) return TFormat.CF_NAME16II;
if (dfs.startsWith("NAMEII")) return TFormat.CF_NAME16II;
if (dfs.startsWith("STRING16II")) return TFormat.CF_NAME16II;
if (dfs.startsWith("CHAR16II")) return TFormat.CF_NAME16II;
if (dfs.startsWith("NAME16I")) return TFormat.CF_NAME16I;
if (dfs.startsWith("STRING16I")) return TFormat.CF_NAME16I;
if (dfs.startsWith("CHAR16I")) return TFormat.CF_NAME16I;
if (dfs.startsWith("NAME32I")) return TFormat.CF_NAME32I;
if (dfs.startsWith("STRING32I")) return TFormat.CF_NAME32I;
if (dfs.startsWith("CHAR32I")) return TFormat.CF_NAME32I;
if (dfs.startsWith("NAME48I")) return TFormat.CF_NAME48I;
if (dfs.startsWith("STRING48I")) return TFormat.CF_NAME48I;
if (dfs.startsWith("CHAR48I")) return TFormat.CF_NAME48I;
if (dfs.startsWith("NAME64I")) return TFormat.CF_NAME64I;
if (dfs.startsWith("STRING64I")) return TFormat.CF_NAME64I;
if (dfs.startsWith("CHAR64I")) return TFormat.CF_NAME64I;
if (dfs.startsWith("NAMEDBLDBL")) return TFormat.CF_NAME16DBLDBL;
if (dfs.startsWith("NAME16DBLDBL")) return TFormat.CF_NAME16DBLDBL;
if (dfs.startsWith("STRING16DBLDBL")) return TFormat.CF_NAME16DBLDBL;
if (dfs.startsWith("CHAR16DBLDBL")) return TFormat.CF_NAME16DBLDBL;
if (dfs.startsWith("NAME32DBLDBL")) return TFormat.CF_NAME32DBLDBL;
if (dfs.startsWith("STRING32DBLDBL")) return TFormat.CF_NAME32DBLDBL;
if (dfs.startsWith("CHAR32DBLDBL")) return TFormat.CF_NAME32DBLDBL;
if (dfs.startsWith("NAME64DBLDBLDBL")) return TFormat.CF_NAME64DBLDBLDBL;
if (dfs.startsWith("STRING64DBLDBLDBL")) return TFormat.CF_NAME64DBLDBLDBL;
if (dfs.startsWith("CHAR64DBLDBLDBL")) return TFormat.CF_NAME64DBLDBLDBL;
if (dfs.startsWith("NAME64DBLDBL")) return TFormat.CF_NAME64DBLDBL;
if (dfs.startsWith("STRING64DBLDBL")) return TFormat.CF_NAME64DBLDBL;
if (dfs.startsWith("CHAR64DBLDBL")) return TFormat.CF_NAME64DBLDBL;
if (dfs.startsWith("NAME64DBL")) return TFormat.CF_NAME64DBL;
if (dfs.startsWith("NAME64TIME")) return TFormat.CF_NAME64TIME;
if (dfs.startsWith("STRING64DBL")) return TFormat.CF_NAME64DBL;
if (dfs.startsWith("CHAR64DBL")) return TFormat.CF_NAME64DBL;
if (dfs.startsWith("NAME8")) return TFormat.CF_NAME8;
if (dfs.startsWith("STRING8")) return TFormat.CF_NAME8;
if (dfs.startsWith("CHAR8")) return TFormat.CF_NAME8;
if (dfs.startsWith("NAME16")) return TFormat.CF_NAME16;
if (dfs.startsWith("STRING16")) return TFormat.CF_NAME16;
if (dfs.startsWith("CHAR16")) return TFormat.CF_NAME16;
if (dfs.startsWith("NAME32")) return TFormat.CF_NAME32;
if (dfs.startsWith("STRING32")) return TFormat.CF_NAME32;
if (dfs.startsWith("CHAR32")) return TFormat.CF_NAME32;
if (dfs.startsWith("NAME48")) return TFormat.CF_NAME48;
if (dfs.startsWith("STRING48")) return TFormat.CF_NAME48;
if (dfs.startsWith("CHAR48")) return TFormat.CF_NAME48;
if (dfs.startsWith("NAME64")) return TFormat.CF_NAME64;
if (dfs.startsWith("STRING64")) return TFormat.CF_NAME64;
if (dfs.startsWith("CHAR64")) return TFormat.CF_NAME64;
if (dfs.startsWith("FLTFLTINT")) return TFormat.CF_FLTFLTINT;
if (dfs.startsWith("FLTFLT")) return TFormat.CF_FLTFLT;
if (dfs.startsWith("POINT")) return TFormat.CF_FLTFLT;
if (dfs.startsWith("FIFI")) return TFormat.CF_FIFI;
if (dfs.startsWith("FLTINTFLTINT")) return TFormat.CF_FIFI;
if (dfs.startsWith("FFI")) return TFormat.CF_FLTFLTINT;
if (dfs.startsWith("FLTINTINT")) return TFormat.CF_FLTINTINT;
if (dfs.startsWith("FII")) return TFormat.CF_FLTINTINT;
if (dfs.startsWith("ADDRESS")) return TFormat.CF_ADDRESS;
if (dfs.startsWith("IIII")) return TFormat.CF_ADDRESS;
if (dfs.startsWith("III")) return TFormat.CF_III;
if (dfs.startsWith("INTINTINT")) return TFormat.CF_III;
if (dfs.startsWith("BOOL")) return TFormat.CF_BOOLEAN;
if (dfs.startsWith("WINDOW")) return TFormat.CF_WINDOW;
if (dfs.startsWith("FWINDOW")) return TFormat.CF_FWINDOW;
if (dfs.startsWith("SPECTRUM")) return TFormat.CF_SPECTRUM;
if (dfs.startsWith("ASPECTRUM")) return TFormat.CF_ASPECTRUM;
if (dfs.startsWith("TDSI")) return TFormat.CF_TDSI;
if (dfs.startsWith("TDS")) return TFormat.CF_TDS;
if (dfs.startsWith("UNAME")) return TFormat.CF_UNAME;
if (dfs.startsWith("IFFFNAME")) return TFormat.CF_UNAME;
if (dfs.startsWith("INTFLTFLTFLTNAME")) return TFormat.CF_UNAME;
if (dfs.startsWith("INTFLTINTINT")) return TFormat.CF_TDSI;
if (dfs.startsWith("INTFLTINT")) return TFormat.CF_TDS;
if (dfs.startsWith("INTFLTFLTFLT")) return TFormat.CF_FILTER;
if (dfs.startsWith("FILTER")) return TFormat.CF_FILTER;
if (dfs.startsWith("USTRING")) return TFormat.CF_USTRING;
if (dfs.startsWith("INTDBL")) return TFormat.CF_INTDBL;
if (dfs.startsWith("FLTDBL")) return TFormat.CF_FLTDBL;
if (dfs.startsWith("DBLDBLDBL")) return TFormat.CF_DBLDBLDBL;
if (dfs.startsWith("DBLDBL")) return TFormat.CF_DBLDBL;
if (dfs.startsWith("DBLTIME")) return TFormat.CF_DBLTIME;
if (dfs.startsWith("FLTINT")) return TFormat.CF_FLTINT;
if (dfs.startsWith("LNGINT")) return TFormat.CF_INTINT;
if (dfs.startsWith("INTINT")) return TFormat.CF_INTINT;
if (dfs.startsWith("DBLINT")) return TFormat.CF_DBLINT;
if (dfs.startsWith("XML")) return TFormat.CF_XML;
if (dfs.startsWith("CHAR")) return TFormat.CF_TEXT;
if (dfs.startsWith("INT")) return TFormat.CF_LONG;
if (dfs.startsWith("BOOLEAN")) return TFormat.CF_BOOLEAN;
if (dfs.startsWith("AIMAGE")) return TFormat.CF_AIMAGE;
if (dfs.startsWith("IMAGE")) return TFormat.CF_IMAGE;
if (dfs.startsWith("HISTORY")) return TFormat.CF_HISTORY;
if (dfs.compareToIgnoreCase("STRING") == 0) return TFormat.CF_STRING;
if (dfs.compareToIgnoreCase("KEYVALUE") == 0) return TFormat.CF_KEYVALUE;
if (dfs.startsWith("MDA")) return TFormat.CF_MDA;
return TFormat.CF_NULL;
}
public static final int IMAGE_STD_FRAMESIZE = 500000;
public static final int SPECTRUM_STD_SIZE = 4096;
public static final int STRING_STD_CAPACITY = 128;
/**
* Returns the size in bytes of a given format type
* @param tag is the format string representation
* @return the carried format size in bytes.
*/
public static int getCarriedFormatSize(String tag)
{ // used with format type CF_HISTORY and CF_MDA
short fmt = getFormatCode(tag);
switch (fmt)
{
case CF_NULL:
int siz = TStructRegistry.getSizeInBytes(tag);
if (siz > 0) return siz;
break;
case CF_STRUCT:
case CF_HISTORY: // a HISTORY or MDA call carrying an itself?
case CF_MDA:
break;
case CF_IMAGE:
return IMAGE_HDR_SIZE + IMAGE_STD_FRAMESIZE;
case CF_SPECTRUM:
return SPECTRUM_HDR_SIZE + SPECTRUM_STD_SIZE;
default:
return formatSizeOf(fmt);
}
return -TErrorList.illegal_format;
}
/**
* @param fmt is the targeted format as a short integer
* @return a TFormat object representation of the input format
*/
public static TFormat valueOf(short fmt)
{
return new TFormat(fmt);
}
private short value;
/**
* Creates new instance of TFormat.
*/
private TFormat(short val)
{
value = val;
}
/**
* Returns short value for format enum.
*
* @return short value for format enum
*/
public short getValue()
{
return value;
}
/**
* The string representation of this TFormat object
* @return The string representation of this TFormat
*/
public String toString()
{
return toString(value);
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof TFormat)) return false;
return ((TFormat)obj).getValue() == getValue();
}
}