aboutsummaryrefslogtreecommitdiffstats
path: root/gr-utils/octave/read_cshort_binary.m
blob: 0e997c286b1cea64ec9da2d483259eca3e616c49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
%
% Copyright 2001,2008 Free Software Foundation, Inc.
%
% This file is part of GNU Radio
%
% SPDX-License-Identifier: GPL-3.0-or-later
% 
%

function cv = read_cshort_binary (filename, count)

  %% usage: read_cshort_binary (filename, [count])
  %%
  %%  open filename and return the contents, treating them as
  %%  signed short integers
  %%

  m = nargchk (1,2,nargin);
  if (m)
    usage (m);
  end

  if (nargin < 2)
    count = Inf;
  end

  f = fopen (filename, 'rb');
  if (f < 0)
    cv = 0;
  else
    v = fread (f, count, 'short');
    fclose (f);
    v_r = v(1:2:end);
    v_i = v(2:2:end)*j;
    clear v;
    cv = v_r+v_i;
  end