fname_use = "ta_6hrLev_GISS-E2-H_historical_r6i1p1_195001010600-195007010000.nc" fname_fix = "ta_6hrLev_GISS-E2-H_historical_r6i1p1_195007010600-195101010000.nc" fname_bkp = fname_fix + ".bkup" print("======================================================================") print("Making a backup copy of " + fname_fix + " called " + fname_bkp) system("cp -f " + fname_fix + " " + fname_bkp) print("======================================================================") print("Opening original NetCDF files") f_use = addfile(fname_use,"r") f_fix = addfile(fname_fix,"w") print("======================================================================") print("Reading time from both files") time_use = f_use->time ; We will use this time's "units" to time_fix = f_fix->time ; fix this time's values. printVarSummary(time_use) printVarSummary(time_fix) print("======================================================================") print("Convert Jul-Dec time array to the same units as the Jan-Jul time array") print("Original units are '" + time_fix@units) print("Converting to units '" + time_use@units) ;---Convert time to Y,M,D,H,M,S values utc_date = cd_calendar(time_fix,0) year = tointeger(utc_date(:,0)) month = tointeger(utc_date(:,1)) day = tointeger(utc_date(:,2)) hour = tointeger(utc_date(:,3)) minute = tointeger(utc_date(:,4)) second = utc_date(:,5) ;---Convert Y,M,D,H,M,S back to numeric time using new units opt = 0 opt@calendar = time_use@calendar ; this is important! 365_day units = time_use@units ; these are the new units time_new = cd_inv_calendar(year,month,day,hour,minute,second,time_use@units, opt) ;---Make the new time a coordinate array of itself time_new!0 = "time" time_new&time = time_new print("======================================================================") printVarSummary(time_new) ;---Overwrite "time" on the original file with the new time print("======================================================================") print("Writing new 'time' back to " + fname_fix) f_fix->time = time_new