# -*- coding: utf-8 -*-

"""
2015-08-01 okada  
"""

import netCDF4


def get_time(ncfile):
    JST = 'seconds since 1968-05-23 09:00:00 GMT'
    nc = netCDF4.Dataset(ncfile, 'r')
    time = nc.variables['ocean_time'][:]
    print ncfile
    print netCDF4.num2date(time[0], JST), 0
    print netCDF4.num2date(time[-1], JST), len(time[:])-1

if __name__ == '__main__':
    #import romspy
    get_time('/Users/teruhisa/Dropbox/Data/ob500_ini_fennelP-6.nc')

@@ -66,35 +66,8 @@
 F4%0A%0A
-%0Adef get_time(ncfile):%0A    
 JST 
@@ -112,54 +112,194 @@
 MT'%0A
-    nc = netCDF4.Dataset(ncfile, 'r')%0A    time
+%0A%0Adef get_time(ncfile, which='ends', tunit=JST):%0A    nc = netCDF4.Dataset(ncfile, 'r')%0A    print ncfile%0A    if which == 'ends':%0A        t = len(nc.dimensions%5B'ocean_time'%5D)%0A        start
  = n
@@ -328,72 +328,266 @@
 e'%5D%5B
-:
+0
 %5D%0A    
-print ncfile%0A    print netCDF4.num2date(time%5B0%5D, JST), 0%0A
+    end = nc.variables%5B'ocean_time'%5D%5Bt-1%5D%0A        print netCDF4.num2date(start, tunit), 0%0A        print netCDF4.num2date(end, tunit), t-1%0A    elif which == 'all':%0A        time = nc.variables%5B'ocean_time'%5D%5B:%5D%0A        for t in range(len(time)):%0A        
     
@@ -614,18 +614,17 @@
 te(time%5B
--1
+t
 %5D, JST),
@@ -628,22 +628,84 @@
 T), 
-len(time%5B:%5D)-1
+t%0A    else:%0A        print 'You should select %22ends%22 or %22all%22'%0A    nc.close()
 %0A%0Aif

Modify get_time