<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Read an adp File in Teledyne/RDI Format — read.adp.rdi • oce</title><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/font-awesome-6.4.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.4.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Read an adp File in Teledyne/RDI Format — read.adp.rdi"><meta name="description" content="Read a Teledyne/RDI ADCP file (called 'adp' in oce). This can
handle a variety of file/instrument types, by recognizing telltale
byte sequences in the data. The scope is limited to types that are
documented adequately in Teledyne/RDI manuals. In some instances,
the manuals provide some information but not enough to enable
inclusion here, for example in the case for wave data (see
https://github.com/dankelley/oce/issues/2216)."><meta property="og:description" content="Read a Teledyne/RDI ADCP file (called 'adp' in oce). This can
handle a variety of file/instrument types, by recognizing telltale
byte sequences in the data. The scope is limited to types that are
documented adequately in Teledyne/RDI manuals. In some instances,
the manuals provide some information but not enough to enable
inclusion here, for example in the case for wave data (see
https://github.com/dankelley/oce/issues/2216)."></head><body>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>


    <nav class="navbar navbar-expand-lg fixed-top bg-light" data-bs-theme="light" aria-label="Site navigation"><div class="container">

    <a class="navbar-brand me-2" href="../index.html">oce</a>

    <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8-4</small>


    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto"><li class="active nav-item"><a class="nav-link" href="../reference/index.html">Reference</a></li>
<li class="nav-item dropdown">
  <button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Articles</button>
  <ul class="dropdown-menu" aria-labelledby="dropdown-articles"><li><a class="dropdown-item" href="../articles/A_oce.html">1. Introduction to Oce</a></li>
    <li><a class="dropdown-item" href="../articles/B_ctd.html">2. Analysis of CTD data</a></li>
    <li><a class="dropdown-item" href="../articles/C_adp.html">3. Analysis of acoustic-Doppler data</a></li>
    <li><a class="dropdown-item" href="../articles/D_map_projections.html">4. Using map projections</a></li>
    <li><a class="dropdown-item" href="../articles/E_flags.html">5. Dealing with data-quality flags</a></li>
    <li><a class="dropdown-item" href="../articles/F_subclassing.html">6. Subclassing oce objects</a></li>
    <li><a class="dropdown-item" href="../articles/G_altering_defaults.html">7. Altering oce Defaults</a></li>
    <li><a class="dropdown-item" href="../articles/H_tides.html">8. Tidal Analysis</a></li>
  </ul></li>
<li class="nav-item"><a class="nav-link" href="../news/index.html">Changelog</a></li>
      </ul><ul class="navbar-nav"><li class="nav-item"><form class="form-inline" role="search">
 <input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="../search.json"></form></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/dankelley/oce/" aria-label="GitHub"><span class="fa fab fa-github fa-lg"></span></a></li>
      </ul></div>


  </div>
</nav><div class="container template-reference-topic">
<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">

      <h1>Read an adp File in Teledyne/RDI Format</h1>
      <small class="dont-index">Source: <a href="https://github.com/dankelley/oce/blob/HEAD/R/adp.rdi.R" class="external-link"><code>R/adp.rdi.R</code></a></small>
      <div class="d-none name"><code>read.adp.rdi.Rd</code></div>
    </div>

    <div class="ref-description section level2">
    <p>Read a Teledyne/RDI ADCP file (called 'adp' in oce). This can
handle a variety of file/instrument types, by recognizing telltale
byte sequences in the data. The scope is limited to types that are
documented adequately in Teledyne/RDI manuals. In some instances,
the manuals provide some information but not enough to enable
inclusion here, for example in the case for wave data (see
<a href="https://github.com/dankelley/oce/issues/2216" class="external-link">https://github.com/dankelley/oce/issues/2216</a>).</p>
    </div>

    <div class="section level2">
    <h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">read.adp.rdi</span><span class="op">(</span></span>
<span>  <span class="va">file</span>,</span>
<span>  <span class="va">from</span>,</span>
<span>  <span class="va">to</span>,</span>
<span>  <span class="va">by</span>,</span>
<span>  tz <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">getOption</a></span><span class="op">(</span><span class="st">"oceTz"</span><span class="op">)</span>,</span>
<span>  longitude <span class="op">=</span> <span class="cn">NA</span>,</span>
<span>  latitude <span class="op">=</span> <span class="cn">NA</span>,</span>
<span>  type <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"workhorse"</span><span class="op">)</span>,</span>
<span>  <span class="va">which</span>,</span>
<span>  encoding <span class="op">=</span> <span class="cn">NA</span>,</span>
<span>  monitor <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>  despike <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>  <span class="va">processingLog</span>,</span>
<span>  testing <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>  debug <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">getOption</a></span><span class="op">(</span><span class="st">"oceDebug"</span><span class="op">)</span>,</span>
<span>  <span class="va">...</span></span>
<span><span class="op">)</span></span></code></pre></div>
    </div>

    <div class="section level2">
    <h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>


<dl><dt id="arg-file">file<a class="anchor" aria-label="anchor" href="#arg-file"></a></dt>
<dd><p>a connection or a character string giving the name of the file
to load.  (For <code>read.adp.sontek.serial</code>, this is generally a list of
files, which will be concatenated.)</p></dd>


<dt id="arg-from">from<a class="anchor" aria-label="anchor" href="#arg-from"></a></dt>
<dd><p>indication of the first profile to read.  This can be an
integer, the sequence number of the first profile to read, or a POSIXt time
before which profiles should be skipped, or a character string that converts
to a POSIXt time (assuming UTC timezone).  See “Examples”, and make
careful note of the use of the <code>tz</code> argument. If <code>from</code> is not
supplied, it defaults to 1.</p></dd>


<dt id="arg-to">to<a class="anchor" aria-label="anchor" href="#arg-to"></a></dt>
<dd><p>an optional indication of the last profile to read, in a
format as described for <code>from</code>.  As a special case, <code>to=0</code> means
to read the file to the end.  If <code>to</code> is not supplied, then it defaults
to 0.</p></dd>


<dt id="arg-by">by<a class="anchor" aria-label="anchor" href="#arg-by"></a></dt>
<dd><p>an optional indication of the stride length to use while walking through
the file.  If this is an integer, then <code>by-1</code> profiles are skipped
between each pair of profiles that is read, e.g. the default <code>by=1</code>
means to read all the data.  (For RDI files <em>only</em>, there are some
extra features to avoid running out of memory; see “Memory considerations”.)</p></dd>


<dt id="arg-tz">tz<a class="anchor" aria-label="anchor" href="#arg-tz"></a></dt>
<dd><p>character string indicating time zone to be assumed in the data.</p></dd>


<dt id="arg-longitude">longitude<a class="anchor" aria-label="anchor" href="#arg-longitude"></a></dt>
<dd><p>optional signed number indicating the longitude in degrees
East.</p></dd>


<dt id="arg-latitude">latitude<a class="anchor" aria-label="anchor" href="#arg-latitude"></a></dt>
<dd><p>optional signed number indicating the latitude in degrees
North.</p></dd>


<dt id="arg-type">type<a class="anchor" aria-label="anchor" href="#arg-type"></a></dt>
<dd><p>character string indicating the type of instrument.</p></dd>


<dt id="arg-which">which<a class="anchor" aria-label="anchor" href="#arg-which"></a></dt>
<dd><p>optional character value.  If this is <code>"??"</code> then the
only other parameters that are examined are <code>file</code> and <code>debug</code>,
<code>read.adp.rdi()</code> works by locating the indices in <code>file</code> at which
data segments begin, and storing them as <code>index</code> in a list that is
returned. The other entry of the list is <code>time</code>, the time of the
observation.</p></dd>


<dt id="arg-encoding">encoding<a class="anchor" aria-label="anchor" href="#arg-encoding"></a></dt>
<dd><p>ignored.</p></dd>


<dt id="arg-monitor">monitor<a class="anchor" aria-label="anchor" href="#arg-monitor"></a></dt>
<dd><p>boolean value indicating whether to indicate the progress
of reading the file, by using <code><a href="https://rdrr.io/r/utils/txtProgressBar.html" class="external-link">txtProgressBar()</a></code> or otherwise.  The value
of <code>monitor</code> is changed to <code>FALSE</code> automatically, for non-interactive
sessions.</p></dd>


<dt id="arg-despike">despike<a class="anchor" aria-label="anchor" href="#arg-despike"></a></dt>
<dd><p>if <code>TRUE</code>, <code><a href="despike.html">despike()</a></code> will be used to clean
anomalous spikes in heading, etc.</p></dd>


<dt id="arg-processinglog">processingLog<a class="anchor" aria-label="anchor" href="#arg-processinglog"></a></dt>
<dd><p>if provided, the action item to be stored in the log.
(Typically only provided for internal calls; the default that it provides is
better for normal calls by a user.)</p></dd>


<dt id="arg-testing">testing<a class="anchor" aria-label="anchor" href="#arg-testing"></a></dt>
<dd><p>logical value (IGNORED).</p></dd>


<dt id="arg-debug">debug<a class="anchor" aria-label="anchor" href="#arg-debug"></a></dt>
<dd><p>a flag that turns on debugging.  Set to 1 to get a moderate
amount of debugging information, or to 2 to get more.</p></dd>


<dt id="arg--">...<a class="anchor" aria-label="anchor" href="#arg--"></a></dt>
<dd><p>optional additional arguments that some (but not all)
<code>read.adp.*()</code> functions pass to lower-level functions.</p></dd>

</dl></div>
    <div class="section level2">
    <h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
    <p>An <a href="adp-class.html">adp</a> object.
The contents of that object make sense for the particular instrument
type under study, e.g. if the data file contains
NMEA strings, then navigational data will be stored in an item
called <code>nmea</code> in the <code>data</code> slot).</p>
    </div>
    <div class="section level2">
    <h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
    <p>If a heading bias had been set with the <code>EB</code> command during the
