#!/bin/csh
#
# This script sorts each resolution and converts each resolution from ASCII
# to binary format.
#
# Robert S Laramee
# 20 Feb '01
# FromASCIItoBinarySortCubeScript
#
set BASE = "../data"
#
# Remove output from previous run of this script.
#
echo 'removing previous binary files...'
@ level = 6
@ resolution = 2
while ($resolution <= 64)

    rm -fv $BASE/level${level}/headRes${resolution}cube.bin

    @ level = $level - 1
    @ resolution = $resolution * 2
end
#
# make a small exception to resolution 128^3
#
echo removing file: $BASE/level${level}/headRes${resolution}cube.bin
echo 'This file takes 4 hours to generate.'
echo 'Continue with remove?'
rm $BASE/level${level}/headRes${resolution}cube.bin
#
# sample file: /export/home/sdb/data/level3/headRes16ErrCube.ascii 
#
echo 'uncompressing input files (if they are there)...'
@ level = 6
@ resolution = 2
while ($resolution <= 128)

    gunzip -v $BASE/level${level}/headRes${resolution}ErrCube.ascii.gz

    @ level = $level - 1
    @ resolution = $resolution * 2

end
echo 'compiling rlaramee/FromASCIItoBinarySortCube.java...'
javac -deprecation rlaramee/FromASCIItoBinarySortCube.java
#
echo 'converting files...'
@ level = 6
@ resolution = 2
while ($resolution <= 128)

    java -Xmx1024m rlaramee/FromASCIItoBinarySortCube \
    $BASE/level${level}/headRes${resolution}ErrCube.ascii \
    $BASE/level${level}/headRes${resolution}cube.bin $level

    @ level = $level - 1
    @ resolution = $resolution * 2

end
#
chmod ugo=r $BASE/level0/headRes128cube.bin
echo 'done sorting resolutions 2^3 - 128^3 cubes (from ASCII to binary)'
#
# disk space is really tough to get here in the CS department!
#
echo 'compressing ASCII, input files..'
# -f -force overwrite, -v verbose
@ level = 6
@ resolution = 2
while ($resolution <= 128)

    gzip -v $BASE/level${level}/headRes${resolution}ErrCube.ascii

    @ level = $level - 1
    @ resolution = $resolution * 2

end
chmod ugo=r $BASE/level0/headRes128ErrCube.ascii.gz
echo 'finished compressing ASCII, input files'
echo 'FromASCIItoBinarySortCubeScript finished'
