
try: paraview.simple
except: from paraview.simple import *

import glob
import os

from subprocess import *

in_filename = "./16500"
print ("in_filename: ", in_filename)

########################################

def get_trajectory_data(filename):
  try:
    ifile = open(filename, 'r')
  except:
    print ("error: unable to open file for reading.",  filename)
    return


#  resonant_out = CSVReader(FileName=filename,
#                          FieldDelimiterCharacters = ' ',
#                          MergeConsecutiveDelimiters = 1,
#                          HaveHeaders = 1)
  trajectory_out = CSVReader(FileName=filename,
                          FieldDelimiterCharacters = ' ',
                          MergeConsecutiveDelimiters = 1,
                          HaveHeaders = 1)
  # this is necessary!  blank objects otherwise...
  trajectory_out.UpdatePipeline()

  return (trajectory_out)


def show_trajectory_locations(trajectory_out):
  TableToPoints1 = TableToPoints(trajectory_out)
  TableToPoints1.XColumn = 'X'
  TableToPoints1.YColumn = 'Y'
  TableToPoints1.ZColumn = 'Z'
  TableToPoints1.UpdatePipeline()

  DataRepresentation2 = Show(TableToPoints1)
  #DataRepresentation2.Visibility = 1
  #DataRepresentation2.FieldAssociation = 6

  Render()


################################################################################

paraview.simple._DisableFirstRenderCameraReset()

filename = in_filename

for s in GetSources().values():  # scan sources for a SLACReader
  if s.GetXMLName() == "SLACReader":
    source = s
    break;

# complain if a SLACReader wasn't found
try:
  mesh = source
except:
  print ("error: can't find a SLACReader in the visualization pipeline!")


if filename == '':
  print ("trajectory plot cancelled.")
else:
  trajectory_out = get_trajectory_data(filename)
  show_trajectory_locations(trajectory_out)

  Render()

