Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 1950 sort station list #2121

Merged
merged 29 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5bff065
Update the top-level README file to list ioda2nc, but also to trigger…
JohnHalleyGotway Mar 14, 2022
1567266
Added bool Sorted variable, set to true or false in relevant function…
Mar 15, 2022
7635147
In parse_sid_mask(), added the line: mask_sid.sort(). SL
Mar 15, 2022
328cba5
Per issue #1950, put in some cout statements for testing. SL
Mar 16, 2022
f74897a
Per issue #1950, working in has() function, checking for Sort and put…
Mar 16, 2022
68a07d1
Per issue #1950: Cleaned up some cout (print) statements. Left one in…
Mar 17, 2022
36e9097
Per issue #1950: modified has() function. Added lower_bound search fo…
Mar 17, 2022
62e69af
Per issue #1950: In has(), I commented out the print (cout) statement…
Mar 23, 2022
3e43b63
added logic to manually trigger a workflow via the GitHub… (#2107)
georgemccabe Mar 28, 2022
3a081aa
Per issue #1950, put back in some print (cout) statements for testing…
Mar 28, 2022
2c58afa
Merge branch 'develop', remote-tracking branch 'origin' into feature_…
Mar 28, 2022
8d5f83f
Per issue #1950: in has() function, experimenting using the upper_bou…
Mar 29, 2022
e288ab3
Per issue #1950: added a new has function that uses binary_search. Re…
Mar 30, 2022
86a0565
Per issue #1950: re-worked original has(), basically reverted back to…
Mar 31, 2022
efe75ea
Per issue #1950: in section that checks Obs Station Id in SID masking…
Mar 31, 2022
d3a8fd2
Per issue #1950: created new mask station id list (CONUS METARs) and …
Mar 31, 2022
d7dae9c
Per issue #1950: reverted back to orginal sid mask site-lists. SL
Apr 1, 2022
bbb7f1d
Per issue #1950: checking in this site-list that was used for testing…
Apr 1, 2022
c78f894
Per issue #1950, modified and added better debugging to figure out cu…
Apr 4, 2022
debac07
Per #1950, small tweak in ascii2nc to make it slightly more efficient…
JohnHalleyGotway Apr 5, 2022
e5dc473
Per #1950: removed mlog and cout print statements from has() function…
Apr 5, 2022
5dc7211
Update met/src/basic/vx_log/string_array.cc
sethlinden Apr 6, 2022
944ccf4
Update met/src/basic/vx_log/string_array.cc
sethlinden Apr 6, 2022
92412b4
Update met/src/basic/vx_log/string_array.cc
sethlinden Apr 6, 2022
c1bf4ef
Update met/src/basic/vx_log/string_array.cc
sethlinden Apr 6, 2022
0620554
Update met/src/basic/vx_log/string_array.cc
sethlinden Apr 6, 2022
69cb61b
Update met/src/basic/vx_log/string_array.h
sethlinden Apr 6, 2022
3cd1297
Delete SID_CONUS.txt
sethlinden Apr 6, 2022
bfe61cc
Delete SID_CONUS_times11.txt
sethlinden Apr 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions met/src/basic/vx_config/config_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@ void parse_sid_mask(const ConcatString &mask_sid_str,

}

// Sort the mask_sid's
mask_sid.sort();

return;
}

Expand Down
193 changes: 117 additions & 76 deletions met/src/basic/vx_log/string_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ MaxLength = 0;

clear();

Sorted = false;

return;

}
Expand All @@ -149,6 +151,8 @@ void StringArray::clear()

s.clear();

Sorted = false;

return;

}
Expand All @@ -166,6 +170,7 @@ clear();
s = a.s;

IgnoreCase = a.IgnoreCase;
Sorted = a.Sorted;

return;

Expand All @@ -183,6 +188,7 @@ Indent prefix(depth);
Indent prefix2(depth + 1);

out << prefix << "IgnoreCase = " << IgnoreCase << "\n";
out << prefix << "Sorted = " << (Sorted ? "true" : "false") << "\n";

int j;

Expand Down Expand Up @@ -250,6 +256,8 @@ void StringArray::add(const std::string text)

s.push_back(text);

Sorted = false;

return;

}
Expand All @@ -265,7 +273,9 @@ void StringArray::add(const StringArray & a)
if ( a.n() == 0 ) return;

s.insert(s.end(), a.s.begin(), a.s.end());


Sorted = false;

return;

}
Expand Down Expand Up @@ -298,6 +308,8 @@ void StringArray::add_css(const std::string text)

}

Sorted = false;

return;

}
Expand All @@ -314,6 +326,9 @@ s.clear();

s.push_back(text);

// Setting to a single value, by nature it is Sorted
Sorted = true;

return;

}
Expand All @@ -336,6 +351,8 @@ void StringArray::set(int i, const std::string text)

s[i] = text;

Sorted = false;

return;

}
Expand All @@ -358,6 +375,8 @@ void StringArray::insert(int i, const char * text)

s.insert(s.begin()+i, text);

Sorted = false;

return;

}
Expand All @@ -366,90 +385,104 @@ void StringArray::insert(int i, const char * text)
////////////////////////////////////////////////////////////////////////


bool StringArray::has(const std::string text, bool forward) const
bool StringArray::has(const std::string text) const

{
bool found = false;
bool forward = true;

if (Sorted && !IgnoreCase) {
found = binary_search(s.begin(), s.end(), text);
}
else {
return ( has(text, forward) );
}

int index;
return found;
}

return ( has(text, index, forward) );

}
////////////////////////////////////////////////////////////////////////


