Commit f6e2f8f4 authored by Keith Bennett's avatar Keith Bennett

Use specified formatting for constants

parent 9a9de0ff
......@@ -84,7 +84,8 @@ static char width_fmt[16];
#define PRINTC(name,variable,fmt) do { \
printf(indent, 1); \
printf(width_fmt, (name)); \
printf(" " fmt, (variable)); \
printf(" "); \
printf(fmt, (variable)); \
printf("\n"); \
} while(0)
......@@ -97,8 +98,12 @@ static char width_fmt[16];
if (!(array)) break; \
printf(indent, 1); \
printf(width_fmt, (name)); \
printf(" (" fmt, (array)[0]); \
for (_i = 1; _i < (len); _i++) printf("," fmt, (array)[_i]); \
printf(" ("); \
printf(fmt, (array)[0]); \
for (_i = 1; _i < (len); _i++) { \
printf(","); \
printf(fmt, (array)[_i]); \
} \
printf(")\n"); \
} while(0)
......@@ -107,9 +112,12 @@ static char width_fmt[16];
if (!(array)) break; \
printf(indent, 1); \
printf(width_fmt, (name)); \
printf(" (" fmt, sdf_datatype_c[(array)[0]]); \
for (_i = 1; _i < (len); _i++) \
printf("," fmt, sdf_datatype_c[(array)[_i]]); \
printf(" ("); \
printf(fmt, sdf_datatype_c[(array)[0]]); \
for (_i = 1; _i < (len); _i++) { \
printf(","); \
printf(fmt, sdf_datatype_c[(array)[_i]]); \
} \
printf(")\n"); \
} while(0)
......@@ -638,7 +646,7 @@ static void print_value(void *data, int datatype)
printf(format_float, *((double*)data));
break;
//case SDF_DATATYPE_REAL16:
// printf("%g", (double)b->const_value);
// printf(format_float, (double)b->const_value);
// break;
case SDF_DATATYPE_CHARACTER:
printf("%c", *((char*)data));
......@@ -666,11 +674,11 @@ static void print_metadata_plain_mesh(sdf_block_t *b)
SET_WIDTH("dim_labels:");
if (verbose_metadata)
PRINTAR("dim_mults:", b->dim_mults, "%g", b->ndims);
PRINTAR("dim_mults:", b->dim_mults, format_float, b->ndims);
PRINTAR("dim_labels:", b->dim_labels, "%s", b->ndims);
PRINTAR("dim_units:", b->dim_units, "%s", b->ndims);
PRINT("geometry:", sdf_geometry_c[b->geometry], "%s");
PRINTAR("extents:", b->extents, "%g", 2*b->ndims);
PRINTAR("extents:", b->extents, format_float, 2*b->ndims);
PRINTAR("dims:", b->dims, "%" PRIi64, b->ndims);
}
......@@ -689,11 +697,11 @@ static void print_metadata_point_mesh(sdf_block_t *b)
SET_WIDTH("dim_labels:");
if (verbose_metadata)
PRINTAR("dim_mults", b->dim_mults, "%g", b->ndims);
PRINTAR("dim_mults", b->dim_mults, format_float, b->ndims);
PRINTAR("dim_labels", b->dim_labels, "%s", b->ndims);
PRINTAR("dim_units", b->dim_units, "%s", b->ndims);
PRINT("geometry:", sdf_geometry_c[b->geometry], "%s");
PRINTAR("extents", b->extents, "%g", 2*b->ndims);
PRINTAR("extents", b->extents, format_float, 2*b->ndims);
//PRINTAR("dims", b->dims, "%" PRIi64, b->ndims);
PRINT("nelements:", b->nelements, "%" PRIi64);
if (b->material_id)
......@@ -715,7 +723,7 @@ static void print_metadata_plain_variable(sdf_block_t *b)
PRINT("mesh id:", b->mesh_id, "%s");
PRINTAR("dims:", b->dims, "%" PRIi64, b->ndims);
if (verbose_metadata) {
PRINT("mult:", b->mult, "%g");
PRINT("mult:", b->mult, format_float);
PRINT("stagger:", sdf_stagger_c[b->stagger], "%s");
}
}
......@@ -737,53 +745,17 @@ static void print_metadata_point_variable(sdf_block_t *b)
if (b->material_id)
PRINT("species id:", b->material_id, "%s");
if (verbose_metadata)
PRINT("mult:", b->mult, "%g");
PRINT("mult:", b->mult, format_float);
}
static void print_metadata_constant(sdf_block_t *b)
{
int32_t i4;
int64_t i8;
float r4;
double r8;
// Metadata is
// - value TYPE_SIZE
printf("%svalue: ", indent);
switch (b->datatype) {
case SDF_DATATYPE_INTEGER4:
memcpy(&i4, b->const_value, sizeof(i4));
printf("%i", i4);
break;
case SDF_DATATYPE_INTEGER8:
memcpy(&i8, b->const_value, sizeof(i8));
printf("%" PRIi64, i8);
break;
case SDF_DATATYPE_REAL4:
memcpy(&r4, b->const_value, sizeof(r4));
printf("%g", r4);
break;
case SDF_DATATYPE_REAL8:
memcpy(&r8, b->const_value, sizeof(r8));
printf("%g", r8);
break;
//case SDF_DATATYPE_REAL16:
// printf("%g", (double)b->const_value);
// break;
case SDF_DATATYPE_CHARACTER:
printf("%c", *b->const_value);
break;
case SDF_DATATYPE_LOGICAL:
if (*b->const_value)
printf("True");
else
printf("False");
break;
}
print_value(b->const_value, b->datatype);
printf("\n");
}
......@@ -966,23 +938,23 @@ static void print_metadata_station(sdf_block_t *b)
PRINT("nvariables:", b->nvariables, "%i");
PRINT("step0:", b->step, "%i");
PRINT("step_increment:", b->step_increment, "%i");
PRINT("time0:", b->time, "%g");
PRINT("time_increment:", b->time_increment, "%g");
PRINT("time0:", b->time, format_float);
PRINT("time_increment:", b->time_increment, format_float);
PRINTAR("station_ids:", b->station_ids, "%s", b->nstations);
PRINTAR("station_names:", b->station_names, "%s", b->nstations);
PRINTAR("station_nvars:", b->station_nvars, "%i", b->nstations);
PRINTAR("station_move:", b->station_move, "%i", b->nstations);
PRINTAR("station_x:", b->station_x, "%g", b->nstations);
PRINTAR("station_x:", b->station_x, format_float, b->nstations);
if (b->ndims > 1)
PRINTAR("station_y:", b->station_y, "%g", b->nstations);
PRINTAR("station_y:", b->station_y, format_float, b->nstations);
if (b->ndims > 2)
PRINTAR("station_z:", b->station_z, "%g", b->nstations);
PRINTAR("station_z:", b->station_z, format_float, b->nstations);
PRINTAR("variable_ids:", b->variable_ids, "%s", b->nvariables);
PRINTAR("variable_names:", b->material_names, "%s", b->nvariables);
PRINTDAR("variable_types:", b->variable_types, "%s", b->nvariables);
PRINTAR("variable_units:", b->dim_units, "%s", b->nvariables);
if (b->dim_mults && verbose_metadata)
PRINTAR("variable_mults:", b->dim_mults, "%g", b->nvariables);
PRINTAR("variable_mults:", b->dim_mults, format_float, b->nvariables);
}
......@@ -1038,13 +1010,13 @@ static void print_metadata_namevalue(sdf_block_t *b)
case(SDF_DATATYPE_REAL4):
r4 = b->data;
for (i = 0; i < b->ndims; i++) {
PRINT(b->material_names[i], r4[i], "%g");
PRINT(b->material_names[i], r4[i], format_float);
}
break;
case(SDF_DATATYPE_REAL8):
r8 = b->data;
for (i = 0; i < b->ndims; i++) {
PRINT(b->material_names[i], r8[i], "%g");
PRINT(b->material_names[i], r8[i], format_float);
}
break;
case(SDF_DATATYPE_LOGICAL):
......
......@@ -51,7 +51,7 @@ int *blocktype_mask;
char *output_file;
char *format_float, *format_int, *format_space;
//static char *default_float = "%9.6fE%+2.2d1p";
static char *default_float = "%13.6E";
static char *default_float = "%13.7E";
static char *default_int = "%" PRIi64;
static char *default_space = " ";
static char *default_indent = " ";
......@@ -88,7 +88,8 @@ static char width_fmt[16];
#define PRINTC(name,variable,fmt) do { \
printf(indent, 1); \
printf(width_fmt, (name)); \
printf(" " fmt, (variable)); \
printf(" "); \
printf(fmt, (variable)); \
printf("\n"); \
} while(0)
......@@ -101,8 +102,12 @@ static char width_fmt[16];
if (!(array)) break; \
printf(indent, 1); \
printf(width_fmt, (name)); \
printf(" (" fmt, (array)[0]); \
for (_i = 1; _i < (len); _i++) printf("," fmt, (array)[_i]); \
printf(" ("); \
printf(fmt, (array)[0]); \
for (_i = 1; _i < (len); _i++) { \
printf(","); \
printf(fmt, (array)[_i]); \
} \
printf(")\n"); \
} while(0)
......@@ -111,9 +116,12 @@ static char width_fmt[16];
if (!(array)) break; \
printf(indent, 1); \
printf(width_fmt, (name)); \
printf(" (" fmt, sdf_datatype_c[(array)[0]]); \
for (_i = 1; _i < (len); _i++) \
printf("," fmt, sdf_datatype_c[(array)[_i]]); \
printf(" ("); \
printf(fmt, sdf_datatype_c[(array)[0]]); \
for (_i = 1; _i < (len); _i++) { \
printf(","); \
printf(fmt, sdf_datatype_c[(array)[_i]]); \
} \
printf(")\n"); \
} while(0)
......@@ -769,7 +777,7 @@ static void print_value(void *data, int datatype)
printf(format_float, *((double*)data));
break;
//case SDF_DATATYPE_REAL16:
// printf("%g", (double)b->const_value);
// printf(format_float, (double)b->const_value);
// break;
case SDF_DATATYPE_CHARACTER:
printf("%c", *((char*)data));
......@@ -1151,7 +1159,7 @@ static void print_header(sdf_file_t *h)
PRINTC("nblocks_file:", h->nblocks_file, "%i");
PRINTC("block_header_length:", h->block_header_length, "%i");
PRINTC("step:", h->step, "%i");
PRINTC("time:", h->time, "%g");
PRINTC("time:", h->time, format_float);
printf(indent, 1);
printf(width_fmt, "jobid:");
printf(" %i.%i\n", h->jobid1, h->jobid2);
......@@ -1175,11 +1183,11 @@ static void print_metadata_plain_mesh(sdf_block_t *b)
// - dims INTEGER(i4), DIMENSION(ndims)
SET_WIDTH("dim_labels:");
PRINTAR("dim_mults:", b->dim_mults, "%g", b->ndims);
PRINTAR("dim_mults:", b->dim_mults, format_float, b->ndims);
PRINTAR("dim_labels:", b->dim_labels, "%s", b->ndims);
PRINTAR("dim_units:", b->dim_units, "%s", b->ndims);
PRINT("geometry:", sdf_geometry_c[b->geometry], "%s");
PRINTAR("extents:", b->extents, "%g", 2*b->ndims);
PRINTAR("extents:", b->extents, format_float, 2*b->ndims);
PRINTAR("dims:", b->dims, "%" PRIi64, b->ndims);
}
......@@ -1197,11 +1205,11 @@ static void print_metadata_point_mesh(sdf_block_t *b)
// - speciesid CHARACTER(id_length)
SET_WIDTH("dim_labels:");
PRINTAR("dim_mults", b->dim_mults, "%g", b->ndims);
PRINTAR("dim_mults", b->dim_mults, format_float, b->ndims);
PRINTAR("dim_labels", b->dim_labels, "%s", b->ndims);
PRINTAR("dim_units", b->dim_units, "%s", b->ndims);
PRINT("geometry:", sdf_geometry_c[b->geometry], "%s");
PRINTAR("extents", b->extents, "%g", 2*b->ndims);
PRINTAR("extents", b->extents, format_float, 2*b->ndims);
//PRINTAR("dims", b->dims, "%" PRIi64, b->ndims);
PRINT("nelements:", b->nelements, "%" PRIi64);
if (b->material_id)
......@@ -1219,7 +1227,7 @@ static void print_metadata_plain_variable(sdf_block_t *b)
// - stagger INTEGER(i4)
SET_WIDTH("mesh id:");
PRINT("mult:", b->mult, "%g");
PRINT("mult:", b->mult, format_float);
PRINT("units:", b->units, "%s");
PRINT("mesh id:", b->mesh_id, "%s");
PRINTAR("dims:", b->dims, "%" PRIi64, b->ndims);
......@@ -1237,7 +1245,7 @@ static void print_metadata_point_variable(sdf_block_t *b)
// - speciesid CHARACTER(id_length)
SET_WIDTH("species id:");
PRINT("mult:", b->mult, "%g");
PRINT("mult:", b->mult, format_float);
PRINT("units:", b->units, "%s");
PRINT("mesh id:", b->mesh_id, "%s");
PRINT("nelements:", b->nelements, "%" PRIi64);
......@@ -1248,47 +1256,11 @@ static void print_metadata_point_variable(sdf_block_t *b)
static void print_metadata_constant(sdf_block_t *b)
{
int32_t i4;
int64_t i8;
float r4;
double r8;
// Metadata is
// - value TYPE_SIZE
printf("%svalue: ", indent);
switch (b->datatype) {
case SDF_DATATYPE_INTEGER4:
memcpy(&i4, b->const_value, sizeof(i4));
printf("%i", i4);
break;
case SDF_DATATYPE_INTEGER8:
memcpy(&i8, b->const_value, sizeof(i8));
printf("%" PRIi64, i8);
break;
case SDF_DATATYPE_REAL4:
memcpy(&r4, b->const_value, sizeof(r4));
printf("%g", r4);
break;
case SDF_DATATYPE_REAL8:
memcpy(&r8, b->const_value, sizeof(r8));
printf("%g", r8);
break;
//case SDF_DATATYPE_REAL16:
// printf("%g", (double)b->const_value);
// break;
case SDF_DATATYPE_CHARACTER:
printf("%c", *b->const_value);
break;
case SDF_DATATYPE_LOGICAL:
if (*b->const_value)
printf("True");
else
printf("False");
break;
}
print_value(b->const_value, b->datatype);
printf("\n");
}
......@@ -1466,23 +1438,23 @@ static void print_metadata_station(sdf_block_t *b)
PRINT("nvariables:", b->nvariables, "%i");
PRINT("step0:", b->step, "%i");
PRINT("step_increment:", b->step_increment, "%i");
PRINT("time0:", b->time, "%g");
PRINT("time_increment:", b->time_increment, "%g");
PRINT("time0:", b->time, format_float);
PRINT("time_increment:", b->time_increment, format_float);
PRINTAR("station_ids:", b->station_ids, "%s", b->nstations);
PRINTAR("station_names:", b->station_names, "%s", b->nstations);
PRINTAR("station_nvars:", b->station_nvars, "%i", b->nstations);
PRINTAR("station_move:", b->station_move, "%i", b->nstations);
PRINTAR("station_x:", b->station_x, "%g", b->nstations);
PRINTAR("station_x:", b->station_x, format_float, b->nstations);
if (b->ndims > 1)
PRINTAR("station_y:", b->station_y, "%g", b->nstations);
PRINTAR("station_y:", b->station_y, format_float, b->nstations);
if (b->ndims > 2)
PRINTAR("station_z:", b->station_z, "%g", b->nstations);
PRINTAR("station_z:", b->station_z, format_float, b->nstations);
PRINTAR("variable_ids:", b->variable_ids, "%s", b->nvariables);
PRINTAR("variable_names:", b->material_names, "%s", b->nvariables);
PRINTDAR("variable_types:", b->variable_types, "%s", b->nvariables);
PRINTAR("variable_units:", b->dim_units, "%s", b->nvariables);
if (b->dim_mults)
PRINTAR("variable_mults:", b->dim_mults, "%g", b->nvariables);
PRINTAR("variable_mults:", b->dim_mults, format_float, b->nvariables);
}
......@@ -1538,13 +1510,13 @@ static void print_metadata_namevalue(sdf_block_t *b)
case(SDF_DATATYPE_REAL4):
r4 = b->data;
for (i = 0; i < b->ndims; i++) {
PRINT(b->material_names[i], r4[i], "%g");
PRINT(b->material_names[i], r4[i], format_float);
}
break;
case(SDF_DATATYPE_REAL8):
r8 = b->data;
for (i = 0; i < b->ndims; i++) {
PRINT(b->material_names[i], r8[i], "%g");
PRINT(b->material_names[i], r8[i], format_float);
}
break;
case(SDF_DATATYPE_LOGICAL):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment