⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 minitab.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------*
 * File Name: minitab.c															*
 * Creation: GD 7/10/2001														*
 * Purpose: Origin C file														*
 * Copyright (c) OriginLab Corp. 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007	*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 * EJP 11-11-2003 v7.5750 QA70-5516 CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH*
 *------------------------------------------------------------------------------*/
 
////////////////////////////////////////////////////////////////////////////////////
// you must include this header file for all Origin built-in functions and classes
#include <origin.h>
//
////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////
// start your functions here

#include "minitab.h"

#define		DATATYPE_UNKNOWN		0
#define		DATATYPE_NUMERIC		1
#define		DATATYPE_DATE			2
#define		DATATYPE_TEXT			3

#define		SORTORDER_ALPHA			0
#define		SORTORDER_OCCUR			1
#define		SORTORDER_USER			2

#define		MINIMISSING				1.23456E30
#define		DATEOFFSET				2415018


// main
int readminitab( String filename, String strWksName )
{
	file		fid;
	int			iFileSize=0;

	Header1		Hdr1;			// size is 80
	Header2		Hdr2;			// size is 60
	Header3		Hdr3;			// size is 37
	Pre			DataPreamble;	// size is 60
	int			iDataType=0;
	PostN		NumericHdr;		// size is 43
	PostN12		Numeric12Hdr;	// size is 34
	PostD		DateHdr;		// size is 47
	PostD12		Date12Hdr;		// size is 38?
	PostT		TextHdr;		// size is 35
	PostT12		Text12Hdr;		// size is 26

	int			iBytesRead = 0;
	char		cVersion[3];	// file version : 12 and 13 supported
	int			iVersion = 0;	// file version : 12 and 13 supported
	int			iLength = 0;	// Generic, used for string reads
	char		Buffer[256];	// Generic, used for string reads
	int			iLoop = 0;		// Generic, used for loops
	int			iPos = 0;		// Generic, used for file position
	int			idatasize = 0;
	int 		iTemp = 0;
	int			iStatus = 0;
	int			iStrSize = 0;

	const double	DateOffset = 2415018; 	// 2415018 days difference in date systems
	const int		Err1 = 1;				// Failed to open file.
	const int		Err2 = 2;				// Column synchronization failure (v12).
	const int		Err3 = 3;				// Column synchronization failure.
	const int		Err4 = 4;				// Field width and string length do not match.
	const int		Err5 = 5;				// Unknown datatype.
	const int		Err6 = 6;				// File too small.
	const int		Err7 = 7;				// Unsupported version for datatype 0.
	const int		Err9 = 9;				// Special error 9. Contact OriginLab Corporation.

	// Begin
	if( fid.Open(filename, file::modeRead) )
	{
		iFileSize = fid.SeekToEnd();

		// If the file is too small to evaluate, just exit
		if(iFileSize<sizeof(Hdr1)+sizeof(Hdr2)+sizeof(Hdr3)+sizeof(DataPreamble))
		{
			LT_set_var("mntbversion", iVersion);
			LT_execute("type -a MiniTab v$(mntbversion);");
			LT_execute("type $OMRDMNTB.errors.err6;");
			fid.Close();
			return Err6;
		}
		fid.SeekToBegin();
		
		// Read Header1 and determine version
		// I will let pass versions greater than 13 and attempt to read them as v13 (with warning)
		// I will let pass versions less than 12 and attempt to read them as v12 (with warning)
		iBytesRead = fid.Read(&Hdr1, sizeof(Hdr1));
		iVersion=0;
		cVersion[0]=Hdr1.ID[3];
		cVersion[1]=Hdr1.ID[4];
		cVersion[2]='\x00';
		iVersion = atoi(cVersion);
		// Let them try any version - so what if it fails, we warned them!
		if(13 != iVersion && 12 != iVersion) {
			LT_set_var("mntbversion", iVersion);
			LT_execute("type -a MiniTab v$(mntbversion).;");
			LT_execute("type -a $OMRDMNTB.warning.warn1;");
		}
		
		// Setup %Z in LabTalk - which will contain header text information
		// Strings in Minitab are an integer containing Length followed by Length characters
		Buffer[0]=0;
		LT_set_str("%Z", Buffer);
		
		// Read and append Name field (to %Z)
		iBytesRead = fid.Read(&iLength, sizeof(iLength));
		if(iLength)
		{
			fid.Read(&Buffer, iLength);
			Buffer[iLength] = 0;
			LT_set_str("%N",Buffer);
			LT_execute("page.label$=%N;page.title=3;%Z=%Z (%N)");
		}
		
		// Read and append User Name field (to %Z)
		iBytesRead = fid.Read(&iLength, sizeof(iLength));
		if(iLength)
		{
			fid.Read(&Buffer, iLength);
			Buffer[iLength] = 0;
			LT_set_str("%N", Buffer);
			LT_execute("%Z=%Z (%N);");
		}
		
		// Read and append Date (to %Z) - could be any text actually
		iBytesRead = fid.Read(&iLength, sizeof(iLength));
		if(iLength)
		{
			fid.Read(&Buffer, iLength);
			Buffer[iLength] = 0;
			LT_set_str("%N", Buffer);
			LT_execute("%Z=%Z (%N);");
		}
		
		// Read and append Notes (to %Z)
		iBytesRead = fid.Read(&iLength, sizeof(iLength));
		if(iLength)
		{
			fid.Read(&Buffer, iLength);
			Buffer[iLength] = 0;
			LT_set_str("%N", Buffer);
			LT_execute("%Z=%Z (%N);");
		}
		
		// Read Header2 - I don't know what any of this means
		iBytesRead = fid.Read(&Hdr2, sizeof(Hdr2)); // All unknowns

		// Read Data Font - the font for Data display - Don't use, but we could
		iBytesRead = fid.Read(&iLength, sizeof(iLength));
		if(iLength)
		{
			fid.Read(&Buffer, iLength);
			Buffer[iLength] = 0;
		}
		
		// Read Label Font - the font for Label Display - Don't use, and we could not anyway
		iBytesRead = fid.Read(&iLength, sizeof(iLength));
		if(iLength)
		{
			fid.Read(&Buffer, iLength);
			Buffer[iLength] = 0;
		}
		
		// Read Header3 - I don't know what any of this means, either
		iBytesRead = fid.Read(&Hdr3, sizeof(Hdr3)); // More unknowns
		
		// Check for valid column data
		// This corrects a problem with a few version 13 files that are missing Hdr3.var9
		if(13 <= iVersion && 3 == Hdr3.var9)
		{
			// Just backup file pointer
			iPos = fid.GetPosition();
			iPos -= 4;
			fid.Seek(iPos, file::begin);
		}
		
		// This corrects a difference for version 13 files that do not have Hdr3.var8 and Hdr3.var9
		if(12 >= iVersion)
		{
			// Backup file pointer by Hdr3.var8 (a double) and Hdr3.var9 (an integer)
			iPos = fid.GetPosition();
			// following line of code did not compile (sizeof fails with structure member)
			// iPos -= (sizeof(Hdr3.var8) + sizeof(Hdr3.var9));
			iPos -= 12;
			fid.Seek(iPos, file::begin);
			// Now do our test for valid column data. This integer should be 3
			iBytesRead = fid.Read(&iTemp, sizeof(iTemp));
			if(iTemp!=3)
			{
				LT_set_var("mntbversion", iVersion);
				LT_execute("type -a MiniTab v$(mntbversion).;");
				LT_execute("type -a $OMRDMNTB.errors.err2;");
				fid.Close();
				return Err2;
			}
			fid.Seek(iPos, file::begin);
		}
		
		// Setup the worksheet with the correct number of columns
		LT_set_var("ncols",Hdr1.NCols);
		LT_execute("wo -a $(ncols-wks.ncols);");
		
		// Use this to replace MiniTab missing values with Origin missing values
		LT_set_var("MNTBMISSING", MINIMISSING);
		
		// For each column
		for(iLoop = 1;iLoop <= Hdr1.NCols; iLoop++)
		{
			// Read the Preamble - Column Number, Number of Rows and SortOrder flag
			iBytesRead = fid.Read(&DataPreamble, sizeof(DataPreamble));
			
			// This is my test for valid column data - see Check for valid column data
			if(3 != DataPreamble.var1)
			{
				LT_set_var("mntbversion", iVersion);
				LT_execute("type -a MiniTab v$(mntbversion).;");
				LT_execute("type $OMRDMNTB.Errors.Err3;");
				fid.Close();
				return Err3;
			}
			
			// Read the Amble - contains Column Label, Column Description and DataType
			
			// Column Label
			iBytesRead = fid.Read(&iLength, sizeof(iLength));
			if(iLength)
			{
				fid.Read(&Buffer, iLength);
				Buffer[iLength] = 0;
				LT_set_var("mntbthiscol",DataPreamble.ColNum);
				LT_set_str("%N", Buffer);
				LT_execute("wks.col$(mntbthiscol).label$=%N;");
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -