reorder and mergetime multiple netcdf from a directory
Added by Beata Szabo-Takacs about 5 years ago
Dear All,
I have several NetCDF files what I would like to merge with mergetime
operator by cdo mergetime *.nc out.nc
Before merging the files I should reorder their dimensions with ncpdq -a time,altitude,latitude,longitude file.nc file.nc
Could someone suggest me a method for reordering multiple files in one way? Thank you for your help in advance!
Replies (3)
RE: reorder and mergetime multiple netcdf from a directory - Added by Karin Meier-Fleischer about 5 years ago
Hi Beata,
in one way? Use a shell script.
-Karin
RE: reorder and mergetime multiple netcdf from a directory - Added by Beata Szabo-Takacs about 5 years ago
Dear Karin, Thank you for your suggestion. I could write a bash shell script to combine nco ncpdq
and cdo mergetime
operators in one way. I have directories like 01, 02, 03 ...10, 11,...31 (days of a month). These directories contain 5 min resolution daily data what I would like to merge. My script can successfully combine these operators. The general description of the script is:
@ #!/bin/bash
dir=1
while [ $dir -le 31 ]
do
D0="/path/to/0$dir"
D1="/path/to/$dir"
if [ ! -d "$D0" ] && [ ! -d "$D1" ]; then
dir=$dir
elif [ $dir -lt 10 ]; then
for f in /path/to/0$dir/*
do
ncpdq -a time,altitude,latitude,longitude -O "$f" "$f"
done
cdo mergetime /path/to/0$dir/*.nc out_$dir.nc
else
for f in /path/to/$dir/*
do
ncpdq -a time,altitude,latitude,longitude -O "$f" "$f"
done
cdo mergetime /path/to/$dir/*.nc out_$dir.nc
fi
dir=$((dir+1))
done
@
and I run it as ./myscript.sh 2> /dev/null
to supress the cdo messages.
I just shared it to help other users.
RE: reorder and mergetime multiple netcdf from a directory - Added by Karin Meier-Fleischer about 5 years ago
Thanks for sharing.