102 {
103 int i_arg;
104 char **input_column;
105 char *input, *output;
106 long read_code, after_zero, after_zero_buffer_width;
107 int64_t i, rows;
108 int32_t columns;
109 unsigned long pipe_flags, major_order_flag;
110 SCANNED_ARG *scanned;
112 double *data, *indep_data;
113 double fractional_limit, absolute_limit, fwhm_limit;
114 short *in_tail;
115 short column_major_order = -1;
116
118 argc =
scanargs(&scanned, argc, argv);
119 if (argc < 2)
121
122 output = input = NULL;
123 input_column = NULL;
124 columns = 0;
125 pipe_flags = 0;
126 fractional_limit = fwhm_limit = 0;
127 absolute_limit = -1;
128 after_zero = 0;
129
130 for (i_arg = 1; i_arg < argc; i_arg++) {
131 if (scanned[i_arg].arg_type == OPTION) {
132
133 switch (
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
134 case CLO_MAJOR_ORDER:
135 major_order_flag = 0;
136 scanned[i_arg].n_items--;
137 if (scanned[i_arg].n_items > 0 &&
138 (!
scanItemList(&major_order_flag, scanned[i_arg].list + 1, &scanned[i_arg].n_items, 0,
139 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
140 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
141 SDDS_Bomb(
"invalid -majorOrder syntax/values");
142 if (major_order_flag & SDDS_COLUMN_MAJOR_ORDER)
143 column_major_order = 1;
144 else if (major_order_flag & SDDS_ROW_MAJOR_ORDER)
145 column_major_order = 0;
146 break;
147 case CLO_COLUMNS:
148 if (scanned[i_arg].n_items < 2)
150 input_column =
tmalloc(
sizeof(*input_column) * (columns = scanned[i_arg].n_items - 1));
151 for (i = 0; i < columns; i++)
152 input_column[i] = scanned[i_arg].list[i + 1];
153 break;
154 case CLO_PIPE:
155 if (!
processPipeOption(scanned[i_arg].list + 1, scanned[i_arg].n_items - 1, &pipe_flags))
157 break;
158 case CLO_FRACTIONAL:
159 if (scanned[i_arg].n_items < 2 || sscanf(scanned[i_arg].list[1], "%lf", &fractional_limit) != 1 || fractional_limit < 0)
161 break;
162 case CLO_ABSOLUTE:
163 if (scanned[i_arg].n_items < 2 || sscanf(scanned[i_arg].list[1], "%lf", &absolute_limit) != 1 || absolute_limit < 0)
165 break;
166 case CLO_FWHM:
167 if (scanned[i_arg].n_items < 2 || sscanf(scanned[i_arg].list[1], "%lf", &fwhm_limit) != 1 || fwhm_limit < 0)
169 break;
170 case CLO_AFTERZERO:
171 after_zero = 1;
172 if (scanned[i_arg].n_items > 2 ||
173 (scanned[i_arg].n_items == 2 &&
174 (sscanf(scanned[i_arg].list[1], "%ld", &after_zero_buffer_width) != 1 ||
175 after_zero_buffer_width <= 0)))
177 break;
178 default:
179 fprintf(stderr, "error: unknown/ambiguous option: %s\n", scanned[i_arg].list[0]);
180 exit(1);
181 break;
182 }
183 } else {
184 if (!input)
185 input = scanned[i_arg].list[0];
186 else if (!output)
187 output = scanned[i_arg].list[0];
188 else
190 }
191 }
192
194
195 if (!columns)
196 SDDS_Bomb(
"supply the names of columns to process with the -columns option");
197
200
201 if (!resolve_column_names(&sdds_in, &input_column, &columns))
203 if (!columns)
204 SDDS_Bomb(
"no columns selected for processing");
205
208 if (column_major_order != -1)
209 sdds_out.layout.data_mode.column_major = column_major_order;
210 else
211 sdds_out.layout.data_mode.column_major = sdds_in.layout.data_mode.column_major;
212
215
218
219 indep_data = NULL;
220 in_tail = NULL;
225 if (fwhm_limit > 0) {
226 indep_data =
SDDS_Realloc(indep_data,
sizeof(*indep_data) * rows);
227 if (!indep_data)
229 for (i = 0; i < rows; i++)
230 indep_data[i] = i;
231 }
232 in_tail =
SDDS_Realloc(in_tail,
sizeof(*in_tail) * rows);
233 if (!in_tail)
235 for (i = 0; i < rows; i++)
236 in_tail[i] = 0;
237 for (i = 0; i < columns; i++) {
239 if (!data)
241 clip_tail(data, rows, absolute_limit, fractional_limit, in_tail);
242 if (fwhm_limit > 0)
243 clip_fwhm(data, rows, fwhm_limit, indep_data, in_tail);
244 if (after_zero)
245 clip_after_zero(data, rows, after_zero_buffer_width, in_tail);
248 free(data);
249 }
250 }
251 if (!
SDDS_SetColumn(&sdds_out, SDDS_SET_BY_NAME, in_tail, rows,
"InTail"))
255 }
258 return 1;
259 }
262 return 1;
263 }
264 if (indep_data)
265 free(indep_data);
266 if (in_tail)
267 free(in_tail);
268 return 0;
269}
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_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_SetColumn(SDDS_DATASET *SDDS_dataset, int32_t mode, void *data, int64_t rows,...)
Sets the values for one data column in the current data table of an SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_DefineColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length)
Defines a 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.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
#define SDDS_SHORT
Identifier for the signed short integer data type.
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
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)
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.