Clicky

Fortran Wiki
notab (changes)

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

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

program testit
 !(削除) test (削除ここまで)(追記) example (追記ここまで)(追記) showing (追記ここまで)(追記) use (追記ここまで)(追記) of (追記ここまで)(追記) NOTABS(3f). (追記ここまで)(追記) Creates (追記ここまで)(追記) a (追記ここまで)(追記) small (追記ここまで) filter(削除) to (削除ここまで)(削除) remove (削除ここまで)(削除) tabs (削除ここまで)(削除) and (削除ここまで)(削除) trailing (削除ここまで)(削除) white (削除ここまで)(削除) space (削除ここまで)(削除) from (削除ここまで)(削除) input (削除ここまで)
 !(削除) on (削除ここまで)(追記) that (追記ここまで)(削除) files (削除ここまで)(追記) removes (追記ここまで)(削除) up (削除ここまで)(追記) tabs (追記ここまで)(削除) to (削除ここまで)(追記) and (追記ここまで)(削除) 255 (削除ここまで)(追記) trailing (追記ここまで)(削除) characters (削除ここまで)(追記) white (追記ここまで)(削除) wide (削除ここまで)(追記) space (追記ここまで)(削除) using (削除ここまで)(追記) from (追記ここまで)(削除) NOTABS(3f) (削除ここまで)(追記) input (追記ここまで)(追記) ! on files up to 255 characters wide. For example (追記ここまで)(追記) 
 (追記ここまで)(追記) ! notabs < infile >outfile (追記ここまで)(追記) 
 (追記ここまで)(追記) !  (追記ここまで)(追記) 
 (追記ここまで)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 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

Revised on December 23, 2015 11:18:15 by John S. Urban (76.125.237.227) (4183 characters / 1.0 pages)
Edit | Back in time (2 revisions) | Hide changes | History | Views: Print | TeX | Source | Linked from: Code

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