Prev: Random_number
Next: UF file reading by Fortran
From: SteveF on 11 Feb 2010 23:58 A Fortran program that used to work now gives an error when opening a file. The error is inconsistent in that it stops at different times for different runs. This program is run by many employees at work, on many different PCs, and it only recently started crashing only on two machines, which have been upgraded by "IT". I have tried four different compilers, running in 'debug' mode, and they all produce OPEN errors when attempting to open a file that has been deleted. Here is the source code: C ********************************************************************** PROGRAM TSTFILE IMPLICIT REAL*8(A-H,O-Z) C PARAMETER (N= 200) DIMENSION A(N,N) C UMB=DFLOAT(N*N) M=0 X=.87654321D0 5 Y=0.D0 Z=0.D0 DO 11 I=1,N DO 10 J=1,N X=X*997.D0 X=X-DINT(X) A(I,J)=X Y=Y+X Z=Z+X*X 10 CONTINUE 11 CONTINUE AVG=Y/UMB RMS=DSQRT(Z/UMB-AVG*AVG) M=M+1 WRITE(6,12)M,AVG,RMS 12 FORMAT(/' ITER NO.',I9,' AVG,RMS=',2E18.9) CALL OPENEW(18) WRITE(18)N DO 15 J=1,N WRITE(18)(A(I,J),I=1,N) 15 CONTINUE CLOSE(18) CALL OPEOLD(18) READ(18)I IF (I.NE.N) STOP 'ERROR ABORT' DO 18 J=1,N READ(18)(A(I,J),I=1,N) 18 CONTINUE CLOSE(18) Y=0.D0 Z=0.D0 DO 21 I=1,N DO 20 J=1,N X=A(I,J) Y=Y+X Z=Z+X*X 20 CONTINUE 21 CONTINUE AV1=Y/UMB RM1=DSQRT(Z/UMB-AVG*AVG) WRITE(6,22)AV1,RM1 22 FORMAT(' AFTER READING DATA AVG,RMS=',2E18.9) IF (AV1.NE.AVG .OR. RM1.NE.RMS) * WRITE(6,23)DABS(AVG-AV1),DABS(RMS-RM1) 23 FORMAT(' ERROR: DIFFERENCES =',2E18.9) X=A(N/2,N/2) IF (M.LT.1000) GO TO 5 C STOP END C C SUBROUTINE OPENEW(IUNIT) C LOGICAL FXIST CHARACTER*8 FNAM C DATA FNAM/'FORT.018'/ C 1 INQUIRE(FILE=FNAM,EXIST=FXIST) IF (FXIST) THEN WRITE(6,'('' DELETE EXISTING FILE'')') OPEN(IUNIT,FILE=FNAM,FORM='UNFORMATTED',STATUS='OLD', * ACCESS='SEQUENTIAL') CLOSE(IUNIT,STATUS='DELETE',ERR=50,IOSTAT=K) GO TO 1 END IF WRITE(6,'('' OPEN NEW FILE'')') OPEN(IUNIT,FILE=FNAM,FORM='UNFORMATTED',STATUS='NEW', * ACCESS='SEQUENTIAL',ERR=50,IOSTAT=K) RETURN C 50 WRITE(6,51)K 51 FORMAT(' ERROR OPENING NEW FILE. CODE=',I6) STOP C END C C SUBROUTINE OPEOLD(IUNIT) C LOGICAL FXIST CHARACTER*8 FNAM C DATA FNAM/'FORT.018'/ C INQUIRE(UNIT=IUNIT,OPENED=FXIST) IF (FXIST) THEN K=-5 GO TO 50 END IF INQUIRE(FILE=FNAM,EXIST=FXIST) IF (.NOT.FXIST) THEN K=-10 GO TO 50 END IF OPEN(IUNIT,FILE=FNAM,FORM='UNFORMATTED',STATUS='OLD', * ACCESS='SEQUENTIAL',ERR=50,IOSTAT=K) RETURN C 50 WRITE(6,51)K 51 FORMAT(' ERROR OPENING OLD FILE. CODE=',I6) STOP C END C ********************************************************************** This program is just a big loop that iterates for 1000 times, opening and closing the same unit number and same file name at each iteration. When this program is run on almost any PC, Here is the beginning and ending portion of the output: C ********************************************************************** ITER NO. 1 AVG,RMS= 0.500417743E+00 0.289480862E+00 OPEN NEW FILE AFTER READING DATA AVG,RMS= 0.500417743E+00 0.289480862E+00 ITER NO. 2 AVG,RMS= 0.496925439E+00 0.289664551E+00 DELETE EXISTING FILE OPEN NEW FILE AFTER READING DATA AVG,RMS= 0.496925439E+00 0.289664551E+00 .. .. .. ITER NO. 999 AVG,RMS= 0.500234166E+00 0.289335165E+00 DELETE EXISTING FILE OPEN NEW FILE AFTER READING DATA AVG,RMS= 0.500234166E+00 0.289335165E+00 ITER NO. 1000 AVG,RMS= 0.496594096E+00 0.288361712E+00 DELETE EXISTING FILE OPEN NEW FILE AFTER READING DATA AVG,RMS= 0.496594096E+00 0.288361712E+00 C ********************************************************************** Now, when compiled with Intel Visual Fortran, Version 11, here is the beginning and ending part of the output: C ********************************************************************** ITER NO. 1 AVG,RMS= 0.500417743E+00 0.289480862E+00 OPEN NEW FILE AFTER READING DATA AVG,RMS= 0.500417743E+00 0.289480862E+00 .. .. .. ITER NO. 281 AVG,RMS= 0.501976899E+00 0.287597412E+00 DELETE EXISTING FILE OPEN NEW FILE AFTER READING DATA AVG,RMS= 0.501976899E+00 0.287597412E+00 ITER NO. 282 AVG,RMS= 0.501186971E+00 0.287591033E+00 DELETE EXISTING FILE ERROR OPENING NEW FILE. CODE= 28 C ********************************************************************** Here is the output from the executable made with the Compaq Visual Fortran compiler: C ********************************************************************** ITER NO. 1 AVG,RMS= 0.500417743E+00 0.289480862E+00 OPEN NEW FILE AFTER READING DATA AVG,RMS= 0.500417743E+00 0.289480862E+00 .. .. .. ITER NO. 577 AVG,RMS= 0.501084552E+00 0.289886200E+00 DELETE EXISTING FILE OPEN NEW FILE AFTER READING DATA AVG,RMS= 0.501084552E+00 0.289886200E+00 ITER NO. 578 AVG,RMS= 0.499086233E+00 0.288576170E+00 DELETE EXISTING FILE ERROR OPENING NEW FILE. CODE= 28 C ********************************************************************** Here is the output using Watcom Fortran 77 compiler: C ********************************************************************** ITER NO. 1 AVG,RMS= 0.500417743E+00 0.289480862E+00 OPEN NEW FILE AFTER READING DATA AVG,RMS= 0.500417743E+00 0.289480862E+00 .. .. .. ITER NO. 242 AVG,RMS= 0.499756402E+00 0.287849676E+00 DELETE EXISTING FILE OPEN NEW FILE AFTER READING DATA AVG,RMS= 0.499756402E+00 0.287849676E+00 ITER NO. 243 AVG,RMS= 0.499474364E+00 0.288877650E+00 DELETE EXISTING FILE ERROR OPENING NEW FILE. CODE= 9 C ********************************************************************** Finally, this is the output using MicroSoft Fortran: C ********************************************************************** ITER NO. 1 AVG,RMS= .498889643E+00 .288239971E+00 OPEN NEW FILE AFTER READING DATA AVG,RMS= .498889643E+00 .288239971E+00 .. .. .. ITER NO. 290 AVG,RMS= .501952775E+00 .288412585E+00 DELETE EXISTING FILE OPEN NEW FILE AFTER READING DATA AVG,RMS= .501952775E+00 .288412585E+00 ITER NO. 291 AVG,RMS= .500927379E+00 .288675169E+00 DELETE EXISTING FILE ERROR OPENING NEW FILE. CODE= 6404 Stop - Program terminated. C ********************************************************************** Does anybody have any ideas how to keep the program from failing? Is there some compiler switch or operating system tweak (registry?) that will allow my Fortran program to open the disk file it needs? -- Steve F.
From: glen herrmannsfeldt on 12 Feb 2010 01:05 SteveF <stevefry(a)dslextreme.com> wrote: > A Fortran program that used to work now gives an error when > opening a file. The error is inconsistent in that it stops > at different times for different runs. This program is run > by many employees at work, on many different PCs, and it only > recently started crashing only on two machines, which have been > upgraded by "IT". I have tried four different compilers, > running in 'debug' mode, and they all produce OPEN errors when > attempting to open a file that has been deleted. My guess is that you don't have write (or create) permission for the directory that you are trying to create the file in. Especially as it is consistent among all compilers, it seems more likely a system problem than a Fortran problem. -- glen
From: e p chandler on 12 Feb 2010 02:49 "glen herrmannsfeldt" <gah(a)ugcs.caltech.edu> wrote in message news:hl2r2k$t0b$1(a)naig.caltech.edu... > SteveF <stevefry(a)dslextreme.com> wrote: > >> A Fortran program that used to work now gives an error when >> opening a file. The error is inconsistent in that it stops >> at different times for different runs. This program is run >> by many employees at work, on many different PCs, and it only >> recently started crashing only on two machines, which have been >> upgraded by "IT". I have tried four different compilers, >> running in 'debug' mode, and they all produce OPEN errors when >> attempting to open a file that has been deleted. > > My guess is that you don't have write (or create) permission > for the directory that you are trying to create the file in. > > Especially as it is consistent among all compilers, it seems > more likely a system problem than a Fortran problem. > > -- glen Very strange. I've had problems compiling with old M$ compilers after upgrading a M$ OS - well known DOS extender or OS/2 family app problem. This seems more like you are running out of some resource at the OS level. The only thing that comes to mind is FCBs, which are MS DOS 1.0 file control blocks, but your compiler can't possibly be that old! (Try adding FCBS=8 to CONFIG.NT.) FWIW, your program runs to completion on 32 bit Vista using the most recent MinGW ports of both gfortran and g95. That, of course, does not prove that the program is properly written. Time to read a printed copy of the source listing .... again. ---- e
From: Louis Krupp on 12 Feb 2010 03:34 SteveF wrote: > > A Fortran program that used to work now gives an error when > opening a file. The error is inconsistent in that it stops > at different times for different runs. This program is run > by many employees at work, on many different PCs, and it only > recently started crashing only on two machines, which have been > upgraded by "IT". I have tried four different compilers, > running in 'debug' mode, and they all produce OPEN errors when > attempting to open a file that has been deleted. > > > Here is the source code: <snip> > SUBROUTINE OPENEW(IUNIT) > C > LOGICAL FXIST > CHARACTER*8 FNAM > C > DATA FNAM/'FORT.018'/ > C > 1 INQUIRE(FILE=FNAM,EXIST=FXIST) > IF (FXIST) THEN > WRITE(6,'('' DELETE EXISTING FILE'')') > OPEN(IUNIT,FILE=FNAM,FORM='UNFORMATTED',STATUS='OLD', > * ACCESS='SEQUENTIAL') > CLOSE(IUNIT,STATUS='DELETE',ERR=50,IOSTAT=K) > GO TO 1 > END IF > WRITE(6,'('' OPEN NEW FILE'')') > OPEN(IUNIT,FILE=FNAM,FORM='UNFORMATTED',STATUS='NEW', > * ACCESS='SEQUENTIAL',ERR=50,IOSTAT=K) > RETURN > C > 50 WRITE(6,51)K > 51 FORMAT(' ERROR OPENING NEW FILE. CODE=',I6) > STOP > C > END <snip> I've seen timing problems that leave a file system in a weird state after file operations. I would put a one-second delay (how you do that may be system- and compiler-dependent) after the CLOSE(... 'DELETE' ....), see if that helps, and fine-tune it from there. Louis
From: Phred Phungus on 12 Feb 2010 03:45
SteveF wrote: > > A Fortran program that used to work now gives an error when > opening a file. The error is inconsistent in that it stops > at different times for different runs. This program is run > by many employees at work, on many different PCs, and it only > recently started crashing only on two machines, which have been > upgraded by "IT". I have tried four different compilers, > running in 'debug' mode, and they all produce OPEN errors when > attempting to open a file that has been deleted. It's fixed form. MM has a source converter that might help. Others might contend that the problem is not that it's fixed form, because that used to be good fortran. I would contend to the contrary, claiming that if MM's source converter doesn't work, then the source needs to be re-written to be minimally legible and embracing the last 2 decades of improvements. I think the professor on Gilligan's Island could fix the open problems with his coconut phone. -- fred |