
# 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

# Stuff to handle domain files.

set domains_var 0

proc remove_some_domains {ifile progname} {
    global domains_var place domains_queried

    catch {destroy .del_domains}
    toplevel .del_domains
    message .del_domains.title -width 400 \
	-relief raised -borderwidth 2 -text \
	"The domains on the left are the ones requested \
in the rebuilt $progname input file, \
and the ones on the right are the ones that have already been computed.  \
If you want to remove some of the computed domains so that they will be \
recomputed, click on the domain number in the right column so that the \
check box is not colored.  This will cause the domain file to be removed \
before $progname is run.  When you are done, click the Done button."
    frame .del_domains.exists -borderwidth 1
    frame .del_domains.needed -relief raised -borderwidth 2
    
    catch {unset domains_queried}
    
    set fd [open $ifile]
    set some_exist 0
    set them ""
    while 1 {
	set line [gets $fd]
	if [eof $fd] break
	if {[scan $line "C PADAMM COMMAND FILE FOR DOMAIN %d" num] \
	    != 1} continue
	
	set them "$them \"[format %3d $num]\""
    }
    
    close $fd
    
    if {$them == ""} {
	destroy .del_domains
	errormsg "No domains in file!"
	return 0
    }
    
    putarray .del_domains.needed $them
    
    set domainfiles [glob -nocomplain \
		     $place/domains/domain.*]
    if {$domainfiles == ""} {destroy .del_domains; return 1}
    foreach d $domainfiles {
	if {[scan $d "$place/domains/domain.%d" \
	     num] != 1} {warningmsg "Strange file $d"; continue}
	set domains_queried($num) 1
    }
    
    if {[picksome .del_domains.exists "" \
	 domains_queried {pack append .del_domains \
	     .del_domains.title {top fill} \
		 .del_domains.needed {left fill} \
		 .del_domains.exists {left expand fill}; \
		 wm geometry .del_domains +300+300} 0] \
	     == "*cancel*"} {destroy .del_domains; return 0}
    destroy .del_domains
    
    foreach i [array names domains_queried] {
	if {!$domains_queried($i)} {
	    set fname $place/domains/domain.$i
	    if [file exists $fname] {
		infomsg "removing file $fname"
		exec rm $fname
	    }
	}
    }
    
    return 1
}
