Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I print a binary double array from commandline (unix)

I got binary file, that contains doubles. How do i print that out to a terminal. I've tried octaldump 'od' but cant figure out the syntax I've tried something like

head -c80 |od -f

But that doesnt work, the man page for od is extremely bad.

I've made a c program that does what I want, something like assuming 10double chunks.

double tmp[10];
while(fread(tmp,sizeof(double),10,stdin))
    for(int i=0;i<10;i++)  printf("%f\t",tmp[i]);

thanks.

like image 365
monkeyking Avatar asked Jan 22 '10 02:01

monkeyking


2 Answers

Have you tried hexdump utility?

hexdump -e ' [iterations]/[byte_count] "[format string]" ' filename

Where format string should be "%f", byte count should be 8, and iterations the amount of floats you want to read

like image 88
Kornel Kisielewicz Avatar answered Oct 13 '22 00:10

Kornel Kisielewicz


The od command you're looking for is

od -t fD

(That means "floating point values, of double size").

like image 28
caf Avatar answered Oct 12 '22 23:10

caf