
# Copyright (c) 1993, 1994 Pacific Marketing and Consulting
# Author:  Wayne A. Christopher, wayne@pmac.com
#          Pacific Marketing and Consulting, Berkeley, California

proc macro_save {var dir names} {
    global $var ${var}_units macro_file
    
    if ![file exists $dir] { cmd_mkdir $dir }
    
    if ![info exists macro_file] { set macro_file "" }
    
    set file [file_select "File to save macro information to." \
		  $dir/$macro_file "Macro information" 0 1]
    if {$file == ""} return
    set macro_file [file tail $file]
    
    set fp [open $file w]
    foreach n $names {
	set un ""
	if [info exists ${var}_units($n)] {
	    set un [set ${var}_units($n)]
	}
	set val [set ${var}($n)]
	regsub -all \n $val " " val
	puts $fp [list $n $val $un]
    }
    close $fp
}

proc macro_load {var dir names} {
    global $var ${var}_units macro_file
    
    if ![info exists macro_file] { set macro_file "" }
    
    set file [file_select "File to load macro information from." \
		  $dir/$macro_file "Macro information" 0 0]
    if {$file == ""} return
    set macro_file [file tail $file]
    
    set fp [open $file r]
    while {![eof $fp]} {
	set line [gets $fp]
	if {[llength $line] >= 2} {
	    set n [lindex $line 0]
	    set ${var}($n) [lindex $line 1]
	    set un [lindex $line 2]
	    if {$un != ""} {
		set ${var}_units($n) $un
	    }
	}
    }
    close $fp
}
