fils2 = systemfunc("ls HAM*.nc") ; read hamsr data q = addfiles(fils2,"r") temp_hamsr = q[:]->ham_airT dims = dimsizes(temp_hamsr) ntim = dims(0) printVarSummary(temp_hamsr) ;--- return permutation vector for sorting time ip = dim_pqsort(temp_hamsr&time,1) ; ; Print the min/max of the time deltas. If you have a negative min and ; a positive max, then the array is NOT monotonic. ; diff_before = temp_hamsr&time(1:)-temp_hamsr&time(0:ntim-2) diff_before@long_name = "time deltas before fix" printMinMax(diff_before,0) ; ; Use ip vector to reorder temp_hamsr. This will also have the effect ; of reordering the time coordinate array. ; temp_hamsr_reorder = temp_hamsr(ip,:) ; ; Print the min/max of time deltas again. Note they are all positive. ; diff_after = temp_hamsr_reorder&time(1:)-temp_hamsr_reorder&time(0:ntim-2) diff_after@long_name = "time deltas after fix" printMinMax(diff_after,0) ;---Create before and after XY plots so you can see the difference. wks = gsn_open_wks("png","hamsr") ;---Set some resources res = True res@gsnMaximize = True ; maximize plot in frame res@gsnDraw = False ; will panel later res@gsnFrame = False res@vpWidthF = 0.8 res@vpHeightF = 0.3 res@trXMinF = min(temp_hamsr&time) res@trXMaxF = max(temp_hamsr&time) res@tiXAxisFontHeightF = 0.015 res@tiYAxisFontHeightF = 0.015 res@tmXBLabelFontHeightF = 0.015 res@tmYLLabelFontHeightF = 0.015 res@xyLineColor = "blue" res@xyLineThicknessF = 2.5 ; default is 1.0 res@tiMainString = "Before reordering" plot_before = gsn_csm_xy(wks,temp_hamsr&time,temp_hamsr(:,0),res) res@tiMainString = "After reordering" plot_after = gsn_csm_xy(wks,temp_hamsr_reorder&time,temp_hamsr_reorder(:,0),res) ;---Panel both plots pres = True pres@gsnMaximize = True gsn_panel(wks,(/plot_before,plot_after/),(/2,1/),pres)