Example showing how to save Gwyddion XYZ file.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <stdio.h>
#include <assert.h>
int main()
{
int xres = 1234;
int yres = 1234;
double **preview_data12;
double *xydata, *zdata, *data_tmp;
double *xydata1, *zdata1;
double *xydata2, *zdata2;
char *desc[] = { "Data" };
char *desc1[] = { "Data 1" };
char *desc2[] = { "Data 2" };
char *desc12[] = { "Data1", "Data2" };
int i;
int n = 160000;
int channels = 8;
preview_data12 = (double **)malloc(channels*sizeof(double*));
data_tmp = (double *)malloc(xres*yres*sizeof(double));
memset(data_tmp, 0, sizeof(double)*xres*yres);
preview_data12[0] = data_tmp;
data_tmp = (double *)malloc(xres*yres*sizeof(double));
memset(data_tmp, 0, sizeof(double)*xres*yres);
preview_data12[1] = data_tmp;
data_tmp = (double *)malloc(xres*yres*sizeof(double));
memset(data_tmp, 0, sizeof(double)*xres*yres);
preview_data12[2] = data_tmp;
data_tmp = (double *)malloc(xres*yres*sizeof(double));
memset(data_tmp, 0, sizeof(double)*xres*yres);
preview_data12[3] = data_tmp;
data_tmp = (double *)malloc(xres*yres*sizeof(double));
memset(data_tmp, 0, sizeof(double)*xres*yres);
preview_data12[4] = data_tmp;
data_tmp = (double *)malloc(xres*yres*sizeof(double));
memset(data_tmp, 0, sizeof(double)*xres*yres);
preview_data12[5] = data_tmp;
data_tmp = (double *)malloc(xres*yres*sizeof(double));
memset(data_tmp, 0, sizeof(double)*xres*yres);
preview_data12[6] = data_tmp;
data_tmp = (double *)malloc(xres*yres*sizeof(double));
memset(data_tmp, 0, sizeof(double)*xres*yres);
preview_data12[7] = data_tmp;
xydata1 = (double *)malloc(2 * n*sizeof(double));
zdata1 = (double *)malloc(n*sizeof(double));
xydata2 = (double *)malloc(2 * n*sizeof(double));
zdata2 = (double *)malloc(n*sizeof(double));
xydata = (double *)malloc(2 * (2 * n*sizeof(double)));
zdata = (double *)malloc(channels * (n*sizeof(double)));
for (i = 0; i < 2 * n; i++)
xydata[i] = xydata1[i];
for (i = 0; i < n; i++)
zdata[i] = zdata1[i];
for (i = 0; i < 2 * n; i++)
xydata[i + 2 * n] = xydata2[i];
for (i = 0; i < n; i++)
zdata[i + n] = zdata2[i];
for (i = 0; i < n; i++)
zdata[i + 2*n] = zdata2[i];
for (i = 0; i < n; i++)
zdata[i + 3*n] = zdata2[i];
for (i = 0; i < n; i++)
zdata[i + 4*n] = zdata2[i];
for (i = 0; i < n; i++)
zdata[i + 5*n] = zdata2[i];
for (i = 0; i < n; i++)
zdata[i + 6*n] = zdata2[i];
for (i = 0; i < n; i++)
zdata[i + 7*n] = zdata2[i];
memcpy(xydata, xydata1, 2 * n*sizeof(double));
memcpy(xydata + 2 * n, xydata2, 2 * n*sizeof(double));
memcpy(zdata, zdata1, n*sizeof(double));
memcpy(zdata + n, zdata2, n*sizeof(double));
free(xydata1);
free(zdata1);
free(xydata2);
free(zdata2);
free(xydata);
free(zdata);
return 0;
}