Clicky

Fortran Wiki
notab (Rev #2, changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #1 to #2: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

program testit
! test filter to remove tabs and trailing white space from input
! on files up to 255 characters wide using NOTABS(3f)
 character(len=255) :: in,out
 integer :: ios ! error flag from read
 integer :: iout
 call whichone()
 do
 read(*,"(a)",iostat=ios)in
 if(ios /= 0)then
 stop
 endif
 call notabs(in,out,iout)
 !write(*,"(i3.3,':')",advance="no")len_trim(in)
 !write(*,"(i3.3,':')",advance="no")iout
 if(iout == 0)then
 write(*,"(a)")
 else
 write(*,"(a)")out(1:iout)
 endif
 enddo
end program testit
!===================================================================================================================================
subroutine notabs(INSTR,OUTSTR,ILEN)
! @(#) convert tabs in input to spaces in output while maintaining columns, assuming a tab is set every 8 characters
!
! USES:
! It is often useful to expand tabs in input files to simplify further processing such as tokenizing an input line.
 ! Some FORTRAN compilers hate tabs in(削除) iput (削除ここまで)(追記) input (追記ここまで) files; some printers; some editors will have problems with tabs
! AUTHOR:
! John S. Urban
!
! SEE ALSO:
! GNU/Unix commands expand(1) and unexpand(1)
!
 use ISO_FORTRAN_ENV, only : ERROR_UNIT ! get unit for standard error. if not supported yet, define ERROR_UNIT for your system (typically 0)
 character(len=*),intent(in) :: INSTR ! input line to scan for tab characters
 character(len=*),intent(out) :: OUTSTR ! tab-expanded version of INSTR produced
 integer,intent(out) :: ILEN ! column position of last character put into output string
 integer,parameter :: TABSIZE=8 ! assume a tab stop is set every 8th column
 character(len=1) :: c ! character read from stdin
 integer :: ipos ! position in OUTSTR to put next character of INSTR
 integer :: lenin ! length of input string trimmed of trailing spaces
 integer :: lenout ! number of characters output string can hold
 integer :: i10 ! counter that advances thru input string INSTR one character at a time
!===================================================================================================================================
 IPOS=1 ! where to put next character in output string OUTSTR
 lenin=len(INSTR) ! length of character variable INSTR
 lenin=len_trim(INSTR(1:lenin)) ! length of INSTR trimmed of trailing spaces
 lenout=len(OUTSTR) ! number of characters output string OUTSTR can hold
 OUTSTR=" " ! this SHOULD blank-fill string, a buggy machine required a loop to set all characters
!===================================================================================================================================
 do i10=1,lenin ! look through input string one character at a time
 c=INSTR(i10:i10)
 if(ichar(c) == 9)then ! test if character is a tab (ADE (ASCII Decimal Equivalent) of tab character is 9)
 IPOS = IPOS + (TABSIZE - (mod(IPOS-1,TABSIZE)))
 else ! c is anything else other than a tab insert it in output string
 if(IPOS > lenout)then
 write(ERROR_UNIT,*)"*notabs* output string overflow"
 exit
 else
 OUTSTR(IPOS:IPOS)=c
 IPOS=IPOS+1
 endif
 endif
 enddo
!===================================================================================================================================
 ILEN=len_trim(OUTSTR(:IPOS)) ! trim trailing spaces
 return
!===================================================================================================================================
end subroutine notabs
!===================================================================================================================================

category: code

Revision from December 22, 2015 19:59:19 by John S. Urban
Forward in time (to current) | Back in time (1 more) | See current | Hide changes | History | Rollback | View: Source | Linked from: Code

AltStyle によって変換されたページ (->オリジナル) /