|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +convert_ssmc() { |
| 5 | + echo "unpacking $1" |
| 6 | + fpath=$1 |
| 7 | + |
| 8 | + format=$2 |
| 9 | + |
| 10 | + if [ -z "$format" ] |
| 11 | + then |
| 12 | + format=COO |
| 13 | + else |
| 14 | + format=$2 |
| 15 | + fi |
| 16 | + |
| 17 | + format_string=`echo ${format} | tr '[:upper:]' '[:lower:]'` |
| 18 | + |
| 19 | + echo "Writing in format ${format}." |
| 20 | + |
| 21 | + fname=`basename ${fpath}` |
| 22 | + directory=`dirname ${fpath}` |
| 23 | + tar -xf $fpath -C $directory |
| 24 | + |
| 25 | + matrix_name=${fname/.tar.gz/} |
| 26 | + |
| 27 | + main_matrix=$directory/$matrix_name/$matrix_name.mtx |
| 28 | + |
| 29 | + dest_file=$directory/$matrix_name.${format_string}.bsp.h5 |
| 30 | + |
| 31 | + # echo "dest file ${dest_file}" |
| 32 | + |
| 33 | + # echo "Primary matrix is \"${main_matrix}\" -> ${dest_file}/root" |
| 34 | + echo "mtx2bsp ${main_matrix} ${dest_file} ${format}" |
| 35 | + mtx2bsp ${main_matrix} ${dest_file} ${format} |
| 36 | + |
| 37 | + # Set "null option" to return an empty list if no files match glob. |
| 38 | + shopt -s nullglob |
| 39 | + |
| 40 | + for secondary_matrix in ${directory}/${matrix_name}/${matrix_name}_*.mtx |
| 41 | + do |
| 42 | + # echo "Secondary matrix \"${secondary_matrix}\"" |
| 43 | + secondary_name=`basename ${secondary_matrix}` |
| 44 | + secondary_name=${secondary_name/.mtx/} |
| 45 | + secondary_name=${secondary_name/${matrix_name}_/} |
| 46 | + echo "mtx2bsp ${secondary_matrix} ${dest_file}:${secondary_name}" |
| 47 | + mtx2bsp ${secondary_matrix} ${dest_file}:${secondary_name} |
| 48 | + done |
| 49 | + |
| 50 | + rm -r ${directory}/${matrix_name} |
| 51 | +} |
| 52 | + |
| 53 | +check_ssmc() { |
| 54 | + echo "unpacking $1" |
| 55 | + fpath=$1 |
| 56 | + |
| 57 | + format=$2 |
| 58 | + |
| 59 | + if [ -z "$format" ] |
| 60 | + then |
| 61 | + format=COO |
| 62 | + else |
| 63 | + format=$2 |
| 64 | + fi |
| 65 | + |
| 66 | + format_string=`echo ${format} | tr '[:upper:]' '[:lower:]'` |
| 67 | + |
| 68 | + fname=`basename ${fpath}` |
| 69 | + directory=`dirname ${fpath}` |
| 70 | + tar -xf $fpath -C $directory |
| 71 | + |
| 72 | + matrix_name=${fname/.tar.gz/} |
| 73 | + |
| 74 | + main_matrix=$directory/$matrix_name/$matrix_name.mtx |
| 75 | + |
| 76 | + dest_file=$directory/$matrix_name.${format_string}.bsp.h5 |
| 77 | + |
| 78 | + # echo "dest file ${dest_file}" |
| 79 | + |
| 80 | + # echo "Primary matrix is \"${main_matrix}\" -> ${dest_file}/root" |
| 81 | + echo "check_equivalence ${main_matrix} ${dest_file}" |
| 82 | + check_equivalence ${main_matrix} ${dest_file} |
| 83 | + |
| 84 | + # Set "null option" to return an empty list if no files match glob. |
| 85 | + shopt -s nullglob |
| 86 | + |
| 87 | + for secondary_matrix in ${directory}/${matrix_name}/${matrix_name}_*.mtx |
| 88 | + do |
| 89 | + # echo "Secondary matrix \"${secondary_matrix}\"" |
| 90 | + secondary_name=`basename ${secondary_matrix}` |
| 91 | + secondary_name=${secondary_name/.mtx/} |
| 92 | + secondary_name=${secondary_name/${matrix_name}_/} |
| 93 | + echo "check_equivalence ${secondary_matrix} ${dest_file}:${secondary_name}" |
| 94 | + check_equivalence ${secondary_matrix} ${dest_file}:${secondary_name} |
| 95 | + done |
| 96 | + |
| 97 | + rm -r ${directory}/${matrix_name} |
| 98 | +} |
| 99 | + |
| 100 | +export PATH=$PATH:$PWD/../../examples |
| 101 | + |
| 102 | +convert_ssmc $1 COO |
| 103 | +check_ssmc $1 COO |
0 commit comments