Silverfrost Forums

Welcome to our forums

Case distinction, file creation and modification

23 Nov 2011 9:18 #9270

Hello guys,

I would like to check if a file exists, if it is the right calculation case. If it does not exist, it is created und results are stored in there. This didnt work correctly, at least not when the file already exists. Here is the code, I hope someone can help me:

      fexist = .FALSE.
      fright = .FALSE.
      fscat = .TRUE.
      
      IF (fscat) THEN
        INQUIRE (FILE = 'mie_scat_int.asc', EXIST=fexist)
        IF (fexist) THEN
          WRITE(*,*) 'mie_scat_int.asc already exists'
          OPEN(20, FILE = 'mie_scat_int.asc', STATUS = 'UNKNOWN')
          READ (20,*) dummy1
          READ (20,*) dummy2
          READ (20,*) dummy3
          CLOSE (UNIT=20)
          IF ((dummy1==alfamax).AND.(dummy2==alfares).AND.(dummy3==nn)) THEN
            fright = .TRUE. 
            WRITE(*,*) 'mie file fits the present analysis'
          ELSE
            fright = .FALSE.
          END IF 
        ENDIF
       
        IF (fexist.AND.fright) THEN
          WRITE (*,*) 'mie_scat_int.asc is read'
          OPEN(20, FILE = 'mie_scat_int.asc', STATUS = 'UNKNOWN')
          READ (20,*) dummy1
          READ (20,*) dummy2
          READ (20,*) dummy3
          DO jj = 1,alfares
            DO ii = 1,nn
               READ (20,*) alfa(ii,jj), theta(ii), i1(ii,jj)
            END DO
          END DO
          CLOSE (UNIT=20)
        ELSE
          WRITE (*,*) 'mie_scat_int.asc is created'
          OPEN(20, FILE = 'mie_scat_int.asc', STATUS = 'UNKNOWN')
          WRITE (20,*) alfamax
          WRITE (20,*) alfares
          WRITE (20,*) nn
          DO ii = 1, nn
             theta(ii) = (ii-1)*dang 
          END DO
23 Nov 2011 5:40 #9281

Your INQUIRE implies, that your FTN95 exe is executed from within the directory of the .asc file. Otherwise add the complete path, best like 'd:\...\mie_scat_int.asc'

24 Nov 2011 12:56 #9283

Miriam,

I'd recommend that you include IOSTAT=error_code in each I/O statement and manage any non-zero error reports.

Another problem could be your access rights, as you may only have read access. This might be tested by including ACTION='READ' or STATUS='READONLY'.

Only a minor point, use a character variable to store the file name. This can make the code more robust.

You have gone through a range of testing the file accessibility. I'd review the order so you can report the likely access states that could exist.

Having just started to use Windows 7, I'm learning how to access files, in restricted areas. Previously I stored configuration files, like sdbg.ini, in c:\windows or c:\ but am now finding these files have restricted access. I am looking for a more robust approach for these files in Windows 7.

John

Please login to reply.