Creating new netCDF file and generating variable
Added by Daniel Burt 10 months ago
Hi,
I'm using CDO version 2.0.4
I'm trying to adapt an older script to my purposes but cannot contact the original author.
The script generates a temporary output file "buffer.nc", sets the attributes from a generate text file and the parameter table with another text file.
The "for" operator is then used to loop across an expression but I get the error "No output variable found!".
Is this an error in the method of assignment of the output variable or with the parameter table?
Should a different procedure be used with this version of CDO?
code used is below:
GATTS_FILE=$TEMP_DIR/attributes.txt
cat > $GATTS_FILE << END
title="$TITLE"
file_type="Annual means file"
model="ECHAM6"
institution="Max-Planck-Institut für Meteorologie"
user="$REAL_NAME"
END
PARTAB_FILE=$TEMP_DIR/units.partab
cat > $PARTAB_FILE << END
¶meter name=var1 units=" " /
END
TEMPDATA_FILE=$TEMP_DIR/buffer.nc
SETGATTS=copy,
if $CDO -h setattribute > /dev/null 2>&1
then
SETGATTS=setattribute,FILE=
elif $CDO -h setgatts > /dev/null 2>&1
then
SETGATTS=setgatts,
fi
$CDO \
-$SETGATTS$GATTS_FILE \
-setpartabn,$PARTAB_FILE \
-settaxis,1000-01-01,00:00:00,1year \
-expr,"var1 = 500 + 0.15 * i" \
-expr,'i = (for > 0) * for' \
-for,-2,1000 $TEMPDATA_FILE
Replies (1)
RE: Creating new netCDF file and generating variable - Added by Karin Meier-Fleischer 10 months ago
I must confess that I never used the seq (former for) operator until now.
What is wrong - what has to be done:
- variable CDO is not defined
- write the parameter table content for the variable in separate lines (as I understand the docu)
- note: the option copy does not take any parameter and is not needed here anyway
- use setattribute only (since cdo version 1.8.0)
- set the output file type to nc (buffer.nc)
With no warranty!!
#!/usr/bin/env bash TEMP_DIR="./" CDO=cdo GATTS_FILE=$TEMP_DIR/attributes.txt cat > $GATTS_FILE << END title="$TITLE" file_type="Annual means file" model="ECHAM6" institution="Max-Planck-Institut für Meteorologie" user="$REAL_NAME" END PARTAB_FILE=$TEMP_DIR/units.partab cat > $PARTAB_FILE << END ¶meter name=var1 units=" " / END TEMPDATA_FILE=$TEMP_DIR/buffer.nc $CDO -f nc -setattribute,FILE=$GATTS_FILE \ -setpartabn,$PARTAB_FILE \ -settaxis,1000-01-01,00:00:00,1year \ -expr,'var1 = 500+0.15*for' \ -expr,'for=(seq > 0)*seq' \ -seq,-2,1000 $TEMPDATA_FILE