Home > ctdcal > make_cruise_dir.m

make_cruise_dir

PURPOSE ^

make_cruise_dir: Setup a new working directory for CTD calibration.

SYNOPSIS ^

function [newPath] = make_cruise_dir(varargin)

DESCRIPTION ^

 make_cruise_dir: Setup a new working directory for CTD calibration.
 
 CTD Calibration toolbox
 
 INPUT: 
    parent_dir: Full or relative path to the parent directory of the calibration_dir
   calibration_dir: Name of the desired directory 

 OUTPUT:
   newdir: the absolute path to the new cruise directory.    

 DESCRIPTION:
   This program will create a new cruise calibration working 
 directory and all the necessary subdirectories to store the CTD  data.
 Additionally, several m files are created which must be edited for each
 new calibration project.

 Depending on the calling syntax, the "calibration_dir" directory will be created 
 in the current working directory or in the given "parent_dir"

 >> theDir = make_cruise_dir('stc02');
 will make a directory called stc02 in the current working directory.

 >> theDir = make_cruise_dir('/data/cruises/','stc02')
 will put the cruise directory in the parent directory /data/cruises.
 
 SEE ALSO: mkdir

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [newPath]  = make_cruise_dir(varargin)
0002 % make_cruise_dir: Setup a new working directory for CTD calibration.
0003 %
0004 % CTD Calibration toolbox
0005 %
0006 % INPUT:
0007 %    parent_dir: Full or relative path to the parent directory of the calibration_dir
0008 %   calibration_dir: Name of the desired directory
0009 %
0010 % OUTPUT:
0011 %   newdir: the absolute path to the new cruise directory.
0012 %
0013 % DESCRIPTION:
0014 %   This program will create a new cruise calibration working
0015 % directory and all the necessary subdirectories to store the CTD  data.
0016 % Additionally, several m files are created which must be edited for each
0017 % new calibration project.
0018 %
0019 % Depending on the calling syntax, the "calibration_dir" directory will be created
0020 % in the current working directory or in the given "parent_dir"
0021 %
0022 % >> theDir = make_cruise_dir('stc02');
0023 % will make a directory called stc02 in the current working directory.
0024 %
0025 % >> theDir = make_cruise_dir('/data/cruises/','stc02')
0026 % will put the cruise directory in the parent directory /data/cruises.
0027 %
0028 % SEE ALSO: mkdir
0029 %
0030 
0031 
0032 % ERRORS: If there is an error, newdir, will be returned empty and the error
0033 %    message can be retrieved using the lasterr syntax.
0034 %
0035 %
0036 
0037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0038 % CHANGELOG:
0039 %   08-Jul-2004, Version 1.0
0040 %        * Initial version.
0041 %10-Aug-2004   DPS
0042 %    * create_cruise_dir.m (): Added different error checking, fixed one logical bug associated %with isempty(dir())
0043 %     16-Sep-2004, DPS
0044 %        * Renamed to make_cruise_dir for consistency with ctdcal toolbox
0045 %23-Sep-2004  DPS
0046 %    *  (make_cruise_dir): Eliminate cruiseid in favor of calib_dir to emphasize that the cruiseid
0047 %            and the name of the directory do not need to be the same.
0048 %
0049 % AUTHOR:
0050 %            Carlos Fonseca
0051 %         UM/CIMAS
0052 %         Mon Jul 12 13:02:10 EDT 2004
0053 
0054 
0055 % default output in case of error
0056 newPath = '';
0057 
0058 % Parse input parameters
0059 msg = nargchk(1,2,nargin);
0060 if ~isempty(msg)
0061     lasterror(struct('message',msg,'identifier','CTD:IncorrectNargin'));
0062     return
0063 end
0064 
0065 if nargin == 1
0066     parent_dir = pwd;
0067     calibration_dir = varargin{1};
0068 elseif nargin == 2
0069     parent_dir = varargin{1};
0070     calibration_dir = varargin{2};
0071 else
0072     lasterror(struct('message','Error parsing input arguments.',...
0073             'identifier','CTD:UnknownAssertion'));
0074     return
0075 end
0076 
0077 
0078 %-------------------------------------------------------------------------------
0079 %- Create the top level output directory
0080 namedir = fullfile(parent_dir,calibration_dir);
0081 fprintf('Creating directory %s...\n',namedir);                 
0082 [status,msg,msgid] = mkdir(parent_dir,calibration_dir);
0083 if ~status
0084     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0085     fprintf('Unable to create the directory %s ...\n',namedir); 
0086     return
0087 end
0088 fprintf('%s successfully created.\n',namedir);                 
0089 
0090 % Rename the namedir since calibration_dir serves as parent_dir for the
0091 % remainder of this function.
0092 calibration_dir = namedir;
0093 
0094 %-------------------------------------------------------------------------------
0095 %- Create directory tree beneath the calibration_dir
0096 [status, msg, msgid] = mkdir(calibration_dir, 'mfiles');
0097 if ~status
0098     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0099     fprintf('Unable to create the directory %s ...\n',calibration_dir); 
0100     return
0101 end
0102 [status, msg, msgid] = mkdir(calibration_dir, 'bottle');
0103 if ~status
0104     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0105     fprintf('Unable to create the directory %s ...\n',calibration_dir); 
0106     return
0107 end
0108 [status, msg, msgid] = mkdir(calibration_dir, 'salts');
0109 if ~status
0110     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0111     fprintf('Unable to create the directory %s ...\n',calibration_dir); 
0112     return
0113 end
0114 [status, msg, msgid] = mkdir(calibration_dir, 'oxy');
0115 if ~status
0116     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0117     fprintf('Unable to create the directory %s ...\n',calibration_dir); 
0118     return
0119 end
0120 [status, msg, msgid] = mkdir(calibration_dir, 'proc_data');
0121 if ~status
0122     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0123     fprintf('Unable to create the directory %s ...\n',calibration_dir); 
0124     return
0125 end
0126 [status, msg, msgid] = mkdir(calibration_dir, 'raw_data');
0127 if ~status
0128     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0129     fprintf('Unable to create the directory %s ...\n',calibration_dir); 
0130     return
0131 end
0132 [status, msg, msgid] = mkdir(calibration_dir, 'calibrated');
0133 if ~status
0134     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0135     fprintf('Unable to create the directory %s ...\n',calibration_dir); 
0136     return
0137 end
0138 [status, msg, msgid] = mkdir(calibration_dir, 'log');
0139 if ~status
0140     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0141     fprintf('Unable to create the directory %s ...\n',calibration_dir); 
0142     return
0143 end
0144 [status, msg, msgid] = mkdir(calibration_dir, 'tmp');
0145 if ~status
0146     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0147     fprintf('Unable to create the directory %s ...\n',calibration_dir); 
0148     return
0149 end
0150 [status, msg, msgid] = mkdir(calibration_dir, 'figures');
0151 if ~status
0152     lasterror(struct('message',msg,'identifier',['CTD:' msgid]));
0153     fprintf('Unable to create the directory %s ...\n',calibration_dir); 
0154     return
0155 end
0156 
0157 %-------------------------------------------------------------------------------
0158 %- Create and/or copy the user editable tmeplates into the calibration_dir
0159 % TODO: There must be a better way to do this.  It requires /demo/ be below ctdcal.
0160 inst_dir = ctdcal('path');
0161 [status,msg,msgid] = copyfile(fullfile(inst_dir,'demos','register_cruise.m'),...
0162         fullfile(calibration_dir,'mfiles',['register_cruise.m']) );
0163 if ~status
0164     warning(msgid,msg)
0165     fprintf('Unable to copy register_cruise.m from %s to %s.\n',fullfile(inst_dir,'demos'),calibration_dir); 
0166 end    
0167 
0168 % Create a new startup type file for easy path management.
0169 [fid,msg] = fopen(fullfile(calibration_dir,'ctdcalpath.m'),'wt');
0170 if fid < 0
0171     fprintf('Unable to create  %s. \n',fullfile(calibration_dir,'ctdcalpath.m')); 
0172 else
0173     fprintf(fid,'%%  ctdcalpath - Add ctdcal and current cruise calibration directories to matlabpath.\n',' ');
0174     fprintf(fid,'%% \n',' ');
0175     fprintf(fid,'%% \n',' ');
0176     fprintf(fid,' \n',' ');
0177     fprintf(fid,'addpath %s \n',inst_dir);
0178     fprintf(fid,'addpath %s \n',calibration_dir);
0179     fprintf(fid,'addpath  %s \n',fullfile(calibration_dir,'mfiles'));
0180     fprintf(fid,' \n',' ');
0181     fclose (fid);    
0182 end
0183 
0184 
0185 if nargout > 0
0186         newPath = calibration_dir;
0187 else
0188         assignin('caller', 'ans', calibration_dir);
0189 end
0190 return
0191

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