1
votes

I'm running Modelsim to do a long simulation. I want to have an ouput like this for my progress report to be logged in a file:

Mon Oct 29 21:05:57 IRST 2018   Section 1 
Mon Oct 29 21:05:57 IRST 2018   Section 2 
Mon Oct 29 21:05:57 IRST 2018   Section 3
...

I want to have a tcl script to create this output and log it in a file during simulation progress. I have below TCL code snippet:

set fp [open mylog.txt w]
puts $fp "Section 1"
close $fp

It will print label Section 1 inside file mylog.txt. However I don't know how to print current system date and time to this file from modelsim command line (TCL). using date >mylog.txt will print date/time to file however since file is open, it will make thing corrputed and output format wouldn't be nice like what I described above. Are there any methods to print system data/time to file inside TCL scripts?

1
Try to see if puts $fp "[clock format [clock scan now]] Section 1" is satisfactory to you. You can futher more alter the timestamp format per the manual here - Jerry
clock scan now is a very costly way to do exactly the same as clock seconds. On my machine it takes 60.9 µS versus 0.48 µS for clock seconds - Schelte Bron
@SchelteBron Good point. Not sure where I picked up that bad habit :) - Jerry
@Jerry please put your comment as answer here, it works. - VSB

1 Answers

0
votes

You can use the command clock for various purposes involving datetime manipulation. To get the current timestamp, you can use clock scan now (slower) or clock seconds (faster, credit to Schelte Bron in the comments) then clock format to format it from epoch format; for example:

puts $fp "[clock format [clock seconds]] Section 1"