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

Example showing how to insert points to existing path.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include "lib/gwyscan.h"
int main()
{
int i;
int ndata, ndata_insert, nindexes;
double *xydata, *xydata_inserted;
int *indexes;
/*********************************** path generation **********************************/
// LabView friendly implementation
xydata = malloc(2*ndata * sizeof(double));
/* insert [10, 11] point in intervals distant 100 elements */
ndata_insert = gwyscan_modify_path_insert(NULL, NULL, &nindexes, xydata, ndata, 10, 11, 100);
xydata_inserted = malloc(2*ndata_insert * sizeof(double));
indexes = malloc(nindexes * sizeof(double));
ndata_insert = gwyscan_modify_path_insert(xydata_inserted, indexes, &nindexes, xydata, ndata, 10, 11, 100);
FILE* fp = fopen("scan_path_insert_in.txt", "wt");
if (fp == NULL) {
printf("Error. Unable to open file for writing %s \n", strerror(errno));
return 0;
}
for (i = 0; i < ndata; i++)
fprintf(fp, "%d %g %g\n", i, xydata[2*i], xydata[2*i + 1]);
fclose(fp);
fp = fopen("scan_path_insert_out.txt", "wt");
if (fp == NULL) {
printf("Error. Unable to open file for writing %s \n", strerror(errno));
return 0;
}
for (i = 0; i < ndata_insert; i++)
fprintf(fp, "%d %g %g\n", i, xydata_inserted[2*i], xydata_inserted[2*i + 1]);
fclose(fp);
free(xydata);
free(xydata_inserted);
free(indexes);
return 0;
}