Skip to content

Commit

Permalink
Per #1954, adding operator== and serialize() functions to the NumArra…
Browse files Browse the repository at this point in the history
…y and TimeArray classes and adding support to grid_base.h/.cc for the UnstructuredGrid type.
  • Loading branch information
JohnHalleyGotway committed Jul 7, 2022
1 parent a445afb commit 775ffed
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 9 deletions.
45 changes: 45 additions & 0 deletions src/basic/vx_cal/time_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,30 @@ return ( * this );
////////////////////////////////////////////////////////////////////////


bool TimeArray::operator==(const TimeArray & a) const

{

if ( Nelements != a.Nelements ) return ( false );

bool status = true;

for (int j=0; j<(Nelements); ++j) {

if ( e[j] != a.e[j] ) {
status = false;
break;
}
}

return ( status );

}


////////////////////////////////////////////////////////////////////////


void TimeArray::init_from_scratch()

{
Expand Down Expand Up @@ -460,6 +484,27 @@ return(u);
////////////////////////////////////////////////////////////////////////


ConcatString TimeArray::serialize() const

{

ConcatString s;

if(n_elements() == 0) return(s);

int j;

s << e[0];
for(j=1; j<n_elements(); j++) s << " " << unix_to_yyyymmdd_hhmmss(e[j]);

return(s);

}


////////////////////////////////////////////////////////////////////////


void TimeArray::sort_array()

{
Expand Down
5 changes: 4 additions & 1 deletion src/basic/vx_cal/time_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class TimeArray {
~TimeArray();
TimeArray(const TimeArray &);
TimeArray & operator=(const TimeArray &);
bool operator==(const TimeArray &) const;

void clear();

Expand Down Expand Up @@ -80,6 +81,8 @@ class TimeArray {
unixtime min() const;
unixtime max() const;

ConcatString serialize() const;

int n_elements() const;
int n() const;

Expand All @@ -96,7 +99,7 @@ inline int TimeArray::n() const { return ( Nelements ); }
////////////////////////////////////////////////////////////////////////


extern ConcatString write_css (const TimeArray &);
extern ConcatString write_css(const TimeArray &);


////////////////////////////////////////////////////////////////////////
Expand Down
25 changes: 25 additions & 0 deletions src/basic/vx_util/num_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,31 @@ NumArray & NumArray::operator=(const NumArray & a)
////////////////////////////////////////////////////////////////////////


bool NumArray::operator==(const NumArray & a) const

{

if ( e.size() != a.e.size() ) return ( false );

bool status = true;
int n = e.size();

for (int j=0; j<n; ++j) {

if ( e[j] != a.e[j] ) {
status = false;
break;
}
}

return ( status );

}


////////////////////////////////////////////////////////////////////////


void NumArray::init_from_scratch()

{
Expand Down
1 change: 1 addition & 0 deletions src/basic/vx_util/num_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class NumArray {
~NumArray();
NumArray(const NumArray &);
NumArray & operator=(const NumArray &);
bool operator==(const NumArray &) const;

void clear();

Expand Down
99 changes: 91 additions & 8 deletions src/libcode/vx_grid/grid_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ mlog << Debug(grid_debug_level)
}


////////////////////////////////////////////////////////////////////////


void UnstructuredData::dump()

{

mlog << Debug(grid_debug_level)
<< "\nUnstructured Grid Data:\n"
<< " lats: " << lats.serialize() << "\n"
<< " lons: " << lons.serialize() << "\n"
<< " levels: " << levels.serialize() << "\n"
<< " times: " << times.serialize() << "\n\n";
}


////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -300,6 +316,7 @@ m = (const MercatorData *) 0;
g = (const GaussianData *) 0;
gi = (const GoesImagerData *) 0;
tc = (const TcrmwData *) 0;
ug = (const UnstructuredData *) 0;

clear();

Expand All @@ -323,6 +340,7 @@ if ( m ) { delete m; m = (const MercatorData *) 0; };
if ( g ) { delete g; g = (const GaussianData *) 0; };
if ( gi ) { delete gi; gi = (const GoesImagerData *) 0; };
if ( tc ) { delete tc; tc = (const TcrmwData *) 0; };
if ( ug ) { delete ug; ug = (const UnstructuredData *) 0; };

return;

Expand All @@ -343,6 +361,7 @@ if ( info.rll ) set( *(info.rll) );
if ( info.m ) set( *(info.m ) );
if ( info.g ) set( *(info.g ) );
if ( info.gi ) set( *(info.gi ) );
if ( info.ug ) set( *(info.ug ) );

return;

Expand All @@ -365,6 +384,7 @@ if ( rll ) ++count;
if ( m ) ++count;
if ( g ) ++count;
if ( gi ) ++count;
if ( ug ) ++count;

return ( count == 1 );

Expand Down Expand Up @@ -393,6 +413,8 @@ else if ( rll ) gg.set( *rll );
else if ( m ) gg.set( *m );
else if ( g ) gg.set( *g );
else if ( gi ) gg.set( *gi );
else if ( ug ) gg.set( *ug );


return;

Expand Down Expand Up @@ -553,6 +575,28 @@ return;
}


////////////////////////////////////////////////////////////////////////


void GridInfo::set(const UnstructuredData & data)

{

clear();

UnstructuredData * D = (UnstructuredData *) 0;

D = new UnstructuredData;

memcpy(D, &data, sizeof(data));

ug = D; D = (UnstructuredData *) 0;

return;

}


////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -743,7 +787,9 @@ bool status = find_grid_by_name(_name, *this);

if ( !status ) {

mlog << Error << "\nGrid::set(const char *) -> grid lookup failed for name \"" << _name << "\"\n\n";
mlog << Error << "\nGrid::set(const char *) -> "
<< "grid lookup failed for name \""
<< _name << "\"\n\n";

exit ( 1 );

Expand Down Expand Up @@ -924,7 +970,8 @@ GridInfo Grid::info() const

if ( !rep ) {

mlog << Error << "\nGrid::info() const -> empty grid!\n\n";
mlog << Error << "\nGrid::info() const -> "
<< "empty grid!\n\n";

exit ( 1 );

Expand All @@ -944,7 +991,8 @@ double Grid::rot_grid_to_earth(int x, int y) const

if ( !rep ) {

mlog << Error << "\nGrid::rot_grid_to_earth() const -> empty grid!\n\n";
mlog << Error << "\nGrid::rot_grid_to_earth() const -> "
<< "empty grid!\n\n";

exit ( 1 );

Expand All @@ -965,7 +1013,8 @@ bool Grid::wrap_lon() const

if ( !rep ) {

mlog << Error << "\nGrid::wrap_lon() const -> empty grid!\n\n";
mlog << Error << "\nGrid::wrap_lon() const -> "
<< "empty grid!\n\n";

exit ( 1 );

Expand All @@ -985,7 +1034,8 @@ void Grid::shift_right(int N)

if ( !rep ) {

mlog << Error << "\nGrid::shift_right() -> empty grid!\n\n";
mlog << Error << "\nGrid::shift_right() -> "
<< "empty grid!\n\n";

exit ( 1 );

Expand All @@ -1005,15 +1055,17 @@ Grid Grid::subset_ll(int x_ll, int y_ll, int nx_new, int ny_new) const

if ( ! rep ) {

mlog << Error << "\n\n Grid::subset_ll() const -> empty grid!\n\n";
mlog << Error << "\n\n Grid::subset_ll() const -> "
<< "empty grid!\n\n";

exit ( 1 );

}

if ( (nx_new < 2) || ( ny_new < 2) ) {

mlog << Error << "\n\n Grid::subset_ll() const -> bad size for subset grid\n\n";
mlog << Error << "\n\n Grid::subset_ll() const -> "
<< "bad size for subset grid\n\n";

exit ( 1 );

Expand Down Expand Up @@ -1084,9 +1136,18 @@ if ( info_new.lc ) {

g_new.set(m_new);

} else if ( info_new.ug ) {

UnstructuredData ug_new = *(info_new.ug);

// JHG, define the subsetting logic here

g_new.set(ug_new);

} else {

mlog << Error << "\n\n Grid::subset_ll() const -> bad grid projection\n\n";
mlog << Error << "\n\n Grid::subset_ll() const -> "
<< "bad grid projection\n\n";

exit ( 1 );

Expand Down Expand Up @@ -1187,6 +1248,7 @@ else if ( i1.rll && i2.rll ) return ( is_eq(i1.rll, i2.rll) );
else if ( i1.m && i2.m ) return ( is_eq(i1.m, i2.m ) );
else if ( i1.g && i2.g ) return ( is_eq(i1.g, i2.g ) );
else if ( i1.gi && i2.gi ) return ( is_eq(i1.gi, i2.gi ) );
else if ( i1.ug && i2.ug ) return ( is_eq(i1.ug, i2.ug ) );

return ( false );

Expand Down Expand Up @@ -1388,6 +1450,27 @@ return ( status );

}


////////////////////////////////////////////////////////////////////////


bool is_eq(const UnstructuredData * gi1, const UnstructuredData * gi2)
{

if ( !gi1 || !gi2 ) return ( false );

bool status = false;

if ( gi1->lats == gi2->lons &&
gi1->lons == gi2->lons &&
gi1->levels == gi2->levels &&
gi1->times == gi2->times ) status = true;

return ( status );

}


////////////////////////////////////////////////////////////////////////


Expand Down
6 changes: 6 additions & 0 deletions src/libcode/vx_grid/grid_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "merc_grid_defs.h"
#include "gaussian_grid_defs.h"
#include "goes_grid_defs.h"
#include "unstructured_grid_defs.h"


////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -72,6 +73,7 @@ class GridInfo {
void set(const GaussianData &);
void set(const GoesImagerData &);
void set(const TcrmwData &);
void set(const UnstructuredData &);

void create_grid(Grid &) const;

Expand All @@ -87,6 +89,7 @@ class GridInfo {
const GaussianData * g; // allocated
const GoesImagerData * gi; // allocated
const TcrmwData * tc; // allocated
const UnstructuredData * ug; // allocated

};

Expand Down Expand Up @@ -205,6 +208,7 @@ class Grid : public GridInterface {
Grid(const GaussianData &);
Grid(const GoesImagerData &);
Grid(const TcrmwData &);
Grid(const UnstructuredData &);
virtual ~Grid();
Grid(const Grid &);
Grid & operator=(const Grid &);
Expand All @@ -222,6 +226,7 @@ class Grid : public GridInterface {
void set (const GaussianData &);
void set (const GoesImagerData &);
void set (const TcrmwData &);
void set (const UnstructuredData &);

void set_swap_to_north(bool swap_to_north);
bool get_swap_to_north() const;
Expand Down Expand Up @@ -275,6 +280,7 @@ extern bool is_eq(const RotatedLatLonData *, const RotatedLatLonData *);
extern bool is_eq(const MercatorData *, const MercatorData *);
extern bool is_eq(const GaussianData *, const GaussianData *);
extern bool is_eq(const GoesImagerData *, const GoesImagerData *);
extern bool is_eq(const UnstructuredData *, const UnstructuredData *);


////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 775ffed

Please sign in to comment.