50#include "match_string.h"
60char *option[N_OPTIONS] = {
68 "lba2sdds [<inputfile>] [<outputfile>]\n"
69 " [-pipe[=input][,output]]\n"
70 " -definition=<name>,<definition-entries>\n"
71 " [-majorOrder=row|column]\n\n"
73 " -pipe[=input][,output] Use pipe for input and/or output.\n"
74 " -definition=<name>,<entries> Define SDDS columns with name and entries.\n"
75 " -majorOrder=row|column Set data major order to row or column.\n\n"
77 " lba2sdds converts a Spiricon LBA file to SDDS format. The definition entries\n"
78 " are specified as <keyword>=<value>, where each keyword is a valid SDDS column field name.\n\n"
79 "Program by Michael Borland (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
81char *process_column_definition(
char **argv,
long argc);
83int main(
int argc,
char **argv) {
87 char *input, *output, *definition;
89 char *data, *data_name;
91 char ts1[100], ts2[100];
93 unsigned long pipeFlags, majorOrderFlag;
94 short columnMajorOrder = 0;
98 argc =
scanargs(&scanned, argc, argv);
103 input = output = data_name = NULL;
108 for (i_arg = 1; i_arg < argc; i_arg++) {
109 if (scanned[i_arg].arg_type == OPTION) {
111 switch (
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
112 case SET_MAJOR_ORDER:
114 scanned[i_arg].n_items--;
115 if (scanned[i_arg].n_items > 0 &&
116 (!
scanItemList(&majorOrderFlag, scanned[i_arg].list + 1, &scanned[i_arg].n_items, 0,
117 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
118 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL))) {
119 SDDS_Bomb(
"Invalid -majorOrder syntax or values");
121 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
122 columnMajorOrder = 1;
123 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
124 columnMajorOrder = 0;
128 data_name = scanned[i_arg].list[1];
129 definition = process_column_definition(scanned[i_arg].list + 1, scanned[i_arg].n_items - 1);
130 if (!strstr(definition,
"type=character"))
131 SDDS_Bomb(
"Data type must be character for now");
135 if (!
processPipeOption(scanned[i_arg].list + 1, scanned[i_arg].n_items - 1, &pipeFlags))
140 bomb(
"Invalid option seen", USAGE);
145 input = scanned[i_arg].list[0];
147 output = scanned[i_arg].list[0];
149 bomb(
"Too many filenames provided", USAGE);
163 if (fread(header,
sizeof(*header), 200, fpi) != 200)
164 SDDS_Bomb(
"Unable to read LBA file header");
179 SDDS_Bomb(
"Data does not appear to be in LBA format--invalid frame type");
183 sprintf(ts1,
"%ld", hsize);
184 sprintf(ts2,
"%ld", vsize);
187 "Screen image from LBA file",
"Screen Image",
195 SDDS_dataset.layout.data_mode.column_major = columnMajorOrder;
200 data =
tmalloc(
sizeof(*data) * hsize * vsize);
203 if (fread(data,
sizeof(*data), hsize * vsize, fpi) != hsize * vsize)
204 SDDS_Bomb(
"Unable to read all data from input file");
207 !
SDDS_SetColumn(&SDDS_dataset, SDDS_SET_BY_NAME, data, hsize * vsize, data_name) ||
211 }
while (fread(header,
sizeof(*header), 200, fpi) == 200);
221char *process_column_definition(
char **argv,
long argc) {
222 char buffer[SDDS_MAXLINE], *ptr;
228 sprintf(buffer,
"&column name=%s, ", argv[0]);
230 for (i = 1; i < argc; i++) {
231 if (!strchr(argv[i],
'=')) {
234 strcat(buffer, argv[i]);
235 strcat(buffer,
", ");
238 if (!strstr(buffer,
"type=")) {
239 strcat(buffer,
"type=character ");
242 strcat(buffer,
"&end");
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
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_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.
int32_t SDDS_ProcessColumnString(SDDS_DATASET *SDDS_dataset, char *string, int32_t mode)
Process a column definition string.
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_LONG
Identifier for the signed 32-bit 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.
char * cp_str(char **s, char *t)
Copies a string, allocating memory for storage.
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)
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.