
# This code creates the ICEM CFD Manager.
#
# Copyright (c) 1993 - 1996 Pacific Marketing and Consulting, Inc,
#       and ICEM Systems, GmbH.  All rights reserved.
# Author:  Wayne A. Christopher, wayne@icemcfd.com

# this file should be kept in sync with iceman/prism.tcl
# Stuff to deal with prism offsets.

proc get_famnames {{surface_file ""}} {
	global file_name fam_visible famboco_data
	set family_boco ""

	if { $surface_file != "" && \
		[ file exists $file_name(mesh_dir)/$surface_file ] } {
		if { [ catch { exec grep read_family_boco \
			$file_name(mesh_dir)/$surface_file } line ] == 0 } {
			set cmd [ lindex $line 0 ]
                        if { $cmd == "read_family_boco" } {
				set family_boco [ lindex $line 1 ]
				set family_boco "$file_name(mesh_dir)/$family_boco"
			}
		}
	}
	if {$family_boco == "" || ! [ file exists $family_boco ] } {
	    if [ic_geo_is_loaded] {
# if a tetin file is loaded use those names
		set famnames [ic_geo_list_families]
		set famnames [lsort $famnames]
		return $famnames
	    }
	    set famnames [ array names fam_visible ] 
	    if { $famnames != "" } {
# if there are names on the screen use them
		set famnames [lsort $famnames]
		return $famnames
	    }
	}
	if { $family_boco == "" && [ file exists $family_boco ] } {
		set family_boco "$file_name(mesh_dir)/family_boco"
	}
	if [ file exists $family_boco ] {
		famboco_load $family_boco
		set famnames [ array names famboco_data ] 
		return $famnames
	}

	set bocos ""
	foreach b [lsort [glob -nocomplain $file_name(mesh_dir)/boco*]] {
		lappend bocos $b
	}
	if {$bocos == ""} {
		errormsg "Can't run Prism -- no boco file was found."
		return ""
	}

	set boco ""
	if { [ llength $bocos ] != 1 } {
		set boco [file_select  "Pick a boco file" \
                	  [lindex $bocos 0] ]
		if {$boco == ""} return ""
	}

	if { $boco == "" } {
                errormsg "Can't run Prism boco file name is null."
                return ""
        }
        if { [file exists $boco] == 0 }  {
                errormsg "Can't run Prism -- boco file $boco was not found."
		return ""
	}
	set famnames ""
	if [ catch { set lines [cmd_grep ^\\* $boco] } ] {
		errormsg "$boco does not seem to be a boco file"
		return ""
	}
	
	foreach fam [split $lines \n] {
        	set ff [string range $fam 1 end]
        	lappend famnames $ff
    	}
	set famnames [lsort $famnames]
        return $famnames
}

proc compute_from { } {
	global prism_values env cprism_values
	set fp [ open tmp_pars w ]
	set n_missing 0
	foreach i { height ratio layers total_height law } {
		if { ![ info exists prism_values($i) ] ||
		     $prism_values($i) == "" } {
			incr n_missing
		} else {
			puts $fp "$i $prism_values($i)"
		}
	}
	close $fp
	if { $n_missing != 1 } {
		errormsg "1 value of Height, Ratio, Layers, \"Total height\" or Law must be empty\n"
		return 0
	}
	if [ info exists env(PRISM_BIN) ] { 
		set prog $env(PRISM_BIN)
	} else {
		set prog [ get_program icemcfd prism ]
	}
	set command "\"$prog\" tmp_pars"
	if [catch {eval exec $command} res] {
	    mess "Error: $res\n" red
	    return
	}
	set res [lindex [split $res \n] end]	
	set len [ llength $res ]
	incr len -1
	set val [ lindex $res $len ]
	incr len -1
	set par [ lindex $res $len ]
	foreach i [ array names cprism_values ] {
		set cprism_values($i) ""
	}
	set cprism_values($par) $val
        return 1
}
proc rebuild_prism_window { form_name prism_params_file } {
# write out the parameters and re-build the window
	write_prism_params $prism_params_file
	form_kill $form_name
	mesher_prism
}

