Home Forums Tools Read Qucs .dat file with Matlab

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1020
    MJH1994
    Participant

      Hi,
      does anyone know the data structure of the .dat file of a S-parameter optimazation? I would like to extract the optimized capacitor values with Matlab. This works with the conversion to a .txt file for a simple circuit simulation but not for the more complex S-parameter simulation.

      I am happy with any advice.

      Best regards

      MJH

      #1021
      pault
      Participant

        A couple of tweaks from the octave version of the load data set program seems to work for matlab with the .opt variables included when trying the stub_filter.sch example:

        function [dataset] = loadQucsDataset(filename)

        pos = 0;
        dataset = [];

        fid = fopen(filename, “rb”);
        if fid < 0
        error(“Cannot open data file.”)
        return
        end

        if strcmp(fscanf(fid, “%8c”, 1), “QucsData”) == 0
        error(“File is not a Qucs data file.”)
        fclose(fid);
        return
        end

        version = fread(fid, 1, “int32”, 0, “ieee-le”);
        size = fread(fid, 1, “int32”, 0, “ieee-le”);

        % load header containing a list of all variables in the file
        header = fread(fid, size, “uchar”);

        type = 0;
        count = 0;
        index = 0;
        % search for the variable
        while index+9 <= size
        type = header(index+1) + 256*(header(index+2) + 256*(header(index+3) + 256*header(index+4)));
        count = header(index+5) + 256*(header(index+6) + 256*(header(index+7) + 256*header(index+8)));

        name = ”;
        dependency = ”;
        index = index + 9;
        while header(index) > 0
        name = strcat(name, char(header(index)));
        index = index + 1;
        end
        if bitget(type, 2) == 1 % is dependent variable?
        index = index + 1;
        while header(index) > 0
        dependency = strcat(dependency,char(header(index)));
        index = index + 1;
        end
        end

        if bitget(type, 3) == 0 % complex-valued numbers?
        data = fread(fid, 2*count, “double”, 0, “ieee-le”);
        data = data(1:2:2*count-1) + j*data(2:2:2*count);
        else
        data = fread(fid, count, “double”, 0, “ieee-le”);
        end

        pos = pos + 1;
        dataset(pos).name = name;
        dataset(pos).depName = dependency;
        dataset(pos).size = count;
        dataset(pos).type = type;
        dataset(pos).data = data;
        end

        fclose(fid);
        endfunction

      Viewing 2 posts - 1 through 2 (of 2 total)
      • You must be logged in to reply to this topic.