
# This code creates the user interface for the mesh editor.
#
# Copyright (c) 1997 Pacific Marketing and Consulting, Inc,
#       and ICEM Systems, GmbH.  All rights reserved.
# Author:  Jason K. Aftosmis, jason@icemcfd.com
# $Revision$ on $Date$
# This file contains special comments of the form ## html ... which are
# used to automatically generate documentation

proc ic_compare_mesh_report {model domain msh_version remote_host os} {
    #
    if {(![file exists $domain]) || ([file size $domain] == 0)} {
        if {($msh_version == "standard")} {
            mess "Standard Mesh file is missing\red"
            return ""
        } else {
            mess "Mesh file was  not created\red"
            return ""
        }
    }
    set operating_system [lindex [split $domain .] end-1] 

    if {($msh_version == "standard")} {
       if {($operating_system == $os)} {
            set rpt_file [file join $model std_report_msh_$os.rpt ]
        } else {
            set rpt_file [file join $model std_report_msh.rpt ]
        }
    } else {
        set rpt_file [file join $model current_report_msh_$remote_host.rpt ]
    }
    #
    if {("standard" != $msh_version) && [file exists $rpt_file]} {
        eval cmd_rm_r $rpt_file
    }
    #
    if {("standard" == $msh_version) && [file exists $rpt_file]} {
        return ""
    }
    if ![file exists $rpt_file] {
#
    if [catch {open $rpt_file w} msh_rpt_file] {
        mess "Error: could not open Mesh Report File for writing: " red
        if ![file writable $rpt_file] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file]\n" red
        return
    }
    # --> Set default prefs
    #
    set mesher "Mesh Editor"
    set title "ANSYS ICEM CFD Mesh Report"
    set user [cmd_whoami]
    set script "__NONE__" ;# fixme

    set write_summary     "All"
    set write_quality     "All"
    set write_diagnostics "All"
    set format "xml"
    #
    # --> Parse up given args to see what to write, e.g.: -${param} $paramVal
    #
    # foreach {n v} $args {
    #   set [string range $n 1 end] $v
    #}
    #
    # -->
    #
    if [ic_uns_is_loaded] {
       ic_unload_mesh
    }
    ic_load_unstruct $domain
    set map all
    set must_unload_uns 1

    #
    # --> Check
    #

    if ![ic_uns_is_loaded] {
        mess "Error: cannot write report for a domain without a mesh loaded\n" red
        return ""
    } elseif ![ic_uns_subset_exists $map] {
        mess "Error: cannot write report because can't find the specified subset \"$map\"\n" red
        return ""
    }

    # --> Get Mesh Summary Info
#   set list_diagnostics [ic_uns_diagnostic_keys]
    set list_diagnostics "duplicate multiple standalone single overlap uncovered missing_internal nmanvert vol_orient surf_orient hanging penetrating disconnbars" 
#
    puts $msh_rpt_file "List of Diagnostics: $list_diagnostics \n"

    set which_metrics "Quality Determinant {Aspect ratio}" 

    puts $msh_rpt_file "List of Quality Matrics: $which_metrics \n"
    set list_fams [ic_uns_list_families]
#
    puts $msh_rpt_file "List of Families: $list_fams \n"
#
    set types [ic_uns_subset_list_types $map]
    puts $msh_rpt_file "List of Types: $types \n"
#
    set total_elements [ic_uns_subset_count_elements $map]

    puts $msh_rpt_file "Total number of Elements: $total_elements \n"       
    set data "Element counts [list TOTAL "" $total_elements]"

    set percent_data ""
    set count_data ""

    foreach t $types {
        set num [ic_uns_subset_count_elements $map $t]
        if {0 < $num} {
            puts $msh_rpt_file "Number of Elements in Type $t : $num\n"
        }
    }
    
    set fams [ic_uns_list_families]
    set nfams [llength $fams]
    foreach part $fams  {
        set counts [ic_uns_count_in_families $part]
        puts $msh_rpt_file "Number of Elements in Part:$part : $counts\n"
    }

    #
    # -->
    #
    set min 0
    set max 1
    set nbars 20
    set int_dist [expr double($max - $min) / $nbars]
    puts $msh_rpt_file "Quality Interval Distance: $int_dist \n"
#
#   set which_metrics [ic_uns_get_metric_names]
    foreach metric $which_metrics {
        puts $msh_rpt_file "******* Checking $metric ******\n"
        set data [ic_uns_metric $map "$metric"]

        set nok [lindex $data 0]
        set nundef [lindex $data 1]
        set nbad [lindex $data 2]
#       set min [lindex $data 3]
        set min 0.0
#       set max [lindex $data 4]
        set max 1.0
        set totval [lindex $data 5]

        if {$min >= $max} {
            continue
        }

        set nbars 20
        set hdata [lrange [ic_uns_histogram $map $min $max $nbars] 1 end-1]

        set interval_dist [expr double($max - $min) / $nbars]
        set low $min
        set histogram_data ""
        foreach num $hdata {
            set high [expr $low + $interval_dist]
            lappend histogram_data [list $low $high $num]
            puts $msh_rpt_file "Number of Elements with $metric between $low and $high : $num\n"
            set low $high
        }

        set hist_attributes "name \"$metric\" min $min max $max nintervals $nbars"
        set histogram [list $hist_attributes $histogram_data]

        set children   ""
        set attributes "name \"$metric\""

    }
    #
    # -->
    #

    foreach diag $list_diagnostics {
        puts $msh_rpt_file "*** Diagnostic Check for $diag ***\n" 
        if [catch {ic_uns_diagnostic diag_type "$diag" subset $map} data] {
            mess "$data\n" red
            continue
        } else {
            set name "\"[ic_uns_sub_get_diagnotic_info $diag verbose]\""
            if {"" == $name} { set name $diag }
            set value [lindex $data 0]
            puts $msh_rpt_file "Number of problems found in $diag: $value\n" 
        }
    }
    ic_unload_mesh

    mess "Wrote mesh report for $msh_version version \n"

    close $msh_rpt_file 
#   return $rpt_file 
    }
}

## <h3>XML report editing and modification functions</h3>

## Write a mesh_report XML file of the given subset name <em>what</em> to the given <em>file</em>
## if {"FILE" == $what}, the you must specify "-domain $domainfilename" and it will write a report
## for that entire mesh.
## Args can be:
##   -write_summary $val, -write_quality $val, -write_diagnostics $val, -format (xml|html)
## e.g.:
##   ic_reports_write_mesh_report All test.xml -format xml
##   ic_reports_write_mesh_report FILE test.html -format html -domain project1.uns


