48char *option[N_OPTIONS] =
54 "sdds2agilentArb [<inputFile>] [<outputFile>] [-pipe[=in][,out]]\n\n"
55 "Converts SDDS to Agilent Arbitrary Waveform files.\n"
56 "Program by Robert Soliday. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
58int main(
int argc,
char *argv[]) {
61 unsigned long pipe_flags = 0;
62 char *input = NULL, *output = NULL;
73 short *waveform = NULL;
78 argc =
scanargs(&scanned, argc, argv);
80 fprintf(stderr,
"%s", usage);
83 for (i_arg = 1; i_arg < argc; i_arg++) {
84 if (scanned[i_arg].arg_type == OPTION) {
85 switch (
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
88 scanned[i_arg].n_items - 1, &pipe_flags)) {
89 fprintf(stderr,
"invalid -pipe syntax\n");
94 fprintf(stderr,
"invalid option seen\n");
95 fprintf(stderr,
"%s", usage);
100 input = scanned[i_arg].list[0];
102 output = scanned[i_arg].list[0];
104 fprintf(stderr,
"too many filenames\n");
105 fprintf(stderr,
"%s", usage);
116 NULL)) != SDDS_CHECK_OKAY) {
117 fprintf(stderr,
"error: Floating type column named I does not exist\n");
121 NULL)) != SDDS_CHECK_OKAY) {
122 fprintf(stderr,
"error: Floating type column named Q does not exist\n");
126 if (SDDS_ReadTable(&sdds_dataset) != 1) {
127 fprintf(stderr,
"error: No data found in SDDS file\n");
130 points = SDDS_RowCount(&sdds_dataset);
141 for (i = 0; i < points; i++) {
142 if (max_amp < i_wave[i])
144 else if (min_amp > i_wave[i])
146 if (max_amp < q_wave[i])
148 else if (min_amp > q_wave[i])
151 max_amp = fabs(max_amp);
152 min_amp = fabs(min_amp);
153 if (min_amp > max_amp)
156 scale = 32767 / max_amp;
157 waveform = malloc(
sizeof(
short) * points * 2);
158 for (i = 0; i < points; i++) {
159 waveform[2 * i] = (short)floor(i_wave[i] * scale + 0.5);
160 waveform[2 * i + 1] = (short)floor(q_wave[i] * scale + 0.5);
166 p_char = (
char *)&waveform[0];
167 for (i = 0; i < 2 * points; i++) {
169 *p_char = *(p_char + 1);
177 if (_setmode(_fileno(stdout), _O_BINARY) == -1) {
178 fprintf(stderr,
"error: unable to set stdout to binary mode\n");
184 fd = fopen(output,
"wb");
187 fprintf(stderr,
"unable to open output file for writing\n");
190 fwrite((
void *)waveform,
sizeof(
short), points * 2, fd);
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_CheckColumn(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a column exists in the SDDS dataset with the specified name, units, and type.
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_ANY_FLOATING_TYPE
Special identifier used by SDDS_Check*() routines to accept any floating-point type.
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)