Home > ctdcal > load_cnv.m

load_cnv

PURPOSE ^

load_cnv: Load the informationin the *.cnv files into the cruise database

SYNOPSIS ^

function varargout = load_cnv(cruiseid)

DESCRIPTION ^

 load_cnv: Load the informationin the *.cnv files into the cruise database

 CTD Calibration toolbox.

 load_cnv reads the data contained in the  SeaBird ASCII .CNV files 
 for a given cruise.  The data is then saved in the cruise database file 
 for later use.  The cruise database file is stored in the cruise directory 
 as definied in register_cruise.m.  See the User's Guide for more information.

 INPUT: 
    cruiseid: Cruise identification name. 

 OUTPUT: 
    cnv_struct: vector of structures each containing the data in 
             one *.cnv file.

 USAGE: 
 load_cnv(cruiseid) 
                     
 cnv=load_cnv(cruiseid)

 SEE ALSO:
        register_cruise, and read_sbecnv

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout  = load_cnv(cruiseid)
0002 % load_cnv: Load the informationin the *.cnv files into the cruise database
0003 %
0004 % CTD Calibration toolbox.
0005 %
0006 % load_cnv reads the data contained in the  SeaBird ASCII .CNV files
0007 % for a given cruise.  The data is then saved in the cruise database file
0008 % for later use.  The cruise database file is stored in the cruise directory
0009 % as definied in register_cruise.m.  See the User's Guide for more information.
0010 %
0011 % INPUT:
0012 %    cruiseid: Cruise identification name.
0013 %
0014 % OUTPUT:
0015 %    cnv_struct: vector of structures each containing the data in
0016 %             one *.cnv file.
0017 %
0018 % USAGE:
0019 % load_cnv(cruiseid)
0020 %
0021 % cnv=load_cnv(cruiseid)
0022 %
0023 % SEE ALSO:
0024 %        register_cruise, and read_sbecnv
0025 %
0026 %
0027 
0028 % AUTHORS:
0029 %        Carlos Fonseca
0030 %      UM/CIMAS
0031 %      Derrick Snowden
0032 %      NOAA/AOML/PhOD
0033 %      Tue May 11 11:23:37 EDT 2004
0034 %
0035 % CHANGELOG:
0036 %   23-Jul-2004, Version 1.0
0037 %        * Initial version.
0038 %   01-Oct-2004  Derrick Snowden
0039 %        * load_cnv (load_cnv): Removed dependence on directory structure in favor of
0040 %             register_cruise
0041 
0042 % Check for correct number of inputs.
0043 error(nargchk(1,1,nargin))
0044 
0045 % Retrieve the necessary preferences for this cruise
0046 group = group_name(cruiseid);
0047 
0048 % cnv_dir is the calibration data directory
0049 if ispref(group,'cal_cnv_dir')
0050     cnv_dir=getpref(group,'cal_cnv_dir');
0051 else
0052     error(['The cal_cnv_dir preference was not set for cruise: ' cruiseid '.  Run register_cruise.m']);
0053 end
0054 
0055 % cruise_dir is the calibration data directory
0056 if ispref(group,'cal_data_dir')
0057     cruise_dir=getpref(group,'cal_data_dir');
0058 else
0059     error(['The cal_data_dir preference was not set for cruise: ' cruiseid '.  Run register_cruise.m']);
0060 end
0061 
0062 % Check that the cnv files are in the given directory.
0063 % TODO: Make use of the upper case/lower case preference.
0064 lc_cnv = dir(fullfile(cnv_dir,'*.cnv')); 
0065 uc_cnv = dir(fullfile(cnv_dir,'*.CNV'));
0066 if size(lc_cnv)==size(uc_cnv)
0067     cnv_names = lc_cnv;
0068 else
0069     if ~isempty(lc_cnv) & ~isempty(uc_cnv)
0070         error(['The *.cnv files in ', cnv_dir...
0071         ,' are named in both upper and lower case.  Pick one and rename before running ',mfilename]);
0072     elseif isempty(lc_cnv) & ~isempty(uc_cnv)
0073         cnv_names = uc_cnv;
0074     elseif ~isempty(lc_cnv) & isempty(uc_cnv)
0075         cnv_names = lc_cnv;
0076     else
0077         error(['No *.cnv files were found in ', cnv_dir]);
0078     end
0079 end
0080 
0081 % The files are there, retrieve the data.
0082 for i=1:length(cnv_names)
0083     cnv(i)=read_sbecnv(fullfile(cnv_dir,cnv_names(i).name));
0084 end
0085 
0086 % Open the output file
0087 db_file = fullfile(cruise_dir,[cruiseid '_db.mat']);
0088 if exist(db_file)==2
0089     save(db_file,'cnv','-append');
0090 else
0091     save(db_file,'cnv');
0092 end
0093 if nargout==0
0094     assignin('caller','ans',cnv);
0095     return
0096 else
0097     varargout{1}=cnv;
0098     return
0099 end
0100

Generated on Fri 08-Oct-2004 11:57:17 by m2html © 2003