setup for the deployment, then a heading bias will have been stored
in the file's header.  This value is stored in the object's
metadata as <code>metadata$heading.bias</code>.  <strong>Importantly</strong>, this value
is subtracted from the headings stored in the file, and the result
of this subtraction is stored in the objects heading value (in
<code>data$heading</code>). It should be noted that <code>read.adp.rdi()</code> was
tested for firmware version 16.30.  For other versions, there may
be problems.  For example, the serial number is not recognized
properly for version 16.28.</p>
<p>In Teledyne/RDI ADP data files, velocities are coded to signed
2-byte integers, with a scale factor being used to convert to
velocity in metres per second.  These two facts control the maximum
recordable velocity and the velocity resolution, values that may be
retrieved for an ADP object name <code>d</code> with <code>d[["velocityMaximum"]]</code>
and <code>d[["velocityResolution"]]</code>.</p>
    </div>
    <div class="section level2">
    <h2 id="handling-of-old-file-formats">Handling of old file formats<a class="anchor" aria-label="anchor" href="#handling-of-old-file-formats"></a></h2>



<p>Early PD0 file formats stored the year of sampling with a different
base year than that used in modern files.  To accommodate this,
<code>read.adp.rdi</code> examines the inferred year, and if it is greater
than 2050, then 100 years are subtracted from the time. This offset
was inferred by tests with sample files, but <em>not</em> from RDI
documentation, so it is somewhat risky.  If the authors can find
RDI documentation that indicates the condition in which this
century offset is required, then a change will be made to the code.
Even if not, the method should not cause problems for a long time.</p>
    </div>
    <div class="section level2">
    <h2 id="names-of-items-in-data-slot">Names of items in data slot<a class="anchor" aria-label="anchor" href="#names-of-items-in-data-slot"></a></h2>



