Silverfrost Forums

Welcome to our forums

CMNAM PROBLEM

26 Apr 2008 10:03 #3084

Dera users

I precompiled sample program form Plato which is attached to explain using form of CMNAM function. The problem is that CMNAM see external tocken (after compilation like FTN95 COPY.F95 /LINK /PARAMS I obtained COPY.EXE and run it like copy.exe abc.txt. When the program is run he always skips to the 201 label. In the code there isn't seen L logical variable as a .TRUE. When I force it and manualy wirte L=.TRUE. it shows me 'File to be written already exists OK to overwrite? (y/n)' but after pushing Y or y he skips to also to 201 label. Why isn't there seen IF (L) THEN...It seems that it can't see that L is .TREU. It is very importan to me ? Can you help me ?

PROGRAM COPY_FILE
CHARACTER (LEN=20)::CMNAM,FILE2
CHARACTER (LEN=128)::DATA
INTEGER*2  K
LOGICAL::L

OPEN(UNIT=3,FILE=CMNAM(),STATUS='MODIFY',ERR=200)
FILE2=CMNAM()
INQUIRE(FILE=FILE2,EXIST=L)
IF (L) THEN
PRINT *,'********************************************************'
PRINT *,'File to be written already exists OK to overwrite? (y/n)'
PRINT *,'********************************************************'

CALL GET_KEY@(K)
IF((K /= 89).AND.(K /= 121)) STOP
PRINT*,'Y'
ENDIF
OPEN(UNIT=4,FILE=FILE2,STATUS='MODIFY',ERR=210)
DO
READ (3,'(A)',END=220) DATA
WRITE(4,'(A)')         DATA
END DO

200 PRINT ,'' PRINT *,'File to be read does not exist' PRINT ,'' STOP 210 PRINT ,'*' PRINT ,'File to be written can not be created' PRINT ,'' 220 END PROGRAM COPY_FILE

26 Apr 2008 2:19 #3085

It looks like the trailing spaces are causing a problem. One approach is to use something like the following...

PROGRAM COPY_FILE 
CHARACTER (LEN=20)::CMNAM,FILE2 
CHARACTER (LEN=128)::DATA 
INTEGER*2 K 
LOGICAL::L 
FILE2=CMNAM() 
OPEN(UNIT=3,FILE=FILE2(1:LEN(FILE2)),STATUS='MODIFY',ERR=200) 
INQUIRE(FILE=FILE2(1:LEN(FILE2)),EXIST=L) 
IF (L) THEN 
PRINT *,'********************************************************' 
PRINT *,'File to be written already exists OK to overwrite? (y/n)' 
PRINT *,'********************************************************' 

CALL GET_KEY@(K) 
IF((K /= 89).AND.(K /= 121)) STOP 
PRINT*,'Y' 
ENDIF 
OPEN(UNIT=4,FILE=FILE2(1:LEN(FILE2)),STATUS='MODIFY',ERR=210) 
DO 
READ (3,'(A)',END=220) DATA 
WRITE(4,'(A)') DATA 
END DO 
200 PRINT *,'******************************' 
PRINT *,'File to be read does not exist' 
PRINT *,'******************************' 
STOP 
210 PRINT *,'*************************************' 
PRINT *,'File to be written can not be created' 
PRINT *,'*************************************' 
220 END PROGRAM COPY_FILE
Please login to reply.