From c61a0a2f1119ef05e22d740ceac7189c5c13c2bb Mon Sep 17 00:00:00 2001 From: mike-dixon Date: Wed, 30 Oct 2024 17:43:01 -0600 Subject: [PATCH] libs/tdrp: (a) in print.c, adjusting the print format for double types to %.9g. (b) in load.c, adjusting buffer sizes to avoid warnings about sprintf buffer overruns --- .../HcrShortLongCombine.cc | 36 +++++--- .../radar/src/HcrShortLongCombine/Params.cc | 82 +++++++++---------- .../radar/src/HcrShortLongCombine/Params.hh | 8 +- .../paramdef.HcrShortLongCombine | 35 ++++---- codebase/libs/tdrp/src/tdrp/load.c | 28 ++++--- codebase/libs/tdrp/src/tdrp/print.c | 2 +- 6 files changed, 103 insertions(+), 88 deletions(-) diff --git a/codebase/apps/radar/src/HcrShortLongCombine/HcrShortLongCombine.cc b/codebase/apps/radar/src/HcrShortLongCombine/HcrShortLongCombine.cc index 4ac1809fc..c0cb0a79e 100644 --- a/codebase/apps/radar/src/HcrShortLongCombine/HcrShortLongCombine.cc +++ b/codebase/apps/radar/src/HcrShortLongCombine/HcrShortLongCombine.cc @@ -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; @@ -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; diff --git a/codebase/apps/radar/src/HcrShortLongCombine/Params.cc b/codebase/apps/radar/src/HcrShortLongCombine/Params.cc index c72a4ddd6..b79bdb9b1 100644 --- a/codebase/apps/radar/src/HcrShortLongCombine/Params.cc +++ b/codebase/apps/radar/src/HcrShortLongCombine/Params.cc @@ -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*' @@ -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++; @@ -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++; @@ -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++; @@ -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++; @@ -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)); @@ -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' diff --git a/codebase/apps/radar/src/HcrShortLongCombine/Params.hh b/codebase/apps/radar/src/HcrShortLongCombine/Params.hh index fe854c6cb..2ef4fadc2 100644 --- a/codebase/apps/radar/src/HcrShortLongCombine/Params.hh +++ b/codebase/apps/radar/src/HcrShortLongCombine/Params.hh @@ -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; @@ -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; diff --git a/codebase/apps/radar/src/HcrShortLongCombine/paramdef.HcrShortLongCombine b/codebase/apps/radar/src/HcrShortLongCombine/paramdef.HcrShortLongCombine index 632bcc76f..f40183756 100644 --- a/codebase/apps/radar/src/HcrShortLongCombine/paramdef.HcrShortLongCombine +++ b/codebase/apps/radar/src/HcrShortLongCombine/paramdef.HcrShortLongCombine @@ -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."; @@ -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."; @@ -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, diff --git a/codebase/libs/tdrp/src/tdrp/load.c b/codebase/libs/tdrp/src/tdrp/load.c index 94971aede..2b4e4a0b9 100644 --- a/codebase/libs/tdrp/src/tdrp/load.c +++ b/codebase/libs/tdrp/src/tdrp/load.c @@ -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; @@ -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 */ @@ -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; @@ -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; @@ -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) { @@ -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; @@ -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; @@ -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 */ @@ -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; diff --git a/codebase/libs/tdrp/src/tdrp/print.c b/codebase/libs/tdrp/src/tdrp/print.c index c9d2e737c..128daa8cf 100644 --- a/codebase/libs/tdrp/src/tdrp/print.c +++ b/codebase/libs/tdrp/src/tdrp/print.c @@ -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;