       IDENTIFICATION DIVISION.
       PROGRAM-ID. Y2KGTOJ.
       AUTHOR. JAY MOSELEY.
       DATE-WRITTEN. DECEMBER, 1997.
       DATE-COMPILED.
      *                                                               *
      *   YY   YY   222   KK   KK  GGGGG TTTTTTTT  OOOOO       JJ     *
      *   YY   YY  2   2  KK  KK  GG   GG   TT    OO   OO      JJ     *
      *   YY   YY      2  KK KK   GG   GG   TT    OO   OO      JJ     *
      *    YY YY       2  KKKK    GG        TT    OO   OO      JJ     *
      *     YYY     222   KKKK    GG  GGG   TT    OO   OO      JJ     *
      *     YY     2      KK KK   GG   GG   TT    OO   OO JJ   JJ     *
      *     YY     2      KK  KK  GG   GG   TT    OO   OO JJ   JJ     *
      *     YY     22222  KK   KK  GGGGG    TT     OOOOO   JJJJJ      *
      *                                                               *
      *************************************************************** *
      *************************************************************** *
      * THIS SUBROUTINE COMPUTES THE JULIAN DATE(YYYYDDD) FOR A GIVEN *
      * GREGORIAN DATE (MMDDYYYY)                                     *
      *                                                               *
      *  VALID INPUT YEARS FOR THIS ROUTINE ARE THE YEARS 1601        *
      *  THROUGH 3399 A. D. (INCLUSIVE)                               *
      *                                                               *
      *  VALID INPUT MONTH VALUES FOR THIS ROUTINE ARE 01 THROUGH 12. *
      *                                                               *
      *  VALID INPUT DAY VALUES FOR THIS ROUTINE ARE 01 THROUGH 31    *
      *  WITH EXCEPTIONS FOR THE MONTHS LISTED:                       *
      *       MONTH          MAXIMUM DAY VALUE                        *
      *        04                    30                               *
      *        06                    30                               *
      *        09                    30                               *
      *        11                    30                               *
      *        02                    28                               *
      *        02 DURING LEAP YEAR   29                               *
      *                                                               *
      *  THE DATE FORMAT MUST BE MMDDYYYY, WHERE MM = THE 2 DIGIT     *
      *  MONTH VALUE, DD = THE 2 DIGIT DAY VALUE, AND YYYY = THE      *
      *  4 DIGIT YEAR VALUE.                                          *
      *                                                               *
      *  THREE FIELDS ARE PASSED AS PARAMETERS TO THE ROUTINE:        *
      *  1)  AN 8 BYTE FIELD CONTAINING THE DATE (IN ZONED-           *
      *      DECIMAL FORMAT) FOR WHICH THE JULIAN DAY NUMBER IS       *
      *      TO BE CALCULATED,                                        *
      *  2)  A 1 BYTE ZONED-DECIMAL RETURN CODE, AND                  *
      *  3)  A 7 BYTE FIELD WHICH WILL RECEIVE THE YEAR AND JULIAN    *
      *      DAY NUMBER (IN ZONED-DECIMAL FORMAT).                    *
      *  THE ROUTINE WILL NOT ALTER THE DATE PASSED TO IT.            *
      *                                                               *
      *  SUGGESTED CALLING SYNTAX FOR COBOL CALLERS:                  *
      *                                                               *
      *       01  GTOJ-PARAMETERS.                                    *
      *           02  DATEG PIC 9(8) VALUE 01011997.                  *
      *           02  RC    PIC 9(1) VALUE 0.                         *
      *           02  JDATE PIC 9(7) VALUE 0.                         *
      *       CALL 'Y2KGTOJ' USING GTOJ-PARAMETERS.                   *
      *                                                               *
      *  THE POSSIBLE VALUES FOR THE RETURN CODE FIELD ARE:           *
      *                                                               *
      *  0 INDICATES SUCCESSFUL EXECUTION OF THE ROUTINE.             *
      *                                                               *
      *  2 INDICATES INVALID DATA WAS FOUND IN THE DATE FIELD.        *
      *  INVALID DATA ARE DETERMINED IF THE FIELD'S LOW ORDER         *
      *  BYTE'S ZONE CONTAINS AN INVALID SIGN, (NOT ONE OF            *
      *  X'C', X'D' OR X'F'), OR IF THE PRECEDING BYTES' ZONES        *
      *  ARE OTHER THAN X'F', OR IF ANY BYTE'S LOW ORDER NIBBLE       *
      *  CONTAINS A VALUE GREATER THAN X'9'.                          *
      *                                                               *
      *  4 INDICATES THE VALUE OF THE YEAR SPECIFIED WAS NOT IN       *
      *  THE RANGE SPECIFIED IN 1 (ABOVE).                            *
      *                                                               *
      *  6 INDICATES THE VALUE OF THE MONTH SPECIFIED WAS NOT IN      *
      *  THE RANGE SPECIFIED IN 2 (ABOVE).                            *
      *                                                               *
      *  8 INDICATES THE VALUE OF THE DAY SPECIFIED WAS NOT IN        *
      *  THE RANGE SPECIFIED IN 3 (ABOVE).                            *
      *                                                               *
      *  UPON SUCCESSFUL EXECUTION, THE 4 DIGIT YEAR PLUS THE 3       *
      *  DIGIT JULIAN DAY NUMBER (YYYYDDD) WILL BE PLACED IN THE      *
      *  3RD PARAMETER FIELD (IN ZONED-DECIMAL FORMAT).  IF THE       *
      *  RETURN CODE IS A NON-ZERO VALUE (UNSUCCESSFUL EXECUTION),    *
      *  THE 3RD PARAMETER FIELD WILL CONTAIN ZEROS.                  *
      *                                                               *
      *---------------------------------------------------------------*
      *                                                               *
      * 18 Sep 2017 - Change from INITIAL to LOCAL-STORAGE            *
      *               This change has no affect on program execution. *
      *               It was made to accomodate a bug in GnuCOBOL 2.2 *
      *               which will be fixed, but the change makes sense *
      *               from a logical viewpoint, so thus is justified. *
      *                                                               *
      *************************************************************** *
      /
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.

       LOCAL-STORAGE SECTION.

       01  FILLER                      PIC X(24)
           VALUE 'Y2KGTOJ STORAGE BEGINS->'.

      * ************************************************************* *
      * THESE ARE PROGRAM CONTROL SWITCHES AND WORK FIELDS.           *
      * ************************************************************* *
       01  PROGRAM-CONTROL-FIELDS.
           02  CURRENT-ASTRO-NUMBER    PIC S9(7).

           02  GTOA-PARAMETERS.
               03  GTOAP-DATEG         PIC 9(8).
               03  FILLER              REDEFINES GTOAP-DATEG.
                   04  GTOAP-DATEG-MD  PIC 9(4).
                   04  GTOAP-DATEG-Y   PIC 9(4).
               03  GTOAP-RC            PIC 9(1).
               03  GTOAP-ANUM          PIC S9(7).

       01  FILLER                      PIC X(24)
           VALUE '<-Y2KGTOJ STORAGE ENDS'.

       LINKAGE SECTION.

      * ************************************************************* *
      * THESE ARE THE FIELDS USED TO RECEIVE INPUT DATA FROM THE      *
      * CALLER AND PASS RESULT FIELDS BACK TO THE CALLER.             *
      * ************************************************************* *
       01  GTOJ-PARAMETERS.
           02  GTOJP-DATEG             PIC 9(8).
           02  GTOJP-RC                PIC 9(1).
           02  GTOJP-DATEJ.
               03  GTOJP-DATEJ-YYYY    PIC 9(4).
               03  GTOJP-DATEJ-DDD     PIC 9(3).
      /
       PROCEDURE DIVISION USING GTOJ-PARAMETERS.

       0000-MAIN SECTION.
       0025-INITIALIZE.
           MOVE ZERO TO GTOJP-RC, GTOJP-DATEJ.

       0050-RETRIEVE-CURRENT-ASTRO.
           MOVE GTOJP-DATEG TO GTOAP-DATEG.
           CALL 'Y2KGTOA' USING GTOA-PARAMETERS.

           IF GTOAP-RC NOT EQUAL '0' THEN
               MOVE GTOAP-RC TO GTOJP-RC
               GOBACK.

           MOVE GTOAP-ANUM TO CURRENT-ASTRO-NUMBER.

       0075-RETRIEVE-YEAREND-ASTRO.
           MOVE '0101' TO GTOAP-DATEG-MD.
           CALL 'Y2KGTOA' USING GTOA-PARAMETERS.

       0100-COMPUTE-JULIAN-DATE.
           SUBTRACT 1 FROM GTOAP-ANUM.
           SUBTRACT GTOAP-ANUM FROM CURRENT-ASTRO-NUMBER.
           MOVE GTOAP-DATEG-Y TO GTOJP-DATEJ-YYYY.
           MOVE CURRENT-ASTRO-NUMBER TO GTOJP-DATEJ-DDD.

           GOBACK.

       END PROGRAM Y2KGTOJ.

