Appendix Z: Computer Software

Hexagram Derivatives

Whilst writing this paper, I needed to check various things. Grunt work that computers are very good at doing. Thus, I wrote a program to provide the hexagram tables that I needed.

I tested this module on Win2K, DrDos 7.03 and Linux. No changes were needed for it to run on those three platforms, so I suspect that it will run on any platform that Python is available for. I developed it using Python 1.5. Testing on the Win2K platform was using Python 2.0.

This is a module written in python, that can determine the following:
Hexagrams

  1. Inverse Hexagram
  2. Reverse Hexagram
  3. Nuclear Hexagram
  4. Golden Hexagram
  5. Interlaced Hexagram
  6. Evolved Hexagram
  7. Axillary Hexagram 1
  8. Axillary Hexagram 2
  9. Axillary Hexagram 3
  10. Axillary Hexagram 4
  11. Axillary Hexagram 5
  12. Axillary Hexagram 6
  13. Wing Wen Sequence: Next Hexagram
  14. Wing Wen Sequence: Prior Hexagram
  15. Fu Xi Sequence: Next Hexagram
  16. Fu Xi Sequence: Prior Hexagram
  17. WaMangDui Sequence: Next Hexagram
  18. WaMangDui Sequence: Prior Hexagram
  19. Base Trigram Sequence: Next Hexagram
  20. Base Trigram Sequence: Prior Hexagram
Trigrams
  1. Upper Trigram
  2. Lower Trigram
  3. Upper Nuclear Trigram
  4. Lower Nuclear Trigram
  5. Upper Interlaced Trigram
  6. Lower Interlaced Trigram
  7. Golden Trigram
  8. Hexagram Family

I may add Terrestrial Branch and Celestial Stem calculations to this module in the future.

The easiest way to obtain this software is to cut and paste from here. I will send the most recent version to people, if they send a floppy disk, formatted for DOS, with a self addressed stamped envelope.

This software is distributed under the GNU licence, thus anybody else is free to distribute in the format of their choice. I would appreciate being informed of such distribution.

This software is copyright by Jonathon Blake. Distribution is governed by the GNU General Public Licence Version 2.0, dated June 1991.



#!/usr/bin/python
import sys
sys.path.insert ( 0, '/usr/local/lib/python-1.5/lib' )
# remember to delete the above line when changing operating systems
#    Yi Jing Hexagram Construction Program
#
#    Initialization routines for hexagrams
#
#    This is version 0.0.0.1
#    Creation Date: 9 May  2001 @ 18:59 H GMT
#    Last Update:   5 June 2001 @ 10:57 H Zulu
#    Copyright:  2001 Jonathon Blake
#    Licence Terms:  Public Versions: GNU General Public Licence
#                    Private Versions: No distribution allowed
#                                      No copying allowed
#
#    This is a private version.
#    This is a private release.
#
#    This version is not for public release.
#    Public versions of this software are released under the
#    GNU General Public Licence.
#
import string



########################## start of #####################################
########################## copyright routines / data etc ****************


