Ejemplo n.º 1
0
void CopyChannelCallback(int menubar, int menuItem, void *callbackData, int panel)
{
    channelPtr chan, newchan;

    chan = channellist_GetSelection();
    newchan = channel_Create();
    if (newchan && channel_AllocMem (newchan, chan->pts))
    {
        Copy1D (chan->readings, chan->pts, newchan->readings);
        Fmt (newchan->label, "%s<Copy(%s)", chan->label);
        Fmt (newchan->note, "%s<Copy of: %s\n%s\n", chan->label, chan->note);
        channellist_AddChannel (newchan);
    }
}
Ejemplo n.º 2
0
void fit_data (void)
{
	int Npoints, num;
	double slope, intercept, residue, coef[4], value;
	GetCtrlVal (ERG_panel, ERG_panel_start_val, &start);
	GetCtrlVal (ERG_panel, ERG_panel_points_num, &Npoints);
	double fit[Npoints];
	int maximumIndex, minimumIndex;
	CNVData data=0;
	CNVWriter writer = 0;
	
	for (int k = 0; k < Npoints; k++)
    fit[k] = 0;
	///////////////////////////////////////////////////////////////
	//////////////mto do : create specific function for background subtraction
	int pix_num,bckgrd_satus;
	double bckgrd_val;
	GetCtrlVal (ERG_panel, ERG_panel_bckgrd_sub, &bckgrd_satus); 
	if (bckgrd_satus==1)
	{
		GetCtrlVal (ERG_panel, ERG_panel_bckgrd, &pix_num);
		Mean (&data2fit[pix_num-50], 100, &bckgrd_val);
		j=0;
		while (j<10000)
		{
			buffer[j] = data2fit[j]-bckgrd_val;
			j++;
		}
	}
	else
	{
		  j=0;
		while (j<10000)
		{
			buffer[j] = data2fit[j];
			j++;
		}
	}
	//////////////////////////////////////////////////////////////
	
	
	
	generate_xarray ();   
	PlotXY (ERG_panel, ERG_panel_scope, &xarray[start], &buffer[start], Npoints, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_SOLID_SQUARE, VAL_SOLID, 1, VAL_GREEN); 
 	
	GetCtrlVal (ERG_panel, ERG_panel_fit_function, &j);
	if (j==0)
	{
		MaxMin1D(&buffer[start], Npoints, &maximumValue, &maximumIndex, &minimumValue, &minimumIndex);
		Npoints=  minimumIndex;
		LinearFitEx (&xarray[start], &buffer[start], NULL, Npoints, LEAST_SQUARE, 0.0001, fit, &slope, &intercept, &residue);
	
		////////////to do: create separated function for uploading network variable/////////////
		//write optimization value (slope) as a network variable
		CNVCreateWriter ("\\\\localhost\\ERG\\optimisation_value", 0, 0, 10000, 0, &writer);
		CNVCreateScalarDataValue (&data, CNVDouble, slope);
//		Delay(0.5);     
		CNVWrite (writer, data, 5000);
		CNVDisposeData (data);
		Delay(0.5);
//		printf("Slope=%f\n", slope); 
	}
							  
	if (j==1)
	{
		Mean (&buffer[start-100], 100, &baseline);
		MaxMin1D(&buffer[start], Npoints, &maximumValue, &maximumIndex, &minimumValue, &minimumIndex);
		Npoints=  minimumIndex;
		Mean (&buffer[start+minimumIndex-5], 10, &minimumValue);
		coef[0]= start+minimumIndex;
		coef[1]= minimumIndex/2;
	//	printf("base=%f, min=%f\n",baseline, minimumValue);      
		NonLinearFitWithMaxIters (&xarray[start], &buffer[start], fit, Npoints, 100, ModelFunct, coef, 2, &residue);
	//	printf("coef1=%f, coef2=%f\n",coef[0], coef[1]);
		
		//write optimization value (rise time; coef[1]) as a network variable
//		coef[1]=coef[1]/10;
		CNVCreateWriter ("\\\\localhost\\ERG\\optimisation_value", 0, 0, 10000, 0, &writer);
		CNVCreateScalarDataValue (&data, CNVDouble, coef[1]/10000);
		CNVWrite (writer, data, 5000);
		CNVDisposeData (data);
		Delay(0.5);
	}
	
	if (j==2)
	{
		MaxMin1D(&buffer[start], Npoints, &maximumValue, &maximumIndex, &minimumValue, &minimumIndex);
		value= maximumValue - minimumValue;
		
		if (minimumIndex < maximumIndex)
		{
			Npoints=maximumIndex-minimumIndex;
			Copy1D (&buffer[minimumIndex+start], Npoints, fit);
			start= minimumIndex+start;
			value= maximumValue - minimumValue;
		}
		else
		{
			value= 0;
		}
		
		CNVCreateWriter ("\\\\localhost\\ERG\\optimisation_value", 0, 0, 10000, 0, &writer);
		CNVCreateScalarDataValue (&data, CNVDouble, value);
		CNVWrite (writer, data, 5000);
		CNVDisposeData (data);
		Delay(0.5);
	}
	
	PlotXY (ERG_panel, ERG_panel_scope, &xarray[start], fit, Npoints, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_SOLID_SQUARE, VAL_SOLID, 1, VAL_RED);
}
Ejemplo n.º 3
0
int DoChannelAdditionCallback(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
    channelPtr chan, newchan;
    int i, n, checked, err, pts;

    if (event == EVENT_COMMIT)
    {
        GetNumCheckedItems (chanops.p, CHANOPS_1_CHANNELS, &n);
        if (n < 2)
        {
            MessagePopup ("Channel Addition Message",
                          "Cannot perform addition w/ less than 2 channels");
            return 0;
        }

        err = FALSE;
        newchan = NULL;
        for (i = 0; i < channelG.channels.nItems; i++)
        {
            IsListItemChecked (panel, CHANOPS_1_CHANNELS, 0, &checked);
            DeleteListItem (panel, CHANOPS_1_CHANNELS, 0, 1);
            if (checked)
            {
                chan = channellist_GetItem (i);
                if (newchan)
                {
                    if (newchan->pts < chan->pts) pts = newchan->pts;
                    else pts = chan->pts;
                    err = Add1D (newchan->readings, chan->readings, pts,
                                 newchan->readings);
                    if (!err)
                        Fmt (newchan->note, "%s[a]<+\n%s", chan->label);
                    else
                    {
                        MessagePopup ("Channel Addition Message",
                                      "Error during calculation -- operation cancelled");
                        break;
                    }
                }
                else
                {
                    newchan = channel_Create();
                    if (newchan && channel_AllocMem (newchan, chan->pts))
                    {
                        Copy1D (chan->readings, chan->pts, newchan->readings);
                        Fmt (newchan->label, "Addition Result");
                        Fmt (newchan->note, "%s", chan->label);
                    }
                    else
                    {
                        util_OutofMemory ("Channel Addition Message");
                        err = TRUE;
                        break;
                    }
                }
            }
            GetNumCheckedItems (panel, CHANOPS_1_CHANNELS, &n);
            if (n == 0) break;
        }
        if (!err)
        {
            Fmt (newchan->note, "%s[a]<\n");
            channellist_AddChannel (newchan);
        }
        else if (newchan)
        {
            if (newchan->readings) free (newchan->readings);
            free (newchan);
        }

        
        DiscardPanel (chanops.p);
    }
    return 0;
}