time_range.ncl 1.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; time_range.ncl
; Carl Schreck (carl@cicsnc.org)
; November 2011
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description: Print the time-range and optionally change the units
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


load "$CJS_NCL_LIB/lib.time.ncl"

begin

  ; These are some parameters that could be useful to have up top
  if( .not.isvar("path") ) then
    path = "*nc"
  end if
  if( .not.isvar("timeVar") ) then
    timeVar = "time"
  end if
21
22
print("path="+path)
print("timeVar="+timeVar)
23

24
25
26
27
28
  if( isStrSubset( path, "*" ) ) then
    pathList = systemfunc( "ls " + path )
  else
    pathList = path
  end if
29
30
31
32
33

  do pathInd = 0, dimsizes(pathList)-1
  
    print( (pathInd+1) + ": " + pathList(pathInd) )
    ioFile = addfile( pathList(pathInd), "r" )
34
    if( isfilevar( ioFile, timeVar ) ) then
35
36
37
38
39
40
41
42
43
44
45
46
47
      time = ioFile->$timeVar$

      print( (/ "          " + time@units /) )

      add_time_atts( time )
      time&$timeVar$ = time

      print( "          Start:  " + time@beginning_date )
      print( "          End:    " + time@ending_date )
      print( "          Range:  " + time@actual_range(0) )
      print( "          Range:  " + time@actual_range(1) )
      print( "          Delta:  " + time@delta_t )
      print( "          Length: " + dimsizes(time) )
48
      print( "          Units:  " + time@units )
49
50
51
52
53
54
55
56

      delete(time)
      delete(ioFile)

    end if
  end do

end