* nccwk-io.f last update 05/27/93 (ccy) * Routines to read/write UWM/COADS 0.5x0.5 degree resolution * weekly data sets. See "ncc-io.f" to read the monthly datasets. * * This package requires NetCDF. * *................................................................... subroutine RDNCCW ( var, idim, jdim, units, . label, filen, iweek ) integer idim, jdim, iweek real var(idim,jdim) character*80 label, filen, units * * This subroutine reads a single week's data from the UWM/COADS * 0.5 x 0.5 degree weekly climatology file. * * On input: * -------- * idim, jdim dimensions (720 x 360) * filen file name (e.g., taux_wkc.nc') * month desired month (jan=1, ..., dec=12) * * On output * --------- * var 720x360 array * label $ delimited title (nice for plotting) * units units. * * NOTES: * * 1) Land value: -1E10 * 2) Grid: * min max delta No. pts * (deg) (deg) (deg) * Longitude 0.25E 359.75E 0.5 720 * Latitude 89.75S 89.75N 0.5 360 * * 3) Questions? Send email to dasilva@gsfc.nasa.gov * *........................................................................ include 'netcdf.inc' integer ncid, varid integer corner(3), edges(3) * Open the file * ------------- ncid = ncopn(filen, NCNOWRIT, iret) * Get variable id * --------------- varid = ncvid(ncid, 'var', iret) * Get title and units attributes * ------------------------------ call ncagtc(ncid, NCGLOBAL, 'title', label, 80, iret) call ncagtc(ncid, varid, 'units', units, 80, iret) * Get the field * ------------- corner(1) = 1 corner(2) = 1 corner(3) = iweek edges(1) = idim edges(2) = jdim edges(3) = 1 call ncvgt(ncid, varid, corner, edges, var, iret) * Close the file * -------------- call ncclos (ncid, iret) return end *.................................................................. subroutine WRNCCW( var, idim, jdim, iweek, . units, label, filen ) * This subroutine creates/appends to a file that holds * 52 fields in our COADS 0.5 by 0.5 resolution. * Land values are saved. include 'netcdf.inc' parameter (nweek = 52) integer iret * netCDF id integer ncid * dimension ids integer ilondim, jlatdim, weekdim * variable ids integer varid, alandid, alat1id, alon1id integer dlonid, dlatid * variable shapes integer dims(3) * corners and edge lengths integer corner(3), edges(3) * data variables real var(idim,jdim) real aland, alat1, alon1, dlon, dlat character*80 label, filen, units * If iweek is 1, create a new file * -------------------------------- * -------------------------------- if ( iweek .eq. 1 ) then * enter define mode ncid = nccre (filen, NCCLOB, iret) * define dimensions ilondim = ncddef(ncid, 'ilon', idim, iret) jlatdim = ncddef(ncid, 'jlat', jdim, iret) weekdim = ncddef(ncid, 'week', nweek, iret) * define variables dims(1) = ilondim dims(2) = jlatdim dims(3) = weekdim varid = ncvdef (ncid, 'var', NCFLOAT, 3, dims, iret) alandid = ncvdef (ncid, 'aland', NCFLOAT, 0, 0, iret) alat1id = ncvdef (ncid, 'alat1', NCFLOAT, 0, 0, iret) alon1id = ncvdef (ncid, 'alon1', NCFLOAT, 0, 0, iret) dlonid = ncvdef (ncid, 'dlon', NCFLOAT, 0, 0, iret) dlatid = ncvdef (ncid, 'dlat', NCFLOAT, 0, 0, iret) * assign attributes call ncaptc(ncid, varid, 'long_name', NCCHAR, 23, . '0.5 by 0.5 degree field', iret) call ncaptc(ncid, varid, 'units', NCCHAR, 80, units, iret) call ncaptc(ncid, alandid, 'long_name', NCCHAR, 10, . 'land value', iret) call ncaptc(ncid, alon1id, 'long_name', NCCHAR, 29, . 'longitude of first grid point', iret) call ncaptc(ncid, alon1id, 'units', NCCHAR, 12, . 'degrees_east', iret) call ncaptc(ncid, alat1id, 'long_name', NCCHAR, 28, . 'latitude of first grid point', iret) call ncaptc(ncid, alat1id, 'units', NCCHAR, 13, . 'degrees_north', iret) call ncaptc(ncid, dlonid, 'long_name', NCCHAR, 34, . 'longitudinal grid point separation', iret) call ncaptc(ncid, dlonid, 'units', NCCHAR, 7, 'degrees', iret) call ncaptc(ncid, dlatid, 'long_name', NCCHAR, 33, . 'latitudinal grid point separation', iret) call ncaptc(ncid, dlatid, 'units', NCCHAR, 7, 'degrees', iret) call ncaptc(ncid, NCGLOBAL, 'title', NCCHAR, 80, label, iret) * leave define mode call ncendf(ncid, iret) * store aland corner(1) = 1 edges(1) = 1 aland = -1e+10 call ncvpt(ncid, alandid, corner, edges, aland, iret) * store alon1 alon1 = 0.25 call ncvpt(ncid, alon1id, corner, edges, alon1, iret) * store alat1 alat1 = -89.75 call ncvpt(ncid, alat1id, corner, edges, alat1, iret) * store dlon dlon = 0.5 call ncvpt(ncid, dlonid, corner, edges, dlon, iret) * store dlat dlat = 0.5 call ncvpt(ncid, dlatid, corner, edges, dlat, iret) * Otherwise open file and get variable info * ----------------------------------------- * ----------------------------------------- else * Open the file * ------------- ncid = ncopn(filen, NCWRITE, iret) * Get variable id's * ----------------- varid = ncvid(ncid, 'var', iret) end if * Always: Write the field * ----------------------- * ----------------------- corner(1) = 1 corner(2) = 1 corner(3) = iweek edges(1) = idim edges(2) = jdim edges(3) = 1 call ncvpt(ncid, varid, corner, edges, var, iret) * Close the file * -------------- call ncclos (ncid, iret) return end