def hexagram_copyright( check ):
   print "Hexagram Derivatives 0.0.0.1: A module that deconstructs hexagrams"
   print "Copyright (c) 2001 Jonathon Blake"
   print """
    By obtaining, using, and/or copying this software and/or its
    associated documentation, you agree that you have read,
    understood,and will comply with the following terms and
    conditions:

    Permission to use, copy, modify, and distribute this software
    and its associated documentation for any purpose and without
    fee is hereby granted, provided that the above copyright
    notice appears in all copies, and that both that copyright
    notice and this permission noticeappear in supporting
    documentation, and that the name of the author ---
    Jonathon Blake --- not be used in
    advertising or publicity pertaining to distribution of the
    software without specific, written prior permission.

    THE AUTHOR --- JONATHON BLAKE --- DISCLAIMS ALL WARRANTIES WITH REGARD TO
    THIS SOFTWARE, INCLUDING ALL IMPLIEDWARRANTIES OF
    MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL THE AUTHOR
    BE LIABLE FOR ANY SPECIAL, INDIRECTOR
    CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
    FROM LOSSOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
    CONTRACT, NEGLIGENCEOR OTHER TORTIOUS ACTION, ARISING OUT OF
    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
    SOFTWARE.

    Furthermore, you also agree to the terms and conditions of
    the GNU General Public License, Version 2.0.

   """

   print    """

                     GNU GENERAL PUBLIC LICENSE
                        Version 2, June 1991
       Copyright (C) 1989, 1991 Free Software Foundation, Inc.
               675 Mass Ave, Cambridge, MA 02139, USA


    Everyone is permitted to copy and distribute verbatim copies
    of this license document, but changing it is not allowed.

                              Preamble

    The licenses for most software are designed to take away your
    freedom to share and change it. By contrast, the GNU General
    Public License is intended to guarantee your freedom to share
    and change free software--to make sure the software is free
    for all its users. This General Public License applies to
    most of the Free Software Foundation's software and to any
    other program whose authors commit to using it. (Some other
    Free Software Foundation software is covered by the GNU
    Library General Public License instead.)  You can apply it to
    your programs, too.

    When we speak of free software, we are referring to freedom,
    not price. Our General Public Licenses are designed to make
    sure that you have the freedom to distribute copies of free
    software (and charge for this service if you wish), that you
    receive source code or can get it if you want it, that you
    can change the software or use pieces of it in new free
    programs; and that you know you can do these things.

    To protect your rights, we need to make restrictions that
    forbid anyone to deny you these rights or to ask you to
    surrender the rights. These restrictions translate to certain
    responsibilities for you if you distribute copies of the
    software, or if you modify it.

    For example, if you distribute copies of such a program,
    whether gratis or for a fee, you must give the recipients all
    the rights that you have. You must make sure that they, too,
    receive or can get the source code. And you must show them
    these terms so they know their rights.

    We protect your rights with two steps: (1) copyright the
    software, and (2) offer you this license which gives you
    legal permission to copy, distribute and/or modify the
    software.

    Also, for each author's protection and ours, we want to make
    certain that everyone understands that there is no warranty
    for this free software. If the software is modified by
    someone else and passed on, we want its recipients to know
    that what they have is not the original, so that any problems
    introduced by others will not reflect on the original
    authors' reputations.

    Finally, any free program is threatened constantly by
    software patents. We wish to avoid the danger that
    redistributors of a free program will individually obtain
    patent licenses, in effect making the program proprietary.
    To prevent this, we have made it clear that any patent must
    be licensed for everyone's free use or not licensed at all.

    The precise terms and conditions for copying, distribution
    and modification follow.

                     GNU GENERAL PUBLIC LICENSE
                      TERMS AND CONDITIONS FOR
               COPYING, DISTRIBUTION AND MODIFICATION

    0. This License applies to any program or other work which
    contains a notice placed by the copyright holder saying it
    may be distributed under the terms of this General Public
    License.  The "Program", below, refers to any such program or
    work, and a "work based on the Program" means either the
    Program or any derivative work under copyright law: that is
    to say, a work containing the Program or a portion of it,
    either verbatim or with modifications and/or translated into
    another language.  (Hereinafter, translation is included
    without limitation in the term "modification".) Each licensee
    is addressed as "you".

    Activities other than copying, distribution and modification
    are not covered by this License; they are outside its scope.
    The act of running the Program is not restricted, and the
    output from the Program is covered only if its contents
    constitute a work based on the Program (independent of having
    been made by running the Program). Whether that is true
    depends on what the Program does.

    1. You may copy and distribute verbatim copies of the
    Program's source code as you receive it, in any medium,
    provided that you conspicuously and appropriately publish on
    each copy an appropriate copyright notice and disclaimer of
    warranty; keep intact all the notices that refer to this
    License and to the absence of any warranty; and give any
    other recipients of the Program a copy of this License along
    with the Program.

    You may charge a fee for the physical act of transferring a
    copy, and you may at your option offer warranty protection in
    exchange for a fee.

    2. You may modify your copy or copies of the Program or any
    portion of it, thus forming a work based on the Program, and
    copy and distribute such modifications or work under the
    terms of Section 1 above, provided that you also meet all of
    these conditions:

    a) You must cause the modified files to carry prominent
    notices stating that you changed the files and the date of
    any change.

    b) You must cause any work that you distribute or publish,
    that in whole or in part contains or is derived from the
    Program or any part thereof, to be licensed as a whole at no
    charge to all third parties under the terms of this License.

    c) If the modified program normally reads commands
    interactively when run, you must cause it, when started
    running for such interactive use in the most ordinary way, to
    print or display an announcement including an appropriate
    copyright notice and a notice that there is no warranty (or
    else, saying that you provide a warranty) and that users may
    redistribute the program under these conditions, and telling
    the user how to view a copy of this License. (Exception: if
    the Program itself is interactive but does not normally print
    such an announcement, your work based on the Program is not
    required to print an announcement.)

    These requirements apply to the modified work as a whole. If
    identifiable sections of that work are not derived from the
    Program, and can be reasonably considered independent and
    separate works in themselves, then this License, and its
    terms, do not apply to those sections when you distribute
    them as separate works. But when you distribute the same
    sections as part of a whole which is a work based on the
    Program, the distribution of the whole must be on the terms
    of this License, whose permissions for other licensees extend
    to the entire whole, and thus to each and every part
    regardless of who wrote it.

    Thus, it is not the intent of this section to claim rights or
    contest your rights to work written entirely by you; rather,
    the intent is to exercise the right to control the
    distribution of derivative or collective works based on the
    Program.

    In addition, mere aggregation of another work not based on
    the Program with the Program (or with a work based on the
    Program) on a volume of a storage or distribution medium does
    not bring the other work under the scope of this License.

    3. You may copy and distribute the Program (or a work based
    on it, under Section 2) in object code or executable form
    under the terms of Sections 1 and 2 above provided that you
    also do one of the following:

    a) Accompany it with the complete corresponding machine-
    readable source code, which must be distributed under the
    terms of Sections 1 and 2 above on a medium customarily used
    for software interchange; or,

    b) Accompany it with a written offer, valid for at least
    three years, to give any third party, for a charge no more
    than your cost of physically performing source distribution,
    a complete machine-readable copy of the corresponding source
    code, to be distributed under the terms of Sections 1 and 2
    above on a medium customarily used for software interchange;
    or,

    c) Accompany it with the information you received as to the
    offer to distribute corresponding source code. (This
    alternative is allowed only for noncommercial distribution
    and only if you received the program in object code or
    executable form with such an offer, in accord with Subsection
    b above.)

    The source code for a work means the preferred form of the
    work for making modifications to it. For an executable work,
    complete source code means all the source code for all
    modules it contains, plus any associated interface definition
    files, plus the scripts used to control compilation and
    installation of the executable. However, as a special
    exception, the source code distributed need not include
    anything that is normally distributed (in either source or
    binary form) with the major components (compiler, kernel, and
    so on) of the operating system on which the executable runs,
    unless that component itself accompanies the executable.

    If distribution of executable or object code is made by
    offering access to copy from a designated place, then
    offering equivalent access to copy the source code from the
    same place counts as distribution of the source code, even
    though third parties are not compelled to copy the source
    along with the object code.

    4. You may not copy, modify, sublicense, or distribute the
    Program except as expressly provided under this License. Any
    attempt otherwise to copy, modify, sublicense or distribute
    the Program is void, and will automatically terminate your
    rights under this License. However, parties who have received
    copies, or rights, from you under this License will not have
    their licenses terminated so long as such parties remain in
    full compliance.

    5. You are not required to accept this License, since you
    have not signed it. However, nothing else grants you
    permission to modify or distribute the Program or its
    derivative works. These actions are prohibited by law if you
    do not accept this License. Therefore, by modifying or
    distributing the Program (or any work based on the Program),
    you indicate your acceptance of this License to do so, and
    all its terms and conditions for copying, distributing or
    modifying the Program or works based on it.

    6. Each time you redistribute the Program (or any work based
    on the Program), the recipient automatically receives a
    license from the original licensor to copy, distribute or
    modify the Program subject to these terms and conditions. You
    may not impose any further restrictions on the recipients'
    exercise of the rights granted herein. You are not
    responsible for enforcing compliance by third parties to this
    License.

    7. If, as a consequence of a court judgment or allegation of
    patent infringement or for any other reason (not limited to
    patent issues), conditions are imposed on you (whether by
    court order, agreement or otherwise) that contradict the
    conditions of this License, they do not excuse you from the
    conditions of this License. If you cannot distribute so as to
    satisfy simultaneously your obligations under this License
    and any other pertinent obligations, then as a consequence
    you may not distribute the Program at all. For example, if a
    patent license would not permit royalty-free redistribution
    of the Program by all those who receive copies directly or
    indirectly through you, then the only way you could satisfy
    both it and this License would be to refrain entirely from
    distribution of the Program.

    If any portion of this section is held invalid or
    unenforceable under any particular circumstance, the balance
    of the section is intended to apply and the section as a
    whole is intended to apply in other circumstances.

    It is not the purpose of this section to induce you to
    infringe any patents or other property right claims or to
    contest validity of any such claims; this section has the
    sole purpose of protecting the integrity of the free software
    distribution system, which is implemented by public license
    practices. Many people have made generous contributions to
    the wide range of software distributed through that system in
    reliance on consistent application of that system; it is up
    to the author/donor to decide if he or she is willing to
    distribute software through any other system and a licensee
    cannot impose that choice.

    This section is intended to make thoroughly clear what is
    believed to be a consequence of the rest of this License.

    8. If the distribution and/or use of the Program is
    restricted in certain countries either by patents or by
    copyrighted interfaces, the original copyright holder who
    places the Program under this License may add an explicit
    geographical distribution limitation excluding those
    countries, so that distribution is permitted only in or among
    countries not thus excluded. In such case, this License
    incorporates the limitation as if written in the body of this
    License.

    9. The Free Software Foundation may publish revised and/or
    new versions of the General Public License from time to time.
    Such new versions will be similar in spirit to the present
    version, but may differ in detail to address new problems or
    concerns.

    Each version is given a distinguishing version number. If the
    Program specifies a version number of this License which
    applies to it and "any later version", you have the option of
    following the terms and conditions either of that version or
    of any later version published by the Free Software
    Foundation. If the Program does not specify a version number
    of this License, you may choose any version ever published by
    the Free Software Foundation.

    10. If you wish to incorporate parts of the Program into
    other free programs whose distribution conditions are
    different, write to the author to ask for permission. For
    software which is copyrighted by the Free Software
    Foundation, write to the Free Software Foundation; we
    sometimes make exceptions for this. Our decision will be
    guided by the two goals of preserving the free status of all
    derivatives of our free software and of promoting the sharing
    and reuse of software generally.

                             NO WARRANTY

    11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS
    NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
    APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE
    COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM
    "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
    IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF
    THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
    YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
    CORRECTION.

    12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED
    TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY
    WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED
    ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
    SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF
    THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
    LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
    LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
    PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH
    HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
    SUCH DAMAGES.

                     END OF TERMS AND CONDITIONS
     """

   print """
       Appendix: How to Apply These Terms to Your New Programs

    If you develop a new program, and you want it to be of the
    greatest possible use to the public, the best way to achieve
    this is to make it free software which everyone can
    redistribute and change under these terms.

    To do so, attach the following notices to the program. It is
    safest to attach them to the start of each source file to
    most effectively convey the exclusion of warranty; and each
    file should have at least the "copyright" line and a pointer
    to where the full notice is found.

    
    Copyright (C) 19yy 

    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.

    This program is distributed in the hope that it will be
    useful, but WITHOUT ANY WARRANTY; without even the implied
    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    PURPOSE. See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public
    License along with this program; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
    USA.

    Also add information on how to contact you by electronic and
    paper mail.

    If the program is interactive, make it output a short notice
    like this when it starts in an interactive mode:

    Gnomovision version 69,
    Copyright (C) 19yy name of author

    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
    type `show w'. This is free software, and you are welcome to
    redistribute it under certain conditions; type `show c' for
    details.

    The hypothetical commands `show w' and `show c' should show
    the appropriate parts of the General Public License. Of
    course, the commands you use may be called something other
    than `show w' and `show c'; they could even be mouse-clicks
    or menu items--whatever suits your program.

    You should also get your employer (if you work as a
    programmer) or your school, if any, to sign a "copyright
    disclaimer" for the program, if necessary.

    Here is a sample; alter the names:

    Yoyodyne, Inc., hereby disclaims all copyright interest in
    the program `Gnomovision' (which makes passes at compilers)
    written by James Hacker.

    , 1 April 1989
    Ty Coon, President of Vice

    This General Public License does not permit incorporating
    your program into proprietary programs. If your program is a
    subroutine library, you may consider it more useful to permit
    linking proprietary applications with the library. If this is
    what you want to do, use the GNU Library General Public
    License instead of this License.

     """
     return



