The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Limited number of parameters of OriginC function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Stefan.E.S

Germany
11 Posts

Posted - 11/12/2009 :  12:13:02 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
In my newly bought Origin Pro 8.1 version I found the following strange behaviour when debugging my previously (using OrginPro 7.5) running LabTalk script. I use an OriginC function which returns a string. When the function has more than 6 parameters it does not execute, when it has 6 or less it does.

The function call is as follows:

%z = ReadALSasciiFileS(%z, filetype, %w, diode, formfactor, clockfrequency, phAmMeterRange, phVFCgain, phdarkSubtract, icurAmMeterRange, icurVFCgain, ionCharge, ionMass, accVoltage, icurValue, ionsmooth, fhvsmooth)$;

I assume that this is a bug of Origin 8.1

Echo_Chu

China
Posts

Posted - 11/12/2009 :  10:22:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I created a simple OC function with 9 parameters but can not reproduce your problem in 81. I am not sure whether the problem is related to specified function. Would you mind to show us prototype and body of ReadALSasciiFileS?

Echo
OriginLab Corp.
Go to Top of Page

Stefan.E.S

Germany
11 Posts

Posted - 11/13/2009 :  05:55:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Echo,

thank you for the fast reply. I attach the OriginC file which contains the function definition. In the meantime I have found a (rather clumsy) workaround). Using Orgin Pro 8.1 the
%z=ReadALSasciiFileS(...)$ variant does not work with more than 6 parameters.

Please let me know, if you should need further source code.

Stefan

/**
 * @file ALSimportascii.c
 * @brief Imports Scan ASCII files
 */
 
////////////////////////////////////////////////////////////////////////////////////
//
#include <origin.h>
#include <wksheet.h>
#include <data.h>
#include <file.h>

#include "ALSfunctions.h"
#include "ALSsens.h"

////////////////////////////////////////////////////////////////////////////////////

/**
 * @brief Composes a data file name from path, date and time
 */
string ALSfilename(string path, string year, string month, string day, string filename, int format=1)
{
	string fn;
	switch (format)
	{
		case 0: 
				fn=path+'\\'+month+'\\'+day+'\\'+filename; break;
		default: 
				fn=path+'\\'+"20"+year+'\\'+"20"+year+"_"+month+'\\'+year+month+day+'\\'+filename;
	}
	char outstr[200];
	return fn;
}

/**
 * @brief Reads an ALS ascii data file (origin v8.0)
 */
