program generate_sstcor ! Purpose ! ------- ! Generates the auxiliary files sstcor.nc and dtm.nc for the new, ! high-resolution version of the Mk3L coupled model. ! ! These files contain the SST adjustments [SSTCOR] and the climatological ! mixed-layer ocean temperature anomalies [DTM]. ! ! Note that this program requires the following data to be provided: ! ! - Climatological SSTs for the start of each month, as used to force the AGCM ! - Climatological monthly-mean mixed-layer ocean temperature anomalies, as ! diagnosed from an AGCM spin-up run ! - Climatological SSTs for the start of each month, as diagnosed from an OGCM ! spin-up run and interpolated onto the AGCM grid; these can be generated ! using the program sst_start_128_112.f90 ! ! Note also that this program assumes that all the climatological data for the ! AGCM and OGCM is provided at 32-bit precision, but that the climatological ! SSTs used to force the AGCM are provided at 64-bit precision. ! ! Usage ! ----- ! ./generate_sstcor ! ! ! where: ! ! agcm_file file containing climatological SSTs used to force the AGCM ! agcm_var variable containing climatological SSTs used to force the AGCM ! lon_var variable containing longitude data for the AGCM ! lat_var variable containing latitude data for the AGCM ! dtm_file file containing climatological MLO delta-T for the AGCM ! dtm_var variable containing climatological MLO delta-T for the AGCM ! ogcm_file file containing climatological SSTs for the OGCM ! ogcm_var variable containing climatological SSTs for the OGCM ! ! History ! ------- ! 2008 Feb 23 Steven Phipps Original version implicit none include 'netcdf.inc' ! Define local parameters integer, parameter :: nx = 64, & ny = 56 ! Declare local variables character(len=80) :: agcm_file, agcm_var, dtm_file, dtm_var, lat_var, & lon_var, ogcm_file, ogcm_var, title character(len=160) :: history integer :: datid, latdid, latvid, londid, lonvid, mondid, month, monthm1, & monvid, ncid, status real(kind=4), dimension(nx) :: lon real(kind=4), dimension(ny) :: lat real(kind=4), dimension(nx, ny, 12) :: dtm, ogcm real, dimension(nx, ny, 12) :: clim, dt, dtm_start ! Get command-line arguments call getarg(1, agcm_file) call getarg(2, agcm_var) call getarg(3, lon_var) call getarg(4, lat_var) call getarg(5, dtm_file) call getarg(6, dtm_var) call getarg(7, ogcm_file) call getarg(8, ogcm_var) ! Get the climatological SSTs used to force the AGCM, as well as the ! longitude and latitude data status = nf_open(trim(agcm_file), nf_nowrite, ncid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_inq_varid(ncid, trim(lon_var), lonvid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_inq_varid(ncid, trim(lat_var), latvid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_inq_varid(ncid, trim(agcm_var), datid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_get_var_real(ncid, lonvid, lon) if (status /= nf_noerr) stop "*** netCDF error" status = nf_get_var_real(ncid, latvid, lat) if (status /= nf_noerr) stop "*** netCDF error" status = nf_get_var_double(ncid, datid, clim) if (status /= nf_noerr) stop "*** netCDF error" status = nf_close(ncid) if (status /= nf_noerr) stop "*** netCDF error" ! Get the climatological mixed-layer ocean temperature anomalies status = nf_open(trim(dtm_file), nf_nowrite, ncid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_inq_varid(ncid, trim(dtm_var), datid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_get_var_real(ncid, datid, dtm) if (status /= nf_noerr) stop "*** netCDF error" status = nf_close(ncid) if (status /= nf_noerr) stop "*** netCDF error" ! Get the climatological OGCM SSTs for the start of each month status = nf_open(trim(ogcm_file), nf_nowrite, ncid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_inq_varid(ncid, trim(ogcm_var), datid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_get_var_real(ncid, datid, ogcm) if (status /= nf_noerr) stop "*** netCDF error" status = nf_close(ncid) if (status /= nf_noerr) stop "*** netCDF error" ! Average the climatological mixed-layer ocean temperature anomalies for ! consecutive months, in order to obtain best estimates of the climatological ! values for the start of each month do month = 1, 12 monthm1 = month - 1 if (month == 1) monthm1 = 12 dtm_start(:, :, month) = 0.5 * (dtm(:, :, monthm1) + dtm(:, :, month)) end do ! Derive the SST adjustments dt = clim + dtm_start - ogcm ! Get title and history data for the auxiliary file sstcor.nc write (*, *) write (*, *) "Please enter the title and history for the file sstcor.nc :" write (*, *) write (*, '(a)', advance='no') "Title : " read (*, '(a)') title write (*, '(a)', advance='no') "History : " read (*, '(a)') history ! Generate the auxiliary file sstcor.nc ! ! (1) Create netCDF file status = nf_create("sstcor.nc", nf_noclobber, ncid) if (status /= nf_noerr) stop "*** netCDF error" ! (2) Define dimensions status = nf_def_dim(ncid, "longitude", nx, londid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_def_dim(ncid, "latitude", ny, latdid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_def_dim(ncid, "month", 12, mondid) if (status /= nf_noerr) stop "*** netCDF error" ! (3) Define variables status = nf_def_var(ncid, "longitude", nf_float, 1, londid, lonvid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_def_var(ncid, "latitude", nf_float, 1, latdid, latvid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_def_var(ncid, "month", nf_int, 1, mondid, monvid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_def_var(ncid, "sstcor", nf_double, 3, & (/ londid, latdid, mondid /), datid) if (status /= nf_noerr) stop "*** netCDF error" ! (4) Create attributes status = nf_put_att_text(ncid, lonvid, "units", 12, "degrees_east") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, latvid, "units", 13, "degrees_north") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, monvid, "units", 6, "months") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, lonvid, "modulo", 1, " ") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, monvid, "modulo", 1, " ") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, lonvid, "point_spacing", 4, "even") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, latvid, "point_spacing", 6, "uneven") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, monvid, "point_spacing", 4, "even") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, nf_global, "title", len(trim(title)), & trim(title)) if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, nf_global, "history", len(trim(history)), & trim(history)) if (status /= nf_noerr) stop "*** netCDF error" ! (5) Exit define mode status = nf_enddef(ncid) if (status /= nf_noerr) stop "*** netCDF error" ! (6) Write data status = nf_put_var_real(ncid, lonvid, lon) if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_var_real(ncid, latvid, lat) if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_var_int(ncid, monvid, (/ 1, 2, 3, 4, 5, 6, & 7, 8, 9, 10, 11, 12 /)) if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_var_double(ncid, datid, dt) if (status /= nf_noerr) stop "*** netCDF error" ! (7) Close netCDF file status = nf_close(ncid) if (status /= nf_noerr) stop "*** netCDF error" ! Get title and history data for the auxiliary file dtm.nc write (*, *) write (*, *) "Please enter the title and history for the file dtm.nc :" write (*, *) write (*, '(a)', advance='no') "Title : " read (*, '(a)') title write (*, '(a)', advance='no') "History : " read (*, '(a)') history ! Generate the auxiliary file dtm.nc ! ! (1) Create netCDF file status = nf_create("dtm.nc", nf_noclobber, ncid) if (status /= nf_noerr) stop "*** netCDF error" ! (2) Define dimensions status = nf_def_dim(ncid, "longitude", nx, londid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_def_dim(ncid, "latitude", ny, latdid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_def_dim(ncid, "month", 12, mondid) if (status /= nf_noerr) stop "*** netCDF error" ! (3) Define variables status = nf_def_var(ncid, "longitude", nf_float, 1, londid, lonvid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_def_var(ncid, "latitude", nf_float, 1, latdid, latvid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_def_var(ncid, "month", nf_int, 1, mondid, monvid) if (status /= nf_noerr) stop "*** netCDF error" status = nf_def_var(ncid, "dtm", nf_double, 3, & (/ londid, latdid, mondid /), datid) if (status /= nf_noerr) stop "*** netCDF error" ! (4) Create attributes status = nf_put_att_text(ncid, lonvid, "units", 12, "degrees_east") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, latvid, "units", 13, "degrees_north") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, monvid, "units", 6, "months") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, lonvid, "modulo", 1, " ") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, monvid, "modulo", 1, " ") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, lonvid, "point_spacing", 4, "even") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, latvid, "point_spacing", 6, "uneven") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, monvid, "point_spacing", 4, "even") if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, nf_global, "title", len(trim(title)), & trim(title)) if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_att_text(ncid, nf_global, "history", len(trim(history)), & trim(history)) if (status /= nf_noerr) stop "*** netCDF error" ! (5) Exit define mode status = nf_enddef(ncid) if (status /= nf_noerr) stop "*** netCDF error" ! (6) Write data status = nf_put_var_real(ncid, lonvid, lon) if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_var_real(ncid, latvid, lat) if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_var_int(ncid, monvid, (/ 1, 2, 3, 4, 5, 6, & 7, 8, 9, 10, 11, 12 /)) if (status /= nf_noerr) stop "*** netCDF error" status = nf_put_var_double(ncid, datid, dtm_start) if (status /= nf_noerr) stop "*** netCDF error" ! (7) Close netCDF file status = nf_close(ncid) if (status /= nf_noerr) stop "*** netCDF error" end program generate_sstcor