From 231c5f17f6e606d065eb4e6d7cad2e2624a558a0 Mon Sep 17 00:00:00 2001 From: Scott Stewart Date: Mon, 4 Nov 2024 10:40:32 -0700 Subject: [PATCH] add script to remove min_concentration field from ancillary file(s) --- .../ancillary/remove_min_conc_in_ancillary.sh | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 scripts/ancillary/remove_min_conc_in_ancillary.sh diff --git a/scripts/ancillary/remove_min_conc_in_ancillary.sh b/scripts/ancillary/remove_min_conc_in_ancillary.sh new file mode 100755 index 00000000..c29ace61 --- /dev/null +++ b/scripts/ancillary/remove_min_conc_in_ancillary.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# ./remove_min_conc_in_ancillary.sh + +# if there is a field called "min_concentration" in arg1, drop it + +# Note: This command outputs a file with the same basename +# in the current directory. +# And it does not allow overwriting of the original file + +# Sample usage: +# This script was used to remove the min_concentration field +# from the v05r00 ancillary files: +# ./remove_min_conc_in_ancillary.sh /share/apps/G02202_V5/v05_ancillary/G02202-ancillary-psn25-v05r00.nc +# ./remove_min_conc_in_ancillary.sh /share/apps/G02202_V5/v05_ancillary/G02202-ancillary-pss25-v05r00.nc + + +var_to_delete=min_concentration + +ifn="$1" +if [ -z "$ifn" ]; then + echo "No input file given. (Should be a netCDF file)" + exit +fi + +ofn=$(basename ${ifn}) + +if [ "$ifn" == "$ofn" ]; then + echo "input and output filename would be the same, exiting" + echo " ${ofn}" + exit +fi + +if [ "$ifn" == ./"$ofn" ]; then + echo "input and output filename would be the same, exiting" + echo " ${ofn}" + exit +fi + +cmd_output=$(ncks -C -O -h -x -v ${var_to_delete} ${ifn} ${ofn}) +if [ ! -z ${cmd_output} ]; then + echo "Command output not empty. Perhaps something went wrong?" + echo "${cmd_output}" +fi