The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl Design Languages >> Verilog-AMS >> try to read a file https://designers-guide.org/forum/YaBB.pl?num=1312296500 Message started by sunnysunnyho on Aug 2nd, 2011, 7:48am |
Title: try to read a file Post by sunnysunnyho on Aug 2nd, 2011, 7:48am Hi. I am trying to read a file from my verilog-AMS program (.csv, it is a lookup table with 2 lists of arrays). real code[41:0]; real thresh[41:0]; initial begin openfile = $fopen("file", "rb"); readfile = $fscanf("file", "%g %g\n",code[40:0],thresh[40:0]); end ncvlog: *E,NOPSOM file,33|72): Part-select or indexed part-select cannot be applied to memory [4.2.2(IEEE)]. readfile = $fscanf("file", "%g %g\n",code[40:0],thresh[40:0]); | ncvlog: *E,NOPSOM (file,33|85): Part-select or indexed part-select cannot be applied to memory [4.2.2(IEEE)]. module testlib.adcdiscrete:verilogams The $fopen part of the codes is OK. The syntax/s of the $fscanf function is the same as the one in the manual. I have no idea what's going on :( :-[ |
Title: Re: try to read a file Post by Ken Kundert on Aug 2nd, 2011, 9:17am My guess is that you cannot use a range of indices on a real vector. Perhaps if you rewrite the code by adding a for loop so that you only access one value in the array at a time. -Ken |
Title: Re: try to read a file Post by sunnysunnyho on Aug 3rd, 2011, 2:23am It is still not working :( To try to solve the problem/s I created a program which just open, write and read a .txt file. module readfile ( ); integer file; integer readfile; integer code; integer a; initial begin a=999; file = $fopen("/home/sunny/Desktop/loadfile/testing.txt", "rw"); $strobe("\nfile OK? = %d\n", file); $fwrite(file, "%g", a); readfile = $fscanf(file, "%d\n", code); $strobe("readfile OK?=%d", readfile); $strobe("code = %d\n", code); end I can open and write to the file (it shows '999' in the .txt), but I cannot read from the file, in fact, the variable readfile returned as "-1" and the code returned as "x". :( :-[ |
Title: Re: try to read a file Post by Geoffrey_Coram on Aug 3rd, 2011, 5:00am I would expect you to need to close and re-open the file in order to read it. Or, at least, you'd need to "rewind" it (is there an $frewind?), because after writing, the file handle will point to the end of the file, and that's why you're getting an EOF error when you try to read. |
Title: Re: try to read a file Post by sunnysunnyho on Aug 4th, 2011, 2:38am Thank you very much for your help, guys!! |
The Designer's Guide Community Forum » Powered by YaBB 2.2.2! YaBB © 2000-2008. All Rights Reserved. |