Skip Navigation Links 
NOAA logo - Click to go to the NOAA homepage National Weather Service   NWS logo - Click to go to the NWS homepage
National Centers for Environmental Prediction
Navigation Bar Left Cap
Navigation Bar End Cap

NCEP Home > NCO Home > Systems Integration Branch > Decoders > CREXLIB Table of Contents > Sample Program - Decoding Tide Gauge Data CREX Messages

Example Program: Decoding Tide Gauge Data CREX Messages

Note: links open in a new window

In this example, we will be decoding a tide gauge data CREX message that was encoded according to the "WMO FM 95-XII CREX" format. We will use the Tide Gauge Station Table, the Sample CREX Table B file, and the Sample CREX Table D file. It is assumed that the CREX message was transmitted in a bulletin and that the bulletin will be passed by the application program in an array bulltn to the CREXLIB software for decoding.

C*      Array to hold the bulletin containing the CREX message.

        CHARACTER       bulltn*(MXBF)

C*      It is assumed that the user has some understanding of the CREX
C*      message to be decoded, and therefore, is able to define maximum
C*      sizes for the following parameters.

C*      Define the maximum number of data values expected in a report
C*	and the maximum number of descriptors after expansion of
C*      descriptor set in Section 1.

        PARAMETER       (  mxdatv = 200, mxndesc = 100 )

C*      Define the maximum number of reports expected in a message and
C*      the maximum report size in characters.

        PARAMETER       ( mxrpt = 75, mxrptsz = 500 )
C*      Array to hold the decoded report values.

        REAL*8    	dataval ( mxrpt, mxdatv )

C*      Array to hold the length of each report in the CREX message.

        INTEGER   	lenrpts ( mxrpt )

C*      Array to hold the Section 1 descriptor list.

        CHARACTER       datadesc ( mxndesc )*6
C*      Array to hold the expanded Section 1 descriptor list.

        CHARACTER       expdesc ( mxdatv )*6
C*	Array to hold the raw reports in the CREX message.
        CHARACTER       rawrpt ( mxrpt, mxrptsz )*8
C*      Open the station table file.
        OPEN  ( UNIT = 10, FILE = 'stntbl' )
C*      Read the tide gauge station table data, which contain lat/long
C*      locations and elevation heights for these sites.
        (Will assume such code exists to read in the station table data.)

C*	Open the CREX table D and define the logical unit number for table D.
        lutbld = 11
        OPEN  ( UNIT = lutbld, FILE = 'crextbld' )
C*	Open the CREX table B. Define the logical unit number for table B.
        lutblb = 12
        OPEN  ( UNIT = lutblb, FILE = 'crextblb' )
C*      Get the next bulletin containing the CREX message and store the
C*      bulletin in the array bulltn. Store the bulletin length in lenb.

        (Will assume such code to read the next bulletin exists here.
         The bulletin will be stored in array bulltn and its length in
         bytes will be store in the variable lenb.)

C*	Decode the CREX message.
        CALL CX_DCOD ( lutblb, lutbld, mxndesc, mxrpt, mxrptsz,
     +                 mxdatv, lenb, bulltn, ctbla, ctblds,
     +                 ndesc, datadesc, nmrpts, nmdesc, expdesc, 
     +                 lenrpts, rawrpt, nmdatval, dataval, iret )

C*      Print the decoded data stored in the arrays datadesc,
C*      expdesc, dataval and rawrpt.

        do lw = 1,ndesc
          write ( 6, 100 ) lw, datadesc(lw)
        end do

        do lw = 1, nmdesc
          write ( 6, 100 ) lw, expdesc(lw)
        end do
100     format ( 1x, 'expdesc(',i2,') = ', a6 )
        do lw = 1,nmrpts
          do lv = 1,nmdatval
            write(6,120) lw,lv,dataval(lw,lv), dataval(lw,lv)
          end do
        end do
120     format(1x,'TGDCOD: ', 3x, 'dataval(',i2,',',i3, ') = ', 
     +         f10.3, 3x, A)

        ln = lenrpts(1)
        nwords = ln / 8
        irem = MOD(ln,8)
        IF ( irem .ne. 0 ) nwords = nwords + 1

        do lw = 1,nwords
          print *, 'rawrpt(1,',lw, ') = ', rawrpt(1,lw)
        end do

C*     See the Example of a Decoded Tide Gauge CREX Message
C*     for an explanation and printout of the data in these output arrays. Since
C*     the data in the dataval array may be either in real or character format,
C*     the data is printed as real and character using format statement 120 which will
C*     enable the user to view the values in dataval. However, one of the two
C*     formats will not be printable.  The printout in the example shows only the one
C*     that is readable.

C*     At this point the user will call the routines he has written to get from the 
C*     array dataval the particular decoded data values he wants. To do this, the user
C*     will use the position of the descriptors in the array expdesc that are associated
C*     with the data values. For example, suppose the user wants to get the sea/water
C*     temperature in Kelvin from the decoded values. The descriptor for this parameter
C*     is B22042. Code will be needed to search for this descriptor in expdesc and
C*     determine its position in the array. In this case, it is at location 7. Since the
C*     first 7 locations in the dataval are in a 1-to-1 correspondence with the the
C*     the first 7 locations of the descriptors in expdesc, location 7 in dataval which
C*     holds the value 280.0 is the sea/water temperature in Kelvin.

C*     When descriptors are replicated, the entire replication set is stored in expdesc.
C*     In the example, B22038 and B22039 are replicated 6 times. The corresponding
C*     values in dataval are in a 1-to-1 correspondence with the replicated descriptors
C*     in expdesc.

C*     It is assumed again that the user is familiar with the CREX Tables B and D used
C*     to decode the CREX message. Since the user has a list of the descriptors for the
C*     current CREX message in the expdesc array, the user can write code which will
C*     read Table B to get the width for each parameter associated with the descriptors
C*     in expdesc. This information can be used to match the descriptors in expdesc
C*     with their corresponding decoded parameters in dataval. The user must keep in
C*     mind that each dataval location is 8-bytes in size.


NOAA/ National Weather Service
National Centers for Environmental Prediction
5830 University Research Court
College Park, MD 20740
NCEP Internet Services Team
Privacy Policy
About Us
Career Opportunities
Page last modified: Wednesday, 10-May-2006 22:18:23 UTC