-
Notifications
You must be signed in to change notification settings - Fork 2
/
lonflip.ncl
63 lines (41 loc) · 1.34 KB
/
lonflip.ncl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;;; NCL lonflip: reorder longitude from -180:180 -> 0:360
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;; Specify arguments to script via command-line:
;; ncl lonflip.ncl infile=\"$in\" outfile=\"$out\" varname=\"$var\"
system("rm "+outfile)
fin = addfile(infile, "r")
fout = addfile(outfile, "c")
filedimdef(fout,"time",-1,True) ;; make time dimension unlimited
data = fin->$varname$
odata = lonFlip(data)
printVarSummary(data)
printVarSummary(odata)
fout->$varname$ = odata
; copy global attributes
att_names = getvaratts(fin)
do i = 0,dimsizes(att_names)-1
fout@$att_names(i)$ = fin@$att_names(i)$
end do
;; No need to add history entry - varname@lonFlip attribute records operation
;; But the data does (potentially) get rearranged, so:
;; update unique tracking_id
fout@tracking_id = systemfunc("uuidgen")
; copy variables
var_names = getfilevarnames (fin) ;
do i = 0,dimsizes(var_names)-1
if (var_names(i) .eq. "lat" .or. \
var_names(i) .eq. "lon" .or. \
var_names(i) .eq. varname \
) then
print(""+var_names(i)+": skipped")
else
print(""+var_names(i))
fout->$var_names(i)$ = fin->$var_names(i)$
end if
end do
delete(fin)
delete(fout)
delete(var_names)
delete(att_names)
;; Copyright 2009-2012 Univ. Corp. for Atmos. Research
;; Author: Seth McGinnis, [email protected]