/* * Copyright (c) 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include bool adtobx(ostream &os, const OBXseg &obx) { if(!obx.ObsValue.ispresent() || obx.ObsValue.isnull()) { LOGWARNING("OBX segment not present"); return FALSE; } if(obx.ValueType != DataTypeCode::NMval) { LOGWARNING("OBX data %s is not NM", (const char *)obx.ValueType); return FALSE; } LabEventInfo lei; if(! lei.lookup(obx.ObsIde.Ide)) { LOGWARNING("unknown observation id: %s", (const char *)obx.ObsIde.Ide); return FALSE; } if(*lei.getLabEventClass() != 0) { LOGWARNING("ignoring observation %s (is a lab event)", (const char *)obx.ObsIde.Ide); return FALSE; // we don't handle lab values here } NMtyp val(obx.ObsValue); double rval; Unit unit1(obx.Units.Ide); Unit unit2(lei.getUnit()); if(unit1 == unit2) rval = (double)val; else if(dim(unit1) == dim(unit2)) rval = convert((double)val, unit1, unit2); else if(lei.getConstVal() != 0) { Unit const_unit(lei.getConstUnit()); Unit new_unit = unit1 * const_unit; if(dim(new_unit) == dim(unit2)) rval = convert((double)val * lei.getConstVal(), new_unit, unit2); } else { LOGWARNING("cannot convert unit %s into unit %s", (const char *)unit1, (const char *)unit2); return FALSE; } // range checking if(lei.getMinValue() != lei.getMaxValue()) if(rval < lei.getMinValue() || rval > lei.getMaxValue()) { LOGWARNING("measurement %g %s out of range [%g--%g]", (double)rval, (const char *)unit1, lei.getMinValue(), lei.getMaxValue()); return FALSE; } NMtyp vval(rval, val.getPrecision()); os << " -" << lei.getMsmt() << " " << vval; return TRUE; }