AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

DAGHIO_hdf_ncsa.C

Go to the documentation of this file.
00001 
00006 #include "DAGHIO_hdf_ncsa.h"
00007 #include "DAGH.h"
00008  
00009 
00010 char* lastfilename = (char*) 0;
00011 
00012 void DAGHIO_HDF_NCSA_Write(GridHierarchy& gh, struct gdhdr* hdr, void* data)
00013   {
00014    assert (hdr->gfdatatype == DAGH_Double);
00015 
00016    const BBox &bb = hdr->bbox;
00017    int rank = bb.rank;
00018 
00019    char* gfname = hdr->gfname;
00020 
00021    // changed from int to int32 --- RD
00022    int32 dims[5], origin[5], resolution[5];
00023    
00024    for (int i=0;i<rank;i++) {
00025      dims[i] = (int32) bb.extents(i);
00026      origin[i] = (int32) bb.lower(i);
00027      resolution[i] = (int32) bb.stepsize(i);
00028    }
00029 
00030    const int orank = rank;
00031    /* Fake up 3D data as a slice for now.  This is clearly a kludge. */
00032    if (orank==1 || orank==2) {
00033      rank          = 3;
00034      dims[2]       = 1;
00035      origin[2]     = 0;
00036      resolution[2] = 1;
00037      resolution[3] = 1;
00038      if (orank==1) {
00039        dims[1]       = 1;
00040        origin[1]     = 0;
00041        resolution[1] = 1;
00042      }
00043    }
00044  
00045    char filename[256];
00046 #ifdef DEBUG_IO
00047    (cout << "Writing a chunk with following:\n" <<
00048     "T   : " << hdr->time << "  L : " << hdr->level << 
00049     " NAME : " << gfname << "\n" <<
00050     "dims: " << dims[0] << " " << dims[1] << " " << dims[2] << "\n").flush();
00051 #endif
00052  
00053    sprintf(filename,"%s.hdf",gfname);
00054 
00055    if (lastfilename) {
00056      if(strcmp(lastfilename,filename)) {
00057        SDSflush(lastfilename);
00058        SDSclose(lastfilename);
00059      }
00060      delete [] lastfilename;
00061    }
00062    lastfilename = new char[strlen(filename)+1];
00063    sprintf(lastfilename,"%s",filename);
00064    
00065    SDSsetNT(filename,DFNT_FLOAT32); 
00066    
00067    double physical_time;
00068    memcpy((char *)&physical_time,hdr->physical_time,sizeof(double));
00069 
00070    float64* src_data = (float64*)data;
00071    float32* save_data = new float32[bb.size()];
00072    for (int32 c=0; c<bb.size(); c++)
00073      save_data[c] = (float32)src_data[c];
00074 
00075    AMRwriteData(filename, gfname,               
00076                 (int32)(hdr->owner),            
00077                 (int32)(hdr->level), 
00078                 (int32)(hdr->index), 
00079                 (int32)(hdr->time_value), 
00080                 (float64)(physical_time),
00081                 (int32)(rank),
00082                 dims, origin, resolution,
00083                 save_data);
00084    delete [] save_data;
00085   }
00086 
00087 void DAGHIO_HDF_NCSA_Read(GridHierarchy &gh, struct gdhdr* hdr, void* data)
00088   {
00089    assert (hdr->gfdatatype == DAGH_Double);
00090 
00091    cerr << "DAGHIO_ncsa_rnpl.C\n" << "Read is defined, but not implemented\n";
00092   }
00093 
00094 void DAGHIO_HDF_NCSA_Finalize() { 
00095   if (lastfilename) {
00096     SDSflush(lastfilename);
00097     SDSclose(lastfilename);
00098     delete [] lastfilename;
00099     lastfilename = (char *) 0;
00100   }
00101   SDScloseAll();
00102 }


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04