0001 function [s,spath,sfileid,newstruct] = imake_struct_jd(dkepath,s,sname,spath,sfileid,equil,basestr,smakecmd,external,status,sbase,workdir,sdefault,opt_gui,opt_multi,opt_id,d_opt,e_opt)
0002
0003
0004
0005
0006 if nargin < 18,
0007 e_opt = 1;
0008 end
0009 if nargin < 17,
0010 d_opt = 1;
0011 end
0012 if nargin < 16,
0013 opt_id = 1;
0014 end
0015 if nargin < 15,
0016 opt_multi = 0;
0017 end
0018 if nargin < 14,
0019 opt_gui = true;
0020 end
0021 if nargin < 13,
0022 sdefault = '';
0023 end
0024 if nargin < 12,
0025 workdir = pwd;
0026 end
0027 if nargin < 11,
0028 sbase = '';
0029 end
0030 if nargin < 10,
0031 status = 0;
0032 end
0033 if nargin < 9,
0034 external = '';
0035 end
0036 if nargin < 8,
0037 smakecmd = '';
0038 end
0039 if nargin < 7,
0040 error('Not enough arguments.');
0041 end
0042
0043 newstruct = 0;
0044
0045 if e_opt && isempty(equil),
0046 disp(['-----> An equilibrium structure must exist to create a ''',sname,''' structure.']);
0047 return
0048 end
0049
0050 ns = length(s);
0051
0052 if e_opt,
0053 sbase_eq = [sbase,'_',equil.id];
0054 else
0055 sbase_eq = sbase;
0056 end
0057
0058
0059
0060 if opt_multi == 0,
0061 if status == 1,
0062
0063 if isempty(sfileid),
0064 disp(['The current structure ''',sname,''' is not saved separately in a file.'])
0065 else
0066 disp(['The current structure ''',sname,''' is saved in the file: ',spath,sbase_eq,'_',sfileid,'.mat']);
0067 end
0068
0069 m_opt = input_dke_yp(['Do you want to: \n(-1) clear the existing ''',sname,''' structure \n(0) see/modify/save the ''',sname,''' structure \n(1) load an existing ''',sname,''' structure \n(2) build a new ''',sname,''' structure\n(3) return to the main menu\n'],0,[-1,0,1,2,3]);
0070
0071 else
0072
0073 m_opt = input_dke_yp(['Do you want to: \n(1) load an existing ''',sname,''' structure \n(2) build a new ''',sname,''' structure\n(3) return to the main menu\n'],1,[1,2,3]);
0074
0075 end
0076
0077
0078
0079 else
0080 if status == 1,
0081
0082 for is = 1:length(s),
0083 sstr = ['--> ',sname,' # ',num2str(is),'; id : ',s{is}.id,'; '];
0084 if isempty(sfileid{is}),
0085 disp([sstr,'This structure is not saved separately in a file.'])
0086 else
0087 disp([sstr,'This structure is saved in the file: ',spath{is},sbase_eq,'_',sfileid{is},'.mat']);
0088 end
0089 end
0090
0091 m_opt = input_dke_yp(['Do you want to: \n(-1) clear existing ''',sname,''' structures \n(0) see/modify/save a ''',sname,''' structure \n(1) load existing ''',sname,''' structures \n(2) build a new ''',sname,''' structure\n(3) return to the main menu\n'],0,[-1,0,1,2,3]);
0092
0093 else
0094
0095 m_opt = input_dke_yp(['Do you want to: \n(1) load existing ''',sname,''' structures \n(2) build a new ''',sname,''' structure\n(3) return to the main menu\n'],1,[1,2,3]);
0096
0097 end
0098 end
0099
0100 if m_opt == -1,
0101
0102 if opt_multi == 0,
0103
0104 s = '';
0105 spath = '';
0106 sfileid = '';
0107 newstruct = 1;
0108
0109 disp(['-----> The structure ''',sname,''' is cleared.'])
0110
0111 else
0112
0113 c_list = input_dke_yp(['Provide the vector of structure ''',sname,''' numbers to be cleared '],1:ns,[1;ns]);
0114
0115 s(c_list) = [];
0116 spath(c_list) = [];
0117 sfileid(c_list) = [];
0118
0119 if length(c_list) >= 1,
0120 newstruct = 1;
0121
0122 disp(['-----> The structures ''',sname,''' # ',num2str(c_list),' are cleared.'])
0123
0124 end
0125
0126 end
0127
0128 return
0129 end
0130
0131 if m_opt == 1,
0132
0133
0134
0135
0136
0137 [s_new,path_new,file_new] = iload_struct_jd(sname,sbase,sdefault,opt_gui,opt_multi,opt_id);
0138
0139 if ~isempty(s_new),
0140
0141 if opt_multi == 0,
0142
0143 s = s_new;
0144
0145 istr = strfind(file_new,sbase_eq);
0146 if ~isempty(istr),
0147 spath = path_new;
0148 sfileid = file_new(length(sbase_eq)+istr+1:end-4);
0149 else
0150 spath = '';
0151 sfileid = '';
0152 end
0153
0154 newstruct = 1;
0155
0156 c_opt = input_dke_yp(['Do you want to see/modify/save the ''',sname,''' structure (y/n)'],'n',{'y','n'});
0157
0158 if strcmp(c_opt,'y'),
0159 m_opt = 0;
0160 end
0161
0162 else
0163
0164 ns_new = length(s_new);
0165
0166 s = [s,s_new];
0167 spath = [spath,repmat({''},[1,ns_new])];
0168 sfileid = [sfileid,repmat({''},[1,ns_new])];
0169
0170 for is = 1:ns_new,
0171 istr = strfind(file_new{is},sbase_eq);
0172 if ~isempty(istr),
0173 spath{end - ns_new + is} = path_new{is};
0174 sfileid{end - ns_new + is} = file_new{is}(length(sbase_eq)+istr+1:end-4);
0175 end
0176 end
0177
0178 newstruct = 1;
0179
0180 end
0181
0182 end
0183
0184 elseif m_opt == 2,
0185
0186 if isempty(smakecmd)
0187 disp('No make command is available for this structure');
0188 s_new = '';
0189 else
0190 if ~isstruct(external) && any(isnan(external)),
0191 s_new = feval(smakecmd,dkepath,basestr,workdir,opt_gui);
0192 elseif isfield(external,sname),
0193 s_new = feval(smakecmd,dkepath,basestr,equil,external.(sname),workdir,opt_gui);
0194 else
0195 s_new = feval(smakecmd,dkepath,basestr,equil,'',workdir,opt_gui);
0196 end
0197 end
0198
0199 if ~isempty(s_new),
0200
0201 disp(['-----> The structure ''',sname,''' has been created']);
0202
0203 if opt_multi == 0,
0204
0205 s = s_new;
0206
0207 else
0208
0209 s = [s,{s_new}];
0210
0211 end
0212
0213 newstruct = 1;
0214 m_opt = 1i;
0215
0216 end
0217
0218 end
0219
0220 if real(m_opt) == 0,
0221
0222 if opt_multi == 0,
0223
0224 [s,mod] = imod_struct_jd(s,sname,d_opt,opt_gui);
0225
0226 if mod == 1,
0227
0228 if ~isfield(s,'id'),
0229 s.id = '';
0230 end
0231
0232 s.id = input_dke_yp(['Please provide a new id for the ''',sname,''' structure'],s.id);
0233 newstruct = 1;
0234
0235 end
0236
0237 if e_opt && isfield(equil,'id'),
0238 id_s = [equil.id,'_',s.id];
0239 else
0240 id_s = s.id;
0241 end
0242
0243 [path_new,file_new] = isave_struct_jd(s,sname,sbase,id_s,workdir,opt_gui);
0244
0245 istr = strfind(file_new,sbase_eq);
0246
0247 if ~isempty(istr),
0248 spath = path_new;
0249 sfileid = file_new(length(sbase_eq)+istr+1:end-4);
0250 else
0251 spath = '';
0252 sfileid = '';
0253 end
0254
0255 else
0256
0257 if imag(m_opt) == 0,
0258 is = input_dke_yp(['Provide the number of the structure ''',sname,''' to be seen/modified/saved '],1,[1;ns]);
0259 else
0260 is = ns + 1;
0261 end
0262
0263 [s{is},mod] = imod_struct_jd(s{is},sname,d_opt,opt_gui);
0264
0265 if mod == 1,
0266
0267 s{is}.id = input_dke_yp(['Please provide a new id for the ''',sname,''' structure'],s{is}.id);
0268 newstruct = 1;
0269
0270 end
0271
0272 if e_opt && isfield(equil,'id'),
0273 if isfield(s{is},'id')
0274 id_s = [equil.id,'_',s{is}.id];
0275 else
0276 id_s = equil.id;
0277 end
0278 else
0279 id_s = s.id;
0280 end
0281
0282 [path_new,file_new] = isave_struct_jd(s{is},sname,sbase,id_s,workdir,opt_gui);
0283
0284 istr = strfind(file_new,sbase_eq);
0285
0286 if ~isempty(istr),
0287 spath{is} = path_new;
0288 sfileid{is} = file_new(length(sbase_eq)+istr+1:end-4);
0289 else
0290 spath{is} = '';
0291 sfileid{is} = '';
0292 end
0293
0294 end
0295
0296 end
0297