kbbF77tricks.html
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.
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+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*----------------------------------------------- * 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
* 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
********************************************************* * similar to "ascii_I2_list" *********************************************************
calls: IMPORTANT_LENGTH
, NO_BLANKS
, SQUEEZE
******************************************************************* * look for non-base 10 characters *******************************************************************
calls: IMPORTANT_LENGTH
******************************************************************* * look for non-base 10 characters *******************************************************************
calls: IMPORTANT_LENGTH
******************************************************************* * look for non-base 10 characters *******************************************************************
calls: IMPORTANT_LENGTH
calls: IMPORTANT_LENGTH
, NO_NULLS
, NO_TABS
, NO_COMMENTS
, NO_LEADING_BLANKS
, ONLY_ONE_BLANK
called by: QCOMMAND
calls: EXTENSION
called by: DEFAULT_EXTENSION
calls: NO_BLANKS
calls: IMPORTANT_LENGTH
, NO_TABS
, NO_BLANKS
, UP_CASE
, SQUEEZE
, NO_LEADING_BLANKS
calls: REAL_DATA_ROW
calls: REAL_DATA_ROW
called by: PARSE_I4_OPTION
calls: IMPORTANT_LENGTH
, NO_TABS
, NO_BLANKS
, UP_CASE
, SQUEEZE
, NO_LEADING_BLANKS
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
called by: KB_SET_OPTIONS
called by: KB_SET_OPTIONS
called by: PARSE_COMMAND
, PARSE_I2_OPTION
, PARSE_I4_OPTION
, QCOMMAND
called by: QCOMMAND
calls: IMPORTANT_LENGTH
calls: IMPORTANT_LENGTH
, NO_NULLS
, SUB_STRING
, UP_SHIFT
, ONLY_ONE_BLANK
, NO_LEADING_BLANKS
calls: IMPORTANT_LENGTH
called by: QCOMMAND
calls: IMPORTANT_LENGTH
, NO_NULLS
, SUB_STRING
, ONLY_ONE_BLANK
, UP_SHIFT
calls: MATCH
, IMPORTANT_LENGTH
, PARSE_COMMAND
, SHIFTALL
, PARSE_I4_OPTION
, KB_BUGS_ON
, KB_BUGS_OFF
called by: KB_SET_OPTIONS
calls: IMPORTANT_LENGTH
, SHIFTALL
, SQUEEZE
called by: ASCII_R4_LIST
, EXTENSION
, GET_I4_VALUES
, GET_VALUES
, PARSE_I4_OPTION
, QCOMMAND
calls: SQUEEZE
called by: DATA_ROW
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
called by: DATA_ROW
, IMPORTANT_LENGTH
, REAL_DATA_ROW
, SQUEEZE
, UP_SHIFT
called by: DATA_ROW
, GET_I4_VALUES
, GET_VALUES
, IMPORTANT_LENGTH
, ONLY_ONE_BLANK
, PARSE_COMMAND
, QCOMMAND
, REAL_DATA_ROW
, UP_SHIFT
called by: STRINGMATCH
calls: IMPORTANT_LENGTH
called by: DATA_ROW
, REAL_DATA_ROW
, REP_ERR
calls: NO_TABS
, NO_LEADING_BLANKS
called by: KB_SET_OPTIONS
, QCOMMAND
calls: IMPORTANT_LENGTH
, NO_LEADING_BLANKS
, NO_TABS
, KB_BUGS_STATUS
calls: IMPORTANT_LENGTH
, KB_BUGS_STATUS
, PARSE_I4_OPTION
called by: KB_SET_OPTIONS
, PARSE_I2_OPTION
calls: IMPORTANT_LENGTH
, KB_BUGS_STATUS
, NO_BLANKS
, UP_CASE
, NO_LEADING_BLANKS
, GET_VALUES
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
called by: GET_R4_VALUES
calls: NO_NULLS
, NO_TABS
, NO_LEADING_BLANKS
, STRIP_COMMENT_FIELD
, ONLY_ONE_BLANK
, SUB_STRING
called by: QCOMMAND
calls: IMPORTANT_LENGTH
, NO_LEADING_BLANKS
, ONLY_ONE_BLANK
called by: KB_SET_OPTIONS
, MATCH
, QCOMMAND
calls: UP_SHIFT
, NO_LEADING_BLANKS
calls: UP_SHIFT
, NO_LEADING_BLANKS
calls: UP_CASE
called by: ASCII_I4_LIST
, ASCII_R4_LIST
, GET_I4_VALUES
, GET_VALUES
, MATCH
, NO_BLANKS
calls: NO_NULLS
calls: IMPORTANT_LENGTH
, SHIFTALL
, NULLTERMINATE
called by: REAL_DATA_ROW
called by: REAL_DATA_ROW
called by: GET_I4_VALUES
, GET_VALUES
, PARSE_I4_OPTION
, SHIFTONE
, UP_SHIFT
called by: SHIFTALL
, SHIFTALL_UNQUOTED
called by: ASCII_I2_LIST
called by: ASCII_I4_LIST
SUBROUTINE BLANKTERMINATE(
STRING )
*
* Insert blanks from the first NULL character onward.
*
SUBROUTINE DATA_ROW(
STRING )
c
c eliminates adjacent blanks, comments, packs with ","s
c ex: "1 2, 3" => "1,2,3,,,,,,,,,,,,,,,,,,,,"
c K.Beard, modified 15aug2001
SUBROUTINE DEFAULT_EXTENSION(
FILENAME,
EXT )
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========================================================================
SUBROUTINE EXTENSION(
OLDNAME,
EXT,
NEWNAME )
C
c adds new extension to old filename
c
SUBROUTINE GET_I4_VALUES(
STRING,
N,
VALUES,
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
*-------------------------------------------------------------
SUBROUTINE GET_R4_VALUES(
STRING,
N,
VALUES,
OK )
*----------------------------------------------------------
* 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
*----------------------------------------------------------
SUBROUTINE GET_R8_VALUES(
STRING,
N,
VALUES,
OK )
*----------------------------------------------------------
* 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
*----------------------------------------------------------
SUBROUTINE GET_VALUES(
STRING,
N,
VALUES,
OK )
*--------------------------------------------------------------
* 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
*--------------------------------------------------------------
INTEGER FUNCTION IMPORTANT_LENGTH(
STRING )
c
c replace nulls$tabs w/ spaces, return last nonblank character position
c
SUBROUTINE KB_BUGS_OFF(
N,
LIST )
*********************************************************
* turn off selected elements of array "KB_buggy" for debugging
*********************************************************
SUBROUTINE KB_BUGS_ON(
N,
LIST )
*********************************************************
* turn on selected elements of array "KB_buggy" for debugging
*********************************************************
SUBROUTINE KB_BUGS_STATUS(
N,
ID,
STATUS )
*********************************************************
* return status of elements of array "KB_buggy" for debugging
*********************************************************
SUBROUTINE KB_ECHOING(
IO,
STRING )
*................................
* maybe echo string to screen
*................................
SUBROUTINE KB_IF_NAMEBUG(
HERE,
OFINTEREST )
*
* Using a list of interesting places is input
* using kbb_set_namebuglist, returns whether
* any elements of here are in the list.
*
SUBROUTINE KB_LOGGING(
STRING )
*................................
* maybe log to a file
*................................
SUBROUTINE KB_PUT_COMMENT(
LINE )
*................................
* keep this comment
*................................
SUBROUTINE KB_SET_NAMEBUG(
LIST,
OK,
ERR )
*
* 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
*
SUBROUTINE KB_SET_OPTIONS(
COMMAND,
OK )
*................................
* turn ON/OFF echoing,KB_log_ON of TOP,ALL
* combinations OK- 'NOLOG TOP' or 'ALL' or 'none'
*................................
LOGICAL FUNCTION MATCH(
TEST,
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
SUBROUTINE NO_BACKSLASH(
STR )
*
* replace all backslash {\} characters with blanks
*
SUBROUTINE NO_BLANKS(
STRING )
c
c strips out blanks and tabs
c
SUBROUTINE NO_COMMENTS(
STRING )
c
c strips out comments [including "quotes"]
c
SUBROUTINE NO_CONTROL(
STR )
*
* replaces all characters NOT between ASCII
* blank and tilde (inclusive) with blanks
*
SUBROUTINE NO_LEADING_BLANKS(
STRING )
*..........................................................
*- strips out leading blanks and tabs
*-K.B.Beard, Hampton U.
*- modified 2/1/94 KBB- removed tab characters
*..........................................................
SUBROUTINE NO_NULLS(
LINE )
c
c replaces nulls with blanks
c
SUBROUTINE NO_TABS(
LINE )
c
c replaces tabs with blanks
c
SUBROUTINE NO_UNQUOTED_BLANKS(
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 )
c
* replace trailing whitespace with nulls
SUBROUTINE NULLTERMINATE(
STRING )
*
* Put a NULL character after the last
* important character in the string.
*
SUBROUTINE ONLY_ONE_BLANK(
STRING )
*
* eliminate tabs,leading blanks, multiple blanks
*
SUBROUTINE PARSE_COMMAND(
INLINE,
N_NAME,
NAME,
N_OPTION,
OPTION )
*----------------------------------------------------------------
* 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
*
*----------------------------------------------------------------
SUBROUTINE PARSE_I2_OPTION(
OPTION,
OPT,
KIND,
VALUE,
STRING )
c...................................................................
SUBROUTINE PARSE_I4_OPTION(
OPTION,
OPT,
KIND,
VALUE,
STRING )
*
* 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
*
SUBROUTINE QCOMMAND(
PRMPT,
INST,
NFLD,
FLD,
NOPT,
OPT,
KEY,
RET,
KILL )
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
*
SUBROUTINE REAL_DATA_ROW(
STRING )
c
c eliminates adjacent blanks, comments, packs with ","s
* inserts missing "."s
c ex: "1.1 2, 3" => "1.,2.,3.,,,,,,,,,,,,,,,,,,,,"
c
SUBROUTINE REP_ERR(
GOOD,
STRING )
c
c if not good, report the error unless suppressed
c
SUBROUTINE SHIFTALL(
INPUT,
OUTPUT )
c
c shifts strings to upper case, removes all tabs,nulls & leading blanks
c
SUBROUTINE SHIFTALL_UNQUOTED(
INPUT,
OUTPUT )
c
c shifts strings to upper case, removes leading blanks and all tabs
c but doesn't change things "inside quote"
c
SUBROUTINE SHIFTONE(
A )
*
* shifts one letter to upper case- maintained for old codes
*
SUBROUTINE SQUEEZE(
LINE,
NONBLANK )
c
c removes all blanks and tabs from a string
c and return nonblank length
c
LOGICAL*4 FUNCTION STRINGMATCH(
STRING,
PATTERN )
*
* 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".
*
SUBROUTINE STRIP_COMMENT_FIELD(
STRING )
c
c strips out comment fields <not including ")(">
c preserves region in "quotes"
c
SUBROUTINE SUB_STRING(
STRING,
OLD,
NEW )
*
********************** substitute new char. for old char. in string
*
SUBROUTINE TRICKS_VERSION(
STRING )
*
* Returns the KBB/F77/TRICKS library version and date.
*
* K.B.Beard, TJNAF, 15aug2001
*
SUBROUTINE UNQUOTED_NO_COMMENTS(
STRING )
c
c strips out comments [excluding "quoted region"]
c
SUBROUTINE UP_CASE(
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
*......................................................
SUBROUTINE UP_SHIFT(
INPUT )
c
c shifts strings to upper case, replaces nulls&tabs with spaces
c
INTEGER*4 FUNCTION ZEXT2(
I2 )
*
* Zero-extension: treat sign bit as just another bit
* (Cray had problems with previous version using IAND)
*
INTEGER*8 FUNCTION ZEXT4(
I4 )
*
* Zero-extension: treat sign bit as just another bit
* (Cray had problems with previous version using IAND)
*
K.B.Beard,
beard@jlab.org, 14 Oct 2004