<html>
<head>
<title>NOAA POD GUIDE APPENDIX B</title>
</head>
<body background= "../../../images/bkground.jpg">
<table width="85%" cellspacing="10"><tr valign=top><td>
<img src="../../../images/i_noaa1.gif">
</td><td align=center>
<a name="top"></a>
<H1>NOAA POD GUIDE</H1>
<H1>Appendix B</H1>
</td></tr></table>
<img src="../../../images/ssb-line.gif" width=1200 height=5>
<center>
<em>
<b>
<img src="../../../images/media.gif" border=0> <a href="../../../intro.htm">Introduction Page</a>, 
<a href = "../../index.htm">POD Guide TOC</a>, <a href="../../acronyms.htm">Acronyms</a>
<br>
<a href="../a/app-a.htm">Previous Section</a>, <a href="../c/app-c.htm">Next Section</a>
</b>
</em>
<hr>
</center>
<p>
<h2>APPENDIX B: <u>Unpacking LAC/HRPT Data</u></h2>
<p>
This appendix describes a user procedure for unpacking five channel LAC/HRPT data received
on CCTs from SSB.  This procedure can be readily adapted to selected channel format
LAC/HRPT data or GAC data.
<p>
As described in <a href="../c3/sec3-2.htm"> Section 3.2</a>, LAC/HRPT data are
written on tape as two physical records per scan.  Each scan contains data from all five channels
plus Earth location and calibration information.  The data are 10-bit samples.  Data from the 5
channels are interleaved, i.e., the first data sample in the scan is from Channel 1, the next from
Channel 2, then Channel 3, Channel 4, and Channel 5, with this sequence repeating through the
scan. The 10-bit data samples are packed three to a four-byte (8 bits/byte) group (i.e., three to a
32-bit word).
<p>
The unpacking procedure described below unpacks the data and rearranges it so that data from
the same channel are collected together and stored in sequence (i.e., all of the data for Channel 1
followed by all of the data for Channel 2, etc.).  Thus, the original five channel scan is sorted into
five consecutive single channel scan lines.  The individual 10-bit data samples are also unpacked
and stored in consecutive pairs of bytes (or 16-bit words, or 32-bit halfwords).  Access to Earth
location and calibration information is also provided.
<p>
The procedure will be outlined in a sequence of steps:
<p><ol>
<li>Define four arrays to be used as data buffers.
<p><ul>
a. ISCAN (3700 @ 32 bits) - This buffer will hold a complete Earth scan (2 physical
records) of unpacked HRPT data. <br>
<p>
b. IEARTH (102 @ 16 bits) - This buffer will contain the Earth location information. <br>
<p>
c. IDATA (2048, 5 @ 16 bits) - This buffer will contain the unpacked 2048 data samples for
each of five channels. <br>
<p>
d.  IBUF (10242 @ 16 bits) - This buffer will hold data at an intermediate point in the
procedure</ul>
<p>
<li>Equivalence IEARTH(1) and ISCAN(27).  This "points" IEARTH to that portion of the
Earth scan containing the Earth location information.
<p>
<li>Skip the first three records on the tape (the first is the TBM Header record and the next
two are the data set header records).
<p>
<li>Read the next record into ISCAN(1) through ISCAN(1850).  This is the first half of an
Earth scan.
<p>
<li>Read the next record into ISCAN(1851) through ISCAN(3700).  This is the second half
of an Earth scan.
<p>
<li>The Earth location information is now available in IEARTH as described in the Level 1b
format.  For example, IEARTH(1) and IEARTH(2) are the latitude and longitude respectively
for the first reference point (#25).  To convert to units of degrees, divide each by 128.
<p>
<li>The calibration coefficients are now available in ISCAN(4) through ISCAN(13), as
described in the Level 1b format.  The use of these calibration coefficients is described in <a
href="../c3/sec3-3.htm"> Section 3.3</a>.
<p>
<li>Use subroutine UNPK10 to unpack the 10-bit data samples into 16-bit elements of IBUF. 
A listing of UNPK10 is included below.  The FORTRAN call is: 
<p>
CALL UNPK10(ISCAN(113),IBUF,3414)
<p>
where ISCAN(113) is the start of the HRPT data in ISCAN,  IBUF is a temporary buffer for
the unpacked but still   interleaved data samples, and 3414 is the number of 32-bit elements
of ISCAN from each of which UNPK10 will extract three data samples (and store them in
three 16-bit elements of IBUF).

<p>
<li>Move data samples from IBUF into IDATA so that data from each channel can be
separately accessed (i.e., IDATA(N,1) will refer to the Nth sample along the scan line for
Channel 1, IDATA(N,2) for Nth sample for Channel 2, etc.).  This is done by the following
FORTRAN loop:
<pre>
 <font size="3"> DO m  I = 1,5       (5 Channels)</font>
 <font size="3"> K = I</font> 
 <font size="3"> DO m  J = 1,2048    (2048 Samples/Channel)</font>
 <font size="3"> IDATA(J,I) = IBUF(K)</font> 
<font size="3">m K = K + 5</font>
</pre>
<li>The 10-bit data values are now accessible in IDATA as desired, concluding the
procedure.</ol>
<p>
In the case of two channel selected data (i.e., where the user has specified that data from only two
designated channels were to be provided) UNPK10 is not used because the data samples have
already been unpacked into 16-bit elements.  In the case of either one or two channel selected
data, the references to the calibration and Earth location information are as shown.
<p>
In the case of five channel GAC data, the procedure may be used as shown with changes for the
record length and position and amount of the Earth location information.
<p>
 A listing of UNPK10 follows:
<pre>
 <b><font size="3">SUBROUTINE UNPK10(ISCAN,IBUF,N)</font></b>
 <font size="3">     DIMENSION ISCAN(3700), IBUF(10242)</font>
 <font size="3">     DATA MASK1/Z3FF00000/</font>
 <font size="3">     DATA MASK2/Z000FFC00/</font>
 <font size="3">     DATA MASK3/Z000003FF/</font>
 <font size="3">     J = 0</font>
 <font size="3">     DO 10 I = 1,N</font>
 <font size="3">     IWORD = ISCAN(I)</font>
 <font size="3">     J = J + 1</font>
 <font size="3">     JWORD = LAND(IWORD,MASK1)</font>
 <font size="3">     IBUF(J) = SHIFTR(JWORD,20)</font>
 <font size="3">     J = J + 1</font>
 <font size="3">     JWORD = LAND(IWORD,MASK2)</font>
 <font size="3">     IBUF(J) = SHIFTR(JWORD,10)</font>
 <font size="3">     J = J + 1</font>
 <font size="3">     IBUF(J) = LAND(IWORD,MASK3)</font>
<font size="3">10    CONTINUE</font>
 <font size="3">     RETURN</font>
 <font size="3">     END</font>
</pre>
The arrays used in UNPK10 are defined as follows:  ISCAN is the input Earth scan buffer, 3700
@ 32-bit elements for LAC/HRPT.  IBUF is the output buffer for unpacked data elements, 10242
@ 16-bit elements for LAC/HRPT.  N is the number of elements of ISCAN to be unpacked,
3414 for LAC/HRPT.
<p>MASK1 is a 32-bit mask with ones set in the 10-bit positions of the first 10-bit data sample
in a 32-bit element of ISCAN.  MASK2 and MASK3 are the same for the second and third data
samples.
<p>The function LAND(A,B) performs a logical "AND" on A and B, with the result left in A. 
The effect in this routine of the use of LAND and the MASK is to zero all bits in IWORD except
those of the data sample specified by the MASK, thus isolating it.


<p>The function SHIFTR(A,N) performs a right shift of the contents of A by N places, and is
equivalent to a division of A by 2<sup>N</sup>.  The purpose of UNPK10 is to right justify the
isolated data sample in IWORD, preparatory to moving it to the output buffer IBUF.
<p>UNPK10 proceeds through the input scan buffer, unpacking the words one by one and
storing in IBUF the three data samples obtained from each input element, until the entire input
scan has been processed.
<p>
<hr>
<center>
<table border="5" width="44%">
<tr>
<td align="center" valign="top" width="19%"><a href="../a/app-a.htm"><em><b>Previous
Section</em></b></a></td>
<td align="center" valign="top" width="17%"><a href="#top"><em><b>Top of
Page</em></b></a></td>
<td align="center" valign="top" width="8%"><a href="../c/app-c.htm"><em><b>Next
Section</em></b></a></td></tr></table>
</center><br>
</body>
</html>