/** @return 0 on failure, 1 on success **/ int group_recorder::read_line(){ size_t index = 0, offset = 0, unit_len = 0; quickobjlist *curr = 0; char *swap_ptr = 0; char buffer[128]; char objname[128]; if(TS_OPEN != tape_status){ // could be ERROR or CLOSED return 0; } // pre-calculate buffer needs if(line_size <= 0 || line_buffer == 0){ size_t prop_size; // in v2.3, there's no measure of the property's string representation size. // this value *is* present in 3.0. prop_size = 48; line_size = (prop_size + 1) * obj_count + 1; line_buffer = (char *)malloc(line_size); if(0 == line_buffer){ return 0; } memset(line_buffer, 0, line_size); if(-1 == write_interval){ // 'on change', will need second buffer prev_line_buffer = (char *)malloc(line_size); if(0 == prev_line_buffer){ gl_error("group_recorder::read_line(): malloc failure"); /* TROUBLESHOOT Memory allocation failure. */ return 0; } memset(prev_line_buffer, 0, line_size); } } // if we need the previous buffer to compare against, swap the buffers if(-1 == write_interval){ swap_ptr = prev_line_buffer; prev_line_buffer = line_buffer; line_buffer = swap_ptr; } memset(line_buffer, 0, line_size); for(curr = obj_list; curr != 0; curr = curr->next){ // GETADDR is a macro defined in object.h if(curr->prop->ptype == PT_complex && complex_part != NONE){ double part_value = 0.0; complex *cptr = 0; // get value as a complex cptr = gl_get_complex(curr->obj, curr->prop); if(0 == cptr){ gl_error("group_recorder::read_line(): unable to get complex property '%s' from object '%s'", curr->prop->name, gl_name(curr->obj, objname, 127)); /* TROUBLESHOOT Could not read a complex property as a complex value. */ return 0; } // switch on part switch(complex_part){ case NONE: // didn't we test != NONE just a few lines ago? gl_error("group_recorder::read_line(): inconsistant complex_part states!"); return 0; case REAL: part_value = cptr->Re(); break; case IMAG: part_value = cptr->Im(); break; case MAG: part_value = cptr->Mag(); break; case ANG: part_value = cptr->Arg() * 180/PI; break; case ANG_RAD: part_value = cptr->Arg(); break; } sprintf(buffer, "%f", part_value); offset = strlen(buffer); } else { offset = gl_get_value(curr->obj, GETADDR(curr->obj, curr->prop), buffer, 127, prop_ptr); if(0 == offset){ gl_error("group_recorder::read_line(): unable to get value for '%s' in object '%s'", curr->prop->name, curr->obj->name); /* TROUBLESHOOT An error occured while reading the specified property in one of the objects. */ return 0; } } // check line_buffer space unit_len = ((print_units && 0 != curr->prop && 0 != curr->prop->unit) ? 1 + strlen(curr->prop->unit->name) : 0); if( unit_len + (index + offset + 1) > line_size ){ gl_error("group_recorder::read_line(): potential buffer overflow from a too-short automatically sized output value buffer"); /* TROUBLESHOOT A potential buffer overflow was caught, most likely due to incorrect property representation assumptions for buffer allocation. */ return 0; } // write to line_buffer // * lead with a comma on all entries, assume leading timestamp will NOT print a comma if(print_units && 0 != curr->prop && 0 != curr->prop->unit){ if(0 >= sprintf(line_buffer+index, ",%s %s", buffer, curr->prop->unit->name)){return 0;} } else { if(0 >= sprintf(line_buffer+index, ",%s", buffer)){return 0;} } index += (offset + 1) + unit_len; // add the comma } // assume write_line will add newline character return 1; }
int histogram::feed_bins(OBJECT *obj){ double value = 0.0; complex cval = 0.0; //gl_get_complex(obj, ; int64 ival = 0; int i = 0; switch(prop_ptr->ptype){ case PT_complex: cval = (prop_ptr ? *gl_get_complex(obj, prop_ptr) : *gl_get_complex_by_name(obj, property) ); switch(this->comp_part){ case REAL: value = cval.Re(); break; case IMAG: value = cval.Im(); break; case MAG: value = cval.Mag(); break; case ANG: value = cval.Arg(); break; default: gl_error("Complex property with no part defined in %s", (obj->name ? obj->name : "(unnamed)")); } ival = 1; /* fall through */ case PT_double: if(ival == 0) value = (prop_ptr ? *gl_get_double(obj, prop_ptr) : *gl_get_double_by_name(obj, property.get_string()) ); for(i = 0; i < bin_count; ++i){ if(value > bin_list[i].low_val && value < bin_list[i].high_val){ ++binctr[i]; } else if(bin_list[i].low_inc && bin_list[i].low_val == value){ ++binctr[i]; } else if(bin_list[i].high_inc && bin_list[i].high_val == value){ ++binctr[i]; } } break; case PT_int16: ival = (prop_ptr ? *gl_get_int16(obj, prop_ptr) : *gl_get_int16_by_name(obj, property.get_string()) ); value = 1.0; case PT_int32: if(value == 0.0){ ival = (prop_ptr ? *gl_get_int32(obj, prop_ptr) : *gl_get_int32_by_name(obj, property.get_string()) ); value = 1.0; } case PT_int64: if(value == 0.0){ ival = (prop_ptr ? *gl_get_int64(obj, prop_ptr) : *gl_get_int64_by_name(obj, property.get_string()) ); value = 1.0; } case PT_enumeration: if(value == 0.0){ ival = (prop_ptr ? *gl_get_enum(obj, prop_ptr) : *gl_get_enum_by_name(obj, property.get_string()) ); value = 1.0; } case PT_set: if(value == 0.0){ ival = (prop_ptr ? *gl_get_set(obj, prop_ptr) : *gl_get_set_by_name(obj, property.get_string()) ); value = 1.0; } /* may be prone to fractional errors */ for(i = 0; i < bin_count; ++i){ if(ival > bin_list[i].low_val && ival < bin_list[i].high_val){ ++binctr[i]; } else if(bin_list[i].low_inc && bin_list[i].low_val == ival){ ++binctr[i]; } else if(bin_list[i].high_inc && bin_list[i].high_val == ival){ ++binctr[i]; } } break; } return 0; }