########################## end of #######################################
########################## copyright routines / data etc ****************



#    bigram functions are below this line #######################3

def reduce_bigram( upper_line, lower_line ):
   if upper_line == "|":
       if lower_line == "o":
           return_bigram = "old yang"
       else:
           return_bigram = "young yang"
   else:
       if lower_line == "o":
           return_bigram = "young yin"
       else:
           return_bigram = "old yin"
   return return_bigram

def moving_line_to_symbol( moving_line ):
#
#    Not the operation overload.
#         In most these I treat moving_line as a a string,
#         but for some of them, moving_line is an integer.
#
#    I _think_ that any reasonable data thrown here, will result
#    in the correct line being returned.
#
   if moving_line == "old_yang":
       return_line = "|"
   elif moving_line == "old_yin":
       return_line = "o"
   elif moving_line == "young_yang":
       return_line = "|"
   elif moving_line == "young_yin":
       return_line = "o"
   elif moving_line == "old yang":
       return_line = "|"
   elif moving_line == "old yin":
       return_line = "o"
   elif moving_line == "young yang":
       return_line = "|"
   elif moving_line == "young yin":
       return_line = "o"
   elif moving_line == "yin":
       return_line = "o"
   elif moving_line == "yang":
       return_line = "|"
   elif moving_line == "|":
       return_line = "|"
   elif moving_line == "o":
       return_line = "o"
   elif moving_line == 9:
       return_line = "|"
   elif moving_line == 8:
       return_line = "o"
   elif moving_line == 7:
       return_line = "|"
   elif moving_line == 6:
       return_line = "o"
   elif moving_line == 3:
       return_line = "|"
   elif moving_line == 2:
       return_line = "o"
   else:
       return_line = "*"
       print moving_line, " was not listed in moving_line_to_symbol "
   return return_line

#    trigram functions are below this line

def decipher_trigram( line_one, line_two, line_three ):
   if line_one == "*":
       return_trigram = "stardust"
       print line_one, line_two, line_three
       print "stardust"
   elif line_one == "o":
       if line_two == "o":
           if line_three == "o":
               return_trigram = "kun"
           else:
               return_trigram = "gen"
       else:
           if line_three == "o":
               return_trigram = "kan"
           else:
               return_trigram = "sun"
   else:
       if line_two == "o":
           if line_three == "o":
               return_trigram = "zhen"
           else:
               return_trigram = "li"
       else:
           if line_three == "o":
               return_trigram = "dui"
           else:
               return_trigram = "qian"
   return return_trigram

def golden_trigram( hexagram_lines ):
   check_line = reduce_bigram( hexagram_lines[1], hexagram_lines[2] )
   line_one = moving_line_to_symbol ( check_line )
   check_line = reduce_bigram( hexagram_lines[3], hexagram_lines[4] )
   line_two = moving_line_to_symbol ( check_line )
   check_line = reduce_bigram( hexagram_lines[5], hexagram_lines[6] )
   line_three = moving_line_to_symbol ( check_line )
   return_trigram = decipher_trigram( line_one, line_two, line_three )
   return return_trigram

def hexagram_family( hex_number ):
   if hex_number in ( 1, 44, 33, 12, 20, 23, 35, 14 ):
       return_trigram = "qian"
   elif hex_number in ( 29, 60, 3, 63, 49, 55, 36, 7 ):
       return_trigram = "kan"
   elif hex_number in (  52, 22, 26, 41, 38, 10, 61, 53 ):
       return_trigram = "gen"
   elif hex_number in ( 51, 16, 40, 32, 46, 48, 28, 17 ):
      return_trigram = "zhen"
   elif hex_number in ( 57, 9, 37, 42, 25, 21, 27, 18):
       return_trigram = "sun"
   elif hex_number in ( 30, 56, 50, 64, 4, 59, 6, 13):
       return_trigram = "li"
   elif hex_number in ( 2, 24, 19, 11, 34, 43, 5, 8):
       return_trigram = "kun"
   elif hex_number in ( 58, 47, 45, 31, 39, 15, 62, 54):
       return_trigram = "dui"
   else:
       return_trigram = "stardust"
       print hex_number
       print "stardust"
   return return_trigram

def trigrams_in_hexagram( hexagram_lines ):
#   print hexagram_lines
   line_six =   hexagram_lines[6]
   line_five =  hexagram_lines[5]
   line_four =  hexagram_lines[4]
   line_three = hexagram_lines[3]
   line_two =   hexagram_lines[2]
   line_one =   hexagram_lines[1]
   lower_trigram = decipher_trigram(line_one, line_two, line_three )
   upper_trigram = decipher_trigram(line_four, line_five, line_six )
   return lower_trigram, upper_trigram


####### hexagram functions are below this line  ##########################

