The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 17th, 2024, 3:38pm
Pages: 1
Send Topic Print
try to read a file (Read 14670 times)
sunnysunnyho
New Member
*
Offline



Posts: 4

try to read a file
Aug 02nd, 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 Sad Embarrassed
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: try to read a file
Reply #1 - 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
Back to top
 
 
View Profile WWW   IP Logged
sunnysunnyho
New Member
*
Offline



Posts: 4

Re: try to read a file
Reply #2 - Aug 3rd, 2011, 2:23am
 
It is still not working Sad
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".

:(  :-[

Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: try to read a file
Reply #3 - 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.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
sunnysunnyho
New Member
*
Offline



Posts: 4

Re: try to read a file
Reply #4 - Aug 4th, 2011, 2:38am
 
Thank you very much for your help, guys!!
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.