proc mesher_prism { } {
    global prism_par_on_off par_list
    global file_name prism_sel prism_values use_xwindows cprism_values
    global prism_family_on prism_family_height 
    global prism_family_ratio prism_extra_name prism_extra_value
    global prism_family_n_layers
    global options fam_visible
    global prism_families par_type par_text par_default
    
# save the current mesh and tetin
#    if [ic_uns_is_modified] { 
#		file_savemesh 1
#    }
#   if [ic_geo_is_modified] { file_savetetin 1 1 }
    file_save_one tetin 1
    file_save_one domain 1

# kill the families window
    catch { form_kill .prism_fam }

    if {$file_name(mesh_dir) == ""} {
	errormsg "Can't run Prism -- the project dir is not set."
	return
    }

# Read in the previous prism_params file.
    set ifile $file_name(mesh_dir)/prism_params
    
    if { [ catch { exec grep surface_file $ifile } line ] == 0 } {
	set surface_file [ lindex $line 1 ]
	set surface_file [ file tail $surface_file ]
	mess "surface file from prism_params: $surface_file\n:"
    } else {
	set surface_file ""
    }
    if { $surface_file == "" } {
	if [ info exists prism_values(surface_file) ] { 
	    set surface_file $prism_values(surface_file)
        } else {
	    set surface_file ""
	}
    }
    set prism_families [ get_famnames $surface_file ]
    set prism_families [ lsort -command "family_name_compare -1" \
			$prism_families ]
    if { $prism_families == "" } {
	return
    }


# domain file
    set domain_file [ file tail $file_name(domain) ]

    set par_text(input_file) "Input mesh file"
    set par_default(input_file) $domain_file
    set par_type(input_file) file

# output file	
    set par_text(output_file) "Output mesh file"
    set par_default(output_file) "prism.uns"
    set par_type(output_file) file

# surface file
    set par_text(surface_file) "Tetin file"
    if [ic_geo_is_loaded] {
    	set surface_file $file_name(tetin)
    } else {
        set surface_file ""
    }
    set surface_file [ file tail $surface_file ]
    set par_default(surface_file) $surface_file
    set par_type(surface_file) file

    set par_text(log) "Log file"
    set par_default(log) "prism.log"
    set par_type(log) file

    set par_text(height) "Initial height"
    set par_default(height) ""
    set par_type(height) number

    set par_text(ratio) "Height ratio"
    set par_default(ratio) ""
    set par_type(ratio) number
 
    set par_text(layers) "Number of layers"
    set par_default(layers) "3"
    set par_type(layers) number

    set par_text(total_height) "Total height"
    set par_default(total_height) ""
    set par_type(total_height) number

    set par_text(ratio_multiplier) "Ratio multiplier"
    set par_default(ratio_multiplier) ""
    set par_type(ratio_multiplier) number

    set par_text(init_dir_from_prev) "Init marching dir from previous layer"
    set par_default(init_dir_from_prev) "1"
    set par_type(init_dir_from_prev) logical

    set par_text(first_layer_smoothing_steps) "First layer n smoothing steps"
    set par_default(first_layer_smoothing_steps) ""
    set par_type(first_layer_smoothing_steps) number

    set par_text(smoothing_steps) "Max smoothing steps"
    set par_default(smoothing_steps) "6"
    set par_type(smoothing_steps) number

    set par_text(fillet) "Fillet ratio"
    set par_default(fillet) 0.1
    set par_type(fillet) unit_number

    set par_text(max_aspect_ratio) "Max height over base"
    set par_default(max_aspect_ratio) ""
    set par_type(max_aspect_ratio) number

#    set par_text(area_power) "Area power"
#    set par_default(area_power) ""
#    set par_type(area_power) number

    set par_text(graphics) "Use interactive graphics"
    set par_default(graphics) 1
    set par_type(graphics) logical

    set par_text(max_prism_angle) "Max prism angle"
    set par_default(max_prism_angle) "180"
    set par_type(max_prism_angle) number

    set par_text(min_prism_quality) "Min prism quality"
    set par_default(min_prism_quality) ".01"
    set par_type(min_prism_quality) number

    set par_text(prism_height_limit) "Prism height limit factor"
    set par_default(prism_height_limit) ""
    set par_type(prism_height_limit) number

    set par_text(n_triangle_smoothing_steps) "Number of tri smoothing steps"
    set par_default(n_triangle_smoothing_steps) "5"
    set par_type(n_triangle_smoothing_steps) number

    set par_text(triangle_quality) "Triangle quality type"
    set par_default(triangle_quality) "laplace"
    set par_type(triangle_quality) list
    set par_list(triangle_quality) "laplace height_over_base \
		skewness min_angle max_angle inscribed_ratio \
		inscribed_area"
    set prism_par_on_off(triangle_quality) prism_values(n_triangle_smoothing_steps)

    set par_text(law) "Growth Law"
    set par_default(law) "exponential"
    set par_type(law) list
    set par_list(law) "linear exponential wb-exponential"

    set par_text(ortho_weight) "Ortho weight"
    set par_default(ortho_weight) .5
    set par_type(ortho_weight) unit_number
    set prism_par_on_off(ortho_weight) \
		[ list  "prism_values(triangle_quality) laplace" ] 


    set par_text(into_orphan) "Extrude into orphan region"
    set par_default(into_orphan) 0
    set par_type(into_orphan) logical
   
    set par_text(new_volume) "New volume Family"
    set par_default(new_volume) ""
    set par_type(new_volume) family
    set par_list(new_volume) $prism_families

    set par_text(side_family) "Side Family"
    set par_default(side_family) ""
    set par_type(side_family) family
    set par_list(side_family) $prism_families

    set par_text(top_family) "Top Family"
    set par_default(top_family) ""
    set par_type(top_family) family
    set par_list(top_family) $prism_families

    set par_text(n_tetra_smoothing_steps) "Number of tetra smoothing steps"
    set par_default(n_tetra_smoothing_steps) "10"
    set par_type(n_tetra_smoothing_steps) number
#   check_tetin1
    
    
    
# initialize the defaults
    foreach i [ array names par_default ] {
	if ![info exists prism_values($i)] {
	    set prism_values($i) $par_default($i)
        }
    }
# this one is special since it is an on off button
    set prism_values(graphics) 0
        
    

    
    if [file exists $ifile] {
	foreach ff $prism_families {
	    set prism_family_on($ff) 0
	    set prism_family_height($ff) ""
	    set prism_family_ratio($ff) ""
	    set prism_family_n_layres($ff) ""
	}
	set fp [open $ifile r]
	while {![eof $fp]} {
	    set line [gets $fp]
# skip blank lines
	    set line [ string trim $line ]
	    if { $line == "" } continue
# skip comment lines
	    if { [ string match "#*" $line ] } continue
# family
	    set par [ lindex $line 0 ]
	    switch $par {
		family {
		    set ff [lindex $line 1]
		    set prism_family_on($ff) 1
		    set prism_family_height($ff) ""
		    set prism_family_ratio($ff) ""
		    set prism_family_n_layers($ff) ""
		    for {set i 2; set j 3} {[lindex $line $i] != ""} \
			{incr i 2; incr j 2} {
			switch [lindex $line $i] {
			ratio {
			    set prism_family_ratio($ff) [lindex $line $j]
			}
			height {
			    set prism_family_height($ff) [lindex $line $j]
			}
			n_layers {
			    set prism_family_n_layers($ff) [lindex $line $j]
			}
			}
		    }
	        }
		input_file -
		DomainInputFile {
			set prism_values(input_file) [lindex $line 1]
		}
		output_file -
		DomainOutputFile {
			set prism_values(output_file) [lindex $line 1]
		}
		surface_file -
		SurfaceFile {
			set prism_values(surface_file) [lindex $line 1]
		}
		n_processors {
		}
		default {
		    if { [ info exists par_text($par) ] == 0 } {
# unknown just read it in
			set prism_values($par) [lindex $line 1]
			set par_text($par) $par
			set par_type($par) number
		    } elseif { $par_type($par) == "logical" } {
			set prism_values($par) 1
		    } else {
			set prism_values($par) [lindex $line 1]
		    }
		}
	    }
	}
	close $fp
    } else {
	foreach ff $prism_families {
	    set prism_family_on($ff) 1
	    set prism_family_height($ff) ""
	    set prism_family_ratio($ff) ""
	    set prism_family_n_layres($ff) ""
	}
    }

# files should just show the tail
#    foreach i [ array names prism_values ] {
#	if { ! [ info exists par_type($i) ] } {
#		unset prism_values($i)
#	}
#    }
    foreach i [ array names prism_values ] {
	if {[info exists par_type($i)] && ($par_type($i)  == "file") } {
    		set prism_values($i)  [ file tail $prism_values($i) ]
	}
    }
# if the tetin file is not set or is set to a file that
# doesn't exist then set it
    if { $prism_values(surface_file) == "" || \
		![file exists $file_name(mesh_dir)/$prism_values(surface_file)] } {
	set prism_values(surface_file) [ file tail $file_name(tetin) ]
    }
    if ![file exists $file_name(mesh_dir)/$prism_values(surface_file)] {
	errormsg "Tetin file $prism_values(surface_file) isn't there."
	return
    }
    if { $prism_values(input_file) != "" && \
	! [ file exists $file_name(domains_dir)/$prism_values(input_file) ] } {
	set prism_values(input_file) ""
    }
	
    foreach pn [array names par_type] {
	if {($par_type($pn) == "family") && [info exists prism_values($pn)] &&
	    ($prism_values($pn) != "")} {
	    set prism_values($pn) [string toupper $prism_values($pn)]
	    fam_check_new $prism_values($pn)
	}
    }
    
    create_prism_options .prism_opt $ifile
    if ![form_wait .prism_opt] {
	form_kill .prism_opt
	return
    }

    
    
    if $use_xwindows { set x " -x" } else { set x "" }
    
# convert file names to long
    if { $prism_values(input_file) == "" } {
	errormsg "Input file not specified"
	form_kill .prism_adv
	return
    }
    set prism_values(input_file) \
			$file_name(domains_dir)/$prism_values(input_file)
    
    if { ! [ file exists $prism_values(input_file) ] } {
	errormsg "Input file $prism_values(input_file) does not exist"
	form_kill .prism_adv
	return
    }
	
    set prism_values(output_file) \
			$file_name(domains_dir)/$prism_values(output_file)
    set prism_values(surface_file) \
			$file_name(mesh_dir)/$prism_values(surface_file)
    
    write_prism_params $ifile

    
    form_kill .prism_adv
    
    ic_run_application_batch . icemcfd prism PRISM_BIN $ifile \
			$file_name(mesh_dir)/$prism_values(log)

    set file $prism_values(output_file)
    if { [ file exists $file ] } {
	if ![popup "Load mesh" "Load the new prism mesh\n$file ?" 1] return
	
# unload the old guy.
# load the new new guy
	if [ic_uns_is_loaded] {
		file_unload domain
	}
	gui_load_domains $file
    }
}

