pro average_stfsal_128_112 ; Purpose ; ------- ; Reads the output of the high-resolution version of the CSIRO Mk3L ocean ; model, derives climatological surface salinity tendencies, and writes the ; values to a netCDF file. ; ; History ; ------- ; 2008 Feb 23 Steven Phipps Original version, based on average_stfsal.pro ; Define parameters nx = 128 ny = 112 nmonth = 12 ; Get details from user run_name = "" year1 = 0 year2 = 0 read, run_name, prompt="Please enter the run name [e.g. g89] " read, year1, prompt="Please enter the initial year [e.g. 6901] " read, year2, prompt="Please enter the final year [e.g. 7000] " ; Get number of years of data to read nyears = year2 - year1 + 1 ; Declare array to hold data stfsal = fltarr(nx, ny, nmonth, nyears) stfsalin = fltarr(nx, ny, 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 stfsalinid = ncdf_varid(inid, "stfsal") ncdf_varget, inid, stfsalinid, stfsalin stfsal(*, *, *, year-year1) = stfsalin ; Close input file ncdf_close, inid endfor ; Derive the climatology clim = total(stfsal, 4) / float(nyears) ; 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 = "stfsal." + 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) stfsalid = ncdf_vardef(outid, "stfsal", [londid, latdid, mondid], /float) ; (4) Put attributes title = "Mk3L run " + run_name + ", years " + year1s + " to " + year2s ncdf_attput, outid, stfsalid, "long_name", "Surface salinity tendency" ncdf_attput, outid, lonvid, "units", "degrees_east" ncdf_attput, outid, latvid, "units", "degrees_north" ncdf_attput, outid, monvid, "units", "months" ncdf_attput, outid, stfsalid, "units", "s^-1" 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, stfsalid, clim ; (7) Close output file ncdf_close, outid end