Reading Numerical Binary Data using KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading Numerical Binary Data using KSH
# 1  
Old 10-08-2008
Reading Numerical Binary Data using KSH

Hi,

I've searched and couldn't find anyone else with this problem. Is there anyway (preferably using ksh - but other script languages would do) that I can read in binary float data into a text file. The data (arrays from various stages of radar processing) comes in various formats, but mainly its float32, though there are some float complex arrays as well. The ability to switch between big and little endian would be useful too.

This sort of thing is easy in IDL and matlab etc, but thats not a cheap solution.

Any ideas?

Jon
# 2  
Old 10-08-2008
Perl. "man perlfunc" and search for "pack" and "unpack". It's quite cryptic, so I'll refer you also to ...The first has some examples for doing exactly what you want. Ultimately, you can create command-line perl scripts...

In reading binary data, the other problem you'll encounter is trying to figure out how to get it into Perl. This is not hard, but it's not obvious. As long as your datafile will easily fit in memory, this is suitable. Otherwise, you'll want to read several bytes at a time with sysread(). (Again, see man perlfunc).

Code:
perl -e 'undef $/; $dat=<>; print length($dat),"\n"; ' inputfile.binary

That reads in your binary file and prints out its size. $dat contains the entire image so now you can do manipulations on it with pack/unpack.

Last edited by otheus; 10-08-2008 at 01:12 PM.. Reason: Fixed post per drl
# 3  
Old 10-08-2008
Hi.

Likely otheus meant undef not under:
Code:
perl -e 'undef $/; $dat=<>; print length($dat),"\n"; ' inputfile.binary

... cheers, drl
# 4  
Old 10-08-2008
Cheers guys, I'll have a play with perl.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Reading binary content

Dear Gurus I am stuck with the peice of work and do not know from where to start. I get a machine generated file which is binary file contain binary data, i want to read binary data as it is without converting into any other format. i want to read byte by byte. Please let me know what... (24 Replies)
Discussion started by: guddu_12
24 Replies

2. UNIX for Dummies Questions & Answers

Divide a numerical data column by a variable

Hello, I have two files, f1 and f2. f1 has 5 columns like so: a b c d 154 e f g h 365 ..... f2 has two columns, the first column contains the name of the above file and second column contains a constant which is to be used for division. e.g. file1 56 I want to divide the 5th... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

3. Shell Programming and Scripting

how to extract data from numbered files using linux in the numerical order-

Hi experts, I have a list of files containing forces as the only number as follows. Force1.txt Force2.txt Force3.txt Force4.txt Force5.txt . . . . . . . . . Force100.txt I want to put all the data(only a number ) in these forces files in the file with the same order like 1,2,3 ..100 .... (2 Replies)
Discussion started by: hamnsan
2 Replies

4. Programming

help with reading a binary file and fseek

this is my code and no matter what record number the user enters i cant get any of the records fields to read into the structure acct. What am i doing wrong? #include <stdio.h> typedef struct { char name; int number; float balance; } acct_info_t; int main (int... (0 Replies)
Discussion started by: bjhum33
0 Replies

5. Programming

reading binary files

#include <stdio.h> /* typedef struct { char name; int number; float balance; } acct_info_t; */ int main() { FILE *fptr; fptr = fopen("acct_info", "r"); int magic = 5; fseek(fptr,3,SEEK_SET); fread(&magic,sizeof(int),1,fptr);... (7 Replies)
Discussion started by: robin_simple
7 Replies

6. Shell Programming and Scripting

script to sort a string of numerical data in set fields

So, I will be working with someone and basically we are trying to build a form that is submitted most likely via the web and the data is just a string of numbers. like: 19383882872201110929282821818182827349190102837364718191001932873711 Now, each number is part of a numerical value of... (4 Replies)
Discussion started by: tlarkin
4 Replies

7. Shell Programming and Scripting

ksh numerical RegX

I need to distinguish between numerical characters in a script: echo "Enter a number." read num if (( $num = * )) ; then exit 0 fi this RegX does not work. Any suggestions? (5 Replies)
Discussion started by: prkfriryce
5 Replies

8. Shell Programming and Scripting

How to strip non numerical data out of file?

Hi, How can I remove all non numerical data from line, so I don't want to delete the line but to have only the numbers. e.g.: ######### 123 aaa124 125bbb 126 127 ######### So I want all the leading and trailing non numerical stuff(letters/white space/tabs anything else except... (10 Replies)
Discussion started by: Juha
10 Replies

9. Programming

Adding files of numerical data

Hi I was hoping that maybe someone could help me with a small piece of C code. I have a number of files, which are all of similar layout ie. three lines of text and 5-6 columns of numerical data. I need to add each of the elements of the second column in one file to their counterparts in the second... (17 Replies)
Discussion started by: Boucho
17 Replies

10. Programming

Reading from a binary file

I'm having trouble with reading information back into a program from a binary file. when i try to display the contents of the file i get a Memory fault(coredump). would anyone be able to assist? this is my fread line fread(&file_data,sizeof(struct book_type),1,fileSave); ive also tried it without... (3 Replies)
Discussion started by: primal
3 Replies
Login or Register to Ask a Question