Gwyscan Library
 All Files Functions Enumerations Enumerator Modules
save_gwyddion_arrays_general.c

Example showing how to save multiple different arrays to a Gwyddion GWY file. This can represent e.g. multiple channels in a scan (height, error signal, etc.), but can also have completely different meaning as the arrays can be of different pixel and physical resolution.

Arrays are passed as an array of pointers to one-dimensional arrays; each one of them is having size xres[i]*yres[i], data are stored row by row.

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