You are on page 1of 5

5/30/2016

EncounterHowTo:WritingTo/ReadingFromaFileWithTCLDigitalImplementationCadenceBlogsCadenceCommunity

Home>Community>Blogs>DigitalImplementation>EncounterHowTo:WritingTo/ReadingFromaFileWithT

EncounterHowTo:WritingTo/ReadingFromaFileWithTCL
Comments(9)
Acoupleweeksago,therewasagoodthreadintheDigitalImplementationForumsaboutmanagingbufferingonnets
betweenIOsandregisters.Theposttouchedonanumberofinterestingtopics,butoneofthefundamentalbuilding
blocksI'dliketoexpanduponinthisblogentryisthefundamentaltaskofwritingtoandreadingfromafile:FileI/O.
ItmayseemlikesecondnatureforfolkswhouseTCLbasedtoolslikeEncounterregularly,andit'sprettymuch
straightTCLthatweusetowriteandread,butIhopehavingconciseexamplesofhowtodothiswithinEncounterisa
usefulreference.
ReadingFromaFile
Sayforexampleyoureceivedalistofnetsinafilethatneededtoberoutedonuppermetallayers.Here'san
exampleofhowyouwouldreadfromthatfileandusethe"setAttribute"commandtoapplythatroutingconstraint.Say
yourfilelookedlikethis:
critical.nets:
n_5822
n_5828
n_5834
Here'showwe'ddoit:
setinfile[opencritical.nets"r"]
while{[gets$infileline]>=0}{
setAttributenet$linebottom_preferred_routing_layer5
}
close$infile
WritingToAFile
SaywewantedtocapturealistofallofthenetsinthedesignthatareconnectedtoIOpins?Here'showwecoulddo
it:
setoutfile[openio.nets"w"]
foreachnet[dbGet[dbGetutop.terms.net].name]{
puts$outfile$net
}
close$outfile
RedirectingCommandOutputToAFile
Anotherscenariothat'softenusefuliswhenwewanttotakecommandoutputthat'sechoedtotheconsoleand
redirectittoafile.Wecanusethe"redirect"commandforthispurpose.(Note:Thecommandisnotdocumented.This
willberectifiedinthenextrelease.)SayforexampleyouwantedtoparsetheoutputoftheverifyGeometrycommand
toseewhethertherewereanyviolations.Here'sonewayyoucoulddoit:
http://community.cadence.com/cadence_blogs_8/b/di/archive/2010/02/24/encounterhowtowritingtoreadingfromafilewithtcl

1/5

5/30/2016

EncounterHowTo:WritingTo/ReadingFromaFileWithTCLDigitalImplementationCadenceBlogsCadenceCommunity

redirectverifyGeometry>verifyGeometry.out
setinfile[openverifyGeometry.out"r"]
while{[gets$infileline]>=0}{
if{[stringmatch*Verification*$line]}{
setnrViols[lindex$line3]
}
}
close$infile
puts"verifyGeometryreported$nrViolsviolation(s)"
Tip:It'smucheasiertouse"dbGettop.markers"toseewhetherthereareviolationsinthedesignafterrunning
verifyGeometry:
encounter1>dbGettop.markers
0x2aab94d7400x2aab94d5f0
Separately,somecommandslikereport_timingsupport">"and">>"redirection.Forexample:
report_timing>timing.report
We'relookingtoexpandthiseasy">"mechanismtoincludeothercommandsinafuturerelease.
Ihopetheseexamplesareuseful.Anyrelatedtipsyou'dliketoshare?
BobDwyer

EDIsystem

encounterdigitalimplementationsystem

FoundationFlowDesign

scripting

DigitalImplementation

Closure

tcl