proc create_prism_options { form_name ifile } {
    global prism_families file_name prism_values 
    global par_list par_text par_default par_type

# parameter with blank defaults are not mandetory
# parameters are indexed by the names in the prism_params file
    set default_pars "layers ratio"
  
    set w [form_init $form_name "Prism options"]
    if {$w != ""} {
#	set d [form_scroller $w.fr 400 {0 0}]
	set d $w
	set ln 1
# default args

	foreach i $default_pars {
		set on_off ""
		if { [ info exists prism_par_on_off($i) ] } {
			set on_off $prism_par_on_off($i)
		}
	        if ![info exists par_type($i)] continue
		if ![ info exists par_text($i) ] {
                        set par_text($i) $i
                }
		switch $par_type($i) {
		    unit_number {
			form_label $d.l$i $par_text($i) " $ln 0" \
				$on_off
			form_scale $d.$i prism_values($i) \
				"" h 0 1 .01 "$ln 1 -cols 2 -fill x" \
				$on_off
		    }
		    default -
		    number - 
		    file {
			form_label $d.l$i $par_text($i) " $ln 0" \
				$on_off
			form_entry $d.$i prism_values($i) string  \
				"$ln 1 -cols 2" $on_off
			if { $i == "surface_file" } {
				bind $d.$i <Return> \
				"rebuild_prism_window $form_name $ifile "
			}
		    }
		    logical {
			form_checkbutton $d.$i $par_text($i) \
			    prism_values($i) "$ln 0 -cols 2" \
				$on_off
		    }
		    list {
			form_label $d.l$i $par_text($i) " $ln 0 " \
				$on_off
			futil_listentry $d.$i prism_values($i) \
				 "list $par_list($i)" " $ln 1 "  \
				$on_off
		    }
		    family {
			form_label $d.l$i $par_text($i) " $ln 0 " \
				$on_off
			futil_listentry $d.$i prism_values($i) \
			 "list $prism_families" " $ln 1 "  $on_off \
			    "" 1
		    }
		}
 		incr ln
	}


	incr ln
	form_button $d.fam "Families"\
			 "family_options .prism_fam "\
			 "$ln 0"
	form_button $d.adv "Advanced options" \
			"advanced_prism_options .prism_adv $ifile"\
			 "$ln 1"


	form_finish +300+300
    }

}


