The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
May 2nd, 2024, 1:42am
Pages: 1
Send Topic Print
Question about "$fclosed" (Read 8164 times)
tumeda
Community Member
***
Offline



Posts: 37

Question about "$fclosed"
Sep 07th, 2005, 7:56am
 
I use these commands " $fopen(fp) &  $fstrobe(fp, ...) & $fclose(fp)" to write the output periods of a PLL into a file. I made a transient simulation, like as 30us, If I set
"if $abstime>=25us; $fclose(fp)" .  The output results are continue written into the file, even if the file is already closed. The number of the written output periods seems to be not dependent of the close time, just only dependent on  the whole transient simulation time.
what is the problem???
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2384
Silicon Valley
Re: Question about "$fclosed"
Reply #1 - Sep 7th, 2005, 12:37pm
 
It sounds as if there is a bug in the simulator. But at the same time, you should not be writing to a file that has been closed.

-Ken
Back to top
 
 
View Profile WWW   IP Logged
tumeda
Community Member
***
Offline



Posts: 37

Re: Question about "$fclosed"
Reply #2 - Sep 8th, 2005, 2:45am
 
Ken, Thanks for your help! Indeed, I donot want to write the periods into the file any more after it is closed.  The verlioga code is showed in following:
......
@(initial_step)begin
         fp=$fopen("PLLPeriods.tcl","w");
   end
@(cross((V(VCO_out)-v_th),1)) begin
         if ($abstime>=tstart) $fstrobe(fp,"%3.10e",$abstime-prev);
     prev=$abstime;
end
if($abstime >= tclose) $fclose(fp);
end
endmodule

Something wrong in the code ?  :P
This problem is not very serious. More samples periods is not a bad thing. Smiley
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2384
Silicon Valley
Re: Question about "$fclosed"
Reply #3 - Sep 8th, 2005, 7:54am
 
Yes, there are two things that are wrong. First you write to a file that has been closed, and second you repeatedly close the same file. Why don't you get rid of the fclose() and add another condition to the test on the fstrobe() so that it does not occur after tclose?

-Ken
Back to top
 
 
View Profile WWW   IP Logged
tumeda
Community Member
***
Offline



Posts: 37

Re: Question about "$fclosed"
Reply #4 - Sep 8th, 2005, 8:11am
 
Ken, thanks for your answer!
From my understanding, the periods should begin to be written into the file at the time point "tstart", and then couldn't be written into the file after the time point "tclose".  What do the Spectre actually do? I don't know?
your metioned another condition is like this "if ($abstime>=tstart)&&($tstart<=tend) then $fstrobe..." ?.
But without $fclose(fp), if i do a simulation again, the new simulation results would append the last simualtion results. That isn't what i want to get.
you can see my last question. http://www.designers-guide.org/Forum/?board=verilogams;action=display;num=112559...
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Question about "$fclosed"
Reply #5 - Sep 8th, 2005, 8:31am
 
tumeda -
What about keeping track of whether the file is open?

@(initial_step) begin
 fp = $fopen...
 open = 1;
end

if (open) $fstrobe()

if ($abstime > 25us) begin
 $fclose(fp);
 open = 0;
end
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2384
Silicon Valley
Re: Question about "$fclosed"
Reply #6 - Sep 8th, 2005, 8:39am
 
You can use the @(final_step) event to close the file.

-Ken
Back to top
 
 
View Profile WWW   IP Logged
tumeda
Community Member
***
Offline



Posts: 37

Re: Question about "$fclosed"
Reply #7 - Sep 8th, 2005, 8:58am
 
Geoffrey_Coram, thanks again!
I just change a little in your code.
@(initial_step) begin
 fp = $fopen...
end

if ($abstime > tstart) open=1;
if (open) $fstrobe()  
if ($abstime > tclose) begin $fclose(fp); open = 0;

...
But the number of the output periods is stiil not dependent on "tclose" timepoint.  It seems stranger.  ::)
Back to top
 
 
View Profile   IP Logged
tumeda
Community Member
***
Offline



Posts: 37

Re: Question about "$fclosed"
Reply #8 - Sep 8th, 2005, 9:16am
 
Ken, thanks!

This is a good suggestion to close the file at the end of simualtion. But i am still strange when the file is already closed, how can the Spectre wirte data into the file?
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Question about "$fclosed"
Reply #9 - Sep 8th, 2005, 10:22am
 
I wonder if you're really successfully closing the file.
Try $fstrobe(fp,"closing file") just before $fclose(fp)
and see if you get that message in the file.
Back to top
 
 

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



Posts: 37

Re: Question about "$fclosed"
Reply #10 - Sep 9th, 2005, 1:38am
 
I am sure I have closed the file, otherwise the new simualtion results would append to the old results.
I have tried to use  "$fstrobe(fp,"closing file"), $fclose(fp)" . The output file looks like
"
....
close file
close file
4.032424e-9         // this is output period
clese fiile
....
"
It might  be a small bug. 8)
Anyway, the Ken's suggestion is good way to close the file.
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.