User Defined (Generic) Data and Objects
If you want to create data that other applications (not written by you or someone working closely with you) can read and understand, these are not the right functions to use. That is because the data that these functions create is not self-describing and inherently non-shareable.
However, if you need to write data that only you (or someone working closely with you) will read such as for restart purposes, the functions described here may be helpful. The functions described here allow users to read and write arbitrary arrays of raw data as well as to create and write or read user-defined Silo objects.
DBWrite()
Summary: Write a simple variable.
C Signature:
int DBWrite (DBfile *dbfile, char const *varname, void const *var, int const *dims, int ndims, int datatype)
Fortran Signature:
Arguments:
Arg name
Description
dbfileDatabase file pointer.
varnameName of the simple variable.
varArray defining the values associated with the variable.
dimsArray of length
ndimswhich describes the dimensionality of the variable. Each value in thedimsarray indicates the number of elements contained in the variable along that dimension.ndimsNumber of dimensions.
datatypeDatatype of the variable. One of the predefined Silo data types.
Returned value:
Returns zero on success and -1 on failure.
Description:
The
DBWritefunction writes a simple variable into a Silo file. It is not associated with any other Silo object.
DBWriteSlice()
Summary: Write a (hyper)slab of a simple variable
C Signature:
int DBWriteSlice (DBfile *dbfile, char const *varname, void const *var, int datatype, int const *offset, int cost *length, int const *stride, int const *dims, int ndims)
Fortran Signature:
integer function dbwriteslice(dbid, varname, lvarname, var, datatype, offset, length, stride, dims, ndims)
Arguments:
Arg name
Description
dbfileDatabase file pointer.
varnameName of the simple variable.
varArray defining the values associated with the slab.
datatypeDatatype of the variable. One of the predefined Silo data types.
offsetArray of
lengthndimsof offsets in each dimension of the variable. This is the 0-origin position from which to begin writing the slice.lengthArray of
lengthndimsof lengths of data in each dimension to write to the variable. All lengths must be positive.strideArray of
lengthndimsofstridesteps in each dimension. If no striding is desired, zeroes should be passed in this array.dimsArray of
lengthndimswhich describes the dimensionality of the entire variable. Each value in thedimsarray indicates the number of elements contained in the entire variable along that dimension.ndimsNumber of dimensions.
Returned value:
zero on success and -1 on failure.
Description:
The
DBWriteSlicefunction writes a slab of data to a simple variable from the data provided in thevarpointer. Any hyperslab of data may be written.The size of the entire variable (after all slabs have been written) must be known when the
DBWriteSlicefunction is called. The data in thevarparameter is written into the entire variable using the location specified in the offset, length, andstrideparameters. The data that makes up the entire variable may be written with one or more calls toDBWriteSlice.The minimum
lengthvalue is 1 and the minimumstridevalue is one.A one-dimensional array slice:
Figure 0-11: Array slice
DBReadVar()
Summary: Read a simple Silo variable.
C Signature:
int DBReadVar (DBfile *dbfile, char const *varname, void *result)
Fortran Signature:
integer function dbrdvar(dbid, varname, lvarname, ptr)
Arguments:
Arg name
Description
dbfileDatabase file pointer.
varnameName of the simple variable.
resultPointer to memory into which the variable should be read. It is up to the application to provide sufficient space in which to read the variable.
Returned value:
zero on success and -1 on failure.
Description:
The
DBReadVarfunction reads a simple variable into the given space.See
DBGetVarfor a memory-allocating version of this function.
DBReadVarSlice()
Summary: Read a (hyper)slab of data from a simple variable.
C Signature:
int DBReadVarSlice (DBfile *dbfile, char const *varname, int const *offset, int const *length, int const *stride, int ndims, void *result)
Fortran Signature:
integer function dbrdvarslice(dbid, varname, lvarname, offset, length, stride, ndims, ptr)
Arguments:
Arg name
Description
dbfileDatabase file pointer.
varnameName of the simple variable.
offsetArray of
lengthndimsof offsets in each dimension of the variable. This is the 0-origin position from which to begin reading the slice.lengthArray of
lengthndimsof lengths of data in each dimension to read from the variable. All lengths must be positive.strideArray of
lengthndimsofstridesteps in each dimension. If no striding is desired, zeroes should be passed in this array.ndimsNumber of dimensions in the variable.
resultPointer to location where the slice is to be written. It is up to the application to provide sufficient space in which to read the variable.
Returned value:
zero on success and -1 on failure.
Description:
The
DBReadVarSlicefunction reads a slab of data from a simple variable into a location provided in theresultpointer. Any hyperslab of data may be read.Note that the minimum
lengthvalue is 1 and the minimumstridevalue is one.A one-dimensional array slice:
Figure 0-12: Array slice
DBGetVar()
Summary: Allocate space for, and return, a simple variable.
C Signature:
void *DBGetVar (DBfile *dbfile, char const *varname)
Fortran Signature:
NoneArguments:
Arg name
Description
dbfileDatabase file pointer.
varnameName of the variable
Returned value:
A pointer to newly allocated and populated memory on success and
NULLon failure.Description:
The
DBGetVarfunction allocates space for a simple variable, reads the variable from the Silo database, and returns a pointer to the new space. If an error occurs,NULLis returned. It is up to the application to cast the returned pointer to the correct data type.See
DBReadVarfor non-memory allocating versions of this function.
DBInqVarExists()
Summary: Queries variable existence
C Signature:
int DBInqVarExists (DBfile *dbfile, char const *name);
Fortran Signature:
NoneArguments:
Arg name
Description
dbfileDatabase file pointer.
nameObject name.
Returned value:
DBInqVarExists returns non-zero if the object exists in the file. Zero otherwise.
Description:
The
DBInqVarExistsfunction is used to check for existence of an object in the given file.If an object was written to a file, but the file has yet to be DBClose’d, the results of this function querying that variable are undefined.
DBInqVarType()
Summary: Return the type of the given object
C Signature:
DBObjectType DBInqVarType (DBfile *dbfile, char const *name);
Fortran Signature:
NoneArguments:
Arg name
Description
dbfileDatabase file pointer.
nameObject
name.Returned value:
Returns the DBObjectType corresponding to the given object.
Description:
The
DBInqVarTypefunction returns theDBObjectTypeof the given object. The value returned is described in the following table:Object Type
Returned Value
Invalid or object not found
DB_INVALID_OBJECTQuadmesh
DB_QUADMESHQuadvar
DB_QUADVARUCD mesh
DB_UCDMESHUCD variable
DB_UCDVARCSG mesh
DB_CSGMESHCSG variable
DB_CSGVARMultiblock mesh
DB_MULTIMESHMultiblock variable
DB_MULTIVARMultiblock material
DB_MULTIMATMultiblock material species
DB_MULTIMATSPECIESMaterial
DB_MATERIALMaterial species
DB_MATSPECIESFacelist
DB_FACELISTZonelist
DB_ZONELISTPolyhedral-Zonelist
DB_PHZONELISTCSG-Zonelist
DB_CSGZONELISTEdgelist
DB_EDGELISTCurve
DB_CURVEPointmesh
DB_POINTMESHPointvar
DB_POINTVARDefvars
DB_DEFVARSCompound array
DB_ARRAYDirectory
DB_DIROther variable (one written out using
DBWrite.)DB_VARIABLEUser-defined
DB_USERDEF
DBGetVarByteLength()
Summary: Return the memory byte length of a simple variable.
C Signature:
int DBGetVarByteLength(DBfile *dbfile, char const *varname)
Fortran Signature:
NoneArguments:
Arg name
Description
dbfileDatabase file pointer.
varnameVariable name.
Returned value:
The length of the given simple variable in bytes on success and -1 on failure.
Description:
The
DBGetVarByteLengthfunction returns the memory length of the requested simple variable, in bytes. This is useful for determining how much memory to allocate before reading a simple variable withDBReadVar. Note that this would not be a concern if one used theDBGetVarfunction, which allocates space itself.
DBGetVarByteLengthInFile()
Summary: Get the file length of a simple variable
C Signature:
DBGetVarByteLengthInFile(DBfile *file, char const *name)
Fortran Signature:
NoneArguments:
Arg name
Description
dbfileThe silo database file handle
nameName of a simple variable in the file
Returned value:
Length of variable in file on success; -1 on failure.
Description:
Sometimes, the length of a variable in a file may be different from its length in memory. This is especially true if type conversion is performed on the variable when it is being read or when compression is applied. This function returns the number of bytes the variable takes up in the file.
DBGetVarDims()
Summary: Get dimension information of a variable in a Silo file
C Signature:
int DBGetVarDims(DBfile *file, const char const *name, int maxdims, int *dims)
Fortran Signature:
NoneArguments:
Arg name
Description
fileThe Silo database
filehandle.nameThe
nameof the Silo object to obtain dimension information for.maxdimsThe maximum size of
dims.dimsAn array of
maxdimsinteger values to be populated with the dimension information returned by this call.Returned value:
The number of dimensions on success; -1 on failure
Description:
This function will populate the
dimsarray up to a maximum ofmaxdimsvalues with dimension information of the specified Silo variable (object)name. The number of dimensions is returned as the function’s return value.
DBGetVarLength()
Summary: Return the number of elements in a simple variable.
C Signature:
int DBGetVarLength (DBfile *dbfile, char const *varname)
Fortran Signature:
integer function dbinqlen(dbid, varname, lvarname, len)
Arguments:
Arg name
Description
dbfileDatabase file pointer.
varnameVariable name.
Returned value:
The number of elements in the given simple variable on success and -1 on failure.
Description:
The
DBGetVarLengthfunction returns the length of the requested simple variable, in number of elements. For example a 16 byte array containing 4 floats has 4 elements.
DBGetVarType()
Summary: Return the Silo datatype of a simple variable.
C Signature:
int DBGetVarType (DBfile *dbfile, char const *varname)
Fortran Signature:
NoneArguments:
Arg name
Description
dbfileDatabase file pointer.
varnameVariable name.
Returned value:
The Silo
DBdatatypeof the given simple variable on success and -1 on failure.Description:
The
DBGetVarTypefunction returns the SiloDBdatatypeof the requested simple variable. This works only for simple Silo variables (those written usingDBWriteorDBWriteSlice). To query the type of other variables, useDBInqVarTypeinstead.
DBPutCompoundarray()
Summary: Write a Compound Array object into a Silo file.
C Signature:
int DBPutCompoundarray (DBfile *dbfile, char const *name, char const * const elemnames[], int const *elemlengths, int nelems, void const *values, int nvalues, int datatype, DBoptlist const *optlist);
Fortran Signature:
integer function dbputca(dbid, name, lname, elemnames, lelemnames, elemlengths, nelems, values, datatype, optlist_id, status)
character*N elemnames (See
dbset2dstrlen.)Arguments:
Arg name
Description
dbfileDatabase file pointer
nameName of the compound array structure.
elemnamesArray of length
nelemscontaining pointers to the names of the elements.elemlengthsArray of length
nelemscontaining the lengths of the elements.nelemsNumber of simple array elements.
valuesArray whose length is determined by
nelemsandelemlengthscontaining thevaluesof the simple array elements.nvaluesTotal length of the
valuesarray.datatypeData type of the
valuesarray. One of the predefined Silo types.optlistPointer to an option list structure containing additional information to be included in the compound array object written into the Silo file. Use
NULLis there are no options.Returned value:
DBPutCompoundarray returns zero on success and -1 on failure.
Description:
The
DBPutCompoundarrayfunction writes a compound array object into a Silo file. A compound array is an array whose elements are simple arrays all of which are the sameDBdatatype.Often, an application will partition a block of memory into named pieces, but write the block to a database as a single entity. Fortran common blocks are used in this way. The compound array object is an abstraction of this partitioned memory block.
DBInqCompoundarray()
Summary: Inquire Compound Array attributes.
C Signature:
int DBInqCompoundarray (DBfile *dbfile, char const *name, char ***elemnames, int *elemlengths, int *nelems, int *nvalues, int *datatype)
Fortran Signature:
integer function dbinqca(dbid, name, lname, maxwidth, nelems, nvalues, datatype)
Arguments:
Arg name
Description
dbfileDatabase file pointer.
nameName of the compound array.
elemnamesReturned array of length
nelemscontaining pointers to the names of the array elements.elemlengthsReturned array of length
nelemscontaining the lengths of the array elements.nelemsReturned number of array elements.
nvaluesReturned number of total values in the compound array.
datatypeDatatype of the data values. One of the predefined Silo data types.
Returned value:
Zero on success and -1 on failure.
Description:
The
DBInqCompoundarrayfunction returns information about the compound array. It does not return the data values themselves; useDBGetCompoundarrayinstead.
DBGetCompoundarray()
Summary: Read a compound array from a Silo database.
C Signature:
DBcompoundarray *DBGetCompoundarray (DBfile *dbfile, char const *arrayname)
Fortran Signature:
integer function dbgetca(dbid, name, lname, lelemnames, elemnames, elemlengths, nelems, values, nvalues, datatype)
Arguments:
Arg name
Description
dbfileDatabase file pointer.
arraynameName of the compound array.
Returned value:
A pointer to a
DBcompoundarraystructure on success andNULLon failure.Description:
The
DBGetCompoundarrayfunction allocates aDBcompoundarraystructure, reads a compound array from the Silo database, and returns a pointer to that structure. If an error occurs,NULLis returned.
DBMakeObject()
Summary: Allocate an object of the specified length and initialize it.
C Signature:
DBobject *DBMakeObject (char const *objname, int objtype, int maxcomps)
Fortran Signature:
NoneArguments:
Arg name
Description
objnameName of the object.
objtypeType of object. One of the predefined
DBObjectTypetypes.maxcompsInitial maximum number of components needed for this object. If this number is exceeded, the library will silently re-allocate more space using the golden rule.
Returned value:
DBMakeObject returns a pointer to the newly allocated and initialized Silo object on success and
NULLon failure.Description:
The
DBMakeObjectfunction allocates space for an object ofmaxcompscomponents.In releases of the Silo library prior to 4.10, if a
DBobjectever had more components added to it than themaxcompsit was created with, an error would be generated and the operation to add a component would fail. However, starting in version 4.10, themaxcompsargument is used only for the initial object creation. If a caller attempts to add more than this number of components to an object, Silo will simply re-allocate the object to accommodate the additional components.Data producers may use this method to either modify an existing Silo object type or create an empty, new user-defined object using the type
DB_USERDEF. Modified Silo objects will be recognized by Silo as long as they are not modified in ways that remove essential data members. Data producers may add data members to Silo objects and those objects will still behave as those Silo objects. However, obtaining any user-defined members of such an object may require reading the object via theDBGetObjectmethod instead of the formal Silo method for the object (e.g.DBGetUcdmeshfor aDB_UCDMESHtype object).
DBFreeObject()
Summary: Free memory associated with an object.
C Signature:
int DBFreeObject (DBobject *object)
Fortran Signature:
NoneArguments:
Arg name
Description
objectPointer to the
objectto be freed. Thisobjectis created with theDBMakeObjectfunction.Returned value:
zero on success and -1 on failure.
Description:
The
DBFreeObjectfunction releases the memory associated with the givenobject. The data associated with the object’s components is not released.DBFreeObjectwill not fail if aNULLpointer is passed to it.
DBChangeObject()
Summary: Overwrite an existing object in a Silo file with a new object
C Signature:
int DBChangeObject(DBfile *file, DBobject *obj)
Fortran Signature:
NoneArguments:
Arg name
Description
fileThe Silo database
filehandle.objThe new
DBobjectobject (which knows its name) to write to thefile.Returned value:
Zero on success; -1 on failure
Description:
DBChangeObjectwrites a newDBobjectobject to a file, replacing the object in thefilewith the same name. Changing (e.g. overwriting) existing objects in Silo files is fraught with peril. SeeDBSetAllowOverwritesfor more information.
DBClearObject()
Summary: Clear an object.
C Signature:
int DBClearObject (DBobject *object)
Fortran Signature:
NoneArguments:
Arg name
Description
objectPointer to the
objectto be cleared. Thisobjectis created with theDBMakeObjectfunction.Returned value:
Zero on success and -1 on failure.
Description:
The
DBClearObjectfunction clears an existingobject. The number of components associated with theobjectis set to zero.
DBAddDblComponent()
Summary: Add a double precision floating point component to an object.
C Signature:
int DBAddDblComponent (DBobject *object, char const *compname, double d)
Fortran Signature:
NoneArguments:
Arg name
Description
objectPointer to an
object. Thisobjectis created with theDBMakeObjectfunction.compnameThe component name.
dThe value of the double precision floating point component.
Returned value:
Zero on success and -1 on failure.
Description:
The
DBAddDblComponentfunction adds a component of double precision floating point data to an existing object.
DBAddFltComponent()
Summary: Add a floating point component to an object.
C Signature:
int DBAddFltComponent (DBobject *object, char const *compname, double f)
Fortran Signature:
NoneArguments:
Arg name
Description
objectPointer to an
object. Thisobjectis created with theDBMakeObjectfunction.compnameThe component name.
fThe value of the floating point component.
Returned value:
Zero on success and -1 on failure.
Description:
The
DBAddFltComponentfunction adds a component of floating point data to an existing object.
DBAddIntComponent()
Summary: Add an integer component to an object.
C Signature:
int DBAddIntComponent (DBobject *object, char const *compname, int i)
Fortran Signature:
NoneArguments:
Arg name
Description
objectPointer to an
object. Thisobjectis created with theDBMakeObjectfunction.compnameThe component name.
iThe value of the integer component.
Returned value:
Zero on success and -1 on failure.
Description:
The
DBAddIntComponentfunction adds a component of integer data to an existing object.
DBAddStrComponent()
Summary: Add a string component to an object.
C Signature:
int DBAddStrComponent (DBobject *object, char const *compname, char const *s)
Fortran Signature:
NoneArguments:
Arg name
Description
objectPointer to the
object. Thisobjectis created with theDBMakeObjectfunction.compnameThe component name.
sThe value of the string component. Silo copies the contents of the string.
Returned value:
Zero on success and -1 on failure.
Description:
The
DBAddStrComponentfunction adds a component of string data to an existing object.
DBAddVarComponent()
Summary: Add a variable component to an object.
C Signature:
int DBAddVarComponent (DBobject *object, char const *compname, char const *vardata)
Fortran Signature:
NoneArguments:
Arg name
Description
objectPointer to the
object. Thisobjectis created with theDBMakeObjectfunction.compnameComponent name.
vardataName of the variable
objectassociated with the component (see Description).Returned value:
Zero on success and -1 on failure.
Description:
The
DBAddVarComponentfunction adds a component of the variable type to an existing object.The variable name in
vardatais stored verbatim into the object. No translation or typing is done on the variable as it is added to the object.
DBWriteComponent()
Summary: Add a variable component to an object and write the associated data.
C Signature:
int DBWriteComponent (DBfile *dbfile, DBobject *object, char const *compname, char const *prefix, char const *datatype, void const *var, int nd, long const *count)
Fortran Signature:
NoneArguments:
Arg name
Description
dbfileDatabase file pointer.
objectPointer to the
object.compnameComponent name.
prefixPath name
prefixof theobject.datatypeData type of the component’s data. One of: “short”, “integer”, “long”, “float”, “double”, “char”.
varPointer to the component’s data.
ndNumber of dimensions of the component.
countAn array of length
ndcontaining the length of the component in each of its dimensions.Returned value:
Zero on success and -1 on failure.
Description:
The
DBWriteComponentfunction adds a component to an existing object and also writes the component’s data to a Silo file.
DBWriteObject()
Summary: Write an object into a Silo file.
C Signature:
int DBWriteObject (DBfile *dbfile, DBobject const *object, int freemem)
Fortran Signature:
NoneArguments:
Arg name
Description
dbfileDatabase file pointer.
objectObject created with
DBMakeObjectand populated with DBAddFltComponent, DBAddIntComponent, DBAddStrComponent, andDBAddVarComponent.freememIf non-zero, then the
objectwill be freed after writing.Returned value:
Zero on success and -1 on failure.
Description:
The
DBWriteObjectfunction writes an object into a Silo file. This method may be used to write any of Silo’s known, high-level Objects. This method is more often used to write user-defined objects. They are used when the basic Silo structures are not sufficient.
DBGetObject()
Summary: Read an object from a Silo file as a generic object
C Signature:
DBobject *DBGetObject(DBfile *file, char const *objname)
Fortran Signature:
NoneArguments:
Arg name
Description
fileThe Silo database
filehandle.objnameThe name of the object to get.
Returned value:
On success, a pointer to a
DBobjectstruct containing the object’s data.NULLon failure.Description:
Each of the objects Silo supports has corresponding methods to both write them to a Silo database file via
DBPutXxxand get them from a file viaDBGetXxx.However, Silo objects can also be accessed as generic objects through the generic object interface. This is recommended only for objects that were written with
DBWriteObject()method.
DBGetComponent()
Summary: Allocate space for, and return, an object component.
C Signature:
void *DBGetComponent (DBfile *dbfile, char const *objname, char const *compname)
Fortran Signature:
NoneArguments:
Arg name
Description
dbfileDatabase file pointer.
objnameObject name.
compnameComponent name.
Returned value:
A pointer to newly allocated space containing the component value on success, and
NULLon failure.Description:
The
DBGetComponentfunction allocates space for one object component, reads the component, and returns a pointer to that space. If either the object or component does not exist,NULLis returned. It is up to the application to cast the returned pointer to the appropriate type.
DBGetComponentType()
Summary: Return the type of an object component.
C Signature:
int DBGetComponentType (DBfile *dbfile, char const *objname, char const *compname)
Fortran Signature:
NoneArguments:
Arg name
Description
dbfileDatabase file pointer.
objnameObject name.
compnameComponent name.
Returned value:
The values that are returned depend on the component’s type and how the component was written into the object. The component types and their corresponding return values are listed in the table below.
Component Type
Return value
intDB_INTfloatDB_FLOATdoubleDB_DOUBLEchar*DB_CHARvariable
DB_VARIABLEeverything else
DB_NOTYPEDescription:
The
DBGetComponentTypefunction reads the component’s type and returns it. If either the object or component does not exist,DB_NOTYPEis returned. This function allows the application to process the component without having to know its type in advance.