59 {
60 char reserved[100];
61 short f_type;
62 char trigger;
63 char dwell_flag;
64 char dwell_units;
65 char acq_mode;
66 unsigned long dwell_913;
67 unsigned short pass_length;
68 unsigned long pass_count;
69 unsigned long pass_count_preset;
70 char acq_time[9];
71 char acq_date[9];
72 unsigned short mark_chan;
73 char mcs_num;
74 char cal_flag;
75 char cal_units[4];
76 float cal_zero;
77 float cal_slope;
78 char id_byte;
79 char detector_len;
80 char detector[65];
81 char sample_len;
82 char sample[65];
83 char disc_sel;
84 char disc_edge;
85 float disc;
86 float sca_uld;
87 float sca_lld;
88 float dwell;
89 char consistent;
90 char mcs_id[9];
91
92 FILE *fpi;
93 char *input, *output;
95 SCANNED_ARG *scanned;
96 long i, i_arg;
97 char ts1[256], ts2[256], ts3[256], ts4[256];
98 unsigned long *ucount;
99 long *count, *channel;
100 long ascii;
101
103 argc =
scanargs(&scanned, argc, argv);
104 if (argc < 3) {
105 fprintf(stderr, "Error: Insufficient arguments.\n");
106 fprintf(stderr, "%s", USAGE);
107 exit(EXIT_FAILURE);
108 }
109
110 input = output = NULL;
111 ascii = 0;
112 for (i_arg = 1; i_arg < argc; i_arg++) {
113 if (scanned[i_arg].arg_type == OPTION) {
114 switch (
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
115 case SET_ASCII:
116 ascii = 1;
117 break;
118 default:
119 fprintf(stderr, "Error: Invalid option '%s'.\n", scanned[i_arg].list[0]);
120 fprintf(stderr, "%s", USAGE);
121 exit(EXIT_FAILURE);
122 }
123 } else {
124 if (!input)
125 input = scanned[i_arg].list[0];
126 else if (!output)
127 output = scanned[i_arg].list[0];
128 else {
129 fprintf(stderr, "Error: Too many filenames provided.\n");
130 fprintf(stderr, "%s", USAGE);
131 exit(EXIT_FAILURE);
132 }
133 }
134 }
135
136 if (!input) {
137 SDDS_Bomb(
"Error: Input file not specified.");
138 }
139 if (!output) {
140 SDDS_Bomb(
"Error: Output file not specified.");
141 }
142
144
145
146
147
148
149
150 if (fread(&f_type, sizeof(short), 1, fpi) != 1) {
151 SDDS_Bomb(
"Error: Unable to read file type.");
152 }
153 swapshort(&f_type);
154 if (f_type != MCS) {
155 fprintf(stderr, "Error: Not a valid MCS file. f_type = %hx\n", f_type);
156 fclose(fpi);
157 exit(EXIT_FAILURE);
158 }
159
160 fread(&trigger, sizeof(char), 1, fpi);
161 fread(&dwell_flag, sizeof(char), 1, fpi);
162 fread(&dwell_units, sizeof(char), 1, fpi);
163 fread(&acq_mode, sizeof(char), 1, fpi);
164 fread(&dwell_913, sizeof(long), 1, fpi);
165 swapulong(&dwell_913);
166 fread(&pass_length, sizeof(short), 1, fpi);
167 swapushort(&pass_length);
168 fread(&pass_count, sizeof(long), 1, fpi);
169 swapulong(&pass_count);
170 fread(&pass_count_preset, sizeof(long), 1, fpi);
171 swapulong(&pass_count_preset);
172 fread(acq_time, sizeof(char), 8, fpi);
173 fread(acq_date, sizeof(char), 8, fpi);
174 fread(&mark_chan, sizeof(short), 1, fpi);
175 swapushort(&mark_chan);
176 fread(&mcs_num, sizeof(char), 1, fpi);
177 fread(&cal_flag, sizeof(char), 1, fpi);
178 fread(cal_units, sizeof(char), 4, fpi);
179 fread(&cal_zero, sizeof(float), 1, fpi);
180 swapfloat(&cal_zero);
181 fread(&cal_slope, sizeof(float), 1, fpi);
182 swapfloat(&cal_slope);
183 fread(reserved, sizeof(char), 10, fpi);
184 fread(&id_byte, sizeof(char), 1, fpi);
185 fread(reserved, sizeof(char), 1, fpi);
186 fread(&detector_len, sizeof(char), 1, fpi);
187 fread(detector, sizeof(char), 63, fpi);
188 fread(&sample_len, sizeof(char), 1, fpi);
189 fread(sample, sizeof(char), 63, fpi);
190 fread(reserved, sizeof(char), 16, fpi);
191 fread(&disc_sel, sizeof(char), 1, fpi);
192 fread(&disc_edge, sizeof(char), 1, fpi);
193 fread(&disc, sizeof(float), 1, fpi);
194 swapfloat(&disc);
195 fread(&sca_uld, sizeof(float), 1, fpi);
196 swapfloat(&sca_uld);
197 fread(&sca_lld, sizeof(float), 1, fpi);
198 swapfloat(&sca_lld);
199 fread(&dwell, sizeof(float), 1, fpi);
200 swapfloat(&dwell);
201 fread(&consistent, sizeof(char), 1, fpi);
202 fread(reserved, sizeof(char), 21, fpi);
203 fread(mcs_id, sizeof(char), 8, fpi);
204 mcs_id[8] = '\0';
205
206 sprintf(ts1, "%d", mcs_num + 1);
207 sprintf(ts2, "%hd", pass_length);
208 sprintf(ts3, "%ld", pass_count);
209 sprintf(ts4, "%ld", pass_count_preset);
210
211 if (!
SDDS_InitializeOutput(&SDDS_dataset, ascii ? SDDS_ASCII : SDDS_BINARY, 1,
"Turbo MCS data",
"Turbo MCS data", output) ||
218 }
219
220 if (dwell_flag == 0) {
221 if (dwell_units == 0)
222 dwell *= 1e-6;
223 else if (dwell_units == 1)
224 dwell *= 1e-3;
225 else if (dwell_units == 3)
226 dwell *= 1e-9;
227 } else {
228 dwell = -1;
229 }
230
231 sprintf(ts1, "%15.8e", dwell);
232 sprintf(ts2, "%8s %8s", acq_time, acq_date);
238 }
239
240 sprintf(ts1, "%15.8e", cal_slope);
241 sprintf(ts2, "%15.8e", cal_zero);
245 }
246
247 if (detector_len) {
248 detector[(unsigned)detector_len] = '\0';
251 }
252 }
253
254 if (sample_len) {
255 sample[(unsigned)sample_len] = '\0';
259 }
260 }
261
262 if (disc_sel == 0) {
263 sprintf(ts1, "%15.8e", sca_lld);
264 sprintf(ts2, "%15.8e", sca_uld);
268 }
269 } else {
270 sprintf(ts1, "%15.8e", disc);
274 }
275 }
276
277 if (consistent == 0) {
278 if (
SDDS_DefineParameter(&SDDS_dataset,
"Inconsistent", NULL, NULL,
"Flag indicating whether data and settings are inconsistent", NULL,
SDDS_LONG,
"1") < 0) {
280 }
281 fprintf(stderr, "WARNING: Settings are not consistent with data\n");
282 }
283
288 }
289
290
291
292
293
294 channel =
tmalloc(
sizeof(*channel) * pass_length);
295 count =
tmalloc(
sizeof(*count) * pass_length);
296 ucount =
tmalloc(
sizeof(*ucount) * pass_length);
297 if (fread(ucount, sizeof(*ucount), pass_length, fpi) != pass_length) {
298 SDDS_Bomb(
"Error: Unable to read channel data.");
299 }
300 for (i = 0; i < (long)pass_length; i++) {
301 swapulong(&ucount[i]);
302 count[i] = (long)ucount[i];
303 channel[i] = i;
304 }
305 if (!
SDDS_SetColumn(&SDDS_dataset, SDDS_SET_BY_NAME, channel, (
long)pass_length,
"ChannelNumber") ||
306 !
SDDS_SetColumn(&SDDS_dataset, SDDS_SET_BY_NAME, count, (
long)pass_length,
"EventCount") ||
309 }
310
311 fclose(fpi);
312 return EXIT_SUCCESS;
313}
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
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_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_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.
int32_t SDDS_DefineParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, char *fixed_value)
Defines a data parameter with a fixed string value.
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_STRING
Identifier for the string data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
FILE * fopen_e(char *file, char *open_mode, long mode)
Opens a file with error checking, messages, and aborts.
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)