void ReadALSasciiFile(string filename, int filetype, string wksname, int photodiode, double formfactor, double clockfrequency, 
                        int phAmMeter_range, int phVFC_gain, int phdark_subtract, int icurAmMeter_range, int icurVFC_gain, 
                        int ion_charge, double ion_mass, double acc_voltage, double icurValue, int nsmooth, int msmooth, string &header)
{
	const double cLight = 29979245800; // cm/s
	const double eCharge = 1.602176462e-19; // As
	const double u = 931494.013; // keV
   	char outstr[200];
	stdioFile fascii;
   	string line;
   	int headerlines = 21; if (filetype==2) headerlines = 8;

    // conversion factor to cross section in MB assuming a form factor of 300/cm
   	double Xsec_factor = 1E18*ion_charge*eCharge/formfactor*cLight*
   	                     sqrt(2*ion_charge*acc_voltage/(ion_mass*u));

	Worksheet wksData;
    int ii, npts = 0;
	
	int recalc_flag = !strcmp(filename,"***recalc***");
	
	if (recalc_flag)
	{
		wksData=Project.ActiveLayer();
	}
	else
	{
		wksData=Project.ActiveLayer();;
		npts = wksData.GetNumRows();

		int ok = fascii.Open(filename, file::modeRead);
		if (!ok)
		{
			sprintf(outstr,"ERROR::File %s not found!",filename);
			MessageBox( GetWindow(), outstr, "ERROR!" , MB_OK);
			header = "error";
			return;
		}
	
		// count number of data rows in file
		for (ii=0; ii<headerlines; ii++) { fascii.ReadString(line); }
		while (fascii.ReadString(line)) 
		{   
		    double etest = atof(line.GetToken(0));
		    if (etest < 1.0E-30) break;
			npts++;
		} 
		fascii.SeekToBegin();
	
		// now create a worksheet using custom template
		string strWksTemplate = GetAppPath(false) + "OriginC/ALS/ALSwks.OTW";

		int nOptionW = CREATE_VISIBLE_SAME;
		bool bRetW = wksData.Create(strWksTemplate, nOptionW);
		wksData.GetPage().Rename(wksname);
	}
	// now assign datasets to columns in the new worksheet and set size of columns

    Dataset ehv(wksData, wksData.Columns("EHV").GetIndex());
    if (recalc_flag)
	{
   		ehv.TrimLeft(TRUE);ehv.TrimRight(TRUE);
    	npts = ehv.GetUpperBound()+1;
	}
	ehv.SetSize(npts);
    Dataset ncts(wksData, wksData.Columns("NCTS").GetIndex());ncts.SetSize(npts);
	Dataset cerror(wksData, wksData.Columns("ERROR").GetIndex());cerror.SetSize(npts);
	Dataset ctson(wksData, wksData.Columns("CTSON").GetIndex());ctson.SetSize(npts);
	Dataset ctsoff(wksData, wksData.Columns("CTSOFF").GetIndex());ctsoff.SetSize(npts);
	Dataset timeon(wksData, wksData.Columns("TIMEON").GetIndex());timeon.SetSize(npts);
	Dataset timeoff(wksData, wksData.Columns("TIMEOFF").GetIndex());timeoff.SetSize(npts);
	Dataset icuron(wksData, wksData.Columns("ICURON").GetIndex());icuron.SetSize(npts);
	Dataset icuroff(wksData, wksData.Columns("ICUROFF").GetIndex());icuroff.SetSize(npts);
	Dataset phflux(wksData, wksData.Columns("PHFLUX").GetIndex());phflux.SetSize(npts);
	Dataset sens(wksData, wksData.Columns("SENS").GetIndex());sens.SetSize(npts);
	Dataset senscoef(wksData, wksData.Columns("SENSCOEF").GetIndex());
	int ncoeff = nint(quantumyield(0.0,photodiode,0))+1;senscoef.SetSize(ncoeff);
	Dataset PARname(wksData,wksData.Columns("PARname").GetIndex());PARname.SetSize(15);
	Dataset PARval(wksData, wksData.Columns("PARval").GetIndex());PARval.SetSize(15);

	vector erron(npts), erroff(npts);

	int icol = wksData.Columns("RINGCUR").GetIndex();
    if (icol<0)
	{   // for compatibility reasons the existence of this column is checked
    	icol =	wksData.AddCol("RINGCUR");
   		wksData.Columns(icol).SetType(OKDATAOBJ_DESIGNATION_Y);
   		wksData.Columns(icol).SetFormat(OKCOLTYPE_TEXT_NUMERIC);
   		wksData.Columns(icol).SetWidth(8);
	}
	Dataset ringcur(wksData,icol); ringcur.SetSize(npts);
    
	// write coefficients of sensitivity function to worksheet column
	senscoef[0]=photodiode;
    for (ii = 1; ii<ncoeff; ii++) senscoef[ii] = quantumyield(0,photodiode,ii);
		
    if(recalc_flag) 
    {

   		double meastime = PARval[0]*PARval[1];
    	for (ii=0; ii<npts; ii++)
    	{
    		phflux[ii] *= sens[ii];
    	    sens[ii] = quantumyield(ehv[ii],photodiode);
    	    phflux[ii] /= sens[ii];
    		if (timeon[ii]>0) meastime = timeon[ii];
    		erron[ii]=sqrt(ctson[ii]/meastime);
    		if (timeoff[ii]>0) meastime = timeoff[ii];
    		erroff[ii]=sqrt(ctsoff[ii]/meastime);
    		if (icurValue>0)
    		{
    			 icuron[ii] = icurValue;
    			icuroff[ii] = icurValue;
    		}
    	}
    	goto final_calculation;
    }

   	int clock_flag = 0; 	// indicates whether clock data columns are present

    // read header
    header = "";
    if (filetype==1)
    { 
    	for(ii = 0; ii<headerlines; ii++) 
    	{
   			fascii.ReadString(line);
    		if ((ii!=0) && (ii!=3) && (ii!=4) && (ii!=7) && (ii<headerlines-4)) 
    		{
   	  	  		line.Replace('#',' ');line.Replace('\x09',' ');
    	  		header += line; 
    	  		if ((ii==1) || (ii==2) || (ii==8) || (ii==10)) { header += ' ';} 
    	  		else { header += '\n';}
    		}
    		//if (ii==19) clock_flag = (line.Find("meas time")>0); //@todo check for external clock
    	}   
    }
    else if (filetype==2)
    {
    	for(ii = 0; ii<headerlines; ii++) 
    	{
   			fascii.ReadString(line);
    		if (ii==(headerlines-1)) continue;
  	  	  	line.Replace('#',' ');
    	  	header += line+'\n'; 
    	}   
    }
    header.Replace('\r',' ');
    
    // read dwelltime and number of sweeps from header
   	double dwelltime; int nsweeps=1;
   	string helpstr;

    int istrpos = header.Find("dwell time:")+12;
   	helpstr = header.Mid(istrpos,5);
   	helpstr.Write(0);
    dwelltime = atof(helpstr);
    PARname.SetText(0,"dwelltime (s):");
    PARval[0] = dwelltime;
  
    if (filetype==1)
    {
   		istrpos = header.Find("Number of Sweeps:")+17;
   		helpstr=header.Mid(istrpos);
    	nsweeps = atoi(helpstr);
    }
    PARname.SetText(1,"sweeps:");
    PARval[1] = nsweeps;
   	double meastime = dwelltime*nsweeps; // total time per point in s
    
    
   	PARname.SetText(2,"dark photons subtracted:");
   	if (phdark_subtract) { PARval.SetText(2,"yes"); }
   		else             { PARval.SetText(2,"no"); }
   	PARname.SetText(3,"photon Ampere meter range (A):");
   	PARval[3] = 2E-7*pow(10,phAmMeter_range);
   	PARname.SetText(4,"photon VFC gain:");
   	PARval[4] = phVFC_gain;
   	PARname.SetText(5,"ion Ampere meter range (A):");
   	PARval[5] = 2E-12*pow(10,icurAmMeter_range);
   	PARname.SetText(6,"icur VFC gain:");
   	PARval[6] = icurVFC_gain;
   	PARname.SetText(7,"ion charge:");
   	PARval[7] = ion_charge;
   	PARname.SetText(8,"ion mass (amu):");
   	PARval = ion_mass;
   	PARname.SetText(9,"acceleration voltage (kV):");
   	PARval[9] = acc_voltage;
   	PARname.SetText(10,"form factor (1/cm):");
   	PARval[10] = formfactor;
   	PARname.SetText(11,"photodiode:");
   	PARval[11] = photodiode;
   	PARname.SetText(12,"filetype:");
   	PARval[12] = filetype;
   	PARname.SetText(13,"external clock frequency (MHz):");
   	PARval[13] = clockfrequency;
   	PARname.SetText(14,"unmeasured ion current (A):");
 	if (icurValue >0) { PARval[14] = icurValue; } else { PARval.SetText(14,""); }
   	if (clockfrequency<=1e-9)
   	{ // do not use clock data when clockfreuquency is zero 
   		clock_flag = 0;
   	}
   	else
   	{
  		clockfrequency*=1E6; // conversion from MHz to Hz
   	}
      	
   	if (phVFC_gain<=0)
    {   // no calibration of photon flux (arbitrary units)
    	phVFC_gain = 1;
    	wksData.Columns(wksData.Columns("PHFLUX").GetIndex()).SetLabel("arb. u.");
   		for (ii=3;ii<=4;ii++) PARval.SetText(ii,"arbitrary");
    }
    else
    {   // photon flux in photons/s
    	wksData.Columns(wksData.Columns("PHFLUX").GetIndex()).SetLabel("(#ph/s)");
    }
    if (icurVFC_gain<=0)
    {   // no calibration of ion current (arbitrary units)
    	icurVFC_gain = 1;
    	wksData.Columns(wksData.Columns("ICURON").GetIndex()).SetLabel("arb. u.");
    	wksData.Columns(wksData.Columns("ICUROFF").GetIndex()).SetLabel("arb. u.");  	
   		for (ii=5;ii<=10;ii++) PARval.SetText(ii,"arbitrary");
    }
	else
    {   // ion current in A
    	wksData.Columns(wksData.Columns("ICURON").GetIndex()).SetLabel("A");
    	wksData.Columns(wksData.Columns("ICUROFF").GetIndex()).SetLabel("A");
    }

   	// ion current calibration factor (VFC frequency -> Amperes)
   	// the smalles range of the Ampere meter is 20 pA
   	// the Ampere meter converts the measure current to a voltage (2V at full range)
   	// the VFC converts 1V to 10^5 Hz x gain
   	double icurfactor = 1E-12*pow(10,icurAmMeter_range)/(1E5*icurVFC_gain);
  	
   	// read data
	double ph_curr;
    for(ii = 0; ii< npts; ii++)
    {
    	fascii.ReadString(line);
    	//int clock_flag = (line.GetNumTokens()>11);
    	string str0 = line.GetToken(0); 
    	string str1 = line.GetToken(1);   
    	string str2 = line.GetToken(2);
    	string str3 = line.GetToken(3);
    	string str4 = line.GetToken(4);
    	string str5 = line.GetToken(5);
    	string str6 = line.GetToken(6);
    	string str7 = line.GetToken(7);
    	string str8 = line.GetToken(8);
    	string str9 = line.GetToken(9);
    	string str10 = line.GetToken(10);
    	string str11 = line.GetToken(11);
    	string str12 = line.GetToken(12);
    	ehv[ii] = atof(str0);
    	sens[ii] = quantumyield(ehv[ii],photodiode);
    	if (filetype==1)
    	{ // from IPB program
    		// data from chopper open period
    		clock_flag =0;
    		if (clock_flag)
    		{   // timining is provided by external clock
   				timeon[ii]  = atof(str11)/clockfrequency;
   				meastime = timeon[ii];
    		}
    		ctson[ii]   = atof(str5)/meastime;         // count rate with photon beam on
    		erron[ii]   = sqrt(atof(str5))/meastime;   // statistical error
    		icuron[ii]  = icurValue > 0? icurValue : atof(str7)/meastime*icurfactor; // ion current
    		phflux[ii]  = (atof(str9)-phdark_subtract*atof(str10))/meastime;   // VFC frequency
            // data from chopper closed period
    		if (clock_flag)
    		{   // timing is provided by external clock
    			timeoff[ii] = atof(str12)/clockfrequency; 
   				meastime = timeon[ii];
    		}
   			if (timeoff[ii] > 0) meastime = timeoff[ii];
    		ctsoff[ii]  = atof(str6)/meastime;        // count rate with photon beam off
    		erroff[ii]  = sqrt(atof(str6))/meastime;  // statistical error
    		icuroff[ii] = icurValue > 0? icurValue : atof(str8)/meastime*icurfactor;
    		// note that the number of photon VFC counts recorded  during the 
    		// 'photons off' phases, i.e. the photodiodes dark current, is subtracted.
    	}
    	else if (filetype==2)
    	{  // from Six Counters program 
 	    	ctson[ii] = atof(str8)/meastime;             // count rate with photon beam on
    		erron[ii] = sqrt(atof(str8))/meastime;       // statistical error
   			ctsoff[ii] = 0;//atof(str6)/meastime;        // count rate with photon beam off
    		erroff[ii] = 0;//sqrt(atof(str6))/meastime;  // statistical error
    		icuron[ii] = atof(str5)/meastime*icurfactor; // ion current
    		icuroff[ii] = atof(str6)/meastime*icurfactor;
    		phflux[ii] = atof(str7)/meastime;//-phdark_subtract*atof(str10))/meastime; // VFC frequency
    		string str13 = line.GetToken(13);
    		ringcur[ii] = atof(str13)*0.001; //ALS rings current in A 
    	}
        // calculation of photon flux
        // for the function ALSphVFCcal see ALSsens.cxx
    	ph_curr = ALSphVFCcal(phflux[ii], phAmMeter_range, phVFC_gain);
    	phflux[ii]  = ph_curr/sens[ii]/eCharge; 
    }
    
    
    // smooth the ion current
   	Dataset icuron_smoothed, icuroff_smoothed;
   	
    if (nsmooth>0)
    {
        // smooth ion current data by averaging over "nsmooth" neighbouring data points
    	nsmooth = (nsmooth - mod(nsmooth,2))/2;
    	
    	int colnum1 = wksData.AddCol("Ionsmoo");
    	int colnum2 = wksData.AddCol("Ioffsmoo");
    	icuron_smoothed.Attach(wksData,colnum1);
    	icuroff_smoothed.Attach(wksData,colnum2);
    	icuron_smoothed.SetSize(npts);
    	icuroff_smoothed.SetSize(npts);

    	int scount = 0;
    	double sumon = 0.0, sumoff = 0.0;
        
    	for (ii=0; ii<nsmooth; ii++)
    	{
    		scount++;
    		sumon  += icuron[ii];
    		sumoff += icuroff[ii];
    	}
    	for (ii=0; ii<npts; ii++)
    	{
    		if (ii>nsmooth) 
    		{
    			sumon   -= icuron[ii-nsmooth-1];
    		    sumoff  -= icuroff[ii-nsmooth-1];
    		}
    		else {scount++;}
    		if (ii<(npts-nsmooth))
    		{
            sumon  += icuron[ii+nsmooth];
            sumoff += icuroff[ii+nsmooth];
    		}
    		else {scount--;}
    		icuron_smoothed[ii] = sumon/scount;
    		icuroff_smoothed[ii] = sumoff/scount;
    	}
    }
    else if (nsmooth<0)
    {
    	// fit polynomial of degree "-nsmooth" to ion current data
    	int colnum1 = wksData.AddCol("Ionpoly");
    	int colnum2 = wksData.AddCol("Ioffpoly");
    	icuron_smoothed.Attach(wksData,colnum1);
    	icuroff_smoothed.Attach(wksData,colnum2);
    	icuron_smoothed.SetSize(npts);
    	icuroff_smoothed.SetSize(npts);
    	
    	int ipolyorder = -nsmooth;
    	if (ipolyorder>9) ipolyorder=9;
        double icuroncoeff[10],icuroffcoeff[10];

    	Curve cicuron(ehv,icuron);
        Curve cicuroff(ehv,icuroff);

        fitpoly(cicuron,  ipolyorder, &icuroncoeff);
        fitpoly(cicuroff, ipolyorder, &icuroffcoeff);
        
    	for (ii=0;ii<npts;ii++)
    	{
    		double pon = icuroncoeff[ipolyorder];
    		double poff = icuroffcoeff[ipolyorder];
    		
    		for (int jj=ipolyorder-1;jj>=0;jj--)
    		{
	            pon  =  pon*ehv[ii]+icuroncoeff[jj];   			
    	        poff = poff*ehv[ii]+icuroffcoeff[jj];   			
    		}
    		icuron_smoothed[ii]  = pon;
    		icuroff_smoothed[ii] = poff;
    	}
   	}
    
    // smooth the photon flux
   	Dataset phflux_smoothed;
   	
    if (msmooth>0)
    {
        // smooth photon flux data by averaging over "msmooth" neighbouring data points
    	msmooth = (msmooth - mod(msmooth,2))/2;
    	
    	int colnum1 = wksData.AddCol("phflsmoo");
    	phflux_smoothed.Attach(wksData,colnum1);
    	phflux_smoothed.SetSize(npts);

    	int scount = 0;
    	double sumon = 0.0;
        
    	for (ii=0; ii<msmooth; ii++)
    	{
    		scount++;
    		sumon  += phflux[ii];
    	}
    	for (ii=0; ii<npts; ii++)
    	{
    		if (ii>msmooth) 
    		{
    			sumon   -= phflux[ii-msmooth-1];
    		}
    		else {scount++;}
    		if (ii<(npts-msmooth))
    		{
            sumon  += phflux[ii+msmooth];
    		}
    		else {scount--;}
    		phflux_smoothed[ii] = sumon/scount;
    	}
    }
    else if (msmooth<0)
    {
    	// fit polynomial of degree "-nsmooth" photon flux data
    	int colnum1 = wksData.AddCol("phflpoly");
    	phflux_smoothed.Attach(wksData,colnum1);
    	phflux_smoothed.SetSize(npts);
    	
    	int ipolyorder = -msmooth;
    	if (ipolyorder>9) ipolyorder=9;
        double phfluxcoeff[10];

    	Curve cphflux(ehv,phflux);

        fitpoly(cphflux, ipolyorder, &phfluxcoeff);
        
    	for (ii=0;ii<npts;ii++)
    	{
    		double pon = phfluxcoeff[ipolyorder];
    		
    		for (int jj=ipolyorder-1;jj>=0;jj--)
    		{
	            pon  =  pon*ehv[ii]+phfluxcoeff[jj];   			
    		}
    		phflux_smoothed[ii]  = pon;
    	}
   	}
    
    final_calculation:	
	// Calculate normalized counts and statistical errors
    double counts, staterr, factor;
 
    for(int jj = 0; jj < npts; jj++)
    {	
        factor = Xsec_factor;
        if (photodiode>1)
        {
        	if (msmooth!=0)
        	{
        		if (phflux_smoothed[jj]>0) factor /= phflux_smoothed[jj];
        	}
        	else
        	{
        		if (phflux[jj]>0) factor /= phflux[jj];
        	}
        }
        
        if (nsmooth!=0)
        {
            counts = ctson[jj]/icuron_smoothed[jj];
            staterr = pow(erron[jj]/icuron_smoothed[jj],2);
        	if (icuroff_smoothed[jj]>0) 
        	{
        		counts -= ctsoff[jj]/icuroff_smoothed[jj];
        		staterr += pow(erroff[jj]/icuroff_smoothed[jj],2);
        	}
        }
        else
        {
            counts = ctson[jj]/icuron[jj];
            staterr = pow(erron[jj]/icuron[jj],2);
            if (icuroff[jj]>0)
            {
        		counts -= ctsoff[jj]/icuroff[jj];
        		staterr += pow(erroff[jj]/icuroff[jj],2);
        	}
        }
        ncts[jj] = factor*counts;
        cerror[jj] = factor*sqrt(staterr);
	}	
	return;// header;
}