bool StringArray::has(const std::string text, bool forward) const

{
int index;
return ( has(text, index, forward) );
}

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


bool StringArray::has(const std::string text, int & index, bool forward) const

{
bool found = false;
index = -1;

if (!s.empty()) {
int count;
std::string lower_text = text;
std::vector<std::string>::const_iterator it;
if ( IgnoreCase ) transform(lower_text.begin(), lower_text.end(), lower_text.begin(), ::tolower);

if (forward) {
count = 0;
for(it = s.begin(); it != s.end(); it++, count++) {
if ( IgnoreCase ) {
std::string lower_s = *it;
transform(lower_s.begin(), lower_s.end(), lower_s.begin(), ::tolower);
if ( lower_s == lower_text) {
// if ( strcasecmp((*it).c_str(), text.c_str()) ) {
found = true;
break;
}
}
else {
if ( *it == text ) {
found = true;
break;
}
}
}
}
else {
count = s.size() - 1;
it = s.end();
for(it--; it != s.begin(); it--, count--) {
if ( IgnoreCase ) {
std::string lower_s = *it;
transform(lower_s.begin(), lower_s.end(), lower_s.begin(), ::tolower);
if ( lower_s == lower_text) {
found = true;
break;
}
}
else {
if ( *it == text ) {
found = true;
break;
}
}
// This function is now used for either an un-sorted array (Sorted is false)
// Or for a case-insensitive search (IgnoreCase is true)
//
bool found = false;
index = -1;

if (!s.empty()) {
int count;
std::string lower_text = text;
std::vector<std::string>::const_iterator it;
if ( IgnoreCase ) transform(lower_text.begin(), lower_text.end(), lower_text.begin(), ::tolower);

if (forward) {
count = 0;
for(it = s.begin(); it != s.end(); it++, count++) {
if ( IgnoreCase ) {
std::string lower_s = *it;
transform(lower_s.begin(), lower_s.end(), lower_s.begin(), ::tolower);
if ( lower_s == lower_text) {
found = true;
break;
}
}
else {
if ( *it == text ) {
found = true;
break;
}
}
}
}
if (!found && it == s.begin()) {
if ( IgnoreCase ) {
std::string lower_s = *it;
transform(lower_s.begin(), lower_s.end(), lower_s.begin(), ::tolower);
found = ( lower_s == lower_text );
}
else found = ( *it == text );
else {
count = s.size() - 1;
it = s.end();
for(it--; it != s.begin(); it--, count--) {
if ( IgnoreCase ) {
std::string lower_s = *it;
transform(lower_s.begin(), lower_s.end(), lower_s.begin(), ::tolower);
if ( lower_s == lower_text) {
found = true;
break;
}
}
else {
if ( *it == text ) {
found = true;
break;
}
}
}
if (!found && it == s.begin()) {
if ( IgnoreCase ) {
std::string lower_s = *it;
transform(lower_s.begin(), lower_s.end(), lower_s.begin(), ::tolower);
found = ( lower_s == lower_text );
}
else found = ( *it == text );
}
}
}
if (found) index = count;
}
//mlog << Debug(9) << " StringArray::has() size=" << s.size()
// << " for " << text << ", found: " << (found ? "true" : "false")
// << ", forward: " << (forward ? "yes" : "no") << "\n";

return found;

if (found) index = count;
}

return found;
}


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


Expand Down Expand Up @@ -500,6 +533,8 @@ void StringArray::parse_delim(const std::string text, const char *delim)
if (start < str.length())
s.push_back(str.substr(start).c_str());

Sorted = false;

return;

}
Expand Down Expand Up @@ -616,13 +651,19 @@ return ( s[k].length() );
void StringArray::sort()

{

if ( n() <= 1 ) return;

std::sort(s.begin(), s.end());

return;

if ( n() <= 1 ) {
Sorted = true;
return;
}

if ( !Sorted ) {
std::sort(s.begin(), s.end());
}

Sorted = true;

return;

}


Expand Down
8 changes: 5 additions & 3 deletions met/src/basic/vx_log/string_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class StringArray {

public:


void init_from_scratch();

void assign(const StringArray &);
Expand All @@ -40,7 +39,8 @@ class StringArray {
int MaxLength;

bool IgnoreCase;


bool Sorted;

public:

Expand Down Expand Up @@ -77,8 +77,10 @@ class StringArray {

int length(int) const;

bool has(const std::string, bool forward=true) const;
bool has(const std::string) const;

bool has(const std::string, bool forward) const;

bool has(const std::string, int & index, bool forward=true) const;

//
Expand Down
2 changes: 2 additions & 0 deletions met/src/libcode/vx_statistics/pair_data_point.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,8 @@ void VxPairDataPoint::add_point_obs(float *hdr_arr, const char *hdr_typ_str,
// masking SID list
else if(pd[i][j][0].mask_sid_ptr != (StringArray *) 0) {
if(!pd[i][j][0].mask_sid_ptr->has(hdr_sid_str)) {
mlog << Debug(9) << "Checking for the obs station id in the masking SID list: rejected hdr_sid_str = "
<< hdr_sid_str << "\n";
inc_count(rej_mask, i, j);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion met/src/tools/other/ascii2nc/met_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ bool MetHandler::_readObservations(LineDataFile &ascii_file)
use_var_id = true;
if (!obs_names.has(data_line[6], var_index)) {
obs_names.add(data_line[6]);
obs_names.has(data_line[6], var_index);
var_index = obs_names.n() - 1;
}
grib_code = var_index;
break;
Expand Down