diff options
Diffstat (limited to 'src/AMRPlus')
27 files changed, 2589 insertions, 0 deletions
diff --git a/src/AMRPlus/AMRPlusConv.C b/src/AMRPlus/AMRPlusConv.C new file mode 100644 index 0000000..7785342 --- /dev/null +++ b/src/AMRPlus/AMRPlusConv.C @@ -0,0 +1,168 @@ +// generated by Fast Light User Interface Designer (fluid) version 1.00 + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <iostream.h> +#include "IEEEIO.hh" +#include "AmrFileReader.hh" +#include "AMRwriterPlus.h" +#include "AMRgridPlus.h" + + + +int main(int argc, char** argv) { + IObase *ifile, *ofile; + AMRwriterPlus *writer; + AmrGridReader *reader; + AmrFileReader *freader; + int maxlev; + + if (argc!=2){ + cerr<<"Usage: addscalars <filename>"<<endl; + exit(0); + } + char *fname=strdup(argv[1]); + ifile=new IEEEIO(fname, IObase::Read); + if (!ifile->isValid()){ + cerr<<fname<<" is not a valid IEEEIO file."<<endl; + exit(0); + } + + freader=new AmrFileReader(*ifile); + maxlev=freader->nLevels(); + + reader=new AmrGridReader(*ifile); + if (reader==NULL){ + cerr<<fname<<" is not a valid AMR file."<<endl; + exit(0); + } + char *outname=(char *)malloc(strlen(fname)+5); + strcpy(outname, fname); + strcat(outname, "plus"); + + ofile=new IEEEIO(outname, IObase::Create); + if (!ofile->isValid()){ + cerr<<"Cannot create "<<outname<<" for output."<<endl; + exit(0); + } + writer = new AMRwriterPlus(*ofile); + if (writer==NULL){ + cerr<<"Something is fishy in denmark. (i.e. at line "<<__LINE__<<")"<<endl; + exit(0); + } + + + AMRgridPlus grid; + // unsigned long numgrids=reader->getNumGrids(); + unsigned long datasz; + + + //prime things: + reader->getGridInfo(grid, 0); + grid.data=malloc(grid.nbytes); + datasz=grid.nbytes; + FlexArray< AmrGrid> gridlist; + + + int tmin, tmax; + int numlev = freader->getNumLevels(); + FlexArray<int> levmask; + int lcnt=numlev, tflag=2, tstep=0; + double t1, t2, tdiff=0, finetimeref=1.0; + int ts1; + levmask.setSize(numlev); + for(int ii=0;ii<numlev;ii++) levmask[ii]=0; + int idx=0; + int fixtime=0, fixtimeval; + AmrGrid *tgrid; + while ( (tgrid=reader->getGridInfo(grid, idx))!=NULL && (lcnt || tflag)){ + IObase::DataType atype; + int length; + int attrnum; + + if ((grid.level==0) && tflag){ + //Getll the time of root grid... + double tm; + attrnum=ifile->readAttributeInfo("time",atype,length); + if(attrnum>=0) ifile->readAttribute(attrnum,&tm); + if (tflag==2){ + t1=tm; + ts1=grid.timestep; + tflag=1; + } else { //tflag==1; + t2=tm; + tdiff=(t2-t1)/(grid.timestep-(float)ts1); + tstep=grid.timestep; + if (tdiff!=0) tflag=0; + } + + } + //If this is a level we havent already seen... + if (levmask[grid.level]==0){ + //Get all the refinement info... + attrnum=ifile->readAttributeInfo("time_refinement",atype,length); + if(attrnum>=0){ + ifile->readAttribute(attrnum,&(grid.timeref)); + } + attrnum=ifile->readAttributeInfo("spatial_refinement",atype,length); + if(attrnum>=0){ + ifile->readAttribute(attrnum,&(grid.spaceref)); + } + attrnum=ifile->readAttributeInfo("grid_placement_refinement",atype,length); + if(attrnum>=0){ + ifile->readAttribute(attrnum,&(grid.placeref)); + } + //feed the refinement info to the writer... + writer->setLevelRefinement(grid.level, + grid.timeref, grid.spaceref, grid.placeref); + //and mark the level as done. + + if (grid.level==numlev-1)finetimeref=grid.timeref; + levmask[grid.level]=1; + lcnt--; + } + idx++; + } + tdiff/=finetimeref; + + //Coarse steps should be composed of + if (finetimeref!=tstep &&(tstep!=0)){ + cout<<"Mismatch between max time refinement and timesteps"<<endl; + cout<<"Timeref="<<finetimeref<<" | Coarse step="<<tstep<<endl; + cout<<"Should I adjust: (C)oarse timestep, or "<<endl; + cout<<"should I (I)gnore it?"<<endl; + char c=cin.get(); + if (c=='C' || c=='c') fixtime=1; + fixtimeval=tstep/finetimeref; + } + + freader->getTimeRange(tmin, tmax); + ii=0; + + tgrid=reader->getGridInfo(grid, 0); + writer->setType((IObase::DataType)grid.datatype); + writer->setTopLevelParameters(grid.rank, grid.origin, grid.delta, tdiff, maxlev); + + + while (tgrid!=NULL){ + if (grid.nbytes>datasz) { + datasz=grid.nbytes; + grid.data=realloc(grid.data, datasz); + } + reader->getGridData(grid, ii); + if (fixtime) grid.timestep/=fixtimeval; + + + + writer->write(&grid, 1); //calc scalars & write + ii++; + tgrid=reader->getGridInfo(grid, ii); + + } + delete ifile; + delete ofile; + + +} diff --git a/src/AMRPlus/AMRTree.C b/src/AMRPlus/AMRTree.C new file mode 100644 index 0000000..9ab86d1 --- /dev/null +++ b/src/AMRPlus/AMRTree.C @@ -0,0 +1,27 @@ +#include "AMRTree.h" + +void AMRNode::AMRNode(AMRgridPlus *first){ + subtimes.setsize(first->timeref) +} +void AMRNode::buildtree(AMRTree *t, int &idx){ + AMRgridPlus *g=grids.getData+idx; + int clev=g->level; + int ctime=c->time; + while (g->level==clev && g->time=ctime){ + idxs.append(idx); + idx++; + } +} + + +AMRTree::AMRTree(GridArray *g): timenode{ + int numlevs=g[0].maxlevel+1; + int timeref=g[0].timerefinement; + int coarsestep=timeref<<numlevs-1; + grids=g; + + for (int ii=0;ii<g.getSize();ii++){ + + + } +} diff --git a/src/AMRPlus/AMRTree.h b/src/AMRPlus/AMRTree.h new file mode 100644 index 0000000..420d4e7 --- /dev/null +++ b/src/AMRPlus/AMRTree.h @@ -0,0 +1,35 @@ +#ifndef AMR_TREE_H +#define AMR_TREE_H +#include "FlexArrayTempl.H" +#include "AMRgridPlus.h" + +struct idxrec { + int idx; + int datastat; +}; + +typedef FlexArray<int> IntArray; + +typedef FlexArray<AMRgridPlus> GridArray + +typedef FlexArray<idxrec> IdxArray; + +class AMRTree; +struct AMRNode{ + IdxArray idxs; + AMRTree subtimes; +}; + +class AMRTree: protected FlexArray<AMRNode>{ + void buildtree(AMRTree *t, int &idx); + public: + AMRTree(GridArray *); + ~AMRTree(); + + private: + AMRNode timenode; + GridArray grids; +}; + + +#endif diff --git a/src/AMRPlus/AMRfilereaderPlus.C b/src/AMRPlus/AMRfilereaderPlus.C new file mode 100644 index 0000000..17d0e45 --- /dev/null +++ b/src/AMRPlus/AMRfilereaderPlus.C @@ -0,0 +1,175 @@ +#include <stdio.h> +#include <stdlib.h> +#include "AMRfilereaderPlus.h" +#include "FlexArrayTmpl.H" +void AMRfilereaderPlus::printGridInfo(AMRgridPlus &g){ + printf("Grid level=%u step=%u maxtime=%u\n",g.level,g.timestep,g.maxtime); + printf("\trank=%u dims[",g.rank); + for(int i=0;i<g.rank-1;i++) printf("%u,",g.dims[i]); + printf("%u]\n",g.dims[g.rank-1]); + printf("\tTimerefine=%u dx[0]=%lf origin[",g.timerefinement,g.delta[0]); + for(i=0;i<g.rank-1;i++) printf("%lf,",g.origin[i]); + printf("%lf]\n",g.origin[g.rank-1]); + printf("\tData Pointer is %u\n",(unsigned long)(g.data)); + if(g.data){ + float *fdata = (float *)(g.data); + for(int i=0;i<3;i++) + printf("\t\tData[%u]=%f\n",i,fdata[i]); + } + } + void AMRfilereaderPlus::printGridInfo(){ + // print it all out... + printf("MaxLevel=%u\n",maxlevel); + for(int i=0;i<grids.getSize();i++){ + printf("Grid[%u]--------------------\n",i); + printGridInfo(grids[i]); + } + } + void AMRfilereaderPlus::printActiveGrids(){ + // print it all out... + printf("Num Active Grids=%u\n",activeGrids.getSize()); + for(int i = 0; i < activeGrids.getSize(); i++){ + printf(" Grid[%u] mapped from %u --------------------\n", + i,activeGrids[i]); + printGridInfo(grids[activeGrids[i]]); + } + } +#define MAXIMIZE(u, v) {(u)=((u)>(v))?(u):(v);} +#define MINIMIZE(u, v) {(u)=((u)<(v))?(u):(v);} + +void AMRfilereaderPlus::buildInfoTable(){ + // Load all grids Info + int index=0; + AMRgridPlus g; + while(getGridInfo(g,index++)){ + if(this->debug) printf("buildInfoTable: getGrid index=%u\n",index); + if(this->debug) printGridInfo(g); + int i=grids.getSize(); + g.data=0; // zero out the data + if(g.level>maxlevel) + maxlevel=g.level; + if(!i){ + smin=g.scalarmin; + smax=g.scalarmax; + mintime = g.timestep; + maxtime = g.timestep; + maxtimeres = g.timerefinement; + maxlevel= g.level; + bounds[0]=g.origin[0]; + bounds[1]=g.origin[0]+g.delta[0]*g.dims[0]; + bounds[2]=g.origin[1]; + bounds[3]=g.origin[1]+g.delta[1]*g.dims[1]; + bounds[4]=g.origin[2]; + bounds[5]=g.origin[2]+g.delta[2]*g.dims[2]; + } + else{ + MINIMIZE(smin, g.scalarmin); + MAXIMIZE(smax, g.scalarmax); + if (g.level==0){ + MINIMIZE(bounds[0], g.origin[0]); + MAXIMIZE(bounds[1], g.origin[0]+g.delta[0]*g.dims[0]); + MINIMIZE(bounds[2], g.origin[1]); + MAXIMIZE(bounds[3], g.origin[1]+g.delta[1]*g.dims[1]); + MINIMIZE(bounds[4], g.origin[2]); + MAXIMIZE(bounds[5], g.origin[2]+g.delta[2]*g.dims[2]); + } + } + if(g.timestep<mintime) + mintime=g.timestep; + if(g.timestep>maxtime) + maxtime=g.timestep; + if(g.timerefinement>maxtimeres) + maxtimeres=g.timerefinement; + grids.append(g); + } +} + +void AMRfilereaderPlus::loadGrids(){ + if(!gridloading) return; + for(int i=0;i<activeGrids.getSize();i++){ + if(this->debug) printf("buildInfoTable: getGrid index=%u activegridindex %u\n",i,activeGrids[i]); + if(this->debug) printGridInfo(grids[activeGrids[i]]); + getGridData(grids[activeGrids[i]],activeGrids[i]); + } +} + +void AMRfilereaderPlus::reclaimGrids(){ + if(!gridloading) return; + for(int i=0;i<grids.getSize();i++){ + int f=0; + for(int j=0;j<activeGrids.getSize();j++){ + if(activeGrids[j]==i){ + f=1; + break; + } + } + if(!f){ + free((grids[i]).data); + (grids[i]).data=0; + } + } +} + +void AMRfilereaderPlus::purgeGrids(){ + for(int i=0;i<grids.getSize();i++){ + if((grids[i]).data) + free((grids[i]).data); + (grids[i]).data=0; + } +} + +AMRfilereaderPlus::AMRfilereaderPlus(IObase &f):AMRgridreaderPlus(f),debug(0),gridloading(1){ + // we need to build a table from the file + // then select grids based on the timestep + buildInfoTable(); // initialize the convertor + levelmask.setSize(maxlevel+1); + for(int i=0;i<=maxlevel;i++) + levelmask[i]=1; // all levels visible is default + showAllLevels(); + setTime(mintime); +} + +void AMRfilereaderPlus::setTime(int timestep){ + // Make Grid Selections + if(timestep<mintime || timestep>maxtime){ + printf("timestep %u is out of range %u:%u\n", + timestep,mintime,maxtime); + return; + } + activeGrids.purge(); + current_time=timestep; + if(this->debug) printf("setTime(%u): mintime=%u maxtime=%u\n",current_time,mintime,maxtime); + for(int i=0;i<grids.getSize();i++){ + if(this->debug) printf("\tgrids[%u].timestep=%u maxtime=%u\n",i,grids[i].timestep, + grids[i].maxtime); + if(current_time>=grids[i].timestep && + current_time<grids[i].maxtime && levelmask[grids[i].level]){ + activeGrids.append(i); + if(this->debug) printf("\t\tAppendGrid number %u\n",i); + } + } + if(this->debug) puts("load grids"); + loadGrids(); + if(this->debug) puts("reclaim grids"); + reclaimGrids(); +} + +void AMRfilereaderPlus::showAllLevels(){ + for(int i=0;i<levelmask.getSize();i++) levelmask[i]=1; +} + +// For C interface + +int AMRfilereaderPlus::getGrids(AMRgridPlus *g){ // assumes number of + for(int i=0;i<grids.getSize();i++) + g[i]=grids[activeGrids[i]]; + return activeGrids.getSize(); +} + +// For C++ interface +int AMRfilereaderPlus::getGrids(FlexArray<AMRgridPlus> &g){ + g.setSize(activeGrids.getSize()); + for(int i=0;i<g.getSize();i++) + g[i]=grids[activeGrids[i]]; + return activeGrids.getSize(); +} diff --git a/src/AMRPlus/AMRfilereaderPlus.h b/src/AMRPlus/AMRfilereaderPlus.h new file mode 100644 index 0000000..a90569d --- /dev/null +++ b/src/AMRPlus/AMRfilereaderPlus.h @@ -0,0 +1,74 @@ +// AmrFileReader +#ifndef __AMRFILEREADERPLUS_HH_ +#define __AMRFILEREADERPLUS_HH_ +#include <stdio.h> +#include <IO.hh> +#include "AMRgridreaderPlus.h" +#include "FlexArrayTmpl.H" + +class AMRfilereaderPlus : public AMRgridreaderPlus { +protected: + int gridloading; + FlexArray<int> activeGrids; + FlexArray<AMRgridPlus> grids; + FlexArray<int> levelmask; + IObase::DataType datatype; + int maxlevel,maxtimeres,mintime,maxtime; + double smax, smin; + double bounds[6]; + int current_time; + // Internal Utility methods + void buildInfoTable(); + void loadGrids(); + void reclaimGrids(); + void purgeGrids(); + void printGridInfo(AMRgridPlus &g); +public: + int debug; + void printGridInfo(); + void printActiveGrids(); + AMRfilereaderPlus(IObase &f); + int getNumLevels(){ return maxlevel+1; } + void getTimeRange(int &min,int &max){ + min=mintime; + max=maxtime; + } + void getScalarRange(double &min, double &max){ + min=smin;max=smax; + } + void getBounds(double *bnds){for (int ii=0;ii<6;ii++){bnds[ii]=bounds[ii];}} + void setTime(int timestep); + // starts out with all selected + void showLevel(int level=-1){ // default is all (-1) + if(level>=levelmask.getSize() || level<0){ + printf("AmrConvert::showLevel(%u) : Level out of range 0:%u\n", + level,levelmask.getSize()-1); + } + else + levelmask[level]=1; + } + void showAllLevels(); + void hideAllLevels(){for (int ii=0;ii<maxlevel+1;ii++)hideLevel(ii);} + void hideLevel(int level=-1){ // default is all (-1) + if(level>=levelmask.getSize() || level<0){ + printf("AmrConvert::showLevel(%u) : Level out of range 0:%u\n", + level,levelmask.getSize()-1); + } + else + levelmask[level]=0; + } + int nLevels(){ return maxlevel+1; } + IObase::DataType getDataType(){return datatype;} + // For C interface + int getNumGrids(){ // number of active grids + return activeGrids.getSize(); + } + int getActiveIndex(int ii){ return activeGrids[ii];} + int getGrids(AMRgridPlus *g); + // For C++ interface + int getGrids(FlexArray<AMRgridPlus> &g); + void setDataLoadingOff(){ gridloading=0; purgeGrids();} + void setDataLoadingOn(){ gridloading=1; loadGrids();} +}; + +#endif diff --git a/src/AMRPlus/AMRgridPlus.h b/src/AMRPlus/AMRgridPlus.h new file mode 100644 index 0000000..b8f866c --- /dev/null +++ b/src/AMRPlus/AMRgridPlus.h @@ -0,0 +1,21 @@ +#ifndef __AMR_GRID_HH_ +#define __AMR_GRID_HH_ +#include "AmrGrid.h" +#include "flexset.h" + +struct AMRgridPlus : public AmrGrid { + double time; + int timeref, spaceref[3], placeref[3]; + double scalarmin,scalarmax; +}; + +struct idxrec{ + int idx; + idxrec(int first=0){idx=first;} + int operator<(const idxrec &other)const {return idx<other.idx;} + int operator==(const idxrec &other)const {return idx==other.idx;} +}; + +typedef flexset<idxrec> IdxSet; +typedef flexarray<AMRgridPlus > GridArray; +#endif diff --git a/src/AMRPlus/AMRgridreaderPlus.C b/src/AMRPlus/AMRgridreaderPlus.C new file mode 100644 index 0000000..de131d3 --- /dev/null +++ b/src/AMRPlus/AMRgridreaderPlus.C @@ -0,0 +1,90 @@ +#include "AMRgridreaderPlus.h" +#include <stdio.h> +#include <stdlib.h> +#include <iostream.h> + + + + + +AMRgridPlus *AMRgridreaderPlus::getGridInfo(AMRgridPlus &g,int index){ + g.dataveclen=1; + if(file.seek(index)<index) + return 0; // fail if index past end + IObase::DataType dt; + file.readInfo(dt,g.rank,g.dims); + g.datatype = dt; + g.nbytes = IObase::nBytes(dt,g.rank,g.dims); + // find the deepest level (finest time resolution) + // Attrib Names? + IObase::DataType atype; + int length; + int attrnum=file.readAttributeInfo("level",atype,length); + if(attrnum>=0){ + int lev; // should be Int level + file.readAttribute(attrnum,&lev); + if(lev>g.maxlevel) g.maxlevel=lev; + g.level=lev; + } + attrnum=file.readAttributeInfo("time",atype,length); + if(attrnum>=0){ + file.readAttribute(attrnum,&(g.time)); + }attrnum=file.readAttributeInfo("time_refinement",atype,length); + if(attrnum>=0){ + file.readAttribute(attrnum,&(g.timerefinement)); + } + attrnum=file.readAttributeInfo("timestep",atype,length); + if(attrnum>=0){ + file.readAttribute(attrnum,&(g.timestep)); + } + attrnum=file.readAttributeInfo("origin",atype,length); + if(attrnum>=0) + file.readAttribute(attrnum,(g.origin)); + attrnum=file.readAttributeInfo("delta",atype,length); + if(attrnum>=0) + file.readAttribute(attrnum,(g.delta)); + attrnum=file.readAttributeInfo("persistence",atype,length); + if(attrnum>=0){ + file.readAttribute(attrnum,&(g.persistence)); + g.maxtime = g.timestep + g.persistence; + } + + attrnum=file.readAttributeInfo("time_refinement",atype,length); + if(attrnum>=0){ + file.readAttribute(attrnum,&(g.timeref)); + } + attrnum=file.readAttributeInfo("spatial_refinement",atype,length); + if(attrnum>=0){ + file.readAttribute(attrnum,&(g.spaceref)); + } + attrnum=file.readAttributeInfo("grid_placement_refinement",atype,length); + if(attrnum>=0){ + file.readAttribute(attrnum,&(g.placeref)); + } + + attrnum=file.readAttributeInfo("range",atype,length); + if(attrnum>=0){ + double range[2]; + file.readAttribute(attrnum,&range); + g.scalarmin=range[0]; g.scalarmax=range[1]; + } + else { + cout<<"Please convert this file with AMRPlusConv"<<endl; + exit(0); + } + + g.data=0; + return &g; +} // done + +AMRgridPlus *AMRgridreaderPlus::getGridData(AMRgridPlus &g,int index){ + IObase::DataType atype; + // if(data) free(data); data=0; // make certain it is empty first + g.data = malloc(g.nbytes); + file.seek(index); + file.readInfo(atype,g.rank,g.dims); + g.datatype=atype; + file.read(g.data); + return &g; +} + diff --git a/src/AMRPlus/AMRgridreaderPlus.h b/src/AMRPlus/AMRgridreaderPlus.h new file mode 100644 index 0000000..fc6f797 --- /dev/null +++ b/src/AMRPlus/AMRgridreaderPlus.h @@ -0,0 +1,41 @@ +#ifndef __AMRGRIDREADERPLUS_HH_ +#define __AMRGRIDREADERPLUS_HH_ + +#include <IO.hh> +#include "AMRgridPlus.h" +#include "IEEEIO.hh" + + +class AMRgridreaderPlus { +protected: + IObase &file; + +public: + AMRgridreaderPlus(IObase &f) : file(f){}; + ~AMRgridreaderPlus(){}; + + /* + * Low level grid/info fetching routines + */ + AMRgridPlus *getGrid(AMRgridPlus &g,int index){ + if(file.seek(index)<index) + return 0; // don't load past end + getGridInfo(g,index); + getGridData(g,index); + return &g; + } + AMRgridPlus *getGrid(int index){ + AMRgridPlus *g=new AMRgridPlus; + return this->getGrid(*g,index); + } + + AMRgridPlus *getGridInfo(AMRgridPlus &g,int index); + AMRgridPlus *getGridData(AMRgridPlus &g,int index); + + + + +}; + + +#endif diff --git a/src/AMRPlus/AMRreaderPlus.C b/src/AMRPlus/AMRreaderPlus.C new file mode 100644 index 0000000..bc47e7b --- /dev/null +++ b/src/AMRPlus/AMRreaderPlus.C @@ -0,0 +1,122 @@ +#include "AMRreaderPlus.h" +#include <stdio.h> +#include <stdlib.h> +#include <iostream.h> +#include <algorithm> + + +AMRreaderPlus::AMRreaderPlus(IObase &f) : AMRgridreaderPlus(f), grids(), + activeset(), timemask(), levelmask(), realtimes() +{ + init(); + selectTimeStep(0); + for (int ii=0;ii<=maxlevel;ii++) showLevel(ii); + modflag=1; +} + + + +AMRreaderPlus::~AMRreaderPlus(){ + +} + + + +void AMRreaderPlus::init(){ + maxlevel=maxtimeres=maxtime=0; + smin=smax=0.0; + numgrids=0; + + build_info(); +} +void AMRreaderPlus::build_info(){ + AMRgridPlus *res, newg; + res=getGridInfo(newg, 0); + if (res==NULL) return; + maxlevel=0; + maxtime=0; + numgrids=0; + smin=newg.scalarmin; + smax=newg.scalarmax; + datatype=newg.datatype; + while (res!=NULL){ //Load all grid info + grids.append(newg); + realtimes.insert(newg.time); + maxlevel=(maxlevel>newg.level)?maxlevel:newg.level; + maxtime=(maxtime>newg.timestep)?maxtime:newg.timestep; + smax=smax>newg.scalarmax?smax:newg.scalarmax; + smin=smin<newg.scalarmin?smin:newg.scalarmin; + numgrids++; + res=getGridInfo(newg, numgrids); + } + levelmask.fill(0, maxlevel+1); + timemask.fill(0, maxtime+1); + + + leveltimes= new flexmatrix<IdxArray> (maxlevel+1, maxtime+1); + + AMRgridPlus *g= grids.getData(0); + for(int ii=0;ii<grids.getSize();ii++){//Extract basic info + for (int jj=g->timestep;jj<g->timestep+g->persistence;jj++){ + if (jj<=maxtime){ + idxrec trec(ii); + (*leveltimes)(g->level, jj).append(trec.idx); + } + } + g++; + } + + cout<<realtimes.getSize()<<" "<<numgrids<<endl<<endl; + +} + +void AMRreaderPlus::build_active(){ + IdxSet newset, delset; + + //Calculate what the set should be + for (int ii=0;ii<=maxtime;ii++) + for (int jj=0;jj<=maxlevel;jj++) + if (timemask[ii]&&levelmask[jj]){ + for (int kk=0;kk<(*leveltimes)(jj, ii).getSize();kk++){ + newset.insert((*leveltimes)(jj, ii)[kk]); + } + } + + //remove all the unneeded grids + setdifference(activeset, newset, delset); + for (ii=0;ii<delset.getSize();ii++) + if (grids[delset[ii].idx].data!=NULL){ + free(grids[delset[ii].idx].data); + grids[delset[ii].idx].data=NULL; + } + activeset=newset; +} + + +void AMRreaderPlus::modify(){modflag=1;} + +void AMRreaderPlus::getActive(IdxSet &grids){ + if (modflag!=0){ + build_active(); + modflag=0; + } + grids=activeset; +} + +void AMRreaderPlus::loadData(IdxSet &loadset){ + if (modflag!=0){ + build_active(); + modflag=0; + } + + if (!activeset.contains(loadset)){ + cout<<"Trying to load non-active grids. Hmmmm."<<endl; + } + + for (int ii=0;ii<loadset.getSize();ii++){ + if (grids[loadset[ii].idx].data==NULL){ + cout<<"Loaded "<<loadset[ii].idx<<endl; + getGridData(grids[loadset[ii].idx], loadset[ii].idx); + } + } +} diff --git a/src/AMRPlus/AMRreaderPlus.h b/src/AMRPlus/AMRreaderPlus.h new file mode 100644 index 0000000..6bd3387 --- /dev/null +++ b/src/AMRPlus/AMRreaderPlus.h @@ -0,0 +1,85 @@ +#ifndef __AMRREADERPLUS_HH_ +#define __AMRREADERPLUS_HH_ + +#include <set> +#include <vector> +#include <IO.hh> +#include "AMRgridreaderPlus.h" +#include "IEEEIO.hh" + +#include "flexmatrix.h" +#include "flexset.h" +#define kNoData 0 +#define kHasData 1 + +/* Method for calculating scalar range - the global range, +range per fine timestep, per coarse, or per (current) root. */ +typedef enum {kGlobal,kFine,kCoarse,kRoot} ScalarMode; + +using namespace std; + + + +typedef flexarray<int> IntArray; + + + +typedef flexarray<int> IdxArray; + + +class AMRreaderPlus : public AMRgridreaderPlus { + public: + int datatype; + int numgrids; + int maxlevel,maxtimeres,maxtime; + double smin,smax; + int modflag; + + IdxSet activeset; + flexset<float> realtimes; + flexmatrix<IdxArray> *leveltimes; + GridArray grids; + IntArray levelmask, timemask; + + void init(); + void build_info(); + void build_active(); + void modify(); //Flag that tells when active set has changed +public: + AMRreaderPlus(IObase &f); + ~AMRreaderPlus(); + + int getNumLevels(){return maxlevel+1;} + int getNumTimesteps(){return maxtime+1;} + int getNumGrids(){return numgrids;} + int getDataType(){return datatype;} + + void showTimeStep(int ts){ + if (ts>=0 && ts<=maxtime) {timemask[ts]=1; modify();} + else cout<<"Timestep out of range: "<<ts<<endl; + } + void hideTimeStep(int ts){ + if (ts>=0 && ts<=maxtime) {timemask[ts]=0; modify();} + else cout<<"Timestep out of range: "<<ts<<endl; + } + void selectTimeStep(int ts) //Shortcut- hides all times but ts + { for (int ii=0;ii<=maxtime;ii++) timemask[ii]=(ii==ts)?1:0;modify();} + + void showLevel(int lev){ + if (lev>=0 && lev<=maxlevel) {levelmask[lev]=1; modify();} + else cout<<"Level out of range: "<<lev<<endl; + } + void hideLevel(int lev){ + if (lev>=0 && lev<=maxlevel) {levelmask[lev]=0; modify();} + else cout<<"Level out of range: "<<lev<<endl; + } + + GridArray *getGridSet(){return &grids;} + void getActive(IdxSet &grids); + void loadData(IdxSet &loadset); + void loadData(){loadData(activeset);} + +}; + + +#endif diff --git a/src/AMRPlus/AMRwriterPlus.C b/src/AMRPlus/AMRwriterPlus.C new file mode 100644 index 0000000..856a356 --- /dev/null +++ b/src/AMRPlus/AMRwriterPlus.C @@ -0,0 +1,48 @@ +#include "AMRwriterPlus.h" + + +AMRwriterPlus::AMRwriterPlus(IObase &descriptor) : AMRwriter(descriptor){ + scalarFlag=0; + curscalarmin=curscalarmax=0; +} + +void AMRwriterPlus::calcScalarRange(void *data){ + long numelts=1; + for (int ii=0;ii<drank;ii++) numelts*=ddims[ii]; + + switch(this->dtypeID){ + case IObase::Byte:{ + char *dptr=(char *)data; + curscalarmin=curscalarmax=*dptr; + for (long kk=0;kk<numelts;kk++){ + curscalarmin=(curscalarmin<dptr[kk])?curscalarmin:dptr[kk]; + curscalarmax=(curscalarmax>=dptr[kk])?curscalarmax:dptr[kk]; + } + } break; + case IObase::Float32:{ + float *fptr=(float *)data; + curscalarmin=curscalarmax=*fptr; + for (long jj=0;jj<numelts;jj++){ + curscalarmin=(curscalarmin<fptr[jj])?curscalarmin:fptr[jj]; + curscalarmax=(curscalarmax>=fptr[jj])?curscalarmax:fptr[jj]; + } + } break; + case IObase::Float64:{ + double *dptr=(double *)data; + curscalarmin=curscalarmax=*dptr; + for (long kk=0;kk<numelts;kk++){ + curscalarmin=(curscalarmin<dptr[kk])?curscalarmin:dptr[kk]; + curscalarmax=(curscalarmax>=dptr[kk])?curscalarmax:dptr[kk]; + } + } break; + } +} + + +void AMRwriterPlus::writePlusattributes(){ + double range[2]; + range[0]=curscalarmin; + range[1]=curscalarmax; + file.writeAttribute("range", IObase::Float64, 2, range); + scalarFlag=0; //reset the flag +} diff --git a/src/AMRPlus/AMRwriterPlus.h b/src/AMRPlus/AMRwriterPlus.h new file mode 100644 index 0000000..a3c47ff --- /dev/null +++ b/src/AMRPlus/AMRwriterPlus.h @@ -0,0 +1,70 @@ +#include "AMRwriter.hh" +#include "AMRgridPlus.h" + +/* + * AMRwriterPlus: + * A subclass of AMRwriter which adds a scalar range attribute + * to each dataset. The AMRwriter interface is unchanged, however + * for convenience, you can: + * + * Set the top level parameters or write a dataset by passing a + * pointer to an AMRgridPlus datastructure to ::setTopLevelParameters + * or ::write respectively + * + * Set the scalar range of the dataset explicitly (before writing) + * with ::setScalarRange. If this is not called, the scalar range will + * be computed from within ::write. Useful (and timesaving) if you + * have already computed the range. + */ + +class AMRwriterPlus : public AMRwriter{ + public: + AMRwriterPlus(IObase &descriptor); + + virtual void setTopLevelParameters(AMRgridPlus *g){ + AMRwriter::setTopLevelParameters(g->rank, g->origin, g->delta, \ + g->timestep, g->maxlevel); + } + + // CC forces me to re-overload this inherited method! + virtual void setTopLevelParameters(int rank,double *origin, + double *delta,double timestep,int maxdepth){ + AMRwriter::setTopLevelParameters(rank, origin, delta, timestep, maxdepth); + } + + void setScalarRange(double smin,double smax){ + curscalarmin=smin;curscalarmax=smax;scalarFlag=1;} + + void write(int *origin,int *dims,void *data){ + AMRwriter::write(origin, dims, data); + if (!scalarFlag) calcScalarRange(data); + writePlusattributes(); + } + void write(float *origin,int *dims,void *data){ + AMRwriter::write(origin, dims, data); + if (!scalarFlag) calcScalarRange(data); + writePlusattributes(); + } + void write(double *origin,int *dims,void *data){ + AMRwriter::write(origin, dims, data); + if (!scalarFlag) calcScalarRange(data); + writePlusattributes(); + } + + virtual void write(AMRgridPlus *g, int calcscalars=0){ + + setType((IObase::DataType)g->datatype); + setLevel(g->level); + setTime(g->timestep); + write(g->origin, g->dims, g->data); + } + + protected: + void writePlusattributes(); + + private: + void calcScalarRange(void *data); + + double curscalarmin, curscalarmax; + int scalarFlag; +}; diff --git a/src/AMRPlus/Dpndfile b/src/AMRPlus/Dpndfile new file mode 100644 index 0000000..1535d4b --- /dev/null +++ b/src/AMRPlus/Dpndfile @@ -0,0 +1,193 @@ +AMRwriterPlus.o: AMRwriterPlus.C AMRwriterPlus.h \ + /home/jshalf/Develop/FlexIO/AMRwriter.hh \ + /home/jshalf/Develop/FlexIO/Arch.h /usr/include/sys/types.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/gnu/stubs.h /usr/include/bits/types.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/stddef.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h \ + /usr/include/string.h /home/jshalf/Develop/FlexIO/IO.hh \ + /home/jshalf/Develop/FlexIO/IO.h \ + /home/jshalf/Develop/FlexIO/Writer.hh \ + /home/jshalf/Develop/FlexIO/Writer.h \ + /home/jshalf/Develop/FlexIO/FlexArrayTmpl.H \ + /home/jshalf/Develop/FlexIO/AMRwriter.h AMRgridPlus.h \ + /home/jshalf/Develop/FlexIO/AmrGrid.h flexset.h flexarrays.h \ + /usr/include/stdlib.h /usr/include/alloca.h +AMRgridreaderPlus.o: AMRgridreaderPlus.C AMRgridreaderPlus.h \ + /home/jshalf/Develop/FlexIO/IO.hh /home/jshalf/Develop/FlexIO/Arch.h \ + /usr/include/sys/types.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h \ + /usr/include/bits/types.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/stddef.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h \ + /usr/include/string.h /home/jshalf/Develop/FlexIO/IO.h AMRgridPlus.h \ + /home/jshalf/Develop/FlexIO/AmrGrid.h flexset.h flexarrays.h \ + /usr/include/stdlib.h /usr/include/alloca.h \ + /home/jshalf/Develop/FlexIO/IEEEIO.hh /usr/include/stdio.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/stdarg.h \ + /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/bits/stdio_lim.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/sys/file.h /usr/include/fcntl.h \ + /usr/include/bits/fcntl.h \ + /home/jshalf/Develop/FlexIO/IEEEIOWinDllApi.h \ + /home/jshalf/Develop/FlexIO/FlexArrayTmpl.H /usr/include/sys/stat.h \ + /usr/include/bits/stat.h /usr/include/strings.h \ + /home/jshalf/Develop/FlexIO/IEEEIO.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/iostream.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/streambuf.h +AMRfilereaderPlus.o: AMRfilereaderPlus.C /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/gnu/stubs.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/stddef.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/stdarg.h \ + /usr/include/bits/types.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/bits/stdio_lim.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h \ + /usr/include/alloca.h AMRfilereaderPlus.h \ + /home/jshalf/Develop/FlexIO/IO.hh /home/jshalf/Develop/FlexIO/Arch.h \ + /usr/include/string.h /home/jshalf/Develop/FlexIO/IO.h \ + AMRgridreaderPlus.h AMRgridPlus.h \ + /home/jshalf/Develop/FlexIO/AmrGrid.h flexset.h flexarrays.h \ + /home/jshalf/Develop/FlexIO/IEEEIO.hh /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/sys/file.h /usr/include/fcntl.h \ + /usr/include/bits/fcntl.h \ + /home/jshalf/Develop/FlexIO/IEEEIOWinDllApi.h \ + /home/jshalf/Develop/FlexIO/FlexArrayTmpl.H /usr/include/sys/stat.h \ + /usr/include/bits/stat.h /usr/include/strings.h \ + /home/jshalf/Develop/FlexIO/IEEEIO.h +flexset.o: flexset.C flexset.h flexarrays.h /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/gnu/stubs.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/stddef.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/bits/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/sys/sysmacros.h /usr/include/alloca.h +AMRreaderPlus.o: AMRreaderPlus.C AMRreaderPlus.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/set \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_tree.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_algobase.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_config.h \ + /usr/include/_G_config.h /usr/include/bits/types.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/gnu/stubs.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/stddef.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_relops.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_pair.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/type_traits.h \ + /usr/include/string.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/limits.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/sys/sysmacros.h /usr/include/alloca.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/new.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/new \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/exception \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/iostream.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/streambuf.h \ + /usr/include/libio.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/stdarg.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_iterator.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_alloc.h \ + /usr/include/assert.h /usr/include/pthread.h /usr/include/sched.h \ + /usr/include/bits/sched.h /usr/include/bits/time.h \ + /usr/include/signal.h /usr/include/bits/pthreadtypes.h \ + /usr/include/bits/sigthread.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_construct.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_function.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_set.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_multiset.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/vector \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_uninitialized.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_vector.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_bvector.h \ + /home/jshalf/Develop/FlexIO/IO.hh /home/jshalf/Develop/FlexIO/Arch.h \ + /home/jshalf/Develop/FlexIO/IO.h AMRgridreaderPlus.h AMRgridPlus.h \ + /home/jshalf/Develop/FlexIO/AmrGrid.h flexset.h flexarrays.h \ + /home/jshalf/Develop/FlexIO/IEEEIO.hh /usr/include/stdio.h \ + /usr/include/bits/stdio_lim.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/sys/file.h /usr/include/fcntl.h \ + /usr/include/bits/fcntl.h \ + /home/jshalf/Develop/FlexIO/IEEEIOWinDllApi.h \ + /home/jshalf/Develop/FlexIO/FlexArrayTmpl.H /usr/include/sys/stat.h \ + /usr/include/bits/stat.h /usr/include/strings.h \ + /home/jshalf/Develop/FlexIO/IEEEIO.h flexmatrix.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/algorithm \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_tempbuf.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_algo.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_heap.h +readtest.o: readtest.C /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/stddef.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/stdarg.h \ + /usr/include/bits/types.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/bits/stdio_lim.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h \ + /usr/include/alloca.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/float.h \ + /usr/include/string.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/iostream.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/streambuf.h \ + /home/jshalf/Develop/FlexIO/IEEEIO.hh /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/sys/file.h /usr/include/fcntl.h \ + /usr/include/bits/fcntl.h \ + /home/jshalf/Develop/FlexIO/IEEEIOWinDllApi.h \ + /home/jshalf/Develop/FlexIO/IO.hh /home/jshalf/Develop/FlexIO/Arch.h \ + /home/jshalf/Develop/FlexIO/IO.h \ + /home/jshalf/Develop/FlexIO/FlexArrayTmpl.H /usr/include/sys/stat.h \ + /usr/include/bits/stat.h /usr/include/strings.h \ + /home/jshalf/Develop/FlexIO/IEEEIO.h AMRreaderPlus.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/set \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_tree.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_algobase.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_config.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_relops.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_pair.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/type_traits.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/limits.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/new.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/new \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include/exception \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_iterator.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_alloc.h \ + /usr/include/assert.h /usr/include/pthread.h /usr/include/sched.h \ + /usr/include/bits/sched.h /usr/include/bits/time.h \ + /usr/include/signal.h /usr/include/bits/pthreadtypes.h \ + /usr/include/bits/sigthread.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_construct.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_function.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_set.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_multiset.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/vector \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_uninitialized.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_vector.h \ + /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/stl_bvector.h \ + AMRgridreaderPlus.h AMRgridPlus.h \ + /home/jshalf/Develop/FlexIO/AmrGrid.h flexset.h flexarrays.h \ + flexmatrix.h diff --git a/src/AMRPlus/FlexSetTempl.h b/src/AMRPlus/FlexSetTempl.h new file mode 100644 index 0000000..27f0d84 --- /dev/null +++ b/src/AMRPlus/FlexSetTempl.h @@ -0,0 +1,20 @@ +#ifndef FLEXSETTEMPL_H +#define FLEXSETTEMPL_H + +template <class T> +class FlexSetOrdered{ + FlexArray arr; + + FlexSetOrdered() : arr(){}; + + int insert(T &item){ + int a=0;b=getSize()-1, c; + if (arr[a]==item || arr[b]==item) return 0; + while (a!=b){ + c=(a+b)/2; + if (arr[c]==item) return 0; + if (arr[c]<item) a=c; else b=c; + } +}; + +#endif diff --git a/src/AMRPlus/filereadtest.C b/src/AMRPlus/filereadtest.C new file mode 100644 index 0000000..5036f46 --- /dev/null +++ b/src/AMRPlus/filereadtest.C @@ -0,0 +1,43 @@ +// generated by Fast Light User Interface Designer (fluid) version 1.00 + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <iostream.h> +#include "IEEEIO.hh" +#include "AMRfilereaderPlus.h" + + + +int main(int argc, char** argv) { + IObase *ifile, *ofile; + AMRfilereaderPlus *reader; + + if (argc!=2){ + cerr<<"Usage: <filename>"<<endl; + exit(0); + } + char *fname=strdup(argv[1]); + ifile=new IEEEIO(fname, IObase::Read); + if (!ifile->isValid()){ + cerr<<fname<<" is not a valid IEEEIO file."<<endl; + exit(0); + } + + reader=new AMRfilereaderPlus(*ifile); + int ii=0; + AMRgridPlus grid, *tgrid; + + + //reader->setTime(0); + for (ii=0;ii<reader->getNumGrids();ii++){ + reader->getGrid(grid, reader->getActiveIndex(ii)); + cout<<"Level: "<<grid.level<<endl; + } + + delete ifile; + + + +} diff --git a/src/AMRPlus/flexarrays.h b/src/AMRPlus/flexarrays.h new file mode 100644 index 0000000..e713e98 --- /dev/null +++ b/src/AMRPlus/flexarrays.h @@ -0,0 +1,184 @@ +#ifndef ARRAYS_HDR +#define ARRAYS_HDR +#include <string.h> +#include <stdlib.h> +//For Shared Objects: +//#include "SafeList.h" +//#define TAG :public shObj +//#define GetMem CAVEMalloc +//#define FreeMem CAVEFree +//For Non-shared Objects: +#define TAG + +/* An flexarray is a dynamic flexarray of objecs. No upper limit, + * the ability to add and remove objects on the fly, etc. + * + * Rundown of routines: + * Constructor - initializes an empty flexarray with increment 10 + * Destructor - Deletes the flexarray. Does NOT delete objects in the flexarray + * copy constructor/ = :deep copy (override X::operator= if you need + * deep copies of the elements) + * + * Information: + * int getLength()/getSize() - returns #objects + * int getActualSize() - returns #slots allocated + * int getIncrement() - returns #slots allocated at a time + * int empty() - true if no elts + * + * Access: + * X& [idx] - return indexed reference, unsafe + * X* getData(idx) - Ptr to indexed elt. + * X* getDataConst - same as above, but everything is const qualified + * + * Manip: + * setIncrement(int) - + * clear() - empties the array + * fill(X&, N) - sets the array to N copies of the X + * setData(X&, idx) - change entry at index + * insertElement(X&, idx) - insert element BEFORE index + * (if index=-1, append element); + * append(X&) - duh. + * InsertElements(start, X*, N) - insert #elements before + * start... read values from X*. + * removeElements(start, N) - remove N elements starting with start + */ + +template <class X> +class flexarray TAG { + int Length, Size, Increment; + X* data; + + public: + flexarray(){Length=Size=0; Increment=10;data=NULL;} + flexarray(const flexarray<X> &src){ + Length=src.Length;Size=src.Size;Increment=src.Increment; + if (Size==0) data=NULL; + else { + data=getNewArray(Size); + memcpy(this->data, src.data, this->Length*sizeof(X)); + } + } + ~flexarray(){if (data) delete[] data;} + + flexarray<X> &operator=(const flexarray<X> &src){ + if (data!=NULL) delete[] data; + Length=src.Length;Size=src.Size;Increment=src.Increment; + if (Size==0) data=NULL; + else { + data=getNewArray(Size); + memcpy(this->data, src.data, this->Length*sizeof(X)); + } + return *this; + } + + int getActualSize() const{return Size;} + int getSize() const{return Length;} + int getLength() const{return Length;} + int getIncrement() const{return Increment;} + int empty() const{return (Size==0);} + + + + const X & operator()(int idx) const{return data[idx];} + X & operator[](int idx) const{return data[idx];} + + X* getData(int idx)const{ + if (idx==-1) idx=Length-1; + if (idx>=0 && idx<Length) + return data+idx; + else return NULL; + } + X* getDataConst(int idx) const{ + if (idx==-1) idx=Length-1; + if (idx>=0 && idx<Length) + return data+idx; + else return NULL; + } + + void setIncrement(int ninc){Increment=ninc;} + void clear(){Length=Size=0; if(data) delete[] data;data=NULL;} + void fill(const X &elt, int howmany){ + clear(); + Length=howmany; + Size=Increment * ((Length+howmany)/Increment +1); + data=getNewArray(Size); + for (int ii=0;ii<howmany;ii++) + data[ii]=elt; + } + + void setData(int idx, const X &ndata){ + if (idx>=0 && idx<Length) + data[idx]=ndata; + } + + + + + void insertElement( const X &elt, int atidx=-1){ + insertElements(atidx, &elt, 1); + } + void append( const X &elt){ + insertElements(-1, &elt, 1); + } + + + void insertElements(int startidx, const X* elts, int howmany){ + if (howmany<=0) return; + if (startidx<-1 || startidx>Length) return; + if (startidx==-1) startidx=Length; + if (this->data==NULL) data=getNewArray(Increment); + if (Size<Length+howmany){ + Size=Increment * ((Length+howmany)/Increment +1); + X* tflexarray=getNewArray(Size); + if (startidx>0) + memcpy(tflexarray, data, startidx*sizeof(X)); + if (startidx<Length) + memcpy(tflexarray+startidx+howmany, data+startidx, \ + ((Length-startidx)*sizeof(X))); + delete[] data; + data=tflexarray; + } + else + if (startidx<Length) + memcpy(data+startidx+howmany, data+startidx, \ + (Length-startidx)*sizeof(X)); + memcpy(data+startidx, elts, howmany*sizeof(X)); + Length+=howmany; + } + + void removeElements(int startidx, int howmany){ + if (howmany<=0 || startidx<-1 || startidx>=Length) return; + if (startidx==-1) startidx=Length-1; + if (startidx+howmany>=Length) howmany=Length-startidx; + memcpy(data+startidx, data+startidx+howmany, + (Length-(startidx+howmany))*sizeof(X)); + Length-=howmany; + } + + + private: + X* getNewArray(int newSize){ + return new X [newSize]; + } + + void resizeArray(int startidx, int numelts){ + int NSize=Length+numelts; + if (NSize>Size){ + Size=Increment * (NSize/Increment +1); + X* tflexarray=getNewArray(Size); + if (startidx>0) + memcpy(tflexarray, data, startidx*sizeof(X)); + if (startidx<Length) + memcpy(tflexarray+startidx+numelts, data+startidx, \ + ((Length-startidx)*sizeof(X))); + delete[] data; + data=tflexarray; + } + } + + + +}; + + +#endif diff --git a/src/AMRPlus/flexmatrix.h b/src/AMRPlus/flexmatrix.h new file mode 100644 index 0000000..6b052e7 --- /dev/null +++ b/src/AMRPlus/flexmatrix.h @@ -0,0 +1,20 @@ +#ifndef FLEX_MATRIX_H +#define FLEX_MATRIX_H +#include <stdlib.h> + +template <class X> +class flexmatrix{ + X* data; + int M, N; + + public: + flexmatrix(int m, int n){ + M=m;N=n; if (M*N==0) cout<<"Serious Problem! "<<endl; + data=new X [M*N]; + } + ~flexmatrix(){delete[] data;} + X& operator()(int m, int n){return data[m*N+n];} +}; + + +#endif diff --git a/src/AMRPlus/flexset.C b/src/AMRPlus/flexset.C new file mode 100644 index 0000000..529fb1a --- /dev/null +++ b/src/AMRPlus/flexset.C @@ -0,0 +1,215 @@ +#include "flexset.h" + +template <class X> +void setunion(const flexset<X> &A, const flexset<X> &B,flexset<X> &result){ + int idxA=0, idxB=0; + int sizeA=A.getSize(), sizeB=B.getSize(); + + if (A.empty()) {result=B;return;} + if (B.empty()) {result=A;return;} + result.clear(); + do { + //I dont like to rely on shortcut boolean operators, so + //that's why I use double ifs + + X *whichadd=NULL; //1,2,3 (A,B, or both) + if (idxA<sizeA && idxB<sizeB){ + if (A(idxA)<B(idxB)) { + whichadd=&A(idxA); idxA++; + } + else if (B(idxB)<A(idxA)){ + whichadd=&B(idxB); idxB++; + } + else { + whichadd=A(idxA); + idxA++; idxB++; + } + } + else { + if (idxA<sizeA){whichadd=&A(idxA); idxA++;} + else if (idxB<sizeB){whichadd=&B(idxB); idxB++;} + } + + if (whichadd!=NULL) + result.append(*whichadd); + } while (idxA<sizeA || idxB<sizeB); +} + +template <class X> +void setunion(flexset<X> &A, const flexset<X> &B){ + flexset<X> tmp=A; + setunion(tmp, B, A); +} + + +template <class X> +void setintersection(const flexset<X> &A, const flexset<X> &B,flexset<X> &result){ + int idxA=0, idxB=0; + int sizeA=A.getSize(), sizeB=B.getSize(); + + result.clear(); + if (A.empty() || B.empty()) return; //result={} + do { + //I dont like to rely on shortcut boolean operators, so + //that's why I use double ifs + + X *whichadd=NULL; //1,2,3 (A,B, or both) + if (idxA<sizeA && idxB<sizeB){ + if (A(idxA)<B(idxB)) { + idxA++; + } + else if (B(idxB)<A(idxA)){ + idxB++; + } + else { + whichadd=&A[idxA]; + idxA++; idxB++; + } + } + else return; //if we've finished off one set, then no more elts in intersection + + if (whichadd!=NULL) + result.append(*whichadd); + } while (idxA<sizeA || idxB<sizeB); +} + + +template <class X> +void setsymmetricdifference(const flexset<X> &A, const flexset<X> &B,flexset<X> &result){ + int idxA=0, idxB=0; + int sizeA=A.getSize(), sizeB=B.getSize(); + if (A.empty()) {result.clear(); return;} + if (B.empty()) {result=A;return;} + result.clear(); + do { + //I dont like to rely on shortcut boolean operators, so + //that's why I use double ifs + + X *whichadd=NULL; //1,2,3 (A,B, or both) + if (idxA<sizeA && idxB<sizeB){ + if (A(idxA)<B(idxB)) { + whichadd=&A(idxA); idxA++; + } + else if (B(idxB)<A(idxA)){ + whichadd=&B(idxB); idxB++; + } + else { + idxA++; idxB++; + } + } + else { + if (idxA<sizeA){whichadd=&A(idxA); idxA++;} + else if (idxB<sizeB){whichadd=&B(idxB); idxB++;} + } + + if (whichadd!=NULL) + result.append(*whichadd); + } while (idxA<sizeA || idxB<sizeB); +} + +template <class X> +void setdifference(const flexset<X> &A, const flexset<X> &B,flexset<X> &result){ + int idxA=0, idxB=0; + int sizeA=A.getSize(), sizeB=B.getSize(); + if (A.empty()) {result=A; return;} + if (B.empty()) {result=A;return;} + result.clear(); + do { + //I dont like to rely on shortcut boolean operators, so + //that's why I use double ifs + + X *whichadd=NULL; //1,2,3 (A,B, or both) + if (idxA<sizeA && idxB<sizeB){ + if (A(idxA)<B(idxB)) { + whichadd=&A[idxA]; idxA++; + } + else if (B(idxB)<A(idxA)){ + idxB++; + } + else { + idxA++; idxB++; + } + } + else { + if (idxA<sizeA){whichadd=&A[idxA]; idxA++;} + else if (idxB<sizeB){idxB++;} + } + + if (whichadd!=NULL) + result.append(*whichadd); + } while (idxA<sizeA || idxB<sizeB); +} + + +template <class X> +void setdifferences(const flexset<X> &A, const flexset<X> &B,flexset<X> &AMB,flexset<X> &BMA){ + int idxA=0, idxB=0; + int sizeA=A.getSize(), sizeB=B.getSize(); + if (A.empty()) {AMB.clear();BMA=B; return;} + if (B.empty()) {BMA.clear();AMB=A;return;} + AMB.clear(); + BMA.clear(); + do { + X *whichaddA=NULL; + X *whichaddB=NULL; + if (idxA<sizeA && idxB<sizeB){ + if (A(idxA)<B(idxB)) { + whichaddA=&A[idxA]; idxA++; + } + else if (B(idxB)<A(idxA)){ + whichaddB=&B[idxB];idxB++; + } + else { + idxA++; idxB++; + } + } + else { + if (idxA<sizeA){whichaddA=&A[idxA]; idxA++;} + else if (idxB<sizeB){whichaddB=&B[idxB];idxB++;} + } + + if (whichaddA!=NULL) + AMB.append(*whichaddA); + if (whichaddB!=NULL) + BMA.append(*whichaddB); + } while (idxA<sizeA || idxB<sizeB); +} + + +template <class X> +void setconvert(flexset<X> &A, const flexset<X> &B){ + int idxA=0, idxB=0; + int sizeA=A.getSize(), sizeB=B.getSize(); + if (A.empty()) {return;} + if (B.empty()) { + cout<<"SetConvert - UHOH! A is not contained in B!"<<endl; + return;} + do { + //I dont like to rely on shortcut boolean operators, so + //that's why I use double ifs + + if (idxA<sizeA && idxB<sizeB){ + if (A(idxA)<B(idxB)) { + cout<<"SetConvert - UHOH! A is not contained in B!"<<endl; + A.clear(); + return; + } + else if (B(idxB)<A(idxA)){ + idxB++; + } + else { + (A[idxA])=B(idxB); + idxA++; idxB++; + } + } + else { + if (idxA<sizeA){ + cout<<"SetConvert - UHOH! A is not contained in B!"<<endl; + A.clear(); + return; + } + } + + } while (idxA<sizeA || idxB<sizeB); +} + diff --git a/src/AMRPlus/flexset.h b/src/AMRPlus/flexset.h new file mode 100644 index 0000000..d2e486d --- /dev/null +++ b/src/AMRPlus/flexset.h @@ -0,0 +1,209 @@ +#ifndef FLEX_SET_H +#define FLEX_SET_H +#include "flexarrays.h" + +/* + * A flexset is a set datastructure. Fast insertion/deletion (O(logN)), + * and basic set operations (union, difference, etc...). This set is + * not completely generalized - you must either use native (non-pointer) + * types, or use a class with operators < and == implemented + * (i.e: inline int operator<(const X&) const{...};) This is what allows + * log time access, and linear time set operations. + * Routines: + * Constructor/Destructor/copy constructor... + * + * Information: + * int getSize() - returns size of set. + * int find(X& x) - return position of x, or -1 if x isn't in the set + * int contains(X& x) - boolean version of above + * int contains(flexset &s) - returns 1 if s is a subset + * + * Manipulation: + * insert(X& x) - add x to the set. If x is already in the set + * (technically, x==e for some e in the set) nothing happens. + * remove(X& x) - remove x (only if x is inside, of course); + * X& [int idx] - access element by index. Index will change with insertion + * buldSubset(flexset<X> &x, int (* test)(X& y)) - creates a subset consisting + * of all elements in the set for which 'test' returns true. + * + * Operations: + * [all of form: set<oper>(X& A, X& B, X& result){ result= A <oper> B}] + * setunion(A=AUB, or C=AUB), setintersection, setdifference, setsymmetricdifference + * setdifferences (returns A-B and B-A in one go) + * NOTE: The result of intersection or difference will consist only + * of items taken from A. (Important if you are comparing sets with + * similar keys and dissimilar data + */ + +/* +class flexset; +template <class X> setiter{ + public: + setiter(flexset *nset){itsset=nset; idx=(nset->empty())?-1:0;} + + operator++(){idx++; if (idx>itsset->getSize()-1) idx=-1;} + operator--(){idx--; if (idx<0) idx=-1;} + int ok(){return idx!=-1;} + + X &operator*(){if (idx==-1) return itsset[0]; return itsset[idx];} + + private: + flexset *itsset; + int idx; +} +*/ + + +template <class X> +class flexset : protected flexarray<X>{ + public: + flexset(): flexarray<X>(){}; + flexset(const flexset<X> &src): flexarray<X>(src){}; + ~flexset(){}; + //by all accounts, this should inherit flexarray operator= + + int getSize() const{return flexarray<X>::getSize();} + int findpos(const X &elt, int start=0, int end=-1) const{ + if (start<0) start=0; + if (end==-1) end=getLength()-1; + + int a=start, b=end, e; + if (empty()) return 0; + if (elt<(*this)(a)) return a; + if (elt==(*this)(a)) return a; //don't depend on <= being implemented + if (elt==(*this)(b)) return b; + if (!(elt<(*this)(b))) return b+1; //given above line, equiv to elt>data[b] + + if ((a+b)&1) e=(a+b+1)/2; //e odd + else e=(a+b)/2; + while ((b-a>1)){ + if (elt==(*this)(e)) return e; + + if (elt<(*this)(e)) b=e; + else a=e; + if ((a+b)&1) e=(a+b+1)/2; //e odd + else e=(a+b)/2; + } + if (elt<(*this)(e)) return e; + if (elt==(*this)(e)) return e; + else return e+1; + + } +//If elt is in the set, return its index, otherwise return -1 + int find(const X &elt, int start=0, int end=-1) const{ + if (empty()) return -1; + int result=findpos(elt, start, end); + if (result<getSize() && elt==*getDataConst(result)) return result; + return -1; + } + + int contains(const X &elt) const{return (find(elt)!=-1);} + + int contains(const flexset<X> &iset) const{ + if (iset.empty()) return 1; //Empty set is in everything! + int a=find(iset(0)); + if (a<0)return 0; + for (int ii=1;ii<iset.getSize();ii++){ + if ((a=find(iset(ii), a))<0) return 0; + } + + return 1; + } + + + + void clear(){ + flexarray<X>::clear(); + } + + int empty() const {return flexarray<X>::empty();} + + void buildSubset(flexset<X> &A, int (* test)(const X&)){ + A.clear(); + for (int ii=0;ii<getSize();ii++) + if (test((*this)[ii])) A.append((*this)[ii]); + } + + + +//Insert elt into the set. If elt is already in, do nothing + void insert(const X &elt){ + int pos=findpos(elt); + if (pos<getSize()) + if (elt==*getData(pos)) return; + insertElement(elt, pos); + }; + + void remove(const X &elt){ + if (empty()) return; + int pos=findpos(elt); + if (pos<getSize()) + if (elt==*getData(pos)) removeElements(pos, 1); + } + + //Indexed removal preserves set ordering, and it's O(1), + //so it is safe to include + void indexremove(int idx){ + if (empty()||idx<0||idx>=getSize()) return; + removeElements(idx, 1); + } + + void append(const X &elt){ + if (empty()) { + insertElement(elt, 0); + return; + } + X *tmp=&(*this)[getSize()-1]; + if ((*tmp)<elt) insertElement(elt, -1); + else if (!((*tmp)==elt)) cout<<"BAD APPEND!"<<endl; + } + void prepend(const X &elt){ + if (empty()) { + insertElement(elt, 0); + return; + } + X *tmp=&(*this)[getSize()-1]; + if (elt<(*tmp)) insertElement(elt, 0); + else if (!((*tmp)==elt)) cout<<"BAD PREPEND!"<<endl; + } + + X &operator[](int idx) const{return *getData(idx);} + const X &operator()(int idx)const {return *getDataConst(idx);} + +friend +void setunion(const flexset<X> &A, const flexset<X> &B,flexset<X> &result); +friend +void setintersection(const flexset<X> &A, const flexset<X> &B,flexset<X> &result); +friend +void setsymmetricdifference(const flexset<X> &A, const flexset<X> &B,flexset<X> &result); +friend +void setdifference(const flexset<X> &A, const flexset<X> &B,flexset<X> &result); +friend +void setdifferences(const flexset<X> &A, const flexset<X> &B,flexset<X> &AMB,flexset<X> &BMA); +friend +void setconvert(flexset<X> &A, const flexset<X> &B); +}; + +template <class X> +void setunion(const flexset<X> &A, const flexset<X> &B,flexset<X> &result); + + +template <class X> +void setunion(flexset<X> &A, const flexset<X> &B); + +template <class X> +void setintersection(const flexset<X> &A, const flexset<X> &B,flexset<X> &result); + + +template <class X> +void setsymmetricdifference(const flexset<X> &A, const flexset<X> &B,flexset<X> &result); + +template <class X> +void setdifference(const flexset<X> &A, const flexset<X> &B,flexset<X> &result); + +template <class X> +void setdifferences(const flexset<X> &A, const flexset<X> &B,flexset<X> &AMB,flexset<X> &BMA); + +template <class X> +void setconvert(flexset<X> &A, const flexset<X> &B); +#endif diff --git a/src/AMRPlus/gridreadtest.C b/src/AMRPlus/gridreadtest.C new file mode 100644 index 0000000..8321d2d --- /dev/null +++ b/src/AMRPlus/gridreadtest.C @@ -0,0 +1,40 @@ +// generated by Fast Light User Interface Designer (fluid) version 1.00 + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <iostream.h> +#include "IEEEIO.hh" +#include "AMRgridreaderPlus.h" + + + +int main(int argc, char** argv) { + IObase *ifile, *ofile; + AMRgridreaderPlus *reader; + + if (argc!=2){ + cerr<<"Usage: <filename>"<<endl; + exit(0); + } + char *fname=strdup(argv[1]); + ifile=new IEEEIO(fname, IObase::Read); + if (!ifile->isValid()){ + cerr<<fname<<" is not a valid IEEEIO file."<<endl; + exit(0); + } + + reader=new AMRgridreaderPlus(*ifile); + int ii=0; + AMRgridPlus grid, *tgrid; + while ((tgrid=reader->getGridInfo(grid, ii))!=NULL){ + cout<<"ScalarRange: "<<grid.scalarmin<<" to "<<grid.scalarmax<<endl; + ii++; + } + + delete ifile; + + + +} diff --git a/src/AMRPlus/jerror.h b/src/AMRPlus/jerror.h new file mode 100644 index 0000000..fc2fffe --- /dev/null +++ b/src/AMRPlus/jerror.h @@ -0,0 +1,291 @@ +/* + * jerror.h + * + * Copyright (C) 1994-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file defines the error and message codes for the JPEG library. + * Edit this file to add new codes, or to translate the message strings to + * some other language. + * A set of error-reporting macros are defined too. Some applications using + * the JPEG library may wish to include this file to get the error codes + * and/or the macros. + */ + +/* + * To define the enum list of message codes, include this file without + * defining macro JMESSAGE. To create a message string table, include it + * again with a suitable JMESSAGE definition (see jerror.c for an example). + */ +#ifndef JMESSAGE +#ifndef JERROR_H +/* First time through, define the enum list */ +#define JMAKE_ENUM_LIST +#else +/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ +#define JMESSAGE(code,string) +#endif /* JERROR_H */ +#endif /* JMESSAGE */ + +#ifdef JMAKE_ENUM_LIST + +typedef enum { + +#define JMESSAGE(code,string) code , + +#endif /* JMAKE_ENUM_LIST */ + +JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */ + +/* For maintenance convenience, list is alphabetical by message code name */ +JMESSAGE(JERR_ARITH_NOTIMPL, + "Sorry, there are legal restrictions on arithmetic coding") +JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix") +JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix") +JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode") +JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS") +JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range") +JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported") +JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition") +JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace") +JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace") +JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length") +JMESSAGE(JERR_BAD_LIB_VERSION, + "Wrong JPEG library version: library is %d, caller expects %d") +JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan") +JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d") +JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d") +JMESSAGE(JERR_BAD_PROGRESSION, + "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d") +JMESSAGE(JERR_BAD_PROG_SCRIPT, + "Invalid progressive parameters at scan script entry %d") +JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors") +JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d") +JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d") +JMESSAGE(JERR_BAD_STRUCT_SIZE, + "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u") +JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access") +JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small") +JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here") +JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet") +JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d") +JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request") +JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d") +JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x") +JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d") +JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d") +JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)") +JMESSAGE(JERR_EMS_READ, "Read from EMS failed") +JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed") +JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan") +JMESSAGE(JERR_FILE_READ, "Input file read error") +JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?") +JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet") +JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow") +JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry") +JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels") +JMESSAGE(JERR_INPUT_EMPTY, "Empty input file") +JMESSAGE(JERR_INPUT_EOF, "Premature end of input file") +JMESSAGE(JERR_MISMATCHED_QUANT_TABLE, + "Cannot transcode due to multiple use of quantization table %d") +JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data") +JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change") +JMESSAGE(JERR_NOTIMPL, "Not implemented yet") +JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time") +JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported") +JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined") +JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image") +JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined") +JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x") +JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)") +JMESSAGE(JERR_QUANT_COMPONENTS, + "Cannot quantize more than %d color components") +JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors") +JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors") +JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers") +JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker") +JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x") +JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers") +JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF") +JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s") +JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file") +JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file") +JMESSAGE(JERR_TFILE_WRITE, + "Write failed on temporary file --- out of disk space?") +JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines") +JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x") +JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up") +JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation") +JMESSAGE(JERR_XMS_READ, "Read from XMS failed") +JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed") +JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT) +JMESSAGE(JMSG_VERSION, JVERSION) +JMESSAGE(JTRC_16BIT_TABLES, + "Caution: quantization tables are too coarse for baseline JPEG") +JMESSAGE(JTRC_ADOBE, + "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d") +JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u") +JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u") +JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x") +JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x") +JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d") +JMESSAGE(JTRC_DRI, "Define Restart Interval %u") +JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u") +JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u") +JMESSAGE(JTRC_EOI, "End Of Image") +JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d") +JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d") +JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE, + "Warning: thumbnail image size does not match data length %u") +JMESSAGE(JTRC_JFIF_EXTENSION, + "JFIF extension marker: type 0x%02x, length %u") +JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image") +JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u") +JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x") +JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u") +JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors") +JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors") +JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization") +JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d") +JMESSAGE(JTRC_RST, "RST%d") +JMESSAGE(JTRC_SMOOTH_NOTIMPL, + "Smoothing not supported with nonstandard sampling ratios") +JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d") +JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d") +JMESSAGE(JTRC_SOI, "Start of Image") +JMESSAGE(JTRC_SOS, "Start Of Scan: %d components") +JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d") +JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d") +JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s") +JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s") +JMESSAGE(JTRC_THUMB_JPEG, + "JFIF extension marker: JPEG-compressed thumbnail image, length %u") +JMESSAGE(JTRC_THUMB_PALETTE, + "JFIF extension marker: palette thumbnail image, length %u") +JMESSAGE(JTRC_THUMB_RGB, + "JFIF extension marker: RGB thumbnail image, length %u") +JMESSAGE(JTRC_UNKNOWN_IDS, + "Unrecognized component IDs %d %d %d, assuming YCbCr") +JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u") +JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u") +JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d") +JMESSAGE(JWRN_BOGUS_PROGRESSION, + "Inconsistent progression sequence for component %d coefficient %d") +JMESSAGE(JWRN_EXTRANEOUS_DATA, + "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x") +JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment") +JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code") +JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d") +JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file") +JMESSAGE(JWRN_MUST_RESYNC, + "Corrupt JPEG data: found marker 0x%02x instead of RST%d") +JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG") +JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines") + +#ifdef JMAKE_ENUM_LIST + + JMSG_LASTMSGCODE +} J_MESSAGE_CODE; + +#undef JMAKE_ENUM_LIST +#endif /* JMAKE_ENUM_LIST */ + +/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */ +#undef JMESSAGE + + +#ifndef JERROR_H +#define JERROR_H + +/* Macros to simplify using the error and trace message stuff */ +/* The first parameter is either type of cinfo pointer */ + +/* Fatal errors (print message and exit) */ +#define ERREXIT(cinfo,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT1(cinfo,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT2(cinfo,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT3(cinfo,code,p1,p2,p3) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (cinfo)->err->msg_parm.i[2] = (p3), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT4(cinfo,code,p1,p2,p3,p4) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (cinfo)->err->msg_parm.i[2] = (p3), \ + (cinfo)->err->msg_parm.i[3] = (p4), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXITS(cinfo,code,str) \ + ((cinfo)->err->msg_code = (code), \ + strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) + +#define MAKESTMT(stuff) do { stuff } while (0) + +/* Nonfatal errors (we can keep going, but the data is probably corrupt) */ +#define WARNMS(cinfo,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) +#define WARNMS1(cinfo,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) +#define WARNMS2(cinfo,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) + +/* Informational/debugging messages */ +#define TRACEMS(cinfo,lvl,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) +#define TRACEMS1(cinfo,lvl,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) +#define TRACEMS2(cinfo,lvl,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) +#define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + _mp[4] = (p5); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMSS(cinfo,lvl,code,str) \ + ((cinfo)->err->msg_code = (code), \ + strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) + +#endif /* JERROR_H */ diff --git a/src/AMRPlus/makefile b/src/AMRPlus/makefile new file mode 100644 index 0000000..56b24de --- /dev/null +++ b/src/AMRPlus/makefile @@ -0,0 +1,70 @@ +SRCS= \ + AMRwriterPlus.C \ + AMRgridreaderPlus.C \ + AMRfilereaderPlus.C \ + flexset.C \ + AMRreaderPlus.C + +OBJS = $(SRCS:.C=.o) +DEPEND = Dpndfile +#################### + +SHELL = /bin/sh + +IEEE_ROOT=/nfs/zeus/lcascr1/mahall/AmrProject/FlexIO + + +ALL_INC = -I$(IEEE_ROOT)/include -I$(HDF_ROOT)/include + + +DEFS = +CC = cc +#COMP_FLAGS = -n32 -mips4 -LNO -IPA -Ofast +COMP_FLAGS = -64 -mips4 -g + +CFLAGS = -c -float ${COMP_FLAGS} -DOPENGL \ + -I$(IEEE_ROOT)/include \ + -DVTK21 $(VTKINCD) -noinline -woff 1681-1682,3322 +CXXFLAGS = ${CFLAGS} + + +LINK = ${CPP} +LIBS = -L$(IEEE_ROOT)/lib -L$(HDF_ROOT)/lib -L. \ + -lhlio -lieeeio -lAMR \ + -lX11 -lm \ + -lGL -lICE -lXt + +.C: $@.o ${OBJS} + $(CXX) ${COMP_FLAGS} -o $@ \ + ${OBJS} $@.o $(LIBS) + + +include $(DEPEND) + +AMRPlusConv: AMRPlusConv.o libAMRPlus.a + $(CXX) ${COMP_FLAGS} -o $@ \ + $@.o -lAMRPlus $(LIBS) + +gridreadtest: gridreadtest.o libAMRPlus.a + $(CXX) ${COMP_FLAGS} -o $@ \ + $@.o -lAMRPlus $(LIBS) + +readtest: readtest.o libAMRPlus.a + $(CXX) ${COMP_FLAGS} -o $@ \ + $@.o -lAMRPlus $(LIBS) + +filereadtest:filereadtest.o libAMRPlus.a + $(CXX) ${COMP_FLAGS} -o $@ \ + $@.o -lAMRPlus $(LIBS) + +libAMRPlus.a: ${OBJS} + rm -f libAMRPlus + ar r libAMRPlus.a ${OBJS} + +dep: $(SRCS) + CC -M ${ALL_INC} $(SRCS) readtest.C > $(DEPEND) + smake + + +clean: + rm *.o diff --git a/src/AMRPlus/ordarrays.h b/src/AMRPlus/ordarrays.h new file mode 100644 index 0000000..b830984 --- /dev/null +++ b/src/AMRPlus/ordarrays.h @@ -0,0 +1,23 @@ +#include "arrays.h" + + + +template <class X> +class flexset : private array<X>{ + public: + ordarray(): array<X>(){}; + ~ordarray(){}; + int insert(const X &elt){ + int a=0, b=getLength()-1; + X* data=this->getData(0); + if (elt==data[0]) this->insertElement(elt, 0); + if (elt==data[b]) insertElement(elt, b); + int c=(a+b)/2; + while (elt!=data[c]){ + if (a==b) {insertElement(elt, a); return a;} + if (elt<data[c]) + } + + }; + +}; diff --git a/src/AMRPlus/readtest.C b/src/AMRPlus/readtest.C new file mode 100644 index 0000000..001441b --- /dev/null +++ b/src/AMRPlus/readtest.C @@ -0,0 +1,54 @@ +// generated by Fast Light User Interface Designer (fluid) version 1.00 + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <iostream.h> +#include "IEEEIO.hh" +#include "AMRreaderPlus.h" + + + +int main(int argc, char** argv) { + IObase *ifile, *ofile; + AMRreaderPlus *reader; + + if (argc!=2){ + cerr<<"Usage: <filename>"<<endl; + exit(0); + } + char *fname=strdup(argv[1]); + ifile=new IEEEIO(fname, IObase::Read); + if (!ifile->isValid()){ + cerr<<fname<<" is not a valid IEEEIO file."<<endl; + exit(0); + } + + reader=new AMRreaderPlus(*ifile); + + IdxSet thegs; + reader->getActive(thegs); + + + for (int ii=0;ii<thegs.getSize();ii++){ + cout<<"Grid #"<<ii<<" : Level="<<reader->grids(thegs[ii].idx).level<<endl; + } + + /* + for (int ii=0;ii<reader->maxtime+1;ii++){ + cout<<endl<<"Timestep #"<<ii<<": "<<endl; + for (int jj=0;jj<reader->maxlevel+1;jj++){ + cout<<"\nLevel #"<<jj<<" grids: "; + for (int kk=0;kk<(*reader->leveltimes)(jj, ii).getSize();kk++){ + cout<<" "<<(*reader->leveltimes)(jj, ii)[kk].idx; + } + } + } + */ + reader->loadData(); + delete ifile; + + + +} diff --git a/src/AMRPlus/settst.C b/src/AMRPlus/settst.C new file mode 100644 index 0000000..743791b --- /dev/null +++ b/src/AMRPlus/settst.C @@ -0,0 +1,59 @@ +#include <iostream.h> +#include "flexset.h" +#include <unistd.h> + +int iseven(const int &y){return !(y&1);} +struct orec; +struct irec{ + int key, data; + irec(int nkey=0, int ndata=0){key=nkey;data=ndata;} + int operator<(const irec &b) const{return key<b.key;} + int operator==(const irec &b) const{return key==b.key;} + int operator<(const orec &b) const; + int operator==(const orec &b) const; +}; + +struct orec{ + int key; + char *str; + orec(int nkey=0){key=nkey;} + int operator<(const orec &b) const{return key<b.key;} + int operator==(const orec &b) const{return key==b.key;} + int operator<(const irec &b) const{return key<b.key;} + int operator==(const irec &b) const{return key==b.key;} +}; + +int irec::operator<(const orec &b) const{return key<b.key;}; +int irec::operator==(const orec &b) const{return key<b.key;}; + +void main(){ + flexset<irec> arr1, arr2, arr3, arr4, arr5; + flexset<orec> iarr1, iarr2; + irec tst; + int ii; + + for (ii=0;ii<20;ii++){ + tst.key=rand()%20; + tst.data=ii; + arr1.insert(tst); + } + + for (ii=0;ii<20;ii++){ + iarr1.insert(rand()%20); + } + + setdifferences(arr1, iarr1, arr2, iarr2); + for (ii=0;ii<arr1.getSize();ii++) + cout<<arr1[ii].key<<" : "<<arr1[ii].data<<endl; + cout<<endl; + for (ii=0;ii<iarr1.getSize();ii++) + cout<<iarr1[ii].key<<endl; + cout<<endl; + for (ii=0;ii<arr2.getSize();ii++) + cout<<arr2[ii].key<<" : "<<arr2[ii].data<<endl; + cout<<endl; + for (ii=0;ii<iarr2.getSize();ii++) + cout<<iarr2[ii].key<<endl; + cout<<endl; + +} diff --git a/src/AMRPlus/testread.C b/src/AMRPlus/testread.C new file mode 100644 index 0000000..b0b7c29 --- /dev/null +++ b/src/AMRPlus/testread.C @@ -0,0 +1,170 @@ +// generated by Fast Light User Interface Designer (fluid) version 1.00 + +#include <vtk.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include "vtkAMRStructuredPointsReader.h" +vtkRenderer *renderer; +vtkRenderWindow* renWin; +vtkOutlineFilter *outline; +vtkContourFilter *contour; +vtkPolyDataMapper *outlineMapper; +vtkPolyDataMapper *contMapper; +vtkActor *outlineActor; +vtkActor *contActor; +vtkPolyData *t, *outlineOut, *contOut, *t1; +vtkStructuredPoints *temp, *out; +vtkAMRStructuredPointsReader* spr=0; + + + +int main(int argc, char** argv) { + // Make a window to put the rendering window in. FLTK interface. + // Fl_Window* w; + //{ Fl_Window* o = w = MainWin = + // new Fl_Window(500, 500, "AMRTest"); + // w = o; + // o->end(); + // } + //renWin = vtkFlRenderWindow::New(); + renderer = vtkRenderer::New(); + + // uncomment this to use the VTK rendering window + //renderer->SetBackground(0.5, 0.5, 0.5); + renWin = vtkRenderWindow::New(); + + renWin->AddRenderer(renderer); + + // uncomment this to use VTK event handler + vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); + iren->SetRenderWindow(renWin); + + //create a reader and open the file "amr.raw" + spr = vtkAMRStructuredPointsReader::New(); + spr->SetFileName("/nfs/zeus/lcascr1/pushkare/work/amr.raw"); + cout<<"NLevels: "<<spr->GetNumLevels()<<endl; + cout<<"NTime: "<<spr->GetNumTimeSteps()<<endl; + int nlevel=0; + if (argc>1) nlevel=atoi(argv[1]); + spr->SelectLevel(nlevel); + spr->SelectTimeStep(0); + spr->Update(); + + int n = spr->GetNumDatasets(); + cout<<"NDataSets: "<<n<<endl; + //initialize the filters for isosurface and bounding box + outline = vtkOutlineFilter::New(); + contour = vtkContourFilter::New(); + + //initialize the data collections to collect data in the various stages of + //the pipeline + vtkDataSetCollection *Data = vtkDataSetCollection::New(); + vtkPolyDataCollection *PolyData = vtkPolyDataCollection::New(); + vtkPolyDataCollection *Outlines = vtkPolyDataCollection::New(); + + // This loop reads the grids from a file and puts them into Data, the + //dataset collection. + for (int i=0; i<n; i++) + { + spr->SelectDataset(i); + spr->Update(); + out = spr->GetOutput(); + temp = (vtkStructuredPoints*)out->MakeObject(); + + temp->CopyStructure(out); + temp->GetPointData()->DeepCopy(out->GetPointData()); + temp->GetCellData()->DeepCopy(out->GetCellData()); + temp->ForceUpdate(); + + Data->AddItem(temp); + } + + int NContours = 0; + Data->InitTraversal(); + + + // This loop takes the grids from Data and processes them to get an outline + // and isosurface for each grid. The isovalue for the dataset is set to 0.86 + // for now. + for (int j=0; j<n; j++) + { + float *x1, Iso; + temp = (vtkStructuredPoints*)Data->GetNextItem(); + x1 = temp->GetPointData()->GetScalars()->GetRange(); + Iso = 0.86; + + //if the isovalue is out of bounds for a particular grid, then just + //ignore that grid. + if (Iso < x1[0] || Iso > x1[1]) + continue; + NContours++; + + //produce the isosurface and stick it into the PolyData collection. + contour->SetInput(temp); + contour->SetValue(0, Iso); + contour->Update(); + contOut = contour->GetOutput(); + + t = (vtkPolyData*)contOut->MakeObject(); + + t->CopyStructure(contOut); + t->GetPointData()->DeepCopy(contOut->GetPointData()); + t->GetCellData()->DeepCopy(contOut->GetCellData()); + t->ForceUpdate(); + + PolyData->AddItem(t); + + //produce a bounding box and put it into an Outlines collection + outline->SetInput(temp); + outline->Update(); + + outlineOut = outline->GetOutput(); + + t1 = (vtkPolyData*)outlineOut->MakeObject(); + t1->CopyStructure(outlineOut); + + Outlines->AddItem(t1); + + } + + PolyData->InitTraversal(); + Outlines->InitTraversal(); + + + //This loop takes care of the final mapper and actor steps of the pipeline + for (int k=0; k<NContours; k++) + { + //produce and add the isosurface actor + contMapper = vtkPolyDataMapper::New(); + contMapper->SetInput(PolyData->GetNextItem()); + contMapper->ImmediateModeRenderingOn(); + contActor = vtkActor::New(); + contActor->SetMapper(contMapper); + contActor->GetProperty()->SetRepresentationToSurface(); + renderer->AddActor(contActor); + + //produce and add the bounding box actor, which is colored RED + outlineMapper = vtkPolyDataMapper::New(); + outlineMapper->SetInput(Outlines->GetNextItem()); + outlineActor = vtkActor::New(); + outlineActor->SetMapper(outlineMapper); + outlineActor->GetProperty()->SetColor(1.0, 0.0, 0.0); + renderer->AddActor(outlineActor); + + } + + // this part makes sure that something actually does show up on the screen + // w->show(argc, argv); + // w->begin(); + // vtkwin = new Fl_vtk_Window( renWin, 1, 1, 498, 498); + // vtkwin->show(1, argv); + //w->end(); + + //return Fl::run(); + + //uncomment this and comment the FLTK stuff to use VTK window and event loop. + renWin->Render(); + iren->Start(); +} diff --git a/src/AMRPlus/tst.C b/src/AMRPlus/tst.C new file mode 100644 index 0000000..cdc9f03 --- /dev/null +++ b/src/AMRPlus/tst.C @@ -0,0 +1,42 @@ +#include <iostream.h> +#include "flexset.h" + +void main(){ + flexset<int> arr1, arr2; + int tst; + int ii; + + for (ii=0;ii<15;ii++){ + tst=rand() %10; + arr1.insert(tst); + } + for (ii=0;ii<15;ii++){ + tst=rand() %10; + arr2.insert(tst); + } + + flexset<int> arr3; + for (ii=0;ii<arr1.getSize();ii++){cout<<arr1[ii]<<endl;} + cout<<endl; + for (ii=0;ii<arr2.getSize();ii++){cout<<arr2[ii]<<endl;} + cout<<endl; + + setunion(arr1, arr2, arr3); + cout<<endl;<<"Union: "<<endl; + for (ii=0;ii<arr3.getSize();ii++){cout<<arr3[ii]<<endl;} + + setintersection(arr1, arr2, arr3); + cout<<endl;<<"Intersection: "<<endl; + for (ii=0;ii<arr3.getSize();ii++){cout<<arr3[ii]<<endl;} + + setdifference(arr1, arr2, arr3); + cout<<endl;<<"Difference: "<<endl; + for (ii=0;ii<arr3.getSize();ii++){cout<<arr3[ii]<<endl;} + + setsymmetricdifference(arr1, arr2, arr3); + cout<<endl;<<"Symmetric Difference: "<<endl; + for (ii=0;ii<arr3.getSize();ii++){cout<<arr3[ii]<<endl;} + + + +} |