proc family_options { form_name } {
    global prism_families file_name prism_family_on prism_values
    global par_list

# parameter with blank defaults are not mandetory
# parameters are indexed by the names in the prism_params file

    set w [form_init $form_name "Families for prism layer"]
    if {$w != ""} {
	set d [form_scroller $w.fr 400 {0 0}]
	set bg [$form_name cget -background]
	set ln 0
	

#	form_label $d.pfl "Families for prisms" "$ln 0 -cols 3"
#
#	incr ln
#	form_frame $d.flabs flat 0 "$ln 0 -cols 3 -sticky w"
	form_label $d.fnl "Family" "0 0"
	form_label $d.fhl "Initial Height" "0 1"
	form_label $d.frl "Height Ratio" "0 2"
	form_label $d.fnuml "N Layers" "0 3"

	incr ln
# a scroller within a scroller seems like a bad idea.
#	set scr [form_scroller $d.scr 200 "$ln 0 -cols 3"]
#	form_frame $d.scr flat 0 "$ln 0 -cols 3 -sticky w"

	set scr $d

	set f0 $ln
	foreach ff $prism_families {
#	    set prism_family_on($ff) 1
	    form_checkbutton $scr.ff_$ln $ff prism_family_on($ff) "$ln 0 -fill both"
	    $scr.ff_$ln configure -background $bg
	    form_entry $scr.ffh_$ln prism_family_height($ff) string "$ln 1"
	    form_entry $scr.ffr_$ln prism_family_ratio($ff) string "$ln 2"
	    form_entry $scr.ffn_$ln prism_family_n_layers($ff) string "$ln 3"
	    incr ln
	}
	
        incr ln
        form_frame $d.allnone flat 0 "$ln 0 -cols 2"
        form_button $d.allnone.all "All" "prism_all 1" "$ln 0"
        form_button $d.allnone.none "None" "prism_all 0" "$ln 1"

	form_finish +300+300
	
	if {$prism_families != ""} {
	    grid columnconfigure $d 0 -minsize [expr [winfo reqwidth $scr.ff_$f0] + 20]
	    grid columnconfigure $d 1 -minsize [expr [winfo width $scr.ffh_$f0] + 10]
	    grid columnconfigure $d 2 -minsize [expr [winfo width $scr.ffr_$f0] + 10]
	}
	
	# Hell if I know ...
	$scr configure -height [expr {[winfo reqheight $scr] + 1}]
    }
}


