Output "--" if that was specified in the header file.

Used the mods field in the attributes to indicate of "--" was specified in the header file.  We
still save the units as "1" to keep it compatible with udunits.  When outputting the variable
in data recording or variable server we check to see if the mods field for "--" is set.  We
output "--" if the mods field is set.  Also allowed "--" to persist in data products.

refs #254
This commit is contained in:
Alex Lin 2016-06-21 16:12:28 -05:00
parent d9f1780939
commit fcb63e0e06
16 changed files with 84 additions and 19 deletions

View File

@ -8,6 +8,7 @@
#define TRICK_VAR_INPUT 0x02
#define TRICK_CHKPNT_OUTPUT 0x04
#define TRICK_CHKPNT_INPUT 0x08
#define TRICK_MODS_UNITSDASHDASH 0x04
#define TRICK_MAX_INDEX 8
@ -89,12 +90,10 @@ typedef struct ATTRIBUTES_tag {
double range_max; /**< -- Minimum allowable value for parameter */
Language language; /**< -- Native language of parameter. */
int mods; /**< -- Modification bits.
bit 0 = c++ reference var
bit 1 = c++ static var
bit 32 = deprecated var */
bit 2 = "--" units
bit 31 = deprecated var */
long offset; /**< -- Offset in bytes of this parameter from beginning of data structure */
void *attr; /**< -- Address to next level parameter attributes

View File

@ -41,6 +41,7 @@ FieldDescription::FieldDescription(
field_width(0) ,
inherited(false) ,
units("1") ,
is_dashdash(false) ,
line_no(0) ,
io(3) ,
type_enum_string("TRICK_VOID") ,
@ -233,6 +234,7 @@ void FieldDescription::parseComment(std::string comment) {
units.erase(remove_if(units.begin(), units.end(), isspace), units.end());
if ( !units.compare("--") ) {
units = "1" ;
is_dashdash = true ;
} else {
// map old unit names to new names
std::string new_units = map_trick_units_to_udunits(units) ;
@ -367,6 +369,10 @@ std::string FieldDescription::getUnits() {
return units ;
}
bool FieldDescription::isDashDashUnits() {
return is_dashdash ;
}
void FieldDescription::setIO(unsigned int in_io) {
io = in_io ;
}

View File

@ -53,6 +53,7 @@ class FieldDescription : public ConstructValues {
void setMangledTypeName( std::string in_val ) ;
std::string getMangledTypeName() ;
std::string getUnits() ;
bool isDashDashUnits() ;
void setIO(unsigned int) ;
unsigned int getIO() ;
std::string getDescription() ;
@ -117,6 +118,9 @@ class FieldDescription : public ConstructValues {
/** Units specified of the field */
std::string units ;
/** was -- used as units */
bool is_dashdash ;
/** io restrictions */
unsigned int io ;

View File

@ -93,7 +93,7 @@ void PrintFileContents10::print_field_attr(std::ofstream & outfile , FieldDescr
outfile << ",sizeof(" << fdes->getTypeName() << ")" ;
}
outfile << ",0,0,Language_CPP" ; // range_min, range_max, language
outfile << "," << (fdes->isStatic() << 1 ) << "," << std::endl ; // mods
outfile << "," << (fdes->isStatic() << 1) + (fdes->isDashDashUnits() << 2) << "," << std::endl ; // mods
if ( fdes->isBitField() ) {
// For bitfields we need the offset to start on 4 byte boundaries because that is what our
// insert and extract bitfield routines work with.

View File

@ -51,7 +51,11 @@ Csv::Csv(char * file_name , char * param_name ) {
unitTimeStr_ = start_unit + 1 ;
}
else {
unitStr_ = map_trick_units_to_udunits(start_unit + 1) ;
if ( !strcmp(start_unit + 1,"--") ) {
unitStr_ = strdup(start_unit + 1) ;
} else {
unitStr_ = map_trick_units_to_udunits(start_unit + 1) ;
}
}
}
break ;

View File

@ -154,7 +154,11 @@ TrickBinary::TrickBinary(char * file_name , char * param_name ) {
}
if ( ! strcmp( name_ptr , param_name )) {
unitStr_ = map_trick_units_to_udunits(units_ptr) ;
if ( !strcmp(units_ptr,"--") ) {
unitStr_ = strdup(units_ptr) ;
} else {
unitStr_ = map_trick_units_to_udunits(units_ptr) ;
}
record_offset_ = record_size_ ;
type_ = type ;
size_ = size ;

View File

@ -54,7 +54,11 @@ TrickHDF5::TrickHDF5(char *file_name , char *parameter_name , char *time_name) {
H5PTget_next(parameter_units, 1, units_buf);
// the specified parameter_name is found, set the units
if (strcmp(parameter_name, name_buf) == 0) {
unitStr_ = map_trick_units_to_udunits(units_buf) ;
if ( !strcmp(units_ptr,"--") ) {
unitStr_ = strdup(units_buf) ;
} else {
unitStr_ = map_trick_units_to_udunits(units_buf) ;
}
break;
}
}

View File

@ -145,7 +145,11 @@ int LogGroup::parseLogHeaders()
}
// Initialize Unit class
currVar->setUnit(map_trick_units_to_udunits(str3));
if ( ! strcmp(str3,"--")) {
currVar->setUnit(str3);
} else {
currVar->setUnit(map_trick_units_to_udunits(str3));
}
// Set Var Name
currVar->setVarName(str4) ;

View File

@ -75,14 +75,22 @@ int Trick::DRAscii::format_specific_init() {
/* Start with the 1st item in the buffer which should be "sys.exec.out.time" */
out_stream << rec_buffer[0]->ref->reference ;
if ( rec_buffer[0]->ref->attr->units != NULL ) {
out_stream << " {" << rec_buffer[0]->ref->attr->units << "}" ;
if ( rec_buffer[0]->ref->attr->mods & TRICK_MODS_UNITSDASHDASH ) {
out_stream << " {--}" ;
} else {
out_stream << " {" << rec_buffer[0]->ref->attr->units << "}" ;
}
}
/* Write out specified recorded parameters */
for (jj = 1; jj < rec_buffer.size() ; jj++) {
out_stream << delimiter << rec_buffer[jj]->ref->reference ;
if ( rec_buffer[jj]->ref->attr->units != NULL ) {
out_stream << " {" << rec_buffer[jj]->ref->attr->units << "}" ;
if ( rec_buffer[jj]->ref->attr->mods & TRICK_MODS_UNITSDASHDASH ) {
out_stream << " {--}" ;
} else {
out_stream << " {" << rec_buffer[jj]->ref->attr->units << "}" ;
}
}
}
out_stream << std::endl ;

View File

@ -95,9 +95,15 @@ int Trick::DRBinary::format_specific_init() {
write( fp , rec_buffer[jj]->ref->reference , write_value ) ;
/* units */
write_value = strlen(rec_buffer[jj]->ref->attr->units) ;
write( fp , &write_value , sizeof(int)) ;
write( fp , rec_buffer[jj]->ref->attr->units , write_value ) ;
if ( rec_buffer[jj]->ref->attr->mods & TRICK_MODS_UNITSDASHDASH ) {
write_value = strlen("--") ;
write( fp , &write_value , sizeof(int)) ;
write( fp , "--" , write_value ) ;
} else {
write_value = strlen(rec_buffer[jj]->ref->attr->units) ;
write( fp , &write_value , sizeof(int)) ;
write( fp , rec_buffer[jj]->ref->attr->units , write_value ) ;
}
write_value = rec_buffer[jj]->ref->attr->type ;
write( fp , &write_value , sizeof(int)) ;

View File

@ -185,7 +185,11 @@ int Trick::DRHDF5::format_specific_init() {
buf = type_string(rec_buffer[ii]->ref->attr->type, rec_buffer[ii]->ref->attr->size );
H5PTappend( param_types_id, 1, buf.c_str() );
/* Param Units */
H5PTappend( param_units_id, 1, rec_buffer[ii]->ref->attr->units );
if ( rec_buffer[ii]->ref->attr->mods & TRICK_MODS_UNITSDASHDASH ) {
H5PTappend( param_units_id, 1, "--" );
} else {
H5PTappend( param_units_id, 1, rec_buffer[ii]->ref->attr->units );
}
/* Param Name */
H5PTappend( param_names_id, 1, rec_buffer[ii]->ref->reference );

View File

@ -484,8 +484,14 @@ int Trick::DataRecordGroup::write_header() {
out_stream << "log_" << group_name << "\t"
<< type_string(rec_buffer[jj]->ref->attr->type,
rec_buffer[jj]->ref->attr->size) << "\t"
<< std::setw(6)<<rec_buffer[jj]->ref->attr->units << "\t"
<< rec_buffer[jj]->ref->reference << std::endl ;
<< std::setw(6) ;
if ( rec_buffer[jj]->ref->attr->mods & TRICK_MODS_UNITSDASHDASH ) {
out_stream << "--" ;
} else {
out_stream << rec_buffer[jj]->ref->attr->units ;
}
out_stream << "\t" << rec_buffer[jj]->ref->reference << std::endl ;
}
// Send all unwritten characters in the buffer to its output/file.

View File

@ -72,7 +72,15 @@ void Trick::AttributesMap::print_xml(std::ofstream & sie_out ) {
std::replace(type_name.begin(), type_name.end(), ':', '_');
sie_out << std::endl << " type=\"" << type_remove_dims(type_name) << "\"" ;
sie_out << std::endl << " io_attributes=\"" << attr->io << "\"" ;
sie_out << std::endl << " units=\"" << attr->units << "\"" ;
sie_out << std::endl << " units=\"" ;
// If the mods bit is set for using -- as the units
if ( attr->mods & TRICK_MODS_UNITSDASHDASH ) {
sie_out << "--" ;
} else {
sie_out << attr->units ;
}
sie_out << "\"" ;
std::string description = attr->des;
if ( ! description.empty() ) {
sie_out << std::endl << " description=\"" << replace_special_chars(description) << "\"" ;

View File

@ -28,6 +28,7 @@ static std::map< std::string, std::string> init_map_old_to_ud() {
init_map["gal"] = "gallon" ;
init_map["one"] = "1" ;
init_map["cnt"] = "count" ;
init_map["--"] = "1" ;
return init_map ;
}

View File

@ -116,6 +116,9 @@ int Trick::VariableServerThread::var_units(std::string var_name, std::string uni
if (!units_name.compare("xx")) {
vars[ii]->ref->units = strdup(vars[ii]->ref->attr->units);
}
else if (!units_name.compare("--")) {
vars[ii]->ref->units = strdup("1");
}
else {
std::string new_units = map_trick_units_to_udunits(units_name) ;
if ( units_name.compare(new_units) ) {

View File

@ -178,7 +178,11 @@ int vs_format_ascii(Trick::VariableReference * var, char *value) {
} //end while
if (ref->units) {
sprintf(value, "%s {%s}", value, ref->units);
if ( ref->attr->mods & TRICK_MODS_UNITSDASHDASH ) {
sprintf(value, "%s {--}", value);
} else {
sprintf(value, "%s {%s}", value, ref->units);
}
}
return (0);