def load_hexagram ( hex_number ):
#   print hex_number, " at load_hexagram "
   if hex_number > 64:
       hex_number = hex_number - 64
   elif hex_number < 1:
       hex_number = hex_number + 64
   hexagram_table = {
                 0 : ( 0,"*", "*", "*", "*", "*", "*"),
                 1 : ( 1,"|", "|", "|", "|", "|", "|"),
                 2 : ( 2,"o", "o", "o", "o", "o", "o"),
                 3 : ( 3,"|", "o", "o", "o", "|", "o"),
                 4 : ( 4,"o", "|", "o", "o", "o", "|"),
                 5 : ( 5,"|", "|", "|", "o", "|", "o"),
                 6 : ( 6,"o", "|", "o", "|", "|", "|"),
                 7 : ( 7,"o", "|", "o", "o", "o", "o"),
                 8 : ( 8,"o", "o", "o", "o", "|", "o"),
                 9 : ( 9,"|", "|", "|", "o", "|", "|"),
                10 : (10,"|", "|", "o", "|", "|", "|"),
                11 : (11,"|", "|", "|", "o", "o", "o"),
                12 : (12,"o", "o", "o", "|", "|", "|"),
                13 : (13,"|", "o", "|", "|", "|", "|"),
                14 : (14,"|", "|", "|", "|", "o", "|"),
                15 : (15,"o", "o", "|", "o", "o", "o"),
                16 : (16,"o", "o", "o", "|", "o", "o"),
                17 : (17,"|", "o", "o", "|", "|", "o"),
                18 : (18,"o", "|", "|", "o", "o", "|"),
                19 : (19,"|", "|", "o", "o", "o", "o"),
                20 : (20,"o", "o", "o", "o", "|", "|"),
                21 : (21,"|", "o", "o", "|", "o", "|"),
                22 : (22,"|", "o", "|", "o", "o", "|"),
                23 : (23,"o", "o", "o", "o", "o", "|"),
                24 : (24,"|", "o", "o", "o", "o", "o"),
                25 : (25,"|", "o", "o", "|", "|", "|"),
                26 : (26,"|", "|", "|", "o", "o", "|"),
                27 : (27,"|", "o", "o", "o", "o", "|"),
                28 : (28,"o", "|", "|", "|", "|", "o"),
                29 : (29,"o", "|", "o", "o", "|", "o"),
                30 : (30,"|", "o", "|", "|", "o", "|"),
                31 : (31,"o", "o", "|", "|", "|", "o"),
                32 : (32,"o", "|", "|", "|", "o", "o"),
                33 : (33,"o", "o", "|", "|", "|", "|"),
                34 : (34,"|", "|", "|", "|", "o", "o"),
                35 : (35,"o", "o", "o", "|", "o", "|"),
                36 : (36,"|", "o", "|", "o", "o", "o"),
                37 : (37,"|", "o", "|", "o", "|", "|"),
                38 : (38,"|", "|", "o", "|", "o", "|"),
                39 : (39,"o", "o", "|", "o", "|", "o"),
                40 : (40,"o", "|", "o", "|", "o", "o"),
                41 : (41,"|", "|", "o", "o", "o", "|"),
                42 : (42,"|", "o", "o", "o", "|", "|"),
                43 : (43,"|", "|", "|", "|", "|", "o"),
                44 : (44,"o", "|", "|", "|", "|", "|"),
                45 : (45,"o", "o", "o", "|", "|", "o"),
                46 : (46,"o", "|", "|", "o", "o", "o"),
                47 : (47,"o", "|", "o", "|", "|", "o"),
                48 : (48,"o", "|", "|", "o", "|", "o"),
                49 : (49,"|", "o", "|", "|", "|", "o"),
                50 : (50,"o", "|", "|", "|", "o", "|"),
                51 : (51,"|", "o", "o", "|", "o", "o"),
                52 : (52,"o", "o", "|", "o", "o", "|"),
                53 : (53,"o", "o", "|", "o", "|", "|"),
                54 : (54,"|", "|", "o", "|", "o", "o"),
                55 : (55,"|", "o", "|", "|", "o", "o"),
                56 : (56,"o", "o", "|", "|", "o", "|"),
                58 : (58,"|", "|", "o", "|", "|", "o"),
                57 : (57,"o", "|", "|", "o", "|", "|"),
                59 : (59,"o", "|", "o", "o", "|", "|"),
                60 : (60,"|", "|", "o", "o", "|", "o"),
                61 : (61,"|", "|", "o", "o", "|", "|"),
                62 : (62,"o", "o", "|", "|", "o", "o"),
                63 : (63,"|", "o", "|", "o", "|", "o"),
                64 : (64,"o", "|", "o", "|", "o", "|"),
                65 : (65, " line 1 ", " line 2 " , " line 3 ", " line 4 ", " line 5 " , " line 6 " )
           }
   try:
       return_hexagram_lines = hexagram_table[hex_number]
   except:
       return_hexagram_lines = ( 66, "*","*","*","*","*","*" )
       print hex_number, " was not found in hexagram_table "
#   if hex_number > 32:
#       print "hex_number was ", hex_number, " and successfully found"
   return return_hexagram_lines

def lines_of_hexagram( hexagram_number ):
   new_lines = ( "x", ".", ".", ".",  ".", ".", ".",  )
   check = load_hexagram( new_lines )
   hex_number = check[hexagram_number]
   return hex_number

def t_kun(lower_trigram):
   if lower_trigram == "kun":
       hexagram_number = 2
   elif lower_trigram == "gen":
       hexagram_number = 15
   elif lower_trigram == "kan":
       hexagram_number = 7
   elif lower_trigram == "sun":
       hexagram_number = 46
   elif lower_trigram == "zhen":
       hexagram_number = 24
   elif lower_trigram == "li":
       hexagram_number = 36
   elif lower_trigram == "dui":
       hexagram_number = 19
   elif lower_trigram == "qian":
       hexagram_number = 11
   else:
       hexagram_number = 70
   return hexagram_number

def t_qian(lower_trigram):
   if lower_trigram == "kun":
       hexagram_number = 12
   elif lower_trigram == "gen":
       hexagram_number = 33
   elif lower_trigram == "kan":
       hexagram_number = 6
   elif lower_trigram == "sun":
       hexagram_number = 44
   elif lower_trigram == "zhen":
       hexagram_number = 25
   elif lower_trigram == "li":
       hexagram_number = 13
   elif lower_trigram == "dui":
       hexagram_number = 10
   elif lower_trigram == "qian":
       hexagram_number = 1
   else:
       hexagram_number = 71
   return hexagram_number

def t_dui(lower_trigram):
   if lower_trigram == "kun":
       hexagram_number = 45
   elif lower_trigram == "gen":
       hexagram_number = 31
   elif lower_trigram == "kan":
       hexagram_number = 47
   elif lower_trigram == "sun":
       hexagram_number = 28
   elif lower_trigram == "zhen":
       hexagram_number = 17
   elif lower_trigram == "li":
       hexagram_number = 49
   elif lower_trigram == "dui":
       hexagram_number = 58
   elif lower_trigram == "qian":
       hexagram_number = 43
   else:
       hexagram_number = 72
   return hexagram_number

def t_li(lower_trigram):
   if lower_trigram == "kun":
       hexagram_number = 35
   elif lower_trigram == "gen":
       hexagram_number = 56
   elif lower_trigram == "kan":
       hexagram_number = 64
   elif lower_trigram == "sun":
       hexagram_number = 50
   elif lower_trigram == "zhen":
       hexagram_number = 21
   elif lower_trigram == "li":
       hexagram_number = 30
   elif lower_trigram == "dui":
       hexagram_number = 38
   elif lower_trigram == "qian":
       hexagram_number = 14
   else:
       hexagram_number = 73
   return hexagram_number

def t_zhen(lower_trigram):
   if lower_trigram == "kun":
       hexagram_number = 16
   elif lower_trigram == "gen":
       hexagram_number = 62
   elif lower_trigram == "kan":
       hexagram_number = 40
   elif lower_trigram == "sun":
       hexagram_number = 32
   elif lower_trigram == "zhen":
       hexagram_number = 51
   elif lower_trigram == "li":
       hexagram_number = 55
   elif lower_trigram == "dui":
       hexagram_number = 54
   elif lower_trigram == "qian":
       hexagram_number = 34
   else:
       hexagram_number = 74
   return hexagram_number

def t_sun(lower_trigram):
   if lower_trigram == "kun":
       hexagram_number = 20
   elif lower_trigram == "gen":
       hexagram_number = 53
   elif lower_trigram == "kan":
       hexagram_number = 59
   elif lower_trigram == "sun":
       hexagram_number = 57
   elif lower_trigram == "zhen":
       hexagram_number = 42
   elif lower_trigram == "li":
       hexagram_number = 37
   elif lower_trigram == "dui":
       hexagram_number = 61
   elif lower_trigram == "qian":
       hexagram_number = 9
   else:
       hexagram_number = 75
   return hexagram_number

def t_kan(lower_trigram):
   if lower_trigram == "kun":
       hexagram_number = 8
   elif lower_trigram == "gen":
       hexagram_number = 39
   elif lower_trigram == "kan":
       hexagram_number = 29
   elif lower_trigram == "sun":
       hexagram_number = 48
   elif lower_trigram == "zhen":
       hexagram_number = 3
   elif lower_trigram == "li":
       hexagram_number = 63
   elif lower_trigram == "dui":
       hexagram_number = 60
   elif lower_trigram == "qian":
       hexagram_number = 5
   else:
       hexagram_number = 76
   return hexagram_number

def t_gen(lower_trigram):
   if lower_trigram == "kun":
       hexagram_number = 23
   elif lower_trigram == "gen":
       hexagram_number = 52
   elif lower_trigram == "kan":
       hexagram_number = 4
   elif lower_trigram == "sun":
       hexagram_number = 18
   elif lower_trigram == "zhen":
       hexagram_number = 27
   elif lower_trigram == "li":
       hexagram_number = 22
   elif lower_trigram == "dui":
       hexagram_number = 41
   elif lower_trigram == "qian":
       hexagram_number = 26
   else:
       hexagram_number = 77
   return hexagram_number

