#!/bin/bash function usage() { cat <.file_0.h5; i.e. be the output from the first process. EOF } set -e from_it=0 to_it=1000000 every_it=1 rl=0 out_dir="" ascii_arg="" while getopts "hf:t:e:r:o:am:" flag do case $flag in "h") usage exit 0 ;; "f") from_it=$OPTARG ;; "t") to_it=$OPTARG ;; "e") every_it=$OPTARG ;; "r") rl=$OPTARG ;; "m") map=$OPTARG ;; "a") ascii_arg="-a" ;; "o") out_dir=$OPTARG ;; esac done shift $(expr $OPTIND - 1) if [ $# = 0 ]; then usage>&2 exit 1 fi while [ $# -gt 0 ]; do infile=$1 infile_prefix="${infile%.file_0.h5}" if [ "${infile_prefix}" = "${infile}" ]; then echo "Input file ${infile} does not have a name ending with .file_0.h5">&2 exit 1 fi infile_prefix2="${infile%/*}" echo $infile_prefix2 if [ -z "$out_dir" ]; then out_dir=${infile_prefix2%.file_0.h5*} fi if [ ! -d "$out_dir" ]; then mkdir $out_dir fi line=$(h5ls "${infile}"|head -2|tail -n +2) fullvar=$(expr match "${line}" '\(.*\)\\ it=') var=${fullvar#*::} comps=$(ls -1 ${infile_prefix}.file_*.h5|wc -l) tl=0 seq $from_it $every_it $to_it | while read it; do echo -n "rl${rl} it${it}: " # Remove any existing component files rm -f ${out_dir}/$var.rl${rl}.c*.it${it}.vtk.tmp outfile=${out_dir}/$var.rl${rl}.it${it}.vtk if [ ! -z "$map" ]; then map_str="m=$map " fi # Only output if the output file does not already exist if [ ! -r $outfile ]; then dataset0_name="$fullvar it=$it tl=$tl ${map_str}rl=$rl c=0" infile0=${infile} if ! ( h5ls "${infile0}/${dataset0_name}" | grep "NOT FOUND" ) >/dev/null; then seq 0 $(expr $comps - 1 ) | ( while read c; do # echo -n "${c} " dataset_name="$fullvar it=$it tl=$tl ${map_str}rl=$rl c=$c" infile=${infile_prefix}.file_${c}.h5 # echo "infile = $infile" # echo "dataset_name = $dataset_name" outfile=$out_dir/$var.rl${rl}.c${c}.it${it}.vtk.tmp # echo "Extracting components from $dataset_name" h5tovtk $ascii_arg -d "$dataset_name" -o $outfile $infile & done; echo -n "..."; wait; echo -n "Extracted..." ) if [ $(ls -1 $out_dir/$var.rl${rl}.c*.it${it}.vtk.tmp|wc -l) != $comps ]; then echo "BROKEN (or fewer components than files)" fi if [ $(ls -1 $out_dir/$var.rl${rl}.c*.it${it}.vtk.tmp|wc -l) != 0 ]; then temp_outfile=${outfile}.tmp2 vtkmerge $temp_outfile $out_dir/$var.rl${rl}.c*.it${it}.vtk.tmp mv $temp_outfile $outfile echo "Merged" # sed 's/nan/100/g' $outfile > $temp_outfile # mv $temp_outfile $outfile # sed 's/inf/200/g' $outfile > $temp_outfile # mv $temp_outfile $outfile fi rm -f $out_dir/$var.rl${rl}.c*.it${it}.vtk.tmp # echo else echo "Not found" fi else echo "Already exists" fi done shift done