The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> Question about "$fclosed"
https://designers-guide.org/forum/YaBB.pl?num=1126104989

Message started by tumeda on Sep 7th, 2005, 7:56am

Title: Question about "$fclosed"
Post by tumeda on Sep 7th, 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???

Title: Re: Question about "$fclosed"
Post by Ken Kundert on 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

Title: Re: Question about "$fclosed"
Post by tumeda on 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. :)

Title: Re: Question about "$fclosed"
Post by Ken Kundert on 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

Title: Re: Question about "$fclosed"
Post by tumeda on 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=1125594213

Title: Re: Question about "$fclosed"
Post by Geoffrey_Coram on 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

Title: Re: Question about "$fclosed"
Post by Ken Kundert on Sep 8th, 2005, 8:39am

You can use the @(final_step) event to close the file.

-Ken

Title: Re: Question about "$fclosed"
Post by tumeda on 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.  ::)

Title: Re: Question about "$fclosed"
Post by tumeda on 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?

Title: Re: Question about "$fclosed"
Post by Geoffrey_Coram on 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.

Title: Re: Question about "$fclosed"
Post by tumeda on 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.

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.