hello DAVID,
I 'm actually working on a plugin that import a data file with several channels .
The format of the file is like this :
Number of sample of channel 1
x1 y1
x2 y2
x3 y3
....
Number of sample of channel 2
x1 y1
x2 y2
x3 y3
....
Number of sample of channel 3
x1 y1
x2 y2
x3 y3
....
for example
3
0.5 1.002
1.0 1.005
1.5 1.007
3
0.5 2.001
1.0 2.005
1.5 2.011
I'm using the following code, but the graph display only one curve, when I display or edit the array of the curve the arrays are empty except for the first one.
The code is th efollowing :
if (NULL == (f = fopen (Filename, "r"))) goto PluginExit;
i = 0;
while(fgets(szLine,sizeof(szLine),f))
{
sscanf(szLine,"%d",&m_NbSample);
if(i < (int)DPlot->MaxPoints)
{
for( a=0; a<m_NbSample; a++)
{
fgets(szLine,sizeof(szLine),f);
sscanf(szLine,"%lf%lf",&x,&y);
X = (float)x;
Y = (float)y;
i++;
}
N = DPlot->NumCurves;
DPlot->NP[N] = m_NbSample;
DPlot->NumCurves++;
lstrcpy(DPlot->Legend[N+1],"From SIMPLEFILE.DLL");
if(DPlot->NP[N] > DPlot->MaxPoints)
{
DPlot->MaxPoints = DPlot->NP[N];
RetCode = PLUGIN_BADARRAYSIZE;
goto PluginExit;
}
}
}
fclose(f);
Can you help me.
Thank you in advance
Regards
Franck
Create Plugin to import file
Moderator: DPlotAdmin
- DPlotAdmin
- Posts: 2312
- Joined: Tue Jun 24, 2003 9:34 pm
- Location: Vicksburg, Mississippi
- Contact:
Franck,
The main problem is in the way you've assumed the input arrays are arranged. If MaxPoints is, for example, 1000, then then first 3 X values in the first curve should be assigned to X[0],X[1],X[2] (which you have). But the first 3 X values in the 2nd curve should be assigned to X[1000],X[1001],X[1002].
Neither here nor there but I can't tell from your snippet whether you're closing the file before returning with a PLUGIN_BADARRAYSIZE. You definitely want to do that, else when DPlot calls the plugin again with larger arrays, fopen will fail. You'll also want to reset the number of curves to its original value when returning a PLUGIN_BADARRAYSIZE, else when returning to the plugin you'll be assigning values to the wrong curve.
And finally, if there's a chance that you might read a file that has the number of points increasing with subsequent data sets - that is, N[1] < N[2] < N[3], etc., then you'll need to either a) make one pass through the file w/o assigning data values to see how many points are required, then either read the data or return a PLUGIN_BADARRAYSIZE, or b) if your files are such that from the first curve you know what the maximum for all curves will be, set the required number of points to that value. The reason for this long-winded explanation is that DPlot will give up trying to read the file after the 2nd PLUGIN_BADARRAYSIZE.
Anyhow - the following should work:
The main problem is in the way you've assumed the input arrays are arranged. If MaxPoints is, for example, 1000, then then first 3 X values in the first curve should be assigned to X[0],X[1],X[2] (which you have). But the first 3 X values in the 2nd curve should be assigned to X[1000],X[1001],X[1002].
Neither here nor there but I can't tell from your snippet whether you're closing the file before returning with a PLUGIN_BADARRAYSIZE. You definitely want to do that, else when DPlot calls the plugin again with larger arrays, fopen will fail. You'll also want to reset the number of curves to its original value when returning a PLUGIN_BADARRAYSIZE, else when returning to the plugin you'll be assigning values to the wrong curve.
And finally, if there's a chance that you might read a file that has the number of points increasing with subsequent data sets - that is, N[1] < N[2] < N[3], etc., then you'll need to either a) make one pass through the file w/o assigning data values to see how many points are required, then either read the data or return a PLUGIN_BADARRAYSIZE, or b) if your files are such that from the first curve you know what the maximum for all curves will be, set the required number of points to that value. The reason for this long-winded explanation is that DPlot will give up trying to read the file after the 2nd PLUGIN_BADARRAYSIZE.
Anyhow - the following should work:
Code: Select all
if (NULL == (f = fopen (Filename, "r"))) goto PluginExit;
i = 0;
NCstart = DPlot->NumCurves;
while(fgets(szLine,sizeof(szLine),f))
{
if(DPlot->NumCurves < DPlot->MaxCurves)
{
sscanf(szLine,"%d",&m_NbSample);
if(m_NbSample <= (int)DPlot->MaxPoints)
{
for( a=0; a<m_NbSample; a++)
{
fgets(szLine,sizeof(szLine),f);
sscanf(szLine,"%lf%lf",&x,&y);
X[a+i*DPlot->MaxPoints] = (float)x;
Y[a+i*DPlot->MaxPoints] = (float)y;
}
i++;
N = DPlot->NumCurves;
DPlot->NP[N] = m_NbSample;
DPlot->LineType[N] = LINESTYLE_SOLID;
DPlot->NumCurves++;
lstrcpy(DPlot->Legend[N+1],"From SIMPLEFILE.DLL");
}
else
{
DPlot->MaxPoints = m_NbSample;
DPlot->NumCurves = NCstart;
RetCode = PLUGIN_BADARRAYSIZE;
fclose(f);
goto PluginExit;
}
}
else
{
DPlot->MaxCurves++;
DPlot->NumCurves = NCstart;
RetCode = PLUGIN_BADARRAYSIZE;
fclose(f);
goto PluginExit;
}
}
fclose(f);
RetCode = PLUGIN_SUCCESS;
PluginExit:
// Re-enable owner
EnableWindow(hwndOwner,TRUE);
return RetCode;
}
Visualize Your Data
support@dplot.com
support@dplot.com
Re:Create Plugin to import file
Ok David I understand the reason of the problem.
I will try your code ASAP.
Thank you for your help.
Best regards
Franck
I will try your code ASAP.
Thank you for your help.
Best regards
Franck