import os
# trace generated using paraview version 5.12.0-RC2
#### import the simple module from the paraview

from paraview.simple import *
#### disable automatic camera reset on 'Show'

# directory
directory = "./"

directory1 = "./"

# Parcours de tous les fichiers plt dans le répertoire
for i in range(0, 10100, 100):
    # Name of file
    filename = f"plt{i:05d}"
    print('filename =', filename)
    
    # Directory of data file
    file_path = os.path.join(directory, filename)
    print('file_path =', file_path)
    
    # Print
    print(f"Lecture de {filename}")
        
    # Data output name
    output_filename = f"Data-{filename}.csv"
        
    # Creation of reading AMReX/BoxLib
    #### disable automatic camera reset on 'Show'
    paraview.simple._DisableFirstRenderCameraReset()
    
    plt_reader = AMReXBoxLibGridReader(FileNames=[file_path])
        
    # Reading configuration
    plt_reader.EnableCaching = 0
    plt_reader.Level = 1
    plt_reader.PointArrayStatus = []
    plt_reader.CellArrayStatus = []
    plt_reader.CellArrayStatus = ['x_velocity', 'y_velocity', 'density', 'rhoh', 'temp', 'RhoRT', 'divu', 'gradpx', 'gradpy', 'HeatRelease', 'mag_vort', 'mag_vel', 'Y(H)', 'Y(H2)', 'Y(O)', 'Y(O2)', 'Y(OH)', 'Y(H2O)', 'Y(HO2)', 'Y(H2O2)', 'Y(N2)', 'D_H', 'D_H2', 'D_O', 'D_O2', 'D_OH', 'D_H2O', 'D_HO2', 'D_H2O2', 'D_N2']
        
    # Creation of a plot line
    plot_over_line = PlotOverLine(registrationName = 'plot_over_line' , Input=plt_reader)
    plot_over_line.SamplingPattern = 'Sample Uniformly'
    plot_over_line.Resolution = 1280
    plot_over_line.PassPartialArrays = 1
    plot_over_line.PassCellArrays = 0
    plot_over_line.PassPointArrays = 0
    plot_over_line.PassFieldArrays = 1
    plot_over_line.ComputeTolerance = 1
    plot_over_line.Tolerance = 2.220446049250313e-16
    plot_over_line.Point1 = [0.0, 0.006, 0.0]
    plot_over_line.Point2 = [0.12000000000000001, 0.006, 0.0]
    
    print('os.path.join(directory, output_filename) =', os.path.join(directory1, output_filename))
            
    # Saving data
    SaveData(os.path.join(directory1, output_filename), proxy=plot_over_line, WriteTimeSteps=0,
            WriteTimeStepsSeparately=0,
            Filenamesuffix='_%d',
            ChooseArraysToWrite=1,
            PointDataArrays=['x_velocity', 'y_velocity', 'density', 'rhoh', 'temp', 'RhoRT', 'divu', 'gradpx', 'gradpy', 'HeatRelease', 'mag_vort', 'mag_vel', 'Y(H)', 'Y(H2)', 'Y(O)', 'Y(O2)', 'Y(OH)', 'Y(H2O)', 'Y(HO2)', 'Y(H2O2)', 'Y(N2)', 'D_H', 'D_H2', 'D_O', 'D_O2', 'D_OH', 'D_H2O', 'D_HO2', 'D_H2O2', 'D_N2'],
            CellDataArrays=[],
            FieldDataArrays=[],
            VertexDataArrays=[],
            EdgeDataArrays=[],
            RowDataArrays=[],
            Precision=5,
            UseStringDelimiter=1,
            UseScientificNotation=0,
            FieldAssociation='Point Data',
            AddMetaData=1,
            AddTimeStep=0,
            AddTime=0)