<p>The names of items in the <code>data</code> slot are below. Not all items are
present for ll file varieties; use e.g. <code>names(d[["data"]])</code> to
determine the names used in an object named <code>d</code>. In this list,
items are either a vector (with one sample per time of
measurement), a <a href="https://rdrr.io/r/base/matrix.html" class="external-link">matrix</a> with first index for time and second for
bin number, or an <a href="https://rdrr.io/r/base/array.html" class="external-link">array</a> with first index for time, second for bin
number, and third for beam number. Items are of vector type, unless
otherwise indicated.</p>
<table class="table table"><tr><td><strong>Item</strong></td><td><strong>Meaning</strong></td></tr><tr><td><code>a</code></td><td>signal amplitude array (units?)</td></tr><tr><td><code>ambientTemp</code></td><td>ambient temperature (degC)</td></tr><tr><td><code>attitude</code></td><td>attitude (deg)</td></tr><tr><td><code>attitudeTemp</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>avgMagnitudeVelocityEast</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>avgMagnitudeVelocityNorth</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>avgSpeed</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>avgTrackMagnetic</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>avgTrackTrue</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>avgTrueVelocityEast</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>avgTrueVelocityNorth</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>br</code></td><td>bottom range matrix (m)</td></tr><tr><td><code>bv</code></td><td>bottom velocity matrix (m/s)</td></tr><tr><td><code>contaminationSensor</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>depth</code></td><td>depth (m)</td></tr><tr><td><code>directionMadeGood</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>distance</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>firstLatitude</code></td><td>latitude at start of profile (deg)</td></tr><tr><td><code>firstLongitude</code></td><td>longitude at start of profile (deg)</td></tr><tr><td><code>firstTime</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>g</code></td><td>data goodness matrix (units?)</td></tr><tr><td><code>heading</code></td><td>instrument heading (degrees)</td></tr><tr><td><code>headingStd</code></td><td>instrument heading std-dev (deg)</td></tr><tr><td><code>lastLatitude</code></td><td>latitude at end of profile (deg)</td></tr><tr><td><code>lastLongitude</code></td><td>longitude at end of profile (deg)</td></tr><tr><td><code>lastTime</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>numberOfHeadingSamplesAveraged</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>numberOfMagneticTrackSamplesAveraged</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>numberOfPitchRollSamplesAveraged</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>numberOfSpeedSamplesAveraged</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>numberOfTrueTrackSamplesAveraged</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>pitch</code></td><td>instrument pitch (deg)</td></tr><tr><td><code>pitchStd</code></td><td>instrument pitch std-dev (deg)</td></tr><tr><td><code>pressure</code></td><td>pressure (dbar)</td></tr><tr><td><code>pressureMinus</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>pressurePlus</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>pressureStd</code></td><td>pressure std-dev (dbar)</td></tr><tr><td><code>primaryFlags</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>q</code></td><td>data quality array</td></tr><tr><td><code>roll</code></td><td>instrument roll (deg)</td></tr><tr><td><code>rollStd</code></td><td>instrument roll std-dev (deg)</td></tr><tr><td><code>salinity</code></td><td>salinity</td></tr><tr><td><code>shipHeading</code></td><td>ship heading (deg)</td></tr><tr><td><code>shipPitch</code></td><td>ship pitch (deg)</td></tr><tr><td><code>shipRoll</code></td><td>ship roll (deg)</td></tr><tr><td><code>soundSpeed</code></td><td>sound speed (m/s)</td></tr><tr><td><code>speedMadeGood</code></td><td>speed over ground (?) (m/s)</td></tr><tr><td><code>speedMadeGoodEast</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>speedMadeGoodNorth</code></td><td>(FIXME add a description here)</td></tr><tr><td><code>temperature</code></td><td>temperature (degC)</td></tr><tr><td><code>time</code></td><td>profile time (POSIXct)</td></tr><tr><td><code>v</code></td><td>velocity array (m/s)</td></tr><tr><td><code>xmitCurrent</code></td><td>transmit current (unit?)</td></tr><tr><td><code>xmitVoltage</code></td><td>transmit voltage</td></tr></table></div>
    <div class="section level2">
    <h2 id="memory-considerations">Memory considerations<a class="anchor" aria-label="anchor" href="#memory-considerations"></a></h2>



