-
Notifications
You must be signed in to change notification settings - Fork 0
/
AvIPosition.cc
1062 lines (962 loc) · 24.6 KB
/
AvIPosition.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//# AvIPosition.cc: A vector of integers, used to index into arrays.
//# Copyright (C) 1994,1995,1996,1997,1998,1999
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: [email protected].
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
//# $Id: AvIPosition.cc,v 19.0 2003/07/16 05:47:27 aips2adm Exp $
//# --------------------------------------------------
//
//
// $Header: /home/cvs/aips++/code/trial/apps/aipsview/Attic/AvIPosition.cc,v 19.0 2003/07/16 05:47:27 aips2adm Exp $
//
// $Log: AvIPosition.cc,v $
// Revision 19.0 2003/07/16 05:47:27 aips2adm
// exhale: Base release 19.000.00
//
// Revision 18.0 2002/06/07 21:29:07 aips2adm
// exhale: Base release 18.000.00
//
// Revision 17.0 2001/11/12 19:42:36 aips2adm
// exhale: Base release 17.000.00
//
// Revision 16.0 2001/05/03 01:42:43 aips2adm
// exhale: Base release 16.000.00
//
// Revision 15.0 2000/10/26 17:11:07 aips2adm
// exhale: Base release 15.000.00
//
// Revision 14.0 2000/03/23 16:08:32 aips2adm
// exhale: Base release 14.000.00
//
// Revision 13.1 1999/12/13 09:57:25 gvandiep
// Move IPosition,Slice,Slicer from Lattices to Arrays
//
// Revision 13.0 1999/08/10 18:40:19 aips2adm
// exhale: Base release 13.000.00
//
// Revision 12.0 1999/07/15 00:23:15 aips2adm
// exhale: Base release 12.000.00
//
// Revision 11.0 1998/10/03 07:00:35 aips2adm
// exhale: Base release 11.000.00
//
// Revision 10.0 1998/07/20 17:54:34 aips2adm
// exhale: Base release 10.000.00
//
// Revision 9.1 1998/06/09 21:37:42 hr
// Removed an unneeded semicolon.
//
// Revision 9.0 1997/08/25 21:28:48 aips2adm
// exhale: Base release 09.000.00
//
// Revision 8.0 1997/02/20 03:17:49 aips2adm
// exhale: Base release 08.000.00
//
// Revision 7.3 1996/12/12 09:26:59 droberts
// Final update from monet archive.
//
// Revision 1.5 1996/11/18 20:40:12 hr
// Added RCS header.
//
//
//---------------------------------------------------------------------------
// #include <aips/Arrays/AvIPosition.h>
// #include <aips/Exceptions/Error.h>
// #include <aips/Arrays/ArrayError.h>
// #include <aips/IO/AipsIO.h>
// #include <aips/Utilities/Assert.h>
#include <iostream.h>
#if defined(sparc) && ! defined(__SVR4)
#include <stdio.h> // printf (for assert)
#endif
#include <assert.h>
#include "AvWPosition.h"
#include "AvIPosition.h"
#ifndef MIN
#define MIN(A,B) (((A) < (B)) ? (A) : (B))
#endif
#define DebugAssert(A,B)
AvIPosition::AvIPosition() : size(0), data(&buffer_p[0])
{
// Nothing
DebugAssert(ok(), AipsError);
}
AvIPosition::AvIPosition(unsigned int length) : size(length)
{
if (size <= BufferLength) {
data = buffer_p;
} else {
data = new int[size];
if (data == 0)
{
cerr << "Cannot allocate storage" << endl;
}
}
DebugAssert(ok(), AipsError);
}
AvIPosition::AvIPosition(unsigned int length, int val) : size(length)
{
if (size <= BufferLength) {
data = buffer_p;
} else {
data = new int[size];
if (data == 0) {
cerr << "Cannot allocate storage" << endl;
}
}
for (unsigned int i=0; i<size; i++) {
data[i] = val;
}
DebugAssert(ok(), AipsError);
}
#if 1
AvIPosition::AvIPosition(const AvWPosition & wp)
{
size = wp.nelements();
if (nelements() <= BufferLength) {
data = buffer_p;
} else {
data = new int[size];
if (data == 0) {
cerr << "Cannot allocate storage" << endl;
}
}
for (unsigned int i=0; i<size; i++) {
data[i] = (int) (wp(i) + 0.5);
}
DebugAssert(ok(), AipsError);
}
#endif
AvIPosition::AvIPosition (unsigned int length, int val0, int val1, int val2, int val3,
int val4, int val5, int val6, int val7, int val8,
int val9)
: size(length), data(0)
{
if (size <= BufferLength) {
data = buffer_p;
} else {
data = new int[size];
if (data == 0) {
cerr << "Cannot allocate storate" << endl;
}
}
if (size > 10 || length < 1) {
cerr << "AvIPosition::AvIPosition(unsigned int length, val0, ...) - "
"Can only initialize from 1 to 10 elements";
}
switch (length) {
case 10: data[9] = val9; // Fall through
case 9: data[8] = val8; // Fall through
case 8: data[7] = val7; // Fall through
case 7: data[6] = val6; // Fall through
case 6: data[5] = val5; // Fall through
case 5: data[4] = val4; // Fall through
case 4: data[3] = val3; // Fall through
case 3: data[2] = val2; // Fall through
case 2: data[1] = val1; // Fall through
case 1: data[0] = val0; break;
default: DebugAssert(0, AipsError); // NOTREACHED
}
for (unsigned int i=0; i < size; i++) {
if (data[i] == MIN_INT) {
cerr << "AvIPosition::AvIPosition(unsigned int length, val0, ...) - "
"One or more valn == INT_MIN. Probably haven't defined "
"enough values. Otherwise specify after construction.";
}
}
DebugAssert(ok(), AipsError);
}
AvIPosition::AvIPosition(const AvIPosition &other) : size(other.size)
{
if (size <= BufferLength) {
data = buffer_p;
} else {
data = new int[size];
if (data == 0) {
cerr << "Cannot allocate storage" << endl;
}
}
for (unsigned int i=0; i < size; i++) {
data[i] = other.data[i];
}
DebugAssert(ok(), AipsError);
}
AvIPosition::~AvIPosition()
{
if (data != &buffer_p[0]) {
// We could also unconditionally delete data; however in the past
// some compilers have complained about deleting a zero-pointer even
// though it is supposed to be OK.
delete [] data;
}
}
AvIPosition AvIPosition::nonDegenerate(unsigned int startingAxis) const
{
DebugAssert(ok(), AipsError);
if (startingAxis >= size)
cerr << "AvIPosition::nonDegenerate: startingAxis is greater than"
" size of this AvIPosition.";
unsigned int ctr = startingAxis;
if(size <= BufferLength) {
for (unsigned int i=startingAxis;i<size;i++)
if (buffer_p[i]!=1) ctr++;
} else {
for (unsigned int i=startingAxis;i<size;i++)
if (data[i]!=1) ctr++;
}
if (ctr == size) return *this;
AvIPosition nondegenerateIP(ctr,1);
ctr=0;
if(size <= BufferLength) {
for (unsigned int i=0; i<size; i++)
if(buffer_p[i] == 1 && i >= startingAxis) ctr++;
else nondegenerateIP(i-ctr) = buffer_p[i];
} else {
for (unsigned int i=0; i<size; i++)
if(data[i] == 1 && i >= startingAxis) ctr++;
else nondegenerateIP(i-ctr) = data[i];
}
return nondegenerateIP;
}
void AvIPosition::resize(unsigned int newSize, int copy)
{
DebugAssert(ok(), AipsError);
// If the size is unchanged, just return (more efficient)
if (newSize == size) {
return;
}
int *newData = 0;
if (newSize <= BufferLength) {
newData = buffer_p;
} else {
newData = new int[newSize];
if (data == 0) {
cerr << "Cannot allocate storage" << endl;
}
}
if (newData != data && copy) {
for (unsigned int i=0; i < MIN(size, newSize); i++) {
newData[i] = data[i];
}
}
// Delete the old data, if any
if (size > 0 && data != &buffer_p[0]) {
delete [] data;
data = 0;
}
// Point to new data
size = newSize;
data = newData;
}
AvIPosition &AvIPosition::operator=(const AvIPosition &other)
{
//cout << "KPos:op=() - size=" << size << ", other.size=" << other.size << endl;
DebugAssert(ok(), AipsError);
if (&other == this) {
return *this;
}
if (size == 0) {
this->resize(other.nelements());
}
if (conform(other) == 0)
{
cerr << "AvIPosition::operator=(const AvIPosition & - "
"this and other differ in length";
assert(0);
}
for (unsigned int i=0; i < size; i++) {
data[i] = other.data[i];
}
return *this;
}
AvIPosition &AvIPosition::operator=(int value)
{
DebugAssert(ok(), AipsError);
for (unsigned int i=0; i < size; i++) {
data[i] = value;
}
return *this;
}
void AvIPosition::append (const AvIPosition& other)
{
unsigned int j = size;
resize (size + other.size);
for (unsigned int i=0; i<other.size; i++) {
data[j++] = other.data[i];
}
}
void AvIPosition::prepend (const AvIPosition& other)
{
unsigned int j = size, i;
resize (size + other.size);
for (i=size; j>0;) {
data[--i] = data[--j];
}
for (i=0; i<other.size; i++) {
data[i] = other.data[i];
}
}
AvIPosition AvIPosition::concatenate (const AvIPosition& other) const
{
AvIPosition tmp (*this);
tmp.append (other);
return tmp;
}
void AvIPosition::setFirst (const AvIPosition& other)
{
if (size < other.size) {
cerr << "AvIPosition::setFirst(other); other is too long";
}
for (unsigned int i=0; i<other.size; i++) {
data[i] = other.data[i];
}
}
void AvIPosition::setLast (const AvIPosition& other)
{
if (size < other.size) {
cerr << "AvIPosition::setLast(other); other is too long";
}
unsigned int j = size - other.size;
for (unsigned int i=0; i<other.size; i++) {
data[j++] = other.data[i];
}
}
AvIPosition AvIPosition::getFirst (unsigned int n) const
{
if (size < n) {
cerr << "AvIPosition::getFirst(n); n is too high";
}
AvIPosition tmp(n);
for (unsigned int i=0; i<n; i++) {
tmp.data[i] = data[i];
}
return tmp;
}
AvIPosition AvIPosition::getLast (unsigned int n) const
{
if (size < n) {
cerr << "AvIPosition::getLast(n); n is too high";
}
AvIPosition tmp(n);
unsigned int j = size - n;
for (unsigned int i=0; i<n; i++) {
tmp.data[i] = data[j++];
}
return tmp;
}
void AvIPosition::operator += (const AvIPosition &other)
{
DebugAssert(ok(), AipsError);
if (conform(other) == 0) {
cerr << "AvIPosition::operator += "
"(const AvIPosition &) - "
"this and other differ in length";
}
for (unsigned int i=0; i < size; i++) {
data[i] += other.data[i];
}
}
void AvIPosition::operator -= (const AvIPosition &other)
{
DebugAssert(ok(), AipsError);
if (conform(other) == 0) {
cerr << "AvIPosition::operator -= "
"(const AvIPosition &) - "
"this and other differ in length";
}
for (unsigned int i=0; i < size; i++) {
data[i] -= other.data[i];
}
}
void AvIPosition::operator *= (const AvIPosition &other)
{
DebugAssert(ok(), AipsError);
if (conform(other) == 0) {
cerr << "AvIPosition::operator *= "
"(const AvIPosition &) - "
"this and other differ in length";
}
for (unsigned int i=0; i < size; i++) {
data[i] *= other.data[i];
}
}
void AvIPosition::operator /= (const AvIPosition &other)
{
DebugAssert(ok(), AipsError);
if (conform(other) == 0) {
cerr << "AvIPosition::operator /= "
"(const AvIPosition &) - "
"this and other differ in length";
}
for (unsigned int i=0; i < size; i++) {
data[i] /= other.data[i];
}
}
void AvIPosition::operator += (int val)
{
DebugAssert(ok(), AipsError);
for (unsigned int i=0; i < size; i++) {
data[i] += val;
}
}
void AvIPosition::operator -= (int val)
{
DebugAssert(ok(), AipsError);
for (unsigned int i=0; i < size; i++) {
data[i] -= val;
}
}
void AvIPosition::operator *= (int val)
{
DebugAssert(ok(), AipsError);
for (unsigned int i=0; i < size; i++) {
data[i] *= val;
}
}
void AvIPosition::operator /= (int val)
{
DebugAssert(ok(), AipsError);
for (unsigned int i=0; i < size; i++) {
data[i] /= val;
}
}
int AvIPosition::isEqual (const AvIPosition &other) const
{
return isEqual (other, nelements());
}
int AvIPosition::isEqual (const AvIPosition &other, unsigned int nrCompare) const
{
if (! conform (other)) {
return 0;
}
if (nrCompare > nelements()) {
nrCompare = nelements();
}
for (unsigned int i=0; i<nrCompare; i++) {
if (data[i] != other(i)) {
return 0;
}
}
return 1;
}
AvIPosition operator + (const AvIPosition &left, const AvIPosition &right)
{
if (left.conform(right) == 0) {
cerr << "::operator + "
"(const AvIPosition &, const AvIPosition &) - "
"left and right operand do not conform ";
}
AvIPosition result(left);
result += right;
return result;
}
AvIPosition operator - (const AvIPosition &left, const AvIPosition &right)
{
if (left.conform(right) == 0) {
cerr << "::operator - "
"(const AvIPosition &, const AvIPosition &) - "
"left and right operand do not conform ";
}
AvIPosition result(left);
result -= right;
return result;
}
AvIPosition operator * (const AvIPosition &left, const AvIPosition &right)
{
if (left.conform(right) == 0) {
cerr << "::operator * "
"(const AvIPosition &, const AvIPosition &) - "
"left and right operand do not conform ";
}
AvIPosition result(left);
result *= right;
return result;
}
AvIPosition operator / (const AvIPosition &left, const AvIPosition &right)
{
if (left.conform(right) == 0) {
cerr << "::operator / "
"(const AvIPosition &, const AvIPosition &) - "
"left and right operand do not conform ";
}
AvIPosition result(left);
result /= right;
return result;
}
AvIPosition operator + (const AvIPosition &left, int val)
{
AvIPosition result(left);
result += val;
return result;
}
AvIPosition operator - (const AvIPosition &left, int val)
{
AvIPosition result(left);
result -= val;
return result;
}
AvIPosition operator * (const AvIPosition &left, int val)
{
AvIPosition result(left);
result *= val;
return result;
}
AvIPosition operator / (const AvIPosition &left, int val)
{
AvIPosition result(left);
result /= val;
return result;
}
AvIPosition operator + (int val, const AvIPosition &right)
{
AvIPosition result(right.nelements());
result = val;
result += right;
return result;
}
AvIPosition operator - (int val, const AvIPosition &right)
{
AvIPosition result(right.nelements());
result = val;
result -= right;
return result;
}
AvIPosition operator * (int val, const AvIPosition &right)
{
AvIPosition result(right.nelements());
result = val;
result *= right;
return result;
}
AvIPosition operator / (int val, const AvIPosition &right)
{
AvIPosition result(right.nelements());
result = val;
result /= right;
return result;
}
int AvIPosition::product() const
{
if (nelements() == 0) {
return 0;
}
int total = 1;
for (unsigned int i=0; i<nelements(); i++) {
total *= (*this)(i);
}
return total;
}
int AvIPosition::sum() const
{
if (nelements() == 0) {
return 0;
}
int total = 0;
for (unsigned int i=0; i<nelements(); i++) {
total += (*this)(i);
}
return total;
}
int operator == (const AvIPosition &left, const AvIPosition &right)
{
if (left.conform(right) == 0) {
cerr << "::operator== "
"(const AvIPosition &, const AvIPosition &) - "
"left and right operand do not conform ";
}
unsigned int n=left.nelements();
int result = 1;
for (unsigned int i=0; i < n; i++) {
if (left(i) == right(i)) {
// Nothing - written to make cut and paste easier
} else {
result = 0;
break;
}
}
return result;
}
int operator != (const AvIPosition &left, const AvIPosition &right)
{
if (left.conform(right) == 0) {
cerr << "::operator!= "
"(const AvIPosition &, const AvIPosition &) - "
"left and right operand do not conform ";
}
unsigned int n=left.nelements();
int result = 0;
for (unsigned int i=0; i < n; i++) {
if (left(i) != right(i)) {
result = 1;
break;
} else {
// Nothing - written to make cut and paste easier
}
}
return result;
}
int operator < (const AvIPosition &left, const AvIPosition &right)
{
if (left.conform(right) == 0)
{
cerr << "::operator< "
"(const AvIPosition &, const AvIPosition &) - "
"left and right operand do not conform ";
}
unsigned int n=left.nelements();
int result = 1;
for (unsigned int i=0; i < n; i++) {
if (left(i) < right(i)) {
// Nothing - written to make cut and paste easier
} else {
result = 0;
break;
}
}
return result;
}
int operator <= (const AvIPosition &left, const AvIPosition &right)
{
if (left.conform(right) == 0)
{
cerr << "::operator<= "
"(const AvIPosition &, const AvIPosition &) - "
"left and right operand do not conform ";
}
unsigned int n=left.nelements();
int result = 1;
for (unsigned int i=0; i < n; i++) {
if (left(i) <= right(i)) {
// Nothing - written to make cut and paste easier
} else {
result = 0;
break;
}
}
return result;
}
int operator > (const AvIPosition &left, const AvIPosition &right)
{
if (left.conform(right) == 0) {
cerr << "::operator> "
"(const AvIPosition &, const AvIPosition &) - "
"left and right operand do not conform ";
}
unsigned int n=left.nelements();
int result = 1;
for (unsigned int i=0; i < n; i++) {
if (left(i) > right(i)) {
// Nothing - written to make cut and paste easier
} else {
result = 0;
break;
}
}
return result;
}
int operator >= (const AvIPosition &left, const AvIPosition &right)
{
if (left.conform(right) == 0) {
cerr << "::operator>= "
"(const AvIPosition &, const AvIPosition &) - "
"left and right operand do not conform ";
}
unsigned int n=left.nelements();
int result = 1;
for (unsigned int i=0; i < n; i++) {
if (left(i) >= right(i)) {
// Nothing - written to make cut and paste easier
} else {
result = 0;
break;
}
}
return result;
}
int operator == (const AvIPosition &left, int val)
{
int result = 1;
unsigned int n = left.nelements();
for (unsigned int i=0; i < n; i++) {
if (left(i) == val) {
// Nothing
} else {
result = 0;
break;
}
}
return result;
}
int operator != (const AvIPosition &left, int val)
{
int result = 0;
unsigned int n = left.nelements();
for (unsigned int i=0; i < n; i++) {
if (left(i) != val) {
result = 1;
break;
} else {
// Nothing
}
}
return result;
}
int operator < (const AvIPosition &left, int val)
{
int result = 1;
unsigned int n = left.nelements();
for (unsigned int i=0; i < n; i++) {
if (left(i) < val) {
// Nothing
} else {
result = 0;
break;
}
}
return result;
}
int operator <= (const AvIPosition &left, int val)
{
int result = 1;
unsigned int n = left.nelements();
for (unsigned int i=0; i < n; i++) {
if (left(i) <= val) {
// Nothing
} else {
result = 0;
break;
}
}
return result;
}
int operator > (const AvIPosition &left, int val)
{
int result = 1;
unsigned int n = left.nelements();
for (unsigned int i=0; i < n; i++) {
if (left(i) > val) {
// Nothing
} else {
result = 0;
break;
}
}
return result;
}
int operator >= (const AvIPosition &left, int val)
{
int result = 1;
unsigned int n = left.nelements();
for (unsigned int i=0; i < n; i++) {
if (left(i) >= val) {
// Nothing
} else {
result = 0;
break;
}
}
return result;
}
int operator == (int val, const AvIPosition &right)
{
int result = 1;
unsigned int n = right.nelements();
for (unsigned int i=0; i < n; i++) {
if (val == right(i)) {
// Nothing
} else {
result = 0;
break;
}
}
return result;
}
int operator != (int val, const AvIPosition &right)
{
int result = 0;
unsigned int n = right.nelements();
for (unsigned int i=0; i < n; i++) {
if (val != right(i)) {
result = 1;
break;
} else {
// Nothing
}
}
return result;
}
int operator < (int val, const AvIPosition &right)
{
int result = 1;
unsigned int n = right.nelements();
for (unsigned int i=0; i < n; i++) {
if (val < right(i)) {
// Nothing
} else {
result = 0;
break;
}
}
return result;
}
int operator <= (int val, const AvIPosition &right)
{
int result = 1;
unsigned int n = right.nelements();
for (unsigned int i=0; i < n; i++) {
if (val <= right(i)) {
// Nothing
} else {
result = 0;
break;
}
}
return result;
}
int operator > (int val, const AvIPosition &right)
{
int result = 1;
unsigned int n = right.nelements();
for (unsigned int i=0; i < n; i++) {
if (val > right(i)) {
// Nothing
} else {
result = 0;
break;
}
}
return result;
}
int operator >= (int val, const AvIPosition &right)
{
int result = 1;
unsigned int n = right.nelements();
for (unsigned int i=0; i < n; i++) {
if (val >= right(i)) {
// Nothing
} else {
result = 0;
break;
}
}
return result;
}
ostream &operator<<(ostream &os, const AvIPosition &ip)
{
os << "[";
for(unsigned int i=0; i < ip.nelements(); i++) {
os << ip(i);
if (i < ip.nelements() - 1) {
os << ", ";
}
}
os << "]";
return os;
}
int AvIPosition::ok() const
{
int retval = 1;
if (size <= BufferLength && data != &buffer_p[0]) { retval = 0; }
if (data == 0) { retval = 0; }
return retval;
}
AvIPosition toAvIPositionInArray (const unsigned int offset,
const AvIPosition &shape,
const AvIPosition &origin)
{
if ( ! origin.conform(shape) ) {
cerr << "AvIPosition ::toIPositionInArray (const unsigned int offset,"
" const AvIPosition &origin, const AvIPosition &shape)"
" - IPositions do not conform";
}
if ( ! isInsideArray (offset, shape, origin) ) {
cerr << "AvIPosition ::toIPositionInArray (const unsigned int offset,"
" const AvIPosition &origin, const AvIPosition &shape)"
" - Invalid offset.";
}
AvIPosition iposition (origin.nelements());
unsigned int divisor = 1;
unsigned int ndim = origin.nelements();
for (unsigned int idim = 0; idim < ndim; idim++) {
iposition(idim) = origin(idim) + ((offset / divisor) % shape(idim));
divisor *= shape(idim);
}
return iposition;
}
unsigned int toOffsetInArray (const AvIPosition &iposition,
const AvIPosition &shape, const AvIPosition &origin)
{
if ( ! (iposition.conform(origin) && iposition.conform(shape)) ) {
cerr << "unsigned int ::toOffsetInArray (const AvIPosition &iposition,"
" const AvIPosition &origin, const AvIPosition &shape)"
" - IPositions do not conform";
}
if ( ! isInsideArray (iposition, shape, origin) ) {