1#!/bin/bash 2 3nargs=3 # Arguments of the script: 4 # time step 5 # number parts 6 # number of syncio files wanted 7 8### Function die called when there is a problem 9function die() { 10 echo -e "${1}" 11 exit 1 12} 13 14 15##################################################################### 16### End of functions - Beginning of the script 17##################################################################### 18 19 20### Check that user entered proper number of args 21if [ "${#}" -lt "$nargs" ] || [ "$1" == "-h" ]; then 22 die "\n Check usage: \n $0\n\n \$1: <time step>\n \$2: <number of parts>\n \$3: <number of SyncIO files>\n\n" 23fi 24 25 26### Read arguments of the script 27N_steps=$1 28N_parts=$2 29N_files=$3 30 31echo "Time step: $N_steps" 32echo "Number of parts: $N_parts" 33echo "Number of SyncIO files: $N_files" 34echo "" 35 36dir=$N_parts-procs_case 37 38 39### Do a couple of sanity check on the input parameters of the script 40if [ ! -d $dir ]; then 41 die "$N_parts-procs_case does not exist\n Aborting" 42fi 43 44if [ ! -e $dir/restart-dat.$N_steps.1 ]; then 45 die "Time step $N_steps does not exist in $N_parts-procs_case\n Aborting" 46fi 47 48nsynciofiles=`ls $dir/restart-dat.$N_steps.* | wc -l` 49if [ "$nsynciofiles" -ne "$N_files" ]; then 50 die "The number of SyncIO files requested does not match with what is found in the procs_case directory: $nsynciofiles - $N_files" 51fi 52 53resmodulo=$(($N_parts % $N_files)) 54if [ "$resmodulo" -ne "0" ]; then 55 die "The number of SyncIO files requested $N_files is not a multiple of the number of parts $N_parts\n Aborting" 56fi 57 58 59### First, count the number of fields (blocks) in the restart files and list them 60list_restart_fields=list_restart_fields.dat 61grep -a ' : < ' $dir/restart-dat.$N_steps.1 | grep -v '< 0 >' | awk -F @ '{print $1}' | uniq -c > $list_restart_fields 62restart_fields=`cat $list_restart_fields | wc -l` 63echo "There are $restart_fields different block fields in the restart files:" 64cat $list_restart_fields 65echo "" 66 67### Start to write now IO.N2O.input 68file=IO.N2O.input 69if [ -e $file ]; then 70 rm $file 71fi 72 73# By default, the geombc files already exist under the posix format so no need to deconvert them. 74# Focuss only on the restart files, which should by default only contain double blocks. 75# In what follows, any single header with no block (characterized by '< 0 >') are also ignored. 76N_geombc_fields_double=0 77N_geombc_fields_integer=0 78N_restart_fields_double=$restart_fields 79N_restart_fields_integer=0 80 81echo "N-geombc-fields-double: $N_geombc_fields_double;" >> $file 82echo "N-geombc-fields-integer: $N_geombc_fields_integer;" >> $file 83echo "N-restart-fields-double: $N_restart_fields_double;" >> $file 84echo "N-restart-fields-integer: $N_restart_fields_integer;" >> $file 85echo "N-steps: $N_steps;" >> $file 86echo "N-parts: $N_parts;" >> $file 87echo "N-files: $N_files;" >> $file 88 89# Now add all the fields found in the restart files. 90# Asumption always verified so far: all the fields in the restart files are double and their header includes 3 integer. 91# If this is not the case any more, then more complex verifications should be added like in the other script. 92 93echo "By default, they will all be specified in $file in order to be deconverted but this can be manually modified" 94echo "This script also assumes that all blocks listed are double" 95while read line 96do 97 field=`echo $line | awk '{$1="";print $0}' | sed -e 's/ */ /g' | sed -e 's/^[ \t]*//g' | sed -e 's/[ \t]*$//g'` 98 echo "restart, $field, double, block, 3;" >> $file 99done < $list_restart_fields 100 101### Some cleaning 102rm $list_restart_fields 103 104echo "$file generated for the converter" 105 106