#!/bin/bash
cd "${0%/*}" || exit 1    # Run from this directory

# Source case functions
. "$WM_PROJECT_SITE/$WM_PROJECT_VERSION/bin/tools/casesFunctions.sh"

targetDirectory="validation/reference"
rm -rf "$targetDirectory"
mkdir -p "$targetDirectory/holdupGasD/0" \
         "$targetDirectory/holdupLiquidC/0" \
         "$targetDirectory/holdupLiquidD/0" \
         "$targetDirectory/surfaceGasC/10" \
         "$targetDirectory/surfaceLiquidC/10" \
         "$targetDirectory/layerAverage/10"

# Zip reference data
gzip -krf postProcessing/surface*/10

# Temporal averaging
mpypost avg --starttime 5 postProcessing/holdupGasD/0/volFieldValue.dat
mpypost avg --starttime 5 postProcessing/holdupLiquidC/0/volFieldValue.dat
mpypost avg --starttime 5 postProcessing/holdupLiquidD/0/volFieldValue.dat

# Copy results from latest run into reference directory
cp -f "postProcessing/holdupGasD/0/volFieldValue_avg.csv" \
    "$targetDirectory/holdupGasD/0"
cp -f "postProcessing/holdupLiquidC/0/volFieldValue_avg.csv" \
    "$targetDirectory/holdupLiquidC/0"
cp -f "postProcessing/holdupLiquidD/0/volFieldValue_avg.csv" \
    "$targetDirectory/holdupLiquidD/0"

cp -f "postProcessing/surfaceGasC/10/isoSurface.xy.gz" \
    "$targetDirectory/surfaceGasC/10"
cp -f "postProcessing/surfaceLiquidC/10/isoSurface.xy.gz" \
    "$targetDirectory/surfaceLiquidC/10"

cp -f "postProcessing/layerAverage/10/layerAverage.csv" \
    "$targetDirectory/layerAverage/10"

#------------------------------------------------------------------------------