proc ic_reports_write_mesh_report_ {what file args} {
    #
    if {"" == [info commands MeshReport::*]} {
        mess "Error: MeshReport module cannot be found to write report: $file\n" red
        return ""
    }
    #
    # --> Set default prefs
    #
    set mesher "Mesh Editor"
    set title "ANSYS ICEM CFD Mesh Report"
    set user [cmd_whoami]
    set script "__NONE__" ;# fixme
    
    set write_summary     "All"
    set write_quality     "All"
    set write_diagnostics "All"    
    set format "xml"    
    #
    # --> Parse up given args to see what to write, e.g.: -${param} $paramVal
    #    
    foreach {n v} $args {
        set [string range $n 1 end] $v
    }
    #
    # --> 
    #    
    if {"FILE" == $what} {
        if [ic_uns_is_loaded] {
            mess "Error: cannot write report for a domain with a mesh already loaded\n" red
            return ""
        } elseif ![info exists domain] {
            mess "Error: cannot write report for a domain without it specified by -domain\n" red
            return ""
        } elseif ![file exists $domain] {
            mess "Error: cannot write report for a domain because can't find $domain\n" red
            return ""
        } else {
            ic_load_unstruct $domain
            set map All
            set must_unload_uns 1
        }
    } else {
        set map $what
    }
    
    #
    # --> Check
    #

    if ![ic_uns_is_loaded] {
        mess "Error: cannot write report for a domain without a mesh loaded\n" red
        return ""
    } elseif ![ic_uns_subset_exists $map] {
        mess "Error: cannot write report because can't find the specified subset \"$map\"\n" red
        return ""
    }
        
    # --> Open/append the report "file" given    
    
    set attributes "title \"$title\" subset $map mesher \"$mesher\" user \"$user\" script \"$script\""
    if [catch { MeshReport::appendReport $file $attributes } dom_key] {
        mess "Error: cannot write report of the specified subset \"$map\" because can't open DOM\n" red
        return ""
    }
        
    # -->    
    
    if {"__NONE__" != $write_summary} {
        
        MeshReport::addSummary $dom_key "subset $map"
                
        # --> Get Mesh Summary Info
        
        set total_elements [ic_uns_subset_count_elements $map]
        
        set data "Element counts [list TOTAL "" $total_elements]"
        set types [ic_uns_subset_list_types $map]
        
        set percent_data ""
        set count_data ""
        
        foreach t $types {
            set num [ic_uns_subset_count_elements $map $t]
            if {0 < $num} {
                lappend percent_data "$t percentage [expr 100 * ${num}.0 / ${total_elements}.0]"
                lappend count_data   "$t integer $num"
            }
        }
        lappend count_data   "Total integer $total_elements"
        
        MeshReport::addSummaryData $dom_key "name \"Element counts\"" $count_data
        MeshReport::addSummaryData $dom_key "name \"Element percentages\"" $percent_data
        
        set fams [ic_uns_list_families]
        set nfams [llength $fams]
        set counts [ic_uns_count_in_families $fams]
        for { set i 0 } { $i < $nfams } { incr i } {
            lappend family_data "[lindex $fams $i] integer [lindex $counts $i]"
        }
        
        MeshReport::addSummaryData $dom_key "name \"Element families\"" $family_data
    }
    
    #
    # --> 
    #
    
    if {"__NONE__" != $write_quality} {

        MeshReport::addQuality $dom_key "subset $map"
        
        if {"All" == $write_quality} {
            set which_metrics [ic_uns_get_metric_names]
        } else {
            set which_metrics $write_quality
        }
        
        foreach metric $which_metrics {
            set data [ic_uns_metric $map "$metric"]
            
            set nok [lindex $data 0]
            set nundef [lindex $data 1]
            set nbad [lindex $data 2]
            set min [lindex $data 3]
            set max [lindex $data 4]
            set totval [lindex $data 5]
                            
            if {$min >= $max} {
                continue
            }
            
            set nbars 10
            set hdata [lrange [ic_uns_histogram $map $min $max $nbars] 1 end-1]         
            
            set interval_dist [expr double($max - $min) / $nbars]
            set low $min
            set histogram_data ""
            foreach num $hdata {
                set high [expr $low + $interval_dist]
                lappend histogram_data [list $low $high $num]
                set low $high
            }
            
            set hist_attributes "name \"$metric\" min $min max $max nintervals $nbars"          
            set histogram [list $hist_attributes $histogram_data]
            
            set children   ""
            set attributes "name \"$metric\""
            
            MeshReport::addQualityMetric $dom_key $attributes $children $histogram
        }       
    }
    
    #
    # --> 
    #
    
    if {"__NONE__" != $write_diagnostics} {
        
        MeshReport::addDiagnostics $dom_key "subset $map"
        
        if {"All" == $write_diagnostics} {
            set which_diagnostics [ic_uns_diagnostic_keys]
        } else {
            set which_diagnostics $write_diagnostics
        }
        
        foreach diag $which_diagnostics {
            
            if [catch {ic_uns_diagnostic diag_type "$diag" subset $map} data] {
                mess "$data\n" red
                continue
            }  else {
                set name "\"[ic_uns_sub_get_diagnotic_info $diag verbose]\""
                if {"" == $name} { set name $diag }
                set value [lindex $data 0]              
                MeshReport::addDiagnosticCriterion $dom_key $name "number $value key \"$diag\""
            }
        }
    }
    
    if {[info exists must_unload_uns] && $must_unload_uns} {
        ic_unload_mesh
    }

    MeshReport::closeReport $dom_key $file $format
    
    mess "Wrote mesh report $file in $format format\n"
    
    return $file    
}
##
proc ic_reports_write_mesh_report {what file args} {
    global fam_visible
    
    #
    # --> Set default prefs
    #
    set mesher "Mesh Editor"
    set title "ANSYS ICEM CFD Mesh Report"
    set user [cmd_whoami]
    set script "__NONE__" ;# fixme
    
    set write_summary     "All"
    set write_quality     "All"
    set write_quality_all "__NONE__"
    set write_diagnostics "All" 
    set format "xml"   
    set map all 
    #
    # --> Parse up given args to see what to write, e.g.: -${param} $paramVal
    #    
    foreach {n v} $args {
        set [string range $n 1 end] $v
    }
    #
    # --> 

    mess "Report File: $file\n" 
    if [catch {open $file w} report_file_html] {
       mess "Error: could not open Report File for writing: " red
       if ![file writable $file] {
           mess " check permissions on directory\n" red
       }
       mess " [file dirname $file]\n" red
       return
    }   
    
    #
    # --> Check
    #

    if ![ic_uns_is_loaded] {
        mess "Error: cannot write report for a domain without a mesh loaded\n" red
        return ""
    } elseif ![ic_uns_subset_exists $map] {
        mess "Error: cannot write report because can't find the specified subset \"$map\"\n" red
        return ""
    }
        
    # --> Open/append the report "file" given    
    puts $report_file_html "<h1><u>$title</u></h1>\n" 
        
    # -->   
    if {"__NONE__" != $write_summary } {
        puts $report_file_html "<h4> <a href=\"#mesh_summary\">Summary of the Mesh</a> </h4>"
    }
    if {"__NONE__" != $write_quality} {
       puts $report_file_html "<h4> <a href=\"#quality_check\">Check Mesh Quality</a> </h4>" 
    }
    if {"__NONE__" != $write_diagnostics} {
       puts $report_file_html "<h4> <a href=\"#diag_check\">Error/Possible Problems in the Mesh</a> </h4>" 
     }    

    if {"__NONE__" != $write_summary} {
        
                
        # --> Get Mesh Summary Info
        
        set total_elements [ic_uns_subset_count_elements $map]
        set total_nodes [ic_uns_subset_count_nodes $map]
        
        set data "Element counts [list TOTAL "" $total_elements]"
        set types [ic_uns_subset_list_types $map]
        
        set percent_data ""
        set count_data ""
        puts $report_file_html "<a name = mesh_summary></a><h4> Summary of the Mesh: </h4>"

        puts $report_file_html "<B>Information of Total Elements: </B>"
        puts $report_file_html "<table BORDER>"
        puts $report_file_html "<tr>"   

        puts $report_file_html "<td><B> Total Elements </B></td>"
        puts $report_file_html "<td><B> Total Nodes </B></td>"
        foreach t $types {
           puts $report_file_html "<td><B> $t </B></td>" 
        }

        puts $report_file_html "<tr>"   

        puts $report_file_html "<td><B> $total_elements </B></td>"
        puts $report_file_html "<td><B> $total_nodes </B></td>"

        foreach t $types {
            set num [ic_uns_subset_count_elements $map $t]
            puts $report_file_html "<td> $num </td>"        
        }
        puts $report_file_html "</tr>"
        puts $report_file_html "</table>"
        puts $report_file_html "<BR>"
                        
        set fams [ic_uns_list_families]
        set nfams [llength $fams]

        puts $report_file_html "<B>Information of Individual Part: </B>"
        puts $report_file_html "<table BORDER>"
        puts $report_file_html "<tr>"
        puts $report_file_html "<td><B> Part Name </B></td>"
        puts $report_file_html "<td> Number of Elements </td>"
        puts $report_file_html "<td> Number of Nodes </td>"
        puts $report_file_html "</tr>"

        set assems ""
        foreach p $fams {
	        set start [string last / $p]
	        if {$start != -1} {
	            lappend assems [string range $p 0 [expr $start - 1]]
	        }
        }

        foreach part [lsort $fams]  {
            if {[lsearch $assems $part] >= 0} continue
            if ![info exists fam_visible($part)] continue
            set counts [ic_uns_count_in_families $part]
            set count_nodes [ic_uns_count_nodes_in_families $part]
            if {"ORFN" != $part} {
                puts $report_file_html "<tr>"
                puts $report_file_html "<td> $part </td>"
                puts $report_file_html "<td> $counts </td>"
                puts $report_file_html "<td> $count_nodes </td>"
                puts $report_file_html "</tr>"
             }
         } 
        puts $report_file_html "</table>"
        puts $report_file_html "<BR>"
        
    }
    
    #
    # --> 
    #
    
    if {"__NONE__" != $write_quality} {

           if {"__NONE__" != $write_quality_all} {
                set which_metrics [ic_uns_get_metric_names]
           } else {
                set which_metrics "Quality Determinant {Aspect ratio} {Min angle} {Max ortho} {Max warp}\
                               {Max warpgls} Skew"
           }
                  
            puts $report_file_html "<h4> <a name=quality_check></a> Quality Check: </h4>"
        
        foreach metric $which_metrics {
            set data [ic_uns_metric $map "$metric"]
            
            puts $report_file_html "<table BORDER>"

            set nok [lindex $data 0]
            set nundef [lindex $data 1]
            set nbad [lindex $data 2]
            set min [lindex $data 3]
            set max [lindex $data 4]
            set totval [lindex $data 5]
                            
            if {$min >= $max} {
                continue
            }
            
            set nbars 10
            set hdata [lrange [ic_uns_histogram $map $min $max $nbars] 1 end-1]         
            
            set interval_dist [expr double($max - $min) / $nbars]
            set low $min
            set low_add $min
            set histogram_data ""

            puts $report_file_html "<tr>" 
            puts $report_file_html "<td><B>Histogram of $metric values</B></td>"            

            foreach num $hdata {
                set high [expr $low + $interval_dist]
                lappend histogram_data [list $low $high $num]
                puts $report_file_html "<td> $low - $high </td>"
                set low $high
            }
            puts $report_file_html "</tr>"          
            puts $report_file_html "<tr>" 
            puts $report_file_html "<td><B> Number of Elements </B></td>"

            foreach num $hdata {
                set high [expr $low_add + $interval_dist]
                lappend histogram_data [list $low_add $high $num]
                puts $report_file_html "<td> $num </td>"
                set low_add $high
            }
            puts $report_file_html "</tr>" 
            puts $report_file_html "</table>"
            puts $report_file_html "<BR>"
        }       
    }
    
    #
    # --> 
    #
    
    if {"__NONE__" != $write_diagnostics} {
        
        
        if {"All" == $write_diagnostics} {
            set which_diagnostics [ic_uns_diagnostic_keys]
        } else {
            set which_diagnostics $write_diagnostics
        }

        puts $report_file_html "<h4> <a name=diag_check></a> Diagnostics Check: </h4>"
        puts $report_file_html "<table BORDER>"
        puts $report_file_html "<tr>" 
        puts $report_file_html "<td><B> Diagnostics </B></td>"      
        puts $report_file_html "<td><B> Number of Elements </B></td>"       
        puts $report_file_html "</tr>" 
        
        foreach diag $which_diagnostics {
            if {"periodic_problem" != $diag} { 
                if [catch {ic_uns_diagnostic diag_type "$diag" subset $map} data] {
                    mess "$data\n" red
                    continue
                }  else {
                    set name "\"[ic_uns_sub_get_diagnotic_info $diag verbose]\""
                    if {"" == $name} { set name $diag }
                    set value [lindex $data 0]          
                    puts $report_file_html "<tr>" 
                    puts $report_file_html "<td><B> $diag </B></td>"    
                    puts $report_file_html "<td><B> $value </B></td>"   
                    puts $report_file_html "</tr>"
                }
            }
        }
    }

    close $report_file_html
    mess "Wrote mesh report $file in $format format\n"
    return $file
}

##

proc ic_reports_compare_mesh {stdmesh {curmesh ""}} {
    set tmpuns reports_tmp.uns
    set mesh2 $stdmesh
    if {$mesh2 == "" || ![file exists $mesh2]} {
        mess "Error: stdmesh not given or not found\n" red
        return ""
    }
    set mesh1 $curmesh
    if {$mesh1 == ""} {
        if {![ic_uns_is_loaded]} {
            mess "Error: no mesh is loaded\n" red
            return ""
        }
        set mesh1 $tmpuns
    } else {
        if {![file exists $mesh1]} {
            mess "Error: curmesh not found\n" red
            return ""
        }
    }
    set saveuns ""
    if {[ic_uns_is_loaded]} {
        set saveuns $tmpuns
        ic_save_unstruct $saveuns
    }

    ic_compare_mesh_report . $mesh2 mesh2 2 ""
    ic_compare_mesh_report . $mesh1 mesh1 1 ""
    ic_compare_get_mesh_report current_report_msh_1.rpt \
        current_report_msh_2.rpt local

    cmd_rm current_report_msh_1.rpt
    cmd_rm current_report_msh_2.rpt
    cmd_rm final_report_local.rpt

    if {$saveuns != ""} {
        ic_load_unstruct $saveuns
        cmd_rm $saveuns
    }

    return final_report_local.html
}

