Manual Reference Pages  - notabs (3m_strings)

NAME

notabs(3f) - [M_strings:NONALPHA] expand tab characters (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
See Also
Author
License

SYNOPSIS

elemental impure subroutine notabs(instr,outstr,lgth)

    character(len=*),intent=(in)           :: INSTR
    character(len=*),intent=(out),optional :: OUTSTR
    integer,intent=(out),optional          :: lgth

DESCRIPTION

NOTABS(3) converts tabs in INSTR to spaces in OUTSTR while maintaining columns. It assumes a tab is set every 8 characters. Trailing spaces are removed.

In addition, trailing carriage returns and line feeds are removed (they are usually a problem created by going to and from MSWindows).

What are some reasons for removing tab characters from an input line? Some Fortran compilers have problems with tabs, as tabs are not part of the Fortran character set. Some editors and printers will have problems with tabs. It is often useful to expand tabs in input files to simplify further processing such as tokenizing an input line.

OPTIONS

instr Input line to remove tabs from

RETURNS

outstr Output string with tabs expanded. Assumed to be of sufficient length
lgth Significant length of returned string. If greater than len(outstr) truncation has occurred.

EXAMPLES

Sample program:

   program demo_notabs
   use M_strings, only : notabs
   character(len=255)           :: in,out
   character(len=:),allocatable :: string
   character(len=1),parameter   :: t=char(9) ! horizontal tab
   integer                      :: iostat,iout,lun
   call makefile(lun) ! create scratch file
   ! read file and expand tabs
   do
      read(lun,’(A)’,iostat=iostat)in
      if(iostat /= 0) exit
      call notabs(in,out,iout)
      write(*,’(a)’)out(:iout)
   enddo
   string=’one’//t//’two’//t//’three’
   call notabs(string,lgth=iout)
   out=repeat(’ ’,iout)
   call notabs(string,out)
   write(*,*)’[’//string//’]’
   contains
   subroutine makefile(lun)
   integer :: lun
   integer :: i
   character(len=80),parameter  :: fakefile(*)=[character(len=80) :: &
   ’col1’//t//’col2’ ,&
   ’a’//t//’one’     ,&
   ’bb’//t//’two’    ,&
   ’ccc’//t//’three’ ,&
   ’dddd’//t//’four’ ,&
   ’’]
   ! create input file
      open(newunit=lun,status=’scratch’)
      write(lun,’(a)’)(trim(fakefile(i)),i=1,size(fakefile))
      rewind(lun)
   end subroutine makefile
   end program demo_notabs
‘‘‘

SEE ALSO

GNU/Unix commands expand(1) and unexpand(1)

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 notabs (3m_strings) January 10, 2025
Generated by manServer 1.08 from 207c6547-937d-4504-8914-4e2c98472d16 using man macros.