classdef QuikSCATL1CV1 < handle
    properties
        filename
        timestr
        time
        dn
        lon
        lat
        fp_start
        fp_end
        npts
        s0
        inc
        azi
        atten
        beam
        land
        espd
        edir
        rspd
        rdir
    end

    methods
        function obj = QuikSCATL1CV1(filename)
            obj.filename = filename;
            obj = obj.read();
        end

        function obj = read(obj)

            numbytesperrecord = 83;

            ifp = fopen(obj.filename, 'rb');
            obj.timestr = char(fread(ifp,[21,inf],'21*char',numbytesperrecord-21)');
            fseek(ifp,21,'bof'); ftell(ifp);
            obj.time = fread(ifp,[1,inf],'double',numbytesperrecord-8);
            fseek(ifp,29,'bof');
            obj.lon = fread(ifp,[1,inf],'float32',numbytesperrecord-4);
            fseek(ifp,33,'bof');
            obj.lat = fread(ifp,[1,inf],'float32',numbytesperrecord-4);
            fseek(ifp,37,'bof');
            obj.fp_start = fread(ifp,[1,inf],'int32',numbytesperrecord-4);
            fseek(ifp,41,'bof');
            obj.fp_end = fread(ifp,[1,inf],'int32',numbytesperrecord-4);
            fseek(ifp,45,'bof');
            obj.npts = fread(ifp,[1,inf],'int32',numbytesperrecord-4);
            fseek(ifp,49,'bof');
            obj.s0 = fread(ifp,[1,inf],'float32',numbytesperrecord-4);
            fseek(ifp,53,'bof');
            obj.inc = fread(ifp,[1,inf],'float32',numbytesperrecord-4);
            fseek(ifp,57,'bof');
            obj.azi = fread(ifp,[1,inf],'float32',numbytesperrecord-4);
            fseek(ifp,61,'bof');
            obj.atten = fread(ifp,[1,inf],'float32',numbytesperrecord-4);
            fseek(ifp,65,'bof');
            obj.beam = fread(ifp,[1,inf],'int8',numbytesperrecord-1);
            fseek(ifp,66,'bof');
            obj.land = fread(ifp,[1,inf],'int8',numbytesperrecord-1);
            fseek(ifp,67,'bof');
            obj.espd = fread(ifp,[1,inf],'float32',numbytesperrecord-4);
            fseek(ifp,71,'bof');
            obj.edir = fread(ifp,[1,inf],'float32',numbytesperrecord-4);
            fseek(ifp,75,'bof');
            obj.rspd = fread(ifp,[1,inf],'float32',numbytesperrecord-4);
            fseek(ifp,79,'bof');
            obj.rdir = fread(ifp,[1,inf],'float32',numbytesperrecord-4);

            fclose(ifp);

            obj.dn = datenum(2000, 1, 1) + obj.time/24/60/60;

        end

    end

end
