function [theResult]  = wmocode1770(varargin)
% wmocode1770: Fall rate equation of an xbt instrument.
% 
% DESCRIPTION: Given a code integer from the wmo code table 1770, 
% this function will return a structure containing the code numbe, instrument
% type and the a and b coefficients of the corresponding fall rate equation.
% 
% INPUT:
%  code: integer representing one of the wmo codes listed in the referenced web page.
%
% OUTPUT:
% 	wmo_entry: structure containing the following fields
% wmo_entry =
% 1x1 struct array with fields:
%    code
%    instrument
%    a
%    b 
%
% If wmocode1770 is called with no input/output  arguments, then table 1770 
% is scrolled across the screen.
%
% SEE ALSO:
% The fall rate coefficients can be applied using apply_fall_rate.m
% 
% REFERENCES:
% http://www.nodc.noaa.gov/GTSPP/document/codetbls/wmocode.htm#tbl1770
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% AUTHOR: Derrick Snowden
%         NOAA/AOML/PhOD
%         Tue Sep 21 17:59:40 EDT 2004

error(nargchk(0,1,nargin))
if nargin == 1
	inCode = varargin{1};
else
	inCode = [];
end

% Get the data
wmo = get_wmotable;

% Rearrange the table that I downloaded from the web
for idx = 1: length(wmo)-1 % Deal with code>901 explicitly.
	this = wmo(idx,:);
	wmo1770(idx).code = str2num(this{1});
	wmo1770(idx).instrument = this{2};
	if isempty(this{3}) | isequal(this{3},'not applicable')
		wmo1770(idx).a = NaN;
		this{3} = 'NA';
	else
		wmo1770(idx).a = str2num(this{3});
	end
	if isempty(this{4}) | isequal(this{4},'not applicable')
		wmo1770(idx).b = NaN;
		this{4} = 'NA';
	else
		wmo1770(idx).b = str2num(this{4})./1000;
	end
	wmo(idx,:) = this;
end

% Now search through the structure for a match
codes = [wmo1770.code];
idx = [];
result = [];
if ~isempty(inCode)
	idx = find(codes==inCode);
end
if ~isempty(idx)
	result = wmo1770(idx);
end
if nargout > 0 
        theResult = result; 
else
	outDisp = wmo';
    disp(sprintf('%-3s %-55s %8s %8s\n',outDisp{:}));
end
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function wmo  = get_wmotable
% get_wmotable: 
%

% Initialize the table from the web address above.
% This awk code is helpful...
% awk 'BEGIN{RS="\n\n\n";FS="\n"}{printf(" \{\"%s\" \"%s\" \"%s\" \"%s\" \}\n ", $1,$2,$3,$4)}' 
% wmocode1770.m >! wmocode1770.txt

