31 #ifndef ARRAY1D_H_SEEN
32 #define ARRAY1D_H_SEEN
43 #include "error_handlers.h"
79 Array1D(
const int& nx,
const T& t): xsize_(nx) {
80 data_.resize(xsize_, t);
111 data_.resize(xsize_);
119 data_.resize(xsize_, t);
124 for(
int i=0; i < data_.size(); i++){
156 if (ix<0 || ix>xsize_){
157 throw Tantrum(
"Array1D:insert():: insert index out of bounds.");
159 int addsize = insarr.
Length();
162 data_.insert(data_.begin()+ix,ptr,ptr+addsize);
168 if (ix<0 || ix>xsize_)
169 throw Tantrum(
"Array1D:insert():: insert index out of bounds.");
171 data_.insert(data_.begin()+ix,insval);
176 if (ix<0 || ix>=xsize_)
177 throw Tantrum(
"Array1D:erase():: erase index out of bounds.");
179 data_.erase(data_.begin()+ix);
184 fwrite(&xsize_,
sizeof(xsize_),1,f_out);
185 fwrite(this->GetConstArrayPointer(),
sizeof(T),xsize_,f_out);
190 fread(&xsize_,
sizeof(xsize_),1,f_in);
191 data_.resize(xsize_);
192 fread(this->GetArrayPointer(),
sizeof(T),xsize_,f_in);
206 f_out = fopen(filename,
"wb");
207 fwrite(&xsize_,
sizeof(xsize_),1,f_out);
208 fwrite(this->GetConstArrayPointer(),
sizeof(T),xsize_,f_out);
217 f_in = fopen(filename,
"rb");
218 fread(&xsize_,
sizeof(xsize_),1,f_in);
219 data_.resize(xsize_);
220 fread(this->GetArrayPointer(),
sizeof(T),xsize_,f_in);
228 f_out.open(filename, ios::out | ios::binary);
229 f_out.write((
char*)this->GetArrayPointer(),
sizeof(T[xsize_]));
238 f_in.open(filename, ios::in | ios::binary);
239 f_in.read((
char*)this->GetArrayPointer(),
sizeof(T[xsize_]));
247 xsize_ = inarray.size();
273 data_.resize(xsize_);
277 Array1D(
const int& nx,
const int& t): xsize_(nx) {
278 data_.resize(xsize_, t);
309 data_.resize(xsize_);
314 void Resize(
const int& nx,
const int& t) {
317 data_.resize(xsize_, t);
322 for(
int i=0; i < (int)data_.size(); i++){
354 if (ix<0 || ix>xsize_){
355 throw Tantrum(
"Array1D:insert():: insert index out of bounds.");
357 int addsize = insarr.
Length();
360 data_.insert(data_.begin()+ix,ptr,ptr+addsize);
366 if (ix<0 || ix>xsize_)
367 throw Tantrum(
"Array1D:insert():: insert index out of bounds.");
369 data_.insert(data_.begin()+ix,insval);
374 if (ix<0 || ix>=xsize_)
375 throw Tantrum(
"Array1D:erase():: erase index out of bounds.");
377 data_.erase(data_.begin()+ix);
382 fwrite(&xsize_,
sizeof(xsize_),1,f_out);
383 fwrite(this->GetConstArrayPointer(),
sizeof(
int),xsize_,f_out);
388 fread(&xsize_,
sizeof(xsize_),1,f_in);
389 data_.resize(xsize_);
390 fread(this->GetArrayPointer(),
sizeof(
int),xsize_,f_in);
404 f_out = fopen(filename,
"wb");
405 fwrite(&xsize_,
sizeof(xsize_),1,f_out);
406 fwrite(this->GetConstArrayPointer(),
sizeof(
int),xsize_,f_out);
415 f_in = fopen(filename,
"rb");
416 fread(&xsize_,
sizeof(xsize_),1,f_in);
417 data_.resize(xsize_);
418 fread(this->GetArrayPointer(),
sizeof(
int),xsize_,f_in);
425 f_out.open(filename, ios::out | ios::binary);
426 f_out.write((
char*)this->GetArrayPointer(),xsize_*
sizeof(
int));
435 f_in.open(filename, ios::in | ios::binary);
436 f_in.read((
char*)this->GetArrayPointer(),xsize_*
sizeof(
int));
444 xsize_ = inarray.size();
450 data_.assign(inarray,inarray+n);
456 copy(data_.begin(), data_.end(), outarray);
484 data_.resize(xsize_);
488 Array1D(
const int& nx,
const double& t): xsize_(nx) {
489 data_.resize(xsize_, t);
520 data_.resize(xsize_);
525 void Resize(
const int& nx,
const double& t) {
528 data_.resize(xsize_, t);
533 for(
int i=0; i < (int)data_.size(); i++){
565 if (ix<0 || ix>xsize_){
566 throw Tantrum(
"Array1D:insert():: insert index out of bounds.");
568 int addsize = insarr.
Length();
571 data_.insert(data_.begin()+ix,ptr,ptr+addsize);
576 void insert(
const double& insval,
int ix){
577 if (ix<0 || ix>xsize_)
578 throw Tantrum(
"Array1D:insert():: insert index out of bounds.");
580 data_.insert(data_.begin()+ix,insval);
585 if (ix<0 || ix>=xsize_)
586 throw Tantrum(
"Array1D:erase():: erase index out of bounds.");
588 data_.erase(data_.begin()+ix);
593 fwrite(&xsize_,
sizeof(xsize_),1,f_out);
594 fwrite(this->GetConstArrayPointer(),
sizeof(
double),xsize_,f_out);
599 fread(&xsize_,
sizeof(xsize_),1,f_in);
600 data_.resize(xsize_);
601 fread(this->GetArrayPointer(),
sizeof(
double),xsize_,f_in);
615 f_out = fopen(filename,
"wb");
616 fwrite(&xsize_,
sizeof(xsize_),1,f_out);
617 fwrite(this->GetConstArrayPointer(),
sizeof(
double),xsize_,f_out);
626 f_in = fopen(filename,
"rb");
627 fread(&xsize_,
sizeof(xsize_),1,f_in);
628 data_.resize(xsize_);
629 fread(this->GetArrayPointer(),
sizeof(
double),xsize_,f_in);
636 f_out.open(filename, ios::out | ios::binary);
637 f_out.write((
char*)this->GetArrayPointer(),xsize_*
sizeof(
double));
646 f_in.open(filename, ios::in | ios::binary);
647 f_in.read((
char*)this->GetArrayPointer(),xsize_*
sizeof(
double));
655 xsize_ = inarray.size();
662 data_.assign(inarray,inarray+n);
669 copy(data_.begin(), data_.end(), outarray);
Definition: Array1D.h:472
Array1D()
Default constructor, which does not allocate any memory.
Definition: Array1D.h:480
void PushBack(const double &t)
Add element to the end of the vector.
Definition: Array1D.h:539
void ReadBinary(char *filename)
Definition: Array1D.h:624
double * GetArrayPointer()
Return a pointer to the first element of the data in the vector so we can use it access the data in a...
Definition: Array1D.h:547
void ReadBinary4py(char *filename, int n)
Definition: Array1D.h:643
const double * GetConstArrayPointer() const
Return a const point to the first element of the data in the vector so we can use it access the data ...
Definition: Array1D.h:554
void Clear()
Function to clear the memory.
Definition: Array1D.h:506
void DumpBinary(char *filename)
Dump contents of the array to a file in binary format.
Definition: Array1D.h:613
void insert(const double &insval, int ix)
Insert a given value to the position ix.
Definition: Array1D.h:576
int XSize() const
Returns size in the x-direction.
Definition: Array1D.h:512
void SetValue(const double &t)
Set all values in the array to the given value.
Definition: Array1D.h:532
double & operator()(int ix)
Definition: Array1D.h:559
int Length() const
Returns length (i.e. size in the x-direction)
Definition: Array1D.h:515
void Resize(const int &nx, const double &t)
Resizes the array and sets ALL entries to the specified value.
Definition: Array1D.h:525
void setnpdblArray(double *inarray, int n)
Definition: Array1D.h:660
void DumpBinary4py(char *filename)
Definition: Array1D.h:634
void Resize(const int &nx)
Resizes the array.
Definition: Array1D.h:518
Array1D(const int &nx, const double &t)
Constructor that allocates and initializes the data to a value t.
Definition: Array1D.h:488
int xsize_
Definition: Array1D.h:474
void DumpBinary(FILE *f_out) const
Dump contents of the array to a file in binary format.
Definition: Array1D.h:592
void setArray(vector< double > inarray)
Definition: Array1D.h:653
Array1D(const int &nx)
Constructor that allocates the memory.
Definition: Array1D.h:483
Array1D & operator=(const Array1D &obj)
Assignment operator copies the data structure by value.
Definition: Array1D.h:493
void getnpdblArray(double *outarray, int n)
Definition: Array1D.h:666
string type()
Definition: Array1D.h:678
Array1D(const Array1D &obj)
Copy constructor.
Definition: Array1D.h:500
void erase(int ix)
Erase the value from the position ix.
Definition: Array1D.h:584
void ReadBinary(FILE *f_in)
Read contents of the array from a file in binary format.
Definition: Array1D.h:598
vector< double > data_
Definition: Array1D.h:476
const double & operator()(int ix) const
Definition: Array1D.h:560
~Array1D()
Destructor that frees up the memory.
Definition: Array1D.h:503
vector< double > flatten()
Definition: Array1D.h:674
void insert(Array1D< double > &insarr, int ix)
Insert a given array to the position ix.
Definition: Array1D.h:564
double & operator[](int i)
Definition: Array1D.h:609
Definition: Array1D.h:262
Array1D(const int &nx, const int &t)
Constructor that allocates and initializes the data to a value t.
Definition: Array1D.h:277
string type()
Definition: Array1D.h:465
void insert(const int &insval, int ix)
Insert a given value to the position ix.
Definition: Array1D.h:365
void Clear()
Function to clear the memory.
Definition: Array1D.h:295
void erase(int ix)
Erase the value from the position ix.
Definition: Array1D.h:373
vector< int > data_
Definition: Array1D.h:266
void setnpintArray(long *inarray, int n)
Definition: Array1D.h:448
void DumpBinary(char *filename)
Dump contents of the array to a file in binary format.
Definition: Array1D.h:402
void Resize(const int &nx)
Resizes the array.
Definition: Array1D.h:307
void DumpBinary4py(char *filename)
Definition: Array1D.h:423
int & operator()(int ix)
Definition: Array1D.h:348
Array1D()
Default constructor, which does not allocate any memory.
Definition: Array1D.h:269
int Length() const
Returns length (i.e. size in the x-direction)
Definition: Array1D.h:304
void ReadBinary4py(char *filename, int n)
Definition: Array1D.h:432
void insert(Array1D< int > &insarr, int ix)
Insert a given array to the position ix.
Definition: Array1D.h:353
void SetValue(const int &t)
Set all values in the array to the given value.
Definition: Array1D.h:321
vector< int > flatten()
Definition: Array1D.h:461
Array1D & operator=(const Array1D &obj)
Assignment operator copies the data structure by value.
Definition: Array1D.h:282
void ReadBinary(char *filename)
Definition: Array1D.h:413
~Array1D()
Destructor that frees up the memory.
Definition: Array1D.h:292
const int * GetConstArrayPointer() const
Return a const point to the first element of the data in the vector so we can use it access the data ...
Definition: Array1D.h:343
int & operator[](int i)
Definition: Array1D.h:398
void setArray(vector< int > inarray)
Definition: Array1D.h:442
void PushBack(const int &t)
Add element to the end of the vector.
Definition: Array1D.h:328
const int & operator()(int ix) const
Definition: Array1D.h:349
Array1D(const Array1D &obj)
Copy constructor.
Definition: Array1D.h:289
int * GetArrayPointer()
Return a pointer to the first element of the data in the vector so we can use it access the data in a...
Definition: Array1D.h:336
int xsize_
Definition: Array1D.h:264
void getnpintArray(long *outarray, int n)
Definition: Array1D.h:453
Array1D(const int &nx)
Constructor that allocates the memory.
Definition: Array1D.h:272
void ReadBinary(FILE *f_in)
Read contents of the array from a file in binary format.
Definition: Array1D.h:387
void Resize(const int &nx, const int &t)
Resizes the array and sets ALL entries to the specified value.
Definition: Array1D.h:314
int XSize() const
Returns size in the x-direction.
Definition: Array1D.h:301
void DumpBinary(FILE *f_out) const
Dump contents of the array to a file in binary format.
Definition: Array1D.h:381
Stores data of any type T in a 1D array.
Definition: Array1D.h:61
T * GetArrayPointer()
Return a pointer to the first element of the data in the vector so we can use it access the data in a...
Definition: Array1D.h:138
T & operator[](int i)
Definition: Array1D.h:200
void ReadBinary(char *filename)
Definition: Array1D.h:215
void setArray(vector< T > inarray)
Definition: Array1D.h:245
Array1D(const int &nx)
Constructor that allocates the memory.
Definition: Array1D.h:74
int XSize() const
Returns size in the x-direction.
Definition: Array1D.h:103
Array1D(const Array1D &obj)
Copy constructor.
Definition: Array1D.h:91
~Array1D()
Destructor that frees up the memory.
Definition: Array1D.h:94
void DumpBinary(FILE *f_out) const
Dump contents of the array to a file in binary format.
Definition: Array1D.h:183
vector< T > data_
Definition: Array1D.h:68
void PushBack(const T &t)
Add element to the end of the vector.
Definition: Array1D.h:130
void SetValue(const T &t)
Set all values in the array to the given value.
Definition: Array1D.h:123
void insert(const T &insval, int ix)
Insert a given value to the position ix.
Definition: Array1D.h:167
void Clear()
Function to clear the memory.
Definition: Array1D.h:97
void Resize(const int &nx, const T &t)
Resizes the array and sets ALL entries to the specified value.
Definition: Array1D.h:116
const T & operator()(int ix) const
Definition: Array1D.h:151
Array1D(const int &nx, const T &t)
Constructor that allocates and initializes the data to a value t.
Definition: Array1D.h:79
vector< T > flatten()
Definition: Array1D.h:252
Array1D & operator=(const Array1D &obj)
Assignment operator copies the data structure by value.
Definition: Array1D.h:84
const T * GetConstArrayPointer() const
Return a const point to the first element of the data in the vector so we can use it access the data ...
Definition: Array1D.h:145
void Resize(const int &nx)
Resizes the array.
Definition: Array1D.h:109
string type()
Definition: Array1D.h:256
void ReadBinary(FILE *f_in)
Read contents of the array from a file in binary format.
Definition: Array1D.h:189
T & operator()(int ix)
Definition: Array1D.h:150
void DumpBinary(char *filename)
Dump contents of the array to a file in binary format.
Definition: Array1D.h:204
int xsize_
Definition: Array1D.h:67
void ReadBinary4py(char *filename, int n)
Definition: Array1D.h:235
int Length() const
Returns length (i.e. size in the x-direction)
Definition: Array1D.h:106
void DumpBinary4py(char *filename)
Definition: Array1D.h:226
Array1D()
Default constructor, which does not allocate any memory.
Definition: Array1D.h:71
void insert(Array1D< T > &insarr, int ix)
Insert a given array to the position ix.
Definition: Array1D.h:155
void erase(int ix)
Erase the value from the position ix.
Definition: Array1D.h:175