473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Binary File Reading : Metastock

Hi

I am having a little trouble trying to read a binary file, I would like
to write an ascii to Metastock converter in python but am not having a
lot of success.

The file formats are

http://sf.gds.tuwien.ac.at/00-pdf/m/.../MetaStock.pdf
If any one can point me in the right direction it would be much
appreciated.

So far I have tried opening file "rb" then trying to use struct and
then binascii but I am not too sure what I should be doing and fuction
I should be using in binascii ?

TIA

May 3 '06 #1
2 4260
Jack wrote:
Hi

I am having a little trouble trying to read a binary file, I would like
to write an ascii to Metastock converter in python but am not having a
lot of success.

The file formats are

http://sf.gds.tuwien.ac.at/00-pdf/m/.../MetaStock.pdf
If any one can point me in the right direction it would be much
appreciated.


Not sure, but this may help you:
http://pyconstruct.wikispaces.com/
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
May 3 '06 #2
Jack wrote:
Hi

I am having a little trouble trying to read a binary file, I would like
to write an ascii to Metastock converter in python but am not having a
lot of success.

The file formats are

http://sf.gds.tuwien.ac.at/00-pdf/m/.../MetaStock.pdf
If any one can point me in the right direction it would be much
appreciated.

So far I have tried opening file "rb" then trying to use struct and
then binascii but I am not too sure what I should be doing and fuction
I should be using in binascii ?

TIA

Jack,
What you may not realize is that Metastock is using an oddball floating
point format.
I have not looked at this for many years now but remember using a small
VB-callable dll with functions BasicToIEEE and IEEEToBasic. This may
help you in recoding conversions into Python.

float BasicToIEEE (unsigned char *value)

{ float result;

unsigned char *msbin = (unsigned char *) value;

unsigned char *ieee = (unsigned char *) &result;

unsigned char sign = 0x00;

unsigned char ieee_exp = 0x00;

int i;

/* MS Binary Format */

/* byte order => m3 | m2 | m1 | exponent */

/* m1 is most significant byte => sbbb|bbbb */

/* m3 is the least significant byte */

/* m = mantissa byte */

/* s = sign bit */

/* b = bit */

sign = msbin[2] & 0x80; /* 1000|0000b */

/* IEEE Single Precision Float Format */

/* m3 m2 m1 exponent */

/* mmmm|mmmm mmmm|mmmm emmm|mmmm seee|eeee */

/* s = sign bit */

/* e = exponent bit */

/* m = mantissa bit */

for (i=0; i<4; i++) ieee[i] = 0;

/* any msbin w/ exponent of zero = zero */

if (msbin[3] == 0) return 0;

ieee[3] |= sign;

/* MBF is bias 128 and IEEE is bias 127. ALSO, MBF places */

/* the decimal point before the assumed bit, while */

/* IEEE places the decimal point after the assumed bit. */

ieee_exp = msbin[3] - 2; /* actually, msbin[3]-1-128+127 */

/* the first 7 bits of the exponent in ieee[3] */

ieee[3] |= ieee_exp >> 1;

/* the one remaining bit in first bin of ieee[2] */

ieee[2] |= ieee_exp << 7;

/* 0111|1111b : mask out the msbin sign bit */

ieee[2] |= msbin[2] & 0x7f;

ieee[1] = msbin[1];

ieee[0] = msbin[0];

return (result);

}

bool IEEEToBasic (float *value, unsigned char *result)

{ unsigned char *ieee = (unsigned char *) value;

unsigned char *msbin = (unsigned char *) result;

unsigned char sign = 0x00;

unsigned char msbin_exp = 0x00;

int i;

/* See _fmsbintoieee() for details of formats */

sign = ieee[3] & 0x80;

msbin_exp |= ieee[3] << 1;

msbin_exp |= ieee[2] >> 7;

/* An ieee exponent of 0xfe overflows in MBF */

if (msbin_exp == 0xfe) return (FALSE);

msbin_exp += 2; /* actually, -127 + 128 + 1 */

for (i=0; i<4; i++) msbin[i] = 0;

msbin[3] = msbin_exp;

msbin[2] |= sign;

msbin[2] |= ieee[2] & 0x7f;

msbin[1] = ieee[1];

msbin[0] = ieee[0];

return (TRUE);

}

Good luck,
malv

May 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
28
by: wwj | last post by:
void main() { char* p="Hello"; printf("%s",p); *p='w'; printf("%s",p); }
9
by: Arnold | last post by:
I need to read a binary file and store it into a buffer in memory (system has large amount of RAM, 2GB+) then pass it to a function. The function accepts input as 32 bit unsigned longs (DWORD). I...
4
by: knapak | last post by:
Hello I'm a self instructed amateur attempting to read a huge file from disk... so bear with me please... I just learned that reading a file in binary is faster than text. So I wrote the...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
3
by: nguser3552 | last post by:
Hello Everyone, I have a problem I can't surmount, anything is gravy at this point. I need to be able to read any type of file .ext (mov,mpeg,mp3,etc) in binary format. I can do this in C, but ...
3
by: The Cool Giraffe | last post by:
Regarding the following code i have a problem. void read () { fstream file; ios::open_mode opMode = ios::in; file.open ("some.txt", opMode); char *ch = new char; vector <charv; while...
27
by: Jeff | last post by:
Im trying to figure out why I cant read back a binary file correctly. I have the following union: #define BITE_RECORD_LEN 12 typedef union { unsigned char byte; struct { unsigned char type;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.