% {'Code Figure '] ['Instrument '] ['Coefficient a '] ['Coefficient b' ];
wmo=   {
['001'] ['Sippican T-4'] ['6.472'] ['-2.16' ];
['002'] ['Sippican T-4'] ['6.691'] ['-2.25' ];
['011'] ['Sippican T-5'] ['6.828'] ['-1.82' ];
['021'] ['Sippican Fast Deep'] ['6.346'] ['-1.82' ];
['031'] ['Sippican T-6'] ['6.472'] ['-2.16' ];
['032'] ['Sippican T-6'] ['6.691'] ['-2.25' ];
['041'] ['Sippican T-7'] ['6.472'] ['-2.16' ];
['042'] ['Sippican T-7'] ['6.691'] ['-2.25' ];
['051'] ['Sippican Deep Blue'] ['6.472'] ['-2.16' ];
['052'] ['Sippican Deep Blue'] ['6.691'] ['-2.25' ];
['061'] ['Sippican T-10'] ['6.301'] ['-2.16' ];
['071'] ['Sippican T-11'] ['1.779'] ['-0.255' ];
['201'] ['TSK T-4'] ['6.472'] ['-2.16' ];
['202'] ['TSK T-4'] ['6.691'] ['-2.25' ];
['211'] ['TSK T-6'] ['6.472'] ['-2.16' ];
['212'] ['TSK T-6'] ['6.691'] ['-2.25' ];
['221'] ['TSK T-7'] ['6.472'] ['-2.16' ];
['222'] ['TSK T-7'] ['6.691'] ['-2.25' ];
['231'] ['TSK T-5'] ['6.828'] ['-1.82' ];
['241'] ['TSK T-10'] ['6.301'] ['-2.16' ];
['251'] ['TSK Deep Blue'] ['6.472'] ['-2.16' ];
['252'] ['TSK Deep Blue'] ['6.691'] ['-2.25' ];
['261'] ['TSK Deep AXBT'] [''] ['' ];
['401'] ['Sparton XBT-1'] ['6.301'] ['-2.16' ];
['411'] ['Sparton XBT-3'] ['5.861'] ['-0.0904' ];
['421'] ['Sparton XBT-4'] ['6.472'] ['-2.16' ];
['431'] ['Sparton XBT-5'] ['6.828'] ['-1.82' ];
['441'] ['Sparton XBT-5DB'] ['6.828'] ['-1.82' ];
['451'] ['Sparton XBT-6'] ['6.472'] ['-2.16' ];
['461'] ['Sparton XBT-7'] ['6.472'] ['-2.16' ];
['462'] ['Sparton XBT-7'] ['6.705'] ['-2.28' ];
['471'] ['Sparton XBT-7DB'] ['6.472'] ['-2.16' ];
['481'] ['Sparton XBT-10'] ['6.301'] ['-2.16' ];
['491'] ['Sparton XBT-20'] ['6.472'] ['-2.16' ];
['501'] ['Sparton XBT-20DB'] ['6.472'] ['-2.16' ];
['700'] ['Sippican XCTD standard'] [''] ['' ];
['710'] ['Sippican XCTD deep'] [''] ['' ];
['720'] ['Sippican AXCTD'] [''] ['' ];
['730'] ['Sippican SXCTD'] [''] ['' ];
['741'] ['TSK XCTD'] [''] ['' ];
['751'] ['TSK AXCTD'] [''] ['' ];
['761'] ['Sparton XCTD standard'] ['3.38'] ['-0.214' ];
['800'] ['Mechanical XBT'] ['not applicable'] ['' ];
['810'] ['Hydrocast'] ['not applicable'] ['' ];
['820'] ['Thermistor Chain'] ['not applicable'] ['' ];
['830'] ['CTD'] ['not applicable'] ['' ];
['831'] ['CTD - P-ALACE float'] ['not applicable'] ['' ];
['840'] ['P-ALACE float, PROVOR, no conductivity sensor'] ['not applicable'] ['' ];
['841'] ['P-ALACE float, PROVOR, Seabird conductivity sensor'] ['not applicable'] ['' ];
['842'] ['P-ALACE float, PROVOR, FSI conductivity sensor'] ['not applicable'] ['' ];
['845'] ['P-ALACE float, Web Research, no conductivity sensor'] ['not applicable'] ['' ];
['846'] ['P-ALACE float, Web Research, Seabird conductivity sensor'] ['not applicable'] ['' ];
['847'] ['P-ALACE float, Web Research, FSI conductivity sensor'] ['not applicable'] ['' ];
['850'] ['P-ALACE float, SOLO, no conductivity sensor'] ['not applicable'] ['' ];
['851'] ['P-ALACE float, SOLO, Seabird conductivity sensor'] ['not applicable'] ['' ];
['852'] ['P-ALACE float, SOLO, FSI conductivity sensor'] ['not applicable'] ['' ];
['855'] ['Profiling float, NINJA, no conductivity sensor'] ['not applicable'] ['' ];
['856'] ['Profiling float, NINJA, SBE conductivity sensor'] ['not applicable'] ['' ];
['857'] ['Profiling float, NINJA, FSI conductivity sensor'] ['not applicable'] ['' ];
['858'] ['Profiling float, NINJA, TSK conductivity sensor'] ['not applicable'] ['' ];
['900'] ['Sippican T-12 XBT'] ['9.727'] ['-0.0000473' ];
['901-999'] ['Reserved'] ['Reserved'] ['Reserved'] };
return