7 Writing HP-UX applications

This chapter discusses how HP Fortran applications running on the HP-UX operating system can use system resources to do the following:

Accessing command-line arguments

Calling HP-UX system and library routines

Using HP-UX file I/O

Accessing command-line arguments

When invoking an HP Fortran executable program, you can include one or more arguments on the command line. The operating system will make these available to your program. For example, the following command line invokes the program fprog:

$ fprog arg1 "another arg" 222

and it also passes three character arguments to the program:

arg1

another arg 222

An HP Fortran program can access these arguments for internal use by calling the IGETARGand IARGCintrinsics; IGETARGis available either as a function or a subroutine. The IGETARGintrinsic gets the specified command-line argument; IARGCreturns the number of arguments on the command line. You can also use the GETARGintrinsic to return command-line arguments, as illustrated in the following example program:

Example 20 Example 7-1 get_args.f90

PROGRAM get_args

INTEGER, PARAMETER :: arg_num = 1

!arg_str is the character array to be written to

!by IGETARG

CHARACTER(LEN=30) :: arg_str

!IGETARG returns number of characters read within

!the specified parameter

!arg_num is the position of the desired argument in the

!the command line (the name by which the program

!was invoked is 0)

!arg_str is the character array in which the argument

!will be written

!30 is the number of characters to write to arg_str PRINT *, IGETARG(arg_num, arg_str, 30)

PRINT *, arg_str

!IARGC returns the total number of arguments on the

!command line

PRINT *, IARGC()

END PROGRAM get_args

When compiled and invoked with the following command lines:

$ f90 get_args.f90

$ a.out perambulation of a different sort

this program produces the following output:

13

perambulation 5

Accessing command-line arguments 107

Page 107
Image 107
HP UX Fortran Software manual Writing HP-UX applications, Accessing command-line arguments, $ fprog arg1 another arg