<p>For <code>RDI</code> files only, and only in the case where <code>by</code> is not
specified, an attempt is made to avoid running out of memory by
skipping some profiles in large input files. This only applies if
<code>from</code> and <code>to</code> are both integers; if they are times, none of the
rest of this section applies.</p>
<p>A key issue is that RDI files store velocities in 2-byte values,
which is not a format that R supports. These velocities become
8-byte (numeric) values in R. Thus, the R object created by
<code>read.adp.rdi</code> will require more memory than that of the data file.
A scale factor can be estimated by ignoring vector quantities (e.g.
time, which has just one value per profile) and concentrating on
matrix properties such as velocity, backscatter, and correlation.
These three elements have equal dimensions. Thus, each 4-byte slide
in the data file (2 bytes + 1 byte + 1 byte) corresponds to 10
bytes in the object (8 bytes + 1 byte + 1 byte). Rounding up the
resultant 10/4 to 3 for safety, we conclude that any limit on the
size of the R object corresponds to a 3X smaller limit on file
size.</p>
<p>Various things can limit the size of objects in R, but a strong
upper limit is set by the space the operating system provides to R.
The least-performant machines in typical use appear to be
Microsoft-Windows systems, which limit R objects to about 2e6 bytes
(see <code>?Memory-limits</code>).  Since R routinely duplicates objects for
certain tasks (e.g. for call-by-value in function evaluation),
<code>read.adp.rdi</code> uses a safety factor in its calculation of when to
auto-decimate a file. This factor is set to 3, based partly on the
developers' experience with datasets in their possession.
Multiplied by the previously stated safety factor of 3, this
suggests that the 2 GB limit on R objects corresponds to
approximately a 222 MB limit on file size. In the present version
of <code>read.adp.rdi</code>, this value is lowered to 200 MB for simplicity.
Larger files are considered to be "big", and are decimated unless
the user supplies a value for the <code>by</code> argument.</p>
<p>The decimation procedure has two cases.</p><ol><li><p>If <code>from=1</code> and <code>to=0</code> (or if neither <code>from</code> or <code>to</code> is given),
then the intention is to process the full span of the data.  If the
input file is under 200 MB, then <code>by</code> defaults to 1, so that all
profiles are read. For larger files, <code>by</code> is set to the <code><a href="https://rdrr.io/r/base/Round.html" class="external-link">ceiling()</a></code>
of the ratio of input file size to 200 MB.</p></li>
<li><p>If <code>from</code> exceeds 1, and/or <code>to</code> is nonzero, then the intention
is to process only an interior subset of the file. In this case,
<code>by</code> is calculated as the <code><a href="https://rdrr.io/r/base/Round.html" class="external-link">ceiling()</a></code> of the ratio of
<code>bbp*(1+to-from)</code> to 200 MB, where <code>bbp</code> is the number of file
bytes per profile. Of course, <code>by</code> is set to 1, if this ratio is
less than 1.</p></li>
</ol><p>If the result of these calculations is that <code>by</code> exceeds 1, then
messages are printed to alert the user that the file will be
decimated, and also <code>monitor</code> is set to <code>TRUE</code>, so that a textual
progress bar is shown (if the session is interactive).</p>
    </div>
    <div class="section level2">
    <h2 id="development-notes">Development Notes<a class="anchor" aria-label="anchor" href="#development-notes"></a></h2>



