pro csiro_detrend_mth_sst ; Purpose ; ------- ; Reads monthly-mean CSIRO OGCM SSTs and generates two timeseries: a low-pass ; filtered timeseries, in which variability on timescales shorter than 100 ; years has been removed, and a timeseries of the anomalies. ; ; History ; ------- ; 2005 Aug 24 Steve Phipps Original version, based on ; csiro_detrend_sst.pro ; Define parameters nx = 64 ny = 56 missing_value=-9999.9 ; Get various information from user run_name = "" filename = "" read, run_name, prompt="Run name [e.g. d60] " read, filename, prompt="Name of file containing SSTs : " print, "" ; Get monthly-mean SSTs ncid = ncdf_open(filename) lonid = ncdf_varid(ncid, "longitude") latid = ncdf_varid(ncid, "latitude") yrid = ncdf_varid(ncid, "year") datid = ncdf_varid(ncid, "sst") ncdf_varget, ncid, lonid, lon ncdf_varget, ncid, latid, lat ncdf_varget, ncid, yrid, year ncdf_varget, ncid, datid, data ncdf_attget, ncid, /global, "title", title_in title = string(title_in) ncdf_close, ncid ; Get other info from user year1 = 0 year2 = 0 num_years = n_elements(year) print, "Data covers years ", strtrim(string(year(0)), 2), " to ", $ strtrim(string(year(num_years-1)), 2), "." print, "" read, year1, prompt="First year to analyse [e.g. 1] " read, year2, prompt="Last year to analyse [e.g. 1000] " print, "" ; Declare output arrays l1 = year1 - year(0) l2 = year2 - year(0) num_years = year2 - year1 + 1 data_low = fltarr(nx, ny, 12, num_years) ; Apply a low-pass filter to derive the two timeseries for month = 0, 11 do begin data_low(*, *, month, *) = lowpass_3d(reform(data(*, *, month, l1:l2)), 100) endfor data_high = data(*, *, *, l1:l2) - data_low ; Fix missing values index = where(data_low lt -9000.0) data_low(index) = missing_value data_high(index) = missing_value ; GENERATE OUTPUT FILE ; ; (1) Create netCDF file year1s = strtrim(string(year1), 1) year2s = strtrim(string(year2), 1) if (year1 lt 10000) then year1s = '0' + year1s if (year1 lt 1000) then year1s = '0' + year1s if (year1 lt 100) then year1s = '0' + year1s if (year1 lt 10) then year1s = '0' + year1s if (year2 lt 10000) then year2s = '0' + year2s if (year2 lt 1000) then year2s = '0' + year2s if (year2 lt 100) then year2s = '0' + year2s if (year2 lt 10) then year2s = '0' + year2s filename = "sst." + run_name + ".mth.detrend." + year1s + "-" + year2s + ".nc" ncid = ncdf_create(filename) ; (2) Define dimensions londid = ncdf_dimdef(ncid, "longitude", nx) latdid = ncdf_dimdef(ncid, "latitude", ny) mthdid = ncdf_dimdef(ncid, "month", 12) yrdid = ncdf_dimdef(ncid, "year", num_years) ; (3) Define variables lonvid = ncdf_vardef(ncid, "longitude", londid, /float) latvid = ncdf_vardef(ncid, "latitude", latdid, /float) mthvid = ncdf_vardef(ncid, "month", mthdid, /long) yrvid = ncdf_vardef(ncid, "year", yrdid, /long) lowid = ncdf_vardef(ncid, "sst_low", [londid, latdid, mthdid, yrdid], /float) highid = ncdf_vardef(ncid, "sst_high", [londid, latdid, mthdid, yrdid], /float) ; (4) Put attributes ncdf_attput, ncid, lowid, "long_name", "Low-pass filtered SST" ncdf_attput, ncid, highid, "long_name", "Detrended SST" ncdf_attput, ncid, lonvid, "units", "degrees_east" ncdf_attput, ncid, latvid, "units", "degrees_north" ncdf_attput, ncid, mthvid, "units", "months" ncdf_attput, ncid, yrvid, "units", "years" ncdf_attput, ncid, lowid, "units", "degC" ncdf_attput, ncid, highid, "units", "degC" ncdf_attput, ncid, lowid, "missing_value", missing_value ncdf_attput, ncid, highid, "missing_value", missing_value ncdf_attput, ncid, lonvid, "modulo", " " ncdf_attput, ncid, mthvid, "modulo", " " ncdf_attput, ncid, lonvid, "point_spacing", "even" ncdf_attput, ncid, latvid, "point_spacing", "uneven" ncdf_attput, ncid, mthvid, "point_spacing", "even" ncdf_attput, ncid, yrvid, "point_spacing", "even" ncdf_attput, ncid, /global, "title", title ; (5) Exit define mode ncdf_control, ncid, /endef ; (6) Write data ncdf_varput, ncid, lonvid, lon ncdf_varput, ncid, latvid, lat ncdf_varput, ncid, mthvid, indgen(12)+1 ncdf_varput, ncid, yrvid, year(l1:l2) ncdf_varput, ncid, lowid, data_low ncdf_varput, ncid, highid, data_high ; (7) Close file ncdf_close, ncid end