473,383 Members | 1,859 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,383 software developers and data experts.

dynamic content of a binary file

I have to output data into a binary file, that will contain data
coming from a four channel measurement instrument.
Since those data have to be read from another C program somewhere
else, the reading program must know how many channels have been
acquired, date, time, and so on. I mean that the position of each
datum is not fixed in the file but depends on the conditions when
acquired.
That is, I need something like a header in the file to interpret it. I
thought to use ascii header, but I do not want to mix ascii and bin in
the file.
What could be a simple solution?
Any suggestion appreciated.

Apr 2 '07 #1
5 2869
bwv539 wrote:
I have to output data into a binary file, that will contain data
coming from a four channel measurement instrument.
Since those data have to be read from another C program somewhere
else, the reading program must know how many channels have been
acquired, date, time, and so on. I mean that the position of each
datum is not fixed in the file but depends on the conditions when
acquired.
That is, I need something like a header in the file to interpret it. I
thought to use ascii header, but I do not want to mix ascii and bin in
the file.
What could be a simple solution?
Any suggestion appreciated.
IOW, you need to impose some structure to the file. Well, one option
is to divide, (or group), your incoming data into an array of
structures and then write them out to the file. Then reading back the
structures could be straightforward. But a binary file is not
necessarily portable between implementations and systems. For maximum
potability a text file is the better option.

You could have a seperate structure member that just notes the members
that have valid values. A possible struct might be:

struct data_set {
data_type channel1;
/* ... */
time_type date_and_time;
/* other members */
};

You could even make the structure an "opaque" one and provide
functions for creating, reading and writing them.

Apr 2 '07 #2
In article <11**********************@b75g2000hsg.googlegroups .com>,
bwv539 <bw****@yahoo.comwrote:
>That is, I need something like a header in the file to interpret it. I
thought to use ascii header, but I do not want to mix ascii and bin in
the file.
What could be a simple solution?
ASCII is just a particular interpretation of 8 bit binary characters.
As far as binary file theory is concerned, there is no difference
(other than efficiency) between having a binary string
\x54\x59\x50\x45\x33\x42 or a binary string \x3B .
The first of the two happens to be interpretable in ASCII as
'TYPE3B', but really it's just a binary string of no more
(and no less) meaning to the file than the binary string \x3B.

The time to be concerned about ASCII vs binary (more correctly, text
streams vs binary streams) is in the treatment of line terminators
(e.g., \n ) and the treatment of binary 0's. If you were trying to mix
binary and text on the same logical line and read it back in a text
stream, you would need to be concerned in case the binary happened to
come out as binary 0 or happened to come out as one of the
implementation-dependant line terminators. But if you are consistant
in using binary streams, and wish to write out something that
is readable to humans when viewed as ASCII, you just have to worry
about whether the execution character set is ASCII
(because if it isn't, and you fputs("TYPE3B",stdout) then
it might not be ASCII's "T" and "Y" and so on that were written out.)
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
Apr 2 '07 #3
bwv539 wrote:
I have to output data into a binary file, that will contain data
coming from a four channel measurement instrument.
Since those data have to be read from another C program somewhere
else, the reading program must know how many channels have been
acquired, date, time, and so on. I mean that the position of each
datum is not fixed in the file but depends on the conditions when
acquired.
That is, I need something like a header in the file to interpret it. I
thought to use ascii header, but I do not want to mix ascii and bin in
the file.
What could be a simple solution?
Any suggestion appreciated.
My opinion? Use a small database like DBM or SQLite to store your data.
This is a perfect companion to a datalogger. As suggested
else-thread, you can also encode and store the data as text, which will
force you to come up with some sort of schema or format.

You can do this by coming up with your own binary format and writing the
routines to provide a normalized interface to that file, but by the time
you do that you've pretty much built a special-purpose database system
anyway.

Just my opinion, but I'm biased against reinventing wheels and toasters.
Apr 2 '07 #4
Thanks to all of you for the suggestions.
But, I have to confess that I made a mistake in the original post: the
data file generated by my C program, has to be read from a matlab
routine, not from a C program. I am not very familiar with Matlab,
someone else will write this routine, but I suppose there are not C
structures.
So, I need a header containing for example the name of the instrument
under test, date, time, environment informations, serial number, and
so on, and then a description of what follows: number of channels,
data types, etc.
I think I will end up writing a binary header with static size.
However, if you have more suggestions, please tell me.

Apr 3 '07 #5

bwv539 wrote:
Thanks to all of you for the suggestions.
But, I have to confess that I made a mistake in the original post: the
data file generated by my C program, has to be read from a matlab
routine, not from a C program. I am not very familiar with Matlab,
someone else will write this routine, but I suppose there are not C
structures.
Though it's possible to correctly interpret binary files generated by
one program with another program, you might find it more
straightforward to use plain text files. The small reductions in space
and time made by using binary files is usually not very important.

It's also quite probable that Matlab has the ability to read files in
a variety of formats. You might consider generating your data file in
one of these formats.

<snip>

Apr 3 '07 #6

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

Similar topics

0
by: Vio | last post by:
I have a basic dynamic lib "noddy.so" which I want to 1- embed inside my executable 2- import by embedded python interpreter using an API call. I have two questions: 1- what would be the...
2
by: mep | last post by:
Hi, After lookup in cherrypy site and google for a while, I haven't found any information about cherrypy how to serve dynamic binary file(some generated charts).Is there any easy way to do this?...
4
by: Daniel Keller | last post by:
Hello! I'm trying to set up a page system using "dynamic" SSI. That means that I normally use the following on my website: <!--#include virtual="file.inc" --> Now I want to make this...
5
by: Tompa | last post by:
Hi, I would like to create images on the fly as a response to an http request. I can do this with PIL like this (file create_gif.py): from PIL import Image, ImageDraw print 'Status: 200 OK'...
3
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
0
by: Neo | last post by:
Hello: I am receiving a Binary File in a Request from a application. The stream which comes to me has the boundary (Something like "---------------------------390C0F3E0099" without the quotes),...
7
by: Mike Livenspargar | last post by:
We have an application converted from v1.1 Framework to v2.0. The executable references a class library which in turn has a web reference. The web reference 'URL Behavior' is set to dynamic. We...
14
by: Brad | last post by:
I have a .net 2.0 web application project that creates a pdf file, saves the pdf to disk (crystal reports does this part), and then my code reads the pdf file and writes it to the httpresponse ...
2
by: WayneBurrows | last post by:
Can I save dynamically created data to a text file on the client's machine? Preferrably in a user named file through a save dialog box. Thanks Wayne
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.