[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.7 Displaying Numeric Values

To display numeric values on the screen, or convert them to strings, it is often convenient to use the standard printf, fprintf, or sprintf functions. Each of these functions requires you to specify the data type as part of the “format” string (for example, to display an int, you might write printf("%d", x), but to display a long int, you might write printf("%ld", x)).

The macros listed below can be used to display WFDB_Sample, WFDB_Time, WFDB_Frequency, and WFDB_Gain values, regardless of which standard C data types these represent. Using these macros can help to ensure your program is portable to other operating systems and C compilers.

Each macro expands to a string constant (such as "d" or "ld"), which does not include the leading ‘%’ character. For example, to display a table of time and sample values, we might write:

 
WFDB_Time t = 0;
WFDB_Sample v[2];
while (getvec(v) > 0) {
    printf("%10"WFDB_Pd_TIME" %6"WFDB_Pd_SAMP" %6"WFDB_Pd_SAMP"\n",
           t, v[0], v[1]);
    t++;
}

The following macros are defined in ‘<wfdb/wfdb.h>’:

MacroArgument typeFormatExample output
WFDB_Pd_SAMPWFDB_SampleBase 10‘995’
WFDB_Pi_SAMPWFDB_SampleBase 10‘995’
WFDB_Po_SAMPWFDB_SampleUnsigned base 8‘1743’
WFDB_Pu_SAMPWFDB_SampleUnsigned base 10‘995’
WFDB_Px_SAMPWFDB_SampleUnsigned base 16‘3e3’
WFDB_PX_SAMPWFDB_SampleUnsigned base 16‘3E3’
WFDB_Pd_TIMEWFDB_TimeBase 10‘650000’
WFDB_Pi_TIMEWFDB_TimeBase 10‘650000’
WFDB_Po_TIMEWFDB_TimeUnsigned base 8‘2365420’
WFDB_Pu_TIMEWFDB_TimeUnsigned base 10‘650000’
WFDB_Px_TIMEWFDB_TimeUnsigned base 16‘9eb10’
WFDB_PX_TIMEWFDB_TimeUnsigned base 16‘9EB10’
WFDB_Pe_FREQWFDB_FrequencyExponential‘3.600000e+02’
WFDB_PE_FREQWFDB_FrequencyExponential‘3.600000E+02’
WFDB_Pf_FREQWFDB_FrequencyFixed-point‘360.000000’
WFDB_Pg_FREQWFDB_FrequencyAutomatic‘360’
WFDB_PG_FREQWFDB_FrequencyAutomatic‘360’
WFDB_Pe_GAINWFDB_GainExponential‘2.000000e+02’
WFDB_PE_GAINWFDB_GainExponential‘2.000000E+02’
WFDB_Pf_GAINWFDB_GainFixed-point‘200.000000’
WFDB_Pg_GAINWFDB_GainAutomatic‘200’
WFDB_PG_GAINWFDB_GainAutomatic‘200’

(The ‘d’ and ‘i’ formats are equivalent, and are provided for symmetry with scanf. For more information, see the documentation of your C compiler.)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

PhysioNet (wfdb@physionet.org)