Gwyscan Library
 All Data Structures Files Functions Enumerations Enumerator Macros Groups
save_gwyddion_arrays.c

Example showing how to save multiple arrays (channels) having the same resolution and physical range to a Gwyddion GWY file. This can represent e.g. multiple channels in a scan (height, error signal, etc.).

Arrays are passed as one-dimensional array which is a flat representation of a 3d array of xres*yres*nchannels size.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include "lib/gwyscan.h"
int main()
{
int ii;
for (ii = 0; ii < 100; ii++)
{
int i, j, idx;
int xres, yres, nchannels;
double width, height;
double *data;
bool res;
const char *xyunit[] = { "m", "V" };
const char *zunit[] = { "m", "A" };
const char *desc[] = { "One channel", "Another channel" };
xres = 300;
yres = 200;
nchannels = 2;
width = height = 1;
/********************************** 1d arrays version ****************************/
data = (double *)malloc(xres*yres*nchannels * sizeof(double));
idx = 0;
for (j = 0; j < yres; j++)
for (i = 0; i < xres; i++)
{
data[idx] = sin(i / 20.0);
idx++;
}
for (j = 0; j < yres; j++)
for (i = 0; i < xres; i++)
{
data[idx] = sin(j / 20.0);
idx++;
}
res = gwyscan_save_gwyddion_arrays(data, 2, xres, yres, width, height, xyunit, zunit, desc, "gwyscan_multiple_same_res.gwy");
if (res == GWYSCAN_SUCCESS)
printf("gwyscan_save_gwyddion_arrays success.\n");
free(data);
}
return 0;
}