[ < ] [ > ]   [ << ] [ 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 10995
WFDB_Pi_SAMPWFDB_SampleBase 10995
WFDB_Po_SAMPWFDB_SampleUnsigned base 81743
WFDB_Pu_SAMPWFDB_SampleUnsigned base 10995
WFDB_Px_SAMPWFDB_SampleUnsigned base 163e3
WFDB_PX_SAMPWFDB_SampleUnsigned base 163E3
WFDB_Pd_TIMEWFDB_TimeBase 10650000
WFDB_Pi_TIMEWFDB_TimeBase 10650000
WFDB_Po_TIMEWFDB_TimeUnsigned base 82365420
WFDB_Pu_TIMEWFDB_TimeUnsigned base 10650000
WFDB_Px_TIMEWFDB_TimeUnsigned base 169eb10
WFDB_PX_TIMEWFDB_TimeUnsigned base 169EB10
WFDB_Pe_FREQWFDB_FrequencyExponential3.600000e+02
WFDB_PE_FREQWFDB_FrequencyExponential3.600000E+02
WFDB_Pf_FREQWFDB_FrequencyFixed-point360.000000
WFDB_Pg_FREQWFDB_FrequencyAutomatic360
WFDB_PG_FREQWFDB_FrequencyAutomatic360
WFDB_Pe_GAINWFDB_GainExponential2.000000e+02
WFDB_PE_GAINWFDB_GainExponential2.000000E+02
WFDB_Pf_GAINWFDB_GainFixed-point200.000000
WFDB_Pg_GAINWFDB_GainAutomatic200
WFDB_PG_GAINWFDB_GainAutomatic200

(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)