#!/bin/bash

rm -f *.txt

for file in IPSL*.nc ; do


YYYY1=2015
YYYY2=2200

if [ "$file" != "${file%histo*}" ] ; then
 YYYY1=1850 ; YYYY2=2014
fi  

rm -f ${file%.nc}.txt

ferret <<EOF
use $file
repeat/name=YYYY/range=$YYYY1:$YYYY2 (\
let l1=1+12*(\`YYYY\`-$YYYY1);\
let l2=12+12*(\`YYYY\`-$YYYY1);\
list/nohead/file=${file%.nc}.txt/append/format=(f5.0,f7.2)  \`YYYY\`,tas[x=@ave,y=@ave,l=\`l1\`:\`l2\`@sum] /12)
quit
EOF

done
