STATISTICA







STATISTICA BASIC Program TwoDataFiles.stb

{ This example demonstrates one of the many uses of the STATISTICA Development Environment. This program produces & saves a multiple scatterplot which uses data from two separate STATISTICA data files.

Program written, modified, or edited at StatSoft, Inc.}


RandomAccess;
{declare the Stadev functions}
{$I:'stadev.inc'}

{prompt the user for two data files and open those files}
if (SelectOpenFileName ('Open File 1', File1$, 'sta')=0) then goto ErrorExit;
handle1:=StaOpenFile(File1$);
if (SelectOpenFileName ('Open File 2', File2$, 'sta')=0) then goto ErrorExit;
handle2:=StaOpenFile(File2$);

{assign the data in columns 1 and 2 of the first data file to the x1 and y1 arrays respectively}
cases1:=StaGetNCases(handle1);
ReDim x1(cases1);
ReDim y1(cases1);
for i:=1 to cases1 do begin
  StaGetData(handle1, 1, i, x1(i));
  StaGetData(handle1, 2, i, y1(i));
end;

{create a scatterplot with the values in the x1 and y1 arrays}
mygraph:=NewGraph (SCATTERPLOT, 'Multiple Scatterplot', 'Y Values', 'X Values', cases1, x1, y1);

{prompt the user to specify a fit type for this plot}
if (DisplaySelectionBox ('Choose fit type for data from file 1',
'FIT_LINEAR|FIT_LOG|FIT_EXP|FIT_SPLINE|FIT_POLYNOMIAL|FIT_LEASTSQUARES|FIT_NEGEXP',
select1, 1)=0) then goto ErrorExit;

{set the specified fit type}
GraphSetPlotFitting (mygraph, 1, select1);

{assign the data in columns 1 and 2 of the second data file to the x2 and y2 arrays respectively}
cases2:=StaGetNCases(handle2);
ReDim x2(cases2);
ReDim y2(cases2);
for i:=1 to cases2 do begin
  StaGetData(handle2, 1, i, x2(i));
  StaGetData(handle2, 2, i, y2(i));
end;

{add a scatter type plot with the values in the x2 and y2 arrays to the the existing graph}
plot2:=GraphAddPlot (mygraph, SCATTERPLOT, ?Name$, cases2, x2, y2);

{prompt the user to specify a fit type for this plot}
if (DisplaySelectionBox ('Choose fit type for data from file 2',
'FIT_LINEAR|FIT_LOG|FIT_EXP|FIT_SPLINE|FIT_POLYNOMIAL|FIT_LEASTSQUARES|FIT_NEGEXP',
select2, 1)=0) then goto ErrorExit;

{set the specified fit type}
GraphSetPlotFitting (mygraph, 2, select2);

{display the graph}
DisplayGraph(mygraph);

{prompt the user to save the graph}
if SelectSaveFileName ('Save the graph as', newfile$, 'stg') then begin
 SaveGraph (mygraph, newfile$);
 mygraph2:=OpenGraph(newfile$);
 end
else goto ErrorExit;

{close all open data files}
StaCloseFile(handle1);
StaCloseFile(handle2);
exit;

{close all open data files in case of any error above}
ErrorExit:
StaCloseFile(handle1);
StaCloseFile(handle2);

exit;
Back to List of Programs



[StatSoft]
2300 East 14th Street, Tulsa, OK 74104
Phone: (918) 749-1119; Fax: (918) 749-2217

[StatSoft]e-mail: info@statsoft.com

©Copyright StatSoft, Inc., 1984-2004.
StatSoft, StatSoft logo, STATISTICA, SEWSS, SEDAS, Data Miner, SEPATH and GTrees are trademarks of StatSoft, Inc.