[netcdfgroup] got mistake when reading string from nc file

anyone please help? Thanks!

Main program is like:
     ....
     use netcdf
     use nc_module
     ....
        DO S = 1, 6
             write(111,*)'driver: rj_name(',s,')=',rj_name(s)
       call nc_chk1_rd1(rj_name(s), chk1_rj(:,:,:,s), s, nstep_nreps)
       enddo

nc_chk1_rd1.f90 is:

   subroutine nc_chk1_rd1(nc_data_name, chk1_data, N_ic, nstep_nreps)
    use netcdf
    use nc_module
    implicit none
      character*16 nc_data_name
      integer :: nc_data_varid
      integer :: start1(4), count1(4)
      integer :: N_ic,nstep_nreps
      real :: chk1_data(132, 90, 14,100)
        start1 = (/ 1, 1, 1, nstep_nreps /)
        count1 = (/ 132, 90, 14, 1 /)
             write(111,*)'nc_chk1_rd1: nc_data_name=',nc_data_name
         call nc_check( nf90_inq_varid(chk_ncid, nc_data_name,
nc_data_varid))
         call nc_check( nf90_get_var(chk_ncid, nc_data_varid &
                      , chk1_data(:,:,:,N_ic), start1, count1
))
   endsubroutine nc_chk1_rd1


rj_name is defined in nc_module.f90:
!     character (len=16) :: rj_name(6)
!     data rj_name(1)/'RJ1             '/
!     data rj_name(2)/'RJ2             '/
!     data rj_name(3)/'RJ3             '/
!     data rj_name(4)/'RJ4             '/
!     data rj_name(5)/'RJ5             '/
!     data rj_name(6)/'RJ6             '/
      character(len=16), dimension(6) :: rj_name= (/&
                      'RJ1             ',&
                      'RJ2             ',&
                      'RJ3             ',&
                      'RJ4             ',&
                      'RJ5             ',&
                      'RJ6             '/)



The 111 file shows:
 nc_chk1_rd1: nc_data_name=RJ1
 nc_chk1_rd1: nc_data_name=          RJ2
.....................the program stops here.

What I'm expecting in file 111 is:
nc_chk1_rd1: nc_data_name=RJ1
nc_chk1_rd1: nc_data_name=RJ2
nc_chk1_rd1: nc_data_name=RJ3
nc_chk1_rd1: nc_data_name=RJ4
nc_chk1_rd1: nc_data_name=RJ5
nc_chk1_rd1: nc_data_name=RJ6

Thanks for any advice!
-- 
Cordially,
Hongyan
  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: