libopenfpga/libopenfpgautil/src/openfpga_scale.cpp
/********************************************************************
 * Convert string time unit to numeric
 * e.g. ps -> 1e-12
 *******************************************************************/
Convert string time unit to numeric
e.g.
Convert string time unit to numeric e . g .
float string_to_time_unit(const std::string& scale) {
  if ( (1 != scale.length())
    && (2 != scale.length()) ) {
    VTR_LOGF_ERROR(__FILE__, __LINE__,
                   "Time unit (='%s') must contain only one or two characters!\n",
                   scale.c_str());
  } 
  if ('s' != scale.back()) {
    VTR_LOGF_ERROR(__FILE__, __LINE__,
                   "Time unit (='%s') must end with 's'!\n",
                   scale.c_str());
  }
  float unit = 1.;
  VTR_ASSERT ( (1 == scale.length())
            || (2 == scale.length()) );
  if (2 == scale.length()) {
    unit = string_to_unit(scale.substr(0, 1));
  }
  if (1e6 < unit) {
    VTR_LOGF_ERROR(__FILE__, __LINE__,
                   "Invalid time unit %g!\nAcceptable units are [1e6|1e3|1|1e-3|1e-6|1e-9|1e-12|1e-15|1e-18]\n",
                   unit); 
    exit(1);
  }
  return unit;
}
float string_to_time_unit ( const std :: string & scale ) { if ( ( 1 != scale . length ( ) ) && ( 2 != scale . length ( ) ) ) { VTR_LOGF_ERROR ( __FILE__ , __LINE__ , " \n " , scale . c_str ( ) ) ; } if ( ' ' != scale . back ( ) ) { VTR_LOGF_ERROR ( __FILE__ , __LINE__ , " \n " , scale . c_str ( ) ) ; } float unit = 1. ; VTR_ASSERT ( ( 1 == scale . length ( ) ) || ( 2 == scale . length ( ) ) ) ; if ( 2 == scale . length ( ) ) { unit = string_to_unit ( scale . substr ( 0 , 1 ) ) ; } if ( 1e6 < unit ) { VTR_LOGF_ERROR ( __FILE__ , __LINE__ , " \n \n " , unit ) ; exit ( 1 ) ; } return unit ; }
Convert string time unit to numeric
 e.g.
Convert string time unit to numeric e . g .
/* The last character must be 's' */ /* For larger than 1 unit, we do not accept */