[proFit-list] Set column type in Applescript

Ludovic Pecqueur lpecqueur at lebs.cnrs-gif.fr
Sun Nov 15 06:11:30 CST 2009


Dear all,

I am using the batch Processing script but I am encountering a problem
due to a type mismatch.
I want to fit several files, then report in a table all the wanted
parameters as well as which original data they correspond to (ie name of
the table). To do that, I first use the Batch Processing Applescript
which calls my program "SingleFit" (see below).

The error comes from the line :
* data[globalData[0],1] := WindowName;
*Where I suspect the program wants a real number instead of a string.
I tried to define the first column as a string with:
SetColumnProperties(col 1, name 'Exp', type textColumn);)
but it did not do the trick.

Is there any way to declare * data[globalData[0],1]  *as a string in the
applescript or in the program itself?

Thank you for your help,

Ludovic


---------------------------------------------------------------------------------------------------

Applescript:
-- bring up a dialog for selecting the folder
set myFolder to choose folder with prompt "Choose a folder with data files:"

-- create a list with all files in the folder
set myFiles to list folder myFolder -- a list of files in myFolder
set myFileCount to count myFiles -- the number of files in myFolder

-- now start fitting with pro Fit
tell application "pro Fit 6.1.11"
    activate -- bring pro Fit to front
    set error alerts to false -- disable error reports within pro Fit
    make new table -- open a data window for storing our results
    set name of front window to "Result data" -- and set its name
    set nrCols of front window to 15 -- set ncol to 15
    set globalData 0 to 0 -- this is our window counter
    repeat with i from 1 to myFileCount
        set theFile to item i of myFiles -- get the i-th file
        try
            set foldName to ((myFolder as string) & theFile)
            open foldName as data window -- open file
            write line "processing: " & theFile
            run program "SingleFit" -- run the program in pro Fit
            close window theFile saving no -- close without saving
        on error errText
            write line "cannot process: " & theFile & " (" & errText & ")"
        end try
    end repeat
    set error alerts to true -- enable error reports within pro Fit
end tell


---------------------------------------------------------------------------------------------------


Profit program:

function ExpAssoc3;
    description
        'y := y0+A1*(1-exp(-R1*x)) + A2*(1-exp(-R2*x))+ A3*(1-exp(-R3*x))';
parameters 7;
inputs
a[1]:=0, active, 'y0', 0, inf;
a[2]:=100, active, 'A1', 0, inf;
a[3]:=1e-1, active, 'R1', 0, inf;
a[4]:=50, active, 'A2', 0, inf;
a[5]:=1e-2, active, 'R2', 0, inf;
a[6]:=25, active, 'A3', 0, inf;
a[7]:=1e-3, active, 'R3', 0, inf;
begin
y := a[1]+ a[2]*(1-exp(-a[3]*x)) + a[4]*(1-exp(-a[5]*x)) +
a[6]*(1-exp(-a[7]*x))
end;

program SingleFit;
var
WindowName:string;
begin
  globalData[0] := globalData[0]+1;           {increase window counter}
  SetCurrentWindow(FrontWindow);     {use data of front window for fit}
  *WindowName:=GetWindowProperty(FrontWindow, name);*
  Statistics(column 2, withBasic False);
  SetFunctionParam('ExpAssoc3', 1,0);              {set starting parameters}
  SetFunctionParam('ExpAssoc3', 2,GetResult(statMaximum));              
{these values depend on}
  SetFunctionParam('ExpAssoc3', 3,0.1);                  {your model and
data}
  SetFunctionParam('ExpAssoc3', 4,GetResult(statMaximum));
  SetFunctionParam('ExpAssoc3', 5,0.1);
  SetFunctionParam('ExpAssoc3', 6,GetResult(statMaximum));
  SetFunctionParam('ExpAssoc3', 7,0.01);
  Fit(function 'ExpAssoc3',algorithm robust, xColumn 1,yColumn 2,
printResults True); {run the fit}                    
  SetCurrentWindow(GetWindowID('Result data'));    {window for results}
  if NumFitParams <> 0 then                 {if the fit was successful}
  begin
     SetColumnProperties(col 1, name 'Exp', type textColumn);
     SetColumnProperties(col 2, name 'y0');
     SetColumnProperties(col 3, name 'A1');
     SetColumnProperties(col 4, name 'R1');
     SetColumnProperties(col 5, name 'A2');
     SetColumnProperties(col 6, name 'R2');
     SetColumnProperties(col 7, name 'A3');
     SetColumnProperties(col 8, name 'R3');
     SetColumnProperties(col 9, name 'Chi2');
     SetColumnProperties(col 10, name 'DoF');
     SetColumnProperties(col 11, name 'Chi2/DoF');
    
    * data[globalData[0],1] := WindowName; *  *Here is the error's origin*
     data[globalData[0],2] := FittedParams(1);            {get results}
     data[globalData[0],3] := FittedParams(2);
     data[globalData[0],4] := FittedParams(3);
     data[globalData[0],5] := FittedParams(4);
     data[globalData[0],6] := FittedParams(5);
     data[globalData[0],7] := FittedParams(6);
     data[globalData[0],8] := FittedParams(7);
     data[globalData[0],9] := GetResult(chiSquared);
     data[globalData[0],10] :=
GetResult(nrDataPoints)-GetResult(nrFittedParameters);
     data[globalData[0],11] :=
GetResult(chiSquared)/(GetResult(nrDataPoints)-GetResult(nrFittedParameters));
    
     Tabulate(function 'ExpAssoc3', from 0, to 550,step pointsStep,
fittedParams True);
    
     SetDataPointStyle (0,1,0);
     PlotData(window GetCurrentWindow(dataType),plotType scatterPlot,
xAxisColumn 1, yAxisColumn 3,xFirst 0, xLast 550, autoY True,
              newWindow True, newGraph True, xScaling linScaling,
                yScaling linScaling, xAxis 1, yAxis 1, xLabel 'Time
(s)', yLabel 'F505',
                pointType 0, pointsRed 0, pointsGreen 0, pointsBlue 0);
     MakeTicks (xAxis, 0,50,4);
     PlotData(window GetCurrentWindow(dataType),plotType scatterPlot,
xAxisColumn 1, yAxisColumn 2,xFirst 0, xLast 550, autoY True,
                newWindow False, newGraph False,
              drawPoints False, connected True, curveRed 65535,
curveThickness 2);
     MakeTicks (xAxis, 0,50,4);
     PlotData(window GetCurrentWindow(dataType),plotType scatterPlot,
xAxisColumn 1, yAxisColumn 4,xFirst 0, xLast 550, autoY True,
              newWindow False, newGraph False, xScaling linScaling,
                yScaling linScaling, xAxis 1, yAxis 1, xLabel 'Time
(s)', yLabel 'F505',
                pointType 0, pointsRed 0, pointsGreen 0, pointsBlue 0);
     MakeTicks (xAxis, 0,50,4);
     CloseWindow(window WindowName, saveOption dontSave); {close initial
data window}
  end;
end;

-- 
*****************************************************************
Dr. Ludovic Pecqueur
CNRS
LEBS UPR3082
Rue de la terrasse - Bât 34
91198 Gif sur Yvette

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://quantum-soft.com/pipermail/profit-list_quantum-soft.com/attachments/20091115/44150a45/attachment.html>


More information about the proFit-list mailing list