/**
 * @brief Reads an ALS ascii data file (origin v7.5)
 */
string ReadALSasciiFileS(string filename, int filetype, string wksname, int photodiode, double formfactor, double clockfrequency, 
                        int phAmMeter_range, int phVFC_gain, int phdark_subtract, int icurAmMeter_range, int icurVFC_gain, 
                        int ion_charge, double ion_mass, double acc_voltage, double icurValue, int nsmooth, int msmooth)
{
	string header;
    ReadALSasciiFile(filename, filetype, wksname, photodiode, formfactor, clockfrequency,  phAmMeter_range, phVFC_gain, phdark_subtract, icurAmMeter_range, icurVFC_gain, 
                        ion_charge, ion_mass, acc_voltage, icurValue, nsmooth, msmooth, header);
	
	return header;
}

///////////////////////////// LabTalk Code //////////////////////////////////////////
//
// LabTalk code that follows will be ignored by the OriginC compiler because of the 
// ifdef statement. The LabTalk interpreter will however read and execute this section
//

#ifdef LABTALK

[ALSimport]
    echo=1;
	errcode=-1;
	run.section(%yOriginC\als\ALSinitScripts,init,errcode);
	if (errcode>0) return;
 
	system.numeric.separators=1; /* use numeric format 1,000.0 */
	type.clearResults(); /* clear results window */
	type.redirection=2; /* output to notes window */
    type.notes$ = import.list;
    if (exist(import.list)!=9) win -n n import.list;
    
	// use fdlog object to launch dialog for selecting file
	run.section(File,Init);
	fdlog.useGroup(ASCII);
	fdlog.addType("[*.DAT] *.DAT");
	fdlog.ShowComment=0;
	fdlog.dlgName$="Open photon-ion data file";
	fdlog.defType=5;
	if(fdlog.Open(A)) return 1;
	%B=fdlog.path$;
	// At this point, the file path and name are in the LabTalk variables %B and %A

	// Construct name for worksheet
	%k = %[%A,'.'];
    filetype = 1; // regular data file
	if (%[%k,1:3]==XAS)
	{ 
		filetype=2;  // XAS data file
		%k=%[%k,4:%[%k]];
	}
	%w = A%k;
    if (exist(%w)==2) win -cd %w; // delete existing worksheet 

	clockfrequency = 1; // frequency of external clock in MHz
    formfactor = 300;
    iselect = 1;
    fhvselect = 1;
    %Z = ALSphotodiodes(0)$;
    %L = (none) (smooth) (polyfit);
   	icurValue = 0;
    getn
		(photodiode) diode:Z
    	(clock frequency (MHz)) clockfrequency
		(ion current smoothing) iselect:L
		(photon flux smoothing) fhvselect:L
        (use calibrated photon flux?) phcal:2		
        (use calibrated ion current?) icurcal:2h		
    	(ion current (nA)) icurValue
     	(ALSimportASCII. v7.2);
    icurValue *= 1e-9;
    
    phdarkSubtract = 0; 	
    if (phcal)
    {
        %Z = (2 muA) (20 muA) (200 muA) (2 mA);
    	getn 
    	   (range of Ampere meter) phAmMeterRange:Z
    	   (gain of VFC) phVFCgain
    	   (subtract dark counts) phdarkSubtract:2
    	(input data for photon flux calibration);
    }
    else
    {
    	phAmMeterRange = 0;
    	phVFCgain = 0;
    }
    
    if (icurcal)
    {
        %Z = (20 pA) (200 pA) (2 nA) (20 nA) (200 nA) (2 muA);
    	getn 
    	   (range of Ampere meter) icurAmMeterRange:Z
    	   (gain of VFC) icurVFCgain
    	   (ion charge) ionCharge
    	   (ion mass (amu)) ionMass
    	   (acceleration voltage (kV)) accVoltage
    	   (formfactor (1/cm)) formfactor
    	(input data for ion current calibration);
    }
    else
    {
    	formfactor = 300;
    	icurAmMeterRange = 3;
    	icurVFCgain = 0;
    	ionCharge = 1;
    	ionMass = 12;
    	accVoltage = 6;
    }
    if ((diode==1)&&(fhvselect>1))
    {
    	fhvselect=1;
    	type -c "No photodiode selected, photon flux smoothing not possible!"
    }
    
    switch (iselect)
    {
    	case 1: ionsmooth = 0; 
    		    break;
    	case 2: %s = smoo;
    	        ionsmooth = 23;
     		    getn 
        		    (number of points) ionsmooth
     				(smoothing of ion current);
     		 	break;
     	case 3: %s = poly;
     	        ionsmooth = 2;
     	     	getn		 
        	    	(polynomial degree) ionsmooth
     				(ion current fitting);
        		 	ionsmooth = -ionsmooth;	// negative value indicates fit
     		 	break;
     	default: ionsmooth = 0;		 
    }
     
    switch (fhvselect)
    {
    	case 1: fhvsmooth = 0; 
    		    break;
    	case 2: %t = smoo;
    		    fhvsmooth = 23;
     		    getn 
        		    (number of points) fhvsmooth
     				(smoothing of photon flux);
     		 	break;
     	case 3: %t = poly;
     		    fhvsmooth = 2;
     	     	getn		 
        	    	(polynomial degree) fhvsmooth
     				(photon flux fitting);
     		 	fhvsmooth = -fhvsmooth;	// negative value indicates fit
     		 	break;
     	default: fhvsmooth = 0;		 
    }
    
	// Call OriginC function to read from the file
	%z=%B%A;
	if (@V<8.0)
	{ // Origin v7.5
		%z = ReadALSasciiFileS(%z,filetype,%w,diode,formfactor,clockfrequency,phAmMeterRange,phVFCgain,phdarkSubtract,
		                      icurAmMeterRange,icurVFCgain,ionCharge,ionMass,accVoltage,icurValue,ionsmooth,fhvsmooth)$;                 
	}
	else
	{ // Origin 8.0 and higher
    	string header$;
    	ReadALSasciiFile(%z,filetype,%w,diode,formfactor,clockfrequency,phAmMeterRange,phVFCgain,phdarkSubtract,
	    	                icurAmMeterRange,icurVFCgain,ionCharge,ionMass,accVoltage,icurValue,ionsmooth,fhvsmooth,header$);                 
    	%z = header$;                  
	}
	system.font.LabelSize=14;
    label -d 10 20 -s %z;
	window -a %w;
	%w_senscoef[1]$ = ALSphotodiodes(diode)$;

	window -z;

	window -i %H;

	get %w_ehv -e imax;
	emin = %w_ehv[1];
	emax = %w_ehv[imax];
	type "%k      [$(emin) - $(emax)]";

	if (iselect>1)
	{ // plot result from ion current smoothing
    	/* create a graph window from template	*/
    	if (exist(I%k)!=3) win -e I%k %Y\OriginC\ALS\ALSglue.OTP; 
		window -z I%k;
    	label -yl ion current (counts);
                   ALSplot1(%w,I%k,"EHV","ICUROFF","",2,1);
        %l=IOFF%s; ALSplot1(%w,I%k,"EHV",%l,"",3,0);
                   ALSplot1(%w,I%k,"EHV","ICURON","",0,1);
        %l=ION%s;  ALSplot1(%w,I%k,"EHV",%l,"",1,0);
        layer.x.rescale=1;
        layer.y.rescale=3;
        layer -a;
	}

	if (fhvselect>1)
	{ // plot result from photon flux smoothing
    	/* create a graph window from template	*/
    	if (exist(P%k)!=3) win -e P%k %Y\OriginC\ALS\ALSglue.OTP; 
		window -z P%k;
    	label -yl photon flux (counts);
                   ALSplot1(%w,P%k,"EHV","PHFLUX","",0,1);
        %l=PHFL%t; ALSplot1(%w,P%k,"EHV",%l,"",1,0);
        layer.x.rescale=1;
        layer.y.rescale=3;
        layer -a;
	}

    /* create a graph window from template	*/
    if (exist(G%k)!=3) win -e G%k %Y\OriginC\ALS\ALSglue.OTP; 
    win -a G%k;
    ALSplot1(%w,G%k,"EHV","NCTS","ERROR");
    win -z G%k;

