filename = "./Test_reads.csv" ;---Open CSV file and read as array of strings lines = asciiread(filename,-1,"string") nlines = dimsizes(lines)-1 ;---Read the 2nd and 3rd columns of data, convert to float jul_day = tofloat(str_get_field(lines(1:),2,",")) rainfall = tofloat(str_get_field(lines(1:),3,",")) ;---Parse the Time field by "," first, then ":", convert to integer hh_mm_ss = str_get_field(lines(1:),1,",") hh = toint(str_get_field(hh_mm_ss,1,":")) mm = toint(str_get_field(hh_mm_ss,2,":")) ss = toint(str_get_field(hh_mm_ss,3,":")) rainfall@long_name = "Rainfall" hh@long_name = "hours" mm@long_name = "minutes" ss@long_name = "seconds" ;---Look at your data! printMinMax(rainfall,0) printMinMax(hh,0) printMinMax(mm,0) printMinMax(ss,0) ;---Loop through 24 hours in steps of 3 and take 3-hourly average. inds = new(nlines,integer) total_inds = 0 ; this is just a counter to make sure we get all time values num_inds = 0 do hr=0,23,3 start_hr = hr end_hr = hr+2 print("Hours " + start_hr + " through " + end_hr) zinds := ind(hh.ge.start_hr.and.hh.le.end_hr) if(.not.any(ismissing(zinds))) then num_inds = dimsizes(zinds) zavg = avg(rainfall(zinds)) print(" # of values in range = " + num_inds) print(" Rainfall average in range = " + zavg) ;---Keep track of indexes we've collected so far just for debugging purposes. inds(total_inds:total_inds+num_inds-1) = zinds total_inds = total_inds + num_inds else print("There are no data values between the hours of " + start_hr + " and " + end_hr) end if end do print("The total number of indexes we collected was: " + total_inds) print("This should equal the number of data values in the CSV file: " + nlines)