26#define USAGE_MESSAGE "Usage: sdds3dconvert <inputFile> [<outputRoot>]\n" \
27 "Converts 3D Vorpal output data into SDDS format compatible with sddscontour.\n\n" \
29 " <inputFile> Path to the input SDDS file containing 3D Vorpal data.\n" \
30 " <outputRoot> (Optional) Root name for the output files. Defaults to <inputFile> name if not provided.\n\n" \
31 "Link date: " __DATE__ " " __TIME__ ", SVN revision: " SVN_VERSION "\n"
33static void setup_output_file(
SDDS_DATASET *sdds_out,
const char *output,
long yz,
long output_columns,
char **output_column);
34static void free_data_memory(
double ****data,
long output_columns,
long pages,
long ydim);
36int main(
int argc,
char **argv) {
38 int32_t i, j, k, row, str_len;
40 char *input_file, *output_root, output1[1024], output2[1024], tmp_col[256];
41 double xmin, xmax, ymin, ymax, zmin, zmax, x_interval, y_interval, z_interval;
42 int32_t x_dim, y_dim, z_dim, column_names, output_columns, page = 0;
43 char **column_name, **output_column;
46 input_file = output_root = NULL;
51 fprintf(stderr,
"%s", USAGE_MESSAGE);
55 column_names = output_columns = 0;
56 column_name = output_column = NULL;
57 input_file = s_arg[1].list[0];
58 output_root = (argc == 3) ? s_arg[2].list[0] : input_file;
60 snprintf(output1,
sizeof(output1),
"%s.yz", output_root);
61 snprintf(output2,
sizeof(output2),
"%s.xz", output_root);
70 for (i = 0; i < column_names; i++) {
72 output_column =
SDDS_Realloc(output_column, (output_columns + 1) *
sizeof(*output_column));
74 fprintf(stderr,
"Memory allocation failed for output_column.\n");
77 str_len = strlen(column_name[i]);
78 output_column[output_columns] = malloc(str_len - 1);
79 if (!output_column[output_columns]) {
80 fprintf(stderr,
"Memory allocation failed for output_column[%d].\n", output_columns);
83 strncpy(output_column[output_columns], column_name[i], str_len - 2);
84 output_column[output_columns][str_len - 2] =
'\0';
89 data = malloc(
sizeof(*data) * output_columns);
91 fprintf(stderr,
"Memory allocation failed for data.\n");
112 setup_output_file(&sdds_out1, output1, 1, output_columns, output_column);
113 setup_output_file(&sdds_out2, output2, 0, output_columns, output_column);
115 for (i = 0; i < output_columns; i++) {
116 data[i] = malloc(z_dim *
sizeof(**data));
118 fprintf(stderr,
"Memory allocation failed for data[%d].\n", i);
119 free_data_memory(data, output_columns, z_dim, y_dim);
122 for (j = 0; j < z_dim; j++) {
123 data[i][j] = malloc(y_dim *
sizeof(***data));
125 fprintf(stderr,
"Memory allocation failed for data[%d][%d].\n", i, j);
126 free_data_memory(data, output_columns, z_dim, y_dim);
133 for (i = 0; i < output_columns; i++) {
134 for (j = 1; j <= y_dim; j++) {
135 snprintf(tmp_col,
sizeof(tmp_col),
"%s_%d", output_column[i], j);
137 if (!data[i][page][j - 1]) {
139 free_data_memory(data, output_columns, z_dim, y_dim);
149 free_data_memory(data, output_columns, z_dim, y_dim);
154 free_data_memory(data, output_columns, z_dim, y_dim);
155 fprintf(stderr,
"Error: Page count (%d) does not match z-dimension size (%d).\n", page, z_dim);
160 for (page = 0; page < x_dim; page++) {
163 "origin1", xmin,
"origin2", ymin,
"origin3", zmin,
164 "max_ext1", xmax,
"max_ext2", ymax,
"max_ext3", zmax,
165 "delta1", x_interval,
"delta2", y_interval,
"delta3", z_interval,
166 "numPhysCells1", x_dim,
"numPhysCells2", y_dim,
"numPhysCells3", z_dim,
167 "Variable1Name",
"Y",
"Variable2Name",
"Z",
168 "ZMinimum", zmin,
"ZMaximum", zmax,
"ZInterval", z_interval,
"ZDimension", z_dim,
169 "YMinimum", ymin,
"YMaximum", ymax,
"YInterval", y_interval,
"YDimension", y_dim,
172 free_data_memory(data, output_columns, z_dim, y_dim);
176 for (i = 0; i < output_columns; i++) {
178 for (j = 0; j < y_dim; j++) {
179 for (k = 0; k < z_dim; k++) {
181 output_column[i], data[i][k][j][page],
182 "z", k * z_interval + zmin,
183 "y", j * y_interval + ymin, NULL)) {
185 free_data_memory(data, output_columns, z_dim, y_dim);
195 free_data_memory(data, output_columns, z_dim, y_dim);
202 free_data_memory(data, output_columns, z_dim, y_dim);
207 for (page = 0; page < y_dim; page++) {
210 "origin1", xmin,
"origin2", ymin,
"origin3", zmin,
211 "max_ext1", xmax,
"max_ext2", ymax,
"max_ext3", zmax,
212 "delta1", x_interval,
"delta2", y_interval,
"delta3", z_interval,
213 "numPhysCells1", x_dim,
"numPhysCells2", y_dim,
"numPhysCells3", z_dim,
214 "Variable1Name",
"X",
"Variable2Name",
"Z",
215 "ZMinimum", zmin,
"ZMaximum", zmax,
"ZInterval", z_interval,
"ZDimension", z_dim,
216 "XMinimum", xmin,
"XMaximum", xmax,
"XInterval", x_interval,
"XDimension", x_dim,
219 free_data_memory(data, output_columns, z_dim, y_dim);
223 for (i = 0; i < output_columns; i++) {
225 for (j = 0; j < x_dim; j++) {
226 for (k = 0; k < z_dim; k++) {
228 output_column[i], data[i][k][page][j],
229 "z", k * z_interval + zmin,
230 "x", j * x_interval + xmin, NULL)) {
232 free_data_memory(data, output_columns, z_dim, y_dim);
242 free_data_memory(data, output_columns, z_dim, y_dim);
247 free_data_memory(data, output_columns, z_dim, y_dim);
257static void free_data_memory(
double ****data,
long output_columns,
long z_dim,
long y_dim) {
261 for (i = 0; i < output_columns; i++) {
264 for (j = 0; j < z_dim; j++) {
267 for (k = 0; k < y_dim; k++) {
277static void setup_output_file(
SDDS_DATASET *sdds_out,
const char *output,
long yz,
long output_columns,
char **output_column) {
323 for (i = 0; i < output_columns; i++) {
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
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_DefineSimpleColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data column within the SDDS dataset.
int32_t SDDS_DefineSimpleParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data parameter within the SDDS 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.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
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_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.