return;    
//////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

[reimport]


if (exist(%w)!=2) 
{
	%t = filename$;
	type -b worksheet %w does not exist, pick data file manually;
	run.section(,ALSimport);
	return;
}

clockfrequency = 1; // clock frequency in MHz
phAmMeterRange = 2;
phVFCgain = 1;
phdarkSubtract = 0;
icurAmMeterRange = 1;
icurVFCgain = 1;
ionCharge = 1; 
ionMass = 12;
accVoltage = 6;
formfactor=300; 
diode = 4;
filetype = 1;
icurValue = 0;
  
if (%w_parval[4]$!="arbitrary")  { phAmMeterRange  = %w_parval[4]; }
if (%w_parval[5]$!="arbitrary")  { phVFCgain = %w_parval[5]; }
if (%w_parval[3]$=="yes")        { phdarkSubtract = 1;} 
if (%w_parval[6]$!="arbitrary")  { icurAmMeterRange = %w_parval[6]; } 
if (%w_parval[7]$!="arbitrary")  { icurVFCgain = %w_parval[7]; }
if (%w_parval$!="arbitrary")  { ionCharge = %w_parval; }
if (%w_parval[9]$!="arbitrary")  { ionMass = %w_parval[9]; }
if (%w_parval[10]$!="arbitrary") { accVoltage = %w_parval[10]; }
if (%w_parval[11]$!="arbitrary") { formfactor = %w_parval[11]; }
if (%w_parval[12]$!="") { diode = %w_parval[12]; }  
if (%w_parval[12]$!="") { filetype = %w_parval[13];}
if (%w_parval[14]$!="arbitrary") { clockfrequency = %w_parval[14]; }
if (%w_parval[15]$!="") { icurValue = %w_parval[15]; }
if (exist(%w)==2) win -cd %w;

