IsisDlm
Version 0.2
|
00001 00002 //_Title CubeIO.h Definition of basic ISIS support structure 00003 // 00004 //_Descr ISIS3 file/functionality definition. 00005 // 00006 //_Hist Jul 24 2004 Kris Becker, USGS 00007 //_Version: $Id: CubeIO.h,v 1.3 2009/07/30 00:15:37 kbecker Exp $ 00008 //_End 00010 #if !defined(CubeIO_h) 00011 #define CubeIO_h 00012 #include <string> 00013 #include "Idl.h" 00014 #include "IdlVariable.h" 00015 #include "IdlVarTypes.h" 00016 #include "CubeIoPolicy.h" 00017 00018 namespace ISISDLM { 00019 00020 // Define the supported I/O engines here 00021 typedef CubeIoPolicy<double, IDL::IdlDouble, StdIO> DoubleIO; 00022 typedef CubeIoPolicy<unsigned char, IDL::IdlByte, RawIO> ByteIO; 00023 typedef CubeIoPolicy<short int, IDL::IdlInt2, RawIO> WordIO; 00024 typedef CubeIoPolicy<float, IDL::IdlFloat, RawIO> FloatIO; 00025 00029 template <class T> 00030 void FetchData(T &reader, Isis::Cube &cube, const IDL::ArrayDims &dims, 00031 const std::string &vname, IDL::IdlVariable &vData) { 00032 00033 // Allocate the reader 00034 typedef typename T::DataType DTYPE; 00035 IDL::IdlVarType vtype = static_cast<IDL::IdlVarType> (reader.getVarType()); 00036 00037 // Get either a 2 or three dimensional array 00038 if (dims.Dim(2) == 1) { 00039 vData = IDL::IdlVariable(vname, vtype, 00040 IDL::ArrayDims(dims.Dim(0),dims.Dim(1))); 00041 } 00042 else { 00043 vData = IDL::IdlVariable(vname, vtype, dims); 00044 } 00045 00046 // Get the variable reference and read the data. Note that it matters 00047 // not that we are using a 3 dimensional TNT injection buffer 00048 DTYPE *dref; 00049 dref = reinterpret_cast<DTYPE *> (vData.vRef(0)); 00050 TNT::Array3D<DTYPE> data(dims.Dim(2), dims.Dim(1), dims.Dim(0), dref); 00051 reader.Read(cube, data); 00052 return; 00053 } 00054 00055 00059 template <class T> 00060 void PutData(T &writer, Isis::Cube &cube, const IDL::ArrayDims &dims, 00061 IDL::IdlVariable &vData) { 00062 00063 // Allocate the reader 00064 typedef typename T::DataType DTYPE; 00065 00066 // Get the variable reference and read the data. Note that it matters 00067 // not that we are using a 3 dimensional TNT injection buffer 00068 DTYPE *dref; 00069 dref = reinterpret_cast<DTYPE *> (vData.vRef(0)); 00070 TNT::Array3D<DTYPE> data(dims.Dim(2), dims.Dim(1), dims.Dim(0), dref); 00071 writer.Write(data, cube); 00072 return; 00073 } 00074 00075 00076 } 00077 #endif