##

proc ic_reports_write_assembly_report { infiles informat outfile outformat args } {
    #
    if {"" == [info commands AssemblyReport::*]} {
        mess "Error: MeshReport module cannot be found to write report: $file\n" red
        return ""
    }
    #
    #
    #
    set mesher "Mesh Editor"
    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 xmlfiles ""
    switch -- $informat {
        domain - uns {
            foreach f $infiles {
                set xml_out "[file root $f].xml"
                lappend xmlfiles [ic_reports_write_mesh_report FILE $xml_out -format xml -domain $f \
                                      -mesher "$mesher" -title $f]
                # nb: these xmlfiles in the list get rm'd later...
            }
        }
        XML - xml {
            set xmlfiles $infiles
        }
        default {
            mess "Error: cannot compile assembly report for intput files of format $informat\n" red
        }
    }
    
    set dom_key [AssemblyReport::appendReport $outfile $attributes]
    
    foreach f $xmlfiles {
        AssemblyReport::addPart $dom_key "name [file root $f]" "" $f
    }
    
    set fixme [AssemblyReport::closeReport $dom_key $outfile $outformat]
    #
    # --> we might have created the xml files ourselves, which we would want to clean up...
    #        
    switch --  $informat {
        domain - uns {
             foreach f $xmlfiles { cmd_rm $f }
        }
    }

    mess "Wrote assembly report $outfile in $outformat format\n"

    return $outfile
} 
#
#
proc ic_compare_geom_report {model geom_file geo_version remote_host os} {
#

    if {(![file exists $geom_file]) || ([file size $geom_file] == 0)} {
        if {($geo_version == "standard")} {
          mess "Standard geometry file is missing\red"
          return ""
         } else {
          mess "Geometry file was  not created\red"
          return ""
         }
      }
    #
     set operating_system [lindex [split $geom_file .] end-1] 
    if {($geo_version == "standard")} {
       if {($operating_system == $os)} {
         set rpt_geo_file [file join $model std_report_geo_$os.rpt ]
       } else {
         set rpt_geo_file [file join $model std_report_geo.rpt]
       }
     } else {
       set rpt_geo_file [file join $model current_report_geo_$remote_host.rpt]
     }
  #
    if {("standard" != $geo_version ) && [file exists $rpt_geo_file]} {
      eval cmd_rm_r $rpt_geo_file
    }  
#  
#
   if ![file exists $rpt_geo_file] {
    if [catch {open $rpt_geo_file w} geo_rpt_file] {
      mess "Error: could not open Geo Report File for writing:\n " red
      if ![file writable $rpt_geo_file] {
        mess " check permissions on directory\n" red
      }
      mess " [file dirname $rpt_geo_file]\n" red
    return
   } 
#
# Making sure 
     if [ic_geo_is_loaded] {
        ic_unload_tetin
      }
#
     ic_load_tetin $geom_file 
     
     if ![ic_geo_is_loaded] {
        error "Can't write the geometry report without any geometry loaded\n" red
     }
# Get the part information
#
      set part_list [ic_geo_list_parts]
      puts $geo_rpt_file "List of Parts: $part_list \n" 
#
      set types [ic_geo_get_types]
      puts $geo_rpt_file "List of Types: $types \n" 
      set fams ""
#
# Get the list of the families present in the tetin file
# 
        foreach part $part_list {
             set fam_in_part [ic_geo_list_families_in_part $part]
              lappend fams $fam_in_part
        }  
      puts $geo_rpt_file "List of Families: $fams \n" 
             set den_names [ic_geo_get_objects density]
      puts $geo_rpt_file "List of Densities: $den_names \n" 

#
        foreach type $types {
          set num [ic_geo_num_objects $type]
          puts $geo_rpt_file " Total number of $type in this geometry: $num\n" 
        } 

#
#----------------------- Curve Information ------------------------
#
        set crvs [ic_geo_get_objects curve]
        set n_unattach_crv 0
        set n_single_crv 0
        set n_double_crv 0
        set n_multi_crv 0
        foreach crv $crvs {
          set con_surfaces [ic_geo_incident curve $crv]
           if {[llength $con_surfaces] == 0} {
              incr n_unattach_crv
            } 
           if {[llength $con_surfaces] == 1} {
              incr n_single_crv 
            } 
           if {[llength $con_surfaces] == 2} {
              incr n_double_crv 
            } 
           if {[llength $con_surfaces] >= 3} {
              incr n_multi_crv 
            } 
          }
         puts $geo_rpt_file "Total Number of Unattached Curve: $n_unattach_crv\n"
         puts $geo_rpt_file "Total Number of Single Curve: $n_single_crv\n"
         puts $geo_rpt_file "Total Number of Double Curve: $n_double_crv\n"
         puts $geo_rpt_file "Total Number of Multiple Curve: $n_multi_crv\n"
#
#----------------------- Surface Information ------------------------
#
        set surfaces [ic_geo_get_objects surface]
        set n_surfs [llength $surfaces]
         puts $geo_rpt_file "Total number of Surface: $n_surfs\n"
        set total_surf_area [ic_geo_srf_area $surfaces]
         puts $geo_rpt_file "Total Surface Area: $total_surf_area\n"
#
#----------------------- Material Information ------------------------
#
        set mats [ic_geo_get_objects material]
        set n_mats [llength $mats]
         puts $geo_rpt_file "Total number of Material Points: $n_mats\n"
#
#----------------------- Loop Information ------------------------
#
        set loops [ic_geo_get_objects loop]
        set n_loops [llength $loops]
         puts $geo_rpt_file "Total number of Loops: $n_loops\n"
#
#----------------------- Density Information ------------------------
#
        set dens [ic_geo_get_objects density]
        set n_dens [llength $dens]
         puts $geo_rpt_file "Total number of Density: $n_dens\n"
#
#----------------------- Density Information ------------------------
#
        set bodys [ic_geo_get_objects body]
        set n_bodys [llength $bodys]
         puts $geo_rpt_file "Total number of body: $n_bodys\n"
#
#------------------ Family Information ----------------------------
#
        foreach fam $fams {
#
# --------- Point Information in Part ----------------------- 
#
         set n_pnt_fam [ic_geo_count_in_family point $fam]
         puts $geo_rpt_file "Number of Points in $fam: $n_pnt_fam\n"
#
# --------- Curve Information in Part ----------------------- 
#
          set fam_crvs [ic_geo_objects_in_family curve $fam]       
           set n_fam_unattach_crv 0
           set n_fam_single_crv 0
           set n_fam_double_crv 0
           set n_fam_multi_crv 0
             foreach fam_crv $fam_crvs {
               set fam_con_surfaces [ic_geo_incident curve $fam_crv]
               if {[llength $fam_con_surfaces] == 0} {
                  incr n_fam_unattach_crv
                } 
                if {[llength $fam_con_surfaces] == 1} {
                   incr n_fam_single_crv 
                } 
                if {[llength $fam_con_surfaces] == 2} {
                    incr n_fam_double_crv 
                } 
                if {[llength $fam_con_surfaces] >= 3} {
                    incr n_fam_multi_crv 
                } 
              }
         puts $geo_rpt_file "Total Number of Unattached Curve in Part $fam : $n_fam_unattach_crv\n"
         puts $geo_rpt_file "Total Number of Single Curve in Part $fam : $n_fam_single_crv\n"
         puts $geo_rpt_file "Total Number of Double Curve in Part $fam : $n_fam_double_crv\n"
         puts $geo_rpt_file "Total Number of Multiple Curve in Part $fam : $n_fam_multi_crv\n"
#
# --------- Surface Information in Part ----------------------- 
#
         set n_surf_fam [ic_geo_count_in_family surface $fam]
         puts $geo_rpt_file "Number of Surfaces in $fam: $n_surf_fam\n"
#
# --------- Material Information in Part ----------------------- 
#
         set n_mat_fam [ic_geo_count_in_family material $fam]
         puts $geo_rpt_file "Number of Material Points in $fam: $n_mat_fam\n"
#
# --------- Density Information in Part ----------------------- 
#
         set n_den_fam [ic_geo_count_in_family density $fam]
         puts $geo_rpt_file "Number of density in $fam: $n_den_fam\n"
#
# --------- Loop Information in Part ----------------------- 
#
         set n_loop_fam [ic_geo_count_in_family loop $fam]
         puts $geo_rpt_file "Number of loop in $fam: $n_loop_fam\n"
#
# --------- Body Information in Part ----------------------- 
#
         set n_body_fam [ic_geo_count_in_family body $fam]
         puts $geo_rpt_file "Number of body in $fam: $n_body_fam\n"
      }
#----------------------- Global Meshing Parameter ----------------------------- 
# Get the reference size
# 
      foreach {n v} [ic_get_meshing_params global 0] {
         if {$n == "gref"} {
           puts $geo_rpt_file "Reference  Global Mesh Size: $v\n"
         }
         if {$n == "gmax"} {
           puts $geo_rpt_file "Max Element Size: $v\n"
         } 
         if {$n == "gnat"} {
           puts $geo_rpt_file "Natural Size: $v\n"
         } 
         if {$n == "gnatref"} {
           puts $geo_rpt_file "Refinement: $v\n"
         } 
         if {$n == "gedgec"} {
           puts $geo_rpt_file "Edge Criteria: $v\n"
         } 
         if {$n == "gcgap"} {
           puts $geo_rpt_file "Cells in Gap: $v\n"
         } 
         if {$n == "gttol"} {
           puts $geo_rpt_file "Trianguler Tolerance: $v\n"
         } 
         if {$n == "gfast"} {
           puts $geo_rpt_file "Fast Transition: $v\n"
         } 
         if {$n == "igwall"} {
           puts $geo_rpt_file "Internal Wall: $v\n"
         } 
      }
# Density Parameters
        foreach name [ic_geo_get_objects density] {
            set np [ic_geo_num_nodes density $name]
            foreach {n v} [ic_get_meshing_params density $name] {
                if {$n == "emax"} {
                  puts $geo_rpt_file "Element Size for Density $name : $v\n"
                }
                if {$n == "erat"} {
                  puts $geo_rpt_file "Height Ratio for Density $name : $v\n"
                }
                if {$n == "ewid"} {
                  puts $geo_rpt_file "Width for Density $name : $v\n"
                }
             }
         } 
        ic_unload_tetin
#        mess "Done Geometry Report\n" blue
        close $geo_rpt_file
     }
}
#
proc ic_compare_blk_report {model geom_file blk_file blk_version remote_host os} {
#
    if {(![file exists $blk_file]) || ([file size $blk_file] == 0)} {
        if {($blk_version == "standard")} {
          mess "Standard blocking file is missing\n"
          return ""
         } else {
          mess "Blocking file was  not created\n"
          return ""
         }
      } 
    #
     set operating_system [lindex [split $blk_file .] end-1] 
    if {($blk_version == "standard")} {
       if {($operating_system == $os)} {
         set rpt_blk_file [file join $model std_report_blk_$os.rpt ]
        } else {
         set rpt_blk_file [file join $model std_report_blk.rpt ]
        } 
     } else {
       set rpt_blk_file [file join $model current_report_blk_$remote_host.rpt ]
     }
  #
    if {("standard" != $blk_version) && [file exists $rpt_blk_file]} {
      eval cmd_rm_r $rpt_blk_file
     }
#
   if ![file exists $rpt_blk_file] { 
  #
    if [catch {open $rpt_blk_file w} geo_blk_file] {
      mess "Error: could not open Mesh Report File for writing: " red
      if ![file writable $rpt_blk_file] {
        mess " check permissions on directory\n" red
      }
      mess " [file dirname $rpt_blk_file]\n" red
    return
     } 
    if ![ic_geo_is_loaded] {
        ic_load_tetin [file join $model $geom_file] 
    }
    
    if ![ic_hex_blocking_loaded] {
        ic_hex_restore_blocking [file join $model $blk_file] 
    }
     
     if ![ic_hex_blocking_loaded] {
        error "Can't write the Blocking report without any Blocking loaded\n" red
     }
#
        ic_hex_report_blocking $rpt_blk_file
        close $geo_blk_file
        ic_unload_tetin 
        ic_hex_unload_blocking  
    }
} 

