-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComputePressureLevels-3hrSim.ncl
executable file
·104 lines (81 loc) · 2.99 KB
/
ComputePressureLevels-3hrSim.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
; ------------------------------------------------------------------------
; Compute vertical profiles of pressure based on files.
; Write out to netCDF file using slightly improved emthod compared to
; version of the script that's saved in NCAR/Analysis/CLUBB_initial/data.
;
; Date: 1 Sept 2020
; Author: Meg Fowler
; ------------------------------------------------------------------------
begin
; -------- Read in data --------
filePS = "/glade/work/mdfowler/data/CLM5wCAM5_highOutput/f.e21.FHIST.f09_f09_mg17.CLM5wCAM5phys-subDailyOutput.001.cam.h1.1989_conusAllTimes-VertProfiles.nc"
fileOut = "/glade/work/mdfowler/data/CLM5wCAM5_highOutput/f.e21.FHIST.f09_f09_mg17.CLM5wCAM5phys-subDailyOutput.001.cam.h1.1989_conus-Pressure-UTCtimes.nc"
;filePS = "/Users/mdfowler/Documents/Analysis/Coupling_initial/data/3hrSim_CAM6-CLM5/f.e21.FHIST.f09_f09.cesm2_cam6_clm5.001.cam.h4.1983_conusAllTimes-VertProfiles.nc"
;fileOut = "/Users/mdfowler/Documents/Analysis/Coupling_initial/data/3hrSim_CAM6-CLM5/f.e21.FHIST.f09_f09.cesm2_cam6_clm5.001.cam.h4.1983_conus-Pressure-UTCtimes.nc"
; Open file with surface pressure
fPS = addfile(filePS,"r")
; Read a few variables
hyam = fPS->hyam
hybm = fPS->hybm
ps = fPS->PS
p0 = fPS->P0
time = fPS->time
lat = fPS->lat
lon = fPS->lon
; ------ Compute pressure levels --------
; Compute pressure levels
pm = pres_hybrid_ccm(ps,p0,hyam,hybm)
; ------ Convert to UTC time ----------
utc_date = cd_calendar(time, 0)
; Also isolate yr/mon/day/hr arrays
UTChr = utc_date(:,3)
UTCday = utc_date(:,2)
UTCmon = utc_date(:,1)
UTCyr = utc_date(:,0)
; ----- Create netCDF file ------
print("Creating netCDF file")
system("/bin/rm -f " + fileOut) ; remove any pre-existing file
ncdf = addfile(fileOut,"c") ; open output netCDF file
; Create global attributes of the file (optional)
fAtt = True ; assign file attributes
fAtt@title = "NCL used to get pressure levels."
fAtt@source_file = filePS
fAtt@Conventions = "None"
fAtt@creation_date = systemfunc ("date")
fileattdef( ncdf, fAtt ) ; copy file attributes
; Make time an unlimited dimension
filedimdef(ncdf,"time",-1,True)
;===================================================================
; output variables directly; NCL will call appropriate functions
; to write the meta data associated with each variable
;===================================================================
pm!0 = "time"
pm!1 = "lev"
pm!2 = "lat"
pm!3 = "lon"
pm&time = time
pm&lev = hyam
pm&lat = lat
pm&lon = lon
pm@long_name = "Vertical profile of pressure"
pm@units = ps@units
ncdf->PRESSURE = pm
; -----------------------------
UTChr!0 = "time"
UTCday!0 = "time"
UTCmon!0 = "time"
UTCyr!0 = "time"
UTChr&time = time
UTCday&time = time
UTCmon&time = time
UTCyr&time = time
UTChr@long_name = "Hour in UTC"
UTCday@long_name = "Day in UTC"
UTCmon@long_name = "Mon in UTC"
UTCyr@long_name = "Yr in UTC"
ncdf->UTC_hr = UTChr
ncdf->UTC_day = UTCday
ncdf->UTC_mon = UTCmon
ncdf->UTC_yr = UTCyr
print("File created!")
end