pro qflux_to_netcdf ; Purpose ; ------- ; Reads in the file qflux.dat, which is generated by average_qflux.pro and ; which contains climatological monthly Q-fluxes, and converts the data to ; netCDF. ; ; History ; ------- ; 2003 Jun 6 Steven Phipps Original version ; 2009 May 2 Steven Phipps Modified to use relative pathnames ; Define constants lon = 64 lat = 28 nmonth = 12 ; Get run details from user run = "" read, run, prompt="Run name [e.g. b44] " ; Declare arrays to hold data occur = dblarr(lon, lat, 2, nmonth) occur_out = dblarr(lon, 2*lat, nmonth) header = "" month_in = 0l occur_in = dblarr(lon, lat, 2) ; Open file for unformatted read access filename = 'qflux.dat.' + run openr, 1, filename, /f77_unformatted ; Read data for month = 1, 12 do begin readu, 1, header readu, 1, month_in readu, 1, occur_in occur(*, *, *, month-1) = occur_in endfor ; Close file close, 1 ; Move the data onto a 64x56 array for j = 0, lat-1 do begin occur_out(*, 2*lat-j-1, *) = occur(*, j, 0, *) occur_out(*, j, *) = occur(*, j, 1, *) endfor ; Get latitudes and longitudes from csiro_landsea.nc ncid = ncdf_open("csiro_landsea.nc") lonid = ncdf_varid(ncid, "longitude") latid = ncdf_varid(ncid, "latitude") ncdf_varget, ncid, lonid, lons ncdf_varget, ncid, latid, lats ncdf_close, ncid ; Create new netCDF file filename = "qflux." + run + ".nc" ncid = ncdf_create(filename) ; Declare dimensions londid = ncdf_dimdef(ncid, "longitude", lon) latdid = ncdf_dimdef(ncid, "latitude", 2*lat) mondid = ncdf_dimdef(ncid, "month", 12) ; Declare variables lonvid = ncdf_vardef(ncid, "longitude", londid, /float) latvid = ncdf_vardef(ncid, "latitude", latdid, /float) monvid = ncdf_vardef(ncid, "month", mondid, /long) climid = ncdf_vardef(ncid, "qflux", [londid, latdid, mondid], /float) ; Put attributes ncdf_attput, ncid, lonvid, "units", "degrees_east" ncdf_attput, ncid, latvid, "units", "degrees_north" ncdf_attput, ncid, monvid, "units", "months" ncdf_attput, ncid, climid, "units", "W/m^2" ncdf_attput, ncid, lonvid, "modulo", " " ncdf_attput, ncid, monvid, "modulo", " " ncdf_attput, ncid, lonvid, "point_spacing", "even" ncdf_attput, ncid, latvid, "point_spacing", "uneven" ncdf_attput, ncid, monvid, "point_spacing", "even" ncdf_attput, ncid, /global, "title", "CSIRO model run " + run + $ ": climatological monthly Q-fluxes" ; Exit define mode ncdf_control, ncid, /endef ; Write data ncdf_varput, ncid, lonvid, lons ncdf_varput, ncid, latvid, lats ncdf_varput, ncid, monvid, indgen(12) + 1 ncdf_varput, ncid, climid, occur_out ; Close netCDF file ncdf_close, ncid end