proc ic_compare_get_mesh_report {cur_msh_rpt std_msh_rpt remote_host {tol 0.7}} {
    #
    # --> Parse up given args to see what to write, e.g.: -${param} $paramVal
    global env html_head
    set model [file dirname $std_msh_rpt]
    set map all
    set min 0.0
    set max 1.0 
    set nbars 20 
    set interval_dist [expr double($max - $min) / $nbars]
    set rpt_file [file join $model final_report_$remote_host.rpt]
    set rpt_file_html [file join $model final_report_$remote_host.html]
    set plat_name [lindex [split [lindex [file split $env(ICEM_ACN)] end] "-"] end]
    #
    #   Print some debug info if > 0.
    #
    set db 0
    #
    if [catch {open $rpt_file a+} final_rpt_file] {
        mess "Error: could not open Mesh Report File for writing: " red
        if ![file writable $rpt_file] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file]\n" red
        return
    }
    if [catch {open $rpt_file_html a+} final_rpt_file_html] {
        mess "Error: could not open Mesh Report File for writing: " red
        if ![file writable $rpt_file_html] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file_html]\n" red
        return
    }
#   set html_head 0
#
    if {(![file exists [file join $model $cur_msh_rpt]]) || ([file size [file join $model $cur_msh_rpt]] == 0)} { 
        puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
        puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
        puts $final_rpt_file_html "<LI><B>Test case failed:</B> Mesh was not created </li>"
        close $final_rpt_file_html
        return
    }
#
    if {(![file exists [file join $model $std_msh_rpt]]) || ([file size [file join $model $std_msh_rpt]] == 0)} {
        puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
        puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
        puts $final_rpt_file_html "<LI><B>Test case failed:</B> Setup is wrong. Please make sure that you have the standard mesh file in the testing directory </li>"
        close $final_rpt_file_html 
        return
    }
#
    set std_file [open [file join $model $std_msh_rpt] r]
    set cur_file [open [file join $model $cur_msh_rpt] r] 
    set l1 0
    set l2 0
#
    while {[gets $std_file sd_ln] >=0} {
        incr l1
        if [regexp "List of Diagnostics:" $sd_ln] {
            set which_diagnostics [lrange $sd_ln 3 end]
        }
        if [regexp "List of Families:" $sd_ln] {
            set fams [lrange $sd_ln 3 end]
        }
        if [regexp "List of Types:" $sd_ln] {
            set types [lrange $sd_ln 3 end]
        }
        if [regexp "List of Quality Matrics:" $sd_ln] {
            set which_metrics [lrange $sd_ln 3 end]
        }
    }
    seek $std_file 0 start
    set line1 0
    set line2 0 
    while {[gets $std_file std_line] >=0} {
        incr line1
#       puts "line$line1: $std_line"
        if [regexp "Total number of Elements:" $std_line] {
            set n_total_elm [lindex $std_line end]
        }
        foreach t $types {
            if [regexp "Number of Elements in Type $t :" $std_line] {
                set n_elem($t) [lindex $std_line end]
            }
        }
        if [regexp Part $std_line] {
            foreach part $fams  {
                if [regexp "Number of Elements in Part:$part :" $std_line] {
                set n_elem($part) [lindex $std_line end]
                }
            }
        }
        if [regexp between $std_line] {
            foreach metric $which_metrics {
                if [regexp $metric $std_line] {
                    set i 0
                    set low $min
                    while {$i <= $nbars} {
                        incr i
                        set high [expr $low + $interval_dist]
                        if [regexp "Number of Elements with $metric between $low and $high" $std_line] {
                            set n_elem_qua($low-$high) [lindex $std_line end]
                        }
                        set low $high
                    }
                }
            }
        }
#
        if [regexp problems $std_line] {
            foreach diag $which_diagnostics {
                if [regexp "Number of problems found in $diag:" $std_line] {
                    set n_elem($diag) [lindex $std_line end]
                }
            }
        }
    }
#
    while {[gets $cur_file cur_line] >=0} {
        incr line2
#       puts "line$line2: $cur_line"
        if {[info exists n_total_elm] && [regexp "Total number of Elements:" $cur_line]} {  
            set n_total_elm_cur [lindex $cur_line end]
            if {[expr abs($n_total_elm - $n_total_elm_cur)] > [expr pow(10,($tol*log10(1+$n_total_elm)))]} {
                puts $final_rpt_file "Difference in Total number of Elements:\n Total Number of Elements in the Current Version is $n_total_elm_cur . Total Number of Elements in the Standard Mesh is $n_total_elm\n"
                if {![info exists html_head] || ($html_head == 0)} {
                    puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                    puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                    set html_head 1 
                }
                puts $final_rpt_file_html "<LI><B> Difference in Total number of Elements:</B> </li> <BR> Total Number of Elements in the Current Version is $n_total_elm_cur <BR> Total Number of Elements in the Standard Mesh is $n_total_elm\n <BR>"
                if {$db > 0} {
                    puts $final_rpt_file_html "Error condition: [expr abs($n_total_elm - $n_total_elm_cur)] > [expr pow(10,($tol*log10(1+$n_total_elm)))]<BR>"
                }
                puts $final_rpt_file_html "<BR>"
            }
        }
        #
        foreach t $types {
            if {[regexp "Number of Elements in Type $t :" $cur_line] && [info exists n_elem($t)]} {  
                set tn_std $n_elem($t) 
                set tn_cur [lindex $cur_line end]
                if {[expr abs($tn_std - $tn_cur)] > [expr pow(10,($tol*log10(1+$tn_std)))]} {
                    puts $final_rpt_file "****Difference in Number of Elements in Type $t:\n Total Number of Elements in the Current Version is $tn_cur . Total Number of Elements in the Standard Mesh is $tn_std\n"
                    if {![info exists html_head] || ($html_head == 0)} {
                        puts $final_rpt_file_html "<h2>Platform:$plat_name </h2>\n"
                        puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>\n"
                        set html_head 1 
                    }
                    puts $final_rpt_file_html "<LI> <B>Difference in Number of Elements in Type $t: </B></li> \n  <BR> Total Number of Elements in the Current Version is $tn_cur <BR> Total Number of Elements in the Standard Mesh is $tn_std\n <BR><BR>"
                }
            }
        }
        #
        if [regexp Part $cur_line] {
            foreach part $fams  {
                if {([regexp "Number of Elements in Part:$part :" $cur_line]) && [info exists n_elem($part)]} {  
                    set tn_std $n_elem($part) 
                    set tn_cur [lindex $cur_line end]
                    if {$part != "ORFN" && ([expr abs($tn_std - $tn_cur)] > [expr pow(10,($tol*log10(1+$tn_std)))])} {
                        puts $final_rpt_file "****Difference in Number of Elements in Part $part:\n Number of Elements in the Current Version is $tn_cur . Number of Elements in the Standard Mesh is $tn_std\n"
                        if {![info exists html_head] || ($html_head == 0)} {
                            puts $final_rpt_file_html "<h2>Platform:$plat_name </h2>\n"
                            puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>\n"
                            set html_head 1 
                        }
                        puts $final_rpt_file_html "<LI><B>Difference in Number of Elements in Part $part: </B> </li> \n <BR>Number of Elements in the Current Version is $tn_cur <BR> Number of Elements in the Standard Mesh is $tn_std\n<BR>"
                        if {$db > 0} {
                            puts $final_rpt_file_html "Error condition: [expr abs($tn_std - $tn_cur)] > [expr pow(10,($tol*log10(1+$tn_std)))]<BR>"
                        }
                        puts $final_rpt_file_html "<BR>"
                    }
                }
            }
        }
        #
        # -->
        #
        if [regexp between $cur_line] {
            if [regexp $metric $cur_line] {
                foreach metric $which_metrics {
                    set i 0 
                    set low $min
                    while {$i <= $nbars} {
                        incr i
                        set high [expr $low + $interval_dist]
                        if {([regexp "Number of Elements with $metric between $low and $high" $cur_line]) && ([info exists n_elem_qua($low-$high)])} {
                            set tn_std $n_elem_qua($low-$high)
                            set tn_cur [lindex $cur_line end]
                            if {$db > 0 && $high <= 0.2} {
                                puts $final_rpt_file_html "Number of Elements with $metric quality between $low and $high is $tn_cur. In the Standard Mesh it's $tn_std<BR>"
                            }
                            if { ($high <= 0.2 ) && [expr abs($tn_std - $tn_cur)] > [expr pow(10,($tol*log10(1+$tn_std)))]} {
                                puts $final_rpt_file "****Difference in Quality:\n Number of Elements with $metric quality between $low and $high is $tn_cur . In the Standard Mesh it's $tn_std\n"
                            if {![info exists html_head] || ($html_head == 0)} {
                                    puts $final_rpt_file_html "<h2>Platform:$plat_name </h2>\n"
                                    puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>\n"
                                    set html_head 1 
                                }
                                puts $final_rpt_file_html "<LI><B>Difference in Quality:</B> </li> <BR> Number of Elements with $metric quality between $low and $high is $tn_cur <BR> In the Standard Mesh it's $tn_std <BR><BR>"
                            }
                        }
                        set low $high
                    }
                }
            }
        }
        #
        # -->
        #
        if [regexp problems $cur_line] {
            foreach diag $which_diagnostics {
                if {([regexp "Number of problems found in $diag:" $cur_line]) && [info exists n_elem($diag)]} {  
                    set n_std($diag) $n_elem($diag)
                    set n_cur($diag) [lindex $cur_line end]
                    if {[expr abs($n_std($diag) - $n_cur($diag))] > [expr pow(10,($tol*log10(1+$n_std($diag))))]} {
                        puts $final_rpt_file "****Difference in Diagnostic Check:\n Number of Problems for $diag is $n_cur($diag) . In the Standard Mesh it's $n_std($diag)\n"
                        if {![info exists html_head] || ($html_head == 0)} {
                            puts $final_rpt_file_html "<h2>Platform:$plat_name </h2>\n"
                            puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>\n"
                            set html_head 1
                        }
                        puts $final_rpt_file_html "<LI><B>Difference in Diagnostic Check: </B></LI> Number of Problems for $diag is $n_cur($diag) <BR> In the Standard Mesh it's $n_std($diag)<BR><BR>"
                    }
                }
            }
        }
    }
    close $std_file
    close $cur_file  
    close $final_rpt_file 
    close $final_rpt_file_html 
    mess "Wrote Final Mesh Report \n"
    return
}