<p>An important part of the work of this function is to recognize what
will be called "data chunks" by two-byte ID sequences. This
function is developed in a practical way, with emphasis being
focussed on data files in the possession of the developers. Since
Teledyne-RDI tends to introduce new ID codes with new instruments,
that means that <code>read.adp.rdi</code> may not work on recently-developed
instruments.</p>
<p>The following two-byte ID codes are recognized by <code>read.adp.rdi</code>
at this time (with bytes listed in natural order, LSB byte before
MSB). Items preceded by an asterisk are recognized, but not handled,
and so produce a warning.</p><table class="table table"><tr><td></td><td><strong>Byte 1</strong></td><td><strong>Byte 2</strong></td><td><strong>Meaning</strong></td></tr><tr><td></td><td>0x00</td><td>0x01</td><td>velocity</td></tr><tr><td></td><td>0x00</td><td>0x01</td><td>velocity</td></tr><tr><td></td><td>0x00</td><td>0x02</td><td>correlation</td></tr><tr><td></td><td>0x00</td><td>0x03</td><td>echo intensity</td></tr><tr><td></td><td>0x00</td><td>0x04</td><td>percent good</td></tr><tr><td></td><td>0x00</td><td>0x06</td><td>bottom track</td></tr><tr><td></td><td>0x00</td><td>0x0a</td><td>Sentinel vertical beam velocity</td></tr><tr><td></td><td>0x00</td><td>0x0b</td><td>Sentinel vertical beam correlation</td></tr><tr><td></td><td>0x00</td><td>0x0c</td><td>Sentinel vertical beam amplitude</td></tr><tr><td></td><td>0x00</td><td>0x0d</td><td>Sentinel vertical beam percent good</td></tr><tr><td></td><td>0x00</td><td>0x20</td><td>VMDASS</td></tr><tr><td></td><td>0x00</td><td>0x30</td><td>Binary Fixed Attitude header</td></tr><tr><td></td><td>0x00</td><td>0x32</td><td>Sentinel transformation matrix</td></tr><tr><td></td><td>0x00</td><td>0x0a</td><td>Sentinel data</td></tr><tr><td></td><td>0x00</td><td>0x0b</td><td>Sentinel correlation</td></tr><tr><td></td><td>0x00</td><td>0x0c</td><td>Sentinel amplitude</td></tr><tr><td></td><td>0x00</td><td>0x0d</td><td>Sentinel percent good</td></tr><tr><td></td><td>0x01</td><td>0x0f</td><td>?? something to do with V series and 4-beam</td></tr></table><p>Lacking a comprehensive Teledyne-RDI listing of ID codes,
the authors have cobbled together a listing from documents to which they
have access, as follows.</p><ul><li><p>Table 33 of reference 3 lists codes as follows:</p><table class="table table"><tr><td><strong>Standard ID</strong></td><td><strong>Standard plus 1D</strong></td><td><strong>DESCRIPTION</strong></td></tr><tr><td>MSB    LSB</td><td>MSB    LSB</td><td></td></tr><tr><td>—    —</td><td>—    —</td><td></td></tr><tr><td>7F     7F</td><td>7F     7F</td><td>Header</td></tr><tr><td>00     00</td><td>00     01</td><td>Fixed Leader</td></tr><tr><td>00     80</td><td>00     81</td><td>Variable Leader</td></tr><tr><td>01     00</td><td>01     01</td><td>Velocity Profile Data</td></tr><tr><td>02     00</td><td>02     01</td><td>Correlation Profile Data</td></tr><tr><td>03     00</td><td>03     01</td><td>Echo Intensity Profile Data</td></tr><tr><td>04     00</td><td>04     01</td><td>Percent Good Profile Data</td></tr><tr><td>05     00</td><td>05     01</td><td>Status Profile Data</td></tr><tr><td>06     00</td><td>06     01</td><td>Bottom Track Data</td></tr><tr><td>20     00</td><td>20     00</td><td>Navigation</td></tr><tr><td>30     00</td><td>30     00</td><td>Binary Fixed Attitude</td></tr><tr><td>30  40-F0</td><td>30  40-F0</td><td>Binary Variable Attitude</td></tr></table></li>
<li><p>Table 6 on p90 of reference 4 lists "Fixed Leader Navigation" ID
codes (none of which are handled by <code>read.adp.rdi</code> yet)
as follows (the format is reproduced literally; note that
e.g. 0x2100 is 0x00,0x21 in the oce notation):</p><table class="table table"><tr><td><strong>ID</strong></td><td><strong>Description</strong></td></tr><tr><td>0x2100</td><td>$xxDBT</td></tr><tr><td>0x2101</td><td>$xxGGA</td></tr><tr><td>0x2102</td><td>$xxVTG</td></tr><tr><td>0x2103</td><td>$xxGSA</td></tr><tr><td>0x2104</td><td>$xxHDT, $xxHGD or $PRDID</td></tr></table><p>and following pages in that manual reveal the following meanings</p><table class="table table"><tr><td><strong>Symbol</strong></td><td><strong>Meaning</strong></td></tr><tr><td><code>DBT</code></td><td>depth below transducer</td></tr><tr><td><code>GGA</code></td><td>global positioning system</td></tr><tr><td><code>VTA</code></td><td>track made good and ground speed</td></tr><tr><td><code>GSA</code></td><td>GPS DOP and active satellites</td></tr><tr><td><code>HDT</code></td><td>heading, true</td></tr><tr><td><code>HDG</code></td><td>heading, deviation, and variation</td></tr><tr><td><code>PRDID</code></td><td>heading, pitch and roll</td></tr></table></li>
</ul></div>
    <div class="section level2">
    <h2 id="error-recovery">Error recovery<a class="anchor" aria-label="anchor" href="#error-recovery"></a></h2>



