DPlot Forum Index DPlot
http://www.dplot.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Create Plugin to import file

 
Post new topic   Reply to topic    DPlot Forum Index -> C, C++, C#
View previous topic :: View next topic  
Author Message
franckgaz



Joined: 03 Mar 2007
Posts: 10
Location: France

PostPosted: Wed Feb 20, 2008 3:22 pm    Post subject: Create Plugin to import file Reply with quote

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[i] = (float)x;
Y[i] = (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
Back to top
View user's profile Send private message
DPlotAdmin
Site Admin


Joined: 24 Jun 2003
Posts: 2310
Location: Vicksburg, Mississippi

PostPosted: Wed Feb 20, 2008 4:55 pm    Post subject: Reply with quote

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:
Code:
   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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
franckgaz



Joined: 03 Mar 2007
Posts: 10
Location: France

PostPosted: Thu Feb 21, 2008 1:39 pm    Post subject: Re:Create Plugin to import file Reply with quote

Ok David I understand the reason of the problem.

I will try your code ASAP.


Thank you for your help.


Best regards

Franck
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    DPlot Forum Index -> C, C++, C# All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group