proc ic_compare_get_solver_input_file_report {cur_solver_input_file std_solver_input_file remote_host} {
      global html_head
      set rpt_file [file join $model final_report_$remote_host.rpt ]
    if [file exists $rpt_file] {
      eval cmd_rm_r $rpt_file
    }  
  # 
    if ![file exists $rpt_file] {
# 
    if [catch {open $rpt_file w} solver_rpt_file] {
      mess "Error: could not open Mesh Report File for writing: " red
      if ![file writable $rpt_file] {
        mess " check permissions on directory\n" red
      }
      mess " [file dirname $rpt_file]\n" red
    return
   } 
 }
}
proc ic_compare_get_geom_report {cur_geom_rpt std_geom_rpt remote_host {tol 1}} {
    #
    global env html_head
    set model [file dirname $std_geom_rpt]
  
       set rpt_file final_report_$remote_host.rpt
       set rpt_file_html final_report_$remote_host.html
    
    set plat_name [lindex [split [lindex [file split $env(ICEM_ACN)] end] "-"] end] 
    #
    # --> Check
    #
    #if [file exists $rpt_file] {
    #  eval cmd_rm_r $rpt_file 
    #}  
    if [catch {open $rpt_file a+} final_rpt_file] {
      mess "Error: could not open Mesh Report File for writing: " red
      if ![file writable $rpt_file] {
        mess " check permissions on directory\n" red
      }
      mess " [file dirname $rpt_file]\n" red
    return
   } 
#
    if [catch {open $rpt_file_html a+} final_rpt_file_html] {
        mess "Error: could not open Mesh Report File for writing: " red
        if ![file writable $rpt_file_html] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file_html]\n" red
        return
    } 
#    set html_head 0
#
         if {(![file exists [file join $model $cur_geom_rpt]]) || ([file size [file join $model $cur_geom_rpt]] == 0)} { 
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1
                } 
                 puts $final_rpt_file_html "<LI><B>Test case failed:</B> Geometry was not created </li>"
                 close $final_rpt_file_html 
                  return 
            } 
#

         if {(![file exists [file join $model $std_geom_rpt]]) || ([file size [file join $model $std_geom_rpt]] == 0)} { 
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1
                } 
                 puts $final_rpt_file_html "<LI><B>Test case failed:</B> Setup is wrong. Please make sure that you have the standard geometry file in the testing directory </li>"
                 close $final_rpt_file_html 
                  return 
             } 
#

        set std_file [open $std_geom_rpt r]
        set cur_file [open $cur_geom_rpt r] 
           set l1 0
        while {[gets $std_file sd_line] >=0} {
            incr l1
           if [regexp "List of Parts:" $sd_line] {
              set part_list [lrange $sd_line 3 end]
            }
           if [regexp "List of Types:" $sd_line] {
              set types [lrange $sd_line 3 end]
            }
           if [regexp "List of Families:" $sd_line] {
              set fams [lrange $sd_line 3 end]
            }
           if [regexp "List of Densities:" $sd_line] {
              set den_names [lrange $sd_line 3 end]
            }
        }
seek $std_file 0 start 
           set line1 0
           set line2 0 
        while {[gets $std_file std_line] >=0} {
           incr line1
#
          foreach type $types {
               if [regexp "Total number of $type in this geometry:" $std_line] {
                  set n_entity($type) [lindex $std_line end]
               }
            }
#
               if [regexp "Total Number of Unattached Curve:" $std_line] {
                  set n_total_unattach [lindex $std_line end]
                }
#
                if [regexp "Total Number of Single Curve:" $std_line] {
                   set n_total_single [lindex $std_line end]
                }
#
                if [regexp "Total Number of Double Curve:" $std_line] {
                   set n_total_double [lindex $std_line end]
                }
#
                if [regexp "Total Number of Multiple Curve:" $std_line] {
                   set n_total_multiple [lindex $std_line end]
                }
# Surface Info
                if [regexp "Total number of Surface:" $std_line] {
                   set n_total_surf [lindex $std_line end]
                }
               if [regexp "Total Surface Area:" $std_line] {
                   set total_surf_area [lindex $std_line end]
               }
# Material Info
                if [regexp "Total number of Material Points:" $std_line] {
                   set n_total_mat [lindex $std_line end]
                }
# Loop Info
                if [regexp "Total number of Loops:" $std_line] {
                   set n_total_loop [lindex $std_line end]
                }
# Density Info
                if [regexp "Total number of Density:" $std_line] {
                   set n_total_den [lindex $std_line end]
                } 
# Body Information
                if [regexp "Total number of body:" $std_line] {
                   set n_total_body [lindex $std_line end]
                }
# Family Info
          foreach fam $fams {
                if [regexp "Number of Points in Part $fam:" $std_line] {
                   set n_points($fam) [lindex $std_line end]
                }
#
                if [regexp "Total Number of Unattached Curve in Part $fam :" $std_line] {
                   set n_crv_unattach($fam) [lindex $std_line end]
                }
#
                if [regexp "Total Number of Single Curve in Part $fam :" $std_line] {
                   set n_crv_single($fam) [lindex $std_line end]
                }
#
                if [regexp "Total Number of Double Curve in Part $fam :" $std_line] {
                   set n_crv_double($fam) [lindex $std_line end]
                }
#
                if [regexp "Total Number of Multiple Curve in Part $fam :" $std_line] {
                   set n_crv_multiple($fam) [lindex $std_line end]
                }
#
                if [regexp "Number of Surfaces in Part $fam:" $std_line] {
                   set n_surf($fam) [lindex $std_line end]
                }
#
                if [regexp "Number of Material Points in Part $fam:" $std_line] {
                   set n_mat($fam) [lindex $std_line end]
                }
#
                if [regexp "Number of Density in Part $fam:" $std_line] {
                   set n_den($fam) [lindex $std_line end]
                }
#
                if [regexp "Number of Body in Part $fam:" $std_line] {
                   set n_body($fam) [lindex $std_line end]
                }
#
                if [regexp "Number of Loop in Part $fam:" $std_line] {
                   set n_loop($fam) [lindex $std_line end]
                }
            }
#
                if [regexp "Reference Global Mesh Size:" $std_line] {
                   set ref_size [lindex $std_line end]
                }
#
                if [regexp "Max Element Size:" $std_line] {
                   set max_size [lindex $std_line end]
                }
#
                if [regexp "Natural Size:" $std_line] {
                   set mat_size [lindex $std_line end]
                }
#                                       
                if [regexp "Refinement:" $std_line] {
                   set refinement [lindex $std_line end]
                }
#
                if [regexp "Edge Criteria:" $std_line] {
                   set edge_crt [lindex $std_line end]
                }
#
                if [regexp "Cells in Gap:" $std_line] {
                   set cell_gap [lindex $std_line end]
                }
#
                if [regexp "Trianguler Tolerance:" $std_line] {
                   set tri_tol [lindex $std_line end]
                }
#
                if [regexp "Fast Transition:" $std_line] {
                   set fast_tran [lindex $std_line end]
                }
#
                if [regexp "Internal Wall:" $std_line] {
                   set inter_all [lindex $std_line end]
                }
#
          foreach name $den_names {
                if [regexp "Element Size for Density $name :" $std_line] {
                   set den_size($name) [lindex $std_line end]
                }
                if [regexp "Height Ratio for Density $name :" $std_line] {
                   set den_ratio($name) [lindex $std_line end]
                }
                if [regexp "Width for Density $name :" $std_line] {
                   set den_width($name) [lindex $std_line end]
                }
           }            
#         
        }
#
         while {[gets $cur_file cur_line] >=0} {
           incr line2
#
#
# Get the list of the families present in the tetin file
# 
        foreach type $types {
             if {[regexp "Total number of $type in this geometry:" $cur_line] && [info exists n_entity($type)]} {  
                  set tn_std $n_entity($type) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Total Number of $type:\n Number of $type in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
#
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Total Number of $type: </B></li> <BR>Number of $type in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                 
                    } 
                }
          } 
