Experimental Physics and
| |||||||||||||||
|
Here is an ad-hoc format converter for a "mantissa and exponent representation without e". In other words: Two signed decimal integers like in +01234-56 meaning 1234e-56 (or 1.234e-43) Eric and someone else I don't remember requested it. Put the converter file in the src directory, add FORMATS+=Exponential to CONFIG_STREAM and requild. The format is %m. (Any better suggestion?) Maximal field width does not work at the moment. Low level, it just reads %d%d. Output is not implemented because it is not clear how to do the formatting, Why +00011-01 and not +00110-02 or +11000-04 ? Was +00011-01 originally 1.1000000000000 or 1.11 or 1.10000000000001 ? What are the rules for rounding and precision? Dirk Dirk Zimoch wrote: Hi Eric,
/*************************************************************** * StreamDevice Support * * * * (C) 1999 Dirk Zimoch ([email protected]) * * (C) 2007 Dirk Zimoch ([email protected]) * * * * This is a custom exponential format converter for * * StreamDevice. * * The number is represented as two signed integers, mantissa * * and exponent, like in +00011-01 * * Please refer to the HTML files in ../doc/ for a detailed * * documentation. * * * * If you do any changes in this file, you are not allowed to * * redistribute it any more. If there is a bug or a missing * * feature, send me an email and/or your patch. If I accept * * your changes, they will go to the next release. * * * * DISCLAIMER: If this software breaks something or harms * * someone, it's your problem. * * * ***************************************************************/ #include "StreamFormatConverter.h" #include "StreamError.h" #include <math.h> // Exponential Converter %m: format +00351-02 means +351e-2 class ExponentialConverter : public StreamFormatConverter { virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); virtual int scanDouble(const StreamFormat&, const char*, double&); }; int ExponentialConverter:: parse(const StreamFormat& fmt, StreamBuffer& info, const char*& source, bool scanFormat) { if (!scanFormat) { error("At the moment for %%m format only input is implemented\n"); return false; } return double_format; } int ExponentialConverter:: scanDouble(const StreamFormat& fmt, const char* input, double& value) { int mantissa; int exponent; int length = -1; sscanf(input, "%d%d%n", &mantissa, &exponent, &length); if (fmt.flags & skip_flag) return length; if (length == -1) return -1; value = (double)(mantissa) * pow(10, exponent); return length; } RegisterConverter (ExponentialConverter, "m");
| ||||||||||||||
ANJ, 10 Nov 2011 |
·
Home
·
News
·
About
·
Base
·
Modules
·
Extensions
·
Distributions
·
Download
·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing · |