ERRSNS subroutine

ERRSNS subroutine

Hi,

Can anyone show me example of using ERRSNS subroutine? I am interested to see scripts assuning there is something wrong in the code and therefore ERRSNS will parse some message.

Thanks in advance,

Akand

10 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

I guess you're asking for more detail than the example provided:

CALL ERRSNS (SYS_ERR=I1, STAT=I2, UNIT=I4)

although, according to the documentation, STAT is useless.

Presumably, you could follow up

CALL ERRSNS (SYS_ERR=I1, io_err=I2, UNIT=I4)

with e.g,

if(io_err /= 0)write(*,*)"errno value:",I1,"on unit:",I4

Portrait de mecej4

The code below replaces the IOSTAT=IERR clause in the example given in the Intel Fortran documentation under "Using the IOSTAT Specifier and Fortran Exit Codes" by a call to ERRSNS. Note, however, that ERRSNS is inherited from VMS Fortran, and ports of ERRSNS to other operating systems and compilers may not contain the same capabilities as the original from VMS Fortran. Therefore, you should not call ERRSNS in new code.

  PROGRAM IOERR
    CHARACTER(LEN=40) :: FILNM
    INTEGER IERR,SYSERR,IOCOND,IUNIT,ISTAT
    INCLUDE 'for_iosdef.for'
    DO I=1,4
      FILNM = ''
      WRITE (6,*)  'Type file name '
      READ (5,*) FILNM
      OPEN (UNIT=1, FILE=FILNM, STATUS='OLD', ERR=100)
      WRITE (6,*) 'Opening file: ', FILNM
!       (process the input file)
      CLOSE (UNIT=1)
      STOP
  100  CALL ERRSNS(IERR,SYSERR,ISTAT,IUNIT,IOCOND)
      IF (IERR .EQ. FOR$IOS_FILNOTFOU) THEN
        WRITE (6,*) 'File: ', FILNM, ' does not exist '
      ELSE IF (IERR .EQ. FOR$IOS_FILNAMSPE) THEN
         WRITE (6,*) 'File: ', FILNM, ' was bad, enter new file name'
      ELSE
        PRINT *, 'Unrecoverable error, code =', IERR
        STOP
      END IF
    END DO
    WRITE (6,*) 'File not found. Locate correct file and run again'
  END PROGRAM

I was wracking my brain trying to remember where ERRSNS came from, so thanks to mecej4 for explaining this.  The ifort version gives partial compatibility with extremely ancient (more than 3 decades ago) versions of DEC Fortran, so it qualifies as a legacy feature which should be avoided, as mecej4 said.  It appears to have showed up as a VMS compatibility feature inherited from the first DVF, which in turn implemented a scheme which had already been outdated for years.

Thanks to TimP and mecej4. The code by mecej4 doesn't work like the following error message observed:

error#6404: This name doesn't have a type, and must have an explicit type. [for I1, I2, I4]. 

error#6503: This keyword is indalid for this intrinsic procedure reference. [UNIT]

etc...

Actually what I want to do is, I want to verify some external code by their running exe file through DO loop in order to see whether the codes are fine.  If there is wrong in any code I just want to pass message that there is an error of the paricular run number. For instance, here is the code to verify number of exe files:

DO = 1, NUMBER_OF_CASE_STUDIES

calling directory of the exe file

! running the exe file

CALL SYSTEM ('./CASE_EXE')

END DO

Here is the problem I am facing: I just want to parse the error message (if in any case study) writing in a text file by the statement CALL SYSTEM ('./CASE_EXE > outputs') but it doesn't work. That's why I thought ERRSNS could be helpful.

Regards,

Akand

I don't see justification for your expection that ERRSNS could catch errors thrown by an application running outside your program in a shell started by SYSTEM, particularly when you don't use SYSTEM or SYSTEMQQ in accordance with the ifort (or DVF) instructions.  Those instructions tell you how to capture an error code passed to the environment by the command you ran in the new shell.

Hi TimP,

Thanks. You are right. After doing some investigation on ERRSNS I realized this should not work for an external code. Now, when I tried to use SYSTEMQQ it looks the SYSTEM and SYSTEMQQ do not work in the same code. Am I right? Then for testing I just ran simple code of SYSTEMQQ. When I gave wrong command like, result = SYSTEMQQ('mkkdir any_file') and want to "print*, result" should I not get the output for "result" as "F"? But I get the output as "mkkdir: command not found, T". Why T?

The whole point I want to pass error message for running the exe file as I showed in my previous post.

-- Akand

Portrait de mecej4

Citation :

Akand a écrit :

The code by mecej4 doesn't work like the following error message observed:

error#6404: This name doesn't have a type, and must have an explicit type. [for I1, I2, I4].

That is an incorrect statement. The cited code, included in-line above, does not contain "i1" or "i2" or "i4" anywhere.

SYSTEMQQ simply tells you about the return value from the shell command.  ifort doesn't perform any analysis on the command.  If Microsoft cmd shell gives a T for "command not found," that's Microsoft's decision.  Maybe if you would spawn another shell such as bash, you might get a different result.

I don't know any reason why SYSTEM and SYSTEMQQ couldn't be used in the same application, but it could be confusing to do so and would make it inconsistent both with DVF/CVF usage and with all non-Intel compiler usage.

Thanks. Yes, the problem is not regarding calling both SYSTEM and SYSTEMQQ in the same code. If I erase all "SYSTEM" and keeps only "SYSTEMQQ" I get following type error message:

error #6552: The CALL statement is invoking a function subprogram as a subroutine. [SYSTEMQQ]

call systemqq(input_action)

-----^

Not to mention input_action is the strings of command like "mkdir new_file"

-- Akand

Connectez-vous pour laisser un commentaire.