32#include "match_string.h"
34#define SET_DEFINITION 0
36#define SET_MAJOR_ORDER 2
39char *option[N_OPTIONS] = {
45char *USAGE =
"lba2sdds [<inputfile>] [<outputfile>]\n\
46 [-pipe[=input][,output]]\n\
47 -definition=<name>,<definition-entries> [-majorOrder=row|column] \n\n\
48lba2sdds converts a Spiricon LBA file to SDDS format. The definition entries\
49are of the form <keyword>=<value>, where the keyword is any valid field name for\
51Program by Michael Borland (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
53char *process_column_definition(
char **argv,
long argc);
55int main(
int argc,
char **argv) {
59 char *input, *output, *definition;
61 char *data, *data_name;
63 char ts1[100], ts2[100];
65 unsigned long pipeFlags, majorOrderFlag;
66 short columnMajorOrder = 0;
70 argc =
scanargs(&scanned, argc, argv);
74 input = output = data_name = NULL;
78 for (i_arg = 1; i_arg < argc; i_arg++) {
79 if (scanned[i_arg].arg_type == OPTION) {
81 switch (
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
84 scanned[i_arg].n_items--;
85 if (scanned[i_arg].n_items > 0 && (!
scanItemList(&majorOrderFlag, scanned[i_arg].list + 1, &scanned[i_arg].n_items, 0,
"row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
"column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
86 SDDS_Bomb(
"invalid -majorOrder syntax/values");
87 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
89 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
93 data_name = scanned[i_arg].list[1];
94 definition = process_column_definition(scanned[i_arg].list + 1, scanned[i_arg].n_items - 1);
95 if (!strstr(definition,
"type=character"))
96 SDDS_Bomb(
"data type must be character for now");
99 if (!
processPipeOption(scanned[i_arg].list + 1, scanned[i_arg].n_items - 1, &pipeFlags))
103 bomb(
"invalid option seen", USAGE);
108 input = scanned[i_arg].list[0];
110 output = scanned[i_arg].list[0];
112 bomb(
"too many filenames", USAGE);
126 if (fread(header,
sizeof(*header), 200, fpi) != 200)
127 SDDS_Bomb(
"unable to read LBA file header");
141 SDDS_Bomb(
"data does not appear to be in LBA format--invalid frame type");
145 sprintf(ts1,
"%ld", hsize);
146 sprintf(ts2,
"%ld", vsize);
148 "screen image from LBA file",
"screen image",
150 SDDS_ProcessColumnString(&SDDS_dataset, definition, 0) < 0 ||
SDDS_DefineParameter(&SDDS_dataset,
"NumberOfRows", NULL, NULL,
"number of rows", NULL,
SDDS_LONG, ts1) < 0 ||
SDDS_DefineParameter(&SDDS_dataset,
"NumberOfColumns", NULL, NULL,
"number of columns", NULL,
SDDS_LONG, ts2) < 0)
152 SDDS_dataset.layout.data_mode.column_major = columnMajorOrder;
156 data =
tmalloc(
sizeof(*data) * hsize * vsize);
158 if (fread(data,
sizeof(*data), hsize * vsize, fpi) != hsize * vsize)
159 SDDS_Bomb(
"unable to read (all) data from input file");
162 }
while (fread(header,
sizeof(*header), 200, fpi) == 200);
169char *process_column_definition(
char **argv,
long argc) {
170 char buffer[SDDS_MAXLINE], *ptr;
175 sprintf(buffer,
"&column name=%s, ", argv[0]);
176 for (i = 1; i < argc; i++) {
177 if (!strchr(argv[i],
'='))
179 strcat(buffer, argv[i]);
180 strcat(buffer,
", ");
182 if (!strstr(buffer,
"type="))
183 strcat(buffer,
"type=character ");
184 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.