function pfio_nf90_put_var_string(ncid, varid, string, start, count) result(status)
integer :: status
integer(kind=C_INT), intent(in) :: ncid
integer(kind=C_INT), intent(in) :: varid
character(*), target,intent(in):: string(:)
integer, optional, intent(in) :: start(:)
integer, optional, intent(in) :: count(:)
integer, target, allocatable :: start_(:), count_(:)
integer :: max_len, str_size, k
character(len=:),allocatable, target :: string_C(:)
max_len = len(string(1)) + 1
str_size = size(string)
if (.not. present(start) .or. .not. present(count)) then
allocate(start_(1), count_(1))
start_(1) = 1
count_(1) = str_size
else
start_ = start
count_ = count
endif
allocate(character(len=max_len) :: string_C(str_size))
do k = 1, str_size
string_C(k) = trim(adjustl(string(k)))//c_null_char
enddo
status = c_f_pfio_put_var_string(ncid, varid, c_loc(string_C), max_len, str_size, c_loc(start_), c_loc(count_))
deallocate(start_, count_)
deallocate(string_C)
end function pfio_nf90_put_var_string