-
Notifications
You must be signed in to change notification settings - Fork 2
/
patch-regrid.ncl
64 lines (41 loc) · 1.53 KB
/
patch-regrid.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
64
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
;infile = "swe_MM5I_ncep_10days.nc"
;wgtfile = "weights/wgt.MM5I.UDEL.grid.nc"
;outfile = "test.swe.nc"
;varname = "swe"
;; Specify arguments to script via command-line:
;; ncl patch-regrid.ncl infile=\"$in\" wgtfile=\"$wgt\" outfile=\"$out\" varname=\"$var\" rezero=False
if (.not. isvar("rezero")) then
rezero = False
end if
system("rm "+outfile)
fin = addfile(infile, "r")
fout = addfile(outfile, "c")
filedimdef(fout,"time",-1,True) ;; make time dimension unlimited
data = fin->$varname$
opt = True
opt@CopyVarAtts = True
opt@CopyVarCoords = True
opt@FixMapMethodForPatch = True ;; else metadata sez bilinear instead of patch
odata = ESMF_regrid_with_weights (data, wgtfile, opt)
delete(odata@grid_mapping)
if(rezero) then
odata = where(odata.lt.0, 0, odata)
end if
fout->$varname$ = odata
fout->lat@standard_name = "latitude"
fout->lon@standard_name = "longitude"
; copy global attributes
att_names = getvaratts(fin)
do i = 0,dimsizes(att_names)-1
fout@$att_names(i)$ = fin@$att_names(i)$
end do
;; append history entry
hstring = systemfunc("date")
hstring = hstring + ": ncl patch-regrid.ncl infile="+infile+" wgtfile="+wgtfile+" outfile="+outfile+" varname="+varname
fout@history = hstring+inttochar(10)+fout@history
;; update unique tracking_id
fout@tracking_id = systemfunc("uuidgen")
;; Copyright 2013 Univ. Corp. for Atmos. Research
;; Author: Seth McGinnis, [email protected]