12#define SET_WITHINDEX 3
17char *option[N_OPTIONS] = {
18 "ascii",
"binary",
"pipe",
"withindex",
"float",
"double"};
20char *USAGE =
"agilentArb2sdds [<inputFile>] [<outputFile>] [-pipe[=in][,out]]\n\
25pipe SDDS toolkit pipe option.\n\
26ascii Requests SDDS ASCII output. Default is binary.\n\
27binary Requests SDDS BINARY output.\n\
28withIndex Add Index column.\n\
29float Output in float format. Default is double.\n\
30double Output in double format.\n\n\
31Converts Agilent Arbitrary Waveform files to SDDS.\n\
32Program by Robert Soliday. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
34#define MAX_NUM_POINTS 100001
35int main(
int argc,
char *argv[]) {
38 int ascii = 0, withIndex = 0, floatValues = 0;
39 unsigned long pipeFlags = 0;
40 char *input = NULL, *output = NULL;
45 short waveform[2 * MAX_NUM_POINTS];
51 int32_t *index = NULL;
54 argc =
scanargs(&scanned, argc, argv);
56 fprintf(stderr,
"%s", USAGE);
59 for (iArg = 1; iArg < argc; iArg++) {
60 if (scanned[iArg].arg_type == OPTION) {
61 switch (
match_string(scanned[iArg].list[0], option, N_OPTIONS, 0)) {
78 if (!
processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags)) {
79 fprintf(stderr,
"invalid -pipe syntax\n");
84 fprintf(stderr,
"invalid option seen\n");
85 fprintf(stderr,
"%s", USAGE);
90 input = scanned[iArg].list[0];
92 output = scanned[iArg].list[0];
94 fprintf(stderr,
"too many filenames\n");
95 fprintf(stderr,
"%s", USAGE);
104 fprintf(stderr,
"input file not found\n");
107 if (!(fd = fopen(input,
"rb"))) {
108 fprintf(stderr,
"problem opening input file\n");
113 if (_setmode(_fileno(stdin), _O_BINARY) == -1) {
114 fprintf(stderr,
"error: unable to set stdin to binary mode\n");
121 points = fread((
void *)waveform,
sizeof(
short), MAX_NUM_POINTS * 2, fd);
122 if (points == MAX_NUM_POINTS * 2) {
123 fprintf(stderr,
"error: number of points in the waveform exceeds the MAX_NUM_POINTS hardcoded in the program.\n");
129 pChar = (
char *)&waveform[0];
130 for (i = 0; i < points; i++) {
132 *pChar = *(pChar + 1);
139 IwaveIn = malloc(
sizeof(
double) * points);
140 QwaveIn = malloc(
sizeof(
double) * points);
141 for (i = 0; i < points; i++) {
142 IwaveIn[i] = waveform[2 * i] / 32767.0;
143 QwaveIn[i] = waveform[2 * i + 1] / 32767.0;
146 index = malloc(
sizeof(int32_t) * points);
147 for (i = 0; i < points; i++) {
173 if (!SDDS_StartTable(&SDDSout, points)) {
191 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)