added example for 3d plot

pull/6/merge
Sergey Bakhurin 2020-06-04 11:57:34 +03:00
rodzic 81c13ef872
commit c5be8c45b0
2 zmienionych plików z 56 dodań i 5 usunięć

Wyświetl plik

@ -255,7 +255,7 @@ int DSPL_API writetxt_int(int* x, int* y, int n, char* fn)
/******************************************************************************
* Write a 3d plot data to file "fn" (pgfplots3d accepteble)
* Write a 3d plot data to file "fn" (pgfplots3d acceptable)
******************************************************************************/
int DSPL_API writetxt_3d(double* x, int nx, double *y, int ny,
double* z, char* fn)
@ -276,7 +276,7 @@ int DSPL_API writetxt_3d(double* x, int nx, double *y, int ny,
for(k = 0; k < ny; k++)
{
for(n = 0; n < nx; n++)
for(n = 0; n < nx; n++)
fprintf(pFile, "%+.12E\t%+.12E\t%+.12E\n",
x[n], y[k], z[n+k*nx]);
fprintf(pFile, "\n");
@ -293,7 +293,7 @@ int DSPL_API writetxt_3d(double* x, int nx, double *y, int ny,
/******************************************************************************
* Write a 3d line data to file "fn" (pgfplots3d accepteble)
* Write a 3d line data to file "fn" (pgfplots3d acceptable)
******************************************************************************/
int DSPL_API writetxt_3dline(double* x, double *y, double* z, int n, char* fn)
{
@ -322,7 +322,7 @@ int DSPL_API writetxt_3dline(double* x, double *y, double* z, int n, char* fn)
/******************************************************************************
Write a real part of coplex array to the text file "fn"
Write a real part of complex array to the text file "fn"
*******************************************************************************/
int DSPL_API writetxt_cmplx_re(double* x, complex_t *y, int n, char* fn)
{
@ -354,7 +354,7 @@ int DSPL_API writetxt_cmplx_re(double* x, complex_t *y, int n, char* fn)
/******************************************************************************
Write a image part of coplex array to the text file "fn"
Write a image part of complex array to the text file "fn"
*******************************************************************************/
int DSPL_API writetxt_cmplx_im(double* x, complex_t *y, int n, char* fn)
{

Wyświetl plik

@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
#define NX 20
#define NY 30
int main(int argc, char* argv[])
{
void* hdspl; /* DSPL handle */
void* hplot; /* GNUPLOT handles */
hdspl = dspl_load(); /* Load DSPL function */
double x[NX];
double y[NY];
double z[NX * NY];
int n, m;
int err;
/* x vector from -4 to 4 */
linspace(-2.0, 2.0, NX, DSPL_SYMMETRIC, x);
/* y vector from -3 to 3 */
linspace(-2.0, 2.0, NY, DSPL_SYMMETRIC, y);
for(n = 0; n < NX; n++)
{
for(m = 0; m < NY; m++)
{
z[n + m*NX] = x[n]*exp(-x[n]*x[n] - y[m]*y[m]);
}
}
/* Save to files "dat/sine.txt" and "dat/cosine.txt" */
err = writetxt_3d(x, NX, y, NY, z, "dat/data3d.txt");
printf("writetxt_3d error 0x%8x\n", err);
/* plotting by GNUPLOT */
/* Create window 0 */
err = gnuplot_create(argc, argv, 560, 480, "img/writetxt_3d.png", &hplot);
printf("GNUPLOT err = %d\n", err);
gnuplot_cmd(hplot, "splot 'dat/data3d.txt' with lines");
gnuplot_close(hplot);
dspl_free(hdspl); /* free dspl handle */
return 0;
}