f_c_string Subroutine

private subroutine f_c_string(fs, cs)

Note

Converts a Fortran string to a C string

A From a memory viewpoint, a C string is like a character vector ending with a C_NULL_CHAR, so the characters are copied one by one in a C_CHAR vector that ends with a C_NULL_CHAR

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fs

fortran string

character(kind=C_CHAR, len=1), intent(out), dimension(:) :: cs

resulting C string


Called by

proc~~f_c_string~~CalledByGraph proc~f_c_string f_c_string proc~scal2surf scal2surf proc~scal2surf->proc~f_c_string proc~write_surf write_surf proc~write_surf->proc~scal2surf program~test_surfile test_surfile program~test_surfile->proc~scal2surf program~test_surfile->proc~write_surf

Source Code

   subroutine f_c_string(fs, cs)
   implicit none
   character(len=*), intent(in) :: fs                       !! *fortran string*
   character(kind=C_CHAR), dimension(:), intent(out) :: cs  !! *resulting C string*

      integer(kind=I4) :: i, ufs

      ufs = len_trim(fs)   ! longueur de la chaîne fortran sans les null, les blancs, ...
      if (ufs==0) then     ! si la chaîne est vide
         cs(1) = C_NULL_CHAR
      else
         do i = 1, ufs
            cs(i) = fs(i:i)
         enddo
         if (ufs<size(cs)) cs(ufs+1) = C_NULL_CHAR ! si la fin du vecteur n'est pas atteinte
      endif

   return
   endsubroutine f_c_string