Example #1
0
int ConfigImpl::set_double_param(const string& section, const string& param_name, double value)
{
    stringstream ss;
    ss<<value;

    string converted = ss.str();

    return set_string_param(section, param_name, converted);
}
Example #2
0
/******************************************************************

   Description:
      This function fills the product parameters of the 
      external model data structure.

   Inputs:
      ext_grid_type - index indicating type of grid data to pack
      product_description - name defining product to be packed
      model_attrs - attributes of current model

   Output:
      none

   Returns:
      A value that is true unless problems were encountered during processing.

******************************************************************/
int fill_product_params( int ext_grid_type, char *product_description, RPGCS_model_attr_t*model_attrs ) {

  char *name = "Model Derived Grid Data";
  int ret, value_int = 0;
  float value_float = 0.0;
  time_t cur_time = time(NULL);

  int yy, mm, dd, hh, mn, ss;
  int ctime, jdate;
  char temp_str[15];

  grid_ext_data->name = (char *) malloc( strlen(name) + 1 );
  strcpy( grid_ext_data->name, name );
  grid_ext_data->name[strlen(name)] = 0;

  grid_ext_data->description = (char *) malloc( strlen(product_description) + 1 );
  strcpy( grid_ext_data->description, product_description );
  grid_ext_data->description[strlen(product_description)] = 0;

  if ( ext_grid_type == FRZ_GRID )
    grid_ext_data->product_id = MODEL_FRZ_GRID;
  else if ( ext_grid_type == CIP_GRID )
    grid_ext_data->product_id = MODEL_CIP_GRID;
  else
    grid_ext_data->product_id = 99;

  grid_ext_data->type = RPGP_EXTERNAL;
  grid_ext_data->spare[0] = 0;
  grid_ext_data->spare[1] = 0;
  grid_ext_data->spare[2] = 0;
  grid_ext_data->spare[3] = 0;
  grid_ext_data->spare[4] = 0;

  /* get current time, convert to unix time, and set to gen_time */
  ret = RPGCS_get_date_time( &ctime, &jdate );
  hh = (int)( ctime / SECS_IN_HOUR );
  mn = (int)( (ctime - (hh * SECS_IN_HOUR)) / 60 );
  ss = ctime - (hh * SECS_IN_HOUR) - (mn * 60);

  ret = RPGCS_julian_to_date( jdate, &yy, &mm, &dd );
  /*fprintf( stderr,"Current Time: %d%02d%02d %02d:%02d:%02d\n", yy, mm, dd, hh, mn, ss );*/

  ret = RPGCS_ymdhms_to_unix_time( &cur_time, yy, mm, dd, hh, mn, ss );
  /*fprintf( stderr,"Current Unix Time: %d\n\n", (unsigned int)cur_time );*/

  grid_ext_data->gen_time = (unsigned int)cur_time;
  grid_ext_data->compress_type = 0;
  grid_ext_data->size_decompressed = 0;
  grid_ext_data->numof_prod_params = PARAMETER_IDS;

  /* fill the parameter ids */
  RPGP_parameter_t *params = (RPGP_parameter_t *) malloc( grid_ext_data->numof_prod_params * sizeof(RPGP_parameter_t) );
  grid_ext_data->prod_params = params;

  set_string_param( params+0, "mod_name", "Model Name", STR_RUC13, "" );

  ret = RPGCS_unix_time_to_ymdhms( model_attrs->model_run_time, &yy, &mm, &dd, &hh, &mn, &ss );
  sprintf( temp_str, "%d%02d%02d", yy, mm, dd );
  set_string_param( params+1, "mod_run_date", RPGCS_MODEL_RUN_DATE, (char *) temp_str, "" );

  sprintf( temp_str, "%02d:%02d:%02d", hh, mn, ss );
  set_string_param( params+2, "mod_run_time", RPGCS_MODEL_RUN_TIME, (char *) temp_str, "" );

  ret = RPGCS_unix_time_to_ymdhms( model_attrs->valid_time, &yy, &mm, &dd, &hh, &mn, &ss );
  sprintf( temp_str, "%d%02d%02d", yy, mm, dd );
  set_string_param( params+3, "val_date", RPGCS_VALID_DATE, (char *) temp_str, "" );

  sprintf( temp_str, "%02d:%02d:%02d", hh, mn, ss );
  set_string_param( params+4, "val_time", RPGCS_VALID_TIME, (char *) temp_str, "" );

  value_int = (model_attrs->valid_time - model_attrs->model_run_time) / 3600;
  set_int_param( params+5, "forecast_hr", RPGCS_FORECAST_HOUR, value_int, "" );

  set_string_param( params+6, "coord_system", "Coordinate System", "Cartesian", "" );

  if ( model_attrs->projection == 1 )
    set_string_param( params+7, "proj", RPGCS_PROJECTION, "Lambert Conformal", "" );
  else
    set_string_param( params+7, "proj", RPGCS_PROJECTION, "Unknown Projection", "" );

  value_float = (float)model_attrs->grid_lower_left.latitude;
  set_float_param( params+8, "lat_lower_left", RPGCS_LATITUDE_LLC, value_float, "degrees" );

  value_float = (float)model_attrs->grid_lower_left.longitude;
  set_float_param( params+9, "lon_lower_left", RPGCS_LONGITUDE_LLC, value_float, "degrees" );

  value_float = (float)model_attrs->grid_upper_right.latitude;
  set_float_param( params+10,"lat_upper_right" , RPGCS_LATITUDE_URC, value_float, "degrees" );

  value_float = (float)model_attrs->grid_upper_right.longitude;
  set_float_param( params+11, "lon_upper_right", RPGCS_LONGITUDE_URC, value_float, "degrees" );

  value_float = (float)model_attrs->tangent_point.latitude;
  set_float_param( params+12, "lat_tang_pt", RPGCS_LATITUDE_TANP, value_float, "degrees" );

  value_float = (float)model_attrs->tangent_point.longitude;
  set_float_param( params+13, "lon_tang_pt", RPGCS_LONGITUDE_TANP, value_float, "degrees" );

  value_int = model_attrs->dimensions[0];
  set_int_param( params+14, "numXpts", RPGCS_X_DIMENSION, value_int, "" );

  value_int = model_attrs->dimensions[1];
  set_int_param( params+15, "numYpts", RPGCS_Y_DIMENSION, value_int, "" );

  return( 1 );

/* End of fill_product_params() */
}