;---------------------------------------------------------------------- ; This function generates WRF-style times ("2008-09-29_12:00:00") ; between the given begin and end years. All months and all days for ; each year are included. The minutes and seconds fields are set to 0. ;---------------------------------------------------------------------- function generate_dummy_wrf_times(beg_year,end_year) begin years = ispan(beg_year,end_year,1) months = ispan(1,12,1) nyears = dimsizes(years) nmonths = dimsizes(months) years2 = ndtooned(conform_dims((/nyears,nmonths/),years,0)) months2 = ndtooned(conform_dims((/nyears,nmonths/),months,1)) dom = days_in_month(years2,months2) ;---Construct the WRF-style times string array times = sprinti("%04i",years2) + "-" + \ sprinti("%02i",months2) + "-" + \ sprinti("%02i",dom) + "_00:00:00" return(times) end ;---------------------------------------------------------------------- ; Main code that extracts MAM and OND ranges from WRF times array ;---------------------------------------------------------------------- begin times = generate_dummy_wrf_times(1982,1997) ; Generate `dummy WRF times mam = (/3,4,5/) ; March, April, May ond = (/10,11,12/) ; October, November, Decmeber ;--Parse the WRF times string to get the months as integers. str1 = str_split_csv(times,"-",0) str2 = str_split_csv(str1(:,2),"_",0) wrf_months = toint(str1(:,1)) ;---Get the index locations for MAM and OND and print out the results mam_ind = ind(wrf_months.ge. 3.and.wrf_months.le. 5) ond_ind = ind(wrf_months.ge.10.and.wrf_months.le.12) wrf_times_mam = times(mam_ind) wrf_times_ond = times(ond_ind) print("MAM: " + wrf_times_mam) print("OND: " + wrf_times_ond) end