The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Binary Import
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Dominik Paulkowski

Germany
Posts

Posted - 01/16/2007 :  08:41:43 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): Origin7.5G SR6 (v7.5886)
Operating System: Windows XP

Hello!

It's very applicable to use binary data files, to store measured values. To analyse them I need to import these data files into Origin. But therefor I need some help.

The headertext in these data files is like:
"
A lot of headertext..
.....
....

...
Binary Data
...

# Mearuring Time .. (column titles)...
"

The binary data starts in a new line.

I've already tried the following, to import binary the data files:

#include <..\OriginLab\Wks_Utils.h> // wuRenameToFileName function
#include <..\OriginLab\BinImp.h> // Function prototypes and non-localized constants
typedef void (*FUNCTYPE)(Worksheet wks, string &strFileName, BINIMP &binimp); // definition to find a function in another c-file

//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------

// Function to read file and look for marker
// Note that the search for marker is case sensitive
static int find_header_marker(string strFile, string strMarker)
{

stdioFile ff;
bool bRet = ff.Open(strFile, file::modeRead);

if( !bRet ) return -1;

int nMarkerLine = -2;
string strTemp;
int iLine = 1;

while( ff.ReadString(strTemp) )
{
if( strTemp.Find(strMarker) != -1 )
{
nMarkerLine = iLine;
break;
}
iLine++;
}

ff.Close();

return nMarkerLine;
}

//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------

static int count_header_bytes(string strFile, int nNumberOfLines)
{
stdioFile ff;
bool bRet = ff.Open(strFile, file::modeRead);

if( !bRet ) return -1;

int nHeaderBytes = 0;
string strTemp;
int iLine = 1;

for( iLine = 1; iLine <= nNumberOfLines; iLine++)
{
ff.ReadString(strTemp);
nHeaderBytes = strTemp.GetLength() + nHeaderBytes;
}

ff.Close();

return nHeaderBytes;

}

//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------

void importprocedure()
{

string strFileName;//= "xy.dat";

// Find where header stops
int nHdrLines = find_header_marker(strFileName, "#");

if( nHdrLines >= 1 ) // if there is a header-marker
{
// Check if there are binary data
int nBinaer = find_header_marker(saFilePaths[i], "Binary Data");
// If there is noch "Binary Data" in the header the line number nBinaer is "0"

if( nBinaer < 1 ) // start ASCII-Import
{
// Get current ascimp settings from worksheet
ASCIMP ascimp;

// ......
// http://www.originlab.com/forum/topic.asp?TOPIC_ID=5310
}
else
{
BINIMP binimp; // PROBLEM: compling is fine. but if I use this "the pointer is not initialized"

int iHeaderBytes = count_header_bytes(saFilePaths[i], nHdrLines); //number of bytes for header
printf("HeaderBytes = %d\n", iHeaderBytes);
int iAutoColTypes = 0; //indicate if set col type explicitly
int iNumColumns = 4; //number of columns
//int iPartial; //indicate partial data will be read from the file
//int iPartialC1; //partial reading start column number, 0 based, include this column
//int iPartialC2; //partial reading end column number, this column will not be included
//int iPartialR1; //partial reading start row number, 0 based, this row will be included
//int iPartialR2; //partial reading end row number, this row will not be included
int iRenameWks = 0; // keep current name //if rename worksheet name to the file name
int iBigEndian = 0; //=0 LittleEndian; numeric value byte order, use big endian if TRUE
//int iApplyRange; //
int iMode = ASCIMP_MODE_REPLACE_DATA;

// Path to another Origin C-file
//string strBinImpCPath = strUserPath + "Tribo\BinImp.c";
string strBinImpCPath = GetAppPath(true) + "OriginC\OriginLab\BinImp.c"; // false fuer User-Unterverzeichnis; true fuer Origin-Root
//string strBinImpCPathWks_Utils = GetAppPath(true) + "OriginC\\OriginLab\\Wks_Utils.c";

// Find the function "importData" in another Origin C-file
FUNCTYPE BinaryImport = Project.FindFunction("importData", strBinImpCPath);
//FindEmptyColumn(Worksheet &wks, int nStartCol)

BinaryImport(wks, saFilePaths[i], binimp); // start binary import (It will do that by setting each cell in the worksheet)

//--------------------------------------------------------------------------------------
// Or calling filter file
//--------------------------------------------------------------------------------------
/**
// Path to another Origin C-file
string strOriginCPath = GetAppPath(true) + "OriginC\OriginLab\ImportFile.c"; // false fuer User-Unterverzeichnis; true fuer Origin-Root

// Find the function "importData" in another Origin C-file
FUNCTYPE callImportFile = Project.FindFunction("ImportFile", strOriginCPath);

// Path to a filter-file
string strFilterFile = strUserPath + "abc.oif";

// http://www.originlab.com/forum/topic.asp?TOPIC_ID=3216
int iRet = callImportFile( wpg, strFilterFile, saFilePaths[i] ); // PROBLEM: I cannot compile, because "the variable types are not compatible"
if( iRet != 0 )
{
printf("Import failed with error: %d\n", iRet);
wpg.Destroy();
return;
}
*/

} // end of else (than it's binary)
} // end if there is headertext





} // end of void

-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany

Edited by - Dominik Paulkowski on 01/18/2007 08:09:33 AM

Dominik Paulkowski

Germany
Posts

Posted - 01/16/2007 :  08:53:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
<Edit>The other double thread should be deleted.</Edit>

-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany

Edited by - Dominik Paulkowski on 01/18/2007 08:17:04 AM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/16/2007 :  11:03:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I'm not sure what you are asking. Does the code you've shown us fail? If so, where and how?

BTW, you can delete your own post with the trash can icon in its header.

Mike Buess
Origin WebRing Member
Go to Top of Page

Dominik Paulkowski

Germany
Posts

Posted - 01/17/2007 :  02:59:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Problem is the bold text in thread:
--(here was a link)---

<Edit> The bold text in this thread show the problems</Edit>

Trash Icon:
After entering Password: "No Permissions to Delete Topic"

-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany

Edited by - Dominik Paulkowski on 01/18/2007 08:15:37 AM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/17/2007 :  1:49:05 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The compiler error occurs because callImportFile (1) does not match your FUNCTYPE prototype and (2) is defined in FileImport.c rather tha ImportFile.c. You can probably fix that by correcting the file name in strOriginCPath and adding a second typedef for the ImportFile function. However, if you are using the ImportWizard all the functions you need (except maybe yours) will already be compiled and you can prototype the ImportFile and ImportData functions directly like this...

// top of your OC file...
#include <..\OriginLab\Wks_Utils.h> // might not be necessary
#include <..\OriginLab\BinImp.h> // this defines the BINIMP structure
int importData(Worksheet& wks, file& fDataFile, BINIMP *pbi);
int ImportFile(Page &pgTarget, LPCSTR lpcszFilter, LPCSTR lpcszFile, int nFile);

If you aren't using the IW you can compile its files with run.loadOC(OriginLab\ImportWiz.ocw).

I also noticed that you are accessing elements of the ASCIMP and BINIMP structs incorrectly. For example,

ASCIMP ascimp;
BINIMP binimp;
int iMode = ASCIMP_MODE_REPLACE_DATA; // incorrect
ascimp.iMode = ASCIMP_MODE_REPLACE_DATA; // set import mode for ASCII import
binimp.iMode = ASCIMP_MODE_APPEND_COLS; // set import mode for binary import

I'm sure that doesn't cover everything so please post again if you have more questions.

Mike Buess
Origin WebRing Member
Go to Top of Page

Dominik Paulkowski

Germany
Posts

Posted - 01/18/2007 :  08:38:24 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Very well, thank you. But I really have more questions.

quote:

// top of your OC file...
#include <..\OriginLab\BinImp.h> // this defines the BINIMP structure
int importData(Worksheet& wks, file& fDataFile, BINIMP *pbi);
int ImportFile(Page &pgTarget, LPCSTR lpcszFilter, LPCSTR lpcszFile, int nFile);

If you aren't using the IW you can compile its files with run.loadOC(OriginLab\ImportWiz.ocw).



Using the filterfile-method:

If I type in run.loadOC(OriginLab\ImportWiz.ocw) at the script window and try to compile my origin c-file, it compiles well and I can import my data.

But if I want to use it automatic in the c-script, like

// Compile files of Import Wizard. Then the function body of "ImportFile" should be available.
LT_execute("run.loadOC(OriginLab\ImportWiz.ocw);");

I cannot compile my c-script.

quote:

I also noticed that you are accessing elements of the ASCIMP and BINIMP structs incorrectly. For example,

ASCIMP ascimp;
BINIMP binimp;
int iMode = ASCIMP_MODE_REPLACE_DATA; // incorrect
ascimp.iMode = ASCIMP_MODE_REPLACE_DATA; // set import mode for ASCII import
binimp.iMode = ASCIMP_MODE_APPEND_COLS; // set import mode for binary import



Using the BINIMP-method:

I now use

binimp.iMode = ASCIMP_MODE_REPLACE_DATA; // set import mode for binary import


Compiling is fine. But when I'm using the script to import my data, the old error occurs.

The script now looks like:

//-----------------------------------------------------------------------
#include <..\OriginLab\BinImp.h> // Function prototypes and non-localized constants // defines the BINIMP structure
int importData(Worksheet& wks, file& fDataFile, BINIMP *pbi);
int ImportFile(Page &pgTarget, LPCSTR lpcszFilter, LPCSTR lpcszFile, int nFile);
typedef void (*FUNCTYPE)(WorksheetPage wpg, string &strFilterFile, string &strDataFileName, int &nFile); // definition to find a function in another c-file
typedef void (*FUNCTYPEbinimp)(Worksheet wks, string &strFileName, BINIMP &binimp); // definition to find a function in another c-file

void importprocedure()
{

string strFileName;//= "xy.dat";

// Find where header stops
int nHdrLines = find_header_marker(strFileName, "#");

if( nHdrLines >= 1 ) // if there is a header-marker
{
// Check if there are binary data
int nBinaer = find_header_marker(saFilePaths[i], "Binary Data");
// If there is noch "Binary Data" in the header the line number nBinaer is "0"

if( nBinaer < 1 ) // start ASCII-Import
{
// Get current ascimp settings from worksheet
ASCIMP ascimp;

// ......
// http://www.originlab.com/forum/topic.asp?TOPIC_ID=5310
}
else
{
BINIMP binimp; // PROBLEM: compling is fine. but if I use this "the pointer is not initialized"

int iHeaderBytes = count_header_bytes(saFilePaths[i], nHdrLines); //number of bytes for header
printf("HeaderBytes = %d\n", iHeaderBytes);
int iAutoColTypes = 0; //indicate if set col type explicitly
int iNumColumns = 4; //number of columns
//int iPartial; //indicate partial data will be read from the file
//int iPartialC1; //partial reading start column number, 0 based, include this column
//int iPartialC2; //partial reading end column number, this column will not be included
//int iPartialR1; //partial reading start row number, 0 based, this row will be included
//int iPartialR2; //partial reading end row number, this row will not be included
int iRenameWks = 0; // keep current name //if rename worksheet name to the file name
int iBigEndian = 0; //=0 LittleEndian; numeric value byte order, use big endian if TRUE
//int iApplyRange; //
binimp.iMode = ASCIMP_MODE_REPLACE_DATA; //ASCIMP_MODE_APPEND_COLS;

// Path to another Origin C-file
//string strBinImpCPath = strUserPath + "Tribo\BinImp.c";
string strBinImpCPath = GetAppPath(true) + "OriginC\OriginLab\BinImp.c"; // false fuer User-Unterverzeichnis; true fuer Origin-Root
//string strBinImpCPathWks_Utils = GetAppPath(true) + "OriginC\\OriginLab\\Wks_Utils.c";

// Find the function "importData" in another Origin C-file
FUNCTYPEbinimp BinaryImport = Project.FindFunction("importData", strBinImpCPath);
//FindEmptyColumn(Worksheet &wks, int nStartCol)

BinaryImport(wks, saFilePaths[i], binimp); // start binary import (It will do that by setting each cell in the worksheet)

//--------------------------------------------------------------------------------------
// Or calling filter file
//--------------------------------------------------------------------------------------
/**
// Path to another Origin C-file
string strOriginCPath = GetAppPath(true) + "OriginC\OriginLab\FileImport.c"; // false fuer User-Unterverzeichnis; true fuer Origin-Root

// Find the function "importData" in another Origin C-file
FUNCTYPE callImportFile = Project.FindFunction("ImportFile", strOriginCPath);

// Path to a filter-file
string strFilterFile = strUserPath + "abc.oif";
string strDataFileName;

// Compile files of Import Wizard. Then the function body of "ImportFile" should be available.
LT_execute("run.loadOC(OriginLab\ImportWiz.ocw);"); // works fine, if typed in at the script window an then compile this c-file

// http://www.originlab.com/forum/topic.asp?TOPIC_ID=3216
int iRet = ImportFile( wpg, strFilterFile, strDataFileName, 0 ); // Compiles only, if I type run.LoadOC at the script window //Here was the old problem
if( iRet != 0 )
{
printf("Import failed with error: %d\n", iRet);
wpg.Destroy();
return;
}
*/

} // end of else (than it's binary)
} // end if there is headertext

} // end of void
//-----------------------------------------------------------------------

-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany

Edited by - Dominik Paulkowski on 01/18/2007 08:43:37 AM

Edited by - Dominik Paulkowski on 01/18/2007 08:46:11 AM

Edited by - Dominik Paulkowski on 01/18/2007 08:48:04 AM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/19/2007 :  09:18:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Using the BINIMP-method:

I now use

binimp.iMode = ASCIMP_MODE_REPLACE_DATA; // set import mode for binary import

Compiling is fine. But when I'm using the script to import my data, the old error occurs.
You must address all BINIMP properties like that, not only binimp.iMode.

BINIMP binimp; // PROBLEM: compling is fine. but if I use this "the pointer is not initialized"
//int iHeaderBytes = count_header_bytes(saFilePaths[i], nHdrLines); //number of bytes for header
binimp.iHeaderBytes = count_header_bytes(saFilePaths[i], nHdrLines);
printf("HeaderBytes = %d\n", binimp.iHeaderBytes);
//int iAutoColTypes = 0; //indicate if set col type explicitly
binimp.iAutoColTypes = 0;
//int iNumColumns = 4; //number of columns
binimp.iNumColumns = 4;
//int iRenameWks = 0; // keep current name //if rename worksheet name to the file name
binimp.iRenameWks = 0;
//int iBigEndian = 0; //=0 LittleEndian; numeric value byte order, use big endian if TRUE
binimp.iBigEndian = 0;
binimp.iMode = ASCIMP_MODE_REPLACE_DATA; //ASCIMP_MODE_APPEND_COLS

More about your FUNCTYPEbinimp struct: its arguments should be the same as the importData function it is designed for which means the last argument should be a pointer rather than reference (*pbi rather than &binimp) and the second argument is file rather than filename or string.

quote:
Using the filterfile-method:
Sorry, apparently I wasn't clear about this. My point was if the necessary files are already compiled you can prototype their functions and then use them directly in your code. This would replace the FindFunction() method, not augment it. Like run.loadOC(), FindFunction() compiles the file if necessary. The problem is that functions used in BinImp.c and FileImport.c might require other files in order to compile/link. Therefore, compiling all files in ImportWiz.ocw seemed safer to me. Use one method or the other but use it correctly.

Mike Buess
Origin WebRing Member
Go to Top of Page

Dominik Paulkowski

Germany
Posts

Posted - 01/22/2007 :  05:21:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You've pointed out my problems very well.

Because the header length of my data might change from time to time I prefer the BINIMP-Method. There I could adjust the header length. (The filter xy.oif - method have a constant header length. To set the XML information therein is not my favorite.)

I changed my script at the pointed things. But there is now a very curious problem. Compiling is fine. The integer iHeaderLength cause a running time failure, when I use the script to import my data. "The pointer is not initialized to the function"

The script now looks like:

//-----------------------------------------------------------------------
#include <..\OriginLab\BinImp.h> // Function prototypes and non-localized constants // defines the BINIMP structure
//int importData(Worksheet& wks, file& fDataFile, BINIMP *pbi);
typedef void (*FUNCTYPEbinimp)(Worksheet& wks, file& fDataFile, BINIMP *pbi); // definition to find a function in another c-file

void importprocedure()
{

string strFileName;//= "xy.dat";

// Find where header stops
int nHdrLines = find_header_marker(strFileName, "#");

if( nHdrLines >= 1 ) // if there is a header-marker
{
// Check if there are binary data
int nBinaer = find_header_marker(strFileName, "Binary Data");
// If there is noch "Binary Data" in the header the line number nBinaer is "0"

if( nBinaer < 1 ) // start ASCII-Import
{
// Get current ascimp settings from worksheet
ASCIMP ascimp;

// ......
// http://www.originlab.com/forum/topic.asp?TOPIC_ID=5310
}
else
{
int iHeaderLength = 2478;// compiling is fine. PROBLEM: "The pointer is not initialized to the function" //count_header_bytes(saFilePaths[i], nHdrLines);

BINIMP binimp; // compiling is fine

binimp.iHeaderBytes = iHeaderLength; //number of bytes for header
printf("HeaderBytes = %d\n", binimp.iHeaderBytes); // Shows the integer "2478" by running the script. Thereafter the problem occurs.
binimp.iAutoColTypes = 0; //indicate if set col type explicitly
binimp.iNumColumns = 4; //number of columns
//binimp.iPartial; //indicate partial data will be read from the file
//binimp.iPartialC1; //partial reading start column number, 0 based, include this column
//binimp.iPartialC2; //partial reading end column number, this column will not be included
//binimp.iPartialR1; //partial reading start row number, 0 based, this row will be included
//binimp.iPartialR2; //partial reading end row number, this row will not be included
binimp.iRenameWks = 0; // keep current name //if rename worksheet name to the file name
binimp.iBigEndian = 0; //=0 LittleEndian; numeric value byte order, use big endian if TRUE
//int iApplyRange; //
binimp.iMode = ASCIMP_MODE_REPLACE_DATA; //ASCIMP_MODE_APPEND_COLS;

// Path to another Origin C-file
//string strBinImpCPath = strUserPath + "Tribo\BinImp.c";
string strBinImpCPath = GetAppPath(true) + "OriginC\OriginLab\BinImp.c"; // false for User-Unterverzeichnis; true for Origin-Root

// Find the function "importData" in another Origin C-file
FUNCTYPEbinimp BinaryImport = Project.FindFunction("importData", strBinImpCPath);
//FindEmptyColumn(Worksheet &wks, int nStartCol)

BINIMP *binimp_ptr;
file fActualFile(strFileName, file::modeRead);
// | file::typeBinary);
//file(LPCTSTR lpszFileName, UINT nOpenFlags)

BinaryImport(wks, fActualFile, binimp_ptr); // compiling is fine // start binary import (It will do that by setting each cell in the worksheet)


} // end of else (than it's binary)
} // end if there is headertext

} // end of void
//-----------------------------------------------------------------------

-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany

Edited by - Dominik Paulkowski on 01/22/2007 05:28:10 AM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000