c_f_string Subroutine

private subroutine c_f_string(cs, fs, lngth_s)

Note

Converts a C string to a Fortran string

From a memory viewpoint, a C string is like a character vector ending with a C_NULL_CHAR so, as long as it is not found, the characters are copied one by one in a fortran string

Arguments

Type IntentOptional Attributes Name
character(kind=C_CHAR, len=1), intent(in), dimension(:) :: cs

C string

character(len=*), intent(out) :: fs

Fortran string

integer(kind=I4), intent(out) :: lngth_s

resulting Fortran string length


Calls

proc~~c_f_string~~CallsGraph proc~c_f_string c_f_string proc~empty empty proc~c_f_string->proc~empty

Called by

proc~~c_f_string~~CalledByGraph proc~c_f_string c_f_string proc~surf2scal surf2scal proc~surf2scal->proc~c_f_string proc~trans_surf_txt trans_surf_txt proc~trans_surf_txt->proc~c_f_string proc~open_surffile open_surffile proc~open_surffile->proc~surf2scal proc~open_surffile->proc~trans_surf_txt proc~write_surf write_surf proc~write_surf->proc~surf2scal program~test_surfile test_surfile program~test_surfile->proc~trans_surf_txt program~test_surfile->proc~write_surf proc~read_surf~2 read_surf program~test_surfile->proc~read_surf~2 proc~read_surf~2->proc~open_surffile

Source Code

   subroutine c_f_string(cs, fs, lngth_s)
   implicit none
   character(kind=C_CHAR), dimension(:), intent(in) :: cs   !! *C string*
   character(len=*), intent(out) :: fs                      !! *Fortran string*
   integer(kind=I4), intent(out) :: lngth_s                 !! *resulting Fortran string length*

      integer(kind=I4) :: i, ucs

      ucs = size(cs) ! vector length
      lngth_s = ucs  ! resulting string default length
      i = 1
      do
         if (i>ucs) exit
         if (cs(i)==C_NULL_CHAR) then  ! fin de chaîne c rencontrée ; s'il n'y a pas de null_char
            lngth_s = i-1              ! c'est qu'on utilise tout le vecteur
            exit
         endif
         i = i + 1
      enddo

      call empty(fs)

      do i = 1, lngth_s ! the C string is translated into fortran
         fs(i:i) = cs(i)
      enddo

   return
   endsubroutine c_f_string