Changeset 599 for trunk/src/series/relabel_i_j.m
- Timestamp:
- Apr 3, 2013, 10:21:53 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/series/relabel_i_j.m
r563 r599 3 3 % function ParamOut=relabel_i_j(Param) 4 4 %------------------------------------------------------------------------ 5 5 % 6 6 %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% 7 7 % 8 % This function is used in four modes by the GUI series:9 % 1) config GUI: with no input argument, the function determine the suitable GUI configuration10 % 2) interactive input: the function is used to interactively introduce input parameters, and then stops11 % 3) RUN: the function itself runs, when an appropriate input structure Param has been introduced.12 % 4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.13 %14 % This function is used in four modes by the GUI series:15 % 1) config GUI: with no input argument, the function determine the suitable GUI configuration16 % 2) interactive input: the function is used to interactively introduce input parameters, and then stops17 % 3) RUN: the function itself runs, when an appropriate input structure Param has been introduced.18 % 4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.19 %20 8 %OUTPUT 21 % GUI_input=list ofoptions in the GUI series.fig needed for the function9 % ParamOut: sets options in the GUI series.fig needed for the function 22 10 % 23 11 %INPUT: 24 12 % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. 25 13 % In batch mode, Param is the name of the corresponding xml file containing the same information 26 % In the absence of input(as activated when the current Action is selected27 % in series), the function ouput GUI_input set the activation of the needed GUI elements14 % when Param.Action.RUN=0 (as activated when the current Action is selected 15 % in series), the function ouput paramOut set the activation of the needed GUI elements 28 16 % 29 % Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param) 17 % Param contains the elements:(use the menu bar command 'export/GUI config' in series to 18 % see the current structure Param) 30 19 % .InputTable: cell of input file names, (several lines for multiple input) 31 20 % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} 32 21 % .OutputSubDir: name of the subdirectory for data outputs 33 % .OutputDir : directory for data outputs, including path22 % .OutputDirExt: directory extension for data outputs 34 23 % .Action: .ActionName: name of the current activated function 35 24 % .ActionPath: path of the current activated function 25 % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct 26 % .RUN =0 for GUI input, =1 for function activation 27 % .RunMode='local','background', 'cluster': type of function use 28 % 36 29 % .IndexRange: set the file or frame indices on which the action must be performed 37 30 % .FieldTransform: .TransformName: name of the selected transform function 38 31 % .TransformPath: path of the selected transform function 39 % .TransformHandle: corresponding function handle40 32 % .InputFields: sub structure describing the input fields withfields 41 % .FieldName: name of the field33 % .FieldName: name(s) of the field 42 34 % .VelType: velocity type 43 35 % .FieldName_1: name of the second field in case of two input series 44 36 % .VelType_1: velocity type of the second field in case of two input series 37 % .Coord_y: name of y coordinate variable 38 % .Coord_x: name of x coordinate variable 45 39 % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) 46 40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% … … 49 43 50 44 %% set the input elements needed on the GUI series when the action is selected in the menu ActionName 51 if ~exist('Param','var') % case with no input parameter 52 ParamOut={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation) 53 'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default) 54 'WholeIndexRange';'on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) 55 'NbSlice';'off'; ...%nbre of slices ('off' by default) 56 'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) 57 'FieldName';'off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) 58 'FieldTransform'; 'off';...%can use a transform function 59 'ProjObject';'off';...%can use projection object(option 'off'/'on', 60 'Mask';'off';...%can use mask option (option 'off'/'on', 'off' by default) 61 'OutputDirExt';'';...%set the output dir extension 62 ''}; 63 return 64 end 65 66 %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%% 67 %% select different modes, RUN, parameter input, BATCH 68 % BATCH case: read the xml file for batch case 45 if isstruct(Param) && isequal(Param.Action.RUN,0) 46 ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) 47 ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) 48 ParamOut.NbSlice='one'; ...%nbre of slices, 'one' prevents splitting in several processes, ('off' by default) 49 ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) 50 ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) 51 ParamOut.FieldTransform = 'off';...%can use a transform function 52 ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on', 53 ParamOut.Mask='off';...%can use mask option (option 'off'/'on', 'off' by default) 54 ParamOut.OutputDirExt='';%set the output dir extension 55 if size(Param.InputTable,1)>1 56 msgbox_uvmat('WARNING', 'this function acts only on the first input file line') 57 end 58 return 59 end 60 61 ParamOut=[]; 62 %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% 63 %% read input parameters from an xml file if input is a file name (batch mode) 64 checkrun=1; 69 65 if ischar(Param) 70 Param=xml2struct(Param); 71 checkrun=0; 72 % RUN case: parameters introduced as the input structure Param 73 else 74 hseries=guidata(Param.hseries);%handles of the GUI series 75 if isfield(Param,'Specific')&& strcmp(Param.Specific,'?') 76 checkrun=1;% will only search interactive input parameters (preparation of BATCH mode) 77 else 78 checkrun=2; % indicate the RUN option is used 79 end 80 end 81 ParamOut=Param; %default output 66 Param=xml2struct(Param);% read Param as input file (batch case) 67 checkrun=0; 68 end 82 69 83 70 %% root input file(s) and type … … 94 81 % numbers of slices and file indices 95 82 96 NbSlice=1;%default97 if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)98 NbSlice=Param.IndexRange.NbSlice;99 end100 nbview=numel(i1_series);%number of input file series (lines in InputTable)101 83 nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) 102 84 nbfield_i=size(i1_series{1},2); %nb of fields for the i index 103 85 nbfield=nbfield_j*nbfield_i; %total number of fields 104 nbfield_i=floor(nbfield/NbSlice);%total number of indexes in a slice (adjusted to an integer number of slices)105 nbfield=nbfield_i*NbSlice; %total number of fields after adjustement106 86 107 87 %determine the file type on each line from the first input file 108 88 ImageTypeOptions={'image','multimage','mmreader','video'}; 109 NcTypeOptions={'netcdf','civx','civdata'}; 110 for iview=1:nbview 111 if ~exist(filecell{iview,1}','file') 112 msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist']) 113 return 114 end 115 [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1}); 116 CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images 117 CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files 118 if ~isempty(j1_series{iview}) 119 frame_index{iview}=j1_series{iview}; 120 else 121 frame_index{iview}=i1_series{iview}; 122 end 123 end 89 90 if ~exist(filecell{1,1}','file') 91 msgbox_uvmat('ERROR',['the first input file ' filecell{1,1} ' does not exist']) 92 return 93 end 94 [FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1}); 95 CheckImage=~isempty(find(strcmp(FileType{1},ImageTypeOptions)));% =1 for images 96 124 97 125 98 %% calibration data and timing: read the ImaDoc files … … 128 101 itime=0; 129 102 NbSlice_calib={}; 130 XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing) 131 for iview=1:nbview%Loop on views 132 SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.' 133 filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder 103 104 SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.' 105 filexml=[fullfile(RootPath{1},SubDirBase) '.xml'];%new convention: xml at the level of the image folder 106 if ~exist(filexml,'file') 107 filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.xml']; % old convention: xml inside the image folder 134 108 if ~exist(filexml,'file') 135 filexml=[fullfile(RootPath{ iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder109 filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.civ']; % very old convention: .civ file 136 110 if ~exist(filexml,'file') 137 filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file 138 if ~exist(filexml,'file') 139 filexml=''; 140 end 141 end 142 end 143 if ~isempty(filexml) 144 [XmlData{iview},error]=imadoc2struct_special(filexml); 145 end 146 if isfield(XmlData{iview},'Time') 147 itime=itime+1; 148 timecell{itime}=XmlData{iview}.Time; 149 end 150 if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') 151 NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform 152 if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) 153 msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); 154 end 111 filexml=''; 112 end 113 end 114 end 115 if ~isempty(filexml) 116 [XmlData,error]=imadoc2struct_special(filexml); 117 end 118 if isfield(XmlData,'Time') 119 itime=itime+1; 120 timecell{itime}=XmlData.Time; 121 end 122 if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord') 123 NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform 124 if ~isequal(NbSlice_calib{1},NbSlice_calib{1}) 125 msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); 155 126 end 156 127 end … … 164 135 % EDIT FROM HERE 165 136 166 %% check the validity of input file types167 if CheckImage{1}168 FileExtOut='.png'; % write result as .png images for image inputs169 elseif CheckNc{1}170 FileExtOut='.nc';% write result as .nc files for netcdf inputs171 else172 msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])173 return174 end175 if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})176 msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')177 return178 end179 % NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series180 % if NbSlice~=nbfield_j181 % answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);182 % if ~strcmp(answer,'Yes')183 % return184 % end185 % end186 137 187 138 %% Set field names and velocity types … … 194 145 display('RDvision system') 195 146 first_label=0; %image numbers start from 0 196 if ~ strcmp(NomType{1},'_000001')147 if ~CheckImage || ~strcmp(NomType{1},'_000001') 197 148 msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation 198 149 return … … 206 157 %% copy and adapt the xml file 207 158 NomTypeNew='_1_1'; 208 if ~isempty(XmlData {1})159 if ~isempty(XmlData) 209 160 t=xmltree(filexml); 210 161 … … 233 184 234 185 %%%% correction RDvision %%%% 235 if isfield(XmlData {1},'NbDtj')186 if isfield(XmlData,'NbDtj') 236 187 uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj'); 237 188 uid_value=children(t,uid_NbDtj); 238 189 if ~isempty(uid_value) 239 t=set(t,uid_value(1),'value',num2str(XmlData {1}.NbDtj));240 end 241 end 242 if isfield(XmlData {1},'NbDtk')190 t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj)); 191 end 192 end 193 if isfield(XmlData,'NbDtk') 243 194 uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk'); 244 195 uid_value=children(t,uid_NbDtk); 245 196 if ~isempty(uid_value) 246 t=set(t,uid_value(1),'value',num2str(XmlData {1}.NbDtk));247 end 248 end 249 if isempty(j1_series{1}) && isfield(XmlData {1},'NbDti')197 t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk)); 198 end 199 end 200 if isempty(j1_series{1}) && isfield(XmlData,'NbDti') 250 201 uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti'); 251 t=add(t,uid_Dti,'chardata',num2str(XmlData {1}.Dti));202 t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti)); 252 203 uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti'); 253 t=add(t,uid_NbDti,'chardata',num2str(XmlData {1}.NbDti));204 t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti)); 254 205 uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj'); 255 206 uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk'); … … 264 215 SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.' 265 216 filexml_new=[fullfile(RootPath{1},SubDirBase) '.xml']; 266 save(t,filexml_new)217 % save(t,filexml_new) 267 218 end 268 219 269 220 %% main loop on images 270 221 %j1=[];%default 271 nbfield2=size(XmlData {1}.Time,2);222 nbfield2=size(XmlData.Time,2) 272 223 for ifile=1:nbfield 273 224 if checkrun 274 update_waitbar(hseries.Waitbar,ifile/nbfield) 275 drawnow 276 stopstate=get(hseries.RUN,'BusyAction'); 225 stopstate=get(Param.RUNHandle,'BusyAction'); 226 update_waitbar(Param.WaitbarHandle,ifile/nbfield) 277 227 else 278 228 stopstate='queue'; 279 229 end 280 if isequal(stopstate,'queue') % enable STOP command 281 filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile)); 282 j1=mod(ifile-1+first_label,nbfield2)+1; 283 i1=floor((ifile-1+first_label)/nbfield2)+1; 284 filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1); 285 try 286 movefile(filename,filename_new); 287 [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a') 288 if ~s 289 msgbox_uvmat('ERROR',errormsg); 290 return 291 end 292 catch ME 293 msgbox_uvmat('ERROR',ME.message); 230 if ~isequal(stopstate,'queue')% enable STOP command 231 break 232 end 233 filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile)); 234 j1=mod(ifile-1+first_label,nbfield2)+1; 235 i1=floor((ifile-1+first_label)/nbfield2)+1; 236 filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1); 237 try 238 movefile(filename,filename_new); 239 [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a') 240 if ~s 241 msgbox_uvmat('ERROR',errormsg); 294 242 return 295 243 end 296 end 244 catch ME 245 msgbox_uvmat('ERROR',ME.message); 246 return 247 end 248 297 249 end 298 250
Note: See TracChangeset
for help on using the changeset viewer.