/* -------------------------------------------------------------------------- *
 *	File Name:		matrix.ogs                                                *
 *	Purpose:		some matrix menu implementations                          *
 *	Author:			ML                                                        *
 *	Date:			8/16/95                                                   *
 *	Copyright:		Microcal Software, Inc. 1995                              *
 *                                                                            *
 *	Modification log:       RKM 11/09/96 added for Origin 5.0 [Dimension][Coordinates]
 *				[Values][Transpose]	                                                  *
 * -------------------------------------------------------------------------- */
 
[Rotate90]
	matrix -id;// check convert to data
	matrix -Convert R;
	return 0;
	
[Flip_V]
	matrix -id;// check convert to data
	matrix -Convert V;
	return 0;
	
[Flip_H]
	matrix -id;// check convert to data
	matrix -Convert H;
	return 0;
	
[Expand]
	matrix -id;// check convert to data
	getn  	$Matrix.ExpandColumns mat.expand.col
		$Matrix.ExpandRows mat.expand.row
		$Matrix.ExpandExpand; 
	mat.matname$ = %H;
	//mat.errout = 2;  
	mat.expand();
	return 0;

[Shrink]
	matrix -id;// check convert to data

	getn  	$Matrix.ShrinkColumns mat.shrink.col
		$Matrix.ShrinkRows mat.shrink.row
		$Matrix.ShrinkShrink; 
	mat.matname$ = %H;
	mat.shrink();
	return 0;

[Inverse]
	matrix -id;// check convert to data
	mat.matname$ = %H;
	// mat.errout = 2;  
	if(mat.inv()!=0)
	{
		switch(mat.lasterrid())
		{
			case 1220:
				type -b $Matrix.SingularError;
				break;
			case 1221:
				type -b $Matrix.SquareError;
				break;
			default:
				type -b $Matrix.GeneralInverse;
				break;
		}
	}
	return 0;

[Mat2Wks]
	matrix -id;// check convert to data

	mat.matname$ = %H;
	win -T wks;     
	mat.wksname$ = %H;
	//mat.errout = 2; 
	mat.m2w();
	return 0;

[Test]
	type -B $Plot.Matrix;
	return 0;

[Dimension]
	matrix -e Dim;
	return 0;

[Coordinates]
	matrix -e Map;
	return 0;

[Values]
	matrix -e;
	return 0;

[Transpose]
	matrix -id;// check convert to data
	matrix -Transpose;
	return 0;

[Smooth]
	matrix -id;// check convert to data
	type -C $Matrix.SmoothPrompt;
	mat.matname$ = %H;
	matrix  -pg DIM nc nr;
	if(nc < 32 || nr < 32)
	{
		mat.expand(2,2);
		mat.shrink(2,2);
	}
	else
	{		
		mat.shrink(2,2);
		mat.expand(2,2);
	};
	return 0;

[Integrate]
	matrix -id;// check convert to data
	mat.matname$ = %H;
	mat.integrate(ii);
	SaveRedirection=type.Redirection(16,3);
	type.BeginResults();
	type;
	type $Matrix.IntegResults;
	type.EndResults();
	type.Redirection=SaveRedirection; // restore previous redirection.
	delete -v SaveRedirection;
	return 0;	

[ConvXYZ]
	matrix -id;// check convert to data
	mat.matname$ = %H;
	%A=$Matrix.ConvXYZConstant;
	getn $Matrix.ConvXYZType mat.type:A
	$Matrix.ConvXYZTitle;
	win -T wks xyz; 
	mat.wksname$ = %H;
	mat.m2xyz();
	return 0;

[Tuning]
	if(dialog.status(OTools.dll,Tuning))
	{
		dialog.start(OTools.dll,Tuning);
	}
	else
	{
		dialog.close(OTools.dll,Tuning);
	}
	return 0;

[ConvertToData]
	matrix -in;	// check convert image to data without asking
	return 0;

[Replace]
	// Open Dialog Builder Matrix Replace dialog box
	run.section(DBRoutines.OGS,SaveAndSetAtOC);

	if(run.section(DBRoutines.OGS,LoadOMatWorkspace)==0)
		OnOpenMR();
	
	run.section(DBRoutines.OGS,RestoreAtOC);
	
	return 0;