%k=%[%w,2:%[%w]]; // %k is the data file name without extension
if (filetype == 2) { filename$=XAS%k.dat; } else { filename$=%k.dat; }

if (%[%k]>8) // check length of filename
{ // newer format
	fyear$ = %[%k,1:2]; 
	fmonth$ = %[%k,3:4];
	fday$ = %[%k,5:6];
	%z = ALSfilename(%p,fyear$,fmonth$,fday$,filename$,1)$;
}
else
{ // older format
    fyear$=%[%p,%[%p]-1:%[%p]];
	fmonth$ = %[%k,1:2]; 
	fday$ = %[%k,3:4]; 
	%z = ALSfilename(%p,fyear$,fmonth$,fday$,filename$,0)$;
}

if (@V<8.0)
{
	%z = ReadALSasciiFileS(%z,filetype,%w,diode,formfactor,clockfrequency,phAmMeterRange,phVFCgain,phdarkSubtract,
	                      icurAmMeterRange,icurVFCgain,ionCharge,ionMass,accVoltage,icurValue,ionsmooth,fhvsmooth)$;                 
}
else
{
    string header$;
    ReadALSasciiFile(%z,filetype,%w,diode,formfactor,clockfrequency,phAmMeterRange,phVFCgain,phdarkSubtract,
	                    icurAmMeterRange,icurVFCgain,ionCharge,ionMass,accVoltage,icurValue,ionsmooth,fhvsmooth,header$);                 
    %z = header$;                  
}

