pro average_sss ; Purpose ; ------- ; Reads in CSIRO ocean model output, derives climatological SSSs and writes ; the values to a netCDF file ; ; History ; ------- ; 2004 Aug 25 Steve Phipps Original version, based on average_sst.pro ; 2004 Sep 17 Steve Phipps Modified for five-digit year numbers ; Define parameters nx = 64 ny = 56 nz = 21 nmonth = 12 missing_value = -9999.9 ; Get details from user run_name = "" year1 = 0 year2 = 0 read, run_name, prompt="Please enter the run name [e.g. d30] " read, year1, prompt="Please enter the initial year [e.g. 1] " read, year2, prompt="Please enter the final year [e.g. 500] " ; Get number of years of data to read nyears = year2 - year1 + 1 ; Declare array to hold data sss = fltarr(nx, ny, nmonth, nyears) salin = fltarr(nx, ny, nz, nmonth) ; Loop over years for year = year1, year2 do begin ; Derive name of input file yr = year yrs = strtrim(string(yr), 2) if (yr lt 10000) then yrs = '0' + yrs if (yr lt 1000) then yrs = '0' + yrs if (yr lt 100) then yrs = '0' + yrs if (yr lt 10) then yrs = '0' + yrs infile = "com." + run_name + "." + yrs + ".nc" print, "Reading data from file ", infile, " ..." ; Open input file inid = ncdf_open(infile) ; If this is the first input file, read the axes if (year eq year1) then begin loninid = ncdf_varid(inid, "lonts") latinid = ncdf_varid(inid, "latts") ncdf_varget, inid, loninid, lon ncdf_varget, inid, latinid, lat endif ; Read data from input file salinid = ncdf_varid(inid, "sal") ncdf_varget, inid, salinid, salin sss(*, *, *, year-year1) = salin(*, *, 0, *) ; Close input file ncdf_close, inid endfor ; Derive the climatology clim = total(sss, 4) / float(nyears) ; Fix missing values clim(where(clim lt -9000.0)) = missing_value ; Derive name of output file year1s = strtrim(string(year1), 2) year2s = strtrim(string(year2), 2) 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 outfile = "sss." + run_name + ".clim." + year1s + "-" + year2s + ".nc" ; Create output file ; ; (1) Create netCDF file outid = ncdf_create(outfile) ; (2) Define dimensions londid = ncdf_dimdef(outid, "longitude", nx) latdid = ncdf_dimdef(outid, "latitude", ny) mondid = ncdf_dimdef(outid, "month", nmonth) ; (3) Define variables lonvid = ncdf_vardef(outid, "longitude", londid, /float) latvid = ncdf_vardef(outid, "latitude", latdid, /float) monvid = ncdf_vardef(outid, "month", mondid, /short) sssid = ncdf_vardef(outid, "sss", [londid, latdid, mondid], /float) ; (4) Put attributes title = "CSIRO model run " + run_name + ", years " + year1s + " to " + year2s ncdf_attput, outid, sssid, "long_name", "Sea surface salinity" ncdf_attput, outid, lonvid, "units", "degrees_east" ncdf_attput, outid, latvid, "units", "degrees_north" ncdf_attput, outid, monvid, "units", "months" ncdf_attput, outid, sssid, "units", "psu" ncdf_attput, outid, sssid, "missing_value", missing_value ncdf_attput, outid, lonvid, "modulo", " " ncdf_attput, outid, lonvid, "point_spacing", "even" ncdf_attput, outid, latvid, "point_spacing", "uneven" ncdf_attput, outid, monvid, "point_spacing", "even" ncdf_attput, outid, /global, "title", title ; (5) Exit define mode ncdf_control, outid, /endef ; (6) Write data months = indgen(12) + 1 ncdf_varput, outid, lonvid, lon ncdf_varput, outid, latvid, lat ncdf_varput, outid, monvid, months ncdf_varput, outid, sssid, clim ; (7) Close output file ncdf_close, outid end