def trigram_table( upper_trigram, lower_trigram ):
#   check = string.strip(upper_trigram)
#   upper_trigram = check
#   check = string.strip(lower_trigram)
#   lower_trigram = check
   if upper_trigram == "kun":
       hexagram_number = t_kun(lower_trigram)
   elif upper_trigram == "gen":
       hexagram_number = t_gen(lower_trigram)
   elif upper_trigram == "kan":
       hexagram_number = t_kan(lower_trigram)
   elif upper_trigram == "sun":
       hexagram_number = t_sun(lower_trigram)
   elif upper_trigram == "zhen":
       hexagram_number = t_zhen(lower_trigram)
   elif upper_trigram == "li":
       hexagram_number = t_li(lower_trigram)
   elif upper_trigram == "dui":
       hexagram_number = t_dui(lower_trigram)
   elif upper_trigram == "qian":
       hexagram_number = t_qian(lower_trigram)
   elif upper_trigram == "stardust":
       hexagram_number = 79
   else:
       hexagram_number = 78
   return hexagram_number

def get_hexagram_number( hexagram_lines ):
   lower_trigram, upper_trigram = trigrams_in_hexagram( hexagram_lines )
   hexagram_number = trigram_table( upper_trigram, lower_trigram )
   return hexagram_number

def decipher_hexagram(hexagram_lines):
   line_1 = hexagram_lines[1]
   line_2 = hexagram_lines[2]
   line_3 = hexagram_lines[3]
   line_4 = hexagram_lines[4]
   line_5 = hexagram_lines[5]
   line_6 = hexagram_lines[6]
   hex_number = get_hexagram_number( hexagram_lines )
   return_hexagram = ( hex_number, line_1, line_2, line_3, line_4, line_5, line_6 )
   return return_hexagram

def inverse_hexagram( hexagram_lines ):
   new_lines = ( 0, hexagram_lines[6], hexagram_lines[5], hexagram_lines[4], hexagram_lines[3], hexagram_lines[2], hexagram_lines[1] )
   this_lines = decipher_hexagram( new_lines )
   return this_lines

def reverse_line( hexagram_line ):
   if hexagram_line == "|":
       new_line = "o"
   elif hexagram_line == "o":
       new_line = "|"
   else:
       new_line = "x"
   return new_line

def reverse_hexagram( hexagram_lines ):
   new_line_1 = reverse_line(hexagram_lines[1])
   new_line_2 = reverse_line(hexagram_lines[2])
   new_line_3 = reverse_line(hexagram_lines[3])
   new_line_4 = reverse_line(hexagram_lines[4])
   new_line_5 = reverse_line(hexagram_lines[5])
   new_line_6 = reverse_line(hexagram_lines[6])
   new_lines = ( 0, new_line_1,new_line_2,new_line_3,new_line_4,new_line_5,new_line_6 )
   this_lines = decipher_hexagram( new_lines )
   return this_lines

def nuclear_hexagram( hexagram_lines ):
   new_lines = ( 0, hexagram_lines[2], hexagram_lines[3],hexagram_lines[4], hexagram_lines[3],hexagram_lines[4],hexagram_lines[5] )
   this_lines = decipher_hexagram( new_lines )
   return this_lines

def golden_hexagram( hexagram_lines ):
   new_lines = ( 0, hexagram_lines[3], hexagram_lines[4], hexagram_lines[3], hexagram_lines[4], hexagram_lines[3], hexagram_lines[4] )
   this_lines = decipher_hexagram( new_lines )
   return  this_lines

def interlaced_hexagram( hexagram_lines ):
   new_lines = ( 0, hexagram_lines[1], hexagram_lines[3], hexagram_lines[5], hexagram_lines[2], hexagram_lines[4], hexagram_lines[6]  )
   this_lines = decipher_hexagram( new_lines )
   return this_lines

def evolved_hexagram( hexagram_lines ):
   line_one = hexagram_lines[1]
   line_two = hexagram_lines[2]
   line_three = hexagram_lines[3]
   line_four = hexagram_lines[4]
   line_five = hexagram_lines[5]
   line_six = hexagram_lines[6]
   new_lines = ( 0, line_six, line_one, line_two, line_three, line_four, line_five )
   this_lines = decipher_hexagram ( new_lines )
   return this_lines

def axillary_hexagram ( hexagram_lines, line_number ):
   line_one = hexagram_lines[1]
   line_two = hexagram_lines[2]
   line_three = hexagram_lines[3]
   line_four = hexagram_lines[4]
   line_five = hexagram_lines[5]
   line_six = hexagram_lines[6]
   if line_number == 1:
       line_one = reverse_line(line_one)
   elif line_number == 2:
       line_two = reverse_line(line_two)
   elif line_number == 3:
       line_three = reverse_line(line_three)
   elif line_number == 4:
       line_four = reverse_line(line_four)
   elif line_number == 5:
       line_five = reverse_line(line_five)
   elif line_number == 6:
       line_six = reverse_line(line_six)
   new_lines = ( 0, line_one, line_two, line_three, line_four, line_five, line_six )
   this_lines = decipher_hexagram ( new_lines )
   return this_lines

def wen_next_hexagram( hex_number ):
   hex_number = hex_number + 1
   if hex_number == "65":
       hex_number = "1"
   this_lines = load_hexagram(hex_number)
   return this_lines

def wen_prior_hexagram( hex_number ):
   hex_number = hex_number - 1
   if hex_number == "0":
       hex_number = "64"
   this_lines = load_hexagram(hex_number)
   return this_lines

def fuxi_prior_hexagram( hex_number ):
#   print hex_number, " is fuxi_prior_hexagram at the begining "
   check_hexagram = convert_to_fuxi_sequence( hex_number )
   fuxi_number = check_hexagram[0]
   fuxi_number = fuxi_number - 1
#   print fuxi_number, " is the coverted fuxi hexagram number "
   check_hexagram = convert_from_fuxi_sequence( fuxi_number )
#   print check_hexagram, " is fuxi_prior_hexagram "
   return check_hexagram

def fuxi_next_hexagram( hex_number ):
   check_hexagram = convert_to_fuxi_sequence( hex_number )
   fuxi_number = check_hexagram[0]
   fuxi_number = fuxi_number + 1
   check_hexagram = convert_from_fuxi_sequence( fuxi_number )
   return check_hexagram

def convert_from_fuxi_sequence( hex_number ):
#   fuxi sequence : king wen arrangement
#   print hex_number, " is the fuxi sequence number "
   if hex_number > 64:
       hex_number = hex_number - 64
   elif hex_number < 1:
       hex_number = hex_number + 64
#   print hex_number, " this is see if my error trapping does anything strange"
   hexagram_table = {
                 1 :  2,
                 2 : 23,
                 3 :  8,
                 4 : 20,
                 5 : 16,
                 6 : 35,
                 7 : 45,
                 8 : 12,
                 9 : 15,
                10 : 52,
                11 : 39,
                12 : 53,
                13 : 62,
                14 : 56,
                15 : 31,
                16 : 33,
                17 : 7,
                18 : 4,
                19 : 29,
                20 : 59,
                21 : 40,
                22 : 64,
                23 : 47,
                24 : 6,
                25 : 46,
                26 : 18,
                27 : 48,
                28 : 57,
                29 : 32,
                30 : 50,
                31 : 28,
                32 : 44,
                33 : 24,
                34 : 27,
                35 : 3,
                36 : 42,
                37 : 51,
                38 : 21,
                39 : 17,
                40 : 25,
                41 : 36,
                42 : 22,
                43 : 63,
                44 : 37,
                45 : 55,
                46 : 30,
                47 : 49,
                48 : 13,
                49 : 19,
                50 : 41,
                51 : 60,
                52 : 61,
                53 : 54,
                54 : 38,
                55 : 58,
                56 : 10,
                57 : 11,
                58 : 26,
                59 :  5,
                60 :  9,
                61 : 34,
                62 : 14,
                63 : 43,
                64 :  1
               }
   try:
       new_hexagram = hexagram_table[hex_number]
   except:
       new_hexagram = 70
