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?
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"