proc advanced_prism_options { form_name ifile } {
    global prism_families file_name par_type par_default par_text
    global par_list
    
# parameter with blank defaults are not mandetory
# parameters are indexed by the names in the prism_params file
    set default_pars "input_file output_file surface_file log \
		law \
		height ratio layers total_height smoothing_steps \
		min_prism_quality graphics \
		n_triangle_smoothing_steps triangle_quality ortho_weight \
		fillet max_aspect_ratio \
		n_tetra_smoothing_steps \
		max_prism_angle into_orphan new_volume \
		top_family side_family  \
		prism_height_limit \
		ratio_multiplier \
		first_layer_smoothing_steps \
		init_dir_from_prev "

    
    set w [form_init $form_name "Advanced prism options"]
    if {$w != ""} {
#	set d [form_scroller $w.fr 400 {0 0}]
	set d $w
	set bg [$form_name cget -background]
	set ln 0
# default args
	set all_pars $default_pars
	foreach i [ array names prism_values ] {
	    if { [ lsearch $default_pars $i ] == -1 } {
		append all_pars " $i"
	    }
	}
	

	foreach i $all_pars {
		set on_off ""
		if { [ info exists prism_par_on_off($i) ] } {
			set on_off $prism_par_on_off($i)
		}
	        if ![info exists par_type($i)] continue
		if ![ info exists par_text($i) ] {
                        set par_text($i) $i
                }
		switch $par_type($i) {
		    unit_number {
			form_label $d.l$i $par_text($i) " $ln 0" \
				$on_off
			form_scale $d.$i prism_values($i) \
				"" h 0 1 .01 "$ln 1 -cols 2 -fill x" \
				$on_off
		    }
		    default -
		    number - 
		    file {
			form_label $d.l$i $par_text($i) " $ln 0" \
				$on_off
			form_entry $d.$i prism_values($i) string  \
				"$ln 1 -cols 2" $on_off
			if { $i == "surface_file" } {
				bind $d.$i <Return> \
				"rebuild_prism_window $form_name $ifile "
			}
		    }
		    logical {
			form_checkbutton $d.$i $par_text($i) \
			    prism_values($i) "$ln 0 -cols 2" \
				$on_off
		    }
		    list {
			form_label $d.l$i $par_text($i) " $ln 0 " \
				$on_off
			futil_listentry $d.$i prism_values($i) \
				 "list $par_list($i)" " $ln 1 "  \
				$on_off
		    }
		    family {
			form_label $d.l$i $par_text($i) " $ln 0 " \
				$on_off
			futil_listentry $d.$i prism_values($i) \
			 "list $prism_families" " $ln 1 "  $on_off \
			    "" 1
		    }
		}
		incr ln
	}


	set cln 4
	form_button $d.cfrom "Compute from others" "compute_from" "$cln 3"
	
        foreach i { height ratio layers total_height } {
                incr cln
                form_entry $d.c${i} cprism_values($i) string  "$cln 3"
        }

# extra args

# empty guy
#
	set prism_extra_name ""
	set prism_extra_value ""
	incr ln
	form_entry $d.extra_par_1 prism_extra_name \
					string " $ln 0 -cols 2"
	form_entry $d.extra_val_1 prism_extra_value \
					string " $ln 1 -cols 2"
	

	incr ln
# a scroller within a scroller seems like a bad idea.
#	set scr [form_scroller $d.scr 200 "$ln 0 -cols 3"]

	form_frame $d.scr flat 0 "$ln 0 -cols 3 -sticky w"
	set scr $d.scr

	
	pathentry on $d.input_file "" $file_name(domains_dir)
	pathentry on $d.output_file "" $file_name(domains_dir)
	pathentry on $d.surface_file "" $file_name(mesh_dir)
	
	form_finish +300+300
	
	
	# Hell if I know ...
	$scr configure -height [expr {[winfo reqheight $scr] + 1}]

	$d.graphics configure -background $bg
    }

}