RobertDwyer HiJohn,
Iseesamehere.LetmecheckwithR&Dandgetbacktoyou.Thanksforthecomment!
Bob
Anonymous HiBob,
Thanksforthecomment!Greattohearthattheredirectworkswithvariables.I'vegivenita
try,anditworksonthecommandline,butnotwithinaprocedure(proc).Istherea
workaroundtouseredirectwithinaproc?
Thanks,
John
RobertDwyer GoodnewsinEDI10.1.USR1redirectsupportsredirectiontovariable.It's
notdocumentedyetbuthere'sthesyntax:
redirect{command}>&variable_name
Forexample:
http://community.cadence.com/cadence_blogs_8/b/di/archive/2010/02/24/encounterhowtowritingtoreadingfromafilewithtcl

2/5

5/30/2016

EncounterHowTo:WritingTo/ReadingFromaFileWithTCLDigitalImplementationCadenceBlogsCadenceCommunity

redirect{verifyGeometry}>&verify_geometry_output
puts"$verify_geometry_output"
Hopethishelps,
Bob
RobertDwyer Currently,Encounter'sredirectcommanddoesn'tsupportredirectionto
variable.I'lltrytogetitenhancedsoitcandoso.
Thanksforasking!
Anonymous HiBob
Canthecommandoutputberedirectedtoavariable?
Thanks
Khandaker
RobertDwyer SorrysuhasImissedyourcommentforsometime.Trythis:
redirect{query_objects[get_pinsof_objectsCELL_NAME]}(greaterthan)filename.txt
Anonymous Howdoweredirectthegivencommandintoafile??
get_pinsof_objectsCELL_NAME
RobertDwyer Awesometips,Jason.Veryuseful.
YourusemodelofredirectwillbeusefulinsharingwithR&Dhowthemoreadvanced
optionsareusedinpractice.I'llpassthisalongtothemasitwillhelpimprovethe
documentationwhenredirectbecomesofficiallysupported.
jgentry Bob,
I'vefoundredirecttobeveryusefulwhenyoudon'twantyourlogfiletobedominatedby,
what'sinmyopinion,uselessoutput.Forinstance:
deleteInst*INSTPATTERN*
...willgiveyoua"Deletinginstance[INSTNAME]"messagesforeachandeveryinstance
thatisbeingdeleted.Insomecases,wehavethousandsofthesemessagesinour
logfiles.Togetridofthis:
redirectquietnolog{
http://community.cadence.com/cadence_blogs_8/b/di/archive/2010/02/24/encounterhowtowritingtoreadingfromafilewithtcl

3/5

5/30/2016

EncounterHowTo:WritingTo/ReadingFromaFileWithTCLDigitalImplementationCadenceBlogsCadenceCommunity

deleteInst*INSTPATTERN*
}>&/dev/null
Theseveralthousandmessagesgetsreducedtonone.Becarefulthough,ifanything
whenwrongduringthecommandsbeingexecutedintheredirectbody,youwon'tknow
aboutit.
Regardingreading/writingfiles,itisprettysimpletoaddcompressiontothemix.For
instance:
###Toreadafilethatmightbegzipped:
if{[fileextension$fileName]==".gz"}{
setinFile[list|gzipdc$fileName]
}else{
setinFile$fileName
}
if{[catch{open$inFiler}IN]}{
...doanycleanupnecessary,thenerrorgracefully.
error$IN
}
###Togzipanoutputfile(makesure$fileNamehas.gzattheend):
setoutFile[list|gzip>$fileName]
if{[catch{open$outFilew}OUT]}{
...doanycleanupnecessary,thenerrorgracefully.
error$OUT
}
Don'tforgettocloseyourfilehandlesusingthe'close'command.
Enjoy,
JG

Post
http://community.cadence.com/cadence_blogs_8/b/di/archive/2010/02/24/encounterhowtowritingtoreadingfromafilewithtcl

4/5

5/30/2016

EncounterHowTo:WritingTo/ReadingFromaFileWithTCLDigitalImplementationCadenceBlogsCadenceCommunity

http://community.cadence.com/cadence_blogs_8/b/di/archive/2010/02/24/encounterhowtowritingtoreadingfromafilewithtcl

5/5