Debian Codegraph @

debian/rust-vendor/statrs/tests/gather_nist_data.sh

raw
1 #! /bin/bash
2 # this script is to download and preprocess datafiles for the nist_tests.rs
3 # integration test for statrs downloads data to directory specified by env
4 # var STATRS_NIST_DATA_DIR
5
6 process_file() {
7 # Define input and output file names
8 SOURCE=$1
9 FILENAME=$2
10 TARGET=${STATRS_NIST_DATA_DIR-tests}/${FILENAME}
11 echo -e ${FILENAME} '\n\tDownloading...'
12 curl -fsSL ${SOURCE}/$FILENAME > ${TARGET}
13
14 # Extract line numbers for Certified Values and Data from the header
15 INFO=$(grep "Certified Values:" $TARGET)
16 CERTIFIED_VALUES_START=$(echo $INFO | awk '{print $4}')
17 CERTIFIED_VALUES_END=$(echo $INFO | awk '{print $6}')
18
19 INFO=$(grep "Data :" $TARGET)
20 DATA_START=$(echo $INFO | awk '{print $4}')
21 DATA_END=$(echo $INFO | awk '{print $6}')
22
23 echo -e '\tFormatting...'
24 # Extract and reformat sections
25 sed -n -i \
26 -e "${CERTIFIED_VALUES_START},${CERTIFIED_VALUES_END}p" \
27 -e "${DATA_START},${DATA_END}p" \
28 $TARGET
29 }
30
31 URL='https://www.itl.nist.gov/div898/strd/univ/data'
32 for file in Lottery.dat Lew.dat Mavro.dat Michelso.dat NumAcc1.dat NumAcc2.dat NumAcc3.dat
33 do
34 process_file $URL $file
35 done
36