📄 minitab.c
字号:
// Column Description
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);");
}
// Column DataType
iBytesRead = fid.Read(&iDataType, sizeof(iDataType));
// Read the Postamble based on the DataType - the actual data is read here
switch(iDataType)
{
case DATATYPE_UNKNOWN:
if(12 == iVersion || 13 == iVersion)
{
if(12 == iVersion)
{
iBytesRead = fid.Read(&Buffer, 26);
}
else
{
iBytesRead = fid.Read(&NumericHdr, sizeof(NumericHdr));
}
}
else
{
LT_set_var("mntbversion", iVersion);
LT_execute("type -a MiniTab v$(mntbversion).;");
LT_execute("type -a $OMRDMNTB.errors.err7;");
fid.Close();
return Err7;
}
break;
case DATATYPE_NUMERIC:
if(13 <= iVersion)
{
iBytesRead = fid.Read(&NumericHdr, sizeof(NumericHdr));
LT_set_var("mntbthiscol",DataPreamble.ColNum);
LT_set_var("mntbthiswidth", NumericHdr.Width);
LT_execute("wks.col$(mntbthiscol).width=mntbthiswidth;");
}
else
{
iBytesRead = fid.Read(&Numeric12Hdr, sizeof(Numeric12Hdr));
}
iStatus = read_numeric_data(fid, strWksName, DataPreamble.ColNum, DataPreamble.Rows1);
break;
case DATATYPE_DATE:
if(13 <= iVersion)
{
iBytesRead = fid.Read(&DateHdr, sizeof(DateHdr));
LT_set_var("mntbthiscol",DataPreamble.ColNum);
LT_set_var("mntbthiswidth", NumericHdr.Width);
LT_execute("wks.col$(mntbthiscol).width=mntbthiswidth;");
}
else
{
iBytesRead = fid.Read(&Date12Hdr, sizeof(Date12Hdr));
}
iStatus = read_date_data(fid, strWksName, DataPreamble.ColNum, DataPreamble.Rows1);
break;
case DATATYPE_TEXT:
if(13 <= iVersion)
{
iBytesRead = fid.Read(&TextHdr, sizeof(TextHdr));
iStrSize = TextHdr.NumChars;
LT_set_var("mntbthiscol",DataPreamble.ColNum);
LT_set_var("mntbthiswidth", NumericHdr.Width);
LT_set_var("mntbthislen", iStrSize + 1);
}
else
{
iBytesRead = fid.Read(&Text12Hdr, sizeof(Text12Hdr));
iStrSize = Text12Hdr.NumChars;
}
iStatus = read_text_data(fid, strWksName, DataPreamble.ColNum, DataPreamble.Rows1, DataPreamble.SortOrder, iStrSize, iVersion);
break;
default:
LT_set_var("mntbversion", iVersion);
LT_execute("type -a Minitab $(mntbversion).;");
LT_execute("type -a $OMRDMNTB.errors.err5;");
fid.Close();
return Err5;
} // end of switch based on DATATYPE
} // end of 'for each column'
fid.Close();
LT_execute("wks.labels();");
} // end if - opening file
else
{
LT_set_var("mntbversion", iVersion);
LT_execute("type -a MiniTab v$(mntbversion).;");
LT_execute("type -a $OMRDMNTB.errors.err1");
fid.Close();
return Err1;
}
return 0;
}
// Read Numeric data into the correct column of the worksheet
int read_numeric_data(file &fid, string TheWorksheet, uint TheColumn, uint NumRows)
{
int iBytesRead;
// link to dataset, set column format to Numeric, set Dataset size
/// EJP 11-11-2003 v7.5750 QA70-5516 CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
///Dataset ThisCol(TheWorksheet, TheColumn - 1);
/// end CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
LT_set_var("mntbthiscol",TheColumn);
LT_execute("wks.col$(mntbthiscol).format=1;");
/// EJP 11-11-2003 v7.5750 QA70-5516 CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
Dataset ThisCol(TheWorksheet, TheColumn - 1);
/// end CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
ThisCol.SetSize(NumRows);
// Read the data into Origin, replace MiniTab Missing with Origin Missing
iBytesRead = fid.Read(&ThisCol, NumRows * sizeof(double));
LT_execute("wcol(mntbthiscol)=wcol(mntbthiscol)==MNTBMISSING?0/0:wcol(mntbthiscol);");
return 0;
}
// Read Date data into the correct column of the worksheet
int read_date_data(file &fid, string strWksName, uint TheColumn, uint NumRows)
{
int iBytesRead;
// link to dataset, set column format to Date, set Dataset size
/// EJP 11-11-2003 v7.5750 QA70-5516 CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
///Dataset ThisCol(strWksName, TheColumn - 1);
/// end CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
LT_set_var("mntbthiscol",TheColumn);
LT_set_var("mntbDateOffset", DATEOFFSET);
LT_execute("wks.col$(mntbthiscol).format=4;");
/// EJP 11-11-2003 v7.5750 QA70-5516 CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
Dataset ThisCol(strWksName, TheColumn - 1);
/// end CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
ThisCol.SetSize(NumRows);
// Read the data into Origin, replace MiniTab Missing wit Origin Missing
iBytesRead = fid.Read(&ThisCol, NumRows * sizeof(double));
LT_execute("wcol(mntbthiscol)=wcol(mntbthiscol)==MNTBMISSING?0/0:wcol(mntbthiscol);");
// Adjust for MiniTab Date system
LT_execute("wcol(mntbthiscol)+=mntbDATEOFFSET;");
return 0;
}
// Read Text data into the correct column of the worksheet
int read_text_data(file &fid, string strWksName, uint TheColumn, uint NumRows, uint TheSortOrder, uint TheStringSize, uint TheVersion)
{
int iLoop = 0;
int iBytesRead = 0;
int iLength = 0;
char Buffer[256];
int iPos = 0;
// link to dataset, set column format to Text, set dataset size
/// EJP 11-11-2003 v7.5750 QA70-5516 CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
///Dataset ThisCol(strWksName, TheColumn - 1);
///ThisCol.SetSize(NumRows);
///LT_execute("wks.col$(mntbthiscol).format=2;");
LT_execute("wks.col$(mntbthiscol).format=7;");
/// end CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
if(13 <= TheVersion)
{
LT_execute("wks.col$(mntbthiscol).width=mntbthiswidth;");
LT_execute("wks.col$(mntbthiscol).twidth=mntbthislen;");
}
/// EJP 11-11-2003 v7.5750 QA70-5516 CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
Dataset ThisCol(strWksName, TheColumn - 1);
ThisCol.SetSize(NumRows);
/// end CHANGING_COL_FORMAT_CAUSES_DATASET_TO_DETACH
// For each row
for(iLoop = 0; iLoop < NumRows; iLoop++)
{
iBytesRead = fid.Read(&iLength, sizeof(iLength));
iBytesRead = fid.Read(&Buffer, iLength);
Buffer[iLength] = 0;
ThisCol.SetText(iLoop, Buffer);
} // end 'For each row'
// for Text - check for SortOrder of User AND that the first integer is not 3
iPos = fid.GetPosition(); // mark position
iBytesRead = fid.Read(&iLength, sizeof(iLength));
fid.Seek(iPos, file::begin); // go back
// Only Text data has this feature, just guessing when datablock is 'doubled
if(SORTORDER_USER == TheSortOrder && 3 != iLength)
{
if(13 <= TheVersion)
{
iPos += NumRows * (sizeof(iLength) + TheStringSize);
}
else
{
iPos += NumRows * (sizeof(iLength) + TheStringSize);
}
fid.Seek(iPos, file::begin);
}
return 0;
}
// The filter function version
int ImportMinitab(Page& pgTarget, TreeNode& trFilter, LPCSTR lpcszFile, int nFile)
{
double dResult;
string strName;
if(pgTarget.GetType() == EXIST_WKS)
{
pgTarget.GetName(strName);
}
else
{
WorksheetPage pg;
pg.Create("origin.otp");
pg.GetName(strName);
}
LT_set_str("%B",strName);
LT_execute("win -a %B;");
LT_set_str("%A", lpcszFile );
LT_execute("run.section(ordMNTB,Init);result = run.section(ordMNTB,Import);");
LT_get_var("result", &dResult);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -