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
 import binary file problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

maxim_n

USA
Posts

Posted - 11/15/2004 :  3:08:23 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): v.7.5853(B853)
Operating System: WindowsXP Pro

Hello,

Code written below was working perfectly for OriginPro 7 SR0, but it does not import file for the current version of Origin (see above). Does anyboly have an idea what might be wrong? It looks like program can not open image file.

CODE:::

BYTE Buffer[5000000];
Dataset ds;
ds.Attach("Curves", 0);
ds.SetSize(40);
for(i=0; i<40; i++)
ds[i]=0.2*i-4;
ds.Detach();
ds.Attach("Curves",1);
ds.SetSize(40);
FileName.Format("c:\\temp\\spectr\\m%d_ori.sf0", FileIndex);
if (!ImageFile.Open(FileName, file::modeRead))
{
ImageFile.Close();
return;
}
ImageFile.Read(Buffer, 5000000);
ImageFile.Close();
for (Point = 0; Point < 1; Point++)
{
for (i=0;i<40;i++)
{
BYTE h, l;
short a;
a = Buffer[i*2*2500 + Point*2]*256 + Buffer[i*2*2500 Point*2 + 1];
ds[i] = a;
}
}
:::

eparent

118 Posts

Posted - 11/15/2004 :  3:27:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Where is the declaration for ImageFile?
Did the call to ImageFile.Open succeed?
Did the call to ImageFile.Read succeed?

More information is needed to diagnose the problem.


Go to Top of Page

maxim_n

USA
Posts

Posted - 11/16/2004 :  5:56:54 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Origin Version (Select Help-->About Origin): v.7.5870(B870)
Operating System: WindowsXP Pro

I wrote function for testing whether the file is opening or not, the answer is always "Failed to open file ...". Function OpenFile() was taken from the example.

Complete code:::

#include <Origin.h>
///////////////
int OpenFile(string strFileName);
void LoadSPImage(int FileIndex);

///////////////
file fScan;
string strFileName;

///////////////
int OpenFile(string strName)
{
strFileName = strName;
if( fScan.Open(strFileName, file::modeRead) )
{
printf("Opened file %s\n", strFileName);
return 0;
}
printf("Failed to open file %s\n", strFileName);
return 1;
}

void LoadSPImage(int FileIndex)
{
string FileName;
FileName.Format("c:\\temp\\spectr\\m%d_ori.sf0",FileIndex);
OpenFile(FileName);
fScan.Close();
}

Please tell me why file is failing to open?
Go to Top of Page

eparent

118 Posts

Posted - 11/17/2004 :  09:53:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
To find out why the file::Open method failed you need to call the file::GetLastError method. The error codes and descriptions are defined at the top of Origin C's file.h.


Go to Top of Page

maxim_n

USA
Posts

Posted - 11/17/2004 :  3:30:18 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank's a lot. file::GetLastError command really helped.
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