Skip to content

Commit

Permalink
libs/tdrp: (a) in print.c, adjusting the print format for double type…
Browse files Browse the repository at this point in the history
…s to %.9g. (b) in load.c, adjusting buffer sizes to avoid warnings about sprintf buffer overruns
  • Loading branch information
mike-dixon committed Oct 30, 2024
1 parent a567c8a commit c61a0a2
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 88 deletions.
36 changes: 25 additions & 11 deletions codebase/apps/radar/src/HcrShortLongCombine/HcrShortLongCombine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,24 @@ int HcrShortLongCombine::_computeMeanLocation()
double sumLonShort = 0.0;
double sumAltShort = 0.0;
long nRaysShort = 0;

RadxRay *rayShort = _readerShort->readNextRay();
while (rayShort != NULL) {
const RadxGeoref *georef = rayShort->getGeoreference();
if (georef != NULL) {
sumLatShort += georef->getLatitude();
sumLonShort += georef->getLongitude();
sumAltShort += georef->getAltitudeKmMsl();
nRaysShort += 1.0;
double lat = georef->getLatitude();
double lon = georef->getLongitude();
double alt = georef->getAltitudeKmMsl();
if (lat >= -90.0 && lat <= 90.0 &&
lon >= -360.0 && lon <= 360 &&
alt > -1.0 && alt < 25.0) {
sumLatShort += lat;
sumLonShort += lon;
sumAltShort += alt;
nRaysShort += 1.0;
}
}
if (nRaysShort % 10000 == 0) {
if (nRaysShort > 0 && nRaysShort % 10000 == 0) {
cerr << " data time, n rays short processed: "
<< rayShort->getRadxTime().asString(6) << ", "
<< nRaysShort << endl;
Expand All @@ -415,12 +422,19 @@ int HcrShortLongCombine::_computeMeanLocation()
while (rayLong != NULL) {
const RadxGeoref *georef = rayLong->getGeoreference();
if (georef != NULL) {
sumLatLong += georef->getLatitude();
sumLonLong += georef->getLongitude();
sumAltLong += georef->getAltitudeKmMsl();
nRaysLong += 1.0;
double lat = georef->getLatitude();
double lon = georef->getLongitude();
double alt = georef->getAltitudeKmMsl();
if (lat >= -90.0 && lat <= 90.0 &&
lon >= -360.0 && lon <= 360 &&
alt > -1.0 && alt < 25.0) {
sumLatLong += lat;
sumLonLong += lon;
sumAltLong += alt;
nRaysLong += 1.0;
}
}
if (nRaysLong % 10000 == 0) {
if (nRaysLong > 0 && nRaysLong % 10000 == 0) {
cerr << " data time, n rays long processed: "
<< rayLong->getRadxTime().asString(6) << ", "
<< nRaysLong << endl;
Expand Down
82 changes: 41 additions & 41 deletions codebase/apps/radar/src/HcrShortLongCombine/Params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,39 +649,6 @@
tt->single_val.e = REALTIME;
tt++;

// Parameter 'compute_mean_location'
// ctype is 'tdrp_bool_t'

memset(tt, 0, sizeof(TDRPtable));
tt->ptype = BOOL_TYPE;
tt->param_name = tdrpStrDup("compute_mean_location");
tt->descr = tdrpStrDup("Option to compute the mean location of the radar from the georeference data in the rays.");
tt->help = tdrpStrDup("Applicable in archive mode only, and only applicable to ground-based projects. It will compute the mean radar location, from the short- and long-pulse input data, and print the mean to the terminal. The mean values can then be used in the radar_location parameter (see later) if override_radar_location is set to true.");
tt->val_offset = (char *) &compute_mean_location - &_start_;
tt->single_val.b = pFALSE;
tt++;

// Parameter 'Comment 3'

memset(tt, 0, sizeof(TDRPtable));
tt->ptype = COMMENT_TYPE;
tt->param_name = tdrpStrDup("Comment 3");
tt->comment_hdr = tdrpStrDup("COMPUTE MEAN RADAR LOCATION?");
tt->comment_text = tdrpStrDup("This mode will compute the mean radar location for a ground-based insytallation.");
tt++;

// Parameter 'compute_mean_radar_location'
// ctype is 'tdrp_bool_t'

memset(tt, 0, sizeof(TDRPtable));
tt->ptype = BOOL_TYPE;
tt->param_name = tdrpStrDup("compute_mean_radar_location");
tt->descr = tdrpStrDup("Option to compute mean radar location.");
tt->help = tdrpStrDup("This mode will compute the mean radar location, from the short- and long-pulse input data, and print the mean to the terminal. The mean values can then be used in the radar_location parameter (see above) if override_radar_location is set to true.");
tt->val_offset = (char *) &compute_mean_radar_location - &_start_;
tt->single_val.b = pFALSE;
tt++;

// Parameter 'input_fmq_url_short'
// ctype is 'char*'

Expand Down Expand Up @@ -742,11 +709,11 @@
tt->single_val.s = tdrpStrDup("$(DATA_DIR)/cfradial/moments/100hz_long");
tt++;

// Parameter 'Comment 4'
// Parameter 'Comment 3'

memset(tt, 0, sizeof(TDRPtable));
tt->ptype = COMMENT_TYPE;
tt->param_name = tdrpStrDup("Comment 4");
tt->param_name = tdrpStrDup("Comment 3");
tt->comment_hdr = tdrpStrDup("OVERRIDE PLATFORM TYPE?");
tt->comment_text = tdrpStrDup("");
tt++;
Expand Down Expand Up @@ -801,11 +768,11 @@
tt->single_val.e = PLATFORM_AIRCRAFT_FORE;
tt++;

// Parameter 'Comment 5'
// Parameter 'Comment 4'

memset(tt, 0, sizeof(TDRPtable));
tt->ptype = COMMENT_TYPE;
tt->param_name = tdrpStrDup("Comment 5");
tt->param_name = tdrpStrDup("Comment 4");
tt->comment_hdr = tdrpStrDup("OVERRIDE PRIMARY AXIS?");
tt->comment_text = tdrpStrDup("");
tt++;
Expand Down Expand Up @@ -850,11 +817,11 @@
tt->single_val.e = PRIMARY_AXIS_Y_PRIME;
tt++;

// Parameter 'Comment 6'
// Parameter 'Comment 5'

memset(tt, 0, sizeof(TDRPtable));
tt->ptype = COMMENT_TYPE;
tt->param_name = tdrpStrDup("Comment 6");
tt->param_name = tdrpStrDup("Comment 5");
tt->comment_hdr = tdrpStrDup("OVERRIDE SWEEP MODE?");
tt->comment_text = tdrpStrDup("");
tt++;
Expand Down Expand Up @@ -929,11 +896,11 @@
tt->single_val.d = 9999;
tt++;

// Parameter 'Comment 7'
// Parameter 'Comment 6'

memset(tt, 0, sizeof(TDRPtable));
tt->ptype = COMMENT_TYPE;
tt->param_name = tdrpStrDup("Comment 7");
tt->param_name = tdrpStrDup("Comment 6");
tt->comment_hdr = tdrpStrDup("OVERRIDE RADAR LOCATION?");
tt->comment_text = tdrpStrDup("This will override the latitude/longitude/altitude in the georeference data blocks. It is only intended for use in a ground-based insytallation.");
tt++;
Expand Down Expand Up @@ -986,6 +953,27 @@
tt->struct_vals[2].d = 0;
tt++;

// Parameter 'Comment 7'

memset(tt, 0, sizeof(TDRPtable));
tt->ptype = COMMENT_TYPE;
tt->param_name = tdrpStrDup("Comment 7");
tt->comment_hdr = tdrpStrDup("COMPUTE MEAN RADAR LOCATION?");
tt->comment_text = tdrpStrDup("This mode will compute the mean radar location for a ground-based insytallation.");
tt++;

// Parameter 'compute_mean_location'
// ctype is 'tdrp_bool_t'

memset(tt, 0, sizeof(TDRPtable));
tt->ptype = BOOL_TYPE;
tt->param_name = tdrpStrDup("compute_mean_location");
tt->descr = tdrpStrDup("Option to compute the mean location of the radar from the georeference data in the rays.");
tt->help = tdrpStrDup("Applicable in archive mode only, and only applicable to ground-based projects. It will compute the mean radar location, from the short- and long-pulse input data, and print the mean to the terminal. The mean values can then be used in the radar_location parameter (see above) if override_radar_location is set to TRUE.");
tt->val_offset = (char *) &compute_mean_location - &_start_;
tt->single_val.b = pFALSE;
tt++;

// Parameter 'Comment 8'

memset(tt, 0, sizeof(TDRPtable));
Expand All @@ -1007,6 +995,18 @@
tt->single_val.d = 0.1;
tt++;

// Parameter 'round_dwell_time_to_nearest_interval'
// ctype is 'tdrp_bool_t'

memset(tt, 0, sizeof(TDRPtable));
tt->ptype = BOOL_TYPE;
tt->param_name = tdrpStrDup("round_dwell_time_to_nearest_interval");
tt->descr = tdrpStrDup("Option to round the dwell time to the nearest dwell interval.");
tt->help = tdrpStrDup("If TRUE, the time for each dwell is rounded to the closest dwell_length_secs. The dwell will be centered on the rounded time.");
tt->val_offset = (char *) &round_dwell_time_to_nearest_interval - &_start_;
tt->single_val.b = pFALSE;
tt++;

// Parameter 'dwell_stats_method'
// ctype is '_dwell_stats_method_t'

Expand Down
8 changes: 4 additions & 4 deletions codebase/apps/radar/src/HcrShortLongCombine/Params.hh
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,6 @@ public:

mode_t mode;

tdrp_bool_t compute_mean_location;

tdrp_bool_t compute_mean_radar_location;

char* input_fmq_url_short;

char* input_fmq_url_long;
Expand Down Expand Up @@ -472,8 +468,12 @@ public:

radar_location_t radar_location;

tdrp_bool_t compute_mean_location;

double dwell_length_secs;

tdrp_bool_t round_dwell_time_to_nearest_interval;

dwell_stats_method_t dwell_stats_method;

double dwell_stats_max_fraction_missing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,6 @@ paramdef enum mode_t {
p_help = "\n\nREALTIME: we read data from two moments FMQ, combine the dwells and write to an output queue. \n\nARCHIVE: we read the moments data from CfRadial files, between the start and end times set on the command line.\n\nIn both REALTIME and ARCHIVE mode, we write the resulting moments to an output FMQ.";
} mode;

paramdef boolean {
p_default = FALSE;
p_descr = "Option to compute the mean location of the radar from the georeference data in the rays.";
p_help = "Applicable in archive mode only, and only applicable to ground-based projects. It will compute the mean radar location, from the short- and long-pulse input data, and print the mean to the terminal. The mean values can then be used in the radar_location parameter (see later) if override_radar_location is set to true.";
} compute_mean_location;

commentdef {
p_header = "COMPUTE MEAN RADAR LOCATION?";
p_text = "This mode will compute the mean radar location for a ground-based insytallation.";
}

paramdef boolean {
p_default = FALSE;
p_descr = "Option to compute mean radar location.";
p_help = "This mode will compute the mean radar location, from the short- and long-pulse input data, and print the mean to the terminal. The mean values can then be used in the radar_location parameter (see above) if override_radar_location is set to true.";
} compute_mean_radar_location;


paramdef string {
p_default = "fmqp:://localhost::/tmp/fmq/input_short";
p_descr = "FMQ from which to read the short pulse moments stream.";
Expand Down Expand Up @@ -234,6 +216,17 @@ paramdef struct radar_location_t {
p_help = "The radar_location is only used if 'override_radar_location' is set true. Otherwise the information in the input data stream is used. Note that the altitude is in km MSL.";
} radar_location;

commentdef {
p_header = "COMPUTE MEAN RADAR LOCATION?";
p_text = "This mode will compute the mean radar location for a ground-based insytallation.";
}

paramdef boolean {
p_default = FALSE;
p_descr = "Option to compute the mean location of the radar from the georeference data in the rays.";
p_help = "Applicable in archive mode only, and only applicable to ground-based projects. It will compute the mean radar location, from the short- and long-pulse input data, and print the mean to the terminal. The mean values can then be used in the radar_location parameter (see above) if override_radar_location is set to TRUE.";
} compute_mean_location;

commentdef {
p_header = "SET THE COMBINED DWELL DETAILS";
p_text = "Normally we combine the high-rate moments data (say at 100 hz) into lower-rate dwells, say at 10 hz.";
Expand All @@ -245,6 +238,12 @@ paramdef double {
p_help = "Dwells from the input data will be combined to form dwells covering the specified time.";
} dwell_length_secs;

paramdef boolean {
p_default = FALSE;
p_descr = "Option to round the dwell time to the nearest dwell interval.";
p_help = "If TRUE, the time for each dwell is rounded to the closest dwell_length_secs. The dwell will be centered on the rounded time.";
} round_dwell_time_to_nearest_interval;

typedef enum {
DWELL_STATS_MEAN = 0,
DWELL_STATS_MEDIAN = 1,
Expand Down
28 changes: 15 additions & 13 deletions codebase/libs/tdrp/src/tdrp/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ static int expand_for_single_val(tdrpVal_t *val)
char work_str[TDRP_LINE_MAX];
char combo_str[TDRP_LINE_MAX];
char env_cpy[TDRP_LINE_MAX];
char final_str[TDRP_LINE_MAX * 2];

char *dollar_bracket;
char *closing_bracket;
Expand Down Expand Up @@ -1473,7 +1474,7 @@ static int expand_for_single_val(tdrpVal_t *val)

*dollar_bracket = '\0';
snprintf(combo_str, TDRP_LINE_MAX, "%s%s%s", pre_str, env_val, post_str);
strncpy(work_str, combo_str, TDRP_LINE_MAX);
strncpy(final_str, combo_str, TDRP_LINE_MAX);
env_found = TRUE;

} /* while */
Expand All @@ -1484,7 +1485,7 @@ static int expand_for_single_val(tdrpVal_t *val)

if (env_found) {
tdrpFree(val->s);
val->s = tdrpStrDup(work_str);
val->s = tdrpStrDup(final_str);
}

return iret;
Expand All @@ -1506,9 +1507,10 @@ static int expand_token(tdrpToken_t *token)

{

char work_str[TDRP_LINE_MAX * 2];
char combo_str[TDRP_LINE_MAX];
char tok_str[TDRP_LINE_MAX];
char combo_str[TDRP_LINE_MAX * 2];
char env_cpy[TDRP_LINE_MAX];
char final_str[TDRP_LINE_MAX * 3];

char *dollar_bracket;
char *closing_bracket;
Expand All @@ -1525,16 +1527,16 @@ static int expand_token(tdrpToken_t *token)
* copy in the string variable
*/

tdrpStrNcopy(work_str, token->tok, TDRP_LINE_MAX);

tdrpStrNcopy(tok_str, token->tok, TDRP_LINE_MAX);
/*
* look for opening '$(' sequence
*/

while ((dollar_bracket = strstr(work_str, "$(")) != NULL) {
while ((dollar_bracket = strstr(tok_str, "$(")) != NULL) {

memset (env_cpy, 0, TDRP_LINE_MAX);
pre_str = work_str;
pre_str = tok_str;
env_str = dollar_bracket + 2;

if ((closing_bracket = strchr(env_str, ')')) == NULL) {
Expand All @@ -1545,7 +1547,7 @@ static int expand_token(tdrpToken_t *token)

fprintf(stderr, "\n>>> TDRP_WARNING <<< - expand_token\n");
fprintf(stderr, "No closing bracket for env variable\n");
fprintf(stderr, "Expanding string '%s'", work_str);
fprintf(stderr, "Expanding string '%s'", tok_str);
/* iret = -1; */
break;

Expand Down Expand Up @@ -1594,7 +1596,7 @@ static int expand_token(tdrpToken_t *token)

fprintf(stderr, "\n>>> TDRP_WARNING <<< - expand_token\n");
fprintf(stderr, "Env str too long.\n");
fprintf(stderr, "Expanding string '%s'", work_str);
fprintf(stderr, "Expanding string '%s'", tok_str);
/* iret = -1; */
break;

Expand All @@ -1605,9 +1607,9 @@ static int expand_token(tdrpToken_t *token)
*/

*dollar_bracket = '\0';
snprintf(combo_str, TDRP_LINE_MAX,
snprintf(combo_str, TDRP_LINE_MAX * 2 - 1,
"%s%s%s", pre_str, env_val, post_str);
strncpy(work_str, combo_str, TDRP_LINE_MAX);
strncpy(final_str, combo_str, TDRP_LINE_MAX * 3 - 1);
env_found = TRUE;

} /* while */
Expand All @@ -1618,7 +1620,7 @@ static int expand_token(tdrpToken_t *token)

if (env_found) {
tdrpFree(token->tok);
token->tok = tdrpStrDup(work_str);
token->tok = tdrpStrDup(final_str);
}

return iret;
Expand Down
2 changes: 1 addition & 1 deletion codebase/libs/tdrp/src/tdrp/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ char *sprintf_val(int ptype, const enum_def_t *enum_def, const tdrpVal_t *val)
else if ( val->d == DBL_MAX )
strcpy(str, MAX_KEYWORD);
else
sprintf(str, "%g", val->d);
sprintf(str, "%.9g", val->d);
return (str);
break;

Expand Down

0 comments on commit c61a0a2

Please sign in to comment.