84 {
85 double *meas_data = NULL, input_voltage = 0.2, z0 = 50;
86 char *input = NULL, *output = NULL, *data_column = NULL, *input_vol_param = NULL;
87 long i_arg, k;
88 double *left = NULL, *right = NULL, *gamma = NULL, *zline = NULL;
89 double g_product, vr_temp, d_increase;
90
92 SCANNED_ARG *scanned = NULL;
93 unsigned long pipe_flags = 0, major_order_flag = 0;
94 int64_t i, rows;
95 short column_major_order = -1;
96
98
99 argc =
scanargs(&scanned, argc, argv);
100 if (argc == 1)
102
103 for (i_arg = 1; i_arg < argc; i_arg++) {
104 if (scanned[i_arg].arg_type == OPTION) {
105 switch (
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
106 case CLO_PIPE:
107 if (!
processPipeOption(scanned[i_arg].list + 1, scanned[i_arg].n_items - 1, &pipe_flags)) {
109 }
110 break;
111 case CLO_MAJOR_ORDER:
112 major_order_flag = 0;
113 scanned[i_arg].n_items--;
114 if (scanned[i_arg].n_items > 0 &&
115 (!
scanItemList(&major_order_flag, scanned[i_arg].list + 1, &scanned[i_arg].n_items, 0,
116 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
117 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL))) {
118 SDDS_Bomb(
"invalid -majorOrder syntax/values");
119 }
120 if (major_order_flag & SDDS_COLUMN_MAJOR_ORDER)
121 column_major_order = 1;
122 else if (major_order_flag & SDDS_ROW_MAJOR_ORDER)
123 column_major_order = 0;
124 break;
125 case CLO_INPUT_VOLTAGE:
126 if (scanned[i_arg].n_items != 2)
127 SDDS_Bomb(
"invalid -inputVoltage syntax");
128 if (scanned[i_arg].list[1][0] == '@') {
129 cp_str(&input_vol_param, scanned[i_arg].list[1] + 1);
130 } else {
131 if (!
get_double(&input_voltage, scanned[i_arg].list[1]))
132 SDDS_Bomb(
"invalid -threshold value given");
133 }
134 break;
135 case CLO_COLUMN:
136 if (scanned[i_arg].n_items != 2)
138 data_column = scanned[i_arg].list[1];
139 break;
140 case CLO_Z0:
141 if (scanned[i_arg].n_items != 2)
145 break;
146 default:
147 fprintf(stderr, "Unknown option %s provided\n", scanned[i_arg].list[0]);
148 exit(1);
149 break;
150 }
151 } else {
152 if (!input)
153 input = scanned[i_arg].list[0];
154 else if (!output)
155 output = scanned[i_arg].list[0];
156 else
158 }
159 }
160
162
165
168
169 if (column_major_order != -1)
170 sdds_out.layout.data_mode.column_major = column_major_order;
171 else
172 sdds_out.layout.data_mode.column_major = sdds_in.layout.data_mode.column_major;
173
176
179
182 continue;
185 if (input_vol_param) {
188 }
191
192 for (i = 0; i < rows; i++)
193 meas_data[i] /= input_voltage;
194
195 left = calloc(sizeof(*left), rows + 1);
196 right = calloc(sizeof(*right), rows + 1);
197 gamma = calloc(sizeof(*gamma), rows + 1);
198 zline = calloc(sizeof(*zline), rows + 1);
199 g_product = 1;
200
201 if (rows >= 1) {
202 gamma[1] = meas_data[0];
203 left[1] = 1;
204 g_product *= (1 - gamma[1] * gamma[1]);
205 }
206 if (rows >= 2) {
207 vr_temp = (1 - gamma[1]) * right[1] + gamma[1] * left[1];
208 gamma[2] = (meas_data[1] - vr_temp) / g_product;
209 left[2] = left[1] * (1 + gamma[1]);
210 right[1] = left[2] * gamma[2];
211 g_product *= (1 - gamma[2] * gamma[2]);
212 }
213 for (i = 3; i <= rows; i++) {
214 left[i] = left[i - 1] * (1 + gamma[i - 1]);
215 left[i - 1] = left[i - 2] * (1 + gamma[i - 2]) - right[i - 2] * gamma[i - 2];
216 for (k = i - 2; k > 2; k--) {
217 right[k] = gamma[k + 1] * left[k + 1] + (1 - gamma[k + 1] * right[k + 1]);
218 left[k] = (1 + gamma[k - 1]) * left[k - 1] - gamma[k - 1] * right[k - 1];
219 }
220 right[1] = left[2] * gamma[2] + right[2] * (1 - gamma[2]);
221 vr_temp = (1 - gamma[1]) * right[1] + gamma[1] * left[1];
222 gamma[i] = (meas_data[i - 1] - vr_temp) / g_product;
223 g_product *= (1 - gamma[i] * gamma[i]);
224 d_increase = left[i] * gamma[i];
225 right[i - 1] += d_increase;
226 for (k = i - 2; k > 1; k--) {
227 d_increase *= (1 - gamma[k + 1]);
228 right[k] += d_increase;
229 }
230 }
231 zline[0] = z0;
232 for (i = 1; i <= rows; i++) {
233 zline[i] = (1 + gamma[i]) / (1 - gamma[i]) * zline[i - 1];
234 }
238 }
239
240 free(left);
241 free(right);
242 free(gamma);
243 free(zline);
244 free(meas_data);
245 meas_data = NULL;
246 }
247
250 exit(1);
251 }
252
254 return 0;
255}
int32_t SDDS_InitializeCopy(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, char *filemode)
int32_t SDDS_CopyPage(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
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_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_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
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.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
#define SDDS_DOUBLE
Identifier for the double data type.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
char * cp_str(char **s, char *t)
Copies a string, allocating memory for storage.
int get_double(double *dptr, char *s)
Parses a double value from the given string.
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)
long scanItemList(unsigned long *flags, char **item, long *items, unsigned long mode,...)
Scans a list of items and assigns values based on provided keywords and types.