** Allocates memory equal to the size of channel (2 * number of samples)
**
** BUGS
-** Need to abstract error checking so it is not so redundant
** Need command line options for verbose and debug output
** Should comment the reading and writing of files to document the file formats
**
-** $Id: wdq2wav.cpp,v 1.1 2003/01/21 01:58:32 kevin Exp $
+** $Id: wdq2wav.cpp,v 1.2 2003/01/21 03:03:49 kevin Exp $
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License (version 2) as
fprintf (stderr, "%s\n",msg);
}
+void
+info_msg (char* msg)
+{
+ fprintf (stdout, "%s\n", msg);
+}
+
void
usage ()
{
- fprintf (stderr, "usage: wdq2wav <wdq-file> <channel-number> <wav-file>\n");
+ error_msg ("usage: wdq2wav <wdq-file> <channel-number> <wav-file>");
}
bool wdq2wav (const char* wdq_fname, const int channel, const char *wav_fname);
char *wav_fname = argv[3];
if (*channel_endptr != 0) {
- fprintf (stderr, "Error: Channel %s is not an integer\n", argv[2]);
+ std::ostringstream os;
+ os << "Error: Channel " << argv[2] << " is not an integer";
+ error_str (os.str().c_str());
usage();
return(1);
}
return 0;
}
-bool wdq2wav (const char* wdq_fname, const int channel, const char *wav_fname)
+bool
+wdq2wav (const char* wdq_fname, const int channel, const char *wav_fname)
{
WindaqFile wdq (wdq_fname);
if (! wdq.ReadHeader()) {
- fprintf (stderr, "Error reading header %s\n", wdq_fname);
return false;
}
if (g_verbose) {
- printf ("Number of channels: %d\n", wdq.m_nChannels);
- printf ("Number of Samples: %d\n", wdq.m_nSamples);
- printf ("Sample Rate: %.1f\n", wdq.m_sample_rate);
+ std::ostringstream os;
+ os << wdq_fname << ": Samples " << wdq.m_nSamples <<
+ ", Channels " << wdq.m_nChannels <<
+ ", Sample Rate " << wdq.m_sample_rate;
+ info_msg (os.str().c_str());
}
WindaqChannel wdq_channel (wdq, channel);
}
if (g_verbose) {
- printf ("Data Min: %f, Data Max: %f\n",
- wdq_channel.m_min_raw_data, wdq_channel.m_max_raw_data);
+ std::ostringstream os1;
+ os1 << "Channel units: " << wdq_channel.m_units.c_str();
+ info_msg (os1.str().c_str());
+ std::ostringstream os2;
+ os2 << "Raw data: minimum " << wdq_channel.m_min_raw_data <<
+ ", maximum " << wdq_channel.m_max_raw_data;
+ info_msg (os2.str().c_str());
+ std::ostringstream os3;
+ os3 << "Slope " << wdq_channel.m_slope <<
+ ", Intercept " << wdq_channel.m_intercept;
+ info_msg (os3.str().c_str());
}
WavFile wav (wdq_channel, wav_fname);
return false;
}
if (tmp2 != 0x8001) {
- fprintf (stderr, "%s is not a WinDAQ file\n", m_strFile.c_str());
+ std::ostringstream os;
+ os << m_strFile << " is not a WinDAQ file";
+ error_msg (os.str().c_str());
return false;
}
if (channel >= 1 && channel <= wdq.m_nChannels) {
m_valid = true;
read_channel_data();
- } else
- fprintf (stderr, "Channel %d is invalid, valid range 1-%d\n",
- channel, wdq.m_nChannels);
+ } else {
+ std::ostringstream os;
+ os << "Channel " << channel << " is invalid, valid range 1-" <<
+ wdq.m_nChannels;
+ error_msg (os.str().c_str());
+ }
}
}
}
m_intercept = float8;
- if (g_verbose)
- printf ("Slope: %f, Intercept: %f\n", m_slope, m_intercept);
-
char units[7];
units[6] = 0;
if (read (fd, units, 6) != 6) {
return false;
}
m_units = units;
- if (g_verbose)
- printf ("Units: %s\n", units);
unsigned int row_bytes = 2 * r_wdq.m_nChannels;
signed short int sample_row [row_bytes];
signed short int data_max, data_min;
for (i = 0; i < r_wdq.m_nSamples; i++) {
if (read (fd, sample_row, row_bytes) != row_bytes) {
- fprintf (stderr, "Error reading file at %d\n", i);
+ std::ostringstream os;
+ os << "Error reading file at " << i;
+ error_msg (os.str().c_str());
return false;
}
if (m_fd == 0)
if ((m_fd = open (m_strFile.c_str(), O_WRONLY | O_TRUNC | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == 0) {
- fprintf (stderr, "Error opening output file %s\n", m_strFile.c_str());
+ std::ostringstream os;
+ os << "Error opening output file ", << m_strFile.c_str();
+ error_msg (os);
return false;
}