aschaeffer
Programmer
Hi,
I've attached a small program extracted from a large program I'm trying to compile in Linux 64 (Ubuntu 9.10). Basically it is a wrapper function to open a file where a directory prefix is automatically added. This is legacy code from an old project (with thousands of lines). When a quoted string is passed to the subroutine, additional text is added to the variable. However, when passed as a string in a variable, this does not occur. Is passing a quoted string in this manner (Test 1 below) not a legal manner in fortran 77? The program, the compiler instruction, and the output I get is in the comments at the end. Thanks for any help, Andrew.
------------------------------------------------------------
C Output from Public domain Ratfor, version 1.01
program ami3d
character*100 testfile
print *,' Test 1:'
print *, ' Testing openfile for quoted string'
print *,kar('testfile123')
call openfile(12,'testfile123')
print *,' '
print *,' Test 2:'
print *,' Testing openfile for passed variable'
testfile="testfile123"
print *,kar(testfile)
call openfile(12,testfile)
end
function kar(string)
character*100 string
kk=100
ii=ichar(string(kk:kk))
800 if((ii.gt.126 .or. ii.lt.33) .and. kk.gt.1)then
kk=kk-1
ii=ichar(string(kk:kk))
goto 800
endif
801 continue
kar=kk
return
end
subroutine openfile(nfile,fname)
! common /opname/ fitdir
character*100 fitdir, fname
write(6,'(a,a,a)') '-',fname(1:kar(fname)),'-'
! open(nfile,file=fitdir(1:kar(fitdir))//fname(1:kar(fname)))
return
end
! compile line:
![aschaeff@triton aschaeff]$ gfortran -std=legacy testfilename.f -o amitest
!
! The output from running this program
![aschaeff@triton aschaeff]$ amitest
! Test 1:
! Testing openfile for quoted string
! 74
!-testfile123
! Test 2: Testing openfile for passed variable(a,a,a)--
!
! Test 2:
! Testing openfile for passed variable
! 11
!-testfile123-
![aschaeff@triton aschaeff]$
I've attached a small program extracted from a large program I'm trying to compile in Linux 64 (Ubuntu 9.10). Basically it is a wrapper function to open a file where a directory prefix is automatically added. This is legacy code from an old project (with thousands of lines). When a quoted string is passed to the subroutine, additional text is added to the variable. However, when passed as a string in a variable, this does not occur. Is passing a quoted string in this manner (Test 1 below) not a legal manner in fortran 77? The program, the compiler instruction, and the output I get is in the comments at the end. Thanks for any help, Andrew.
------------------------------------------------------------
C Output from Public domain Ratfor, version 1.01
program ami3d
character*100 testfile
print *,' Test 1:'
print *, ' Testing openfile for quoted string'
print *,kar('testfile123')
call openfile(12,'testfile123')
print *,' '
print *,' Test 2:'
print *,' Testing openfile for passed variable'
testfile="testfile123"
print *,kar(testfile)
call openfile(12,testfile)
end
function kar(string)
character*100 string
kk=100
ii=ichar(string(kk:kk))
800 if((ii.gt.126 .or. ii.lt.33) .and. kk.gt.1)then
kk=kk-1
ii=ichar(string(kk:kk))
goto 800
endif
801 continue
kar=kk
return
end
subroutine openfile(nfile,fname)
! common /opname/ fitdir
character*100 fitdir, fname
write(6,'(a,a,a)') '-',fname(1:kar(fname)),'-'
! open(nfile,file=fitdir(1:kar(fitdir))//fname(1:kar(fname)))
return
end
! compile line:
![aschaeff@triton aschaeff]$ gfortran -std=legacy testfilename.f -o amitest
!
! The output from running this program
![aschaeff@triton aschaeff]$ amitest
! Test 1:
! Testing openfile for quoted string
! 74
!-testfile123
! Test 2: Testing openfile for passed variable(a,a,a)--
!
! Test 2:
! Testing openfile for passed variable
! 11
!-testfile123-
![aschaeff@triton aschaeff]$