#   print new_hexagram, " is the new_hexagram number "
   return_hexagram = load_hexagram(new_hexagram)
#   print return_hexagram
   return return_hexagram

def convert_to_fuxi_sequence( hex_number ):
#    king wen arrangement : fuxi arrangement
   if hex_number > 64:
       hex_number = hex_number - 64
   elif hex_number < 1:
       hex_number = hex_number + 64
   hexagram_table = {
                      2 :  1,
                     23 :  2,
                      8 :  3,
                     20 :  4,
                     16 :  5,
                     35 :  6,
                     45 :  7,
                     12 :  8,
                     15 :  9,
                     52 : 10,
                     39 : 11,
                     53 : 12,
                     62 : 13,
                     56 : 14,
                     31 : 15,
                     33 : 16,
                      7 : 17,
                      4 : 18,
                     29 : 19,
                     59 : 20,
                     40 : 21,
                     64 : 22,
                     47 : 23,
                      6 : 24,
                     46 : 25,
                     18 : 26,
                     48 : 27,
                     57 : 28,
                     32 : 29,
                     50 : 30,
                     28 : 31,
                     44 : 32,
                     24 : 33,
                     27 : 34,
                      3 : 35,
                     42 : 36,
                     51 : 37,
                     21 : 38,
                     17 : 39,
                     25 : 40,
                     36 : 41,
                     22 : 42,
                     63 : 43,
                     37 : 44,
                     55 : 45,
                     30 : 46,
                     49 : 47,
                     13 : 48,
                     19 : 49,
                     41 : 50,
                     60 : 51,
                     61 : 52,
                     54 : 53,
                     38 : 54,
                     58 : 55,
                     10 : 56,
                     11 : 57,
                     26 : 58,
                      5 : 59,
                      9 : 60,
                     34 : 61,
                     14 : 62,
                     43 : 63,
                      1 : 64
                    }
   try:
       new_hexagram = hexagram_table[hex_number]
   except:
       new_hexagram = 70
   return_hexagram = load_hexagram(new_hexagram)
   return return_hexagram

def mawangdui_prior_hexagram( hex_number ):
   check_hexagram = convert_to_mawangdui_sequence( hex_number )
   mawangdui_number = check_hexagram[0]
   mawangdui_number = mawangdui_number - 1
   check_hexagram = convert_from_mawangdui_sequence( mawangdui_number )
   return check_hexagram

def mawangdui_next_hexagram( hex_number ):
   check_hexagram = convert_to_mawangdui_sequence( hex_number )
   mawangdui_number = check_hexagram[0]
   mawangdui_number = mawangdui_number + 1
   check_hexagram = convert_from_mawangdui_sequence( mawangdui_number )
   return check_hexagram

def convert_to_mawangdui_sequence( hex_number ):
   # king wen sequence :  mawangdui sequence
   if hex_number > 64:
       hex_number = hex_number - 64
   elif hex_number < 1:
       hex_number = hex_number + 64
   hexagram_table = {
                       1 :  1,
                      12 :  2,
                      33 :  3,
                      10 :  4,
                       6 :  5,
                      13 :  6,
                      25 :  7,
                      44 :  8,
                      52 :  9,
                      26 : 10,
                      23 : 11,
                      41 : 12,
                       4 : 13,
                      22 : 14,
                      27 : 15,
                      18 : 16,
                      29 : 17,
                       5 : 18,
                       8 : 19,
                      39 : 20,
                      60 : 21,
                      63 : 22,
                       3 : 23,
                      48 : 24,
                      51 : 25,
                      34 : 26,
                      16 : 27,
                      62 : 28,
                      54 : 29,
                      40 : 30,
                      55 : 31,
                      32 : 32,
                       2 : 33,
                      11 : 34,
                      15 : 35,
                      19 : 36,
                       7 : 37,
                      36 : 38,
                      24 : 39,
                      46 : 40,
                      58 : 41,
                      43 : 42,
                      45 : 43,
                      31 : 44,
                      47 : 45,
                      49 : 46,
                      17 : 47,
                      28 : 48,
                      30 : 49,
                      14 : 50,
                      35 : 51,
                      56 : 52,
                      38 : 53,
                      64 : 54,
                      21 : 55,
                      50 : 56,
                      57 : 57,
                       9 : 58,
                      20 : 59,
                      53 : 60,
                      61 : 61,
                      59 : 62,
                      37 : 63,
                      42 : 64,
                       1 :  1
                       }
   try:
       new_hexagram = hexagram_table[hex_number]
   except:
       new_hexagram = 70
   return_hexagram = load_hexagram(new_hexagram)
   return return_hexagram

def convert_from_mawangdui_sequence(hex_number):
#    mawangui_sequence : king wen sequence
   if hex_number > 64:
       hex_number = hex_number - 64
   elif hex_number < 1:
       hex_number = hex_number + 64
   hexagram_table = {
                      1 : 1,
                      2 : 12,
                      3 : 33,
                      4 : 10,
                      5 : 6,
                      6 : 13,
                      7 : 25,
                      8 : 44,
                      9 : 52,
                     10 : 26,
                     11 : 23,
                     12 : 41,
                     13 : 4,
                     14 : 22,
                     15 : 27,
                     16 : 18,
                     17 : 29,
                     18 : 5,
                     19 : 8,
                     20 : 39,
                     21 : 60,
                     22 : 63,
                     23 : 3,
                     24 : 48,
                     25 : 51,
                     26 : 34,
                     27 : 16,
                     28 : 62,
                     29 : 54,
                     30 : 40,
                     31 : 55,
                     32 : 32,
                     33 : 2,
                     34 : 11,
                     35 : 15,
                     36 : 19,
                     37 : 7,
                     38 : 36,
                     39 : 24,
                     40 : 46,
                     41 : 58,
                     42 : 43,
                     43 : 45,
                     44 : 31,
                     45 : 47,
                     46 : 49,
                     47 : 17,
                     48 : 28,
                     49 : 30,
                     50 : 14,
                     51 : 35,
                     52 : 56,
                     53 : 38,
                     54 : 64,
                     55 : 21,
                     56 : 50,
                     57 : 57,
                     58 : 9,
                     59 : 20,
                     60 : 53,
                     61 : 61,
                     62 : 59,
                     63 : 37,
                     64 : 42,
                      1 : 1
                    }
   try:
       new_hexagram = hexagram_table[hex_number]
   except:
       new_hexagram = 70
   return_hexagram = load_hexagram(new_hexagram)
   return return_hexagram

def convert_from_base_trigram_sequence(hex_number):
#    base_trigram_sequence : king wen sequence
   if hex_number > 64:
       hex_number = hex_number - 64
   elif hex_number < 1:
       hex_number = hex_number + 64
   hexagram_table = {
                      1 :  1,
                      2 : 44,
                      3 : 13,
                      4 : 33,
                      5 : 10,
                      6 :  6,
                      7 : 25,
                      8 : 12,
                      9 :  9,
                     10 : 57,
                     11 : 37,
                     12 : 53,
                     13 : 61,
                     14 : 59,
                     15 : 42,
                     16 : 20,
                     17 : 14,
                     18 : 50,
                     19 : 30,
                     20 : 56,
                     21 : 38,
                     22 : 64,
                     23 : 21,
                     24 : 35,
                     25 : 26,
                     26 : 18,
                     27 : 22,
                     28 : 52,
                     29 : 41,
                     30 :  4,
                     31 : 27,
                     32 : 23,
                     33 : 43,
                     34 : 28,
                     35 : 49,
                     36 : 31,
                     37 : 58,
                     38 : 47,
                     39 : 17,
                     40 : 45,
                     41 :  5,
                     42 : 48,
                     43 : 63,
                     44 : 39,
                     45 : 60,
                     46 : 29,
                     47 :  3,
                     48 :  8,
                     49 : 34,
                     50 : 32,
                     51 : 55,
                     52 :  6,
                     53 : 54,
                     54 : 40,
                     55 : 51,
                     56 : 16,
                     57 : 11,
                     58 : 46,
                     59 : 36,
                     60 : 15,
                     61 : 19,
                     62 :  7,
                     63 : 24,
                     64 : 12
                     }
   try:
       new_hexagram = hexagram_table[hex_number]
   except:
       new_hexagram = 70
   return_hexagram = load_hexagram(new_hexagram)
   return return_hexagram

def convert_to_base_trigram_sequence(hex_number):
#  king wen sequence : base_trigram_sequence
   if hex_number > 64:
       hex_number = hex_number - 64
   elif hex_number < 1:
       hex_number = hex_number + 64
   hexagram_table = {
                     1 :  1,
                    44 :  2,
                    13 :  3,
                    33 :  4,
                    10 :  5,
                     6 :  6,
                    25 :  7,
                    12 :  8,
                     9 :  9,
                    57 : 10,
                    37 : 11,
                    53 : 12,
                    61 : 13,
                    59 : 14,
                    42 : 15,
                    20 : 16,
                    14 : 17,
                    50 : 18,
                    30 : 19,
                    56 : 20,
                    38 : 21,
                    64 : 22,
                    21 : 23,
                    35 : 24,
                    26 : 25,
                    18 : 26,
                    22 : 27,
                    52 : 28,
                    41 : 29,
                     4 : 30,
                    27 : 31,
                    23 : 32,
                    43 : 33,
                    28 : 34,
                    49 : 35,
                    31 : 36,
                    58 : 37,
                    47 : 38,
                    17 : 39,
                    45 : 40,
                     5 : 41,
                    48 : 42,
                    63 : 43,
                    39 : 44,
                    60 : 45,
                    29 : 46,
                     3 : 47,
                     8 : 48,
                    34 : 49,
                    32 : 50,
                    55 : 51,
                     6 : 52,
                    54 : 53,
                    40 : 54,
                    51 : 55,
                    16 : 56,
                    11 : 57,
                    46 : 58,
                    36 : 59,
                    15 : 60,
                    19 : 61,
                     7 : 62,
                    24 : 63,
                    12 : 64
                   }
   try:
       new_hexagram = hexagram_table[hex_number]
   except:
       new_hexagram = 70
   return_hexagram = load_hexagram(new_hexagram)
   return return_hexagram

def base_prior_hexagram( hex_number ):
   check_hexagram = convert_to_base_trigram_sequence( hex_number )
   base_number = check_hexagram[0]
   base_number = base_number - 1
   check_hexagram = convert_from_base_trigram_sequence( base_number )
   return check_hexagram

def base_next_hexagram( hex_number ):
   check_hexagram = convert_to_base_trigram_sequence( hex_number )
   base_number = check_hexagram[0]
   base_number = base_number + 1
   check_hexagram = convert_from_base_trigram_sequence( base_number )
   return check_hexagram

### The following hexagrams are derivatives that _might_ be useful ####
#
#    C    : cast hexagram
#    The number refers to the top line number of the trigram
#    The first number refers to the upper trigram
#    The second number refers to the lower trigram
#

def c6c3( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[1], hexagram_lines[2], hexagram_lines[3], hexagram_lines[4], hexagram_lines[5], hexagram_lines[6] )
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c6c4( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[2], hexagram_lines[3], hexagram_lines[4], hexagram_lines[4], hexagram_lines[5], hexagram_lines[6] )
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c6c5( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[3], hexagram_lines[4], hexagram_lines[5], hexagram_lines[4], hexagram_lines[5], hexagram_lines[6] )
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c6c6( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[4], hexagram_lines[5], hexagram_lines[6], hexagram_lines[4], hexagram_lines[5], hexagram_lines[6] )
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c5c6( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[4], hexagram_lines[5], hexagram_lines[6], hexagram_lines[3], hexagram_lines[4], hexagram_lines[5])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c5c5( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[3], hexagram_lines[4], hexagram_lines[5], hexagram_lines[3], hexagram_lines[4], hexagram_lines[5])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c5c4(hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[2], hexagram_lines[3], hexagram_lines[4], hexagram_lines[3], hexagram_lines[4], hexagram_lines[5])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c5c3( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[1], hexagram_lines[2], hexagram_lines[3], hexagram_lines[3], hexagram_lines[4], hexagram_lines[5])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c4c6( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[4], hexagram_lines[5], hexagram_lines[6], hexagram_lines[2], hexagram_lines[3], hexagram_lines[4])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c4c5( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[3], hexagram_lines[4], hexagram_lines[5], hexagram_lines[2], hexagram_lines[3], hexagram_lines[4])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c4c4( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[2], hexagram_lines[3], hexagram_lines[4], hexagram_lines[2], hexagram_lines[3], hexagram_lines[4])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c4c3( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[1], hexagram_lines[2], hexagram_lines[3], hexagram_lines[2], hexagram_lines[3], hexagram_lines[4])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c3c6( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[4], hexagram_lines[5], hexagram_lines[6], hexagram_lines[1], hexagram_lines[2], hexagram_lines[3])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c3c5( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[3], hexagram_lines[4], hexagram_lines[5], hexagram_lines[1], hexagram_lines[2], hexagram_lines[3])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c3c4( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[2], hexagram_lines[3], hexagram_lines[4], hexagram_lines[1], hexagram_lines[2], hexagram_lines[3])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def c3c3( hexagram_lines ):
   new_hexagram = ( 0, hexagram_lines[1], hexagram_lines[2], hexagram_lines[3], hexagram_lines[1], hexagram_lines[2], hexagram_lines[3])
   new_hexagram = decipher_hexagram( new_hexagram )
   return new_hexagram

def display_all_hexagram_data( hexagram_lines ):
#   print "displaying data at display_all_data "
   this_hexagram = hexagram_lines
   hex_number = this_hexagram[0]
#   print this_hexagram, " is this_hexagram"
#   print hex_number , " is hex_number "
   inverse = inverse_hexagram(this_hexagram)
#   print inverse , " is  inverse hexagram "
   reverse = reverse_hexagram(this_hexagram)
#   print reverse , " is  reverse hexagram "
   nuclear = nuclear_hexagram(this_hexagram)
#   print nuclear , " is  nuclear hexagram "
   golden = golden_hexagram( this_hexagram )
#   print golden , " is  golden hexagram "
   axillary_one = axillary_hexagram( this_hexagram, 1)
#   print axillary_one , " is  axillary_one hexagram "
   axillary_two = axillary_hexagram( this_hexagram, 2)
#   print axillary_two , " is  axillary_two hexagram "
   axillary_three = axillary_hexagram( this_hexagram, 3)
#   print axillary_three , " is  axillary_three hexagram "
   axillary_four = axillary_hexagram( this_hexagram, 4)
#   print axillary_four , " is  axillary_four hexagram "
   axillary_five = axillary_hexagram( this_hexagram, 5)
#   print axillary_five , " is  axillary_five hexagram "
   axillary_six = axillary_hexagram( this_hexagram, 6)
#   print axillary_six , " is  axillary_six hexagram "
   interlaced = interlaced_hexagram(this_hexagram)
#   print interlaced, " is  interlaced hexagram "
   evolved = evolved_hexagram(this_hexagram)
#   print evolved , " is  evolved hexagram "
   wen_prior = wen_prior_hexagram(hex_number)
#   print wen_prior , " is  wen_prior hexagram "
   wen_next = wen_next_hexagram(hex_number)
#   print wen_next , " is  wen_next hexagram "
   mawangdui_prior = mawangdui_prior_hexagram(hex_number)