<p>Files can sometimes be corrupted, and <code>read.adp.rdi</code> has ways to
handle two types of error that have been noticed in files supplied
by users.</p><ol><li><p>There are two bytes within each ensemble that indicate the
number of bytes to check within that ensemble, to get the checksum.
Sometimes, those two bytes can be erroneous, so that the wrong
number of bytes are checked, leading to a failed checksum. As a
preventative measure, <code>read.adp.rdi</code> checks the stated ensemble
length, whenever it detects a failed checksum. If that length
agrees with the length of the most recent ensemble that had a good
checksum, then the ensemble is declared as faulty and is ignored.
However, if the length differs from that of the most recent
accepted ensemble, then <code>read.adp.rdi</code> goes back to just after the
start of the ensemble, and searches forward for the next two-byte
pair, namely <code>0x7f 0x7f</code>, that designates the start of an ensemble.
Distinct notifications are given about these two cases, and they
give the byte numbers in the original file, as a way to help
analysts who want to look at the data stream with other tools.</p></li>
<li><p>At the end of an ensemble, the next two characters ought to be
<code>0x7f 0x7f</code>, and if they are not, then the next ensemble is faulty.
If this error occurs, <code>read.adp.rdi</code> attempts to recover by
searching forward to the next instance of this two-byte pair,
discarding any information that is present in the mangled ensemble.</p></li>
</ol><p>In each of these cases, warnings are printed about ensembles that
seem problematic. Advanced users who want to diagnose the problem
further might find it helpful to examine the original data file
using other tools. To this end, <code>read.adp.rdi</code> inserts an element
named <code>ensembleInFile</code> into the <code>metadata</code> slot. This gives the
starting byte number of each inferred ensemble within the original
data file.  For example, if <code>d</code> is an object read with
<code>read.adp.rdi</code>, then using</p>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="fu">plot</span>(d[[<span class="st">"time"</span>]][<span class="sc">-</span><span class="dv">1</span>], <span class="fu">diff</span>(d[[<span class="st">"ensembleInFile"</span>]]))</span></code></pre><p></p></div>
<p>can be a good way to narrow in on problems.</p>
    </div>
    <div class="section level2">
    <h2 id="changes">Changes<a class="anchor" aria-label="anchor" href="#changes"></a></h2>


<ul><li><p>The <code>bq</code> (bottom-track quality) field was called <code>bc</code> until 2023-02-09.
See https://github.com/dankelley/oce/issues/2039 for discussion.</p></li>
</ul></div>
    <div class="section level2">
    <h2 id="how-the-binary-file-is-decoded">How the binary file is decoded<a class="anchor" aria-label="anchor" href="#how-the-binary-file-is-decoded"></a></h2>



<p>This file type, like other acoustic-Doppler types, is read
with a hybrid R/C++ system, for efficiency.
The processing steps are sketched below, for
users who want to inspect the code or build upon it.</p><ol><li><p>In R, <code><a href="https://rdrr.io/r/base/readBin.html" class="external-link">readBin()</a></code> is used to insert the file contents into
a <a href="https://rdrr.io/r/base/vector.html" class="external-link">vector</a> of type <code>raw</code>.</p></li>
<li><p>In C++, this raw vector is scanned byte by byte,
to find the starting indices of data "chunks", or subsections of
the data that correspond to individual sampling times.
Checksum computations are also done at this stage, to detect
possible data corruption.  Warnings are issued for any bad chunks,
and they are skipped in further processing. The valid
starting points are then passed back to R as a <a href="https://rdrr.io/r/base/vector.html" class="external-link">vector</a> of
type <code>integer</code>.</p></li>
<li><p>In R, <code><a href="https://rdrr.io/r/base/readBin.html" class="external-link">readBin()</a></code> is used to read the components of each chunk.
For speed, this is done in a vectorized fashion. For example,
all the velocities in the whole file are read in a single call
to <code><a href="https://rdrr.io/r/base/readBin.html" class="external-link">readBin()</a></code>. This process is done for each of the data
fields that are to be handled.  Importantly, these <code><a href="https://rdrr.io/r/base/readBin.html" class="external-link">readBin()</a></code>
calls are tailored to the data, using values of
the <code>size</code>, <code>endian</code> and <code>signed</code> parameters that are tailored
to the structure of the given component.
Scaling factors are then applied as required, to convert the
components to physical units.</p></li>
<li><p>Finally, in R, the acquired items are inserted into the <code>data</code> or
<code>metadata</code> slot of the return value, according to oce convention.</p></li>
</ol></div>
    <div class="section level2">
    <h2 id="references">References<a class="anchor" aria-label="anchor" href="#references"></a></h2>

