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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Second File dialog crashes Origin

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
SteffenG Posted - 03/01/2010 : 07:47:47 AM
Origin 8.0G SR6
Operating System: Win XP

Hi all,

I tried several days to import binary datas. Because of some problems I wrote a topic regrading these probs approx. one week ago.
Today I could locate the line of code which crashes Origin. It is a simple file dialog. Regardless if I try the X-function dlgFile or the getfilename-method or fdlog. Each time if I run the script a first time the script is working. Starting the script a second time the complete Origin crashes immediately if the script comes to the point where the file dialog is called.

I have no more ideas to work around that problem. But I found a similar topic from another user some years ago. This issue was solved by the fdlog-dialog. But this did not solve my problem.

Maybe there is some help out where.

Best regards,
Steffen
3   L A T E S T    R E P L I E S    (Newest First)
greg Posted - 03/02/2010 : 2:19:11 PM
Your code fragments are not complete enough to run so I tried some modified code:

//file name dialog;
dlgfile group:=*.*;

calc_offset=12;
spectra_name$=Imp_Val_String(%(fname$), $(calc_offset), 512)$;
type %(spectra_name$);

spectra_offset = 1; // force the main code to run
spectra_base = 0; // Don't know what value you use
spectra_length = 10; // Don't know what value you use
range ww = [%H]1!; // I guess you use a range variable?
// I replaced your $(spectra_column)
// with ww.ncols

if (spectra_offset!=0)
{
worksheet -c energy;
wks.col$(wks.ncols).type=4;
worksheet -c spectra;

calc_offset=$(spectra_base+19)+($(spectra_offset)-1)*4;
voltage =Imp_Val_Float(%(fname$), $(calc_offset));
type $(voltage);

calc_offset=$(spectra_base+83)+(spectra_offset-1)*4;
Data_read=Imp_Col_UInt(%(fname$), $(spectra_length-1), $(calc_offset), ww.ncols);

set %H -e $(wks.nrows);
ww.NROWS=4095;
}
else
{
type -c "File is empty - no spectra available!";
ww.NROWS=$(size_wks);
}

which I can run repeatedly with no problem, so perhaps it's related to your data files? Again, I recommend sending a complete test suite so tech can check in debug or get familiar with debugging in Code Builder.
SteffenG Posted - 03/02/2010 : 03:38:22 AM
Hi Greg,

you're right. Please excuse the unfortunately phrased description of my problem. Give me a second try.

I want to import binary files. Inside of the files there are some float values, some strings and a vector of integers. Some of the offsets of the different values are static (header data) and some are not static. With the static values I can calculate the offsets of the non-static offsets. That's why I'm not using Import filters (oif-files) because the filters can only handle static offsets (Or not?).

In a first attempt I tried binary import with the impbin2d-function. After the import I used some labtalk-macros to make out of the imported values the floats, integers and so on. But unfortunately with impbin2d Origin runs several time into unstable conditions and crashes. I don't know why. This issue is described in an earlier topic here in the forum.

My second attempt is now to use complete self written OriginC-routines for the import. The respective OC-code comes now:
//----------start of OC-----------------
#include <Origin.h>

string Imp_Val_String(string strFile, uint Offset, uint ByteReadSoll){
if( !strFile.IsFile() ) return -1;
bool bIsLittleEndian = true;
file fp;
fp.Open(strFile, file::modeRead);
vector<char> vi(ByteReadSoll+1);
string imp_char;
fp.Seek(Offset, file::begin);
int bGood = fp.ReadInt(&vi, sizeof(char), ByteReadSoll, bIsLittleEndian);
fp.Close();

if( !bGood ) return -2;
vi[ByteReadSoll]=0;
for (int ii=ByteReadSoll;ii>-1;ii--){
imp_char.Insert(0,vi[ii]);
};

return imp_char;
}
float Imp_Val_Float(string strFile, uint Offset){
uint ByteReadSoll = 1;
if( !strFile.IsFile() ) return -1;
bool bIsLittleEndian = true;
file fp;
fp.Open(strFile, file::modeRead);
vector<float> vi(ByteReadSoll);
fp.Seek(Offset, file::begin);
int bGood = fp.ReadInt(&vi, sizeof(float), ByteReadSoll, bIsLittleEndian);
fp.Close();

if( !bGood ) return -2;
return vi[0];
}
byte Imp_Val_Byte(string strFile, uint Offset){
uint ByteReadSoll = 1;
if( !strFile.IsFile() ) return -1;
bool bIsLittleEndian = true;
file fp;
fp.Open(strFile, file::modeRead);
vector<byte> vi(ByteReadSoll);
fp.Seek(Offset, file::begin);
int bGood = fp.ReadInt(&vi, sizeof(byte), ByteReadSoll, bIsLittleEndian);
fp.Close();

if( !bGood ) return -2;
return vi[0];
}
int Imp_Col_UInt(string strFile, uint ByteReadSoll, uint Offset, uint TargetCol){
if( !strFile.IsFile() ) return -1;
bool bIsLittleEndian = true;
file fp;
fp.Open(strFile, file::modeRead);
vector<uint> vi(ByteReadSoll);
fp.Seek(Offset, file::begin);
int bGood = fp.ReadInt(&vi, sizeof(uint), ByteReadSoll, bIsLittleEndian);
fp.Close();

if( !bGood ) return -2;
Worksheet wks = Project.ActiveLayer();
Column cc;
cc.Attach(wks, TargetCol-1);
cc.SetFormat(OKCOLTYPE_TEXT_NUMERIC);
Dataset ds(wks,TargetCol-1);
ds = vi;

return bGood;
}
//--------------end of OC code---------------

The LabTalk-code (in part) which calls the OC-functions comes now:
//--------------start of labtalk code--------
%A= path to OC-files;
if (run.LoadOC("%A\Binary_import_column.c")!=0) {
type -c "Compiling error Binary_import_column.c";
};
if (run.LoadOC("%A\Binary_import_value.c")!=0) {
type -c "Compiling error Binary_import_column.c";
};

//file name dialog;
dlgfile group:=*.dbm;

calc_offset=12;
spectra_name$=Imp_Val_String(%(fname$), $(calc_offset), 512)$;
type %(spectra_name$);

if (spectra_offset!=0){
worksheet -c energy;
wks.col$(wks.ncols).type=4;
worksheet -c spectra;

calc_offset=$(spectra_base+19)+($(spectra_offset)-1)*4;
voltage =Imp_Val_Float(%(fname$), $(calc_offset));
type $(voltage);

calc_offset=$(spectra_base+83)+(spectra_offset-1)*4;
Data_read=Imp_Col_UInt(%(fname$), $(spectra_length-1), $(calc_offset), $(spectra_column));

set %H -e $(wks.nrows);
ww.NROWS=4095;
}
else {
type -c "File is empty - no spectra available!";
ww.NROWS=$(size_wks);
};
//-----------------end of LT code-------------

The code is only in part copied to this forum because of the length. But the main parts are to be seen. Maybe you will see here some mistakes I wrote in the code.

Unfortunately I can't show you the crash because there is no error message. Origin disappears after the second call of the file dialog immediately.

Best regards,
Steffen
greg Posted - 03/01/2010 : 10:14:24 AM
Without actually seeing the script - and the crash - there is no way of knowing what's going on. I suspect that the dialog problem may be a red herring in that something else in your script may be creating a problem and Origin is already 'in trouble' before you run the script the second time and it's only when it tries to get Windows to do something (i.e. bring up the dialog) that things fall apart completely.

If the script is reasonably small and the conditions for execution easy to reproduce, then post those here. Otherwise send us a project, script and any support files.

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000