34 long d2[2] = {NX, NY}, dx[1] = {NX}, dy[1] = {NY}, dz[1] = {NZ};
35 long d3[3] = {NX, NY, NZ};
36 double **p2, *x, *y, ***p3, *z;
44 if (!(p2 = (
double **)
zarray_2d(
sizeof(
double), d2[0], d2[1])) ||
45 !(p3 = (
double ***)
zarray_2d(
sizeof(**p3), d3[0], d3[1])) ||
46 !(x = malloc(
sizeof(
double) * d2[0])) || !(y = malloc(
sizeof(
double) * d2[1])) ||
47 !(z = malloc(
sizeof(
double) * d3[2]))) {
52 for (i = 0; i < NX; i++) {
53 for (j = 0; j < NY; j++) {
54 if (!(p3[i][j] = malloc(
sizeof(***p3) * NZ)))
55 bomb(
"memory allocation failure", NULL);
60 if (!
SDDS_InitializeOutput(&SDDS_dataset, SDDS_ASCII, 1,
"description 1",
"description 2",
"atest.out")) {
80 for (i = 0; i < d2[0]; i++) {
81 for (j = 0; j < d2[1]; j++) {
82 x[i] = (1.0 * i) / d2[0];
83 y[j] = sqr(sqr((1.0 * j) / d2[1]));
85 p2[i][j] = x[i] + y[j] * y[j];
89 for (i = 0; i < d3[0]; i++) {
90 for (j = 0; j < d3[1]; j++) {
91 for (k = 0; k < d3[2]; k++) {
93 p3[i][j][k] = (k + 1) * (x[i] + y[j] * y[j]);
99 !
SDDS_SetArray(&SDDS_dataset,
"p2", SDDS_POINTER_ARRAY, p2, d2) ||
100 !
SDDS_SetArray(&SDDS_dataset,
"p3", SDDS_POINTER_ARRAY, p3, d3) ||
101 !
SDDS_SetArray(&SDDS_dataset,
"x", SDDS_POINTER_ARRAY, x, dx) ||
102 !
SDDS_SetArray(&SDDS_dataset,
"y", SDDS_POINTER_ARRAY, y, dy) ||
103 !
SDDS_SetArray(&SDDS_dataset,
"z", SDDS_POINTER_ARRAY, z, dz)) {
112 fprintf(stderr,
"No errors detected\n");
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_SetArray(SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer, int32_t *dimension)
Sets the values of an array variable in the SDDS dataset using specified dimensions.
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_DefineArray(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length, int32_t dimensions, const char *group_name)
Defines a data array within the SDDS dataset.
int32_t SDDS_SetNoRowCounts(SDDS_DATASET *SDDS_dataset, int32_t value)
Sets the flag to enable or disable row counts in 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.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
#define SDDS_DOUBLE
Identifier for the double data type.
void ** zarray_2d(uint64_t size, uint64_t n1, uint64_t n2)
Allocates a 2D array with specified dimensions.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.