Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

NARGS

Inquiry Intrinsic Function (Specific): Returns the total number of command-line arguments, including the command. This function cannot be passed as an actual argument.

result = NARGS( )

Results

The result type is INTEGER(4). The result is the number of command-line arguments, including the command. For example, NARGS returns 4 for the command-line invocation of PROG1 -g -c -a.

Example


    INTEGER(2) result
    result = RUNQQ('myprog', '-c -r')
    END

 !  MYPROG.F90 responds to command switches -r, -c,
 !  and/or -d
 INTEGER(4) count, num, i, status
 CHARACTER(80) buf
 REAL r1 / 0.0 /
 COMPLEX c1 / (0.0,0.0) /
 REAL(8) d1 / 0.0 /

 num = 5
 count = NARGS()
 DO i = 1, count-1
    CALL GETARG(i, buf, status)
    IF (status .lt. 0) THEN
      WRITE (*,*) 'GETARG error - exiting'
      EXIT
    END IF
    IF (buf(2:status) .EQ.'r') THEN
      r1 = REAL(num)
      WRITE (*,*) 'r1 = ',r1
    ELSE IF (buf(2:status) .EQ.'c') THEN
      c1 = CMPLX(num)
      WRITE (*,*) 'c1 = ', c1
    ELSE IF (buf(2:status) .EQ.'d') THEN
      d1 = DBLE(num)
      WRITE (*,*) 'd1 = ', d1
    ELSE
      WRITE(*,*) 'Invalid command switch: ', buf (1:status)
    END IF
 END DO
 END