ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c write_mseed_internal.for
c Internal variables for writing Mini-SEED.
c
c DO NOT INCLUDE THIS FILE IN YOUR MAIN PROGRAM!!!
c
c Author: Rodrigo Canabrava
c Email:  rlpcfr@yahoo.com.br
c Universitetet i Bergen - Department of Earth Sciences
c
c  changes
c
c  dec 21 2005 jh    add seed_pc
c  mar 22 2006 jh    add force_len
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 

c MAX_BLK_SIZE must be at most the size of the variable seed_record

      INTEGER*4 BLK_SIZE        ! block size
      INTEGER*4 MAX_BLK_SIZE    ! maximum block size
      PARAMETER (MAX_BLK_SIZE = 4096)

cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c Data Record
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      character*4096 seed_record

      common / miniseed_data_record / seed_record, BLK_SIZE, length_

      character*6    seq_number ! block sequence number
      character      header_type ! header type
      character      continuation ! continuation code
      character*5    station_   ! station name
      character*2    location_  ! location id
      character*3    channel_   ! channel name
      character*2    network_   ! network id
      integer*2      year_      ! year
      integer*2      day_of_year_ ! day of year
      character*1    hour_      ! hour
      character*1    minute_    ! minute
      character*1    second_    ! second
      integer*2      fracsec_   ! fraction of seconds
      integer*2      n_samples  ! number of samples
      integer*2      sample_rate_factor ! sample rate factor
      integer*2      sample_rate_multiplier ! sample rate multiplier
      character*1    activity_flags ! activity flags
      character*1    io_flags   ! io flags
      character*1    quality_flags ! quality flags
      character*1    n_blockettes ! number of blockettes
      integer*4      time_correction ! time correction
      integer*2      data_p     ! pointer to data
      integer*2      first_blk  ! pointer to first blockette
      integer*2      blk_type_1000 ! field of blockette type
      integer*2      next_1000  ! pointer to next blockette
      character*1    encoding_  ! encoding format
      character*1    rec_length ! record length
      character*1    byte_order ! byte order
      logical        seed_pc    ! true if on pc platform
      logical        force_len  ! true if write litte endian

      integer*2 length_          ! block length as power of 2

      equivalence(seed_record(1:6), seq_number)
      equivalence(seed_record(7:7), header_type)
      equivalence(seed_record(8:8), continuation)
      equivalence(seed_record(9:13), station_)
      equivalence(seed_record(14:15), location_)
      equivalence(seed_record(16:18), channel_)
      equivalence(seed_record(19:20), network_)
      equivalence(seed_record(21:22), year_)
      equivalence(seed_record(23:24), day_of_year_)
      equivalence(seed_record(25:25), hour_)
      equivalence(seed_record(26:26), minute_)
      equivalence(seed_record(27:27), second_)
c     reserved byte skipped: seed_record(28)
      equivalence(seed_record(29:30), fracsec_)
      equivalence(seed_record(31:32), n_samples)
      equivalence(seed_record(33:34), sample_rate_factor)
      equivalence(seed_record(35:36), sample_rate_multiplier)
      equivalence(seed_record(37:37), activity_flags)
      equivalence(seed_record(38:38), io_flags)
      equivalence(seed_record(39:39), quality_flags)
      equivalence(seed_record(40:40), n_blockettes)
      equivalence(seed_record(41:44), time_correction)
      equivalence(seed_record(45:46), data_p)
      equivalence(seed_record(47:48), first_blk)
      equivalence(seed_record(49:50), blk_type_1000)
      equivalence(seed_record(51:52), next_1000)
      equivalence(seed_record(53:53), encoding_)
      equivalence(seed_record(54:54), byte_order)
      equivalence(seed_record(55:55), rec_length)

ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c Control variables of DFA
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

      integer*4 FRAMESIZE       ! number of words in frame
      PARAMETER (FRAMESIZE = 16)

      integer*4 w0              ! encoding info of frame
      integer*4 f_count         ! number of current frame
      integer*4 f_pos           ! position of word in frame
      integer*4 n               ! number of compressed samples
      integer*4 diff(4)         ! buffer with differences on the limbo
      integer*2 state           ! current state of DFA

      common / DFA / diff, w0, f_count, f_pos, n, state, seed_pc,
     *               force_len

ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c Time variables really used inside the writing routines.
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

      integer*2      year ! year
      integer*2      doy ! day of year
      integer*2      hour ! hour
      integer*2      minute ! minute
      integer*2      second ! second
      integer*2      fracsec ! fraction of second

      integer*2 encoding ! encoding format

      COMMON / mseed_param_intern / year, doy, hour, minute, second, 
     &     fracsec, encoding
