#
# Library functions for the scripting library (scrib)
#
# File: scrib/lib/xml.tcl
#
# $Revision$ on $Date$
# 
# Copyright (c) 1993-2003 ICEM CFD Engineering
#
#---------------------------------------------------------------------


## Open up a domain file, and create an XML file with the specified
## xml-elements, or else create the default report.

proc scrib_lib_xml_mesh_report_write {domain_file xmlfile args} {
    
    set mesher "Batch Surface"    
    return [ic_reports_write_mesh_report FILE "$xmlfile" -format xml \
		-mesher "$mesher" -domain $domain_file]
}


## Open up a domain file, and create an XML file with the specified
## xml-elements, or else create the default report.

proc scrib_lib_xml_assembly_report_write { infiles informat outfile outformat args } {
    
    set mesher "Batch Surface"
    
    switch -- $informat {
	domain - uns {
	    
	    if [scrib_lib_exec_inside_of_med] {
		return [ic_reports_write_assembly_report $infiles $informat $outfile $outformat\
			    -mesher "$mesher" $args]
	    } else {
		mess "Error: cannot write assembly report of uns files outside of med\n" red
		return ""
	    }
	}
	XML - xml {
	    
	    set title "ANSYS/ICEM CFD Assembly Report"
	    set user [cmd_whoami]
	    foreach {n v} $args {
		set [string range $n 1 end] $v
	    }
	    set attributes "title \"$title\" mesher \"$mesher\" user \"$user\""
	    
	    set dom_key [AssemblyReport::appendReport $outfile $attributes]
	    
	    foreach f $infiles {
		AssemblyReport::addPart $dom_key "name [file root $f]" "" $f
	    }
	    
	    set fixme [AssemblyReport::closeReport $dom_key $outfile $outformat]
	    
	    mess "Wrote assembly report $outfile in $outformat format\n"
	    
	    return $outfile
	}
	default {
	    mess "Error: cannot compile assembly report for intput files of format $informat\n" red
	    return ""
	}
    } 
    
    return ""
}
