83 {
85 SCANNED_ARG *scanned;
86 long i_arg;
87 char *input, *output, *definition;
88 long hsize, vsize;
89 char *data, *data_name;
90 char header[200];
91 char ts1[100], ts2[100];
92 FILE *fpi;
93 unsigned long pipeFlags, majorOrderFlag;
94 short columnMajorOrder = 0;
95
97
98 argc =
scanargs(&scanned, argc, argv);
99 if (argc < 4) {
101 }
102
103 input = output = data_name = NULL;
104 definition = NULL;
105 pipeFlags = 0;
106 hsize = vsize = 0;
107
108 for (i_arg = 1; i_arg < argc; i_arg++) {
109 if (scanned[i_arg].arg_type == OPTION) {
110
111 switch (
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
112 case SET_MAJOR_ORDER:
113 majorOrderFlag = 0;
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");
120 }
121 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
122 columnMajorOrder = 1;
123 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
124 columnMajorOrder = 0;
125 break;
126
127 case SET_DEFINITION:
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");
132 break;
133
134 case SET_PIPE:
135 if (!
processPipeOption(scanned[i_arg].list + 1, scanned[i_arg].n_items - 1, &pipeFlags))
137 break;
138
139 default:
140 bomb(
"Invalid option seen", USAGE);
141 break;
142 }
143 } else {
144 if (!input)
145 input = scanned[i_arg].list[0];
146 else if (!output)
147 output = scanned[i_arg].list[0];
148 else
149 bomb(
"Too many filenames provided", USAGE);
150 }
151 }
152
154
155 if (!definition)
157
158 if (input)
160 else
161 fpi = stdin;
162
163 if (fread(header, sizeof(*header), 200, fpi) != 200)
164 SDDS_Bomb(
"Unable to read LBA file header");
165
166 switch (header[0]) {
167 case 'A':
168 hsize = vsize = 120;
169 break;
170 case 'B':
171 vsize = 256;
172 hsize = 240;
173 break;
174 case 'C':
175 vsize = 512;
176 hsize = 480;
177 break;
178 default:
179 SDDS_Bomb(
"Data does not appear to be in LBA format--invalid frame type");
180 break;
181 }
182
183 sprintf(ts1, "%ld", hsize);
184 sprintf(ts2, "%ld", vsize);
185
187 "Screen image from LBA file", "Screen Image",
188 output) ||
193 }
194
195 SDDS_dataset.layout.data_mode.column_major = columnMajorOrder;
196
199
200 data =
tmalloc(
sizeof(*data) * hsize * vsize);
201
202 do {
203 if (fread(data, sizeof(*data), hsize * vsize, fpi) != hsize * vsize)
204 SDDS_Bomb(
"Unable to read all data from input file");
205
207 !
SDDS_SetColumn(&SDDS_dataset, SDDS_SET_BY_NAME, data, hsize * vsize, data_name) ||
210 }
211 } while (fread(header, sizeof(*header), 200, fpi) == 200);
212
213 fclose(fpi);
214
217
218 return EXIT_SUCCESS;
219}
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.
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.