Spectre HDL $fread() question

Discussion in 'Cadence' started by rubin, Jan 13, 2004.

  1. rubin

    rubin Guest

    Greeting to all,

    I'm using $fread() function in spectreHDL. The code is as the
    following:

    finput = $fopen("dataFileName","r");
    while(! $fread(finput,"%e %e\n",V1[size],I1[size]));

    //"V1,I1" are real type array, "finput" is the input file handle

    to read in the following data file in:

    0.0e-1 3.0e-1
    1.0e-1 2.969e-1
    2.0e-1 2.875e-1
    3.0e-1 2.711e-1
    4.0e-1 2.462e-1
    5.0e-1 2.100e-1
    6.0e-1 1.545e-1
    7.0e-1 0.000e-1

    This data file is exactly of the format "%e %e\n" (At least, I think
    it is). But when I simulate it in Cadence, it keeps on complaining as
    the following:

    ******************************************************************
    Fatal error found by spectre during DC analysis `dc'.
    "/usr/local/cadence/db/rect/ahdl/ahdl.def" 19: format string in
    $fread() does not match input file.

    Analysis `dc' terminated prematurely due to error.
    ******************************************************************

    Line 19 is the the $fread() code line described at the beginning.

    Anybody has similar experience? Does this mean something is wrong with
    our cadence enviorment? We use ic446. Any advice will be appriciated.

    Thanks,

    Tian
     
    rubin, Jan 13, 2004
    #1
  2. You should post the complete model; it's very difficult to help out with just
    the error and a snippet of the code.

    Andrew.

     
    Andrew Beckett, Jan 13, 2004
    #2
  3. rubin

    rubin Guest

    All right, here it is:

    // Spectre AHDL for mitllmp6, rectenna_emp, ahdl

    #define Nmax 200

    module rectenna_emp (p,n) (order)
    node [V,I] p,n; //2 nodes module
    parameter integer order = 1 from [1:3]; //Interpolation order

    {
    table VIdata; //Interpolation table
    real V1[Nmax], I1[Nmax]; //real type array defination
    real vd; //temp variable to hold voltage as interpolation input.
    integer size = 0;
    stream finput; //file handle
    initial
    {
    finput = $fopen("/home/ecestud/zhaot/proj_mit/v_i.data","r");
    while(! $fread(finput,"%e %e\n",V1[size],I1[size]));
    {
    size++;
    }
    $fclose(finput);

    VIdata=$build_table(order,I1,V1,size);
    }
    analog
    {
    vd = V(p,n);
    I(n,p)<- $interpolate(VIdata,vd);
    }
    }

    That's all for the module. This is not much different from the
    magnetic core B-H characteristic modeling example, which is given by
    the spectreHDL manual. But, for some reason, it just complains and
    displays the message as I mentioned in the first email. The data file
    it reads in is as shown in the first email.

    Thanks,

    Tian

     
    rubin, Jan 14, 2004
    #3
  4. Hi Tian,

    I think it's a bug, which you should report to Cadence via your normal support
    channel.

    I did some experiments, and found that if I omitted the \n from the format
    string, it can read the first line in the file, but fails on subsequent lines.
    It seems to be something to do with the carriage returns, which is odd, because
    I'd expect those to be interpreted as whitespace (this is what C's fscanf
    does, as does SKILL's fscanf).

    I came up with a workaround, which is to use the %[] syntax to read the
    separators as a dummy string. This seems to work fine (see below).
    Note, you had an error in your code; there was a semicolon at the
    end of the while statement which would have meant (if it had worked)
    that it would read all the lines from the file, but not store them in the
    array).

    Regards,

    Andrew.

    // Spectre AHDL for mitllmp6, rectenna_emp, ahdl

    #define Nmax 200

    module rectenna_emp (p,n) (order)
    node [V,I] p,n; //2 nodes module
    parameter integer order = 1 from [1:3]; //Interpolation order

    {
    table VIdata; //Interpolation table
    real V1[Nmax], I1[Nmax]; //real type array defination
    real vd; //temp variable to hold voltage as interpolation input.
    string dummy;
    integer size = 0;
    stream finput; //file handle
    initial
    {
    finput = $fopen("rubin.data","r");
    //while(! $fread(finput,"%e %e\n",V1[size],I1[size]));
    while(!
    $fread(finput,"%e%[^0-9.]%e%[^0-9]",V1[size],dummy,I1[size],dummy))
    {
    $debug("debug %e %e\n",V1[size],I1[size]);
    size=size+1;
    }
    $debug("Size is %d\n",size);
    $fclose(finput);

    VIdata=$build_table(order,I1,V1,size);
    }
    analog
    {
    vd = V(p,n);
    I(n,p)<- $interpolate(VIdata,vd);
    }
    }


     
    Andrew Beckett, Jan 14, 2004
    #4
  5. rubin

    rubin Guest

    Hi Andrew,

    I tried the alternative way, it works perfect. I will report the bug to Cadence.

    Thanks so much for the help.

    best,

    Tian
     
    rubin, Jan 15, 2004
    #5
  6. Hi Tian,

    To avoid re-work for my colleagues when you report this, please can you
    point them to this discussion? (on google say) so that they can see the
    workaround too.

    Thanks,

    Andrew.

     
    Andrew Beckett, Jan 15, 2004
    #6
  7. rubin

    fogh Guest

    Tian & Andrew ,

    isn t this just the usual infamous DOS versus unix versus Mac line-end
    problem in ASCII files ?
    I believe that dos files have <cr><lf> whereas unix expects only <cr>
    and Macs expect only <lf>

    This is the cause of the most unusual/cryptic messages also with skill
    files. It happens when your files where generated by windows/dirty-OS
    tools, or transfered through some "intelligent" ftp or SMB client/server
    setup.

    Under linux, the "file" command tells you wether your ascii file is
    with dos or unix line-ends (I assume solaris does the same).
     
    fogh, Jan 19, 2004
    #7
  8. Possibly, but that was the first thing I checked when I tried it out...
    My files were completely with UNIX end-of-line characters.

    Andrew.

     
    Andrew Beckett, Jan 19, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.