csdl.tcl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #----------------------------------------------*-TCL-*------------
  2. #
  3. # csdl.tcl
  4. #
  5. # Cross Section Description Language
  6. #
  7. # This module defines the csdl namespace and procedures
  8. # for reading and writing csdl descriptions to and
  9. # from files.
  10. #
  11. # Copyright 2001-2004 Mayo Foundation. All Rights Reserved.
  12. # $Id: csdl.tcl,v 1.11 2004/07/19 18:22:01 techenti Exp $
  13. #
  14. #-----------------------------------------------------------------
  15. package require Itcl
  16. package provide csdl 1.0.1
  17. namespace eval ::csdl:: {
  18. namespace export csdlReadTCL
  19. namespace export csdlWriteTCL
  20. }
  21. ##########################################################
  22. # Read the <node>.xsctn file.
  23. ##########################################################
  24. proc ::csdl::csdlReadTCL { filename } {
  25. namespace eval :: [list source $filename]
  26. # As of today, BEM MMTL doesn't convert coupling length into
  27. # default units correctly, so we saved coupling length in
  28. # meters, and must now convert it into default units.
  29. set ::Stackup::couplingLength [::units::convert "$::Stackup::couplingLength meters" $::Stackup::defaultLengthUnits]
  30. }
  31. ##########################################################
  32. # Write the <node>.xsctn file.
  33. ##########################################################
  34. proc ::csdl::csdlWriteTCL { filename title cSegs pSegs } {
  35. if { [file exists $filename] && ([string first temp $filename] < 1) } {
  36. # Make a copy of this file.
  37. # puts "Move this file to $filename.backup"
  38. set bckup "$filename.backup"
  39. file copy -force $filename $bckup
  40. }
  41. #--------------------------------------------------
  42. # Open the file for write.
  43. #--------------------------------------------------
  44. set fp [open $filename w]
  45. puts $fp "#----------------------------------"
  46. puts $fp "# File: $filename"
  47. puts $fp "# [clock format [clock seconds]]"
  48. puts $fp "#----------------------------------"
  49. puts $fp ""
  50. puts $fp "package require csdl"
  51. puts $fp ""
  52. puts $fp "set _title \"$title\""
  53. # As of today, BEM MMTL doesn't convert coupling length into
  54. # default units correctly, so convert coupling length to default
  55. # units, then convert it into meters.
  56. set lenDef [length $::Stackup::couplingLength]
  57. set cLength [::units::convert "$lenDef $::Stackup::defaultLengthUnits" "meters"]
  58. puts $fp "set ::Stackup::couplingLength \"$cLength\""
  59. puts $fp "set ::Stackup::riseTime \"$::Stackup::riseTime\""
  60. puts $fp "set ::Stackup::frequency \"$::Stackup::frequency\""
  61. puts $fp "set ::Stackup::defaultLengthUnits\
  62. \"$::Stackup::defaultLengthUnits\""
  63. puts $fp "set CSEG $cSegs"
  64. puts $fp "set DSEG $pSegs"
  65. puts $fp ""
  66. foreach item $::Stackup::structureList {
  67. set nme [string range $item 2 \
  68. [expr {[string length $item] - 1} ]]
  69. #-------------------------------------------------
  70. # Find out the component-type of $nme.
  71. #-------------------------------------------------
  72. if { [$nme isa GroundPlane] } {
  73. set type 0
  74. set lst "GroundPlane $nme "
  75. }
  76. if { [$nme isa DielectricLayer] } {
  77. set type 1
  78. set lst "DielectricLayer $nme "
  79. }
  80. if { [$nme isa RectangleDielectric] } {
  81. set type 1
  82. set lst "RectangleDielectric $nme "
  83. }
  84. if { [$nme isa RectangleConductors] } {
  85. set type 2
  86. set lst "RectangleConductors $nme "
  87. }
  88. if { [$nme isa CircleConductors] } {
  89. set type 2
  90. set lst "CircleConductors $nme "
  91. }
  92. if { [$nme isa TrapezoidConductors] } {
  93. set type 2
  94. set lst "TrapezoidConductors $nme "
  95. }
  96. #-------------------------------------------------
  97. # Loop through the attributes of this item.
  98. #-------------------------------------------------
  99. foreach def [$item configure] {
  100. set flg [lindex $def 0]
  101. set vle [lindex $def 2]
  102. append lst " \\\n\t $flg $vle"
  103. }
  104. puts $fp $lst
  105. }
  106. close $fp
  107. }