program read_srb_rel3_qclw_3hrlymonthly_nc use netcdf implicit none character (200) :: path_in, file_in, file_out integer :: rec integer :: month, year character(4) :: cyear character(2) :: cmon ! netCDF id integer :: ncid ! dimension ids integer :: lat_dim, lon_dim, time_dim integer, parameter :: NDIMS = 3, NRECS = 8 integer, parameter :: NLVLS = 1, NLATS = 180, NLONS = 360 character (len = *), parameter :: LAT_NAME = "lat" character (len = *), parameter :: LON_NAME = "lon" character (len = *), parameter :: time_name = "time" ! The start and count arrays will tell the netCDF library where to ! read our data. integer :: start(NDIMS), count(NDIMS) ! In addition to the latitude and longitude dimensions, we will also ! create latitude and longitude variables which will hold the actual ! latitudes and longitudes. Since they hold data about the ! coordinate system, the netCDF term for these is: "coordinate ! variables." real :: lats(NLATS), lons(NLONS) character (len = *), parameter :: sfcdn_name="lw_sfc_dn" character (len = *), parameter :: sfcnet_name="lw_sfc_net" character (len = *), parameter :: csfcdn_name="clr_lw_sfc_dn" ! variable ids integer :: lat_id, lon_id, time_id, & clr_lw_sfc_dn_id, lw_sfc_net_id, lw_sfc_dn_id double precision :: time real, dimension(nlons,nlats) :: clr_lw_sfc_dn, lw_sfc_net, lw_sfc_dn integer :: dimids(NDIMS) ! To check the units attributes. character (80) :: clr_lw_sfc_dn_units_in, & lw_sfc_net_units_in, lw_sfc_dn_units_in character (80) :: lat_units_in, lon_units_in month=2 year=1984 write (cyear,"(i4)") year write (cmon,"(i2.2)") month path_in='' path_in='/SCF2/RADAPP/srb/NetCDF/QCLW/1984/' file_in=trim(path_in)//'srb_rel3.0_qclw_3hrlymonthly_'//cyear//cmon//'.nc' print*,trim(file_in) ! Open the file. call check( nf90_open(file_in, nf90_nowrite, ncid)) ! Get the varids of the latitude and longitude coordinate variables. call check( nf90_inq_varid(ncid, LAT_NAME, lat_id) ) call check( nf90_inq_varid(ncid, LON_NAME, lon_id) ) ! Read the latitude and longitude data. call check( nf90_get_var(ncid, lat_id, lats) ) call check( nf90_get_var(ncid, lon_id, lons) ) ! Read the time information. call check( nf90_inq_varid(ncid, time_name, time_id) ) call check( nf90_get_var(ncid, time_id, time) ) ! Get the varids of the variables call check( nf90_inq_varid(ncid, csfcdn_name, clr_lw_sfc_dn_id) ) call check( nf90_inq_varid(ncid, sfcnet_name, lw_sfc_net_id) ) call check( nf90_inq_varid(ncid, sfcdn_name, lw_sfc_dn_id) ) ! Read the units call check( nf90_get_att(ncid, clr_lw_sfc_dn_id, 'units', clr_lw_sfc_dn_units_in) ) call check( nf90_get_att(ncid, lw_sfc_net_id, 'units', lw_sfc_net_units_in) ) call check( nf90_get_att(ncid, lw_sfc_dn_id, 'units', lw_sfc_dn_units_in) ) count = (/ NLONS, NLATS, 1 /) start = (/ 1, 1, 1 /) do rec = 1, NRECS start(3)=rec ! Read the variables call check( nf90_get_var(ncid, clr_lw_sfc_dn_id, clr_lw_sfc_dn,start=start,& count=count) ) call check( nf90_get_var(ncid, lw_sfc_net_id, lw_sfc_net,start=start,& count=count) ) call check( nf90_get_var(ncid, lw_sfc_dn_id, lw_sfc_dn,start=start,& count=count) ) end do call check( nf90_close(ncid) ) contains !***************************************** subroutine check(status) integer, intent ( in) :: status if(status /= nf90_noerr) then print *, trim(nf90_strerror(status)) stop "Stopped" end if end subroutine check !***************************************** end program read_srb_rel3_qclw_3hrlymonthly_nc