Serious Problem using Dplot
Posted: Wed Feb 11, 2009 1:18 pm
hello david. i'm experiencing a serious error when using Dplot to do a 3D surface. It's not easy to explain, and i've tried basically everything so i'll just show you some code to see if you could help me.
Just some important info: i'm using VS 2005 c++ express edition, and running vista32 business, programing in C.
i'm copied the dplotlib.lib and the dplotlib.dll to my project folder.
i have dplot installed on c:\programfiles\dplot\.
My project is this: receive a 1023 bits signal, sample it with 5000 samples.
after this, use Correlation in the time domain and in the freq domain correlating this 5000 signal with local replicas stored (41 diffferent replicas).
Basically i 1st create two 2D arrays with [41][5000]
Then on the load method, i fill them with my data:
After loading, i'm in this moment only using Time Domain Correlation so:
The actual method:
i've tested everything on my code to this part. If i save the result_time[][] values to a .txt file, everything is correct, so i imagine that the problem isn't here. (it stores the correct values, even when the program crashes)
After this method i wanna use the result_time[][] to plot a 3D graph using the Dplot, so i call:
The complete graph class is this:
ok so now my actual problem:
i was until this point only using the Time Correlation, but when i created the array_time, i created also the array_freq although i was not using it until now.
The strange thing is this: if i create array_freq with less than 5000 doubles, the program gives me an exception when i call the Dplot function.
this is very strange because the graphic is done with another array, (result_time[][]) and i don't use array_freq for nothing (will use in the future). i just create it and then free() it when the app closes.
The error is this:
Unhandled exception at 0x77588a73 in GUI_Correlation.exe: 0xC0000005: Access violation reading location 0x02809000.
This is the stack:
>ntdll.dll!77588a73()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
user32.dll!769763d4()
dplotlib.dll!00022b81()
dplotlib.dll!00023d0e()
>GUI_Correlation.exe!timeGraph(double * * result_time=0x0012b9d8) Line 61 + 0x1e bytes
my hope is that i'm doing something wrong on the graph method and you can spot it.
So resuming: i use array_time[][] to calculate the correlation values and then store it on result_time[][].
i then pass result_time[][] to Dplot so it makes the graph.
If i create array_freq with 5000 doubles or more, it all works fine.
If i don't create array_freq, or create it with less than 5000 doubles the programs crashes on the DocNum = DPLOT_PLOT (&DPlot,extents,*result_time,..... statement.
i know this is a very long post and if you can help me out it would be great.
Thank you
Just some important info: i'm using VS 2005 c++ express edition, and running vista32 business, programing in C.
i'm copied the dplotlib.lib and the dplotlib.dll to my project folder.
i have dplot installed on c:\programfiles\dplot\.
My project is this: receive a 1023 bits signal, sample it with 5000 samples.
after this, use Correlation in the time domain and in the freq domain correlating this 5000 signal with local replicas stored (41 diffferent replicas).
Basically i 1st create two 2D arrays with [41][5000]
Code: Select all
double *array_time[41], *array_freq[41]; (global variables)
double *result_time[41]; //correlation result, explained later
Code: Select all
for(a=0; a<41;a++){ //41 lines, each one with 5000 doubles
array_time[a] = (double*) malloc(sizeof(double) * 5000);
}
for(a=0; a<41;a++){
array_freq[a] = (double*) malloc(sizeof(double) * 5000);
}
//then i call both loaders:
time_loader(array_time,signal_array);
freq_loader(array_freq,signal_array);
The actual method:
Code: Select all
//create the 2D array to store the results
//it will only store the Z component
for(i = 0; i != 41; i++)
{
result_time[i] = (double*) malloc(sizeof(double) * 5000);
}
//correlation method
for(i=0; i <41 ; i++){
for (k = 0; k < 5000; k++)
{
result_time[i][k] = timeCorrelation(sample_signal,array_time[i],sample_array_size, k);
}
}
After this method i wanna use the result_time[][] to plot a 3D graph using the Dplot, so i call:
Code: Select all
timeGraph(result_time);
Code: Select all
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "dplot.h"
#define DOUBLEPRECISION
#ifdef DOUBLEPRECISION
#define REAL double
#define DPLOT_PLOT dPlot_Plot8
#else
#define REAL float
#define DPLOT_PLOT dPlot_Plot
#endif
void timeGraph(double *result_time[] ){
DPLOT DPlot;
int DocNum;
int Nx, Ny;
REAL extents[4];
#ifdef __GNUC__
HINSTANCE dll;
if((dll = dPlot_Init()) == NULL)
{
printf("LoadLibrary for DPLOTLIB.DLL failed.\n");
exit(0);
}
#endif
dPlot_SetErrorMethod(2);
Nx = 41; // Columns
Ny = 5000; // Rows
extents[0] = -10.f; // xlo
extents[1] = 0.f; // ylo
extents[2] = 10.f; // xhi
extents[3] = 5000.f; // yhi
memset(&DPlot,0,sizeof(DPlot));
DPlot.Version = DPLOT_DDE_VERSION;
DPlot.DataFormat = DATA_3D;
DPlot.MaxCurves = Nx-1; // Size of the grid, in grid cells
DPlot.MaxPoints = Ny-1;
DPlot.NumCurves = 1;
DPlot.Scale = SCALE_LINEARX_LINEARY;
strcpy(DPlot.Title[0],"Time Correlation");
strcpy(DPlot.XAxis,"Doppler Shift");
strcpy(DPlot.YAxis,"Code Phase");
DocNum = DPLOT_PLOT(&DPlot,extents,*result_time,"[Caption(\"GuiCorrelation\")]"
"[Contour3D(1)][ContourMethod(0)][ContourGrid(1)][ContourAxes(1)][ContourView(315,26)]"
"[ContourLevels(20,-1000,5000)][ContourScales(250,1,0.5)][ContourLighting(2,0.2)]"
"[FontPoints(1,10)][ZAxisLabel(\"Magnitude\")]" );
#ifdef __GNUC__
FreeLibrary(dll);
#endif
}
i was until this point only using the Time Correlation, but when i created the array_time, i created also the array_freq although i was not using it until now.
The strange thing is this: if i create array_freq with less than 5000 doubles, the program gives me an exception when i call the Dplot function.
this is very strange because the graphic is done with another array, (result_time[][]) and i don't use array_freq for nothing (will use in the future). i just create it and then free() it when the app closes.
The error is this:
Unhandled exception at 0x77588a73 in GUI_Correlation.exe: 0xC0000005: Access violation reading location 0x02809000.
This is the stack:
>ntdll.dll!77588a73()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
user32.dll!769763d4()
dplotlib.dll!00022b81()
dplotlib.dll!00023d0e()
>GUI_Correlation.exe!timeGraph(double * * result_time=0x0012b9d8) Line 61 + 0x1e bytes
my hope is that i'm doing something wrong on the graph method and you can spot it.
So resuming: i use array_time[][] to calculate the correlation values and then store it on result_time[][].
i then pass result_time[][] to Dplot so it makes the graph.
If i create array_freq with 5000 doubles or more, it all works fine.
If i don't create array_freq, or create it with less than 5000 doubles the programs crashes on the DocNum = DPLOT_PLOT (&DPlot,extents,*result_time,..... statement.
i know this is a very long post and if you can help me out it would be great.
Thank you