00001 #include "strctbse.h"
00002
00003 #undef __IMPEXP__
00004 #ifdef __BCPLUSPLUS__
00005 #ifdef __EXPORT_MVASUPPORT_B__
00006 #define __IMPEXP__ __export
00007 #else
00008 #define __IMPEXP__
00009 #endif
00010 #else
00011 #define __IMPEXP__
00012 #endif
00013
00014 #ifdef __STATIC__
00015 #undef __IMPEXP__
00016 #define __IMPEXP__
00017 #endif
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 CAMstructureBase::CAMstructureBase(): indexBegin(), indexEnd(), indexStride(),
00043 indexBeginBase(), indexEndBase()
00044 {
00045 dataDimension = 0;
00046 }
00047
00048 CAMstructureBase::CAMstructureBase(long dimension): indexBegin(dimension ), indexEnd(dimension), indexStride(dimension),
00049 indexBeginBase(dimension), indexEndBase(dimension)
00050 {
00051 dataDimension = dimension;
00052 }
00053 CAMstructureBase::CAMstructureBase( const CAMstructureBase& A)
00054 {
00055 dataDimension = A.dataDimension;
00056 indexBegin = A.indexBegin;
00057 indexEnd = A.indexEnd;
00058 indexStride = A.indexStride;
00059 indexBeginBase = A.indexBeginBase;
00060 indexEndBase = A.indexEndBase;
00061 }
00062 CAMstructureBase::CAMstructureBase(const CAMrange& R1, const CAMrange& R2 ,
00063 const CAMrange& R3 , const CAMrange&R4 ,
00064 const CAMrange& R5 , const CAMrange&R6 ,
00065 const CAMrange& R7) : indexBegin(), indexEnd(), indexStride(),
00066 indexBeginBase(), indexEndBase()
00067 {
00068 if(R1.getNullFlag() == 1)
00069 { dataDimension = 0;}
00070 else if(R2.getNullFlag() == 1)
00071 {dataDimension = 1;}
00072 else if(R3.getNullFlag() == 1)
00073 {dataDimension = 2;}
00074 else if(R4.getNullFlag() == 1)
00075 {dataDimension = 3;}
00076 else if(R5.getNullFlag() == 1)
00077 {dataDimension = 4;}
00078 else if(R6.getNullFlag() == 1)
00079 {dataDimension = 5;}
00080 else if(R7.getNullFlag() == 1)
00081 {dataDimension = 6;}
00082 else
00083 {dataDimension = 7;}
00084
00085 indexBegin.initialize(dataDimension);
00086 indexEnd.initialize(dataDimension);
00087 indexStride.initialize(dataDimension);
00088 indexBeginBase.initialize(dataDimension);
00089 indexEndBase.initialize(dataDimension);
00090
00091 const CAMrange* RangeInput[7];
00092 RangeInput[0] = &R1;
00093 RangeInput[1] = &R2;
00094 RangeInput[2] = &R3;
00095 RangeInput[3] = &R4;
00096 RangeInput[4] = &R5;
00097 RangeInput[5] = &R6;
00098 RangeInput[6] = &R7;
00099
00100 int i;
00101 for(i = 0; i < dataDimension; i++)
00102 {
00103 indexBegin[i] = RangeInput[i]->getBase();
00104 indexEnd[i] = RangeInput[i]->getBound();
00105 indexStride[i] = RangeInput[i]->getStride();
00106 indexBeginBase[i] = indexBegin[i];
00107 indexEndBase[i] = indexEnd[i];
00108 }
00109 }
00110
00111
00112
00113
00114
00115 CAMstructureBase::~CAMstructureBase()
00116 {
00117 }
00118
00119
00120
00121
00122
00123
00124 ostream& operator <<(ostream& out_stream, const CAMstructureBase& A)
00125 {
00126 int i;
00127 out_stream << "Structure Dimension = " << A.dataDimension << '\n';
00128
00129 out_stream << "indexBegin = ";
00130 for(i = 0; i < A.dataDimension; i++)
00131 out_stream << " " << A.indexBegin[i];
00132 out_stream << '\n';
00133
00134 out_stream << "indexEnd = ";
00135 for(i = 0; i < A.dataDimension; i++)
00136 out_stream << " " << A.indexEnd[i];
00137 out_stream << '\n';
00138
00139 out_stream << "indexStride = ";
00140 for(i = 0; i < A.dataDimension; i++)
00141 out_stream << " " << A.indexStride[i];
00142 out_stream << '\n';
00143
00144 out_stream << "indexBeginBase = ";
00145 for(i = 0; i < A.dataDimension; i++)
00146 out_stream << " " << A.indexBeginBase[i];
00147 out_stream << '\n';
00148
00149 out_stream << "indexEndBase = ";
00150 for(i = 0; i < A.dataDimension; i++)
00151 out_stream << " " << A.indexEndBase[i];
00152 out_stream << '\n';
00153
00154
00155 return(out_stream);
00156 }
00157
00158
00159
00160
00161
00162
00163 CAMstructureBase& CAMstructureBase::operator =( const CAMstructureBase& A)
00164 {
00165 dataDimension = A.dataDimension;
00166 indexBegin = A.indexBegin;
00167 indexEnd = A.indexEnd;
00168 indexStride = A.indexStride;
00169 indexBeginBase = A.indexBeginBase;
00170 indexEndBase = A.indexEndBase;
00171 return *this;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180 void CAMstructureBase::initialize()
00181 {
00182 indexBegin.initialize();
00183 indexEnd.initialize();
00184 indexStride.initialize();
00185 indexBeginBase.initialize();
00186 indexEndBase.initialize();
00187 dataDimension = 0;
00188 }
00189
00190
00191 void CAMstructureBase::initialize(long dimension)
00192 {
00193 indexBegin.initialize(dimension);
00194 indexEnd.initialize(dimension);
00195 indexStride.initialize(dimension);
00196 indexBeginBase.initialize(dimension);
00197 indexEndBase.initialize(dimension);
00198 dataDimension = dimension;
00199 }
00200
00201 void CAMstructureBase::initialize(const CAMstructureBase& A)
00202 {
00203 dataDimension = A.dataDimension;
00204 indexBegin.initialize(A.indexBegin);
00205 indexEnd.initialize(A.indexEnd);
00206 indexStride.initialize(A.indexStride);
00207 indexBeginBase.initialize(A.indexBeginBase);
00208 indexEndBase.initialize(A.indexEndBase);
00209 }
00210 void CAMstructureBase::initialize(const CAMrange& R1, const CAMrange& R2,
00211 const CAMrange& R3, const CAMrange&R4, const CAMrange& R5,
00212 const CAMrange&R6, const CAMrange& R7)
00213 {
00214 if(R1.getNullFlag() == 1){dataDimension = 0;}
00215 else if(R2.getNullFlag() == 1){dataDimension = 1;}
00216 else if(R3.getNullFlag() == 1){dataDimension = 2;}
00217 else if(R4.getNullFlag() == 1){dataDimension = 3;}
00218 else if(R5.getNullFlag() == 1){dataDimension = 4;}
00219 else if(R6.getNullFlag() == 1){dataDimension = 5;}
00220 else if(R7.getNullFlag() == 1){dataDimension = 6;}
00221 else {dataDimension = 7;}
00222
00223 indexBegin.initialize(dataDimension);
00224 indexEnd.initialize(dataDimension);
00225 indexStride.initialize(dataDimension);
00226 indexBeginBase.initialize(dataDimension);
00227 indexEndBase.initialize(dataDimension);
00228
00229 const CAMrange* RangeInput[7];
00230 RangeInput[0] = &R1;
00231 RangeInput[1] = &R2;
00232 RangeInput[2] = &R3;
00233 RangeInput[3] = &R4;
00234 RangeInput[4] = &R5;
00235 RangeInput[5] = &R6;
00236 RangeInput[6] = &R7;
00237
00238 int i;
00239 for(i = 0; i < dataDimension; i++)
00240 {
00241 indexBegin[i] = RangeInput[i]->getBase();
00242 indexEnd[i] = RangeInput[i]->getBound();
00243 indexStride[i] = RangeInput[i]->getStride();
00244 indexBeginBase[i] = indexBegin[i];
00245 indexEndBase[i] = indexEnd[i];
00246 }
00247 }
00248
00249
00250
00251
00252
00253 int CAMstructureBase::isConformingTo(const CAMstructureBase& A) const
00254 {
00255 int returnValue = 0;
00256
00257 long loopDimension;
00258 long AloopDimension;
00259
00260 MVAlongBase Count(dataDimension);
00261 MVAlongBase ACount(A.dataDimension);
00262 long i, ii;
00263
00264 for(i = 0; i < dataDimension; i++)
00265 Count[i] = (( indexEnd[i] - indexBegin[i])/ indexStride[i]) + 1;
00266
00267 ii = 0;
00268 for(i = 0; i < dataDimension; i++)
00269 { if(Count[i] != 1) {Count[ii] = Count[i]; ii++;} }
00270
00271 loopDimension = ii;
00272 if(loopDimension == 0) loopDimension = 1;
00273
00274
00275 for(i = 0; i < A.dataDimension; i++)
00276 ACount[i] = ((A.indexEnd[i] - A.indexBegin[i])/A.indexStride[i]) + 1;
00277
00278 ii = 0;
00279 for(i = 0; i < A.dataDimension; i++)
00280 { if(ACount[i] != 1) {ACount[ii] = ACount[i]; ii++;} }
00281
00282 AloopDimension = ii;
00283 if(AloopDimension == 0) AloopDimension = 1;
00284
00285 if(loopDimension == AloopDimension)
00286 {
00287 returnValue = 1;
00288 for(i =0; i< loopDimension; i++)
00289 if(ACount[i] != Count[i]) returnValue =0;
00290 }
00291
00292 return returnValue;
00293 }
00294
00295 int CAMstructureBase::isStrictConformingTo(const CAMstructureBase& A) const
00296 {
00297 int returnValue = 0;
00298
00299 MVAlongBase Count(dataDimension);
00300 MVAlongBase ACount(A.dataDimension);
00301 long i;
00302
00303 for(i = 0; i < dataDimension; i++)
00304 Count[i] = (( indexEnd[i] - indexBegin[i])/ indexStride[i]) + 1;
00305
00306 for(i = 0; i < A.dataDimension; i++)
00307 ACount[i] = ((A.indexEnd[i] - A.indexBegin[i])/A.indexStride[i]) + 1;
00308
00309 if(dataDimension == A.dataDimension)
00310 {
00311 returnValue = 1;
00312 for(i =0; i< dataDimension; i++)
00313 if(ACount[i] != Count[i]) returnValue =0;
00314 }
00315
00316 return returnValue;
00317 }
00318
00319 int CAMstructureBase::isMatrixOpConformingTo(const CAMstructureBase& A) const
00320 {
00321 if((dataDimension !=2)||(A.dataDimension !=2)) return 0;
00322
00323 int returnValue = 0;
00324
00325 long Count2 = (( indexEnd[1] - indexBegin[1])/ indexStride[1]) + 1;
00326 long ACount1 = ((A.indexEnd[0] - A.indexBegin[0])/A.indexStride[0]) + 1;
00327
00328 if(Count2 == ACount1) returnValue = 1;
00329
00330 return returnValue;
00331 }
00332
00333 int CAMstructureBase::isSubset() const
00334 {
00335
00336
00337
00338 int returnValue = 0;
00339 for(int i = 0; i < dataDimension; i++)
00340 returnValue += (indexEndBase[i] - indexEnd[i])
00341 + (indexBegin[i] - indexBeginBase[i])
00342 + (indexStride[i] - 1);
00343 if(returnValue > 0) returnValue = 1;
00344 return returnValue;
00345
00346 }
00347 void CAMstructureBase::getNormalizedLoops(long& loopDimension, long& Offset, MVAlongBase& Count, MVAlongBase& Stride) const
00348 {
00349 MVAlongBase localCount(dataDimension);
00350 MVAlongBase localStride(dataDimension);
00351
00352
00353 long i; long M; long i_new;
00354
00355 for(i = 0; i < dataDimension; i++)
00356 localCount[i] = ((indexEnd[i] - indexBegin[i])/indexStride[i]) + 1;
00357
00358 M = 1;
00359 Offset = (indexBegin[0] - indexBeginBase[0])*M;
00360 localStride[0] = indexStride[0];
00361
00362 for(i = 1; i < dataDimension; i++)
00363 {
00364 M = M*((indexEndBase[i-1] - indexBeginBase[i-1]) + 1);
00365 localStride[i] = indexStride[i]*M;
00366 Offset += (indexBegin[i] - indexBeginBase[i])*M;
00367 }
00368
00369
00370
00371 i_new = 0;
00372 for(i = 0; i < dataDimension; i++)
00373 {
00374 if(localCount[i] != 1)
00375 {
00376 localCount[i_new] = localCount[i];
00377 localStride[i_new] = localStride[i];
00378 i_new++;
00379 }
00380 }
00381
00382 loopDimension = i_new;
00383 if(loopDimension == 0) loopDimension = 1;
00384
00385 Count.initialize(loopDimension);
00386 Stride.initialize(loopDimension);
00387 for(i = 0; i < loopDimension; i++)
00388 {
00389 Count[i] = localCount[i];
00390 Stride[i] = localStride[i];
00391 }
00392
00393 }
00394
00395 void CAMstructureBase::setStructureSubset(const CAMrange& R1, const CAMrange& R2 ,
00396 const CAMrange& R3 , const CAMrange&R4 ,
00397 const CAMrange& R5 , const CAMrange&R6 ,
00398 const CAMrange& R7)
00399 {
00400 const CAMrange* RangeInput[7];
00401 RangeInput[0] = &R1;
00402 RangeInput[1] = &R2;
00403 RangeInput[2] = &R3;
00404 RangeInput[3] = &R4;
00405 RangeInput[4] = &R5;
00406 RangeInput[5] = &R6;
00407 RangeInput[6] = &R7;
00408
00409 int i;
00410 for(i = 0; i < dataDimension; i++)
00411 {
00412 if(RangeInput[i]->getUnderscoreFlag() == 1)
00413 {indexStride[i] = 1;}
00414 else if(RangeInput[i]->getSingleArgumentFlag() == 1)
00415 {
00416 indexBegin[i] = RangeInput[i]->getBound();
00417 indexEnd[i] = RangeInput[i]->getBound();
00418
00419 indexStride[i] = 1;
00420
00421
00422
00423
00424 }
00425 else
00426 {
00427 indexBegin[i] = RangeInput[i]->getBase();
00428 indexEnd[i] = RangeInput[i]->getBound();
00429 indexStride[i] = RangeInput[i]->getStride();
00430 }
00431 }
00432 return;
00433
00434 }
00435
00436 long CAMstructureBase::getFullDataCount() const
00437 {
00438 if(dataDimension == 0) return 0;
00439
00440 long fullDataCount = 1;
00441 for(long i = 0; i < dataDimension; i++)
00442 { fullDataCount *= (indexEndBase[i] - indexBeginBase[i]) + 1;}
00443 return fullDataCount;
00444 }
00445 long CAMstructureBase::getDataCount() const
00446 {
00447 if(dataDimension == 0) return 0;
00448
00449 long dataCount = 1;
00450 for(long i = 0; i < dataDimension; i++)
00451 { dataCount *= ((indexEnd[i] - indexBegin[i])/indexStride[i]) + 1;}
00452 return dataCount;
00453 }
00454 void CAMstructureBase::initializeMinStructure(CAMstructureBase& A) const
00455 {
00456 A.dataDimension = dataDimension;
00457 A.indexBegin.initialize(indexBegin);
00458 A.indexEnd.initialize(dataDimension);
00459 A.indexBeginBase.initialize(indexBegin);
00460 A.indexEndBase.initialize(dataDimension);
00461 A.indexStride.initialize(dataDimension);
00462
00463 for(long i = 0; i < dataDimension; i++)
00464 {
00465 A.indexEnd[i] = A.indexBegin[i] + ((indexEnd[i] - indexBegin[i])/indexStride[i]);
00466 A.indexEndBase[i] = A.indexEnd[i];
00467 A.indexStride[i] = 1;
00468 }
00469 }
00470
00471
00472
00473
00474
00475 long CAMstructureBase::exchangeReferenceIndex(long i)
00476 {
00477 static long index = 1;
00478 long index_return = index;
00479 index = i;
00480 return index_return ;
00481 }
00482
00483 CAMstructureBase& CAMstructureBase::operator[](long i)
00484 {
00485 if((i < 0)||(i > dataDimension))
00486 {CAMstructureBase::illegalDimension(i, dataDimension);}
00487 CAMstructureBase::exchangeReferenceIndex(i);
00488
00489 return *this;
00490 }
00491
00492 const CAMstructureBase& CAMstructureBase::operator[](long i) const
00493 {
00494 if((i < 0)||(i > dataDimension))
00495 {CAMstructureBase::illegalDimension(i, dataDimension);}
00496 CAMstructureBase::exchangeReferenceIndex(i);
00497 return *this;
00498 }
00499
00500 long CAMstructureBase::getIndexBase() const
00501 {
00502 long index = CAMstructureBase::exchangeReferenceIndex(1);
00503 return indexBegin[index - 1];
00504 }
00505
00506 long CAMstructureBase::getIndexBaseBase() const
00507 {
00508 long index = CAMstructureBase::exchangeReferenceIndex(1);
00509 return indexBeginBase[index - 1];
00510 }
00511
00512 long CAMstructureBase::getIndexBound() const
00513 {
00514 long index = CAMstructureBase::exchangeReferenceIndex(1);
00515 return indexEnd[index-1];
00516 }
00517
00518
00519 long CAMstructureBase::getIndexStride() const
00520 {
00521 long index = CAMstructureBase::exchangeReferenceIndex(1);
00522 return indexStride[index - 1];
00523 }
00524
00525 long CAMstructureBase::getIndexCount() const
00526 {
00527 long index = CAMstructureBase::exchangeReferenceIndex(1);
00528 return
00529 ((indexEnd[index - 1] - indexBegin[index- 1])/indexStride[index -1]) + 1;
00530 }
00531
00532 void CAMstructureBase::setIndexBase(long i)
00533 {
00534 long k = CAMstructureBase::exchangeReferenceIndex(1);
00535 long offset = i - indexBegin[k];
00536 indexBegin[k] = indexBegin[k] + offset;
00537 indexEnd[k] = indexEnd[k] + offset;
00538 indexBeginBase[k] = indexBeginBase[k] + offset;
00539 indexEndBase[k] = indexEndBase[k] + offset;
00540 }
00541
00542 void CAMstructureBase::setIndexStride(long i)
00543 {
00544 long index = CAMstructureBase::exchangeReferenceIndex(1);
00545 indexStride[index - 1] = i;
00546 }
00547
00548 void CAMstructureBase::setAllIndexBase(long i)
00549 {
00550 long offset;
00551
00552 for(long k = 0; k < dataDimension; k++)
00553 {
00554 offset = i - indexBegin[k];
00555 indexBegin[k] = indexBegin[k] + offset;
00556 indexEnd[k] = indexEnd[k] + offset;
00557 indexBeginBase[k] = indexBeginBase[k] + offset;
00558 indexEndBase[k] = indexEndBase[k] + offset;
00559 }
00560 }
00561
00562
00563
00564
00565
00566 void CAMstructureBase::illegalDimension(long i, long dimension)
00567 {
00568 cerr << "Argument to Dimension Selection Out of Bounds " << '\n';
00569 cerr << "Argument Input : " << i << " Acceptable Range : " <<
00570 "(0, " << dimension << ")" << endl;
00571 CAMmvaExit();
00572 }
00573
00574
00575
00576
00577
00578
00579
00580