C Copyright(c) 1999, Space Science and Engineering Center, UW-Madison C Refer to "McIDAS Software Acquisition and Distribution Policies" C in the file mcidas/data/license.txt C *** $Id: smpargfetch.f,v 1.0 1999/09/28 14:38:32 russd Tst $ *** C ? SMPARGFETCH - McIDAS command line argument fetching sample C ? SMPARGFETCH C ? Parameters: C ? none C ? Keywords: C ? DAY=day1..dayN | list of days C ? DBL=dbl1..dbl2 | list of real (double precision) values C ? INT=int1..intN | list of integer values C ? LATlon=lat1 lon1..latN lonN | list of latitude/longitude pairs C ? STR='str1'..'strN' | list of character strings C ? TIMe=time1..timeN | list of times C ? Remarks: C ? McIDAS programing sample. C ? C ? This sample illustrates the command line argumet fetching API C ? functions. C ? ---------- subroutine main0 implicit none c --- external functions c --- internal functions integer arg_utils ! test arg fetcher utils c --- internal variables integer status ! function status c **************** Program Body ************** c --- set initial program status to FAILED call MCCODESET( -1 ) c --- command line argument fetchers status = ARG_UTILS( ) if( status.lt.0 ) return c --- set the program status to SUCCESS call MCCODESET( 0 ) c --- signal finished call EDEST('Done ...',0) return end ** Name: ** arg_utils - code samples for command line argument fetchers ** ** Interface: ** integer function ** arg_utils( ) ** ** Input: ** none ** ** Input and Output: ** none ** ** Output: ** none ** ** Return values: ** 0 - Success ** -1 - Failed ** ** Remarks: ** Used to illustrate basic command line retrieval functions ** ** Categories: ** argument ** parse integer function arg_utils( ) implicit none c --- parameters c --- internal constants integer MAXNPARMS ! array limit for parameter lists parameter (MAXNPARMS = 10) integer NKEYWORDS ! number of valid keywords parameter (NKEYWORDS = 6) c --- external functions real ftime ! convert hhmmss to hh.hhh integer mccmd ! recover complete command integer mccmdnam ! list of keywords entered integer mccmdnum ! number of parameters entered for keyword integer mccmdkey ! verify keywords entered integer mccmdint ! integer parameter integer mccmdstr ! character string parameter integer mccmddbl ! double precision parameter integer mccmddhr ! time as double precision parameter integer mccmddll ! lat/lon as double precision parameter integer mccmdihr ! time as integer parameter integer mccmdill ! lat/lon as integer parameter integer mccmdiyd ! day as integer parameter integer mccmdquo ! character string quote field parameter c --- internal variables character*12 keys(NKEYWORDS) ! list of entered keywords character*256 c_val ! returned parameter value double precision d_def ! default parameter value double precision d_min ! minimum parameter value double precision d_max ! maximum parameter value double precision d_val ! returned parameter value integer i_def ! default parameter value integer i_min ! minimum parameter value integer i_max ! maximum parameter value integer i_val ! returned parameter value integer ikey ! keyword loop pointer integer iparm ! paarmeter loop pointer integer nkeys ! number of keywords integer nparms ! number of parameters integer ok ! function status integer today ! current day (ccyyddd) integer now ! current time (hhmmss) character*256 command ! complete command text integer nday ! counter for DAY keyword parameters integer days(MAXNPARMS) ! array of days integer ndbl ! counter for DBL keyword parameters double precision dbl(MAXNPARMS) ! array of double precison values integer nintr ! counter for INT keyword parameters integer nlatlon ! counter for LATLON keyword parameters integer ilatlon(MAXNPARMS,2) ! array of lat/lon pairs double precision dlatlon(MAXNPARMS,2) ! array of lat/lon pairs integer nstr ! counter for STR keyword parameters character*256 str(MAXNPARMS) ! array of character strings integer ntime ! counter for TIME keyowrd parameters integer itimes(MAXNPARMS) ! array of times double precision dtimes(MAXNPARMS) ! array of times character*256 quote ! quote field integer intr(MAXNPARMS) ! array of integer values c ********************* VALID COMMAND LINE KEYWORDS ****************** c Modify these data values to add/delete command line keywords c Note that the internal constant NKEYWORDS is defined as the number c of keywords deemed valid within the SAMPLE program. character*12 keywords(NKEYWORDS) ! array of valid keyword names data keywords/ & 'DAY', & 'DBL', & 'INT', & 'LAT.LON', & 'STR', & 'TIM.E' & / c ********************* VALID COMMAND LINE KEYWORDS ****************** c ************ Function Body ************* c --- initialize the function status arg_utils = -1 c --- get the current day and time call MCGETDAYTIME( today, now ) c --- initialize the keyword parameter counters nday = 0 ndbl = 0 nintr = 0 nlatlon = 0 nstr = 0 ntime = 0 quote = ' ' c --- rcover the command text ok= MCCMD( command ) if( ok.lt.0 ) return c --- validate the command line keywords ok= MCCMDKEY( NKEYWORDS, keywords ) if( ok.lt.0 ) return c --- get a list of command line keywords nkeys = MCCMDNAM( NKEYWORDS, keys ) c --- fetch the keyword parameters if( nkeys.gt.0 ) then c ------ loop through the list of entered keywords do ikey = 1, nkeys c ------ get the number of parameters entered for this keyword nparms = MCCMDNUM( keys(ikey) ) if( nparms.gt.MAXNPARMS ) then call EDEST('Too many parameters entered for keyword '// & keys(ikey),0) return endif c ------ DAY keyword if( keys(ikey)(1:3).eq.'DAY' ) then i_def = today i_min = 1972001 i_max = 2100001 do iparm = 1, nparms ok= MCCMDIYD('DAY',iparm,'DAY',i_def,i_min,i_max,i_val) if( ok.lt.0 ) return days(iparm) = i_val end do nday = nparms c ------ DBL keyword else if( keys(ikey)(1:3).eq.'DAY' ) then d_def = 0.0D0 d_min = 1.0D0 d_max = -1.0D0 do iparm = 1, nparms ok= MCCMDDBL('DBL',iparm,'DBL',d_def,d_min,d_max,d_val) if( ok.lt.0 ) return dbl(iparm) = d_val end do ndbl = nparms c ------ INT keyword else if( keys(ikey)(1:3).eq.'INT' ) then i_def = 0 i_min = 1 i_max = -1 do iparm = 1, nparms ok= MCCMDINT('INT',iparm,'INT',i_def,i_min,i_max,i_val) if( ok.lt.0 ) return intr(iparm) = i_val end do nintr = nparms c ------ LAT.LON keyword else if( keys(ikey)(1:3).eq.'LAT' ) then do iparm = 1, nparms, 2 ok= MCCMDILL('LAT.LON',iparm,'LATITUDE',990000, & -900000,900000,i_val) if( ok.lt.0 ) return ilatlon(iparm,1) = i_val ok= MCCMDDLL('LAT.LON',iparm,'LATITUDE',99.0D0, & -90.0D0,90.0D0,d_val) if( ok.lt.0 ) return dlatlon(iparm,1) = d_val ok= MCCMDILL('LAT.LON',iparm+1,'LONGITUDE',9990000, & -1800000,1800000,i_val) if( ok.lt.0 ) return ilatlon(iparm,2) = i_val ok= MCCMDDLL('LAT.LON',iparm+1,'LONGITUDE',999.0D0, & -180.0D0,180.0D0,d_val) if( ok.lt.0 ) return dlatlon(iparm,2) = d_val end do nlatlon = nparms / 2 c ------ STR keyword else if( keys(ikey)(1:3).eq.'STR' ) then do iparm = 1, nparms ok= MCCMDSTR('STR',iparm,' ',c_val) if( ok.lt.0 ) return str(iparm) = c_val end do nstr = nparms c ------ TIM.E keyword else if( keys(ikey)(1:3).eq.'TIM' ) then i_def = now i_min = 0 i_max = 235959 d_def = dble( ftime(now) ) d_min = 0.0D0 d_max = 23.99D0 do iparm = 1, nparms ok= MCCMDIHR('TIM.E',iparm,'TIME',i_def,i_min,i_max,i_val) if( ok.lt.0 ) return itimes(iparm) = i_val ok= MCCMDDHR('TIM.E',iparm,'TIME',d_def,d_min,d_max,d_val) if( ok.lt.0 ) return dtimes(iparm) = d_val end do ntime = nparms endif end do endif c --- recover the quote field ok = MCCMDQUO( quote ) if( ok.lt.0 ) return c --- set return status arg_utils = 0 return end