67char *option[N_OPTIONS] = {
77 "Usage: agilentArb2sdds [<inputFile>] [<outputFile>]\n"
78 " [-pipe[=in][,out]]\n"
79 " [-ascii | -binary]\n"
81 " [-float | -double]\n"
84 " -pipe[=in][,out] Enable pipe mode with optional input and output pipes.\n"
85 " -ascii Request SDDS ASCII output. Default is binary.\n"
86 " -binary Request SDDS BINARY output.\n"
87 " -withIndex Add an Index column to the output.\n"
88 " -float Output data in float format. Default is double.\n"
89 " -double Output data in double format.\n"
91 "Converts Agilent Arbitrary Waveform files to SDDS.\n"
92 "Program by Robert Soliday. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
94#define MAX_NUM_POINTS 100001
96int main(
int argc,
char *argv[]) {
99 int ascii = 0, withIndex = 0, floatValues = 0;
100 unsigned long pipeFlags = 0;
101 char *input = NULL, *output = NULL;
106 short waveform[2 * MAX_NUM_POINTS];
112 int32_t *index = NULL;
115 argc =
scanargs(&scanned, argc, argv);
117 fprintf(stderr,
"%s", USAGE);
121 for (iArg = 1; iArg < argc; iArg++) {
122 if (scanned[iArg].arg_type == OPTION) {
123 switch (
match_string(scanned[iArg].list[0], option, N_OPTIONS, 0)) {
140 if (!
processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags)) {
141 fprintf(stderr,
"Error: Invalid -pipe syntax.\n");
142 fprintf(stderr,
"%s", USAGE);
147 fprintf(stderr,
"Error: Invalid option '%s'.\n", scanned[iArg].list[0]);
148 fprintf(stderr,
"%s", USAGE);
153 input = scanned[iArg].list[0];
155 output = scanned[iArg].list[0];
157 fprintf(stderr,
"Error: Too many filenames provided.\n");
158 fprintf(stderr,
"%s", USAGE);
168 fprintf(stderr,
"Error: Input file '%s' not found.\n", input);
171 if (!(fd = fopen(input,
"rb"))) {
172 fprintf(stderr,
"Error: Unable to open input file '%s'.\n", input);
177 if (_setmode(_fileno(stdin), _O_BINARY) == -1) {
178 fprintf(stderr,
"Error: Unable to set stdin to binary mode.\n");
185 points = fread((
void *)waveform,
sizeof(
short), MAX_NUM_POINTS * 2, fd);
186 if (points == MAX_NUM_POINTS * 2) {
187 fprintf(stderr,
"Error: Number of points in the waveform exceeds the maximum (%d).\n", MAX_NUM_POINTS);
193 pChar = (
char *)&waveform[0];
194 for (i = 0; i < points; i++) {
196 *pChar = *(pChar + 1);
203 IwaveIn = malloc(
sizeof(
double) * points);
204 QwaveIn = malloc(
sizeof(
double) * points);
205 if (!IwaveIn || !QwaveIn) {
206 fprintf(stderr,
"Error: Memory allocation failed for waveform data.\n");
210 for (i = 0; i < points; i++) {
211 IwaveIn[i] = waveform[2 * i] / 32767.0;
212 QwaveIn[i] = waveform[2 * i + 1] / 32767.0;
216 index = malloc(
sizeof(int32_t) * points);
218 fprintf(stderr,
"Error: Memory allocation failed for index data.\n");
221 for (i = 0; i < points; i++) {
253 if (!SDDS_StartTable(&SDDSout, points)) {
275 if (!SDDS_WriteTable(&SDDSout)) {
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_SetColumnFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, double *data, int64_t rows,...)
Sets the values for a single data column using double-precision floating-point numbers.
int32_t SDDS_SetColumnFromLongs(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t *data, int64_t rows,...)
Sets the values for a single data column using long integer numbers.
int32_t SDDS_InitializeOutput(SDDS_DATASET *SDDS_dataset, int32_t data_mode, int32_t lines_per_row, const char *description, const char *contents, const char *filename)
Initializes the SDDS output dataset.
int32_t SDDS_DefineSimpleColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data column within the SDDS dataset.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
int32_t SDDS_IsBigEndianMachine()
Determines whether the current machine uses big-endian byte ordering.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
long fexists(const char *filename)
Checks if a file exists.
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
long processPipeOption(char **item, long items, unsigned long *flags)
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
void free_scanargs(SCANNED_ARG **scanned, int argc)