INTEGER FUNCTION GETMENU( ITEMCNT, DEFAULT, PROMPT, CHOICES ) INTEGER , INTENT(IN ) :: ITEMCNT ! number of choices INTEGER , INTENT(IN ) :: DEFAULT ! Default return value CHARACTER*(*), INTENT(IN ) :: PROMPT ! Prompt for user CHARACTER*(*), INTENT(IN ) :: CHOICES( ITEMCNT ) ! array of menu choice strings
Display a menu to the screen; then displayPROMPT
, get the user's response, check that it is within range, and return it. ReturnDEFAULT
if the user hits <RET>. Reprompts on error for up to 5 attempts; exits in case of more than 5 entry errors. If environment variable PROMPTFLAG is set to "N", returnsDEFAULT
without prompting the user. Logs the value returned, for tracking and validation purposes.The number for the default response is displayed in square brackets at the end of the prompt
[LIKE THIS]
NOTE: prompt and menu choice strings should have length at most 72 characters. Ideally, the number of items should be at most 18; should be at most 999, in any case.
See also: GETVAL(), GETDATE(), GETDBLE(), GETNUM(), GETREAL(), GETSTR(), and GETYN().
NumberITEMCNT
of choices at least 1 and at most 999. In practice,ITEMCNT
should be at most 20, so that the menu will cleanly fit "on-screen".PROMPT
andCHOICES
should have (trimmed) length at most 72
GETVAL()
is the Fortran-90-generic (I/O API-3.2 or later only) that calls this or various other similar routines, as determined by the argument-list.For Fortran-90 declarations and interface checking:
USE M3UTILIO(See sample programs LATLON or PRESZ for additional usage examples.)
... USE M3UTILIO !! else: INTEGER, EXTERNAL :: GETMENU ... INTEGER L, M, N ... CHARACTER*72, PARAMETER :: CHOICES( 4 ) = & (/ 'This is the first choice', & 'This is the second choice', & 'This is the third choice', & 'This is the last choice' /) CHARACTER*72, PARAMETER :: CHOICE2( 3 ) = & (/ 'This is the first choice', & 'This is the second choice', & 'This is the last choice' /) ... L = GETMENU( 4, 1, 'Choose one', CHOICES ) M = GETVAL( 3, 1, 'Choose one', CHOICE2 ) !! only if USE M3UTILIO N = GETVAL( 99, 'Give me a (INTEGER) number' ) !! only if USE M3UTILIO ...
don't
To: Models-3/EDSS I/O API: The Help Pages