User Guide
Chapters
Table of Contents
User-Defined Functions
Trace Statements

Utility Files


Qtawk includes several files which contain functions that can be included and used as needed. The following files are included:
  1. addcomma.awk
  2. capitalize.awk
  3. engineering_notation.awk
  4. fin_eqns.awk
  5. gcd.awk
  6. graph.awk
  7. holiday_and_dates.awk
  8. jdn.awk
  9. roman.awk
  10. sun_rise_set.awk
  11. function_add.awk
  12. create_file_hdr.awk
Each file contains one or more functions as listed below.

  1. addcomma.awk
    addcomma(x,nfrmt)
    function to format numbers as separated digits. The separator is specified by the LOCALE["THOUSANDS_SEP"]. If no value is specified by the LOCALE string,a comma, ',', is used. Note the function could be extended to also use the LOCALE speification for digit grouping, LOCALE["GROUPING"]. Currently the function assumes a grouping of 3 digits for each separated group.
  2. capitalize.awk
    _common_capitalize_function_
    This is a common function used by the next two functions
    capitalize
    function to capitalize first letter of each word following one or more field separator characters and first leter of first word
    capitalize_sentence
    function to capitalize first letter of each word following a period and one or more field separator characters
    reverse
    function to reverse case of characters in string passed
    compress
    function to remove all characters specified in second string from first string
    Note: if second string is a single character, then this function is the same as
          the built-in "remove" function.
    Example: remove all vowels from a string:
          compress(line,"AEIOUaeiou");
    Example: to get the string to remove all consonents:
          local consonents = compress(POSIX[upper] ><                                                                                              POSIX[lower],"AEIOUaeiou");
  3. engineering_notation.awk
    fmt_eng(n, R)
    Engineering notation.  Number, n, is displayed as:
       1: abs(n) > 0 ==>  [DD]D.DDDeN where first two digits are not both zero
       2: abs(n) < 1 ==> 0.[00]DDDDeN
    N is a multiple of 3.
  4. fin_eqns.awk. This is  a complete  financial computation  utility to  solve for  the five standard financial values: n, %i, PV, PMT and FV
        n   == number of payment periods
        %i  == nominal interest rate, NAR, charged
        PV  == Present Value
        PMT == Periodic Payment
        FV  == Future Value

     The following global variables are defined:
     1. n
     2. i
     3. pv
     4. pmt
     5. fv
     6. CF
     7. PF
     8. disc
     9. bep
    function rnd(x,places)
    return 'x' rounded to 'places' past decimal if 'places' < 0, return 'x'
    function abs(x)
    return absolute value of 'x'
    function sanity_check(n,i,pv,pmt,fv,check)
    function to perform sanity check on input values.
    function _A(eint,per)
    used by functions to compute financial values
    function _B(eint,beg)
    used by functions to compute financial values
    function _C(eint,pmt,beg)
    used by functions to compute financial values
    function N()
    compute Number of Periods from preset data
    function _N(nint,pv,pmt,fv,CF,PF,disc,bep)
    Compute number of periods from arguments passed:
       1. Nominal Interest
       2. Present Value
       3. Periodic Payment
       4. Future Value
    function I()
    compute Interest from preset data
    function _I(per,pv,pmt,fv,CF,PF,disc,bep)
    Compute Nominal Interest from arguments passed:
       1. Number of periods
       2. Present Value
       3. Periodic Payment
       4. Future Value
    function PV()
    compute Present value from preset data
    function _PV(per,nint,pmt,fv,CF,PF,disc,bep)
    Compute Present Value from arguments passed:
       1. Number of periods
       2. Nominal Interest
       3. Periodic Payment
       4. Future Value
    function PMT()
    compute Periodic Payment from preset data
    function _PMT(per,nint,pv,fv,CF,PF,disc,bep)
    Compute Periodic Payment from arguments passed:
       1. Number of periods
       2. Nominal Interest
       3. Present Value
       4. Future Value
    function FV()
    compute Future Value from preset data
    function _FV(per,nint,pv,pmt,CF,PF,disc,bep)
    Compute Future Value from arguments passed:
       1. Number of periods
       2. Nominal Interest
       3. Present Value
       4. Periodic Payments
    function nom_int(eint,CF,PF,disc)
    compute Nominal Interest Rate from Effective Interest Rate
    function eff_int(nint,CF,PF,disc)
    Compute Effective Interest Rate from Nominal Interest Rate
    function fi(per,eint,pv,pmt,fv,bep)
    calculation used in interest computation
    function fip(per,eint,pv,pmt,fv,bep)
    calculation used in interest computation
    function set_default()
    Set default values for financial variables
    function Amortization(nint,
                          n,
                          pv,
                          pmt,
                          fv,
                          CF,
                          PF,
                          disc,
                          bep,
                          Eff_Date_jdn,
                          Init_Date_jdn,
                          fix_pmt,
                          option,
                          summary,
                          output_file)
    Compute amortization table from data passed.
    n == number of periods
    pv == present value
    pmt == periodic payment
    fv == future value
    CF == Compounding Frequency
    PF == Payment Frequency
    disc == discrete/continuous compounding
    bep == beginning/end of period payments
    Eff_Date_jdn == JDN of Effective date
    Init_Date_jdn== JDN of initial payment date
    fix_pmt == fixed payment or zero
    option == specify amortization options
    summary == TRUE/FALSE for summary
    output_file == output file name, null string uses stdout
  5. gcd.awk
    gcd_si(k, l)
    compute the Greatest Common Divisor, gcd, of two signed integers, k and l
  6. graph.awk
    function frame()
    create frame for graph
    function ticks()
    create tick marks for both axes
    function label()
    center label under x-axis
    function data()
    create data points
    function draw()
    print graph from array
    function xscale(x)
    scale x-value
    function yscale(y)
    scale y-value
    function plot(x,y,c)
    put character c in array
    function splot(x,y,s)
    put string s in array
  7. holiday_and_dates.awk
    function set_family_dates(tdate_yr,tdate_mn,tdate_dy)
    function to set dates for family occasions - data set by user - sorted by date
    function set_family_dates_sorted(tdate_yr,tdate_mn,tdate_dy)
    function to set dates for family occasions - data set by user - sorted alphabetically
    function set_National_Holiday_dates(tdate_yr,tdate_mn,tdate_dy)
    Compute National Holidays - USA
    function set_Religious_Holiday_dates(tdate_yr,tdate_mn,tdate_dy)
    Compute Religious Holidays (Christian and Jewish)
    function Holiday_dates(year)
    Compute Jewish Holiday Dates
    function Holiday_dates_jdn(year)
    Used by above
    function pass_over_day(year)
    Used by above
    function JulianLeapYear(year)
    Used by function below to compute Easter date
    function GregorianLeapYear(year)
    Used by function below to compute Easter date
    function _JHSSB_(century)
    Used by function below to compute Easter date
    function _JHSB_(year)
    Used by function below to compute Easter date
    function _GEP_(year)
    Used by function below to compute Easter date
    function Easter(year)
    Compute date of Easter

  8. jdn.awk
    function auto_jdn(...)
    Automatically corrects for Gregorian or Julian calender. Returns JDN or calender date.
    Correct forms:
    auto_jdn or auto_jdn() --> returns JDN for current date
    auto_jdn(JDN) --> returns calender date for JDN passed
    auto_jdn(year,month,day) --> returns JDN for date passed
    function Weekday_Following(yr,mon,day,wd)
    Returns the number of days from the date passed to the weekday specified and following the date passed. For example, if the date passed is 1999-4-1 (yyy-m-d), Thursday, and the weekday specified is Sunday, 3 is returned. If Friday had been specified, 1 would be returned.

    The weekday is specified as an integer between 0 and 6 inclusive, with:
       0 == Sunday
       1 == Monday
       2 == Tuesday
       3 == Wednesday
       4 == Thursday
       5 == Friday
       6 == Saturday
    function Weekday_Preceeding(yr,mon,day,wd
    Returns the number of days from the date passed to the weekday specified and preceeding the date passed. For example, if the date passed is 1999-4-1 (yyyy-m-d), Thursday, and the weekday specified is Sunday, 4 is returned. If Friday had been specified, 6 would be returned.

    The weekday is specified as an integer between 0 and 6 inclusive, with:
       0 == Sunday
       1 == Monday
       2 == Tuesday
       3 == Wednesday
       4 == Thursday
       5 == Friday
       6 == Saturday
    function WeekNumber(year,month,day)
    Returns the week number of the date passed. The week number is the week in the calender year in which the date falls.
    function WeekDay(year,month,day)
    Day of week
         0 == Sunday
        1 == Monday
        2 == Tueday
        3 == Wednesday
        4 == Thursday
        5 == Friday
        6 == Saturday
    function MDY_to_DoC(Year, Month, Day)
    Day Of Century Function
    function month_day_date(month,occur,dow,year)
    function to compute day of month for day passed as:
       month, 1 <= m <= 12
       occurrence, 1 <= w <= 5
       dow == day of week (0 == Sunday, 6 == Saturday)
       year
    e.g., want day of month for the second Thursday in September, pass:
           month == 9
           occur == 2
           dow   == 4
           year  == 1996
        returns: 12
    function last_dow_of_month(month,dow,year)
    function to compute day of month for dow passed as last dow in month
       dow == Day Of Week

      month, 1 ó month ó 12
      dow, 0 ó dow ó 6
      year
    ,e.g., for last thursday in month of October, 1996, pass:
           month == 10
           dow   == 4
           year  == 1996
        returns:  31
  9. roman.awk
    function roman_numeral(num)
    convert decimal number to roman numeral
    function d_to_alpha
    convert decimal number to alphabetic number - useful if alphabetic page numbering wanted
    function alpha_to_decimal
    convert alphanumeric to decimal number
  10. sun_rise_set.awk
    This utility will compute the sunrise and sunset times when the longitude and latitude has been specified. The longitude and latitude is specified in the 'BEGIN' action in decimal format.
  11. function_add.awk
    This utility uses the 'qtgrep' program to scan a QTAwk utility  for the 'function' keyword. It uses the output to read the utulity file and place a listing of all functions defined in the file at the top of the file.
    It also uses the "tmpfile_mod.so" module to create a temporary filename which is then used to copy the utility file to and then read it back in place.
  12. create_file_hdr.awk
    This file takes one input filename, it then prints to the standard output file a header for a source file, which can be used when starting a new source file. The header is similar to the following:
    /***************************************************************************
     *                         tmpfile_mod.c -  description
     *                            -------------------
     *   begin                : Thu 29 Dec 2005 04:39:30 PM EST
     *   copyright            : (C) 2005 by Terry D. Boldt
     *   email                : fastsnip-wm1@yahoo.com
     ***************************************************************************/

    /***************************************************************************
     *                                                                         *
     *   This program is free software; you can redistribute it and/or modify  *
     *   it under the terms of the GNU General Public License as published by  *
     *   the Free Software Foundation; either version 2 of the License, or     *
     *   (at your option) any later version.                                   *
     *                                                                         *
     ***************************************************************************/
    /*
     *
     *   QTAwk plugin function to create temporary file name for use
     */