window -a %w;
system.font.LabelSize=14;
label -d 10 20 -s %z;
window -a %w;
%w_senscoef[1]$ = ALSphotodiodes(diode)$;
				  
/* create a graph window from template	*/
if (exist(G%k)!=3) win -e G%k %Y\OriginC\ALS\ALSglue.OTP; 
win -a G%k;
ALSplot1(%w,G%k,"EHV","NCTS","ERROR");
win -z G%k;
					  
return;
    
[recalc]
%w = %h; // recalc ist called from a button in the worksheet itself

clockfrequency = 1; // clock frequency in MHz
phAmMeterRange = 2;
phVFCgain = 1;
phdarkSubtract = 0;
icurAmMeterRange = 1;
icurVFCgain = 1;
ionCharge = 1; 
ionMass = 12;
accVoltage = 6;
formfactor=300; 
diode = 4;
filetype = 1;
icurValue = 0;
  
if (%w_parval[4]$!="arbitrary")  { phAmMeterRange  = log(%w_parval[4]/2E-7); }
if (%w_parval[5]$!="arbitrary")  { phVFCgain = %w_parval[5]; }
if (%w_parval[3]$=="yes")        { phdarkSubtract = 1;} 
if (%w_parval[6]$!="arbitrary")  { icurAmMeterRange = log(%w_parval[6]/2E-12); } 
if (%w_parval[7]$!="arbitrary")  { icurVFCgain = %w_parval[7]; }
if (%w_parval$!="arbitrary")  { ionCharge = %w_parval; }
if (%w_parval[9]$!="arbitrary")  { ionMass = %w_parval[9]; }
if (%w_parval[10]$!="arbitrary") { accVoltage = %w_parval[10]; }
if (%w_parval[11]$!="arbitrary") { formfactor = %w_parval[11]; }
if (%w_parval[12]$!="") { diode = %w_parval[12]; }  
if (%w_parval[12]$!="") { filetype = %w_parval[13];}
if (%w_parval[14]$!="arbitrary") { clockfrequency = %w_parval[14]; }
if (%w_parval[15]$!="") { icurValue = %w_parval[15]; }

