Skip to content

Commit 08fd40c

Browse files
committed
Fix time range to work with YYYYMMDD or YYYYMMDDHH as well as original YYYY
1 parent 3d91475 commit 08fd40c

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

diagnostics/MJO_suite/daily_netcdf.ncl

+35-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,36 @@ begin
1717
end if
1818
end ; procedure debug_print
1919

20+
undef("check_date_format")
21+
function check_date_format(date_in,date_type,routine_name,debug)
22+
begin
23+
if (date_in.lt.1.e4) then ; input just YYYY, need to add MMDDHH
24+
if (date_type.eq."start") then
25+
date_suffix = 101*100
26+
else if (date_type.eq."end") then
27+
date_suffix = 1231*10
28+
else
29+
print("ERROR: "+routine_name+" No date_type given to function check_date_format")
30+
end if
31+
end if
32+
33+
debug_print("Incoming "+date_type+" date YYYY format: "+date_in,routine_name,debug)
34+
date_out = date_in*1000000+ date_suffix
35+
debug_print("Corrected "+date_type+" date to:"+date_out,routine_name,debug)
36+
37+
else
38+
if (date_in .lt. 100000000) ; YYYYMMDD
39+
debug_print("Incoming "+date_type+" date YYYYMMDD format: "+date_in,routine_name,debug)
40+
date_out = date_in*100 ;; HH = 00
41+
debug_print("Corrected "+date_type+" date to:"+date_out,routine_name,debug)
42+
else
43+
debug_print("Found start date format YYYYMMDDHH: "+yr,routine_name,debug)
44+
date_out = date_in
45+
end if ; YYYYMMDD
46+
end if ; YYYY
47+
48+
return date_out
49+
end ; function check_date_format
2050

2151
begin
2252
; read daily output files from CAM2 and process the data
@@ -63,12 +93,10 @@ nd = dimsizes(time_all)
6393
i2 = nd(0) - 1
6494
debug_print("Time range in file: "+time_all(0)+" -"+time_all(i2),routine_name,debug)
6595

66-
; in hours to match cd_calendar/ut_calendar output YYYYMMDDHH
67-
; uses 18 hrs for endtime since 6-hourly is the most high res we expect
68-
; should still work for daily, just finds YYYY123100
69-
start_time = yr1*1000000+101*100
70-
end_time = yr2*1000000+1231*100+18
71-
debug_print("Time range requested: "+start_time+" "+end_time,routine_name,debug)
96+
; Check if date came in as YYYYMMDD or YYYY (historic)
97+
start_time = check_date_format(yr1,"start",routine_name,debug)
98+
end_time = check_date_format(yr2,"end",routine_name,debug)
99+
72100
tol = 24 ; 24 hours tolerance allows for different time resolutions
73101
do i=0,dimsizes(time_all)-1
74102
; debug_print("examining times "+i+" "+time_all(i),routine_name,debug)
@@ -108,8 +136,7 @@ if ( isMonotonic(date) .ne. 1 ) then
108136
exit ; exit on error
109137
end if
110138

111-
; DRB: used to do pr, rlut separately. Folding them into the loop instead.
112-
; **here first just use read_model_file for pr here, then put into var loop below
139+
; First just use read_model_file for pr here, then put into var loop below
113140
; precipitation rate (pr)
114141
print("daily_netcdf.ncl reading "+file_pr+" for making precip file!")
115142

0 commit comments

Comments
 (0)