#!/bin/ksh
#######################################################################
# SCRIPT: getnummo.ksh                                                #
# LANGUAGE: Korn Shell                                                #
#---------------------------------------------------------------------#
# PURPOSE: Calculates number of months between two input dates        #
#---------------------------------------------------------------------#
# INPUT FILES: None                                                   #
# OUTPUT FILES: None                                                  #
# SOURCED FILES: None                                                 #
#---------------------------------------------------------------------#
# COMMAND LINE VARIABLES:                                             #
#    ${1} - Initial Date [YYYYMM format]                              #
#    ${2) - Final Date [YYYYMM format]                                #
# LOCAL VARIABLES:                                                    #
#    cline - Flag indicating if command line argument conditions      #
#            have been met                                            #
#    mm - Array containing 2 digit months                             #
#    nummo - Number of months between final and initial input dates   #
#    yyyy - Array containing 4 digit years                            #
#---------------------------------------------------------------------#
# AUTHOR: Scott Handel                                                #
#---------------------------------------------------------------------#
# DATE: Oct 31, 2005                                                  #
#---------------------------------------------------------------------#
# MODIFICATIONS:                                                      #
#######################################################################
#######################################################################
# QUALITY CONTROL COMMAND LINE ARGUMENTS                              #
#######################################################################
cline="TRUE"
case $# in
    2) case ${1} in
         19[0-9][0-9][0-1][0-9]|2[0-9][0-9][0-9][0-1][0-9])
cline=${cline} ;;
         *) cline="FALSE" ;;
       esac
       case ${2} in
         19[0-9][0-9][0-1][0-9]|2[0-9][0-9][0-9][0-1][0-9])
cline=${cline} ;;
         *) cline="FALSE" ;;
       esac ;;
    *) cline="FALSE" ;;
esac
#######################################################################
# IF ANY OF COMMAND LINE ARGUMENT CONDITIONS ARE NOT MET, ALERT USER  #
# OF PROPER USAGE                                                     #
#######################################################################
if [ ${cline} = "FALSE" ]; then
   echo 'USAGE: getnummo.ksh ${1} ${2}'
   echo "--------------------------------"
   echo '${1}= Initial month [YYYYMM format]'
   echo '${2}= Final month [YYYYMM format]'
   exit
fi
#######################################################################
# ESTABLISH INITIAL AND FINAL FORECAST MONTHS AND YEARS RESPECTIVELY  #
#######################################################################
mm[1]=`echo ${1} | cut -c 5-6`
mm[2]=`echo ${2} | cut -c 5-6`
yyyy[1]=`echo ${1} | cut -c 1-4`
yyyy[2]=`echo ${2} | cut -c 1-4`
#######################################################################
# ESTABLISH NUMBER OF MONTHS BETWEEN FINAL AND INITIAL INPUT DATES    #
#######################################################################
let nummo="((${yyyy[2]}-${yyyy[1]})*12)+(${mm[2]}-${mm[1]})"
echo ${nummo}
