|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Alfred Rogers
Joined: 23 Apr 2007 Posts: 2
|
Posted: Wed May 02, 2007 3:58 pm Post subject: Expansion of TAB character in source |
|
|
I am a new institutional user of SilverFrost who has a large body of statistical subroutines that currently compile and operate successfully in a half dozen compilers on three platforms (Windows/UNIX/Linux). Many of these routines use TAB characters instead of spaces to make the source code more readable. Apparently the FTN95 compiler expands these characters out to 8-character intervals before compiling, resulting in error messages related to exceeding the 72-character limts per line. I have tried using the /WI option with some success, but a few routines get flagged at the 132-character limit.
Is there an option to either alter or suppress the conversion of tabs to spaces or a way to make the /WI option override the 132-character limit?
Thanks. |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Thu May 03, 2007 4:35 am Post subject: |
|
|
Alfred,
How may characters does your tab imply ?
Are there different interpretations for columns 1-6 and 7-72
My understanding is that tabs are intrepreted differently by different editors. I use ED for Windows, where the tab setting can be easily changed.
My advise would be to write a simple code line converter to remove the tabs, as you imply they should be.
( If you write it in FTN95, mak sure you allow the tab character to be read in and not expanded, using the fortran input convention! See READ_TABS@(unitno) in the OPEN statement description )
Good luck.
John |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Thu May 03, 2007 8:09 am Post subject: |
|
|
There are three approaches that I can think of...
a) Editing out the tab characters
b) Using /WIDE on the FTN95 command line
c) Changing from fixed format Fortran to free format Fortran.
None of these provide an easy solution.
a) This would be easy if the tab characters always appeared in the same column (column 1 say). Then you could use a global edit to replace the tabs by the right number of spaces. Plato has an option in the Options dialog to enable you to see the tabs and ^t can be used to find them but there is no option to find and replace ^t with the correct number of space according to the column number. Plato also has an option to replace tabs with spaces but only as you type. Maybe some other editor is better at this.
b) There is no way to change the extra width provided by /WIDE.
c) Sometimes it is a simple matter to change to free format Fortran but you will still be limited to 132 characters. The main difference is the way that line continuation markers are deployed. Try using /FREE on the command line.
Another possibility might be to print the document to a file and to find a way to read it back again. |
|
Back to top |
|
|
Alfred Rogers
Joined: 23 Apr 2007 Posts: 2
|
Posted: Thu May 03, 2007 2:30 pm Post subject: Clarification |
|
|
Let me clarify, as I did not fully explain the situation. There are a mixture of fixed and free formatted source files involved. Some came from an IBM mainframe environment (Fortran 66) and maintain a fixed format. The free-formatted files were developed on VAX and PC platforms (F77) where TABs were permitted but line lengths still constrained to 72 chars. Many of the routines were rewriten in F90 free formats and have TABs embedded within lines as well as leading lines.
The files are distinguished by format using the .f and .f90 file types and I presume that the compiler makes the same distinction. To be sure, I am compiling every source file with the /WI option.
I currently use the MS Visual Studio to edit and develop these routines, which aligns the TAB characters on 4-character boundaries and it does warn when the "tabbed" line length exceeds 132 characters.
My underlying question addresses the rationale for the compiler to simulate the expansion of the TAB characters when a simple substitution of a single space character would suffice? Many other compilers that are also bound by the 72 & 132 character limits do not have this problem with the TAB characters. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Thu May 03, 2007 7:37 pm Post subject: |
|
|
FTN95 is compatible with the orginal FTN77 compiler which goes way back.
My guess is that allowing tabs with a tab size of 8 on input reflects something in the history of the Fortran standard or one of the major dialects. I can check if you like but the main point is that it has been a feature for many years (getting on for 30 years now).
At the moment you cannot change the tab size from the value 8.
It would be a simple matter for us to add an optional tab size to the command line but this would be for the next release. If you need something quickly then you could negotiate a fee via Silverfrost. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Sat May 05, 2007 8:21 am Post subject: |
|
|
For the next release of FTN95 we have increased the /WIDE_SOURCE limit to 1024 characters and applied this to both free and fixed format Fortran. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Sun May 06, 2007 12:42 pm Post subject: |
|
|
My understanding is that TAB formatting of source code is not part of Fortran 90 or 95, and so any handling of TAB characters is an extension, and therefore intrinsically incompatible between compilers.
This seems to me to be a deficiency in the standard(s), since the move away from statement numbers and fixed format towards constructs like DO .. ENDDO rely on indenting to make the source code legible, and TAB formatting is the obvious and logical way to do that! Furthermore, multiple indenting - especially when combined with long variable names - makes the fixed source form very narrow, one quickly requires a wider source form. Even 132 columns becomes narrow quickly.
Since a statement number is essentially an unique "outdent", and "outdenting" is the flavour of the month (I'm using tabs in Internet Explorer, Excel etc etc), and indenting was the way we did it in Elliot Algol 60 some 40 years ago, I suggest that the Fortran Standards Committee did not do their job very well, and that the "giant strides" they took between Fortran77 and 90 were often backwards!
Might something like Michael Metcalf's "convert.f90" program which reformats source code stripping out statement labels etc and progressively indenting the structures be helpful? It isn't to me - I prefer the old 72 column fixed format, I like statement labels, and would like the reverse program to make an unreadable free format source to the sort of Fortran I can understand!
Eddie |
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Sun May 13, 2007 12:57 pm Post subject: Removing tabs |
|
|
Here is a little program, which uses a modified routine posted on the DECUS library about 20 odd years ago. It reads a tab definition file called "tablist.txt" which should contain something like:
6 7 9 11 13 15 17 19 21 23 25 27 29
Regards
Ian
Untab.for
Code: |
character*256 line_in,file_in,file_out,file_bak
integer*4 itab
common/tab_stops/itab(32)
integer*2 error_code
c
c initialise tab stops
itab=10000
open(unit=10,file='tablist.txt',status='old')
read(10,*,end=1000,err=1000)itab
1000 continue
close(unit=10)
print *,'Tab positions set at:'
print 90,itab
90 format(4(8i6/))
call command_line@(file_in)
nline = 0
if(file_in .ne. ' ')then
open(unit=10,file=file_in,status='old')
call read_tabs@(10)
ios = 0
file_out = file_in
call default_extension(file_out,'utb',0)
open(unit=11,file=file_out,status='unknown')
do while (ios .eq. 0)
read(10,100,iostat=ios)line_in
100 format(a)
if(ios .eq. 0)then
call untab(line_in)
ilen = leng(line_in)
nline = nline + 1
if(ilen .gt. 0)then
write(11,100)line_in(:ilen)
else
write(11,100)
endif
endif
enddo
close(unit=10)
close(unit=11)
if(nline .gt. 0)then
c
c if untabing done, then rename files if processed
file_bak = file_in
call default_extension(file_bak,'bak',0)
c
c original file to .bak
call erase@(file_bak,error_code)
call rename@(file_in, file_bak, error_code)
if(error_code .eq. 0)then
c
c success so rename untabbed file to original name
call rename@(file_out, file_in, error_code)
endif
ilen = leng(file_in)
istart = max(1,ilen-30)
print *,nline,' lines processed in file ',
& file_in(istart:ilen)
endif
endif
end
|
It needs the subroutines in the next post.
Last edited by IanLambley on Sun May 13, 2007 1:07 pm; edited 1 time in total |
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Sun May 13, 2007 1:06 pm Post subject: Untab part 2 |
|
|
See also part 3
Code: |
SUBROUTINE UNTAB ( STRING )
C*
C* *******************************
C* *******************************
C* ** **
C* ** UNTAB **
C* ** **
C* *******************************
C* *******************************
C*
C* SUBPROGRAM :
C* REMOVE TABS
C* AUTHOR :
C* ART RAGOSTA
C* MS 207-5
C* AMES RESEARCH CENTER
C* MOFFETT FIELD, CA 94035
C* (415) 694-5578
C*
C* PURPOSE :
C* REPLACE A STRING WITH THE SAME STRING WHERE TABS ARE
C* REPLACED BY AN APPROPRIATE NUMBER OF BLANKS TO HAVE
C* SIMILAR SPACING.
C*
C* INPUT ARGUMENTS :
C* STRING - STRING FROM WHICH TABS ARE TO BE REMOVED
C*
C* OUTPUT ARGUMENTS :
C* STRING - SAME STRING WITH BLANKS REPLACING TABS(INPLACE)
C*
C* INTERNAL WORK AREAS :
C* ITAB - AN ARRAY CONTAINING THE TAB STOP SETTINGS.
C* LINE - TEMPORARY STORAGE FOR TABBED STRING.
C*
C* COMMON BLOCKS :
C* NONE
C*
C* FILE REFERENCES :
C* NONE
C*
C* DATA BASE ACCESS :
C* NONE
C*
C* SUBPROGRAM REFERENCES :
C* NONE
C*
C* ERROR PROCESSING :
C* NONE
C*
C* TRANSPORTABILITY LIMITATIONS :
C* THE NON-STANDARD DATA STATEMENT SETS TAB CHARACTER TO ASCII 9.
C* ( TRANSPORTABLE VERSION IS COMMENTED )
C*
C* ASSUMPTIONS AND RESTRICTIONS :
C* NONE
C*
C* LANGUAGE AND COMPILER :
C* ANSI FORTRAN 77
C*
C* VERSION AND DATE :
C* VERSION I.1 29-july-1985
C*
C* CHANGE HISTORY :
C* 29-JUL-85 ITPTR FIXED (INITIALIZED)
C* 15-OCT-84 INITIAL VERSION
C*
C***********************************************************************
C*
CHARACTER *(*) STRING
CHARACTER *256 LINE
CHARACTER *1 TAB
integer*4 itab
common/tab_stops/itab(32)
c old DIMENSION ITAB(32)
c old DATA ITAB / 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 98, 106,
c old $ 114, 122, 130, 138, 146, 154, 162, 170, 178, 186, 195, 203,
c old $ 211, 219, 227, 235, 243, 251, 10000 /
C
C --- NON-STANDARD DATA STATEMENT :
C
c DATA TAB/9/
C
C --- STANDARD REPLACEMENT FOR ABOVE DATA STATEMENT :
TAB = CHAR ( 9 )
C
LINE = STRING
STRING = ' '
L = LENG(LINE)
LL = LEN(STRING)
K = 1
ITPTR = 1
DO 20 I = 1,L
IF ( LINE(I:I) .EQ. TAB ) THEN
C
C ------ FIND NEXT TAB STOP
C
5 IF ( K .GE. ITAB(ITPTR)) THEN
ITPTR = ITPTR + 1
GO TO 5
ENDIF
C
C ------ SKIP BLANKS TO TAB STOP ( ALREADY BEEN INITIALIZED TO BLANKS )
C
10 IF ( K .LT. ITAB(ITPTR)) THEN
K = K + 1
GO TO 10
ENDIF
ELSE
C
C ------ COPY NON-TAB CHARACTERS
C
STRING(K:K) = LINE(I:I)
K = K + 1
ENDIF
IF ( K .GT. LL ) RETURN
20 CONTINUE
RETURN
END
C
C---END UNTAB
C |
|
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Sun May 13, 2007 1:08 pm Post subject: Untab part 3 |
|
|
Code: |
subroutine default_extension(filnam,ext,iwhen)
character*(*) filnam,ext
c
c iwhen specifies when to put the default extension on
c 0 = always
c 1 = when no 'dot ext' exsists
c
c now reset the file extension to default
c first skip the directory [] brackets
ibracket = max(1,index(filnam,']'))
ilen_name = leng(filnam)
idot = 0
do 10 ii=ibracket+1,ilen_name
if(filnam(ii:ii) .eq. '.')then
idot = ii
goto 456
endif
10 continue
456 continue
c
c set the position of the dot if it exists else set it to be after
c the end of the file name
jdot = idot
if(idot .eq. 0)then
jdot = ilen_name+1
endif
c
c append extension as desired
if(iwhen .eq. 1)then
c only if one not found
if(idot .eq. 0)filnam(jdot:)='.'//ext
else
c
c always
filnam(jdot:)='.'//ext
endif
return
end
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|