$Application ExitOnReturnOn

set kw(vtkTemp1) [$Application GetMainWindow]
set kw(vtkTemp22) [$kw(vtkTemp1) GetMainView]

if {[info exists argc]} { 
    set argcm1 [expr $argc - 1]
    for {set i 0} {$i < $argcm1} {incr i} {
        if {[lindex $argv $i] == "-D" && $i < $argcm1} {
		set DataDir [lindex $argv [expr $i + 1]]
        }
        if {[lindex $argv $i] == "-UC" && $i < $argcm1} {
            set rmui [$kw(vtkTemp22) GetRenderModuleUI]
            catch {$rmui SetCompositeThreshold 0}
        }
    }
} 

# Disable popup message dialogs.
$kw(vtkTemp1) SetUseMessageDialog 0

set pvWindow $kw(vtkTemp1)

# Choose the file name/type based on whether we are in parallel mode.
set kw(vtkTemp1000) [$Application GetController]
set nprocs [$kw(vtkTemp1000) GetNumberOfProcesses]

set ext "vtk"
if {$nprocs > 1} { set ext "pvtp" }

$pvWindow Open "$DataDir/Data/blow data.vtk"
if { [catch {
  $pvWindow DisableMenus
  $pvWindow ShowAnimationProperties
  $pvWindow ShowCurrentSourceProperties
  $pvWindow EnableMenus
  $pvWindow WriteVTKFile vtkParaViewWriteTest.$ext
  $pvWindow WriteVTKFile vtkParaViewWriteTestGhost.$ext 3
  
  # Barrier after write.  We don't want to delete files before they
  # are written.
  [$Application GetProcessModule] SendStringToClientAndServer {
    Invoke id(1) GetController
    Invoke result() Barrier
  }

  file delete -force vtkParaViewWriteTest.$ext
  file delete -force vtkParaViewWriteTestGhost.$ext

  
  if {$nprocs > 1} {
    # Delete the temporary file's pieces.
    for {set i 0} { $i < $nprocs } { incr i } {
      catch { file delete -force "vtkParaViewWriteTest.$i.vtp" }
      catch { file delete -force "vtkParaViewWriteTestGhost.$i.vtp" }
    }
  }

  file delete -force vtkParaViewWriteTest.tcl
} res ] != 0 } {
	puts "Error: $res"
	$Application SetExitStatus 1
}

$Application Exit
