diff options
author | tradke <tradke@21a6bef8-4479-4f54-8f8d-0db94a2919ef> | 2000-09-13 13:49:13 +0000 |
---|---|---|
committer | tradke <tradke@21a6bef8-4479-4f54-8f8d-0db94a2919ef> | 2000-09-13 13:49:13 +0000 |
commit | 8fe367ecf2cbda79960a68a052fdb84916427c0e (patch) | |
tree | 45c017765ab7f0eb6caf97540fc76ffd3bffba59 /src/WildWriter.hh | |
parent | c490022d592551af7c29bc960cbbc09daf45972d (diff) |
Importing latest stuff from development repository
git-svn-id: http://svn.cactuscode.org/arrangements/CactusExternal/FlexIO/trunk@2 21a6bef8-4479-4f54-8f8d-0db94a2919ef
Diffstat (limited to 'src/WildWriter.hh')
-rw-r--r-- | src/WildWriter.hh | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/WildWriter.hh b/src/WildWriter.hh new file mode 100644 index 0000000..a391ea3 --- /dev/null +++ b/src/WildWriter.hh @@ -0,0 +1,142 @@ +#ifndef __WILDWRITER_HH_ +#define __WILDWRITER_HH_ + +#include <IO.hh> +#include <IEEEIO.hh> +#include <FlexArrayTmpl.H> + +#define DISKBLOCKSIZE 8192 +#define BLOCKSIZE 2*DISKBLOCKSIZE + +// Does not assume contiguous data (writes in chunks) +class WildWriterB { + IObase &file; + int nnodes,ncells,ncomp; + char buffer[BLOCKSIZE]; // could dynamically allocate + FlexArray<char> compnames; + int totalcomp; + IObase::DataType comptype; + FlexArray<int> compsizes; + int bufferindex,masterindex,segsize; +public: + WildWriterB(IObase &descriptor):file(descriptor){ + } + ~WildWriterB(){} + void beginDataset(int numnodes, + int numcells, + IObase::DataType datacomponenttype, + int numdatacomponents, + int *componentsizes, + char *componentnames, + char componentnameseparator); + + void beginNodes(int numnodes); + void beginNodes(); + inline void addNode(float *coords){ + // attrib WildNode[%u] (should buffer internally) + // but we can only chunk on Datasets :( + // so collect data in 8k buffers + //checkMode(WriteNodes); + float *copyptr=(float *)buffer; + // copy into master buffer. + int index=bufferindex*3; + for(int i=0;i<3;i++) copyptr[index+i]=coords[i]; + bufferindex++; + masterindex++; + if(bufferindex>=segsize){ // dump the buffer to disk + int origin[2]={0,0},dims[2]={3,0}; + dims[1]=segsize; + origin[1]=masterindex-segsize; + file.writeChunk(dims,origin,buffer); + bufferindex=0; // reset the bufferindex for next seg + } + } + void endNodes(); + void beginCells(int numcells); + void beginCells(); + inline void addCell(int level,int *neighborlist){ + // checkMode(WriteCells); + int *copyptr=(int *)buffer; + int index=bufferindex*9; + // copy into master buffer. + copyptr[index+1]=level; + for(int i=0;i<8;i++) + copyptr[index+i+1]=neighborlist[i]; + bufferindex++; + masterindex++; + if(bufferindex>=segsize){ // dump the buffer to disk + int origin[2]={0,0},dims[2]={3,0}; + dims[1]=segsize; + origin[1]=masterindex-segsize; + file.writeChunk(dims,origin,buffer); + bufferindex=0; // reset the bufferindex for next seg + } + } + void endCells(); + void beginData(); + void beginData(IObase::DataType datacomponenttype, + int numdatacomponents, + int *componentsizes, + char *componentnames, + char componentnameseparator); + inline void addData(void *data){ + // checkMode(WriteCells); + if(comptype==IObase::Float32){ + float *copyptr=(float *)buffer; + float *dptr=(float*)data; + int index = bufferindex*totalcomp*sizeof(double); + for(int i=0;i<totalcomp;i++) copyptr[index+i]=dptr[i]; + } + else if(comptype==IObase::Float64){ + double *copyptr=(double *)buffer; + double *dptr = (double *)data; + int index = bufferindex*totalcomp*sizeof(double); + for(int i=0;i<totalcomp;i++) copyptr[index+i]=dptr[i]; + } + bufferindex++; + masterindex++; + if(bufferindex>=segsize){ // dump the buffer to disk + int origin[2]={0,0},dims[2]={0,0}; + dims[0]=totalcomp; + dims[1]=segsize; + origin[1]=masterindex-segsize; + file.writeChunk(dims,origin,buffer); + bufferindex=0; // reset the bufferindex for next seg + } + } + void endData(); + void endDataset() ; +}; + +extern "C" { +#include "WildWriter.h" +} + +#endif + +/* +// Assumes Contiguous Data +class WildWriterA { + IO &file; +public: + WildWriter(IO &descriptor):file(descriptor){ + } + ~WildWriter(){ + } + // All nodes for all levels + void writeNodes(int numnodes,float *node_coords){ + int dims[2]={3,0}; + dims[1]=numnodes; + file.write(IObase::Float32,2,dims,node_coords); + file.writeAttribute("WildNodes",IObase::Int,0,dims); + } + // Must Be Hexahedral Cells + void writeCells(int level,int ncells,int *celllist){ + + } + // Assumes Node-centered data + void writeData(char *name,IObase::DataType type,int veclen,void *data){ + + } +}; +*/ |