Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need emergency help with Huffman encoding please!!!

Status
Not open for further replies.

gh787

Programmer
Apr 17, 2006
4
US
I am attempting to build a Huffman encoding package and need help with building the tree and then encoding a text file to a compressed state. Can anyone assist me please? Thanks in advance.
 
Which version of Fortran are you using?

There are a several ways of coding a tree, depending on which version of Fortran you're using. Say you want to code a tree like this where each node can have two children

1) If you are using F77, there are no structures so use a 2D array. eg
Code:
      parameter (nodemax = 100)
      parameter (ixLeft = 1, ixRight = 2, ixData = 3)
      integer itree(nodemax, ixData)
2) If you are using F90, there are structures but they cannot be allocated dynamically
Code:
      parameter (nodemax = 100)
      type::Node
         integer:: ixLeft
         integer:: ixRIght
         ...  ! the data
      end type Node

      type(Node), dimension(nodemax):: itree
3) If you are using F95, the structures can be allocated automatically
Code:
      type::Node
          type (Node), pointer:: ptrLeft
          type (Node), pointer:: ptrRight
          ... ! the data
      end type Node

      type (Node):: root
 
I am sorry. I'm using Fortran 90/95
 
Dynamic memory allocation has its own breed of problems. eg when assigning pointers, if you use = instead of => the compiler doesn't moan but the program doesn't work.

Use the Fortran 90 structure to start with. When you've got the algorithm working then you can try the Fortran 95 structure. Keep a count of how many nodes you have used and when you need a new one just increment the count.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top