////////////////////////////////////////////////////////////////////////////////
// Filename:		BATCH.OGS
// Creation:		by Lorraine Weibel, 6/1/96
// Purpose:		Demonstration of a simple LabTalk batch process routine
// Modifications:	SDB-Updated for Origin 6.0
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
// Main Section
// This code calls other specialized sections to accomplish the main task.
//
// Execute script:  run.section(Batch,Main);
// Operations: 
//	1. Import each file into a new worksheet
//	2. Plot all data in worksheet to a graph window
//	3. Perform Linear fit from Simplefit code in LR.OGS
//	4. Report Slope and Intercept values to Results log for each fit
////////////////////////////////////////////////////////////////////////////////
[Main]
	FDLOG.multiopen.colview=12;		//12/7/98 new property for dialog options
	FDLOG.UseGroup(Ascii);			//Open ASCII files
	if (FDLOG.multiopen()==0/0)
		return 1;

	loop(ii,1,FDlog.MultiOpen.Count)
	{
		FDlog.Get(A, ii);
		win -t data;
		open -w %A;
		run.section(,Plot,%H);	//Run Plot section
		run.section(,Fit);
	}


[Plot]
	win -t plot Origin;   		//Bring up origin.otp
	layer -w %1 201;			//Include worksheet data in the active layer
	layer -a;			//Rescale x and y axes 
	return 0; 

[Fit]
	type.BeginResults();		/// RKM 12/10/98 v6.0141 REPORT_TO_OUTPUTLOG
	layer -c;
	loop(ii,1,count)
	{
		%C=%[%Z,#ii];
		run.section(lr,simplefit);
		run.section(,Results,%[%Z,#ii]);
	};
	type.EndResults();
	return 0;

[Results]
	SaveRedirection=type.Redirection(16,3);		//SDB 1/7/99 REPORT_TO_OUTPUTLOG
	type -a "Slope of %1 is $(stat.lr.b)"; 		//Returns slope
	type -a "Y-Intercept of %1 is $(stat.lr.a)"; 	//Returns y-intercept value
	type;						//Type out an extra line.
	type.Redirection=SaveRedirection; 		//restore previous redirection.
	delete -v SaveRedirection;
	return 0;