Menu

#15 Creating monthly time series

None
closed
None
5
2015-09-04
2014-12-12
DARRAS
No

I am trying to make a monthly time series from monthly-year files from year 1990 to year 1999.

Here is the code I have written but I have problems with the loops and the indexes which are not well interpreted in my script:


num_days=0
days=0
month=0
for YR in {0..9};do

  ncks -O --mk_rec_dmn time file_199${YR}.nc out.nc       
  ncap2 -O -s 'time=array(0,1,$time)' out.nc out2.nc
  ncatted -O -a units,time,m,c,"days since 1990-01-01 00:00" out2.nc

  #### bisextiles years ######
  if ($YR='2' || or $YR='6') then 
    { 
       ncap2 -O -s 'time(0+month)=days+0' -s 'time(1+month)=days+32' -s 'time(2+month)=days+60' -s 'time(3+month)=days+91' -s 'time(4+month)=days+121' -s 'time(5+month)=days+151' -s 'time(6+month)=days+182' -s 'time(7+month)=days+213' -s 'time(8+month)=days+244' -s 'time(9+month)=days+274' -s 'time(10+month)=days+305' -s 'time(11+month)=days+335' out2.nc file_199${YR}.nc
       num_days= 366
    }
  else 
    {
       ncap2 -O -s 'time(0+month)=days+0' -s 'time(1+month)=days+31' -s 'time(2+month)=days+59' -s 'time(3+month)=days+90' -s 'time(4+month)=days+120' -s 'time(5+month)=days+151' -s 'time(6+month)=days+181' -s 'time(7+month)=days+212' -s 'time(8+month)=days+243' -s 'time(9+month)=days+273' -s 'time(10+month)=days+304' -s 'time(11+month)=days+334' out2.nc file_199${YR}.nc
       num_days= 365
    }
  days=days+num_days 
  month=month+12

done
ncrcat -O file_199[0123456789].nc file_1990-1999.nc


1) What am I doing wrong with the indexes
2) Perhaps you have a more elegant solution ?

Discussion

  • Charlie Zender

    Charlie Zender - 2014-12-15

    it's unclear what you're trying to do.
    the manual has examples of accounting for uneven numbers of days in months:
    http://nco.sf.net/nco.html#ccsm
    cz

     
    • DARRAS

      DARRAS - 2014-12-17

      Thank you again for your quick reply.
      Though I have very often been through the manual I never really ended up on these examples.
      That should be very helpfull, I will give it a try!

       
  • Charlie Zender

    Charlie Zender - 2015-09-04

    No activity so closing ticket

     
  • Charlie Zender

    Charlie Zender - 2015-09-04
    • status: open --> closed
    • assigned_to: Charlie Zender
    • Group: -->
     

Log in to post a comment.

MongoDB Logo MongoDB