datahndl.cpp

Go to the documentation of this file.
00001 #include "datahndl.h"
00002 #include "blas.h"
00003 #include "mvaexit.h"
00004 
00005 
00006 //
00007 //******************************************************************************
00008 //                    DATAHNDL.CPP
00009 //******************************************************************************
00010 //
00011 //
00012 //********************************************************************************
00013 //
00014 //            Chris Anderson (C) UCLA 1995
00015 //
00016 //            Thu Sep 07 00:49:17 1995
00017 //
00018 //********************************************************************************
00019 //
00020 //
00021 //********************************************************************************
00022 //                    CONSTRUCTORS
00023 //********************************************************************************
00024 
00025 CAMdataHandler::CAMdataHandler()
00026 {
00027     dataType        = 0;
00028     dataPointer     = 0;
00029     dataSize        = 0;
00030     temporaryFlag   = 0;
00031     referenceCount  = 0;
00032 }
00033 
00034 CAMdataHandler::CAMdataHandler( const CAMdataHandler& A)
00035 {
00036     if(A.temporaryFlag == 1)
00037     {
00038         dataType        = A.dataType;
00039         dataSize        = A.dataSize;
00040         dataPointer     = A.dataPointer;
00041         temporaryFlag   = 0;
00042         referenceCount  = 0;
00043 
00044     }
00045     else
00046     {
00047         allocateData(A.dataSize,A.dataType);
00048         setTypeFlag(A.dataType);
00049         copyData(A.dataSize,A.dataPointer);
00050         temporaryFlag   = 0;
00051         referenceCount  = 0;
00052     }
00053 }
00054 
00055 CAMdataHandler::CAMdataHandler(long size, int dType)
00056 {
00057         allocateData(size,dType);
00058         setTypeFlag(dType);
00059         temporaryFlag   = 0;
00060         referenceCount  = 0;
00061 }
00062 //
00063 //********************************************************************************
00064 //                    DESTRUCTOR
00065 //********************************************************************************
00066 //
00067 CAMdataHandler::~CAMdataHandler()
00068 {
00069     if(temporaryFlag == 0) destroyData();
00070 }
00071 //
00072 //********************************************************************************
00073 //                    OUTPUT
00074 //********************************************************************************
00075 //
00076 ostream&  operator <<(ostream& out_stream, const CAMdataHandler& A)
00077 {
00078 
00079 #ifndef __NO_COMPLEX__
00080     complex* cdataP;
00081 #endif
00082 
00083     long i;
00084 
00085     switch(A.dataType)
00086     {
00087     case  CAMType::typeInt :
00088     int i_out;
00089     for(i = 0; i < A.dataSize; i++)
00090     {A.getDataValue(i, i_out); out_stream  << i_out << " ";}
00091     out_stream  << endl;
00092     break;
00093 
00094     case  CAMType::typeLong :
00095     long l_out;
00096     for(i = 0; i < A.dataSize; i++)
00097     {A.getDataValue(i, l_out); out_stream  << l_out << " ";}
00098     out_stream << endl;
00099     break;
00100 
00101     case  CAMType::typeFloat :
00102     float f_out;
00103     for(i = 0; i < A.dataSize; i++)
00104     {A.getDataValue(i, f_out); out_stream  << f_out << " ";}
00105     out_stream << endl;
00106     break;
00107 
00108     case  CAMType::typeDouble :
00109     double d_out;
00110     for(i = 0; i < A.dataSize; i++)
00111     {A.getDataValue(i, d_out); out_stream  << d_out << " ";}
00112     out_stream << endl;
00113     break;
00114 
00115 #ifndef __NO_COMPLEX__
00116     case  CAMType::typeComplex :
00117     cdataP = (complex*)A.dataPointer;
00118     for(i = 0; i < A.dataSize; i++)
00119     out_stream << *(cdataP + i) << " ";
00120     out_stream << endl;
00121     break;
00122 #endif
00123 
00124     }
00125     return(out_stream);
00126 
00127 }
00128 //
00129 //********************************************************************************
00130 //                    ASSIGNMENT
00131 //********************************************************************************
00132 //
00133 CAMdataHandler&  CAMdataHandler::operator =( const CAMdataHandler& A)
00134 {
00135     if(A.temporaryFlag == 1)
00136     {
00137         dataType        = A.dataType;
00138         dataSize        = A.dataSize;
00139         dataPointer     = A.dataPointer;
00140         temporaryFlag   = 0;
00141         referenceCount  = 0;
00142     }
00143     else
00144     {
00145         destroyData();
00146         allocateData(A.dataSize,A.dataType);
00147         setTypeFlag(A.dataType);
00148         copyData(A.dataSize,A.dataPointer);
00149         temporaryFlag   = 0;
00150         referenceCount  = 0;
00151     }
00152     return *this;
00153 }
00154 
00155 //
00156 //********************************************************************************
00157 //                    MEMBER_FUNCTIONS
00158 //********************************************************************************
00159 //
00160 
00161 void  CAMdataHandler::initialize()
00162 {
00163     destroyData();
00164 
00165     dataType        = 0;
00166     dataPointer     = 0;
00167     dataSize        = 0;
00168     temporaryFlag   = 0;
00169     referenceCount  = 0;
00170 }
00171 
00172 void  CAMdataHandler::initialize(const CAMdataHandler& A)
00173 {
00174 
00175 
00176     if(A.temporaryFlag == 1)
00177     {
00178         dataType        = A.dataType;
00179         dataSize        = A.dataSize;
00180         dataPointer     = A.dataPointer;
00181         temporaryFlag   = 0;
00182     }
00183     else
00184     {
00185         destroyData();
00186         allocateData(A.dataSize,A.dataType);
00187         setTypeFlag(A.dataType);
00188         copyData(A.dataSize,A.dataPointer);
00189         temporaryFlag   = 0;
00190     }
00191 }
00192 
00193 void CAMdataHandler::initialize(long size, int dType)
00194 {
00195         destroyData();
00196         allocateData(size,dType);
00197         setTypeFlag(dType);
00198         temporaryFlag   = 0;
00199 }
00200 void  CAMdataHandler::setTypeFlag(int dType)
00201 {
00202 
00203     switch(dType)
00204     {
00205     case CAMType::typeInt :
00206 
00207     dataType        = CAMType::typeInt;
00208     break;
00209 
00210     case CAMType::typeLong :
00211 
00212     dataType        = CAMType::typeLong;
00213     break;
00214 
00215     case CAMType::typeFloat :
00216 
00217     dataType        = CAMType::typeFloat;
00218     break;
00219 
00220     case CAMType::typeDouble :
00221 
00222     dataType        = CAMType::typeDouble;
00223     break;
00224 
00225 #ifndef __NO_COMPLEX__
00226     case CAMType::typeComplex :
00227     dataType        = CAMType::typeComplex;
00228     break;
00229 #endif
00230     }
00231 
00232 }
00233 
00234 void  CAMdataHandler::allocateData(long size, int dType)
00235 {
00236 
00237     switch(dType)
00238     {
00239     case CAMType::typeInt :
00240     dataSize        = size;
00241     dataPointer     = new int[size];
00242     break;
00243 
00244     case CAMType::typeLong :
00245     dataSize        = size;
00246     dataPointer     = new long[size];
00247     break;
00248 
00249     case CAMType::typeFloat :
00250     dataSize        = size;
00251     dataPointer     = new float[size];
00252     break;
00253 
00254     case CAMType::typeDouble :
00255     dataSize        = size;
00256     dataPointer     = new double[size];
00257     break;
00258 
00259 #ifndef __NO_COMPLEX__
00260     case CAMType::typeComplex :
00261     dataSize        = size;
00262     dataPointer     = new complex[size];
00263     break;
00264 #endif
00265     }
00266 //
00267 //  initialize with zero's
00268 //
00269 #ifndef __NO_BLAS__
00270     int    izero    = 0;
00271     long   lzero    = 0;
00272     float  fzero    = 0.0;
00273     double dzero    = 0.0;
00274     long   strideX = 0;
00275     long   strideY = 1;
00276 #endif
00277 
00278     switch(dType)
00279     {
00280     case  CAMType::typeInt :
00281     register int* idataP;
00282 #ifdef __NO_BLAS__
00283     for(idataP = (int*)dataPointer; idataP < (int*)dataPointer + size; idataP++)
00284      *(idataP) = 0;
00285 #else
00286     idataP = (int*)dataPointer;
00287     icopy_(&size,&izero,&strideX, idataP, &strideY);
00288 #endif
00289     break;
00290 
00291     case  CAMType::typeLong :
00292     register long* ldataP;
00293 #ifdef __NO_BLAS__
00294     for(ldataP = (long*)dataPointer; ldataP < (long*)dataPointer + size; ldataP++)
00295      *(ldataP) = 0;
00296 #else
00297     ldataP = (long*)dataPointer;
00298     lcopy_(&size,&lzero,&strideX, ldataP, &strideY);
00299 #endif
00300     break;
00301 
00302     case  CAMType::typeFloat :
00303     register  float* fdataP;
00304 #ifdef __NO_BLAS__
00305     for(fdataP = (float*)dataPointer; fdataP < (float*)dataPointer + size; fdataP++)
00306      *(fdataP) = 0.0;
00307 #else
00308     fdataP = (float*)dataPointer;
00309     scopy_(&size,&fzero,&strideX, fdataP, &strideY);
00310 #endif
00311     break;
00312 
00313     case  CAMType::typeDouble :
00314     register double* ddataP;
00315 #ifdef __NO_BLAS__
00316     for(ddataP = (double*)dataPointer; ddataP < (double*)dataPointer + size; ddataP++)
00317      *(ddataP) = 0.0;
00318 #else
00319     ddataP = (double*)dataPointer;
00320     dcopy_(&size,&dzero,&strideX, ddataP, &strideY);
00321 #endif
00322 
00323     break;
00324 
00325 #ifndef __NO_COMPLEX__
00326     case  CAMType::typeComplex :
00327     complex* cdataP;
00328     for(cdataP = (complex*)dataPointer; cdataP < (complex*)dataPointer + size; cdataP++)
00329     *(cdataP) = complex(0.0,0.0);
00330     break;
00331 #endif
00332 
00333     }
00334 }
00335 
00336 void  CAMdataHandler::copyData(long Size, void* dataP)
00337 {
00338 #ifndef __NO_BLAS__
00339     long strideX = 1;
00340     long strideY = 1;
00341 #endif
00342 
00343     switch(dataType)
00344     {
00345     case  CAMType::typeInt :
00346     register int* idataP; register  int* inIdataP;
00347 #ifdef __NO_BLAS__
00348     for(idataP = (int*)dataPointer, inIdataP = (int*)dataP;
00349     idataP < (int*)dataPointer + Size; idataP++, inIdataP++)
00350     *(idataP) = *(inIdataP);
00351 #else
00352     idataP   = (int*)dataPointer;
00353     inIdataP = (int*)dataP;
00354     icopy_(&Size,inIdataP,&strideX, idataP, &strideY);
00355 #endif
00356 
00357     break;
00358 
00359     case  CAMType::typeLong :
00360     register long* ldataP; register  long* inLdataP;
00361 #ifdef __NO_BLAS__
00362     for(ldataP = (long*)dataPointer, inLdataP = (long*)dataP;
00363     ldataP < (long*)dataPointer + Size; ldataP++, inLdataP++)
00364     *(ldataP) = *(inLdataP);
00365 #else
00366     ldataP   = (long*)dataPointer;
00367     inLdataP = (long*)dataP;
00368     lcopy_(&Size,inLdataP,&strideX, ldataP, &strideY);
00369 #endif
00370 
00371     break;
00372 
00373     case  CAMType::typeFloat :
00374     register float* fdataP;  register float*  inFdataP;
00375 #ifdef __NO_BLAS__
00376     for(fdataP = (float*)dataPointer, inFdataP = (float*)dataP;
00377     fdataP < (float*)dataPointer + Size; fdataP++, inFdataP++)
00378     *(fdataP) = *(inFdataP);
00379 #else
00380     fdataP = (float*)dataPointer;
00381     inFdataP = (float*)dataP;
00382     scopy_(&Size,inFdataP,&strideX, fdataP, &strideY);
00383 #endif
00384 
00385     break;
00386 
00387     case  CAMType::typeDouble :
00388     register double* ddataP;  register double* inDdataP;
00389 #ifdef __NO_BLAS__
00390     for(ddataP = (double*)dataPointer, inDdataP = (double*)dataP;
00391     ddataP < (double*)dataPointer + Size; ddataP++, inDdataP++)
00392      *(ddataP) = *(inDdataP);
00393 #else
00394     ddataP   = (double*)dataPointer;
00395     inDdataP = (double*)dataP;
00396     dcopy_(&Size,inDdataP,&strideX, ddataP, &strideY);
00397 #endif
00398 
00399     break;
00400 
00401 #ifndef __NO_COMPLEX__
00402     case  CAMType::typeComplex :
00403     complex* cdataP;  complex* inCdataP;
00404     for(cdataP = (complex*)dataPointer, inCdataP = (complex*)dataP;
00405     cdataP < (complex*)dataPointer + Size; cdataP++, inCdataP++)
00406      *(cdataP) = *(inCdataP);
00407     break;
00408 #endif
00409 
00410     }
00411 }
00412 
00413 void  CAMdataHandler::destroyData()
00414 {
00415     if(dataType != 0)
00416     {
00417     switch(dataType)
00418     {
00419     case  CAMType::typeInt :
00420     int* idataP;
00421     idataP = (int*)dataPointer;
00422     if(idataP != 0) delete [] idataP;
00423     break;
00424 
00425     case  CAMType::typeLong :
00426     long* ldataP;
00427     ldataP = (long*)dataPointer;
00428     if(ldataP != 0) delete [] ldataP;
00429     break;
00430 
00431     case  CAMType::typeFloat :
00432     float* fdataP;
00433     fdataP = (float*)dataPointer;
00434     if(fdataP != 0) delete [] fdataP;
00435     break;
00436 
00437     case  CAMType::typeDouble :
00438     double* ddataP;
00439     ddataP = (double*)dataPointer;
00440     if(ddataP != 0) delete [] ddataP;
00441     break;
00442 
00443 #ifndef __NO_COMPLEX__
00444     case  CAMType::typeComplex :
00445     complex* cdataP;
00446     cdataP = (complex*)dataPointer;
00447     if(cdataP != 0) delete [] cdataP;
00448     break;
00449 #endif
00450     }
00451 
00452     }
00453 }
00454 //
00455 //********************************************************************************
00456 //                    Reference Counting Functions
00457 //********************************************************************************
00458 //
00459 
00460 void  CAMdataHandler::incrementReferenceCount()
00461 {
00462     if(referenceCount == 0) CAMdataHandler::referenceCountError();
00463     referenceCount++;
00464 }
00465 
00466 void  CAMdataHandler::referenceCountError()
00467 {
00468 cerr << " Cannot Use Reference Counting on Objects New\'d by the Compiler " << endl;
00469 CAMmvaExit();
00470 }
00471 //
00472 //********************************************************************************
00473 //                     CPP File End
00474 //********************************************************************************
00475 //
00476 
00477 
00478   

Generated on Wed Aug 6 12:58:44 2003 for Open-Sessame Framework by doxygen1.3