//if (exist(%w)==2) win -cd %w;

if (@V<8.0)
{
	%z = ReadALSasciiFileS("***recalc***",filetype,%w,diode,formfactor,clockfrequency,phAmMeterRange,phVFCgain,phdarkSubtract,
	                      icurAmMeterRange,icurVFCgain,ionCharge,ionMass,accVoltage,icurValue,ionsmooth,fhvsmooth)$;                 
}
else
{
    string header$;
    ReadALSasciiFile("***recalc***",filetype,%w,diode,formfactor,clockfrequency,phAmMeterRange,phVFCgain,phdarkSubtract,
	                    icurAmMeterRange,icurVFCgain,ionCharge,ionMass,accVoltage,icurValue,ionsmooth,fhvsmooth,header$);                 
    %z = header$;                  
}
#endif
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 11/15/2009 :  6:47:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Looks like the problem is related to passing LT string by ref into OC numeric function, while string functions works.


int ff1(int nn, string& str)
{
	string strTemp;	
	strTemp.Format("%d:%s", nn, str);	
	str = strTemp;
	return 2;
}

string ss1(int n1, int n2, int n3, int n4, int n5, int n6, string& str)
{
	string strTemp;
	strTemp.Format("%d:%s", n1, str);
	str = strTemp;
	return strTemp + " end";
}



I tried the above two functions and ff1 failed while ss1 works.

I called with following LT code for ss1


string str$="abc";
%Z=ss1(1,2,3,4,5,6,str$)$;
%Z=;
str$=;


We will see if we can fix this for 81 SR1.

CP
Go to Top of Page

Stefan.E.S

Germany
11 Posts

Posted - 11/16/2009 :  03:17:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by cpyang

We will see if we can fix this for 81 SR1.

CP




Please let me know in case the problem will have been fixed.

Stefan
Go to Top of Page

Echo_Chu

China
Posts

Posted - 11/23/2009 :  04:03:59 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Stefan.E.S


Please let me know in case the problem will have been fixed.

Stefan



Hi, Stefan,

We have submitted a tracker, tr#14669, for it and have got it fixed in our in-house build. You should able to use it when Origin 8.1 SR1 is released

Echo
OriginLab Corp
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000