help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: binary file format??


From: Kai Mueller
Subject: Re: binary file format??
Date: Wed, 10 Jun 1998 21:04:48 +0200

On Wed, Jun 10, 1998 at 01:17:51PM -0600, Rusty Boyd wrote:
> What is the file format used when using the 'fwrite' function, or, more to 
> the   
> point, how can I read a file created with this function using a 'C' program. 
> I   
> have tried every precision type listed, but after about 30 or so items from a 
>   
> column vector, the numbers start making no sense (to me). For example, 
> instead   
> of 0xFFFF, the file will contain FFDF, or, instead of 0x000E, it will be   
> 0x00E0. 
> Thanks in advance, 
> Rusty 
> 

Octave example:
  a =

    1  2  3
    4  5  6
    7  8  9


  octave:8> fwrite(fn,a,"double")
  ans = 9

Read file in C:

  #include <stdio.h>

  int main()
  {
      FILE  *fp;
      double x;

      if ((fp = fopen("xxx.xxx", "rb")) == NULL)  exit(1);
      for (;;)
      {
          fread(&x, sizeof(double), 1, fp);
          if feof(fp)  break;
          printf("%f\n", x);
      }
      fclose(fp);
      return 0;
  }

This program lists file "xxx.xxx":

  [leo]/XXX$ readbin
  1.000000
  4.000000
  7.000000
  2.000000
  5.000000
  8.000000
  3.000000
  6.000000
  9.000000

(Fortran column-wise dense format).

Kai

-- 
 Kai P. Mueller
 Control Department (Regelungstechnik) | Phone [+49] (531) 391-3835
 Technical University Braunschweig     | Fax   [+49] (531) 391-5194
 D-38092 Braunschweig                  | Email address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]