<ol><li><p>Teledyne-RDI, 2007. <em>WorkHorse commands and output data
format.</em> P/N 957-6156-00 (November 2007).  (Section 5.3 h details the binary
format, e.g. the file should start with the byte <code>0x7f</code> repeated twice,
and each profile starts with the bytes <code>0x80</code>, followed by <code>0x00</code>,
followed by the sequence number of the profile, represented as a
little-endian two-byte short integer.  <code>read.adp.rdi</code> uses these
sequences to interpret data files.)</p></li>
<li><p>Teledyne RD Instruments, 2015. <em>V Series monitor, sentinel Output Data Format.</em>
P/N 95D-6022-00 (May 2015). <code>SV_ODF_May15.pdf</code></p></li>
<li><p>Teledyne RD Instruments, 2014. <em>Ocean Surveyor / Ocean Observer Technical Manual.</em>
P/N 95A-6012-00 (April 2014). <code>OS_TM_Apr14.pdf</code></p></li>
<li><p>Teledyne RD Instruments, 2001. <em>WinRiver User's Guide International Version.</em>
P/N 957-6171-00 (June 2001) <code>WinRiver User Guide International Version.pdf.pdf</code></p></li>
</ol></div>
    <div class="section level2">
    <h2 id="see-also">See also<a class="anchor" aria-label="anchor" href="#see-also"></a></h2>
    <div class="dont-index"><p>Other things related to adp data:
