bugGNU Octave - Bugs: bug #54111, binary data read using...

 
 

bug #54111: binary data read using "fread" doesn't recognize any "PRECISION" arg in Windows 10

Submitter:  Bill S <bills>
Submitted:  Wed 13 Jun 2018 01:38:25 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Bill S Open/Closed:  * Closed
Release:  * 4.4.0 Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 13 Jun 2018 04:46:44 PM UTC, comment #2: 

I think Michael is correct in comment #1.  Try 'help fread' and note this paragraph


The PRECISION argument may also specify a type conversion.  For
example, 'int16=>int32' causes 'fread' to read 16-bit integer
values and return an array of 32-bit integer values.  By default,
'fread' returns a double precision array.  The special form '*TYPE'
is shorthand for 'TYPE=>TYPE'.


Modifying your code to include the type conversion


octave:1> fidw=fopen("test.bin","w");
octave:2> fwrite(fidw,[100],"int8");
octave:3> fclose(fidw);
octave:4> fidr=fopen("test.bin","rb");
octave:5> val=fread(fidr,1,"int8=>int8")
val = 100
octave:6> fclose(fidr);
octave:7> whos val
Variables in the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  =====
        val         1x1                          1  int8

Total is 1 element using 1 byte


Marking as invalid and closing report.


Rik <rik5>
Group administrator
Wed 13 Jun 2018 02:10:06 PM UTC, comment #1: 

This is not a bug, this is correct behaviour. The default return type of fread indeed is double. What you are after is type conversion, or rather probably no type conversion to the default double in your case, which you get by replacing "int8" by "*int8".

Michael Leitner <mleitner>
Wed 13 Jun 2018 01:38:25 PM UTC, original submission:  

Trying to read binary data using FREAD with PRECISION set to different arguments produces only "double" as answers.
EXAMPLE:
fidw=fopen("test.bin","w");
fwrite(fidw,[100],"int8");
fclose(fidw);
fidr=fopen("test.bin","rb");
val=fread(fidr,1,"int8")
fclose(fidr);
whos val

Attr Name    Size     Bytes  Class
==== ====    ====     =====  =====
     val     1x1       8  double

Bill S <bills>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mleitner (Posted a comment)
  • -email is unavailable- added by bills (Submitted the item)
  • -email is unavailable- added by bills
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-06-13 rik5 StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
    2018-06-13 bills Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code