function groupName  = group_name(cruiseid)
% GROUP_NAME - get the preference group name for a given cruiseid
%
% AOML/PhOD CTDCalibration toolbox.
%
% USAGE: groupName  = group_name(cruiseid)
% 
% INPUT: cruiseid (string): valid cruiseid.
% 
% OUTPUT: groupName (string): the corresponding group name.
% 
% DESCRIPTION:  This function creates the group name to be used with the
% preference management functions in the CTDCalibration toolbox.  It does not
% check to see if the given cruiseid is registered in the preferences
% database, it only returns a valid groupname for future or current use.  The
% cruiseid is altered if it contains spaces.  Leading and trailing spaces are
% deleted, multiple spaces are deleted and the remaining single spaces are
% replaced by underscores.
% 

% AUTHOR: Derrick Snowden
%         NOAA/AOML/PhOD
%         Tue May 11 11:23:37 EDT 2004
% 
% SEE ALSO: register_cruise, ctdgetpref, ctdsetpref, ctdshowpref
% 
% DEPENDENCIES:
%
% EXAMPLES: 
% theGroupName = group_name('stc02')
% 
% REFERENCES:

% 
% VERSION: 
%	$Revision: 1.7 $
%	$Date: 2008/02/18 19:34:17 $
%	$Id: group_name.m,v 1.7 2008/02/18 19:34:17 duncombe Exp duncombe $

% CHANGELOG:
% 2007/11/27 CMDR - There is a whole directory structure set up
% for a cruise, and the calibration process starts with cd'ing to
% that directory structure. Therefore it seems counter productive
% to have to essentially enter the cruiseid by hand each time.
% Create a cruise_id file, which has the cruise id in it, and use
% that. Create a function getcruiseid which searches for this
% file, reads it if it exists and otherwise proceeds as
% previously done, ie to fail with error.  I attempted to do this
% by having the cruise id be determined by group_name function
% but that requires too many other changes have to be made. 

% Check for correct number of inputs.
% error(nargchk(1,1,nargin))
if nargin==0, cruiseid=getcruiseid; end;

% error(nargchk(1,1,nargin));
% 
% % if cruiseid is empty, we cannot recover...punt.
% if isempty(cruiseid)
% 	error('cruiseid must be nonempty.');
% end

% NOTE % This may give unpredictable results and may be removed.
if ~ischar(cruiseid)
	cruiseid = char(cruiseid);
end

% pretty things up.
cruiseid = ddewhite(cruiseid);
cruiseid = strrep(cruiseid,' ','_');

groupName = [cruiseid,'_ctd_calibration'];

return


