pro csiro_detrend_sst ; Purpose ; ------- ; Reads annual-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 23 Steve Phipps Original version, based on ; csiro_detrend_climat.pro ; 2005 Sep 25 Steve Phipps Improved the fixing of missing values ; 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 annual-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, "" ; Apply a low-pass filter to derive the two timeseries l1 = year1 - year(0) l2 = year2 - year(0) data_low = lowpass_3d(data(*, *, l1:l2), 100) data_high = data(*, *, l1:l2) - data_low ; Fix missing values for k = 0, year2-year1 do begin for j = 0, ny-1 do begin for i = 0, nx-1 do begin if (data_low(i, j, k) lt -9000.0) then begin data_low(i, j, k) = missing_value data_high(i, j, k) = missing_value endif endfor endfor endfor ; 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 + ".detrend." + year1s + "-" + year2s + ".nc" ncid = ncdf_create(filename) ; (2) Define dimensions londid = ncdf_dimdef(ncid, "longitude", nx) latdid = ncdf_dimdef(ncid, "latitude", ny) yrdid = ncdf_dimdef(ncid, "year", year2-year1+1) ; (3) Define variables lonvid = ncdf_vardef(ncid, "longitude", londid, /float) latvid = ncdf_vardef(ncid, "latitude", latdid, /float) yrvid = ncdf_vardef(ncid, "year", yrdid, /long) lowid = ncdf_vardef(ncid, "sst_low", [londid, latdid, yrdid], /float) highid = ncdf_vardef(ncid, "sst_high", [londid, latdid, 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, 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, lonvid, "point_spacing", "even" ncdf_attput, ncid, latvid, "point_spacing", "uneven" 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, yrvid, year(l1:l2) ncdf_varput, ncid, lowid, data_low ncdf_varput, ncid, highid, data_high ; (7) Close file ncdf_close, ncid end