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>
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;
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++;
}
printf("gwyscan_save_gwyddion_arrays success.\n");
free(data);
}
return 0;
}