source: TI02-CSML/trunk/parser/API/ops_ArrayGenerator.py @ 1355

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/parser/API/ops_ArrayGenerator.py@1355
Revision 1355, 1.5 KB checked in by domlowe, 13 years ago (diff)

more changes to allow full use of ArrayGenerator class, including change and some corrections to parser code

Line 
1''' ops_ArrayGenerator '''
2from API import *
3import sys
4import cdtime
5   
6def getGeneratedValues(self,frame, summary=None):
7    #For times, given a CF 'frame' generate a list of times.
8    #frame of the form "calendar:units since date time")
9    #supported calendars on NDG wiki
10    #eg getGeneratedValues("360_day:days since 2001-12-18 00:00:00")
11    cal=frame.split(':',1)[0]
12    basedate=frame.split(':',1)[1]
13    csmltime.setcdtimeCalendar(cal)
14    start=int(self.expression.split(':')[0])
15    interval=int(self.expression.split(':')[1])
16    end=int(self.expression.split(':')[2])
17    cdtime.DefaultCalendar=cdtime.MixedCalendar
18    if summary is not None:
19        #return a summary of times (min, interval, max)  using cdtime
20        timelist=[]
21        tmin = cdtime.reltime(start, basedate).tocomp()
22        tmin=csmltime.UDtimeToCSMLtime(tmin)
23        tmax = cdtime.reltime(end, basedate).tocomp()
24        tmax=csmltime.UDtimeToCSMLtime(tmax)
25        timelist.append(tmin)
26        timelist.append(tmax)
27        print timelist
28        print cdtime.DefaultCalendar
29       
30    else:
31        #use cdtime to return a full list of times - may take a long time..
32        timelist=[]
33        t = cdtime.reltime(start, basedate).tocomp()
34        for i in range(start, end, interval):
35            t = t.add(60,cdtime.Seconds)
36            #t = cdtime.reltime(i, basedate).tocomp()
37            #t=csmltime.UDtimeToCSMLtime(t)
38            timelist.append(t)
39        print timelist[:150]
40       
41   
42    return timelist
43   
Note: See TracBrowser for help on using the repository browser.