#
#----------------------- Curve Information ------------------------
#
             if {[regexp "Total Number of Unattached Curve:" $cur_line] && [info exists n_total_unattach]} {  
                  set tn_std $n_total_unattach 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Total Number of Unattached Curve:\n Number of unattached curve in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Total Number of Unattached Curve: </li></B> <BR> Number of unattached curve in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR> <BR>"
                     }
                }
             if {[regexp "Total Number of Single Curve:" $cur_line] && [info exists n_total_single]} {  
                  set tn_std $n_total_single 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Total Number of single Curve:\n Number of single curve in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI> <B>Difference in Total Number of single Curve: </B> </LI> <BR> Number of single curve in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR> <BR>"
                     }
                }
             if {[regexp "Total Number of Double Curve:" $cur_line] && [info exists n_total_double]} {  
                  set tn_std $n_total_double 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>$tol} {
                    puts $final_rpt_file "****Difference in Total Number of double Curve:\n Number of double curve in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html " <LI> <B>Difference in Total Number of double Curve: </B> </li> Number of double curve in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Total Number of Multiple Curve:" $cur_line] && [info exists n_total_multiple]} {  
                  set tn_std $n_total_multiple 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>$tol} {
                    puts $final_rpt_file "****Difference in Total Number of multiple Curve:\n Number of multiple curve in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html " <LI><B>Difference in Total Number of multiple Curve: </B></li> <BR> Number of multiple curve in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
#----------------------- Surface Information ------------------------
#
             if {[regexp "Total number of Surface:" $cur_line] && [info exists n_total_surf]} {  
                  set tn_std $n_total_surf 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Total Number of Surfaces:\n Number of surface in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Total Number of Surfaces: </B></li> <BR>Number of surface in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
               if {[regexp "Total Surface Area:" $cur_line] && ($n_total_surf >0)} {
                   set area_std $total_surf_area 
                   set area_cur [lindex $cur_line end] 
                      if {[expr abs($area_cur - $area_std)*100/$area_std]>1.0} {
                          puts $final_rpt_file "****Difference in Total Surface Area:\n Total surface area in the current version is $area_cur . In the Standard Geometry it's $area_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                                puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                                puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                                set html_head 1 
               }
                        puts $final_rpt_file_html "<LI><B>Difference in Total Surface Area: </B></li> <BR>Total surface area in the current version is $area_cur <BR> In the Standard Geometry it's $area_std <BR><BR>"
                  
                      }
               } 
#----------------------- Material Information ------------------------
#
             if {[regexp "Total number of Material Points:" $cur_line] && [info exists n_total_mat]} {  
                  set tn_std $n_total_mat 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Total Number of Material Points:\n Number of Material Points in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Total Number of Material Points: <B></li> Number of Material Points in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
#----------------------- Loop Information ------------------------
#
             if {[regexp "Total number of Loops:" $cur_line] && [info exists n_total_loop]} {  
                  set tn_std $n_total_loop 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Total Number of Loops:\n Number of Loops in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Total Number of Loops: </B></li> Number of Loops in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
#----------------------- Density Information ------------------------
#
             if {[regexp "Total number of Density:" $cur_line] && [info exists n_total_den]} {  
                  set tn_std $n_total_den 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Total Number of Density:\n Number of Density in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Total Number of Density: </B></li> <BR> Number of Density in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
#----------------------- Body Information ------------------------
#
             if {[regexp "Total number of body:" $cur_line] && [info exists n_total_body]} {  
                  set tn_std $n_total_body 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Total Number of Body:\n Number of Body in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Total Number of Body: </B></li> <BR> Number of Body in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
#------------------ Family Information ----------------------------
#
        foreach fam $fams {
#
# --------- Point Information in Part ----------------------- 
#
             if {[regexp "Number of Points in $fam:" $cur_line] && [info exists n_points($fam)]} {  
                  set tn_std $n_points($fam) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>$tol} {
                    puts $final_rpt_file "****Difference in Number of Points in Part $fam: \n Number of points in the current version is $tn_cur . In the Standard Geometry it's $tn_std \n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of Points in Part $fam: </B></li> <BR> Number of points in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
# --------- Curve Information in Part ----------------------- 
#
             if {[regexp "Total Number of Unattached Curve in Part $fam :" $cur_line] && [info exists n_crv_unattach($fam)]} { 
                  set tn_std $n_crv_unattach($fam) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Number of Unattached curve in Part $fam:\n Number of unattached curve in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of Unattached curve in Part $fam: </B></li> Number of unattached curve in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Total Number of Single Curve in Part $fam :" $cur_line] && [info exists n_crv_single($fam)]} { 
                  set tn_std $n_crv_single($fam) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Number of single curve in Part $fam:\n Number of single curve in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of single curve in Part $fam: </B> </li> Number of single curve in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Total Number of Double Curve in Part $fam :" $cur_line] && [info exists n_crv_double($fam)]} { 
                  set tn_std $n_crv_double($fam) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>$tol} {
                    puts $final_rpt_file "****Difference in Number of double curve in Part $fam:\n Number of double curve in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of double curve in Part $fam: </B></LI> Number of double curve in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Total Number of Multiple Curve in Part $fam :" $cur_line] && [info exists n_crv_multiple($fam)]} { 
                  set tn_std $n_crv_multiple($fam) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>$tol} {
                    puts $final_rpt_file "****Difference in Number of multiple curve in Part $fam:\n Number of multiple curve in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html " <LI><B>Difference in Number of multiple curve in Part $fam: </B></li> Number of multiple curve in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
# --------- Surface Information in Part ----------------------- 
#
             if {[regexp "Number of Surfaces in $fam:" $cur_line] && [info exists n_surf($fam)]} { 
                  set tn_std $n_surf($fam) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Number of surfaces in Part $fam:\n Number of surface in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of surfaces in Part $fam: </B></li> Number of surface in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
# --------- Material Information in Part ----------------------- 
#
             if {[regexp "Number of Material Points in $fam:" $cur_line] && [info exists n_mat($fam)]} { 
                  set tn_std $n_mat($fam) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Number of materials in Part $fam:\n Number of materials in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of materials in Part $fam: </B></li> <BR>  Number of materials in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
# --------- Density Information in Part ----------------------- 
#
             if {[regexp "Number of density in $fam:" $cur_line] && [info exists n_den($fam)]} { 
                  set tn_std $n_den($fam) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Number of Density in Part $fam:\n Number of density in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of Density in Part $fam: </B></li> <BR> Number of density in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
# --------- Loop Information in Part ----------------------- 
#
             if {[regexp "Number of loop in $fam:" $cur_line] && [info exists n_loop($fam)]} { 
                  set tn_std $n_loop($fam) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Number of loop in Part $fam:\n Number of loop in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of loop in Part $fam: <B> </li> Number of loop in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
# --------- Body Information in Part ----------------------- 
#
             if {[regexp "Number of body in $fam:" $cur_line] && [info exists n_body($fam)]} { 
                  set tn_std $n_body($fam) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Number of body in Part $fam:\n Number of body in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of body in Part $fam: </B></li> <BR> Number of body in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
      }
#----------------------- Global Meshing Parameter ----------------------------- 
# Get the reference size
# 
             if {[regexp "Reference  Global Mesh Size:" $cur_line] && [info exists ref_size]} { 
                  set tn_std $ref_size 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Reference Mesh Size:\n Reference size in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Reference Mesh Size: </B> </li> <BR> Reference size in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Max Element Size:" $cur_line] && [info exists max_size]} { 
                  set tn_std $max_size 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Max Element Size:\n Max size in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html " <LI><B>Difference in Max Element Size: </B></li> Max size in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Natural Size:" $cur_line] && [info exists mat_size]} { 
                  set tn_std $mat_size 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Natural Size:\n Natural size in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file "<LI><B>Difference in Natural Size: </B></li> Natural size in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Refinement:" $cur_line] && [info exists refinement]} { 
                  set tn_std $refinement 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Refinement:\n Refinement in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Refinement: </B></LI> <BR> Refinement in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Edge Criteria:" $cur_line] && [info exists edge_crt]} { 
                  set tn_std $edge_crt 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Edge Criteria:\n Edge Criteria in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Edge Criteria: </B></li> <BR> Edge Criteria in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Cells in Gap:" $cur_line] && [info exists cell_gap]} { 
                  set tn_std $cell_gap 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Cells in Gap:\n Cells in Gap in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Cells in Gap: </B></li> <BR> Cells in Gap in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Trianguler Tolerance:" $cur_line] && [info exists tri_tol]} { 
                  set tn_std $tri_tol 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Trianguler Tolerance:\n Trianguler Tolerance in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Trianguler Tolerance: </B></li> Trianguler Tolerance in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Fast Transition:" $cur_line] && [info exists fast_tran]} { 
                  set tn_std $fast_tran 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Fast Transition:\n Fast Transition in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Fast Transition: </B></li> <BR> Fast Transition in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Internal Wall:" $cur_line] && [info exists inter_all]} { 
                  set tn_std $inter_all 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Internal Wall:\n Internal Wall in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Internal Wall: </B></li> Internal Wall in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
# Density Parameters
        foreach name $den_names {
             if {[regexp "Element Size for Density $name :" $cur_line] && [info exists den_size($name)]} { 
                  set tn_std $den_size($name) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Density Size:\n Density size for density $name in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Density Size: </B> </li> Density size for density $name in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR> <BR>"
                     }
                }
             if {[regexp "Height Ratio for Density $name :" $cur_line] && [info exists den_ratio($name)]} { 
                  set tn_std $den_ratio($name) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Density Ratio:\n Density ratio for density $name in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Density Ratio: </B></li> <BR> Density ratio for density $name in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Width for Density $name :" $cur_line] && [info exists den_width($name)]} { 
                  set tn_std $den_width($name) 
                  set tn_cur [lindex $cur_line end]
                      if {[expr abs($tn_std - $tn_cur)]>0} {
                    puts $final_rpt_file "****Difference in Density Width:\n Density width for density $name in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Density Width: </B></LI> <BR> Density width for density $name in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             }
        
           } 
     close $std_file
     close $cur_file  
     close $final_rpt_file 
     close $final_rpt_file_html 
     mess "Wrote Final Geometry Report \n"
} 
#
#
proc ic_compare_get_blk_report {cur_blk_rpt std_blk_rpt remote_host {tol 0.5}} {
    #
       global env html_head
  
    set plat_name [lindex [split [lindex [file split $env(ICEM_ACN)] end] "-"] end] 
    set model [file dirname $cur_blk_rpt]
    set rpt_file [file join $model final_report_$remote_host.rpt]
    set rpt_file_html final_report_$remote_host.html
# 
    if [catch {open $rpt_file a+} final_rpt_file] {
        mess "Error: could not open Mesh Report File for writing: " red
        if ![file writable $rpt_file] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file]\n" red
        return
    } 
#
    if [catch {open $rpt_file_html a+} final_rpt_file_html] {
        mess "Error: could not open Mesh Report File for writing: " red
        if ![file writable $rpt_file_html] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file_html]\n" red
        return
    } 
#    set html_head 0
#
         if {(![file exists [file join $model $cur_blk_rpt]]) || ([file size [file join $model $cur_blk_rpt]] == 0)} { 
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 puts $final_rpt_file_html "<LI><B>Test case failed:</B> Blocking file was not created </li>"
                 close $final_rpt_file_html 
                  return 
            } 
#

         if {(![file exists [file join $model $std_blk_rpt]]) || ([file size [file join $model $std_blk_rpt]] == 0)} { 
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 puts $final_rpt_file_html "<LI><B>Test case failed:</B> Setup is wrong. Please make sure that you have the standard blocking file in the testing directory </li>"
                 close $final_rpt_file_html 
                  return 
             } 
#
#    set html_head 0
          
    set std_file [open [file join $model $std_blk_rpt] r]
    set cur_file [open [file join $model $cur_blk_rpt] r] 
    set l1 0
    while {[gets $std_file std_line] >=0} {
   
        if [regexp "List of Dimensions:" $std_line] {
           set list_dims [lrange $std_line 3 end]
        }  
#
        if [regexp "Quality Diagnostics:" $std_line] {
           set list_diags [lrange $std_line 2 end]
        }
#
     }
  seek $std_file 0 start  
  set l2 0

    while {[gets $std_file sd_ln] >=0} {
   
           incr l2
#
             if {[regexp "Blocking dimension:" $sd_ln]} {  
                  set block_dim [lindex $sd_ln end]
                }
             if {[regexp "Index Range:" $sd_ln]} {  
                  set index_range [lrange $sd_ln 2 end]
                }
             if {[regexp "Number of dimensions:" $sd_ln]} {  
                  set n_dims [lindex $sd_ln end]
                }
#
             foreach dim $list_dims {
                if {[regexp "Block Information Along: $dim" $sd_ln]} {
                set blk_info($dim) [lrange $sd_ln 4 end]
                } 
             }
#
             if {[regexp "Number of Nodes =" $sd_ln]} {  
                  set n_nodes [lindex $sd_ln end]
                }
#
             if {[regexp "Number of Quads =" $sd_ln]} {  
                  set n_quads [lindex $sd_ln end]
                }
#
             if {[regexp "Number of Hexas =" $sd_ln]} {  
                  set n_hexa [lindex $sd_ln end]
                }
#
           foreach diag $list_diags {
             if {[regexp "Quality - $diag range:" $sd_ln]} {  
             set quality($diag) $diag
             set tline 1
             set low 0
             set stp 0.1
             while {$tline <= 10} {
                set high [expr {$low + $stp}]
                gets $std_file sd_ln 
#
                set n_elem($low-$high-$diag) [lindex $sd_ln 0] 
                    incr tline
                    set low $high 
                }
              }
           }      
    } 
# Reading the current file
#
    set line2 0
         while {[gets $cur_file cur_line] >=0} {
           incr line2
#
             if {[regexp "Blocking dimension:" $cur_line] && [info exists block_dim]} {  
                  set tn_std $block_dim 
                  set tn_cur [lindex $cur_line end]
                      if { $tn_std != $tn_cur } {
                    puts $final_rpt_file "****Difference in Block Dimension:\n The dimension in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Block Dimension: </B></li> <BR> The dimension in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Index Range:" $cur_line] && [info exists index_range]} {  
                  set tn_std $index_range 
                  set tn_cur [lrange $cur_line 2 end]
                      if { $tn_std != $tn_cur } {
                    puts $final_rpt_file "****Difference in Index Range:\n The index range in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Index Range: </B></li> <BR> The index range in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
             if {[regexp "Number of dimensions:" $cur_line] && [info exists n_dims]} {  
                  set tn_std $n_dims
                  set tn_cur [lindex $cur_line end]
                      if { $tn_std != $tn_cur } {
                    puts $final_rpt_file "****Difference in Number of dimensions:\n The number of dimension in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of dimensions: </B></li> <BR> The number of dimension in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
             foreach dim $list_dims {
        
                if {[regexp "Block Information Along: $dim" $cur_line] && [info exists blk_info($dim)]} {

                set tn_std $blk_info($dim)
                set tn_cur [lrange $cur_line 4 end] 
                set n_edges_cur [lindex $cur_line 4]
                set n_nodes_cur [lindex $cur_line end]
                set n_edges_std [lindex $tn_std 4]
                set n_nodes_std [lindex $tn_std end]
 
                   if { [join $tn_std] != [join $tn_cur] } {
                     puts $final_rpt_file "****Difference in blocks along $dim :\n Current Blocking: \n\t Number of Edges along $dim : $n_edges_cur\n\t Node Distribution: $n_nodes_cur\n Standard Blocking: \n\t Number of Edges along $dim : $n_edges_std\n\t Node Distribution: $n_nodes_std\n"  
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                     puts $final_rpt_file_html "<LI><B>Difference in blocks along $dim : </B></li> <BR> <B>Current Blocking: </B> <BR> Number of Edges along $dim : $n_edges_cur <BR> Node Distribution: $n_nodes_cur <BR> Standard Blocking: <BR> Number of Edges along $dim : $n_edges_std <BR> Node Distribution: $n_nodes_std <BR><BR>"  
                   }
                } 
             }
#
             if {[regexp "Number of Nodes =" $cur_line] && [info exists n_nodes]} {  
                  set tn_std $n_nodes
                  set tn_cur [lindex $cur_line end]
                 if {[expr abs($tn_std - $tn_cur)] > [expr pow(10,($tol*log10(1+$tn_std)))]} {
                    puts $final_rpt_file "****Difference in Number of Nodes:\n The number of nodes in the current version is $tn_cur . In the Standard Geometry it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of Nodes: </B></li> <BR> The number of nodes in the current version is $tn_cur <BR> In the Standard Geometry it's $tn_std <BR><BR>"
                     }
                }
#
             if {[regexp "Number of Quads =" $cur_line] && [info exists n_quads]} {  
                  set tn_std $n_quads
                  set tn_cur [lindex $cur_line end]
                 if {[expr abs($tn_std - $tn_cur)] > [expr pow(10,($tol*log10(1+$tn_std)))]} {
                    puts $final_rpt_file "****Difference in Number of Quads:\n The number of Quads in the current version is $tn_cur . In the Standard Blocking it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of Quads: </B></li> The number of Quads in the current version is $tn_cur <BR> In the Standard Blocking it's $tn_std <BR><BR>"
                     }
                }
#
             if {[regexp "Number of Hexas =" $cur_line] && [info exists n_hexa]} {  
                  set tn_std $n_hexa
                  set tn_cur [lindex $cur_line end]
                 if {[expr abs($tn_std - $tn_cur)] > [expr pow(10,($tol*log10(1+$tn_std)))]} {
                    puts $final_rpt_file "****Difference in Number of Volume elements:\n The number of hexas in the current version is $tn_cur . In the Standard Blocking it's $tn_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Number of Volume elements: </B></li> <BR> The number of hexas in the current version is $tn_cur <BR> In the Standard Blocking it's $tn_std <BR><BR>"
                     }
                }
#
           foreach diag $list_diags {
             if {[regexp "Quality - $diag range:" $cur_line] && [info exists quality($diag)]} {  
             set tline 1
             set low 0
             set stp 0.1
             while {$tline <= 10} {
                set high [expr {$low + $stp}]
                gets $cur_file cur_line
#
                set n_elems_cur [lindex $cur_line 0]
                set n_elems_std $n_elem($low-$high-$diag) 
                 if {[expr abs($n_elems_std - $n_elems_cur)] > [expr pow(10,($tol*log10(1+$n_elems_std)))]} {
                    puts $final_rpt_file "****Difference in Quality - $diag:\n The number of elements between Quality $low and $high is $n_elems_cur . In the Standard Geometry it's $n_elems_std\n"
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                    puts $final_rpt_file_html "<LI><B>Difference in Quality - $diag: </B></li> <BR>The number of elements between Quality $low and $high is $n_elems_cur <BR> In the Standard Geometry it's $n_elems_std <BR><BR>"
                      }
                    incr tline
                    set low $high 
                }
              }
           } 
       }              
     close $std_file
     close $cur_file  
     close $final_rpt_file 
     close $final_rpt_file_html 
     mess "Wrote Final Blocking Report \n"
}
#
proc ic_compare_get_solver_report {solver_input_file std_solver_input_file remote_host} {
    #
    global env html_head
    # --> Parse up given args to see what to write, e.g.: -${param} $paramVal
    set model [file dirname $solver_input_file]
    set model_dir [lindex [file split $model] end]
    set module_dir [lindex [file split $model] end-1]

    set rpt_file [file join $model final_report_$remote_host.rpt]
#   set rpt_file_html [file join $model final_report_$remote_host.html]
    set rpt_file_html final_report_$remote_host.html
#
    if [catch {open $rpt_file a+} final_rpt_file] {
        mess "Error: could not open Solver Report File for writing: " red
        if ![file writable $rpt_file] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file]\n" red
        return
    }
#
    if [catch {open $rpt_file_html a+} final_rpt_file_html] {
        mess "Error: could not open Solver Report File for writing: " red
        if ![file writable $rpt_file_html] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file_html]\n" red
        return
    }
    if {(![file exists $solver_input_file]) || ([file size $solver_input_file]  == 0)} {
        set plat_name [lindex [split [lindex [file split $env(ICEM_ACN)] end] "-"] end]
        if {![info exists html_head] || ($html_head == 0)} {
                puts $final_rpt_file_html "<h2>Testcase: $module_dir:$model_dir  </h2>\n"
                puts $final_rpt_file_html "<h2>Platform:$plat_name  </h2>\n"
                puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>\n"
              set html_head 1
           }
        puts $final_rpt_file_html "<B>Solver interface:</B> Can\'t find \"$solver_input_file\".<BR><BR>"
        close $final_rpt_file_html
        return ""
    }
#
    if {(![file exists $std_solver_input_file]) || ([file size $std_solver_input_file]  == 0)} {
        set plat_name [lindex [split [lindex [file split $env(ICEM_ACN)] end] "-"] end]
        if {![info exists html_head] || ($html_head == 0)} {
                puts $final_rpt_file_html "<h2>Testcase: $module_dir:$model_dir  </h2>\n"
                puts $final_rpt_file_html "<h2>Platform:$plat_name  </h2>\n"
                puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>\n"
                set html_head 1
        }
        puts $final_rpt_file_html "<B>Solver interface:</B> Standard solver input file is missing from the testing directory<BR><BR>"
        close $final_rpt_file_html
        return ""
    }
#
#     if {[file exists $solver_input_file] && [file exists $std_solver_input_file]} {
#     set f1 [file size $solver_input_file]
#     set f2 [file size $std_solver_input_file]
#      if {[expr abs($f1-$f2)]>0} {
#      set plat_name [lindex [split [lindex [file split $env(ICEM_ACN)] end] "-"] end]
#      puts $final_rpt_file_html "<h2>Testcase: $module_dir:$model_dir  </h2>\n"
#      puts $final_rpt_file_html "<h2>Platform:$plat_name  </h2>\n"
#      puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>\n"
#       puts $final_rpt_file "Some difference found in the current version. Please check\n"
#       puts $final_rpt_file_html "<LI>Some difference found in the current version. Please check</li>\n"
#
#     }
#     }
    close $final_rpt_file
    close $final_rpt_file_html
     mess "Wrote Final Solver Report \n"
}
#
proc ic_compare_get_fea_solver_report {solver_input_file std_solver_input_file remote_host os} {
    #
    global env html_head
    # --> Parse up given args to see what to write, e.g.: -${param} $paramVal
    set model [file dirname $solver_input_file]
    set model_dir [lindex [file split $model] end]
    set module_dir [lindex [file split $model] end-1]

     set rpt_file [file join $model final_report_$remote_host.rpt]
#    set rpt_file_html [file join $model final_report_$remote_host.html]
     set rpt_file_html final_report_$remote_host.html
#
    if [catch {open $rpt_file a+} final_rpt_file] {
        mess "Error: could not open Solver Report File for writing: " red
        if ![file writable $rpt_file] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file]\n" red
        return
    }
#
    if [catch {open $rpt_file_html a+} final_rpt_file_html] {
        mess "Error: could not open Solver Report File for writing: " red
        if ![file writable $rpt_file_html] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file_html]\n" red
        return
    }

    if {(![file exists $solver_input_file]) || ([file size $solver_input_file]==0)} {
      set plat_name [lindex [split [lindex [file split $env(ICEM_ACN)] end] -] end]
        if {![info exists html_head] || ($html_head == 0)} {
                puts $final_rpt_file_html "<h2>Testcase: $module_dir:$model_dir  </h2>\n"
                puts $final_rpt_file_html "<h2>Platform:$plat_name  </h2>\n"
                puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>\n"
                set html_head 1
           }
      puts $final_rpt_file_html "<B>Test case failed:</B> Solver input file was not created<BR><BR>"
    close $final_rpt_file_html
     return ""
    }
#
    if {(![file exists $std_solver_input_file]) || ([file size $std_solver_input_file]  == 0)} {
      set plat_name [lindex [split [lindex [file split $env(ICEM_ACN)] end] "-"] end]
        if {![info exists html_head] || ($html_head == 0)} {
                puts $final_rpt_file_html "<h2>Testcase: $module_dir:$model_dir  </h2>\n"
                puts $final_rpt_file_html "<h2>Platform:$plat_name  </h2>\n"
                puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>\n"
                set html_head 1
          }
      puts $final_rpt_file_html "<B>Wrong testcase setup:</B> Standard solver input file is missing from the testing directory<BR><BR>"
    close $final_rpt_file_html
     return ""
    }
#
    if {[file exists $solver_input_file] && [file exists $std_solver_input_file]} { 
     set operating_system [lindex [split $std_solver_input_file .] end-1] 
       if {($operating_system == $os)} {
                 catch {exec diff $std_solver_input_file $solver_input_file >diff_file}
        if {[file size $model/diff_file] > 0} {
                set df_file [open $model/diff_file r]
                set plat_name [lindex [split [lindex [file split $env(ICEM_ACN)] end] "-"] end]
           if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Testcase: $module_dir:$model_dir  </h2>\n"
                puts $final_rpt_file_html "<h2>Platform:$plat_name  </h2>\n"
                puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>\n"
                set html_head 1
           }
        set l1 0
       while {[gets $df_file line] >=0} {
         incr l1
         puts $final_rpt_file $line
         puts $final_rpt_file_html "<BR> $line <BR>"
        }
        close $df_file
      }
     }
    }
    close $final_rpt_file
    close $final_rpt_file_html
    mess "Wrote Final Solver Report \n"
}
#
 proc ic_get_c3d_report {model c3d_pref_file plat_name remote_host} {
      global html_head
      set replay_file [open $model//med.replay r]
      set l1 0
       while {[gets $replay_file line] >=0} {
         incr l1
        if (![regexp "ic_mesh_cart3d_auto_inputs" $line]) {
         if [regexp "ic_run_df2cart3d" $line] {
            set run_df2cart3d 1
         } 
         if [regexp "ic_mesh_cart3d" $line] {
            set n [lsearch $line run_intersect]
            if [lindex $line [incr n]] {
               set mesh_with_intersect 1
            }
         } 
         if [regexp "ic_mesh_cart3d" $line] {
            set n [lsearch $line run_cubes]
            if [lindex $line [incr n]] {
               set mesh_with_cubes 1
            }
         } 
         if [regexp "ic_run_flowCart" $line] {
            set run_flowCart 1
         } 
         if [regexp "ic_run_clic" $line] {
            set run_clic 1
         }
         if [regexp "ic_run_sixdof" $line] {
            set run_sixdof 1
            set n1 [lsearch $line time_start]
            set start_time [lindex $line [incr n1]]
            set n2 [lsearch $line time_step]
            set step [lindex $line [incr n2]]
            set n3 [lsearch $line time_end]
            set end_time [lindex $line [incr n3]]
            set time [format "%g" $start_time]
            set n 0
            set sixdof_dirs ""   
              while {$time <= $end_time} {
                 set sixdof_dir [file join $model sixDOF time_$time]
                 lappend sixdof_dirs $sixdof_dir
              } 
          }           
         }           
       }
         close $replay_file
#
     set rpt_file [file join $model final_report_$remote_host.rpt]
#    set rpt_file_html [file join $model final_report_$remote_host.html]
     set rpt_file_html final_report_$remote_host.html
#
    if [catch {open $rpt_file a+} final_rpt_file] {
        mess "Error: could not open Solver Report File for writing: " red
        if ![file writable $rpt_file] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file]\n" red
       return
    }
#
    if [catch {open $rpt_file_html a+} final_rpt_file_html] {
        mess "Error: could not open Solver Report File for writing: " red
        if ![file writable $rpt_file_html] {
            mess " check permissions on directory\n" red
        }
        mess " [file dirname $rpt_file_html]\n" red
        return
    }
#
#       set html_head 0
#
         if [info exists run_df2cart3d] {
                set atri_file [file join $model $c3d_pref_file.a.tri]
            
            if {(![file exists $atri_file]) || ([file size $atri_file]  == 0)} {
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                puts $final_rpt_file_html "<LI> <B>df2cart3d</B> failed: </li> <BR> $atri_file was not created"
                puts $final_rpt_file "Df2cart3d failed: $atri_file was not created"
            }

         }

         if [info exists mesh_with_intersect] {
                set itri_file [file join $model $c3d_pref_file.i.tri]
            
            if {(![file exists $itri_file]) || ([file size $itri_file]  == 0)} {
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                puts $final_rpt_file_html "<LI> <B>Intersect</B> failed: </li> <BR> $itri_file was not created"
                puts $final_rpt_file "Intersect failed: $itri_file was not created"
            }
         }
         if [info exists mesh_with_cubes] {
                set mg_file [file join $model $c3d_pref_file.mesh.mg]
            
            if {(![file exists $mg_file]) || ([file size $mg_file]  == 0)} {
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                puts $final_rpt_file_html "<LI> <B>Cubes</B> failed: </li> <BR> $mg_file was not created"
                puts $final_rpt_file "Cubes failed: $mg_file was not created"
            }

         }
         if [info exists run_flowCart] {
                set triq_file [file join $model $c3d_pref_file.i.triq]
            
            if {(![file exists $triq_file]) || ([file size $triq_file]  == 0)} {
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                puts $final_rpt_file_html "<LI> <B>Flowcart</B> failed: </li> <BR> $triq_file was not created"
                puts $final_rpt_file "Flowcart failed: $triq_file was not created"
            }

         }
         if [info exists run_clic] {
                set clic_file [file join $model $c3d_pref_file.clic.out]
            
            if {(![file exists $clic_file]) || ([file size $clic_file]  == 0)} {
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                puts $final_rpt_file_html "<LI> <B>Clic</B> failed: </li> <BR> $clic_file was not created"
                puts $final_rpt_file "Clic failed: $clic_file was not created"
            }

         }
         if [info exists run_sixdof] {
                
            foreach sixdof_dir $sixdof_dirs {
             set sixdof_file [$sixdof_dir $c3d_pref_file.i.triq]
             if {(![file exists $sixdof_file]) || ([file size $sixdof_file]  == 0)} {
               if {![info exists html_head] || ($html_head == 0)} {
                 puts $final_rpt_file_html "<h2>Platform: $plat_name </h2>"
                 puts $final_rpt_file_html "<h2>Host:$remote_host  </h2>"
                 set html_head 1 
               }
                  puts $final_rpt_file_html "<LI> <B>SIXDOF</B> failed: </li> <BR> $sixdof_file was not created"
                  puts $final_rpt_file "SIXDOF failed: $sixdof_file was not created"
             }
            }
         }

          close $final_rpt_file
          close $final_rpt_file_html
          mess "Wrote Final Cart3D Report \n"
}