proc prism_all { on } {
	global prism_family_on
	foreach ff [ array names prism_family_on ]  {
		set prism_family_on($ff) $on
	}
}
proc write_prism_params { ifile } {
    global prism_values prism_extra_name prism_families prism_extra_value
    global prism_family_on options prism_family_ratio prism_family_n_layers
    global prism_family_height par_type


    ic_rm $ifile
    set fp [ ic_unique_id ]
    ic_open $ifile w $fp
    foreach i [ array names prism_values ] {
	if {$i == "" || ![info exists par_type($i)]} continue
	
	if { $i == "log" } continue
	if { $par_type($i) == "logical" } {
 		if { $prism_values($i) == 1 } {
			ic_puts $fp $i
		}
	} elseif { $prism_values($i) != "" } {
		ic_puts $fp "$i $prism_values($i)"
	}
    }
    if  {[info exists prism_extra_name] && ($prism_extra_name != "") } {
	ic_puts $fp "$prism_extra_name $prism_extra_value"
    }

# families
    set any_families 0
    foreach ff $prism_families {
	if { [info exists prism_family_on($ff) ] && 
			$prism_family_on($ff) } {
	    set any_families 1
	    set line "family $ff"
# add ratio
	    if {$prism_family_ratio($ff) != ""} {
		append line " ratio $prism_family_ratio($ff)"
	    }
# add height
	    if {$prism_family_height($ff) != ""} {
		append line " height $prism_family_height($ff)"
	    }
            if {$prism_family_n_layers($ff) != "" } {
		append line " n_layers $prism_family_n_layers($ff)"
	    }
	    ic_puts $fp $line
	}
    }

    if { $options(n_processors) != "" } {
	ic_puts $fp "n_processors $options(n_processors)"
    }

# prism doesn't use this for anything.
#    if { $options(max_binary_tetin) >= 0 } { 
# the med parameter is in MB
#	ic_puts $fp "max_binary_tetin [expr $options(max_binary_tetin) * 1048576]"
#    }

    ic_close $fp
    if { $any_families == 0 } {
	errormsg "no prism families selected"
    }
}