<code><a href="sub-sub-adp-method.html">[[,adp-method</a></code>,
<code>[[&lt;-,adp-method</code>,
<code><a href="ad2cpCodeToName.html">ad2cpCodeToName</a>()</code>,
<code><a href="ad2cpHeaderValue.html">ad2cpHeaderValue</a>()</code>,
<code><a href="adp.html">adp</a></code>,
<code><a href="adp-class.html">adp-class</a></code>,
<code><a href="adpAd2cpFileTrim.html">adpAd2cpFileTrim</a>()</code>,
<code><a href="adpConvertRawToNumeric.html">adpConvertRawToNumeric</a>()</code>,
<code><a href="adpEnsembleAverage.html">adpEnsembleAverage</a>()</code>,
<code><a href="adpFlagPastBoundary.html">adpFlagPastBoundary</a>()</code>,
<code><a href="adpRdiFileTrim.html">adpRdiFileTrim</a>()</code>,
<code><a href="adp_rdi.000.html">adp_rdi.000</a></code>,
<code><a href="applyMagneticDeclination-adp-method.html">applyMagneticDeclination,adp-method</a></code>,
<code><a href="as.adp.html">as.adp</a>()</code>,
<code><a href="beamName.html">beamName</a>()</code>,
<code><a href="beamToXyz.html">beamToXyz</a>()</code>,
<code><a href="beamToXyzAdp.html">beamToXyzAdp</a>()</code>,
<code><a href="beamToXyzAdpAD2CP.html">beamToXyzAdpAD2CP</a>()</code>,
<code><a href="beamToXyzAdv.html">beamToXyzAdv</a>()</code>,
<code><a href="beamUnspreadAdp.html">beamUnspreadAdp</a>()</code>,
<code><a href="binmapAdp.html">binmapAdp</a>()</code>,
<code><a href="enuToOther.html">enuToOther</a>()</code>,
<code><a href="enuToOtherAdp.html">enuToOtherAdp</a>()</code>,
<code><a href="handleFlags-adp-method.html">handleFlags,adp-method</a></code>,
<code><a href="is.ad2cp.html">is.ad2cp</a>()</code>,
<code><a href="plot-adp-method.html">plot,adp-method</a></code>,
<code><a href="read.adp.html">read.adp</a>()</code>,
<code><a href="read.adp.ad2cp.html">read.adp.ad2cp</a>()</code>,
<code><a href="read.adp.nortek.html">read.adp.nortek</a>()</code>,
<code><a href="read.adp.sontek.html">read.adp.sontek</a>()</code>,
<code><a href="read.adp.sontek.serial.html">read.adp.sontek.serial</a>()</code>,
<code><a href="read.aquadopp.html">read.aquadopp</a>()</code>,
<code><a href="read.aquadoppHR.html">read.aquadoppHR</a>()</code>,
<code><a href="read.aquadoppProfiler.html">read.aquadoppProfiler</a>()</code>,
<code><a href="rotateAboutZ.html">rotateAboutZ</a>()</code>,
<code><a href="setFlags-adp-method.html">setFlags,adp-method</a></code>,
<code><a href="subset-adp-method.html">subset,adp-method</a></code>,
<code><a href="subtractBottomVelocity.html">subtractBottomVelocity</a>()</code>,
<code><a href="summary-adp-method.html">summary,adp-method</a></code>,
<code><a href="toEnu.html">toEnu</a>()</code>,
<code><a href="toEnuAdp.html">toEnuAdp</a>()</code>,
<code><a href="velocityStatistics.html">velocityStatistics</a>()</code>,
<code><a href="xyzToEnu.html">xyzToEnu</a>()</code>,
<code><a href="xyzToEnuAdp.html">xyzToEnuAdp</a>()</code>,
<code><a href="xyzToEnuAdpAD2CP.html">xyzToEnuAdpAD2CP</a>()</code></p>
<p>Other functions that read adp data:
<code><a href="read.adp.html">read.adp</a>()</code>,
<code><a href="read.adp.ad2cp.html">read.adp.ad2cp</a>()</code>,
<code><a href="read.adp.nortek.html">read.adp.nortek</a>()</code>,
<code><a href="read.adp.sontek.html">read.adp.sontek</a>()</code>,
<code><a href="read.adp.sontek.serial.html">read.adp.sontek.serial</a>()</code>,
<code><a href="read.aquadopp.html">read.aquadopp</a>()</code>,
<code><a href="read.aquadoppHR.html">read.aquadoppHR</a>()</code>,
<code><a href="read.aquadoppProfiler.html">read.aquadoppProfiler</a>()</code></p></div>
    </div>
    <div class="section level2">
    <h2 id="author">Author<a class="anchor" aria-label="anchor" href="#author"></a></h2>
    <p>Dan Kelley and Clark Richards</p>
    </div>

    <div class="section level2">
    <h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="va">adp</span> <span class="op">&lt;-</span> <span class="fu">read.adp.rdi</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/system.file.html" class="external-link">system.file</a></span><span class="op">(</span><span class="st">"extdata"</span>, <span class="st">"adp_rdi.000"</span>, package <span class="op">=</span> <span class="st">"oce"</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></span><span class="op">(</span><span class="va">adp</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ADP Summary</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> -----------</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Filename:          "/private/var/folders/8b/l4h64m1j22v5pb7vj049ff140000gn/T/RtmpFbPNQ2/temp_libpath17ff52acea456/oce/extdata/adp_rdi.000"</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Instrument:        adcp</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Manufacturer:      teledyne rdi</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Serial number:     unknown</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Firmware:          16.28</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Cell Size:         0.50 m</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Beam Angle:        20 deg</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Location:          unknown latitude, unknown longitude</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Frequency:         600 kHz</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Ensemble Numbers:   1, 2, ..., 8, 9</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Transformation matrix::</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>      1.462  -1.462   0.000   0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>      0.000   0.000  -1.462   1.462</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>      0.266   0.266   0.266   0.266</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>      1.034   1.034  -1.034  -1.034</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Time: 2008-06-25 10:00:00 to 2008-06-25 10:01:20 (9 samples, mean increment 10 s)</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Data Overview</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>                              Min.                Mean                Max.                Dim.     NAs</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     v [m/s]                  -0.416              0.011534            0.406               "9x84x4" 0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     q                        NA                  NA                  NA                  "9x84x4" 0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     a                        NA                  NA                  NA                  "9x84x4" 0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     g                        NA                  NA                  NA                  "9x84x4" 0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     distance [m]             2.23                22.98               43.73               84       0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     time                     2008-06-25 10:00:00 2008-06-25 10:00:40 2008-06-25 10:01:20 9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     pressure [dbar]          -0.274              -0.23489            -0.193              9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     temperature [°C, ITS-90] 12.06               12.082              12.11               9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     salinity [PSS-78]        35                  35                  35                  9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     depth [m]                0                   0                   0                   9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     soundSpeed [m/s]         1497                1497                1497                9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     heading [°]              276.39              277.14              278.14              9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     pitch [°]                1.1209              1.2033              1.4212              9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     roll [°]                 -2.49               -2.4033             -2.35               9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     headingStd [°]           0                   0.22222             1                   9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     pitchStd [°]             0.1                 0.11111             0.2                 9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     rollStd [°]              0                   0.088889            0.1                 9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     pressureStd              76                  100                 135                 9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     xmitCurrent              61                  61                  61                  9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     xmitVoltage              155                 155                 155                 9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ambientTemp              103                 103                 103                 9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     pressurePlus             77                  77                  77                  9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     pressureMinus            76                  76.778              77                  9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     attitudeTemp             101                 101                 101                 9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     attitude [°]             130                 130                 130                 9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     contaminationSensor      159                 159                 159                 9        0  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> * Processing Log</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     - 2024-09-24 10:30:02 UTC: `read.adp.rdi(file = system.file("extdata", "adp_rdi.000", package = "oce"))`</span>
<span class="r-in"><span></span></span>
</code></pre></div>
    </div>
  </main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
    </nav></aside></div>


    <footer><div class="pkgdown-footer-left">
  <p>Developed by Dan Kelley, Clark Richards.</p>
</div>

<div class="pkgdown-footer-right">
  <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.1.0.9000.</p>
</div>

    </footer></div>





  </body></html>

