473,654 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2897
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************ **********@b75g 2000hsg.googleg roups.com>,
bwv539 <bw****@yahoo.c omwrote:
>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\x4 5\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
1144
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 recommended technique to embed a binary file inside an executable? My guess would be to add the binary "noddy.so" to the linking command, but then
2
4258
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? In cherrypy 2.0 & python 2.4 -- Best Regards, Wang Kebo
4
4630
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 "dynamic" and I don't have a clue how to do so. I want to link to a file using something like this: <a href="file.shtml?dynamic">Link</a>
5
4389
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' print 'Content-type: text/html' print print '<HTML><HEAD><TITLE>Python Dynamic Image Creation Test</TITLE></HEAD>'
3
1312
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 below... --
0
1458
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), and also some more text like this and file name (e.g. "Content-Disposition: form-data; name="upload_file"; filename="C:\testing\myfile.dat" Content-Type: application/octet-stream") The binary content starts after "application/octet-stream".
7
22483
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 added an entry to the executable's .exe.config file to specify the URL, and under the 1.1 framework this worked well. Unfortunately, this is not working under the 2.0 framework. I see in the Reference.cs file under the web service reference the...
14
9473
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 The web app works great on win2003 and xp and the end result is a pdf file is displayed in the browser. When I run the same code on Vista, the browser displays the message "Internet Explorer cannot display the web page". If I open the same...
2
2301
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
0
8375
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7306
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.