function mk_amp(filename, yearbase, outdir)
% function mk_amp(filename, yearbase, outdir)
%
% Read the raw adcp file "filename", which may have been
% written by ue4 or may have been logged on our Linux
% ADCP logging machine, Peale or Gentoo, and write out
% a file containing only the raw amplitude data.  The
% output file will have the same name as the input file,
% but will have the extension ".amp".  It will be written
% to the directory "outdir", which defaults to the
% current working directory.
%
% You must add the subdirectories rawadcp/ and rawadcp/rdi/ to
% your path (easiest is to add the root programs/matlab directory 
% and then run each of the following: 
%    ef_path, adcppath, utilpath, radcppath; rdipath
%


% 2001/07/24 EF
% This is a quick hack, using a companion old version of
% read_nb.m, for use in GLOBEC.
% 2001/09/11 JH changed to use the rawadcp/rdi/@nb scheme

if (nargin < 2)
   help(mfilename)
   error('must set 4-digit yearbase')
end
if ((yearbase < 1980) | (yearbase > 2070))
   error('must set 4-digit yearbase')
end


if nargin == 2,
   outdir = './';
end

[path, name, ext] = fileparts(filename);
amp_file = fullfile(outdir, [name, '.amp']);


% from the old read_nb
%   read_nb(file, offset, nprof, step, varargin)
%d = read_nb(filename, 0, 1e5, 1, 'amp');

d = read(nb, filename, 'yearbase', yearbase, 'vars', 'amp');

fid = fopen(amp_file, 'w');
nn = fwrite(fid, d.amp, 'uchar');
fclose(fid);


