view test/octave.test/io/binary-io-1.m @ 4720:e759d01692db ss-2-1-53

[project @ 2004-01-23 04:13:37 by jwe]
author jwe
date Fri, 23 Jan 2004 04:13:37 +0000
parents 7c96e85c76db
children
line wrap: on
line source

type_list = ["char"; "char*1"; "integer*1"; "int8"; 
	     "schar"; "signed char"; "uchar"; "unsigned char";
	     "short"; "ushort"; "unsigned short"; "int";
	     "uint"; "unsigned int"; "long"; "ulong"; "unsigned long";
	     "float"; "float32"; "real*4"; "double"; "float64";
	     "real*8"; "int16"; "integer*2"; "int32"; "integer*4"];

n = rows (type_list);

nm = tmpnam ();

id = fopen (nm, "wb");

if (id > 0)

  for i = 1:n
    fwrite (id, i, deblank (type_list(i,:)));
  endfor

  fclose (id);

  id = fopen (nm, "rb");

  if (id > 0)

    x = zeros (1, n);

    for i = 1:n
      x(i) = fread (id, [1, 1], deblank (type_list(i,:)));
    endfor

    if (x == 1:n)
      printf ("ok\n");
    endif

  endif

endif

unlink (nm);