-
-
Notifications
You must be signed in to change notification settings - Fork 211
convbin.sh refactoring for triple band and rinex date interval optimization #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
y3nd
wants to merge
2
commits into
Stefal:dev
Choose a base branch
from
y3nd:nrcan-optimization
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+158
−73
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,110 +1,175 @@ | ||
| #!/bin/bash | ||
| #convert zipped raw file to rinex | ||
| #./convbin.sh ubx.zip directory rinex_type | ||
| # convert zipped raw file to rinex | ||
| # usage: ./convbin.sh <raw_archive_or_rawfile> <data_dir> <rinex_type> | ||
|
|
||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
| source <( grep '=' "${SCRIPT_DIR}"/../settings.conf ) | ||
| RAW_ARCHIVE=$1 | ||
| DATA_DIR=$2 | ||
| MOUNT_NAME=$mnt_name_a | ||
| RAW_TYPE=$receiver_format | ||
| RINEX_TYPE=$3 | ||
| CONVBIN_PATH=$(type -P convbin) | ||
| ANT_POSITION=$(echo "${position}" | cs2cs EPSG:4979 EPSG:4978 -f "%.2f" | sed 's/\s/\//g') | ||
|
|
||
| RAW_ARCHIVE="${1:?Missing raw archive/raw file argument}" | ||
| DATA_DIR="${2:?Missing data dir argument}" | ||
| RINEX_TYPE="${3:?Missing rinex_type argument}" | ||
|
|
||
| MOUNT_NAME="$mnt_name_a" | ||
| RAW_TYPE="$receiver_format" | ||
| CONVBIN_PATH="$(type -P convbin || true)" | ||
|
|
||
| ANT_POSITION=$(echo "${position}" | cs2cs EPSG:4979 EPSG:4978 -f "%.2f" | sed 's/\s/\//g') | ||
| RECEIVER="${receiver}" | ||
| REC_VERSION="${receiver_firmware}" | ||
| REC_OPTION='' | ||
| [[ -n $ntrip_a_receiver_options ]] && REC_OPTION="${ntrip_a_receiver_options}" | ||
| [[ -n "${ntrip_a_receiver_options:-}" ]] && REC_OPTION="${ntrip_a_receiver_options}" | ||
| ANT_TYPE="${antenna_info}" | ||
| RTKBASE_VERSION='RTKBase v'"${version}" | ||
|
|
||
| test -z "${CONVBIN_PATH}" && echo 'Error: convbin not found in PATH' 1>&2 && exit 1 | ||
|
|
||
| extract_raw_file() { | ||
| raw_file=$(unzip -l "${RAW_ARCHIVE}" "*.${RAW_TYPE}" | awk '/-----/ {p = ++p % 2; next} p {print $NF}') | ||
| test $(echo "${raw_file}" | wc -l) -gt 1 && echo 'Error: There is more than 1 file in this archive' 1>&2 && exit 1 | ||
| echo "- Extracting " "${raw_file}" | ||
| test "$(echo "${raw_file}" | wc -l)" -gt 1 && echo 'Error: There is more than 1 file in this archive' 1>&2 && exit 1 | ||
| echo "- Extracting ${raw_file}" | ||
| unzip -o "${RAW_ARCHIVE}" "${raw_file}" | ||
| return $? | ||
| } | ||
|
|
||
| # Determine observation date for convbin -ts/-te (requires YYYY/MM/DD). | ||
| # Primary: RAW_ARCHIVE filename starts with YYYY-MM-DD | ||
| # Fallback: filesystem mtime of RAW_ARCHIVE | ||
| set_obs_date() { | ||
| filedate="${RAW_ARCHIVE:0:10}" # expected: YYYY-MM-DD | ||
| year2="${RAW_ARCHIVE:2:2}" # used for RINEX v2 naming | ||
|
|
||
| if [[ "${filedate}" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then | ||
| OBS_DATE="${filedate//-/\/}" # YYYY/MM/DD | ||
| else | ||
| OBS_DATE="$(date -r "${RAW_ARCHIVE}" +%Y-%m-%d)" # get mtime date (modified date) | ||
| PREV_DATE="$(date -d "${OBS_DATE} -1 day" +%Y-%m-%d)" # previous day of OBS_DATE | ||
| year2="${PREV_DATE:2:2}" | ||
| fi | ||
|
|
||
| export OBS_DATE filedate year2 | ||
| } | ||
|
|
||
| # GPS Time window for the day (convbin default is GPST unless -tu is used) | ||
| TS_HMS="00:00:00" | ||
| TE_HMS="23:59:30" | ||
|
|
||
| # Rinex v2.11 - 30s - GPS | ||
| convert_to_rinex_ign() { | ||
| echo "- CREATING RINEX " "${RINEX_FILE}" | ||
| "${CONVBIN_PATH}" "${raw_file}" -v 2.11 -r "${RAW_TYPE}" \ | ||
| -hc "${RTKBASE_VERSION}" -hm "${MOUNT_NAME}" \ | ||
| -hp "${ANT_POSITION}" -ha 0000/"${ANT_TYPE}" \ | ||
| -hr 0000/"${RECEIVER}"/"${REC_VERSION}" \ | ||
| -f 2 -y R -y E -y J -y S -y C -y I \ | ||
| -od -os -oi -ot -ti 30 -tt 0.005 \ | ||
| echo "- CREATING RINEX ${RINEX_FILE}" | ||
| "${CONVBIN_PATH}" "${raw_file}" -v 2.11 -r "${RAW_TYPE}" \ | ||
| -hc "${RTKBASE_VERSION}" -hm "${MOUNT_NAME}" \ | ||
| -hp "${ANT_POSITION}" -ha 0000/"${ANT_TYPE}" \ | ||
| -hr 0000/"${RECEIVER}"/"${REC_VERSION}" \ | ||
| -f 3 -y R -y E -y J -y S -y C -y I \ | ||
| -od -os -oi -ot \ | ||
| -ti 30 -tt 0.005 \ | ||
| -ts "${OBS_DATE}" "${TS_HMS}" \ | ||
| -te "${OBS_DATE}" "${TE_HMS}" \ | ||
| -ro "${REC_OPTION}" -o "${RINEX_FILE}" | ||
| return $? | ||
| } | ||
|
|
||
| # (kept for reference; fixed to pass args as separate tokens, not one string) | ||
| convert_to_rinex_ign_bis() { | ||
| echo "- CREATING RINEX " "${RINEX_FILE}" | ||
| args="${raw_file}"' -v 2.11 -r '"${RAW_TYPE}"' -hc '"${RTKBASE_VERSION}"' -hm '"${MOUNT_NAME}"' -hp '"${ANT_POSITION}"' -ha 0000/'"${ANT_TYPE}"' -hr 0000/'"${RECEIVER}"'/'"${REC_VERSION}"' -f 2 -y R -y E -y J -y S -y C -y I -od -os -oi -ot -ti 30 -tt 0 -ro '"${REC_OPTION}"' -o '"${RINEX_FILE}" | ||
| "${CONVBIN_PATH}" "${args}" | ||
| return $? | ||
| echo "- CREATING RINEX ${RINEX_FILE}" | ||
| "${CONVBIN_PATH}" "${raw_file}" -v 2.11 -r "${RAW_TYPE}" \ | ||
| -hc "${RTKBASE_VERSION}" -hm "${MOUNT_NAME}" \ | ||
| -hp "${ANT_POSITION}" -ha 0000/"${ANT_TYPE}" \ | ||
| -hr 0000/"${RECEIVER}"/"${REC_VERSION}" \ | ||
| -f 3 -y R -y E -y J -y S -y C -y I \ | ||
| -od -os -oi -ot \ | ||
| -ti 30 -tt 0 \ | ||
| -ts "${OBS_DATE}" "${TS_HMS}" \ | ||
| -te "${OBS_DATE}" "${TE_HMS}" \ | ||
| -ro "${REC_OPTION}" -o "${RINEX_FILE}" | ||
| } | ||
| # Rinex v3.04 - 30s - GPS + GLONASS + GALILEO | ||
|
|
||
| # Rinex v3.04 - 30s - GPS + GLONASS + GALILEO | ||
| convert_to_rinex_nrcan() { | ||
| echo "- CREATING RINEX " "${RINEX_FILE}" | ||
| "${CONVBIN_PATH}" "${raw_file}" -v 3.04 -r "${RAW_TYPE}" \ | ||
| -hc "${RTKBASE_VERSION}" -hm "${MOUNT_NAME}" \ | ||
| -hp "${ANT_POSITION}" -ha 0000/"${ANT_TYPE}" \ | ||
| -hr 0000/"${RECEIVER}"/"${REC_VERSION}" \ | ||
| -f 2 -y J -y S -y C -y I \ | ||
| -od -os -oi -ot -ti 30 -tt 0 \ | ||
| echo "- CREATING RINEX ${RINEX_FILE}" | ||
| "${CONVBIN_PATH}" "${raw_file}" -v 3.04 -r "${RAW_TYPE}" \ | ||
| -hc "${RTKBASE_VERSION}" -hm "${MOUNT_NAME}" \ | ||
| -hp "${ANT_POSITION}" -ha 0000/"${ANT_TYPE}" \ | ||
| -hr 0000/"${RECEIVER}"/"${REC_VERSION}" \ | ||
| -f 3 -y J -y S -y C -y I \ | ||
| -od -os -oi -ot \ | ||
| -ti 30 -tt 0 \ | ||
| -ts "${OBS_DATE}" "${TS_HMS}" \ | ||
| -te "${OBS_DATE}" "${TE_HMS}" \ | ||
| -ro "${REC_OPTION}" -o "${RINEX_FILE}" | ||
| return $? | ||
| } | ||
|
|
||
| # Rinex v3.04 - 30s - GPS + GLONASS + GALILEO + BEIDOU + QZSS + NAVIC + SBAS | ||
| # Rinex v3.04 - 30s - GPS + GLONASS + GALILEO + BEIDOU + QZSS + NAVIC + SBAS | ||
| convert_to_rinex_30s_full() { | ||
| echo "- CREATING RINEX " "${RINEX_FILE}" | ||
| "${CONVBIN_PATH}" "${raw_file}" -v 3.04 -r "${RAW_TYPE}" \ | ||
| -hc "${RTKBASE_VERSION}" -hm "${MOUNT_NAME}" \ | ||
| -hp "${ANT_POSITION}" -ha 0000/"${ANT_TYPE}" \ | ||
| -hr 0000/"${RECEIVER}"/"${REC_VERSION}" \ | ||
| -od -os -oi -ot -ti 30 -tt 0 \ | ||
| echo "- CREATING RINEX ${RINEX_FILE}" | ||
| "${CONVBIN_PATH}" "${raw_file}" -v 3.04 -r "${RAW_TYPE}" \ | ||
| -hc "${RTKBASE_VERSION}" -hm "${MOUNT_NAME}" \ | ||
| -hp "${ANT_POSITION}" -ha 0000/"${ANT_TYPE}" \ | ||
| -hr 0000/"${RECEIVER}"/"${REC_VERSION}" \ | ||
| -od -os -oi -ot \ | ||
| -ti 30 -tt 0 \ | ||
| -ts "${OBS_DATE}" "${TS_HMS}" \ | ||
| -te "${OBS_DATE}" "${TE_HMS}" \ | ||
| -ro "${REC_OPTION}" -o "${RINEX_FILE}" | ||
| return $? | ||
| } | ||
|
|
||
| # Rinex v3.04 - 1s - GPS + GLONASS + GALILEO + BEIDOU + QZSS + NAVIC + SBAS | ||
| # Rinex v3.04 - 1s - GPS + GLONASS + GALILEO + BEIDOU + QZSS + NAVIC + SBAS | ||
| convert_to_rinex_1s_full() { | ||
| echo "- CREATING RINEX " "${RINEX_FILE}" | ||
| "${CONVBIN_PATH}" "${raw_file}" -v 3.04 -r "${RAW_TYPE}" \ | ||
| -hc "${RTKBASE_VERSION}" -hm "${MOUNT_NAME}" \ | ||
| -hp "${ANT_POSITION}" -ha 0000/"${ANT_TYPE}" \ | ||
| -hr 0000/"${RECEIVER}"/"${REC_VERSION}" \ | ||
| -od -os -oi -ot -ti 1 -tt 0 \ | ||
| echo "- CREATING RINEX ${RINEX_FILE}" | ||
| "${CONVBIN_PATH}" "${raw_file}" -v 3.04 -r "${RAW_TYPE}" \ | ||
| -hc "${RTKBASE_VERSION}" -hm "${MOUNT_NAME}" \ | ||
| -hp "${ANT_POSITION}" -ha 0000/"${ANT_TYPE}" \ | ||
| -hr 0000/"${RECEIVER}"/"${REC_VERSION}" \ | ||
| -od -os -oi -ot \ | ||
| -ti 1 -tt 0 \ | ||
| -ts "${OBS_DATE}" "${TS_HMS}" \ | ||
| -te "${OBS_DATE}" "${TE_HMS}" \ | ||
| -ro "${REC_OPTION}" -o "${RINEX_FILE}" | ||
| return $? | ||
| } | ||
|
|
||
| #go to directory | ||
| # go to directory | ||
| cd "${DATA_DIR}" || exit 1 | ||
| #get date file, year & create RINEX name | ||
| filedate=$(echo ${1:0:10}) | ||
| year2=$(echo ${1:2:2}) | ||
|
|
||
| test -z "${CONVBIN_PATH}" && echo 'Error: Convbin not found' && exit 1 | ||
| if [[ ${RINEX_TYPE} == 'ign' ]] ; then rnx_conversion_func='convert_to_rinex_ign' ; RINEX_FILE=$(echo "${filedate}"-"${MOUNT_NAME}"_"${RINEX_TYPE}"."${year2}"o) | ||
| elif [[ ${RINEX_TYPE} == 'nrcan' ]] ; then rnx_conversion_func='convert_to_rinex_nrcan' ; RINEX_FILE=$(echo "${filedate}"-"${MOUNT_NAME}"_"${RINEX_TYPE}".obs) | ||
| elif [[ ${RINEX_TYPE} == '30s_full' ]] ; then rnx_conversion_func='convert_to_rinex_30s_full' ; RINEX_FILE=$(echo "${filedate}"-"${MOUNT_NAME}"_"${RINEX_TYPE}".obs) | ||
| elif [[ ${RINEX_TYPE} == '1s_full' ]] ; then rnx_conversion_func='convert_to_rinex_1s_full' ; RINEX_FILE=$(echo "${filedate}"-"${MOUNT_NAME}"_"${RINEX_TYPE}".obs) | ||
| fi | ||
|
|
||
| #Let's launch the CONVBIN process | ||
| echo "- Processing on ""${RAW_ARCHIVE}" | ||
| # compute dates for naming and time window | ||
| set_obs_date | ||
|
|
||
| # choose conversion function and output name | ||
| case "${RINEX_TYPE}" in | ||
| ign) | ||
| rnx_conversion_func='convert_to_rinex_ign' | ||
| RINEX_FILE="${filedate}-${MOUNT_NAME}_${RINEX_TYPE}.${year2}o" | ||
| ;; | ||
| nrcan) | ||
| rnx_conversion_func='convert_to_rinex_nrcan' | ||
| RINEX_FILE="${filedate}-${MOUNT_NAME}_${RINEX_TYPE}.obs" | ||
| ;; | ||
| 30s_full) | ||
| rnx_conversion_func='convert_to_rinex_30s_full' | ||
| RINEX_FILE="${filedate}-${MOUNT_NAME}_${RINEX_TYPE}.obs" | ||
| ;; | ||
| 1s_full) | ||
| rnx_conversion_func='convert_to_rinex_1s_full' | ||
| RINEX_FILE="${filedate}-${MOUNT_NAME}_${RINEX_TYPE}.obs" | ||
| ;; | ||
| *) | ||
| echo "Error: unknown rinex_type '${RINEX_TYPE}' (expected: ign|nrcan|30s_full|1s_full)" 1>&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| # Launch convbin | ||
| echo "- Processing on ${RAW_ARCHIVE}" | ||
|
|
||
| file_extension="${RAW_ARCHIVE##*.}" | ||
| if [[ $file_extension == 'zip' ]] | ||
| then | ||
| extract_raw_file | ||
| else | ||
| raw_file="${RAW_ARCHIVE}" | ||
| if [[ "${file_extension}" == "zip" ]]; then | ||
| extract_raw_file | ||
| else | ||
| raw_file="${RAW_ARCHIVE}" | ||
| fi | ||
| ${rnx_conversion_func} | ||
|
|
||
| "${rnx_conversion_func}" | ||
| return_code=$? | ||
| echo -n 'rinex_file='"${RINEX_FILE}" | ||
| [[ $file_extension == 'zip' ]] && rm "${raw_file}" | ||
| exit $return_code | ||
|
|
||
| echo -n "rinex_file=${RINEX_FILE}" | ||
|
|
||
| [[ "${file_extension}" == "zip" ]] && rm -f "${raw_file}" | ||
|
|
||
| exit "${return_code}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-f 3The ign service support only L1/L2. I think we should keep
-f 2