kbbF77tricks.html KBB F77 Tricks library

KBB F77 Tricks library

Dr. K.B.Beard

15 October 2001
Center for Advanced Studies of Accelerators
Thomas Jefferson National Accelerator Facility


This is just a collection of the author's handy F77 string manipulation routines which are not machine dependent. Many are for use with the "Q" formalism (see below).

Unless otherwise stated, all integers are INTEGER*4, all real are REAL*4, and all character strings (string, InPut, OUTPUT, line, Cx, old, new) declared as CHARACTER*(*), and all logicals as LOGICAL*4 (ok). Inputs are in green, outputs in red, and both are in orange.


VERSION:

  • SUBROUTINE tricks_version(string) - return this library version and date

  • DEBUGGING:

  • SUBROUTINE kb_if_namebug( here, OfInterest ) - return whether descriptions within HERE match those set in kbb_set_namebug
  • SUBROUTINE kb_set_namebug( list, Ok, err ) - sets descriptions for use with kb_if_namebug, returns success or failure and why


    STRING MANIPULATION:

  • INTEGER FUNCTION important_length(string) - replaces all nulls & tabs with spaces, removes leading and redundant spaces, returns the last nonblank character or "1" if the string is blank
  • LOGICAL FUNCTION match(test, pattern) - require all of "test" match "pattern", require at least up to "*", ignore ":" or "=" onward
  • LOGICAL FUNCTION stringmatch(test, pattern) - require all of "test" match "pattern" (with * and % wildcards)
  • SUBROUTINE UP_case(string) - change lower case letters to upper.
  • SUBROUTINE UP_shift(string) - change lower case to upper, replace nulls&tabs with spaces
  • SUBROUTINE NO_backslash(string) - replace all "\" characters with blanks
  • SUBROUTINE NO_Comments(string) - remove comments
  • SUBROUTINE NO_control(string) - replace all characters outside " " to "~" with blanks
  • SUBROUTINE NO_leading_blanks(string) - remove leading blanks
  • SUBROUTINE NO_nulls(string) - replace nulls with blanks
  • SUBROUTINE NO_unquoted_blanks(string) - remove all blanks not in "quotes"
  • SUBROUTINE null_end(string) - replace trailing whitespace with nulls
  • SUBROUTINE nullterminate(string) - insert null after last important character
  • SUBROUTINE blankterminate(string) - insert blanks from 1st null character onward
  • SUBROUTINE only_one_blank(string) - remove all redundant blanks
  • SUBROUTINE strip_comment_field(string) - remove comments (except those in parenthesis)
  • SUBROUTINE unquoted_NO_Comments(string) - remove unquoted comments
  • SUBROUTINE NO_blanks(string) - remove all blanks
  • SUBROUTINE squeeze(string,nonblank) - remove all blanks, return nonblank length
  • SUBROUTINE ShiftAll(InPut, OUTPUT) - copy input to output and shift to upper case
  • SUBROUTINE ShiftAll_unquoted(InPut, OUTPUT) - similar, but doesn't shift "quoted"
  • SUBROUTINE real_data_row(string) - prepare data for scan (ex:"1 2.3"->"1,2.3,,,,")
  • SUBROUTINE rep_err(good, string) - if LOGICAL*2 good=.FALSE., output string
  • SUBROUTINE sub_string(string, old, new) - substitue "new" for "old" in string

  • Q FORMAT INTERFACE

    c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    c
    c		....Q interface style....
    c
    c	The LAMPF-Q acquisition system uses line oriented commands with
    c  the style:   
    c		field1/option1:data1:data2/option2 field2/option3....
    c	or	@filename.ext
    c	ex:       TRIG/info:[qBeard]TRIG.DAT/help /test
    c		  @scratch1:[Beard.demo]DEMO1.com
    c
    c	These routines handle command files "@file.ext" which can in turn
    c  contain other command files ("@next.ext") to a depth of 10 layers.
    c  The INCLUDE file allows communication with special options within the
    c  routines.  Codes using these routines are PSEUDOQ and CAMAC_CHAT.
    c  Typical use:
    c
    c	call Qcommand('WHAT',inst,Nfld,fld,Nopt,opt,key,ret,kill)
    c	Do k=1,Nopt
    c	  call parse_i4_option(opt(k),op,kind,value,string)
    c	  if(op.eq.'HE') then
    c	    ............
    c	  endif
    c	EndDo
    c
    c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    

    Usually, only Qcommand and parse_i4_option are commonly called by the user.

  • SUBROUTINE Qcommand( prmpt, inst, Nfld, fld, Nopt, opt, key, ret, kill) - - provides a prompt "prmpt>", and given an input line "inst" (possibly including a file to read with @file, which possibly contains references to other files to a maximum depth of 10), parses it into INTEGER Nfld and Nopt, CHARACTER*(*) fld(*) and opt(*), and LOGICAL key, ret, and kill which indicate respectively keyboard input, return at end-of-file, and abort.

  • SUBROUTINE parse_i4_option( option, opt, kind, value, string) - from option, gets CHARACTER*(*) opt, the kind (or number) of values, the INTEGER*4 value(*) or string following opt (ex: option="opt:ok" or "opt:1:2:5")

  • SUBROUTINE parse_i2_option( option, opt, kind, value, string) - from option, gets CHARACTER*(*) opt, the kind (or number) of values, the INTEGER*2 value(*) or string following opt (ex: option="opt:ok" or "opt:1:2:5")

  • SUBROUTINE ascii_I2_list( N, V, Cx, lenCx) - INTEGER*2 N,V(*) values are put into "Cx", length returned
  • SUBROUTINE ascii_I4_list( N, V, Cx, lenCx) - N,V(*) values are put into "Cx", length returned
  • SUBROUTINE ascii_R4_list( N, V, Cx, lenCx, fmt) - N REAL*4 V(*) values are put into "Cx", length returned
  • SUBROUTINE base10_i2_check( Nval, string) - checks for nondecimal values in string (ex: "5:F7x:3"), Nval=-1 on err
  • SUBROUTINE base10_i4_check( Nval, string) - checks for nondecimal values in string; Nval=-1 on err
  • SUBROUTINE base10_R4_check( Nval, string) - checks for nondecimal values in string; Nval=-1 on err
  • SUBROUTINE get_I4_values( string, n, values, ok) - extracts n INTEGER*4 values(*) from string
  • SUBROUTINE get_R4_values( string, n, values, ok) - extracts n REAL*4 values(*) from string
  • SUBROUTINE get_R8_values( string, n, values, ok) - extracts n REAL*8 values(*) from string
  • SUBROUTINE get_values( string, n, values, ok) - extracts n INTEGER*4 values(*) from string, returns LOGICAL*2 ok
  • SUBROUTINE parse_command( string, N_name, name, N_option, option) - gets N_name and N_option CHARACTER*(*) name(*), option(*) from string

  • details


    SUBROUTINE ASCII_I2_LIST( N, V, CX, LENCX )
    INTEGER*2 N - # in list
    INTEGER*2 V - list of values
    CHARACTER*(*) CX - string to use
    >INTEGER*4 LENCX - important length of string
    *-----------------------------------------------
    * Write a list of N V(*) numbers into Cx with
    * important length lenCx.
    *
    *.........modified Oct.21 1998 K.B.Beard (replaced ZEXT() intrinsic)
    *             
    *-----------------------------------------------
    

    calls: ZEXT2 , ASCII_I4_LIST

    SUBROUTINE ASCII_I4_LIST( N, V, CX, LENCX )
    INTEGER*4 N - # in list
    INTEGER*4 V - list of values
    CHARACTER*(*) CX - string to write into
    INTEGER*4 LENCX - important length of string
    *
    c  takes N elements of vector V and writes them into string Cx
    c  in an efficient way
    c  ex:    N=7 V=3,4,5,10,10,10,8 => "3::5:3*10:8"  "::"=sequence
    c						   "*"=duplication
    *.........modified Dec.7 1992 K.B.Beard
    *.........modified Oct.21 1998 K.B.Beard (replaced ZEXT() intrinsic)
    *
    

    called by: ASCII_I2_LIST

    calls: ZEXT4 , SQUEEZE

    SUBROUTINE ASCII_R4_LIST( N, V, CX, LENCX, FMT )
    INTEGER N - # in list
    REAL*4 V - list
    CHARACTER*(*) CX - string to write into
    INTEGER LENCX - important length
    CHARACTER*(*) FMT - FORTRAN format (blank=>'(f20.10)')
    *********************************************************
    *  		similar to "ascii_I2_list"
    *********************************************************
    

    calls: IMPORTANT_LENGTH , NO_BLANKS , SQUEEZE

    SUBROUTINE BASE10_I2_CHECK( NVAL, STRING )
    INTEGER*2 NVAL - # values expected, returns -1 if not all OK
    CHARACTER*(*) STRING - string to examine
    *******************************************************************
    *		look for non-base 10 characters
    *******************************************************************
    

    calls: IMPORTANT_LENGTH

    SUBROUTINE BASE10_I4_CHECK( NVAL, STRING )
    INTEGER*4 NVAL - # values expected, returns -1 if not all OK
    CHARACTER*(*) STRING - string to examine
    *******************************************************************
    *		look for non-base 10 characters
    *******************************************************************
    

    calls: IMPORTANT_LENGTH

    SUBROUTINE BASE10_R4_CHECK( NVAL, STRING )
    INTEGER NVAL - # values expected, returns -1 if not all OK
    CHARACTER*(*) STRING - string to examine
    *******************************************************************
    *		look for non-base 10 characters
    *******************************************************************
    

    calls: IMPORTANT_LENGTH

    SUBROUTINE BLANKTERMINATE( STRING )
    CHARACTER*(*) STRING - !input&output string
    *
    *   Insert blanks from the first NULL character onward.
    *
    

    SUBROUTINE DATA_ROW( STRING )
    CHARACTER*(*) STRING - input and output
    c
    c      eliminates adjacent blanks, comments, packs with ","s 
    c	ex: "1   2,	3" =>  "1,2,3,,,,,,,,,,,,,,,,,,,,"
    c                               K.Beard, modified 15aug2001
    

    calls: IMPORTANT_LENGTH , NO_NULLS , NO_TABS , NO_COMMENTS , NO_LEADING_BLANKS , ONLY_ONE_BLANK

    SUBROUTINE DEFAULT_EXTENSION( FILENAME, EXT )
    CHARACTER*(*) FILENAME - filename to modify
    CHARACTER*(*) EXT - default extension
    c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    c
    c	Often, it is convenient to deal with filenames via calls.
    c
    c
    c	If no extension on filename, add extension ext
    c	ex: CAMAC:input => CAMAC:input.ext
    c	    CAMAC_input: => CAMAC_input:
    c
    c========================================================================
    

    called by: QCOMMAND

    calls: EXTENSION

    SUBROUTINE EXTENSION( OLDNAME, EXT, NEWNAME )
    CHARACTER*(*) OLDNAME - input filename
    CHARACTER*(*) EXT - new extension
    CHARACTER*(*) NEWNAME - output filename
    C
    c                    adds new extension to old filename
    c
    

    called by: DEFAULT_EXTENSION

    calls: NO_BLANKS

    SUBROUTINE GET_I4_VALUES( STRING, N, VALUES, OK )
    CHARACTER*(*) STRING -
    INTEGER*4 N -
    INTEGER*4 VALUES -
    LOGICAL*2 OK -
    *-------------------------------------------------------------
    *-   given an ASCII string, attempt to extract integers
    *-
    *-  Input: string   -  character string; 1st 132 bytes significant
    *- Output: n        -  number of values found
    *-         values   -  found integers
    *-         ok       -  success or failure
    *-
    *- K.B.Beard, Hampton Univ.
    *- KBB modified 2/1/94 better documentation
    *- KBB modified 3/24/00 for GNU g77
    *- KBB modified 8/15/01 for standard maximum string
    *-------------------------------------------------------------
    

    calls: IMPORTANT_LENGTH , NO_TABS , NO_BLANKS , UP_CASE , SQUEEZE , NO_LEADING_BLANKS

    SUBROUTINE GET_R4_VALUES( STRING, N, VALUES, OK )
    CHARACTER*(*) STRING - input
    INTEGER*4 N - # values found
    REAL*4 VALUES - values found
    LOGICAL OK - success or failure
    *----------------------------------------------------------
    * given an ASCII string, attempts to extract real values
    *      Input:  string - ASCII string, 1st 132 bytes significant
    *     OutPut:  n      - number real numbers found
    *              values - values of real numbers
    *              OK     - success or failure
    *
    *- K.B.Beard, Hampton U.
    *- KBB modified 2/1/94 improved documentation
    *- KBB modified 8/15/01 standard maximum string length
    *----------------------------------------------------------
    

    calls: REAL_DATA_ROW

    SUBROUTINE GET_R8_VALUES( STRING, N, VALUES, OK )
    CHARACTER*(*) STRING - input
    INTEGER*4 N - # values found
    REAL*8 VALUES - values found
    LOGICAL OK - success or failure
    *----------------------------------------------------------
    * given an ASCII string, attempts to extract real values
    *      Input:  string - ASCII string, 1st 132 bytes significant
    *     OutPut:  n      - I*4 number real numbers found
    *              values - values of real*8 numbers
    *              OK     - success or failure
    *
    *- K.B.Beard, Hampton U.
    *- KBB modified 2/1/94 improved documentation
    *- KBB modified 8/15/01 standard maximum string length
    *- KBB modified 5/10/04 for R*8
    *----------------------------------------------------------
    

    calls: REAL_DATA_ROW

    SUBROUTINE GET_VALUES( STRING, N, VALUES, OK )
    CHARACTER*(*) STRING - input
    INTEGER*4 N - # values found
    INTEGER*4 VALUES - values found
    LOGICAL*2 OK - success or failure
    *--------------------------------------------------------------
    *    given an ASCII string, attempts to extract INTEGER values
    *       input:  string- any length character string, only 1st 132 used
    *       output: n     - number of integers found
    *               values- array containing values
    *               ok-     success or failure NOTE: LOGICAL*2 for
    *                       "Q" compatability
    *
    *-K.B.Beard, Hampton Univ.
    *-KBB modified 2/1/94 added documentation
    *-KBB modified 3/24/00 for GNU g77
    *- KBB modified 8/15/01 standard maximum string length
    *--------------------------------------------------------------
    

    called by: PARSE_I4_OPTION

    calls: IMPORTANT_LENGTH , NO_TABS , NO_BLANKS , UP_CASE , SQUEEZE , NO_LEADING_BLANKS

    INTEGER FUNCTION IMPORTANT_LENGTH( STRING )
    CHARACTER*(*) STRING - input & output
    c
    c    replace nulls$tabs w/ spaces, return last nonblank character position
    c
    

    called by: ASCII_R4_LIST , BASE10_I2_CHECK , BASE10_I4_CHECK , BASE10_R4_CHECK , DATA_ROW , GET_I4_VALUES , GET_VALUES , KB_ECHOING , KB_LOGGING , KB_SET_OPTIONS , MATCH , PARSE_COMMAND , PARSE_I2_OPTION , PARSE_I4_OPTION , QCOMMAND , REP_ERR

    calls: NO_NULLS , NO_TABS

    SUBROUTINE KB_BUGS_OFF( N, LIST )
    INTEGER N - # in list
    INTEGER LIST - list
    *********************************************************
    *  turn off selected elements of array "KB_buggy" for debugging
    *********************************************************
    

    called by: KB_SET_OPTIONS

    SUBROUTINE KB_BUGS_ON( N, LIST )
    INTEGER N - # in list
    INTEGER LIST - list
    *********************************************************
    *  turn on selected elements of array "KB_buggy" for debugging
    *********************************************************
    

    called by: KB_SET_OPTIONS

    SUBROUTINE KB_BUGS_STATUS( N, ID, STATUS )
    INTEGER N - # in list
    INTEGER ID - ID#s
    LOGICAL STATUS - status
    *********************************************************
    *  return status of elements of array "KB_buggy" for debugging
    *********************************************************
    

    called by: PARSE_COMMAND , PARSE_I2_OPTION , PARSE_I4_OPTION , QCOMMAND

    SUBROUTINE KB_ECHOING( IO, STRING )
    INTEGER IO - already opened IO channel
    CHARACTER*(*) STRING - message
    *................................
    *		maybe echo string to screen
    *................................
    

    called by: QCOMMAND

    calls: IMPORTANT_LENGTH

    SUBROUTINE KB_IF_NAMEBUG( HERE, OFINTEREST )
    CHARACTER*(*) HERE - !input current location
    LOGICAL*4 OFINTEREST - !output whether of interest or not
    *
    *  Using a list of interesting places is input 
    *  using kbb_set_namebuglist, returns whether
    *  any elements of here are in the list.
    *
    

    calls: IMPORTANT_LENGTH , NO_NULLS , SUB_STRING , UP_SHIFT , ONLY_ONE_BLANK , NO_LEADING_BLANKS

    SUBROUTINE KB_LOGGING( STRING )
    CHARACTER*(*) STRING - message
    *................................
    *		maybe log to a file 
    *................................
    

    calls: IMPORTANT_LENGTH

    SUBROUTINE KB_PUT_COMMENT( LINE )
    CHARACTER*(*) LINE - message
    *................................
    *  keep this comment
    *................................
    

    called by: QCOMMAND

    SUBROUTINE KB_SET_NAMEBUG( LIST, OK, ERR )
    CHARACTER*(*) LIST - !input list of names as a big string
    LOGICAL*4 OK - !output success or failure
    CHARACTER*(*) ERR - !output reason for failure, if any
    *
    *  Stores a list of blank, "," , or ":" delineated
    *  (case insensitive) names for subsequent flagging as of
    *  interest by kb_if_namebug.  A blank list clears all entries.
    *  KBB 3/5/03
    *
    

    calls: IMPORTANT_LENGTH , NO_NULLS , SUB_STRING , ONLY_ONE_BLANK , UP_SHIFT

    SUBROUTINE KB_SET_OPTIONS( COMMAND, OK )
    CHARACTER*(*) COMMAND - list of options
    LOGICAL OK - success or failure
    *................................
    *  turn ON/OFF echoing,KB_log_ON of TOP,ALL
    *  combinations OK-   'NOLOG TOP' or 'ALL' or 'none'
    *................................
    

    calls: MATCH , IMPORTANT_LENGTH , PARSE_COMMAND , SHIFTALL , PARSE_I4_OPTION , KB_BUGS_ON , KB_BUGS_OFF

    LOGICAL FUNCTION MATCH( TEST, PATTERN )
    CHARACTER*(*) TEST -
    CHARACTER*(*) PATTERN -
    c.................................................................
    c
    c  require all of "test" match "pattern", require at least up to "*" 
    C  EX: test="cl" matches pattern="CL*EAR" but not pattern="CLEAR"
    C      test="clx" does not match-   [case insensitive]
    c
    

    called by: KB_SET_OPTIONS

    calls: IMPORTANT_LENGTH , SHIFTALL , SQUEEZE

    SUBROUTINE NO_BACKSLASH( STR )
    CHARACTER*(*) STR - !input/output string
    *
    * replace all backslash {\} characters with blanks
    *
    

    SUBROUTINE NO_BLANKS( STRING )
    CHARACTER*(*) STRING -
    c
    c      strips out blanks and tabs
    c
    

    called by: ASCII_R4_LIST , EXTENSION , GET_I4_VALUES , GET_VALUES , PARSE_I4_OPTION , QCOMMAND

    calls: SQUEEZE

    SUBROUTINE NO_COMMENTS( STRING )
    CHARACTER*(*) STRING -
    c
    c         strips out comments [including "quotes"]
    c
    

    called by: DATA_ROW

    SUBROUTINE NO_CONTROL( STR )
    CHARACTER*(*) STR - !input/output string
    *
    * replaces all characters NOT between ASCII
    * blank and tilde (inclusive) with blanks
    *
    

    SUBROUTINE NO_LEADING_BLANKS( STRING )
    CHARACTER*(*) STRING -
    *..........................................................
    *-      strips out leading blanks and tabs
    *-K.B.Beard, Hampton U.
    *- modified 2/1/94 KBB- removed tab characters
    *..........................................................
    

    called by: DATA_ROW , GET_I4_VALUES , GET_VALUES , ONLY_ONE_BLANK , PARSE_COMMAND , PARSE_I4_OPTION , QCOMMAND , REAL_DATA_ROW , REP_ERR , SHIFTALL , SHIFTALL_UNQUOTED

    SUBROUTINE NO_NULLS( LINE )
    CHARACTER*(*) LINE -
    c
    c   replaces nulls with blanks
    c
    

    called by: DATA_ROW , IMPORTANT_LENGTH , REAL_DATA_ROW , SQUEEZE , UP_SHIFT

    SUBROUTINE NO_TABS( LINE )
    CHARACTER*(*) LINE -
    c
    c   replaces tabs with blanks
    c
    

    called by: DATA_ROW , GET_I4_VALUES , GET_VALUES , IMPORTANT_LENGTH , ONLY_ONE_BLANK , PARSE_COMMAND , QCOMMAND , REAL_DATA_ROW , UP_SHIFT

    SUBROUTINE NO_UNQUOTED_BLANKS( LINE )
    CHARACTER*(*) LINE -
    c
    c      removes all blanks and tabs from a string excepting "quotes"
    c       but replaces tabs w/ blanks in "quotes"
    c
    

    SUBROUTINE NULL_END( LINE )
    CHARACTER*(*) LINE -
    c
    *   replace trailing whitespace with nulls
    
    

    SUBROUTINE NULLTERMINATE( STRING )
    CHARACTER*(*) STRING - !input&output string
    *
    *   Put a NULL character after the last
    *   important character in the string.
    *
    

    called by: STRINGMATCH

    calls: IMPORTANT_LENGTH

    SUBROUTINE ONLY_ONE_BLANK( STRING )
    CHARACTER*(*) STRING -
    *
    * eliminate tabs,leading blanks, multiple blanks
    *
    

    called by: DATA_ROW , REAL_DATA_ROW , REP_ERR

    calls: NO_TABS , NO_LEADING_BLANKS

    SUBROUTINE PARSE_COMMAND( INLINE, N_NAME, NAME, N_OPTION, OPTION )
    CHARACTER*(*) INLINE - input string
    INTEGER N_NAME - # names found
    CHARACTER*(*) NAME - names
    INTEGER N_OPTION - #options found
    CHARACTER*(*) OPTION - options
    *----------------------------------------------------------------
    *  given an ASCII command string, get command names and options
    *    Input:  inline   - string, only 1st 132 bytes significant
    *   Output: N_name    - number of names found
    *           name      - names found
    *           N_option  - number of options found
    *           option    - option (including qualifiers, if any)
    *
    *-K.B.Beard, Hampton Univ.
    *-KBB modified 2/1/94, better documentation
    *- KBB modified 8/15/01 standard maximum string length
    *
    * form:  name1 /opt1 /opt2:arg name2  relative ordering opt, names doesn't
    *                                     matter
    *
    *----------------------------------------------------------------
    

    called by: KB_SET_OPTIONS , QCOMMAND

    calls: IMPORTANT_LENGTH , NO_LEADING_BLANKS , NO_TABS , KB_BUGS_STATUS

    SUBROUTINE PARSE_I2_OPTION( OPTION, OPT, KIND, VALUE, STRING )
    CHARACTER*(*)OPTION - input
    CHARACTER*(*)OPT - root of option
    INTEGER*4 KIND - # integers found
    INTEGER*2 VALUE - list of integers found
    CHARACTER*(*)STRING - string value of option
    c...................................................................
    

    calls: IMPORTANT_LENGTH , KB_BUGS_STATUS , PARSE_I4_OPTION

    SUBROUTINE PARSE_I4_OPTION( OPTION, OPT, KIND, VALUE, STRING )
    CHARACTER*(*) OPTION - input
    CHARACTER*(*) OPT - root of option
    INTEGER*4 KIND - # of integer values
    INTEGER*4 VALUE - list of values
    CHARACTER*(*) STRING - string form of value
    *
    *     parse Q-style option into opt + kind of value (if any)
    *     & values and/or string
    *
    *     /OPT[:values]  ex: /IN:filename /SIZE:1:10 /ROTATE:27.55
    *
    * warning: since value(*) open ended; might overrun array
    *
    

    called by: KB_SET_OPTIONS , PARSE_I2_OPTION

    calls: IMPORTANT_LENGTH , KB_BUGS_STATUS , NO_BLANKS , UP_CASE , NO_LEADING_BLANKS , GET_VALUES

    SUBROUTINE QCOMMAND( PRMPT, INST, NFLD, FLD, NOPT, OPT, KEY, RET, KILL )
    CHARACTER*(*) PRMPT - prompt identifying level
    CHARACTER*(*) INST - command
    INTEGER NFLD - #fields
    CHARACTER*(*) FLD - fields
    INTEGER NOPT - #options
    CHARACTER*(*) OPT - options
    LOGICAL KEY - keyboard input?
    LOGICAL RET - return when done?
    LOGICAL KILL - abort?
    
    c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    c
    c		....Q interface style....
    c
    c	The LAMPF-Q acquisition system uses line oriented commands with
    c  the style:   
    c		field1/option1:data1:data2/option2 field2/option3....
    c	or	@filename.ext
    c	ex:       TRIG/info:[qBeard]TRIG.DAT/help /test
    c		  @scratch1:[Beard.demo]DEMO1.com
    c
    c	These routines handle command files "@file.ext" which can in turn
    c  contain other command files ("@next.ext") to a depth of 10 layers.
    c  The INCLUDE file allows communication with special options within the
    c  routines.  Codes using these routines are PSEUDOQ and CAMAC_CHAT.
    c  Typical use:
    c
    c	call Qcommand('WHAT',inst,Nfld,fld,Nopt,opt,key,ret,kill)
    c	Do k=1,Nopt
    c	  call parse_i4_OPtion(opt(k),op,kind,value,string)
    c	  if(op.eq.'HE') then
    c	    ............
    c	  endif
    c	EndDo
    c
    * written by Dr. K.B.Beard,
    * "type *" statements removed for g77 compatibility 10/98
    *
    

    calls: IMPORTANT_LENGTH , KB_BUGS_STATUS , NO_TABS , NO_BLANKS , SHIFTALL , NO_LEADING_BLANKS , KB_ECHOING , KB_PUT_COMMENT , PARSE_COMMAND , DEFAULT_EXTENSION , REP_ERR

    SUBROUTINE REAL_DATA_ROW( STRING )
    CHARACTER*(*) STRING -
    c
    c      eliminates adjacent blanks, comments, packs with ","s 
    *      inserts missing "."s
    c	ex: "1.1   2,	3" =>  "1.,2.,3.,,,,,,,,,,,,,,,,,,,,"
    c
    

    called by: GET_R4_VALUES

    calls: NO_NULLS , NO_TABS , NO_LEADING_BLANKS , STRIP_COMMENT_FIELD , ONLY_ONE_BLANK , SUB_STRING

    SUBROUTINE REP_ERR( GOOD, STRING )
    LOGICAL*2 GOOD -
    CHARACTER*(*) STRING -
    c
    c	   if not good, report the error unless suppressed
    c
    

    called by: QCOMMAND

    calls: IMPORTANT_LENGTH , NO_LEADING_BLANKS , ONLY_ONE_BLANK

    SUBROUTINE SHIFTALL( INPUT, OUTPUT )
    CHARACTER*(*) INPUT -
    CHARACTER*(*) OUTPUT -
    c
    c      shifts strings to upper case, removes all tabs,nulls & leading blanks
    c
    

    called by: KB_SET_OPTIONS , MATCH , QCOMMAND

    calls: UP_SHIFT , NO_LEADING_BLANKS

    SUBROUTINE SHIFTALL_UNQUOTED( INPUT, OUTPUT )
    CHARACTER*(*) INPUT -
    CHARACTER*(*) OUTPUT -
    c
    c      shifts strings to upper case, removes leading blanks and all tabs
    c	but doesn't change things "inside quote"
    c
    

    calls: UP_SHIFT , NO_LEADING_BLANKS

    SUBROUTINE SHIFTONE( A )
    CHARACTER*(*) A -
    *
    *  shifts one letter to upper case- maintained for old codes
    *
    

    calls: UP_CASE

    SUBROUTINE SQUEEZE( LINE, NONBLANK )
    CHARACTER*(*) LINE -
    INTEGER NONBLANK -
    c
    c      removes all blanks and tabs from a string
    c       and return nonblank length
    c
    

    called by: ASCII_I4_LIST , ASCII_R4_LIST , GET_I4_VALUES , GET_VALUES , MATCH , NO_BLANKS

    calls: NO_NULLS

    LOGICAL*4 FUNCTION STRINGMATCH( STRING, PATTERN )
    CHARACTER*(*) STRING - ! string of interest
    CHARACTER*(*) PATTERN - ! pattern that string may or may not match
    *
    *    Given a string, return whether it matches the pattern.
    *    Case insensitive.
    *    * - any number of characters
    *    % - any single character
    *
    *    For example, string "today" matches pattern "t*" and "*day*",
    *    but not "%day". 
    *
    

    calls: IMPORTANT_LENGTH , SHIFTALL , NULLTERMINATE

    SUBROUTINE STRIP_COMMENT_FIELD( STRING )
    CHARACTER*(*) STRING -
    c
    c         strips out comment fields <not including ")("> 
    c			preserves region in "quotes"
    c
    

    called by: REAL_DATA_ROW

    SUBROUTINE SUB_STRING( STRING, OLD, NEW )
    CHARACTER*(*) STRING -
    CHARACTER*(*) OLD -
    CHARACTER*(*) NEW -
    *
    ********************** substitute new char. for old char. in string
    *
    

    called by: REAL_DATA_ROW

    SUBROUTINE TRICKS_VERSION( STRING )
    CHARACTER*(*) STRING -
    *
    * Returns the KBB/F77/TRICKS library version and date.
    *
    * K.B.Beard, TJNAF, 15aug2001
    *
    

    SUBROUTINE UNQUOTED_NO_COMMENTS( STRING )
    CHARACTER*(*) STRING -
    c
    c         strips out comments [excluding "quoted region"]
    c
    

    SUBROUTINE UP_CASE( STRING )
    CHARACTER*(*) STRING -
    *......................................................
    *	shifts "string" to upper case
    *
    *
    *-K.B.Beard, Hampton Univ.   
    *- modified 2/1/94, KBB - misc. improvements and 
    *-        bug fix of checking beyond end of string
    *......................................................
    

    called by: GET_I4_VALUES , GET_VALUES , PARSE_I4_OPTION , SHIFTONE , UP_SHIFT

    SUBROUTINE UP_SHIFT( INPUT )
    CHARACTER*(*) INPUT -
    c
    c      shifts strings to upper case, replaces nulls&tabs with spaces
    c
    

    called by: SHIFTALL , SHIFTALL_UNQUOTED

    calls: NO_NULLS , NO_TABS , UP_CASE

    INTEGER*4 FUNCTION ZEXT2( I2 )
    INTEGER*2 I2 -
    *
    * Zero-extension: treat sign bit as just another bit
    * (Cray had problems with previous version using IAND)
    *
    

    called by: ASCII_I2_LIST

    INTEGER*8 FUNCTION ZEXT4( I4 )
    INTEGER*4 I4 -
    *
    * Zero-extension: treat sign bit as just another bit
    * (Cray had problems with previous version using IAND)
    *
    

    called by: ASCII_I4_LIST


  • KBB - KBB library - main page
  • KBB/C - KBB C library
  • KBB/F77/TRICKS - KBB F77 TRICKS library
  • KBB/F77/SPECIAL - KBB F77 SPECIAL library
  • BS - Beard's System
  • style - coding style
  • machine dependencies - comments and guide

  • K.B.Beard, beard@jlab.org, 14 Oct 2004