diff --git a/ush/cdo_post_ocean_format.sh b/ush/cdo_post_ocean_format.sh deleted file mode 100755 index 9e88736dda..0000000000 --- a/ush/cdo_post_ocean_format.sh +++ /dev/null @@ -1,193 +0,0 @@ -#! /usr/bin/env bash - -####### -# Script for updating/adding specified netCDF variable metadata -# attribute values. -# -# Syntax: -# cdo_post_prep.sh variable_file input_netcdf output_netcdf -# -# Arguments: -# -# variable_file: ASCII formatted file containing netCDF variables -# and the respective metadata attributes to be -# updated/added; the supported format is as -# follows. -# -# -# -# -# An example using the format described above is as follows. -# -# SST coordinates geolon,geolat,time -# uo coordinates geolon_u,geolon_u,time -# vo coordinates geolon_v,geolon_v,time -# -# The example above will perform the following task using this -# script. -# -# * Assign the netCDF metadata attribute `coordinates` for -# variable `SST` the values `geolon,geolat,time` and update -# the `output_netcdf` file path. -# -# * Assign the netCDF metadata attribute `coordinates` for -# variable `uo` the values `geolon_u,geolat_u,time` and update -# the `output_netcdf` file path. -# -# * Assign the netCDF metadata attribute `coordinates` for -# variable `vo` the values `geolon_v,geolat_v,time` and update -# the `output_netcdf` file path. -# -# input_netcdf: The netCDF-formatted file path containing the -# variables defined in `variable_file`. -# -# output_netcdf: A netCDF-formatted file path to contain the -# specified variables remapped to the destination -# grid projection. -####### - -# Collect the command line arguments and check the validity. -variable_file="${1}" -input_path="${2}" -output_path="${3}" - -####### - -if [[ "$#" -ne 3 ]]; then - echo "Usage: $0 " - exit 100 -fi - -####### - -# _comma_split_string - Split a comma-delimited string into an array. -# -# Description: -# This function takes a comma-delimited string as input and splits -# it into an array. Each element in the resulting array is -# obtained by splitting the input string at commas and then -# removing leading and trailing spaces. -# -# Parameters: -# $1 - The comma-delimited string to split. -# -# Global Variables: -# global_array - An array containing the split elements. -# -# Example usage: -# _comma_split_string "item1,item2 item3,item4" -# for element in "${global_array[@]}"; do -# echo "$element" -# done -# -# This example will split the input string into individual elements -# and print each element on a separate line. -function _comma_split_string() { - local string="${1}" - - local local_array=() - global_array=() - IFS="," read -ra items <<< "${string}" - for item in "${items[@]}"; do - local_array+=("${item} ") - done - for item in "${local_array[@]}"; do - IFS=" " read -ra items <<< "${item}" - for element in "${items[@]}"; do - global_array+=("${element} ") - done - done -} - -####### - -# _strip_whitespace - Remove whitespace from a string. -# -# Description: -# This function takes an input string and removes all whitespace -# characters (spaces, tabs, and newline characters) to produce a -# cleaned output string. -# -# Parameters: -# $1 - The input string from which whitespace will be removed. -# -# Return: -# The cleaned string with no whitespace. -# -# Example usage: -# cleaned_string=$(_strip_whitespace " This is a string with spaces ") -# echo "Cleaned string: \"$cleaned_string\"" -# -# This example will remove all leading, trailing, and internal -# whitespace from the input string and display the cleaned result. -function _strip_whitespace(){ - local in_string="${1}" - - out_string=$(echo "${in_string}" | $(command -v sed) "s/ //g") -} - -####### - -# ncattr_update - Update/add attributes for a variable in a netCDF file. -# -# Description: -# This function updates the specified attribute for a specified -# variable in a netCDF file using the `ncatted` command. -# -# Parameters: -# $1 - The variable name to update. -# $2 - netCDF variable metadata attribute name. -# $3 - The coordinates as a comma-separated string. -# -# Global Variables: -# global_array - An array containing the split coordinates. -# output_path - The path to the output netCDF file. -# -# Example usage: -# ncupdate "variable_name" "coords" "lon,lat,time" -# -# This example updates the `coords` attributes for the specified -# variable and writes the updates to the output netCDF file. -function ncattr_update(){ - local varname="${1}" - local ncattr="${2}" - local coords="${3}" - - _comma_split_string "${coords}" - coords="${global_array[@]}" - coords_str="$(echo "${coords}" | $(command -v tr) -s ' ')" - ncattr_str="$(echo "${ncattr}" | $(command -v tr) -s ' ')" - echo "Adding netCDF attribute ${ncattr_str} values ${coords_str} to variable ${varname} metadata and writing to file ${output_path}" - ($(command -v ncatted) -O -a "${ncattr_str}","${varname}",c,c," ${coords_str}" "${output_path}" "${output_path}") -} - -####### - -start_time=$(date +%s) -_calling_script=$(basename "${BASH_SOURCE[0]}") -start_time_human=$(date -d"@${start_time}" -u) -echo "Begin ${_calling_script} at ${start_time_human}." - -# Copy the input file path to the output file path. -echo "Copying file ${input_path} to ${output_path} and preparing for variable updates." -$(command -v cp) "${input_path}" "${output_path}" - -# Read the configuration file for the the variables to be updated and -# proceed accordingly. -while IFS= read -r line; do - - # Get the attributes for the respective variable. - varname=$(echo "${line}" | $(command -v awk) '{print $1}') - ncattr=$(echo "${line}" | $(command -v awk) '{print $2}') - coords=$(echo "${line}" | $(command -v awk) '{print $3}') - - # Update the variable attributes and write the updates to the - # specified output file (see `output_path`). - ncattr_update "${varname}" "${ncattr}" "${coords}" - -done < "${variable_file}" - -stop_time=$(date +%s) -_calling_script=$(basename "${BASH_SOURCE[0]}") -stop_time_human=$(date -d"@${stop_time}" -u) -echo "End ${_calling_script} at ${stop_time_human}." diff --git a/ush/remap_prep.sh b/ush/remap_prep.sh index d2cd7f5504..0368812201 100755 --- a/ush/remap_prep.sh +++ b/ush/remap_prep.sh @@ -124,7 +124,7 @@ function _comma_split_string() { function _strip_whitespace(){ local in_string="${1}" - out_string=$(echo "${in_string}" | $(command -v sed) "s/ //g") + out_string=$(echo "${in_string}" | sed "s/ //g") } ####### @@ -156,10 +156,10 @@ function ncattr_update(){ _comma_split_string "${coords}" coords="${global_array[@]}" - coords_str="$(echo "${coords}" | $(command -v tr) -s ' ')" - ncattr_str="$(echo "${ncattr}" | $(command -v tr) -s ' ')" + coords_str="$(echo "${coords}" | tr -s ' ')" + ncattr_str="$(echo "${ncattr}" | tr -s ' ')" echo "Adding netCDF attribute ${ncattr_str} values ${coords_str} to variable ${varname} metadata and writing to file ${output_path}" - ($(command -v ncatted) -O -a "${ncattr_str}","${varname}",c,c," ${coords_str}" "${output_path}" "${output_path}") + (ncatted -O -a "${ncattr_str}","${varname}",c,c," ${coords_str}" "${output_path}" "${output_path}") } ####### @@ -171,16 +171,16 @@ echo "Begin ${_calling_script} at ${start_time_human}." # Copy the input file path to the output file path. echo "Copying file ${input_path} to ${output_path} and preparing for variable updates." -$(command -v cp) "${input_path}" "${output_path}" +cp "${input_path}" "${output_path}" # Read the configuration file for the the variables to be updated and # proceed accordingly. while IFS= read -r line; do # Get the attributes for the respective variable. - varname=$(echo "${line}" | $(command -v awk) '{print $1}') - ncattr=$(echo "${line}" | $(command -v awk) '{print $2}') - coords=$(echo "${line}" | $(command -v awk) '{print $3}') + varname=$(echo "${line}" | awk '{print $1}') + ncattr=$(echo "${line}" | awk '{print $2}') + coords=$(echo "${line}" | awk '{print $3}') # Update the variable attributes and write the updates to the # specified output file (see `output_path`).