# SYNTAX :
#
#    <script> SCAL_REF_DATASET SCAL_INDEX SCAL_DATASET
#
# Creates the Scalability <SCAL_INDEX> N-Triples file from the zipped Scalability Reference Dataset
# and directs it to the standard output for redirection or pipe operations
#

SCRIPT_NAME=`basename "$0"`
SYNTAX="
SYNTAX: $SCRIPT_NAME <zipped scalability_ref_dataset> <scalability_index>
\t<zipped scalability_ref_dataset>\t:\tScalability Reference dataset,
\t<scalability_index>\t:\t{10K | 100K | 1M | 10M | 100M | 500M} triples"

# there should be 2 arguments
if [ "$#" -ne 2 ]; then
    echo -e "Illegal number of parameters ${SYNTAX}"
    exit 1
fi

# assign arguments to variables
SCAL_REF_DATASET=${1}
SCAL_INDEX=${2^^} # convert to capital

# echo -e "${SCRIPT_NAME} ${SCAL_REF_DATASET} ${SCAL_INDEX} ${SCAL_DATASET}"

# test valid range of SCAL_INDEX
VALID_SCAL_INDEX="10K|100K|1M|10M|100M|500M";
case ${SCAL_INDEX} in
        10K|100K|1M|10M|100M|500M) ;;
        *) echo -e "Valid range for scalability_index:  ${VALID_SCAL_INDEX}"
           echo -e "${SYNTAX}"
           exit 2 ;;
esac

# convert SCAL_INDEX to number of lines
case ${SCAL_INDEX} in
        10K)  LINES=10000 ;;
        100K) LINES=100000 ;;
        1M)   LINES=1000000 ;;
        10M)  LINES=10000000 ;;
        100M) LINES=100000000 ;;
        *)    LINES=500000000
              SCAL_INDEX=500M ;;
esac

gunzip -c ${SCAL_REF_DATASET} | head -n ${LINES}
