Project

General

Profile

RE: Sort Grid Cell Values From Greatest to Smallest (Rank) ยป sortCdo.zsh

Ralf Mueller, 2019-10-22 18:34

 
set -x
inputfile=$1
outputfile='sortedInput.nc'

min=$(cdo -outputkey,value,nohead -fldmin $inputfile)

cdo -gtc,$((min - 1)) $inputfile mask

cdo -f nc -reducegrid,mask $inputfile unstructuredInput

# create an orderes list of location indices, use options of 'sort' to control the order
cells=$(cdo -outputkey,value,xind,nohead unstructuredInput | sort -rn | rev | cut -d ' ' -f 2 | rev | xargs echo | tr ' ' ,)

# selecta (all) grid locations in the order of the data values
cdo -selgridcell,$cells unstructuredInput $outputfile
    (1-1/1)