#   print mawangdui_prior , " is  mawangdui_prior hexagram "
   mawangdui_next = mawangdui_next_hexagram(hex_number)
#   print mawangdui_next , " is  mawangdui_next hexagram "
   fu_prior = fuxi_prior_hexagram(hex_number)
#   print fu_prior , " is  fu_prior hexagram "
   fu_next = fuxi_next_hexagram(hex_number)
#   print fu_next , " is  fu_next hexagram "
   base_prior = base_prior_hexagram(hex_number)
#   print base_prior , " is  base_prior hexagram "
   base_next = base_next_hexagram(hex_number)
#   print base_next , " is  base_next hexagram "
   print this_hexagram[0], inverse[0], reverse[0], nuclear[0], golden[0], evolved[0], interlaced[0], axillary_one[0], axillary_two[0], axillary_three[0], axillary_four[0], axillary_five[0], axillary_six[0], wen_prior[0], wen_next[0], fu_prior[0], fu_next[0], mawangdui_prior[0], mawangdui_next[0], base_prior[0], base_next[0]
   print "H# In Re Nu Go Ev It A1 A2 A3 A4 A5 A6 WP WN FP FN MP MN BP BN "
   string_hex_1 = ( this_hexagram[0], inverse[0], reverse[0], nuclear[0], golden[0], evolved[0], interlaced[0], axillary_one[0], axillary_two[0], axillary_three[0], axillary_four[0], axillary_five[0], axillary_six[0], wen_prior[0], wen_next[0], fu_prior[0], fu_next[0], mawangdui_prior[0], mawangdui_next[0], base_prior[0], base_next[0] )


   c6c6_hexagram = c6c6(hexagram_lines)
   c6c5_hexagram = c6c5(hexagram_lines)
   c6c4_hexagram = c6c4(hexagram_lines)
   c6c3_hexagram = c6c3(hexagram_lines)
   c5c6_hexagram = c5c6(hexagram_lines)
   c5c5_hexagram = c5c5(hexagram_lines)
   c5c4_hexagram = c5c4(hexagram_lines)
   c5c3_hexagram = c5c3(hexagram_lines)
   c4c6_hexagram = c4c6(hexagram_lines)
   c4c5_hexagram = c4c5(hexagram_lines)
   c4c4_hexagram = c4c4(hexagram_lines)
   c4c3_hexagram = c4c3(hexagram_lines)
   c3c6_hexagram = c3c6(hexagram_lines)
   c3c5_hexagram = c3c5(hexagram_lines)
   c3c4_hexagram = c3c4(hexagram_lines)
   c3c3_hexagram = c3c3(hexagram_lines)
   print c6c6_hexagram[0] , c6c5_hexagram[0] , c6c4_hexagram[0] , c6c3_hexagram[0] , c5c6_hexagram[0] , c5c5_hexagram[0] , c5c4_hexagram[0] , c5c3_hexagram[0] , c4c6_hexagram[0] , c4c5_hexagram[0] , c4c4_hexagram[0] , c4c3_hexagram[0] , c3c6_hexagram[0] , c3c5_hexagram[0] , c3c4_hexagram[0] , c3c3_hexagram[0]
   print "66 65 64 63 56 55 54 53 46 45 44 43 36 35 34 33 "
   string_hex_2 = ( c6c6_hexagram[0] , c6c5_hexagram[0] , c6c4_hexagram[0] , c6c3_hexagram[0] , c5c6_hexagram[0] , c5c5_hexagram[0] , c5c4_hexagram[0] , c5c3_hexagram[0] , c4c6_hexagram[0] , c4c5_hexagram[0] , c4c4_hexagram[0] , c4c3_hexagram[0] , c3c6_hexagram[0] , c3c5_hexagram[0] , c3c4_hexagram[0] , c3c3_hexagram[0] )
   string_hexagram = ( string_hex_1 + string_hex_2 )
   print string_hexagram

   print this_hexagram[0], inverse[0], reverse[0], nuclear[0], golden[0], evolved[0], interlaced[0], axillary_one[0], axillary_two[0], axillary_three[0], axillary_four[0], axillary_five[0], axillary_six[0], wen_prior[0], wen_next[0], fu_prior[0], fu_next[0], mawangdui_prior[0], mawangdui_next[0], base_prior[0], base_next[0],c6c6_hexagram[0] , c6c5_hexagram[0] , c6c4_hexagram[0] , c6c3_hexagram[0] , c5c6_hexagram[0] , c5c5_hexagram[0] , c5c4_hexagram[0] , c5c3_hexagram[0] , c4c6_hexagram[0] , c4c5_hexagram[0] , c4c4_hexagram[0] , c4c3_hexagram[0] , c3c6_hexagram[0] , c3c5_hexagram[0] , c3c4_hexagram[0] , c3c3_hexagram[0]
   print "H# In Re Nu Go Ev It A1 A2 A3 A4 A5 A6 WP WN FP FN MP MN BP BN c66 c65 c64 c63 c56 c55 c54 c53 c46 c45 c44 c43 c36 c35 c34 c33 "
   return string_hexagram

def display_all_trigram_data( hexagram_lines ):

   lower_trigram, upper_trigram = trigrams_in_hexagram( hexagram_lines )
   nuclear = nuclear_hexagram( hexagram_lines )
   nuclear_lower_trigram, nuclear_upper_trigram = trigrams_in_hexagram( nuclear )
   interlaced = interlaced_hexagram( hexagram_lines )
   interlaced_lower_trigram, interlaced_upper_trigram = trigrams_in_hexagram( interlaced )
   golden = golden_trigram( hexagram_lines )
   hex_family = hexagram_family( hexagram_lines[0] )
   nuclear_hex_family = hexagram_family( nuclear[0] )
   interlaced_hex_family = hexagram_family( interlaced[0] )
   space = " "
   print hexagram_lines[0], space , upper_trigram, space ,lower_trigram, space, nuclear_upper_trigram, space , nuclear_lower_trigram, space , interlaced_upper_trigram, space , interlaced_lower_trigram, space , golden, space , hex_family, space , nuclear_hex_family, space , interlaced_hex_family
   print "UT, LT, NUT, NLT, IUT, ILT, GT,   HF,   NF,   IF"
   trigram_string = ( hexagram_lines[0], upper_trigram, nuclear_upper_trigram, nuclear_lower_trigram, interlaced_upper_trigram, interlaced_lower_trigram, golden, hex_family, nuclear_hex_family, interlaced_hex_family )
   return trigram_string

def run_a_hexagram( hex_number ):
   this_hexagram = load_hexagram(hex_number)
   hexagram_string = display_all_hexagram_data(this_hexagram)
   trigram_string = display_all_trigram_data(this_hexagram)
   return hexagram_string, trigram_string

def run_through_the_hexagrams( hex_number ):
   kounter = 0
   for kounter in range(65):
       hex_number = kounter
       this_hexagram = load_hexagram(hex_number)
       check = display_all_hexagram_data(this_hexagram)
       print check
   print "H# In Re Nu Go Ev It A1 A2 A3 A4 A5 A6 WP WN FP FN MP MN BP BN c66 c65 c64 c63 c56 c55 c54 c53 c46 c45 c44 c43 c36 c35 c34 c33 "
   kounter = 0
   for kounter in range(65):
       hex_number = kounter
       this_hexagram = load_hexagram(hex_number)
       check = display_all_trigram_data(this_hexagram)
       print check
   print "Hexagram #, UT, LT, NUT, NLT, IUT, ILT, GT,   HF,   NF,   IF"
   return


check = 61
hexagram_copyright( check ):
run_through_the_hexagrams( check )
hexagram_string, trigram_string = run_a_hexagram(check)
print hexagram_string
print trigram_string

print "Program is complete"
check = """

          Hexagram.py Version 0.0.0.2
          Copyright 2001: Jonathon Blake
          Distribution governed by the GNU General Public Licence

          This module provides basic hexagram and trigram deconstruction,
          for study of the Yi Jing.

          """
print check