0001 function matmk_var=save_matmk(matmk_var,new_fname,new_fname_path,force)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 if nargin<4,
0078 force=0;
0079 end
0080
0081
0082 var_type=[];
0083 if isfield(matmk_var,'freqs'),
0084 if isfield(matmk_var,'group_desc'),
0085 var_type='specGRP';
0086 else
0087 var_type='specGND';
0088 end
0089 elseif isfield(matmk_var,'tfr_fname'),
0090 var_type='TFR';
0091 elseif isfield(matmk_var,'ftrip'),
0092 var_type='tfrGND';
0093 elseif isfield(matmk_var,'group_desc'),
0094 var_type='GRP';
0095 elseif isfield(matmk_var,'grands'),
0096 var_type='GND';
0097 end
0098 if isempty(var_type),
0099 error('The first argument of save_matmk.m needs to be a GND, GRP, specGND, specGRP, TFR, or tfrGND variable.');
0100 end
0101
0102
0103 if ismac || isunix
0104
0105 slash='/';
0106 else
0107
0108 slash='\';
0109 end
0110
0111 gui=0;
0112 if nargin>1,
0113
0114 if strcmpi(new_fname,'gui'),
0115 gui=1;
0116 end
0117
0118
0119 if nargin==2 || isempty(new_fname_path),
0120
0121 new_fname_path=[pwd slash];
0122 end
0123 if new_fname_path(end)~=slash,
0124 new_fname_path=[new_fname_path slash];
0125 end
0126 if ~gui
0127 if strcmpi(var_type,'TFR'),
0128 matmk_var.tfr_fname=[new_fname_path new_fname];
0129 else
0130 matmk_var.filepath=new_fname_path;
0131 matmk_var.filename=new_fname;
0132 end
0133 end
0134 full_fname=[new_fname_path new_fname];
0135 else
0136
0137 if strcmpi(var_type,'TFR'),
0138 slash_ids=find(matmk_var.tfr_fname==slash);
0139 if isempty(slash_ids),
0140 new_fname_path=[pwd slash];
0141 full_fname=[new_fname_path matmk_var.tfr_fname];
0142 else
0143 new_fname_path=matmk_var.tfr_fname(1:slash_ids(end));
0144 full_fname=matmk_var.tfr_fname;
0145 end
0146 else
0147 if isempty(matmk_var.filepath),
0148
0149
0150 matmk_var.filepath=[pwd slash];
0151 end
0152 new_fname_path=matmk_var.filepath;
0153 full_fname=[matmk_var.filepath matmk_var.filename];
0154 end
0155 end
0156
0157 if ~isempty(full_fname) && ~gui,
0158
0159 if force,
0160 resp='y';
0161 else
0162 resp=[];
0163 end
0164 while ~(strcmpi(resp,'y') || strcmpi(resp,'yes') || strcmpi(resp,'n') || strcmpi(resp,'no'))
0165 fprintf('Save %s variable as %s? (y or n)',var_type,full_fname);
0166 resp=input('','s');
0167 if ~(strcmpi(resp,'y') || strcmpi(resp,'yes') || strcmpi(resp,'n') || strcmpi(resp,'no'))
0168 fprintf('Please respond with just the letter "n" or the letter "y" (no quotes).\n');
0169 end
0170 end
0171 if strcmpi(resp,'y') || strcmpi(resp,'yes'),
0172 matmk_var.saved='yes';
0173 if ismac || isunix
0174
0175 [s ss]=unix(['ls "' new_fname_path '"']);
0176
0177
0178 else
0179
0180 if isdir(new_fname_path),
0181 s=0;
0182 else
0183 s=1;
0184 end
0185 end
0186 if s,
0187
0188 watchit(sprintf('Path %s does NOT exist.',new_fname_path));
0189 fprintf('Saving variable to disk aborted. %s variable NOT saved to disk.\n',var_type);
0190 else
0191 if strcmpi(var_type,'GRP'),
0192 GRP=matmk_var;
0193 elseif strcmpi(var_type,'GND'),
0194 GND=matmk_var;
0195 elseif strcmpi(var_type,'specGND'),
0196 specGND=matmk_var;
0197 elseif strcmpi(var_type,'specGRP'),
0198 specGRP=matmk_var;
0199 elseif strcmpi(var_type,'TFR'),
0200 TFR=matmk_var;
0201 else
0202 tfrGND=matmk_var;
0203 end
0204 save(full_fname,var_type);
0205 fprintf('%s variable successfully saved to disk.\n',var_type);
0206 end
0207 else
0208 fprintf('Saving variable to disk aborted. %s variable NOT saved to disk.\n',var_type);
0209 end
0210 else
0211
0212 if strcmpi(var_type,'GRP'),
0213 [jname, jpath]=uiputfile({'*.GRP','*.GRP files',; ...
0214 '*.*','All files'},sprintf('Save GRP variable as:','untitled.GRP'));
0215 elseif strcmpi(var_type,'GND'),
0216 [jname, jpath]=uiputfile({'*.GND','*.GND files'; ...
0217 '*.*','All files'},sprintf('Save GND variable as:','untitled.GND'));
0218 elseif strcmpi(var_type,'specGND'),
0219 [jname, jpath]=uiputfile({'*.specGND','*.specGND files'; ...
0220 '*.*','All files'},sprintf('Save specGND variable as:','untitled.specGND'));
0221 elseif strcmpi(var_type,'specGRP'),
0222 [jname, jpath]=uiputfile({'*.specGRP','*.specGRP files'; ...
0223 '*.*','All files'},sprintf('Save specGRP variable as:','untitled.specGRP'));
0224 elseif strcmpi(var_type,'TFR'),
0225 [jname, jpath]=uiputfile({'*.tfr','*.tfr files'; ...
0226 '*.*','All files'},sprintf('Save TFR variable as:','untitled.tfr'));
0227 else
0228
0229 [jname, jpath]=uiputfile({'*.tfrGND','*.tfrGND files'; ...
0230 '*.*','All files'},sprintf('Save tfrGND variable as:','untitled.tfrGND'));
0231 end
0232 if ~jpath,
0233 fprintf('Output filename selection cancelled. %s variable NOT saved to disk.\n',var_type);
0234 else
0235 matmk_var=save_matmk(matmk_var,jname,jpath,1);
0236 end
0237 end
0238