program trypnetcdf use pnetcdf ! Replace nf_ functions with nfmpi_ functions. Huo, 28/08/2016 use module_mpp_land, only: io_id, global_nx, global_ny, my_id, mpp_land_sync,MPP_LAND_PAR_INI, mpp_land_init, getLocalXY implicit none include 'mpif.h' integer :: i, j integer :: ix_tmp, jx_tmp integer :: ierr integer :: xstart, xend, ystart, yend real, ALLOCATABLE, DIMENSION(:,:) :: IVGTYP ! vegetation type character(len=256) :: hrldas_constants_file call MPP_LAND_INIT() ix_tmp = 1600 jx_tmp =1040 call MPP_LAND_PAR_INI(1,ix_tmp,jx_tmp,1) call getLocalXY(ix_tmp,jx_tmp,xstart,ystart,xend,yend) hrldas_constants_file="/HOME/gcess_weigong_1/WORKSPACE/CLDASIN/2008010101.LDASIN_DOMAIN0" ALLOCATE ( IVGTYP (XSTART:XEND,YSTART:YEND) ) ! vegetation type call get_ivgtyp(trim(hrldas_constants_file), xstart, xend, ystart, yend, ivgtyp, "PSFC") call MPI_COMM_RANK(MPI_COMM_WORLD, my_id, ierr) ! Huo, 29/08/2016 if (ierr /= MPI_SUCCESS) stop "MPI_COMM_RANK" if(my_id == 0) then print *, 'xstart = ',xstart,'xend = ',xend,'ystart = ',ystart,'yend = ',yend do i = xstart, xend do j = ystart, yend print *, ivgtyp(i,j) end do end do endif contains subroutine get_ivgtyp(flnm, xstart, xend, ystart, yend, array, varname) implicit none character(len=*), intent(in):: flnm integer , intent(in):: xstart, xend, ystart, yend real, dimension(xstart:xend,ystart:yend), intent(out):: array character(len=*), intent(in):: varname integer(KIND=MPI_OFFSET_KIND),dimension(2) ::startxy, countxy integer :: ierr, ncid, varid startxy=(/xstart,ystart/) countxy=(/xend-xstart+1, yend-ystart+1/) if(my_id == 0) then print *, xstart, xend, ystart, yend endif ierr = nfmpi_open(MPI_COMM_WORLD, trim(flnm), NF_NOWRITE, MPI_INFO_NULL, ncid) if (ierr /= 0) stop "NFMPI_OPEN" ierr = nfmpi_inq_varid(ncid, varname, varid) if (ierr /= 0) stop "NFMPI_INQ_VARID" !ierr = nfmpi_get_vara_int_all(ncid, varid, (/xstart,ystart/), (/xend-xstart+1, yend-ystart+1/), array) ! 06/09/2016, Huo. ierr = nfmpi_get_vara_real_all(ncid, varid, startxy, countxy, array) ! 06/09/2016, Huo. print *, ierr if (ierr /= 0) stop "NFMPI_GET_VARA_INT_ALL" ierr=nfmpi_close(ncid) if (ierr /= 0) stop "NFMPI_CLOSE" end subroutine get_ivgtyp end program trypnetcdf