Index: /trunk/src/ListDir.m
===================================================================
--- /trunk/src/ListDir.m (revision 2)
+++ /trunk/src/ListDir.m (revision 2)
@@ -0,0 +1,98 @@
+%'ListDir': scan the structure of the directory tree (for dataview.m)
+%------------------------------------------------------------------------
+function [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices_in,ListRecords_in)
+
+ListRecords={};
+ListDevices={};
+ListXml={};
+irecord_tot=0;
+idevice_tot=0;
+ixml_tot=0;
+for iexp=1:length(ListExperiments)
+ List.Experiment{iexp}.name=ListExperiments{iexp};
+ hdir=dir(fullfile(CurrentPath,ListExperiments{iexp}));
+ idevice=0;
+ for isub=1:length(hdir)% scan the sub-directories of the current experiment
+ if hdir(isub).isdir
+ name=hdir(isub).name;%name of the current device
+ if ~isequal(name(1),'.')% subdirectory of the current experiment
+ [testnew,testselect]=test_select(name,ListDevices,ListDevices_in);
+ if testselect
+ idevice=idevice+1;
+ List.Experiment{iexp}.Device{idevice}.name=name;
+ if testnew
+ idevice_tot=idevice_tot+1;
+ ListDevices{idevice_tot}=name;
+ end
+ CurrentDevice=fullfile(CurrentPath,ListExperiments{iexp},name);
+ hsubxml=dir(fullfile(CurrentDevice,'*.xml'));%look at xml files in the subdirectory of the current device
+ if isempty(hsubxml) % the subdirectory of the current device contains directories 'Record''
+ hsubdir=dir(fullfile(CurrentPath,ListExperiments{iexp},name));%list what is inside the directory 'Device'
+ irecord=0;
+ for isubsub=1:length(hsubdir)% subdirectories of the current device
+ if hsubdir(isubsub).isdir
+ RecordName=hsubdir(isubsub).name;
+ if ~isequal(RecordName(1),'.')
+ [testnew,testselect]=test_select(RecordName,ListRecords,ListRecords_in);
+ if testselect
+ if testnew
+ irecord_tot=irecord_tot+1;
+ ListRecords{irecord_tot}=RecordName;
+ end
+ irecord=irecord+1;
+ List.Experiment{iexp}.Device{idevice}.Record{irecord}.name=RecordName;
+ hsubsubxml=dir(fullfile(CurrentDevice,RecordName,'*.xml'));%
+ for ixml=1:length(hsubsubxml)
+ XmlName=hsubsubxml(ixml).name;
+ List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}=XmlName;
+ testnew=test_select(XmlName,ListXml,{});
+ if testnew
+ ixml_tot=ixml_tot+1;
+ ListXml{ixml_tot}=XmlName;
+ end
+ end
+ end
+ end
+ end
+ end
+ else
+ for ixml=1:length(hsubxml)
+ XmlName=hsubxml(ixml).name;
+ List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}=XmlName;
+ testnew=test_select(XmlName,ListXml,{});
+ if testnew
+ ixml_tot=ixml_tot+1;
+ ListXml{ixml_tot}=XmlName;
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [testnew,testselect]=test_select(name,ListDevices,ListDevices_in)
+if ~isempty(ListDevices_in)
+ testnew=0;
+ testselect=0;
+ for ilist=1:length(ListDevices_in)
+ if isequal(name,ListDevices_in{ilist})
+ testnew=1;
+ testselect=1;
+ break
+ end
+ end
+else
+ testnew=1;
+ testselect=1;
+end
+if testnew
+ for ilist=1:length(ListDevices)
+ if isequal(name,ListDevices{ilist})
+ testnew=0;
+ break
+ end
+ end
+end
Index: /trunk/src/PARAM_LINUX.xml
===================================================================
--- /trunk/src/PARAM_LINUX.xml (revision 2)
+++ /trunk/src/PARAM_LINUX.xml (revision 2)
@@ -0,0 +1,13 @@
+
+
+ /CIVX/bin/civ
+ /CIVX/bin/civ1
+ /CIVX/bin/civ2
+ /CIVX/bin/fix_flag
+ /CIVX/bin/patch_up
+ /CIVX/bin/interpolation
+ /CIVX/bin/job_folder/
+ 1
+ /CIVX/bin/calibration/ccal_fo
+ /coriolis/bigone/PROJETS/00_DATA_MANAGEMENT/XML_SCHEMAS
+
Index: /trunk/src/PARAM_WIN.xml
===================================================================
--- /trunk/src/PARAM_WIN.xml (revision 2)
+++ /trunk/src/PARAM_WIN.xml (revision 2)
@@ -0,0 +1,13 @@
+
+
+ /home/gauthier/SVN/civx/civ/civ
+ \\Papillon\civbin\civx2004\civ1.exe
+ \\Papillon\civbin\civx2004\civ2.exe
+ \\Papillon\civbin\civx2004\fix_flag.exe
+ \\Papillon\civbin\civx2004\patch.exe
+
+ \\Papillon\civbin\job_folder1
+ 1
+ /CIVX/bin/calibration/ccal_fo
+ \\Papillon\civbin\XML_SCHEMAS
+
Index: /trunk/src/RUN_FIX.m
===================================================================
--- /trunk/src/RUN_FIX.m (revision 2)
+++ /trunk/src/RUN_FIX.m (revision 2)
@@ -0,0 +1,145 @@
+%'RUN_FIX': function for fixing velocity fields:
+%-----------------------------------------------
+% RUN_FIX(filename,field,flagindex,thresh_vecC,thresh_vel,iter,flag_mask,maskname,fileref,fieldref)
+%
+%filename: name of the netcdf file (used as input and output)
+%field: structure specifying the field to fix (field.vel_type='civ1' or 'civ2')
+%flagindex: flag specifying which values of vec_f are removed:
+ % if flagindex(1)=1: vec_f=-2 vectors are removed
+ % if flagindex(2)=1: vec_f=3 vectors are removed
+ % if flagindex(3)=1: vec_f=2 vectors are removed (if iter=1) or vec_f=4 vectors are removed (if iter=2)
+%iter=1 for civ1 fields and iter=2 for civ2 fields
+%thresh_vecC: threshold in the image correlation vec_C
+%flag_mask: =1 mask used to remove vectors (0 else)
+%maskname: name of the mask image file for fix
+%thresh_vel: threshold on velocity, or on the difference with the reference file fileref if exists
+%inf_sup=1: remove values smaller than threshold thresh_vel, =2, larger than threshold
+%fileref: .nc file name for a reference velocity (='': refrence 0 used)
+%fieldref: 'civ1','filter1'...feld used in fileref
+
+function error=RUN_FIX(filename,field,flagindex,iter,thresh_vecC,flag_mask,maskname,thresh_vel,inf_sup,fileref,fieldref)
+error=[]; %default
+vel_type{1}=field.vel_type;
+Field=read_civxdata(filename,[],field.vel_type);
+if isfield(Field,'Txt')
+ error=Field.Txt; %error in reading
+ return
+end
+
+if ~isfield(Field,'X') || ~isfield(Field,'Y') || ~isfield(Field,'U') || ~isfield(Field,'V')
+ error=['input file ' filename ' does not contain vectors in RUN_FIX.m']; %bad input file
+ return
+end
+if ~isfield(Field,'C')
+ Field.C=ones(size(Field.X));%correlation=1 by default
+end
+if ~isfield(Field,'F')
+ Field.F=ones(size(Field.X));%warning flag=1 by default
+end
+if ~isfield(Field,'FF')
+ Field.FF=zeros(size(Field.X));%fixflag=0 by default
+end
+
+vec_f_unit=abs(Field.F)-10*double(uint16(abs(Field.F)/10)); %unityterm of vec_F in abs value
+vec_f_sign=sign(Field.F).*vec_f_unit;% gives the unity digit of vec_f with correct sign
+flag1=(flagindex(1)==1)&(vec_f_sign==-2);%removed vectors vec_f=-2
+flag2=(flagindex(2)==1)&(vec_f_sign==3);%removed vectors vec_f=3
+if iter==1
+ flag3=(flagindex(3)==1)&(vec_f_sign==2); % Hart vectors
+elseif iter==2
+ flag3=(flagindex(3)==1)&(vec_f_sign==4); %
+end
+flag4=(Field.C < thresh_vecC)&(flag1~=1)&(flag2~=1)&(flag3~=1); % =1 for low vec_C vectors not previously removed
+
+% criterium on velocity values
+delta_u=Field.U;%default without ref file
+delta_v=Field.V;
+if exist('fileref','var') && ~isempty(fileref)
+ if ~exist(fileref,'file')
+ error='reference file not found in RUN_FIX.m';
+ display(error);
+ return
+ end
+ FieldRef=read_civxdata(fileref,[],fieldref);
+ if isfield(FieldRef,'FF')
+ index_true=find(FieldRef.FF==0);
+ FieldRef.X=FieldRef.X(index_true);
+ FieldRef.Y=FieldRef.Y(index_true);
+ FieldRef.U=FieldRef.U(index_true);
+ FieldRef.V=FieldRef.V(index_true);
+ end
+ if ~isfield(FieldRef,'X') || ~isfield(FieldRef,'Y') || ~isfield(FieldRef,'U') || ~isfield(FieldRef,'V')
+ error='reference file is not a velocity field in RUN_FIX.m '; %bad input file
+ return
+ end
+ if length(FieldRef.X)<=1
+ errordlg('reference field with one vector or less in RUN_FIX.m')
+ return
+ end
+ vec_U_ref=griddata_uvmat(FieldRef.X,FieldRef.Y,FieldRef.U,Field.X,Field.Y); %interpolate vectors in the ref field
+ vec_V_ref=griddata_uvmat(FieldRef.X,FieldRef.Y,FieldRef.V,Field.X,Field.Y); %interpolate vectors in the ref field to the positions of the main field
+ delta_u=Field.U-vec_U_ref;%take the difference with the interpolated ref field
+ delta_v=Field.V-vec_V_ref;
+end
+
+thresh_vel_x=thresh_vel;
+thresh_vel_y=thresh_vel;
+if isequal(inf_sup,1)
+ flag5=abs(delta_u)thresh_vel_x | abs(delta_v)>thresh_vel_y) &(flag1~=1)&(flag2~=1)&(flag3~=1)&(flag4~=1);
+end
+
+ % flag7 introduce a grey mask, matrix M
+if isequal (flag_mask,1)
+ M=imread(maskname);
+ nxy=size(M);
+ M=reshape(M,1,nxy(1)*nxy(2));
+ rangx0=[0.5 nxy(2)-0.5];
+ rangy0=[0.5 nxy(1)-0.5];
+ vec_x1=Field.X-Field.U/2;%beginning points
+ vec_x2=Field.X+Field.U/2;%end points of vectors
+ vec_y1=Field.Y-Field.V/2;%beginning points
+ vec_y2=Field.Y+Field.V/2;%end points of vectors
+ indx=1+round((nxy(2)-1)*(vec_x1-rangx0(1))/(rangx0(2)-rangx0(1)));% image index x at abcissa vec_x
+ indy=1+round((nxy(1)-1)*(vec_y1-rangy0(1))/(rangy0(2)-rangy0(1)));% image index y at ordinate vec_y
+ test_in=~(indx < 1 |indy < 1 | indx > nxy(2) |indy > nxy(1)); %=0 out of the mask image, 1 inside
+ indx=indx.*test_in+(1-test_in); %replace indx by 1 out of the mask range
+ indy=indy.*test_in+(1-test_in); %replace indy by 1 out of the mask range
+ ICOMB=((indx-1)*nxy(1)+(nxy(1)+1-indy));%determine the indices in the image reshaped in a Matlab vector
+ Mvalues=M(ICOMB);
+ flag7b=((20 < Mvalues) & (Mvalues < 200))| ~test_in';
+ indx=1+round((nxy(2)-1)*(vec_x2-rangx0(1))/(rangx0(2)-rangx0(1)));% image index x at abcissa Field.X
+ indy=1+round((nxy(1)-1)*(vec_y2-rangy0(1))/(rangy0(2)-rangy0(1)));% image index y at ordinate vec_y
+ test_in=~(indx < 1 |indy < 1 | indx > nxy(2) |indy > nxy(1)); %=0 out of the mask image, 1 inside
+ indx=indx.*test_in+(1-test_in); %replace indx by 1 out of the mask range
+ indy=indy.*test_in+(1-test_in); %replace indy by 1 out of the mask range
+ ICOMB=((indx-1)*nxy(1)+(nxy(1)+1-indy));%determine the indices in the image reshaped in a Matlab vector
+ Mvalues=M(ICOMB);
+ flag7e=((Mvalues > 20) & (Mvalues < 200))| ~test_in';
+ flag7=(flag7b|flag7e)';
+else
+ flag7=0;
+end
+flagmagenta=flag1|flag2|flag3|flag4|flag5|flag7;
+
+%write fix flags
+[errorread,message]=fileattrib(filename);
+
+if ~isempty(message) && ~isequal(message.UserWrite,1)
+ msgbox_uvmat('ERROR',['no writting access to ' filename ' (RUN_FIX.m)']);
+ return
+end
+nc=netcdf(filename,'write'); %open netcdf file for writing
+result=redef(nc);
+if isempty(result), errordlg('##Bad redef operation.'),end
+if iter==1
+ nc.fix=1;
+elseif iter==2
+ nc.fix2=1;
+end
+%theDim=nc(field.nb) ;% get the number of velocity vectors
+nc{field.fixflag}=ncfloat(field.nb);
+fixflag_unit=Field.FF-10*floor(Field.FF/10); %unity term of fix_flag
+nc{field.fixflag}(:)=fixflag_unit+10*flagmagenta;
+close(nc);
Index: /trunk/src/RUN_STLIN.m
===================================================================
--- /trunk/src/RUN_STLIN.m (revision 2)
+++ /trunk/src/RUN_STLIN.m (revision 2)
@@ -0,0 +1,202 @@
+%'RUN_STLIN': combine velocity fields for stereo PIV
+% file_A,file_B: input velocity files
+%vel_type: string ='civ1' or 'civ2'
+function RUN_STLIN(file_A,file_B,vel_type,file_st,nx_patch,ny_patch,thresh_patch,fileAxml,fileBxml)
+
+ [XmlDataA,error]=imadoc2struct(fileAxml);
+ [XmlDataB,error]=imadoc2struct(fileBxml);
+ npxA=[]; npyA=[]; pxB=[]; npyB=[];
+ if isfield(XmlDataA,'Camera') && isfield(XmlDataB,'Camera')
+ if isfield(XmlDataA.Camera,'ImageSize')&& isfield(XmlDataB.Camera,'ImageSize')
+ ImageSizeA=XmlDataA.Camera.ImageSize;
+ ImageSizeB=XmlDataB.Camera.ImageSize;
+ if ~isempty(ImageSizeA)&& ~isempty(ImageSizeB)
+ xindex=findstr(ImageSizeA,'x');
+ if length(xindex)>=2
+ npxA=str2num(ImageSizeA(1:xindex(1)-1));
+ npyA=str2num(ImageSizeA(xindex(1)+1:xindex(2)-1));
+ end
+ xindex=findstr(ImageSizeB,'x');
+ if length(xindex)>=2
+ npxB=str2num(ImageSizeB(1:xindex(1)-1));
+ npyB=str2num(ImageSizeB(xindex(1)+1:xindex(2)-1));
+ end
+ end
+ end
+ end
+ if isempty(npxA) ||isempty(npxB)
+ warndlg_uvmat('The size of image A needs to be defined in the xml file ImaDoc','ERROR')
+ return
+ elseif isempty(npxB) || isempty(npyB)
+ warndlg_uvmat('The size of image B needs to be defined in the xml file ImaDoc','ERROR')
+ return
+ end
+ if isfield(XmlDataA,'GeometryCalib')
+ tsaiA=XmlDataA.GeometryCalib;
+ else
+ warndlg_uvmat('no geometric calibration available for image A','ERROR')
+ return
+ end
+ if isfield(XmlDataB,'GeometryCalib')
+ tsaiB=XmlDataB.GeometryCalib;
+ else
+ warndlg_uvmat('no geometric calibration available for image B','ERROR')
+ return
+ end
+
+ %corners of each image in real coordinates:
+ cornerA(:,1)=[0 0 npxA npxA]';%x positions
+ cornerA(:,2)=[0 npyA 0 npyA]';%y positions
+ cornerB(:,1)=[0 0 npxB npxB]';%x positions
+ cornerB(:,2)=[0 npyB 0 npyB]';%y positions
+[xyA(:,1),xyA(:,2)]=phys_XYZ(tsaiA,cornerA(:,1),cornerA(:,2));
+[xyB(:,1),xyB(:,2)]=phys_XYZ(tsaiB,cornerB(:,1),cornerB(:,2));
+ max_x=max(max(xyA(:,1)),max(xyB(:,1)));%maximum on the 4 corners of the the images
+ min_x=min(min(xyA(:,1)),min(xyB(:,1)));%minimum on the 4 corners of the the images
+ max_y=max(max(xyA(:,2)),max(xyB(:,2)));
+ min_y=min(min(xyA(:,2)),min(xyB(:,2)));
+ array_realx=[min_x:(max_x-min_x)/(nx_patch-1):max_x];
+ array_realy=[min_y:(max_y-min_y)/(ny_patch-1):max_y];
+ [grid_realx,grid_realy]=meshgrid(array_realx,array_realy);
+ grid_real(:,1)=reshape(grid_realx,nx_patch*ny_patch,1);
+ grid_real(:,2)=reshape(grid_realy,nx_patch*ny_patch,1);
+ grid_real(:,3)=zeros(nx_patch*ny_patch,1);
+[grid_imaA(:,1),grid_imaA(:,2)]=px_XYZ(tsaiA,grid_real(:,1),grid_real(:,2));
+[grid_imaB(:,1),grid_imaB(:,2)]=px_XYZ(tsaiB,grid_real(:,1),grid_real(:,2));
+
+ flagA=grid_imaA(:,1)>0 & grid_imaA(:,1)0 & grid_imaA(:,2)0 & grid_imaB(:,1)0 & grid_imaB(:,2)length(textlu)
+ blankstr=char(32*ones(1,widthcolumn(jtab)-length(textlu)));
+ textlu=[textlu blankstr];
+ end
+ if ~isempty(charchain)
+ textlu=[separator textlu];
+ end
+ charchain=[charchain textlu];
+ end
+ %Tabchar(itab)={charchain};
+ Tabchar(itab,1)={charchain};
+end
Index: /trunk/src/check_field_structure.m
===================================================================
--- /trunk/src/check_field_structure.m (revision 2)
+++ /trunk/src/check_field_structure.m (revision 2)
@@ -0,0 +1,151 @@
+%'check_field_structure': check the validity of the field struture representation consitant with the netcdf format
+%----------------------------------------------------------------------
+% function [DataOut,errormsg]=check_field_structure(Data)
+%
+% OUTPUT:
+% Data: structure reproducing the input structure Data, with the additional elements:
+% with fields:
+%
+% .ListDimName: cell listing the names of the array dimensions
+% .DimValue: array dimension values (Matlab vector with the same length as .ListDimName
+% .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName
+% .VarDimName: cell containing a cell of dimension names (in list .ListDimName) for each variable of .ListVarName
+% errormsg: error message which is not empty when the input structure does not have the right form
+%
+%INPUT:
+% Data: structure containing
+% (optional) .ListGlobalAttribute: cell listing the names of the global attributes
+% .Att_1,Att_2... : values of the global attributes
+% (requested) .ListVarName: list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} )
+% (requested) .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)
+% (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
+
+
+function [DataOut,errormsg]=check_field_structure(Data)
+DataOut=[]; %default
+errormsg=[];
+if ~isstruct(Data)
+ errormsg='input field is not a structure';
+ return
+end
+if isfield(Data,'ListVarName') && iscell(Data.ListVarName)
+ nbfield=numel(Data.ListVarName);
+else
+ errormsg='input field does not contain the list of variables .ListVarNames';
+ return
+end
+%check dimension names
+% definition by VarDimIndex (obsolete)
+% if ~isfield(Data,'VarDimName') && isfield(Data,'VarDimIndex') && isfield(Data,'ListDimName')%old convention
+% for ivar=1:nbfield
+% DimCell=Data.VarDimIndex{ivar};
+% if isnumeric(DimCell)
+% if DimCell <= numel(Data.ListDimName)
+% Data.VarDimName{ivar}=Data.ListDimName(DimCell);
+% else
+% errormsg='dimension names not defined';
+% return
+% end
+% else
+% errormsg='unrecognized format for .VarDimIndex';
+% end
+% end
+% end
+if ~(isfield(Data,'VarDimName') && iscell(Data.VarDimName))
+ errormsg='input field does not contain the list of dimensions .VarDimName';
+ return
+end
+if isfield(Data,'DimValue')
+ Data=rmfield(Data,'DimValue');
+end
+if isfield(Data,'VarDimName') && iscell(Data.VarDimName)
+ nbdim=0;
+ if numel(Data.VarDimName)==nbfield
+ for ivar=1:nbfield
+ VarName=Data.ListVarName{ivar};
+ if ~isfield(Data,VarName)
+ errormsg=['the listed variable ' VarName ' is not found'];
+ return
+ else
+ eval(['sizvar=size(Data.' VarName ');'])% sizvar = dimension of variable
+ DimCell=Data.VarDimName{ivar};
+ if ischar(DimCell)
+ DimCell={DimCell};
+ elseif ~iscell(DimCell)
+ errormsg=['wrong format for .VarDimName{' num2str(ivar) ' (must be the cell of dimension names of the variable ' VarName];
+ return
+ end
+ nbcoord=numel(sizvar);
+ if numel(DimCell)==0
+ errormsg=['empty declared dimension .VarDimName{' num2str(ivar) '} for ' VarName];
+ return
+ elseif numel(DimCell)==1% one dimension declared
+ if nbcoord==2
+ if sizvar(1)==1
+ nbcoord=1;
+ sizvar(1)=sizvar(2);
+ elseif sizvar(2)==1
+ nbcoord=1;
+ else
+ errormsg=['1 dimension declared in .VarDimName{' num2str(ivar) '} inconsistent with the nbre of dimensions =2 of the variable ' VarName];
+ return
+ end
+ else
+ errormsg=['1 dimension declared in .VarDimName{' num2str(ivar) '} inconsistent with the nbre of dimensions =' num2str(nbcoord) ' of the variable ' VarName];
+ return
+ end
+ else
+ if numel(DimCell)>nbcoord
+ DimCell=DimCell(end-nbcoord+1:end);%first singleton diemnsions omitted,
+ elseif nbcoord > numel(DimCell)
+ errormsg=['nbre of declared dimensions in .VarDimName{' num2str(ivar) '} smaller than the nbre of dimensions =' num2str(nbcoord) ' of the variable ' VarName];
+ return
+ end
+ end
+ DimIndex=[];
+ for idim=1:nbcoord %loop on the coordinates of variable #ivar
+ DimName=DimCell{idim};
+ testprev=0;
+ for iprev=1:nbdim %check previously listed dimension names
+ if strcmp(Data.ListDimName{iprev},DimName)
+ if ~isequal(Data.DimValue(iprev),sizvar(idim))
+ if isequal(Data.DimValue(iprev),0) % the dimension has been already detected as a range [min max]
+ Data.DimValue(idim)=sizvar(idim); %update with actual value
+ elseif sizvar(idim)==2 && strcmp(DimName,VarName)
+ %case of a regularly spaced coordinate defined by the first and last values: dimension will be determined later
+ else
+ errormsg=['dimension declaration inconsistent with the size =[' num2str(sizvar) '] for ' VarName];
+ return
+ end
+ end
+ DimIndex=[DimIndex iprev];
+ testprev=1;
+ break
+ end
+ end
+ if ~testprev % a new dimension is appended to the list
+ nbdim=nbdim+1;
+ if sizvar(idim)==2 && strcmp(DimName,VarName)
+ Data.DimValue(nbdim)=0; %to be updated for a later variable
+% Data.VarType{ivar}='range';
+ else
+ Data.DimValue(nbdim)=sizvar(idim);
+ end
+ Data.ListDimName{nbdim}=DimName;
+ DimIndex=[DimIndex nbdim];
+ end
+ end
+ Data.VarDimIndex{ivar}=DimIndex;
+ end
+ end
+ else
+ errormsg=' .ListVarNames and .VarDimName have different lengths';
+ return
+ end
+else
+ errormsg='input field does not contain the cell of dimension names .VarDimName for variables';
+ return
+end
+DataOut=Data;
+
+
Index: /trunk/src/check_functions.m
===================================================================
--- /trunk/src/check_functions.m (revision 2)
+++ /trunk/src/check_functions.m (revision 2)
@@ -0,0 +1,117 @@
+%'check_functions': check the path and modification date for all the
+% function in the toolbox UVMAT. Called at the opening of uvmat.fig
+%----------------------------------------------------------------------
+% function [errormsg,date_str]=check_functions
+%
+% OUTPUT:
+% errormsg: error message listing functions whose paths are not in the directory of uvmat.m
+% date_str: date of the most recent modification of a file in the toolbox
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function [errormsg,date_str]=check_functions
+errormsg={};%default
+list_fct={'calc_field';...% defines fields (velocity, vort, div...) from civx data and calculate them
+ 'cell2tab';... %transform a Matlab cell in a character array suitable for display in a table
+ 'check_functions';...
+ 'civ';... %function associated with the interface 'civ.fig' for PIV and spline interpolation
+ 'civ.fig';...
+ 'civ_3D';... function associated with the interface 'civ_3D.fig' for PIV in volume (in progress)
+ 'civ_3D.fig';...
+ 'close_fig';...% function activated when a figure is closed
+ 'copyfields';...%copy fields between two matlab structures
+ 'delete_object';...%delete a projection object, defined by its index in the Uvmat list or by its graphic handle
+ 'editxml';...%display and edit xml files using a xls schema
+ 'editxml.fig';...%interface for editxml
+ 'find_field_indices';...% group the variables of a nc-formated Matlab structure into 'fields' with common dimensions
+ 'geometry_calib';...%performs geometric calibration from a set of reference points
+ 'geometry_calib.fig';...%interface for geometry_calib
+ 'get_field';...% choose and plot a field from a Netcdf file
+ 'get_field.fig';...%interface for get_field
+ 'get_plot_handles';... %provides handles of elements setting the plotting parameters in the uvmat interface
+ 'griddata_uvmat';...%make 2D linear interpolation using griddata, with input appropriate for both Matlab 6.5 and 7
+ 'hist_update';...% update of a current global histogram by inclusion of a new field
+ 'imadoc2struct';...%convert the image documentation file ImaDoc into a Matlab structure
+ 'keyboard_callback';... % function activated when a key is pressed on the keyboard
+ 'ListDir';... scan the structure of the directory tree (for dataview.m)
+ 'mouse_down';% function activated when the mouse button is pressed on a figure (callback for 'WindowButtonDownFcn')
+ 'mouse_motion';...% permanently called by mouse motion over a figure (callback for 'WindowButtonMotionFcn')
+ 'mouse_up';... % function to be activated when the mouse button is released (callback for 'WindowButtonUpFcn')
+ 'msgbox_uvmat';... associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
+ 'msgbox_uvmat.fig';...
+ 'name2display';...% extracts the root name and field numbers from an input filename
+ 'name_generator';...%creates a file name from a root name and indices.
+ 'nc2struct';...% transform a netcdf file in a corresponding matlab structure
+ 'peaklock';...%
+ 'phys';...% transforms fields from image (px) to real world (phys) coordinates using geometric calibration parameters
+ 'phys_polar';... transform image coordinates (px) to physical ploar coordinates
+ 'phys_XYZ';...%transforms image (px) to real world (phys) coordinates using geometric calibration parameters
+ 'px';...% transform fields from physical to px coordinates using geometrical calibration parameters
+ 'px_XYZ';...% ransform physical to px coordinates using geometrical calibration parameters
+ 'plot_field';...%displays a vector field and/or scalar or images
+ 'plot_object';...%draws a projection object (points, line, plane...)
+ 'proj_field';...%project a field on a projection object (plane, line,...)
+ 'read_civxdata';...reads civx data from netcdf files
+ 'read_imatext';...%read .civ files (obsolete, but can be adapted to other text documentation files)
+ 'read_plot_param';... %read the plotting option parameters on the uvmat interface
+ 'read_set_object';...%read the data on the set_object interface
+ 'read_xls';...%read excel files containing the list of the experiments
+ 'reinit';...% suppress the personal parameter file 'uvmat_perso.mat'
+ 'RUN_FIX';...% fix velocity fields
+ 'RUN_STLIN';...% combine 2 displacement fields for stereo PIV
+ 'series';...% master function for analysis field series, with interface 'series.fig'
+ 'series.fig';...% interface for 'series'
+ 'set_col_vec';...
+ 'set_grid';...% creates a grid for PIV
+ 'set_grid.fig';...% interface for set_grid
+ 'set_object.m';...% edit a projection object
+ 'set_object.fig';...% interface for set_object
+ 'sub_field';...% combine the two input fields,
+ 'struct2nc';...% %write fields in netcdf files
+ 'uvmat';...% master function for file scanning and visualisation of 2D fields
+ 'uvmat.fig';... %interface for uvmat
+ 'update_obj';... update the object representation graph and its projection field, record it in the uvmat interface
+ 'update_waitbar';... update the waitbar display, used for ACTION functions in the GUI 'series'
+ 'warndlg_uvmat';...% display messages (error, warning, confirmation) , OBSOLETE, use msgbox_uvmat
+ 'write_plot_param'};%update plotting parameters after plot
+ dir_fct=which('uvmat');% path to uvmat
+[pathuvmat,name,ext]=fileparts(dir_fct);
+icount=0;
+% loop on the list of functions in the uvmat package
+ for i=1:length(list_fct)
+ dir_fct=which(list_fct{i});% path to fct
+ if isempty(dir_fct)
+ icount=icount+1;
+ errormsg{icount}=[list_fct{i} ' not found'];% test for function not found
+ else
+ [pth,name,ext]=fileparts(dir_fct);
+ if ~isequal(pathuvmat,pth)
+ icount=icount+1;
+ errormsg{icount}=[dir_fct ' overrides the package UVMAT'];% bad path for the function
+ end
+ datfile=dir(dir_fct);
+ date_str=datfile.date;%string of the date of last modification
+ datnum(i)=0;%default
+ char_code=double(date_str);% code of the date characters
+ special_char=(char_code>127); %non standard Ascii character (e.g. date in french)
+ if isempty(find(special_char))% standard Ascii character
+ datnum(i)=datenum(date_str);
+ end
+ end
+end
+errormsg=errormsg';
+date_str=datestr(max(datnum));
Index: /trunk/src/civ.m
===================================================================
--- /trunk/src/civ.m (revision 2)
+++ /trunk/src/civ.m (revision 2)
@@ -0,0 +1,5248 @@
+%'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)
+%------------------------------------------------------------------------
+% provides an interface for the software CIVx
+% function varargout = civ(varargin)
+% provides an interface for the software CIVx
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+function varargout = civ(varargin)
+
+% Last Modified by GUIDE v2.5 29-Oct-2009 19:05:39
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @civ_OpeningFcn, ...
+ 'gui_OutputFcn', @civ_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin && ischar(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+%--------------------------------------------------------------------------
+% --- Executes just before civ is made visible.
+%--------------------------------------------------------------------------
+function civ_OpeningFcn(hObject, eventdata, handles, varargin)
+% This function has no output args, see OutputFcn.
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+% varargin command line arguments to civ (see VARARGIN)
+global test_batch patch_new_exe%=1 if patch processing available
+%filebase: root name
+%nom_type: nomencalture used ('png_old','_i_j'...)
+%list of field numbers to process
+%subdir: subdirectory of the opened netcdf file
+%ind_opening: operation number advised for beginning (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2),
+%ind_a_opening ind_b_opening chosen pair from the opened netcdf file
+% Choose default command line output for civ
+handles.output = hObject;
+% Update handles structure
+guidata(hObject, handles);
+
+%default initial parameters
+filebase=''; % root file name ('filebase'.civ)
+nom_type=[]; % nomenclature type
+ext=[];
+testall=0;
+browse=[];
+
+%load the initial parameters if the interface is started from uvmat
+if ~isempty(varargin)% the interface is opened from uvmat
+ varcell=varargin{1};
+ filebase=varcell{1};
+ nom_type_read=varcell{2};
+ num1=varcell{3};
+ num2=varcell{4};
+ num_a=varcell{5};
+ num_b=varcell{6};
+ subdir=varcell{7};
+ ind_opening=varcell{8};
+ ext=varcell{11};
+else
+ num1=1; % set of field i numbers
+ num2=2; % set of field i numbers
+ num_a=1; % set of field j numbers (fields a)
+ num_b=1; % second set of field j numbers (fields b)
+ subdir='A'; % subdir for the netcdf result files
+ ind_opening=1; % proposed operation number (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2)
+end
+
+if exist('ext','var') && length(ext)>1 && (~isempty(imformats(ext([2:end])))|...
+ isequal(ext,'.avi')||isequal(ext,'.AVI'));%if an image file has been opened by uvmat
+ set(handles.ext_ima,'String',ext)
+ if exist('nom_type_read','var')
+ browse.nom_type_ima=nom_type_read; % the image nomenclature is stored
+ end
+elseif isequal(ext,'.nc')
+ if exist('nom_type_read','var')
+ browse.nom_type_nc=nom_type_read;% the netcdf nomenclature is stored
+ end
+end
+set(handles.displ_filebase,'String',filebase);
+set(handles.ImaDoc,'UserData',testall);
+set(handles.ImaDoc,'String',ext)
+
+
+% set(handles.ImaDoc,'String',ext)
+
+%read names of the .exe file to adjust the interface according to
+%available prog
+%read names of the .exe file
+path_uvmat=which('uvmat');% check the path detected for source file uvmat
+path_UVMAT=fileparts(path_uvmat); %path to UVMAT
+if isunix
+ syst='LINUX';
+ %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ binary names
+ xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml');
+ display(xmlfile)
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+else
+ syst='WIN';
+ %fid = fopen(fullfile(path_UVMAT,'PARAM_WIN.txt'),'r');%open the file with civ binary names
+ xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+end
+display(syst)
+patch_new_exe='';
+% todo_patch='';
+sge=0;
+
+if isfield(sparam,'PatchNew_exe')
+ patch_new_exe=sparam.PatchNew_exe;
+end
+if isfield(sparam,'Todo_path')
+ todo_path=sparam.Todo_path;
+end
+if isfield(sparam,'SGE')
+ sge=str2num(sparam.SGE);
+end
+name_todo=fullfile(todo_path,'TODO.txt');
+display(name_todo)
+test_batch=1;
+if ~sge
+if isequal(todo_path,'') || isequal(todo_path,[])
+ display(['no batch distributed processing available:file path TODO.txt not defined in UVMAT/PARAM_' syst])
+ test_batch=0;
+end
+if exist(name_todo,'file')~=2
+ msgbox_uvmat('WARNING',['no batch distributed processing available, queue file ' name_todo ' absent']);
+ % test_batch=0; % Problems to detect file on linux/nfs filesystems
+end
+end
+
+
+if test_batch==0
+ set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
+end
+
+set(handles.subdir_civ1,'String',subdir)%default subdir on which uvmat was working
+set(handles.subdir_civ2,'String',subdir)%default subdir on which uvmat was working
+
+%initiate advised operations
+if isequal(ind_opening,[])
+ ind_opening=1; % default
+end
+% set default operation options
+ enable_civ1(handles,'off')
+ enable_civ2(handles,'off')
+ enable_pair1(handles,'on')
+ enable_fix1(handles,'off')
+ desable_patch1(handles)
+ desable_fix2(handles)
+ desable_patch2(handles)
+ set(handles.CIV1,'Value',0)
+ set(handles.FIX1,'Value',0)
+ set(handles.PATCH1,'Value',0)
+ set(handles.CIV2,'Value',0)
+ set(handles.FIX2,'Value',0)
+ set(handles.PATCH2,'Value',0)
+ set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
+if isequal(ind_opening,1)
+ set(handles.CIV1,'Value',1)
+ enable_civ1(handles,'on')
+elseif isequal(ind_opening,2)
+ set(handles.FIX1,'Value',1)
+ enable_fix1(handles,'on')
+elseif isequal(ind_opening,3)
+ set(handles.PATCH1,'Value',1)
+ enable_patch1(handles)
+elseif isequal(ind_opening,4)
+ set(handles.CIV2,'Value',1)
+ enable_civ2(handles,1)
+elseif isequal(ind_opening,5)
+ set(handles.FIX2,'Value',1)
+ enable_fix2(handles)
+ set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
+ set(handles.list_pair_civ2,'Enable','On')
+ set(handles.list_pair_civ2,'Enable','On')
+ enable_pair1(handles,'off')
+elseif isequal(ind_opening,6)
+ set(handles.PATCH2,'Value',1)
+ enable_patch2(handles)
+ set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
+ set(handles.list_pair_civ2,'Enable','On')
+ enable_pair1(handles,'off')
+end
+
+% set the range of fields (1:1 by default) and selected pair
+if isempty(num2)|isequal(num2,num1)
+ num_ref_i=num1;
+else
+ num_ref_i=floor((num1+num2)/2);
+ browse.incr_pair(1)=num2-num1;
+ browse.incr_pair(2)=0;
+end
+if isempty(num_b)|isequal(num_a,num_b)
+ if isempty(num_a)
+ num_ref_j=1;
+ else
+ num_ref_j=num_a;
+ end
+else
+ num_ref_j=floor((num_a+num_b)/2);
+ browse.incr_pair(2)=num_b-num_a;
+end
+set(handles.first_i,'String',num2str(num_ref_i));
+set(handles.last_i,'String',num2str(num_ref_i));
+set(handles.first_j,'String',num2str(num_ref_j));
+set(handles.last_j,'String',num2str(num_ref_j));
+set(handles.ref_i,'String',num2str(num_ref_i));
+set(handles.ref_j,'String',num2str(num_ref_j));
+set(handles.browse_root,'UserData',browse);
+if ~isempty(varargin)% the interface is opened from uvmat
+ displ_filebase_Callback(hObject, eventdata, handles);
+end
+
+set(handles.waitbar_1,'Position',[0.946 0.877 0.03 0.001])
+set(handles.waitbar_patch1,'Position',[0.946 0.626 0.03 0.001])
+set(handles.waitbar_civ2,'Position',[0.946 0.406 0.03 0.001])
+set(handles.waitbar_patch2,'Position',[0.946 0.187 0.03 0.001])
+
+
+%--------------------------------------------------------------
+% --- Outputs from this function are returned to the command line.
+%-----------------------------------------------------------------
+function varargout = civ_OutputFcn(hObject, eventdata, handles)
+% varargout cell array for returning output args (see VARARGOUT);
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+
+%------------------------------------------------------------------
+% --- Executes on button press in browse_root.
+function browse_root_Callback(hObject, eventdata, handles)
+%get the input file properties
+filebase=get(handles.displ_filebase,'String');
+oldfile=''; %default
+if isempty(filebase)|isequal(filebase,'')%loads the previously stored file name and set it as default in the file_input box
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ display(profil_perso)
+ if exist(profil_perso,'file')
+ h=load (profil_perso);
+ if isfield(h,'filebase')&& ischar(h.filebase)
+ oldfile=h.filebase;
+ end
+ if isfield(h,'RootPath') && ischar(h.RootPath)
+ oldfile=h.RootPath;
+ end
+ end
+ else
+ oldfile=filebase;
+ end
+testall=get(handles.ImaDoc,'UserData');
+ind_opening=1;%default
+browse.incr_pair=[0 0]; %default
+if testall
+ menu={'*.*', 'All Files (*.*)'; '*.xml; *.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
+ '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc','.nc files'};
+else % menu selecting only .civ or .avi files
+menu={'*.xml;*.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
+ '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc', '.nc files';...
+ '*.*', 'All Files (*.*)'};
+end
+[FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
+fileinput=[PathName FileName];%complete file name
+sizf=size(fileinput);
+if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
+[path,name,ext]=fileparts(fileinput);
+testeditxml=0;
+if isequal(ext,'.xml')
+ testeditxml=1;
+ t_browse=xmltree(fileinput);
+ head_element=get(t_browse,1);
+ if isfield(head_element,'name')& isequal(head_element.name,'ImaDoc')
+ testeditxml=0;
+ end
+end
+if testeditxml==1 | isequal(ext,'.xls')
+ heditxml=editxml({fileinput});
+ set(heditxml,'Tag','browser')
+ waitfor(heditxml,'Tag','idle')
+ if ~ishandle(heditxml)
+ return
+ end
+ attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
+ set(handles.browse,'UserData',fileinput)% store for future opening with browser
+ fileinput=get(attr,'UserData');
+ if ~exist(fileinput,'file')
+ return
+ end
+end
+
+[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
+filebase=fullfile(RootPath,RootFile);
+if isequal(get(handles.compare,'Value'),1)
+ browse=[];%initialisation
+else
+ browse=get(handles.browse_root,'UserData');
+end
+if length(ext)>1 & (~isempty(imformats(ext([2:end])))|...
+ isequal(ext,'.avi')|isequal(ext,'.AVI'));%if an image file has been opened by uvmat
+ set(handles.ext_ima,'String',ext)
+ browse.nom_type_ima=nom_type;
+ browse.field_count=str2num(field_count);
+ A=imread(fileinput);
+ npxy=size(A);
+ set(handles.ext_ima,'UserData',npxy)
+end
+set(handles.ImaDoc,'String',ext);
+
+%%%%% read the state of the selected netcdf file to advise default operation
+if isequal(ext,'.nc')
+ browse.nom_type_nc=nom_type;
+ ind_opening=2;% propose 'fix' as the default option
+ Data=nc2struct(fileinput,[]);
+ if isfield(Data,'absolut_time_T0')%test for civx files
+ if isfield(Data,'fix') && isequal(Data.fix,1)
+ ind_opening=3;
+ end
+ if isfield(Data,'patch') && isequal(Data.patch,1)
+ ind_opening=4;
+ end
+ if isfield(Data,'civ2') && isequal(Data.civ2,1)
+ ind_opening=5;
+ end
+ if isfield(Data,'fix2') && isequal(Data.fix2,1)
+ ind_opening=6;
+ end
+ testciv=1; %TO SUPPRESS WITH NEW VERSION OF CIVX
+ else
+ ind_opening=3; %GUI used only for patch
+ testciv=0;
+ end
+ set(handles.subdir_civ1,'String',subdir);%set the default subdir directories for installing the .nc results
+ set(handles.subdir_civ2,'String',subdir);
+ browse.testciv=testciv;
+ browse.ind_opening=ind_opening;
+end
+set(handles.displ_filebase,'String',filebase);
+set(handles.ImaDoc,'String',ext);
+if ~isempty(str2num(field_count))
+ ref_i=str2num(field_count);
+ if ~isempty(str2num(str2))
+ ref_i=floor((ref_i+str2num(str2))/2);% reference image number corresponding to the file
+ browse.incr_pair(1)=str2num(str2)-str2num(field_count);
+ browse.incr_pair(2)=0;
+ end
+ set(handles.first_i,'String',num2str(ref_i));
+ set(handles.last_i,'String',num2str(ref_i));
+ set(handles.ref_i,'String',num2str(ref_i));
+end
+if isempty(str2num(str_a))
+ set(handles.ref_j,'String','1');
+else
+ ref_j=str2num(str_a);
+ if ~isempty(str2num(str_b))
+ ref_j=floor((str2num(str_a)+str2num(str_b))/2);
+ browse.incr_pair(2)=str2num(str_b)-str2num(str_a);
+ end
+ set(handles.first_j,'String',num2str(ref_j));
+ set(handles.last_j,'String',num2str(ref_j));
+ set(handles.ref_j,'String',num2str(ref_j));
+end
+
+% set default operation options
+enable_civ1(handles,'off')
+enable_civ2(handles,'off')
+enable_pair1(handles,'on')
+enable_fix1(handles,'off')
+desable_patch1(handles)
+desable_fix2(handles)
+desable_patch2(handles)
+set(handles.CIV1,'Value',0)
+set(handles.FIX1,'Value',0)
+set(handles.PATCH1,'Value',0)
+set(handles.CIV2,'Value',0)
+set(handles.FIX2,'Value',0)
+set(handles.PATCH2,'Value',0)
+set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
+if isequal(ind_opening,1)
+ set(handles.CIV1,'Value',1)
+ enable_civ1(handles,'on')
+elseif isequal(ind_opening,2)
+ set(handles.FIX1,'Value',1)
+ enable_fix1(handles,'on')
+elseif isequal(ind_opening,3)
+ set(handles.PATCH1,'Value',1)
+ enable_patch1(handles)
+elseif isequal(ind_opening,4)
+ set(handles.CIV2,'Value',1)
+ enable_civ2(handles,1)
+elseif isequal(ind_opening,5)
+ enable_pair1(handles,'off')
+ set(handles.FIX2,'Value',1)
+ enable_fix2(handles)
+ set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
+ set(handles.list_pair_civ2,'Enable','On')
+ set(handles.list_pair_civ2,'Enable','On')
+elseif isequal(ind_opening,6)
+ enable_pair1(handles,'off')
+ set(handles.PATCH2,'Value',1)
+ enable_patch2(handles)
+ set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
+ set(handles.list_pair_civ2,'Enable','On')
+end
+set(handles.browse_root,'UserData',browse);% store information from browser
+testall=isequal(menu(filtindex,1),{'*.*'});
+set(handles.ImaDoc,'UserData',testall);
+
+displ_filebase_Callback(hObject, eventdata, handles);
+
+%------------------------------------------------
+
+function ImaDoc_Callback(hObject, eventdata, handles)
+displ_filebase_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------------------------
+%function activated when a new filebase (image series) is introduced
+%------------------------------------------------------------
+function displ_filebase_Callback(hObject, eventdata, handles)
+
+global test_batch
+%set(gcf,'Pointer','watch')
+set(handles.compare,'Visible','on')
+ext_ima=get(handles.ext_ima,'String');
+nom_type_ima=[];%default
+field_count=1;%default
+nom_type_nc=[];
+npx=[];%default
+npy=[];
+time=[];
+TimeUnit=[]; %default
+CoordUnit=[];%default
+pxcmx_search=[];%default
+pxcmy_search=[];%default
+filebase=get(handles.displ_filebase,'String');
+
+ext=get(handles.ImaDoc,'String');
+browse=get(handles.browse_root,'UserData');%default
+if ~isempty(browse)
+ if isfield(browse,'nom_type_ima')
+ nom_type_ima=browse.nom_type_ima;
+ end
+ if isfield(browse,'field_count')
+ field_count=browse.field_count;
+ end
+end
+
+%default first_i and j and increments
+first_i=str2num(get(handles.first_i,'String'));%value possibly set by uvmat_Opening
+if isempty(first_i)| first_i < 1
+ first_i=1; %default first_i
+end
+last_i=str2num(get(handles.last_i,'String'));
+if isempty(last_i)| last_i < first_i
+ last_i=first_i; %default last_i
+end
+first_j=str2num(get(handles.first_j,'String'));
+if isempty(first_j)| first_j < 1
+ first_j=1; %default first_j
+end
+last_j=str2num(get(handles.last_j,'String'));
+if isempty(last_j)| last_j < first_j
+ last_j=first_j; %default last_j
+end
+incr_i=str2num(get(handles.incr_i,'String'));
+if isempty(incr_i) | incr_i < 1;
+ set(handles.incr_i,'String','1') %default incr_i
+end
+incr_j=str2num(get(handles.incr_j,'String'));
+if isempty(incr_j) | incr_j < 1;
+ set(handles.incr_j,'String','1') %default incr_j
+end
+dt=[];%default
+testmode=0;%default
+nbfield=[]; %default
+nburst=[];%default
+pxcmx=1;
+pxcmy=1;
+
+ %look for an image documentation file
+ext
+if ~isequal(ext,'.xml') && ~isequal(ext,'.civ')&& ~isequal(ext,'.avi')&& ~isequal(ext,'.AVI')
+ if exist([filebase '.xml'],'file')
+ ext='.xml';
+ elseif exist([filebase '.civxml'],'file')
+ ext='.civxml';
+ elseif exist([filebase '.civ'],'file')
+ ext='.civ';
+ elseif exist([filebase '.avi'],'file')
+ ext='.avi';
+ elseif exist([filebase '.AVI'],'file')
+ ext='.AVI';
+ end
+ set(handles.ImaDoc,'String',ext)
+end
+
+%%%%%%%% read image documentation file %%%%%%%%%%%%%%%%%%%%%%%%%%%
+ mode=''; %default
+ set(handles.ImaDoc,'BackgroundColor',[1 1 0])
+ drawnow
+ %read the image documentation file if found
+if isequal(ext,'.civxml') | isequal(ext,'.xml')| isequal(ext,'.civ')
+ set(handles.ref_i,'Visible','On')%use a reference index
+ set(handles.ref_j,'Visible','On')
+ set(handles.dt,'Visible','Off')
+ set(handles.dt_text,'String','ref. ind.')
+elseif isequal(ext,'.avi') | isequal(ext,'.AVI')
+ set(handles.ref_j,'Visible','Off')
+ set(handles.dt,'Visible','Off')
+ set(handles.dt_text,'String','ref. ind.')
+else
+ set(handles.ref_i,'Visible','Off')
+ set(handles.ref_j,'Visible','Off')
+ set(handles.dt,'Visible','On')
+ set(handles.dt_text,'String','dt(ms)=')
+end
+if isequal(ext,'.civxml')%TO ABANDON
+ [nbfield,nburst,time]=read_civxml([filebase '.civxml']);
+ mode='pair j1-j2';
+ if isempty(nom_type_ima)% dtermine types by default if not already selected by browser or uvmat
+ nom_type_ima='_i_j';
+ end
+elseif isequal(ext,'.xml')
+ [XmlData,warntext]=imadoc2struct([filebase '.xml']);
+ if isfield(XmlData,'Time')
+ time=XmlData.Time;
+ nbfield=size(XmlData.Time,1);
+ nburst=size(XmlData.Time,2);
+ end
+ ext_ima_read=[];
+ nom_type_read=[];
+ XmlData.Heading
+ if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')
+ [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
+ end
+ if isfield(XmlData,'Camera')
+ if isfield(XmlData.Camera,'TimeUnit')
+ TimeUnit=XmlData.Camera.TimeUnit;
+ end
+ if isfield(XmlData.Camera,'ImageSize')
+ ImageSize=XmlData.Camera.ImageSize;
+ if ~isempty(ImageSize)&& ~isempty(ImageSize)
+ xindex=findstr(ImageSize,'x');
+ if length(xindex)>=2
+ npx=str2num(ImageSize(1:xindex(1)-1));
+ npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
+ end
+ end
+ end
+ end
+ pxcmx_search=1;
+ pxcmy_search=1;
+ if isfield(XmlData,'GeometryCalib')
+ tsai=XmlData.GeometryCalib;
+ if isfield(tsai,'f') & isfield(tsai,'Tz') & isfield(tsai,'dpx') & isfield(tsai,'dpy')& isfield(tsai,'R')
+ rot2D=tsai.R([1:2],[1,2]);
+ pxcmx_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpx);
+ pxcmy_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpy);
+ end
+ if isfield(tsai,'CoordUnit')
+ CoordUnit=tsai.CoordUnit;
+ end
+ end
+ if ~isempty(ext_ima_read) && ~isempty(nom_type_read)
+ if isempty(ext_ima)
+ ext_ima=ext_ima_read;% define image extension from the xml file if an image has not been opened previously
+ else %keep the image extension
+ if ~strcmp(ext_ima_read,ext_ima)
+ msgbox_uvmat('WARNING',['FirtsImage extension ' ext_ima_read ' announced in the xml file inconsistent with the selected image'])
+ end
+ end
+ nom_type_ima=nom_type_read;
+ end
+elseif isequal(ext,'.civ')% case of .civ image documentation file
+ [error,time,TimeUnit,mode,npx,npy]=read_imatext([filebase '.civ']);
+ if error==2, warndlg(['no file ' filebase '.civ']);
+ elseif error==1, warndlg('inconsistent number of fields in the .civ file');
+ end
+% ext_ima='.png';
+ nom_type_ima='png_old';
+elseif isequal(lower(ext),'.avi')
+ nom_type_ima='*';
+ ext_ima=ext;
+ set(handles.mode,'String',{'series(Di)'})
+ dt=0.04;%default
+ if exist([filebase ext],'file')==2
+ info=aviinfo([filebase ext]);%read infos on the avi movie
+ dt=1/info.FramesPerSecond;%time interval between successive frames
+ nbfield=info.NumFrames;%number of frames
+ end
+ time=(dt*[0:nbfield-1])';%list of image times
+ set(handles.dt,'String',num2str(dt*1000));%store the time interval between successive images
+end
+if isempty(time)
+ set(handles.ImaDoc,'String',''); %xml file not used for timing
+end
+set(handles.ImaDoc,'BackgroundColor',[1 1 1])
+
+% no image documentation file found: look for a series of existing images or .nc files
+if isempty(time) && ~isequal(ext,'.nc')
+ subdir=get(handles.subdir_civ1,'String');
+ incr_pair=[0 0];%default
+ if isfield(browse,'incr_pair')
+ incr_pair=browse.incr_pair;
+ end
+ nbdetect=0;%test of detected images
+ field_i=field_count;
+ idetect=1;
+ while idetect==1 %look for the maximum file number in the series
+ field_i=field_i+1;
+ imagename=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
+ if strcmp(nom_type_ima,'none')||strcmp(nom_type_ima,'')
+ idetect=0; %stop if the same image is repeated (if nom_type='none')
+ nbdetect=1;
+ else
+ idetect=(exist(imagename,'file')==2);
+ end
+ %SEE CASE OF NETCDF FILES
+ nbdetect=nbdetect+(exist(imagename,'file')==2);
+ end
+ nb_field=field_i;% last detected field number
+ field_i=field_count;%look for the minimum file number in the series
+ idetect=1;
+ while idetect==1
+ field_i=field_i-1;
+ imagename=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
+ if isequal(nom_type_ima,'none')||strcmp(nom_type_ima,'')
+ idetect=0; %stop if the same image is repeted (if nom_type='none')
+ nbdetect=1;
+ else
+ idetect=(exist(imagename,'file')==2);
+ end
+ nbdetect=nbdetect+idetect;
+ end
+ first_i=max(field_i+1,1);
+ %determine the set of times and possible intervals for CIV
+ dt=(1/1000)*str2num(get(handles.dt,'String'));
+ time=(dt*[0:nb_field-1])';
+ set(handles.mode,'String',{'series(Di)'})
+end
+if isequal(nom_type_ima,'none')% no file numbering used
+ first_i=1;
+ last_i=1;
+ first_j=1;
+ last_j=1;
+end
+if exist('time','var')
+ if size(time,1)+size(time,2)>=3 % if there are at least two time values to define dt
+ nbfield=size(time,1);
+ nbfield2=size(time,2);
+ set(handles.displ_filebase,'UserData',time); %store the set of times
+ if isempty(TimeUnit)
+ set(handles.dt_unit,'String','e-03');
+ set(handles.TimeUnit,'String','');
+ else
+ set(handles.dt_unit,'String',['m' TimeUnit]);
+ set(handles.TimeUnit,'String',TimeUnit);
+ end
+ set(handles.nb_field,'String',num2str(nbfield));
+ set(handles.nb_field2,'String',num2str(nbfield2));
+ end
+end
+set(handles.CoordUnit,'String',[CoordUnit '/'])
+set(handles.calcul_search,'UserData',[pxcmx_search pxcmy_search]);
+% npxy=[npy npx];
+set(handles.ext_ima,'String',ext_ima)
+set(handles.first_i,'String',num2str(first_i));
+set(handles.last_i,'String',num2str(last_i));%
+set(handles.first_j,'String',num2str(first_j));
+set(handles.last_j,'String',num2str(last_j));%
+browse.nom_type_ima=nom_type_ima;
+set(handles.browse_root,'UserData',browse)% store the nomenclature type
+
+ %%%%%%%%%%% set the menus of image pairs and default selection for civ %%%%%%%%%%%%%%%%%%%
+if isequal(nom_type_ima,'_i')| isequal(nom_type_nc,'_i1-i2')|~exist('nbfield2','var')|(nbfield2==1)
+ set(handles.mode,'String',{'series(Di)'})
+ set(handles.mode,'Value',1)
+elseif isequal(nom_type_ima,'png_old')|isequal(nom_type_nc,'netc_old')
+ set(handles.mode,'String',{'pair j1-j2'})
+ set(handles.mode,'Value',1)
+elseif (nbfield==1)% simple series in j
+ set(handles.mode,'String',{'series(Dj)'})
+ set(handles.mode,'Value',1)
+else
+ set(handles.mode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
+ if isequal(mode,'volume')
+ set(handles.mode,'Value',3)
+ elseif nbfield2 <= 5
+ set(handles.mode,'Value',1)% advice 'pair j1-j2' for small bursts
+ else
+ set(handles.mode,'Value',2)% advice series Dj for long bursts, not volume
+ end
+end
+
+%update the subdir
+pathdir=fileparts(filebase);%path to the current xml file
+listot=dir(pathdir);
+idir=0;
+listdir={''};%default
+for ilist=1:length(listot)
+ if listot(ilist).isdir
+ name=listot(ilist).name;
+ if ~isequal(name,'.') && ~isequal(name,'..')
+ idir=idir+1;
+ listdir{idir,1}=listot(ilist).name;
+ end
+ end
+end
+set(handles.list_subdir_civ1,'Value',1)
+set(handles.list_subdir_civ2,'Value',1)
+set(handles.list_subdir_civ1,'String',['browse...';listdir])
+set(handles.list_subdir_civ2,'String',['browse...';listdir])
+%check wether the current subdir exists:
+subdir_civ1=get(handles.subdir_civ1,'String');
+subdir_civ2=get(handles.subdir_civ2,'String');
+
+mode_Callback(hObject, eventdata, handles)
+
+%%%%%% initialize waitbars and RUN button
+set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
+set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
+set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
+set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
+set(handles.RUN, 'Enable','On')
+set(handles.RUN,'BackgroundColor',[1 0 0])
+if isequal(test_batch,1)%if batch installation is available
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+end
+
+%%%%% store the root input filename for future opening
+dir_perso=prefdir;
+profil_perso=fullfile(prefdir,'uvmat_perso.mat');
+RootPath=fileparts(filebase);
+if exist(profil_perso,'file')
+ save (profil_perso,'RootPath','-append'); %store the root name for future opening of uvmat
+else
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
+ else
+ save (profil_perso,'RootPath'); %store the root name for future opening of uvmat
+ end
+end
+% save(profil_perso, 'filebase'); %store the root name for future opening of uvmat
+set(gcf,'Pointer','arrow')
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
+% --- Executes on button press in mode.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function mode_Callback(hObject, eventdata, handles)
+browse=get(handles.browse_root,'UserData');
+
+compare_list=get(handles.compare,'String');
+val=get(handles.compare,'Value');
+compare=compare_list{val};
+if strcmp(compare,'displacement')
+ mode='displacement';
+else
+ mode_list=get(handles.mode,'String');
+ mode_value=get(handles.mode,'Value');
+ mode=mode_list{mode_value};
+end
+displ_num=[];%default
+first_i=str2num(get(handles.first_i,'String'));
+% last_i=str2num(get(handles.last_i,'String'));
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+siztime=size(time);
+nbfield=siztime(1);
+nbfield2=siztime(2);
+indchosen=1; %%first pair selected by default
+if isequal(mode,'pair j1-j2')%| isequal(mode,'st_pair j1-j2')
+ dt=1;
+ displ='';
+ index=0;
+ numlist_a=[];
+ numlist_B=[];
+ %get all the time intervals in bursts
+ displ_dt=1;%default
+ nbfield2=min(nbfield2,10);%limitate the number of pairs to 10x10
+% if nbfield2<2
+% nbfield2=2,
+% end
+ for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
+ for numod_b=(numod_a+1):nbfield2
+ index=index+1;
+ numlist_a(index)=numod_a;
+ numlist_b(index)=numod_b;
+ if ~isempty(time)
+ dt(numod_a,numod_b)=time(first_i,numod_b)-time(first_i,numod_a);%first time interval dt
+ displ_dt(index)=dt(numod_a,numod_b);
+ else
+ displ_dt(index)=1;
+ end
+ end
+ end
+ [dtsort,indsort]=sort(displ_dt);
+ if ~isempty(numlist_a)
+ displ_num(1,:)=numlist_a(indsort);
+ displ_num(2,:)=numlist_b(indsort);
+ end
+ displ_num(3,:)=0;
+ displ_num(4,:)=0;
+ set(handles.jtext,'Visible','Off')
+ set(handles.first_j,'Visible','Off')
+ set(handles.last_j,'Visible','Off')
+ set(handles.incr_j,'Visible','Off')
+ set(handles.nb_field2,'Visible','Off')
+ set(handles.ref_j,'Visible','Off')
+elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)')
+ for index=1:min(nbfield2-1,200)
+ displ_num(1,index)=-floor(index/2);
+ displ_num(2,index)=ceil(index/2);
+ displ_num(3,index)=0;
+ displ_num(4,index)=0;
+ end
+ set(handles.jtext,'Visible','On')
+ set(handles.first_j,'Visible','On')
+ set(handles.last_j,'Visible','On')
+ set(handles.incr_j,'Visible','On')
+ set(handles.nb_field2,'Visible','On')
+ set(handles.ref_j,'Visible','On')
+ if nbfield > 1
+ set(handles.itext,'Visible','On')
+ set(handles.first_i,'Visible','On')
+ set(handles.last_i,'Visible','On')
+ set(handles.incr_i,'Visible','On')
+ set(handles.nb_field,'Visible','On')
+ set(handles.ref_i,'Visible','On')
+ else
+ set(handles.itext,'Visible','Off')
+ set(handles.first_i,'Visible','Off')
+ set(handles.last_i,'Visible','Off')
+ set(handles.incr_i,'Visible','Off')
+ set(handles.nb_field,'Visible','Off')
+ set(handles.ref_i,'Visible','Off')
+ end
+elseif isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
+ for index=1:200%min(nbfield-1,200)
+ displ_num(1,index)=0;
+ displ_num(2,index)=0;
+ displ_num(3,index)=-floor(index/2);
+ displ_num(4,index)=ceil(index/2);
+ end
+ set(handles.itext,'Visible','On')
+ set(handles.first_i,'Visible','On')
+ set(handles.last_i,'Visible','On')
+ set(handles.incr_i,'Visible','On')
+ set(handles.nb_field,'Visible','On')
+ set(handles.ref_i,'Visible','On')
+ if nbfield2 > 1
+ set(handles.jtext,'Visible','On')
+ set(handles.first_j,'Visible','On')
+ set(handles.last_j,'Visible','On')
+ set(handles.incr_j,'Visible','On')
+ set(handles.nb_field2,'Visible','On')
+ set(handles.ref_j,'Visible','On')
+ else
+ set(handles.jtext,'Visible','Off')
+ set(handles.first_j,'Visible','Off')
+ set(handles.last_j,'Visible','Off')
+ set(handles.incr_j,'Visible','Off')
+ set(handles.nb_field2,'Visible','Off')
+ set(handles.ref_j,'Visible','Off')
+ end
+elseif isequal(mode,'displacement')%the pairs have the same indices
+ displ_num(1,1)=0;
+ displ_num(2,1)=0;
+ displ_num(3,1)=0;
+ displ_num(4,1)=0;
+ if nbfield > 1
+ set(handles.itext,'Visible','On')
+ set(handles.first_i,'Visible','On')
+ set(handles.last_i,'Visible','On')
+ set(handles.incr_i,'Visible','On')
+ set(handles.nb_field,'Visible','On')
+ set(handles.ref_i,'Visible','On')
+ else
+ set(handles.itext,'Visible','Off')
+ set(handles.first_i,'Visible','Off')
+ set(handles.last_i,'Visible','Off')
+ set(handles.incr_i,'Visible','Off')
+ set(handles.nb_field,'Visible','Off')
+ set(handles.ref_i,'Visible','Off')
+ end
+ if nbfield2 > 1
+ set(handles.jtext,'Visible','On')
+ set(handles.first_j,'Visible','On')
+ set(handles.last_j,'Visible','On')
+ set(handles.incr_j,'Visible','On')
+ set(handles.nb_field2,'Visible','On')
+ set(handles.ref_j,'Visible','On')
+ else
+ set(handles.jtext,'Visible','Off')
+ set(handles.first_j,'Visible','Off')
+ set(handles.last_j,'Visible','Off')
+ set(handles.incr_j,'Visible','Off')
+ set(handles.nb_field2,'Visible','Off')
+ set(handles.ref_j,'Visible','Off')
+ end
+end
+set(handles.list_pair_civ1,'UserData',displ_num);
+find_netcpair_civ1(hObject, eventdata, handles)
+find_netcpair_civ2(hObject, eventdata, handles)
+
+%--------------------------------------------------------------
+% determine the menu for civ1 pairs depending on existing netcdf file at the middle of
+% the field series set by first_i, incr, last_i
+%----------------------------------------------------------------
+function find_netcpair_civ1(hObject, eventdata, handles)
+set(gcf,'Pointer','watch')
+%nomenclature types
+filebase=get(handles.displ_filebase,'String');
+[filepath,Nme,ext_dir]=fileparts(filebase);
+browse=get(handles.browse_root,'UserData');
+compare_list=get(handles.compare,'String');
+val=get(handles.compare,'Value');
+compare=compare_list{val};
+if strcmp(compare,'displacement')
+ mode='displacement';
+else
+ mode_list=get(handles.mode,'String');
+ mode_value=get(handles.mode,'Value');
+ mode=mode_list{mode_value};
+end
+
+% nomenclature type of the .nc files
+nom_type_ima=[];%default
+if isfield(browse,'nom_type_ima')
+ nom_type_ima=browse.nom_type_ima;
+end
+
+%determine nom_type_nc:
+nom_type_nc=[];%default
+if isfield(browse,'nom_type_nc')
+ nom_type_nc=browse.nom_type_nc;
+end
+if isempty(nom_type_nc)
+ 'TESTciv'
+ nom_type_ima
+ [nom_type_nc]=nomtype2pair(nom_type_ima,isequal(mode,'series(Di)'),isequal(mode,'series(Dj)'));
+end
+browse.nom_type_nc=nom_type_nc;
+set(handles.browse_root,'UserData',browse)
+
+%reads .nc subdirectoy and image numbers from the interface
+subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
+first_i=str2num(get(handles.first_i,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+incr=str2num(get(handles.incr_i,'String'));
+num1=first_i:incr:last_i;
+if isempty(num1)
+ set(handles.list_pair_civ1,'String',{''});
+ return
+end
+ref_i=str2num(get(handles.ref_i,'String'));
+if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
+ ref_j=0;
+else
+ ref_j=str2num(get(handles.ref_j,'String'));
+end
+if isequal(get(handles.dt_text,'String'),'dt(ms)=')%simple series(Di) with equal interval
+ ref_i=floor((first_i+last_i)/2);
+ ref_j=1;
+end
+time=get(handles.displ_filebase,'UserData');%get the set of times
+if isempty(time)
+ time=[0 1];
+end
+dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
+displ_num=get(handles.list_pair_civ1,'UserData');
+
+%eliminate the first pairs inconsistent with the position
+ if isempty(displ_num)
+ nbpair=0;
+ else
+ nbpair=length(displ_num(1,:));%nbre of displayed pairs
+ if isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
+ nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
+ elseif isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
+ nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
+ end
+ end
+nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
+
+%look for existing processed pairs involving the field at the middle of the series if civ1 will not
+% be performed, while the result is needed for next steps.
+displ_pair={''};
+select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
+testpair=0;
+if get(handles.CIV1,'Value')==0 %
+ dirname=fullfile(filepath,subdir_civ1,ext_dir);
+ if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir')
+ msgbox_uvmat('ERROR',['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist']);
+ set(handles.list_pair_civ1,'String',{});
+ return
+ end
+ for ipair=1:nbpair
+ filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
+ ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
+ select(ipair)=exist(filename,'file')==2;
+ end
+ if ~exist('select','var') || isequal(select,zeros(size(1:nbpair)))
+ if isfield(browse,'incr_pair')
+ num_i1=ref_i-floor(browse.incr_pair(1)/2);
+ num_i2=ref_i+ceil(browse.incr_pair(1)/2);
+ num_j1=ref_j-floor(browse.incr_pair(2)/2);
+ num_j2=ref_j+ceil(browse.incr_pair(2)/2);
+ filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ1);
+ select(1)=exist(filename,'file')==2;
+ testpair=1;
+ else
+ if isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
+ msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ1]);
+ else
+ msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ1]);
+ end
+ set(handles.list_pair_civ1,'String',{''});
+ %COMPLETER CAS STEREO
+ return
+ end
+ end
+end
+if isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
+ if testpair
+ displ_pair{1}=['Di= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
+ elseif ~isequal(get(handles.dt_text,'String'),'dt(ms)=')
+ for ipair=1:nbpair
+ if select(ipair)
+ if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
+ dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
+ end
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+ else
+ for ipair=1:nbpair
+ if select(ipair)
+ displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt_unit*ipair)];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+ end
+elseif isequal(mode,'series(Dj)')%|isequal(mode,'st_series(Dj)')% series on the j index
+ if testpair
+ displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
+ else
+ for ipair=1:nbpair
+ if select(ipair)
+ if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
+ dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
+ end
+ elseif testpair
+ displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(2)/2)) '|' num2str(ceil(browse.incr_pair(2)/2))];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+ end
+elseif isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')%case of pairs
+ for ipair=1:nbpair
+ if select(ipair)
+ dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
+ ' :dt= ' num2str(dt*1000)];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+elseif isequal(mode,'displacement')
+ displ_pair={'Di=Dj=0'};
+end
+set(handles.list_pair_civ1,'String',displ_pair');
+ichoice=min(find(select));
+if (isempty(ichoice) | ichoice < 1); ichoice=1; end;
+initial=get(handles.list_pair_civ1,'Value');
+if initial>nbpair |~isequal(select(initial),1)
+ set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
+end
+%set(handles.list_pair_civ2,'String',displ_pair');
+initial=get(handles.list_pair_civ2,'Value');
+if initial>length(displ_pair')%|~isequal(select(initial),1)
+ if ichoice <= length(displ_pair')
+ set(handles.list_pair_civ2,'Value',ichoice);% same pair proposed by default for civ2
+ else
+ set(handles.list_pair_civ2,'Value',1);% same pair proposed by default for civ2
+ end
+end
+set(handles.list_pair_civ2,'String',displ_pair');
+set(gcf,'Pointer','arrow')
+%--------------------------------------------------------------
+% determine the menu for civ2 pairs depending on the existing netcdf file at the
+%middle of the series set by first_i, incr, last_i
+%--------------------------------------------------------------
+function find_netcpair_civ2(hObject, eventdata, handles)
+set(gcf,'Pointer','watch')
+%nomenclature types
+filebase=get(handles.displ_filebase,'String');
+[filepath,Nme,ext_dir]=fileparts(filebase);
+browse=get(handles.browse_root,'UserData');
+compare_list=get(handles.compare,'String');
+val=get(handles.compare,'Value');
+compare=compare_list{val};
+if strcmp(compare,'displacement')
+ mode='displacement';
+else
+ mode_list=get(handles.mode,'String');
+ mode_value=get(handles.mode,'Value');
+ mode=mode_list{mode_value};
+end
+
+% nomenclature type of the .nc files
+nom_type_ima='ima_num';%default
+if isfield(browse,'nom_type_ima')
+ nom_type_ima=browse.nom_type_ima;
+end
+nom_type_nc='_i1-i2';%default
+if isfield(browse,'nom_type_nc')
+ nom_type_nc=browse.nom_type_nc;
+end
+if isequal(nom_type_ima,'png_old') | isequal(nom_type_ima,'netc_old')| isequal(nom_type_ima,'raw_SMD')| isequal(nom_type_nc,'netc_old')
+ nom_type_nc='netc_old';%nom_type for the netcdf files
+elseif isequal(nom_type_ima,'none')|isequal(nom_type_nc,'none')
+ nom_type_nc='none';
+elseif isequal(nom_type_ima,'avi')|isequal(nom_type_ima,'_i')|isequal(nom_type_ima,'ima_num')|isequal(nom_type_nc,'_i1-i2')
+ nom_type_nc='_i1-i2';
+else
+ if isequal(mode,'series(Di)')%|isequal(mode,'st_series(Di)')
+ nom_type_nc='_i1-i2_j'; % PIV in volume
+ else
+ nom_type_nc='_i_j1-j2';
+ end
+end
+browse.nom_type_nc=nom_type_nc;
+set(handles.browse_root,'UserData',browse)
+
+%reads .nc subdirectory and image numbers from the interface
+subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
+subdir_civ2=get(handles.subdir_civ2,'String');%subdirectory subdir_civ2 for the netcdf data
+first_i=str2num(get(handles.first_i,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+incr=str2num(get(handles.incr_i,'String'));
+num1=first_i:incr:last_i;
+if isempty(num1)
+ set(handles.list_pair_civ2,'Value',1);
+ set(handles.list_pair_civ2,'String',{''});
+ return
+end
+ref_i=str2num(get(handles.ref_i,'String'));
+if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
+ ref_j=0;
+else
+ ref_j=str2num(get(handles.ref_j,'String'));
+end
+if isequal(get(handles.dt_text,'String'),'dt(ms)=')%simple series(Di) with equal interval
+ ref_i=ceil((first_i+last_i)/2);
+ ref_j=1;
+end
+% ref_i=browse.num_ref;%field number initially selected by the browser
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+if isempty(time)
+ time=[0 1];%default
+end
+dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
+displ_num=get(handles.list_pair_civ1,'UserData');
+
+
+%eliminate the first pairs inconsistent with the position
+if isempty(displ_num)
+ nbpair=0;
+else
+ nbpair=length(displ_num(1,:));%nbre of displayed pairs
+ if isequal(mode,'series(Di)')% | isequal(mode,'st_series(Di)')
+ nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
+ elseif isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
+ nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
+ end
+end
+nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
+
+%look for existing processed pairs involving the field at the middle of the series if civ1 will not
+% be performed, while the result is needed for next steps.
+displ_pair={''}; %default
+select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
+if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0%&...
+ if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
+ errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
+ set(handles.list_pair_civ2,'Value',1);
+ set(handles.list_pair_civ2,'String',{''});
+ return
+ end
+ for ipair=1:nbpair
+ filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
+ ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
+ select(ipair)=exist(filename,'file')==2;
+ end
+ if isequal(select,zeros(size(1:nbpair)))
+ if isfield(browse,'incr_pair')
+ num_i1=ref_i-floor(browse.incr_pair(1)/2);
+ num_i2=ref_i+floor((browse.incr_pair(1)+1)/2);
+ num_j1=ref_j-floor(browse.incr_pair(2)/2);
+ num_j2=ref_j+floor((browse.incr_pair(2)+1)/2);
+ filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
+ select(1)=exist(filename,'file')==2;
+ else
+ if isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
+ errordlg(['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
+ else
+ errordlg(['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
+ end
+ set(handles.list_pair_civ2,'Value',1);
+ set(handles.list_pair_civ2,'String',{''});
+ return
+ end
+ end
+end
+if isequal(mode,'series(Di)') % | isequal(mode,'st_series(Di)')
+% if ~isequal(get(handles.dt_text,'String'),'dt(ms)=')
+ for ipair=1:nbpair
+ if select(ipair)
+ if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
+ dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
+ end
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+% else
+% for ipair=1:nbpair
+% if select(ipair)
+% displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt_unit*ipair)];
+% else
+% displ_pair{ipair}='...'; %pair not displayed in the menu
+% end
+% end
+% end
+elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)') % series on the j index
+ for ipair=1:nbpair
+ if select(ipair)
+ if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
+ dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
+ end
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+elseif isequal(mode,'pair j1-j2')% | isequal(mode,'st_pair j1-j2') %case of pairs
+ for ipair=1:nbpair
+ if select(ipair)
+ dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
+ ' :dt= ' num2str(dt*1000)];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+elseif isequal(mode,'displacement')
+ displ_pair={'Di=Dj=0'};
+end
+val=get(handles.list_pair_civ2,'Value');
+ichoice=min(find(select));
+if (isempty(ichoice) | ichoice < 1); ichoice=1; end;
+if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
+ val=ichoice;% first valid pair proposed by default in the menu
+end
+if val>length(displ_pair')
+ set(handles.list_pair_civ2,'Value',1);% first valid pair proposed by default in the menu
+else
+ set(handles.list_pair_civ2,'Value',val);
+end
+set(handles.list_pair_civ2,'String',displ_pair');
+
+
+set(gcf,'Pointer','arrow')
+%----------------------------------------------------
+% determine the list of index pairs of processing file
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
+ find_pair_indices(handles,mode)
+first_i=str2num(get(handles.first_i,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+incr=str2num(get(handles.incr_i,'String'));
+num1=[first_i:incr:last_i];
+if isequal(get(handles.first_j,'Visible'),'on')
+ first_j=str2num(get(handles.first_j,'String'));
+ last_j=str2num(get(handles.last_j,'String'));
+ incr_j=str2num(get(handles.incr_j,'String'));
+else
+ first_j=1;
+ last_j=1;
+ incr_j=1;
+end
+num_j=[first_j:incr_j:last_j];
+list_civ1=get(handles.list_pair_civ1,'String');
+index_civ1=get(handles.list_pair_civ1,'Value');
+str_civ1=list_civ1{index_civ1};
+if isempty(str_civ1)||isequal(str_civ1,'')
+ msgbox_uvmat('ERROR','no image pair selected for civ1')
+ return
+end
+list_civ2=get(handles.list_pair_civ2,'String');
+index_civ2=get(handles.list_pair_civ2,'Value');
+if index_civ2>length(list_civ2)
+ list_civ2=list_civ1;
+ index_civ2=index_civ1;
+end
+str_civ2=list_civ2{index_civ2};
+if isequal(first_i,[])|isequal(first_j,[]), errordlg('first field number not defined'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+if isequal(last_i,[])| isequal(last_j,[]),errordlg('last field number not defined'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+if isequal(incr,[])| isequal(incr_j,[]),errordlg('increment in field number not defined'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+if last_i < first_i | last_j < first_j , errordlg('last field number must be larger than the first one'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+if isequal (mode,'series(Di)')% |isequal(mode,'st_series(Di)')
+ %recognize the pair civ1 from the display
+ indsel=find((double(str_civ1)<48)|(double(str_civ1)>57));% character indices of non numerical characters
+ str_raw=str_civ1(indsel);
+ indsepar=find(str_raw=='|'); %character index of the separator
+ d1=str2num(str_civ1([indsel(indsepar-1)+1:indsel(indsepar)-1]));
+ if indsepar==length(str_raw)
+ d2=str2num(str_civ1([indsel(indsepar)+1:end]));
+ else
+ d2=str2num(str_civ1([indsel(indsepar)+1:indsel(indsepar+1)-1]));
+ end
+ num1_civ1=num1-d1;% set of first image numbers
+ num2_civ1=num1+d2;
+ num_a_civ1=num_j;
+ num_b_civ1=num_j;
+
+ %recognize the pair civ2 from the display
+ indsel=find((double(str_civ2)<48)|(double(str_civ2)>57));% character indices of non numerical characters
+ str_raw=str_civ2(indsel);
+ indsepar=find(str_raw=='|'); %character index of the separator
+ d1=str2num(str_civ2([indsel(indsepar-1)+1:indsel(indsepar)-1]));
+ if indsepar==length(str_raw)
+ d2=str2num(str_civ2([indsel(indsepar)+1:end]));
+ else
+ d2=str2num(str_civ2([indsel(indsepar)+1:indsel(indsepar+1)-1]));
+ end
+ if isempty(d1)
+ num1_civ2=num1;
+ else
+ num1_civ2=num1-d1;% set of first image numbers
+ end
+ if isempty(d2)
+ num2_civ2=num1;
+ else
+ num2_civ2=num1+d2;
+ end
+ num_a_civ2=num_j;
+ num_b_civ2=num_j;
+
+ % adjust the first and last field number
+ lastfield=str2num(get(handles.nb_field,'String'));
+ if isequal(lastfield,[])
+ indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
+ else
+ indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
+ end
+ if length(indsel)>=1
+ firstind=indsel(1);
+ lastind=indsel(end);
+ set(handles.first_i,'String',num2str(num1(firstind)))%update the display of first and last fields
+ set(handles.last_i,'String',num2str(num1(lastind)))
+ num1=num1(indsel);
+ num1_civ1=num1_civ1(indsel);
+ num1_civ2=num1_civ2(indsel);
+ num2_civ1=num2_civ1(indsel);
+ num2_civ2=num2_civ2(indsel);
+ end
+elseif isequal (mode,'series(Dj)')%|isequal (mode,'st_series(Dj)')
+ lastfield_j=str2num(get(handles.nb_field2,'String'));
+ num1_civ1=num1;% set of first image numbers
+ num2_civ1=num1;
+ num_a_civ1=num_j-floor(index_civ1/2)*ones(size(num_j));
+ num_b_civ1=num_j+ceil(index_civ1/2)*ones(size(num_j));
+ num1_civ2=num1;
+ num2_civ2=num1;
+ num_a_civ2=num_j-floor(index_civ2/2)*ones(size(num_j));
+ num_b_civ2=num_j+ceil(index_civ2/2)*ones(size(num_j));
+ % adjust the first and last field number
+ if isequal(lastfield_j,[])
+ indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
+ else
+ indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
+ end
+ if length(indsel)>=1
+ firstind=indsel(1);
+ lastind=indsel(end);
+ set(handles.first_j,'String',num2str(num_j(firstind)))%update the display of first and last fields
+ set(handles.last_j,'String',num2str(num_j(lastind)))
+ num_j=num_j(indsel);
+ num_a_civ1=num_a_civ1(indsel);
+ num_a_civ2=num_a_civ2(indsel);
+ num_b_civ1=num_b_civ1(indsel);
+ num_b_civ2=num_b_civ2(indsel);
+ end
+elseif isequal(mode,'pair j1-j2')% | isequal(mode,'st_pair j1-j2') %case of bursts (png_old or png_2D)
+ num1_civ1=num1;
+ num1_civ2=num1;
+ displ_num=get(handles.list_pair_civ1,'UserData');
+ num2_civ1=num1;
+ num_a_civ1=displ_num(1,index_civ1);
+ num_b_civ1=displ_num(2,index_civ1);
+ num2_civ2=num1;
+ num_a_civ2=displ_num(1,index_civ2);
+ num_b_civ2=displ_num(2,index_civ2);
+elseif isequal(mode,'displacement')
+ num1_civ1=num1;
+ num2_civ1=num1;
+ num_a_civ1=num_j;
+ num_b_civ1=num_j;
+ num1_civ2=num1;
+ num2_civ2=num1;
+ num_a_civ2=num_j;
+ num_b_civ2=num_j;
+end
+
+
+%-------------------------------------------------------------
+% --- Executes on selection change in list_pair_civ1.
+function list_pair_civ1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------
+%reproduce by default the chosen pair in the civ2 menu
+list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
+index_pair=get(handles.list_pair_civ1,'Value');
+displ_num=get(handles.list_pair_civ1,'UserData');
+num_a=displ_num(1,index_pair);
+num_b=displ_num(2,index_pair);
+list_pair2=get(handles.list_pair_civ2,'String');%get the menu of image pairs
+if index_pair<=length(list_pair2)
+ set(handles.list_pair_civ2,'Value',index_pair);
+end
+
+%update first_i and last_i according to the chosen image pairs
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+if isequal(mode,'series(Di)')
+ first_i=str2num(get(handles.first_i,'String'));
+ last_i=str2num(get(handles.last_i,'String'));
+ incr_i=str2num(get(handles.incr_i,'String'));
+ num1=first_i:incr_i:last_i;
+ lastfield=str2num(get(handles.nb_field,'String'));
+ if ~isequal(lastfield,[])
+ ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
+ (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
+ num1=num1(ind);
+ end
+ set(handles.first_i,'String',num2str(num1(1)));
+ set(handles.last_i,'String',num2str(num1(end)));
+elseif isequal(mode,'series(Dj)')
+ first_j=str2num(get(handles.first_j,'String'));
+ last_j=str2num(get(handles.last_j,'String'));
+ incr_j=str2num(get(handles.incr_j,'String'));
+ num_j=first_j:incr_j:last_j;
+ lastfield2=str2num(get(handles.nb_field2,'String'));
+ if ~isequal(lastfield2,[])
+ ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
+ (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
+ num1=num_j(ind);
+ end
+ set(handles.first_j,'String',num2str(num1(1)));
+ set(handles.last_j,'String',num2str(num1(end)));
+end
+
+%------------------------------------------------------------------
+% --- Executes on selection change in list_pair_civ2.
+function list_pair_civ2_Callback(hObject, eventdata, handles)
+
+index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu
+
+%update first_i and last_i according to the chosen image pairs
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+if isequal(mode,'series(Di)')
+ first_i=str2num(get(handles.first_i,'String'));
+ last_i=str2num(get(handles.last_i,'String'));
+ incr_i=str2num(get(handles.incr_i,'String'));
+ num1=first_i:incr_i:last_i;
+ lastfield=str2num(get(handles.nb_field,'String'));
+ if ~isequal(lastfield,[])
+ ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
+ (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
+ num1=num1(ind);
+ end
+ set(handles.first_i,'String',num2str(num1(1)));
+ set(handles.last_i,'String',num2str(num1(end)));
+elseif isequal(mode,'series(Dj)')
+ first_j=str2num(get(handles.first_j,'String'));
+ last_j=str2num(get(handles.last_j,'String'));
+ incr_j=str2num(get(handles.incr_j,'String'));
+ num_j=first_j:incr_j:last_j;
+ lastfield2=str2num(get(handles.nb_field2,'String'));
+ if ~isequal(lastfield2,[])
+ ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
+ (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
+ num1=num_j(ind);
+ end
+ set(handles.first_j,'String',num2str(num1(1)));
+ set(handles.last_j,'String',num2str(num1(end)));
+end
+
+%---------------------------------------------------
+% --- Executes on button press in RUN.
+%------------------------------------------------------
+function RUN_Callback(hObject, eventdata, handles)
+global civ1_exe civ2_exe patch_exe patch_new_exe sge
+
+compare=get(handles.compare,'Value');%test for usual PIV (compare=1) or displacement (=2) or stereo PIV (=3)
+%check the list of operations:
+operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
+run_flag=1;
+box_test(1)=get(handles.CIV1,'Value');
+box_test(2)=get(handles.FIX1,'Value');
+box_test(3)=get(handles.PATCH1,'Value');
+box_test(4)=get(handles.CIV2,'Value');
+box_test(5)=get(handles.FIX2,'Value');
+box_test(6)=get(handles.PATCH2,'Value');
+index=find(box_test==1);
+if isempty(index)
+ msgbox_uvmat('ERROR','no selected operation')
+ return
+end
+index_first=min(index);
+index_last=max(index);
+box_used=box_test([index_first : index_last]);
+[box_missing,ind_missing]=min(box_used);
+if isequal(box_missing,0)
+ msgbox_uvmat('ERROR',['missing' cell2mat(operations(ind_missing))]);
+ return
+end
+
+%root name
+filebase=get(handles.displ_filebase,'String');
+if isempty(filebase)||isequal(filebase,'')
+ msgbox_uvmat('ERROR','no input files')
+ return
+end
+%check mask if selecetd
+if isequal(get(handles.get_mask_civ1,'Value'),1)
+ get_mask_civ1_Callback(hObject, eventdata, handles);
+end
+if isequal(get(handles.get_mask_fix1,'Value'),1)
+ get_mask_fix1_Callback(hObject, eventdata, handles);
+end
+if isequal(get(handles.get_mask_civ2,'Value'),1)
+ get_mask_civ2_Callback(hObject, eventdata, handles);
+end
+if isequal(get(handles.get_mask_fix2,'Value'),1)
+ get_mask_fix2_Callback(hObject, eventdata, handles);
+end
+
+%read names of the .exe file
+if box_test(1)==1 | box_test(3)==1 | box_test(4)==1 | box_test(6)==1
+ path_uvmat=which('uvmat');% check the path detected for source file uvmat
+ path_UVMAT=fileparts(path_uvmat); %path to UVMAT
+ if isunix
+ %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ binary names
+ xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml');
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+ else
+ %fid = fopen(fullfile(path_UVMAT,'PARAM_WIN.txt'),'r');%open the file with civ binary names
+ xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+ end
+ if isfield(sparam,'Civ1_exe')
+ civ1_exe=sparam.Civ1_exe;
+ end
+ if isfield(sparam,'Civ2_exe')
+ civ2_exe=sparam.Civ2_exe;
+ end
+ if isfield(sparam,'Patch_exe')
+ patch_exe=sparam.Patch_exe;
+ end
+ if isfield(sparam,'Stinterp_exe')
+ stinterp_exe=sparam.Stinterp_exe;
+ end
+ if isfield(sparam,'SGE')
+ sge=str2num(sparam.SGE);
+ end
+ if ~isunix % for windows system, check whether the Matlab working dir is a UBC name
+ dircur=pwd;
+ if ~isequal(dircur([2 3]),':\')
+ msgbox_uvmat('ERROR','move to a Matlab current working directory with a Windows name, e.g. m:/...')
+ return;
+ end
+ end
+end
+
+%initialize the waitbars
+set(handles.waitbar_1,'Position',[0.946 0.877 0.03 0.001])
+set(handles.waitbar_patch1,'Position',[0.946 0.626 0.03 0.001])
+set(handles.waitbar_civ2,'Position',[0.946 0.406 0.03 0.001])
+set(handles.waitbar_patch2,'Position',[0.946 0.187 0.03 0.001])
+set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
+set(handles.RUN, 'Enable','Off')
+drawnow
+
+% get the list of file names and check the files
+display('checking the files...')
+[filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
+ set_civ_filenames(handles,compare,box_test);
+display('files OK, processing...')
+nbfield=size(num1_civ1,2);
+nbslice=size(num1_civ1,1);
+
+%RUN CIV1
+if box_test(1)==1
+ RUN_CIV1(handles,filecell.ima1.civ1,filecell.ima2.civ1,filecell.nc.civ1,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,nom_type_nc)
+ if compare==3
+ RUN_CIV1(handles,filecell.imaA1.civ1,filecell.imaA2.civ1,filecell.ncA.civ1,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,nom_type_nc)
+ end
+end
+
+%RUN FIX1
+if box_test(2)==1
+ filebase=get(handles.displ_filebase,'String');
+ %names of the civ1 fields
+ field1.vel_type='civ1';
+ field1.nb='nb_vectors';
+ field1.X='vec_X';
+ field1.Y='vec_Y';
+ field1.U='vec_U';
+ field1.V='vec_V';
+ field1.fixflag='vec_FixFlag';
+ flagindex(1)=get(handles.vec_Fmin2, 'Value');
+ flagindex(2)=get(handles.vec_F3, 'Value');
+ flagindex(3)=get(handles.vec_F2, 'Value');
+ thresh_vecC=str2num(get(handles.thresh_vecC,'String'));%threshold on image correlation vec_C
+ thresh_vel=str2num(get(handles.thresh_vel,'String'));%threshold on velocity modulus
+ inf_sup=get(handles.inf_sup1,'Value');
+ menu=get(handles.field_ref1,'String');
+ index=get(handles.field_ref1,'Value');
+ if isempty(menu)
+ fieldchoice='';
+ else
+ fieldchoice=menu{index};
+ end
+ h = waitbar(0,['removing velocity vectors, fix1']);% display a wait bar
+ test_mask=get(handles.get_mask_fix1,'Value');
+ maskdispl=get(handles.mask_fix1,'String');
+ maskbase=[get(handles.displ_filebase,'String') '_' maskdispl]; % mask root name
+ for ifile=1:nbfield
+ waitbar(ifile/nbfield); %update the waitbar
+ for j=1:nbslice
+ if test_mask==0
+ maskname='noFile use default';
+ maskflag=0;
+ else
+ nbslice_mask=str2num(maskdispl(1:end-4)); %
+ num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
+ maskname=name_generator(maskbase,num1_mask,1,'.png','_i');% mask corresponding to the first image of the pair
+ maskflag= exist(maskname,'file')==2;
+ if ~maskflag;
+ maskname='noFile use default';
+ end
+ end
+ if ~isempty(file_ref_fix1)
+ file_ref=file_ref_fix1{ifile,j};
+ else
+ file_ref='';
+ end
+ error=RUN_FIX(filecell.nc.civ1{ifile,j},field1,flagindex,1,thresh_vecC,maskflag,maskname,...
+ thresh_vel,inf_sup,file_ref,fieldchoice);
+
+ if compare==3 &&(isequal(mode,'pair j1-j2') || isequal(mode,'series(Dj)') || isequal(mode,'series(Di)'))
+ if test_mask==0
+ maskname='noFile use default';
+ maskflag=0;
+ else
+ maskbase=[get(handles.displ_filebase2,'String') '_' maskdispl]; % mask root name
+ nbslice_mask=str2num(maskdispl(1:end-4)); %
+ num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
+ maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
+ maskflag= exist(maskname,'file')==2;
+ if ~maskflag;
+ maskname='noFile use default';
+ end
+ end
+ error=RUN_FIX(filecell.ncA.civ1{ifile,j},field1,flagindex,1,thresh_vecC,maskflag,maskname,...
+ thresh_vel,inf_sup,file_ref,fieldchoice);
+ if ~isempty(error)
+ msgbox_uvmat('ERROR',error)
+ return
+ end
+ end
+ end
+ end
+ close(h)
+end
+
+% RUN PATCH1
+if box_test(3)==1
+ rho_patch1=str2num(get(handles.rho_patch1,'String'));
+ if isempty(rho_patch1)
+ rho_patch1='1000';
+ set(handles.rho_patch1,'String','1')
+ else
+ rho_patch1=num2str(1000*rho_patch1);
+ end
+ nx_patch1=get(handles.nx_patch1,'String');
+ if isequal(str2num(nx_patch1),[])
+ nx_patch1='50' ;%default
+ set(handles.nx_patch1,'String','50');
+ end
+ ny_patch1=get(handles.ny_patch1,'String');
+ if isequal(str2num(ny_patch1),[])
+ ny_patch1='50' ;%default
+ set(handles.ny_patch1,'String','50');
+ end
+ subdomain_patch1=get(handles.subdomain_patch1,'String');
+ thresh_patch1=get(handles.thresh_patch1,'String');
+ test_interp=get(handles.test_interp,'Value');
+ icount=0;
+ for ifile=1:nbfield
+ for j=1:nbslice
+ icount=icount+1;
+ barlength=0.188*icount/(nbfield*nbslice);
+ set(handles.waitbar_patch1,'Position',[0.946 0.627-barlength 0.03 barlength])
+ drawnow
+ if isequal(get(handles.test_stereo1,'Value'),0)
+ cmd=RUN_PATCH(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp);
+ s=-1;
+ if sge
+ [s,w]=unix(['qrsh -q -fast.q ' cmd]);
+ end
+ if s~=0
+ display(['!' cmd])
+ eval(['!' cmd]);
+ end
+
+ %stereo case:
+ elseif isequal(get(handles.test_stereo1,'Value'),1)
+ if exist('stinterp_exe','var')%Prog Gauthier
+ cmd=RUN_STINTERP(stinterp_exe,filecell.ncA.civ1{ifile,j},filecell.nc.civ1{ifile,j},filecell.st{ifile,j},...
+ nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,[filebase_A '.xml'],[filebase_B '.xml']);
+ display(['!' cmd])
+ eval(['!' cmd]);
+ else
+ RUN_STLIN(filecell.ncA.civ1{ifile,j},filecell.nc.civ1{ifile,j},'civ1',filecell.st{ifile,j},...
+ str2num(nx_patch1),str2num(ny_patch1),str2num(thresh_patch1),[filebase_A '.xml'],[filebase_B '.xml']);
+ end
+ end
+ if compare==3 && isequal(get(handles.test_stereo1,'Value'),0)
+ cmd=RUN_PATCH(filecell.ncA.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp);
+ s=-1;
+ if sge
+ [s,w]=unix(['qrsh -q -fast.q ' cmd]);
+ end
+ if s~=0
+ display(['!' cmd])
+ eval(['!' cmd]);
+ end
+ end
+ end
+ end
+end
+
+% CIV2
+if box_test(4)==1
+ RUN_CIV2(handles,filecell.ima1.civ2,filecell.ima2.civ2,filecell.nc.civ1,filecell.nc.civ2,num1_civ2,num2_civ2,...
+ num_a_civ2,num_b_civ2,nom_type_nc)
+end
+
+% FIX2
+if box_test(5)==1
+ %names of the civ2 fields
+ field2.vel_type='civ2';
+ field2.nb='nb_vectors2';
+ field2.X='vec2_X';
+ field2.Y='vec2_Y';
+ field2.U='vec2_U';
+ field2.V='vec2_V';
+ field2.fixflag='vec2_FixFlag';
+ flagindex(1)=get(handles.vec_Fmin2_2, 'Value');
+ flagindex(2)=get(handles.vec_F3_2, 'Value');
+ flagindex(3)=get(handles.vec_F4, 'Value');
+ thresh_vec2C=str2num(get(handles.thresh_vec2C,'String'));%threshold on image correlation vec_C
+ thresh_vel2=str2num(get(handles.thresh_vel2,'String'));%threshold on velocity modulus
+ inf_sup=get(handles.inf_sup2,'Value');
+ menu=get(handles.field_ref2,'String');
+ index=get(handles.field_ref2,'Value');
+ if isempty(menu)
+ fieldchoice='';
+ else
+ fieldchoice=menu{index};
+ end
+ h = waitbar(0,['removing velocity vectors, fix2']);% display a wait bar
+ test_mask=get(handles.get_mask_fix2,'Value');
+ maskdispl=get(handles.mask_fix2,'String');
+ maskbase=[get(handles.displ_filebase,'String') '_' maskdispl]; % mask root name
+ for ifile=1:nbfield
+ waitbar(ifile/nbfield); %update the waitbar
+ for j=1:nbslice
+ if test_mask==0
+ maskname='noFile use default';
+ maskflag=0;
+ else
+ nbslice_mask=str2num(maskdispl(1:end-4)); %
+ num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
+ maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
+ maskflag= exist(maskname,'file')==2;
+ if ~maskflag;
+ maskname='noFile use default';
+ end
+ end
+ if ~isempty(file_ref_fix2)
+ file_ref=file_ref_fix2{ifile,j};
+ else
+ file_ref='';
+ end
+ error=RUN_FIX(filecell.nc.civ2{ifile,j},field2,flagindex,2,thresh_vec2C,maskflag,maskname,...
+ thresh_vel2,inf_sup,file_ref,fieldchoice);
+ if ~isempty(error)
+ msgbox_uvmat('ERROR',error)
+ return
+ end
+ if compare==3
+ if test_mask==0
+ maskname='noFile use default';
+ maskflag=0;
+ else
+ maskbase=[get(handles.displ_filebase2,'String') '_' maskdispl]; % mask root name
+ nbslice_mask=str2num(maskdispl(1:end-4)); %
+ num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
+ maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
+ maskflag= exist(maskname,'file')==2;
+ if ~maskflag;
+ maskname='noFile use default';
+ end
+ end
+ error=RUN_FIX(filecell.ncA.civ2{ifile,j},field2,flagindex,1,thresh_vec2C,maskflag,maskname,...
+ thresh_vel2,inf_sup,file_ref,fieldchoice);
+ if ~isempty(error)
+ msgbox_uvmat('ERROR',error)
+ return
+ end
+ end
+ end
+ end
+ close(h)
+end
+
+%PATCH 2
+if box_test(6)==1
+ rho_patch2=str2num(get(handles.rho_patch2,'String'));
+ if isempty(rho_patch2)
+ rho_patch2='1000';
+ set(handles.rho_patch2,'String','1')
+ else
+ rho_patch2=num2str(1000*rho_patch2);
+ end
+ nx_patch2=get(handles.nx_patch2,'String');
+ ny_patch2=get(handles.ny_patch2,'String');
+ thresh_patch2=get(handles.thresh_patch2,'String');
+ if isequal(str2num(nx_patch2),[])
+ nx_patch2='50' ;%default
+ set(handles.nx_patch2,'String','50');
+ end
+ if isequal(str2num(ny_patch2),[])
+ ny_patch2='50' ;%default
+ set(handles.ny_patch2,'String','50');
+ end
+ subdomain_patch2=get(handles.subdomain_patch2,'String');
+ icount=0;
+ for ifile=1:nbfield
+ for j=1:nbslice
+ icount=icount+1;
+ barlength=0.188*icount/(nbfield*nbslice);
+ set(handles.waitbar_patch2,'Position',[0.946 0.188-barlength 0.03 barlength])
+ drawnow
+ if compare~=3 | isequal(get(handles.test_stereo2,'Value'),0)
+ cmd=RUN_PATCH(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,1,0);
+ s=-1;
+ if sge
+ [s,w]=unix(['qrsh -q -fast.q ' cmd]);
+ end
+ if s~=0
+ display(['!' cmd])
+ eval(['!' cmd]);
+ end
+ elseif compare==3 && isequal(get(handles.test_stereo2,'Value'),1)
+ if exist('stinterp_exe','var')%Prog Gauthier
+ cmd=RUN_STINTERP(stinterp_exe,filecell.ncA.civ2{ifile,j},filecell.nc.civ2{ifile,j},filecell.st{ifile,j},...
+ nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,[filebase_A '.xml'],[filebase_B '.xml']);
+ display(['!' cmd])
+ eval(['!' cmd])
+ else
+ RUN_STLIN(filecell.ncA.civ2{ifile,j},filecell.nc.civ2{ifile,j},'civ2',filecell.st{ifile,j},...
+ str2num(nx_patch2),str2num(ny_patch2),str2num(thresh_patch2),[filebase_A '.xml'],[filebase_B '.xml'])
+ end
+ end
+ if compare==3 && isequal(get(handles.test_stereo2,'Value'),0)
+ cmd=RUN_PATCH(filecell.ncA.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,1,0);
+ s=-1;
+ if sge
+ [s,w]=unix(['qrsh -q -fast.q ' cmd]);
+ end
+ if s~=0
+ display(['!' cmd])
+ eval(['!' cmd]);
+ end
+ end
+ end
+ end
+end
+
+set(handles.RUN, 'Enable','On')
+set(handles.RUN,'BackgroundColor',[1 0 0])
+
+%save the current interface setting as figure namefig, append .0 to the name if it already exists
+if isfield(filecell,'st')
+ fileresu=filecell.st{1,1};
+elseif isfield(filecell,'nc')
+ if isfield(filecell.nc,'civ2')
+ fileresu=filecell.nc.civ2{1,1};
+ else
+ fileresu=filecell.nc.civ1{1,1};
+ end
+end
+[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
+namedoc=fullfile(RootPath,subdir,RootFile);
+detect=1;
+while detect==1
+ namefigfull=[namedoc '.fig'];
+ hh=dir(namefigfull);
+ if ~isempty(hh)
+ detect=1;
+ namedoc=[namedoc '.0'];
+ else
+ detect=0;
+ end
+end
+saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER .xml)
+
+
+%-----------------------------------------------------------
+% --- Executes on button press in BATCH: remote processing
+%-----------------------------------------------------------
+function BATCH_Callback(hObject, eventdata, handles)
+global civ1_exe civ2_exe patch_exe patch_new_exe fix_exe todo_path sge Civ_exe
+compare=get(handles.compare,'Value');%test for usual PIV (compare=1) or displacement (=2) or stereo PIV (=3)
+
+%check the list of operations:
+operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
+run_flag=1;
+box_test(1)=get(handles.CIV1,'Value');
+box_test(2)=get(handles.FIX1,'Value');
+box_test(3)=get(handles.PATCH1,'Value');
+box_test(4)=get(handles.CIV2,'Value');
+box_test(5)=get(handles.FIX2,'Value');
+box_test(6)=get(handles.PATCH2,'Value');
+index=find(box_test==1);
+if isempty(index)
+ msgbox_uvmat('ERROR','no selected operation')
+ return
+end
+index_first=min(index);
+index_last=max(index);
+box_used=box_test([index_first : index_last]);
+[box_missing,ind_missing]=min(box_used);
+if isequal(box_missing,0)
+ msgbox_uvmat('ERROR',['missing' cell2mat(operations(ind_missing))]);
+ return
+end
+
+%root name
+filebase=get(handles.displ_filebase,'String');
+if isempty(filebase)||isequal(filebase,'')
+ msgbox_uvmat('ERROR','no input files')
+ return
+end
+
+%check mask if selecetd
+if isequal(get(handles.get_mask_civ1,'Value'),1)
+ get_mask_civ1_Callback(hObject, eventdata, handles);
+end
+if isequal(get(handles.get_mask_fix1,'Value'),1)
+ get_mask_fix1_Callback(hObject, eventdata, handles);
+end
+if isequal(get(handles.get_mask_civ2,'Value'),1)
+ get_mask_civ2_Callback(hObject, eventdata, handles);
+end
+if isequal(get(handles.get_mask_fix2,'Value'),1)
+ get_mask_fix2_Callback(hObject, eventdata, handles);
+end
+
+%read names of the .exe file
+path_uvmat=which('uvmat');% check the path detected for source file uvmat
+path_UVMAT=fileparts(path_uvmat); %path to UVMAT
+if isunix
+ xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml');
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+else
+ xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+end
+sge=0;
+if isfield(sparam,'Civ_exe')
+ Civ_exe=sparam.Civ_exe;
+end
+if isfield(sparam,'Civ1_exe')
+ civ1_exe=sparam.Civ1_exe;
+end
+if isfield(sparam,'Civ2_exe')
+ civ2_exe=sparam.Civ2_exe;
+end
+if isfield(sparam,'Patch_exe')
+ patch_exe=sparam.Patch_exe;
+end
+ if isfield(sparam,'PatchNew_exe')
+ patch_new_exe=sparam.PatchNew_exe;
+ end
+ if isfield(sparam,'Fix_exe')
+ fix_exe=sparam.Fix_exe;
+ end
+ if isfield(sparam,'Todo_path')
+ todo_path=sparam.Todo_path;
+ end
+if isfield(sparam,'SGE')
+ sge=str2num(sparam.SGE);
+end
+
+%choice of batch priority
+ind_answer=2;
+if sge
+ [s,w]=unix('qstat -q civ.q|grep job_| wc -l'); %check the waiting list (command unix)
+ if isequal(s,0)
+ w(end)=[];
+ str_displ={[w ' jobs in the waiting list'];'Select a priority:'};
+ str={'urgent';'normal';'low'};
+ [ind_answer,v] = listdlg('PromptString',str_displ,...
+ 'SelectionMode','single',...
+ 'ListString',str,'ListSize',[200 200],'Name','job priority','InitialValue',3);
+ if isequal(v,0) % to handle Cancel button and figure close,
+ return % a better way should be create
+ end
+ else
+ msgbox_uvmat('ERROR','batch system not available')
+ return
+ end
+end
+
+%initialize the waitbars
+set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
+set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
+set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
+set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
+set(handles.BATCH, 'Enable','Off')
+set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
+drawnow
+%get the filename root, nomenclature and numbers
+
+% for Windows system find the UBC path name if needed
+if ~isunix & isequal(todo_path(1:2),'\\') & isequal(filebase(2:3),':\')
+ cur_dir=pwd;
+ if ~isequal(cur_dir(2:3),':\')
+ cd(matlabroot); %move to the Matlab root directory if the current Matlab dir does not allow the dos command or is M:
+ end
+ [ss,ww]=dos(['net use ' filebase(1:2)]);
+ if isequal(ss,0)
+ rankpath=findstr(ww,'\\');
+ if ~isempty(rankpath)
+ wwrest=ww(rankpath:end);
+ rankend=min(find(double(wwrest)==10))-1;
+ filebase=[wwrest(1:rankend) filebase(3:end)];
+ set(handles.displ_filebase,'String',filebase);
+ end
+ else
+ msgbox_uvmat('ERROR','for BATCH option, UBC file names, beginning by \\, are needed');
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+end
+
+% set the list of files and check them
+display('checking the files...')
+[filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
+ set_civ_filenames(handles,compare,box_test);
+display('files OK, processing...')
+nbfield=size(num1_civ1,2);
+nbslice=size(num1_civ1,1);
+
+%GET PARAMETERS:
+ %get civ parameters
+if box_test(1)==1
+ par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1,1});
+end
+
+%get fix1 parameters
+if box_test(2)==1
+ flagindex1(1)=get(handles.vec_Fmin2, 'Value');
+ flagindex1(2)=get(handles.vec_F3, 'Value');
+ flagindex1(3)=get(handles.vec_F2, 'Value');
+ thresh_vecC1=str2num(get(handles.thresh_vecC,'String'));%threshold on image correlation vec_C
+ thresh_vel1=str2num(get(handles.thresh_vel,'String'));%threshold on velocity modulus
+ test_mask=get(handles.get_mask_fix1,'Value');
+ nbslice_mask=get(handles.mask_fix1,'UserData'); % get the number of slices (= number of masks)
+ %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX
+% inf_sup=get(handles.inf_sup1,'Value');
+% fileref=get(handles.ref_fix1,'String');
+% refpath=get(handles.ref_fix1,'UserData');
+% fileref=fullfile(refpath,fileref);
+ menu=get(handles.field_ref1,'String');
+ index=get(handles.field_ref1,'Value');
+ if isempty(menu)
+ fieldchoice='';
+ else
+ fieldchoice=menu{index};
+ msgbox_uvmat('WARNING','reference field is not used presently with batch, use RUN option')
+ end
+end
+
+ %get patch1 parameters
+ if box_test(3)==1
+ rho_patch1=str2num(get(handles.rho_patch1,'String'));
+ if isempty(rho_patch1)
+ rho_patch1='1000';
+ set(handles.rho_patch1,'String','1')
+ else
+ rho_patch1=num2str(1000*rho_patch1);
+ end
+ nx_patch1=get(handles.nx_patch1,'String');
+ ny_patch1=get(handles.ny_patch1,'String');
+ if isequal(str2num(nx_patch1),[])
+ nx_patch1='50' ;%default
+ set(handles.nx_patch1,'String','50');
+ end
+ if isequal(str2num(ny_patch1),[])
+ ny_patch1='50' ;%default
+ set(handles.ny_patch1,'String','50');
+ end
+ subdomain_patch1=get(handles.subdomain_patch1,'String');
+ thresh_patch1=get(handles.thresh_patch1,'String');
+ test_interp=get(handles.test_interp,'Value');
+ end
+
+ %get civ2 parameters
+if box_test(4)==1
+ par_civ2=read_param_civ2(handles,cell2mat(filecell.ima1.civ2(1,1)));
+end
+
+%get fix2 parameters
+if box_test(5)==1
+ flagindex2(1)=get(handles.vec_Fmin2_2, 'Value');
+ flagindex2(2)=get(handles.vec_F3_2, 'Value');
+ flagindex2(3)=get(handles.vec_F4, 'Value');
+ thresh_vec2C=str2num(get(handles.thresh_vec2C,'String'));%threshold on image correlation vec_C
+ thresh_vel2=str2num(get(handles.thresh_vel2,'String'));%threshold on velocity modulus
+ test_mask=get(handles.get_mask_fix2,'Value');
+ nbslice_mask=get(handles.mask_fix2,'UserData'); % get the number of slices (= number of masks)
+ %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX AVEC REF FILE ET OPTION inf_sup=2
+% inf_sup=get(handles.inf_sup2,'Value');
+% ref=get(handles.ref_fix2,'UserData');
+
+ %%%%%%%%%%%%%%%%%%%
+end
+
+
+%get patch2 parameters
+if box_test(6)==1
+ rho_patch2=str2num(get(handles.rho_patch2,'String'));
+ if isempty(rho_patch2)
+ rho_patch2='1000';
+ set(handles.rho_patch2,'String','1')
+ else
+ rho_patch2=num2str(1000*rho_patch2);
+ end
+ nx_patch2=get(handles.nx_patch2,'String');
+ ny_patch2=get(handles.ny_patch2,'String');
+ if isequal(str2num(nx_patch2),[])
+ nx_patch2='50' ;%default
+ set(handles.nx_patch2,'String','50');
+ end
+ if isequal(str2num(ny_patch2),[])
+ ny_patch2='50' ;%default
+ set(handles.ny_patch2,'String','50');
+ end
+ subdomain_patch2=get(handles.subdomain_patch2,'String');
+ thresh_patch2=get(handles.thresh_patch2,'String');
+ test_interp=get(handles.test_interp,'Value');
+end
+
+if ~sge
+
+ %OPEN THE WAIT LIST FOR BATCH PROCESSES
+ name_lock=fullfile(todo_path,'lock'); %lock file
+ iwait=0;
+ while(exist(name_lock) & iwait<15)
+ pause(1); %wait 1 second
+ iwait=iwait+1;
+ end
+ if iwait==15
+ msgbox_uvmat('ERROR',['I''m tired to wait for the lock file, please delete it then click again on BATCH' name_lock ])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+ p0=fopen(name_lock,'w'); %create the file name_lock: prevents other users to interfere
+ name_todo=fullfile(todo_path,'TODO.txt');
+ p1=fopen(name_todo,'a');
+ if (p1<0)
+ msgbox_uvmat('ERROR',['error in opening ' name_todo])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return;
+ end
+end
+
+%MAIN LOOP
+% for ifile=1:nbfield
+p1text=[];%initiate command text
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+civAll=get(handles.Experimental,'Value'); % Boolean for new civ excution method
+for ifile=1:nbfield
+ for j=1:nbslice
+ i_cmd=0;
+ cmd='';
+ if sge
+ cmd='#!/bin/bash';
+ cmd=char({cmd;'#$ -cwd'});
+ cmd=char({cmd;'hostname && date'});
+ end
+ if civAll
+ civAllxml=xmltree;% xml contents, all parameters
+ civAllCmd=[];
+ civAllxml=set(civAllxml,1,'name','CivDoc');
+ end
+% filecell.nc.civ1
+ filename_cmx=cell2mat(filecell.nc.civ1(ifile,j));%output netcdf file
+ filename_cmx([end-1:end])='cm';%name of cmx file
+ filename_cmx=[filename_cmx 'x'];
+
+ %CIV1
+ if box_test(1)==1
+ par_civ1.filename_ima_a=cell2mat(filecell.ima1.civ1(ifile,j));
+ % par_civ1.filename_ima_a([end-3:end])=[];%remove .png extension
+ par_civ1.filename_ima_b=cell2mat(filecell.ima2.civ1(ifile,j));
+ % par_civ1.filename_ima_b([end-3:end])=[];%remove .png extension
+
+ namelog=[filename_cmx([1:end-3]) 'log'];
+ par_civ1.Dt=num2str(time(num2_civ1(ifile),num_b_civ1(j))-time(num1_civ1(ifile),num_a_civ1(j)));
+ par_civ1.T0=num2str((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(j)))/2);
+ par_civ1.term_a=num2stra(num_a_civ1(j),nom_type_nc);%UTILITE?
+ par_civ1.term_b=num2stra(num_b_civ1(j),nom_type_nc);%
+ test_mask=get(handles.get_mask_civ1,'Value');
+ if test_mask==0
+ par_civ1.maskname='noFile use default';
+ par_civ1.maskflag='n';
+ else
+ maskdispl=get(handles.mask_civ1,'String');
+ maskbase=[filebase '_' maskdispl]; %
+ nbslice_mask=str2num(maskdispl(1:end-4)); %
+ num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
+ par_civ1.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
+ if exist(par_civ1.maskname,'file')
+ par_civ1.maskflag='y';
+ else
+ par_civ1.maskname='noFile use default';
+ par_civ1.maskflag='n';
+ end
+ end
+
+ %TESTgrid
+ test_grid=get(handles.browse_gridciv1,'Value');
+ if test_grid
+ par_civ1.gridflag='y';
+ gridname=get(handles.grid_civ1,'String');
+ if isequal(gridname(end-3:end),'grid')
+ nbslice_grid=str2num(gridname(1:end-4)); %
+ if ~isempty(nbslice_grid)
+ num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
+ par_civ1.gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
+ if ~exist(par_civ1.gridname,'file')
+ msgbox_uvmat('ERROR','grid file absent for civ1')
+ end
+ elseif exist(gridname,'file')
+ par_civ1.gridname=gridname;
+ else
+ msgbox_uvmat('ERROR','grid file absent for civ1')
+ end
+ end
+ else
+ par_civ1.gridname='noFile use default';
+ par_civ1.gridflag='n';
+ end
+ %endTESTgrid
+
+ i_cmd=i_cmd+1;
+ if isequal(civAll,0)
+ cmd=char({cmd;BATCH_CIV1(filename_cmx([1:end-4]),namelog,par_civ1,handles)});
+ else
+ civAllCmd=[civAllCmd ' civ1 '];
+ str=BATCH_CIV1_Unified(filename_cmx([1:end-4]),namelog,par_civ1);
+ fieldnames=fields(str);
+ [civAllxml,uid_civ1]=add(civAllxml,1,'element','civ1');
+ for ilist=1:length(fieldnames)
+ val=eval(['str.' fieldnames{ilist}]);
+ if ischar(val)
+ [civAllxml,uid_t]=add(civAllxml,uid_civ1,'element',fieldnames{ilist});
+ [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+ end
+ end
+ end
+ end
+
+ % FIX1
+ if box_test(2)==1
+ test_mask=get(handles.get_mask_fix1,'Value');
+ if test_mask==0
+ maskname='';
+ else
+ maskdispl=get(handles.mask_fix1,'String');
+ nbslice_mask=str2num(maskdispl(1:end-4)); %
+ num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
+ maskbase=[filebase '_' maskdispl];
+ maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
+ end
+ if isequal(civAll,0)
+ cmd_FIX=[fix_exe ' -f ' filecell.nc.civ1{ifile,j} ' -fi1 ' num2str(flagindex1(1)) ...
+ ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
+ ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName ' maskname];
+ cmd=char({cmd ;cmd_FIX});
+ else
+ fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
+ fix1.fi1=num2str(flagindex1(1));
+ fix1.fi2=num2str(flagindex1(2));
+ fix1.fi3=num2str(flagindex1(3));
+ fix1.threshC=num2str(thresh_vecC1);
+ fix1.threshV=num2str(thresh_vel1);
+ fieldnames=fields(fix1);
+ [civAllxml,uid_fix1]=add(civAllxml,1,'element','fix1');
+ for ilist=1:length(fieldnames)
+ val=eval(['fix1.' fieldnames{ilist}]);
+ if ischar(val)
+ [civAllxml,uid_t]=add(civAllxml,uid_fix1,'element',fieldnames{ilist});
+ [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+ end
+ end
+ civAllCmd=[civAllCmd ' fix1 '];
+ end
+ end
+
+ %PATCH1
+ if box_test(3)==1
+ if isequal(civAll,0)
+ cmd_PATCH=RUN_PATCH(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp);
+ cmd=char({cmd ;cmd_PATCH});
+ else
+ patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
+ patch1.nopt=subdomain_patch1;
+ patch1.maxdiff=thresh_patch1;
+ patch1.ro=rho_patch1;
+ test_grid=get(handles.get_gridpatch1,'Value');
+ if test_grid
+ patch1.gridflag='y';
+ gridname=get(handles.grid_patch1,'String');
+ if isequal(gridname(end-3:end),'grid')
+ nbslice_grid=str2num(gridname(1:end-4)); %
+ if ~isempty(nbslice_grid)
+ num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
+ patch1.gridPatch=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
+ if ~exist(patch1.gridPatch,'file')
+ msgbox_uvmat('ERROR','grid file absent for patch1')
+ end
+ elseif exist(gridname,'file')
+ patch1.gridPatch=gridname;
+ else
+ msgbox_uvmat('ERROR','grid file absent for patch1')
+ end
+ end
+ else
+ patch1.gridPatch='n';
+ patch1.gridflag='n';
+ patch1.m=nx_patch1;
+ patch1.n=ny_patch1;
+ end
+ patch1.convectFlow='n';
+ fieldnames=fields(patch1);
+ [civAllxml,uid_patch1]=add(civAllxml,1,'element','patch1');
+ for ilist=1:length(fieldnames)
+ val=eval(['patch1.' fieldnames{ilist}]);
+ if ischar(val)
+ [civAllxml,uid_t]=add(civAllxml,uid_patch1,'element',fieldnames{ilist});
+ [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+ end
+ end
+ civAllCmd=[civAllCmd ' patch1 '];
+ end
+ end
+
+ if box_test(4)==1 | box_test(5)==1 | box_test(6)==1
+ filename_cmx=filecell.nc.civ2{ifile,j};%output netcdf file
+ filename_cmx([end-1:end])=[ 'cm'];%name of cmx file
+ filename_cmx=[filename_cmx 'x'];
+ end
+
+ if box_test(4)==1
+ par_civ2.filename_ima_a=filecell.ima1.civ2{ifile,j};
+ %par_civ2.filename_ima_a([end-3:end])=[];%remove .png extension
+ par_civ2.filename_ima_b=filecell.ima2.civ2{ifile,j};
+ %par_civ2.filename_ima_b([end-3:end])=[];%remove .png extension
+ namelog=[filename_cmx([1:end-3]) 'log'];
+ par_civ2.Dt=num2str(time(num2_civ2(ifile),num_b_civ2(j))-time(num1_civ2(ifile),num_a_civ2(j)));
+ par_civ2.T0=num2str((time(num2_civ1(ifile),num_b_civ2(j))+time(num1_civ2(ifile),num_a_civ2(j)))/2);
+ par_civ2.term_a=num2stra(num_a_civ2(j),nom_type_nc);
+ par_civ2.term_b=num2stra(num_b_civ2(j),nom_type_nc);
+ par_civ2.filename_nc1=filecell.nc.civ1{ifile,j};
+ par_civ2.filename_nc1([end-2:end])=[]; % remove '.nc'
+ test_mask=get(handles.get_mask_civ2,'Value');
+ if test_mask==0
+ par_civ2.maskname='noFile use default';
+ par_civ2.maskflag='n';
+ else
+ maskdispl=get(handles.mask_civ2,'String');
+ maskbase=[filebase '_' maskdispl]; %
+ nbslice_mask=str2num(maskdispl(1:end-4)); %
+ num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
+ par_civ2.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
+ if exist(par_civ2.maskname,'file')
+ par_civ2.maskflag='y';
+ else
+ par_civ2.maskname='noFile use default';
+ par_civ2.maskflag='n';
+ end
+ end
+ %TESTgrid
+ test_grid=get(handles.browse_gridciv2,'Value');
+ gridname=get(handles.grid_civ2,'String');
+ gridflag='y';
+ if numel(gridname)>=4 && isequal(gridname(end-3:end),'grid')
+ nbslice_grid=str2num(gridname(1:end-4)); %
+ if ~isempty(nbslice_grid)
+ par_civ2.gridflag='y';
+ num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
+ par_civ2.gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
+ if exist(par_civ2.gridname,'file')
+ par_civ2.gridflag='y';
+ else
+ par_civ2.gridname='noFile use default';
+ par_civ2.gridflag='n';
+ end
+ elseif exist(gridname,'file')
+ par_civ2.gridflag='y';
+ else
+ par_civ2.gridname='noFile use default';
+ par_civ2.gridflag='n';
+ end
+ end
+ %endTESTgrid
+ i_cmd=i_cmd+1;
+ cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par_civ2);
+ if isequal(civAll,0)
+ if(isunix)
+ cmd=char({cmd ; ['cp -f ' filename_cmx '2 ' filename_cmx]; cmd_CIV2});
+ else
+ cmd=char({cmd ; ['copy /Y ' filename_cmx '2 ' filename_cmx]; cmd_CIV2});
+ end
+ else
+ civAllCmd=[civAllCmd ' civ2 '];
+ str=BATCH_CIV2_Unified(filename_cmx([1:end-4]),namelog,par_civ2);
+ fieldnames=fields(str);
+ [civAllxml,uid_civ2]=add(civAllxml,1,'element','civ2');
+ for ilist=1:length(fieldnames)
+ val=eval(['str.' fieldnames{ilist}]);
+ if ischar(val)
+ [civAllxml,uid_t]=add(civAllxml,uid_civ2,'element',fieldnames{ilist});
+ [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+ end
+ end
+ end
+ end
+
+ % FIX2
+ if box_test(5)==1
+ test_mask=get(handles.get_mask_fix2,'Value');
+ if test_mask==0
+ maskname=''; %no mask used
+ else
+ maskdispl=get(handles.mask_fix2,'String');
+ maskbase=[filebase '_' maskdispl]; %
+ nbslice_mask=str2num(maskdispl(1:end-4)); %
+ num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
+ maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
+ end
+ if isequal(civAll,0)
+ cmd_FIX=[fix_exe ' -f ' filecell.nc.civ2{ifile,j} ' -fi1 ' num2str(flagindex2(1)) ...
+ ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
+ ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName ' maskname];
+ cmd=char({cmd ;cmd_FIX});
+ else
+ fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
+ fix2.fi1=num2str(flagindex2(1));
+ fix2.fi2=num2str(flagindex2(2));
+ fix2.fi3=num2str(flagindex2(3));
+ fix2.threshC=num2str(thresh_vec2C);
+ fix2.threshV=num2str(thresh_vel2);
+ fieldnames=fields(fix2);
+ [civAllxml,uid_fix2]=add(civAllxml,1,'element','fix2');
+ for ilist=1:length(fieldnames)
+ val=eval(['fix2.' fieldnames{ilist}]);
+ if ischar(val)
+ [civAllxml,uid_t]=add(civAllxml,uid_fix2,'element',fieldnames{ilist});
+ [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+ end
+ end
+ civAllCmd=[civAllCmd ' fix2 '];
+ end
+ end
+
+ %PATCH2
+ if box_test(6)==1
+ if isequal(civAll,0)
+ cmd_PATCH=RUN_PATCH(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,test_interp);
+ cmd=char({cmd; cmd_PATCH});
+ else
+ patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
+ patch2.nopt=subdomain_patch1;
+ patch2.maxdiff=thresh_patch1;
+ patch2.ro=rho_patch1;
+ test_grid=get(handles.get_gridpatch2,'Value');
+ if test_grid
+ patch2.gridflag='y';
+ gridname=get(handles.grid_patch2,'String');
+ if isequal(gridname(end-3:end),'grid')
+ nbslice_grid=str2num(gridname(1:end-4)); %
+ if ~isempty(nbslice_grid)
+ num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
+ patch2.gridPatch=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
+ if ~exist(patch2.gridPatch,'file')
+ msgbox_uvmat('ERROR','grid file absent for patch2')
+ end
+ elseif exist(gridname,'file')
+ patch2.gridPatch=gridname;
+ else
+ msgbox_uvmat('ERROR','grid file absent for patch2')
+ end
+ end
+ else
+ patch2.gridPatch='n';
+ patch2.gridflag='n';
+ patch2.m=nx_patch2;
+ patch2.n=ny_patch2;
+ end
+ patch2.convectFlow='n';
+ fieldnames=fields(patch2);
+ [civAllxml,uid_patch2]=add(civAllxml,1,'element','patch2');
+ for ilist=1:length(fieldnames)
+ val=eval(['patch2.' fieldnames{ilist}]);
+ if ischar(val)
+ [civAllxml,uid_t]=add(civAllxml,uid_patch2,'element',fieldnames{ilist});
+ [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+ end
+ end
+ civAllCmd=[civAllCmd ' patch2 '];
+ end
+ end
+ if isequal(civAll,1)
+ civAllxml
+ save(civAllxml,[filename_cmx([1:end-4]) '.xml']);
+ cmd=char({cmd;[Civ_exe ' -f ' [filename_cmx([1:end-4]) '.xml'] ' ' civAllCmd]});
+ end
+
+ % create the .bat file:
+ if sge
+ [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
+ filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
+ else
+ filename_bat=filename_cmx;
+ end
+ filename_bat(end-2:end)='bat';
+
+ dlmwrite(filename_bat,cmd,'');%write commands in filename_bat
+ if sge
+ pvalue=num2str((1-ind_answer)*500);
+ namelog=[filename_bat '.patch.log'];
+ ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat];
+ eval( ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
+ else
+ if(isunix)
+ cmdtodo=['. ' filename_bat ];%removed for Mathieu tests %' && rm -f ' filename_bat] ;
+ else
+ cmdtodo=[filename_bat];%removed for Mathieu tests %' && del /F /Q ' filename_bat' ;
+ end
+ count= fprintf(p1,'%s\n', cmdtodo);
+ end
+ end
+end
+if ~sge
+ fclose(p1);
+ fclose(p0);
+ delete(name_lock);
+end
+
+set(handles.BATCH, 'Enable','On')
+set(handles.BATCH,'BackgroundColor',[1 0 0])
+
+%save interface state
+if isfield(filecell,'nc')
+ if isfield(filecell.nc,'civ2')
+ fileresu=filecell.nc.civ2{1,1};
+ else
+ fileresu=filecell.nc.civ1{1,1};
+ end
+end
+[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
+namedoc=fullfile(RootPath,subdir,RootFile);
+detect=1;
+while detect==1
+ namefigfull=[namedoc '.fig'];
+ hh=dir(namefigfull);
+ if ~isempty(hh)
+ detect=1;
+ namedoc=[namedoc '.0'];
+ else
+ detect=0;
+ end
+end
+saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER .xml)
+
+
+%----------------------------------------------------------
+%OUTPUT:
+% filecell: structure of input and output files
+% .ima1.civ1{i,j}, .ima1.civ2{i,j}; set of first image names for correlations, for civ1 and civ2
+% .ima2.civ1{i,j}, .ima2.civ2{i,j} ; set of second image names for correlations
+% .imaA1.civ1{i,j}, .ima1.civ2{i,j}; set of first image names for correlations, for civ1 and civ2, with camA in stereo case (then .ima1 corresponds to camB)
+% .imaA2.civ1{i,j}, .ima2.civ2{i,j} ; set of second image names for correlations, with camA in stereo case (then .ima1 corresponds to camB)
+% .nc.civ1{i,j}, .nc.civ2{i,j}; set of nc files for PIV results
+% .ncA.civ1{i,j}, .ncA.civ2{i,j}; set of nc files for PIV results with camA (then .nc corresponds to camB)
+% .st{i,j}; set of nc files for the combined stereo fields
+
+function [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
+ set_civ_filenames(handles,compare,box_test)
+
+%get the filename root, nomenclature and numbers
+filebase=get(handles.displ_filebase,'String');
+browse=get(handles.browse_root,'UserData');
+compare_list=get(handles.compare,'String');
+val=get(handles.compare,'Value');
+compare=compare_list{val};
+if strcmp(compare,'displacement')
+ mode='displacement';
+else
+ mode_list=get(handles.mode,'String');
+ mode_value=get(handles.mode,'Value');
+ mode=mode_list{mode_value};
+end
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+ext_ima=get(handles.ext_ima,'String');
+nom_type_nc=browse.nom_type_nc;
+nom_type_ima2=browse.nom_type_ima;
+if isequal(nom_type_ima2,[]),nom_type_ima2='ima_num';end; %default
+if isequal(nom_type_nc,[]),nom_type_nc='_i1-i2';end; %default
+[num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
+ find_pair_indices(handles,mode);
+
+%determine the new filebase for 'displacement' mode (comparison of two series)
+filebase_B=filebase;% root name of the second field series for stereo
+if strcmp(compare,'displacement') || strcmp(compare,'stereo PIV')
+ test_disp=1;
+ nom_type_ima1=browse.nom_type_ima_1; %nomenclature type of the second file series
+ [Path2,Name2]=fileparts(filebase_B);
+ Path1=Path2;
+ Name1=get(handles.displ_filebase2,'String');% root name of the first field series for stereo
+ filebase_A=fullfile(Path1,Name1);
+ if length(Name1)>6
+ Name1=Name1(end-5:end);
+ end
+ if length(Name2)>6
+ Name2=Name2(end-5:end);
+ end
+ filebase_AB=fullfile(Path2,[Name2 '-' Name1]);
+else
+ test_disp=0;
+ filebase_A=filebase;
+ nom_type_ima1=nom_type_ima2;
+ filebase_AB=filebase;
+end
+if strcmp(compare,'displacement')
+ filebase_ima1=filebase_A;
+ filebase_ima2=filebase_B;
+ filebase_nc=filebase_AB; %root name for the result of civ2
+else
+ filebase_ima1=filebase_B;
+ filebase_ima2=filebase_B;
+ filebase_nc=filebase_B;
+end
+
+%determine reference files for fix:
+file_ref_fix1={};%default
+file_ref_fix2={};
+nbfield=length(num1_civ1);
+nbslice=length(num_a_civ1);
+if box_test(2)==1% fix1 performed
+ ref=get(handles.ref_fix1,'UserData');%read data on the ref file stored by get_ref_fix1_Callback
+ if ~isempty(ref)
+ first_i=str2num(get(handles.first_i,'String'));
+ last_i=str2num(get(handles.last_i,'String'));
+ incr_i=str2num(get(handles.incr_i,'String'));
+ first_j=str2num(get(handles.first_j,'String'));
+ last_j=str2num(get(handles.last_j,'String'));
+ incr_j=str2num(get(handles.incr_j,'String'));
+ num_i_ref=[first_i:incr_i:last_i];
+ num_j_ref=[first_j:incr_j:last_j];
+ if isequal(mode,'displacement')
+ num_i1=num_i_ref;
+ num_i2=num_i_ref;
+ num_j1=num_j_ref;
+ num_j2=num_j_ref;
+ elseif isequal(mode,'pair j1-j2')% isequal(mode,'st_pair j1-j2')
+ num_i1=num_i_ref;
+ num_i2=num_i1;
+ num_j1=ref.num_a*ones(size(num_i_ref));
+ num_j2=ref.num_b*ones(size(num_i_ref));
+ elseif isequal(mode,'series(Di)') % isequal(mode,'st_series(Di)')
+ delta1=floor((ref.num2-ref.num1)/2);
+ delta2=ceil((ref.num2-ref.num1)/2);
+ num_i1=num_i_ref-delta1*ones(size(num_i_ref));
+ num_i2=num_i_ref+delta2*ones(size(num_i_ref));
+ if isempty(ref.num_a)
+ ref.num_a=1;
+ end
+ num_j1=ref.num_a*ones(size(num_i1));
+ num_j2=num_j1;
+ elseif isequal(mode,'series(Dj)')%| isequal(mode,'st_series(Dj)')
+ delta1=floor((ref.num_b-ref.num_a)/2);
+ delta2=ceil((ref.num_b-ref.num_a)/2);
+ num_i1=ref.num1*ones(size(num_i_ref));
+ num_i2=num_i1;
+ num_j1=num_j_ref-delta1*ones(size(num_j_ref));
+ num_j2=num_j_ref+delta2*ones(size(num_j_ref));
+ end
+ for ifile=1:nbfield
+ for j=1:nbslice
+ file_ref=name_generator(ref.filebase,num_i1(ifile),num_j1(j),'.nc',ref.nom_type,1,num_i2(ifile),num_j2(j),ref.subdir);%
+ file_ref_fix1(ifile,j)={file_ref};
+ if ~exist(file_ref,'file')
+ msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix1'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+ end
+ end
+ end
+end
+
+%determine reference files for fix2:
+if box_test(5)==1% fix2 performed
+ ref=get(handles.ref_fix2,'UserData');
+ if ~isempty(ref)
+ first_i=str2num(get(handles.first_i,'String'));
+ last_i=str2num(get(handles.last_i,'String'));
+ incr_i=str2num(get(handles.incr_i,'String'));
+ first_j=str2num(get(handles.first_j,'String'));
+ last_j=str2num(get(handles.last_j,'String'));
+ incr_j=str2num(get(handles.incr_j,'String'));
+ num_i_ref=[first_i:incr_i:last_i];
+ num_j_ref=[first_j:incr_j:last_j];
+ if isequal(mode,'displacement')
+ num_i1=num_i_ref;
+ num_i2=num_i_ref;
+ num_j1=num_j_ref;
+ num_j2=num_j_ref;
+ elseif isequal(mode,'pair j1-j2')
+ num_i1=num_i_ref;
+ num_i2=num_i1;
+ num_j1=ref.num_a;
+ num_j2=ref.num_b;
+ elseif isequal(mode,'series(Di)')
+ delta1=floor((ref.num2-ref.num1)/2);
+ delta2=ceil((ref.num2-ref.num1)/2);
+ num_i1=num_i_ref-delta1*ones(size(num_i_ref));
+ num_i2=num_i_ref+delta2*ones(size(num_i_ref));
+ num_j1=ref.num_a*ones(size(num_i1));
+ num_j2=num_j1;
+ elseif isequal(mode,'series(Dj)')
+ delta1=floor((ref.num_b-ref.num_a)/2);
+ delta2=ceil((ref.num_b-ref.num_a)/2);
+ num_i1=ref.num1*ones(size(num_i_ref));
+ num_i2=num_i1;
+ num_j1=num_j_ref-delta1*ones(size(num_j_ref));
+ num_j2=num_j_ref+delta2*ones(size(num_j_ref));
+ end
+ for ifile=1:nbfield
+ for j=1:nbslice
+ file_ref=name_generator(ref.filebase,num_i1(ifile),num_j1(j),'.nc',ref.nom_type,1,num_i2(ifile),num_j2(j),ref.subdir);%
+ file_ref_fix2(ifile,j)={file_ref};
+ if ~exist(file_ref,'file')
+ msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix2'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+ end
+ end
+ end
+end
+
+%check dir
+subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf output data
+subdir_civ2=get(handles.subdir_civ2,'String');
+if isequal(subdir_civ1,''),subdir_civ1='A'; end% put default subdir
+if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
+currentdir=pwd;%store the current working directory
+[Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ)
+if ~exist(Path_ima,'dir')
+ warndlg_uvmat(['path to images ' Path_ima ' not found'],'ERROR')
+ return
+end
+cd(Path_ima);%move to the directory of the images: needed to create the result dir by 'mkdir'
+dircur=pwd; %current working directory
+m2='';
+[erread,message]=fileattrib(Path_ima);
+if ~isempty(message) & ~isequal(message.UserWrite,1)
+ msgbox_uvmat('ERROR',['No writting access to ' Path_ima])
+ cd(currentdir);
+ return
+end
+
+%check the existence of the netcdf and image files involved
+% %%%%%%%%%%%% case CIV1 activated %%%%%%%%%%%%%
+if box_test(1)==1;
+ detect=1;
+ while detect==1 %create a new subdir if the netcdf files already exist
+ for ifile=1:nbfield;
+ for j=1:nbslice
+ filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);
+ detect=exist(filename,'file')==2;
+ if detect% if a netcdf file already exists
+ subdir_civ1=[subdir_civ1 '.0'];
+ subdir_civ2=subdir_civ1;
+ break
+ end
+ filecell.nc.civ1(ifile,j)={filename};
+ end
+ if detect% if a netcdf file already exists
+ break
+ end
+ end
+ %create the new subdir_civ1
+ if ~exist(fullfile(Path_ima,subdir_civ1),'dir')
+ [m1,m2,m3]=mkdir(subdir_civ1);
+ if ~isequal(m2,'')
+ msgbox_uvmat('ERROR', m2)
+ %msgbox(m2);%error message for directory creation
+ end
+ end
+ if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
+ detect=exist(filename,'file')==2;
+ if detect% if a netcdf file already exists
+ subdir_civ1=[subdir_civ1 '.0'];
+ subdir_civ2=subdir_civ1;
+ break
+ end
+ filecell.ncA.civ1(ifile,j)={filename};
+ end
+ if detect% if a netcdf file already exists
+ break
+ end
+ end
+ %create the new subdir_civ1
+ if ~exist(fullfile(Path_ima,subdir_civ1),'dir')
+ [m1,m2,m3]=mkdir(subdir_civ1);
+ if ~isequal(m2,'')
+ msgbox_uvmat('ERROR', m2)
+ end
+ end
+ end
+ end
+ % get image names
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_ima1, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
+ idetect(j)=exist(filename,'file')==2;
+ filecell.ima1.civ1(ifile,j)={filename}; %first image
+ filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
+ idetect_1(j)=exist(filename,'file')==2;
+ filecell.ima2.civ1(ifile,j)={filename};%second image
+ end
+ [idetectmin,indexj]=min(idetect);
+ if idetectmin==0,
+ msgbox_uvmat('ERROR',[filecell.ima1.civ1{ifile,indexj} ' not found'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ cd(currentdir)
+ return
+ end
+ [idetectmin,indexj]=min(idetect_1);
+ if idetectmin==0,
+ msgbox_uvmat('ERROR',[filecell.ima2.civ1{ifile,indexj} ' not found'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ cd(currentdir)
+ return
+ end
+ end
+ if strcmp(compare,'stereo PIV') && (strcmp(mode,'pair j1-j2') || strcmp(mode,'series(Dj)') || strcmp(mode,'series(Di)'))
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
+ idetect(j)=exist(filename,'file')==2;
+ filecell.imaA1.civ1(ifile,j)={filename} ;%first image
+ filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
+ idetect_1(j)=exist(filename,'file')==2;
+ filecell.imaA2.civ1(ifile,j)={filename};%second image
+ end
+ [idetectmin,indexj]=min(idetect);
+ if idetectmin==0,
+ msgbox_uvmat('ERROR',[filecell.imaA1.civ1{ifile,indexj} ' not found'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ cd(currentdir)
+ return
+ end
+ [idetectmin,indexj]=min(idetect_1);
+ if idetectmin==0,
+ msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ cd(currentdir)
+ return
+ end
+ end
+ end
+
+ %%%%%%%%%%%%% fix1 or patch1 activated but no civ1 %%%%%%%%%%%%%
+elseif (box_test(2)==1 || box_test(3)==1);
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
+ nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
+ detect=exist(filename,'file')==2;
+ filecell.nc.civ1(ifile,j)={filename};
+ end
+ end
+ if strcmp(compare,'stereo PIV')
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
+ filecell.ncA.civ1(ifile,j)={filename};
+ if ~exist(filename,'file')
+ msgbox_uvmat('ERROR',['input file ' filename ' not found'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ cd(currentdir)
+ return
+ end
+ end
+ end
+ end
+end
+
+%%%%%%%%%%%%% if civ2 performed with pairs different than civ1 %%%%%%%%%%%%%
+testdiff=0;
+if (box_test(4)==1)&&...
+ ((get(handles.list_pair_civ1,'Value')~=get(handles.list_pair_civ2,'Value'))||~isequal(subdir_civ2,subdir_civ1))
+ testdiff=1;
+ detect=1;
+ while detect==1 %create a new subdir if the netcdf files already exist
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
+ detect=exist(filename,'file')==2;
+ if detect% if a netcdf file already exists
+ subdir_civ2=[subdir_civ2 '.0'];
+ break
+ end
+ filecell.nc.civ2(ifile,j)={filename};
+ end
+ if detect% if a netcdf file already exists
+ break
+ end
+ end
+ %create the new subdir_civ2
+ if ~exist(fullfile(Path_ima,subdir_civ2),'dir')
+ [m1,m2,m3]=mkdir(subdir_civ2);
+ if ~isequal(m2,'')
+ msgbox_uvmat('ERROR', m2)
+ end
+ end
+ if strcmp(compare,'stereo PIV')%check second nc series
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
+ nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2);%
+ detect=exist(filename,'file')==2;
+ if detect% if a netcdf file already exists
+ subdir_civ2=[subdir_civ2 '.0'];
+ break
+ end
+ filecell.ncA.civ2(ifile,j)={filename};
+ end
+ if detect% if a netcdf file already exists
+ break
+ end
+ end
+ %create the new subdir_civ1
+ if ~exist(fullfile(Path_ima,subdir_civ2),'dir')
+ [m1,m2,m3]=mkdir(subdir_civ2);
+ if ~isequal(m2,'')
+ msgbox_uvmat('ERROR', m2)
+ %msgbox(m2);%error message for directory creation
+ end
+ end
+ end
+ end
+end
+cd(currentdir);%come back to the current working directory
+
+
+%%%%%%%%%%%%% if civ2 results are obtained or used %%%%%%%%%%%%%
+if box_test(4)==1 || box_test(5)==1 || box_test(6)==1 %civ2
+ %check source netcdf file of civ1 estimates
+ if box_test(1)==0; %no civ1 performed
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
+ nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
+ filecell.nc.civ1(ifile,j)={filename};% name of the civ1 file
+ if ~exist(filename,'file')
+ msgbox_uvmat('ERROR',['input file ' filename ' not found'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+ if ~testdiff % civ2 or patch2 are written in the same file as civ1
+ if box_test(4)==0 ; %check the existence of civ2 if it is not calculated
+ Data=nc2struct(filename,'ListGlobalAttribute','civ2');
+ if isempty(Data.civ2)||isequal(Data.civ2,0)
+ msgbox_uvmat('ERROR',['no civ2 data in ' filename])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+ elseif box_test(3)==0; %check the existence of patch if it is not calculated
+ Data=nc2struct(filename,'ListGlobalAttribute','patch');
+ if isempty(Data.patch)||isequal(Data.patch,0)
+ msgbox_uvmat('ERROR',['no patch data in ' filename])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+ end
+ end
+ end
+ end
+ if strcmp(compare,'stereo PIV')
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
+ nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
+ filecell.ncA.civ2(ifile,j)={filename};
+ if ~exist(filename,'file')
+ msgbox_uvmat('ERROR',['input file ' filename ' not found'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ cd(currentdir)
+ return
+ end
+ end
+ end
+ end
+ end
+
+ detect=1;
+% while detect==1%creates a new subdir if the netcdf files already contain civ2 data
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
+ nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);
+ detect=exist(filename,'file')==2;
+ filecell.nc.civ2(ifile,j)={filename};
+ end
+ end
+ %get first image names for civ2
+ if box_test(1)==1 & isequal(num1_civ1,num1_civ2) & isequal(num_a_civ1,num_a_civ2)
+ filecell.ima1.civ2=filecell.ima1.civ1;
+ elseif box_test(4)==1
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_ima1, num1_civ2(ifile),num_a_civ2(j),ext_ima,nom_type_ima1);
+ idetect_2(j)=exist(filename,'file')==2;
+ filecell.ima1.civ2(ifile,j)={filename};%first image
+ end
+ [idetectmin,indexj]=min(idetect_2);
+ if idetectmin==0,
+ msgbox_uvmat('ERROR',['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+ end
+ end
+
+ %get second image names for civ2
+ if box_test(1)==1 & isequal(num2_civ1,num2_civ2) & isequal(num_b_civ1,num_b_civ2)
+ filecell.ima2.civ2=filecell.ima2.civ1;
+ elseif box_test(4)==1
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),ext_ima,nom_type_ima2);
+ idetect_3(j)=exist(filename,'file')==2;
+ filecell.ima2.civ2(ifile,j)={filename};%first image
+ end
+ [idetectmin,indexj]=min(idetect_3);
+ if idetectmin==0,
+ msgbox_uvmat('ERROR',['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+ end
+ end
+end
+if (box_test(5)==1 || box_test(6)==1 ) && box_test(4)==0 % need to read an existing netcdf civ2 file
+ if ~testdiff
+ filecell.nc.civ2=filecell.nc.civ1;% file already checked
+ else % check the civ2 files
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
+ nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
+ filecell.nc.civ2(ifile,j)={filename};
+ if ~exist(filename,'file')
+ msgbox_uvmat('ERROR',['input file ' filename ' not found'])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ else
+ Data=nc2struct(filename,'ListGlobalAttribute','civ2');
+ if isempty(Data.civ2)||isequal(Data.civ2,0)
+ msgbox_uvmat('ERROR',['no civ2 data in ' filename])
+ set(handles.RUN, 'Enable','On')
+ set(handles.RUN,'BackgroundColor',[1 0 0])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+ end
+ end
+ end
+ end
+end
+
+%%%%%%%%%%%%% if stereo fields are calculated by PATCH %%%%%%%%%%%%%
+if strcmp(compare,'stereo PIV')
+ if box_test(3)==1 & isequal(get(handles.test_stereo1,'Value'),1)
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_AB,num1_civ1(ifile),num_a_civ1(j),'.nc',...
+ nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
+ filecell.st(ifile,j)={filename};
+ end
+ end
+ end
+ if box_test(6)==1 & isequal(get(handles.test_stereo2,'Value'),1)
+ for ifile=1:nbfield
+ for j=1:nbslice
+ filename=name_generator(filebase_AB,num1_civ2(ifile),num_a_civ2(j),'.nc',...
+ nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
+ filecell.st(ifile,j)={filename};
+ end
+ end
+ end
+end
+set(handles.subdir_civ1,'String',subdir_civ1);%update the edit box
+set(handles.subdir_civ2,'String',subdir_civ2);%update the edit box
+browse.nom_type_nc=nom_type_nc;
+set(handles.browse_root,'UserData',browse); %update the nomenclature type for uvmat
+
+
+%COPY IMAGES TO THE FORMAT .png IF NEEDED
+if isequal(nom_type_ima1,'*')
+ nom_type_imanew='_i';
+else
+ nom_type_imanew1=nom_type_ima1;
+end
+if isequal(nom_type_ima2,'*')
+ nom_type_imanew='_i';
+else
+ nom_type_imanew2=nom_type_ima2;
+end
+if ~isequal(ext_ima,'.png')
+ %npxy=get(handles.ext_ima,'UserData');
+% % if numel(npxy)<2
+%
+% filename=name_generator(filebase_ima1,num1_civ1(1),num_a_civ1(1),ext_ima,nom_type_ima1);
+% A=imread(filename);
+% npxy=size(A);
+% % end
+% npy=npxy(1);
+% npx=npxy(2);
+ if box_test(1)==1 %if civ1 is performed
+ h = waitbar(0,['copy images to the .png format for civ1']);% display a wait bar
+ for ifile=1:nbfield
+ waitbar(ifile/nbfield);
+ for j=1:nbslice
+ filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
+ if ~exist(filename,'file')
+ A=read_image(filecell.ima1.civ1{ifile,j},nom_type_ima2,num1_civ1(ifile));
+ imwrite(A,filename,'BitDepth',16);
+ end
+ filecell.ima1.civ1(ifile,j)={filename};
+ filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
+ if ~exist(filename,'file')
+ A=read_image(filecell.ima2.civ1{ifile,j},nom_type_ima2,num2_civ1(ifile));
+ imwrite(A,filename,'BitDepth',16);
+ end
+ filecell.ima2.civ1(ifile,j)={filename};
+ end
+ end
+ close(h)
+ end
+ if box_test(4)==1 %if civ2 is performed
+ h = waitbar(0,['copy images to the .png format for civ2']);% display a wait bar
+ for ifile=1:nbfield
+ waitbar(ifile/nbfield);
+ for j=1:nbslice
+ filename=name_generator(filebase_ima1,num1_civ2(ifile),num_a_civ2(j),'.png',nom_type_imanew1);
+ if ~exist(filename,'file')
+ A=read_image(cell2mat(filecell.ima1.civ2(ifile,j)),nom_type_ima2,num1_civ2(ifile));
+ imwrite(A,filename,'BitDepth',16);
+ end
+ filecell.ima1.civ2(ifile,j)={filename};
+ filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
+ if ~exist(filename,'file')
+ A=read_image(cell2mat(filecell.ima2.civ2(ifile,j)),nom_type_ima2,num2.civ1(ifile));
+ imwrite(A,filename,'BitDepth',16);
+ end
+ filecell.ima2.civ2(ifile,j)={filename};
+ end
+ end
+ close(h);
+ end
+end
+
+%---------------------------------------------------------
+%CIV1 CIV1 CIV1 CIV1
+%----------------------------------------------------------
+function RUN_CIV1(handles,filecell,filecell_1,filecell_nc1,num1,num2,num_a,num_b,nom_type_nc)
+%pixels per cm and matrix of the image times, read from the .civ file by uvmat
+global civ1_exe sge%name of the executable for civ1 calculation
+
+%get civ parameters
+ibx_val=str2num(get(handles.ibx,'String'));
+if isempty(ibx_val)
+ ibx='21'; set(handles.ibx,'String','21')
+else
+ ibx=num2str(ibx_val);
+end
+iby_val=str2num(get(handles.iby,'String'));
+if isempty(iby_val)
+ iby='21'; set(handles.iby,'String','21')
+else
+ iby=num2str(iby_val);
+end
+isx=get(handles.isx,'String');
+if isempty(str2num(isx)), isx='41'; set(handles.isx,'String','41'), end; %default
+if str2num(isx)4 && isequal(gridname(end-3:end),'grid')
+ nbslice_grid=str2num(gridname(1:end-4)); %
+ if ~isempty(nbslice_grid)
+ gridflag='y';
+ end
+ elseif exist(gridname,'file')
+ gridflag='y';
+ else
+ msgbox_uvmat('ERROR',['input grid file ' gridname ' not found'])
+ return
+ end
+end
+if isequal(get(handles.ImaThreshold,'Value'),1)
+ threshflag='y';
+ min_ima=get(handles.MinIma,'String');
+ max_ima=get(handles.MaxIma,'String');
+else
+ threshflag='n';
+ min_ima='0';
+ max_ima='4096';
+end
+ %main loop
+filebase=get(handles.displ_filebase,'String');
+sizcell=size(filecell);
+nbfield=sizcell(1);
+nbslice=sizcell(2);
+icount=0;
+for ifile=1:nbfield
+ for j=1:nbslice
+ icount=icount+1;
+ barlength=0.188*icount/(nbfield*nbslice);
+ set(handles.waitbar_1,'Position',[0.946 0.877-barlength 0.03 barlength])
+ drawnow
+ filename_ima=cell2mat(filecell(ifile,j));
+ filename_ima([end-3:end])=[];%remove .png extension
+ filename_ima_1=cell2mat(filecell_1(ifile,j));
+ filename_ima_1([end-3:end])=[];%remove .png extension
+ filename_cmx=cell2mat(filecell_nc1(ifile,j));%output netcdf file
+ filename_cmx([end-1:end])=[ 'cm'];%name of cmx file
+ filename_cmx=[filename_cmx 'x'];
+ namelog=[filename_cmx([1:end-3]) 'log'];
+ if size(time,1)>=num2(ifile) & size(time,2)>=num_b(j)
+ Dt=num2str(time(num2(ifile),num_b(j))-time(num1(ifile),num_a(j)));
+ if isequal(Dt,'0')
+ Dt='1' ;%case of 'displacement' mode
+ end
+ T0=num2str((time(num2(ifile),num_b(j))+time(num1(ifile),num_a(j)))/2);
+ else
+ Dt='1';
+ T0='0';
+ end
+ term_a=num2stra(num_a(j),nom_type_nc);%UTILITE?
+ term_b=num2stra(num_b(j),nom_type_nc);%
+ if test_grid && ~isempty(nbslice_grid)
+ num1_grid=mod(num1(ifile)-1,nbslice_grid)+1
+ gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
+ if ~exist(gridname,'file')
+ msgbox_uvmat('ERROR',['missing grid file ' gridname])
+ return
+ end
+ end
+ test_mask=get(handles.get_mask_civ1,'Value');
+ if test_mask==0
+ maskname='noFile use default';
+ maskflag='n';
+ else
+ maskdispl=get(handles.mask_civ1,'String');%look for mask name in edit box
+ maskbase=[filebase '_' maskdispl];%
+ nbslice=str2num(maskdispl(1:end-4)); %
+ num1_mask=mod(num1(ifile)-1,nbslice)+1;
+ maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
+ if exist(maskname,'file')
+ maskflag='y';
+ else
+ maskname='noFile use default';
+ maskflag='n';
+ end
+ end
+ textcmx={'############## CMX file';...
+ ['FirstImage ' filename_ima];...
+ ['LastImage ' filename_ima_1];...
+ 'XX' ;...
+ ['Mask ' maskflag] ;...
+ ['MaskName ' maskname];...
+ ['ImageSize ' npx ' ' npy];... %VERIFIER CAS GENERAL ?
+ ['CorrelationBoxesSize ' ibx ' ' iby];...
+ ['SearchBoxeSize ' isx ' ' isy];...
+ ['RO ' rho];...
+ ['GridSpacing ' dx ' ' dy];...
+ 'XX 1.0';...
+ ['Dt_TO ' Dt ' ' T0];...
+ ['PixCmXY ' pxcmx ' ' pxcmy];...
+ 'XX 1';...
+ ['ShiftXY ' shiftx ' ' shifty];...
+ ['Grid ' gridflag];...
+ ['GridName ' gridname] ;...
+ 'XX 85';...
+ 'XX 1.0';...
+ 'XX 1.0';...
+ 'Hart 1';...
+ 'DecimalShift 0';...
+ 'Deformation 0';...
+ 'CorrelationMin 0';...
+ 'IntensityMin 0';...
+ ['SeuilImage ' threshflag];...
+ ['SeuilImageValues ' min_ima ' ' max_ima];...
+ ['ImageToUse ' term_a ' ' term_b];... % VERIFIER ?
+ 'ImageUsedBefore null null'};
+ textout=char(textcmx);
+ dlmwrite(filename_cmx,textout,'');
+ s=-1;
+ display(['!' civ1_exe ' -f ' filename_cmx ' > ' namelog])
+ eval(['!' civ1_exe ' -f ' filename_cmx ' > ' namelog]);
+% if sge%dispatch computation on the cluster using interactive queue
+% % [s,w] = unix(['qrsh -q fast.q ' civ1_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1' ]);
+% end
+% if s~=0
+% % ['!' civ1_exe ' -f ' filename_cmx ' > ' namelog]
+% % eval(['!' civ1_exe ' -f ' filename_cmx ' > ' namelog]);
+% end
+ end
+end
+
+%---------------------------------------------------------------
+% RUN CIV2 CIV2 CIV2 CIV2
+%-----------------------------------------------------------
+function RUN_CIV2(handles,filecell_2,filecell_3,filecell_nc1,filecell_nc2,num1,num2,num_a,num_b,nom_type_nc)
+%filecell_2: names of first image
+%filecell_3: names of second images
+global civ2_exe sge
+
+%names of the civ2 fields
+field.vel_type='civ2';
+field.nb='nb_vectors2';
+field.X='vec2_X';
+field.Y='vec2_Y';
+field.U='vec2_U';
+field.V='vec2_V';
+
+%get civ parameters
+ibx=get(handles.ibx_civ2,'String');
+iby=get(handles.iby_civ2,'String');
+rho=get(handles.rho_civ2,'String');
+decimal=int2str(get(handles.decimal,'Value'));
+deformation=int2str(get(handles.deformation,'Value'));
+dx=get(handles.dx_civ2,'String');
+dy=get(handles.dy_civ2,'String');
+if isequal(str2num(dx),[])
+ dx='20';%default
+end
+if isequal(str2num(dy),[])
+ dy='20';%default
+end
+ pxcmx='1';%velocity fields are expressed in pixel displacement
+ pxcmy='1';
+A=imread(cell2mat(filecell_2(1,1)));%read the first image to get the size
+sizim=size(A);
+npx=num2str(sizim(2));
+npy=num2str(sizim(1));
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+filebase=get(handles.displ_filebase,'String');
+%grid
+gridname='';%default ='noFile use default'
+gridflag='n';%default
+test_grid=get(handles.browse_gridciv2,'Value');
+nbslice_grid=[];
+if test_grid
+ gridname=get(handles.grid_civ2,'String');
+ if numel(gridname)>4 && isequal(gridname(end-3:end),'grid')
+ nbslice_grid=str2num(gridname(1:end-4)); %
+ if ~isempty(nbslice_grid)
+ gridflag='y';
+ end
+ elseif exist(gridname,'file')
+ gridflag='y';
+ else
+ msgbox_uvmat('ERROR',['input grid file ' gridname ' not found'])
+ return
+ end
+end
+sizcell=size(filecell_2);
+nbfield=sizcell(1);
+nbslice=sizcell(2);
+
+%main loop
+icount=0;
+for ifile=1:nbfield
+ for j=1:nbslice
+ icount=icount+1;
+ barlength=0.188*icount/(nbfield*nbslice);
+ set(handles.waitbar_civ2,'Position',[0.946 0.407-barlength 0.03 barlength])
+ drawnow
+ filename_ima_2=cell2mat(filecell_2(ifile,j));
+ filename_ima_2([end-3:end])=[];%remove .png extension
+ filename_ima_3=cell2mat(filecell_3(ifile,j));
+ filename_ima_3([end-3:end])=[];%remove .png extension
+ filename_cmx=cell2mat(filecell_nc2(ifile,j));%output netcdf file
+ filename_cmx([end-1:end])=[ 'cm'];%name of cmx file
+ filename_cmx=[filename_cmx 'x'];
+ namelog=[filename_cmx([1:end-3]) 'log'];
+ if size(time,1)>=num2(ifile) & size(time,2)>=num_b(j)
+ Dt=num2str(time(num2(ifile),num_b(j))-time(num1(ifile),num_a(j)));
+ if isequal(Dt,'0')
+ Dt='1' ;%case of 'displacement' mode
+ end
+ T0=num2str((time(num2(ifile),num_b(j))+time(num1(ifile),num_a(j)))/2);
+ else
+ Dt='1';
+ T0='0';
+ end
+ term_a=num2stra(num_a(j),nom_type_nc);
+ term_b=num2stra(num_b(j),nom_type_nc);
+ filename_nc1=cell2mat(filecell_nc1(ifile,j));
+ filename_nc1([end-2:end])=[]; % remove '.nc'
+ if test_grid && ~isempty(nbslice_grid)
+ num1_grid=mod(num1(ifile)-1,nbslice_grid)+1
+ gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
+ if ~exist(gridname,'file')
+ msgbox_uvmat('ERROR',['missing grid file ' gridname])
+ return
+ end
+ end
+ test_mask=get(handles.get_mask_civ2,'Value');
+ if test_mask==0
+ maskname='noFile use default';
+ maskflag='n';
+ else
+ maskdispl=get(handles.mask_civ2,'String');
+ maskbase=[filebase '_' maskdispl]; %
+ nbslice_mask=str2num(maskdispl(1:end-4)); %
+ num1_mask=mod(num1(ifile)-1,nbslice_mask)+1;
+ maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
+ if ~exist(maskname,'file')
+ maskflag='y';
+ else
+ maskname='noFile use default';
+ maskflag='n';
+ end
+ end
+
+ textcmx={'############## CMX file';...
+ ['FirstImage ' filename_ima_2];...
+ ['LastImage ' filename_ima_3];...
+ 'XX' ;...
+ ['Mask ' maskflag];...
+ ['MaskName ' maskname];...
+ ['ImageSize ' npx ' ' npy];...
+ ['CorrelationBoxesSize ' ibx ' ' iby];...
+ ['SearchBoxeSize ' ibx ' ' iby];...
+ ['RO ' rho];...
+ ['GridSpacing ' dx ' ' dy];...
+ 'XX 1.0';...
+ ['Dt_TO ' Dt ' ' T0];...
+ ['PixCmXY ' pxcmx ' ' pxcmy];...
+ 'XX 1';...
+ ['ShiftXY 0 0'];...
+ ['Grid ' gridflag];...
+ ['GridName ' gridname];...
+ 'XX 85';...
+ 'XX 1.0';...
+ 'XX 1.0';...
+ 'Hart 1';...
+ ['DecimalShift ' decimal];...
+ ['Deformation ' deformation];...
+ 'CorrelationMin 0';...
+ 'IntensityMin 0';...
+ 'SeuilImage n';...
+ 'SeuilImageValues 0 4096';...
+ ['ImageToUse ' term_a ' ' term_b];... % VERIFIER ?
+ ['ImageUsedBefore ' filename_nc1]};
+ textout=char(textcmx);
+ dlmwrite(filename_cmx,textout,'');
+ s=-1;
+ display(['!' civ2_exe ' -f ' filename_cmx ' > ' namelog])
+ eval(['!' civ2_exe ' -f ' filename_cmx ' > ' namelog]);
+
+% if sge%dispatch computation on the cluster using interactive queue
+% [s,w] = unix(['qrsh -q fast.q ' civ2_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']);
+% end
+% if s~=0
+% eval(['!' civ2_exe ' -f ' filename_cmx ' > ' namelog]);
+% ['!' civ2_exe ' -f ' filename_cmx ' > ' namelog]
+% end
+ end
+end
+% close(h)
+
+
+%----------------------------------------
+%PATCH
+%---------------------------------------
+function cmd_PATCH=RUN_PATCH(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp)
+global patch_exe patch_new_exe
+ namelog=[filename_nc([1:end-3]) '_patch.log'];
+ if test_interp==0
+ cmd_PATCH=[patch_exe ' -f ' filename_nc ' -m ' nx_patch ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
+ ' > ' namelog ' 2>&1']; % redirect standard output to the log file
+ else %nouveau programme patch
+ cmd_PATCH=[patch_new_exe ' -f ' filename_nc ' -m ' nx_patch ' -n ' ny_patch ' -ro ' rho_patch ...
+ ' -max ' thresh_value ' -nopt ' subdomain_patch ' > ' namelog ' 2>&1']; % redirect standard output to the log file
+ end
+
+%----------------------------------------
+%STEREO Interp
+%---------------------------------------
+function cmd=RUN_STINTERP(stinterp_exe,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
+namelog=[filename_nc([1:end-3]) '_stinterp.log'];
+cmd=[stinterp_exe ' -f1 ' filename_A_nc ' -f2 ' filename_B_nc ' -f ' filename_nc ...
+ ' -m ' nx_patch ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ' -c1 ' xmlA ' -c2 ' xmlB ' -xy x -Nfy 1024 > ' namelog ' 2>&1']; % redirect standard output to the log file
+
+%----------------------------------------------------
+function first_j_Callback(hObject, eventdata, handles)
+last_j_Callback(hObject, eventdata, handles)
+
+%---------------------------------------------------------
+% --- Executes on button press in CIV1.
+function CIV1_Callback(hObject, eventdata, handles)
+val=get(handles.CIV1,'Value');
+if isequal(val,1)
+ enable_civ1(handles,'on')
+ enable_pair1(handles,'on')
+else
+ enable_civ1(handles,'off')
+end
+find_netcpair_civ1(hObject, eventdata, handles);
+
+%------------------------------------------------------
+% --- Executes on button press in FIX1.
+function FIX1_Callback(hObject, eventdata, handles)
+
+enable_fix1(handles,get(handles.FIX1,'Value'))
+
+
+%----------------------------------------------------------------
+% --- Executes on button press in PATCH1.
+function PATCH1_Callback(hObject, eventdata, handles)
+
+if get(handles.PATCH1,'Value')==1
+enable_patch1(handles)
+else
+desable_patch1(handles)
+end
+
+%----------------------------------------------------------
+% --- Executes on button press in CIV2.
+function CIV2_Callback(hObject, eventdata, handles)
+state=get(handles.CIV2,'Value');
+enable_civ2(handles,state)
+if state
+ find_netcpair_civ2(hObject, eventdata, handles)
+ enable_pair1(handles,'on')
+end
+
+%---------------------------------------------------
+% --- Executes on button press in FIX2.
+function FIX2_Callback(hObject, eventdata, handles)
+if get(handles.FIX2,'Value')==1
+ enable_fix2(handles)
+ if get(handles.CIV2,'Value')==0
+ find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
+ end
+else
+ desable_fix2(handles)
+end
+
+
+%-------------------------------------------------------
+% --- Executes on button press in PATCH2.
+function PATCH2_Callback(hObject, eventdata, handles)
+%--------------------------------------------------------
+if get(handles.PATCH2,'Value')==1
+ enable_patch2(handles)
+ if get(handles.CIV2,'Value')==0
+ find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
+ end
+else
+ desable_patch2(handles)
+end
+
+
+
+%-----------------------------------------------------------
+function first_i_Callback(hObject, eventdata, handles)
+%------------------------------------------------------
+last_i_Callback(hObject, eventdata, handles)
+
+%-----------------------------------------------------------
+% --- Executes on button press in calcul_search: determine the search range isx,isy
+%--------------------------------------------------------
+function calcul_search_Callback(hObject, eventdata, handles)
+
+%determine pair numbers
+list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
+index=get(handles.list_pair_civ1,'Value');
+displ_num=get(handles.list_pair_civ1,'UserData');
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+pxcm_xy=get(handles.calcul_search,'UserData');
+pxcmx=pxcm_xy(1);
+pxcmy=pxcm_xy(2);
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+if isequal (mode, 'series(Di)' )
+ ref_i=str2num(get(handles.ref_i,'String'));
+ num1=ref_i-floor(index/2);% first image numbers
+ num2=ref_i+ceil(index/2);
+ num_a=1;
+ num_b=1;
+elseif isequal (mode, 'series(Dj)')
+ num1=1;
+ num2=1;
+ ref_j=str2num(get(handles.ref_j,'String'));
+ num_a=ref_j-floor(index/2);% first image numbers
+ num_b=ref_j+ceil(index/2);
+elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
+ ref_i=str2num(get(handles.ref_i,'String'));
+ num1=ref_i;
+ num2=ref_i;
+ num_a=displ_num(1,index);
+ num_b=displ_num(2,index);
+end
+dt=time(num2,num_b)-time(num1,num_a);
+ibx=str2num(get(handles.ibx,'String'));
+iby=str2num(get(handles.iby,'String'));
+umin=dt*pxcmx*str2num(get(handles.umin,'String'));
+umax=dt*pxcmx*str2num(get(handles.umax,'String'));
+vmin=dt*pxcmy*str2num(get(handles.vmin,'String'));
+vmax=dt*pxcmy*str2num(get(handles.vmax,'String'));
+shiftx=round((umin+umax)/2);
+shifty=round((vmin+vmax)/2);
+isx=(umax+2-shiftx)*2+ibx;
+isx=2*ceil(isx/2)+1;
+isy=(vmax+2-shifty)*2+iby;
+isy=2*ceil(isy/2)+1;
+set(handles.shiftx,'String',num2str(shiftx));
+set(handles.shifty,'String',num2str(shifty));
+set(handles.isx,'String',num2str(isx));
+set(handles.isy,'String',num2str(isy));
+
+
+%---------------------------------------------------------
+% Executes on carriage return on the subdir civ1 edit window
+%--------------------------------------------------------
+function subdir_civ1_Callback(hObject, eventdata, handles)
+subdir=get(handles.subdir_civ1,'String');
+set(handles.subdir_civ2,'String',subdir);
+if get(handles.CIV1,'Value')==0
+ find_netcpair_civ1(hObject, eventdata, handles); %update the list of available pairs from netcdf files in the new directory
+end
+
+%---------------------------------------------------------
+% Executes on carriage return on the subdir civ1 edit window
+%---------------------------------------------------------
+function subdir_civ2_Callback(hObject, eventdata, handles)
+%update the list of available pairs from netcdf files in the new directory
+if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
+ find_netcpair_civ2(hObject, eventdata, handles);
+end
+
+%------------------------------------------------------
+% --- Executes on button press in get_mask_civ1.
+%------------------------------------------------------
+function get_mask_civ1_Callback(hObject, eventdata, handles)
+maskval=get(handles.get_mask_civ1,'Value');
+if isequal(maskval,0)
+ set(handles.mask_civ1,'String','')
+else
+ mask_displ='no mask'; %default
+ filebase=get(handles.displ_filebase,'String');
+ [ nbslice_mask, flag_mask]=get_mask(filebase,handles);
+ if isequal(flag_mask,1)
+ mask_displ=[num2str(nbslice_mask) 'mask'];
+ elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
+ common_path=fileparts(filebase);
+ filebase_a=fullfile(common_path,get(handles.displ_filebase2,'String'));
+ [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
+ if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice_mask)
+ mask_displ='no mask';
+ end
+ end
+ if isequal(mask_displ,'no mask')
+ set(handles.get_mask_civ1,'Value',0)
+ set(handles.get_mask_fix1,'Value',0)
+ set(handles.get_mask_civ2,'Value',0)
+ set(handles.get_mask_fix2,'Value',0)
+ else
+ set(handles.get_mask_fix1,'Value',1)
+ set(handles.get_mask_fix2,'Value',1)
+ end
+ set(handles.mask_civ1,'String',mask_displ)
+ set(handles.mask_fix1,'String',mask_displ)
+ set(handles.mask_civ2,'String',mask_displ)
+ set(handles.mask_fix2,'String',mask_displ)
+end
+
+%--------------------------------------------------------------
+% --- Executes on button press in get_mask_fix1.
+function get_mask_fix1_Callback(hObject, eventdata, handles)
+maskval=get(handles.get_mask_fix1,'Value');
+if isequal(maskval,0)
+ set(handles.mask_fix1,'String','')
+else
+mask_displ='no mask'; %default
+filebase=get(handles.displ_filebase,'String');
+[nbslice, flag_mask]=get_mask(filebase,handles);
+if isequal(flag_mask,1)
+ mask_displ=[num2str(nbslice) 'mask'];
+elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
+ filebase_a=get(handles.displ_filebase2,'String');
+ [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
+ if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
+ mask_displ='no mask';
+ end
+end
+if isequal(mask_displ,'no mask')
+ set(handles.get_mask_fix1,'Value',0)
+ set(handles.get_mask_civ2,'Value',0)
+ set(handles.get_mask_fix2,'Value',0)
+else
+ %set(handles.get_mask_civ2,'Value',1)
+ set(handles.get_mask_fix2,'Value',1)
+end
+set(handles.mask_fix1,'String',mask_displ)
+set(handles.mask_civ2,'String',mask_displ)
+set(handles.mask_fix2,'String',mask_displ)
+end
+%-----------------------------------------
+% --- Executes on button press in get_mask_civ2.
+function get_mask_civ2_Callback(hObject, eventdata, handles)
+maskval=get(handles.get_mask_civ2,'Value');
+if isequal(maskval,0)
+ set(handles.mask_civ2,'String','')
+else
+mask_displ='no mask'; %default
+filebase=get(handles.displ_filebase,'String');
+[nbslice, flag_mask]=get_mask(filebase,handles);
+if isequal(flag_mask,1)
+ mask_displ=[num2str(nbslice) 'mask'];
+elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
+ filebase_a=get(handles.displ_filebase2,'String');
+ [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
+ if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
+ mask_displ='no mask';
+ end
+end
+if isequal(mask_displ,'no mask')
+ set(handles.get_mask_civ2,'Value',0)
+ set(handles.get_mask_fix2,'Value',0)
+else
+ set(handles.get_mask_fix2,'Value',1)
+end
+set(handles.mask_civ2,'String',mask_displ)
+set(handles.mask_fix2,'String',mask_displ)
+end
+%-------------------------------------
+% --- Executes on button press in get_mask_fix2.
+function get_mask_fix2_Callback(hObject, eventdata, handles)
+maskval=get(handles.get_mask_fix2,'Value');
+if isequal(maskval,0)
+ set(handles.mask_fix2,'String','')
+else
+mask_displ='no mask'; %default
+filebase=get(handles.displ_filebase,'String');
+[nbslice, flag_mask]=get_mask(filebase,handles);
+if isequal(flag_mask,1)
+ mask_displ=[num2str(nbslice) 'mask'];
+elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
+ filebase_a=get(handles.displ_filebase2,'String');
+ [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
+ if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
+ mask_displ='no mask';
+ end
+end
+if isequal(mask_displ,'no mask')
+ set(handles.get_mask_fix2,'Value',0)
+end
+set(handles.mask_fix2,'String',mask_displ)
+end
+
+%---------------------------------------
+function [nbslice, flag_mask]=get_mask(filebase,handles)
+%detect mask files, images with appropriate file base
+%[filebase '_' xx 'mask'], xx=nbslice
+%flag_mask=1 indicates detection
+
+flag_mask=0;%default
+nbslice=1;
+
+% subdir=get(handles.subdir_civ1,'String');
+[Path,Name]=fileparts(filebase);
+currentdir=pwd;
+cd(Path);%move in the dir of the root name filebase
+maskfiles=dir([Name '_*mask_*.png']);%look for mask files
+cd(currentdir);%come back to the current working directory
+if isempty(maskfiles)
+ msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
+else
+ flag_mask=1;
+ maskname=maskfiles(1).name;% take the first mask file in the list
+ [Path2,Name,ext]=fileparts(maskname);
+ Namedouble=double(Name);
+ val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
+ ind_mask=findstr('mask',Name);
+ i=ind_mask-1;
+ while val(i)==0 & i>0
+ i=i-1;
+ end
+ nbslice=str2num(Name(i+1:ind_mask-1));
+ if ~isequal(nbslice,[]) & Name(i)=='_'
+ flag_mask=1;
+ else
+ msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
+ return
+ nbslice=1;
+ end
+end
+
+%---------------------------------------
+function [nbslice, flag_mask]=get_grid(filebase,handles)
+
+flag_mask=0;%default
+nbslice=1;
+[Path,Name]=fileparts(filebase);
+currentdir=pwd;
+cd(Path);%move in the dir of the root name filebase
+maskfiles=dir([Name '_*grid_*.grid']);%look for mask files
+cd(currentdir);%come back to the current working directory
+if ~isempty(maskfiles)
+ flag_mask=1;
+ maskname=maskfiles(1).name;% take the first mask file in the list
+ [Path2,Name,ext]=fileparts(maskname);
+ Namedouble=double(Name);
+ val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
+ ind_mask=findstr('grid',Name);
+ i=ind_mask-1;
+ while val(i)==0 & i>0
+ i=i-1;
+ end
+ nbslice=str2num(Name(i+1:ind_mask-1));
+ if ~isequal(nbslice,[]) & Name(i)=='_'
+ flag_mask=1;
+ else
+ msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
+ return
+ nbslice=1;
+ end
+end
+%------------------------------
+
+function grid_civ1_Callback(hObject, eventdata, handles)
+% hObject handle to grid_civ1 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of grid_civ1 as text
+% str2double(get(hObject,'String')) returns contents of grid_civ1 as a double
+
+
+%-----------------------------------------------------------
+% transform numbers to letters
+%--------------------------------------------
+function str=num2stra(num,nom_type);
+if isequal(nom_type,'png_old') | isequal(nom_type,'netc_old') |isequal(nom_type,'raw_SMD')
+ str=char(96+num);
+elseif isequal(nom_type,'_i')|isequal(nom_type,'_i1-i2')...
+ |isequal(nom_type,'ima_num')| isequal(nom_type,'avi')| isequal(nom_type,'none')
+ str='';
+else
+ str=num2str(num);
+end
+%---------------------------------------------------
+function mask_civ1_Callback(hObject, eventdata, handles)
+set(handles.mask_civ1,'UserData',[])
+set(handles.mask_civ1,'String','')
+%----------------------------------------------------
+function mask_civ2_Callback(hObject, eventdata, handles)
+set(handles.mask_civ2,'UserData',[])
+set(handles.mask_civ2,'String','')
+%----------------------------------------------------
+function mask_fix1_Callback(hObject, eventdata, handles)
+set(handles.mask_fix1,'UserData',[])
+set(handles.mask_fix1,'String','')
+%----------------------------------------------------
+function mask_fix2_Callback(hObject, eventdata, handles)
+set(handles.mask_fix2,'UserData',[])
+set(handles.mask_fix2,'String','')
+
+%--------------------------------------------------------------------------
+% --- Executes on button press in list_subdir_civ1.
+function list_subdir_civ1_Callback(hObject, eventdata, handles)
+list_subdir_civ1=get(handles.list_subdir_civ1,'String');
+val=get(handles.list_subdir_civ1,'Value');
+if val>1
+ subdir=list_subdir_civ1{val};
+ set(handles.subdir_civ1,'String',subdir);
+ set(handles.list_subdir_civ1,'Value',1);
+end
+
+
+%--------------------------------------------------------------------------
+% --- Executes on button press in list_subdir_civ2.
+function list_subdir_civ2_Callback(hObject, eventdata, handles)
+list_subdir_civ2=get(handles.list_subdir_civ2,'String');
+val=get(handles.list_subdir_civ2,'Value');
+if val>1
+ subdir=list_subdir_civ2{val};
+ set(handles.subdir_civ2,'String',subdir);
+ set(handles.list_subdir_civ2,'Value',1);
+end
+
+
+%----------------------------------------------
+function last_i_Callback(hObject, eventdata, handles)
+first_i=str2num(get(handles.first_i,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+ref_i=ceil((first_i+last_i)/2);
+set(handles.ref_i,'String', num2str(ref_i))
+ref_i_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------
+function last_j_Callback(hObject, eventdata, handles)
+first_j=str2num(get(handles.first_j,'String'));
+last_j=str2num(get(handles.last_j,'String'));
+ref_j=ceil((first_j+last_j)/2);
+set(handles.ref_j,'String', num2str(ref_j))
+ref_j_Callback(hObject, eventdata, handles)
+
+
+%-----------------------------------------------------------
+% --- Executes on button press in browse_gridciv1.
+function browse_gridciv1_Callback(hObject, eventdata, handles)
+%-----------------------------------------------------------
+value=get(handles.browse_gridciv1,'Value');
+testgrid=0;
+if value
+ filebase=get(handles.displ_filebase,'String');
+ [nbslice, flag_grid]=get_grid(filebase,handles)
+ if isequal(flag_grid,1)
+ filegrid=[num2str(nbslice) 'grid'];
+ testgrid=1;
+ else
+ [FileName, PathName, filterindex] = uigetfile( ...
+ {'*.grid', ' (*.grid)';
+ '*.grid', '.grid files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',filebase);
+ filegrid=fullfile(PathName,FileName);
+ if ~(isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file'))
+ testgrid=1;
+ end
+ end
+end
+if testgrid
+ set(handles.browse_gridciv2,'Value',1)
+ set(handles.get_gridpatch1,'Value',1)
+ set(handles.get_gridpatch2,'Value',1)
+ set(handles.dx_civ1,'Visible','off');
+ set(handles.dy_civ1,'Visible','off');
+ set(handles.dx_civ2,'Visible','off');
+ set(handles.dy_civ2,'Visible','off');
+ set(handles.grid_civ1,'String',filegrid)
+ set(handles.grid_patch1,'String',filegrid)
+ set(handles.grid_civ2,'String',filegrid)
+ set(handles.grid_patch2,'String',filegrid)
+ else
+ set(handles.browse_gridciv1,'Value',0);
+ set(handles.browse_gridciv2,'Value',0);
+ set(handles.get_gridpatch1,'Value',0)
+ set(handles.get_gridpatch2,'Value',0)
+ set(handles.dx_civ1,'Visible','on');
+ set(handles.dy_civ1,'Visible','on');
+ set(handles.dx_civ2,'Visible','on');
+ set(handles.dy_civ2,'Visible','on');
+ set(handles.grid_civ1,'String','')
+ set(handles.grid_patch1,'String','')
+ set(handles.grid_civ2,'String','')
+ set(handles.grid_patch2,'String','')
+end
+
+%-----------------------------------------------------------
+% --- Executes on button press in browse_gridciv1.
+function browse_gridciv2_Callback(hObject, eventdata, handles)
+%-----------------------------------------------------------
+value=get(handles.browse_gridciv2,'Value');
+if value
+ filebase=get(handles.displ_filebase,'String');
+ [nbslice, flag_grid]=get_grid(filebase,handles)
+ if isequal(flag_grid,1)
+ mask_displ=[num2str(nbslice) 'grid'];
+ set(handles.grid_civ2,'String',mask_displ)
+ set(handles.dx_civ2,'Visible','off');
+ set(handles.dy_civ2,'Visible','off');
+ else
+ [FileName, PathName, filterindex] = uigetfile( ...
+ {'*.grid', ' (*.grid)';
+ '*.grid', '.grid files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',filebase);
+ filegrid=fullfile(PathName,FileName);
+ if isempty(FileName)|isempty(PathName)|isequal(FileName,0)|~exist(filegrid,'file')
+ set(handles.browse_gridciv2,'Value',0);
+ set(handles.grid_civ2,'string','');
+ set(handles.dx_civ2,'Visible','on');
+ set(handles.dy_civ2,'Visible','on');
+ set(handles.grid_civ2,'string','');
+ else
+ set(handles.grid_civ2,'string',filegrid);
+ set(handles.dx_civ2,'Visible','off');
+ set(handles.dy_civ2,'Visible','off');
+ set(handles.grid_civ2,'string',filegrid);
+ end
+ end
+else
+ set(handles.grid_civ2,'string','');
+ set(handles.dx_civ2,'Visible','on');
+ set(handles.dy_civ2,'Visible','on');
+ set(handles.grid_civ2,'string','');
+end
+
+% % --- Executes on button press in browse_gridciv2.
+% function browse_gridciv2_Callback(hObject, eventdata, handles)
+%
+% filebase=get(handles.displ_filebase,'String');
+% [FileName, PathName, filterindex] = uigetfile( ...
+% {'*.grid', ' (*.grid)';
+% '*.grid', '.grid files '; ...
+% '*.*', 'All Files (*.*)'}, ...
+% 'Pick a file',filebase);
+% filegrid=fullfile(PathName,FileName);
+% set(handles.grid_civ2,'string',filegrid);
+% set(handles.dx_civ2,'String',' ');
+% set(handles.dy_civ2,'String',' ');
+% % set(handles.grid_patch2,'string',filegrid);
+
+% --- Executes on button press in get_gridpatch1.
+function get_gridpatch1_Callback(hObject, eventdata, handles)
+% hObject handle to get_gridpatch1 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+filebase=get(handles.displ_filebase,'String');
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.grid', ' (*.grid)';
+ '*.grid', '.grid files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',filebase);
+filegrid=fullfile(PathName,FileName);
+set(handles.grid_patch1,'string',filegrid);
+% set(handles.grid_patch2,'string',filegrid
+
+%-----------------------------------------------------------------
+% --- Executes on button press in get_gridpatch2.
+function get_gridpatch2_Callback(hObject, eventdata, handles)
+
+
+%----------------------------------------------------------
+function enable_civ1(handles,state)
+if isequal(state,0)
+ state='off';
+end
+if isequal(state,1)
+ state='on';
+end
+if isequal(state,'on')
+ set(handles.frame_civ1,'BackgroundColor',[1 1 0])
+ set(handles.frame_para_civ1,'BackgroundColor',[1 1 0])
+ set(handles.frame_grid_civ1,'BackgroundColor',[1 1 0])
+else
+ set(handles.frame_civ1,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.frame_para_civ1,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.frame_grid_civ1,'BackgroundColor',[0.831 0.816 0.784])
+end
+set(handles.ibx,'Visible',state)
+set(handles.iby,'Visible',state)
+set(handles.isx,'Visible',state)
+set(handles.isy,'Visible',state)
+set(handles.shiftx,'Visible',state)
+set(handles.shifty,'Visible',state)
+set(handles.rho,'Visible',state)
+set(handles.dx_civ1,'Visible',state)
+set(handles.dy_civ1,'Visible',state)
+set(handles.calcul_search,'Visible',state)
+set(handles.u_text,'Visible',state)
+set(handles.v_text,'Visible',state)
+set(handles.min,'Visible',state)
+set(handles.max,'Visible',state)
+set(handles.umin,'Visible',state)
+set(handles.umax,'Visible',state)
+set(handles.vmin,'Visible',state)
+set(handles.vmax,'Visible',state)
+set(handles.grid_civ1,'Visible',state)
+set(handles.mask_civ1,'Visible',state)
+set(handles.browse_gridciv1,'Visible',state)
+set(handles.get_mask_civ1,'Visible',state)
+set(handles.parameters,'Visible',state)
+set(handles.grid,'Visible',state)
+set(handles.dx_civ1,'Visible',state)
+set(handles.dy_civ1,'Visible',state)
+set(handles.ImaThreshold,'Visible',state)
+if isequal(state,'off')
+ set(handles.MinIma,'Visible','off')
+ set(handles.MaxIma,'Visible','off')
+ set(handles.ImaThreshold,'Value',0)
+end
+set(handles.dx_civ1_title,'Visible',state)
+set(handles.dy_civ1_title,'Visible',state)
+set(handles.ImaThreshold_title,'Visible',state)
+set(handles.ib_title,'Visible',state)
+set(handles.is_title,'Visible',state)
+set(handles.shift_title,'Visible',state)
+set(handles.rho_title,'Visible',state)
+
+%----------------------------------------------------------
+function enable_fix1(handles,state)
+if isequal(state,0)
+ state='off';
+end
+if isequal(state,1)
+ state='on';
+end
+if isequal(state,'on')
+ set(handles.frame_fix1,'BackgroundColor',[1 1 0])
+else
+ set(handles.frame_fix1,'BackgroundColor',[0.7 0.7 0.7])
+end
+set(handles.REMOVE,'Visible',state)
+set(handles.vec_Fmin2,'Visible',state)
+set(handles.vec_F2,'Visible',state)
+set(handles.vec_F3,'Visible',state)
+set(handles.thresh_vecC,'Visible',state)
+set(handles.thresh_vecC_title,'Visible',state)
+set(handles.thresh_vel,'Visible',state)
+set(handles.thresh_vel_text,'Visible',state)
+set(handles.mask_fix1,'Visible',state)
+set(handles.get_mask_fix1,'Visible',state)
+set(handles.get_ref_fix1,'Visible',state)
+set(handles.ref_fix1,'Visible',state)
+set(handles.inf_sup1,'Visible',state)
+set(handles.field_ref1,'Visible',state)
+
+
+%--------------------------------------------------------------
+function enable_patch1(handles)
+global patch_new_exe
+set(handles.frame_patch1,'BackgroundColor',[1 1 0])
+set(handles.rho_patch1,'Visible','on')
+set(handles.rho_text1,'Visible','on')
+set(handles.thresh_patch1,'Visible','on')
+set(handles.thresh_text1,'Visible','on')
+set(handles.subdomain_patch1,'Visible','on')
+set(handles.subdomain_text1,'Visible','on')
+set(handles.nx_patch1,'Visible','on')
+set(handles.ny_patch1,'Visible','on')
+set(handles.nx_patch1_title,'Visible','on')
+set(handles.ny_patch1_title,'Visible','on')
+if (~isequal(patch_new_exe,[]) & ~isequal(patch_new_exe,[]))
+ set(handles.test_interp,'Visible','on');
+end
+set(handles.get_gridpatch1,'Visible','on')
+set(handles.grid_patch1,'string','none');
+set(handles.grid_patch1,'Visible','on')
+
+%--------------------------------------------------------------
+function desable_patch1(handles)
+set(handles.frame_patch1,'BackgroundColor',[0.831 0.816 0.784])
+set(handles.rho_patch1,'Visible','off')
+set(handles.rho_text1,'Visible','off')
+set(handles.thresh_patch1,'Visible','off')
+set(handles.thresh_text1,'Visible','off')
+set(handles.subdomain_patch1,'Visible','off')
+set(handles.subdomain_text1,'Visible','off')
+set(handles.nx_patch1,'Visible','off')
+set(handles.ny_patch1,'Visible','off')
+set(handles.nx_patch1_title,'Visible','off')
+set(handles.ny_patch1_title,'Visible','off')
+set(handles.test_interp,'Visible','off')
+set(handles.get_gridpatch1,'Visible','off')
+set(handles.grid_patch1,'Visible','off')
+
+%----------------------------------------------------------
+function enable_civ2(handles,state)
+if isequal(state,0)
+ state='off';
+end
+if isequal(state,1)
+ state='on';
+end
+if isequal(state,'on')
+ set(handles.frame_civ2,'BackgroundColor',[1 1 0])
+ set(handles.frame_para_civ2,'BackgroundColor',[1 1 0])
+ set(handles.frame_grid_civ2,'BackgroundColor',[1 1 0])
+ set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
+else
+ set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
+end
+set(handles.ibx_civ2,'Visible',state)
+set(handles.iby_civ2,'Visible',state)
+set(handles.decimal,'Visible',state)
+set(handles.deformation,'Visible',state)
+set(handles.rho_civ2,'Visible',state)
+set(handles.dx_civ2,'Visible',state)
+set(handles.dy_civ2,'Visible',state)
+set(handles.browse_gridciv2,'Visible',state)
+set(handles.get_mask_civ2,'Visible',state)
+set(handles.parameters,'Visible',state)
+set(handles.grid,'Visible',state)
+set(handles.parameters_text,'Visible',state)
+set(handles.grid_text,'Visible',state)
+set(handles.grid_civ2,'Visible',state)
+set(handles.mask_civ2,'Visible',state)
+set(handles.dx_civ2_title,'Visible',state)
+set(handles.dy_civ2_title,'Visible',state)
+set(handles.ibx_civ2_text,'Visible',state)
+set(handles.rho_civ2_title,'Visible',state)
+set(handles.ImaThreshold2,'Visible',state)
+set(handles.ImaThreshold_title2,'Visible',state)
+if isequal(state,'off')
+ set(handles.MinIma2,'Visible','off')
+ set(handles.MaxIma2,'Visible','off')
+ set(handles.ImaThreshold2,'Value',0)
+ if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
+ set(handles.list_pair_civ2,'Visible','off')
+ set(handles.subdir_civ2,'Visible','off')
+ set(handles.subdir_civ2_text,'Visible','off')
+ end
+else
+ set(handles.list_pair_civ2,'Visible','on')
+ set(handles.subdir_civ2,'Visible','on')
+ set(handles.subdir_civ2_text,'Visible','on')
+end
+
+
+%----------------------------------------------------------
+function enable_fix2(handles)
+set(handles.frame_fix2,'BackgroundColor',[1 1 0])
+set(handles.REMOVE2,'Visible','on')
+set(handles.vec_Fmin2_2,'Visible','on')
+set(handles.vec_F4,'Visible','on')
+set(handles.vec_F3_2,'Visible','on')
+set(handles.thresh_vec2C,'Visible','on')
+set(handles.thresh_vec2C_text,'Visible','on')
+set(handles.thresh_vel2,'Visible','on')
+set(handles.thresh_vel2_text,'Visible','on')
+set(handles.mask_fix2,'Visible','on')
+set(handles.get_mask_fix2,'Visible','on')
+set(handles.list_pair_civ2,'Visible','on')
+set(handles.subdir_civ2,'Visible','on')
+set(handles.subdir_civ2_text,'Visible','on')
+set(handles.get_ref_fix2,'Visible','on')
+set(handles.ref_fix2,'Visible','on')
+set(handles.inf_sup2,'Visible','on')
+set(handles.field_ref2,'Visible','on')
+
+%----------------------------------------------------------
+function desable_fix2(handles)
+set(handles.frame_fix2,'BackgroundColor',[0.831 0.816 0.784])
+set(handles.REMOVE2,'Visible','off')
+set(handles.vec_Fmin2_2,'Visible','off')
+set(handles.vec_F4,'Visible','off')
+set(handles.vec_F3_2,'Visible','off')
+set(handles.thresh_vec2C,'Visible','off')
+set(handles.thresh_vec2C_text,'Visible','off')
+set(handles.thresh_vel2,'Visible','off')
+set(handles.thresh_vel2_text,'Visible','off')
+set(handles.mask_fix2,'Visible','off')
+set(handles.get_mask_fix2,'Visible','off')
+set(handles.get_ref_fix2,'Visible','off')
+set(handles.ref_fix2,'Visible','off')
+set(handles.inf_sup2,'Visible','off')
+set(handles.field_ref2,'Visible','off')
+if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
+ set(handles.list_pair_civ2,'Visible','off')
+ set(handles.subdir_civ2,'Visible','off')
+ set(handles.subdir_civ2_text,'Visible','off')
+end
+
+%--------------------------------------------------------------
+function enable_patch2(handles)
+set(handles.frame_patch2,'BackgroundColor',[1 1 0])
+%set(handles.rho_patch2,'Visible','on')
+set(handles.rho_text2,'Visible','on')
+set(handles.thresh_patch2,'Visible','on')
+set(handles.thresh_text2,'Visible','on')
+set(handles.subdomain_patch2,'Visible','on')
+set(handles.subdomain_text2,'Visible','on')
+set(handles.nx_patch2,'Visible','on')
+set(handles.ny_patch2,'Visible','on')
+set(handles.nx_patch2_title,'Visible','on')
+set(handles.ny_patch2_title,'Visible','on')
+set(handles.get_gridpatch2,'Visible','on')
+set(handles.grid_patch2,'Visible','on')
+set(handles.list_pair_civ2,'Visible','on')
+set(handles.subdir_civ2,'Visible','on')
+set(handles.subdir_civ2_text,'Visible','on')
+
+%--------------------------------------------------------------
+function desable_patch2(handles)
+set(handles.frame_patch2,'BackgroundColor',[0.831 0.816 0.784])
+set(handles.rho_patch2,'Visible','off')
+set(handles.rho_text2,'Visible','off')
+set(handles.thresh_patch2,'Visible','off')
+set(handles.thresh_text2,'Visible','off')
+set(handles.subdomain_patch2,'Visible','off')
+set(handles.subdomain_text2,'Visible','off')
+set(handles.nx_patch2,'Visible','off')
+set(handles.ny_patch2,'Visible','off')
+set(handles.nx_patch2_title,'Visible','off')
+set(handles.ny_patch2_title,'Visible','off')
+set(handles.get_gridpatch2,'Visible','off')
+set(handles.grid_patch2,'Visible','off')
+if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.FIX2,'Value'),0)
+ set(handles.list_pair_civ2,'Visible','off')
+ set(handles.subdir_civ2,'Visible','off')
+ set(handles.subdir_civ2_text,'Visible','off')
+end
+
+%--------------------------------------------------------------
+function enable_pair1(handles,state)
+set(handles.subdir_civ1,'Visible',state)
+set(handles.list_subdir_civ1,'Visible',state)
+set(handles.SUBDIR_CIV1_txt,'Visible',state)
+set(handles.frame_subdirciv1,'Visible',state)
+set(handles.list_pair_civ1,'Visible',state)
+set(handles.PAIR_txt,'Visible',state)
+set(handles.dt_display_txt,'Visible',state)
+set(handles.dt_unit,'Visible',state)
+set(handles.PAIR_frame,'Visible',state)
+
+% --- Executes on button press in test_interp.
+function test_interp_Callback(hObject, eventdata, handles)
+% hObject handle to test_interp (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hint: get(hObject,'Value') returns toggle state of test_interp
+
+
+
+
+
+
+%------------------------------------------------
+%Read the parameters for civ1 on the interface
+%--------------------------------------------------
+function par=read_param_civ1(handles,file_ima)
+
+ibx_val=str2num(get(handles.ibx,'String'));
+par.ibx=num2str(ibx_val);
+iby_val=str2num(get(handles.iby,'String'));
+par.iby=num2str(iby_val);
+isx=get(handles.isx,'String');
+if isempty(str2num(isx)), isx='41'; set(handles.isx,'String','41'), end; %default
+if str2num(isx) filename ( no extension )
+
+ if isequal(par.Dt,'0')
+ par.Dt='1' ;%case of 'displacement' mode
+ end
+
+ textcmx={'############## CMX file';...
+ ['FirstImage ' par.filename_ima_a];...
+ ['LastImage ' par.filename_ima_b];...
+ 'XX' ;...
+ ['Mask ' par.maskflag] ;...
+ ['MaskName ' par.maskname];...
+ ['ImageSize ' par.npx ' ' par.npy];... %VERIFIER CAS GENERAL ?
+ ['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
+ ['SearchBoxeSize ' par.isx ' ' par.isy];...
+ ['RO ' par.rho];...
+ ['GridSpacing ' par.dx ' ' par.dy];...
+ 'XX 1.0';...
+ ['Dt_TO ' par.Dt ' ' par.T0];...
+ ['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
+ 'XX 1';...
+ ['ShiftXY ' par.shiftx ' ' par.shifty];...
+ ['Grid ' par.gridflag];...
+ ['GridName ' par.gridname] ;...
+ 'XX 85';...
+ 'XX 1.0';...
+ 'XX 1.0';...
+ 'Hart 1';...
+ 'DecimalShift 0';...
+ 'Deformation 0';...
+ 'CorrelationMin 0';...
+ 'IntensityMin 0';...
+ 'SeuilImage n';...
+ 'SeuilImageValues 0 4096';...
+ ['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
+ 'ImageUsedBefore null null'};
+
+ textout=char(textcmx);
+ % timeL1=clock;
+ dlmwrite([filename '.cmx'],textout,'');
+ % timeL2=clock;
+ % timciv1=etime(timeL2,timeL1)
+ if sge
+ cmd_CIV1=[civ1_exe ' -f ' filename '.cmx' ]; % redirect standard output to the log file
+ else
+ cmd_CIV1=[civ1_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
+ end
+ if(isunix)
+ [Rootbat,Filebat,extbat]=fileparts(namelog);
+ ncName=fullfile(Rootbat,[ Filebat '.nc']);
+ cmd_CIV1=char({cmd_CIV1 ; ['mv ' namelog ' ' namelog '.civ1.log'];['chmod g+w ' ncName]});
+ else
+ cmd_CIV1=char({cmd_CIV1 ; ['copy /Y ' namelog ' ' namelog '.civ1.log']});
+ end
+
+%---------------------------------------------------------
+%CIV1 Unified
+%----------------------------------------------------------
+function xml_civ1_parameters=BATCH_CIV1_Unified(filename,namelog,par)
+%pixels per cm and matrix of the image times, read from the .civ file by uvmat
+global civ1_exe Civ_exe%name of the executable for civ1 calculation
+
+ civ1.image1=par.filename_ima_a;
+ civ1.image2=par.filename_ima_b;
+ civ1.imageSize_X=par.npx;
+ civ1.imageSize_Y=par.npy;
+ civ1.outputFileName=[filename '.nc'];
+ civ1.correlationBoxesSize_X=par.ibx;
+ civ1.correlationBoxesSize_Y=par.iby;
+ civ1.searchBoxesSize_X=par.isx;
+ civ1.searchBoxesSize_Y=par.isy;
+ civ1.globalShift_X=par.shiftx;
+ civ1.globalShift_Y=par.shifty;
+ civ1.ro=par.rho;
+ civ1.hart='y';
+ if isequal(par.gridflag,'y')
+ civ1.grid=par.gridname;
+ else
+ civ1.grid='n';
+ civ1.gridSpacing_X=par.dx;
+ civ1.gridSpacing_Y=par.dy;
+ end
+ if isequal(par.maskflag,'y')
+ civ1.mask=par.maskname;
+ end
+ civ1.dt=par.Dt;
+ civ1.unit='pixel';
+ civ1.absolut_time_T0=par.T0;
+ civ1.pixcmx=par.pxcmx;
+ civ1.pixcmy=par.pxcmy;
+ civ1.convectFlow='n';
+
+ xml_civ1_parameters=civ1;
+
+%---------------------------------------------------------
+%CIV2 Unified
+%----------------------------------------------------------
+function civ2=BATCH_CIV2_Unified(filename,namelog,par)
+%pixels per cm and matrix of the image times, read from the .civ file by uvmat
+global civ2_exe Civ_exe%name of the executable for civ1 calculation
+
+civ2.image1=par.filename_ima_a;
+civ2.image2=par.filename_ima_b;
+civ2.imageSize_X=par.npx;
+civ2.imageSize_Y=par.npy;
+civ2.inputFileName=[par.filename_nc1 '.nc'];
+civ2.outputFileName=[filename '.nc'];
+civ2.correlationBoxesSize_X=par.ibx;
+civ2.correlationBoxesSize_Y=par.iby;
+civ2.ro=par.rho;
+%civ2.decimalShift=par.decimal;
+%civ2.deformation=par.deformation;
+if isequal(par.decimal,'1')
+ civ2.decimalShift='y';
+else
+ civ2.decimalShift='n';
+end
+if isequal(par.deformation,'1')
+ civ2.deformation='y';
+else
+ civ2.deformation='n';
+end
+if isequal(par.gridflag,'y')
+ civ2.grid=par.gridname;
+else
+ civ2.grid='n';
+ civ2.gridSpacing_X=par.dx;
+ civ2.gridSpacing_Y=par.dy;
+end
+civ2.gridSpacing_X='10';
+civ2.gridSpacing_Y='10';%NOTE: faut mettre gridSpacing pourque ca tourne, meme si c'est la grille qui est utilisee
+if isequal(par.maskflag,'y')
+ civ2.mask=par.maskname;
+else
+ civ2.mask='n';
+end
+civ2.dt=par.Dt;
+civ2.unit='pixel';
+civ2.absolut_time_T0=par.T0;
+civ2.pixcmx=par.pxcmx;
+civ2.pixcmy=par.pxcmy;
+civ2.convectFlow='n';
+civ2.pixcmx=par.pxcmx;
+civ2.pixcmy=par.pxcmy;
+civ2.convectFlow='n';
+
+%---------------------------------------------------------
+%CIV2 CIV2 CIV2 CIV2
+%----------------------------------------------------------
+function cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par)
+%pixels per cm and matrix of the image times, read from the .civ file by uvmat
+global civ2_exe sge%name of the executable for civ1 calculation
+ if isequal(par.Dt,'0')
+ par.Dt='1' ;%case of 'displacement' mode
+ end
+textcmx={'############## CMX file';...
+['FirstImage ' par.filename_ima_a];...
+['LastImage ' par.filename_ima_b];...
+'XX' ;...
+['Mask ' par.maskflag];...
+['MaskName ' par.maskname];...
+['ImageSize ' par.npx ' ' par.npy];...
+['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
+['SearchBoxeSize ' par.ibx ' ' par.iby];...
+['RO ' par.rho];...
+['GridSpacing ' par.dx ' ' par.dy];...
+'XX 1.0';...
+['Dt_TO ' par.Dt ' ' par.T0];...
+['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
+'XX 1';...
+['ShiftXY 0 0'];...
+['Grid ' par.gridflag];...
+['GridName ' par.gridname];...
+'XX 85';...
+'XX 1.0';...
+'XX 1.0';...
+'Hart 1';...
+['DecimalShift ' par.decimal];...
+['Deformation ' par.deformation];...
+'CorrelationMin 0';...
+'IntensityMin 0';...
+'SeuilImage n';...
+'SeuilImageValues 0 4096';...
+['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
+['ImageUsedBefore ' par.filename_nc1]};
+ textout=char(textcmx);
+ dlmwrite([filename_cmx '2'] ,textout,'');
+ if sge
+ cmd_CIV2=[civ2_exe ' -f ' filename_cmx ]; % redirect standard output to the log file
+ else
+ cmd_CIV2=[civ2_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
+ end
+
+
+% --- Executes on button press in HELP.
+function HELP_Callback(hObject, eventdata, handles)
+path_to_uvmat=which ('uvmat');% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+else
+web([helpfile '#civ'])
+end
+
+
+%----------------------------------------------------------
+%--read images and convert them to the uint16 format used for PIV
+function A=read_image(filename,nom_type,npx,npy,num);
+%npx, npy are the dimensions needed for the raw SMD images
+%num is the view number needed for an avi movie
+if isequal(nom_type,'avi')
+ mov=aviread(filename,num);
+ A=frame2im(mov(1));
+ A=sum(double(A),3);
+ A=uint16(A);
+elseif isequal(nom_type,'raw_SMD')
+ [fid,message]=fopen(filename,'r');
+ B=fread(fid,Inf,'int16',0,'ieee-le');%read 16 bit binary file
+ A=(reshape(B,npx,npy))'; %remplissage ligne par ligne avec une matrice colonne ? transposer(uB) pour avoir une matrice ligne
+ A=uint16(A);
+ fclose(fid);
+else
+ A=imread(filename);
+ siz=size(A);
+ if length(siz)==3;%color images
+ A=sum(double(A),3);
+ end
+ A=uint16(A);
+end
+
+%----------------------------------------------------------------
+%Executes on carriage return on the time interval dt
+%----------------------------------------------------------------
+function dt_Callback(hObject, eventdata, handles)
+%determine the set of times and possible intervals for CIV
+% answer=inputdlg('time interval between images?');
+ dt=(1/1000)*str2num(get(handles.dt,'String'));
+ nbfield=str2num(get(handles.nb_field,'String')); %last image number selected in the processing series
+ time=(dt*[0:nbfield-1])';
+% set(handles.incr_i,'UserData',dt);%store the time interval between successive images
+ set(handles.displ_filebase,'UserData',time); %store the set of times
+ for index=1:min(nbfield-1,200)
+ displ_num(1,index)=1;
+ displ_num(2,index)=1;
+ displ_num(3,index)=-floor(index/2);
+ displ_num(4,index)=ceil(index/2);
+ end
+set(handles.list_pair_civ1,'Value',1);
+set(handles.list_pair_civ1,'UserData',displ_num);
+set(handles.list_pair_civ2,'Value',1);
+%update the list of time intervals
+find_netcpair_civ1(hObject, eventdata, handles)
+find_netcpair_civ2(hObject, eventdata, handles)
+
+%-------------------------------------------------------
+function ref_i_Callback(hObject, eventdata, handles)
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+if isequal(get(handles.CIV1,'Value'),0)| isequal(mode,'series(Di)')
+ find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
+end
+if isequal(mode,'series(Di)') | ...% we do patch2 only
+ (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
+ find_netcpair_civ2(hObject, eventdata, handles);
+end
+
+%----------------------------------------------------
+function ref_j_Callback(hObject, eventdata, handles)
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+if isequal(get(handles.CIV1,'Value'),0)| isequal(mode,'series(Dj)')
+ find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
+end
+if isequal(mode,'series(Dj)') | ...
+ (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
+ find_netcpair_civ2(hObject, eventdata, handles);
+end
+%----------------------------------------------------
+% --- Executes on button press in compare.
+function compare_Callback(hObject, eventdata, handles)
+test=get(handles.compare,'Value');
+if test==2 || test==3
+ filebase=get(handles.displ_filebase,'String');
+ browse=get(handles.browse_root,'Userdata');
+ browse.nom_type_ima1=browse.nom_type_ima;
+ set(handles.browse_root,'UserData',browse);
+ set(handles.sub_txt,'Visible','on')
+ set(handles.displ_filebase2,'Visible','On');%mkes the second file input window visible
+ mode_store=get(handles.mode,'String');%get the present 'mode'
+ set(handles.compare,'UserData',mode_store);%store the mode display
+ set(handles.mode,'Visible','off')
+ if test==2
+ set(handles.mode,'Visible','off')
+ else
+ set(handles.mode,'Visible','on')
+ end
+
+ % open an image file with the browser
+ ind_opening=1;%default
+ browse.incr_pair=[0 0]; %default
+ oldfile=get(handles.displ_filebase,'String');
+ menu={'*.xml;*.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
+ '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc', '.nc files';...
+ '*.*', 'All Files (*.*)'};
+ [FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
+ fileinput=[PathName FileName];%complete file name
+ sizf=size(fileinput);
+ if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
+ [path,name,ext]=fileparts(fileinput);
+ [path1]=fileparts(filebase);
+ if ~strcmp(path1,path)
+ msgbox_uvmat('ERROR','The two input image series must be in the same directory')
+ return
+ end
+ set(handles.displ_filebase2,'String',name);
+ [RootPath,RootFile,field_count,str2,str_a,str_b,xx,nom_type,subdir]=name2display(name);
+ browse=get(handles.browse_root,'UserData');
+ browse.nom_type_ima_1=nom_type;
+ set(handles.browse_root,'UserData',browse)
+
+ %check image extension
+ if ~strcmp(ext,get(handles.ext_ima,'String'))
+ msgbox_uvmat('ERROR','The two input image series must have the same extenion name')
+ return
+ end
+
+ %check image size
+ A=imread(fileinput);
+ npxy=get(handles.ext_ima,'UserData');
+ if ~isequal(npxy(1),size(A,1))|| ~isequal(npxy(2),size(A,2))
+ msgbox_uvmat('ERROR','The two input image series must have the same size')
+ return
+ end
+else
+ set(handles.mode,'Visible','on')
+ set(handles.displ_filebase2,'Visible','Off');
+ set(handles.sub_txt,'Visible','off')
+ set(handles.displ_filebase2,'String',[]);
+ mode_store=get(handles.compare,'UserData');
+ set(handles.mode,'String',mode_store)
+ set(handles.test_stereo1,'Value',0)
+ set(handles.test_stereo2,'Value',0)
+end
+mode_Callback(hObject, eventdata, handles)
+
+%-----------------------------------------------------------
+% --- Executes on button press in get_ref_fix1.
+function get_ref_fix1_Callback(hObject, eventdata, handles)
+filebase=get(handles.displ_filebase,'String');
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.nc', ' (*.nc)';
+ '*.nc', 'netcdf files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',filebase);
+
+fileinput=[PathName FileName];
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
+%[filebasesub,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
+[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
+%filebase=fullfile(RootPath,RootFile);
+% [Pth,FileN]=fileparts(filebasesub);
+% Pth=fileparts(Pth);
+ref.filebase=fullfile(Path,File);
+ref.num_a=stra2num(str_a);
+ref.num_b=stra2num(str_b);
+ref.num1=str2num(field_count);
+ref.num2=str2num(str2);
+browse=[];%initialisation
+if ~isequal(ref.ext,'.nc')
+ msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
+ return
+end
+% [path,name]=fileparts(ref.filebase);
+set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
+set(handles.ref_fix1,'UserData',ref)
+menu_field{1}='civ1';
+Data=nc2struct(fileinput,[]);
+if isfield(Data,'patch') & isequal(Data.patch,1)
+ menu_field{2}='filter1';
+end
+if isfield(Data,'civ2') & isequal(Data.civ2,1)
+ menu_field{3}='civ2';
+end
+if isfield(Data,'patch2') & isequal(Data.patch2,1)
+ menu_field{4}='filter2';
+end
+% [cte_detect,vdt,cte_read]=read_netcdf(fileinput,{'patch','civ2','patch2'});
+% if isequal(cte_detect(1),1) & isequal(cte_read(1),1)
+% menu_field{2}='filter1';
+% end
+% if isequal(cte_detect(2),1) & isequal(cte_read(2),1)
+% menu_field{3}='civ2';
+% end
+% if isequal(cte_detect(3),1) & isequal(cte_read(3),1)
+% menu_field{4}='filter2';
+% end
+set(handles.field_ref1,'String',menu_field);
+set(handles.field_ref1,'Value',length(menu_field));
+set(handles.inf_sup1,'Value',2);
+set(handles.thresh_vel,'String','1');%default threshold
+set(handles.ref_fix1,'Enable','on')
+
+%---------------------------------------------------------------
+% --- Executes on button press in get_ref_fix2.
+function get_ref_fix2_Callback(hObject, eventdata, handles)
+if isequal(get(handles.get_ref_fix2,'Value'),1)
+ filebase=get(handles.displ_filebase,'String');
+ [FileName, PathName, filterindex] = uigetfile( ...
+ {'*.nc', ' (*.nc)';
+ '*.nc', 'netcdf files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',filebase);
+ fileinput=[PathName FileName];
+ sizf=size(fileinput);
+ if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
+ %[filebasesub,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
+ [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
+% [Pth,FileN]=fileparts(filebasesub);
+% Pth=fileparts(Pth);
+ ref.filebase=fullfile(Path,File);
+ ref.num_a=stra2num(str_a);
+ ref.num_b=stra2num(str_b);
+ ref.num1=str2num(field_count);
+ ref.num2=str2num(str2);
+ browse=[];%initialisation
+ if ~isequal(ref.ext,'.nc')
+ msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
+ return
+ end
+% [path,name]=fileparts(ref.filebase);
+ set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
+ set(handles.ref_fix2,'UserData',ref)
+ menu_field{1}='civ1';
+% [cte_detect,vdt,cte_read]=read_netcdf(fileinput,{'patch','civ2','patch2'});
+ Data=nc2struct(fileinput,[]);
+ if isfield(Data,'patch') & isequal(Data.patch,1)
+ menu_field{2}='filter1';
+ end
+ if isfield(Data,'civ2') & isequal(Data.civ2,1)
+ menu_field{3}='civ2';
+ end
+ if isfield(Data,'patch2') & isequal(Data.patch2,1)
+ menu_field{4}='filter2';
+ end
+
+% if isequal(cte_detect(1),1) & isequal(cte_read(1),1)
+% menu_field{2}='filter1';
+% end
+% if isequal(cte_detect(2),1) & isequal(cte_read(2),1)
+% menu_field{3}='civ2';
+% end
+% if isequal(cte_detect(3),1) & isequal(cte_read(3),1)
+% menu_field{4}='filter2';
+% end
+ set(handles.field_ref2,'String',menu_field);
+ set(handles.field_ref2,'Value',length(menu_field));
+ set(handles.inf_sup2,'Value',2);
+ set(handles.thresh_vel2,'String','1');%default threshold
+ set(handles.ref_fix2,'Enable','on')
+ set(handles.ref_fix2,'Visible','on')
+ set(handles.field_ref2,'Visible','on')
+else
+ set(handles.ref_fix2,'Visible','off')
+ set(handles.field_ref2,'Visible','off')
+end
+%-------------------------------------------------------
+
+function ref_fix1_Callback(hObject, eventdata, handles)
+ set(handles.inf_sup1,'Value',1);
+ set(handles.field_ref1,'Value',1)
+ set(handles.field_ref1,'String',{' '})
+ set(handles.ref_fix1,'UserData',[]);
+ set(handles.ref_fix1,'String','');
+ set(handles.thresh_vel1,'String','0');
+
+
+%------------------------------------------------------
+
+function ref_fix2_Callback(hObject, eventdata, handles)
+ set(handles.inf_sup2,'Value',1);
+ set(handles.field_ref2,'Value',1)
+ set(handles.field_ref2,'String',{' '})
+ set(handles.ref_fix2,'UserData',[]);
+ set(handles.ref_fix2,'String','');
+ set(handles.thresh_vel2,'String','0');
+
+%--------------------------------------------------------
+% --- Executes on selection change in inf_sup1.
+function inf_sup1_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------------------------------------
+
+
+% --- Executes on selection change in field_ref.
+function field_ref_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------------------------
+
+% --- Executes on selection change in field_ref2.
+function field_ref2_Callback(hObject, eventdata, handles)
+
+% -----------------------------------------------------------
+% transform letters to numbers
+%--------------------------------------------
+function numres=stra2num(str)
+numres=double(str)-96;
+if double(str) >= 48 & double(str) <= 57 % = 1 for numbers
+ numres=str2num(str);
+end
+
+
+% --- Executes on button press in test_stereo1.
+function test_stereo1_Callback(hObject, eventdata, handles)
+if isequal(get(handles.test_stereo1,'Value'),0)
+ set(handles.subdomain_patch1,'Visible','on')
+ set(handles.rho_patch1,'Visible','on')
+else
+ set(handles.subdomain_patch1,'Visible','off')
+ set(handles.rho_patch1,'Visible','off')
+end
+
+% --- Executes on button press in test_stereo2.
+function test_stereo2_Callback(hObject, eventdata, handles)
+if isequal(get(handles.test_stereo2,'Value'),0)
+ set(handles.subdomain_patch2,'Visible','on')
+ set(handles.rho_patch2,'Visible','on')
+else
+ set(handles.subdomain_patch2,'Visible','off')
+ set(handles.rho_patch2,'Visible','off')
+end
+
+% --- Executes on button press in ImaThreshold.
+function ImaThreshold_Callback(hObject, eventdata, handles)
+if isequal(get(handles.ImaThreshold,'Value'),1)
+ set(handles.MinIma,'Visible','on')
+ set(handles.MaxIma,'Visible','on')
+else
+ set(handles.MinIma,'Visible','off')
+ set(handles.MaxIma,'Visible','off')
+end
+
+
+% --- Executes on button press in ImaThreshold2.
+function ImaThreshold2_Callback(hObject, eventdata, handles)
+if isequal(get(handles.ImaThreshold2,'Value'),1)
+ set(handles.MinIma2,'Visible','on')
+ set(handles.MaxIma2,'Visible','on')
+else
+ set(handles.MinIma2,'Visible','off')
+ set(handles.MaxIma2,'Visible','off')
+end
+
+
+% --- Executes on button press in Experimental.
+function Experimental_Callback(hObject, eventdata, handles)
+
+
+
+function ext_ima_1_Callback(hObject, eventdata, handles)
+% hObject handle to ext_ima_1 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of ext_ima_1 as text
+% str2double(get(hObject,'String')) returns contents of ext_ima_1 as a double
+
+
+% --- Executes during object creation, after setting all properties.
+function ext_ima_1_CreateFcn(hObject, eventdata, handles)
+% hObject handle to ext_ima_1 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+
+function ext_ima_Callback(hObject, eventdata, handles)
+% hObject handle to ext_ima (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of ext_ima as text
+% str2double(get(hObject,'String')) returns contents of ext_ima as a double
+
+
+% --- Executes during object creation, after setting all properties.
+function ext_ima_CreateFcn(hObject, eventdata, handles)
+% hObject handle to ext_ima (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
Index: /trunk/src/civ_3D.m
===================================================================
--- /trunk/src/civ_3D.m (revision 2)
+++ /trunk/src/civ_3D.m (revision 2)
@@ -0,0 +1,3340 @@
+%'civ_3D': function associated with the interface 'civ_3D.fig' for PIV in volume
+%------------------------------------------------------------------------
+% provides an interface for the software CIVx
+% function varargout = civ_3D(varargin)
+% provides an interface for the software CIVx
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+function varargout = civ_3D(varargin)
+
+% Last Modified by GUIDE v2.5 25-Feb-2009 23:14:16
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @civ_3D_OpeningFcn, ...
+ 'gui_OutputFcn', @civ_3D_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin & isstr(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+%--------------------------------------------------------------------------
+% --- Executes just before civ_3D is made visible.
+%--------------------------------------------------------------------------
+function civ_3D_OpeningFcn(hObject, eventdata, handles, varargin)
+% This function has no output args, see OutputFcn.
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+% varargin command line arguments to civ_3D (see VARARGIN)
+global test_batch patch_new_exe%=1 if patch processing available
+%filebase: root name
+%nom_type: nomencalture used ('png_old','_i_j'...)
+%list of field numbers to process
+%subdir: subdirectory of the opened netcdf file
+%ind_opening: operation number advised for beginning (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2),
+%ind_a_opening ind_b_opening chosen pair from the opened netcdf file
+% Choose default command line output for civ_3D
+handles.output = hObject;
+% Update handles structure
+guidata(hObject, handles);
+
+%default initial parameters
+filebase=''; % root file name ('filebase'.civ_3D)
+nom_type=[]; % nomenclature type
+ext=[];
+testall=0;
+browse=[];
+
+%load the initial parameters if the interface is started from uvmat
+if ~isempty(varargin)% the interface is opened from uvmat
+ varcell=varargin{1};
+ filebase=varcell{1};
+ nom_type_read=varcell{2};
+ num1=varcell{3};
+ num2=varcell{4};
+ num_a=varcell{5};
+ num_b=varcell{6};
+ subdir=varcell{7};
+ ind_opening=varcell{8};
+ ind_a_opening=varcell{9};
+ ind_b_opening=varcell{10};
+ ext=varcell{11};
+else
+ num1=1; % set of field i numbers
+ num2=2; % set of field i numbers
+ num_a=1; % set of field j numbers (fields a)
+ num_b=1; % second set of field j numbers (fields b)
+ subdir='A'; % subdir for the netcdf result files
+ ind_opening=1; % proposed operation number (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2)
+ ind_a_opening=1; % proposed index in the menu of fields a
+ ind_b_opening=2; % proposed index in the menu of fields b
+end
+
+if exist('ext','var') & length(ext)>1 & (~isempty(imformats(ext([2:end])))|...
+ isequal(ext,'.avi')|isequal(ext,'.AVI'));%if an image file has been opened by uvmat
+ browse.ext_ima=ext;
+ if exist('nom_type_read','var')
+ browse.nom_type_ima=nom_type_read; % the image nomenclature is stored
+ end
+elseif isequal(ext,'.nc')
+ if exist('nom_type_read','var')
+ browse.nom_type_nc=nom_type_read;% the netcdf nomenclature is stored
+ end
+end
+set(handles.displ_filebase,'String',filebase);
+set(handles.ImaDoc,'UserData',testall);
+set(handles.browse_root,'UserData',browse)
+set(handles.ImaDoc,'String',ext)
+
+
+% set(handles.ImaDoc,'String',ext)
+
+%read names of the .exe file to adjust the interface according to
+%available prog
+%read names of the .exe file
+path_uvmat=which('uvmat');% check the path detected for source file uvmat
+path_UVMAT=fileparts(path_uvmat); %path to UVMAT
+if isunix
+ syst='LINUX'
+ %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ_3D binary names
+ xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml')
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+else
+ syst='WIN'
+ %fid = fopen(fullfile(path_UVMAT,'PARAM_WIN.txt'),'r');%open the file with civ_3D binary names
+ xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+end
+
+patch_new_exe='';
+todo_patch='';
+sge=0;
+
+if isfield(sparam,'PatchNew_exe')
+ patch_new_exe=sparam.PatchNew_exe;
+end
+if isfield(sparam,'Todo_path')
+ todo_path=sparam.Todo_path
+end
+if isfield(sparam,'SGE')
+ sge=str2num(sparam.SGE);
+end
+name_todo=fullfile(todo_path,'TODO.txt')
+test_batch=1;
+if ~sge
+if isequal(todo_path,'') |isequal(todo_path,[])
+ ['no batch distributed processing available:file path TODO.txt not defined in UVMAT/PARAM_' syst]
+ test_batch=0;
+end
+if exist(name_todo,'file')~=2
+ hwarn=warndlg(['no batch distributed processing available, queue file ' name_todo ' absent']);
+ % test_batch=0; % Problems to detect file on linux/nfs filesystems
+end
+end
+
+
+if test_batch==0
+ set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
+end
+
+set(handles.subdir_civ1,'String',subdir)%default subdir on which uvmat was working
+set(handles.subdir_civ2,'String',subdir)%default subdir on which uvmat was working
+
+%initiate advised operations
+if isequal(ind_opening,[])
+ ind_opening=1; % default
+end
+% set default operation options
+ enable_civ1(handles,'off')
+ enable_civ2(handles,'off')
+ desable_fix1(handles)
+ desable_patch1(handles)
+ desable_fix2(handles)
+ desable_patch2(handles)
+ set(handles.CIV1,'Value',0)
+ set(handles.FIX1,'Value',0)
+ set(handles.PATCH1,'Value',0)
+ set(handles.CIV2,'Value',0)
+ set(handles.FIX2,'Value',0)
+ set(handles.PATCH2,'Value',0)
+ set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
+if isequal(ind_opening,1)
+ set(handles.CIV1,'Value',1)
+ enable_civ1(handles,'on')
+elseif isequal(ind_opening,2)
+ set(handles.FIX1,'Value',1)
+ enable_fix1(handles)
+elseif isequal(ind_opening,3)
+ set(handles.PATCH1,'Value',1)
+ enable_patch1(handles)
+elseif isequal(ind_opening,4)
+ set(handles.CIV2,'Value',1)
+ enable_civ2(handles,1)
+elseif isequal(ind_opening,5)
+ set(handles.FIX2,'Value',1)
+ enable_fix2(handles)
+ set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
+ set(handles.list_pair_civ2,'Enable','On')
+ set(handles.list_pair_civ2,'Enable','On')
+elseif isequal(ind_opening,6)
+ set(handles.PATCH2,'Value',1)
+ enable_patch2(handles)
+ set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
+ set(handles.list_pair_civ2,'Enable','On')
+end
+
+% set the range of fields (1:1 by default) and selected pair
+if isempty(num2)|isequal(num2,num1)
+ num_ref_i=num1;
+else
+ num_ref_i=floor((num1+num2)/2);
+ browse.incr_pair(1)=num2-num1;
+ browse.incr_pair(2)=0;
+end
+if isempty(num_b)|isequal(num_a,num_b)
+ if isempty(num_a)
+ num_ref_j=1;
+ else
+ num_ref_j=num_a;
+ end
+else
+ num_ref_j=floor((num_a+num_b)/2);
+ browse.incr_pair(2)=num_b-num_a;
+end
+set(handles.first_i,'String',num2str(num_ref_i));
+set(handles.last_i,'String',num2str(num_ref_i));
+set(handles.first_j,'String',num2str(num_ref_j));
+set(handles.last_j,'String',num2str(num_ref_j));
+set(handles.ref_i,'String',num2str(num_ref_i));
+set(handles.ref_j,'String',num2str(num_ref_j));
+set(handles.browse_root,'UserData',browse);
+if ~isempty(varargin)% the interface is opened from uvmat
+ displ_filebase_Callback(hObject, eventdata, handles);
+end
+
+set(handles.waitbar_1,'Position',[0.946 0.877 0.03 0.001])
+set(handles.waitbar_patch1,'Position',[0.946 0.626 0.03 0.001])
+set(handles.waitbar_civ2,'Position',[0.946 0.406 0.03 0.001])
+set(handles.waitbar_patch2,'Position',[0.946 0.187 0.03 0.001])
+
+
+%--------------------------------------------------------------
+% --- Outputs from this function are returned to the command line.
+%-----------------------------------------------------------------
+function varargout = civ_3D_OutputFcn(hObject, eventdata, handles)
+% varargout cell array for returning output args (see VARARGOUT);
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+
+%------------------------------------------------------------------
+% --- Executes on button press in browse_root.
+function browse_root_Callback(hObject, eventdata, handles)
+%get the input file properties
+filebase=get(handles.displ_filebase,'String');
+oldfile=''; %default
+if isempty(filebase)|isequal(filebase,'')%loads the previously stored file name and set it as default in the file_input box
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat')
+ if exist(profil_perso,'file')
+ h=load (profil_perso);
+ if isfield(h,'filebase')&ischar(h.filebase)
+ oldfile=h.filebase;
+ end
+ if isfield(h,'RootPath')&ischar(h.RootPath)
+% oldfile=h.filebase{1}
+ oldfile=h.RootPath;
+ end
+ end
+ else
+ oldfile=filebase;
+ end
+testall=get(handles.ImaDoc,'UserData');
+ind_opening=1;%default
+browse.incr_pair=[0 0]; %default
+
+menu={'*.*', 'All Files (*.*)'; '*.xml;*.vol; *.avi;*.AVI','(*.xml,*.civ,*.avi,*.vol)'; ...
+ '*.xml', '.xml files';'*.civ', '.civ files';...
+ '*.avi;*.AVI', '.avi files';'*.vol', '.vol files'};
+
+[FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
+fileinput=[PathName FileName];%complete file name
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
+[path,name,ext]=fileparts(fileinput);
+testeditxml=0;
+if isequal(ext,'.xml')
+ testeditxml=1;
+ t_browse=xmltree(fileinput);
+ head_element=get(t_browse,1);
+ if isfield(head_element,'name')& isequal(head_element.name,'ImaDoc')
+ testeditxml=0;
+ end
+end
+if testeditxml==1 | isequal(ext,'.xls')
+ heditxml=editxml({fileinput});
+ set(heditxml,'Tag','browser')
+ waitfor(heditxml,'Tag','idle')
+ if ~ishandle(heditxml)
+ return
+ end
+ attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
+ set(handles.browse,'UserData',fileinput)% store for future opening with browser
+ fileinput=get(attr,'UserData');
+ if ~exist(fileinput,'file')
+ return
+ end
+end
+[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
+filebase=fullfile(RootPath,RootFile);
+if isequal(get(handles.compare,'Value'),1)
+ browse=get(handles.browse_root,'UserData');
+else
+ browse=[];%initialisation
+end
+if length(ext)>1 & (~isempty(imformats(ext([2:end])))||...
+ isequal(lower(ext),'.avi')||isequal(ext,'.vol'));%if an image file has been opened by uvmat
+ browse.ext_ima=ext;
+ browse.nom_type_ima=nom_type;
+ browse.field_count=str2num(field_count);
+end
+set(handles.ImaDoc,'String',ext);
+%%%%% read the state of the selected netcdf file to advise default operation
+if isequal(ext,'.nc')
+ browse.nom_type_nc=nom_type;
+ ind_opening=2;% propose 'fix' as the default option
+ Data=nc2struct(fileinput,[]);
+ if isfield(Data,'fix') & isequal(Data.fix,1)
+ ind_opening=3;
+ end
+ if isfield(Data,'patch') & isequal(Data.patch,1)
+ ind_opening=4;
+ end
+ if isfield(Data,'civ2') & isequal(Data.civ2,1)
+ ind_opening=5;
+ end
+ if isfield(Data,'fix2') & isequal(Data.fix2,1)
+ ind_opening=6;
+ end
+ if isfield(Data,'pixcmx') & isequal(Data,'pixcmy')
+ browse.pxcmx=Data.pixcmx;
+ browse.pxcmy=Data.pixcmy;
+ end
+ testciv=1; %TO SUPPRESS WITH NEW VERSION OF CIVX
+ subdir='';%default
+ if testciv
+ [Pathbase,Namebase]=fileparts(filebase)
+ [Pathprev,subdir,extdir]=fileparts(Pathbase)
+ subdir=[subdir extdir]
+% if isequal (subdir,subdir_obs)
+ filebase=fullfile(Pathprev,Namebase)% move upward to get the base name (corresponding to the .civ_3D file and images)
+% end
+ end
+ set(handles.subdir_civ1,'String',subdir);%set the default subdir directories for installing the .nc results
+ set(handles.subdir_civ2,'String',subdir);
+ browse.testciv=testciv;
+ browse.ind_opening=ind_opening;
+end
+set(handles.displ_filebase,'String',filebase);
+set(handles.ImaDoc,'String',ext);
+if ~isempty(str2num(field_count))
+ ref_i=str2num(field_count);
+ if ~isempty(str2num(str2))
+ ref_i=floor((ref_i+str2num(str2))/2);% reference image number corresponding to the file
+ browse.incr_pair(1)=str2num(str2)-str2num(field_count);
+ browse.incr_pair(2)=0;
+ end
+ set(handles.first_i,'String',num2str(ref_i));
+ set(handles.last_i,'String',num2str(ref_i));
+ set(handles.ref_i,'String',num2str(ref_i));
+end
+if isempty(str2num(str_a))
+ set(handles.ref_j,'String','1');
+else
+ ref_j=str2num(str_a);
+ if ~isempty(str2num(str_b))
+ ref_j=floor((str2num(str_a)+str2num(str_b))/2);
+ browse.incr_pair(2)=str2num(str_b)-str2num(str_a);
+ end
+ set(handles.first_j,'String',num2str(ref_j));
+ set(handles.last_j,'String',num2str(ref_j));
+ set(handles.ref_j,'String',num2str(ref_j));
+end;
+if isequal(ind_opening,1)
+ set(handles.CIV1,'Value',1)
+ enable_civ1(handles,'on')
+elseif isequal(ind_opening,2)
+ set(handles.FIX1,'Value',1)
+ enable_fix1(handles)
+elseif isequal(ind_opening,3)
+ set(handles.PATCH1,'Value',1)
+ enable_patch1(handles)
+elseif isequal(ind_opening,4)
+ set(handles.CIV2,'Value',1)
+ enable_civ2(handles,1)
+elseif isequal(ind_opening,5)
+ set(handles.FIX2,'Value',1)
+ enable_fix2(handles)
+ set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
+ set(handles.list_pair_civ2,'Enable','On')
+ set(handles.list_pair_civ2,'Enable','On')
+elseif isequal(ind_opening,6)
+ set(handles.PATCH2,'Value',1)
+ enable_patch2(handles)
+ set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
+ set(handles.list_pair_civ2,'Enable','On')
+end
+set(handles.browse_root,'UserData',browse);% store information from browser
+testall=isequal(menu(filtindex,1),{'*.*'});
+set(handles.ImaDoc,'UserData',testall);
+
+displ_filebase_Callback(hObject, eventdata, handles);
+
+%------------------------------------------------
+
+function ImaDoc_Callback(hObject, eventdata, handles)
+displ_filebase_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------------------------
+%function activated when a new filebase (image series) is introduced
+%------------------------------------------------------------
+function displ_filebase_Callback(hObject, eventdata, handles)
+
+global test_batch
+set(gcf,'Pointer','watch')
+ext_ima=[]; %default
+nom_type_ima=[];%default
+field_count=1;%default
+nom_type_nc=[];
+npx=[];%default
+npy=[];
+TimeUnit='s'; %default
+CoordUnit='cm';%default
+pxcmx_search=[];%default
+pxcmy_search=[];%default
+filebase=get(handles.displ_filebase,'String');
+
+ext=get(handles.ImaDoc,'String');
+browse=get(handles.browse_root,'UserData');%default
+if ~isempty(browse)
+ if isfield(browse,'ext_ima')
+ ext_ima=browse.ext_ima;
+ end
+ if isfield(browse,'nom_type_ima')
+ nom_type_ima=browse.nom_type_ima;
+ end
+ if isfield(browse,'field_count')
+ field_count=browse.field_count;
+ end
+end
+
+%default first_i and j and increments
+first_i=str2num(get(handles.first_i,'String'));%value possibly set by uvmat_Opening
+if isempty(first_i)| first_i < 1
+ first_i=1; %default first_i
+end
+last_i=str2num(get(handles.last_i,'String'));
+if isempty(last_i)| last_i < first_i
+ last_i=first_i; %default last_i
+end
+first_j=str2num(get(handles.first_j,'String'));
+if isempty(first_j)| first_j < 1
+ first_j=1; %default first_j
+end
+last_j=str2num(get(handles.last_j,'String'));
+if isempty(last_j)| last_j < first_j
+ last_j=first_j; %default last_j
+end
+incr_i=str2num(get(handles.incr_i,'String'));
+if isempty(incr_i) | incr_i < 1;
+ set(handles.incr_i,'String','1') %default incr_i
+end
+incr_j=str2num(get(handles.incr_j,'String'));
+if isempty(incr_j) | incr_j < 1;
+ set(handles.incr_j,'String','1') %default incr_j
+end
+dt=[];%default
+testmode=0;%default
+nbfield=1; %default
+if isfield(browse,'pxcmx') & isfield(browse,'pxcmy')
+ pxcmx=num2str(browse.pxcmx);
+ pxcmy=num2str(browse.pxcmy);
+else
+ pxcmx=1;%default
+ pxcmy=1;
+end
+ %look for an image documentation file
+if ~isequal(ext,'.xml') & ~ isequal(ext,'.avi')& ~ isequal(ext,'.AVI')
+ if exist([filebase '.xml'],'file')
+ ext='.xml';
+ set(handles.ImaDoc,'String','.xml')
+ elseif exist([filebase '.civ_3D'],'file')
+ ext='.civ_3D';
+ set(handles.ImaDoc,'String','.civ_3D')
+ elseif exist([filebase '.avi'],'file')
+ ext='.avi';
+ set(handles.ImaDoc,'String','.avi')
+ elseif exist([filebase '.AVI'],'file')
+ ext='.AVI';
+ set(handles.ImaDoc,'String','.AVI')
+ end
+end
+%%%%%%%% read image documentation file %%%%%%%%%%%%%%%%%%%%%%%%%%%
+ mode=''; %default
+ %read the image documentation file if found
+if isequal(ext,'.xml')
+ set(handles.ref_i,'Visible','On')%use a reference index
+ set(handles.ref_j,'Visible','On')
+ set(handles.dt,'Visible','Off')
+ set(handles.dt_text,'String','ref. ind.')
+elseif isequal(ext,'.avi') | isequal(ext,'.AVI')
+ set(handles.ref_j,'Visible','Off')
+ set(handles.dt,'Visible','Off')
+ set(handles.dt_text,'String','ref. ind.')
+else
+ set(handles.ref_i,'Visible','Off')
+ set(handles.ref_j,'Visible','Off')
+ set(handles.dt,'Visible','On')
+ set(handles.dt_text,'String','dt(ms)=')
+end
+
+if isequal(ext,'.xml')
+ [XmlData,warntext]=imadoc2struct([filebase '.xml']);
+ if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')
+ [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
+ end
+ if isfield(XmlData,'Camera')
+ if isfield(XmlData.Camera,'TimeUnit')
+ TimeUnit=XmlData.Camera.TimeUnit;
+ end
+ if isfield(XmlData.Camera,'ImageSize')
+ ImageSize=XmlData.Camera.ImageSize;
+ if ~isempty(ImageSize)&& ~isempty(ImageSize)
+ xindex=findstr(ImageSize,'x');
+ if length(xindex)>=2
+ npx=str2num(ImageSize(1:xindex(1)-1));
+ npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
+ end
+ end
+ end
+ end
+ pxcmx_search=1;
+ pxcmy_search=1;
+ if isfield(XmlData,'GeometryCalib')
+ tsai=XmlData.GeometryCalib;
+ if isfield(tsai,'f') & isfield(tsai,'Tz') & isfield(tsai,'dpx') & isfield(tsai,'dpy')& isfield(tsai,'R')
+ rot2D=tsai.R([1:2],[1,2]);
+ pxcmx_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpx);
+ pxcmy_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpy);
+ end
+ if isfield(tsai,'CoordUnit')
+ CoordUnit=tsai.CoordUnit;
+ end
+ end
+ if isempty(ext_ima_read)
+ ext_ima='.png';%default
+ else
+ ext_ima=ext_ima_read;
+ end
+ if isempty(nom_type_read)
+ nom_type_ima='_i_j';
+ warndlg_uvmat('no ImageName defined in ImaDoc/Heading, take _i_j indexing by default','WARNING')
+ else
+ nom_type_ima=nom_type_read;
+ end
+
+elseif isequal(ext,'.avi')|isequal(ext,'.AVI')
+ nom_type_ima='avi';
+ ext_ima=ext;
+ set(handles.mode,'String',{'series(Di)'})
+ dt=0.04;%default
+ if exist([filebase ext],'file')==2
+ info=aviinfo([filebase ext]);%read infos on the avi movie
+ dt=1/info.FramesPerSecond;%time interval between successive frames
+ nbfield=info.NumFrames;%number of frames
+ end
+ time=(dt*[0:nbfield-1])';%list of image times
+ set(handles.dt,'String',num2str(dt*1000));%store the time interval between successive images
+
+ % no image documentation file found: look for a series of existing images or .nc files
+elseif ~isequal(ext,'.nc')
+ subdir=get(handles.subdir_civ1,'String');
+ incr_pair=[0 0];%default
+ if isfield(browse,'incr_pair')
+ incr_pair=browse.incr_pair;
+ end
+ nbdetect=0;%test of detected images
+ field_i=field_count;
+ idetect=1;
+% imagename='';%default
+ while idetect==1 %look for the maximum file number in the series
+ field_i=field_i+1;
+% imagename_last=imagename;
+ [imagename,idetect]=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
+ if isequal(nom_type_ima,'none')
+ idetect=0; %stop if the same image is repeated (if nom_type='none')
+ nbdetect=1;
+ end
+ %SEE CASE OF NETCDF FILES
+ nbdetect=nbdetect+idetect;
+ end
+% nb_field=field_i-1;% last detected field number
+ nb_field=field_i;% last detected field number
+ field_i=field_count;%look for the minimum file number in the series
+ idetect=1;
+ while idetect==1
+ field_i=field_i-1;
+ [imagename,idetect]=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
+ if isequal(nom_type_ima,'none')
+ idetect=0; %stop if the same image is repeted (if nom_type='none')
+ nbdetect=1;
+ end
+ nbdetect=nbdetect+idetect;
+ end
+ first_i=max(field_i+1,1);
+ %determine the set of times and possible intervals for CIV_3D
+ dt=(1/1000)*str2num(get(handles.dt,'String'));
+ time=(dt*[0:nb_field-1])';
+% set(handles.incr_i,'UserData',dt);%store the time interval
+% between successive images
+ %displ_num:list of possible time intervals for civ_3D calculations
+ set(handles.mode,'String',{'series(Di)'})
+end
+if isequal(nom_type_ima,'none')% no file numbering used
+ first_i=1;
+ last_i=1;
+ first_j=1;
+ last_j=1;
+end
+if exist('time','var')
+ siztime=size(time);
+ nbfield=siztime(1);
+ nbfield2=siztime(2);
+ set(handles.displ_filebase,'UserData',time); %store the set of times
+ set(handles.dt_unit,'String',['m' TimeUnit]);
+ set(handles.TimeUnit,'String',TimeUnit);
+ set(handles.nb_field,'String',num2str(nbfield));
+ set(handles.nb_field2,'String',num2str(nbfield2));
+end
+set(handles.CoordUnit,'String',[CoordUnit '/'])
+set(handles.pxcmx,'String',num2str(pxcmx));
+set(handles.pxcmy,'String',num2str(pxcmy));
+if isempty(pxcmx_search)
+ set(handles.calcul_search,'UserData',[pxcmx pxcmy]);
+else
+ set(handles.calcul_search,'UserData',[pxcmx_search pxcmy_search]);
+end
+set(handles.pxcmx,'UserData',npx);
+set(handles.pxcmy,'UserData',npy);
+set(handles.first_i,'String',num2str(first_i));
+set(handles.last_i,'String',num2str(last_i));%
+set(handles.first_j,'String',num2str(first_j));
+set(handles.last_j,'String',num2str(last_j));%
+browse.ext_ima=ext_ima;
+browse.nom_type_ima=nom_type_ima;
+set(handles.browse_root,'UserData',browse)% store the nomenclature type
+
+ %%%%%%%%%%% set the menus of image pairs and default selection for civ_3D %%%%%%%%%%%%%%%%%%%
+if isequal(get(handles.compare,'Value'),1)
+ if isequal(nom_type_ima,'_i')| isequal(nom_type_nc,'_i1-i2')|~exist('nbfield2','var')|(nbfield2==1)
+ set(handles.mode,'String',{'st_series(Di)';'displacement'})
+ set(handles.mode,'Value',1)
+ elseif (nbfield==1)% simple series in j
+ set(handles.mode,'String',{'st_series(Dj)';'displacement'})
+ set(handles.mode,'Value',1)
+ else
+ set(handles.mode,'String',{'st_pair j1-j2';'st_series(Dj)';'st_series(Di)';'displacement'})%multiple choice
+ if isequal(mode,'volume')
+ set(handles.mode,'Value',3)
+ elseif nbfield2 <= 5
+ set(handles.mode,'Value',1)% advice 'pair j1-j2' for small bursts
+ end
+ end
+else
+ if isequal(nom_type_ima,'_i')| isequal(nom_type_nc,'_i1-i2')|~exist('nbfield2','var')|(nbfield2==1)
+ set(handles.mode,'String',{'series(Di)'})
+ set(handles.mode,'Value',1)
+ elseif isequal(nom_type_ima,'png_old')|isequal(nom_type_nc,'netc_old')
+ set(handles.mode,'String',{'pair j1-j2'})
+ set(handles.mode,'Value',1)
+ elseif (nbfield==1)% simple series in j
+ set(handles.mode,'String',{'series(Dj)'})
+ set(handles.mode,'Value',1)
+ else
+ set(handles.mode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
+ if isequal(mode,'volume')
+ set(handles.mode,'Value',3)
+ elseif nbfield2 <= 5
+ set(handles.mode,'Value',1)% advice 'pair j1-j2' for small bursts
+ else
+ set(handles.mode,'Value',2)% advice series Dj for long bursts, not volume
+ end
+ end
+end
+mode_Callback(hObject, eventdata, handles)
+
+%%%%%% initialize waitbars and RUN button
+set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
+set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
+set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
+set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
+set(handles.RUN, 'Enable','On')
+set(handles.RUN,'BackgroundColor',[1 0 0])
+if isequal(test_batch,1)%if batch installation is available
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+end
+
+%%%%% store the root input filename for future opening
+dir_perso=prefdir;
+profil_perso=fullfile(prefdir,'uvmat_perso.mat');
+RootPath=fileparts(filebase);
+if exist(profil_perso,'file')
+ save (profil_perso,'RootPath','-append'); %store the root name for future opening of uvmat
+else
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
+ else
+ save (profil_perso,'RootPath'); %store the root name for future opening of uvmat
+ end
+end
+% save(profil_perso, 'filebase'); %store the root name for future opening of uvmat
+set(gcf,'Pointer','arrow')
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
+% --- Executes on button press in mode.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function mode_Callback(hObject, eventdata, handles)
+browse=get(handles.browse_root,'UserData');
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+displ_num=[];%default
+first_i=str2num(get(handles.first_i,'String'));
+% last_i=str2num(get(handles.last_i,'String'));
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+siztime=size(time);
+nbfield=siztime(1);
+nbfield2=siztime(2);
+indchosen=1; %%first pair selected by default
+if isequal(mode,'pair j1-j2')| isequal(mode,'st_pair j1-j2')
+ dt=1;
+ displ='';
+ index=0;
+ %get all the time intervals in bursts
+ displ_dt=1;%default
+ nbfield2=min(nbfield2,10),%limitate the number of pairs to 10x10
+% if nbfield2<2
+% nbfield2=2,
+% end
+ for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
+ for numod_b=(numod_a+1):nbfield2
+ index=index+1;
+ numlist_a(index)=numod_a;
+ numlist_b(index)=numod_b;
+ if ~isempty(time)
+ dt(numod_a,numod_b)=time(first_i,numod_b)-time(first_i,numod_a);%first time interval dt
+ displ_dt(index)=dt(numod_a,numod_b);
+ else
+ displ_dt(index)=1
+ end
+ end
+ end
+ [dtsort,indsort]=sort(displ_dt);
+ displ_num(1,:)=numlist_a(indsort);
+ displ_num(2,:)=numlist_b(indsort);
+ displ_num(3,:)=0;
+ displ_num(4,:)=0;
+ set(handles.jtext,'Visible','Off')
+ set(handles.first_j,'Visible','Off')
+ set(handles.last_j,'Visible','Off')
+ set(handles.incr_j,'Visible','Off')
+ set(handles.nb_field2,'Visible','Off')
+ set(handles.ref_j,'Visible','Off')
+elseif isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
+ for index=1:min(nbfield2-1,200)
+ displ_num(1,index)=-floor(index/2);
+ displ_num(2,index)=ceil(index/2);
+ displ_num(3,index)=0;
+ displ_num(4,index)=0;
+ end
+ set(handles.jtext,'Visible','On')
+ set(handles.first_j,'Visible','On')
+ set(handles.last_j,'Visible','On')
+ set(handles.incr_j,'Visible','On')
+ set(handles.nb_field2,'Visible','On')
+ set(handles.ref_j,'Visible','On')
+ if nbfield > 1
+ set(handles.itext,'Visible','On')
+ set(handles.first_i,'Visible','On')
+ set(handles.last_i,'Visible','On')
+ set(handles.incr_i,'Visible','On')
+ set(handles.nb_field,'Visible','On')
+ set(handles.ref_i,'Visible','On')
+ else
+ set(handles.itext,'Visible','Off')
+ set(handles.first_i,'Visible','Off')
+ set(handles.last_i,'Visible','Off')
+ set(handles.incr_i,'Visible','Off')
+ set(handles.nb_field,'Visible','Off')
+ set(handles.ref_i,'Visible','Off')
+ end
+elseif isequal(mode,'series(Di)') | isequal(mode,'st_series(Di)')
+ for index=1:min(nbfield-1,200)
+ displ_num(1,index)=0;
+ displ_num(2,index)=0;
+ displ_num(3,index)=-floor(index/2);
+ displ_num(4,index)=ceil(index/2);
+ end
+ set(handles.itext,'Visible','On')
+ set(handles.first_i,'Visible','On')
+ set(handles.last_i,'Visible','On')
+ set(handles.incr_i,'Visible','On')
+ set(handles.nb_field,'Visible','On')
+ set(handles.ref_i,'Visible','On')
+ if nbfield2 > 1
+ set(handles.jtext,'Visible','On')
+ set(handles.first_j,'Visible','On')
+ set(handles.last_j,'Visible','On')
+ set(handles.incr_j,'Visible','On')
+ set(handles.nb_field2,'Visible','On')
+ set(handles.ref_j,'Visible','On')
+ else
+ set(handles.jtext,'Visible','Off')
+ set(handles.first_j,'Visible','Off')
+ set(handles.last_j,'Visible','Off')
+ set(handles.incr_j,'Visible','Off')
+ set(handles.nb_field2,'Visible','Off')
+ set(handles.ref_j,'Visible','Off')
+ end
+elseif isequal(mode,'displacement')%the pairs have the same indices
+ displ_num(1,1)=0;
+ displ_num(2,1)=0;
+ displ_num(3,1)=0;
+ displ_num(4,1)=0;
+ if nbfield > 1
+ set(handles.itext,'Visible','On')
+ set(handles.first_i,'Visible','On')
+ set(handles.last_i,'Visible','On')
+ set(handles.incr_i,'Visible','On')
+ set(handles.nb_field,'Visible','On')
+ set(handles.ref_i,'Visible','On')
+ else
+ set(handles.itext,'Visible','Off')
+ set(handles.first_i,'Visible','Off')
+ set(handles.last_i,'Visible','Off')
+ set(handles.incr_i,'Visible','Off')
+ set(handles.nb_field,'Visible','Off')
+ set(handles.ref_i,'Visible','Off')
+ end
+ if nbfield2 > 1
+ set(handles.jtext,'Visible','On')
+ set(handles.first_j,'Visible','On')
+ set(handles.last_j,'Visible','On')
+ set(handles.incr_j,'Visible','On')
+ set(handles.nb_field2,'Visible','On')
+ set(handles.ref_j,'Visible','On')
+ else
+ set(handles.jtext,'Visible','Off')
+ set(handles.first_j,'Visible','Off')
+ set(handles.last_j,'Visible','Off')
+ set(handles.incr_j,'Visible','Off')
+ set(handles.nb_field2,'Visible','Off')
+ set(handles.ref_j,'Visible','Off')
+ end
+end
+set(handles.list_pair_civ1,'UserData',displ_num);
+find_netcpair_civ1(hObject, eventdata, handles)
+find_netcpair_civ2(hObject, eventdata, handles)
+
+%--------------------------------------------------------------
+% determine the menu for civ1 pairs depending on existing netcdf file at the middle of
+% the field series set by first_i, incr, last_i
+%----------------------------------------------------------------
+function find_netcpair_civ1(hObject, eventdata, handles)
+set(gcf,'Pointer','watch')
+%nomenclature types
+filebase=get(handles.displ_filebase,'String');
+[filepath,Nme,ext_dir]=fileparts(filebase);
+browse=get(handles.browse_root,'UserData');
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+% nomenclature type of the .nc files
+nom_type_ima=[];%default
+if isfield(browse,'nom_type_ima')
+ nom_type_ima=browse.nom_type_ima;
+end
+
+%determine nom_type_nc:
+nom_type_nc=[];%default
+if isfield(browse,'nom_type_nc')
+ nom_type_nc=browse.nom_type_nc;
+end
+if isequal(nom_type_ima,'png_old') | isequal(nom_type_nc,'netc_old')| isequal(nom_type_ima,'raw_SMD')
+ nom_type_nc='netc_old';%nom_type for the netcdf files
+elseif isequal(nom_type_ima,'none')|isequal(nom_type_nc,'none')
+ nom_type_nc='none';
+elseif isequal(nom_type_ima,'avi')|isequal(nom_type_ima,'_i')|isequal(nom_type_ima,'ima_num')|...
+ isequal(nom_type_nc,'_i1-i2')
+ nom_type_nc='_i1-i2';
+elseif isequal(nom_type_ima,'_i_j1-j2')||isequal(nom_type_nc,'_i1-i2_j1-j2')
+ nom_type_nc='_i1-i2_j1-j2';
+else
+ if isequal(mode,'series(Di)')|isequal(mode,'st_series(Di)')
+ nom_type_nc='_i1-i2_j'; % PIV in volume
+ else
+ nom_type_nc='_i_j1-j2';
+ end
+end
+browse.nom_type_nc=nom_type_nc;
+set(handles.browse_root,'UserData',browse)
+
+%reads .nc subdirectoy and image numbers from the interface
+subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
+first_i=str2num(get(handles.first_i,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+incr=str2num(get(handles.incr_i,'String'));
+num1=first_i:incr:last_i;
+if isempty(num1)
+ set(handles.list_pair_civ1,'String',{''});
+ return
+end
+ref_i=str2num(get(handles.ref_i,'String'));
+if isequal(mode,'pair j1-j2')|isequal(mode,'st_pair j1-j2')
+ ref_j=0;
+else
+ ref_j=str2num(get(handles.ref_j,'String'));
+end
+if isequal(get(handles.dt_text,'String'),'dt(ms)=')%simple series(Di) with equal interval
+ ref_i=floor((first_i+last_i)/2);
+ ref_j=1;
+end
+time=get(handles.displ_filebase,'UserData');%get the set of times
+if isempty(time)
+ time=[0 1];
+end
+dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
+displ_num=get(handles.list_pair_civ1,'UserData');
+
+%eliminate the first pairs inconsistent with the position
+if isempty(displ_num)
+ nbpair=0;
+else
+ nbpair=length(displ_num(1,:));%nbre of displayed pairs
+ if isequal(mode,'series(Di)') | isequal(mode,'st_series(Di)')
+ nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
+ elseif isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
+ nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
+ end
+end
+nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
+
+%look for existing processed pairs involving the field at the middle of the series if civ1 will not
+% be performed, while the result is needed for next steps.
+displ_pair={''};
+select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
+testpair=0;
+if get(handles.CIV1,'Value')==0 %
+ dirname=fullfile(filepath,subdir_civ1,ext_dir);
+ if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir')
+ hwarn=warndlg_uvmat(['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist'],'ERROR');
+ set(handles.list_pair_civ1,'String',{});
+ return
+ end
+ for ipair=1:nbpair
+ [filename,select(ipair)]=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
+ ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
+ end
+ if ~exist('select','var') | isequal(select,zeros(size(1:nbpair)))
+ if isfield(browse,'incr_pair')
+ num_i1=ref_i-floor(browse.incr_pair(1)/2);
+ num_i2=ref_i+ceil(browse.incr_pair(1)/2);
+ num_j1=ref_j-floor(browse.incr_pair(2)/2);
+ num_j2=ref_j+ceil(browse.incr_pair(2)/2);
+ [filename,select(1)]=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ1);
+ testpair=1;
+ else
+ if isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
+ hwarn=warndlg_uvmat(['no civ1 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ1],'ERROR');
+ set(hwarn,'WindowStyle','modal');
+ else
+ hwarn=warndlg_uvmat(['no civ1 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ1],'ERROR');
+ set(hwarn,'WindowStyle','modal');
+ end
+ set(handles.list_pair_civ1,'String',{''});
+ %COMPLETER CAS STEREO
+ return
+ end
+ end
+end
+if isequal(mode,'series(Di)') | isequal(mode,'st_series(Di)')
+ if testpair
+ displ_pair{1}=['Di= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
+ elseif ~isequal(get(handles.dt_text,'String'),'dt(ms)=')
+ for ipair=1:nbpair
+ if select(ipair)
+ dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+ else
+ for ipair=1:nbpair
+ if select(ipair)
+ displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt_unit*ipair)];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+ end
+elseif isequal(mode,'series(Dj)')|isequal(mode,'st_series(Dj)')% series on the j index
+ if testpair
+ displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
+ else
+ for ipair=1:nbpair
+ if select(ipair)
+ dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
+ elseif testpair
+ displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(2)/2)) '|' num2str(ceil(browse.incr_pair(2)/2))];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+ end
+elseif isequal(mode,'pair j1-j2')|isequal(mode,'st_pair j1-j2')%case of pairs
+ for ipair=1:nbpair
+ if select(ipair)
+ dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
+ ' :dt= ' num2str(dt*1000)];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+elseif isequal(mode,'displacement')
+ displ_pair={'Di=Dj=0'};
+end
+set(handles.list_pair_civ1,'String',displ_pair');
+ichoice=min(find(select));
+if (isempty(ichoice) | ichoice < 1); ichoice=1; end;
+initial=get(handles.list_pair_civ1,'Value');
+if initial>nbpair |~isequal(select(initial),1)
+ set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
+end
+set(handles.list_pair_civ2,'String',displ_pair');
+initial=get(handles.list_pair_civ2,'Value');
+if initial>nbpair |~isequal(select(initial),1)
+ set(handles.list_pair_civ2,'Value',ichoice);% same pair proposed by default for civ2
+end
+set(gcf,'Pointer','arrow')
+%--------------------------------------------------------------
+% determine the menu for civ2 pairs depending on the existing netcdf file at the
+%middle of the series set by first_i, incr, last_i
+%--------------------------------------------------------------
+function find_netcpair_civ2(hObject, eventdata, handles)
+set(gcf,'Pointer','watch')
+%nomenclature types
+filebase=get(handles.displ_filebase,'String');
+[filepath,Nme,ext_dir]=fileparts(filebase);
+browse=get(handles.browse_root,'UserData');
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+
+% nomenclature type of the .nc files
+nom_type_ima='ima_num';%default
+if isfield(browse,'nom_type_ima')
+ nom_type_ima=browse.nom_type_ima;
+end
+nom_type_nc='_i1-i2';%default
+if isfield(browse,'nom_type_nc')
+ nom_type_nc=browse.nom_type_nc;
+end
+if isequal(nom_type_ima,'png_old') | isequal(nom_type_ima,'netc_old')| isequal(nom_type_ima,'raw_SMD')| isequal(nom_type_nc,'netc_old')
+ nom_type_nc='netc_old';%nom_type for the netcdf files
+elseif isequal(nom_type_ima,'none')|isequal(nom_type_nc,'none')
+ nom_type_nc='none';
+elseif isequal(nom_type_ima,'avi')|isequal(nom_type_ima,'_i')|isequal(nom_type_ima,'ima_num')|isequal(nom_type_nc,'_i1-i2')
+ nom_type_nc='_i1-i2';
+else
+ if isequal(mode,'series(Di)')|isequal(mode,'st_series(Di)')
+ nom_type_nc='_i1-i2_j'; % PIV in volume
+ else
+ nom_type_nc='_i_j1-j2';
+ end
+end
+browse.nom_type_nc=nom_type_nc;
+set(handles.browse_root,'UserData',browse)
+
+%reads .nc subdirectory and image numbers from the interface
+subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
+subdir_civ2=get(handles.subdir_civ2,'String');%subdirectory subdir_civ2 for the netcdf data
+first_i=str2num(get(handles.first_i,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+incr=str2num(get(handles.incr_i,'String'));
+num1=first_i:incr:last_i;
+if isempty(num1)
+ set(handles.list_pair_civ2,'String',{});
+ return
+end
+ref_i=str2num(get(handles.ref_i,'String'));
+if isequal(mode,'pair j1-j2')|isequal(mode,'st_pair j1-j2')
+ ref_j=0;
+else
+ ref_j=str2num(get(handles.ref_j,'String'));
+end
+if isequal(get(handles.dt_text,'String'),'dt(ms)=')%simple series(Di) with equal interval
+ ref_i=ceil((first_i+last_i)/2);
+ ref_j=1;
+end
+% ref_i=browse.num_ref;%field number initially selected by the browser
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+if isempty(time)
+ time=[0 1];%default
+end
+dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
+displ_num=get(handles.list_pair_civ1,'UserData');
+
+
+%eliminate the first pairs inconsistent with the position
+if isempty(displ_num)
+ nbpair=0;
+else
+ nbpair=length(displ_num(1,:));%nbre of displayed pairs
+ if isequal(mode,'series(Di)') | isequal(mode,'st_series(Di)')
+ nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
+ elseif isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
+ nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
+ end
+end
+nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
+
+%look for existing processed pairs involving the field at the middle of the series if civ1 will not
+% be performed, while the result is needed for next steps.
+displ_pair={''}; %default
+select=ones(size(1:nbpair));%default =1 for nubers of displayed pairs
+if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0%&...
+ if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
+ errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
+ set(handles.list_pair_civ2,'String',{});
+ return
+ end
+ for ipair=1:nbpair
+ [filename,select(ipair)]=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
+ ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
+ end
+ if isequal(select,zeros(size(1:nbpair)))
+ if isfield(browse,'incr_pair')
+ num_i1=ref_i-floor(browse.incr_pair(1)/2);
+ num_i2=ref_i+floor((browse.incr_pair(1)+1)/2);
+ num_j1=ref_j-floor(browse.incr_pair(2)/2);
+ num_j2=ref_j+floor((browse.incr_pair(2)+1)/2);
+ [filename,select(1)]=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
+ else
+ if isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
+ errordlg(['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
+ else
+ errordlg(['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
+ end
+ set(handles.list_pair_civ2,'String',{});
+ return
+ end
+ end
+end
+if isequal(mode,'series(Di)') | isequal(mode,'st_series(Di)')
+ if ~isequal(get(handles.dt_text,'String'),'dt(ms)=')
+ for ipair=1:nbpair
+ if select(ipair)
+ dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+ else
+ for ipair=1:nbpair
+ if select(ipair)
+ displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt_unit*ipair)];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+ end
+elseif isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)') % series on the j index
+ for ipair=1:nbpair
+ if select(ipair)
+ dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+elseif isequal(mode,'pair j1-j2') | isequal(mode,'st_pair j1-j2') %case of pairs
+ for ipair=1:nbpair
+ if select(ipair)
+ dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
+ displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
+ ' :dt= ' num2str(dt*1000)];
+ else
+ displ_pair{ipair}='...'; %pair not displayed in the menu
+ end
+ end
+elseif isequal(mode,'displacement')
+ displ_pair={'Di=Dj=0'};
+end
+set(handles.list_pair_civ2,'String',displ_pair');
+ichoice=min(find(select));
+if (isempty(ichoice) | ichoice < 1); ichoice=1; end;
+if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
+ set(handles.list_pair_civ2,'Value',ichoice);% first valid pair proposed by default in the menu
+end
+set(gcf,'Pointer','arrow')
+%----------------------------------------------------
+% determine the list of index pairs of processing file
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
+ find_pair_indices(handles,mode)
+first_i=str2num(get(handles.first_i,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+incr=str2num(get(handles.incr_i,'String'));
+first_j=str2num(get(handles.first_j,'String'));
+last_j=str2num(get(handles.last_j,'String'));
+incr_j=str2num(get(handles.incr_j,'String'));
+list_civ1=get(handles.list_pair_civ1,'String');
+index_civ1=get(handles.list_pair_civ1,'Value');
+str_civ1=list_civ1{index_civ1};
+list_civ2=get(handles.list_pair_civ2,'String');
+index_civ2=get(handles.list_pair_civ2,'Value');
+str_civ2=list_civ2{index_civ2};
+if isequal(first_i,[])|isequal(first_j,[]), errordlg('first field number not defined'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+if isequal(last_i,[])| isequal(last_j,[]),errordlg('last field number not defined'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+if isequal(incr,[])| isequal(incr_j,[]),errordlg('increment in field number not defined'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+if last_i < first_i | last_j < first_j , errordlg('last field number must be larger than the first one'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+num1=[first_i:incr:last_i];
+num_j=[first_j:incr_j:last_j];
+if isequal (mode,'series(Di)') |isequal(mode,'st_series(Di)')
+ %recognize the pair civ1 from the display
+ indsel=find((double(str_civ1)<48)|(double(str_civ1)>57));% character indices of non numerical characters
+ str_raw=str_civ1(indsel);
+ indsepar=find(str_raw=='|'); %character index of the separator
+ d1=str2num(str_civ1([indsel(indsepar-1)+1:indsel(indsepar)-1]));
+ if indsepar==length(str_raw)
+ d2=str2num(str_civ1([indsel(indsepar)+1:end]));
+ else
+ d2=str2num(str_civ1([indsel(indsepar)+1:indsel(indsepar+1)-1]));
+ end
+ %recognize the pair civ2 from the display
+ num1_civ1=num1-d1;% set of first image numbers
+ num2_civ1=num1+d2;
+ num_a_civ1=num_j;
+ num_b_civ1=num_j;
+ num1_civ2=num1-floor(index_civ2/2)*ones(size(num1));% set of first image numbers
+ num2_civ2=num1+ceil(index_civ2/2)*ones(size(num1));
+ num1_civ2=num1-d1;% set of first image numbers
+ num2_civ2=num1+d2;
+ num_a_civ2=num_j;
+ num_b_civ2=num_j;
+ % adjust the first and last field number
+ lastfield=str2num(get(handles.nb_field,'String'));
+ if isequal(lastfield,[])
+ indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
+ else
+ indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
+ end
+ if length(indsel)>=1
+ firstind=indsel(1);
+ lastind=indsel(end);
+ set(handles.first_i,'String',num2str(num1(firstind)))%update the display of first and last fields
+ set(handles.last_i,'String',num2str(num1(lastind)))
+ num1=num1(indsel);
+ num1_civ1=num1_civ1(indsel);
+ num1_civ2=num1_civ2(indsel);
+ num2_civ1=num2_civ1(indsel);
+ num2_civ2=num2_civ2(indsel);
+ end
+elseif isequal (mode,'series(Dj)')|isequal (mode,'st_series(Dj)')
+ lastfield_j=str2num(get(handles.nb_field2,'String'));
+ num1_civ1=num1;% set of first image numbers
+ num2_civ1=num1;
+ num_a_civ1=num_j-floor(index_civ1/2)*ones(size(num_j));
+ num_b_civ1=num_j+ceil(index_civ1/2)*ones(size(num_j));
+ num1_civ2=num1;
+ num2_civ2=num1;
+ num_a_civ2=num_j-floor(index_civ2/2)*ones(size(num_j));
+ num_b_civ2=num_j+ceil(index_civ2/2)*ones(size(num_j));
+ % adjust the first and last field number
+ if isequal(lastfield_j,[])
+ indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
+ else
+ indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
+ end
+ if length(indsel)>=1
+ firstind=indsel(1);
+ lastind=indsel(end);
+ set(handles.first_j,'String',num2str(num_j(firstind)))%update the display of first and last fields
+ set(handles.last_j,'String',num2str(num_j(lastind)))
+ num_j=num_j(indsel);
+ num_a_civ1=num_a_civ1(indsel);
+ num_a_civ2=num_a_civ2(indsel);
+ num_b_civ1=num_b_civ1(indsel);
+ num_b_civ2=num_b_civ2(indsel);
+ end
+elseif isequal(mode,'pair j1-j2') | isequal(mode,'st_pair j1-j2') %case of bursts (png_old or png_2D)
+ num1_civ1=num1;
+ num1_civ2=num1;
+ displ_num=get(handles.list_pair_civ1,'UserData');
+ num2_civ1=num1;
+ num_a_civ1=displ_num(1,index_civ1);
+ num_b_civ1=displ_num(2,index_civ1);
+ num2_civ2=num1;
+ num_a_civ2=displ_num(1,index_civ2);
+ num_b_civ2=displ_num(2,index_civ2);
+elseif isequal(mode,'displacement')
+ num1_civ1=num1;
+ num2_civ1=num1;
+ num_a_civ1=num_j;
+ num_b_civ1=num_j;
+ num1_civ2=num1;
+ num2_civ2=num1;
+ num_a_civ2=num_j;
+ num_b_civ2=num_j;
+end
+
+
+%-------------------------------------------------------------
+% --- Executes on selection change in list_pair_civ1.
+function list_pair_civ1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------
+%reproduce by default the chosen pair in the civ2 menu
+list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
+index_pair=get(handles.list_pair_civ1,'Value');
+displ_num=get(handles.list_pair_civ1,'UserData');
+num_a=displ_num(1,index_pair);
+num_b=displ_num(2,index_pair);
+set(handles.list_pair_civ2,'Value',index_pair);
+
+%update first_i and last_i according to the chosen image pairs
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+if isequal(mode,'series(Di)')
+ first_i=str2num(get(handles.first_i,'String'));
+ last_i=str2num(get(handles.last_i,'String'));
+ incr_i=str2num(get(handles.incr_i,'String'));
+ num1=first_i:incr_i:last_i;
+ lastfield=str2num(get(handles.nb_field,'String'));
+ if ~isequal(lastfield,[])
+ ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
+ (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
+ num1=num1(ind);
+ end
+ set(handles.first_i,'String',num2str(num1(1)));
+ set(handles.last_i,'String',num2str(num1(end)));
+elseif isequal(mode,'series(Dj)')
+ first_j=str2num(get(handles.first_j,'String'));
+ last_j=str2num(get(handles.last_j,'String'));
+ incr_j=str2num(get(handles.incr_j,'String'));
+ num_j=first_j:incr_j:last_j;
+ lastfield2=str2num(get(handles.nb_field2,'String'));
+ if ~isequal(lastfield2,[])
+ ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
+ (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
+ num1=num_j(ind);
+ end
+ set(handles.first_j,'String',num2str(num1(1)));
+ set(handles.last_j,'String',num2str(num1(end)));
+end
+
+%------------------------------------------------------------------
+% --- Executes on selection change in list_pair_civ2.
+function list_pair_civ2_Callback(hObject, eventdata, handles)
+
+index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu
+
+%update first_i and last_i according to the chosen image pairs
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+if isequal(mode,'series(Di)')
+ first_i=str2num(get(handles.first_i,'String'));
+ last_i=str2num(get(handles.last_i,'String'));
+ incr_i=str2num(get(handles.incr_i,'String'));
+ num1=first_i:incr_i:last_i;
+ lastfield=str2num(get(handles.nb_field,'String'));
+ if ~isequal(lastfield,[])
+ ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
+ (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
+ num1=num1(ind);
+ end
+ set(handles.first_i,'String',num2str(num1(1)));
+ set(handles.last_i,'String',num2str(num1(end)));
+elseif isequal(mode,'series(Dj)')
+ first_j=str2num(get(handles.first_j,'String'));
+ last_j=str2num(get(handles.last_j,'String'));
+ incr_j=str2num(get(handles.incr_j,'String'));
+ num_j=first_j:incr_j:last_j;
+ lastfield2=str2num(get(handles.nb_field2,'String'));
+ if ~isequal(lastfield2,[])
+ ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
+ (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield));
+ num1=num_j(ind);
+ end
+ set(handles.first_j,'String',num2str(num1(1)));
+ set(handles.last_j,'String',num2str(num1(end)));
+end
+
+
+
+
+%-----------------------------------------------------------
+% --- Executes on button press in BATCH: remote processing
+%-----------------------------------------------------------
+function BATCH_Callback(hObject, eventdata, handles)
+global civ1_exe civ2_exe patch_exe patch_new_exe fix_exe todo_path sge Civ_exe
+
+pxcmx=get(handles.pxcmx,'String');
+pxcmy=get(handles.pxcmy,'String');
+npx=get(handles.pxcmx,'UserData');
+npy=get(handles.pxcmy,'UserData');
+
+%check the list of operations:
+operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
+run_flag=1;
+box_test(1)=get(handles.CIV1,'Value');
+box_test(2)=get(handles.FIX1,'Value');
+box_test(3)=get(handles.PATCH1,'Value');
+box_test(4)=get(handles.CIV2,'Value');
+box_test(5)=get(handles.FIX2,'Value');
+box_test(6)=get(handles.PATCH2,'Value');
+index=find(box_test==1);
+if isempty(index)
+ errordlg('no selected operation')
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+end
+index_first=min(index);
+index_last=max(index);
+box_used=box_test([index_first : index_last]);
+[box_missing,ind_missing]=min(box_used);
+if isequal(box_missing,0)
+ errordlg(['missing' cell2mat(operations(ind_missing))]);
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+end
+
+%check mask if selecetd
+if isequal(get(handles.get_mask_civ1,'Value'),1)
+ get_mask_civ1_Callback(hObject, eventdata, handles);
+end
+if isequal(get(handles.get_mask_fix1,'Value'),1)
+ get_mask_fix1_Callback(hObject, eventdata, handles);
+end
+if isequal(get(handles.get_mask_civ2,'Value'),1)
+ get_mask_civ2_Callback(hObject, eventdata, handles);
+end
+if isequal(get(handles.get_mask_fix2,'Value'),1)
+ get_mask_fix2_Callback(hObject, eventdata, handles);
+end
+
+
+%read names of the .exe file
+path_uvmat=which('uvmat');% check the path detected for source file uvmat
+path_UVMAT=fileparts(path_uvmat); %path to UVMAT
+if isunix
+ %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ_3D binary names
+ xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml');
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+else
+ %fid = fopen(fullfile(path_UVMAT,'PARAM_WIN.txt'),'r');%open the file with civ_3D binary names
+ xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+end
+ sge=0;
+if isfield(sparam,'Civ_exe')
+ Civ_exe=sparam.Civ_exe
+end
+if isfield(sparam,'Civ1_exe')
+ civ1_exe=sparam.Civ1_exe
+end
+if isfield(sparam,'Civ2_exe')
+ civ2_exe=sparam.Civ2_exe
+end
+if isfield(sparam,'Patch_exe')
+ patch_exe=sparam.Patch_exe
+end
+if isfield(sparam,'PatchNew_exe')
+ patch_new_exe=sparam.PatchNew_exe
+end
+if isfield(sparam,'Fix_exe')
+ fix_exe=sparam.Fix_exe
+end
+if isfield(sparam,'Todo_path')
+ todo_path=sparam.Todo_path
+end
+if isfield(sparam,'SGE')
+ sge=str2num(sparam.SGE)
+end
+%choice of batch priority
+ind_answer=2;
+if sge
+ [s,w]=unix('qstat -q civ_3D.q|grep job_| wc -l'); %check the waiting list (command unix)
+ if isequal(s,0)
+ w(end)=[];
+ str_displ={[w ' jobs in the waiting list'];'Select a priority:'};
+ str={'urgent';'normal';'low'};
+ [ind_answer,v] = listdlg('PromptString',str_displ,...
+ 'SelectionMode','single',...
+ 'ListString',str,'ListSize',[200 200],'Name','job priority','InitialValue',3);
+ if isequal(v,0) % to handle Cancel button and figure close,
+ return % a better way should be create
+ end
+ else
+ warndlg_uvmat('batch system not available','ERROR')
+ return
+ end
+end
+%initialize the waitbars
+set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
+set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
+set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
+set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
+set(handles.BATCH, 'Enable','Off')
+set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
+
+%get the filename root, nomenclature and numbers
+filebase=get(handles.displ_filebase,'String');
+% for Windows system find the UBC path name if needed
+if ~isunix & isequal(todo_path(1:2),'\\') & isequal(filebase(2:3),':\')
+ cur_dir=pwd;
+ if ~isequal(cur_dir(2:3),':\')
+ cd(matlabroot); %move to the Matlab root directory if the current Matlab dir does not allow the dos command or is M:
+ end
+ [ss,ww]=dos(['net use ' filebase(1:2)]);
+ if isequal(ss,0)
+ rankpath=findstr(ww,'\\');
+ if ~isempty(rankpath)
+ wwrest=ww(rankpath:end);
+ rankend=min(find(double(wwrest)==10))-1;
+ filebase=[wwrest(1:rankend) filebase(3:end)];
+ set(handles.displ_filebase,'String',filebase);
+ end
+ else
+ warndlg_uvmat('for BATCH option, UBC file names, beginning by \\, are needed','ERROR');
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+end
+browse=get(handles.browse_root,'UserData')
+ext_ima=browse.ext_ima;
+nom_type_nc='_i1-i2';
+nom_type_ima=browse.nom_type_ima;
+% nom_type_nc=browse.nom_type_nc;
+% if isequal(nom_type_ima2,[]),nom_type_ima2='ima_num';end; %default
+% if isequal(nom_type_nc,[]),nom_type_nc='_i1-i2';end; %default
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+
+[num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
+find_pair_indices(handles,mode); %determine the pairs of processing file
+
+%check dir
+subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf output data
+subdir_civ2=get(handles.subdir_civ2,'String');
+if isequal(subdir_civ1,''),subdir_civ1='A'; end% put default subdir
+if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
+currentdir=pwd;%store the current working directory
+[Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ_3D)
+if ~exist(Path_ima,'dir')
+ warndlg_uvmat(['path to images ' Path_ima ' not found'],'ERROR')
+ return
+end
+cd(Path_ima);%move to the directory of the images
+dircur=pwd; %current working directory
+m2='';
+[erread,message]=fileattrib(Path_ima);
+if ~isempty(message) & ~isequal(message.UserWrite,1)
+ errordlg(['No writting access to ' Path_ima])
+ cd(currentdir)
+ return
+end
+
+%test for reference file in fix
+ref_fix1=get(handles.ref_fix1,'UserData');
+ref_fix2=get(handles.ref_fix2,'UserData');
+if (~isempty(ref_fix1) & box_test(2)==1)|(~isempty(ref_fix2) & box_test(5)==1)
+ errordlg('reference file not implemented in BATCH mode, use RUN')
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+end
+nbfield=length(num1_civ1);
+nbslice=length(num_a_civ1);
+
+%check the existence of the netcdf and image files involved
+% if box_test(1)==1;%CIV1 activated
+detect=1;
+while detect==1 %name a new subdir if one of the netcdf files already exists
+ for ifile=1:nbfield
+% for j=1:nbslice
+ [filename,detect]=name_generator(filebase,num1_civ1(ifile),[],'.nc',...
+ nom_type_nc,1,num2_civ1(ifile),[],subdir_civ1);%
+ if detect==1% if a netcdf file already exists
+ subdir_civ1=[subdir_civ1 '.0'];
+ subdir_civ2=subdir_civ1;
+ break
+ end
+ filecell_nc1(ifile)={filename};
+ if detect==1% if a netcdf file already exists
+ break
+ end
+ end
+ %create the new subdir_civ1 if it does not exist
+ if ~exist(fullfile(Path_ima,subdir_civ1),'dir')
+ [m1,m2,m3]=mkdir(subdir_civ1)
+ if ~isequal(m2,'')
+ msgbox(m2);%error message for directory creation
+ end
+ end
+end
+%get image names
+for ifile=1:nbfield
+ [filecell_ima1_civ1{ifile},idetect]=name_generator(filebase, num1_civ1(ifile),[],ext_ima,nom_type_ima);%first image
+ [filecell_ima2_civ1{ifile},idetect_1]=name_generator(filebase, num2_civ1(ifile),[],ext_ima,nom_type_ima); %second image
+ if idetect==0
+ warndlg_uvmat([filecell_ima1_civ1{ifile} ' not found'],'ERROR')
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ cd(currentdir)
+ return
+ end
+ if idetect_1==0,
+ errordlg([filecell_ima2_civ1{ifile} ' not found'])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ cd(currentdir)
+ return
+ end
+end
+
+cd(currentdir);%come back to the initial working directory
+% if ~isequal(m2,'')
+% msgbox(m2);%error message for directory creation
+% end
+set(handles.subdir_civ1,'String',subdir_civ1);%update the edit box
+set(handles.subdir_civ2,'String',subdir_civ2);%update the edit box
+browse.nom_type_nc=nom_type_nc;
+set(handles.browse_root,'UserData',browse);%update the nomenclature type for uvmat
+
+%COPY IMAGES TO THE FORMAT .vol IF NEEDED
+if isequal(nom_type_ima,'avi')
+ nom_type_imanew='_i';
+else
+ nom_type_imanew=nom_type_ima;
+end
+
+if ~isequal(ext_ima,'.vol')
+ if box_test(1)==1 %if civ1 is performed
+ h = waitbar(0,['copy images to the .png format for civ1']);% display a wait bar
+ for ifile=1:nbfield
+ waitbar(ifile/nbfield);
+ Atot=[];
+ [filename_A,idetect_cur]=name_generator(filebase,num1_civ1(ifile),1,'.png','_i');%A VOIR
+ for j=1:nbslice
+ if idetect_cur==0
+ A=read_image(cell2mat(filecell_ima1_civ1(ifile,j)),nom_type_ima2,npx,npy,num1_civ1(ifile));
+ Atot=[Atot;A];
+ %imwrite(A,filename,'BitDepth',16);
+ end
+ end
+ imwrite(Atot,filename_A,'BitDepth',16);
+ %filecell_ima1_civ1(ifile,j)={filename};
+ Atot=[];
+ [filename_B,idetect_cur]=name_generator(filebase, num2_civ1(ifile),1,'.png','_i');
+ for j=1:nbslice
+ if idetect_cur==0
+ A=read_image(cell2mat(filecell_ima2_civ1(ifile,j)),nom_type_ima2,npx,npy,num2_civ1(ifile));
+ Atot=[Atot;A];
+% imwrite(A,filename,'BitDepth',16);
+ end
+ %filecell_ima2_civ1(ifile,j)={filename};
+ end
+ imwrite(Atot,filename_B,'BitDepth',16);
+ end
+ close(h)
+ end
+end
+
+if ~sge
+ %OPEN THE WAIT LIST FOR BATCH PROCESSES
+ name_lock=fullfile(todo_path,'lock'); %lock file
+ iwait=0;
+ while(exist(name_lock) & iwait<15)
+ pause(1); %wait 1 second
+ iwait=iwait+1;
+ end
+ if iwait==15
+ errordlg(['I''m tired to wait for the lock file, please delete it then click again on BATCH' name_lock ])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return
+ end
+ p0=fopen(name_lock,'w'); %create the file name_lock: prevents other users to interfere
+ name_todo=fullfile(todo_path,'TODO.txt');
+ p1=fopen(name_todo,'a');
+ if (p1<0)
+ errordlg(['error in opening ' name_todo])
+ set(handles.BATCH, 'Enable','On')
+ set(handles.BATCH,'BackgroundColor',[1 0 0])
+ return;
+ end
+end
+
+for ifile=1:nbfield
+ i_cmd=0;
+ cmd='';
+ if sge
+ cmd='#!/bin/bash';
+ cmd=char({cmd;'#$ -cwd'});
+ cmd=char({cmd;'hostname && date'});
+ end
+ filename_cmx=cell2mat(filecell_nc1(ifile));%output netcdf file
+ filename_cmx([end-1:end])='cm';%name of cmx file
+ filename_cmx=[filename_cmx 'x'];
+
+%CIV1
+ if box_test(1)==1
+ %GET civ_3D PARAMETERS:
+ par_civ1=read_param_civ1(handles,cell2mat(filecell_ima1_civ1(1,1)));
+ p1text=[];
+ [par_civ1.path,resu_file,resu_ext]=fileparts(filecell_nc1{ifile});
+ par_civ1.volume1=filecell_ima1_civ1{ifile};
+ par_civ1.volume2=filecell_ima2_civ1{ifile}
+ par_civ1.nx=1024;
+ par_civ1.ny=1024;
+ par_civ1.nz=par_civ1.gridLimits_Zmax - par_civ1.gridLimits_Zmin;
+ 'TEST'
+ par_civ1
+ % civAll=get(handles.Experimental,'Value'); % Boolean for new civ excution method
+ % if isequal(civAll,1)
+ civAllxml=struct2xml(par_civ1);% xml contents, all parameters
+ civAllxml=set(civAllxml,1,'name','civ3d3c');
+ % save(civAllxml)
+ par_civ1_3d_xml=fullfile(par_civ1.path,[resu_file '.xml']);%[par_civ1.path '/test_to_change.xml'];
+ pvalue=num2str((1-ind_answer)*500);
+ save(civAllxml,par_civ1_3d_xml);
+ if(isunix && sge)
+ ['echo /CIVX/bin/MPI/lam-7.1.3_g95/bin/mpirun C /CIVX/bin/civ3d3c -p ' par_civ1_3d_xml '|qsub -p ' pvalue ' -q lam.q -pe lam_loose 16 -e ' par_civ1_3d_xml '.errors -o ' par_civ1_3d_xml '.log' ]
+ eval ( ['!echo /CIVX/bin/MPI/lam-7.1.3_g95/bin/mpirun C /CIVX/bin/civ3d3c -p ' par_civ1_3d_xml '|qsub -p ' pvalue ' -q lam.q -pe lam_loose 16 -e ' par_civ1_3d_xml '.errors -o ' par_civ1_3d_xml '.log' ])
+ else
+ '3D mode is NOT supported without sge'
+ end
+ return
+ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % fichier xml produit
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % A CONTINUER
+ %civAllxml
+ civAllCmd=[];
+ civAllxml=set(civAllxml,1,'name','civ3d3c');
+ namelog=[filename_cmx([1:end-3]) 'log'];
+ %par_civ1.Dt=num2str(time(num2_civ1(ifile),num_b_civ1(j))-time(num1_civ1(ifile),num_a_civ1(1)));
+ %par_civ1.T0=num2str((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(1)))/2);
+ % test_mask=get(handles.get_mask_civ1,'Value');
+ i_cmd=i_cmd+1;
+% if isequal(civAll,0)
+% cmd=char({cmd;BATCH_CIV1(filename_cmx([1:end-4]),namelog,par_civ1,handles)});
+% else
+ civAllCmd=[civAllCmd ' civ1 '];
+ str=BATCH_CIV1_Unified(filename_cmx([1:end-4]),namelog,par_civ1,handles);
+ fieldnames=fields(str);
+ [civAllxml,uid_civ1]=add(civAllxml,1,'element','civ1');
+ for ilist=1:length(fieldnames)
+ val=eval(['str.' fieldnames{ilist}]);
+ if ischar(val)
+ [civAllxml,uid_t]=add(civAllxml,uid_civ1,'element',fieldnames{ilist});
+ [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+ end
+ end
+% end
+ end
+ if(isunix)
+ cmd=char({cmd ; ['cp -f ' filename_cmx '2 ' filename_cmx]; cmd_CIV2});
+ else
+ cmd=char({cmd ; ['copy /Y ' filename_cmx '2 ' filename_cmx]; cmd_CIV2});
+ end
+end
+
+% if isequal(civAll,1)
+ save(civAllxml,[filename_cmx([1:end-4]) '.xml']);
+ cmd=char({cmd;[Civ_exe ' -f ' [filename_cmx([1:end-4]) '.xml'] ' ' civAllCmd]});
+
+ %save(civAllxml,'/tmp/test.xml');
+% end
+
+
+% create the .bat file:
+if sge
+ [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
+ filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
+else
+ filename_bat=filename_cmx;
+end
+filename_bat(end-2:end)='bat';
+
+% pbat=fopen(filename_bat,'w'); %create the file filename_bat
+dlmwrite(filename_bat,cmd,'');%write commands in filename_bat
+if sge
+ pvalue=num2str((1-ind_answer)*500);
+ namelog=[filename_bat '.patch.log'];
+ ['!qsub -p ' pvalue ' -q civ_3D.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat];
+ eval( ['!qsub -p ' pvalue ' -q civ_3D.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
+else
+ if(isunix)
+ cmdtodo=['. ' filename_bat ];%removed for Mathieu tests %' && rm -f ' filename_bat] ;
+ else
+% cmdtodo=[filename_bat ' && del /F /Q ' filename_bat];
+ cmdtodo=[filename_bat];%removed for Mathieu tests %' && del /F /Q ' filename_bat' ;
+ end
+ count= fprintf(p1,'%s\n', cmdtodo);
+end
+if ~sge
+ fclose(p1);
+ fclose(p0);
+ delete(name_lock);
+end
+set(handles.BATCH, 'Enable','On')
+set(handles.BATCH,'BackgroundColor',[1 0 0])
+%save interface state
+[Path,Name]=fileparts(filebase);
+namefig=fullfile(Path,subdir_civ2,Name);
+detect=1;
+while detect==1
+ namefigfull=[namefig '.fig'];
+ hh=dir(namefigfull);
+ if ~isempty(hh)
+ detect=1;
+ namefig=[namefig '.0'];
+ else
+ detect=0;
+ end
+end
+saveas(gcbf,namefigfull);%save the interface with name namefigfull
+
+
+%----------------------------------------
+%PATCH
+%---------------------------------------
+function cmd_PATCH=RUN_PATCH(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp)
+global patch_exe patch_new_exe
+ namelog=[filename_nc([1:end-3]) '_patch.log'];
+ if test_interp==0
+ cmd_PATCH=[patch_exe ' -f ' filename_nc ' -m ' nx_patch ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
+ ' > ' namelog ' 2>&1'] % redirect standard output to the log file
+ else %nouveau programme patch
+ cmd_PATCH=[patch_new_exe ' -f ' filename_nc ' -m ' nx_patch ' -n ' ny_patch ' -ro ' rho_patch ...
+ ' -max ' thresh_value ' -nopt ' subdomain_patch ' > ' namelog ' 2>&1']; % redirect standard output to the log file
+ end
+
+
+%----------------------------------------------------
+function first_j_Callback(hObject, eventdata, handles)
+last_j_Callback(hObject, eventdata, handles)
+
+%---------------------------------------------------------
+% --- Executes on button press in CIV1.
+function CIV1_Callback(hObject, eventdata, handles)
+enable_civ1(handles,get(handles.CIV1,'Value'))
+find_netcpair_civ1(hObject, eventdata, handles);
+
+%------------------------------------------------------
+% --- Executes on button press in FIX1.
+function FIX1_Callback(hObject, eventdata, handles)
+
+if get(handles.FIX1,'Value')==1
+enable_fix1(handles)
+else
+desable_fix1(handles)
+end
+
+%----------------------------------------------------------------
+% --- Executes on button press in PATCH1.
+function PATCH1_Callback(hObject, eventdata, handles)
+
+if get(handles.PATCH1,'Value')==1
+enable_patch1(handles)
+else
+desable_patch1(handles)
+end
+
+%----------------------------------------------------------
+% --- Executes on button press in CIV2.
+function CIV2_Callback(hObject, eventdata, handles)
+state=get(handles.CIV2,'Value');
+enable_civ2(handles,state)
+if state
+ find_netcpair_civ2(hObject, eventdata, handles)
+end
+
+%---------------------------------------------------
+% --- Executes on button press in FIX2.
+function FIX2_Callback(hObject, eventdata, handles)
+if get(handles.FIX2,'Value')==1
+ enable_fix2(handles)
+ if get(handles.CIV2,'Value')==0
+ find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
+ end
+else
+ desable_fix2(handles)
+end
+
+
+%-------------------------------------------------------
+% --- Executes on button press in PATCH2.
+function PATCH2_Callback(hObject, eventdata, handles)
+%--------------------------------------------------------
+if get(handles.PATCH2,'Value')==1
+ enable_patch2(handles)
+ if get(handles.CIV2,'Value')==0
+ find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
+ end
+else
+ desable_patch2(handles)
+end
+
+
+
+%-----------------------------------------------------------
+function first_i_Callback(hObject, eventdata, handles)
+%------------------------------------------------------
+last_i_Callback(hObject, eventdata, handles)
+
+%-----------------------------------------------------------
+% --- Executes on button press in calcul_search: determine the search range isx,isy
+%--------------------------------------------------------
+function calcul_search_Callback(hObject, eventdata, handles)
+
+%determine pair numbers
+list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
+index=get(handles.list_pair_civ1,'Value');
+displ_num=get(handles.list_pair_civ1,'UserData');
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+pxcm_xy=get(handles.calcul_search,'UserData')
+pxcmx=pxcm_xy(1);
+pxcmy=pxcm_xy(2);
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+if isequal (mode, 'series(Di)' )
+ ref_i=str2num(get(handles.ref_i,'String'));
+ num1=ref_i-floor(index/2);% first image numbers
+ num2=ref_i+ceil(index/2);
+ num_a=1;
+ num_b=1;
+elseif isequal (mode, 'series(Dj)')
+ num1=1;
+ num2=1;
+ ref_j=str2num(get(handles.ref_j,'String'));
+ num_a=ref_j-floor(index/2);% first image numbers
+ num_b=ref_j+ceil(index/2);
+elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
+ ref_i=str2num(get(handles.ref_i,'String'));
+ num1=ref_i;
+ num2=ref_i;
+ num_a=displ_num(1,index);
+ num_b=displ_num(2,index);
+end
+dt=time(num2,num_b)-time(num1,num_a);
+ibx=str2num(get(handles.ibx,'String'));
+iby=str2num(get(handles.iby,'String'));
+umin=dt*pxcmx*str2num(get(handles.umin,'String'));
+umax=dt*pxcmx*str2num(get(handles.umax,'String'));
+vmin=dt*pxcmy*str2num(get(handles.vmin,'String'));
+vmax=dt*pxcmy*str2num(get(handles.vmax,'String'));
+shiftx=round((umin+umax)/2);
+shifty=round((vmin+vmax)/2);
+isx=(umax+2-shiftx)*2+ibx;
+isx=2*ceil(isx/2)+1;
+isy=(vmax+2-shifty)*2+iby;
+isy=2*ceil(isy/2)+1;
+set(handles.shiftx,'String',num2str(shiftx));
+set(handles.shifty,'String',num2str(shifty));
+set(handles.isx,'String',num2str(isx));
+set(handles.isy,'String',num2str(isy));
+
+
+%---------------------------------------------------------
+% Executes on carriage return on the subdir civ1 edit window
+%--------------------------------------------------------
+function subdir_civ1_Callback(hObject, eventdata, handles)
+subdir=get(handles.subdir_civ1,'String');
+set(handles.subdir_civ2,'String',subdir);
+if get(handles.CIV1,'Value')==0
+ find_netcpair_civ1(hObject, eventdata, handles); %update the list of available pairs from netcdf files in the new directory
+end
+
+%---------------------------------------------------------
+% Executes on carriage return on the subdir civ1 edit window
+%---------------------------------------------------------
+function subdir_civ2_Callback(hObject, eventdata, handles)
+%update the list of available pairs from netcdf files in the new directory
+if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
+ find_netcpair_civ2(hObject, eventdata, handles);
+end
+
+%------------------------------------------------------
+% --- Executes on button press in get_mask_civ1.
+%------------------------------------------------------
+function get_mask_civ1_Callback(hObject, eventdata, handles)
+maskval=get(handles.get_mask_civ1,'Value')
+if isequal(maskval,0)
+ set(handles.mask_civ1,'String','')
+else
+mask_displ='no mask'; %default
+filebase=get(handles.displ_filebase,'String');
+[ nbslice, flag_mask]=get_mask(filebase,handles)
+if isequal(flag_mask,1)
+ mask_displ=[num2str(nbslice) 'mask'];
+end
+if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
+ filebase_a=get(handles.displ_filebase2,'String');
+ [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
+ if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
+ mask_displ='no mask';
+ end
+end
+if isequal(mask_displ,'no mask')
+ set(handles.get_mask_civ1,'Value',0)
+ set(handles.get_mask_fix1,'Value',0)
+ set(handles.get_mask_civ2,'Value',0)
+ set(handles.get_mask_fix2,'Value',0)
+else
+ set(handles.get_mask_fix1,'Value',1)
+ set(handles.get_mask_civ2,'Value',1)
+ set(handles.get_mask_fix2,'Value',1)
+end
+set(handles.mask_civ1,'String',mask_displ)
+set(handles.mask_fix1,'String',mask_displ)
+set(handles.mask_civ2,'String',mask_displ)
+set(handles.mask_fix2,'String',mask_displ)
+end
+%--------------------------------------------------------------
+% --- Executes on button press in get_mask_fix1.
+function get_mask_fix1_Callback(hObject, eventdata, handles)
+maskval=get(handles.get_mask_fix1,'Value')
+if isequal(maskval,0)
+ set(handles.mask_fix1,'String','')
+else
+mask_displ='no mask'; %default
+filebase=get(handles.displ_filebase,'String');
+[nbslice, flag_mask]=get_mask(filebase,handles)
+if isequal(flag_mask,1)
+ mask_displ=[num2str(nbslice) 'mask'];
+end
+if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
+ filebase_a=get(handles.displ_filebase2,'String');
+ [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
+ if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
+ mask_displ='no mask';
+ end
+end
+if isequal(mask_displ,'no mask')
+ set(handles.get_mask_fix1,'Value',0)
+ set(handles.get_mask_civ2,'Value',0)
+ set(handles.get_mask_fix2,'Value',0)
+else
+ set(handles.get_mask_civ2,'Value',1)
+ set(handles.get_mask_fix2,'Value',1)
+end
+set(handles.mask_fix1,'String',mask_displ)
+set(handles.mask_civ2,'String',mask_displ)
+set(handles.mask_fix2,'String',mask_displ)
+end
+%-----------------------------------------
+% --- Executes on button press in get_mask_civ2.
+function get_mask_civ2_Callback(hObject, eventdata, handles)
+maskval=get(handles.get_mask_civ2,'Value')
+if isequal(maskval,0)
+ set(handles.mask_civ2,'String','')
+else
+mask_displ='no mask'; %default
+filebase=get(handles.displ_filebase,'String');
+[nbslice, flag_mask]=get_mask(filebase,handles)
+if isequal(flag_mask,1)
+ mask_displ=[num2str(nbslice) 'mask'];
+end
+if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
+ filebase_a=get(handles.displ_filebase2,'String');
+ [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
+ if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
+ mask_displ='no mask';
+ end
+end
+if isequal(mask_displ,'no mask')
+ set(handles.get_mask_civ2,'Value',0)
+ set(handles.get_mask_fix2,'Value',0)
+else
+ set(handles.get_mask_fix2,'Value',1)
+end
+set(handles.mask_civ2,'String',mask_displ)
+set(handles.mask_fix2,'String',mask_displ)
+end
+%-------------------------------------
+% --- Executes on button press in get_mask_fix2.
+function get_mask_fix2_Callback(hObject, eventdata, handles)
+maskval=get(handles.get_mask_fix2,'Value')
+if isequal(maskval,0)
+ set(handles.mask_fix2,'String','')
+else
+mask_displ='no mask'; %default
+filebase=get(handles.displ_filebase,'String');
+[nbslice, flag_mask]=get_mask(filebase,handles)
+if isequal(flag_mask,1)
+ mask_displ=[num2str(nbslice) 'mask'];
+end
+if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
+ filebase_a=get(handles.displ_filebase2,'String');
+ [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
+ if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
+ mask_displ='no mask';
+ end
+end
+if isequal(mask_displ,'no mask')
+ set(handles.get_mask_fix2,'Value',0)
+end
+set(handles.mask_fix2,'String',mask_displ)
+end
+
+%---------------------------------------
+function [nbslice, flag_mask]=get_mask(filebase,handles)
+%detect mask files, images with appropriate file base
+%[filebase '_' xx 'mask'], xx=nbslice
+%flag_mask=1 indicates detection
+
+flag_mask=0;%default
+nbslice=1;
+
+% subdir=get(handles.subdir_civ1,'String');
+[Path,Name]=fileparts(filebase)
+currentdir=pwd;
+cd(Path);%move in the dir of the root name filebase
+maskfiles=dir([Name '_*mask_*.png'])%look for mask files
+cd(currentdir);%come back to the current working directory
+if isempty(maskfiles)
+ browse=get(handles.browse_root,'UserData');
+ varargin{1}='';
+ [image_name,idetect]=name_generator(filebase,1,1,browse.ext_ima,browse.nom_type_ima);%name of an image
+ if idetect==1
+ varargin{1}=image_name;
+ end
+ warndlg_uvmat('no mask available, use TOOL menu in the uvmat interface to create it','ERROR')
+% makemask(varargin); %open the makemask interface
+else
+ maskname=maskfiles(1).name;% take the first mask file in the list
+ [Path2,Name,ext]=fileparts(maskname);
+ Namedouble=double(Name);
+ val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
+ ind_mask=findstr('mask',Name);
+ i=ind_mask-1;
+ while val(i)==0 & i>0
+ i=i-1;
+ end
+ nbslice=str2num(Name(i+1:ind_mask-1));
+ if ~isequal(nbslice,[]) & Name(i)=='_'
+ flag_mask=1;
+ else
+ errordlg(['bad mask file ' Name ext ' found in ' Path2])
+ return
+ nbslice=1;
+ end
+end
+%------------------------------
+
+
+function grid_civ1_Callback(hObject, eventdata, handles)
+% hObject handle to grid_civ1 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of grid_civ1 as text
+% str2double(get(hObject,'String')) returns contents of grid_civ1 as a double
+
+
+%-----------------------------------------------------------
+% transform numbers to letters
+%--------------------------------------------
+function str=num2stra(num,nom_type);
+if isequal(nom_type,'png_old') | isequal(nom_type,'netc_old') |isequal(nom_type,'raw_SMD')
+ str=char(96+num);
+elseif isequal(nom_type,'_i')|isequal(nom_type,'_i1-i2')...
+ |isequal(nom_type,'ima_num')| isequal(nom_type,'avi')| isequal(nom_type,'none')
+ str='';
+else
+ str=num2str(num);
+end
+%---------------------------------------------------
+function mask_civ1_Callback(hObject, eventdata, handles)
+set(handles.mask_civ1,'UserData',[])
+set(handles.mask_civ1,'String','')
+%----------------------------------------------------
+function mask_civ2_Callback(hObject, eventdata, handles)
+set(handles.mask_civ2,'UserData',[])
+set(handles.mask_civ2,'String','')
+%----------------------------------------------------
+function mask_fix1_Callback(hObject, eventdata, handles)
+set(handles.mask_fix1,'UserData',[])
+set(handles.mask_fix1,'String','')
+%----------------------------------------------------
+function mask_fix2_Callback(hObject, eventdata, handles)
+set(handles.mask_fix2,'UserData',[])
+set(handles.mask_fix2,'String','')
+
+%--------------------------------------------------------------------------
+% --- Executes on button press in list_subdir_civ1.
+function list_subdir_civ1_Callback(hObject, eventdata, handles)
+
+filebase=get(handles.displ_filebase,'String');
+dirinput = uigetdir(filebase)
+ set(handles.subdir_civ1,'String',dirinput)
+ set(handles.subdir_civ2,'String',dirinput)
+
+displ_filebase_Callback(hObject, eventdata, handles);
+
+
+function rho_civ2_Callback(hObject, eventdata, handles)
+% hObject handle to rho_civ2 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of rho_civ2 as text
+% str2double(get(hObject,'String')) returns contents of rho_civ2 as a double
+
+%----------------------------------------------
+function last_i_Callback(hObject, eventdata, handles)
+first_i=str2num(get(handles.first_i,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+ref_i=ceil((first_i+last_i)/2);
+set(handles.ref_i,'String', num2str(ref_i))
+ref_i_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------
+function last_j_Callback(hObject, eventdata, handles)
+first_j=str2num(get(handles.first_j,'String'));
+last_j=str2num(get(handles.last_j,'String'));
+ref_j=ceil((first_j+last_j)/2);
+set(handles.ref_j,'String', num2str(ref_j))
+ref_j_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------------------------------------
+% --- Executes on button press in browse_gridciv1.
+function browse_gridciv1_Callback(hObject, eventdata, handles)
+value=get(handles.browse_gridciv1,'Value');
+if value
+ filebase=get(handles.displ_filebase,'String');
+ [FileName, PathName, filterindex] = uigetfile( ...
+ {'*.grid', ' (*.grid)';
+ '*.grid', '.grid files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',filebase);
+ filegrid=fullfile(PathName,FileName);
+ if isempty(FileName)|isempty(PathName)|isequal(FileName,0)|~exist(filegrid,'file')
+ set(handles.browse_gridciv1,'Value',0);
+ set(handles.grid_civ1,'string','');
+ set(handles.dx_civ1,'Visible','on');
+ set(handles.dy_civ1,'Visible','on');
+ set(handles.grid_civ2,'string','');
+ if get(handles.CIV2,'Value')
+ set(handles.dx_civ2,'Visible','on');
+ set(handles.dy_civ2,'Visible','on');
+ end
+ else
+ set(handles.grid_civ1,'string',filegrid);
+ set(handles.dx_civ1,'Visible','off');
+ set(handles.dy_civ1,'Visible','off');
+ set(handles.grid_civ2,'string',filegrid);
+ set(handles.dx_civ2,'Visible','off');
+ set(handles.dy_civ2,'Visible','off');
+% set(handles.grid_patch1,'string',filegrid);
+% set(handles.grid_patch2,'string',filegrid);
+ end
+else
+ set(handles.grid_civ1,'string','');
+ set(handles.dx_civ1,'Visible','on');
+ set(handles.dy_civ1,'Visible','on');
+ set(handles.grid_civ2,'string','');
+ if get(handles.CIV2,'Value')
+ set(handles.dx_civ2,'Visible','on');
+ set(handles.dy_civ2,'Visible','on');
+ end
+end
+
+
+
+function pxcmx_Callback(hObject, eventdata, handles)
+% hObject handle to pxcmx (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of pxcmx as text
+% str2double(get(hObject,'String')) returns contents of pxcmx as a double
+
+
+
+function pxcmy_Callback(hObject, eventdata, handles)
+% hObject handle to pxcmy (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of pxcmy as text
+% str2double(get(hObject,'String')) returns contents of pxcmy as a double
+
+
+% --- Executes on button press in browse_gridciv2.
+function browse_gridciv2_Callback(hObject, eventdata, handles)
+
+filebase=get(handles.displ_filebase,'String');
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.grid', ' (*.grid)';
+ '*.grid', '.grid files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',filebase);
+filegrid=fullfile(PathName,FileName);
+set(handles.grid_civ2,'string',filegrid);
+set(handles.dx_civ2,'String',' ');
+set(handles.dy_civ2,'String',' ');
+% set(handles.grid_patch2,'string',filegrid);
+
+% --- Executes on button press in get_gridpatch1.
+function get_gridpatch1_Callback(hObject, eventdata, handles)
+% hObject handle to get_gridpatch1 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+filebase=get(handles.displ_filebase,'String');
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.grid', ' (*.grid)';
+ '*.grid', '.grid files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',filebase);
+filegrid=fullfile(PathName,FileName);
+set(handles.grid_patch1,'string',filegrid);
+% set(handles.grid_patch2,'string',filegrid
+
+%-----------------------------------------------------------------
+% --- Executes on button press in get_gridpatch2.
+function get_gridpatch2_Callback(hObject, eventdata, handles)
+% hObject handle to get_gridpatch2 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+%----------------------------------------------------------
+function enable_civ1(handles,state)
+if isequal(state,0)
+ state='off';
+end
+if isequal(state,1)
+ state='on';
+end
+if isequal(state,'on')
+ set(handles.frame_civ1,'BackgroundColor',[1 1 0])
+ set(handles.frame_para_civ1,'BackgroundColor',[1 1 0])
+ set(handles.frame_grid_civ1,'BackgroundColor',[1 1 0])
+else
+ set(handles.frame_civ1,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.frame_para_civ1,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.frame_grid_civ1,'BackgroundColor',[0.831 0.816 0.784])
+end
+set(handles.ibx,'Visible',state)
+set(handles.iby,'Visible',state)
+set(handles.isx,'Visible',state)
+set(handles.isy,'Visible',state)
+set(handles.shiftx,'Visible',state)
+set(handles.shifty,'Visible',state)
+set(handles.rho,'Visible',state)
+set(handles.dx_civ1,'Visible',state)
+set(handles.dy_civ1,'Visible',state)
+set(handles.calcul_search,'Visible',state)
+set(handles.u_text,'Visible',state)
+set(handles.v_text,'Visible',state)
+set(handles.min,'Visible',state)
+set(handles.max,'Visible',state)
+set(handles.umin,'Visible',state)
+set(handles.umax,'Visible',state)
+set(handles.vmin,'Visible',state)
+set(handles.vmax,'Visible',state)
+set(handles.grid_civ1,'Visible',state)
+set(handles.mask_civ1,'Visible',state)
+set(handles.browse_gridciv1,'Visible',state)
+set(handles.get_mask_civ1,'Visible',state)
+set(handles.parameters,'Visible',state)
+set(handles.grid,'Visible',state)
+set(handles.dx_civ1,'Visible',state)
+set(handles.dy_civ1,'Visible',state)
+set(handles.ImaThreshold,'Visible',state)
+if isequal(state,'off')
+ set(handles.MinIma,'Visible','off')
+ set(handles.MaxIma,'Visible','off')
+ set(handles.ImaThreshold,'Value',0)
+end
+set(handles.dx_civ1_title,'Visible',state)
+set(handles.dy_civ1_title,'Visible',state)
+set(handles.ImaThreshold_title,'Visible',state)
+set(handles.ib_title,'Visible',state)
+set(handles.is_title,'Visible',state)
+set(handles.shift_title,'Visible',state)
+set(handles.rho_title,'Visible',state)
+
+%----------------------------------------------------------
+function enable_fix1(handles)
+set(handles.frame_fix1,'BackgroundColor',[1 1 0])
+set(handles.REMOVE,'Visible','on')
+set(handles.vec_Fmin2,'Visible','on')
+set(handles.vec_F2,'Visible','on')
+set(handles.vec_F3,'Visible','on')
+set(handles.thresh_vecC,'Visible','on')
+set(handles.thresh_vecC_title,'Visible','on')
+set(handles.thresh_vel,'Visible','on')
+set(handles.thresh_vel_text,'Visible','on')
+set(handles.mask_fix1,'Visible','on')
+set(handles.get_mask_fix1,'Visible','on')
+set(handles.get_ref_fix1,'Visible','on')
+set(handles.ref_fix1,'Visible','on')
+set(handles.inf_sup1,'Visible','on')
+set(handles.field_ref1,'Visible','on')
+
+%----------------------------------------------------------
+function desable_fix1(handles)
+set(handles.frame_fix1,'BackgroundColor',[0.831 0.816 0.784])
+set(handles.REMOVE,'Visible','off')
+set(handles.vec_Fmin2,'Visible','off')
+set(handles.vec_F2,'Visible','off')
+set(handles.vec_F3,'Visible','off')
+set(handles.thresh_vecC,'Visible','off')
+set(handles.thresh_vecC_title,'Visible','off')
+set(handles.thresh_vel,'Visible','off')
+set(handles.thresh_vel_text,'Visible','off')
+set(handles.mask_fix1,'Visible','off')
+set(handles.get_mask_fix1,'Visible','off')
+set(handles.get_ref_fix1,'Visible','off')
+set(handles.ref_fix1,'Visible','off')
+set(handles.inf_sup1,'Visible','off')
+set(handles.field_ref1,'Visible','off')
+
+%--------------------------------------------------------------
+function enable_patch1(handles)
+global patch_new_exe
+set(handles.frame_patch1,'BackgroundColor',[1 1 0])
+set(handles.rho_patch1,'Visible','on')
+set(handles.rho_text1,'Visible','on')
+set(handles.thresh_patch1,'Visible','on')
+set(handles.thresh_text1,'Visible','on')
+set(handles.subdomain_patch1,'Visible','on')
+set(handles.subdomain_text1,'Visible','on')
+set(handles.nx_patch1,'Visible','on')
+set(handles.ny_patch1,'Visible','on')
+set(handles.nx_patch1_title,'Visible','on')
+set(handles.ny_patch1_title,'Visible','on')
+if (~isequal(patch_new_exe,[]) & ~isequal(patch_new_exe,[]))
+ set(handles.test_interp,'Visible','on');
+end
+set(handles.get_gridpatch1,'Visible','on')
+set(handles.grid_patch1,'string','none');
+set(handles.grid_patch1,'Visible','on')
+
+%--------------------------------------------------------------
+function desable_patch1(handles)
+set(handles.frame_patch1,'BackgroundColor',[0.831 0.816 0.784])
+set(handles.rho_patch1,'Visible','off')
+set(handles.rho_text1,'Visible','off')
+set(handles.thresh_patch1,'Visible','off')
+set(handles.thresh_text1,'Visible','off')
+set(handles.subdomain_patch1,'Visible','off')
+set(handles.subdomain_text1,'Visible','off')
+set(handles.nx_patch1,'Visible','off')
+set(handles.ny_patch1,'Visible','off')
+set(handles.nx_patch1_title,'Visible','off')
+set(handles.ny_patch1_title,'Visible','off')
+set(handles.test_interp,'Visible','off')
+set(handles.get_gridpatch1,'Visible','off')
+set(handles.grid_patch1,'Visible','off')
+
+%----------------------------------------------------------
+function enable_civ2(handles,state)
+if isequal(state,0)
+ state='off';
+end
+if isequal(state,1)
+ state='on';
+end
+if isequal(state,'on')
+ set(handles.frame_civ2,'BackgroundColor',[1 1 0])
+ set(handles.frame_para_civ2,'BackgroundColor',[1 1 0])
+ set(handles.frame_grid_civ2,'BackgroundColor',[1 1 0])
+ set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
+else
+ set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
+end
+set(handles.ibx_civ2,'Visible',state)
+set(handles.iby_civ2,'Visible',state)
+set(handles.decimal,'Visible',state)
+set(handles.deformation,'Visible',state)
+set(handles.rho_civ2,'Visible',state)
+set(handles.dx_civ2,'Visible',state)
+set(handles.dy_civ2,'Visible',state)
+set(handles.browse_gridciv2,'Visible',state)
+set(handles.get_mask_civ2,'Visible',state)
+set(handles.parameters,'Visible',state)
+set(handles.grid,'Visible',state)
+set(handles.parameters_text,'Visible',state)
+set(handles.grid_text,'Visible',state)
+set(handles.grid_civ2,'Visible',state)
+set(handles.mask_civ2,'Visible',state)
+set(handles.dx_civ2_title,'Visible',state)
+set(handles.dy_civ2_title,'Visible',state)
+set(handles.ibx_civ2_text,'Visible',state)
+set(handles.rho_civ2_title,'Visible',state)
+set(handles.ImaThreshold2,'Visible',state)
+set(handles.ImaThreshold_title2,'Visible',state)
+if isequal(state,'off')
+ set(handles.MinIma2,'Visible','off')
+ set(handles.MaxIma2,'Visible','off')
+ set(handles.ImaThreshold2,'Value',0)
+ if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
+ set(handles.list_pair_civ2,'Visible','off')
+ set(handles.subdir_civ2,'Visible','off')
+ set(handles.subdir_civ2_text,'Visible','off')
+ end
+else
+ set(handles.list_pair_civ2,'Visible','on')
+ set(handles.subdir_civ2,'Visible','on')
+ set(handles.subdir_civ2_text,'Visible','on')
+end
+
+%----------------------------------------------------------
+% function desable_civ2(handles)
+% set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
+% set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
+% set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
+% set(handles.ibx_civ2,'Visible','off')
+% set(handles.iby_civ2,'Visible','off')
+% set(handles.decimal,'Visible','off')
+% set(handles.deformation,'Visible','off')
+% set(handles.rho_civ2,'Visible','off')
+% set(handles.dx_civ2,'Visible','off')
+% set(handles.dy_civ2,'Visible','off')
+% set(handles.browse_gridciv2,'Visible','off')
+% set(handles.get_mask_civ2,'Visible','off')
+% set(handles.parameters,'Visible','off')
+% set(handles.grid,'Visible','off')
+% set(handles.grid,'Visible','on')
+% set(handles.parameters_text,'Visible','off')
+% set(handles.grid_text,'Visible','off')
+% set(handles.grid_civ2,'Visible','off')
+% set(handles.mask_civ2,'Visible','off')
+% set(handles.dx_civ2_title,'Visible','off')
+% set(handles.dy_civ2_title,'Visible','off')
+% set(handles.ibx_civ2_text,'Visible','off')
+% set(handles.rho_civ2_title,'Visible','off')
+% set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
+% if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
+% set(handles.list_pair_civ2,'Visible','off')
+% set(handles.subdir_civ2,'Visible','off')
+% set(handles.subdir_civ2_text,'Visible','off')
+% end
+
+%----------------------------------------------------------
+function enable_fix2(handles)
+set(handles.frame_fix2,'BackgroundColor',[1 1 0])
+set(handles.REMOVE2,'Visible','on')
+set(handles.vec_Fmin2_2,'Visible','on')
+set(handles.vec_F4,'Visible','on')
+set(handles.vec_F3_2,'Visible','on')
+set(handles.thresh_vec2C,'Visible','on')
+set(handles.thresh_vec2C_text,'Visible','on')
+set(handles.thresh_vel2,'Visible','on')
+set(handles.thresh_vel2_text,'Visible','on')
+set(handles.mask_fix2,'Visible','on')
+set(handles.get_mask_fix2,'Visible','on')
+set(handles.list_pair_civ2,'Visible','on')
+set(handles.subdir_civ2,'Visible','on')
+set(handles.subdir_civ2_text,'Visible','on')
+set(handles.get_ref_fix2,'Visible','on')
+set(handles.ref_fix2,'Visible','on')
+set(handles.inf_sup2,'Visible','on')
+set(handles.field_ref2,'Visible','on')
+
+%----------------------------------------------------------
+function desable_fix2(handles)
+set(handles.frame_fix2,'BackgroundColor',[0.831 0.816 0.784])
+set(handles.REMOVE2,'Visible','off')
+set(handles.vec_Fmin2_2,'Visible','off')
+set(handles.vec_F4,'Visible','off')
+set(handles.vec_F3_2,'Visible','off')
+set(handles.thresh_vec2C,'Visible','off')
+set(handles.thresh_vec2C_text,'Visible','off')
+set(handles.thresh_vel2,'Visible','off')
+set(handles.thresh_vel2_text,'Visible','off')
+set(handles.mask_fix2,'Visible','off')
+set(handles.get_mask_fix2,'Visible','off')
+set(handles.get_ref_fix2,'Visible','off')
+set(handles.ref_fix2,'Visible','off')
+set(handles.inf_sup2,'Visible','off')
+set(handles.field_ref2,'Visible','off')
+if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
+ set(handles.list_pair_civ2,'Visible','off')
+ set(handles.subdir_civ2,'Visible','off')
+ set(handles.subdir_civ2_text,'Visible','off')
+end
+
+%--------------------------------------------------------------
+function enable_patch2(handles)
+set(handles.frame_patch2,'BackgroundColor',[1 1 0])
+set(handles.rho_patch2,'Visible','on')
+set(handles.rho_text2,'Visible','on')
+set(handles.thresh_patch2,'Visible','on')
+set(handles.thresh_text2,'Visible','on')
+set(handles.subdomain_patch2,'Visible','on')
+set(handles.subdomain_text2,'Visible','on')
+set(handles.nx_patch2,'Visible','on')
+set(handles.ny_patch2,'Visible','on')
+set(handles.nx_patch2_title,'Visible','on')
+set(handles.ny_patch2_title,'Visible','on')
+set(handles.get_gridpatch2,'Visible','on')
+set(handles.grid_patch2,'Visible','on')
+set(handles.list_pair_civ2,'Visible','on')
+set(handles.subdir_civ2,'Visible','on')
+set(handles.subdir_civ2_text,'Visible','on')
+
+%--------------------------------------------------------------
+function desable_patch2(handles)
+set(handles.frame_patch2,'BackgroundColor',[0.831 0.816 0.784])
+set(handles.rho_patch2,'Visible','off')
+set(handles.rho_text2,'Visible','off')
+set(handles.thresh_patch2,'Visible','off')
+set(handles.thresh_text2,'Visible','off')
+set(handles.subdomain_patch2,'Visible','off')
+set(handles.subdomain_text2,'Visible','off')
+set(handles.nx_patch2,'Visible','off')
+set(handles.ny_patch2,'Visible','off')
+set(handles.nx_patch2_title,'Visible','off')
+set(handles.ny_patch2_title,'Visible','off')
+set(handles.get_gridpatch2,'Visible','off')
+set(handles.grid_patch2,'Visible','off')
+if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.FIX2,'Value'),0)
+ set(handles.list_pair_civ2,'Visible','off')
+ set(handles.subdir_civ2,'Visible','off')
+ set(handles.subdir_civ2_text,'Visible','off')
+end
+
+% --- Executes on button press in test_interp.
+function test_interp_Callback(hObject, eventdata, handles)
+
+
+%------------------------------------------------
+%Read the parameters for civ1 on the interface
+%--------------------------------------------------
+function par=read_param_civ1(handles,file_ima)
+
+ibx_val=str2num(get(handles.ibx,'String'));
+par.correlationBoxesSize_X=num2str(ibx_val);
+iby_val=str2num(get(handles.iby,'String'));
+par.correlationBoxesSize_Y=num2str(iby_val);
+ibz_val=str2num(get(handles.ibz,'String'));
+par.correlationBoxesSize_Z=num2str(ibz_val);
+isx=get(handles.isx,'String');
+if isempty(str2num(isx)), isx='41'; set(handles.isx,'String','41'), end; %default
+maxDisplacement_X=floor((str2num(isx)-ibx_val)/2);
+par.maxDisplacement_X=num2str(maxDisplacement_X);
+isy=get(handles.isy,'String');
+if isempty(str2num(isy)), isy='41'; set(handles.isy,'String','41'), end; %default
+maxDisplacement_Y=floor((str2num(isy)-iby_val)/2);
+par.maxDisplacement_Y=num2str(maxDisplacement_Y);
+isz=get(handles.isz,'String');
+if isempty(str2num(isz)), isz='41'; set(handles.isz,'String','41'), end; %default
+maxDisplacement_Z=floor((str2num(isz)-ibz_val)/2);
+par.maxDisplacement_Z=num2str(maxDisplacement_Z);
+% par.rho=get(handles.rho,'String');
+par.gridSpacing_X=get(handles.dx_civ1,'String');
+par.gridSpacing_Y=get(handles.dy_civ1,'String');
+par.gridSpacing_Z=get(handles.dz_civ1,'String');
+% Zmin=str2num(get(handles.first_j,'String'))-1;
+Zmax=str2num(get(handles.nb_field2,'String'));
+par.gridLimits_Xmin=0;
+par.gridLimits_Ymin=0;
+par.gridLimits_Zmin=0;
+% A=imread(file_ima);%read the first image to get the size
+%sizim=size(A);
+par.gridLimits_Xmax=1024;%num2str(sizim(2));
+par.gridLimits_Ymax=1024;%num2str(sizim(1));
+par.gridLimits_Zmax=Zmax;
+par.grid='grille';
+par.grid_division=4;
+par.hart=0;
+par.ratioHoverZ=1;
+
+%
+% %----------------------------------------------------------------
+% function par=read_param_civ2(handles,file_ima)
+% par.ibx=get(handles.ibx_civ2,'String');
+% par.iby=get(handles.iby_civ2,'String');
+% par.rho=get(handles.rho_civ2,'String');
+% par.decimal=int2str(get(handles.decimal,'Value'));
+% par.deformation=int2str(get(handles.deformation,'Value'));
+% par.dx=get(handles.dx_civ2,'String');
+% par.dy=get(handles.dy_civ2,'String');
+% if isequal(str2num(par.dx),[])
+% if isempty(get(handles.grid_civ2,'String'));
+% par.dx='0'; %just read by civ_3D program, not used
+% else
+% par.dx='20';%default
+% set(handles.dx_civ2,'String','20');
+% end
+% end
+% if isequal(str2num(par.dy),[])
+% if isempty(get(handles.grid_civ2,'String'));
+% par.dy='0';%just read by civ_3D program, not used
+% else
+% par.dy='20';%default
+% set(handles.dy_civ2,'String','20');
+% end
+% end
+% par.pxcmx=get(handles.pxcmx,'String');
+% par.pxcmy=get(handles.pxcmy,'String');
+% if isempty(str2num(par.pxcmx)) |isempty(str2num(par.pxcmy))
+% par.pxcmx='1';
+% par.pxcmy='1';
+% end
+% % par.npx=get(handles.pxcmx,'UserData');
+% % par.npy=get(handles.pxcmy,'UserData');
+% A=imread(file_ima);%read the first image to get the size
+% sizim=size(A);
+% par.npx=num2str(sizim(2));
+% par.npy=num2str(sizim(1));
+% time=get(handles.displ_filebase,'UserData'); %get the set of times
+% par.gridname=get(handles.grid_civ2,'String');
+% par.gridflag='y';
+% if isequal(par.gridname,'')| isempty(par.gridname)
+% par.gridname='nogrid';
+% par.gridflag='n';
+% end
+
+
+%---------------------------------------------------------
+%CIV1 CIV1 CIV1 CIV1
+%----------------------------------------------------------
+function cmd_CIV1=BATCH_CIV1(filename,namelog,par,handles)
+%pixels per cm and matrix of the image times, read from the .civ_3D file by uvmat
+global civ1_exe Civ_exe sge%name of the executable for civ1 calculation
+
+%changes : filename_cmx -> filename ( no extension )
+
+ if isequal(par.Dt,'0')
+ par.Dt='1' ;%case of 'displacement' mode
+ end
+
+ textcmx={'############## CMX file';...
+ ['FirstImage ' par.filename_ima_a];...
+ ['LastImage ' par.filename_ima_b];...
+ 'XX' ;...
+ ['Mask ' par.maskflag] ;...
+ ['MaskName ' par.maskname];...
+ ['ImageSize ' par.npx ' ' par.npy];... %VERIFIER CAS GENERAL ?
+ ['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
+ ['SearchBoxeSize ' par.isx ' ' par.isy];...
+ ['RO ' par.rho];...
+ ['GridSpacing ' par.dx ' ' par.dy];...
+ 'XX 1.0';...
+ ['Dt_TO ' par.Dt ' ' par.T0];...
+ ['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
+ 'XX 1';...
+ ['ShiftXY ' par.shiftx ' ' par.shifty];...
+ ['Grid ' par.gridflag];...
+ ['GridName ' par.gridname] ;...
+ 'XX 85';...
+ 'XX 1.0';...
+ 'XX 1.0';...
+ 'Hart 1';...
+ 'DecimalShift 0';...
+ 'Deformation 0';...
+ 'CorrelationMin 0';...
+ 'IntensityMin 0';...
+ 'SeuilImage n';...
+ 'SeuilImageValues 0 4096';...
+ ['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
+ 'ImageUsedBefore null null'};
+
+ textout=char(textcmx);
+ % timeL1=clock;
+ dlmwrite([filename '.cmx'],textout,'');
+ % timeL2=clock;
+ % timciv1=etime(timeL2,timeL1)
+ if sge
+ cmd_CIV1=[civ1_exe ' -f ' filename '.cmx' ]; % redirect standard output to the log file
+ else
+ cmd_CIV1=[civ1_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
+ end
+ if(isunix)
+ [Rootbat,Filebat,extbat]=fileparts(namelog);
+ ncName=fullfile(Rootbat,[ Filebat '.nc']);
+ cmd_CIV1=char({cmd_CIV1 ; ['mv ' namelog ' ' namelog '.civ1.log'];['chmod g+w ' ncName]});
+ else
+ cmd_CIV1=char({cmd_CIV1 ; ['copy /Y ' namelog ' ' namelog '.civ1.log']});
+ end
+
+%---------------------------------------------------------
+%CIV1 Unified
+%----------------------------------------------------------
+function xml_civ1_parameters=BATCH_CIV1_Unified(filename,namelog,par,handles)
+%pixels per cm and matrix of the image times, read from the .civ_3D file by uvmat
+global civ1_exe Civ_exe%name of the executable for civ1 calculation
+
+ civ1.image1=par.filename_ima_a;
+ civ1.image2=par.filename_ima_b;
+ civ1.imageSize_X=par.npx;
+ civ1.imageSize_Y=par.npy;
+ civ1.outputFileName=[filename '.nc'];
+ civ1.correlationBoxesSize_X=par.ibx;
+ civ1.correlationBoxesSize_Y=par.iby;
+ civ1.searchBoxesSize_X=par.isx;
+ civ1.searchBoxesSize_Y=par.isy;
+ civ1.globalShift_X=par.shiftx;
+ civ1.globalShift_Y=par.shifty;
+ civ1.ro=par.rho;
+ civ1.hart='y';
+ if isequal(par.gridflag,'y')
+ civ1.grid=par.gridname;
+ end
+ civ1.gridSpacing_X=par.dx;
+ civ1.gridSpacing_Y=par.dy;
+ if isequal(par.maskflag,'y')
+ civ1.mask=par.maskname;
+ end
+ civ1.dt=par.Dt;
+ civ1.unit='pixel';
+ civ1.absolut_time_T0=par.T0;
+ civ1.pixcmx=par.pxcmx;
+ civ1.pixcmy=par.pxcmy;
+ civ1.convectFlow='n';
+
+ xml_civ1_parameters=civ1;
+
+%---------------------------------------------------------
+%CIV2 CIV2 CIV2 CIV2
+%----------------------------------------------------------
+function cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par)
+%pixels per cm and matrix of the image times, read from the .civ_3D file by uvmat
+global civ2_exe sge%name of the executable for civ1 calculation
+ if isequal(par.Dt,'0')
+ par.Dt='1' ;%case of 'displacement' mode
+ end
+textcmx={'############## CMX file';...
+['FirstImage ' par.filename_ima_a];...
+['LastImage ' par.filename_ima_b];...
+'XX' ;...
+['Mask ' par.maskflag];...
+['MaskName ' par.maskname];...
+['ImageSize ' par.npx ' ' par.npy];...
+['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
+['SearchBoxeSize ' par.ibx ' ' par.iby];...
+['RO ' par.rho];...
+['GridSpacing ' par.dx ' ' par.dy];...
+'XX 1.0';...
+['Dt_TO ' par.Dt ' ' par.T0];...
+['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
+'XX 1';...
+['ShiftXY 0 0'];...
+['Grid ' par.gridflag];...
+['GridName ' par.gridname];...
+'XX 85';...
+'XX 1.0';...
+'XX 1.0';...
+'Hart 1';...
+['DecimalShift ' par.decimal];...
+['Deformation ' par.deformation];...
+'CorrelationMin 0';...
+'IntensityMin 0';...
+'SeuilImage n';...
+'SeuilImageValues 0 4096';...
+['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
+['ImageUsedBefore ' par.filename_nc1]};
+ textout=char(textcmx);
+ dlmwrite([filename_cmx '2'] ,textout,'');
+ if sge
+ cmd_CIV2=[civ2_exe ' -f ' filename_cmx ]; % redirect standard output to the log file
+ else
+ cmd_CIV2=[civ2_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
+ end
+
+
+% --- Executes on button press in HELP.
+function HELP_Callback(hObject, eventdata, handles)
+path_to_uvmat=which ('uvmat');% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+else
+web([helpfile '#civ_3D'])
+end
+
+
+%----------------------------------------------------------
+%--read images and convert them to the uint16 format used for PIV
+function A=read_image(filename,nom_type,npx,npy,num);
+%npx, npy are the dimensions needed for the raw SMD images
+%num is the view number needed for an avi movie
+if isequal(nom_type,'avi')
+ mov=aviread(filename,num);
+ A=frame2im(mov(1));
+ A=sum(double(A),3);
+ A=uint16(A);
+elseif isequal(nom_type,'raw_SMD')
+ [fid,message]=fopen(filename,'r');
+ B=fread(fid,Inf,'int16',0,'ieee-le');%read 16 bit binary file
+ A=(reshape(B,npx,npy))'; %remplissage ligne par ligne avec une matrice colonne ? transposer(uB) pour avoir une matrice ligne
+ A=uint16(A);
+ fclose(fid);
+else
+ A=imread(filename);
+ siz=size(A);
+ if length(siz)==3;%color images
+ A=sum(double(A),3);
+ end
+ A=uint16(A);
+end
+
+%----------------------------------------------------------------
+%Executes on carriage return on the time interval dt
+%----------------------------------------------------------------
+function dt_Callback(hObject, eventdata, handles)
+%determine the set of times and possible intervals for CIV_3D
+% answer=inputdlg('time interval between images?');
+ dt=(1/1000)*str2num(get(handles.dt,'String'));
+ nbfield=str2num(get(handles.nb_field,'String')); %last image number selected in the processing series
+ time=(dt*[0:nbfield-1])';
+% set(handles.incr_i,'UserData',dt);%store the time interval between successive images
+ set(handles.displ_filebase,'UserData',time); %store the set of times
+ for index=1:min(nbfield-1,200)
+ displ_num(1,index)=1;
+ displ_num(2,index)=1;
+ displ_num(3,index)=-floor(index/2);
+ displ_num(4,index)=ceil(index/2);
+ end
+set(handles.list_pair_civ1,'Value',1);
+set(handles.list_pair_civ1,'UserData',displ_num);
+set(handles.list_pair_civ2,'Value',1);
+%update the list of time intervals
+find_netcpair_civ1(hObject, eventdata, handles)
+find_netcpair_civ2(hObject, eventdata, handles)
+
+%-------------------------------------------------------
+function ref_i_Callback(hObject, eventdata, handles)
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+if isequal(get(handles.CIV1,'Value'),0)| isequal(mode,'series(Di)')
+ find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
+end
+if isequal(mode,'series(Di)') | ...% we do patch2 only
+ (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
+ find_netcpair_civ2(hObject, eventdata, handles);
+end
+
+%----------------------------------------------------
+function ref_j_Callback(hObject, eventdata, handles)
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+if isequal(get(handles.CIV1,'Value'),0)| isequal(mode,'series(Dj)')
+ find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
+end
+if isequal(mode,'series(Dj)') | ...
+ (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
+ find_netcpair_civ2(hObject, eventdata, handles);
+end
+%----------------------------------------------------
+% --- Executes on button press in compare.
+function compare_Callback(hObject, eventdata, handles)
+test=get(handles.compare,'Value');
+if test
+ filebase=get(handles.displ_filebase,'String');
+ browse=get(handles.browse_root,'Userdata');
+ browse.nom_type_ima1=browse.nom_type_ima;
+ set(handles.browse_root,'UserData',browse);
+ set(handles.displ_filebase2,'Visible','On');%mkes the second file input window visible
+ set(handles.displ_filebase2,'String',filebase);
+ mode_store=get(handles.mode,'String');%get the present 'mode'
+ set(handles.compare,'UserData',mode_store);%store the mode display
+ set(handles.mode,'Value',1)
+ set(handles.mode,'String',{'displacement';'st_pair j1-j2'})
+else
+ set(handles.displ_filebase2,'Visible','Off');
+ set(handles.displ_filebase2,'String',[]);
+ mode_store=get(handles.compare,'UserData');
+ set(handles.mode,'String',mode_store)
+ set(handles.test_stereo1,'Value',0)
+ set(handles.test_stereo2,'Value',0)
+end
+mode_Callback(hObject, eventdata, handles)
+
+%-----------------------------------------------------------
+% --- Executes on button press in get_ref_fix1.
+function get_ref_fix1_Callback(hObject, eventdata, handles)
+filebase=get(handles.displ_filebase,'String');
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.nc', ' (*.nc)';
+ '*.nc', 'netcdf files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',filebase);
+
+fileinput=[PathName FileName];
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
+%[filebasesub,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
+[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
+%filebase=fullfile(RootPath,RootFile);
+% [Pth,FileN]=fileparts(filebasesub);
+% Pth=fileparts(Pth);
+ref.filebase=fullfile(Path,File);
+ref.num_a=stra2num(str_a);
+ref.num_b=stra2num(str_b);
+ref.num1=str2num(field_count);
+ref.num2=str2num(str2);
+browse=[];%initialisation
+if ~isequal(ref.ext,'.nc')
+ errordlg('the reference file must be in netcdf format (*.nc)')
+ return
+end
+% [path,name]=fileparts(ref.filebase);
+set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
+set(handles.ref_fix1,'UserData',ref)
+menu_field{1}='civ1';
+Data=nc2struct(fileinput,[]);
+if isfield(Data,'patch') & isequal(Data.patch,1)
+ menu_field{2}='filter1';
+end
+if isfield(Data,'civ2') & isequal(Data.civ2,1)
+ menu_field{3}='civ2';
+end
+if isfield(Data,'patch2') & isequal(Data.patch2,1)
+ menu_field{4}='filter2';
+end
+% [cte_detect,vdt,cte_read]=read_netcdf(fileinput,{'patch','civ2','patch2'});
+% if isequal(cte_detect(1),1) & isequal(cte_read(1),1)
+% menu_field{2}='filter1';
+% end
+% if isequal(cte_detect(2),1) & isequal(cte_read(2),1)
+% menu_field{3}='civ2';
+% end
+% if isequal(cte_detect(3),1) & isequal(cte_read(3),1)
+% menu_field{4}='filter2';
+% end
+set(handles.field_ref1,'String',menu_field);
+set(handles.field_ref1,'Value',length(menu_field));
+set(handles.inf_sup1,'Value',2);
+set(handles.thresh_vel,'String','1');%default threshold
+set(handles.ref_fix1,'Enable','on')
+
+%---------------------------------------------------------------
+% --- Executes on button press in get_ref_fix2.
+function get_ref_fix2_Callback(hObject, eventdata, handles)
+if isequal(get(handles.get_ref_fix2,'Value'),1)
+ filebase=get(handles.displ_filebase,'String');
+ [FileName, PathName, filterindex] = uigetfile( ...
+ {'*.nc', ' (*.nc)';
+ '*.nc', 'netcdf files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',filebase);
+ fileinput=[PathName FileName];
+ sizf=size(fileinput);
+ if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
+ %[filebasesub,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
+ [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
+% [Pth,FileN]=fileparts(filebasesub);
+% Pth=fileparts(Pth);
+ ref.filebase=fullfile(Path,File)
+ ref.num_a=stra2num(str_a);
+ ref.num_b=stra2num(str_b);
+ ref.num1=str2num(field_count);
+ ref.num2=str2num(str2);
+ browse=[];%initialisation
+ if ~isequal(ref.ext,'.nc')
+ errordlg('the reference file must be in netcdf format (*.nc)')
+ return
+ end
+% [path,name]=fileparts(ref.filebase);
+ set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
+ set(handles.ref_fix2,'UserData',ref)
+ menu_field{1}='civ1';
+% [cte_detect,vdt,cte_read]=read_netcdf(fileinput,{'patch','civ2','patch2'});
+ Data=nc2struct(fileinput,[]);
+ if isfield(Data,'patch') & isequal(Data.patch,1)
+ menu_field{2}='filter1';
+ end
+ if isfield(Data,'civ2') & isequal(Data.civ2,1)
+ menu_field{3}='civ2';
+ end
+ if isfield(Data,'patch2') & isequal(Data.patch2,1)
+ menu_field{4}='filter2';
+ end
+
+% if isequal(cte_detect(1),1) & isequal(cte_read(1),1)
+% menu_field{2}='filter1';
+% end
+% if isequal(cte_detect(2),1) & isequal(cte_read(2),1)
+% menu_field{3}='civ2';
+% end
+% if isequal(cte_detect(3),1) & isequal(cte_read(3),1)
+% menu_field{4}='filter2';
+% end
+ set(handles.field_ref2,'String',menu_field);
+ set(handles.field_ref2,'Value',length(menu_field));
+ set(handles.inf_sup2,'Value',2);
+ set(handles.thresh_vel2,'String','1');%default threshold
+ set(handles.ref_fix2,'Enable','on')
+ set(handles.ref_fix2,'Visible','on')
+ set(handles.field_ref2,'Visible','on')
+else
+ set(handles.ref_fix2,'Visible','off')
+ set(handles.field_ref2,'Visible','off')
+end
+%-------------------------------------------------------
+
+function ref_fix1_Callback(hObject, eventdata, handles)
+ set(handles.inf_sup1,'Value',1);
+ set(handles.field_ref1,'Value',1)
+ set(handles.field_ref1,'String',{' '})
+ set(handles.ref_fix1,'UserData',[]);
+ set(handles.ref_fix1,'String','');
+ set(handles.thresh_vel1,'String','0');
+
+
+%------------------------------------------------------
+
+function ref_fix2_Callback(hObject, eventdata, handles)
+ set(handles.inf_sup2,'Value',1);
+ set(handles.field_ref2,'Value',1)
+ set(handles.field_ref2,'String',{' '})
+ set(handles.ref_fix2,'UserData',[]);
+ set(handles.ref_fix2,'String','');
+ set(handles.thresh_vel2,'String','0');
+
+%--------------------------------------------------------
+% --- Executes on selection change in inf_sup1.
+function inf_sup1_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------------------------------------
+
+
+% --- Executes on selection change in field_ref.
+function field_ref_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------------------------
+
+% --- Executes on selection change in field_ref2.
+function field_ref2_Callback(hObject, eventdata, handles)
+
+% -----------------------------------------------------------
+% transform letters to numbers
+%--------------------------------------------
+function numres=stra2num(str)
+numres=double(str)-96;
+if double(str) >= 48 & double(str) <= 57 % = 1 for numbers
+ numres=str2num(str);
+end
+
+
+% --- Executes on button press in test_stereo1.
+function test_stereo1_Callback(hObject, eventdata, handles)
+if isequal(get(handles.test_stereo1,'Value'),0)
+ set(handles.subdomain_patch1,'Visible','on')
+ set(handles.rho_patch1,'Visible','on')
+else
+ set(handles.subdomain_patch1,'Visible','off')
+ set(handles.rho_patch1,'Visible','off')
+end
+
+% --- Executes on button press in test_stereo2.
+function test_stereo2_Callback(hObject, eventdata, handles)
+if isequal(get(handles.test_stereo2,'Value'),0)
+ set(handles.subdomain_patch2,'Visible','on')
+ set(handles.rho_patch2,'Visible','on')
+else
+ set(handles.subdomain_patch2,'Visible','off')
+ set(handles.rho_patch2,'Visible','off')
+end
+
+% --- Executes on button press in ImaThreshold.
+function ImaThreshold_Callback(hObject, eventdata, handles)
+if isequal(get(handles.ImaThreshold,'Value'),1)
+ set(handles.MinIma,'Visible','on')
+ set(handles.MaxIma,'Visible','on')
+else
+ set(handles.MinIma,'Visible','off')
+ set(handles.MaxIma,'Visible','off')
+end
+
+
+% --- Executes on button press in ImaThreshold2.
+function ImaThreshold2_Callback(hObject, eventdata, handles)
+if isequal(get(handles.ImaThreshold2,'Value'),1)
+ set(handles.MinIma2,'Visible','on')
+ set(handles.MaxIma2,'Visible','on')
+else
+ set(handles.MinIma2,'Visible','off')
+ set(handles.MaxIma2,'Visible','off')
+end
+
+
+
+% --- Executes on button press in Experimental.
+function Experimental_Callback(hObject, eventdata, handles)
+
+
+
+function ibz_Callback(hObject, eventdata, handles)
+% hObject handle to ibz (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of ibz as text
+% str2double(get(hObject,'String')) returns contents of ibz as a double
+
+
+% --- Executes during object creation, after setting all properties.
+function ibz_CreateFcn(hObject, eventdata, handles)
+% hObject handle to ibz (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+
+function edit74_Callback(hObject, eventdata, handles)
+% hObject handle to edit74 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of edit74 as text
+% str2double(get(hObject,'String')) returns contents of edit74 as a double
+
+
+% --- Executes during object creation, after setting all properties.
+function edit74_CreateFcn(hObject, eventdata, handles)
+% hObject handle to edit74 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+
+function edit75_Callback(hObject, eventdata, handles)
+% hObject handle to edit75 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of edit75 as text
+% str2double(get(hObject,'String')) returns contents of edit75 as a double
+
+
+% --- Executes during object creation, after setting all properties.
+function edit75_CreateFcn(hObject, eventdata, handles)
+% hObject handle to edit75 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+
+function dz_civ1_Callback(hObject, eventdata, handles)
+% hObject handle to dz_civ1 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of dz_civ1 as text
+% str2double(get(hObject,'String')) returns contents of dz_civ1 as a double
+
+
+% --- Executes during object creation, after setting all properties.
+function dz_civ1_CreateFcn(hObject, eventdata, handles)
+% hObject handle to dz_civ1 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
Index: /trunk/src/close_fig.m
===================================================================
--- /trunk/src/close_fig.m (revision 2)
+++ /trunk/src/close_fig.m (revision 2)
@@ -0,0 +1,12 @@
+%'close_fig': function activated when a figure is closed
+%----------------------------------------------------------------
+% function close_fig(ggg,eventdata,hparent,type)
+% activated by the command:
+%set(hObject,'DeleteFcn',{@close_fig,hparent,type})
+% where hObject is the handle of the figure
+%
+
+function close_fig(ggg,eventdata,hparent,type)
+if isequal(type,'zoom')
+ delete(hparent) % delete the rectangle showing the zoom graph in the parent fig
+end
Index: /trunk/src/copyfields.m
===================================================================
--- /trunk/src/copyfields.m (revision 2)
+++ /trunk/src/copyfields.m (revision 2)
@@ -0,0 +1,22 @@
+%'copyfields' copy fields between two matlab structures
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% OUPUT:
+% NewData: resulting structure
+%
+%INPUT:
+% listfields: cell arrays representing the list of field names to be copied
+% SourceData: structure containing the source data to copy in NewData
+% OldData: (optional) preexisting data structure.
+
+function NewData=copyfields(listfields,SourceData,OldData)
+if ~exist('OldData','var')
+ OldData=[];
+end
+NewData=OldData;%default
+for ifield=1:length(listfields)
+ if isfield(SourceData,listfields{ifield}) & ~isempty(eval(['SourceData.' listfields{ifield}]))
+ eval(['NewData.' listfields{ifield} '=SourceData.' listfields{ifield} ';']);
+ elseif isfield(OldData,listfields{ifield})
+ NewData=rmfield(NewData,listfields{ifield});
+ end
+end
Index: /trunk/src/dataview.m
===================================================================
--- /trunk/src/dataview.m (revision 2)
+++ /trunk/src/dataview.m (revision 2)
@@ -0,0 +1,513 @@
+%TEST 'dataview': function for scanning directories in a campaign (TEST)
+%------------------------------------------------------------------------
+% function varargout = series(varargin)
+% associated with the GUI dataview.fig
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function varargout = dataview(varargin)
+
+% Last Modified by GUIDE v2.5 28-Apr-2009 00:12:36
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @dataview_OpeningFcn, ...
+ 'gui_OutputFcn', @dataview_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin & isstr(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+
+% --- Executes just before dataview is made visible.
+function dataview_OpeningFcn(hObject, eventdata, handles, varargin)
+
+% Choose default command line output for dataview
+handles.output = hObject;
+
+% Update handles structure
+guidata(hObject, handles);
+
+%----------------------------------------------------------------
+% --- Outputs from this function are returned to the command line.
+function varargout = dataview_OutputFcn(hObject, eventdata, handles)
+
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%------------------------------------------------------
+% --- Executes on button press in browser.
+function browser_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+
+CurrentFile='/coriolis/bigone/PROJETS';%get(handles.RootDirectory,'String');
+set(handles.SubCampaignTest,'Value',0)
+CampaignDir=uigetdir(CurrentFile,'Open the Campaign directory'); %file browser
+set(handles.RootDirectory,'String',CampaignDir)
+RootDirectory_Callback(hObject, eventdata, handles)
+
+% --- Executes on button press in open_SubCampaign.
+function OpenSubCampaign_Callback(hObject, eventdata, handles)
+CurrentFile='/coriolis/bigone/PROJETS';%get(handles.RootDirectory,'String');
+set(handles.SubCampaignTest,'Value',1)
+CampaignDir=uigetdir(CurrentFile,'Open the Campaign directory'); %file browser
+set(handles.RootDirectory,'String',CampaignDir)
+
+RootDirectory_Callback(hObject, eventdata, handles)
+
+%------------------------------------------------------------------------
+
+function RootDirectory_Callback(hObject, eventdata, handles)
+CampaignDir=get(handles.RootDirectory,'String');
+if exist(CampaignDir,'dir')
+ hdir=dir(CampaignDir); %list files and dirs
+ idir=0;
+ for ilist=1:length(hdir)
+ if hdir(ilist).isdir
+ dirname=hdir(ilist).name;
+ if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
+ idir=idir+1;
+ ExpName{idir}=hdir(ilist).name;
+ end
+ % look for the list of 'devices'
+ else
+ %warning for isolated files
+ end
+ end
+ set(handles.ListExperiments,'String',[{'*'};ExpName'])
+ set(handles.ListExperiments,'Value',1)
+ ListExperiments_Callback(hObject, eventdata, handles)
+else
+ warndlg_uvmat(['The input ' CampaignDir ' is not a directory'],'ERROR')
+end
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in ListExperiments.
+ function ListExperiments_Callback(hObject, eventdata, handles)
+CurrentPath=get(handles.RootDirectory,'String');
+ListExperiments=get(handles.ListExperiments,'String');
+list_val=get(handles.ListExperiments,'Value');
+if isequal(list_val(1),1)
+ ListExperiments=ListExperiments(2:end); %choose all experiments
+ testList=1;
+ set(handles.ListExperiments,'Value',1)
+else
+ ListExperiments=ListExperiments(list_val);%choose selected experiments
+ testList=0;
+end
+set(handles.ListDevices,'Value',1)
+set(handles.ListRecords,'Value',1)
+set(handles.ListXml,'Value',1)
+[ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,{},{});
+set(handles.ListRecords,'String',[{'*'};ListRecords'])
+set(handles.ListDevices,'String',[{'*'};ListDevices'])
+set(handles.ListXml,'String',[{'*'};ListXml'])
+if testList
+ hh=get(handles.ListExperiments,'parent');
+ set(hh,'UserData',List)
+end
+set(handles.CampaignDoc,'Visible','on')
+set(handles.edit_xml,'Visible','on')
+
+%------------------------------------------------------------------------
+% --- Executes on button press in update_headings.
+function ListDevices_Callback(hObject, eventdata, handles)
+CurrentPath=get(handles.RootDirectory,'String');
+ListExperiments=get(handles.ListExperiments,'String');
+list_val=get(handles.ListExperiments,'Value');
+if isequal(list_val,1)
+ ListExperiments=ListExperiments(2:end);
+else
+ ListExperiments=ListExperiments(list_val);
+end
+set(handles.ListRecords,'Value',1)
+set(handles.ListXml,'Value',1)
+ListDevices=get(handles.ListDevices,'String');
+list_val=get(handles.ListDevices,'Value');
+if isequal(list_val,1)
+ ListDevices=ListDevices(2:end);
+else
+ ListDevices=ListDevices(list_val);
+end
+[ListDevices,ListRecords,ListXml]=ListDir(CurrentPath,ListExperiments,ListDevices,{});
+set(handles.ListRecords,'String',[{'*'};ListRecords'])
+set(handles.ListXml,'String',[{'*'};ListXml'])
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in ListRecords.
+function ListRecords_Callback(hObject, eventdata, handles)
+Value=get(handles.ListRecords,'Value');
+if isequal(Value(1),1)
+ set(handles.ListRecords,'Value',1);
+end
+
+%------------------------------------------------------------------------
+% --- Executes on button press in CampaignDoc.
+function CampaignDoc_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file')
+if ~isequal(answer{1},'OK')
+ return
+end
+set(handles.ListExperiments,'Value',1)
+ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
+hh=get(handles.CampaignDoc,'parent');
+List=get(hh,'UserData');
+Currentpath=get(handles.RootDirectory,'String');
+[Currentpath,Campaign,DirExt]=fileparts(Currentpath);
+Campaign=[Campaign DirExt];
+t=xmltree;
+t=set(t,1,'name','CampaignDoc');
+t = attributes(t,'add',1,'source','directory');
+SubCampaignTest=get(handles.SubCampaignTest,'Value');
+root_uid=1;
+if SubCampaignTest
+ %TO DO open an exoiting xml doc
+ [t,root_uid]=add(t,1,'element','SubCampaign');
+ t =attributes(t,'add',root_uid,'DirName',Campaign);
+end
+for iexp=1:length(List.Experiment)
+ set(handles.ListExperiments,'Value',iexp+1)
+ drawnow
+ test_mod=0;
+ [t,uid_exp]=add(t,root_uid,'element','Experiment');
+ t = attributes(t,'add',uid_exp,'i',num2str(iexp));
+ ExpName=List.Experiment{iexp}.name;
+ t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
+
+ if isfield(List.Experiment{iexp},'Device')
+ for idevice=1:length(List.Experiment{iexp}.Device)
+ [t,uid_device]=add(t,uid_exp,'element','Device');
+ DeviceName=List.Experiment{iexp}.Device{idevice}.name;
+ t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);
+ if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
+ for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
+ FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
+ [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
+ if test
+ [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']
+ end
+ if isequal(Title,'ImaDoc')
+ [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
+ t = attributes(t,'add',uid_xml,'source','file');
+ [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});
+ end
+ end
+ elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
+ for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
+ RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
+ [t,uid_record]=add(t,uid_device,'element','Record');
+ t = attributes(t,'add',uid_record,'DirName',RecordName);
+ if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
+ for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
+ FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
+ [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
+ if test
+ [FileName ' , Heading updated']
+ end
+ [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
+ t = attributes(t,'add',uid_xml,'source','file');
+ [t]=add(t,uid_xml,'chardata',FileName);
+ end
+ end
+ end
+ end
+ end
+ end
+end
+set(handles.ListExperiments,'Value',1)
+outputdir=get(handles.RootDirectory,'String');
+[path,dirname]=fileparts(outputdir);
+outputfile=fullfile(outputdir,[dirname '.xml']);
+%campaigndoc(t);
+save(t,outputfile)
+
+%------------------------------------------------------------------------
+% --- Executes on button press in CampaignDoc.
+function edit_xml_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+CurrentPath=get(handles.RootDirectory,'String');
+%[CurrentPath,Name,Ext]=fileparts(CurrentDir);
+ListExperiments=get(handles.ListExperiments,'String');
+Value=get(handles.ListExperiments,'Value');
+if ~isequal(Value,1)
+ ListExperiments=ListExperiments(Value);
+end
+ListDevices=get(handles.ListDevices,'String');
+Value=get(handles.ListDevices,'Value');
+if ~isequal(Value,1)
+ ListDevices=ListDevices(Value);
+end
+ListRecords=get(handles.ListRecords,'String');
+Value=get(handles.ListRecords,'Value');
+if ~isequal(Value,1)
+ ListRecords=ListRecords(Value);
+end
+[ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
+ListXml=get(handles.ListXml,'String');
+Value=get(handles.ListXml,'Value');
+set(handles.ListXml,'Value',Value(1));
+if isequal(Value(1),1)
+ warndlg_uvmat('an xml file needs to be selected','ERROR')
+ return
+else
+ XmlName=ListXml{Value(1)};
+end
+for iexp=1:length(List.Experiment)
+ ExpName=List.Experiment{iexp}.name;
+ if isfield(List.Experiment{iexp},'Device')
+ for idevice=1:length(List.Experiment{iexp}.Device)
+ DeviceName=List.Experiment{iexp}.Device{idevice}.name;
+ if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
+ for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
+ FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}
+ if isequal(FileName,XmlName)
+ editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
+ return
+ end
+ end
+ elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
+ for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
+ RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
+ if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
+ for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
+ FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
+ if isequal(FileName,XmlName)
+ editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName));
+ return
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% CurrentPath/Campaign: root directory
+function [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign)
+
+ %Shema for Heading:
+% Campaign
+% (SubCampaign)
+% Experiment
+% Device
+% (Record)
+% ImageName
+% DateExp
+% old: %Project: suppressed ( changed to Campaign)
+ %Exp: suppressed (changed to experiment)
+ %ImaNames: changed to ImageName
+if exist('Record','var') && ~isempty(Record)
+ xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname);
+ testrecord=1;
+else
+ xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname);
+ testrecord=0;
+end
+if ~exist('testSubCampaign','var')
+ testSubCampaign=0;
+end
+if testSubCampaign
+ SubCampaign=Campaign;
+ [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
+ Campaign=[Campaign DirExt];
+end
+test_mod=0; %test for the modification of the xml file
+t_device=xmltree(xmlfullname);
+Title=get(t_device,1,'name');
+uid_child=children(t_device,1);
+Heading_old=[];
+uidheading=0;
+for ilist=1:length(uid_child)
+ name=get(t_device,uid_child(ilist),'name');
+ if isequal(name,'Heading')
+ uidheading=uid_child(ilist);
+ end
+end
+if uidheading
+ subt=branch(t_device,uidheading);
+ Heading_old=convert(subt);
+else
+ return % do not edit xml files without element 'Heading'
+end
+if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign))
+ test_mod=1;
+end
+Heading.Campaign=Campaign;
+if testSubCampaign
+ if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign))
+ test_mod=1;
+ end
+ Heading.SubCampaign=SubCampaign;
+end
+if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment))
+ test_mod=1;
+end
+Heading.Experiment=Experiment;
+if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device))
+ test_mod=1;
+end
+Heading.Device=Device;
+if testrecord
+ if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record))
+ test_mod=1;
+ end
+ Heading.Record=Record;
+end
+if isfield(Heading_old,'ImaNames')
+ test_mod=1;
+ if ~isempty(Heading_old.ImaNames)
+ Heading.ImageName=Heading_old.ImaNames;
+ end
+end
+if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName)
+ Heading.ImageName=Heading_old.ImageName;
+end
+if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp)
+ Heading.DateExp=Heading_old.DateExp;
+end
+if test_mod && uidheading
+ uid_child=children(t_device,uidheading);
+ t_device=delete(t_device,uid_child);
+ t_device=struct2xml(Heading,t_device,uidheading);
+ backupfile=xmlfullname;
+ testexist=2;
+ while testexist==2
+ backupfile=[backupfile '~'];
+ testexist=exist(backupfile,'file');
+ end
+ [success,message]=copyfile(xmlfullname,backupfile);%make backup
+ if isequal(success,1)
+ delete(xmlfullname)
+ else
+ return
+ end
+ save(t_device,xmlfullname)
+end
+
+% --- Executes on button press in HELP.
+function HELP_Callback(hObject, eventdata, handles)
+path_to_uvmat=which ('uvmat')% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+else
+web([helpfile '#dataview'])
+end
+
+
+
+
+% --- Executes on button press in SubCampaignTest.
+function SubCampaignTest_Callback(hObject, eventdata, handles)
+
+
+% --- Executes on selection change in ListXml.
+function ListXml_Callback(hObject, eventdata, handles)
+Value=get(handles.ListXml,'Value');
+if isequal(Value(1),1)
+ set(handles.ListXml,'Value',1);
+end
+
+
+% --- Executes on button press in clean_civ_cmx.
+function clean_civ_cmx_Callback(hObject, eventdata, handles)
+message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)';
+answer=msgbox_uvmat('INPUT_Y-N',message);
+if ~isequal(answer{1},'OK')
+ return
+end
+set(handles.ListExperiments,'Value',1)
+ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
+hh=get(handles.CampaignDoc,'parent');
+List=get(hh,'UserData');
+Currentpath=get(handles.RootDirectory,'String');
+[Currentpath,Campaign,DirExt]=fileparts(Currentpath);
+Campaign=[Campaign DirExt];
+SubCampaignTest=get(handles.SubCampaignTest,'Value');
+nbdelete_tot=0;
+for iexp=1:length(List.Experiment)
+ set(handles.ListExperiments,'Value',iexp+1)
+ drawnow
+ test_mod=0;
+ ExpName=List.Experiment{iexp}.name;
+ nbdelete=0;
+ if isfield(List.Experiment{iexp},'Device')
+ for idevice=1:length(List.Experiment{iexp}.Device)
+ DeviceName=List.Experiment{iexp}.Device{idevice}.name;
+ if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
+ currentdir=fullfile(Currentpath,Campaign,ExpName,DeviceName);
+ hdir=dir(currentdir); %list files and dirs
+ idir=0;
+ for ilist=1:length(hdir)
+ if hdir(ilist).isdir
+ dirname=hdir(ilist).name;
+ if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
+ CivDir=fullfile(currentdir,dirname)
+ hCivDir=dir(CivDir);
+ for ilist=1:length(hCivDir)
+ FileName=hCivDir(ilist).name;
+ [dd,ff,Ext]=fileparts(FileName);
+ if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors')
+ delete(fullfile(CivDir,FileName))
+ nbdelete=nbdelete+1;
+ end
+ end
+ end
+ end
+ end
+ elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
+ for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
+ RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
+ if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
+ 'look at subdirectories'
+ end
+ end
+ end
+ end
+ end
+ display([num2str(nbdelete) ' files deleted'])
+ nbdelete_tot=nbdelete_tot+nbdelete;
+end
+msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete_tot) ' files deleted by clean_civ_cmx'])
+set(handles.ListExperiments,'Value',1)
+
+
+
+
Index: /trunk/src/datenum_uvmat.m
===================================================================
--- /trunk/src/datenum_uvmat.m (revision 2)
+++ /trunk/src/datenum_uvmat.m (revision 2)
@@ -0,0 +1,602 @@
+%'datenum_uvmat': like the Matlab function datenum.m but gives empty output instead of stopping for input error
+%--------------------------------------------------------------------------
+function n = datenum_uvmat(arg1,arg2,arg3,h,min,s)
+%DATENUM Serial date number.
+% N = DATENUM(V) converts one or more date vectors V into serial date
+% numbers N. Input V can be an M-by-6 or M-by-3 matrix containing M full
+% or partial date vectors respectively. DATENUM returns a column vector
+% of M date numbers.
+%
+% A date vector contains six elements, specifying year, month, day, hour,
+% minute, and second. A partial date vector has three elements, specifying
+% year, month, and day. Each element of V must be a positive double
+% precision number. A serial date number of 1 corresponds to Jan-1-0000.
+% The year 0000 is merely a reference point and is not intended to be
+% interpreted as a real year.
+%
+% N = DATENUM(S,F) converts one or more date strings S to serial date
+% numbers N using format string F. S can be a character array where each
+% row corresponds to one date string, or one dimensional cell array of
+% strings. DATENUM returns a column vector of M date numbers, where M is
+% the number of strings in S.
+%
+% All of the date strings in S must have the same format F, which must be
+% composed of date format symbols according to Table 2 in DATESTR help.
+% Formats with 'Q' are not accepted by DATENUM.
+%
+% Certain formats may not contain enough information to compute a date
+% number. In those cases, hours, minutes, and seconds default to 0, days
+% default to 1, months default to January, and years default to the
+% current year. Date strings with two character years are interpreted to
+% be within the 100 years centered around the current year.
+%
+% N = DATENUM(S,F,P) or N = DATENUM(S,P,F) uses the specified format F
+% and the pivot year P to determine the date number N, given the date
+% string S. The pivot year is the starting year of the 100-year range in
+% which a two-character year resides. The default pivot year is the
+% current year minus 50 years.
+%
+% N = DATENUM(Y,MO,D) and N = DATENUM([Y,MO,D]) return the serial date
+% numbers for corresponding elements of the Y,MO,D (year,month,day)
+% arrays. Y, MO, and D must be arrays of the same size (or any can be a
+% scalar).
+%
+% N = DATENUM(Y,MO,D,H,MI,S) and N = DATENUM([Y,MO,D,H,MI,S]) return the
+% serial date numbers for corresponding elements of the Y,MO,D,H,MI,S
+% (year,month,day,hour,minute,second) arrays. The six arguments must be
+% arrays of the same size (or any can be a scalar).
+%
+% N = DATENUM(S) converts the string or date vector (as defined by
+% DATEVEC) S into a serial date number. If S is a string, it must be in
+% one of the date formats 0,1,2,6,13,14,15,16,23 as defined by DATESTR.
+% This calling syntax is provided for backward compatibility, and is
+% significantly slower than the syntax which specifies the format string.
+% If the format is known, the N = DATENUM(S,F) syntax should be used.
+%
+% N = DATENUM(S,P) converts the date string S, using pivot year P. If the
+% format is known, the N = DATENUM(S,F,P) or N = DATENUM(S,P,F) syntax
+% should be used.
+%
+% Note: The vectorized calling syntax can offer significant performance
+% improvement for large arrays.
+%
+% Examples:
+% n = datenum('19-May-2000') returns n = 730625.
+% n = datenum(2001,12,19) returns n = 731204.
+% n = datenum(2001,12,19,18,0,0) returns n = 731204.75.
+% n = datenum('19.05.2000','dd.mm.yyyy') returns n = 730625.
+%
+% See also NOW, DATESTR, DATEVEC, DATETICK.
+
+% Copyright 1984-2004 The MathWorks, Inc.
+% $Revision: 1.24.4.7 $ $Date: 2004/10/27 23:53:57 $
+
+if (nargin<1) || (nargin>6)
+ error('MATLAB:datenumr:Nargin',nargchk(1,6,nargin));
+end
+
+% parse input arguments
+isdatestr = ~isnumeric(arg1);
+isdateformat = false;
+if nargin == 2
+ isdateformat = ischar(arg2);
+elseif nargin == 3
+ isdateformat = [ischar(arg2),ischar(arg3)];
+end
+% try to convert date string or date vector to a date number
+try
+ switch nargin
+ case 1
+ if isdatestr
+ n = datenummx(datevec(arg1));
+ elseif (size(arg1,2)==3) || (size(arg1,2)==6)
+ n = datenummx(arg1);
+ else
+ n = arg1;
+ end
+ case 2
+ if isdateformat
+ if ischar(arg1)
+ arg1 = cellstr(arg1);
+ end
+ n = dtstr2dtnummx(arg1,cnv2icudf(arg2));
+ else
+ n = datenummx(datevec(arg1,arg2));
+ end
+ case 3
+ if any(isdateformat)
+ if isdateformat(1)
+ format = arg2;
+ pivot = arg3;
+ elseif isdateformat(2)
+ format = arg3;
+ pivot = arg2;
+ end
+ if ischar(arg1)
+ arg1 = cellstr(arg1);
+ end
+ icu_dtformat = cnv2icudf(format);
+ showyr = strfind(icu_dtformat,'y');
+ if ~isempty(showyr)
+ wrtYr = numel(showyr);
+ checkYr = diff(showyr);
+ if any(checkYr~=1)
+ error('MATLAB:datenum:YearFormat','Unrecognized year format');
+ end
+ switch wrtYr
+ case 4,
+ icu_dtformat = strrep(icu_dtformat,'yyyy','yy');
+ case 3,
+ icu_dtformat = strrep(icu_dtformat,'yyy','yy');
+ end
+ end
+ n = dtstr2dtnummx(arg1,icu_dtformat,pivot);
+ else
+ n = datenummx(arg1,arg2,arg3);
+ end
+ case 6, n = datenummx(arg1,arg2,arg3,h,min,s);
+ otherwise, error('MATLAB:datenum:Nargin',...
+ 'Incorrect number of arguments');
+ end
+catch
+ err = lasterror;
+ err.message = sprintf('DATENUM failed.\n%s',err.message);
+
+ if (nargin == 1 && ~isdatestr)
+ err.identifier = 'MATLAB:datenum:ConvertDateNumber';
+ elseif (nargin == 1 && isdatestr) || (isdatestr && any(isdateformat))
+ err.identifier = 'MATLAB:datenum:ConvertDateString';
+ elseif (nargin > 1) && ~isdatestr && ~any(isdateformat)
+ err.identifier = 'MATLAB:datenum:ConvertDateVector';
+ end
+
+ rethrow(err);
+end
+end
+
+function [y,mo,d,h,mi,s] = datevec(t,varargin)
+%DATEVEC Date components.
+% V = DATEVEC(N) converts one or more date numbers N to date vectors V. N
+% can be a scalar, vector, or multidimensional array of positive date
+% numbers. DATEVEC returns an M-by-6 matrix containing M date vectors,
+% where M is the total number of date numbers in N.
+%
+% V = DATEVEC(S,F) converts one or more date strings S to date vectors
+% V using format string F to interpret the date strings in S. S can be a
+% cell array of strings or a character array where each row corresponds
+% to one date string. All of the date strings in S must have the same
+% format which must be composed of date format symbols according to
+% Table 2 in DATESTR help. Formats with 'Q' are not accepted by DATEVEC.
+% DATEVEC returns an M-by-6 matrix of date vectors, where M is the number
+% of date strings in S.
+%
+% Certain formats may not contain enough information to compute a date
+% vector. In those cases, hours, minutes, and seconds default to 0, days
+% default to 1, months default to January, and years default to the
+% current year. Date strings with two character years are interpreted to
+% be within the 100 years centered around the current year.
+%
+% V = DATEVEC(S,F,P) or V = DATEVEC(S,P,F) converts the date string S to
+% a date vector V, using the pivot year P and the date format F. The
+% pivot year is the starting year of the 100-year range in which a
+% two-character year resides. The default pivot year is the current year
+% minus 50 years.
+%
+% [Y,MO,D,H,MI,S] = DATEVEC(...) takes any of the two syntaxes shown
+% above and returns the components of the date vector as individual
+% variables.
+%
+% V = DATEVEC(S) converts date string S to date vector V. S must be in
+% one of the date formats 0,1,2,6,13,14,15,16,23 as defined by DATESTR.
+% This calling syntax is provided for backward compatibility, and is
+% significantly slower than the syntax which specifies the format string.
+% If the format is known, the V = DATEVEC(S,F) syntax should be used.
+%
+% V = DAVEVEC(S,P) converts the date string S using pivot year P.
+% If the format is known, the V = DATEVEC(S,F,P) or V = DATEVEC(S,P,F)
+% syntax should be used.
+%
+% Note 1: If more than one input argument is used, the first argument
+% must be a date string or array of date strings.
+%
+% Note 2: The vectorized calling syntax can offer significant performance
+% improvement for large arrays.
+%
+% Examples
+% d = '12/24/1984';
+% t = 725000.00;
+% c = datevec(d) or c = datevec(t) produce c = [1984 12 24 0 0 0].
+% [y,m,d,h,mi,s] = datevec(d) returns y=1984, m=12, d=24, h=0, mi=0, s=0.
+% c = datevec('5/6/03') produces c = [2003 5 6 0 0 0] until 2054.
+% c = datevec('5/6/03',1900) produces c = [1903 5 6 0 0 0].
+% c = datevec('19.05.2000','dd.mm.yyyy') produces c = [2000 5 19 0 0 0].
+%
+% See also DATENUM, DATESTR, CLOCK, DATETICK.
+
+% Copyright 1984-2004 The MathWorks, Inc.
+% $Revision: 1.28.4.11 $ $Date: 2004/10/27 23:53:59 $
+
+if (nargin<1) || (nargin>3)
+% error('MATLAB:datevec:Nargin',nargchk(1,3,nargin));
+ return
+end
+
+% parse input arguments
+isdatestr = ~isnumeric(t);
+isdateformat = false;
+if ~isdatestr && nargin > 1
+ warning('MATLAB:datevec:Inputs', ...
+ 'Unless the first input argument is a date string, all subsequent\narguments will be ignored.');
+elseif nargin > 1
+ isdateformat = cellfun('isclass',varargin,'char');
+ if (nargin == 3)
+ if ~isdateformat(1)
+ pivotyear = varargin{1};
+ elseif ~isdateformat(2)
+ pivotyear = varargin{2};
+ elseif isdateformat(1) && isdateformat(2)
+% error('MATLAB:datevec:DateFormat',...
+% 'You specified two date format strings.\nThere can only be one.');
+ return
+ end
+ elseif (nargin == 2) && ~isdateformat
+ pivotyear = varargin{1};
+ end
+end
+
+if isdatestr && isempty(t)
+ if nargout <= 1
+ y = zeros(0,6);
+ else
+ [y,mo,d,h,mi,s] = deal(zeros(0,0));
+ end;
+ warning('MATLAB:datevec:EmptyDate',...
+ 'Usage of DATEVEC with empty date strings is not supported.\nResults may change in future versions.');
+ return;
+end
+
+% branch to appropriate date string parser
+if isdatestr
+ % a date format string was specified
+ % map date format to ICU date format tokens
+ if ischar(t)
+ % convert to cellstring.
+ t = cellstr(t);
+ end
+ icu_dtformat = {};
+ if ~any(isdateformat)
+ format = getformat(t);
+ if ~isempty(format)
+ icu_dtformat = cnv2icudf(format);
+ end
+ else
+ icu_dtformat = cnv2icudf(varargin{isdateformat});
+ end
+ if ~isempty(icu_dtformat)
+ % call ICU MEX function to parse date string to date vector
+ try
+ if nargin < 2 || (nargin == 2 && any(isdateformat))
+ y = dtstr2dtvecmx(t,icu_dtformat);
+ else
+ showyr = findstr(icu_dtformat,'y');
+ if ~isempty(showyr)
+ wrtYr = numel(showyr);
+ if showyr(end) - showyr(1) >= wrtYr
+% error('MATLAB:datevec:YearFormat','Unrecognized year format');
+ return
+ end
+ switch wrtYr
+ case 4,
+ icu_dtformat = strrep(icu_dtformat,'yyyy','yy');
+ case 3,
+ icu_dtformat = strrep(icu_dtformat,'yyy','yy');
+ end
+ end
+ y = dtstr2dtvecmx(t,icu_dtformat,pivotyear);
+ end
+ if nargout > 1
+ mo = y(:,2);
+ d = y(:,3);
+ h = y(:,4);
+ mi = y(:,5);
+ s = y(:,6);
+ y = y(:,1);
+ end
+ catch
+ err = lasterror;
+ err.identifier = 'MATLAB:datevec:dtstr2dtvecmx';
+ err.message = sprintf(['DATEVEC failed, calling DTSTR2DTVECMX.\n'...
+ '%s'],err.message);
+ rethrow(err);
+ end
+ else
+ %last resort!!!
+ if ischar(t)
+ m = size(t,1);
+ else
+ m = length(t);
+ end
+ y = zeros(m,6);
+ t = lower(t);
+% ampmtokens = lower(getampmtokensmx);
+ amtok = 'am'; %ampmtokens{1};
+ amtok0 = 'am';
+ pmtok = 'pm';%ampmtokens{2};
+ pmtok0 = 'pm';
+ M={'jan';'feb';'mar';'apr';'may';'jun';'jul';'aug';'sept';'oct';'nov';'dec'};
+ M0=M;
+% M = lower(getmonthnames);
+% M0 = lower(getmonthnames(0)); % fall-back list of English short month names.
+ try
+ for i = 1:m
+ % Convert date input to date vector
+ % Initially, the six fields are all unknown.
+ c(1,1:6) = NaN;
+ pm = -1; % means am or pm is not in datestr
+ if ischar(t)
+ str = t(i,:);
+ else
+ str = t{i};
+ end
+ d = [' ' str ' '];
+
+ % Replace 'a ' or 'am', 'p ' or 'pm' with ': '.
+ p = max(find(d == amtok(1) | d == pmtok(1) | ...
+ d == amtok0(1)| d == pmtok0(1)));
+ if ~isempty(p)
+ if (d(p+1) == amtok(2) | ...
+ d(p+1) == amtok0(2)| isspace(d(p+1))) & ...
+ d(p-1) ~= lower('e')
+ pm = (d(p) == pmtok(1) | d(p) == pmtok0(1));
+ if d(p-1) == ' '
+ d(p-1:p+1) = ': ';
+ else
+ d(p:p+1) = ': ';
+ end
+ end
+ end
+
+ % Any remaining letters must be in the month field
+ p = find(isletter(d));
+
+ % Test length of string to catch a bogus date string.
+ % Get index of month in list of months of year
+ % replace with spaces, month name in date string.
+ % If native month name lookup fails, fall back on
+ % list of English month names.
+ if ~isempty(p) && numel(d)>4
+ k = min(p);
+ if d(k+3) == '.', d(k+3) = ' '; end
+ monthidx = ~cellfun('isempty',strfind(M,d(k:k+2)));
+ if ~any(monthidx)
+ monthidx = ~cellfun('isempty',strfind(M0,d(k:k+2)));
+ if ~any(monthidx)
+% error('MATLAB:datevec:MonthOfYear',...
+% 'Failed to lookup month of year.');
+ return
+ end
+ end
+ c(2) = find(monthidx);
+ d(p) = char(' '*ones(size(p)));
+ end
+
+ % Find all nonnumbers.
+ p = find((d < '0' | d > '9') & (d ~= '.'));
+
+ % Pick off and classify numeric fields, one by one.
+ % Colons delinate hour, minutes and seconds.
+
+ k = 1;
+ while k < length(p)
+ if d(p(k)) ~= ' ' && d(p(k)+1) == '-'
+ f = str2double(d(p(k)+1:p(k+2)-1));
+ k = k+1;
+ else
+ f = str2double(d(p(k)+1:p(k+1)-1));
+ end
+ if ~isnan(f)
+ if d(p(k))==':' || d(p(k+1))==':'
+ if isnan(c(4))
+ c(4) = f; % hour
+ % Add 12 if pm specified and hour isn't 12
+ if pm == 1 && f ~= 12
+ c(4) = f+12;
+ elseif pm == 0 && f == 12
+ c(4) = 0;
+ end
+ elseif isnan(c(5))
+ c(5) = f; % minutes
+ elseif isnan(c(6))
+ c(6) = f; % seconds
+ else
+% error('MATLAB:datevec:NumberOfTimeFields',...
+% 'Too many time fields in %s', str);
+ return
+ end
+ elseif isnan(c(2))
+ if f > 12
+% error('MATLAB:datevec:IllegalDateField',...
+% '%s is too large to be a month.',num2str(f));
+ return
+ end
+ c(2) = f; % month
+ elseif isnan(c(3))
+ c(3) = f; % date
+ elseif isnan(c(1))
+ if (f >= 0) & (p(k+1)-p(k) == 3) % two char year
+ if nargin < 2
+ clk = clock;
+ pivotyear = clk(1)-50; %(current year-50 years)
+ end
+ % Moving 100 year window centered around current year
+ c(1) = pivotyear+rem(f+100-rem(pivotyear,100),100);
+ else
+ c(1) = f; % year
+ end
+ else
+% error('MATLAB:datevec:NumberOfDateFields',...
+% 'Too many date fields in %s', str);
+ return
+ end
+ end
+ k = k+1;
+ end
+
+ if sum(isnan(c)) >= 5
+% error('MATLAB:datevec:ParseDateString',...
+% 'Cannot parse date %s', str);
+ return
+ end
+ % If any field has not been specified
+ if isnan(c(1)), clk = clock; c(1) = clk(1); end
+ if isnan(c(2)), c(2) = 1; end;
+ if isnan(c(3)), c(3) = 1; end;
+ if isnan(c(4)), c(4) = 0; end;
+ if isnan(c(5)), c(5) = 0; end;
+ if isnan(c(6)), c(6) = 0; end;
+
+ % Normalize components to correct ranges.
+ y(i,:) = datevecmx(datenummx(c));
+ end
+ catch
+ err = lasterror;
+ err.message = sprintf('Failed to parse date string.\n%s',...
+ err.message);
+ rethrow(err);
+ end
+ if nargout > 1
+ mo = y(:,2);
+ d = y(:,3);
+ h = y(:,4);
+ mi = y(:,5);
+ s = y(:,6);
+ y = y(:,1);
+ end
+ end
+elseif nargout <= 1
+ % date number was specified
+ y = datevecmx(t);
+elseif nargout == 3
+ % date number was specified and first three date fields for output
+ [y,mo,d] = datevecmx(t);
+else
+ % date number was specified and all six date fields for output
+ [y,mo,d,h,mi,s] = datevecmx(t);
+end
+end
+%--------------------------------------------------------------------------
+%--
+function [format] = getformat(str)
+ format = '';
+ formatstr = cell(11,1);
+ formatstr(1) = {'dd-mmm-yyyy HH:MM:SS'};
+ formatstr(2) = {'dd-mmm-yyyy'};
+ formatstr(3) = {'mm/dd/yy'};
+ formatstr(4) = {'mm/dd'};
+ formatstr(5) = {'HH:MM:SS'};
+ formatstr(6) = {'HH:MM:SS PM'};
+ formatstr(7) = {'HH:MM'};
+ formatstr(8) = {'HH:MM PM'};
+ formatstr(9) = {'mm/dd/yyyy'};
+ formatstr(10) = {'dd-mmm-yyyy HH:MM'}; %used by finance
+ formatstr(11) = {'dd-mmm-yy'}; %used by finance
+
+ AlphaFormats = [1 1 0 0 0 1 0 1 0 1 1];
+ %[1 2 6 8 10 11];
+ SlashFormats = [ 0 0 1 1 0 0 0 0 1 0 0];
+ %[3 4 9];
+ TwoSlashFormats = [ 0 0 1 0 0 0 0 0 1 0 0];
+ %[3 9];
+ DashFormats = [ 1 1 0 0 0 0 0 0 0 1 1];
+ %[1 2 10 11];
+ ColonFormats = [1 0 0 0 1 1 1 1 0 1 0];
+ %[1 5 6 7 8 10];
+ TwoColonFormats = [1 0 0 0 1 1 0 0 0 0 0];
+ %[1 5 6];
+ SpaceFormats = [1 0 0 0 0 1 0 1 0 1 0];
+ %[1 6 8 10];
+
+ bMask = [ 1 1 1 1 1 1 1 1 1 1 1];
+
+ if length(str) > 1
+ str = str(1,1);
+ end
+ str = strtrim(char(str));
+ slashes = strfind(str, '/');
+ if ~isempty(slashes)
+ bMask = bMask & SlashFormats;
+ if (length(slashes) > 0 && slashes(1) == 2)
+ if (length(slashes) > 1 && slashes(2) == 4)
+ str = ['0' str(1:slashes(1)) '0' str(slashes(1)+1:end)];
+ else
+ str = ['0' str];
+ end
+ elseif (length(slashes) > 1 && slashes(2) - slashes(1) == 2)
+ str = [str(1:slashes(1)) '0' str(slashes(1)+1:end)];
+ end
+ if length(slashes) > 1
+ bMask = bMask & TwoSlashFormats;
+ else
+ bMask = bMask & ~TwoSlashFormats;
+ end
+ else
+ bMask = bMask & ~SlashFormats;
+ end
+
+ dashes = strfind(str,'-');
+ if ~isempty(dashes)
+ bMask = bMask & DashFormats;
+ if (length(dashes) > 0 && dashes(1) == 2)
+ str = ['0' str];
+ end
+ else
+ bMask = bMask & ~DashFormats;
+ end
+
+ colons = strfind(str,':');
+ if ~isempty(colons)
+ bMask = bMask & ColonFormats;
+ if (length(colons) > 0) && (colons(1) == 2) && (length(str) - colons(end) > 3)
+ str = ['0' str];
+ end
+ if length(colons) > 1
+ bMask = bMask & TwoColonFormats;
+ else
+ bMask = bMask & ~TwoColonFormats;
+ end
+ else
+ bMask = bMask & ~ColonFormats;
+ end
+
+ spaces = strfind(str,' ');
+ if ~isempty(spaces)
+ bMask = bMask & SpaceFormats;
+ else
+ bMask = bMask & ~SpaceFormats;
+ end
+
+ for i = 1:11
+ if bMask(i)
+ try
+ str1 = dateformverify(str,char(formatstr(i)));
+ if (strcmpi(str, strtrim(str1)) == 1)
+ format = char(formatstr(i));
+ break;
+ end
+ catch
+ lasterr('');
+ end
+ if AlphaFormats(i)
+ try
+ str1 = dateformverify(str,char(formatstr(i)),'local');
+ if (strcmpi(str, strtrim(str1)) == 1)
+ format = char(formatstr(i));
+ break;
+ end
+ catch
+ lasterr('');
+ end
+ end
+ end
+ end
+ end
Index: /trunk/src/delete_object.m
===================================================================
--- /trunk/src/delete_object.m (revision 2)
+++ /trunk/src/delete_object.m (revision 2)
@@ -0,0 +1,73 @@
+%'delete_object': delete a projection object, defined by its index in the Uvmat list or by its graphic handle
+%
+%INPUT:
+% hObject: object index (if integer) or handle of the graphic object. If
+% hObject is a subobject, the parent object is detected and deleted.
+
+function delete_object(hObject)
+
+huvmat=findobj('Name','uvmat');%handles of the uvmat interface
+UvData=get(huvmat,'UserData');
+hlist_object=findobj(huvmat,'Tag','list_object');%handles of the object liçst in the uvmat interface
+list_str=get(hlist_object,'String');%objet list
+ObjectData=[];%default
+hdisplay=[];
+if isequal(floor(hObject),hObject) %case of an index
+ if ~isempty(UvData) & isfield(UvData, 'Object') & length(UvData.Object)>=hObject
+ if isfield(UvData.Object{hObject},'HandlesDisplay')
+ hdisplay=UvData.Object{hObject}.HandlesDisplay;
+ for iview=1:length(hdisplay)
+ if ishandle(hdisplay(iview)) & ~isequal(hdisplay(iview),0)
+ ObjectData=get(hdisplay(iview),'UserData');
+ if isfield(ObjectData,'SubObject') & ishandle(ObjectData.SubObject)
+ delete(ObjectData.SubObject);
+ end
+ if isfield(ObjectData,'DeformPoint') & ishandle(ObjectData.DeformPoint)
+ delete(ObjectData.DeformPoint);
+ end
+ delete(hdisplay(iview))
+ end
+ ishandle(hdisplay(iview))
+ end
+ end
+ for iobj=hObject+1:length(UvData.Object)
+ hdisplay=UvData.Object{iobj}.HandlesDisplay;
+ for iview=1:length(hdisplay)
+ if ishandle(hdisplay(iview)) && ~isequal(hdisplay(iview),0)
+ PlotData=get(hdisplay(iview),'UserData');
+ PlotData.IndexObj=iobj-1;
+ set(hdisplay(iview),'UserData',PlotData);
+ end
+ end
+ end
+ UvData.Object(hObject)=[];
+ list_str(hObject)=[];
+ end
+elseif ishandle(hObject)%object handle
+ userdata=get(hObject,'UserData');
+ if ishandle(userdata)%the selected line depends on a parent line
+ hdisplay=userdata;% the parent object becomes the current one
+ else
+ hdisplay=hObject;% the selected object becomes the current one
+ end
+ PlotData=get(hdisplay,'UserData');
+ if isfield(PlotData,'SubObject') & ishandle(PlotData.SubObject)
+ delete(PlotData.SubObject);
+ end
+ if isfield(PlotData,'DeformPoint') & ishandle(PlotData.DeformPoint)
+ delete(PlotData.DeformPoint);
+ end
+ delete(hdisplay);
+ if isfield(PlotData,'IndexObj')
+ IndexObj=PlotData.IndexObj;
+ if isequal(round(IndexObj),IndexObj) & IndexObj>=1 & length(list_str) > IndexObj
+ if isfield(UvData,'Object')& length(UvData.Object) > IndexObj
+ UvData.Object(IndexObj)=[];
+ end
+ list_str(IndexObj)=[];
+ end
+ end
+end
+set(huvmat,'UserData',UvData);
+set(hlist_object,'String',list_str)
+set(hlist_object,'Value',length(list_str))
Index: /trunk/src/editxml.m
===================================================================
--- /trunk/src/editxml.m (revision 2)
+++ /trunk/src/editxml.m (revision 2)
@@ -0,0 +1,1556 @@
+%'editxml': function for editing xml files using a xml schema (associated with the GUI editxml.fig)
+%------------------------------------------------------------------------
+% function heditxml=editxml(inputfile)
+%
+%OUTPUT: heditxml: graphic handle of the GUI
+%
+%INPUT: inputfile: name of an xml file
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function varargout = editxml(varargin)
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @editxml_OpeningFcn, ...
+ 'gui_OutputFcn', @editxml_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin & isstr(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+
+% --- Executes just before editxml is made visible.
+function editxml_OpeningFcn(hObject, eventdata, handles, varargin)
+% This function has no output args, see OutputFcn.
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+% varargin command line arguments to editxml (see VARARGIN)
+
+% set(handles.replicate,'String',['copy';'<---'])
+if nargin
+ CurrentFile=varargin{1}
+else
+ CurrentFile=[];
+end
+% if exist('varargin') & length(varargin)>=1
+% CurrentFile=cell2mat(varargin{1});
+% else
+% CurrentFile=[];
+% end
+% Choose default command line output for editxml
+handles.output = hObject;
+% set(hObject,'Units','pixel')
+if exist(CurrentFile,'file')
+ [PathName,Nme,FileExt]=fileparts(CurrentFile);
+ if isequal(FileExt,'.xls')
+ DataIn.hfig_xls=read_xls(CurrentFile);% DataIn.hfig_xls=handle of the Excel display figure
+ DataIn.CurrentUid=1;
+ figpos=get(hObject,'Position');%position of the editxml interface
+ figposunit=get(hObject,'Units');%unity used to indicate position
+ newfigpos=[figpos(1)-0.5*figpos(3) figpos(2) figpos(3) figpos(4)];
+ set(DataIn.hfig_xls,'Units',figposunit)
+ set(DataIn.hfig_xls,'Position',newfigpos); %set position of the Excel display figure
+ set(hObject,'UserData',DataIn)
+ else
+ set(handles.CurrentFile,'String',CurrentFile)
+ CurrentFile_Callback(hObject, eventdata, handles)
+ end
+end
+% Update handles structure
+guidata(hObject, handles);
+
+%----------------------------------------------------------------
+% --- Outputs from this function are returned to the command line.
+function varargout = editxml_OutputFcn(hObject, eventdata, handles)
+% varargout cell array for returning output args (see VARARGOUT);
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+
+
+% --- Executes on selection change in list_element.
+function list_element_Callback(hObject, eventdata, handles)
+global t xs t_ref
+CurrentFile=get(handles.CurrentFile,'String');
+bla=get(hObject,'String');
+ind=get(hObject,'Value');
+list=get(hObject,'UserData');
+NewRootUid=list.uid(ind);
+heditxml=get(hObject,'Parent');
+DataIn=get(heditxml,'UserData');
+if ~isempty(xs)
+ xs_node=list.xs_uid(ind);%xs_node of the subelement #ind
+ [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_node);
+ [element,subelem]=get_xml(t,path,xs_element,NewRootUid,xs_subelem);
+ update_list(handles,path,xs_element,element,NewRootUid,xs_subelem,subelem);
+ if xs_element.subtest
+ DataIn.CurrentUid=[DataIn.CurrentUid NewRootUid];%record new current uid
+ DataIn.xs_CurrentUid=[DataIn.xs_CurrentUid xs_node];%record the new curent schema uid
+ end
+
+% %update the import file display
+% if isfield(DataIn,'h_ref')&ishandle(DataIn.h_ref)
+% tag0_ref=find(t_ref,['/' path '/' xs_element.key]);
+% node_ref=list.index(ind);
+% if length(tag0_ref)1
+ nodeup=DataIn.CurrentUid(end-1);
+ DataIn.CurrentUid(end)=[];
+else
+ nodeup=[];
+end
+if isempty(xs)
+ if isempty(nodeup)
+ test_root=1;
+ else
+ DataIn=displ_xml(handles,t,nodeup,DataIn,heditxml);
+ end
+else
+ xs_nodeup=[];
+% if isfield(DataIn,'xs_UpUid')
+ if isfield(DataIn,'xs_CurrentUid')&length(DataIn.xs_CurrentUid)>1
+% xs_nodeup=DataIn.xs_UpUid
+ xs_nodeup=DataIn.xs_CurrentUid(end-1);
+ DataIn.xs_CurrentUid(end)=[];%uid of the root element in the schema
+ end
+ if isempty(xs_nodeup)
+ test_root=1;
+ else
+ [xs_nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_nodeup);
+ [element,subelem]=get_xml(t,path,xs_element,nodeup,xs_subelem);
+ update_list(handles,path,xs_element,element,nodeup,xs_subelem,subelem);
+ %update the import file display
+ if isfield(DataIn,'h_ref')&ishandle(DataIn.h_ref)
+ [ref_element,ref_subelem]=get_xml(t_ref,path,xs_element,nodeup,xs_subelem);
+ update_ref_list(DataIn.h_ref,xs_element,ref_element,nodeup,xs_subelem,ref_subelem);
+ end
+ end
+ set(get(hObject,'parent'),'UserData',DataIn);
+end
+if test_root% we are a the root,
+ testupfile=0;
+ DataIn=get(get(hObject,'parent'),'UserData');
+ if isfield(DataIn,'UpFile')&~isempty(DataIn.UpFile)
+ [UpPath,UpName,UpExt]=fileparts(DataIn.UpFile{1});
+ if isequal(UpExt,'.xml')
+ set(handles.CurrentFile,'String',DataIn.UpFile{1})
+ CurrentFile_Callback(handles.CurrentFile,[],handles)
+ testupfile=1;
+ DataIn.UpFile{1}={};
+ end
+ end
+ if ~testupfile %open the browser
+ RootPath=fileparts(CurrentFile);
+ [FileName, PathName]=uigetfile( ...
+ {'*.xml', '(*.xml)';
+ '*.xml', '.xml files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',RootPath); %file browser
+ fileinput_new=fullfile(PathName,FileName);
+ set(handles.CurrentFile,'String',fileinput_new)
+ CurrentFile_Callback(handles.CurrentFile,[],handles)
+ end
+end
+set(heditxml,'UserData',DataIn);
+%---------------------------------------------------------
+%edit element value
+function element_value_Callback(hObject, eventdata, handles)
+%----------------------------------------------------------
+global t xs
+if isequal(get(handles.element_value,'ForegroundColor'),[0.7 0.7 0.7])
+ return% edit element desactivated (grey display)
+end
+list_enum=get(handles.element_value,'String');
+list_index=get(handles.element_value,'Value');
+if iscell(list_enum)
+ value=list_enum{list_index};
+else
+ value=list_enum;
+end
+heditxml=get(handles.element_value,'Parent');
+DataIn=get(heditxml,'UserData');
+%create the current root element if needed
+LengthElement=length(DataIn.CurrentUid);
+FilledUid=find(DataIn.CurrentUid~=0);
+LengthFilled=FilledUid(end);
+for irank=LengthFilled+1:LengthElement
+ attrib=attributes(xs,'get',DataIn.xs_CurrentUid(irank),1);
+ [t,DataIn.CurrentUid(irank)]=add(t,DataIn.CurrentUid(irank-1),'element',attrib.val);
+end
+node_element=get(handles.element_value,'UserData');
+element_key=get(handles.element_key,'String');
+t=set_element(t,DataIn.CurrentUid(end),node_element,element_key,value);
+
+set(heditxml,'UserData',DataIn)
+%update the current listing
+[nodeup,path,xs_element,xs_subelem]=scan_schema(xs,DataIn.xs_CurrentUid(end));
+[element,subelem]=get_xml(t,path,xs_element,DataIn.CurrentUid(end),xs_subelem);
+element_index=get(handles.list_element,'Value');
+update_list(handles,path,xs_element,element,DataIn.CurrentUid(end),xs_subelem,subelem);
+set(handles.list_element,'Value',element_index);
+
+%
+% % --- Executes on button press in inport_file.
+% function inport_file_Callback(hObject, eventdata, handles)
+% CurrentFile=get(handles.RefFile,'String');
+% if isempty(CurrentFile)|isequal(CurrentFile,'')
+% CurrentFile=get(handles.CurrentFile,'String')
+% end
+% [FileName, PathName]=uigetfile( ...
+% {'*.xml', '(*.xml)';
+% '*.xml', '.xml files '; ...
+% '*.*', 'All Files (*.*)'}, ...
+% 'Pick a file',CurrentFile); %file browser
+% fileinput=fullfile(PathName,FileName);
+% sizf=size(fileinput);
+% if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end% keep only character strings as input file name
+% if exist(fileinput,'file')
+% set(handles.RefFile,'Visible','on')
+% set(handles.replicate,'Visible','on')
+% set(handles.RefFile,'String',fileinput)
+% RefFile_Callback(handles.RefFile, eventdata, handles)
+% end
+
+
+%------------------------------------------------------
+% --- Executes on button press in browser.
+function browser_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+heditxml=get(hObject,'parent');%handle of the interface figure
+DataIn=get(heditxml,'UserData');%get the current input xml file
+CurrentFile=get(handles.CurrentFile,'String');
+DataIn.Schema=[];%schema input file put to [] by default
+[FileName, PathName]=uigetfile( ...
+ {'*.xml;*.xls','(*.xml,*.xls)';
+ '*.xml', '.xml files '; ...
+ '*.xls', '.xls files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',CurrentFile); %file browser
+CurrentFile=fullfile(PathName,FileName);
+sizf=size(CurrentFile);
+if (~ischar(CurrentFile)|~isequal(sizf(1),1)),return;end% keep only character strings as input file name
+if exist(CurrentFile,'file')
+% set(handles.CurrentAttributes,'UserDataIn',PathName); %store the path to the xml file
+ [CurPath,CurName,CurExt]=fileparts(CurrentFile);
+ if isequal(CurExt,'.xls')
+ if isfield(DataIn,'hfig_xls')&ishandle(DataIn.hfig_xls)
+ [hfig_xls]=read_xls(CurrentFile,DataIn.hfig_xls);
+ else
+ [hfig_xls]=read_xls(CurrentFile);
+ end
+ figpos=get(heditxml,'Position');
+ newfigpos=[figpos(1)-0.25*figpos(3) figpos(2) 0.5*figpos(3) 0.5*figpos(4)];
+ set(hfig_xls,'Position',newfigpos)
+ else
+ set(handles.CurrentFile,'String',CurrentFile)
+ CurrentFile_Callback(hObject, eventdata, handles)
+ end
+end
+
+%------------------------------------
+function CurrentFile_Callback(hObject, eventdata, handles)
+global t xs
+CurrentFile=get(handles.CurrentFile,'String');
+heditxml=get(handles.CurrentFile,'parent');%handles of the inteface
+DataIn=get(heditxml,'UserData');
+t=xmltree(CurrentFile);%open the xml file
+head_element=get(t,1);
+if ~isfield(head_element,'name') | ~isfield(head_element,'attributes')
+ warndlg_uvmat('root element of the .xml file not in correct format','ERROR')
+end
+head_name=head_element.name;
+head_attr=head_element.attributes;% attribute of root gives the name of the associated schema
+xstest=0;
+for iattr=1:length(head_attr)
+ if isequal(head_attr{iattr}.key,'xmlns:xsi')& isequal(head_attr{iattr}.val,'none')%no schema to read
+ xs=[];
+% xstest=1;
+ end
+ if isequal(head_attr{iattr}.key,'xsi:noNamespaceSchemaLocation') & exist(head_attr{iattr}.val,'file')
+ DataIn.Schema=head_attr{iattr}.val;
+ xs=xmltree(DataIn.Schema);%open the associated schema file
+ xstest=1;
+ end
+end
+if xstest==0 %look for the corresponding schema in the directory PARAM_LINUX.xml or PARAM_WIN.xml
+ head_name=get(t,1,'name');
+ %Path to shemas:
+ path_uvmat=which('editxml');% check the path detected for source file uvmat
+ path_UVMAT=fileparts(path_uvmat); %path to UVMAT
+ if isunix
+ xmlparam=fullfile(path_UVMAT,'PARAM_LINUX.xml')
+ if exist(xmlparam,'file')
+ tparam=xmltree(xmlparam);
+ sparam=convert(tparam);
+ if isfield(sparam,'SchemaPath')
+ schemapath=[fullfile(sparam.SchemaPath,head_name) '.xsd']
+ end
+ end
+% schemapath=['/coriolis/papillon/data/civbin/XML_SCHEMAS/' head_name '.xsd']%current dir for schema
+ else
+ xmlparam=fullfile(path_UVMAT,'PARAM_WIN.xml')
+ if exist(xmlparam,'file')
+ tparam=xmltree(xmlparam);
+ sparam=convert(tparam)
+ if isfield(sparam,'SchemaPath')
+ schemapath=[fullfile(sparam.SchemaPath,head_name) '.xsd']
+ end
+ end
+% schemapath=['\\Papillon\data\civbin\XML_SCHEMAS\' head_name '.xsd']%current dir for schemas
+ end
+ if exist(schemapath,'file')
+ xs=xmltree(schemapath);
+ else
+ warndlg_uvmat(['The xml schema for ' CurrentFile ' is unknown, check the schema path set in the xml file PARAM'],'ERROR')
+ [FileName, PathName]=uigetfile( ...
+ {'*.xsd', '(*.xsd)';
+ '*.xsd', '.xsd files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ ['Pick a .xsd schema'] ,schemapath); %file browser
+ if ischar(PathName)&ischar(FileName)& exist(fullfile(PathName,FileName),'file')
+ DataIn.Schema=fullfile(PathName,FileName);
+ xs=xmltree(DataIn.Schema);%open the associated schema file
+ else
+ xs=[];
+ end
+ end
+end
+DataIn.CurrentUid=1;
+if isempty(xs)
+ displ_xml(handles,t,1,DataIn,get(hObject,'parent'));%no associated schema, default display of the xml file
+% set(handles.inport_file,'Visible','off')
+% set(handles.RefFile,'Visible','off')
+else
+ DataIn.xs_CurrentUid=find(xs,'/xs:schema/xs:element');%uid of the root element in the schema
+ [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,DataIn.xs_CurrentUid);%scan the schema at the root level
+ [element,subelem]=get_xml(t,path,xs_element,1,xs_subelem);% read the corresponding xml data
+ update_list(handles,path,xs_element,element,1,xs_subelem,subelem);%update the display of information on the interface
+ % set(handles.inport_file,'Visible','on')
+ % set(handles.RefFile,'Visible','on')
+end
+set(heditxml,'UserData',DataIn);%store the new input xml file name
+
+%-------------------------------------------------------
+% function scan_schema: read the xml schema xs
+%--------------------------------------------------------
+%OUTPUT:
+%nodeup: parent node of nodeinput
+%path: path to nodeinput in the tree
+%xs_element: element corresponding to nodeinput
+ %xs_element.uid, =tag of the element in the schema (=nodeinput)
+ %xs_element.key: key label of nodeinput
+ %xs_element.type: type of data contained in the element
+ %xs_element.annot: annotation of nodeinput
+ %xs_element.attrib: list of accepted attributes keys for xs_element
+ %xs_element.enum: enumeration, list of accepted values for nodeinput
+ %xs_element.subtest: =1 if the element contains subelements in the schema, 0 else
+
+%xs_subelement(k): subelement #k of xs_element
+ %xs_subelem(k).node: node number in the schema
+ %xs_subelem(k).key: key name of the element
+ %xs_subelem(k).testsub: =1 if element contains subelements, 0 else
+ %xs_subelem(k).minOccurs: =0 for a non mandatory element, =1 else
+ %xs_subelem(k).maxOccurs
+%
+%INPUT:
+%xs: schema xml tree
+%nodeinput: tag of the current root element in the schema
+function [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,nodeinput)
+nodeup=[];
+path=[];
+xs_element.key=[];
+xs_element.type=[];
+xs_element.annot=[];
+xs_element.attrib=[];
+xs_element.subtest=0;
+xs_element.enum={};
+xs_subelem=[];%default
+% get default nodeinput (root of the file) if not defined
+if ~exist('nodeinput') | isempty(nodeinput)% we start at the root
+ node=find(xs,'/xs:schema/xs:element');%description of the root element
+else
+ node=nodeinput;
+end
+xs_element.uid=node;
+%get the key name and element_type of the element
+node_content=get(xs,node);
+if isempty(node_content),return,end;
+if ~isempty(node_content) & isfield(node_content,'attributes')
+ attrib=node_content.attributes;
+ for iattr=1:length(attrib)
+ struct=attrib{iattr};
+ if isequal(struct.key,'name')
+ xs_element.key=struct.val; % read element key name
+ elseif isequal(struct.key,'type')
+ xs_element.type=struct.val; % read element key name
+ end
+ end
+end
+
+%get the parent node of nodeinput
+if ~isempty(node_content)
+ nodeup=get(xs,node,'parent');%move up to the parent in the tree
+ if ~isempty(nodeup)
+ nodeup=get(xs,nodeup(1),'parent');%move up to the parent in the tree
+ if isequal(nodeup,[])
+ %OUVRIR FICHIER AMONT
+ up=0;
+ else
+ nodeup=get(xs,nodeup(1),'parent');%move up to the parent in the tree
+ end
+ end
+end
+%get the path to 'nodeinput' in the schema
+up=1;
+path=[];
+if ~isempty(nodeup)
+ attrib=attributes(xs,'get',nodeup,1);
+ path=attrib.val;
+ nodeup2=nodeup;
+ while up==1;
+ nodeup2=get(xs,nodeup2(1),'parent');%move up to the parent in the tree
+ nodeup2=get(xs,nodeup2(1),'parent');%move up to the parent in the tree
+ if isempty(nodeup2)
+ up=0;
+ else
+ nodeup2=get(xs,nodeup2(1),'parent');%move up to the parent in the tree
+ if isempty(nodeup2)
+ up=0;
+ else
+ attrib=attributes(xs,'get',nodeup2,1);
+ path=[attrib.val '/' path];
+ end
+ end
+ end
+end
+
+%explore the subtree in the schema file
+node1=children(xs,node); %find the children of the root element
+test_sub=0; %no subtree in the .xml file by default
+comment='';
+element={};
+minOccurs={};
+maxOccurs={};
+testsub={};
+list_menu={};
+text={};
+if ~isempty(node1)
+ for i=1:length(node1)
+ nodename1=get(xs,node1(i),'name');
+ node2=children(xs,node1(i));
+ if isequal(nodename1,'xs:annotation')
+ for j=1:length(node2)
+ nodename2=get(xs,node2(j),'name');
+ if isequal(nodename2,'xs:documentation')
+ node3=children(xs,node2(j));
+ xs_element.annot=get(xs,node3,'value');%read annotation
+ end
+ end
+ % pour les elements
+ elseif isequal(nodename1,'xs:simpleType')
+ for j=1:length(node2)
+ nodename2=get(xs,node2(j),'name');
+ if isequal(nodename2,'xs:restriction')
+ node3=children(xs,node2(j));
+ for k=1:length(node3)
+ nodename3=get(xs,node3(k),'name');
+ if isequal(nodename3,'xs:enumeration')
+ node3_content=get(xs,node3(k));
+ attr=node3_content.attributes;
+ for m=1:length(attr)
+ struct=attr{m};
+ if isequal(struct.key,'value')
+ xs_element.enum{k}=struct.val; % read enumeration
+ end
+ end
+ end
+ end
+ end
+ end
+ elseif isequal(nodename1,'xs:complexType')
+ for j=1:length(node2)
+ nodename2=get(xs,node2(j),'name');
+ if isequal(nodename2,'xs:attribute')
+ node_content=get(xs,node2(j));
+ attr=node_content.attributes;
+ for k=1:length(attr)
+ struct=attr{k};%read attributes
+ if isequal(struct.key,'name')
+ xs_element.attrib=struct.val; %read attributes of main node
+ end
+ end
+ elseif isequal(nodename2,'xs:sequence')
+ xs_element.subtest=1;
+ node3=children(xs,node2(j));%nodes of the sequence
+ for k=1:length(node3)
+ xs_subelem(k).node=node3(k);
+ xs_subelem(k).testsub=0;%default
+ node_content=get(xs,node3(k));
+ xs_subelem(k).minOccurs=1; %default
+ xs_subelem(k).maxOccurs=1; %default
+% pref{k}=[]; %default
+ if isequal(node_content.name,'xs:element')
+ attr=node_content.attributes;
+% attr{:}.key
+ for l=1:length(attr)
+ if isequal(attr{l}.key,'name')
+ xs_subelem(k).key=attr{l}.val;%name of the element
+ elseif isequal(attr{l}.key, 'minOccurs')
+ xs_subelem(k).minOccurs=attr{l}.val;
+ elseif isequal(attr{l}.key, 'maxOccurs')
+ xs_subelem(k).maxOccurs=attr{l}.val;
+ end
+ end
+ end
+ node4=children(xs,node3(k));
+ for l=1:length(node4)
+ res=get(xs,node4(l),'name');
+ if isequal(res,'xs:complexType')%look whether the element k contains a subtree
+ node5=children(xs,node4(l));
+ for m=1:length(node5)
+ res2=get(xs,node5(m),'name');
+ if isequal(res2,'xs:sequence')
+ xs_subelem(k).testsub=1; %flag for the existence of a subtree
+ end
+ end
+ end
+ end
+ end
+
+ end
+ end
+ end
+ end
+end
+% look for predefined types
+if length(xs_element.type)>=3 & (xs_element.type([1:3])~='xs:')
+ node_type=find(xs,'/xs:schema/xs:simpleType')
+ for i=1:length(node_type)
+ content=get(xs,node_type(i));
+ nodeattr=content.attributes;
+ if ~isempty(nodeattr) & isequal(nodeattr{1}.key,'name') & isequal(nodeattr{1}.val,xs_element.type)
+ node1=children(xs,node_type(i));
+ node2=find(xs,node1,'name','xs:restriction');
+% nodename1=find(xs,
+ node3=children(xs,node2);
+ node4=find(xs,node3,'name','xs:enumeration');
+ for ienum=1:length(node4)
+ struct2=get(xs,node4(ienum));
+ enumval=struct2.attributes;
+ xs_element.enum{ienum}=enumval{1}.val;
+ end
+ end
+ end
+end
+
+%--------------------------------------------------------
+%OUTPUT:
+%element.val: value of the current element, =[] in the absence of chardata value
+%node: node (iud) of the element in t
+%element.attr_key{iattr}: attribute key #iattr of the current element
+%element.attr_val{iattr}: attribute value #iattr of the current element
+%element.attrup: %structure containing the attributes of the element, including the ones unheritated from parent nodes
+%subelem(iline).val : value of subelement # iline, concatenated with corresponding attributes
+%subelem(iline).xsindex: index k of the subelement #iline in the list xs_subelem of the schema
+%subelem(iline).index: index of the subelement #iline inside its xs_subelement, =0 when the xs_subelement is absent in t
+
+%INPUT:
+%t: xml tree
+%path: path to the current element in the schema
+%xs_element: current element in the schema
+ %xs_element.key: key label
+ %xs_element.type: type of data contained in the element
+ %xs_element.annot: annotation of nodeinput
+ %xs_element.attrib: list of accepted attributes keys for xs_element
+ %xs_element.enum: enumeration, list of accepted values
+ %xs_element.subtest: =1 if the element contains subelements in the schema, 0 else
+%index: index of the element, =1 in case of single occurence in xs_element,=0 in case of missing element
+%xs_subelem(k): subelement #k of the current element in the schema
+ %xs_subelem(k).node: node iud of the
+ %xs_subelem(k).key: key name of the subelement #k in the schema
+ %xs_subelem(k).testsub: =1 if element contains subelements, 0 else
+ %xs_subelem(k).minOccurs
+ %xs_subelem(k).maxOccurs
+
+function [element,subelem]=get_xml(t,path,xs_element,node,xs_subelem)
+element.attr_key='';%default
+element.attr_val='';%default
+element.val='';
+% element.type='';
+% element.testmanual=testmanual %inheritates the input manual editing flag by default
+subelem=[]; %default
+attrup=[];
+% node=[];
+
+% %find the element properties in the xml file
+if node >= 1
+ elem_struct=get(t,node);
+ if ~xs_element.subtest
+ elem_contents=get(t,elem_struct.contents);
+ if isempty(elem_contents)
+ element.val=[];
+ else
+ element.val=elem_contents.value
+ end
+ end
+ if isfield(elem_struct,'attributes')
+ elem_attr=elem_struct.attributes;
+ for iattr=1:length(elem_attr)
+ element.attr_key{iattr}=elem_attr{iattr}.key ;
+ element.attr_val{iattr}=elem_attr{iattr}.val;
+% attrup=setfield(attrup,elem_attr{iattr}.key,elem_attr{iattr}.val);
+ breakdetect=find(elem_attr{iattr}.key=='/'| elem_attr{iattr}.key==':'| elem_attr{iattr}.key=='.');% find '/'
+ if isempty(breakdetect)
+% comline=['attrup.' elem_attr{iattr}.key '=' elem_attr{iattr}.val ';']
+ eval(['attrup.' elem_attr{iattr}.key '=''' elem_attr{iattr}.val ''';'])
+ end
+ end
+ end
+end
+%get the parent node attributes
+up=1;
+if node>0
+ nodeup=node;
+ while up==1;
+ nodeup=get(t,nodeup,'parent');%move up to the parent in the tree
+ if isempty(nodeup)
+ up=0;
+ else
+ nodeup_content=get(t,nodeup);
+ attrib=nodeup_content.attributes;
+ for iattr=1:length(attrib)
+ key=attrib{iattr}.key;
+ breakdetect=find(key=='/'| key==':'| key=='.');% find '/'
+ if ~isfield(attrup,key) & isempty(breakdetect)
+ eval(['attrup.' key '=''' attrib{iattr}.val ''';'])
+ end
+ end
+ end
+ end
+ element.attrup=attrup;
+end
+%find the subelement properties in the xml file
+if xs_element.subtest
+ iline=0;
+ for k=1:length(xs_subelem)%node2: list of subelements in the sub-sequence
+% attr=attributes(xs,'get',node2(i),1);%
+% element=attr.val;%name of the element
+ tag=find(t,['/' path '/' xs_element.key '/' xs_subelem(k).key]);%look for the corresponding element node in the .xml tree
+ struct_element=get(t,tag);%get the content of the element
+ if isempty(struct_element)
+ iline=iline+1;
+ subelem(iline).uid=0;
+ subelem(iline).xsindex=k;
+ subelem(iline).index=0;
+% subelem(iline).testmanual=element.testmanual;% inheritates the manual editing flag by default
+ if isequal(xs_subelem(k).minOccurs,'0')
+ subelem(iline).val='[]';%element value not mandatory in the schema
+ else
+ subelem(iline).val='[MISSING]';%element value mandatory in the schema
+ end
+% subelem(iline).attrup=attrup; %inheritated attributes
+ elseif isequal(length(struct_element),1)
+ contents=get(t,struct_element.contents);
+ iline=iline+1;
+ subelem(iline).uid=tag;
+ subelem(iline).xsindex=k;
+ subelem(iline).index=1;
+% subelem(iline).testmanual=element.testmanual;%
+ if isfield(contents,'value') & ~isempty(contents.value)
+ subelem(iline).val=contents.value;
+ elseif xs_subelem(k).testsub
+ subelem(iline).val='';
+ elseif isequal(xs_subelem(k).minOccurs,0)
+ subelem(iline).val='[]';%element value not mandatory in the schema
+ else
+ subelem(iline).val='[MISSING]';%element value mandatory in the schema
+ end
+% subelem(iline).attrup=attrup; %inheritated attributes
+ if isfield(struct_element,'attributes')
+ element_attr=struct_element.attributes;
+ attr_display=[];
+ for iattr=1:length(element_attr)
+% attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val];
+ subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val];
+% subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val);
+ end
+ end
+ else%case of a multiple element
+ for subindex=1:length(struct_element)
+ contents=get(t,struct_element{subindex}.contents);
+ iline=iline+1;
+ subelem(iline).index=subindex;%index of the element
+ subelem(iline).xsindex=k;
+% subelem(iline).testmanual=element.testmanual;%
+ if isfield(contents,'value')& ~isempty(contents.value)
+ subelem(iline).val=contents.value;
+ elseif xs_subelem(k).testsub
+ subelem(iline).val='';
+ else
+ subelem(iline).val='[]';
+ end
+% subelem(iline).attrup=attrup; %inheritated attributes
+ if isfield(struct_element{subindex},'attributes')
+ element_attr=struct_element{subindex}.attributes;
+ attr_display=[];
+ for iattr=1:length(element_attr)
+% attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val];
+ subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val];
+% subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val);
+ end
+ end
+ end
+ end
+ end
+end
+
+%-------------------------------------
+%updates the interface
+function update_list(handles,path,xs_element,element,node,xs_subelem,subelem)
+%-----------------------------
+if xs_element.subtest% we list the sub-elements of root
+ set(handles.export_list,'Value',1)
+ set(handles.export_list,'String','')%flush the export list
+ set(handles.CurrentElement,'String',[path '/' xs_element.key])
+% title_element.key=[path '/' xs_element.key];
+% if ~isempty(path)
+% xsnode_index=get(handles.list_element,'UserDataIn');
+% ind=get(handles.list_element,'Value');
+% title_element.index=xsnode_index(2,ind);
+% else
+% title_element.index=1;
+% end
+% title_element.xsnode=xs_element.uid;
+% title_element.node=node;
+% set(handles.CurrentFile,'UserDataIn',title_element)%element corresponding to the title
+ set(handles.CurrentAnnotation,'String',xs_element.annot)
+ attr_col=[];
+ testedit=0;% cannot edit elements by default
+ for iattr=1:length(element.attr_key)
+% if isequal(element.attr_key{iattr},'source') & isequal(element.attr_val{iattr},'manual')
+% testedit=1;
+% end
+ attr_col=strvcat(attr_col,[element.attr_key{iattr} ' = ' element.attr_val{iattr}]);
+ end
+ set(handles.CurrentAttributes,'String',attr_col)
+ pref_col='';
+ key_col='';
+ equal_sign='';
+ val_col='';
+ for iline=1:length(subelem)
+ xsindex=subelem(iline).xsindex;
+ index(iline)=subelem(iline).index;
+ subuid=subelem(iline).uid;
+ if isempty(subuid)
+ list.uid(iline)=0;
+ else
+ list.uid(iline)=subuid;
+ end
+ node(iline)=xs_subelem(xsindex).node;
+% testmanual(iline)=subelem(iline).testmanual;
+ ikey=xs_subelem(xsindex).key;
+ if xs_subelem(xsindex).testsub
+ ival=[' + ' subelem(iline).val];
+ else
+ ival=[' = ' subelem(iline).val];
+ end
+ key_col=strvcat(key_col,ikey);
+ val_col=strvcat(val_col,ival);
+ end
+ list_element=[key_col val_col];
+ set(handles.list_element,'String',list_element)
+ set(handles.list_element,'Value',1)
+ list.xs_uid=node;
+ list.index=index;
+ set(handles.list_element,'UserData',list)
+ set(handles.element_attrib,'Visible','off')
+ set(handles.element_key,'Visible','off')
+ set(handles.element_value,'Visible','off')
+else % we edit an element
+
+ export_list=get(handles.export_list,'String');%export list
+ testadd=1;
+ for ilist=1:length(export_list)
+ if isequal(xs_element.key,export_list{ilist})
+ testadd=0;
+ break
+ end
+ end
+ if testadd
+ export_list=[export_list;{xs_element.key}];
+ ilist=length(export_list);
+ end
+ set(handles.export_list,'String',export_list)
+ if iscell(element.val)
+ element_val=element.val{1};
+ else
+ element_val=element.val;
+ end
+ set(handles.element_value,'String',element_val)
+ export_val=get(handles.export_list,'UserData');
+ export_val{ilist}=element_val;
+ set(handles.export_list,'UserData',export_val);
+ set(handles.element_annot,'String',xs_element.annot)
+ set(handles.element_type,'String',['type: ' xs_element.type])
+ attr_col=[];
+ testedit=0;% cannot edit element by default
+ for iattr=1:length(element.attr_key)
+% if isequal(element.attr_key{iattr},'source') & isequal(element.attr_val{iattr},'manual')
+% testedit=1;
+% end
+ attr_col=strvcat(attr_col,[element.attr_key{iattr} ' = ' element.attr_val{iattr}]);
+ end
+ set(handles.element_attrib,'String',attr_col)
+ set(handles.element_key,'String',xs_element.key)
+
+
+ if isempty(xs_element.enum)
+ set(handles.element_value,'Value',1)
+ set(handles.element_value,'Style','edit')
+ else % case of an enumeration of possible values
+ list_enum=[];
+ list_val=[];
+ for ienum=1:length(xs_element.enum)
+ list_enum{ienum,1}=xs_element.enum{ienum};
+ if isequal(xs_element.enum{ienum},element_val)
+ list_val=ienum;
+ end
+ end
+ if isempty(list_val)
+ list_enum{length(xs_element.enum)+1,1}=['[' element_val ']'];%show the non-valid element between brackets
+ list_val=length(xs_element.enum)+1;
+ end
+ set(handles.element_value,'Style','popupmenu')
+ set(handles.element_value,'String',list_enum)
+ set(handles.element_value,'Value',list_val)
+ end
+ if isempty(element.val)
+ testedit=1;%allow element editing if value is missing
+ end
+ set(handles.element_attrib,'Visible','On')
+ set(handles.element_key,'Visible','On')
+ set(handles.element_value,'Visible','On')
+end
+set(handles.element_value,'UserData',node)
+if ~testedit && isfield(element,'attrup') & isfield(element.attrup,'source')&& ~isequal(element.attrup.source,'manual')
+ set(handles.element_value,'Enable','inactive')
+else
+ set(handles.element_value,'Enable','on')
+end
+
+
+% --- Executes on button press in SAVE.
+function SAVE_Callback(hObject, eventdata, handles)
+global t
+DataIn=get(get(handles.SAVE,'parent'),'UserData');
+CurrentFile=get(handles.CurrentFile,'String');
+if isfield(DataIn,'Schema')
+if ~isempty(DataIn.Schema)% update ref to schema
+ attrxsd=attributes(t,'get',1);
+ setest=0;
+ for iattr=1:length(attrxsd)
+ if isequal(attrxsd{iattr}.key,'xsi:noNamespaceSchemaLocation')
+ t= attributes(t,'set',1,iattr,'xsi:noNamespaceSchemaLocation',DataIn.Schema);
+ setest=1;
+ end
+ end
+ if setest==0;
+ t=attributes(t,'add',1,'xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
+ t= attributes(t,'add',1,'xsi:noNamespaceSchemaLocation',DataIn.Schema);
+ end
+end
+end
+copyfile(CurrentFile,[CurrentFile '.bak']);
+save(t,CurrentFile);
+
+%-------------------------------------
+% creates and/or set values to an element in t
+%t: xml tree
+%RootUid: uid of t under which we introduce an element
+%node: uid of the element that we correct, if =0, a new element is created
+%key: key name of the element
+%value: new value of the element
+function t=set_element(t,RootUid,node,key,value)
+%create the subelement if needed
+if isequal(node,0)
+ [t,node]= add(t,RootUid,'element',key);
+end
+node_chardata=children(t,node); %corresponding data node
+if isempty(node_chardata)%if the data does not exist in t, create it
+ t=add(t,node,'chardata',value);
+elseif isequal(length(node_chardata),1)&isequal(get(t,node_chardata,'type'),'chardata')% update only a simple element with 'chardata'
+ t=set(t,node_chardata,'value',value);%modify existing data
+end
+attr=attributes(t,'get',node);
+if isempty(attr)
+ t=attributes(t,'add',node,'source','manual');%indicate a manual eidting
+end
+
+% --- Executes on selection change in element_attr_val.
+function element_attr_val_Callback(hObject, eventdata, handles)
+% hObject handle to element_attr_val (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: contents = get(hObject,'String') returns element_attr_val contents as cell array
+% contents{get(hObject,'Value')} returns selected item from element_attr_val
+
+
+% --- Executes on button press in ADD.
+function ADD_Callback(hObject, eventdata, handles)
+% hObject handle to ADD (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+%----------------------------------------
+%read an xml file without schema
+function [Data,testsimple]=displ_xml(handles,t,root_uid,DataIn,heditxml)
+Data=DataIn;%default
+if ~isfield(Data,'CurrentUid')
+ Data.CurrentUid=[];
+end
+CurrentFile=get(handles.CurrentFile,'String');
+
+%display the current element
+root_element=get(t,root_uid);
+uidparent=root_uid;
+if isfield(root_element,'name')
+ CurrentElement=root_element.name;
+ while ~isequal(uidparent,1)%while the first level has not been reached
+ uidparent=parent(t,uidparent);
+ dirdat=get(t,uidparent);
+ if isfield(dirdat,'name')
+ CurrentElement=[dirdat.name '/' CurrentElement];
+ end
+ end
+ set(handles.CurrentElement,'String',CurrentElement)
+end
+list_uid=children(t,root_uid);
+%case of a single element
+testsimple=0;
+filedat=[];
+if ~isempty(list_uid)
+ filedat=get(t,list_uid(1))
+ if isfield(filedat,'type') & isequal(filedat.type,'chardata') &isfield(filedat,'value')
+ testsimple=1;%simple element
+ end
+end
+
+%attributes of the current element
+nbattrib= attributes(t,'length',root_uid);
+testopen=0;
+attr_col=[];
+for iattr=1:nbattrib
+ attr= attributes(t,'get',root_uid,iattr);
+ if isequal(attr.key,'source')% look for 'source' attribute
+ if isequal(attr.val,'file')%if the source is 'file', look for the path and open it
+ if isfield(filedat,'type') & isequal(filedat.type,'chardata') &isfield(filedat,'value')
+ cur_file=filedat.value;
+ uidparent=root_uid;%initialization
+ while ~isequal(uidparent,1)%while the first level has not been reached
+ uidparent=parent(t,uidparent);
+ dirdat=get(t,uidparent);
+ if isfield(dirdat,'type') & isequal(dirdat.type,'element') & isfield(dirdat,'name')
+ nbattrib_up= attributes(t,'length',uidparent);
+ for iattr_up=1:nbattrib_up
+ attr= attributes(t,'get',uidparent,iattr_up);
+% if isequal(attr.key,'source')&isequal(attr.val,'directory')% look for 'source' attribute
+ if isequal(attr.key,'DirName')
+ cur_file=fullfile(attr.val,cur_file);
+ end
+ end
+ end
+ end
+ RootPath=fileparts(CurrentFile);%path to the current .xml file
+ cur_file=fullfile(RootPath,cur_file)
+ set(handles.CurrentAttributes,'UserData',cur_file)%will be searched by uvmat
+ [path,fil,ext]=fileparts(cur_file);
+ if ~exist(cur_file,'file')
+ warndlg_uvmat(['non-existent link file' cur_file],'ERROR') % A FAIRE: propose to updtate the .xml file
+ return
+ elseif isequal(ext,'.xml')
+ if ~isfield(Data,'UpFile')
+ Data.UpFile={CurrentFile};
+ else
+ Data.UpFile=[{CurrentFile};Data.UpFile];
+ end
+ set(heditxml,'UserData',Data)
+ set(handles.CurrentFile,'String',cur_file)
+ CurrentFile_Callback(handles.CurrentFile, [], handles)
+ else
+ if isequal(get(heditxml,'Tag'),'browser'); %if editxml has been called as a browser
+ set(heditxml,'Tag','idle')% signal for uvmat browser
+ else
+ uvmat({cur_file}); %open the link fiel with uvmat
+ end
+ return
+ end
+ end
+ %elseif isequal(attr.val,'dir') A FAIRE : check directory
+ %else A FAIRE: edit the element
+ end
+ end
+ attr_col=strvcat(attr_col,[attr.key ' = ' attr.val]);
+end
+set(handles.CurrentAttributes,'String',attr_col)
+
+%list subtree
+if ~testsimple
+ list_element=[];
+% Data.CurrentUid=[Data.CurrentUid root_uid]%record new current uid
+ for iline=1:length(list_uid)
+ element=get(t,list_uid(iline));
+ if isfield(element,'type')&isequal(element.type,'element')
+ list_element{iline,2}=element.name;
+ child_uid=children(t,list_uid(iline));
+ subelem=get(t,child_uid);
+ if isfield(subelem,'type')& isfield(subelem,'value') & isequal(subelem.type,'chardata')
+ data_read=subelem.value;
+ list_element{iline,3}=['= ' data_read];
+ end
+ if iscell(subelem)|(isfield(subelem,'type')&isequal(subelem.type,'element'))
+ list_element{iline,1}='+ ';%sign for subtree existence
+ else
+ list_element{iline,1}=' ';
+ end
+ nbattr=attributes(t,'length',list_uid(iline));
+ if nbattr==1
+ attr=attributes(t,'get',list_uid(iline));
+ list_element{iline,4}=[attr.key '='];
+ list_element{iline,5}=attr.val;
+ elseif nbattr>1
+ for iattr=1:nbattr
+ attr=attributes(t,'get',list_uid(iline),iattr);
+ list_element{iline,2+2*iattr}=[attr.key '='];
+ list_element{iline,3+2*iattr}=attr.val;
+ end
+ end
+ end
+ end
+ set(handles.list_element,'Value',1)%select the first line of list_element by default
+ set(handles.list_element,'String',cell2tab(list_element,' ') )
+ list.uid=list_uid;
+ set(handles.list_element,'UserData',list)
+end
+%---------------------------------------------------------
+%-------------------------------------
+%updates the interface
+function update_ref_list(hh,xs_element,element,node,xs_subelem,subelem)
+%-----------------------------
+pref_col='';
+key_col='';
+equal_sign='';
+val_col='';
+for iline=1:length(subelem)
+ xsindex=subelem(iline).xsindex;
+ indexcur=subelem(iline).index;
+ subuid=subelem(iline).uid;
+ if isempty(subuid)
+ RefDataIn.uid(iline)=0;
+ else
+ RefDataIn.uid(iline)=subuid;
+ end
+ index(iline)=indexcur;
+ node(iline)=xs_subelem(xsindex).node;
+% testmanual(iline)=subelem(iline).testmanual;
+ ikey=xs_subelem(xsindex).key;
+ if xs_subelem(xsindex).testsub
+ ival=[' + ' subelem(iline).val];
+ else
+ ival=[' = ' subelem(iline).val];
+ end
+ key_col=strvcat(key_col,ikey);
+ val_col=strvcat(val_col,ival);
+end
+RefDataIn.xs_uid=node;
+list_element=[key_col val_col];
+siztext=size(list_element);
+set(hh,'Value',[1:siztext(1)])
+set(hh,'String',list_element)
+set(hh,'UserData',RefDataIn)
+
+%
+% function RefFile_Callback(hObject, eventdata, handles)
+% global t_ref xs
+% t_ref=xmltree(get(hObject,'String'));%open the xml file fileinput
+% heditxml=get(hObject,'parent');
+% DataIn=get(get(hObject,'parent'),'UserData');
+% % set(heditxml,'Units','pixel')
+% figpos=get(heditxml,'Position')
+% % title_element=get(handles.element_cur,'UserDataIn');
+% % xs_node=xsnode_index(1,ind);
+% % index_chosen=xsnode_index(2,ind);
+% if isfield(DataIn,'fig_ref')&ishandle(DataIn.fig_ref)
+% figure(DataIn.fig_ref);
+% else
+% DataIn.fig_ref=figure;
+% end
+% set(DataIn.fig_ref,'Name',get(hObject,'String'))
+% set(DataIn.fig_ref,'MenuBar','none')
+% newfigpos=[figpos(1)+figpos(3) figpos(2)+0.4*figpos(4) 0.5*figpos(3) 0.3*figpos(4)];
+% set(DataIn.fig_ref,'Units','normalized')
+% set(DataIn.fig_ref,'Position',newfigpos)
+% DataIn.h_ref=uicontrol('Style','listbox', 'Max',2,'Units','pixel','Position', [0 0 newfigpos(3) newfigpos(4)], ...
+% 'FontName','FixedWidth','Tag','listbox');
+% if isfield(DataIn,'xs_CurrentUid');
+% xs_CurrentUid=DataIn.xs_CurrentUid(end);
+% else
+% DataIn.xs_CurrentUid=find(xs,'/xs:schema/xs:element');%uid of the root element in the schema
+% end
+% [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_CurrentUid(end));
+% xs_element.key
+% tag0=find(t_ref,['/' path '/' xs_element.key]);
+% if length(tag0)>=1
+% CurrentRefNode=tag0(1);%chose the first occurence of the element
+% else
+% CurrentRefNode=0;
+% end
+% [ref_element,ref_subelem]=get_xml(t_ref,path,xs_element,CurrentRefNode,xs_subelem);
+% update_ref_list(DataIn.h_ref,xs_element,ref_element,CurrentRefNode,xs_subelem,ref_subelem);
+% siztext=size(get(DataIn.h_ref,'String'));
+% set(DataIn.h_ref,'Value',[1:siztext(1)]); %select the whole list by default
+% set(heditxml,'UserData',DataIn)
+% set(handles.ref_data,'Value',siztext(1)); %select the whole list by default
+% 'TESTimport'
+% title_element=get(handles.element_cur,'UserDataIn')
+% xs_node=title_element.xsnode;%uid of the element in the schema
+% node=title_element.node;
+% t=flush(t,node);%removes the corresponding subtree in t
+% [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_node);%scan the schema
+% tag0=find(t_import,['/' path '/' xs_element.key])
+% if isempty(tag)
+% errordlg(['element /' path '/' xs_element.key ' not found in' fileinput])
+% return
+% end
+% % [element_import,node_import]=get_xml(t_import,path,xs_element,1,xs_subelem);% read the corresponding xml data
+% node2_import=children(t_import,tag0);
+% % t_import=branch(t_import,node_import);% extract branch of the new file
+% % %removes the corresponding subtree in t
+% for inode=1:length(node2_import)
+% struct=get(t_import,node2_import(inode))
+% if isfield(struct,'type') & isfield(struct,'name')%if the node is an elmeent type
+% node3_import=children(t_import,node2_import(inode))
+% [t,newuid]=add(t,node,struct.type,struct.name);
+% for inode2=1:length(node3_import)
+% struct2=get(t_import,node3_import(inode2))
+% if isequal(struct2.type,'chardata')
+% t=add(t,newuid,'chardata',struct2.value);
+% end
+% end
+% end
+% end
+% --- Executes on button press in replicate.
+function replicate_Callback(hObject, eventdata, handles)
+global xs t
+
+export_list=get(handles.export_list,'String');
+export_val=get(handles.export_list,'UserData');
+heditxml=get(handles.replicate,'parent');
+Data=get(heditxml,'UserData')
+
+hdataview=findobj(allchild(0),'Name','dataview')
+if isempty(hdataview)
+ hdataview=dataview;
+ return
+end
+hhdataview=guidata(hdataview);
+CurrentPath=get(hhdataview.CurrentFile,'String');
+ListExperiments=get(hhdataview.ListExperiments,'String');
+Value=get(hhdataview.ListExperiments,'Value');
+if ~isequal(Value,1)
+ ListExperiments=ListExperiments(Value);
+end
+ListDevices=get(hhdataview.ListDevices,'String');
+Value=get(hhdataview.ListDevices,'Value');
+if ~isequal(Value,1)
+ ListDevices=ListDevices(Value);
+end
+ListRecords=get(hhdataview.ListRecords,'String');
+Value=get(hhdataview.ListRecords,'Value');
+if ~isequal(Value,1)
+ ListRecords=ListRecords(Value);
+end
+% uvmat('runplus_Callback',hObject,eventdata,handleshaxes)
+[ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
+ListXml=get(hhdataview.ListXml,'String');
+Value=get(hhdataview.ListXml,'Value');
+if isequal(Value,1)
+ warndlg_uvmat('you need to select the xml files to edit','ERROR')
+ return
+end
+ListXml=ListXml(Value);%list of
+for iexp=1:length(List.Experiment)
+ ExpName=List.Experiment{iexp}.name;
+ if isfield(List.Experiment{iexp},'Device')
+ for idevice=1:length(List.Experiment{iexp}.Device)
+ DeviceName=List.Experiment{iexp}.Device{idevice}.name;
+ if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
+ for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
+ FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
+ for ilistxml=1:length(ListXml)
+ if isequal(FileName,ListXml{ilistxml})
+ xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
+ t_export=xmltree(xmlfullname);
+ rootelement=get(t_export,1,'name');
+ uidlist=Data.CurrentUid;
+ if isequal(rootelement,get(t,1,'name'))
+ backupfile=xmlfullname;
+ testexist=2;
+ while testexist==2
+ backupfile=[backupfile '~'];
+ testexist=exist(backupfile,'file');
+ end
+ [success,message]=copyfile(xmlfullname,backupfile);%make backup
+ if ~isequal(success,1)
+ warndlg_uvmat(['Error in the backup of ' xmlfullname],'ERROR')
+ return
+ end
+ findstr=['/' rootelement];
+ uid_export(1)=1;
+ % fill the root elements if absent
+ for index=2:length(uidlist)
+ name_t=get(t,uidlist(index),'name')
+ findstr=[findstr '/' name_t]
+ uid=find(t_export,findstr)
+ if isempty(uid)
+ [t_export,uid_export(index)]=add(t_export,uid_export(index-1),'element',name_t);
+ else
+ uid_export(index)=uid;
+ end
+ end
+ % chardata......
+ end
+ break
+ end
+ end
+% [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
+% if test
+% [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']
+% end
+ end
+ elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
+ for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
+ RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
+ if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
+ for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
+ FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
+ for ilistxml=1:length(ListXml)
+ if isequal(FileName,ListXml{ilistxml})
+ xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName)
+ break
+ end
+ end
+% [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
+% if test
+% [FileName ' , Heading updated']
+% end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+return
+%%%%%%%%%%% A REVOIR
+% Copier la liste des elements selectionnés dans dataview
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%ANCIEN:
+heditxml=get(hObject,'parent');
+DataIn=get(heditxml,'UserData');
+if ~isfield(DataIn,'h_ref')
+ DataIn.h_ref=[];
+end
+if ~ishandle(DataIn.h_ref)
+ errordlg('no source file opened for import')
+ return
+end
+%create the current root element if needed
+LengthElement=length(DataIn.CurrentUid);
+FilledUid=find(DataIn.CurrentUid~=0);
+LengthFilled=FilledUid(end);
+for irank=LengthFilled+1:LengthElement
+ attrib=attributes(xs,'get',DataIn.xs_CurrentUid(irank),1);
+ [t,DataIn.CurrentUid(irank)]=add(t,DataIn.CurrentUid(irank-1),'element',attrib.val);
+end
+
+%copy list of subelements
+RefDataIn=get(DataIn.h_ref,'UserData');
+list=get(handles.list_element,'UserData');%=,[node;index]
+for ilist=get(DataIn.h_ref,'Value')
+ node_content=get(xs,RefDataIn.xs_uid(ilist));
+ if ~isempty(node_content) & isfield(node_content,'attributes')
+ attrib=node_content.attributes;
+ for iattr=1:length(attrib)
+ struct=attrib{iattr};
+ if isequal(struct.key,'name')
+ key=struct.val; % read element key name
+ end
+ end
+ end
+ value='';
+ if ~isequal(RefDataIn.uid(ilist),0)
+ child_uid=children(t_ref,RefDataIn.uid(ilist));
+ if isequal(length(child_uid),1)
+ content=get(t_ref,child_uid);
+ if isfield(content,'type') &isfield(content,'value')& isequal(content.type,'chardata')
+ value=content.value;
+ end
+ end
+ end
+ t=set_element(t,DataIn.CurrentUid(end),list.uid(ilist),key,value);
+end
+set(heditxml,'UserData',DataIn)
+%update the current listing
+[nodeup,path,xs_element,xs_subelem]=scan_schema(xs,DataIn.xs_CurrentUid(end));
+[element,subelem]=get_xml(t,path,xs_element,DataIn.CurrentUid(end),xs_subelem);
+update_list(handles,path,xs_element,element,DataIn.CurrentUid(end),xs_subelem,subelem);
+% t=set_xml(t,xs_DataIn,subelem)
+%edit list of subelments:
+
+%A REVOIR
+% xsnode_index=get(handles.list_element,'UserDataIn')
+% xs_node=xsnode_index(1,ind);
+% RefDataIn=get(handles.ref_data,'UserDataIn');
+% subelem=RefDataIn.subelem;
+% xsnode_index=get(handles.list_element,'UserDataIn');%data on the xs_nodes of the subelements
+% ref_list=get(handles.ref_data,'Value');%selected indices in the list of reference subelements
+% xs_node=xsnode_index(1,ref_list);%xs_nodes of the selected subelements
+% % index_chosen=xsnode_index(2,ref_list);% indices in the list of occurence for a subelement
+% % for ilist=ref_list
+% ilist=1;
+% while icontinue
+% 'TESTCOPY'
+% [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_node(ilist))
+% xs_subelem.key
+% tsub=subelem(ilist).tsub
+% xsnode_index(2,ilist)
+% [ref_elem,ref_node,ref_subelem]=get_xml(tsub,'',xs_element,1,xs_subelem)
+% ref_subelem.val
+% testedit= ~isfield(element.attrup,'source') | isequal(element.attrup.source,'manual') %| element vide
+%
+%
+% icontinue=0
+% end
+% function [element,node,subelem]=get_xml(t,path,xs_element,node,xs_subelem)
+% element.attr_key='';%default
+% element.attr_val='';%default
+% element.val='';
+% % element.type='';
+% % element.testmanual=testmanual %inheritates the input manual editing flag by default
+% subelem=[]; %default
+% attrup=[];
+% % node=[];
+%
+% % %find the element properties in the xml file
+% if node >= 1
+% elem_struct=get(t,node);
+% if ~xs_element.subtest
+% elem_contents=get(t,elem_struct.contents);
+% if isempty(elem_contents)
+% element.val=[];
+% else
+% element.val=elem_contents.value
+% end
+% end
+% if isfield(elem_struct,'attributes')
+% elem_attr=elem_struct.attributes;
+% for iattr=1:length(elem_attr)
+% element.attr_key{iattr}=elem_attr{iattr}.key ;
+% element.attr_val{iattr}=elem_attr{iattr}.val;
+% % attrup=setfield(attrup,elem_attr{iattr}.key,elem_attr{iattr}.val);
+% breakdetect=find(elem_attr{iattr}.key=='/'| elem_attr{iattr}.key==':'| elem_attr{iattr}.key=='.');% find '/'
+% if isempty(breakdetect)
+% % comline=['attrup.' elem_attr{iattr}.key '=' elem_attr{iattr}.val ';']
+% eval(['attrup.' elem_attr{iattr}.key '=''' elem_attr{iattr}.val ''';'])
+% end
+% end
+% end
+% end
+% %get the parent node attributes
+% up=1
+% if node>0
+% nodeup=node;
+% while up==1;
+% nodeup=get(t,nodeup,'parent');%move up to the parent in the tree
+% if isempty(nodeup)
+% up=0;
+% else
+% nodeup_content=get(t,nodeup);
+% attrib=nodeup_content.attributes;
+% for iattr=1:length(attrib)
+% key=attrib{iattr}.key;
+% breakdetect=find(key=='/'| key==':'| key=='.');% find '/'
+% if ~isfield(attrup,key) & isempty(breakdetect)
+% eval(['attrup.' key '=''' attrib{iattr}.val ''';'])
+% end
+% end
+% end
+% end
+% element.attrup=attrup;
+% end
+% %find the subelement properties in the xml file
+% if xs_element.subtest
+% iline=0;
+% for k=1:length(xs_subelem)%node2: list of subelements in the sub-sequence
+% % attr=attributes(xs,'get',node2(i),1);%
+% % element=attr.val;%name of the element
+% tag=find(t,['/' path '/' xs_element.key '/' xs_subelem(k).key]);%look for the corresponding element node in the .xml tree
+% struct_element=get(t,tag);%get the content of the element
+% if isempty(struct_element)
+% iline=iline+1;
+% subelem(iline).xsindex=k;
+% subelem(iline).index=0;
+% % subelem(iline).testmanual=element.testmanual;% inheritates the manual editing flag by default
+% if isequal(xs_subelem(k).minOccurs,0)
+% subelem(iline).val='[]';%element value not mandatory in the schema
+% else
+% subelem(iline).val='[MISSING]';%element value mandatory in the schema
+% end
+% % subelem(iline).attrup=attrup; %inheritated attributes
+% elseif isequal(length(struct_element),1)
+% contents=get(t,struct_element.contents);
+% iline=iline+1;
+% subelem(iline).xsindex=k;
+% subelem(iline).index=1;
+% % subelem(iline).testmanual=element.testmanual;%
+% if isfield(contents,'value') & ~isempty(contents.value)
+% subelem(iline).val=contents.value;
+% elseif xs_subelem(k).testsub
+% subelem(iline).val='';
+% elseif isequal(xs_subelem(k).minOccurs,0)
+% subelem(iline).val='[]';%element value not mandatory in the schema
+% else
+% subelem(iline).val='[MISSING]';%element value mandatory in the schema
+% end
+% % subelem(iline).attrup=attrup; %inheritated attributes
+% if isfield(struct_element,'attributes')
+% element_attr=struct_element.attributes;
+% attr_display=[];
+% for iattr=1:length(element_attr)
+% % attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val];
+% subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val];
+% % subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val);
+% end
+% end
+% else%case of a multiple element
+% for subindex=1:length(struct_element)
+% contents=get(t,struct_element{subindex}.contents);
+% iline=iline+1;
+% subelem(iline).index=subindex;%index of the element
+% subelem(iline).xsindex=k;
+% % subelem(iline).testmanual=element.testmanual;%
+% if isfield(contents,'value')& ~isempty(contents.value)
+% subelem(iline).val=contents.value;
+% elseif xs_subelem(k).testsub
+% subelem(iline).val='';
+% else
+% subelem(iline).val='[]';
+% end
+% % subelem(iline).attrup=attrup; %inheritated attributes
+% if isfield(struct_element{subindex},'attributes')
+% element_attr=struct_element{subindex}.attributes;
+% attr_display=[];
+% for iattr=1:length(element_attr)
+% % attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val];
+% subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val];
+% % subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val);
+% end
+% end
+% end
+% end
+% end
+% end
+
+
+% --- Executes on button press in HELP.
+function HELP_Callback(hObject, eventdata, handles)
+path_to_uvmat=which ('uvmat')% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+else
+web([helpfile '#editxml'])
+end
+
+
+% --- Executes on button press in Export.
+function Export_Callback(hObject, eventdata, handles)
+val=get(handles.Export,'Value');
+if val
+ set(handles.Export,'BackgroundColor',[0 1 0])
+ set(handles.export_list,'Visible','on')
+ set(handles.replicate,'Visible','on')
+ h_dataview=findobj(allchild(0),'name',dataview');
+ if isempty(h_dataview)
+ % CurrentFile=get(handles.CurrentFile,'String');
+ dataview;
+ end
+else
+ set(handles.Export,'BackgroundColor',[0.7 0.7 0.7])
+ set(handles.export_list,'Visible','off')
+ set(handles.replicate,'Visible','off')
+end
+
+
+% --- Executes on button press in pushbutton9.
+function pushbutton9_Callback(hObject, eventdata, handles)
+% hObject handle to pushbutton9 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
Index: /trunk/src/find_field_indices.m
===================================================================
--- /trunk/src/find_field_indices.m (revision 2)
+++ /trunk/src/find_field_indices.m (revision 2)
@@ -0,0 +1,181 @@
+%'find_file_indices': test field structure for input in proj_field and plot_field
+%group the variables into 'fields' with common dimensions
+%----------------------------------------------------------------------
+% function [DimVarIndex,CellVarIndex,NbDim,VarType]=find_field_indices(Data)
+%
+%OUTPUT:
+% CellVaxIndex: cell whose elements are arrays of indices in the list data.ListVarName
+% CellvarIndex{i} represents a set of variables with the same dimensions
+% NbDim: array with the length of CellVarIndex, giving its space dimension
+% VarType: cell array of structures with fields
+% .coord_x, y, z: indices (in .ListVarname) of variables representing unstructured coordinates x, y, z
+% .vector_x,_y,_z: indices of variables giving the vector components x, y, z
+% .warnflag: index of warnflag
+% .errorflag: index of error flag
+% .ancillary: indices of ancillary variables
+% .image : B/W image, (behaves like scalar)
+% .color : color image, the last index, which is not a coordinate variable, represent the 3 color components rgb
+% .discrete: like scalar, but set of data points without continuity, represented as dots in a usual plot, instead of continuous lines otherwise
+% .scalar: scalar field (default)
+
+%
+%INPUT:
+% Data: structure representing fields, output of check_field_structure
+% .ListDimName: cell listing the names of the array dimensions
+% .ListVarName: cell listing the names of the variables
+% .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName
+%
+% HELP:
+% to get the dimensions of arrays common to the field #icell
+% VarIndex=CellVarIndex{icell}; % list of variable indices
+% DimIndex=Data.VarDimIndex{VarIndex(1)} % list of dimensions for each variable in the cell #icell
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data)
+CellVarIndex={};
+NbDim=[];
+VarType=[];
+errormsg=[];
+nbvar=numel(Data.ListVarName);%number of field variables
+icell=0;
+ivardim=0;
+VarDimIndex=[];
+VarDimName={};
+
+if ~isfield(Data,'VarDimName')
+ errormsg='missing .VarDimName';
+ return
+end
+
+%loop on the list of variables
+for ivar=1:nbvar
+ DimCell=Data.VarDimName{ivar}; %dimensions associated with the variable #ivar
+ if ischar(DimCell)
+ DimCell={DimCell};
+ Data.VarDimName{ivar}={Data.VarDimName{ivar}};%transform char chain into cell
+ end
+ testnewcell=1;
+ for icell_prev=1:numel(CellVarIndex)%detect whether the dimensions of ivar fit with an existing cell
+ PrevVarIndex=CellVarIndex{icell_prev};
+ PrevDimName=Data.VarDimName{PrevVarIndex(1)};
+ if isequal(PrevDimName,DimCell)
+ CellVarIndex{icell_prev}=[CellVarIndex{icell_prev} ivar];% add variable index #ivar to the cell #icell_prev
+ testnewcell=0; %existing cell detected
+ break
+ end
+ end
+ if testnewcell
+ icell=icell+1;
+ CellVarIndex{icell}=ivar;%put the current variabl index in the new cell
+ end
+
+ %look for dimension variables
+ if numel(DimCell)==1% if the variable has a single dimension
+ Role='';
+ if isfield(Data,'VarAttribute') && length(Data.VarAttribute)>=ivar && isfield(Data.VarAttribute{ivar},'Role')
+ Role=Data.VarAttribute{ivar}.Role;
+ end
+ if strcmp(DimCell{1},Data.ListVarName{ivar}) || strcmp(Role,'dimvar')
+ ivardim=ivardim+1;
+ VarDimIndex(ivardim)=ivar;%index of the variable
+ VarDimName{ivardim}=DimCell{1};%name of the dimension
+ end
+ end
+end
+
+% find the spatial dimensions and vector components
+ListRole={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','warnflag','errorflag',...
+ 'ancillary','image','color','discrete','scalar'};
+for icell=1:length(CellVarIndex)
+ for ilist=1:numel(ListRole)
+ eval(['ivar_' ListRole{ilist} '=[];'])
+ end
+ VarIndex=CellVarIndex{icell};%set of variable indices with the same dim
+ DimCell=Data.VarDimName{VarIndex(1)};% list of dimensions for each variable in the cell #icell
+ if isfield(Data,'VarAttribute');
+ VarAttribute=Data.VarAttribute;
+ else
+ VarAttribute={};
+ end
+ test_2D=0;
+ for ivar=VarIndex
+ if length(VarAttribute)>=ivar
+ if isfield(VarAttribute{ivar},'Role')
+ role=VarAttribute{ivar}.Role;
+ switch role
+ case ListRole
+ eval(['ivar_' role '=[ivar_' role ' ivar];'])
+ otherwise
+ ivar_scalar=[ivar_scalar ivar];%variables are consiered as 'scalar' by default (in the absence of attribute 'Role')
+ end
+ else
+ ivar_scalar=[ivar_scalar ivar];% variable considered as scalar in the absence of Role attribute
+ end
+ if isfield(VarAttribute{ivar},'Coord_2')
+ test_2D=1; %obsolete convention
+ end
+ else
+ ivar_scalar=[ivar_scalar ivar];%variables are consiered as 'scalar' by default (in the absence of attribute 'Role')
+ end
+ end
+ for ilist=1:numel(ListRole)
+ eval(['VarType{icell}.' ListRole{ilist} '=ivar_' ListRole{ilist} ';'])
+ end
+ if numel(ivar_coord_x)>1 || numel(ivar_coord_y)>1 || numel(ivar_coord_z)>1
+ errormsg='multiply defined coordinates in the same cell';
+ return
+ end
+ if numel(ivar_vector_x)>1 || numel(ivar_vector_y)>1 || numel(ivar_vector_z)>1
+ errormsg='multiply defined vector components in the same cell';
+ return
+ end
+ if numel(ivar_errorflag)>1
+ errormsg='multiply defined error flag in the same cell';
+ return
+ end
+ if numel(ivar_warnflag)>1
+ errormsg='multiply defined warning flag in the same cell';
+ return
+ end
+ NbDim(icell)=0;% nbre of space dimensions
+ if ~isempty(ivar_coord_z)
+ NbDim(icell)=3;
+ elseif ~isempty(ivar_coord_y)
+ NbDim(icell)=2;
+ elseif ~isempty(ivar_coord_x)
+ NbDim(icell)=1;
+ end
+
+ % look at coordinates variables
+ coord=zeros(1,numel(DimCell));%default
+ if NbDim(icell)==0 && ~isempty(VarDimName)% no unstructured coordinate found
+ for idim=1:numel(DimCell) %loop on the dimensions of the variables in cell #icell
+ for ivardim=1:numel(VarDimName)
+ if strcmp(VarDimName{ivardim},DimCell{idim})
+ coord(idim)=VarDimIndex(ivardim);
+ break
+ end
+ end
+ end
+ NbDim(icell)=numel(find(coord));
+ end
+ VarType{icell}.coord=coord;
+ if NbDim(icell)==0 && test_2D %look at attributes Coord_1, coord_2 (obsolete convention)
+ NbDim(icell)=2;
+ end
+end
Index: /trunk/src/geometry_calib.m
===================================================================
--- /trunk/src/geometry_calib.m (revision 2)
+++ /trunk/src/geometry_calib.m (revision 2)
@@ -0,0 +1,1312 @@
+%'geometry_calib': performs geometric calibration from a set of reference points
+%
+% function varargout = geometry_calib(varargin)
+%
+%A%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function varargout = geometry_calib(varargin)
+% GEOMETRY_CALIB M-file for geometry_calib.fig
+% GEOMETRY_CALIB, by itself, creates a MenuCoord GEOMETRY_CALIB or raises the existing
+% singleton*.
+%
+% H = GEOMETRY_CALIB returns the handle to a MenuCoord GEOMETRY_CALIB or the handle to
+% the existing singleton*.
+%
+% GEOMETRY_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local
+% function named CALLBACK in GEOMETRY_CALIB.M with the given input arguments.
+%
+% GEOMETRY_CALIB('Property','Value',...) creates a MenuCoord GEOMETRY_CALIB or raises the
+% existing singleton*. Starting from the left, property value pairs are
+% applied to the GUI before geometry_calib_OpeningFunction gets called. An
+% unrecognized property name or invalid value makes property application
+% stop. All inputs are passed to geometry_calib_OpeningFcn via varargin.
+%
+% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
+% instance to run (singleton)".
+%
+% See also: GUIDE, GUIDATA, GUIHANDLES
+
+% Edit the above text to modify the response to help geometry_calib
+
+% Last Modified by GUIDE v2.5 28-Dec-2009 23:41:18
+
+% Begin initialization code - DO NOT edit
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @geometry_calib_OpeningFcn, ...
+ 'gui_OutputFcn', @geometry_calib_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin & isstr(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT edit
+
+
+% --- Executes just before geometry_calib is made visible.
+%INPUT:
+%handles: handles of the geometry_calib interface elements
+% PlotHandles: set of handles of the elements contolling the plotting
+% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
+function geometry_calib_OpeningFcn(hObject, eventdata, handles, handles_uvmat,pos,inputfile)
+set(handles.Phi,'TooltipString','Phi: rotation angle of the physical point coordiantes (in degrees)')% TO PUT IN GUIDE
+% Choose default command line output for geometry_calib
+handles.output = hObject;
+
+% Update handles structure
+guidata(hObject, handles);
+movegui(hObject,'east');% position the GUI ton the right of the screen
+if exist('handles_uvmat','var') %& isfield(data,'ParentButton')
+ set(hObject,'DeleteFcn',{@closefcn,handles_uvmat})%
+end
+%set the position of the interface
+if exist('pos','var')& length(pos)>2
+ pos_gui=get(hObject,'Position');
+ pos_gui(1)=pos(1);
+ pos_gui(2)=pos(2);
+ set(hObject,'Position',pos_gui);
+end
+inputxml='';
+if exist('inputfile','var')& ~isempty(inputfile)
+ [Path,Name,ext]=fileparts(inputfile);
+ form=imformats(ext([2:end]));
+ if ~isempty(form)% if the input file is an image
+ struct.XmlInputfile=inputfile;
+ set(hObject,'UserData',struct)
+ [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile);
+ inputxml=[fullfile(Pathsub,RootFile) '.xml'];
+ end
+end
+set(handles.ListCoord,'String',{''})
+if exist(inputxml,'file')
+ loadfile(handles,inputxml)% load the point coordiantes existing in the xml file
+end
+
+set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function
+%set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function on uvmat interface when geometry_calib is on top
+%htable=uitable(10,5)
+%set(htable,'ColumnNames',{'x','y','z','X(pixels)','Y(pixels)'})
+
+% --- Outputs from this function are returned to the command line.
+function varargout = geometry_calib_OutputFcn(hObject, eventdata, handles)
+% varargout cell array for returning output args (see VARARGOUT);
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+varargout{2}=handles;
+
+%------------
+function Phi_Callback(hObject, eventdata, handles)
+
+
+
+
+%--------------------------------------------------
+%read input xml file and update the edit boxes
+function loadfile(handles,fileinput)
+
+%read the input xml file
+t=xmltree(fileinput);
+s=convert(t);%convert to matlab structure
+%read data currently displayed on the interface
+PointCoord=[];
+Coord_cell=get(handles.ListCoord,'String');
+data=read_geometry_calib(Coord_cell);
+%data=read_geometry_calib(handles);
+Coord=[]; %default
+if isfield(data,'Coord')
+ Coord=data.Coord;
+end
+TabChar_0=get(handles.ListCoord,'String');
+nbcoord_0=size(TabChar_0,1);
+if isequal(get(handles.edit_append,'Value'),2) %edit mode A REVOIR
+ val=get(handles.ListCoord,'Value')-1;
+else
+ val=length(TabChar_0);
+end
+nbcoord=0;
+
+%case of calibration (ImaDoc) input file
+hcalib=get(handles.calib_type,'parent');
+CalibData=get(hcalib,'UserData');
+CalibData.XmlInput=fileinput;
+if isfield(s,'Heading')
+ CalibData.Heading=s.Heading;
+end
+
+set(hcalib,'UserData',CalibData);%store the heading in the interface 'UserData'
+if isfield(s,'GeometryCalib')
+ Calib=s.GeometryCalib;
+ if isfield(Calib,'CalibrationType')
+ CalibrationType=Calib.CalibrationType;
+ switch CalibrationType
+ case 'linear'
+ set(handles.calib_type,'Value',2)
+ case 'tsai'
+ set(handles.calib_type,'Value',3)
+ end
+ end
+ if isfield(Calib,'SourceCalib')
+ if isfield(Calib.SourceCalib,'PointCoord')
+ PointCoord=Calib.SourceCalib.PointCoord;
+ end
+ end
+ nbcoord=length(PointCoord);
+ if ~isfield(Calib,'ErrorRms')&~isfield(Calib,'ErrorMax') %old convention of Gauthier (cord in mm)
+ for i=1:length(PointCoord)
+ line=str2num(PointCoord{i});
+ Coord(i+val,4:5)=line(4:5);%px x
+ Coord(i+val,1:3)=line(1:3)/10;%phys x
+ end
+ else
+ for i=1:length(PointCoord)
+ line=str2num(PointCoord{i});
+ Coord(i,4:5)=line(4:5);%px x
+ Coord(i,1:3)=line(1:3);%phys x
+ end
+ end
+end
+%case of xml files of points
+if isfield(s,'Coord')
+ PointCoord=s.Coord;
+ nbcoord=length(PointCoord);
+ %case of image coordinates
+ if isfield(s,'CoordType')& isequal(s.CoordType,'px')
+ for i=1:nbcoord
+ line=str2num(PointCoord{i});
+ Coord(i+val,4:5)=line(1:2);
+ end
+ %case of physical coordinates
+ else
+ for i=1:nbcoord
+ line=str2num(PointCoord{i});
+ Coord(i+val,1:3)=line(1:3);
+ nbcolumn=size(Coord,2);
+ if nbcolumn<5
+ Coord(i+val,nbcolumn+1:5)=zeros(1,5-nbcolumn);
+ end
+ end
+ end
+end
+CoordCell={};
+for iline=1:size(Coord,1)
+ for j=1:5
+ CoordCell{iline,j}=num2str(Coord(iline,j),4);
+ end
+end
+Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display
+set(handles.ListCoord,'Value',1)
+set(handles.ListCoord,'String',Tabchar)
+
+
+%----------------------------------------------------
+% executed when closing: set the parent interface button to value 0
+function closefcn(gcbo,eventdata,handles_uvmat)
+huvmat=findobj(allchild(0),'Name','uvmat');
+if exist('handles_uvmat','var')
+ set(handles_uvmat.cal,'Value',0)
+ uvmat('cal_Callback',huvmat,[],handles_uvmat);
+% set(parent_button,'Value',0)%put unactivated buttons to green
+% set(parent_button,'BackgroundColor',[0 1 0]);
+end
+
+
+% % --- Executes on button press in MenuCoord.
+% function MenuCoord_Callback(hObject, eventdata, handles)
+
+%
+% % --- Executes on button press in delete.
+% function delete_Callback(hObject, eventdata, handles)
+% SetData=get(gcbf,'UserData');%get the interface data
+% IndexObj=SetData.IndexObj;
+% delete_object(IndexObj);
+
+
+%------------------------------------------------------------------
+% --- Executes on button press in calibrate_lin.
+function APPLY_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------
+calib_cell=get(handles.calib_type,'String');
+val=get(handles.calib_type,'Value');
+calib_type=calib_cell{val};
+Coord_cell=get(handles.ListCoord,'String');
+Object=read_geometry_calib(Coord_cell);
+
+if isequal(calib_type,'rescale')
+ GeometryCalib=calib_rescale(Object.Coord);
+elseif isequal(calib_type,'linear')
+ GeometryCalib=calib_linear(Object.Coord);
+elseif isequal(calib_type,'tsai')
+ GeometryCalib=calib_tsai(Object.Coord);
+end
+unitlist=get(handles.CoordUnit,'String');
+unit=unitlist{get(handles.CoordUnit,'value')};
+GeometryCalib.CoordUnit=unit;
+
+huvmat=findobj(allchild(0),'Name','uvmat');
+hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
+RootPath='';
+RootFile='';
+if ~isempty(hhuvmat.RootPath)& ~isempty(hhuvmat.RootFile)
+ testhandle=1;
+ RootPath=get(hhuvmat.RootPath,'String');
+ RootFile=get(hhuvmat.RootFile,'String');
+ filebase=fullfile(RootPath,RootFile);
+ outputfile=[filebase '.xml'];
+else
+ question={'save the calibration data and point coordinates in'};
+ def={fullfile(RootPath,['ObjectCalib.xml'])};
+ options.Resize='on';
+ answer=inputdlg(question,'save average in a new file',1,def,options);
+ outputfile=answer{1};
+end
+testappend=0;
+if exist(outputfile,'file');%=1 if the output file already exists, 0 else
+ t=xmltree(outputfile); %read the file
+ backupfile=outputfile;
+ testexist=2;
+ while testexist==2
+ backupfile=[backupfile '~'];% make a backup name by adding ~ to the xml file name
+ testexist=exist(backupfile,'file');
+ end
+ [success,message]=copyfile(outputfile,backupfile);%make backup
+ t=xmltree(outputfile); %read the file
+ uid=find(t,'ImaDoc');
+ if ~isequal(uid,1)%if the xml file is not ImaDoc, delete it (after backup)
+ if isequal(success,1)
+ delete(outputfile)
+ else
+ msgbox_uvmat('ERROR',['error in the backup of the existing xml file: ' message])
+ return
+ end
+ else
+ uid_calib=find(t,'ImaDoc/GeometryCalib');
+ testappend=1;
+ if isempty(uid_calib)
+ [t,uid_calib]=add(t,1,'element','GeometryCalib');
+ else %if GeometryCalib already exists, delete its content
+ uid_child=children(t,uid_calib);
+ t=delete(t,uid_child);
+ testappend=1;
+ end
+ end
+end
+if ~testappend %create a new xml file for calibration data
+ t=xmltree;
+ t=set(t,1,'name','ImaDoc');
+ [t,uid_calib]=add(t,1,'element','GeometryCalib');
+end
+% hgrid=get(handles.REPLICATE,'parent');%read the calibration image source on the interface userdata
+% imagename=get(hgrid,'UserData');
+% if exist(imagename,'file')
+% GeometryCalib.SourceCalib.ImageCalib=imagename;
+% end
+GeometryCalib.SourceCalib.PointCoord=Object.Coord;
+t=struct2xml(GeometryCalib,t,uid_calib);
+save(t,outputfile);
+msgbox_uvmat('CONFIRMATION',{[outputfile ' updated with calibration data'];...
+ ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
+ ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']})
+
+%display image with new calibration in the currently opened uvmat interface
+hhh=findobj(hhuvmat.axes3,'Tag','calib_marker');% delete calib points and markers
+if ~isempty(hhh)
+ delete(hhh);
+end
+hhh=findobj(hhuvmat.axes3,'Tag','calib_points');
+if ~isempty(hhh)
+ delete(hhh);
+end
+set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
+set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
+uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat
+
+%------------------------------------------------------------------
+% --- Executes on button press in calibrate_lin.
+function REPLICATE_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------
+calib_cell=get(handles.calib_type,'String');
+val=get(handles.calib_type,'Value');
+calib_type=calib_cell{val};
+Coord_cell=get(handles.ListCoord,'String');
+Object=read_geometry_calib(Coord_cell);
+
+if isequal(calib_type,'rescale')
+ GeometryCalib=calib_rescale(Object.Coord);
+elseif isequal(calib_type,'linear')
+ GeometryCalib=calib_linear(Object.Coord);
+elseif isequal(calib_type,'tsai')
+ GeometryCalib=calib_tsai(Object.Coord);
+end
+% %record image source
+% hgrid=get(handles.REPLICATE,'parent');%read the calibration image source on the interface userdata
+% imagename=get(hgrid,'UserData');
+% if exist(imagename,'file')
+% GeometryCalib.SourceCalib.ImageCalib=imagename;
+% end
+GeometryCalib.SourceCalib.PointCoord=Object.Coord;
+
+%open and read the dataview GUI
+h_dataview=findobj(allchild(0),'name','dataview');
+Device=[];%default
+if isempty(h_dataview)
+ h_dataview=dataview;
+ hhdataview=guidata(h_dataview);
+ drawnow
+ hGUI=get(handles.REPLICATE,'parent');%read the calibration image source on the interface userdata
+ CalibData=get(hGUI,'UserData');
+ if isfield(CalibData,'XmlInput')
+ XmlInput=fileparts(CalibData.XmlInput);
+ [XmlInput,filename,ext]=fileparts(XmlInput);
+ end
+ if isfield(CalibData,'Heading')
+ Heading=CalibData.Heading;
+ if isfield(Heading,'Record') && isequal([filename ext],Heading.Record)
+ [XmlInput,filename,ext]=fileparts(XmlInput);
+ end
+ if isfield(Heading,'Device') && isequal([filename ext],Heading.Device)
+ [XmlInput,filename,ext]=fileparts(XmlInput);
+ Device=Heading.Device;
+ end
+ if isfield(Heading,'Experiment') && isequal([filename ext],Heading.Experiment)
+ [PP,filename,ext]=fileparts(XmlInput);
+ end
+ testinput=0;
+ if isfield(Heading,'SubCampaign') && isequal([filename ext],Heading.SubCampaign)
+ set(hhdataview.RootDirectory,'String',XmlInput)
+ set(hhdataview.SubCampaignTest,'Value',1)
+ testinput=1;
+ elseif isfield(Heading,'Campaign') && isequal([filename ext],Heading.Campaign)
+ set(hhdataview.RootDirectory,'String',XmlInput)
+ set(hhdataview.SubCampaignTest,'Value',0)
+ testinput=1;
+ end
+ end
+ if testinput
+ dataview('RootDirectory_Callback',hObject,eventdata,hhdataview)
+ ListDevices=get(hhdataview.ListDevices,'String');
+ for ilist=1:length(ListDevices)
+ if isequal(ListDevices{ilist},Device)
+ set(hhdataview.ListDevices,'Value',ilist)
+ dataview('ListDevices_Callback',hObject,eventdata,hhdataview)
+ break
+ end
+ end
+ end
+ return
+end
+
+hhdataview=guidata(h_dataview);
+CurrentPath=get(hhdataview.RootDirectory,'String');
+ListExperiments=get(hhdataview.ListExperiments,'String');
+Value=get(hhdataview.ListExperiments,'Value');
+if ~isequal(Value,1)
+ ListExperiments=ListExperiments(Value);
+end
+ListDevices=get(hhdataview.ListDevices,'String');
+Value=get(hhdataview.ListDevices,'Value');
+if isequal(Value,1)
+ warndlg_uvmat('manually select in the GUI dataview the device being calibrated','ERROR')
+ return
+else
+ ListDevices=ListDevices(Value);
+end
+ListRecords=get(hhdataview.ListRecords,'String');
+Value=get(hhdataview.ListRecords,'Value');
+if ~isequal(Value,1)
+ ListRecords=ListRecords(Value);
+end
+[ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
+ListXml=get(hhdataview.ListXml,'String');
+Value=get(hhdataview.ListXml,'Value');
+if isequal(Value,1)
+ warndlg_uvmat('you need to select in the GUI dataview the xml files to edit','ERROR')
+ return
+else
+ ListXml=ListXml(Value);
+end
+
+%update all the selected xml files
+answer=msgbox_uvmat('INPUT_Y-N',[num2str(length(Value)) ' xml files for device ' ListDevices{1} ' will be refreshed with ' calib_type ' calibration data']);
+if ~isequal(answer{1},'OK')
+ return
+end
+% 'TEST'
+% List
+% return
+for iexp=1:length(List.Experiment)
+ ExpName=List.Experiment{iexp}.name;
+ if isfield(List.Experiment{iexp},'Device')
+ for idevice=1:length(List.Experiment{iexp}.Device)
+ DeviceName=List.Experiment{iexp}.Device{idevice}.name;
+ if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
+ for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
+ FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
+ for ilistxml=1:length(ListXml)
+ if isequal(FileName,ListXml{ilistxml})
+ set(hhdataview.ListXml,'Value',Value(ilistxml))
+ drawnow
+ xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
+ update_imadoc(GeometryCalib,xmlfullname)
+ break
+ end
+ end
+ end
+ elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
+ for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
+ RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
+ if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
+ for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
+ FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
+ for ilistxml=1:length(ListXml)
+ if isequal(FileName,ListXml{ilistxml})
+ set(hhdataview.ListXml,'Value',Value(ilistxml))
+ drawnow
+ xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName);
+ update_imadoc(GeometryCalib,xmlfullname)
+ break
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+set(hhdataview.ListXml,'Value',Value)
+
+
+%-------------------------------------------------------------
+function update_imadoc(GeometryCalib,outputfile)
+testappend=0;
+if exist(outputfile,'file');%=1 if the output file already exists, 0 else
+ t=xmltree(outputfile); %read the file
+ uid=find(t,'ImaDoc');
+ if isequal(uid,1)%if the xml file is ImaDoc
+ uid_calib=find(t,'ImaDoc/GeometryCalib');
+ if ~isempty(uid) %if GeometryCalib already exists, delete its content
+ backupfile=outputfile;
+ testexist=2;
+ while testexist==2
+ backupfile=[backupfile '~'];
+ testexist=exist(backupfile,'file');
+ end
+ [success,message]=copyfile(outputfile,backupfile);%make backup
+ if isequal(success,1)
+ delete(outputfile)
+ else
+ return
+ end
+ uid_child=children(t,uid_calib);
+ t=delete(t,uid_child);
+ testappend=1;
+ end
+ end
+end
+if ~testappend
+ t=xmltree;
+ t=set(t,1,'name','ImaDoc');
+ [t,uid_calib]=add(t,1,'element','GeometryCalib');
+% t=struct2xml(GeometryCalib,t,uid_calib);
+end
+
+t=struct2xml(GeometryCalib,t,uid_calib);
+save(t,outputfile);
+
+
+%-----------------------------------------------------------------
+% determine the parameters for a calibration by an affine function (rescaling and offset, no rotation)
+function GeometryCalib=calib_rescale(Coord)
+%------------------------------------------------------------------
+
+X=Coord(:,1);
+Y=Coord(:,2);
+x_ima=Coord(:,4);
+y_ima=Coord(:,5);
+[px,sx]=polyfit(X,x_ima,1);
+[py,sy]=polyfit(Y,y_ima,1);
+T_x=px(2);
+T_y=py(2);
+GeometryCalib.CalibrationType='rescale';
+GeometryCalib.focal=1;
+GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
+GeometryCalib.Tx_Ty_Tz=[T_x T_y 1];
+GeometryCalib.R=[px(1),0,0;0,py(1),0;0,0,1];
+
+%check error
+Calib.dpx=1;
+Calib.dpy=1;
+Calib.sx=1;
+Calib.Cx=0;
+Calib.Cy=0;
+Calib.Tz=1;
+Calib.kappa1=0;
+Calib.f=GeometryCalib.focal;
+Calib.Tx=T_x;
+Calib.Ty=T_y;
+Calib.R=GeometryCalib.R;
+[Xpoints,Ypoints]=px_XYZ(Calib,X,Y,0);
+GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
+GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
+GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
+GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima));
+
+
+%------------------------------------------------------------------
+% determine the parameters for a calibration by a linear transform matrix (rescale and rotation)
+function GeometryCalib=calib_linear(Coord)
+%------------------------------------------------------------------
+X=Coord(:,1);
+Y=Coord(:,2);
+x_ima=Coord(:,4);
+y_ima=Coord(:,5);
+XY_mat=[ones(size(X)) X Y];
+a_X1=XY_mat\x_ima; %transformation matrix for X
+x1=XY_mat*a_X1;%reconstruction
+err_X1=max(abs(x1-x_ima));%error
+a_Y1=XY_mat\y_ima;%transformation matrix for X
+y1=XY_mat*a_Y1;
+err_Y1=max(abs(y1-y_ima));%error
+T_x=a_X1(1);
+T_y=a_Y1(1);
+GeometryCalib.CalibrationType='linear';
+GeometryCalib.focal=1;
+GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
+GeometryCalib.Tx_Ty_Tz=[T_x T_y 1];
+GeometryCalib.R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1];
+
+%check error
+GeometryCalib.ErrorRms(1)=sqrt(mean((x1-x_ima).*(x1-x_ima)));
+GeometryCalib.ErrorMax(1)=max(abs(x1-x_ima));
+GeometryCalib.ErrorRms(2)=sqrt(mean((y1-y_ima).*(y1-y_ima)));
+GeometryCalib.ErrorMax(2)=max(abs(y1-y_ima));
+
+
+
+
+%------------------------------------------------------------------
+function GeometryCalib=calib_tsai(Coord)
+%------------------------------------------------------------------
+%TSAI
+% 'calibration_lin' provides a linear transform on coordinates,
+path_uvmat=which('uvmat');% check the path detected for source file uvmat
+path_UVMAT=fileparts(path_uvmat); %path to UVMAT
+if isunix
+ %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ binary names
+ xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml');
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+else
+ %fid = fopen(fullfile(path_UVMAT,'PARAM_WIN.txt'),'r');%open the file with civ binary names
+ xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
+ if exist(xmlfile,'file')
+ t=xmltree(xmlfile);
+ sparam=convert(t);
+ end
+end
+if ~isfield(sparam,'GeometryCalib_exe')
+ warndlg_uvmat(['calibration program undefined in parameter file ' xmlfile],'ERROR')
+ return
+end
+Tsai_exe=sparam.GeometryCalib_exe;
+if ~exist(Tsai_exe,'file')
+ warndlg_uvmat(['calibration program ' Tsai_exe ' does not exist'],'ERROR')
+ return
+end
+
+textcoord=num2str(Coord,4);
+dlmwrite('t.txt',textcoord,'');
+% ['!' Tsai_exe ' -f1 0 -f2 t.txt']
+ eval(['!' Tsai_exe ' -f t.txt > tsaicalib.log']);
+if ~exist('calib.dat','file')
+ warndlg_uvmat('no output from calibration program Tsai_exe: possibly too few points','ERROR')
+end
+calibdat=dlmread('calib.dat');
+GeometryCalib.CalibrationType='tsai';
+GeometryCalib.focal=calibdat(10);
+GeometryCalib.dpx_dpy=[calibdat(5) calibdat(6)];
+GeometryCalib.Cx_Cy=[calibdat(7) calibdat(8)];
+GeometryCalib.sx=calibdat(9);
+GeometryCalib.kappa1=calibdat(11);
+GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
+GeometryCalib.Tx_Ty_Tz=[calibdat(12) calibdat(13) calibdat(14)];
+Rx_Ry_Rz=calibdat([15:17]);
+sa = sin(Rx_Ry_Rz(1)) ;
+ca=cos(Rx_Ry_Rz(1));
+sb=sin(Rx_Ry_Rz(2));
+cb =cos(Rx_Ry_Rz(2));
+sg =sin(Rx_Ry_Rz(3));
+cg =cos(Rx_Ry_Rz(3));
+r1 = cb * cg;
+r2 = cg * sa * sb - ca * sg;
+r3 = sa * sg + ca * cg * sb;
+r4 = cb * sg;
+r5 = sa * sb * sg + ca * cg;
+r6 = ca * sb * sg - cg * sa;
+r7 = -sb;
+r8 = cb * sa;
+r9 = ca * cb;
+%EN DEDUIRE MATRICE R ??
+GeometryCalib.R=[r1,r2,r3;r4,r5,r6;r7,r8,r9];
+%erreur a caracteriser?
+%check error
+Calib.dpx=GeometryCalib.dpx_dpy(1);
+Calib.dpy=GeometryCalib.dpx_dpy(2);
+Calib.sx=GeometryCalib.sx;
+Calib.Cx=GeometryCalib.Cx_Cy(1);
+Calib.Cy=GeometryCalib.Cx_Cy(2);
+Calib.kappa1=GeometryCalib.kappa1;
+Calib.f=GeometryCalib.focal;
+Calib.Tx=GeometryCalib.Tx_Ty_Tz(1);
+Calib.Ty=GeometryCalib.Tx_Ty_Tz(2);
+Calib.Tz=GeometryCalib.Tx_Ty_Tz(3);
+Calib.R=GeometryCalib.R;
+X=Coord(:,1);
+Y=Coord(:,2);
+Z=Coord(:,3);
+x_ima=Coord(:,4);
+y_ima=Coord(:,5);
+[Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z);
+
+GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
+GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
+GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
+GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima));
+% Nfx
+% dx
+% dy
+% 5 dpx
+% 6 dpy
+% cx
+% cy
+% sx
+% f
+% kappa1
+% tx
+% ty
+% tz
+% rx
+% ry
+% rz
+% p1
+% p2
+
+%calibcoeff=str2num(calibdat)
+
+
+
+% --- Executes on button press in rotation.
+function rotation_Callback(hObject, eventdata, handles)
+angle_rot=(pi/180)*str2num(get(handles.Phi,'String'));
+Coord_cell=get(handles.ListCoord,'String');
+data=read_geometry_calib(Coord_cell);
+data.Coord(:,1)=cos(angle_rot)*data.Coord(:,1)+sin(angle_rot)*data.Coord(:,2);
+data.Coord(:,1)=-sin(angle_rot)*data.Coord(:,1)+cos(angle_rot)*data.Coord(:,2);
+set(handles.XObject,'String',num2str(data.Coord(:,1),4));
+set(handles.YObject,'String',num2str(data.Coord(:,2),4));
+
+
+function XImage_Callback(hObject, eventdata, handles)
+update_list(hObject, eventdata,handles)
+
+function YImage_Callback(hObject, eventdata, handles)
+update_list(hObject, eventdata,handles)
+
+function XObject_Callback(hObject, eventdata, handles)
+update_list(hObject, eventdata,handles)
+
+function YObject_Callback(hObject, eventdata, handles)
+update_list(hObject, eventdata,handles)
+
+function ZObject_Callback(hObject, eventdata, handles)
+update_list(hObject, eventdata,handles)
+
+function update_list(hObject, eventdata, handles)
+str4=get(handles.XImage,'String');
+str5=get(handles.YImage,'String');
+str1=get(handles.XObject,'String');
+tt=double(str1);
+str2=get(handles.YObject,'String');
+str3=get(handles.ZObject,'String');
+if ~isempty(str1) & ~isequal(double(str1),32) & (isempty(str3)|isequal(double(str3),32))
+ str3='0';%put z to 0 by default
+end
+strline=[str1 ' | ' str2 ' | ' str3 ' | ' str4 ' | ' str5];
+Coord=get(handles.ListCoord,'String');
+val=get(handles.ListCoord,'Value');
+Coord{val}=strline;
+set(handles.ListCoord,'String',Coord)
+
+%--------------------------------------------------------------------
+% --- Executes on selection change in ListCoord.
+%--------------------------------------------------------------------
+function ListCoord_Callback(hObject, eventdata, handles)
+% hObject handle to ListCoord (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: contents = get(hObject,'String') returns ListCoord contents as cell array
+% contents{get(hObject,'Value')} returns selected item from ListCoord
+%set(handles.edit_append,'Value',2); %set to edit mode
+Coord_cell=get(handles.ListCoord,'String');
+val=get(handles.ListCoord,'Value');
+if length(Coord_cell)>0
+ coord_str=Coord_cell{val};
+ k=findstr('|',coord_str);
+ if isempty(k)
+ return
+ end
+ set(handles.XObject,'String',coord_str(1:k(1)-5))
+ set(handles.YObject,'String',coord_str(k(1)+5:k(2)-5))
+ set(handles.ZObject,'String',coord_str(k(2)+5:k(3)-5))
+ set(handles.XImage,'String',coord_str(k(3)+5:k(4)-5))
+ set(handles.YImage,'String',coord_str(k(4)+5:end))
+ huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
+ hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat
+ h_menu_coord=findobj(huvmat,'Tag','menu_coord');
+ menu=get(h_menu_coord,'String');
+ choice=get(h_menu_coord,'Value');
+ if iscell(menu)
+ option=menu{choice};
+ else
+ option='px'; %default
+ end
+ if isequal(option,'phys')
+ XCoord=str2num(coord_str(1:k(1)-5));
+ YCoord=str2num(coord_str(k(1)+5:k(2)-5));
+ elseif isequal(option,'px')|| isequal(option,'')
+ XCoord=str2num(coord_str(k(3)+5:k(4)-5));
+ YCoord=str2num(coord_str(k(4)+5:end));
+ else
+ warndlg_uvmat('the choice in menu_coord of uvmat must be px or phys ','ERROR')
+ end
+ huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
+ hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat
+ hhh=findobj(hplot,'Tag','calib_marker');
+ if isempty(hhh)
+ axes(hplot)
+ line(XCoord,YCoord,'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20);
+ else
+ set(hhh,'XData',XCoord)
+ set(hhh,'YData',YCoord)
+ end
+end
+
+
+%----------------------------------------------------
+% --- Executes on button press in rotation_plus.
+function rotation_plus_Callback(hObject, eventdata, handles)
+Phi=0;
+Phi=get(handles.Phi,'String');
+if ~isempty(Phi)
+ Phi=str2num(Phi);
+end
+rotation(handles,Phi)
+
+%-------------------------------------------------
+% --- Executes on button press in rotation_minus.
+function rotation_minus_Callback(hObject, eventdata, handles)
+Phi=0;
+Phi=get(handles.Phi,'String');
+if ~isempty(Phi)
+ Phi=-str2num(Phi);
+end
+rotation(handles,Phi)
+
+%-----------------------------------------------------
+%rotation
+function rotation(handles,Phi)
+O_x=str2num(get(handles.O_x,'String'));
+O_y=str2num(get(handles.O_y,'String'));
+if isempty(O_x)
+ O_x=0;%default
+end
+if isempty(O_y)
+ O_y=0;%default
+end
+Coord_cell=get(handles.ListCoord,'String');
+data=read_geometry_calib(Coord_cell);
+%data=read_geometry_calib(handles);
+r1=cos(pi*Phi/180);
+r2=-sin(pi*Phi/180);
+r3=sin(pi*Phi/180);
+r4=cos(pi*Phi/180);
+x=data.Coord(:,1);
+y=data.Coord(:,2);
+data.Coord(:,1)=r1*x+r2*y;
+data.Coord(:,2)=r3*x+r4*y;
+% data.Coord(:,[4 5])=data.Coord(:,[4 5]);
+for i=1:size(data.Coord,1)
+ for j=1:5
+ Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z
+ end
+end
+Tabchar=cell2tab(Coord,' | ');
+set(handles.ListCoord,'Value',1)
+set(handles.ListCoord,'String',Tabchar)
+
+
+function O_x_Callback(hObject, eventdata, handles)
+
+
+function O_y_Callback(hObject, eventdata, handles)
+
+
+function O_z_Callback(hObject, eventdata, handles)
+
+
+% --- Executes on selection change in edit_append.
+function edit_append_Callback(hObject, eventdata, handles)
+% val=get(handles.PLOT_append,'Value');
+% if isequal(val,2); %append mode
+% %appeler mouse
+% end
+choice=get(handles.edit_append,'Value');
+if choice==1
+ Coord=get(handles.ListCoord,'String');
+ val=length(Coord);
+ if val>=1 & isequal(Coord{val},'')
+ val=val-1; %do not take into account blank
+ end
+ Coord{val+1}='';
+ set(handles.ListCoord,'String',Coord)
+ set(handles.ListCoord,'Value',val+1)
+end
+
+
+%A REVOIR
+% if choice==2
+% %display image with px coordinates
+% hrootpath=findobj(huvmat,'Tag','RootPath');
+% hrootfile=findobj(huvmat,'Tag','RootFile');
+% RootPath='';
+% RootFile='';
+% % if ~isempty(hrootpath)& ~isempty(hrootfile)
+% testhandle=1;
+% RootPath=get(hrootpath,'String');
+% RootFile=get(hrootfile,'String');
+% % filebase=fullfile(RootPath,RootFile);
+% % outputfile=[filebase '.xml'];
+% Indices=get(findobj(huvmat,'Tag','FileIndex'),'String');
+% Ext=get(findobj(huvmat,'Tag','FileExt'),'String');
+% imagename=[fullfile(RootPath,RootFile) Indices Ext];
+% % input.menu_coord=1;
+% h_menu_coord=findobj(huvmat,'Tag','menu_coord');
+% set(h_menu_coord,'Value',3)
+% huvmat=uvmat(imagename);%open uvmat, set phys coord (Value 1)
+%
+% % end
+% end
+
+function NEW_Callback(hObject, eventdata, handles)
+%A METTRE SOUS UN BOUTON
+huvmat=findobj(allchild(0),'Name','uvmat');
+hchild=get(huvmat,'children');
+hcoord=findobj(hchild,'Tag','menu_coord');
+coordtype=get(hcoord,'Value');
+haxes=findobj(hchild,'Tag','axes3');
+AxeData=get(haxes,'UserData');
+if ~isequal(hcoord,2)
+ set(hcoord,'Value',2)
+ huvmat=uvmat(AxeData);
+ 'relancer uvmat';
+end
+if ~isfield(AxeData,'ZoomAxes')
+ warndlg_uvmat('first draw a window around a grid marker','ERRROR')
+ return
+end
+XLim=get(AxeData.ZoomAxes,'XLim');
+YLim=get(AxeData.ZoomAxes,'YLim');
+np=size(AxeData.A);
+ind_sub_x=round(XLim);
+ind_sub_y=np(1)-round(YLim);
+Mfiltre=AxeData.A([ind_sub_y(2):ind_sub_y(1)] ,ind_sub_x,:);
+Mfiltre_norm=double(Mfiltre);
+Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm));
+Mfiltre_norm=100*(Mfiltre_norm-mean(mean(Mfiltre_norm)));
+Atype=class(AxeData.A);
+Data.NbDim=2;
+Data.A=filter2(Mfiltre_norm,double(AxeData.A));
+Data.A=feval(Atype,Data.A);
+Data.AName='image';
+Data.AX=AxeData.AX;
+Data.AY=AxeData.AY;
+Data.CoordType='px';
+plot_field(Data)
+
+
+
+%'key_press_fcn:' function activated when a key is pressed on the keyboard
+%-----------------------------------
+function key_press_fcn(hObject,eventdata,handles)
+hh=get(hObject,'parent');
+xx=double(get(hh,'CurrentCharacter')); %get the keyboard character
+
+if ismember(xx,[8 127])%backspace or delete
+ Coord_cell=get(handles.ListCoord,'String');
+ data=read_geometry_calib(Coord_cell);
+ Coord=[]; %default
+ if isfield(data,'Coord')
+ Coord=data.Coord;
+ end
+ val=get(handles.ListCoord,'Value');
+ Coord(val,:)=[];%suppress the selected item in the list
+ CoordCell={};
+ for iline=1:size(Coord,1)
+ for j=1:5
+ CoordCell{iline,j}=num2str(Coord(iline,j),4);
+ end
+ end
+ Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display
+ val=min(size(Coord,1),val);
+ set(handles.ListCoord,'Value',max(val,1))
+ set(handles.ListCoord,'String',Tabchar)
+ ListCoord_Callback(hObject, eventdata, handles)
+ PLOT_Callback(hObject,eventdata,handles)
+end
+
+
+% --- Executes on button press in append_point.
+function append_point_Callback(hObject, eventdata, handles)
+
+ Coord=get(handles.ListCoord,'String');
+ val=length(Coord);
+ if val>=1 & isequal(Coord{val},'')
+ val=val-1; %do not take into account blank
+ end
+ Coord{val+1}='';
+ set(handles.ListCoord,'String',Coord)
+ set(handles.ListCoord,'Value',val+1)
+
+
+% --------------------------------------------------------------------
+function MenuOpen_Callback(hObject, eventdata, handles)
+%get the object file
+huvmat=findobj(allchild(0),'Name','uvmat');
+UvData=get(huvmat,'UserData');
+hchild=get(huvmat,'Children');
+hrootpath=findobj(hchild,'Tag','RootPath');
+oldfile=get(hrootpath,'String');
+if isempty(oldfile)
+ oldfile='';
+end
+%[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile)
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.xml;*.mat', ' (*.xml,*.mat)';
+ '*.xml', '.xml files '; ...
+ '*.mat', '.mat matlab files '}, ...
+ 'Pick a file',oldfile);
+fileinput=[PathName FileName];%complete file name
+testblank=findstr(fileinput,' ');%look for blanks
+if ~isempty(testblank)
+ msgbox_uvmat('ERROR','forbidden input file name or path: no blank character allowed')
+ return
+end
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
+loadfile(handles,fileinput)
+
+
+% --------------------------------------------------------------------
+function Untitled_3_Callback(hObject, eventdata, handles)
+% hObject handle to Untitled_3 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function MenuPlot_Callback(hObject, eventdata, handles)
+
+huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
+UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
+hhuvmat=guidata(huvmat); %handles of GUI elements in uvmat
+hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat
+h_menu_coord=findobj(huvmat,'Tag','menu_coord');
+menu=get(h_menu_coord,'String');
+choice=get(h_menu_coord,'Value');
+if iscell(menu)
+ option=menu{choice};
+else
+ option='px'; %default
+end
+Coord_cell=get(handles.ListCoord,'String');
+ObjectData=read_geometry_calib(Coord_cell);
+%ObjectData=read_geometry_calib(handles);%read the interface input parameters defining the object
+if isequal(option,'phys')
+ ObjectData.Coord=ObjectData.Coord(:,[1:3]);
+elseif isequal(option,'px')||isequal(option,'')
+ ObjectData.Coord=ObjectData.Coord(:,[4:5]);
+else
+ msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be px or phys ')
+end
+axes(hhuvmat.axes3)
+hh=findobj('Tag','calib_points');
+if isempty(hh)
+ hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
+else
+ set(hh,'XData',ObjectData.Coord(:,1))
+ set(hh,'YData',ObjectData.Coord(:,2))
+end
+
+% --------------------------------------------------------------------
+function MenuHelp_Callback(hObject, eventdata, handles)
+path_to_uvmat=which ('uvmat');% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+ helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), warndlg_uvmat('The help file uvmat_doc.html needs to be put in the directory UVMAT/UVMAT_DOC','ERROR')
+else
+ web([helpfile '#geometry_calib'])
+end
+
+
+
+% --------------------------------------------------------------------
+function MenuCreateGrid_Callback(hObject, eventdata, handles)
+% hObject handle to MenuCreateGrid (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function MenuTranslatePoints_Callback(hObject, eventdata, handles)
+hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib
+CalibData=get(hcalib,'UserData')
+Tinput=[];%default
+if isfield(CalibData,'translate')
+ Tinput=CalibData.translate;
+end
+T=translate_points(Tinput);%display translate_points GUI and get shift parameters
+CalibData.translate=T;
+set(hcalib,'UserData',CalibData)
+Coord_cell=get(handles.ListCoord,'String');
+data=read_geometry_calib(Coord_cell);
+% data=read_geometry_calib(handles);
+data.Coord(:,1)=T(1)+data.Coord(:,1);
+data.Coord(:,2)=T(2)+data.Coord(:,2);
+data.Coord(:,3)=T(3)+data.Coord(:,3);
+data.Coord(:,[4 5])=data.Coord(:,[4 5]);
+for i=1:size(data.Coord,1)
+ for j=1:5
+ Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z
+ end
+end
+Tabchar=cell2tab(Coord,' | ');
+set(handles.ListCoord,'Value',1)
+set(handles.ListCoord,'String',Tabchar)
+
+
+% --------------------------------------------------------------------
+function MenuRotatePoints_Callback(hObject, eventdata, handles)
+% hObject handle to MenuRotatePoints (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function Untitled_8_Callback(hObject, eventdata, handles)
+% hObject handle to Untitled_8 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+
+function edit27_Callback(hObject, eventdata, handles)
+
+
+function edit28_Callback(hObject, eventdata, handles)
+% hObject handle to O_y (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of O_y as text
+% str2double(get(hObject,'String')) returns contents of O_y as a double
+
+
+% --- Executes on button press in rotation_plus.
+function pushbutton16_Callback(hObject, eventdata, handles)
+% hObject handle to rotation_plus (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --- Executes on button press in rotation_minus.
+function pushbutton17_Callback(hObject, eventdata, handles)
+% hObject handle to rotation_minus (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+
+function edit30_Callback(hObject, eventdata, handles)
+% hObject handle to Phi (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of Phi as text
+% str2double(get(hObject,'String')) returns contents of Phi as a double
+
+
+% --- Executes during object creation, after setting all properties.
+function O_y_CreateFcn(hObject, eventdata, handles)
+% hObject handle to O_y (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+% --- Executes during object creation, after setting all properties.
+function O_x_CreateFcn(hObject, eventdata, handles)
+% hObject handle to O_x (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+% --- Executes during object creation, after setting all properties.
+function T_x_CreateFcn(hObject, eventdata, handles)
+% hObject handle to T_x (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+% --- Executes during object creation, after setting all properties.
+function T_y_CreateFcn(hObject, eventdata, handles)
+% hObject handle to T_y (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+% --- Executes during object creation, after setting all properties.
+function T_z_CreateFcn(hObject, eventdata, handles)
+% hObject handle to T_z (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+
+function edit31_Callback(hObject, eventdata, handles)
+% hObject handle to edit31 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of edit31 as text
+% str2double(get(hObject,'String')) returns contents of edit31 as a double
+
+
+% --- Executes during object creation, after setting all properties.
+function edit31_CreateFcn(hObject, eventdata, handles)
+% hObject handle to edit31 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+
+function edit32_Callback(hObject, eventdata, handles)
+% hObject handle to edit32 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of edit32 as text
+% str2double(get(hObject,'String')) returns contents of edit32 as a double
+
+
+% --- Executes during object creation, after setting all properties.
+function edit32_CreateFcn(hObject, eventdata, handles)
+% hObject handle to edit32 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+% See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+ set(hObject,'BackgroundColor','white');
+end
+
+
+
+function edit33_Callback(hObject, eventdata, handles)
+% hObject handle to edit33 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of edit33 as text
+% str2double(get(hObject,'String')) returns contents of edit33 as a double
+
+
+% --- Executes on button press in pushbutton18.
+function pushbutton18_Callback(hObject, eventdata, handles)
+% hObject handle to pushbutton18 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --- Executes on button press in pushbutton19.
+function pushbutton19_Callback(hObject, eventdata, handles)
+% hObject handle to pushbutton19 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+
+
Index: /trunk/src/get_field.m
===================================================================
--- /trunk/src/get_field.m (revision 2)
+++ /trunk/src/get_field.m (revision 2)
@@ -0,0 +1,1958 @@
+%'get_field': display variables and attributes from a Netcdf file, and RUN selected fields
+%------------------------------------------------------------------------
+%function varargout = get_field(varargin)
+% associated with the GUI get_field.fig
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function varargout = get_field(varargin)
+
+% Last Modified by GUIDE v2.5 13-Nov-2009 22:14:18
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 0;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @get_field_OpeningFcn, ...
+ 'gui_OutputFcn', @get_field_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin & isstr(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+
+% --- Executes just before get_field is made visible.
+function get_field_OpeningFcn(hObject, eventdata, handles,filename,Field,haxes)
+
+set(handles.dimensions,'enable','on')% should be put by guide
+browse_fig(handles.list_fig)
+
+% Choose default command line output for get_field
+handles.output = hObject;
+
+% Update handles structure
+guidata(hObject, handles);
+pathuvmat=fileparts(which('uvmat'));
+addpath(fullfile(pathuvmat,'FIELD_FCT'))
+set(handles.attributes,'enable','on')% TO BE SET BY GUIDE
+set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles})%set mouse click action function
+if exist('filename','var')& ischar(filename)
+ set(handles.inputfile,'String',filename)
+ inputfile_Callback(hObject, eventdata, handles)
+else
+ set(handles.inputfile,'String','')
+ %loads the information stored in prefdir to initiate the browser and the list of functions
+ menu_str={'PLOT'};%list of functions included in 'get_field.m'
+ %menu_str(end)=[];%remove from the list the last option 'more...'
+ path_get_field=which('get_field');%path of the function 'get_field'
+ for ilist=1:length(menu_str)
+ fct_path{ilist,1}=path_get_field;%paths of the fuctions buil-in in 'get_field.m'
+ end
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ if exist(profil_perso,'file')
+ % menu={'RUN';'raw2phys';'histogram';'FFT';'peaklocking'};
+ h=load (profil_perso);
+ if isfield(h,'get_field_fct') && iscell(h.get_field_fct)
+ for ilist=1:length(h.get_field_fct)
+ [path,file]=fileparts(h.get_field_fct{ilist});
+ fct_path=[fct_path; {path}];%concatene the list of paths
+ menu_str=[menu_str; {file}];
+ end
+
+ end
+ end
+ menu_str=[menu_str;{'more...'}];
+ set(handles.ACTION,'String',menu_str)
+ set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION
+ % display the GUI for the default action 'check_files'
+ ACTION_Callback(hObject, eventdata, handles)
+end
+% menu=[menu;h.fct_get_field];
+% menu=[menu;{'more...'}];
+% fct_path=h.fct_path_get_field;
+% set(handles.ACTION,'String',menu)
+% set(handles.ACTION,'UserData',fct_path)
+% for ipath=1:length(fct_path)
+% if exist(fct_path{ipath},'dir')
+% addpath(fct_path{ipath})
+% end
+% end
+% end
+% end
+% end
+if exist('Field','var') & isstruct(Field)
+ Field_input(eventdata,handles,Field)
+ if exist('haxes','var')
+ Field.PlotAxes=haxes;
+ end
+ set(hObject,'UserData',Field);
+end
+
+
+
+
+
+
+%-----------------------------------------------------------
+% --- Outputs from this function are returned to the command line.
+function varargout = get_field_OutputFcn(hObject, eventdata, handles)
+varargout{1} = handles.output;
+
+%-----------------------------------------------------------
+% --- Executes on button press in browse.
+function browse_Callback(hObject, eventdata, handles)
+
+
+
+
+%---------------------------------------------------------
+function inputfile_Callback(hObject, eventdata, handles)
+inputfile=get(handles.inputfile,'String');
+Field=nc2struct(inputfile,[]);% reads only the lists of fields, dimensions and attributes
+hfig=get(handles.inputfile,'parent');
+set(hfig,'UserData',Field);
+Field_input(eventdata,handles,Field);
+
+
+%---------------------------------------------------------
+function Field_input(eventdata,handles,Field)
+
+if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
+ Tabcell(:,1)=Field.ListDimName;
+ for iline=1:length(Field.ListDimName)
+ Tabcell{iline,2}=num2str(Field.DimValue(iline));
+ end
+ Tabchar=cell2tab(Tabcell,'=');
+ set(handles.dimensions,'String',Tabchar)
+end
+if ~isfield(Field,'ListVarName')
+ return
+end
+Txt=Field.ListVarName;
+set(handles.variables,'Value',1)
+set(handles.variables,'String',[{'*'} Txt])
+variables_Callback(handles.variables,[], handles)
+set(handles.abscissa,'String',[{''} Txt ])
+set(handles.ordinate,'String',Txt)
+set(handles.vector_x,'String',[Txt ])
+set(handles.vector_y,'String',[Txt ])
+set(handles.vector_z,'String',[{''} Txt ])
+set(handles.vec_color,'String',[{''} Txt ])
+set(handles.coord_x_scalar,'String',[{''} Txt ])
+set(handles.coord_y_scalar,'String',[{''} Txt ])
+set(handles.coord_x_vectors,'String',[{''} Txt ])
+set(handles.coord_y_vectors,'String',[{''} Txt ])
+set(handles.coord_z_scalar,'String',[{''} Txt ])
+set(handles.coord_z_vectors,'String',[{''} Txt ])
+set(handles.scalar,'Value',1)
+set(handles.scalar,'String', Txt )
+
+[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field);
+if ~isempty(errormsg)
+ msgbox_uvmat('ERROR',['error in get_field/Field_input/find_field_indices: ' errormsg])
+ return
+end
+[maxdim,imax]=max(NbDim);
+
+if maxdim>=3
+ set(handles.vector_z,'Visible','on')
+ set(handles.vector_z,'String',[{''} Txt ])
+ set(handles.coord_z_vectors,'Visible','on')
+ set(handles.coord_z_vectors,'String',[{''} Txt ])
+ set(handles.coord_z_scalar,'Visible','on')
+ set(handles.coord_z_scalar,'String',[{''} Txt ])
+else
+ set(handles.vector_z,'Visible','off')
+ set(handles.coord_z_vectors,'Visible','off')
+ set(handles.coord_z_scalar,'Visible','off')
+end
+if maxdim>=2
+ set(handles.check_1Dplot,'Value',0)
+ if ~isempty(VarType{imax}.vector_x) && ~isempty(VarType{imax}.vector_y)
+ set(handles.check_vector,'Value',1)
+ set(handles.vector_x,'Value',VarType{imax}.vector_x)
+ set(handles.vector_y,'Value',VarType{imax}.vector_y)
+ set(handles.check_scalar,'Value',0)
+ else
+ set(handles.check_scalar,'Value',1)
+ set(handles.check_vector,'Value',0)
+ if isfield(VarType{imax},'scalar') && length(VarType{imax}.scalar)>=1
+ set(handles.scalar,'Value',VarType{imax}.scalar(1))
+ end
+ end
+ check_1Dplot_Callback(handles.check_1Dplot, eventdata, handles)
+ check_scalar_Callback(handles.check_scalar, eventdata, handles)
+ check_vector_Callback(handles.check_vector, eventdata, handles)
+end
+
+
+%----------------------------------------------------------
+function ordinate_Callback(hObject, eventdata, handles)
+%update_field(hObject, eventdata, handles)
+% A REVOIR
+hselect_field=get(handles.inputfile,'parent');
+Field=get(hselect_field,'UserData');
+% xindex=get(handles.abscissa,'Value');
+list=get(handles.ordinate,'String');
+yindex=get(handles.ordinate,'Value');
+yindex=name2index(list{yindex(1)},Field.ListVarName);
+if ~isempty(yindex)
+ set(handles.variables,'Value',yindex+1)
+ variables_Callback(hObject, eventdata, handles)
+end
+[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field);
+for icell=1:numel(CellVarIndex)
+ VarIndex=CellVarIndex{icell};
+ if ~isempty(find(VarIndex==yindex)) && (isempty(VarType{icell}.coord_x)||~isequal(VarType{icell}.coord_x,VarIndex))
+ cell_select=icell;
+ break
+ end
+end
+
+val=get(handles.abscissa,'Value');
+set(handles.abscissa,'Value',min(val,2));
+coord_x_index=VarType{cell_select}.coord;
+coord_x_index=coord_x_index(find(coord_x_index));
+set(handles.abscissa,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
+% Field.VarIndex.y=yindex;
+% set(hselect_field,'UserData',Field);
+%update_UserData(handles)
+
+%----------------------------------------------------------------------
+% --- Executes on selection change in abscissa.
+function abscissa_Callback(hObject, eventdata, handles)
+ hselect_field=get(handles.inputfile,'parent');
+ Field=get(hselect_field,'UserData');%current input field
+ xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa
+% test_2D=get(handles.check_vector,'Value');% =1 for vector fields
+% test_scalar=get(handles.check_scalar,'Value');% =1 for scalar fields
+%if isequal(xdispindex,1)% blank selection, no selected variable for abscissa
+% Txt=Field.ListVarName;
+% set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates
+% xindex=[];
+% else
+ xlist=get(handles.abscissa,'String');%list of abscissa
+ VarName=xlist{xdispindex}; %selected variable name
+ update_field(hObject, eventdata, handles,VarName)
+% xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables
+% if ~isempty(xindex)
+% set(handles.variables,'Value',xindex+1)
+% variables_Callback(hObject, eventdata, handles)
+% end
+% set(handles.variables,'Value',xindex+1)%outline in the list of variables
+% variables_Callback(hObject, eventdata, handles) %display properties of the variable (dim, attributes)
+% if ~test_2D & ~test_scalar% look for possible varaibles to RUN in ordinate
+% index=Field.VarDimIndex{xindex};%dimension indices of the variable selected for abscissa
+% VarIndex=[];
+% for ilist=1:length(Field.VarDimIndex)%detect
+% index_i=Field.VarDimIndex{ilist};
+% if ~isempty(index_i)
+% if isequal(index_i(1),index(1))%if the first dimension of the variable coincide with the selected one, RUN is possible
+% VarIndex=[VarIndex ilist];
+% end
+% end
+% end
+% % set(handles.ordinate,'Value',1)
+% set(handles.ordinate,'String',Field.ListVarName(VarIndex))
+% end
+% end
+%
+% update_UserData(handles)
+
+%-------------------------------------------------------
+% --- Executes on selection change in scalar menu.
+function scalar_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+Aindex=get(handles.scalar,'Value');
+Astring=get(handles.scalar,'String');
+VarName=Astring{Aindex};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in coord_x_scalar.
+function coord_x_scalar_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.coord_x_scalar,'Value');
+string=get(handles.coord_x_scalar,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in coord_y_scalar.
+function coord_y_scalar_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.coord_y_scalar,'Value');
+string=get(handles.coord_y_scalar,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in coord_z_scalar.
+function coord_z_scalar_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.coord_z_scalar,'Value');
+string=get(handles.coord_z_scalar,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in vector_x.
+function vector_x_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.vector_x,'Value');
+string=get(handles.vector_x,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in vector_y.
+function vector_y_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.vector_y,'Value');
+string=get(handles.vector_y,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in vector_z.
+function vector_z_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.vector_z,'Value');
+string=get(handles.vector_z,'String');
+VarName=Astring{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in coord_x_vectors.
+function coord_x_vectors_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.coord_x_vectors,'Value');
+string=get(handles.coord_x_vectors,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in coord_y_vectors.
+%-------------------------------------------------------
+function coord_y_vectors_Callback(hObject, eventdata, handles)
+index=get(handles.coord_y_vectors,'Value');
+string=get(handles.coord_y_vectors,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in coord_z_scalar.
+function coord_z_vectors_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.coord_z_vectors,'Value');
+string=get(handles.coord_z_vectors,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in vec_color.
+function vec_color_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.vec_color,'Value');
+string=get(handles.vec_color,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%---------------------------------
+function update_field(hObject, eventdata, handles,VarName)
+% VarName= input variable name for scalar or vector plots
+%if ischar(VarName)
+hselect_field=get(handles.inputfile,'parent');
+Field=get(hselect_field,'UserData');
+index=name2index(VarName,Field.ListVarName);
+if ~isempty(index)
+ set(handles.variables,'Value',index+1)
+ variables_Callback(hObject, eventdata, handles)
+end
+%
+%
+% hselect_field=get(handles.inputfile,'parent');
+% Field=get(hselect_field,'UserData');
+% ivar_sel=[];%default
+% for ivar=1:length(Field.ListVarName)%detect
+% if isequal(Field.ListVarName{ivar},VarName)
+% ivar_sel=ivar; %ivar_sel = index of the input variable in the list ListVarName
+% break
+% end
+% end
+% if isempty(ivar_sel)
+% return
+% end
+% set(handles.variables,'Value',ivar_sel+1)%select the corresponding item in the displayed list 'variables'
+% variables_Callback(hObject, eventdata, handles)%show the dimensions and attributes of the input variable
+%
+% index=Field.VarDimIndex{ivar_sel};%dimension indices of the input variable
+% DimValue=Field.DimValue(index);%dimension values of the input variable
+% ind_1=find(DimValue==1);
+% index(ind_1)=[];%Mremove singletons
+%
+%
+% % detect possible variables for abscissa and ordinate
+% VarIndex=[];%initiate list of selected variable indices
+% ind_coordvar=[]; %initiate list of coordinate variables
+% for ilist=1:length(Field.VarDimIndex)
+% if ~isequal(ilist,ivar_sel)
+% index_i=Field.VarDimIndex{ilist};%indices of dimensions associated with variable #ilist
+% if length(index_i)>1
+% DimValue=Field.DimValue(index_i);
+% ind_1=find(DimValue==1);
+% index_i(ind_1)=[];%Mremove singletons
+% if isequal(index,index_i)
+% VarIndex=[VarIndex ilist]; %selected variable withb the same dimensions of the input variable
+% end
+% else
+% idim=find(index==index_i(1));
+% if ~isempty(idim)
+% VarIndex=[VarIndex ilist]; %possible dimension variable
+% if isequal(Field.ListDimName{index_i(1)},Field.ListVarName{ilist})
+% ind_coordvar=[ind_coordvar length(VarIndex)];
+% end
+% end
+% end
+% end
+% end
+% % val=get(handles.abscissa,'Value');
+% % if val>length(Field.ListVarName(VarIndex))+1
+% % set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
+% % end
+% % val=get(handles.ordinate,'Value');
+% % if val>length(Field.ListVarName(VarIndex))+1
+% % set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
+% % end
+% % val=get(handles.coord_z_vectors_scalar,'Value');
+% % if val>length(Field.ListVarName(VarIndex))+1
+% % set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
+% % end
+% set(handles.abscissa,'Value',1)%default
+% set(handles.ordinate,'Value',1)%default
+% set(handles.coord_z_scalar,'Value',1)%default
+% set(handles.abscissa,'String',[{''} Field.ListVarName(VarIndex) ])
+% set(handles.ordinate,'String',[{''} Field.ListVarName(VarIndex) ])
+% set(handles.coord_z_scalar,'String',[{''} Field.ListVarName(VarIndex) ])
+% if length(ind_coordvar)>=1
+% set(handles.abscissa,'Value',ind_coordvar(1)+1)
+% elseif length(index)==1 && length(VarIndex)>=1
+% set(handles.abscissa,'Value',2)
+% end
+% if length(ind_coordvar)>=2
+% set(handles.ordinate,'Value',ind_coordvar(2)+1)
+% elseif length(index)==1 && length(VarIndex)>=2
+% set(handles.ordinate,'Value',3)
+% end
+% if length(ind_coordvar)>=3
+% set(handles.coord_z_scalar,'Value',ind_coordvar(3)+1)
+% elseif length(index)==1 && length(VarIndex)>=3
+% set(handles.coord_z_scalar,'Value',4)
+% end
+
+%---------------------------------------------------------
+% update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback)
+function update_UserData(handles)
+%---------------------------------------------------------
+return
+% global SubField
+hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
+Field=get(hselect_field,'UserData');% read the current field Structure in the get_field interface
+if isfield(Field,'VarAttribute')
+ VarAttribute=Field.VarAttribute;
+else
+ VarAttribute={};
+end
+
+
+% select the indices of field variables for 2D plots
+test_check_1Dplot=get(handles.check_1Dplot,'Value');
+test_scalar=get(handles.check_scalar,'Value');
+test_vector=get(handles.check_vector,'Value');
+
+%transform if needed (calibration)
+list=get(handles.menu_coord,'String');
+index=get(handles.menu_coord,'Value');
+transform=list{index};
+if ~isequal(transform,'')
+ Field=feval(transform,Field);
+end
+VarIndex.u=[];
+VarIndex.v=[];
+VarIndex.w=[];
+VarIndex.A=[];
+VarIndex_tot=[];
+iuA=[];
+if test_scalar
+ Astring=get(handles.scalar,'String');
+ Aindex=get(handles.scalar,'Value');%selected indices in the ordinate listbox
+ list_var=Astring(Aindex);
+ VarIndex.A=name2index(list_var,Field.ListVarName);%index of the variable A in ListVarName
+ VarIndex_tot= [VarIndex_tot VarIndex.A];
+ DimIndex=Field.VarDimIndex{VarIndex.A};%dimension indices of the variable
+ DimValue=Field.DimValue(DimIndex);
+ ind=find(DimValue==1);
+ DimIndex(ind)=[];%Mremove singleton
+end
+if test_vector
+ Ustring=get(handles.vector_x,'String');
+ Uindex=get(handles.vector_x,'Value'); %selected indices in the ordinate listbox
+ list_var=Ustring{Uindex};%name of the selected scalar
+ VarIndex.u=name2index(list_var,Field.ListVarName);
+ Vstring=get(handles.vector_y,'String');
+ Vindex=get(handles.vector_y,'Value'); %selected indices in the ordinate listbox
+ list_var=Ustring{Vindex};%name of the selected scalar
+ VarIndex.v=name2index(list_var,Field.ListVarName);
+ if isequal(VarIndex.u,VarIndex.A)|isequal(VarIndex.v,VarIndex.A)
+ iuA=VarIndex.A; %same variable used for vector and scalar
+ VarIndex_tot(iuA)=[];
+ end
+ VarIndex_tot=[VarIndex_tot VarIndex.u VarIndex.v];
+ %dimensions
+ DimIndex_u=Field.VarDimIndex{VarIndex.u};%dimension indices of the variable
+ DimValue=Field.DimValue(DimIndex_u);
+ ind=find(DimValue==1);
+ DimIndex_u(ind)=[];%Mremove singleton
+ DimIndex_v=Field.VarDimIndex{VarIndex.v};%dimension indices of the variable
+ DimValue=Field.DimValue(DimIndex_v);
+ ind=find(DimValue==1);
+ DimIndex_v(ind)=[];%Mremove singleton
+ if ~isequal(DimIndex_u,DimIndex_v)
+ warndlg_uvmat('inconsistent dimensions for u and v','ERROR')
+ set(handles.vector_y,'Value',1);
+ return
+ elseif test_scalar & ~isequal(DimIndex_u,DimIndex)
+ warndlg_uvmat('inconsistent dimensions for vector and scalar represented as vector color','ERROR')
+ set(handles.scalar,'Value',1);
+ return
+ end
+ DimIndex=DimIndex_u;
+ %TODO possibility of selecting 3 times the same variable for u, v, w components
+end
+
+
+% select the variable index (or indices) for z coordinates
+test_grid=0;
+if test_scalar | test_vector
+ nbdim=length(DimIndex);
+ if nbdim > 3
+ warndlg_uvmat('array with more than three dimensions, not supported','ERROR')
+ return
+ else
+ perm_ind=[1:nbdim];
+ end
+ if nbdim==3
+ zstring=get(handles.coord_z_vectors_scalar,'String');
+ zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox
+ list_var=zstring(zindex);
+ VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable
+ if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z)
+ if zindex ~= 1
+ set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components
+ return
+ end
+ else
+ VarIndex_tot=[VarIndex_tot VarIndex_z];
+ DimIndex_z=Field.VarDimIndex{VarIndex_z};
+ DimValue=Field.DimValue(DimIndex_z);
+ ind=find(DimValue==1);
+ DimIndex_z(ind)=[];%Mremove singleton
+ if isequal(DimIndex_z,DimIndex)
+ VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates
+ elseif length(DimIndex_z)==1
+ VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z}; %dimension variable
+ ind_z=find(DimIndex==DimIndex_z(1));
+ perm_ind(ind_z)=1;
+ test_grid=1;
+ else
+ warndlg_uvmat('multiple dimensions for the z coordinate','ERROR')
+ return
+ end
+ end
+% if ~isempty(VarIndex_z)
+% DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the variable
+% if length(DimIndex_z)==1 & nbdim==3 %dimension variable
+% VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
+% ind_z=find(DimIndex==DimIndex_z(1));
+% perm_ind(ind_z)=1;
+% test_grid=1;
+% end
+% end
+ end
+end
+
+% select the variable index (or indices) for ordinate
+ystring=get(handles.ordinate,'String');
+yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
+list_var=ystring(yindex);
+VarIndex.y=name2index(list_var,Field.ListVarName);
+if isequal(VarIndex.A,VarIndex.y)
+ set(handles.coord_y_scalar,'Value',1)
+elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y)
+ set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components
+else
+ for ivar=1:length(VarIndex.y)
+ VarAttribute{VarIndex.y(ivar)}.Role='coord_y';
+ end
+ VarIndex_tot=[VarIndex_tot VarIndex.y];
+end
+if (test_scalar | test_vector) & ~isempty(VarIndex.y)
+ DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable
+ if length(DimIndex_y)==1
+ ind_y=find(DimIndex==DimIndex_y(1));
+ test_grid=1;
+ if nbdim==3
+ VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
+ perm_ind(ind_y)=2;
+ elseif nbdim==2
+ VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
+ perm_ind(ind_y)=1;
+ end
+ elseif test_grid
+ warndlg_uvmat('the dimension of the y coordinate variable should be 1','ERROR')
+ end
+end
+
+%select the variable index for the abscissa
+xstring=get(handles.abscissa,'String');
+xindex=get(handles.abscissa,'Value');
+list_var=xstring(xindex);
+VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var
+if length(VarIndex.x)==1
+ DimIndex_x=Field.VarDimIndex{VarIndex.x};
+ DimValue=Field.DimValue(DimIndex_x);
+ ind=find(DimValue==1);
+ DimIndex_x(ind)=[];%Mremove singleton
+ VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; %dimension variable
+% VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified)
+ index_detect=find(VarIndex_tot==VarIndex.x);
+else
+ index_detect=[];%coord x variable not already used
+end
+if isempty(index_detect)
+ VarIndex_tot=[VarIndex_tot VarIndex.x];
+elseif ~test_check_1Dplot
+ VarIndex.x=[];
+ set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa
+end
+
+if (test_scalar | test_vector) & ~isempty(VarIndex.x)
+ DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable
+ if length(DimIndex_x)==1
+ ind_x=find(DimIndex==DimIndex_x(1));
+ if nbdim==3
+ %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
+ perm_ind(ind_x)=3;
+ elseif nbdim==2
+ %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
+ perm_ind(ind_x)=2;
+ end
+ if isequal(perm_ind,1:nbdim)
+ test_grid=0;
+ end
+ DimIndex=DimIndex(perm_ind);
+ elseif test_grid
+ warndlg_uvmat('the dimension of the x coordinate variable should be 1','ERROR')
+ end
+ if isequal(DimIndex_x,DimIndex)
+ VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates
+ end
+end
+
+%defined the selected sub-field SubField
+SubField.ListGlobalAttribute{1}='InputFile';
+SubField.InputFile=get(handles.inputfile,'String');
+SubField.ListDimName=Field.ListDimName;
+SubField.DimValue=Field.DimValue;
+SubField.ListVarName=Field.ListVarName(VarIndex_tot);
+SubField.VarDimIndex=Field.VarDimIndex(VarIndex_tot);
+
+testperm=0;
+testattr=0;
+for ivar=VarIndex.u
+ VarAttribute{ivar}.Role='vector_x';
+ testattr=1;
+ if test_grid
+ VarDimIndex{ivar}=DimIndex; %permute dimensions
+ testperm=1;
+ end
+end
+for ivar=VarIndex.v
+ VarAttribute{ivar}.Role='vector_y';
+ testattr=1;
+ if test_grid
+ VarDimIndex{ivar}=DimIndex;%permute dimensions
+ testperm=1;
+ end
+end
+for ivar=VarIndex.A
+ if test_grid
+ VarDimIndex{ivar}=DimIndex;%permute dimensions
+ testperm=1;
+ end
+ if isempty(iuA)
+ VarAttribute{ivar}.Role='scalar';%Role =scalar
+ testattr=1;
+ else
+ VarAttribute=[VarAttribute VarAttribute(ivar)]; %duplicate the attribute for a new variable
+ nbattr=length(VarAttribute);
+ VarAttribute{nbattr}.Role='scalar';
+ testattr=1;
+ end
+end
+if testperm
+ SubField.VarDimIndex=VarDimIndex(VarIndex_tot);
+end
+if testattr
+ SubField.VarAttribute=VarAttribute(VarIndex_tot);
+end
+set(hselect_field,'UserData',Field)
+
+%---------------------------------------------------------
+% --- Executes on button press in RUN.
+function RUN_Callback(hObject, eventdata, handles)
+%---------------------------------------------------------
+list=get(handles.ACTION,'String');
+index=get(handles.ACTION,'Value');
+ACTION=list{index};
+hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
+feval(ACTION,hselect_field);
+browse_fig(handles.list_fig); %update the list of new existing figures
+
+%---------------------------------------------------------
+% --- Executes on button press in RUN.
+function PLOT(hget_field)
+%---------------------------------------------------------
+[SubField,errormsg]=read_get_field(hget_field);
+if ~isempty(errormsg)
+ msgbox_uvmat('ERROR',['error in get_field/PLOT input:' errormsg])
+ return
+end
+handles=guidata(hget_field);
+list_fig=get(handles.list_fig,'String');
+val=get(handles.list_fig,'Value');
+if strcmp(list_fig{val},'uvmat')
+ uvmat(SubField)
+else
+hfig=str2num(list_fig{val});% chosen figure number from tyhe GUI
+if isempty(hfig)
+ hfig=figure;
+ list_fig=[list_fig;num2str(hfig)];
+ set(handles.list_fig,'String',list_fig);
+ haxes=axes;
+else
+ figure(hfig);
+end
+haxes=findobj(hfig,'Type','axes');
+
+plot_field(SubField,haxes)
+end
+
+
+%
+% return
+% testuvmat=0;
+% if test_scalar|test_vector
+% [DimVarIndex,CellVarIndex,NbDim]=find_field_indices(SubField);
+% NbDim=max(NbDim);
+% if NbDim==3
+% testuvmat=1; %uvmat interface needed for 3D plots
+% end
+% end
+% if iscell(list_fig)
+% RUN_fig=list_fig{fig_index};
+% else
+% RUN_fig='new fig...';%new plotting axes must be created
+% end
+% if isequal(RUN_fig,'new fig...') & (test_scalar|test_vector)
+% RUN_fig='uvmat';%use uvmat for a new fig
+% end
+% if testuvmat
+% RUN_fig='uvmat';
+% end
+% if isequal(RUN_fig,'uvmat')
+%
+% huvmat=uvmat(SubField);
+% menu=update_menu(handles.list_fig,'uvmat');%add the selected fct to the menu
+% else
+% test_new=1;
+% if ~isequal(RUN_fig,'new fig...')
+% sep=regexp(RUN_fig,'_')%look for subaxes in a fig
+% if isempty(sep)
+% axe_index=1;
+% else
+% axe_index=str2num(RUN_fig(sep+1:end))
+% RUN_fig=RUN_fig([1:sep-1])
+% end
+% if ishandle(str2num(RUN_fig))
+% haxes=findobj(str2num(RUN_fig),'Type','axes')
+% for iaxe=1:length(haxes)
+% Tag=get(haxes(iaxe),'Tag');
+% if isequal(Tag,'Colorbar')|isequal(Tag,'legend')
+% iselect(iaxe)=0;
+% else
+% iselect(iaxe)=1;
+% end
+% end
+% haxes=haxes(find(iselect));
+% if length(haxes)>=axe_index
+% test_new=0
+% haxes=haxes(axe_index);
+% set(haxes,'NextPlot','add')
+% end
+% end
+% end
+% if test_new
+% hfig=figure;
+% haxes=axes;
+% menu=update_menu(handles.list_fig,num2str(hfig));%add the selected fct to the menu
+% end
+% RUN_field(SubField,haxes)
+% end
+% end
+%
+%
+%
+%
+% w components
+% end
+%
+%
+% % select the variable index (or indices) for z coordinates
+% test_grid=0;
+% if test_scalar | test_vector
+% nbdim=length(DimIndex);
+% if nbdim > 3
+% warndlg_uvmat('array with more than three dimensions, not supported','ERROR')
+% return
+% else
+% perm_ind=[1:nbdim];
+% end
+% if nbdim==3
+% zstring=get(handles.coord_z_vectors_scalar,'String');
+% zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox
+% list_var=zstring(zindex);
+% VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable
+% if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z)
+% if zindex ~= 1
+% set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components
+% return
+% end
+% else
+% VarIndex_tot=[VarIndex_tot VarIndex_z];
+% DimIndex_z=Field.VarDimIndex{VarIndex_z};
+% DimValue=Field.DimValue(DimIndex_z);
+% ind=find(DimValue==1);
+% DimIndex_z(ind)=[];%Mremove singleton
+% if isequal(DimIndex_z,DimIndex)
+% VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates
+% elseif length(DimIndex_z)==1
+% VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z}; %dimension variable
+% ind_z=find(DimIndex==DimIndex_z(1));
+% perm_ind(ind_z)=1;
+% test_grid=1;
+% else
+% warndlg_uvmat('multiple dimensions for the z coordinate','ERROR')
+% return
+% end
+% end
+% % if ~isempty(VarIndex_z)
+% % DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the variable
+% % if length(DimIndex_z)==1 & nbdim==3 %dimension variable
+% % VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
+% % ind_z=find(DimIndex==DimIndex_z(1));
+% % perm_ind(ind_z)=1;
+% % test_grid=1;
+% % end
+% % end
+% end
+% end
+%
+% % select the variable index (or indices) for ordinate
+% ystring=get(handles.ordinate,'String');
+% yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
+% list_var=ystring(yindex);
+% VarIndex.y=name2index(list_var,Field.ListVarName);
+% if isequal(VarIndex.A,VarIndex.y)|isequal(VarIndex.u,VarIndex.y)|isequal(VarIndex.v,VarIndex.y)|isequal(VarIndex.w,VarIndex.y)
+% set(handles.ordinate,'Value',1)%ordinate cannot be the same as scalar or vector components
+% else
+% for ivar=1:length(VarIndex.y)
+% VarAttribute{VarIndex.y(ivar)}.Role='coord_y';
+% end
+% VarIndex_tot=[VarIndex_tot VarIndex.y];
+% end
+% if (test_scalar | test_vector) & ~isempty(VarIndex.y)
+% DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable
+% if length(DimIndex_y)==1
+% ind_y=find(DimIndex==DimIndex_y(1));
+% test_grid=1;
+% if nbdim==3
+% VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
+% perm_ind(ind_y)=2;
+% elseif nbdim==2
+% VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
+% perm_ind(ind_y)=1;
+% end
+% elseif test_grid
+% warndlg_uvmat('the dimension of the y coordinate variable should be 1','ERROR')
+% end
+% end
+%
+% %select the variable index for the abscissa
+% xstring=get(handles.abscissa,'String');
+% xindex=get(handles.abscissa,'Value');
+% list_var=xstring(xindex);
+% VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var
+% if length(VarIndex.x)==1
+% DimIndex_x=Field.VarDimIndex{VarIndex.x};
+% DimValue=Field.DimValue(DimIndex_x);
+% ind=find(DimValue==1);
+% DimIndex_x(ind)=[];%Mremove singleton
+% VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; %dimension variable
+% % VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified)
+% index_detect=find(VarIndex_tot==VarIndex.x);
+% else
+% index_detect=[];%coord x variable not already used
+% end
+% if isempty(index_detect)
+% VarIndex_tot=[VarIndex_tot VarIndex.x];
+% else
+% VarIndex.x=[];
+% set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa
+% end
+%
+% if (test_scalar | test_vector) & ~isempty(VarIndex.x)
+% DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable
+% if length(DimIndex_x)==1
+% ind_x=find(DimIndex==DimIndex_x(1));
+% if nbdim==3
+% %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
+% perm_ind(ind_x)=3;
+% elseif nbdim==2
+% %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
+% perm_ind(ind_x)=2;
+% end
+% if isequal(perm_ind,[1:nbdim])
+% test_grid=0;
+% end
+% DimIndex=DimIndex(perm_ind);
+% elseif test_grid
+% warndlg_uvmat('the dimension of the x coordinate variable should be 1','ERROR')
+% end
+% if isequal(DimIndex_x,DimIndex)
+% VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates
+% end
+% end
+%
+% %defined the selected sub-field SubField
+% SubField.ListGlobalAttribute{1}='InputFile';
+% SubField.InputFile=get(handles.inputfile,'String');
+% SubField.ListVarName=Field.ListVarName(VarIndex_tot);
+% VarDimIndex=Field.VarDimIndex;
+%
+% for ivar=VarIndex.u
+% VarAttribute{ivar}.Role='vector_x';
+% if test_grid
+% VarDimIndex{ivar}=DimIndex; %permute dimensions
+% end
+% end
+% for ivar=VarIndex.v
+% VarAttribute{ivar}.Role='vector_y';
+% if test_grid
+% VarDimIndex{ivar}=DimIndex;%permute dimensions
+% end
+% end
+% for ivar=VarIndex.A
+% if test_grid
+% VarDimIndex{ivar}=DimIndex;%permute dimensions
+% end
+% if isempty(iuA)
+% VarAttribute{ivar}.Role='scalar';%Role =scalar
+% else
+% VarAttribute=[VarAttribute VarAttribute{ivar}]; %duplicate the attribute for a new variable
+% nbattr=length(VarAttribute);
+% VarAttribute{nbattr}.Role='scalar';
+% end
+% end
+% SubField.VarDimIndex=VarDimIndex(VarIndex_tot);
+% SubField.VarAttribute=VarAttribute(VarIndex_tot);
+% % Field.SubListVarName=SubField.ListVarName;
+% % Field.SubVarDimIndex=SubField.VarDimIndex;
+% % Field.SubVarAttribute=SubField.VarAttribute;
+% set(hselect_field,'UserData',Field);
+% % copy variables on SubField
+% for ivar=1:length(VarIndex_tot)
+% VarName=Field.ListVarName{VarIndex_tot(ivar)};
+% eval(['SubField.' VarName '=Field.' VarName ';'])
+% end
+% if test_grid
+% for ivar=1:length(VarIndex.u)
+% VarName=Field.ListVarName{VarIndex.u(ivar)};
+% eval(['SubField.' VarName '=permute(SubField.' VarName ',perm_ind);'])
+% end
+%
+% for ivar=1:length(VarIndex.v)
+% VarName=Field.ListVarName{VarIndex.v(ivar)};
+% eval(['SubField.' VarName '=permute(SubField.' VarName ',perm_ind);'])
+% end
+% for ivar=1:length(VarIndex.A)
+% VarName=Field.ListVarName{VarIndex.A(ivar)};
+% eval(['SubField.' VarName '=permute(SubField.' VarName ',perm_ind);'])
+% end
+% end
+% if ~isempty(iuA)
+% VarName= ['A' Field.ListVarName{iuA}]; %create the new variable to distinguish the scaler form the velocity component
+% SubField.ListVarName=[SubField.ListVarName VarName];
+% SubField.VarDimIndex=[SubField.VarDimIndex Field.VarDimIndex(iuA)];
+% eval(['SubField.' VarName '=Field.' Field.ListVarName{iuA} ';'])
+% end
+% % dimension of SubField
+% if test_scalar|test_vector
+% % SubField.NbDim=2;
+% SubField.InputFile=get(handles.inputfile,'String');
+% SubField.get_field_handle=hselect_field;
+% else
+% SubField.NbDim=1;
+% end
+%
+% list_fig=get(handles.list_fig,'String');
+% fig_index=get(handles.list_fig,'Value');
+% %ACTION on SubField
+% index=get(handles.ACTION,'Value');
+
+%
+% % if (test_scalar|test_vector)
+% % RUN_fig='uvmat';
+% % elseif iscell(list_fig)
+% testuvmat=0;
+% if test_scalar|test_vector
+% [DimVarIndex,CellVarIndex,NbDim]=find_field_indices(SubField);
+% NbDim=max(NbDim);
+% if NbDim==3
+% testuvmat=1; %uvmat interface needed for 3D plots
+% end
+% end
+% if iscell(list_fig)
+% RUN_fig=list_fig{fig_index};
+% else
+% RUN_fig='new fig...';%new plotting axes must be created
+% end
+% if isequal(RUN_fig,'new fig...') & (test_scalar|test_vector)
+% RUN_fig='uvmat';%use uvmat for a new fig
+% end
+% if testuvmat
+% RUN_fig='uvmat';
+% end
+% if isequal(RUN_fig,'uvmat')
+%
+% huvmat=uvmat(SubField);
+% menu=update_menu(handles.list_fig,'uvmat');%add the selected fct to the menu
+% else
+% test_new=1;
+% if ~isequal(RUN_fig,'new fig...')
+% sep=regexp(RUN_fig,'_')%look for subaxes in a fig
+% if isempty(sep)
+% axe_index=1;
+% else
+% axe_index=str2num(RUN_fig(sep+1:end))
+% RUN_fig=RUN_fig([1:sep-1])
+% end
+% if ishandle(str2num(RUN_fig))
+% haxes=findobj(str2num(RUN_fig),'Type','axes')
+% for iaxe=1:length(haxes)
+% Tag=get(haxes(iaxe),'Tag');
+% if isequal(Tag,'Colorbar')|isequal(Tag,'legend')
+% iselect(iaxe)=0;
+% else
+% iselect(iaxe)=1;
+% end
+% end
+% haxes=haxes(find(iselect));
+% if length(haxes)>=axe_index
+% test_new=0
+% haxes=haxes(axe_index);
+% set(haxes,'NextPlot','add')
+% end
+% end
+% end
+% if test_new
+% hfig=figure;
+% haxes=axes;
+% menu=update_menu(handles.list_fig,num2str(hfig));%add the selected fct to the menu
+% end
+% RUN_field(SubField,haxes)
+% end
+% end
+% %Field.VarIndex=VarIndex; %save for use in uvmat
+% % set(hselect_field,'UserData',Field)
+
+
+%------------------------------------------------
+% --- Executes on button press in Plot_histo.
+%RUN global histograms
+%-------------------------------------------------
+function RUN_histo_Callback(hObject, eventdata, handles)
+% hObject handle to RUN (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+%time plots
+leg={};
+n=0;
+if (get(handles.cm_switch,'Value')==1)
+ Uval_p=Uval_cm;
+ Vval_p=Vval_cm;
+ Uhist_p=Uhist_cm;
+ Vhist_p=Vhist_cm;
+ xlab='velocity (cm/s)';
+else
+ Uval_p=Uval;
+ Vval_p=Vval;
+ Uhist_p=Uhist;
+ Vhist_p=Vhist;
+ xlab='velocity (pixels)';
+end
+if (get(handles.vector_y,'Value') == 1)
+ hhh=figure(2);
+ hold on
+ title([filebase ', ' strindex ', ' fieldtitle])
+ plot(Uval_p,Uhist_p,'b-')
+ n=n+1;
+ leg{n}='Uhist';
+ xlabel(xlab)
+end
+if (get(handles.Vhist_input,'Value') == 1)
+ hhh=figure(2);
+ hold on
+ title([filebase ', ' strindex ', ' fieldtitle])
+ plot(Vval_p,Vhist_p,'r-')
+ n=n+1;
+ leg{n}='Vhist';
+ xlabel(xlab);
+end
+if (get(handles.Chist_input,'Value') == 1)
+ hhhh=figure(3);
+ hold on
+ title([filebase ', ' strindex ', ' fieldtitle])
+ plot(Cval,Chist,'k-')
+ leg{1}='Chist';
+end
+% hold off
+grid on
+legend(leg);
+
+% %-------------------------------------------------------------
+% % --- Executes on button press in Save_input.
+% function Save_input_Callback(hObject, eventdata, handles)
+% list_str=get(handles.abscissa,'String');
+% val=get(handles.abscissa,'Value');
+% var=list_str{val};
+% hselect_field=get(handles.Save_input,'parent')
+% set(hselect_field,'UserData',var);
+% set(hselect_field,'Tag','idle')
+
+%
+% %-------------------------------------------------------------
+% % --- Executes on button press in save_histo.
+% function save_histo_Callback(hObject, eventdata, handles)
+% global filebase
+%
+% pathstr = fileparts(filebase)
+% if (get(handles.Chist_input,'Value') == 1)
+% def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']};
+% else
+
+% def = {[pathstr pathstr(1) 'vel_histo.fig']};
+% end
+% prompt={'save figure(2) as'}
+% dlg_title = 'save figure';
+% num_lines= 1;
+% answer = inputdlg(prompt,dlg_title,num_lines,def)
+% saveas(2,answer{1})
+
+%
+% % --- Executes on selection change in spectrum.
+% function Field=FFT(Field)
+% 'TESTFFT'
+% Field
+% nbfield=length(Field.ListVarName);
+% if nbfield==0
+% warndlg_uvmat('no field selected for FFT','ERROR')
+% elseif nbfield>2
+% warndlg_uvmat('select only one field for FFT','ERROR')
+% end
+% if nbfield==2
+% % list_fields=get(handles.spectrum,'String');% list menu fields
+% % index_fields=get(handles.spectrum,'Value');% selected string index
+% % fields= list_fields{index_fields(1)}; % selected action
+% % func=eval(fields);
+% dtmin=min(diff(time));%time step
+% time1=time(1);timend=time(end);
+% timeq=[time1:dtmin:timend];%equal time spacing
+% funcinterp=interp1(time,func,timeq); %interpolated func
+% else
+% varname=Field.ListVarName{1};
+% eval(['funcinterp=Field.' varname ';'])
+% end
+% np=length(funcinterp);
+% funcinterp=funcinterp-sum(funcinterp)/np; %substract mean
+% fourier=fft(funcinterp);%take fft (complex)
+% spec=abs(fourier).*abs(fourier);% take sqare of the modulus
+% spec=spec([1:floor(np/2)]);%keep only the first half (the other is symmetric)
+% eval(['Field.' varname '=spec;'])
+% Field
+% % dfreq=1/(time(end)-time(1));%frequency interval
+% % freq=[0:dfreq:(floor(np/2)-1)*dfreq];
+% % figure(1)
+% % hold on
+% % RUN(freq,spec)
+% % xlabel('frequency (Hz)')
+% % ylabel('spectral intensity')
+% % title(['spectrum of' fields]);
+% % grid on
+
+
+
+
+
+%%-------------------------------------------------------
+% --- Executes on button press in peaklocking.
+%-------------------------------------------------
+function peaklocking(handles)
+%evaluation of peacklocking errors
+%use splinhist: give spline coeff cc for a smooth histo (call spline4)
+%use histsmooth(x,cc): calculate the smooth histo for any value x
+%use histder(x,cc): calculate the derivative of the smooth histo
+global hfig1 hfig2 hfig3
+global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval
+global xval xerror yval yerror
+
+set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface
+set(handles.Vhist_input,'Value',1)
+set(handles.cm_switch,'Value',0) % put the switch to 'pixel'
+
+%adjust the extremal values of the histogram in U with respect to integer
+%values
+minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins
+maximU=round(max(Uval)-0.5)+0.5;
+minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval
+maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value
+nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below
+nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above
+Uval=[minim_fin:(1/nbb):maxim_fin];
+histu_min=zeros(nb_bin_min,1);
+histu_max=zeros(nb_bin_max,1);
+Uhist=[histu_min; Uhist ;histu_max]; % column vector
+
+%adjust the extremal values of the histogram in V
+minimV=round(min(Vval-0.5)+0.5);
+maximV=round(max(Vval-0.5)+0.5);
+minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval
+maxim_fin=maximV+0.5-1/(2*nbb); % last integer value
+nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below
+nb_bin_max=round((maxim_fin -max(Vval))*nbb);
+Vval=[minim_fin:(1/nbb):maxim_fin];
+histu_min=zeros(nb_bin_min,1);
+histu_max=zeros(nb_bin_max,1);
+Vhist=[histu_min; Vhist ;histu_max]; % column vector
+
+% RUN_histo_Callback(hObject, eventdata, handles)
+% %adjust the histogram to integer values:
+
+%histoU and V
+[Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist);
+[Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist);
+
+% selection of value ranges such that histo>=10 (enough statistics)
+Uval_ind=find(Uhist>=10);
+ind_min=min(Uval_ind);
+ind_max=max(Uval_ind);
+U_min=Uval(ind_min);% minimum allowed value
+U_max=Uval(ind_max);%maximum allowed value
+
+% selection of value ranges such that histo>=10 (enough statistics)
+Vval_ind=find(Vhist>=10);
+ind_min=min(Vval_ind);
+ind_max=max(Vval_ind);
+V_min=Vval(ind_min);% minimum allowed value
+V_max=Vval(ind_max);%maximum allowed value
+
+figure(4)% plot U histogram with smoothed one
+plot(Uval,Uhist,'b')
+grid on
+hold on
+plot(Uval,Uhistinter,'r');
+hold off
+
+figure(5)% plot V histogram with smoothed one
+plot(Vval,Vhist,'b')
+grid on
+hold on
+plot(Vval,Vhistinter,'r');
+hold off
+
+figure(6)% plot pixel error in two subplots
+hfig4=subplot(2,1,1);
+hfig5=subplot(2,1,2);
+axes(hfig4)
+plot(xval,xerror)
+axis([U_min U_max -0.4 0.4])
+xlabel('velocity u (pix)')
+ylabel('peaklocking error (pix)')
+grid on
+axes(hfig5)
+plot(yval,yerror)
+axis([V_min V_max -0.4 0.4]);
+xlabel('velocity v (pix)')
+ylabel('peaklocking error (pix)')
+grid on
+
+
+% ------------------------------------------------------------------
+function variables_Callback(hObject, eventdata, handles)
+Tabchar={''};%default
+Tabcell=[];
+hselect_field=get(handles.variables,'parent');
+Field=get(hselect_field,'UserData');
+index=get(handles.variables,'Value');%index in the list 'variables'
+if isequal(index,1)
+ set(handles.attributes_txt,'String','global attributes')
+% list global attribute names and values if index=1 (blank variable display) is selected
+ if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
+ for iline=1:length(Field.ListGlobalAttribute)
+ Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
+ if isfield(Field, Field.ListGlobalAttribute{iline})
+ eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
+ if ischar(val);
+ Tabcell{iline,2}=val;
+ else
+ Tabcell{iline,2}=num2str(val);
+ end
+ end
+ end
+ Tabchar=cell2tab(Tabcell,'=');
+ end
+else
+%list attribute names and values associated to the variable # injdex-1
+ list_var=get(handles.variables,'String');
+ var_select=list_var{index};
+ set(handles.attributes_txt,'String', ['attributes of ' var_select])
+ if isfield(Field,'VarAttribute')& length(Field.VarAttribute)>=index-1
+% nbline=0;
+ VarAttr=Field.VarAttribute{index-1};
+ if isstruct(VarAttr)
+ attr_list=fieldnames(VarAttr);
+ for iline=1:length(attr_list)
+ Tabcell{iline,1}=attr_list{iline};
+ eval(['val=VarAttr.' attr_list{iline} ';'])
+ if ischar(val);
+ Tabcell{iline,2}=val;
+ else
+ Tabcell{iline,2}=num2str(val);
+ end
+ end
+ end
+ end
+
+end
+if ~isempty(Tabcell)
+ Tabchar=cell2tab(Tabcell,'=');
+ Tabchar=[{''};Tabchar];
+end
+set(handles.attributes,'String',Tabchar);
+
+% list_var=get(handles.dimensions,'String');
+% val=get(handles.dimensions,'Value');
+
+% update dimensions;
+if isfield(Field,'VarDimIndex')
+ Tabdim={};%default
+ if isequal(index,1)
+ dim_indices=1:length(Field.ListDimName);
+ set(handles.dimensions_txt,'String', 'dimensions')
+ else
+ dim_indices=Field.VarDimIndex{index-1};
+ set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
+ end
+ for iline=1:length(dim_indices)
+ Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
+ Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
+ end
+ Tabchar=cell2tab(Tabdim,'=');
+ Tabchar=[{''} ;Tabchar];
+ set(handles.dimensions,'String',Tabchar)
+end
+
+% --- Executes on button press in check_1Dplot.
+function check_1Dplot_Callback(hObject, eventdata, handles)
+val=get(handles.check_1Dplot,'Value');
+if isequal(val,0)
+ set(handles.Panel1Dplot,'Visible','off')
+% set(handles.scalar,'Visible','off')
+% set(handles.ordinate,'Max',2.0)%allow multiple ordinate input option
+% if isequal(get(handles.check_vector,'Value'),0);
+% set(handles.coord_z_vectors_scalar,'Visible','off')
+% end
+else
+ set(handles.Panel1Dplot,'Visible','on')
+% set(handles.scalar,'Visible','on')
+% val=get(handles.ordinate,'Value');
+% val=val(1);
+% set(handles.ordinate,'Value',val);%suppress multiple ordinates
+% set(handles.ordinate,'Max',1.0);%suppress multiple ordinate input option
+% set(handles.coord_z_vectors_scalar,'Visible','on')
+end
+
+% --- Executes on button press in check_scalar.
+function check_scalar_Callback(hObject, eventdata, handles)
+val=get(handles.check_scalar,'Value');
+if isequal(val,0)
+ set(handles.PanelScalar,'Visible','off')
+% set(handles.scalar,'Visible','off')
+% set(handles.ordinate,'Max',2.0)%allow multiple ordinate input option
+% if isequal(get(handles.check_vector,'Value'),0);
+% set(handles.coord_z_vectors_scalar,'Visible','off')
+% end
+else
+ set(handles.PanelScalar,'Visible','on')
+% set(handles.scalar,'Visible','on')
+% val=get(handles.ordinate,'Value');
+% val=val(1);
+% set(handles.ordinate,'Value',val);%suppress multiple ordinates
+% set(handles.ordinate,'Max',1.0);%suppress multiple ordinate input option
+% set(handles.coord_z_vectors_scalar,'Visible','on')
+end
+
+%---------------------------
+% --- Executes on button press in check_vector.
+function check_vector_Callback(hObject, eventdata, handles)
+val=get(handles.check_vector,'Value');
+if isequal(val,0)
+ set(handles.PanelVectors,'Visible','off')
+else
+ set(handles.PanelVectors,'Visible','on')
+end
+
+
+
+%-----------------------------
+function mouse_up_gui(ggg,eventdata,handles)
+if isequal(get(ggg,'SelectionType'),'alt')
+ message='';
+ global CurData
+ inputfield=get(handles.inputfile,'String');
+ if exist(inputfield,'file')
+ CurData=nc2struct(inputfield);
+ else
+ CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
+ end
+ %%%% TODO: put the matalb command window in front
+ evalin('base','global CurData')%make CurData global in the workspace
+ evalin('base','CurData') %display CurData in the workspace
+end
+
+%---------------------------------------------
+% --- Executes on selection change in ACTION.
+function ACTION_Callback(hObject, eventdata, handles)
+list_ACTION=get(handles.ACTION,'String');% list menu fields
+index_ACTION=get(handles.ACTION,'Value');% selected string index
+ACTION= list_ACTION{index_ACTION}; % selected string
+path_get_field=which('get_field');%path to series.m
+list_path=get(handles.ACTION,'UserData');
+nb_builtin=0;
+list_path
+if iscell(list_path)
+for ilist=1:length(list_path)
+ if isequal(list_path{ilist},path_get_field)
+ nb_builtin=nb_builtin+1;
+ else
+ break
+ end
+end
+end
+if nb_builtin==0% the path to get_field has been changed, reinitialize
+ get_field_OpeningFcn(hObject, eventdata, handles)
+ return
+end
+
+% add a new function to the menu
+if isequal(ACTION,'more...')
+ pathfct=fileparts(path_get_field);
+ browse_name=fullfile(path_get_field,'FIELD_FCT');
+ if length(list_path)>nb_builtin
+ browse_name=list_path{end};% initialize browser with the path of the last introduced function
+ end
+% fct_name='';
+% dir_perso=prefdir;
+% profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+% display(profil_perso)
+% if exist(profil_perso,'file')
+% h=load (profil_perso);
+% if isfield(h,'get_field_fct')
+% fct_name=h.get_field_fct;
+% end
+% else
+% path_to_uvmat=which ('uvmat');% check the path of uvmat
+% pathfct=fileparts(path_to_uvmat);
+% fct_name=fullfile(pathfct,'USR_FCT');%go to UVMAT/USR_FCT by default
+% end
+ [FileName, PathName] = uigetfile( ...
+ {'*.m', ' (*.m)';
+ '*.m', '.m files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',browse_name);
+ if length(FileName)<2
+ return
+ end
+ ext_fct=FileName(end-1:end);
+ if ~isequal(ext_fct,'.m')
+ msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
+ return
+ end
+ ACTION=FileName(1:end-2);% ACTION choice updated by the selected item
+
+ % insert the choice in the action menu
+ menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
+ index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
+ list_path{index_ACTION}=PathName;
+ if length(menu_str)>nb_builtin+5;
+ nbremove=length(menu_str)-nb_builtin-5;
+ menu_str(nb_builtin+1:end-5)=[];
+ list_path(nb_builtin+1:end-4)=[];
+ index_ACTION=index_ACTION-nbremove;
+ set(handles.ACTION,'Value',index_ACTION)
+ set(handles.ACTION,'String',menu_str)
+ end
+ list_path{index_ACTION}=PathName;
+ set(handles.ACTION,'UserData',list_path);
+ set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off')
+
+ %record the current menu in personal file profil_perso
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ for ilist=nb_builtin+1:length(menu_str)-1
+ get_field_fct{ilist-nb_builtin}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);
+ end
+ if exist(profil_perso,'file')
+ save(profil_perso,'get_field_fct','-append')
+ else
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ save(profil_perso,'get_field_fct','-V6')
+ else
+ save(profil_perso, 'get_field_fct')
+ end
+ end
+end
+
+ %check the current path to the selected function
+PathName=list_path{index_ACTION};%current recorded path
+if ~isequal(path_get_field,PathName)
+ CurrentPath=fileparts(which(ACTION));
+ if ~isequal(PathName,CurrentPath)
+ addpath(PathName)
+ errormsg=check_functions;
+ msgbox_uvmat('CONFIRMATION',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
+ end
+end
+set(handles.path_action,'String',PathName); %show the path to the senlected function
+
+
+% fct_name=fullfile(PathName, FileName);
+% if ~exist(fct_name,'file')
+% msgbox_uvmat('ERROR',['procesing fct ' fct_name ' not found'])
+% else
+% ACTION=FileName(1:end-2);%
+% menu=update_menu(handles.ACTION,ACTION);%add the selected fct to the menu
+% index_ACTION=get(handles.ACTION,'Value');% selected string index
+% list_path{index_ACTION}=PathName;
+% set(handles.ACTION,'UserData',list_path)
+% if exist(profil_perso,'file')
+% save (profil_perso,'coord_fct','-append'); %store the root name for future opening of uvmat
+% end
+% end
+%
+%
+% fileinput=FileName;%complete file name
+% eval(['spath=which(''' FileName ''');'])% current path to the function FileName
+% if ~isequal(spath,PathName)
+% addpath(PathName)
+% end
+% FileName([end-1:end])=[];
+%
+% % insert the choice in the action menu
+% nbACTION=length(list_ACTION);
+% index=0;
+% for ilist=1:nbACTION
+% if isequal(FileName,list_ACTION{ilist})%look for the selected scalar in the fields_input menu
+% index=ilist;%
+% end
+% end
+% if index==0
+% list_ACTION{nbACTION}=FileName; %put the chosen fct at the penultimate place in the fields_input menu
+% list_path{nbACTION}=PathName;
+% index=nbACTION;
+% list_ACTION{nbACTION+1}='more...';
+% set(handles.ACTION,'String',list_ACTION)
+% end
+% set(handles.ACTION,'Value',index);% store the selected scalar type
+% set(handles.ACTION,'UserData',list_path);
+% usr_defined_fct=fct_name;
+% nbmenu=length(list_ACTION);
+% nbadd=nbmenu-5;
+% ilist=0;
+% for imenu=nbmenu-min(4,nbadd):nbmenu-1
+% ilist=ilist+1;
+% fct_get_field{ilist,1}=list_ACTION{imenu};
+% fct_path_get_field{ilist}=list_path{imenu};
+% end
+% if exist(profil_perso,'file')
+% save(profil_perso,'usr_defined_fct','fct_get_field','fct_path_get_field','-append')
+% else
+% save(profil_perso,'usr_defined_fct','fct_get_field','fct_path_get_field','-V6')
+% end
+% end
+
+% %check the current path to the selected function
+% list_path
+% PathName=list_path{index_ACTION}
+% CurrentPath=fileparts(which(ACTION))
+% if ~isequal(PathName,CurrentPath)
+% addpath(PathName)
+% errormsg=check_functions;
+% msgbox_uvmat('WARNING',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
+% end
+% set(handles.path_action,'String',fullfile(PathName,' ')); %show the path to the senlected function
+
+%default setting for the visibility of the GUI elements*
+if ~isequal(ACTION,'PLOT')
+ varargout=feval(ACTION);% input list asked by the selected function
+ test_1Dplot=[];
+ test_scalar=[];
+ test_vector=[];
+ for ilist=1:length(varargout)-1
+ switch varargout{ilist}
+ %RootFile always visible
+ case 'check_1Dplot'
+ test_1Dplot=isequal(lower(varargout{ilist+1}),'y');
+ case 'check_scalar'
+ test_scalar=isequal(lower(varargout{ilist+1}),'y');
+ case 'check_vector'
+ test_vector=isequal(lower(varargout{ilist+1}),'y');
+ end
+ end
+ if test_1Dplot==0
+ set(handles.check_1Dplot,'Value',0);
+ end
+ if test_1Dplot==1
+ set(handles.check_1Dplot,'Value',1);
+ end
+ if test_scalar==0
+ set(handles.check_scalar,'Value',0);
+ end
+ if test_scalar==1
+ set(handles.check_scalar,'Value',1);
+ end
+ if test_vector==0
+ set(handles.check_vector,'Value',0);
+ end
+ if test_vector==1
+ set(handles.check_vector,'Value',1);
+ end
+ check_1Dplot_Callback(hObject, eventdata, handles)
+ check_scalar_Callback(hObject, eventdata, handles)
+ check_vector_Callback(hObject, eventdata, handles)
+end
+%
+% % --- Executes on selection change in menu_coord.
+% function menu_coord_Callback(hObject, eventdata, handles)
+% hget_field=get(handles.menu_coord,'parent');
+% menu=get(handles.menu_coord,'String');
+% ind_coord=get(handles.menu_coord,'Value');
+% coord_option=menu{ind_coord};
+% if isequal(coord_option,'more...');
+% fct_name='';
+% if exist('./TMP/current_usr_fct.mat','file')% if a file is found
+% h=load('./TMP/current_usr_fct.mat');
+% if isfield(h,'fct_name');
+% fct_name=h.fct_name;
+% end
+% end
+% prompt = {'Enter the name of the transform function'};
+% dlg_title = 'user defined transform';
+% num_lines= 1;
+% [FileName, PathName, filterindex] = uigetfile( ...
+% {'*.m', ' (*.m)';
+% '*.m', '.m files '; ...
+% '*.*', 'All Files (*.*)'}, ...
+% 'Pick a file', fct_name);
+% fct_name=fullfile(PathName,FileName);
+% addpath(PathName);%add the path to the selected fct
+% [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER
+% if ~exist(fct_name,'file')
+% warndlg_uvmat(['image procesing fct ' fct_name ' not found'],'WARNING')
+% else
+% transform=FileName(1:end-2);%
+% menu=update_menu(handles.menu_coord,transform);%add the selected fct to the menu
+% % set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu
+% save ('./TMP/current_usr_fct.mat','fct_name');
+% end
+% end
+
+% --- Executes on selection change in menu_coord.
+function HELP_Callback(hObject, eventdata, handles)
+path_to_uvmat=which ('uvmat');% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+else
+web([helpfile '#get_field'])
+end
+
+%-----------------------------------------------------
+% --- browse existing figures
+%-----------------------------------------------------
+function browse_fig(menu_handle)
+hh=findobj(allchild(0),'Type','figure');
+ilist=0;
+list={};
+for ifig=1:length(hh) %look for all existing figures
+ name=get(hh(ifig),'Name');
+ if ~isequal(name,'uvmat')%case of uvmat GUI
+% ilist=ilist+1;
+% list{ilist,1}='uvmat';
+% else %other figures
+ hchild=get(hh(ifig),'children');% look for axes contained in each figure
+ nbaxe=0;
+ for ichild=1:length(hchild)
+ Type=get(hchild(ichild),'Type');
+ Tag=get(hchild(ichild),'Tag');
+ if isequal(Type,'axes')
+ if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting
+ nbaxe=nbaxe+1;%count the existing axis
+ end
+ end
+ end
+ if nbaxe==1
+ ilist=ilist+1;%add a line in the list of axis
+ list{ilist,1}=num2str(hh(ifig));
+ elseif nbaxe>1
+ for iaxe=1:nbaxe
+ ilist=ilist+1;%add a line in the list of axis
+ list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)];
+ end
+ end
+ end
+end
+list=['new fig...';'uvmat';list];
+set(menu_handle,'Value',1)
+set(menu_handle,'String',list)
+
+
+%-----------------------------------------------------
+function list_fig_Callback(hObject, eventdata, handles)
+%-----------------------------------------------------
+list_fig=get(handles.list_fig,'String');
+fig_val=get(handles.list_fig,'Value');
+plot_fig=list_fig{fig_val};
+if isequal(plot_fig,'uvmat')
+ huvmat=findobj(allchild(0),'name','uvmat');
+ if ~isempty(huvmat)
+ uistack(huvmat,'top')
+ end
+elseif ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat')
+ sep=regexp(plot_fig,'_');
+ if ~isempty(sep)
+ plot_fig=plot_fig([1:sep-1]);
+ end
+ if ishandle(str2num(plot_fig))
+ figure(str2num(plot_fig))% display existing figure
+ else
+ browse_fig(handles.list_fig); %reset the current list of figures
+ end
+end
+
+
+%-------------------------------------------------
+% give index numbers of the strings str in the list ListvarName
+function VarIndex_y=name2index(cell_str,ListVarName)
+VarIndex_y=[];
+if ischar(cell_str)
+ for ivar=1:length(ListVarName)
+ varlist=ListVarName{ivar};
+ if isequal(varlist,cell_str)
+ VarIndex_y= ivar;
+ break
+ end
+ end
+elseif iscell(cell_str)
+ for isel=1:length(cell_str)
+ varsel=cell_str{isel};
+ for ivar=1:length(ListVarName)
+ varlist=ListVarName{ivar};
+ if isequal(varlist,varsel)
+ VarIndex_y=[VarIndex_y ivar];
+ end
+ end
+ end
+end
+
+% --------------------------------------------------------------------
+function MenuOpen_Callback(hObject, eventdata, handles)
+% hObject handle to MenuOpen (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function MenuExport_Callback(hObject, eventdata, handles)
+% hObject handle to MenuExport (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function MenuBrowse_Callback(hObject, eventdata, handles)
+
+oldfile=get(handles.inputfile,'String');
+testrootfile=0;
+testsubdir=0;
+if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
+ oldfile='';
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ if exist(profil_perso,'file')
+ h=load (profil_perso);
+ if isfield(h,'RootPath')
+ RootPath=h.RootPath;
+ end
+ if isfield(h,'SubDir')
+ SubDir=h.SubDir;
+ if ~isempty(SubDir)
+ testsubdir=1;
+ end
+ end
+ if isfield(h,'RootFile')
+ RootFile=h.RootFile;
+ if ~isempty(RootFile)
+ testrootfile=1;
+ end
+ end
+ end
+end
+if testrootfile
+ if ~testsubdir
+ oldfile=fullfile(RootPath,RootFile);
+ else
+ oldfile=fullfile(RootPath,SubDir,RootFile);
+ end
+end
+[FileName, PathName] = uigetfile( ...
+ {'*.nc', ' *.nc';...
+ '*.cdf', ' *.cdf';...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',oldfile);
+
+%global inputfile
+fileinput=[PathName FileName];%complete file name
+testblank=findstr(fileinput,' ');%look for blanks
+if ~isempty(testblank)
+ warndlg_uvmat(['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'],'ERROR')
+ return
+end
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
+set(handles.inputfile,'String',fileinput)
+inputfile_Callback(hObject, eventdata, handles)
+
+
+%update list of recent files in the menubar
+MenuFile_1=fileinput;
+MenuFile_2=get(handles.MenuFile_1,'Label');
+MenuFile_3=get(handles.MenuFile_2,'Label');
+MenuFile_4=get(handles.MenuFile_3,'Label');
+MenuFile_5=get(handles.MenuFile_4,'Label');
+set(handles.MenuFile_1,'Label',MenuFile_1)
+set(handles.MenuFile_2,'Label',MenuFile_2)
+set(handles.MenuFile_3,'Label',MenuFile_3)
+set(handles.MenuFile_4,'Label',MenuFile_4)
+set(handles.MenuFile_5,'Label',MenuFile_5)
+
+
+% %store input file in personal file uvmat_perso.mat
+% dir_perso=prefdir;
+% profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+% if exist(profil_perso,'file')
+% save (profil_perso,'RootPath','SubDir','RootFile','NomType', 'ext','-append'); %store the root name for future opening of uvmat
+% else
+% save (profil_perso,'RootPath','SubDir','RootFile','NomType', 'ext'); %store the root name for future opening of uvmat
+% end
+
+
+% --------------------------------------------------------------------
+function MenuFile_1_Callback(hObject, eventdata, handles)
+% hObject handle to MenuFile_1 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function MenuFile_2_Callback(hObject, eventdata, handles)
+% hObject handle to MenuFile_2 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function MenuFile_3_Callback(hObject, eventdata, handles)
+% hObject handle to MenuFile_3 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function MenuFile_4_Callback(hObject, eventdata, handles)
+% hObject handle to MenuFile_4 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function MenuFile_5_Callback(hObject, eventdata, handles)
+% hObject handle to MenuFile_5 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function ExportField_Callback(hObject, eventdata, handles)
+% hObject handle to ExportField (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+
Index: /trunk/src/get_plot_handles.m
===================================================================
--- /trunk/src/get_plot_handles.m (revision 2)
+++ /trunk/src/get_plot_handles.m (revision 2)
@@ -0,0 +1,73 @@
+%'get_plot_handles': list the handles of elements setting the plotting parameters in the uvmat interface
+%--------------------------------------------------------
+%function [PlotHandles]=get_plot_handles(handles)
+%
+% OUTPUT:
+% PlotHandles: structure containing the used to set plotting parameters
+% INPUT:
+% handles: structure of the handles of the graphic elements in the uvmat interface
+% -- TODO: needs to be replaced by a cell listing the element tags --
+
+function PlotHandles=get_plot_handles(handles)
+PlotHandles.auto_xy=handles.auto_xy;
+%For scalar field representation
+PlotHandles.MaxA=handles.MaxA;
+PlotHandles.MinA=handles.MinA;
+PlotHandles.AutoScal=handles.AutoScal;
+PlotHandles.BW=handles.BW;
+PlotHandles.Contours=handles.Contours;
+PlotHandles.IncrA=handles.IncrA;
+PlotHandles.SCALAR_title=handles.SCALAR_title;
+PlotHandles.min_title=handles.min_title;
+PlotHandles.max_title=handles.max_title;
+PlotHandles.frame_scal=handles.frame_scal;
+PlotHandles.npx=handles.npx;
+PlotHandles.npy=handles.npy;
+PlotHandles.npx_title=handles.npx_title;
+PlotHandles.npy_title=handles.npy_title;
+
+%For vector field representation
+PlotHandles.frame_vect=handles.frame_vect;
+PlotHandles.VECT_title=handles.VECT_title;
+PlotHandles.VecScale=handles.VecScale;
+PlotHandles.AutoVec=handles.AutoVec;
+PlotHandles.HideFalse=handles.HideFalse;
+PlotHandles.HideWarning=handles.HideWarning;
+PlotHandles.record=handles.record;
+PlotHandles.col_vec=handles.col_vec;
+PlotHandles.Color_title=handles.Color_title;
+PlotHandles.color_code=handles.color_code;
+PlotHandles.colcode1=handles.colcode1;
+PlotHandles.colcode2=handles.colcode2;
+PlotHandles.vec_col_bar=handles.vec_col_bar;
+PlotHandles.slider1=handles.slider1;
+PlotHandles.slider2=handles.slider2;
+PlotHandles.max_vec=handles.max_vec;
+PlotHandles.min_vec=handles.min_vec;
+PlotHandles.scale_title=handles.scale_title;
+PlotHandles.AutoVecColor=handles.AutoVecColor;
+PlotHandles.decimate4=handles.decimate4;
+PlotHandles.min_C_title=handles.min_C_title;
+PlotHandles.max_C_title=handles.max_C_title;
+PlotHandles.MenuVectors=handles.MenuVectors;
+PlotHandles.MenuEditVectors=handles.MenuEditVectors;
+PlotHandles.edit_vect=handles.edit_vect;
+%menu for the choice of the current plotting axes
+%PlotHandles.MenuAxes=handles.MenuAxes;
+
+%handles for move_mouse
+PlotHandles.mouse_coord=handles.mouse_coord;
+% PlotHandles.POINTS=handles.POINTS;
+% PlotHandles.LINE=handles.LINE;
+% PlotHandles.PLANE=handles.PLANE;
+% PlotHandles.PATCH=handles.PATCH;
+PlotHandles.cal=handles.cal;
+%PlotHandles.makemask=handles.makemask;
+PlotHandles.edit=handles.edit;
+PlotHandles.text_display_1=handles.text_display_1;
+PlotHandles.text_display_2=handles.text_display_2;
+PlotHandles.text_display_3=handles.text_display_3;
+PlotHandles.text_display_4=handles.text_display_4;
+
+%handles for mouse_up
+PlotHandles.zoom=handles.zoom;
Index: /trunk/src/griddata_uvmat.m
===================================================================
--- /trunk/src/griddata_uvmat.m (revision 2)
+++ /trunk/src/griddata_uvmat.m (revision 2)
@@ -0,0 +1,12 @@
+%'griddata_uvmat': function griddata_uvmat(vec2_X,vec2_Y,vec2_U,vec_X,vec_Y,'linear')
+%adapt the input of the matlab function griddata to the appropriate version of Matlab
+function ZI = griddata_uvmat(X,Y,Z,XI,YI)
+txt=ver;
+Release=txt(1).Release;
+relnumb=str2num(Release(3:4));
+if relnumb >= 14
+ ZI=griddata(X,Y,Z,XI,YI,'linear',{'QJ'});
+else
+ ZI=griddata(X,Y,Z,XI,YI,'linear');
+end
+
Index: /trunk/src/hist_update.m
===================================================================
--- /trunk/src/hist_update.m (revision 2)
+++ /trunk/src/hist_update.m (revision 2)
@@ -0,0 +1,54 @@
+%'hist_update': update of a current global histogram by inclusion of a new field
+%------------------------------------------------------------------------
+%[val,HIST]=hist_update(val,HIST,C,dC)
+%
+% OUTPUT:
+% val: vector of field values at which the histogram is determined (middle of bins)
+% HIST(:,icolor): nbre of occurence of the field value in the bins whose middle is given by val
+% can be a column vector, same size as val, or a matrix with three columns, for color images
+%
+% INPUT:
+% val: existing field values from the current histogram, =[] if there is no current histogram
+% HIST(:,icolor): current histogram, =[] if there is none
+% can be a column vector (icolor=1), same size as val, or a matrix with three columns, for color images
+% C(:,icolor): vector representing the current field values
+% can be a column vector (icolor=1), or a matrix with three columns, for color images
+% dC: width of the new bins extending val to account for the new field.
+
+function [val,HIST]=hist_update(val,HIST,C,dC)
+
+valplus=[];valminus=[];
+HISTplus=[];HISTminus=[];
+if isempty(HIST)
+ HIST=0;
+end
+siz=size(C);nbfields=siz(2);
+C=double(C);
+valmin=min(val);
+valmax=max(val);
+Cmin=min(min(C)); Cmax=max(max(C));
+if isempty(val)%no current histogram
+ val=[Cmin-dC/2:dC:Cmax+dC/2];
+else %extending the current histogram beyond its maximum value
+ if Cmax>=valmax+dC/2;
+ valplus=[valmax+dC:dC:Cmax+dC/2];% we extend the values val
+ HISTplus=zeros(length(valplus),nbfields);% we put histogram to zero at these values
+ end
+ %extending the current histogram below its minimum value
+ if Cmin<=valmin-dC/2;
+ valminus=[valmin-dC:-dC:Cmin-dC/2];% we extend the values val
+ valminus=sort(valminus);% we reverse the order
+ HISTminus=zeros(length(valminus),nbfields);% we put histogram to zero at these values
+ end
+ val=[valminus val valplus];
+end
+HIST=[HISTminus;HIST;HISTplus];
+if nbfields==1
+ histC=(hist(C,val))';% initiate the global histogram
+elseif nbfields==3
+ HIST1=(hist(C(:,1),val))';
+ HIST2=(hist(C(:,2),val))';
+ HIST3=(hist(C(:,3),val))';
+ histC=[HIST1 HIST2 HIST3];
+end
+HIST=HIST+histC;
Index: /trunk/src/imadoc2struct.m
===================================================================
--- /trunk/src/imadoc2struct.m (revision 2)
+++ /trunk/src/imadoc2struct.m (revision 2)
@@ -0,0 +1,250 @@
+%'imadoc2struct': reads the xml file for image documentation
+%
+%function [s,errormsg]=imadoc2struct(ImaDoc)
+%--------------------------------------------------------
+% OUTPUT:
+% s: structure representing ImaDoc
+% s.Heading: information about the data hierarchical structure
+% s.Time: matrix of times
+% s.TimeUnit
+% s.GeometryCalib: substructure containing the parameters for geometric calibration
+% errormsg: error message
+%
+% INPUT:
+% ImaDoc: full name of the xml input file with head key ImaDoc
+%function [s,error,Heading,nom_type_ima,ext_ima,abs_time,TimeUnit,mode,NbSlice]=imadoc2struct(ImaDoc)
+function [s,errormsg]=imadoc2struct(ImaDoc)
+
+errormsg=[];%default
+s.Heading=[];%default
+s.Time=[]; %default
+s.TimeUnit=[]; %default
+s.GeometryCalib=[];
+nom_type_ima=[];%default
+ext_ima=[];%default
+% abs_time=[];%initiation
+% GeometryCalib.CoordUnit='cm';%default
+mode=[]; %default
+NbSlice=1;%default
+npx=[];%default
+npy=[];%default
+% GeometryCalib.Pxcmx=1;
+% GeometryCalib.Pxcmy=1;
+% GeometryCalib=[];
+NbDtj=1;
+tsai=[];%default
+% if ~exist('testime','var')
+% testime=1;%default
+
+if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
+try
+ t=xmltree(ImaDoc);
+catch
+ errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
+ display(errormsg);
+ return
+end
+
+uid_root=find(t,'/ImaDoc');
+if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
+
+%Heading
+uid_Heading=find(t,'/ImaDoc/Heading');
+if ~isempty(uid_Heading),
+ uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
+ uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
+ uid_Device=find(t,'/ImaDoc/Heading/Device');
+ uid_Record=find(t,'/ImaDoc/Heading/Record');
+ uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
+ s.Heading.Campaign=get(t,children(t,uid_Campaign),'value');
+ s.Heading.Experiment=get(t,children(t,uid_Exp),'value');
+ s.Heading.Device=get(t,children(t,uid_Device),'value');
+ if ~isempty(uid_Record)
+ s.Heading.Record=get(t,children(t,uid_Record),'value');
+ end
+ s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
+ FirstImage=s.Heading.ImageName;
+ if ~isempty(FirstImage)
+ [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type_ima]=name2display(FirstImage);
+ end
+end
+
+%Camera
+uid_Camera=find(t,'/ImaDoc/Camera');
+if ~isempty(uid_Camera)
+ uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
+ if ~isempty(uid_ImageSize);
+ ImageSize=get(t,children(t,uid_ImageSize),'value');
+ xindex=findstr(ImageSize,'x');
+ if length(xindex)>=2
+ npx=str2num(ImageSize(1:xindex(1)-1));
+ npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
+ end
+ end
+ uid_NbSlice=find(t,'/ImaDoc/Camera/NbSlice');
+ if ~isempty(uid_NbSlice)
+ NbSlice=str2num(get(t,children(t,uid_NbSlice),'value'));
+ if isempty(NbSlice),NbSlice=1;end; %default
+ end
+ uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
+ if ~isempty(uid_TimeUnit)
+ s.TimeUnit=get(t,children(t,uid_TimeUnit),'value');
+ end
+ uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
+ if ~isempty(uid_BurstTiming)
+ for k=1:length(uid_BurstTiming)
+ Dtj=[];%default
+ NbDtj=1;%default
+ subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
+ % reading Dtk
+ Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1);
+ Dtj=get_value(subt,'/BurstTiming/Dtj',[]);
+ Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
+ NbDtj=get_value(subt,'/BurstTiming/NbDtj',1);
+ Dti=get_value(subt,'/BurstTiming/Dti',[]);
+ Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
+ NbDti=get_value(subt,'/BurstTiming/NbDti',1);
+ Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
+ if ~isempty(Dti)
+ Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
+ Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals Dti
+ end
+ if ~isempty(Dtj)
+ Dtj=reshape(Dtj'*ones(1,NbDtj),1,NbDtj*numel(Dtj)); %concatene Dti vector NbDti times
+ Dtj=[0 Dtj];
+% Time_val'
+% ones(1,numel(Dtj))
+% ones(numel(Time_val'),1)
+% cumsum(Dtj)
+ Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
+ end
+ % reading Dtk
+ Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
+ NbDtk=get_value(subt,'/BurstTiming/NbDtk',1)
+ if isempty(Dtk)
+ s.Time=[s.Time;Time_val];
+ else
+ for kblock=1:NbDtk+1
+ Time_val=Time_val+(kblock-1)*Dtk;
+ s.Time=[s.Time;Time_val];
+ end
+ end
+ end
+ end
+ if size(s.Time,1)==1
+ s.Time=(s.Time)'; %change vector into column
+ end
+end
+
+%read calibration
+uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
+if ~isempty(uid_GeometryCalib)
+ if length(uid_GeometryCalib)>1
+ error=['More than one GeometryCalib in ' filecivxml];
+ return
+ end
+ subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
+ cont=get(subt,1,'contents');
+ if ~isempty(cont)
+ uid_pixcmx=find(subt,'/GeometryCalib/Pxcmx');
+ uid_pixcmy=find(subt,'/GeometryCalib/Pxcmy');
+ if ~isempty(uid_pixcmx) & ~isempty(uid_pixcmy)%NON UTILISE
+ pixcmx=str2num(get(subt,children(subt,uid_pixcmx),'value'));
+ if isempty(pixcmx),pixcmx=1;end; %default
+ pixcmy=str2num(get(subt,children(subt,uid_pixcmy),'value'));
+ if isempty(pixcmy),pixcmy=1;end; %default
+ tsai.Pxcmx=pixcmx;
+ tsai.Pxcmy=pixcmy;
+ end
+ %default values:
+ tsai.f=1;
+ tsai.dpx=1;
+ tsai.dpy=1;
+ tsai.sx=1;
+ tsai.Cx=0;
+ tsai.Cy=0;
+ tsai.Tz=1;
+ tsai.Tx=0;
+ tsai.Ty=0;
+ tsai.R=[1 0 0; 0 1 0; 0 0 0];
+ tsai.kappa1=0;
+ uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
+ if ~isempty(uid_CoordUnit)
+ tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
+ end
+ uid_focal=find(subt,'/GeometryCalib/focal');
+ uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
+ uid_sx=find(subt,'/GeometryCalib/sx');
+ uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
+ uid_kappa1=find(subt,'/GeometryCalib/kappa1');
+ uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
+ uid_R=find(subt,'/GeometryCalib/R');
+ if ~isempty(uid_focal) & ~isempty(uid_dpx_dpy) & ~isempty(uid_Cx_Cy)
+ tsai.f=str2num(get(subt,children(subt,uid_focal),'value'));
+ dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
+ tsai.dpx=dpx_dpy(1);
+ tsai.dpy=dpx_dpy(2);
+ if ~isempty(uid_sx)
+ tsai.sx=str2num(get(subt,children(subt,uid_sx),'value'));
+ end
+ Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
+ tsai.Cx=Cx_Cy(1);
+ tsai.Cy=Cx_Cy(2);
+ end
+ if ~isempty(uid_Tx_Ty_Tz)
+ Tx_Ty_T_char=get(subt,children(subt,uid_Tx_Ty_Tz),'value');
+ Tx_Ty_Tz=str2num(Tx_Ty_T_char);
+ tsai.Tx=Tx_Ty_Tz(1);
+ tsai.Ty=Tx_Ty_Tz(2);
+ tsai.Tz=Tx_Ty_Tz(3);
+ end
+ if ~isempty(uid_R)
+ RR=get(subt,children(subt,uid_R),'value');
+ if length(RR)==3
+ tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
+ end
+ end
+ if ~isempty(uid_kappa1)
+ tsai.kappa1=str2num(get(subt,children(subt,uid_kappa1),'value'));
+ end
+ %look for laser plane definitions
+ uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
+ uid_Pos=find(subt,'/GeometryCalib/PlanePos');
+ if ~isempty(uid_Angle)
+ tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
+ end
+ if ~isempty(uid_Pos)
+ for j=1:length(uid_Pos)
+ tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
+ end
+ end
+ s.GeometryCalib=tsai;
+ end
+end
+
+%--------------------------------------------------
+% read an xml element
+function val=get_value(t,label,default)
+%--------------------------------------------------
+val=default;
+uid=find(t,label);%find the element iud(s)
+if ~isempty(uid)
+ uid_child=children(t,uid);
+ if ~isempty(uid_child)
+ data=get(t,uid_child,'type');
+ if iscell(data)
+ for icell=1:numel(data)
+ val_read=str2num(get(t,uid_child(icell),'value'));
+ if ~isempty(val_read)
+ val(icell)=val_read;
+ end
+ end
+ val=val';
+ else
+ val_read=str2num(get(t,uid_child,'value'));
+ if ~isempty(val_read)
+ val=val_read;
+ end
+ end
+ end
+end
Index: /trunk/src/interp2_uvmat.m
===================================================================
--- /trunk/src/interp2_uvmat.m (revision 2)
+++ /trunk/src/interp2_uvmat.m (revision 2)
@@ -0,0 +1,25 @@
+% A matrix (npy,npx) to interpolate
+%XIMA: matrix of non-integer x index values (npY,npX)
+%YIMA: matrix of non-integer y index values (npY,npX), (with the same size as XIMA)
+function A_out=interp2_uvmat(A,XIMA,YIMA)
+npx=size(A,2);
+npy=size(A,1);
+npX=size(XIMA,2);
+npY=size(XIMA,1)
+XIMA=reshape(XIMA,1,npX*npY)+0.5;%indices corresponding to XIMA, reshaped in a matlab vector
+YIMA=reshape(YIMA,1,npX*npY)+0.5;%indices corresponding to XIMA, reshaped in a matlab vector
+X_delta=XIMA-floor(XIMA);%distance to the closest integer value
+XIMA=floor(XIMA);%integer x index on the image
+Y_delta=YIMA-floor(YIMA);%distance to the closest integer value
+YIMA=floor(YIMA);%integer x index on the image
+flagin=(XIMA>=1 & XIMA<=npx-1 & YIMA >=1 & YIMA<=npy-1);%flagin=1 inside the original image
+ind_in=find(flagin);%list of indices of XIndex for valid values of image indices (inside the original image)
+ind_out=find(~flagin);
+vec_A=double(reshape(A(:,:,1),1,npx*npy));%reshape the original image as a Matlab image vector
+ICOMB=((XIMA-1)*npy+(npy+1-YIMA));%determine the indices in the image Matlab vector corresponding to XIMA and YIMA
+ICOMB=ICOMB(flagin);%selection of the valid indices
+X_delta=X_delta(ind_in);
+Y_delta=Y_delta(ind_in);
+A_out(ind_in)=(1-Y_delta).*(1-X_delta).*vec_A(ICOMB)+Y_delta.*(1-X_delta).*vec_A(ICOMB-1)+X_delta.*(1-Y_delta).*vec_A(ICOMB+npy)+X_delta.*Y_delta.*vec_A(ICOMB+npy-1);
+A_out(ind_out)=zeros(size(ind_out));
+A_out=reshape(A_out,npY,npX);%interpolated image
Index: /trunk/src/keyboard_callback.m
===================================================================
--- /trunk/src/keyboard_callback.m (revision 2)
+++ /trunk/src/keyboard_callback.m (revision 2)
@@ -0,0 +1,51 @@
+%'keyboard_callback:' function activated when a key is pressed on the keyboard
+%-----------------------------------
+function keyboard_callback(hObject,eventdata,handleshaxes)
+xx=double(get(hObject,'CurrentCharacter')); %get the keyboard character
+cur_axes=get(gcbf,'CurrentAxes');
+if ~isempty(cur_axes)
+ xlimit=get(cur_axes,'XLim');
+ ylimit=get(cur_axes,'Ylim');
+ dx=(xlimit(2)-xlimit(1))/10;
+ dy=(ylimit(2)-ylimit(1))/10;
+
+ if isequal(xx,29)%move arrow right
+ xlimit=xlimit+dx;
+ elseif isequal(xx,28)%move arrow left
+ xlimit=xlimit-dx;
+ elseif isequal(xx,30)%move arrow up
+ ylimit=ylimit+dy;
+ elseif isequal(xx,31)%move arrow down
+ ylimit=ylimit-dy;
+ end
+ set(cur_axes,'XLim',xlimit)
+ set(cur_axes,'YLim',ylimit)
+end
+if ismember(xx,[8 127]) %if the delete or suppr key is pressed, delete the current object
+ currentobject=gco;
+ huvmat=findobj(allchild(0),'Name','uvmat');
+% UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
+ hlist_object=findobj(huvmat,'Tag','list_object');
+ ObjIndex=get(hlist_object,'Value');
+ if ObjIndex>1
+ delete_object(ObjIndex)
+ end
+ if ishandle(currentobject)
+ tag=get(currentobject,'Tag');%tag of the current selected object
+ if isequal(tag,'proj_object')
+ delete_object(currentobject)
+ end
+ end
+elseif isequal(xx,112)% key 'p'
+ uvmat('runplus_Callback',hObject,eventdata,handleshaxes)
+elseif isequal(xx,109)% key 'm'
+ uvmat('runmin_Callback',hObject,eventdata,handleshaxes)
+end
+
+AxeData=get(cur_axes,'UserData');
+if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
+ hparentrect=AxeData.ParentRect;
+ rect([1 2])=[xlimit(1) ylimit(1)];
+ rect([3 4])=[xlimit(2)-xlimit(1) ylimit(2)-ylimit(1)];
+ set(hparentrect,'Position',rect)
+end
Index: /trunk/src/mouse_down.m
===================================================================
--- /trunk/src/mouse_down.m (revision 2)
+++ /trunk/src/mouse_down.m (revision 2)
@@ -0,0 +1,343 @@
+%'mouse_down': function activated when the mouse button is pressed on a figure (callback for 'WindowButtonDownFcn'
+%--------------------------------------------------------------
+% xy=mouse_down(hObject,eventdata)
+% activated by the command:
+% set(hObject,'WindowButtonDownFcn',{'mouse_down'}),
+% where hObject is the handle of the figure
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function xy=mouse_down(hObject,eventdata)
+testzoom=0;%default
+MouseAction='none'; %default
+huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle which controls theoption of mouse action
+if ~isempty(huvmat)
+ hhuvmat=guidata(huvmat);%handles of elements in uvmat
+ UvData=get(huvmat,'UserData');
+ testzoom=get(hhuvmat.zoom,'Value');% get the mouse action from the uvmat GUI: options:
+ if isfield(UvData,'MouseAction')
+ MouseAction=UvData.MouseAction;% get the mouse action from the uvmat GUI: options:
+ end
+end
+test_create=~testzoom && (isequal(MouseAction,'create_object') || isequal(MouseAction,'create_mask'));
+%test_cal=get(handles.cal,'Value');
+test_cal=isequal(MouseAction,'calib');
+handles_coord=findobj(huvmat,'Tag','menu_coord');
+menu_coord=get(handles_coord,'String');
+coord_choice=get(handles_coord,'Value');
+coord_type=menu_coord{coord_choice};
+test_edit=isequal(MouseAction,'edit_object');
+test_edit_vect=isequal(MouseAction,'edit_vect');
+xdisplay=[];%default
+ydisplay=[];%default
+haxes=[];
+AxeData=[];%default
+
+%edit an existing point or line if found
+hcurrentobject=gco;% current object handle (selected by the mouse)
+hcurrentfig=gcbo;% current figure handle
+tag_obj=get(gco,'Tag');
+xy=[];%default
+xy_fig=get(hcurrentfig,'CurrentPoint');% current point of the current figure (gcbo)
+hchild=get(hcurrentfig,'Children');%handles of all objects in the current figure
+% loop on all the objects in the current figure (selected by the last mouse click)
+for ichild=1:length(hchild)
+ obj_pos=get(hchild(ichild),'Position');%position of the object
+ if xy_fig(1) >=obj_pos(1) & xy_fig(2) >= obj_pos(2)& xy_fig(1) <=obj_pos(1)+obj_pos(3) & xy_fig(2) <= obj_pos(2)+obj_pos(4);
+ htype=get(hchild(ichild),'Type');%type of object child of the current figure
+ %if the mouse is over an axis, look at the data
+ if isequal(htype,'axes')
+ haxes=hchild(ichild);
+ xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+ AxeData=get(haxes,'UserData');% data attached to the axis
+ AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin
+ if ~isequal(tag_obj,'proj_object') & ~test_create
+ x_mouse=xy(1,1);%default
+ y_mouse=xy(1,2);%default
+ u_mouse=[];
+ v_mouse=[];
+ w_mouse=[];
+ A_mouse=[];
+ c_text=[];
+ f_text=[];
+ ff_text=[];
+ ivec=[];
+ if isfield(AxeData,'X') & isfield(AxeData,'Y') & isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis
+ flag_vec=(AxeData.X<(xy(1,1)+AxeData.Mesh/4) & AxeData.X>(xy(1,1)-AxeData.Mesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse
+ (AxeData.Y<(xy(1,2)+AxeData.Mesh/4) & AxeData.Y>(xy(1,2)-AxeData.Mesh/4));%f
+ ivec=find(flag_vec);% search the selected vector index ivec
+ if length(ivec)>0
+ ivec=ivec(1);%choice the first selected vector if several are selected
+ end
+ end
+ end
+ elseif isequal(get(hchild(ichild),'Visible'),'on')& ~isequal(get(hchild(ichild),'Style'),'frame')
+ %FAIRE UNE OPTION D'AIDE AVEC BOUTON SOURIS DROIT (ALT)??
+ end
+ end
+end
+test2D=0;
+if isfield(AxeData,'NbDim')
+ if isequal(AxeData.NbDim,2)
+ test2D=1;
+ end
+end
+if ~test2D %desable object creation and vector editing if NbDim different from 2
+ test_create=0;
+ test_edit_vect=0;
+end
+%delete the current zoom rectangle
+if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom)
+ delete(AxeData.CurrentRectZoom)
+ AxeData.CurrentRectZoom=[];
+end
+
+if testzoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var')
+ AxeData.Drawing='zoom'; %initiate drawing mode
+ AxeData.CurrentObject=[];%unselect objects
+elseif ~isempty(huvmat)
+ %selection of an existing projection object
+ if test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint'))
+ if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create'))
+ userdata=get(hcurrentobject,'UserData');
+ if ishandle(userdata)%the selected line depends on a parent line
+ AxeData.CurrentObject=userdata;% the parent object becomes the current one
+ else
+ AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one
+ end
+ ObjectData=get(AxeData.CurrentObject,'UserData');
+ if test_edit & isfield(ObjectData,'IndexObj')
+ hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
+ set(hother,'Color','b');%reset all the proj objects in 'blue' by default
+ set(hother,'Selected','off')
+ hother=findobj('Tag','proj_object','Type','rectangle');
+ set(hother,'EdgeColor','b');
+ set(hother,'Selected','off');
+ hother=findobj('Tag','proj_object','Type','image');
+ for iobj=1:length(hother)
+ Acolor=get(hother(iobj),'CData');
+ Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
+ set(hother(iobj),'CData',Acolor);
+ end
+ hother=findobj('Tag','DeformPoint');
+ set(hother,'Color','b');
+ set(hother,'Selected','off')
+ if isequal(get(AxeData.CurrentObject,'Type'),'line')
+ set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color
+ elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle')
+ set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color
+ end
+ if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject)
+ for iobj=1:length(ObjectData.SubObject)
+ hsub=ObjectData.SubObject(iobj);
+ if isequal(get(hsub,'Type'),'rectangle')
+ set(hsub,'EdgeColor','m'); %set the selected object to magenta color
+ elseif isequal(get(hsub,'Type'),'image')
+ Acolor=get(hsub,'CData');
+ Acolor(:,:,1)=Acolor(:,:,3);
+ set(hsub,'CData',Acolor);
+ else
+ set(hsub,'Color','m')
+ end
+ end
+ end
+ if isequal(tag_obj,'DeformPoint')
+ set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color
+ end
+ IndexObj=ObjectData.IndexObj;
+ hlist_object=findobj(huvmat,'Tag','list_object');
+ set(hlist_object,'Value',IndexObj);
+ testdeform=0;
+ set(gcbo,'Pointer','circle');
+ AxeData.Drawing='deform';
+ if isequal(tag_obj,'DeformPoint')
+ if isfield(ObjectData,'DeformPoint')
+ set(hcurrentobject,'Selected','on')
+ for ipt=1:length(ObjectData.DeformPoint)
+ if isequal(ObjectData.DeformPoint(ipt),hcurrentobject)
+ AxeData.CurrentIndex=ipt;
+ testdeform=1;
+ end
+ end
+ end
+ end
+ if testdeform==0
+ AxeData.Drawing='translate';
+ set(AxeData.CurrentObject,'Selected','on')
+ set(gcbo,'Pointer','fleur');
+ end
+ end
+ end
+ end
+ % create new projection object
+ if test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create'))
+ ObjectData=read_set_object(UvData.sethandles);
+ ObjectData.Coord=[]; %reset previous object coordinates
+ ObjectData.Coord(1,1)=xy(1,1);
+ ObjectData.Coord(1,2)=xy(1,2);
+ ObjectData.Coord(1,3)=0;
+ if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
+ ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
+ end
+ AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject
+ if isfield(UvData,'Object')
+ IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface
+ else
+ IndexObj=2;
+ end
+ UvData.Object{IndexObj}=ObjectData;
+ UvData.Object{IndexObj}.HandlesDisplay(1)=AxeData.CurrentObject;
+ set(huvmat,'UserData',UvData)
+ list_str=get(hhuvmat.list_object,'String');
+ list_str{IndexObj}=[num2str(IndexObj) '-' set_title(ObjectData.Style,ObjectData.ProjMode)];
+ if ~isequal(list_str{end},'...')
+ list_str{end+1}='...';
+ end
+ set(hhuvmat.list_object,'String',list_str)
+ set(hhuvmat.list_object,'Value',IndexObj)
+ PlotData=get(AxeData.CurrentObject,'UserData');
+ PlotData.IndexObj=IndexObj;
+ set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph
+ AxeData.Drawing='create';
+ end
+
+ % create calibration points if the GUI geometry_calib is opened
+ if test_cal & ~isempty(xy)
+ h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
+ hh_geometry_calib=guidata(h_geometry_calib);
+ h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
+ h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append');
+ if isequal(get(h_edit_append,'Value'),1)
+ if ~isequal(coord_type,'')
+ set(handles_coord,'Value',1)
+ coord_type='';
+ set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
+ set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
+ uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat
+ end
+% if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates
+ strline=[ ' | ' ' | ' ' | ' num2str(xy(1,1),4) ' | ' num2str(xy(1,2),4)];
+% else %phys cordinates
+% strline=[ num2str(xy(1,1),4) ' | ' num2str(xy(1,2),4) ' | 0 | ' ' | ' ];
+% end
+ Coord=get(h_ListCoord,'String');
+ val=get(h_ListCoord,'Value');
+ if isequal(Coord,{''})
+ val=0;
+ end
+ if length(Coord)>val
+ Coord(val+2:length(Coord)+1)=Coord(val+1:length(Coord));% push the list forward beyond the current point
+ end
+ Coord{val+1}=strline;
+ set(h_ListCoord,'String',Coord)
+ set(h_ListCoord,'Value',val+1)
+ geometry_calib('ListCoord_Callback',hObject,eventdata,hh_geometry_calib)
+ data=read_geometry_calib(Coord);
+ if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates
+ XCoord=data.Coord(:,4);
+ YCoord=data.Coord(:,5);
+ else %phys cordinates
+ XCoord=data.Coord(:,1);
+ YCoord=data.Coord(:,2);
+ end
+ hh=findobj('Tag','calib_points')
+ if isempty(hh)
+ line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
+ else
+ set(hh,'XData',XCoord)
+ set(hh,'YData',YCoord)
+ end
+ hhh=findobj('Tag','calib_marker');
+ if ~isempty(hhh)
+ set(hhh,'XData',xy(1,1))
+ set(hhh,'YData',xy(1,2))
+ else
+ line(xy(1,1),xy(1,2),'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20);
+ end
+ %uistack(h_geometry_calib,'top')
+ end
+ end
+
+ % edit vectors
+ if test_edit_vect & ~isempty(ivec)
+ % FF_100=FF-100*double(uint(abs(FF)/100); %value of FF without units and dizaines
+ if ~isfield(AxeData,'FF')
+ AxeData.FF=zeros(size(AxeData.X));
+ end
+ if isequal(AxeData.FF(ivec),0)
+
+ AxeData.FF(ivec)=100; %mark vector #ivec as false
+
+ else
+ AxeData.FF(ivec)=0;
+ end
+ set(haxes,'UserData',AxeData)
+ update_plot
+ end
+end
+set(haxes,'UserData',AxeData);
+
+%------------------------------------------------------
+function update_plot
+%--------------------------------------------
+huvmat=gcbf;
+UvData=get(gcbf,'UserData');
+%determine the axes of action of the set_edit interface
+% list_axes=get(handles.MenuAxes,'String');% list menu fields
+% index_axes=get(handles.MenuAxes,'Value');% selected string index
+% current_axes= list_axes{index_axes(1)} % selected string
+% eval(['haxes=UvData.' current_axes '.Axes']);
+% if isempty(haxes)|~ishandle(haxes)| ~isequal(get(haxes,'Type'),'axes')
+ haxes= findobj(huvmat,'Tag','axes3'); %main plotting axes as default
+% set(handles.MenuAxes,'Value',1)
+% end
+AxeData=get(haxes,'UserData');
+%For vector field representation
+%NEW
+PlotHandles.VecScale=findobj(huvmat,'Tag','VecScale');
+PlotHandles.AutoVec=findobj(huvmat,'Tag','AutoVec');
+PlotHandles.checkyellow=findobj(huvmat,'Tag','checkyellow');
+PlotHandles.checkblack=findobj(huvmat,'Tag','checkblack');
+PlotHandles.col_vec=findobj(huvmat,'Tag','col_vec');
+PlotHandles.colcode1=findobj(huvmat,'Tag','colcode1');
+PlotHandles.colcode2=findobj(huvmat,'Tag','colcode2');
+PlotHandles.vec_col_bar=findobj(huvmat,'Tag','vec_col_bar');
+PlotHandles.slider1=findobj(huvmat,'Tag','slider1');
+PlotHandles.slider2=findobj(huvmat,'Tag','slider2');
+PlotHandles.max_vec=findobj(huvmat,'Tag','max_vec');
+PlotHandles.min_vec=findobj(huvmat,'Tag','min_vec');
+PlotHandles.AutoVecColor=findobj(huvmat,'Tag','AutoVecColor');
+PlotHandles.decimate4=findobj(huvmat,'Tag','decimate4');
+
+%vectors
+Vectors.VecScale=str2num(get(PlotHandles.VecScale,'String'));
+Vectors.AutoVec=get(PlotHandles.AutoVec,'Value');%automatic vector length
+Vectors.checkyellow=get(PlotHandles.checkyellow,'Value');
+Vectors.checkblack=get(PlotHandles.checkblack,'Value');
+Vectors.decimate4=get(PlotHandles.decimate4,'Value');% =1; for reducing the nbre of vectors
+menu_col=get(PlotHandles.col_vec,'String');
+menu_val=get(PlotHandles.col_vec,'Value');
+Vectors.CName=menu_col{menu_val}; %'ima_cor','black','white',...
+Vectors.colcode1=str2num(get(PlotHandles.colcode1,'String'));% first threshold for rgb, first value for'continuous'
+Vectors.colcode2=str2num(get(PlotHandles.colcode2,'String'));% second threshold for rgb, last value (saturation) for 'continuous'
+Vectors.option=get(PlotHandles.vec_col_bar,'Value'); % =1 (64 colors), =0 (3 colors)
+Vectors.min=get(PlotHandles.slider1,'Min');
+Vectors.max=get(PlotHandles.slider1,'Max');
+Vectors.auto=get(PlotHandles.AutoVecColor,'Value');% =1; thresholds scaling relative to min and max, =0 fixed thresholds
+PlotParam.Vectors=Vectors;
+
+[PlotType,ScalOut]= plot_field(AxeData,haxes,PlotParam,1);
Index: /trunk/src/mouse_motion.m
===================================================================
--- /trunk/src/mouse_motion.m (revision 2)
+++ /trunk/src/mouse_motion.m (revision 2)
@@ -0,0 +1,289 @@
+%'mouse_motion': permanently called by mouse motion over a figure (Callback for 'WindowButtonMotionFcn' of the figure)
+%-----------------------------------------------------------------------
+%
+% function mouse_motion(hObject,eventdata,handles)
+% activated by the command:
+% set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})
+% where hObject is the handle of the figure
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function mouse_motion(hObject,eventdata,handles)
+if ~exist('handles','var')
+ return
+end
+if ~isfield(handles, 'mouse_coord')
+ return
+end
+if ~ishandle(handles.mouse_coord)
+ return
+end
+proj_coord=get(handles.mouse_coord,'String');
+choice=get(handles.mouse_coord,'Value');
+if ~isempty(proj_coord); proj_coord=proj_coord{choice};else;proj_coord=[];end;
+test_create=0;%default
+test_edit=0;%default
+if isfield(handles,'VOLUME') % mouse_motion not applied to the uvmat figure, no object creation
+ test_create=get(handles.create,'Value');
+end
+test_edit=isfield(handles,'edit') & get(handles.edit,'Value');% edit test for mouse shap: an arrow
+test_zoom=isfield(handles,'zoom')& get(handles.zoom,'Value');% edit test for mouse shap: an arrow
+
+%find the current axe 'haxes' and display the current mouse position or uicontrol tag
+text_displ_1='';
+text_displ_2='';
+text_displ_3='';
+text_displ_4='';
+
+haxes=[];
+AxeData=[];%default
+mouse=[];
+
+pointershape='arrow';% default pointer is an arrow
+
+xy_fig=get(gcbo,'CurrentPoint');% current point of the current figure (gcbo)
+hchild=get(gcbo,'Children');%handles of all objects in the current figure
+currentfig=gcbo;%store gcbo as variable currentfig
+% loop on all the objects in the current figure (selected by the last mouse click)
+for ichild=1:length(hchild)
+ obj_pos=get(hchild(ichild),'Position');%position of the object
+ if xy_fig(1) >=obj_pos(1) & xy_fig(2) >= obj_pos(2)& xy_fig(1) <=obj_pos(1)+obj_pos(3) & xy_fig(2) <= obj_pos(2)+obj_pos(4);
+ htype=get(hchild(ichild),'Type');%type of the crrent child
+ %if the mouse is over an axis, look at the data
+ if isequal(htype,'axes')
+ haxes=hchild(ichild);
+ xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+ mouse.X=xy(1,1);
+ mouse.Y=xy(1,2);
+ u_mouse=[];
+ v_mouse=[];
+ w_mouse=[];
+ A_mouse=[];
+ c_text=[];
+ f_text=[];
+ ff_text=[];
+ ivec=[];
+ AxeData=get(haxes,'UserData');% data attached to the axis
+ if ~test_edit && ~test_zoom
+ pointershape='crosshair';%set pointer with cross shape (default when mouse is over an axis)
+% % pointershape='crosshair';%set pointer with cross shape (default over axis)
+ end
+ if isfield(AxeData,'X') && isfield(AxeData,'Y') && isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis
+ if ~isempty(AxeData.Mesh)
+ flag_vec=(AxeData.X<(xy(1,1)+AxeData.Mesh/3) & AxeData.X>(xy(1,1)-AxeData.Mesh/3)) & ...%flagx=1 for the vectors with x position selected by the mouse
+ (AxeData.Y<(xy(1,2)+AxeData.Mesh/3) & AxeData.Y>(xy(1,2)-AxeData.Mesh/3));%f
+ ivec=find(flag_vec);% search the selected vector index ivec
+ if length(ivec)>0
+ if ~test_create
+ pointershape='arrow'; %mouse indicates the detection of a vector
+ end
+ ivec=ivec(1);%choice the first selected vector if several are selected
+ mouse.X=AxeData.X(ivec);
+ mouse.Y=AxeData.Y(ivec);
+ u_mouse=AxeData.U(ivec);%displacement
+ v_mouse=AxeData.V(ivec);
+ w_mouse=0; %default
+ if isfield(AxeData,'W')&length(AxeData.W)>=ivec
+ w_text=[', w=' num2str(AxeData.W(ivec),3)];
+ else
+ w_text='';
+ end
+ if ~isfield(AxeData,'CName')
+ AxeData.CName='C';%REVOIR
+ end
+ c_text=[', ' AxeData.CName '=' num2str(AxeData.C(ivec),3)];
+ if isfield(AxeData,'F')&length(AxeData.F)>=ivec
+ f_text=[', f=' num2str(AxeData.F(ivec),3)];
+ else
+ f_text='';
+ end
+ if isfield(AxeData,'FF')&length(AxeData.FF)>=ivec
+ ff_text=[', ff=' num2str(AxeData.FF(ivec),3)];
+ else
+ ff_text='';
+ end
+ end
+ end
+ end
+ if isfield(AxeData,'Z')
+ mouse.Z=AxeData.Z; %generaliser au cas avec angle
+ end
+ if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
+ mouse.Z=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
+ end
+ testscal= isfield(AxeData,'A')& isfield(AxeData,'AX')& isfield(AxeData,'AY');%test the existence of an image (or scalar represented by an image)
+ if testscal
+ testscal=~isempty(AxeData.A)&~isempty(AxeData.AX)& ~isempty(AxeData.AY);
+ end
+ if testscal%test the existence of an image (or scalar represented by an image)
+ nxy=size(AxeData.A);
+ MaxAY=max(AxeData.AY(1),AxeData.AY(end));
+ MinAY=min(AxeData.AY(1),AxeData.AY(end));
+ if (xy(1,1)>AxeData.AX(1))&(xy(1,1)MinAY)
+ indx0=1+round((nxy(2)-1)*(xy(1,1)-AxeData.AX(1))/(AxeData.AX(end)-AxeData.AX(1)));% index x of pixel
+ indy0=1+round((nxy(1)-1)*(xy(1,2)-AxeData.AY(1))/(AxeData.AY(end)-AxeData.AY(1)));% index y of pixel
+ if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1)
+ A_mouse=AxeData.A(indy0,indx0,:);
+ end
+ end
+ end
+ %coordinate transform if proj_coord differs from menu_coord
+ if isfield(AxeData,'CoordType')
+ mouse.CoordType=AxeData.CoordType;
+ end
+ if isfield(AxeData,'CoordUnit')
+ mouse.CoordUnit=AxeData.CoordUnit;
+ end
+ if isfield(mouse,'CoordType') &~isequal(mouse.CoordType,proj_coord)
+ huvmat=findobj(allchild(0),'Tag','uvmat');%find the uvmat interface handle
+ UvData=get(huvmat,'UserData'); %coord transformed stored in the uvmat interface, updated by file input
+ if isfield(AxeData,'CoordType')
+ mouse.CoordType=AxeData.CoordType;
+ end
+ if isfield(AxeData,'dt')
+ mouse.dt=AxeData.dt;
+ end
+% if ~isempty(z_mouse)
+% mouse.Z=z_mouse;
+% end
+ if length(ivec)>0 %& isfield(AxeData,'dt')
+ mouse.U=u_mouse;
+ mouse.V=v_mouse;
+ end
+ mouse=feval(proj_coord,mouse,UvData);%apply transform proj_coord to the position
+ if length(ivec)>0%& isfield(AxeData,'dt')
+ u_mouse=mouse.U;
+ v_mouse=mouse.V;
+ end
+ end
+ if isfield(mouse,'CoordType')
+ if isequal(mouse.CoordType,'px')
+ mouse.CoordUnit='px';
+ end
+ else
+ mouse.CoordUnit='';%default
+ end
+ text_displ_1=['x=' num2str(mouse.X,4) ',y=' num2str(mouse.Y,4)];
+ if isfield(mouse,'Z')&~isempty(mouse.Z)
+ text_displ_1=[text_displ_1 ',z=' num2str(mouse.Z,3)];
+ end
+ if isfield(mouse,'CoordUnit')
+ text_displ_1=[text_displ_1 ' ' mouse.CoordUnit];
+ end
+ if ~isempty(ivec)
+ text_displ_4=['vec#=' num2str(ivec)];
+ end
+ if ~isempty(u_mouse)
+ text_displ_3=['u=' num2str(u_mouse,3) ',v=' num2str(v_mouse,3) w_text ];
+ if isfield(mouse,'CoordUnit')
+ if isequal(mouse.CoordUnit,'px')
+ text_displ_3=[text_displ_3 ' ' mouse.CoordUnit];
+ elseif isfield(AxeData,'TimeUnit')
+ text_displ_3=[text_displ_3 ' ' mouse.CoordUnit '/' AxeData.TimeUnit];
+ end
+ end
+ text_displ_4=[text_displ_4 c_text f_text ff_text];
+ end
+
+ if ~isempty(A_mouse)
+ text_displ_2=['A=' num2str(double(A_mouse)) ',i=' num2str(indx0) ',j=' num2str(indy0)];
+ end
+ elseif isequal(get(hchild(ichild),'Visible'),'on')& ~isequal(get(hchild(ichild),'Style'),'frame')
+ text_displ_1=get(hchild(ichild),'Tag');
+ end
+ end
+end
+set(handles.text_display_1,'String',text_displ_1);
+set(handles.text_display_2,'String',text_displ_2);
+set(handles.text_display_3,'String',text_displ_3);
+set(handles.text_display_4,'String',text_displ_4);
+
+%%%%%%%%%%%%%%%%%
+%create or modify an object
+if isfield(AxeData,'CurrentObject') & ishandle(AxeData.CurrentObject) & isfield(AxeData,'Drawing') & ~isequal(AxeData.Drawing,'off')
+ PlotData=get(AxeData.CurrentObject,'UserData');
+ huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle
+ if ~isempty(huvmat)
+ UvData=get(huvmat,'UserData');
+ if ~isfield(PlotData,'IndexObj')
+ return
+ end
+ ObjectData=UvData.Object{PlotData.IndexObj};
+ XYData=AxeData.CurrentOrigin;
+ if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin)
+ if isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|isequal(ObjectData.Style,'polygon')|isequal(ObjectData.Style,'points')
+ xy(1,3)=0;
+ ObjectData.Coord=[ObjectData.Coord ;xy(1,:)];
+ % ObjectData.Coord(end,:)=xy(1,:);
+ elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')|isequal(ObjectData.Style,'volume')
+ ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
+ ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
+ ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
+ ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
+ elseif isequal(ObjectData.Style,'plane') %case of 'plane'
+ DX=(xy(1,1)-ObjectData.Coord(1,1));
+ DY=(xy(1,2)-ObjectData.Coord(1,2));
+ ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt
+ if isfield(ObjectData,'RangeX')
+ XMax=sqrt(DX*DX+DY*DY);
+ if XMax>max(ObjectData.RangeX)
+ ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
+ end
+ end
+ end
+ plot_object(ObjectData,[],AxeData.CurrentObject,'m');
+ pointershape='crosshair';
+ elseif isequal(AxeData.Drawing,'translate')
+ DX=xy(1,1)-XYData(1);%translation from initial position
+ DY=xy(1,2)-XYData(2);
+ ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
+ ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
+ plot_object(ObjectData,[],AxeData.CurrentObject,'m');
+ pointershape='fleur';
+ elseif isequal(AxeData.Drawing,'deform')
+ ind_move=AxeData.CurrentIndex;
+ ObjectData.Coord(ind_move,1)=xy(1,1);
+ ObjectData.Coord(ind_move,2)=xy(1,2);
+ plot_object(ObjectData,[],AxeData.CurrentObject,'m');
+ pointershape='circle';
+ end
+ end
+end
+%%%%%%%%%%%%%
+%draw a rectangle if no object creation is selected
+if ~isempty(haxes) & isfield(AxeData,'Drawing')& isequal(AxeData.Drawing,'zoom')& isfield(AxeData,'CurrentOrigin')...
+ & isequal(get(gcf,'SelectionType'),'normal')%
+ xy_rect=AxeData.CurrentOrigin;
+ if ~isempty(xy_rect)
+ rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate
+ rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate
+ rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width
+ rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height
+ if rect(3)>0 & rect(4)>0
+ if isfield(AxeData,'CurrentRectZoom')& ishandle(AxeData.CurrentRectZoom)
+ set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position
+ else
+ AxeData.CurrentRectZoom=rectangle('Position',rect,'LineStyle',':','Tag','rect_zoom');
+ set(haxes,'UserData',AxeData)
+ end
+ end
+ end
+end
+if test_zoom
+ pointershape='arrow';
+end
+set(currentfig,'Pointer',pointershape);
Index: /trunk/src/mouse_up.m
===================================================================
--- /trunk/src/mouse_up.m (revision 2)
+++ /trunk/src/mouse_up.m (revision 2)
@@ -0,0 +1,322 @@
+%'mouse_up': function activated when the mouse button is released
+%----------------------------------------------------------------
+% function mouse_up(ggg,eventdata,handles)
+% activated by the command:
+% set(hObject,'WindowButtonUpFcn',{'mouse_up'}),
+% where hObject is the handle of the figure
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function mouse_up(ggg,eventdata,handles)
+MouseAction='none'; %default
+zoomstate=0;%default
+if ~exist('handles','var')
+ handles=get(gcbo,'UserData');
+end
+huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle
+if ~isempty(huvmat)
+ hhuvmat=guidata(huvmat);
+ UvData=get(huvmat,'UserData');
+ if isfield(UvData,'MouseAction')
+ MouseAction=UvData.MouseAction;% set the mouse action (edit, create objects...)
+ end
+ zoomstate=get(hhuvmat.zoom,'Value');
+end
+if isequal(MouseAction,'calib') && ~zoomstate
+ return
+end
+currentfig=gcbo;
+AxeData=get(gca,'UserData');
+currentaxes=gca; %store the current axes handle
+test_drawing=0;%default
+
+%finalize the fabrication or the translation/deformation of an object and plot the corresponding projected field
+if ~isempty(huvmat) & isfield(AxeData,'Drawing') & ~isequal(AxeData.Drawing,'off') & isfield(AxeData,'CurrentObject')...
+ & ishandle(AxeData.CurrentObject)
+ xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+ PlotData=get(AxeData.CurrentObject,'UserData');%get data attached to the current projection object
+ IndexObj=PlotData.IndexObj;
+ ObjectData=UvData.Object{IndexObj};
+ if isequal(AxeData.Drawing,'translate')
+ XYData=AxeData.CurrentOrigin;
+ DX=xy(1,1)-XYData(1);%translation from initial position
+ DY=xy(1,2)-XYData(2);
+ ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
+ ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
+ elseif isequal(AxeData.Drawing,'deform')
+ ind_move=AxeData.CurrentIndex;
+ ObjectData.Coord(ind_move,1)=xy(1,1);
+ ObjectData.Coord(ind_move,2)=xy(1,2);
+ else %creating object
+ if isequal(ObjectData.Style,'line')||isequal(ObjectData.Style,'polyline')||...
+ isequal(ObjectData.Style,'polygon')||isequal(ObjectData.Style,'points')
+ if isfield(AxeData,'ObjectCoord') && size(AxeData.ObjectCoord,2)==3
+ xy(1,3)=AxeData.ObjectCoord(1,3); % z coordinate of the mouse: to generalise ...
+ else
+ xy(1,3)=0; % z coordinate set to 0 by default
+ end
+ if ~isequal(ObjectData.Coord,xy(1,:))
+ ObjectData.Coord=[ObjectData.Coord ;xy(1,:)];% append the coordiantes marked by the mouse to the eobject
+ end
+ elseif isequal(ObjectData.Style,'rectangle')||isequal(ObjectData.Style,'ellipse')||isequal(ObjectData.Style,'volume')
+ XYData=AxeData.CurrentOrigin;
+ ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
+ ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
+ ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
+ ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
+ elseif isequal(ObjectData.Style,'plane') %case of 'plane'
+ DX=(xy(1,1)-ObjectData.Coord(1,1));
+ DY=(xy(1,2)-ObjectData.Coord(1,2));
+ ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt
+ if isfield(ObjectData,'RangeX')
+ XMax=sqrt(DX*DX+DY*DY);
+ if XMax>max(ObjectData.RangeX)
+ ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
+ end
+ end
+ end
+ end
+ %set(AxeData.CurrentObject,'UserData',ObjectData); %update the object properties
+ if isequal(ObjectData.Style,'rectangle')||isequal(ObjectData.Style,'ellipse')
+ NbDefPoint=1;
+ elseif isequal(ObjectData.Style,'line')|| isequal(ObjectData.Style,'plane');
+ NbDefPoint=2;
+ else
+ NbDefPoint=3;
+ end
+
+ %show object coordinates in the GUI set_object
+ h_set_object=findobj(allchild(0),'Name','set_object');
+ h_XObject=findobj(h_set_object,'Tag','XObject');
+ h_YObject=findobj(h_set_object,'Tag','YObject');
+ h_ZObject=findobj(h_set_object,'Tag','ZObject');
+ set(h_XObject,'String',num2str(ObjectData.Coord(:,1),4));
+ set(h_YObject,'String',num2str(ObjectData.Coord(:,2),4));
+ set(h_ZObject,'String',num2str(ObjectData.Coord(:,3),4));
+ if NbDefPoint<=2 || isequal(get(currentfig,'SelectionType'),'alt') ||...
+ isequal(AxeData.Drawing,'translate') || isequal(AxeData.Drawing,'deform');%stop drawing
+ AxeData.CurrentOrigin=[]; %suppress the current origin
+ if isequal(ObjectData.Style,'line') && size(ObjectData.Coord,1)<=1
+ AxeData.Drawing='off';
+ set(currentaxes,'UserData',AxeData);
+ return % line needs at leqst two points
+ end
+ if ~isempty(ObjectData)
+ testmask=0;
+ hmask=findobj(huvmat,'Tag','makemask');
+ if ~isempty(hmask)
+ testmask=get(hmask,'Value');
+ end
+ if testmask
+ PlotHandles=[];%do not project data on the object during mask creation
+ else
+ PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
+ end
+ AxeData.hset_object=set_object(ObjectData,PlotHandles);% call the set_object interface ,*
+ UvData.Object{IndexObj}=update_obj(UvData,IndexObj,ObjectData,PlotHandles);
+ %ObjectData=update_obj(UvData,IndexObj,ObjectData,PlotHandles);
+ if isfield(UvData.Object{IndexObj},'PlotParam')
+ write_plot_param(PlotHandles,UvData.Object{IndexObj}.PlotParam); %update the display of plotting parameters for the current object
+ end
+ set(hhuvmat.create,'Value',0);% set to 'off' the button for object creation
+ set(hhuvmat.create,'BackgroundColor',[0 1 0]);% paint the creation button in green
+ set(hhuvmat.edit,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
+ set(hhuvmat.edit,'Value',1);%
+ set(hhuvmat.edit,'Enable','on');%
+ set(hhuvmat.MenuEdit,'Enable','on');%
+ set(hhuvmat.MenuEdit,'Enable','on');%
+ set(hhuvmat.MenuObject,'Enable','on');%
+ UvData.MouseAction='edit_object'; % set the edit button to 'on'
+ end
+ else
+ AxeData.CurrentOrigin=[xy(1,1) xy(1,2)]; %the current point becomes the new current origin
+ test_drawing=1;%allow continuation of drawing object
+ UvData.Object{IndexObj}=ObjectData;
+ end
+ hother=findobj('Tag','deformpoint');%find all the deformpoints
+ set(hother,'Color','b');%reset all the deformpoints in 'blue'
+else
+ test_drawing=0;
+end
+
+%creation of a new zoom plot
+test_replot=0;
+if isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
+% FigData=get(currentfig,'UserData');
+ hparentfig=currentfig;
+ %open or update a new zoom figure if a rectangle has been drawn
+ if ishandle(currentaxes);
+ if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom)
+ PosRect=get(AxeData.CurrentRectZoom,'Position');
+ if isfield(AxeData,'CurrentVec') & ishandle(AxeData.CurrentVec)
+ delete(AxeData.CurrentVec)
+ end
+ %update the axes UvData.Plane2 if it exists, else create it
+% if isfield (UvData,'Plane2') & ishandle(UvData.Plane2.Fig)%if the second plan plotting axis already exists
+% hfig2=UvData.Plane2.Fig;
+% if isequal(gcf,hfig2)%if we are already on the secondary figure
+% test_replot=1;
+% else
+% figure(hfig2)%set hfig2 as the current figure
+% clf; %erase axes
+% end
+% else
+ hfig2=figure;%create new figure
+ set(hfig2,'name','zoom')
+ set(hfig2,'Units','normalized')
+ set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
+% UvData.Plane2.Fig=hfig2;
+ map=colormap(currentaxes);
+ colormap(map);%transmit the current colormap to the zoom fig
+ get(handles.RootFile,'String')
+% end
+ set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
+ if test_replot==0
+ set(hfig2,'Unit','normalized')
+ set(hfig2,'KeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
+ set(hfig2,'WindowButtonMotionFcn',{@mouse_motion,handles})%set mouse action function
+ set(hfig2,'WindowButtonDownFcn',{@mouse_down})%set mouse click action function
+ set(hfig2,'WindowButtonUpFcn',{@mouse_up,handles})
+ set(hfig2,'DeleteFcn',{@close_fig,AxeData.CurrentRectZoom,'zoom'})
+ set(hfig2,'UserData',AxeData.CurrentRectZoom)% record the parent object (zoom rectangle) in the new fig
+ %UvData.Plane2.Axes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
+ AxeData.ZoomAxes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
+ figure(hfig2)
+ set(AxeData.ZoomAxes,'Position',[0.1300 0.1100 0.7750 0.8150])% standard axes position on a figure
+ hcol=findobj(hparentfig,'Tag','Colorbar'); %look for colorbar axes
+ if ~isempty(hcol)
+ hcol_new=colorbar;
+ YTick=get(hcol,'YTick');
+ YTicklabel=get(hcol,'Yticklabel');
+ colbarlim=get(hcol,'YLim');
+ newcolbarlim=get(hcol_new,'YLim');
+ scale_bar=(newcolbarlim(2)-newcolbarlim(1))/(colbarlim(2)-colbarlim(1));
+ YTick_rescaled=newcolbarlim(1)+scale_bar*(YTick-colbarlim(1));
+ set(hcol_new,'YTick',YTick_rescaled);
+ set(hcol_new,'Yticklabel',YTicklabel);
+ end
+ end
+ if ishandle(AxeData.ZoomAxes)
+ hnew_rect=findobj(AxeData.ZoomAxes,'Tag','rect_zoom');
+ if ~isempty(hnew_rect)
+ delete(hnew_rect);
+ ChildAxeData=get(AxeData.ZoomAxes,'UserData');
+ ChildAxeData.CurrentRectZoom=[]; % no rect zoom in the new window
+ ChildAxeData.Drawing='off';
+ ChildAxeData.ParentRect=AxeData.CurrentRectZoom;%set the rectangle as a 'parent' associated to the new axes
+ set(AxeData.ZoomAxes,'UserData',ChildAxeData);%update the AxeData of the new axes
+ % UvData.TopFig=hfig2;%put the new fig to the top of the stack for uvmat
+ % set(huvmat,'UserData',UvData)
+ set(AxeData.ZoomAxes,'Xlim',[PosRect(1) PosRect(1)+PosRect(3)])
+ set(AxeData.ZoomAxes,'Ylim',[PosRect(2) PosRect(2)+PosRect(4)])
+ end
+ end
+ end
+ end
+end
+%zoom in if no new figure is created
+if zoomstate
+ if isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
+ %zoom(2)% zoom in by a factor of 2
+ alpha=0.5; %zoom factor (zoom in by a factor 2)
+ xlim=get(currentaxes,'XLim');
+ xlim_new(1)=(1+alpha)*xlim(1)/2+(1-alpha)*xlim(2)/2;
+ xlim_new(2)=(1-alpha)*xlim(1)/2+(1+alpha)*xlim(2)/2;
+ set(currentaxes,'XLim',xlim_new)
+ ylim=get(currentaxes,'YLim');
+ ylim_new(1)=(1+alpha)*ylim(1)/2+(1-alpha)*ylim(2)/2;
+ ylim_new(2)=(1-alpha)*ylim(1)/2+(1+alpha)*ylim(2)/2;
+ set(currentaxes,'YLim',ylim_new)
+ if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
+ hparentrect=AxeData.ParentRect;
+ xlim=get(currentaxes,'XLim');
+ ylim=get(currentaxes,'YLim');
+ rect([1 2])=[xlim(1) ylim(1)];
+ rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
+ set(hparentrect,'Position',rect)
+ end
+
+ elseif isequal(get(currentfig,'SelectionType'),'alt'); %if right button has been pressed
+ %zoom(0.5)% zoom out by a factor of 2
+ alpha=2; %zoom factor (zoom out by a factor 2)
+ xlim=get(currentaxes,'XLim');
+ xlim_new(1)=(1+alpha)*xlim(1)/2+(1-alpha)*xlim(2)/2;
+ xlim_new(2)=(1-alpha)*xlim(1)/2+(1+alpha)*xlim(2)/2;
+ ylim=get(currentaxes,'YLim');
+ ylim_new(1)=(1+alpha)*ylim(1)/2+(1-alpha)*ylim(2)/2;
+ ylim_new(2)=(1-alpha)*ylim(1)/2+(1+alpha)*ylim(2)/2;
+ set(currentaxes,'XLim',xlim_new)
+ set(currentaxes,'YLim',ylim_new)
+ %test whther zoom out is operating (to inactivate AxedAta
+ if ~isfield(AxeData,'CurrentXLim')| ~isequal(xlim,AxeData.CurrentXLim)
+ AxeData.CurrentXLim=xlim;%
+ end
+ if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
+ hparentrect=AxeData.ParentRect;
+ xlim=get(currentaxes,'XLim');
+ ylim=get(currentaxes,'YLim');
+ rect([1 2])=[xlim(1) ylim(1)];
+ rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
+ set(hparentrect,'Position',rect)
+ end
+ end
+end
+
+%display the data of the current object selected with the mouse right click
+if isequal(get(currentfig,'SelectionType'),'alt') && ~zoomstate && (~isfield(AxeData,'Drawing')||~isequal(AxeData.Drawing,'create'))
+ hother=findobj('Tag','proj_object');%find all the proj objects
+ nbselect=0;
+ %test the existence of selected objects:
+ for iproj=1:length(hother);
+ iselect=isequal(get(hother(iproj),'Selected'),'on');%reset all the proj objects in 'blue' by default
+ nbselect=nbselect+iselect;
+ end
+ hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
+ set(hother,'Color','b');%reset all the proj objects in 'blue' by default
+ set(hother,'Selected','off')
+ hother=findobj('Tag','proj_object','Type','rectangle');
+ set(hother,'EdgeColor','b');
+ set(hother,'Selected','off')
+ hother=findobj('Tag','proj_object','Type','patch');
+ set(hother,'FaceColor','b');
+ if isequal(get(gco,'Type'),'image')
+ currentobj=get(gco,'parent');%parent axes of the image
+ else
+ currentobj=gco;%default
+ end
+ if ((nbselect==0) && isequal(get(currentobj,'Type'),'axes')) || isequal(currentobj,huvmat)
+ global CurData
+ CurData=get(currentobj,'UserData');
+ %plot_text(CurData)
+ %get_field([],CurData);
+ evalin('base','global CurData')%make CurData global in the workspace
+ objtype=get(currentobj,'Type');
+ display(['UserData of ' objtype ':'])
+ evalin('base','CurData') %display CurData in the workspace
+ commandwindow
+ end
+end
+if test_drawing==0
+ AxeData.Drawing='off';%stop current drawing action
+end
+set(currentaxes,'UserData',AxeData);
+if ~isempty(huvmat)
+ set(huvmat,'UserData',UvData);
+end
+
+
+
Index: /trunk/src/msgbox_uvmat.m
===================================================================
--- /trunk/src/msgbox_uvmat.m (revision 2)
+++ /trunk/src/msgbox_uvmat.m (revision 2)
@@ -0,0 +1,203 @@
+%'msgbox_uvmat': associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
+% msgbox_uvmat(title,display)
+%
+% OUTPUT:
+% answer (text string)= 'yes', 'No', 'cancel', or the text string introduced as input
+%
+%INPUT:
+% title: string indicating the type of message box:
+% title= 'INPUT_TXT','CONFIMATION' ,'ERROR', 'WARNING', 'INPUT_Y-N', default = 'INPUT_TXT' (the title is displayed in the upper bar of the fig).
+% if title='INPUT_TXT', input data is asked in an edit box
+% if title='CONFIMATION'', 'ERROR', 'WARNING', the figure remains opened until a button 'OK' is pressed
+% if title='INPUT_Y-N', an answer Yes/No is requested
+% display, displayed text
+% default_answer: default answer in the edit box (only used with title='INPUT_TXT')
+
+function varargout = msgbox_uvmat(varargin)
+
+% Last Modified by GUIDE v2.5 24-Oct-2009 21:55:17
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @msgbox_uvmat_OpeningFcn, ...
+ 'gui_OutputFcn', @msgbox_uvmat_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin && ischar(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+% --- Executes just before msgbox_uvmat is made visible.
+function msgbox_uvmat_OpeningFcn(hObject, eventdata, handles,title,display,default_answer)
+% This function has no output args, see OutputFcn.
+
+% Choose default command line output for msgbox_uvmat
+handles.output = 'Cancel';
+
+% Update handles structure
+guidata(hObject, handles);
+testNo=0;
+testCancel=1;
+testinputstring=0;
+icontype='quest';%default question icon (text input asked)
+if exist('title','var')
+ set(hObject, 'Name', title);
+ if isequal (title,'CONFIRMATION')
+ icontype='';
+ testCancel=0; %no cancel button
+ elseif isequal (title,'ERROR')
+ icontype='error';
+ testCancel=0; %no cancel button
+ elseif isequal (title,'WARNING')
+ icontype='warn';
+ testCancel=0; %no cancel button
+ elseif isequal (title,'INPUT_Y-N')
+ icontype='quest';
+ testNo=1; % button No activated
+ else
+ testinputstring=1;
+ end
+end
+if exist('display','var')
+ set(handles.text1, 'String', display);
+end
+if testinputstring
+ set(handles.edit_box, 'Visible', 'on');
+else
+ set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
+end
+if exist('default_answer','var') && testinputstring
+ set(handles.edit_box, 'String', default_answer);
+end
+% Determine the position of the dialog - centered on the screen
+FigPos=get(0,'DefaultFigurePosition');
+OldUnits = get(hObject, 'Units');
+set(hObject, 'Units', 'pixels');
+OldPos = get(hObject,'Position');
+FigWidth = OldPos(3);
+FigHeight = OldPos(4);
+ScreenUnits=get(0,'Units');
+set(0,'Units','pixels');
+ScreenSize=get(0,'ScreenSize');
+set(0,'Units',ScreenUnits);
+
+FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
+FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
+FigPos(3:4)=[FigWidth FigHeight];
+set(hObject, 'Position', FigPos);
+set(hObject, 'Units', OldUnits);
+
+% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
+if isequal(icontype,'')
+ hima=findobj(handles.axes1,'Type','image');
+ if ~isempty(hima)
+ delete(hima)
+ end
+else
+ load dialogicons.mat
+ eval(['IconData=' icontype 'IconData;'])
+ eval(['IconCMap=' icontype 'IconMap;'])
+ questIconMap(256,:) = get(handles.figure1, 'Color');
+ Img=image(IconData, 'Parent', handles.axes1);
+ set(handles.figure1, 'Colormap', IconCMap);
+ set(handles.axes1, ...
+ 'Visible', 'off', ...
+ 'YDir' , 'reverse' , ...
+ 'XLim' , get(Img,'XData'), ...
+ 'YLim' , get(Img,'YData') ...
+ );
+end
+if testCancel
+ set(handles.Cancel,'Visible','on')
+else
+ set(handles.Cancel,'Visible','off')
+end
+if testNo
+ set(handles.No,'Visible','on')
+else
+ set(handles.No,'Visible','off')
+end
+set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
+% UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
+uiwait(handles.figure1);
+
+
+% --- Outputs from this function are returned to the command line.
+function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
+
+% Get default command line output from handles structure
+if isequal(handles.output,'Cancel')
+ varargout{1}='Cancel';
+elseif isequal(handles.output,'No')
+ varargout{1}='No';
+else
+ varargout{1}=get(handles.edit_box,'String');
+ isequal(varargout{1},'')
+ if isempty(varargout{1}) || isequal(varargout{1},'')
+ varargout{1}='Yes';
+ end
+end
+% The figure can be deleted now
+delete(handles.figure1);
+
+% --- Executes on button press in OK.
+function OK_Callback(hObject, eventdata, handles)
+handles.output = get(hObject,'String');
+guidata(hObject, handles);% Update handles structure
+uiresume(handles.figure1);
+
+% --- Executes on button press in No.
+function No_Callback(hObject, eventdata, handles)
+handles.output='No';
+guidata(hObject, handles);
+uiresume(handles.figure1);
+
+% --- Executes on button press in Cancel.
+function Cancel_Callback(hObject, eventdata, handles)
+handles.output = get(hObject,'String');
+%handles.output = 'Cancel'
+guidata(hObject, handles); % Update handles structure
+% Use UIRESUME instead of delete because the OutputFcn needs
+% to get the updated handles structure.
+uiresume(handles.figure1);
+
+
+% --- Executes when user attempts to close figure1.
+function figure1_CloseRequestFcn(hObject, eventdata, handles)
+if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
+ % The GUI is still in UIWAIT, us UIRESUME
+ uiresume(handles.figure1);
+else
+ % The GUI is no longer waiting, just close it
+ delete(handles.figure1);
+end
+
+% --- Executes on key press over figure1 with no controls selected.
+function figure1_KeyPressFcn(hObject, eventdata, handles)
+% Check for "enter" or "escape"
+if isequal(get(hObject,'CurrentKey'),'escape')
+ % User said no by hitting escape
+ handles.output = 'No';
+
+ % Update handles structure
+ guidata(hObject, handles);
+
+ uiresume(handles.figure1);
+end
+if isequal(get(hObject,'CurrentKey'),'return')
+ uiresume(handles.figure1);
+end
+
+
+
+
+
Index: /trunk/src/name2display.m
===================================================================
--- /trunk/src/name2display.m (revision 2)
+++ /trunk/src/name2display.m (revision 2)
@@ -0,0 +1,205 @@
+%'name2display': extracts the root name and field numbers from an input filename
+%--------------------------------------------------------------------
+%[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput)
+%
+%OUTPUT:
+%filebasesub: filename without appendix
+%field_count: string for the first number i
+%str2: string for the second number i (only for .nc files)
+%str_a: string for the first number j
+%str_b:string for the second number j (only for .nc files)
+%ext: file extension
+%nom_type: char chain characterizing the file nomenclature: with values
+% nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined)
+% nom_type='*':constant name for a file representing a series (e.g. avi movie)
+% nom_type='_i': series of files with a single index i preceded by '_'(e.g. 'aa_45.png').
+% nom_type='#', series of indexed images wich is not series_i [filebase index ext], e.g. 'aa045.jpg' or 'aa45.tif'
+% nom_type='_i_j': matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png')
+% nom_type='_i1-i2': from pairs from a single index (e.g. 'aa_45-47.nc')
+% nom_type='_i_j1-j2': pairs of j indices (e.g. 'aa_45_2-3.nc')
+% nom_type='_i1-i2_j': pairs of i indices (e.g. 'aa_45-46_2.nc')
+% nom_type='#a','#A", with a numerical index and an index letter(e.g.'aa045b.png') (lower or upper case)
+% nom_type='raw_SMD', same as '#' but with no extension ext='', OBSOLETE
+% nom_type='#_ab', from pairs of '#' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by '_i_j1-j2')
+%subdir: name of the subdirectory for netcdf files
+%
+%INPUT:
+%fileinput: complete name of the file, including path
+
+function [RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput)
+% siz=length(fileinput);
+% indcur=siz;
+% default values:
+% test_=0;
+field_count='';%character string
+str2='';
+str_a='';
+str_b='';
+% ext='';
+nom_type='';
+subdir='';
+ %select file extension
+[RootPath,RootFile,ext]=fileparts(fileinput);
+indcur=length(RootFile);% nbre of characters in fileraw
+
+ %recognize the name form
+filerawascii=double(RootFile);%ascci code
+val=(48>filerawascii)|(filerawascii>57); % test for the non-numerical characters
+indsel=find(val);% character indices of non numerical characters
+filelit=RootFile(indsel);% fileraw name with numbers removed
+nbchar=length(indsel);
+if nbchar<4% put '*' before the name (remove at the end)
+ prefilelit(1:4-nbchar)='*';%insert 3_nbchar '*' in the file name
+ filelit=[prefilelit filelit];
+ indsel=[1:4-nbchar indsel+4-nbchar];
+ RootFile=[prefilelit RootFile];
+ indcur=indcur+4-nbchar;
+end
+separ3=indsel(end);% index of last non numerical character in fileraw
+separ2=indsel(end-1);% index of previous non numerical character
+separ1=indsel(end-2);
+separ0=indsel(end-3);
+num1='';num2='';num3='';
+if separ1>=separ0+1,num0=RootFile(separ0+1:separ1-1);end
+if separ2>=separ1+1,num1=RootFile(separ1+1:separ2-1);end
+if separ3>=separ2+1,num2=RootFile(separ2+1:separ3-1);end
+if indcur>=separ3+1,num3=RootFile(separ3+1:indcur);end
+last_str=RootFile(indcur);%last character in fileraw
+last=double(last_str);%corresponding ascii code
+penult=double(RootFile(indcur-1));%ascii code of the penultimate character
+testsub=0; %default
+if strcmpi(ext,'.avi')
+ nom_type='*';
+ %case of old image nomenclature
+elseif (strcmp(ext,'.png') || strcmp(ext,'')) && penult >= 48 && penult <= 57 && (last < 48 || last > 57)
+ % if the penultimate character is a number and the last a letter
+ % search the appendix a,b,c,
+ str_a=last_str; %put appendix a,b,c....
+ indcur=indcur-1;
+ if strcmp(ext,'.png'), nom_type='#a'; end
+ if strcmp(ext,''), nom_type='raw_SMD'; end
+ num=1;count=0; % extract the numerical appendix
+ while num==1;
+ filascii=double(RootFile(indcur));
+ if (48>filascii)||(filascii>57); % select the non-numerical characters
+ num=0;
+ else
+ indcur=indcur-1; count=count+1;
+ end
+ end
+ if count~=0
+ field_count=RootFile(indcur+1:indcur+count);% set the selected field number
+ end
+elseif penult >= 48 && penult <= 57 && (last <= 66 && last >= 65)% PCO camera Toulouse, end with A or B (NEW)
+ % if the penultimate character is a number and the last a letter
+ % search the appendix a,b,c,
+ str_a=last_str; %put appendix a,b,c....
+ indcur=indcur-1;
+ nom_type='#A';
+ num=1;count=0; % extract the numerical appendix
+ while num==1;
+ filascii=double(RootFile(indcur));
+ if (48>filascii)||(filascii>57); % select the non-numerical characters
+ num=0;
+ else
+ indcur=indcur-1; count=count+1;
+ end
+ end
+ if count~=0
+ field_count=RootFile(indcur+1:indcur+count);% set the selected field number
+ end
+ indcur=indcur-1;
+elseif strcmp(filelit(end-2:end),'-_-_')%new nomenclature appendix num1-num2_num_a-num_b
+ field_count=num0;
+ str2=num1;
+ str_a=num2;
+ str_b=num3;
+ nom_type='_i1-i2_j1-j2';
+ testsub=1;
+ indcur=separ0-1;
+elseif strcmp(filelit(end-2:end),'_-_')%new nomenclature appendix num1-num2_num_a
+ field_count=num1;
+ str2=num2;
+ str_a=num3;
+ nom_type='_i1-i2_j';
+ testsub=1;
+ indcur=separ1-1;
+elseif strcmp(filelit(end-2:end),'__-')%new nomenclature appendix num1_num2-num2
+ indcur=separ1-1;
+ field_count=num1;
+ str_a=num2;
+ str_b=num3;
+ nom_type='_i_j1-j2';
+ testsub=1;
+elseif strcmp(filelit(end-1:end),'_-')
+ indcur=separ2-1;
+ field_count=num2;
+ str2=num3;
+ str_a='';
+ nom_type='_i1-i2';
+ testsub=1;
+elseif strcmp(filelit(end-1:end),'__')
+ indcur=separ2-1;
+ field_count=num2;
+ str2='';
+ str_a=num3;
+ nom_type='_i_j';
+elseif strcmp(filelit(end),'_')
+ indcur=separ3-1;
+% field_count=num3;
+ str2='';
+ str_a='';
+ %detect zeros before the number
+% count=0; % extract the numerical appendix
+ if strcmp('0',RootFile(separ3+1)); % select the non-numerical characters
+ nom_type=['_%0' num2str(length(RootFile(separ3+1:end))) 'd'];
+ else
+ nom_type='_i';
+ end
+ field_count=RootFile(separ3+1:end);% set the selected field number'%03d'
+elseif RootFile(indcur-2)=='_'% search appendix a,b,c,d
+ last=RootFile(indcur-1:indcur);
+ if isequal(length(last),2) && double(last(1)) >= 97 && double(last(1)) <= 122 ...% = 1 for letters
+ && double(last(2)) >= 97 && double(last(2)) <= 122
+ str_a=last(1);%put appendix a,b,c, ou d
+ str_b=last(2);%put appendix a,b,c, ou d
+% indcur=indcur-3;
+ separ0=indsel(end-3);
+ num0=RootFile(separ0+1:separ1-1);
+ field_count=num0;
+ indcur=separ0;
+ nom_type='#_ab';
+ testsub=1;
+ end
+%search for other names with counter
+else
+ if length(ext)>1
+ num=1;count=0; % extract the numerical appendix
+ while num==1;
+ filascii=double(RootFile(indcur));
+ if (48>filascii)||(filascii>57); % select the non-numerical characters
+ num=0;
+ else
+ indcur=indcur-1; count=count+1;
+ end
+ end
+ if count~=0
+ field_count=RootFile(indcur+1:indcur+count);% set the selected field number'%03d'
+ if isequal(field_count(1),'0')
+ nbfigures=length(field_count);
+ nom_type=['%0' num2str(nbfigures) 'd'];
+ else
+ nom_type='#';
+ end
+ end
+ end
+end
+ %select the root name in the file_input window
+RootFile=RootFile(1:indcur);
+if nbchar<4% put '*' before the name (remove at the end)
+ RootFile(1:4-nbchar)=[];
+end
+if testsub
+ [RootPath,subdir,extdir]=fileparts(RootPath);
+ subdir=[subdir extdir];
+end
Index: /trunk/src/name_generator.m
===================================================================
--- /trunk/src/name_generator.m (revision 2)
+++ /trunk/src/name_generator.m (revision 2)
@@ -0,0 +1,284 @@
+%'name_generator': creates a file name from a root name and indices.
+%---------------------------------------------------------------------
+% [filename,idetect,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=...
+ % name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir);
+%---------------------------------------------------------------------
+% This function detects the existence the constructed file name and it can
+% find indices according to file existence if they are not specified
+%%rmq: this function is related to the reverse functions display2name and name2diplay
+%---------------------------------------------------------------------
+% OUTPUT:
+%filename: string representing the file name (including path)
+%idetect: =1 if the file is detected, 0 otherwise
+%num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out: index numbers and subdirectory detected
+ %for free input (= to the corresponding input indices when comp_input=1)
+%---------------------------------------------------------------------
+% INPUT:
+% 'filebase': the root name,
+% 'num_i1: first labelling index i
+% 'num_j1', first labelling index j
+% 'ext': file name extension (e.g. '.png' or '.nc')
+% 'nom_type': string defining the kind of nomenclature used:
+ %nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined)
+ %nom_type='*': the same file [filebase ext] contains successive fields (ex avi movies)
+ %nom_type='_i': series of files with a single index i preceded by '_'(e.g. 'aa_45.png').
+ %nom_type='#' series of indexed images wich is not series_i [filebase index ext], e.g. 'aa045.jpg' or 'aa45.tif'
+ %nom_type='_i_j' matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png')
+ %nom_type='_i1-i2' from pairs from a single index (e.g. 'aa_45-47.nc')
+ %nom_type='_i_j1-j2'pairs of j indices (e.g. 'aa_45_2-3.nc')
+ %nom_type='_i1-i2_j' pairs of i indices (e.g. 'aa_45-46_2.nc')
+ %nom_type='#a','#A' with a numerical index and an index letter(e.g.'aa045b.png'), OBSOLETE (replaced by 'series_i_j')
+ %nom_type='%03d' or '%04d', series of indexed images with numbers completed with zeros to 3 or 4 digits, e.g.'aa045.tif'
+ %nom_type='_%03d', '_%04d', or '_%05d', series of indexed images with _ and numbers completed with zeros to 3, 4 or 5 digits, e.g.'aa_045.tif'
+ %nom_type='raw_SMD', same as '#a' but with no extension ext='', OBSOLETE
+ %nom_type='#_ab' from pairs of '#a' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D')
+ %nom_type='%3dab' from pairs of '%3da' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D')
+% A REVOIR: 'comp_input'=1 for writting =0 for reading , 'comp_input'(for nom_type involving index pairs (e.g. netc))
+ %comp_input=1: the index pair is imposed,
+ %comp_input=0: the index pair is automatically searched, choosing the most recent file in case of multiple choice
+% 'num_i2': second index i (for nom_type involving index pairs (e.g. netc))
+% 'num_j2': second index j (for nom_type involving index pairs (e.g. netc))
+% 'subdir': (used for nom_type=netc...) string representing the name of the subdirectory 'subdir' containing file.
+ %subdir='': no subdirectory,
+ %subdir='?', the file is first searched with no subdirectory, then in the most recently modified subdirectory if not detected.
+
+% A FAIRE: si comp_inpu=0, si _i_j n'existe pas, chercher _i,
+function [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=...
+ name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir);
+sizf=size(filebase);
+if (~ischar(filebase)||~isequal(sizf(1),1)),filebase='';end
+if ~ischar(ext),ext='';end
+% filename=[filebase ext];%default
+idetect=0;
+if ~exist('num_i1','var') || isequal(num_i1,[])
+ num_i1=1; %default
+end
+if ~exist('num_j1','var') || isequal(num_j1,[])
+ num_j1=1; %default
+end
+if ~exist('num_i2','var') || isequal(num_i2,[])
+ num_i2=num_i1; %default
+end
+if ~exist('subdir','var')|| isempty(subdir)
+ subdir='' ; %default
+end
+%detection of mask or mean: filebase of the form [root '_' xxx 'm$$$'] with xxx a number and $$$ three characters
+% if length(filebase)>4 & filebase(end-3)=='m';
+% basedouble=double(filebase);
+% val=(48>basedouble)|(basedouble>57);% select the non-numerical characters
+% i=length(filebase)-4;
+% while val(i)==0 & i>0
+% i=i-1;
+% end
+% nbslice=str2num(filebase(i+1:end-4));
+% if ~isequal(nbslice,[])
+% num_i1=mod(num_i1-1,nbslice)+1; %take the rest in the division
+% if isequal(nom_type,'png_old')|isequal(nom_type,'#a')
+% num_j1=1;% mask name must end by 'a'
+% end
+% end
+% end
+test_pairs=isequal(nom_type,'netc_old')| isequal(nom_type,'netc_2D') | isequal(nom_type,'netc_3D')| isequal(nom_type,'_i1-i2_j1-j2')| ...
+ isequal(nom_type,'netc_series')| isequal(nom_type,'#_ab')| isequal(nom_type,'_i_j1-j2')| isequal(nom_type,'_i1-i2_j')| isequal(nom_type,'_i1-i2');
+test_2D= isequal(nom_type,'netc_old') |isequal(nom_type,'netc_2D')|isequal(nom_type,'#_ab') |isequal(nom_type,'_i_j1-j2');
+test_3D=isequal(nom_type,'netc_3D') |isequal(nom_type,'netc_series')| isequal(nom_type,'_i1-i2_j')| isequal(nom_type,'_i1-i2');
+if isequal(nom_type,'series_i')| isequal(nom_type,'_i');
+ filename=[filebase '_' num2str(num_i1) ext];
+ % idetect=(exist(filename,'file')==2);
+elseif length(nom_type)==5 && isequal(nom_type(1:3),'_%0')&& isequal(nom_type(5),'d');
+ filename=[filebase '_' num2str(num_i1,nom_type(2:5)) ext];
+ % idetect=(exist(filename,'file')==2);
+elseif isequal(nom_type,'series_i_j')| isequal(nom_type,'_i_j')
+ filename=[filebase '_' num2str(num_i1) '_' num2str(num_j1) ext];
+ % idetect=(exist(filename,'file')==2);
+elseif isequal(nom_type,'png_old')| isequal(nom_type,'#a')| isequal(nom_type,'#A')
+ filename=[filebase num2str(num_i1,'%03d') num2stra(num_j1,nom_type) ext];
+ % idetect=(exist(filename,'file')==2);
+elseif length(nom_type)>=5 & isequal(nom_type(2:3),'%0') & isequal(nom_type(5),'d') %isequal(nom_type,'_%04dA') %camera PCO Toulouse
+ filename=[filebase nom_type(1) num2str(num_i1,nom_type(2:4)) num2stra(num_j1,nom_type) ext];
+ % idetect=(exist(filename,'file')==2);
+elseif isequal(nom_type,'raw_SMD') %suffix a, b, c without extension
+ filename=[filebase num2str(num_i1,'%03d') num2stra(num_j1,nom_type)];
+% idetect=(exist(filename,'file')==2);
+elseif isequal(nom_type,'ima_num')| isequal(nom_type,'#')
+ filename=[filebase num2str(num_i1) ext];
+% idetect=(exist(filename,'file')==2);
+elseif length(nom_type)>=4 & isequal(nom_type(1:2),'%0') & isequal(nom_type(end),'d')
+ filename=[filebase num2str(num_i1,nom_type) ext]; %test number with a 0 before
+% idetect=(exist(filename,'file')==2);
+
+%case of derived file indexing (e.g. netcdf files)
+elseif test_pairs
+ if (~exist('num_j2','var')| isequal(num_j2,[])) & test_2D
+ num_j2=num_j1+1; %default if num_j2 undefined
+ end
+ if (~exist('num_i2','var')| isequal(num_i2,[])) & test_3D
+ num_i2=num_i1+1; %default if num_i2 undefined
+ end
+ filebasesub=filebase;
+ % get the root name filebasesub for the netcdf files
+ if ~isequal(subdir,'') && ~isequal(subdir,'?')
+ [Path,Name]=fileparts(filebase);
+ filebasesub=fullfile(Path,subdir,Name);
+ end
+ %inexistant pair if num_i2=0 or num_j2=0
+ if isequal(num_i2,0)
+ filename=[filebasesub '*-*_' num2str(num_i1) ext];
+ return
+ end
+ if isequal(num_j2,0)
+ filename=[filebasesub '_' num2str(num_i1) '_*-*' ext];
+ return
+ end
+ % case of an imposed image pair (comp_input=1)
+ if (exist('comp_input','var') & isequal(comp_input,1))
+ if isequal(nom_type,'netc_old')|isequal(nom_type,'#_ab')
+ if isequal(num2str(num_j1),num2str(num_j2))% case of displacements at the same time
+ filename=[filebasesub num2str(num_i1,'%03d') '_' num2stra(num_j1,nom_type) ext];
+ else
+ filename=[filebasesub num2str(num_i1,'%03d') '_' num2stra(num_j1,nom_type) num2stra(num_j2,nom_type) ext];
+ end
+ elseif isequal(nom_type,'netc_2D')|isequal(nom_type,'_i_j1-j2')
+ if isequal(num2str(num_j1),num2str(num_j2))% case of displacements at the same time
+ filename=[filebasesub '_' num2str(num_i1) '_' num2str(num_j1) ext];
+ else
+ filename=[filebasesub '_' num2str(num_i1) '_' num2str(num_j1) '-' num2str(num_j2) ext];
+ end
+ elseif isequal(nom_type,'netc_3D') || isequal(nom_type,'_i1-i2_j')
+ if isequal(num2str(num_i1),num2str(num_i2))% case of displacements at the same time
+ filename=[filebasesub '_' num2str(num_i1) '_' num2str(num_j1) ext];
+ else
+ filename=[filebasesub '_' num2str(num_i1) '-' num2str(num_i2) '_' num2str(num_j1) ext];
+ end
+ elseif isequal(nom_type,'netc_series') || isequal(nom_type,'_i1-i2')
+ if isequal(num2str(num_i1),num2str(num_i2))% case of displacements at the same time
+ filename=[filebasesub '_' num2str(num_i1) ext];
+ else
+ filename=[filebasesub '_' num2str(num_i1) '-' num2str(num_i2) ext];
+ end
+ elseif isequal(nom_type,'_i1-i2_j1-j2')
+ if isequal(num2str(num_i1),num2str(num_i2))% case of displacements at the same time
+ app1= [num2str(num_i1)];
+ else
+ app1= [num2str(num_i1) '-' num2str(num_i2)];
+ end
+ if isequal(num2str(num_j1),num2str(num_j2))% case of displacements at the same time
+ app2= [num2str(num_j1)];
+ else
+ app2= [num2str(num_j1) '-' num2str(num_j2)];
+ end
+ filename=[filebasesub '_' app1 '_' app2 ext];
+ end
+ idetect=1;
+ % idetect=(exist(filename,'file')==2);
+ % case of an image pair to determine (comp_input=0)
+ else
+ [filename,num_i1,num_j1,num_i2,num_j2,idetect]=search_pair(filebasesub,num_i1,num_j1,num_i2,nom_type);
+ end
+
+ %look for sub-directories containing netcdf files
+ if idetect==0 && isequal(subdir,'?')
+ [pathfile,name]=fileparts(filebase);
+ direct=dir(pathfile);%directory containing filebase
+ datedir=[];%default
+ idir=0;
+ indir=find(cell2mat({direct.isdir}));% find indices of subdirectories
+ direct=direct(indir([3:end]));% keep only the subdirectories,eliminating the two first terms '.' and '..'
+ lengthdir=length(direct);
+ if lengthdir==0
+ subdir='';% no subdirectory found
+ else
+ for idir=1:lengthdir
+ date_str=direct(idir).date;%string of the date of last modification
+ datedir(idir)=0;%default
+ char_code=double(date_str);% code of the date characters
+ special_char=(char_code>127); %non standard Ascii character (e.g. date in french)
+ if isempty(find(special_char))% standard Ascii character
+ datedir(idir)=datenum(date_str);
+ end
+% datedir(idir)=datenum(direct(idir).date); %absolute date of last directory modification
+ end
+ [mostrec,indrec]=max(datedir);% most recently modified subdir chosen by default
+ subdir=direct(indrec).name; %chosen directory
+ end
+ filebasesub=fullfile(pathfile,subdir,name);
+ %if the image pair is imposed
+ if (exist('comp_input','var') & isequal(comp_input,1))
+ if isequal(nom_type,'netc_old')|isequal(nom_type,'#_ab')
+ filename=[filebasesub num2str(num_i1,'%03d') '_' num2stra(num_j1,nom_type) num2stra(num_j2,nom_type) ext];
+ elseif isequal(nom_type,'netc_2D')|isequal(nom_type,'_i1_j1-j2')
+ filename=[filebasesub '_' num2str(num_i1) '_' num2str(num_j1) '-' num2str(num_i2) ext];
+ elseif isequal(nom_type,'netc_3D')|isequal(nom_type,'_i1-i2_j')
+ filename=[filebasesub '_' num2str(num_i1) '-' num2str(num_i2) '_' num2str(num_j1) ext];
+ elseif isequal(nom_type,'netc_series')|isequal(nom_type,'_i1-i2')
+ filename=[filebasesub '_' num2str(num_i1) '-' num2str(num_i2) ext];
+ end
+ idetect=(exist(filename,'file')==2);
+ else
+ [filename,num_i1,num_j1,num_i2,num_j2,idetect]=search_pair(filebasesub,num_i1,num_j1,num_i2,nom_type);
+ end
+ end
+% elseif isequal(nom_type,'none')|isequal(nom_type,'')|isequal(nom_type,'*')
+else
+ filebasesub=filebase;
+ if ~isequal(subdir,'') && ~isequal(subdir,'?')
+ [Path,Name]=fileparts(filebase);
+ filebasesub=fullfile(Path,subdir,Name);
+ end
+ filename=[filebasesub ext];
+ idetect=(exist(filename,'file')==2);
+end
+num_i1_out=num_i1;
+num_j1_out=num_j1;
+if exist('num_i2','var'), num_i2_out=num_i2; else, num_i2_out=[]; end;
+if exist('num_j2','var'), num_j2_out=num_j2; else, num_j2_out=[]; end;
+if ~isequal(subdir,'?'), subdir_out=subdir; else, subdir_out='';end;
+
+%---------------------------------------------------------------
+% search the appropriate image pair (netcdf file) corresponding to a given
+% image number
+%-------------------------------------------------------------------
+function [filename,num_i1,num_j1,num_i2,num_j2,idetect]=search_pair(filebasesub,num_i1,num_j1,num_i2,nom_type)
+% for nom_type=netc_2D or netc_old, it searches all the pairs corresponding
+% to num_i1, and chooses the most recent file.
+%for nom_type=netc_3D or netc_series, it searches all the pairs (num_i1
+%num_i2), with num_i1 as the first index, and chooses the most recent file.
+
+filename=[];num_j2=[];idetect=0;%default values
+if isequal(nom_type,'netc_old')|isequal(nom_type,'#_ab')
+ dirpair=dir([filebasesub num2str(num_i1,'%03d') '_*.nc']);
+elseif isequal(nom_type,'netc_2D')|isequal(nom_type,'_i_j1-j2')
+ dirpair=dir([filebasesub '_' num2str(num_i1) '_*-*.nc']);
+elseif isequal(nom_type,'netc_3D')|isequal(nom_type,'_i1-i2_j')
+ dirpair=dir([filebasesub '_' num2str(num_i1) '-*_' num2str(num_j1) '.nc']);
+elseif isequal(nom_type,'netc_series')|isequal(nom_type,'_i1-i2')
+ dirpair=dir([filebasesub '_' num2str(num_i1) '-*.nc']);
+ if isempty(dirpair)
+ dirpair=dir([filebasesub '_*-' num2str(num_i2) '.nc']);
+ end
+end
+nbpair=length(dirpair);
+if nbpair >= 1 %choose the most recent file if several are found
+ idetect=1; %detected pair
+ for ipair=1:nbpair
+ date_str=dirpair(ipair).date;%string of the date of last modification
+ datepair(ipair)=0;%default
+ char_code=double(date_str);% code of the date characters
+ special_char=(char_code>127); %non standard Ascii character (e.g. date in french)
+ if isempty(find(special_char))% standard Ascii character
+ datepair(ipair)=datenum(date_str);
+ end
+ % datepair(ipair)=datenum(dirpair(ipair).date);
+ end
+ [choice,indpair]=max(datepair);
+% [filebase,field_count,str2,str_a,str_b,ext,nom_type]=name2display(dirpair(indpair).name);
+ [pathname,file,field_count,str2,str_a,str_b,ext,nom_type]=name2display(dirpair(indpair).name);
+ num_i1=str2num(field_count);
+ num_i2=str2num(str2);
+ num_j1=stra2num(str_a);
+ num_j2=stra2num(str_b);
+ pathname=fileparts(filebasesub);% CORRIGE LE 6 JUIN (ETAIT DESACTIVE)
+ filename=fullfile(pathname,dirpair(indpair).name);
+end
+
+
Index: /trunk/src/nc2struct.m
===================================================================
--- /trunk/src/nc2struct.m (revision 2)
+++ /trunk/src/nc2struct.m (revision 2)
@@ -0,0 +1,269 @@
+%'nc2struct': transform a netcdf file in a corresponding matlab structure
+% it reads all the global attributes and all variables, or a selected list.
+% The corresponding dimensions and variable attributes are then extracted
+%%%%%% TODO: add the possibility to read only attributes, see nc2struct_toolbox %%%
+%----------------------------------------------------------------------
+% function [Data,var_detect,ichoice]=nc2struct(nc,ListVarName)
+%
+% OUTPUT:
+% Data: structure containing all the information of the netcdf file (or netcdf object)
+% with fields:
+% .ListGlobalAttribute: cell listing the names of the global attributes
+% .Att_1,Att_2... : values of the global attributes
+% .ListDimName: cell listing the names of the array dimensions
+% .DimValue: array dimension values (Matlab vector with the same length as .ListDimName
+% .ListVarName: cell listing the names of the variables
+% .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName
+% .VarDimName: cell containing a cell of dimension names (in list .ListDimName) for each variable of .ListVarName
+% .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
+% .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
+% var_detect: vector with same length as ListVarName, with 1 for each detected variable and 0 else.
+% ichoice: = line
+%
+%INPUT:
+% nc: name of a netcdf file (char string) or netcdf object
+% ListVarName: optional list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} )
+% if ListVarName=[] or {}, no variables is read (only global attributes and lists of dimensions, variables and attriburtes)
+% if ListVarName is absent, or = '*', ALL the variables are read.
+% if ListVarName is a cell array with n lines, the set of variables
+% will be sought by order of priority in the list, while output names will be set by the first line
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function [Data,var_detect,ichoice]=nc2struct(nc,varargin)
+List=varargin;
+if nargin==0
+ List{1}='*';
+end
+% if ~exist('ListVarName','var')
+% ListVarName='*';
+% end
+hhh=which('netcdf.open');% look for built-in matlab netcdf library
+
+if ~isequal(hhh,'')
+ %default output
+ Data=[];
+ var_detect=[];
+ ichoice=[];%default
+ %open the netcdf file for reading
+ if ischar(nc)
+ if exist(nc,'file')
+ nc=netcdf.open(nc,'NC_NOWRITE');
+ testfile=1;
+ else
+ Data.Txt=['ERROR:file ' nc ' does not exist'];
+ return
+ end
+ else
+ testfile=0;
+ end
+ % short reading of global attributes
+ if isequal(List{1},'ListGlobalAttribute')
+ for ilist=2:numel(List)
+ valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),List{ilist});
+ eval(['Data.' List{ilist} '=valuestr;'])
+ end
+ netcdf.close(nc)
+ return
+ end
+
+ % reading of variables, including attributes
+ ListVarName=List{1};
+ [ndims,nvars,ngatts]=netcdf.inq(nc);%nbre of dimensions, variables, attributes
+
+ % -------- read global attributes (constants)-----------
+ att_key={};%default
+ iatt_g=0;
+ Data.ListGlobalAttribute={};%default
+ for iatt=1:ngatts
+ keystr= netcdf.inqAttName(nc,netcdf.getConstant('NC_GLOBAL'),iatt-1);
+ indstr1=regexp(keystr,'\\');%detect '\\'
+ indstr2=regexp(keystr,'\.');%detect '\.'
+ if isempty(indstr1) && isempty(indstr2)
+ valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),keystr);
+ if ischar(valuestr) && length(valuestr)<200
+ iatt_g=iatt_g+1;
+ indstr1=regexp(keystr,'\\');%detect '\\'
+ indstr2=regexp(keystr,'\.');%detect '\.'
+ if isempty(indstr1) && isempty(indstr2)
+ eval(['Data.' keystr '=''' valuestr ''';'])
+ att_key{iatt_g}=keystr;
+ end
+ elseif isempty(valuestr)
+ iatt_g=iatt_g+1;
+ eval(['Data.' keystr '=[];'])
+ att_key{iatt_g}=keystr;
+ elseif isnumeric(valuestr)
+ iatt_g=iatt_g+1;
+ eval(['Data.' keystr '=valuestr;'])
+ att_key{iatt_g}=keystr;
+ end
+ end
+ end
+ Data.ListGlobalAttribute=att_key;
+
+ % -------- read dimensions -----------
+ dim_name={};
+ dim_value=[];
+ for idim=1:ndims%length(dim_read);
+ [dim_name{idim},dim_value(idim)] = netcdf.inqDim(nc,idim-1);
+ end
+ if ~isempty(dim_name) && ~isempty(dim_value)
+ Data.ListDimName=dim_name;
+ Data.DimValue=dim_value;
+% DimIndices=[1:ndims]; %index of the dimension in the netcdf file
+ dim_used=zeros(1,ndims);%initialize test of used dimensions
+ end
+
+ % -------- read variables -----------
+ var_read={}; %default
+ dimids={};
+ nbatt=[];
+ for ivar=1:nvars
+ [var_read{ivar},xtype,dimids{ivar},nbatt(ivar)] = netcdf.inqVar(nc,ivar-1);
+ end
+ var_index=1:nvars; %default set of variable indices in the netcdf file
+ testmulti=0;
+ OutputList=[];
+ %select input variables, if requested by the input ListVarName
+ if ~(isequal(ListVarName,'*')||isempty(ListVarName))
+ sizvar=size(ListVarName);
+ testmulti=(sizvar(1)>1);
+ var_index=zeros(1,sizvar(2));%default
+ if testmulti
+ OutputList=ListVarName(1,:);
+ testend=0;
+ for iline=1:sizvar(1)
+ if testend
+ break
+ end
+ % var_index=zeros(size(ListVarName));%default
+ for ivar=1:sizvar(2)
+ if ~isempty(ListVarName{iline,ivar})
+ for ilist=1:nvars
+ if isequal(var_read{ilist},ListVarName{iline,ivar})
+ var_index(ivar)=ilist;
+ % var_detect(ivar)=1;
+ break
+ end
+ end
+ if ivar==1
+ if var_index(ivar)==0
+ break%go to next line if the first nc variable is not found
+ else
+ testend=1; %this line will be read
+ ichoice=iline-1; %selectedline number in the list of input names of variables
+ end
+ end
+ end
+ end
+ end
+ else %single list of input variables
+ for ivar=1:sizvar(2)
+ for ilist=1:nvars
+ if isequal(var_read{ilist},ListVarName{ivar})
+ var_index(ivar)=ilist;
+ var_detect(ivar)=1;
+ break
+ end
+ end
+ end
+ end
+ list_index=find(var_index);
+ if ~isempty(list_index)
+ if testmulti
+ OutputList=OutputList(list_index);
+ end
+ var_index=var_index(list_index);
+ var_detect=(var_index~=0);
+ var_read=var_read(var_index);
+ end
+ end
+
+
+ %select variable attributes and associate dimensions
+% var_dim_index=[]; %default
+ Data.ListVarName={};%default
+ VarDimIndex={};%default
+ for ivar=1:length(var_read)
+ if testmulti
+ Data.ListVarName{ivar}=OutputList{ivar};%new name given by ListVarName(1,:)
+ else
+ Data.ListVarName{ivar}=var_read{ivar};%name of the variable
+ end
+ var_dim=dimids{var_index(ivar)}+1; %dimension indices used by the variable
+ dim_used(var_dim)=ones(size(var_dim));
+ VarDimIndex{ivar}=var_dim;
+
+ %variable attributes
+ if ivar==1
+ Data.VarAttribute={};%initialisation of the list of variable attributes
+ end
+ %variable attributes
+ for iatt=1:nbatt(var_index(ivar))
+ attname = netcdf.inqAttName(nc,var_index(ivar)-1,iatt-1);
+ valuestr= netcdf.getAtt(nc,var_index(ivar)-1,attname);
+ if ischar(valuestr)
+ eval(['Data.VarAttribute{ivar}.' attname '=''' valuestr ''';'])
+ elseif isempty(valuestr)
+ eval(['Data.VarAttribute{ivar}.' attname '=[];'])
+ elseif isnumeric(valuestr)
+ eval(['Data.VarAttribute{ivar}.' attname '=valuestr;'])
+ end
+ end
+ end
+
+ %select the used dimensions
+ if isempty(var_read)
+ if isfield(Data,'ListDimName') && isfield(Data,'DimValue')
+ Data=rmfield(Data,'ListDimName');
+ Data=rmfield(Data,'DimValue');
+ end
+ else
+% list_dim=1:ndims;
+ dim_index=find(dim_used);
+% list_dim=list_dim(dim_index);
+ old2new=cumsum(dim_used);
+ Data.ListDimName=Data.ListDimName(dim_index);
+ Data.DimValue=Data.DimValue(dim_index);
+ end
+ for ivar=1:length(var_read)
+ Data.VarDimIndex{ivar}=old2new(VarDimIndex{ivar});% ENLEVER Data.VarDimIndex ulterieurement
+ Data.VarDimName{ivar}=Data.ListDimName(Data.VarDimIndex{ivar});
+ end
+ %variable values
+ if ~isempty(ListVarName)
+ for ivar=1:length(Data.ListVarName)
+ VarName=Data.ListVarName{ivar};
+ indstr=regexp(VarName,'-');%detect '-'
+ if ~isempty(indstr)
+ VarName(indstr)=[];
+ end
+ eval(['Data.' VarName '=netcdf.getVar(nc,var_index(ivar)-1);'])%read the variable data
+ eval(['siz=size(Data.' VarName ');'])
+ if numel(siz)<=2
+ eval(['Data.' VarName '=Data.' VarName ''';'])%read the variable data
+ end
+ end
+ end
+ % -------- close fle-----------
+ if testfile==1
+ netcdf.close(nc)
+ end
+else
+ [Data,var_detect,ichoice]=nc2struct_toolbox(nc,varargin);
+end
Index: /trunk/src/nc2struct_toolbox.m
===================================================================
--- /trunk/src/nc2struct_toolbox.m (revision 2)
+++ /trunk/src/nc2struct_toolbox.m (revision 2)
@@ -0,0 +1,260 @@
+%'nc2struct_toolbox': transform a netcdf file in a corresponding matlab structure, USE OLD NETCDF LIBRARY
+%----------------------------------------------------------------------
+% function [Data,var_detect,ichoice]=nc2struct_toolbox(nc,ListField)
+%
+% OUTPUT:
+% Data: structure containing all the information of the netcdf file (or netcdf object)
+% with fields:
+% .ListGlobalAttribute: cell listing the names of the global attributes
+% .Att_1,Att_2... : values of the global attributes
+% .ListDimName: cell listing the names of the array dimensions
+% .DimValue: array dimension values (Matlab vector with the same length as .ListDimName
+% .ListVarName: cell listing the names of the variables
+% .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName
+% .VarDimName: cell containing a cell of dimension names (in list .ListDimName) for each variable of .ListVarName
+% .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
+% .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
+% var_detect: vector with same length as ListVarName, with 1 for each detected variable and 0 else.
+% ichoice: = line
+%
+%INPUT:
+% nc: name of a netcdf file (char string) or netcdf object
+% ListField: optional list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} )
+% if ListField is absent or ='*', ALL the attributes and variables are read. %
+% if ListField='ListGlobalAttribute', followed by the arguments 'name1', name2'..., only thes global attributes will be read (short option)
+% if ListField=[] or{}, no variables is read (only global attributes and lists of vdimensions, variables and attriburtes)
+% if ListField is a cell array with n lines, the set of variables
+% will be sought by order of priority in the list, while output names will be set by the first line
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function [Data,var_detect,ichoice]=nc2struct_toolbox(nc,varargin)
+
+List=varargin{1};
+%default output
+Data=[];
+var_detect=[];
+ichoice=[];%default
+
+%open the netcdf file for reading
+if ischar(nc)
+ if exist(nc,'file') % rmq: time for exist search = 0.5 ms CPU
+ nc=netcdf(nc,'nowrite'); % rmq: time needed for opening = 2 ms CPU
+ testfile=1;
+ else
+ Data.Txt=['ERROR:file ' nc ' does not exist'];
+ return
+ end
+else
+ testfile=0;
+end
+
+% short reading of global attributes
+if ~isempty(List) && isequal(List{1},'ListGlobalAttribute')
+ for ilist=2:numel(List)
+ att_str=List{ilist};
+ eval(['Data.' att_str '=nc.' att_str '(:);'])
+ end
+ close(nc)
+ %total time from beginning : 15 ms for a single attribute
+ return
+end
+
+% reading of variables, including attributes
+if isempty(List)
+ ListVarName='*';
+else
+if isempty(List{1})
+ ListVarName='*';
+else
+ ListVarName=List{1};
+end
+end
+% -------- read global attributes -----------
+att_read=att(nc);%cell of 'global attributes' (nc objects), CPU time 30 ms
+att_key={};%default
+iatt_g=0;
+for iatt=1:length(att_read)
+ aa=att_read{iatt};
+ keystr=name(aa);
+ indstr1=regexp(keystr,'\\');%replace dots'
+ indstr2=regexp(keystr,'\.');%replace dots'
+ if ~isequal(keystr,'title') % PROBLEM WITH civx files do not read 'title'
+ if isempty(indstr1) && isempty(indstr2) %
+ eval(['valuestr=nc.' keystr '(:);'])
+ if ischar(valuestr) && length(valuestr)<200
+ iatt_g=iatt_g+1;
+ indstr1=regexp(keystr,'\\');%replace dots'
+ indstr2=regexp(keystr,'\.');%replace dots'
+ if isempty(indstr1) && isempty(indstr2)
+ eval(['Data.' keystr '=''' valuestr ''';'])
+ att_key{iatt_g}=keystr;
+ end
+ elseif isempty(valuestr)
+ iatt_g=iatt_g+1;
+ eval(['Data.' keystr '=[];'])
+ att_key{iatt_g}=keystr;
+ elseif isnumeric(valuestr)
+ iatt_g=iatt_g+1;
+ eval(['Data.' keystr '=valuestr;'])
+ att_key{iatt_g}=keystr;
+ end
+ end
+ end
+end
+Data.ListGlobalAttribute=att_key;
+nbattr=length(att_key);
+neworder=[nbattr+1 (1:nbattr)];
+Data=orderfields(Data,neworder);
+
+% -------- read dimensions -----------
+dim_read=dim(nc);%cell of variable dimension names (nc objects): CPU time 0.0013
+dim_name={};
+dim_value=[];
+for idim=1:length(dim_read);
+ aa=dim_read{idim};
+ if ~isempty(aa)
+ dim_name{idim}=name(aa);
+ dim_value(idim)=length(aa);
+ end
+end
+if ~isempty(dim_name) && ~isempty(dim_value)
+ Data.ListDimName=dim_name;
+ Data.DimValue=dim_value;
+ used=zeros(1,length(dim_value));%initialize test of used dimensions
+end
+
+% -------- read variables -----------
+var_read={}; %default
+testmulti=0;
+OutputList=[];
+if isequal(ListVarName,'*')%|| isempty(ListVarName)
+ var_read=var(nc);%cell of all variables
+elseif ~isempty(ListVarName)
+ sizvar=size(ListVarName);
+ testmulti=(sizvar(1)>1);
+ if testmulti
+ OutputList=ListVarName(1,:);
+ testend=0;
+ for iline=1:sizvar(1)
+ if testend
+ break
+ end
+ for ivar=1:sizvar(2)
+ var_read{ivar}=[];%default
+ var_detect(ivar)=0;%default
+ VarName=ListVarName{iline,ivar};
+ if ~isempty(VarName)
+ var_read{ivar}=nc{VarName};%select the input variable names
+ if ivar==1
+ if isempty (var_read{ivar})
+ break%go to next line if the first nc variable is not found
+ else
+ testend=1; %this line will be read
+ ichoice=iline-1; %selectedline number in the list of input names of variables
+ var_detect(ivar)=1;
+ end
+ else
+ var_detect(ivar)=~isempty (var_read{ivar});
+ end
+ end
+ end
+ end
+ if ~isempty(find(var_detect,1))
+ OutputList=OutputList(find(var_detect));
+ end
+ else %single list of input variables
+ var_detect=ones(size(ListVarName));
+ for ivar=1:sizvar(2)
+ var_read{ivar}=nc{ListVarName{ivar}};%select the input variable names
+ var_detect(ivar)=~isempty(var_read{ivar});
+ end
+ end
+ var_read=var_read(find(var_detect));
+end
+
+% var_dim_index=[]; %default
+Data.ListVarName={};%default
+for ivar=1:length(var_read)
+ vv=var_read{ivar};
+ Data.ListVarName{ivar}=name(vv);%name of the variable
+ if testmulti
+ Data.ListVarName{ivar}=OutputList{ivar};
+ else
+ Data.ListVarName{ivar}=name(vv);%name of the variable
+ end
+ var_dim=dim(vv);%dimension netcdf object of the variable
+ for ivardim=1:length(var_dim)
+ var_dim_name=name(var_dim{ivardim});%name of the dimension
+ for idim=1:length(dim_name)% find the index of the current dimension in the list of dimensions
+ if isequal(dim_name{idim},var_dim_name)
+ Data.VarDimIndex{ivar}(ivardim)=idim;
+ used(idim)=1;
+ break
+ end
+ end
+ end
+ Data.VarDimName{ivar}={};
+ %variable attributes
+ Data.VarAttribute{ivar}=[];%initialisation of the list of variable attributes
+ %variable attributes
+ att_read=att(vv);
+ for iatt=1:length(att_read)
+ aa=att_read{iatt};
+ eval(['valuestr=vv.' name(aa) '(:);'])
+ if ischar(valuestr)
+ eval(['Data.VarAttribute{ivar}.' name(aa) '=''' valuestr ''';'])
+ elseif isempty(valuestr)
+ eval(['Data.VarAttribute{ivar}.' name(aa) '=[];'])
+ elseif isnumeric(valuestr)
+ eval(['Data.VarAttribute{ivar}.' name(aa) '=valuestr;'])
+ end
+ end
+end
+
+%select the used dimensions
+if isempty(var_read)
+ if isfield(Data,'ListDimName') && isfield(Data,'DimValue')
+ Data=rmfield(Data,'ListDimName');
+ Data=rmfield(Data,'DimValue');
+ end
+else
+ old_dim_index=find(used); %dimension indices which are used by the selected variables
+ old2new=cumsum(used);
+ Data.ListDimName=Data.ListDimName(old_dim_index);
+ Data.DimValue=Data.DimValue(old_dim_index);
+end
+for ivar=1:length(var_read)
+ Data.VarDimIndex{ivar}=(old2new(Data.VarDimIndex{ivar}));
+ Data.VarDimName{ivar}=(Data.ListDimName(Data.VarDimIndex{ivar}));
+end
+%variable values
+
+if ~isempty(ListVarName)
+ for ivar=1:length(Data.ListVarName)
+ vv=var_read{ivar};
+ vdata=vv(:);%data array of the field variable
+ eval(['Data.' Data.ListVarName{ivar} '=vdata;'])%read the variable data
+ end
+end
+% -------- close fle-----------
+if testfile==1
+ close(nc)
+end
+
+%total time from beginning : 150 ms for a full civ2 field, 65 ms for four fields
+
Index: /trunk/src/nomtype2pair.m
===================================================================
--- /trunk/src/nomtype2pair.m (revision 2)
+++ /trunk/src/nomtype2pair.m (revision 2)
@@ -0,0 +1,70 @@
+%'nomtype2pair': creates nomencalture for index pairs.
+%---------------------------------------------------------------------
+% [nom_type_nc]=nomtype2pair(nom_type);
+%---------------------------------------------------------------------
+% This function detects the existence the constructed file name and it can
+% find indices according to file existence if they are not specified
+%%rmq: this function is related to the reverse functions display2name and name2diplay
+%---------------------------------------------------------------------
+% OUTPUT:
+%nom_type_nc
+
+%---------------------------------------------------------------------
+% INPUT:
+% 'nom_type': string defining the kind of nomenclature used:
+ %nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined)
+ %nom_type='*': the same file [filebase ext] contains successive fields (ex avi movies)
+ %nom_type='_i': series of files with a single index i preceded by '_'(e.g. 'aa_45.png').
+ %nom_type='#' series of indexed images wich is not series_i [filebase index ext], e.g. 'aa045.jpg' or 'aa45.tif'
+ %nom_type='_i_j' matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png')
+ %nom_type='_i1-i2' from pairs from a single index (e.g. 'aa_45-47.nc')
+ %nom_type='_i_j1-j2'pairs of j indices (e.g. 'aa_45_2-3.nc')
+ %nom_type='_i1-i2_j' pairs of i indices (e.g. 'aa_45-46_2.nc')
+ %nom_type='#a','#A', with a numerical index and an index letter(e.g.'aa045b.png'), OBSOLETE (replaced by 'series_i_j')
+ %nom_type='%03d' or '%04d', series of indexed images with numbers completed with zeros to 3 or 4 digits, e.g.'aa045.tif'
+ %nom_type='_%03d', '_%04d', or '_%05d', series of indexed images with _ and numbers completed with zeros to 3, 4 or 5 digits, e.g.'aa_045.tif'
+ %nom_type='raw_SMD', same as '#a' but with no extension ext='', OBSOLETE
+ %nom_type='#_ab' from pairs of '#a' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D')
+ %nom_type='%3dab' from pairs of '%3da' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D')
+% Dti: ~=0 if i index pairs are used
+% Dtj: ~=0 if i index pairs are used
+
+function [nom_type_pair]=nomtype2pair(nom_type,Dti,Dtj);
+
+%determine nom_type_nc:
+nom_type_nc=[];%default
+switch nom_type
+ case {'_i_j'}
+ if Dtj>0 || Dtj<0
+ nom_type_pair='_i_j1-j2';
+ if Dti>0 || Dti<0
+ nom_type_pair='_i1-i2_j1-j2';
+ end
+ elseif Dti>0 || Dti<0
+ nom_type_pair='_i1-i21_j';
+ else
+ nom_type_pair='_i_j';
+ end
+ case {'_i1-i2_j'}
+ if Dtj>0 || Dtj<0
+ nom_type_pair='_i1-i2_j1-j2';
+ else
+ nom_type_pair='_i1-i2_j';
+ end
+ case {'i_j1-j2'}
+ if Dti>0 || Dti<0
+ nom_type_pair='_i1-i2_j1-j2';
+ else
+ nom_type_pair='_i1-i2_j';
+ end
+ case {'i1-i2_j1-j2'}
+ nom_type_pair='_i1-i2_j1-j2';
+ case '#a'
+ if Dtj>0 || Dtj<0
+ nom_type_pair='#_ab';
+ end
+ otherwise
+ if Dti>0 || Dti<0
+ nom_type_pair='_i1-i2';
+ end
+end
Index: /trunk/src/num2stra.m
===================================================================
--- /trunk/src/num2stra.m (revision 2)
+++ /trunk/src/num2stra.m (revision 2)
@@ -0,0 +1,41 @@
+%'num2stra': transform number to the corresponding character string depending on the nomenclature
+%--------------------------------------------
+% function str=num2stra(num,nom_type)
+%
+% OUTPUT:
+% str: character string
+%
+% INPUT:
+% num: input number (file index)
+% nom_type: nomencalture type (see fct name_generator)
+%
+% see also: stra2num, name_generator, name2display
+
+function str=num2stra(num,nom_type,index);
+if ~exist('index','var')
+ index=2; %index 1 or 2 of the file indices
+end
+switch index
+ case 1
+ if length(nom_type)>=4 && isequal(nom_type(1:2),'%0') && isequal(nom_type(4),'d')
+ str=num2str(num,nom_type(1:4));
+ else
+ str=num2str(num);
+ end
+ case 2
+ if isempty(nom_type)
+ nom_type='none';
+ end
+ if isequal(nom_type,'png_old') || isequal(nom_type,'netc_old') || isequal(nom_type,'raw_SMD')||...
+ isequal(nom_type(end),'a')||isequal(nom_type(end),'b')
+ str=char(96+num);
+ elseif isequal(nom_type(end),'A')|isequal(nom_type(end),'B')
+ str=char(64+num);
+ elseif isequal(nom_type,'series_i')|isequal(nom_type,'netc_series')...
+ |isequal(nom_type,'ima_num')| isequal(nom_type,'avi')| isequal(nom_type,'none')...
+ isequal(nom_type,'_i')|isequal(nom_type,'_i1-i2')
+ str='';
+ else
+ str=num2str(num);
+ end
+end
Index: /trunk/src/parseXML.m
===================================================================
--- /trunk/src/parseXML.m (revision 2)
+++ /trunk/src/parseXML.m (revision 2)
@@ -0,0 +1,70 @@
+% PARSEXML Convert XML file to a MATLAB structure. (from matlab help)
+function theStruct = parseXML(filename)
+
+try
+ tree = xmlread(filename);
+catch
+ error('Failed to read XML file %s.',filename);
+end
+
+% Recurse over child nodes. This could run into problems
+% with very deeply nested trees.
+try
+ theStruct = parseChildNodes(tree);
+catch
+ error('Unable to parse XML file %s.');
+end
+
+
+% ----- Subfunction PARSECHILDNODES -----
+function children = parseChildNodes(theNode)
+% Recurse over node children.
+children = [];
+if theNode.hasChildNodes
+ childNodes = theNode.getChildNodes;
+ numChildNodes = childNodes.getLength;
+ allocCell = cell(1, numChildNodes);
+
+ children = struct( ...
+ 'Name', allocCell, 'Attributes', allocCell, ...
+ 'Data', allocCell, 'Children', allocCell);
+
+ for count = 1:numChildNodes
+ theChild = childNodes.item(count-1);
+ children(count) = makeStructFromNode(theChild);
+ end
+end
+
+% ----- Subfunction MAKESTRUCTFROMNODE -----
+function nodeStruct = makeStructFromNode(theNode)
+% Create structure of node info.
+
+nodeStruct = struct( ...
+ 'Name', char(theNode.getNodeName), ...
+ 'Attributes', parseAttributes(theNode), ...
+ 'Data', '', ...
+ 'Children', parseChildNodes(theNode));
+
+if any(strcmp(methods(theNode), 'getData'))
+ nodeStruct.Data = char(theNode.getData);
+else
+ nodeStruct.Data = '';
+end
+
+% ----- Subfunction PARSEATTRIBUTES -----
+function attributes = parseAttributes(theNode)
+% Create attributes structure.
+
+attributes = [];
+if theNode.hasAttributes
+ theAttributes = theNode.getAttributes;
+ numAttributes = theAttributes.getLength;
+ allocCell = cell(1, numAttributes);
+ attributes = struct('Name', allocCell, 'Value', allocCell);
+
+ for count = 1:numAttributes
+ attrib = theAttributes.item(count-1);
+ attributes(count).Name = char(attrib.getName);
+ attributes(count).Value = char(attrib.getValue);
+ end
+end
Index: /trunk/src/peaklock.m
===================================================================
--- /trunk/src/peaklock.m (revision 2)
+++ /trunk/src/peaklock.m (revision 2)
@@ -0,0 +1,197 @@
+%'peaklock': determines peacklocking errors from velocity histograms.
+%-------------------------------------------------------
+%first smooth the input histogram 'histu' in such a way that the integral over
+%n-n+1 is preserved, then deduce the peaklocking 'error' function of the pixcel displacement 'x'.
+%
+% [histinter,x,error]=peaklock(nbb,minim,maxim,histu)
+%OUTPUT:
+%histinter: smoothed interpolated histogram
+% x: vector of displacement values.
+% error: vector of estimated errors corresponding to x
+%INPUT:
+%histu=vector representing the values of histogram of measured velocity ;
+%minim, maxim: extremal values of the measured velocity (absica for histu)
+%nbb: number of bins inside each integer interval for the histograms
+%SUBROUTINES INCLUDED:
+%spline4.m% spline interpolation at 4th order
+%splinhist.m: give spline coeff cc for a smooth histo (call spline4)
+%histsmooth.m(x,cc): calculate the smooth histo for any value x
+%histder.m(x,cc): calculate the derivative of the smooth histo
+function [histinter,x,error]=peaklock(nbb,minim,maxim,histu)
+
+nint=maxim-minim+1
+xfin=[minim-0.5+1/(2*nbb):(1/nbb):maxim+0.5-(1/(2*nbb))];
+histo=(reshape(histu,nbb,nint));%extract values with x between integer -1/2 integer +1/2
+Integ=sum(histo)/nbb; %integral of the pdf on each integer bin
+[histinter,cc]=splinhist(Integ,minim,nbb);
+histx=reshape(histinter,nbb,nint);
+xint=[minim:1:maxim];
+x=zeros(nbb,nint);
+%determination of the displacement x(j,:)
+%j=1
+delx=histo(1,:)./histsmooth(-0.5*ones(1,nint),cc)/nbb;
+%del(1,:)=delx;
+x(1,:)=-0.5+delx-(delx.*delx/2).*histder(-0.5*ones(1,nint),cc);
+%histx(1,:)=histsmooth(x(j-1,:),cc);
+for j=2:nbb
+ delx=histo(j,:)./histsmooth(x(j-1,:),cc)/nbb;
+ %delx=delx.*(delx<3*ones(1,nint)/nbb)+3*ones(1,nint)/nbb.*~(delx <3*ones(1,nint)/nbb)
+ x(j,:)=x(j-1,:)+delx-(delx.*delx/2).*histder(x(j-1,:),cc);
+end
+%reshape
+xint=ones(nbb,1)*xint;
+x=x+xint;
+x=reshape(x,1,nbb*nint);
+error=xfin+1/(2*nbb)-x;
+
+%-------------------------------------------------------
+% --- determine the spline coefficients cc for the interpolated histogram.
+%-------------------------------------------------
+function [histsmooth,cc]= splinhist(Integ,mini,nbb)
+% provides a smooth histogramm histmooth, which remains always positive,
+% and is such that its sum over each integer bin [i-1/2 i+1/2] is equal to
+% Integ(i). The function determines histmooth as the exponential of a 4th
+% order spline function and adjust the cefficients by a Newton method to
+% fit the integral conditions Integ
+% histmooth is determined at the abscissa
+% xfin=[mini-0.5+1/(2*n):(1/n):maxi+0.5-(1/(2*n))] (maxi=mini+size(aa)-1)
+%cc(1-5,i) provides the spline coefficients
+
+% order 0
+siz=size(Integ);
+nint=siz(2);
+izero=find(Integ==0); %indices of zero elements
+inonzero=find(Integ);
+Integ(izero)=min(Integ(inonzero));
+aa=log(Integ);%initial guess for a coeff
+spli=spline4(aa,mini,nbb); %appel à la fonction spline4
+histsmooth=exp(spli);
+
+S=(sum(reshape(histsmooth,nbb,nint)))/nbb;% integral of the fit histsmooth on ]i-1/2 i+1/2[
+epsilon=max(abs(Integ-S));
+iter=0;
+while epsilon > 0.000001 & iter<10
+ident=eye(nint);
+dSda=ones(nint);
+for j=1:nint% determination of the jacobian matrix dSda
+dhistda=spline4(ident(j,:),mini,nbb);
+expdhistda=dhistda.*histsmooth;
+dSda(j,:)=(sum(reshape(expdhistda,nbb,nint)))/nbb;
+end
+aa=aa+(Integ-S)*inv(dSda);%new estimate of coefficients aa by linear interpolation
+[spli,bb]=spline4(aa,mini,nbb);% new fit histsmooth
+histsmooth=exp(spli);
+S=(sum(reshape(histsmooth,nbb,nint)))/nbb;% integral of the fit histsmooth on ]i-1/2 i+1/2[
+epsilon=max(abs(Integ-S));
+iter=iter+1;
+end
+if iter==10, errordlg('splinhist did not converge after 10 iterations'),end
+cc(1,:)=aa;
+cc(2,:)=bb(1,:);
+cc(3,:)=bb(2,:);
+cc(4,:)=bb(3,:);
+cc(5,:)=bb(4,:);
+
+%-------------------------------------------------------
+% --- determine the 4th order spline coefficients from the function values aa.
+%-------------------------------------------------
+function [histsmooth,bb]= spline4(aa,mini,n)
+% spline interpolation at 4th order
+%aa=vector of values of a function at integer abscissa, starting at mini
+%n=number of subdivisions for the interpolated function
+% histmooth =interpolated values at absissa
+% xfin=[mini-0.5+1/(2*n):(1/n):maxi+0.5-(1/(2*n))] (maxi=mini+size(aa)-1)
+%bb=[b(i);c(i);d(i); e(i)] matrix of spline coeff
+L1=[1/2 1/4 1/8 1/16;1 1 3/4 1/2;0 2 3 3;0 0 6 12];
+L2=[-1/2 1/4 -1/8 1/16;1 -1 3/4 -1/2;0 2 -3 3;0 0 6 -12];
+M=inv(L2)*L1;
+[V,D]=eig(M);
+F=-inv(V)*inv(L2)*[1 ;0 ;0;0];
+a1rev=[1 -1/D(1,1)];
+b1rev=[F(1)/D(1,1)];
+a2rev=[1 -1/D(2,2)];
+b2rev=[F(2)/D(2,2)];
+a3=[1 -D(3,3)];
+b3=[F(3)];
+a4=[1 -D(4,4)];
+b4=[F(4)];
+
+%data
+% n=10;% résolution de la pdf: nbre de points par unite de u
+% mini=-10.0;%general mini=uint16(min(values)-1 CHOOSE maxi-mini+1 EVEN
+% maxi=9.0; % general maxi=uint16(max(values))+1
+%nint=double(maxi-mini+1); % nombre d'intervals entiers EVEN!
+siz=size(aa);
+nint=siz(2);
+maxi=mini+nint-1;
+npdf=nint*n;% nbre total d'intervals à introduire dans la pdf: hist(u,npdf)
+%simulation de pdf
+xfin=[mini-0.5+1/(2*n):(1/n):maxi+0.5-(1/(2*n))];% valeurs d'interpolation: we take n values in each integer interval
+%histolin=exp(-(xfin-1).*(xfin-1)).*(2+cos(10*(xfin-1)));% simulation d'une pdf
+%histo=log(histolin);
+%histo=sin(2*pi*xfin);
+%histextract=(reshape(histo,n,nint));
+%aa=sum(histextract)/n %integral of the pdf on each integer bin
+IP=[0 diff(aa)];
+Irev=zeros(size(aa));
+for i=1:nint
+ Irev(i)=aa(end-i+1);
+end
+IPrev=[0 diff(Irev)];
+
+%get the spline coelfficients a_d, using filter on the eigen vectors A,B,C
+Arev=filter(b1rev,a1rev,IPrev);
+Brev=filter(b2rev,a2rev,IPrev);
+C=filter(b3,a3,IP);
+D=filter(b4,a4,IP);
+A=zeros(size(Arev));
+B=zeros(size(Brev));
+for i=1:nint
+ A(i)=Arev(end-i+1);
+ B(i)=Brev(end-i+1);
+end
+%Matr=V*[A;B;C;D];
+bb=V*[A;B;C;D];
+%b=Matr(1,:);
+%c=Matr(2,:);
+%d=Matr(3,:);
+%e=Matr(4,:);
+%a=aa;
+
+%calculate the interpolation using the spline coefficients a-d
+%xextract=(reshape(xfin,n,nint));%
+chi=xfin+1/(2*n)-min(xfin)-double(int16(xfin+(1/(2*n))-min(xfin)))-0.5;% decimal part
+chi2=chi.*chi;
+chi3=chi2.*chi;
+chi4=chi3.*chi;
+avec=reshape(ones(n,1)*aa,1,n*nint);
+bvec=reshape(ones(n,1)*bb(1,:),1,n*nint);
+cvec=reshape(ones(n,1)*bb(2,:),1,n*nint);
+dvec=reshape(ones(n,1)*bb(3,:),1,n*nint);
+evec=reshape(ones(n,1)*bb(4,:),1,n*nint);
+histsmooth=avec+bvec.*chi+cvec.*chi2+dvec.*chi3+evec.*chi4;
+
+%-------------------------------------------------------
+% --- determine the interpolated histogram at points chi from the spline ceff cc.
+%-------------------------------------------------
+function histx= histsmooth(chi,cc)
+% provides the value of the interpolated histogram at values chi=x-i
+%(difference with the mnearest integer)
+% cc(5,size(chi)) is the set of spline coefficients obtained by splinhist
+chi2=chi.*chi;
+chi3=chi2.*chi;
+chi4=chi3.*chi;
+histx=exp(cc(1,:)+cc(2,:).*chi+cc(3,:).*chi2+cc(4,:).*chi3+cc(5,:).*chi4);
+
+%-------------------------------------------------------
+% --- determine the derivative p'/p of the interpolated histogram at points chi from the spline ceff cc.
+%-------------------------------------------------
+function histder= histder(chi,cc)
+% provides the logarithmique derivative p'/p of the interpolated histogram
+%at values chi=x-i
+%(difference with the nearest integer)
+% cc(5,size(chi)) is the set of spline coefficients obtained by splinhist
+chi2=chi.*chi;
+chi3=chi2.*chi;
+chi4=chi3.*chi;
+histder=cc(2,:)+2*cc(3,:).*chi+3*cc(4,:).*chi2+4*cc(5,:).*chi3;
Index: /trunk/src/phys.m
===================================================================
--- /trunk/src/phys.m (revision 2)
+++ /trunk/src/phys.m (revision 2)
@@ -0,0 +1,232 @@
+%'phys': transforms image (px) to real world (phys) coordinates using geometric calibration parameters
+% OUTPUT:
+% DataOut: structure representing the modified field
+% DataOut_1: structure representing the second modified field
+
+%INPUT:
+% Data: structure of input data
+% with fields .A (image or scalar matrix), AX, AY
+% .X,.Y,.U,.V, .DjUi
+% .ZIndex: index of plane in multilevel case
+% Data.CoordType='phys' or 'px', The function ACTS ONLY IF .CoordType='px'
+% Calib: structure containing calibration parameters or a subtree Calib.GeometryCalib =calibration data (tsai parameters)
+
+function [DataOut,DataOut_1]=phys(varargin)
+% A FAIRE: 1- verifier si DataIn est une 'field structure'(.ListVarName'):
+% chercher ListVarAttribute, for each field (cell of variables):
+% .CoordType: 'phys' or 'px' (default==phys, no transform)
+% .scale_factor: =dt (to transform displacement into velocity) default=1
+% .covariance: 'scalar', 'coord', 'D_i': covariant (like velocity), 'D^i': contravariant (like gradient), 'D^jD_i' (like strain tensor)
+% (default='coord' if .Role='coord_x,_y...,
+% 'D_i' if '.Role='vector_x,...',
+% 'scalar', else (thenno change except scale factor)
+Calib{1}=[];
+if nargin==2||nargin==4 % nargin =nbre of input variables
+ Data=varargin{1};
+ DataOut=Data;%default
+ DataOut_1=[];%default
+ CalibData=varargin{2};
+ if isfield(CalibData,'GeometryCalib')
+ Calib{1}=CalibData.GeometryCalib;
+ end
+ Calib{2}=Calib{1};
+else
+ DataOut.Txt='wrong input: need two or four structures';
+end
+test_1=0;
+if nargin==4
+ test_1=1;
+ Data_1=varargin{3};
+ DataOut_1=Data_1;%default
+ CalibData_1=varargin{4};
+ if isfield(CalibData_1,'GeometryCalib')
+ Calib{2}=CalibData_1.GeometryCalib;
+ end
+end
+iscalar=0;
+if ~isempty(Calib{1})
+ DataOut=phys_1(Data,Calib{1});
+ %case of images or scalar: in case of two input fields, we need to project the transform of on the same regular grid
+ if isfield(Data,'A') && isfield(Data,'AX') && ~isempty(Data.AX) && isfield(Data,'AY')&&...
+ ~isempty(Data.AY) && length(Data.A)>1
+ iscalar=1;
+ A{1}=Data.A;
+ end
+end
+%transform of X,Y coordinates for vector fields
+if isfield(Data,'ZIndex')&&~isempty(Data.ZIndex)
+ ZIndex=Data.ZIndex;
+else
+ ZIndex=0;
+end
+if test_1
+ DataOut_1=phys_1(Data_1,Calib{2});
+ if isfield(Data_1,'A')&&isfield(Data_1,'AX')&&~isempty(Data_1.AX) && isfield(Data_1,'AY')&&...
+ ~isempty(Data_1.AY)&&length(Data_1.A)>1
+ iscalar=iscalar+1;
+ Calib{iscalar}=Calib{2};
+ A{iscalar}=Data_1.A;
+ if isfield(Data_1,'ZIndex') && ~isequal(Data_1.ZIndex,ZIndex)
+ DataOut.Txt='inconsistent plane indexes in the two input fields';
+ end
+ if iscalar==1% case for which only the second field is a scalar
+ [A,AX,AY]=phys_Ima(A,Calib,ZIndex);
+ DataOut_1.A=A{1};
+ DataOut_1.AX=AX;
+ DataOut_1.AY=AY;
+ return
+ end
+ end
+end
+if iscalar~=0
+ [A,AX,AY]=phys_Ima(A,Calib,ZIndex);%TODO : introduire interp2_uvmat ds phys_ima
+ DataOut.A=A{1};
+ DataOut.AX=AX;
+ DataOut.AY=AY;
+ if iscalar==2
+ DataOut_1.A=A{2};
+ DataOut_1.AX=AX;
+ DataOut_1.AY=AY;
+ end
+end
+
+%------------------------------------------------
+function DataOut=phys_1(Data,Calib)
+% for icell=1:length(Data)
+
+DataOut=Data;%default
+DataOut.CoordType='phys'; %put flag for physical coordinates
+% The transform ACTS ONLY IF .CoordType='px'and Calib defined
+if isfield(Data,'CoordType')&& isequal(Data.CoordType,'px')&& ~isempty(Calib)
+ if isfield(Calib,'CoordUnit')
+ DataOut.CoordUnit=Calib.CoordUnit;
+ else
+ DataOut.CoordUnit='cm'; %default
+% elseif isfield(DataOut,'CoordUnit')
+% DataOut=rmfield(DataOut,'CoordUnit');
+ end
+ DataOut.TimeUnit='s';
+ %transform of X,Y coordinates for vector fields
+ if isfield(Data,'ZIndex') && ~isempty(Data.ZIndex)
+ Z=Data.ZIndex;
+ else
+ Z=0;
+ end
+ if isfield(Data,'X') &&isfield(Data,'Y')&&~isempty(Data.X) && ~isempty(Data.Y)
+ [DataOut.X,DataOut.Y,DataOut.Z]=phys_XYZ(Calib,Data.X,Data.Y,Z);
+ if isfield(Data,'U')&&isfield(Data,'V')&&~isempty(Data.U) && ~isempty(Data.V)&& isfield(Data,'dt')
+ if ~isempty(Data.dt)
+ [XOut_1,YOut_1]=phys_XYZ(Calib,Data.X-Data.U/2,Data.Y-Data.V/2,Z);
+ [XOut_2,YOut_2]=phys_XYZ(Calib,Data.X+Data.U/2,Data.Y+Data.V/2,Z);
+ DataOut.U=(XOut_2-XOut_1)/Data.dt;
+ DataOut.V=(YOut_2-YOut_1)/Data.dt;
+ end
+ end
+ end
+ %transform of an image or scalar: done in phys_ima
+
+ %transform of spatial derivatives
+ if isfield(Data,'X') && ~isempty(Data.X) && isfield(Data,'DjUi') && ~isempty(Data.DjUi)...
+ && isfield(Data,'dt')
+ if ~isempty(Data.dt)
+ % estimate the Jacobian matrix DXpx/DXphys
+ for ip=1:length(Data.X)
+ [Xp1,Yp1]=phys_XYZ(Calib,Data.X(ip)+0.5,Data.Y(ip),Z);
+ [Xm1,Ym1]=phys_XYZ(Calib,Data.X(ip)-0.5,Data.Y(ip),Z);
+ [Xp2,Yp2]=phys_XYZ(Calib,Data.X(ip),Data.Y(ip)+0.5,Z);
+ [Xm2,Ym2]=phys_XYZ(Calib,Data.X(ip),Data.Y(ip)-0.5,Z);
+ %Jacobian matrix DXpphys/DXpx
+ DjXi(1,1)=(Xp1-Xm1);
+ DjXi(2,1)=(Yp1-Ym1);
+ DjXi(1,2)=(Xp2-Xm2);
+ DjXi(2,2)=(Yp2-Ym2);
+ DjUi(:,:)=Data.DjUi(ip,:,:);
+ DjUi=(DjXi*DjUi')/DjXi;% =J-1*M*J , curvature effects (derivatives of J) neglected
+ DataOut.DjUi(ip,:,:)=DjUi';
+ end
+ DataOut.DjUi = DataOut.DjUi/Data.dt; % min(Data.DjUi(:,1,1))=DUDX
+ end
+ end
+end
+
+
+%%%%%%%%%%%%%%%%%%%%
+function [A_out,Rangx,Rangy]=phys_Ima(A,CalibIn,ZIndex)
+xcorner=[];
+ycorner=[];
+npx=[];
+npy=[];
+for icell=1:length(A)
+ siz=size(A{icell});
+ npx=[npx siz(2)];
+ npy=[npy siz(1)];
+ Calib=CalibIn{icell};
+ xima=[0.5 siz(2)-0.5 0.5 siz(2)-0.5];%image coordiantes of corners
+ yima=[0.5 0.5 siz(1)-0.5 siz(1)-0.5];
+ [xcorner_new,ycorner_new]=phys_XYZ(Calib,xima,yima,ZIndex);%corresponding physical coordinates
+ xcorner=[xcorner xcorner_new];
+ ycorner=[ycorner ycorner_new];
+end
+Rangx(1)=min(xcorner);
+Rangx(2)=max(xcorner);
+Rangy(2)=min(ycorner);
+Rangy(1)=max(ycorner);
+test_multi=(max(npx)~=min(npx)) | (max(npy)~=min(npy));
+npx=max(npx);
+npy=max(npy);
+x=linspace(Rangx(1),Rangx(2),npx);
+y=linspace(Rangy(1),Rangy(2),npy);
+[X,Y]=meshgrid(x,y);%grid in physical coordiantes
+vec_B=[];
+A_out={};
+for icell=1:length(A)
+ Calib=CalibIn{icell};
+ if (isfield(Calib,'R') && ~isequal(Calib.R(2,1),0) && ~isequal(Calib.R(1,2),0)) ||...
+ ((isfield(Calib,'kappa1')&& ~isequal(Calib.kappa1,0))) || test_multi || ~isequal(Calib,CalibIn{1})
+ zphys=0; %default
+ if isfield(Calib,'SliceCoord') %.Z= index of plane
+ SliceCoord=Calib.SliceCoord(ZIndex,:);
+ zphys=SliceCoord(3); %to generalize for non-parallel planes
+ end
+ [XIMA,YIMA]=px_XYZ(CalibIn{icell},X,Y,zphys);%corresponding image indices for each point in the real space grid
+ XIMA=reshape(round(XIMA),1,npx*npy);%indices reorganized in 'line'
+ YIMA=reshape(round(YIMA),1,npx*npy);
+ flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
+ testuint8=isa(A{icell},'uint8');
+ testuint16=isa(A{icell},'uint16');
+ if numel(siz)==2 %(B/W images)
+ vec_A=reshape(A{icell},1,npx*npy);%put the original image in line
+ ind_in=find(flagin);
+ ind_out=find(~flagin);
+ ICOMB=((XIMA-1)*npy+(npy+1-YIMA));
+ ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
+ vec_B(ind_in)=vec_A(ICOMB);
+ vec_B(ind_out)=zeros(size(ind_out));
+ A_out{icell}=reshape(vec_B,npy,npx);%new image in real coordinates
+ elseif numel(siz)==3
+ for icolor=1:siz(3)
+ vec_A=reshape(A{icell}(:,:,icolor),1,npx*npy);%put the original image in line
+ ind_in=find(flagin);
+ ind_out=find(~flagin);
+ ICOMB=((XIMA-1)*npy+(npy+1-YIMA));
+ ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
+ vec_B(ind_in)=vec_A(ICOMB);
+ vec_B(ind_out)=zeros(size(ind_out));
+ A_out{icell}(:,:,icolor)=reshape(vec_B,npy,npx);%new image in real coordinates
+ end
+ end
+ if testuint8
+ A_out{icell}=uint8(A_out{icell});
+ end
+ if testuint16
+ A_out{icell}=uint16(A_out{icell});
+ end
+ else%
+
+ A_out{icell}=A{icell};%no transform
+ Rangx=[0.5 npx-0.5];%image coordiantes of corners
+ Rangy=[npy-0.5 0.5];
+ [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],[ZIndex ZIndex]);%case of translations without rotation and quadratic deformation
+ [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,[ZIndex ZIndex]);
+ end
+end
Index: /trunk/src/phys_XYZ.m
===================================================================
--- /trunk/src/phys_XYZ.m (revision 2)
+++ /trunk/src/phys_XYZ.m (revision 2)
@@ -0,0 +1,54 @@
+%'phys_XYZ':transforms image (px) to real world (phys) coordinates using geometric calibration parameters
+% function [Xphys,Yphys]=phys_XYZ(Calib,X,Y,Z)
+%
+%OUTPUT:
+%
+%INPUT:
+%Z: index of plane
+function [Xphys,Yphys,Zphys]=phys_XYZ(Calib,X,Y,Z)
+if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'SliceCoord')&length(Calib.SliceCoord)>=Z
+ Zindex=Z;
+ Zphys=Calib.SliceCoord(Zindex,3);%GENERALISER AUX CAS AVEC ANGLE
+else
+% if exist('Z','var')
+% Zphys=Z;
+% else
+ Zphys=0;
+% end
+end
+if ~exist('X','var')||~exist('Y','var')
+ Xphys=[];
+ Yphys=[];%default
+ return
+end
+Xphys=X;%default
+Yphys=Y;
+%image transform
+if isfield(Calib,'R')
+ R=(Calib.R)';
+ Dx=R(5)*R(7)-R(4)*R(8);
+ Dy=R(1)*R(8)-R(2)*R(7);
+ D0=Calib.f*(R(2)*R(4)-R(1)*R(5));
+ Z11=R(6)*R(8)-R(5)*R(9);
+ Z12=R(2)*R(9)-R(3)*R(8);
+ Z21=R(4)*R(9)-R(6)*R(7);
+ Z22=R(3)*R(7)-R(1)*R(9);
+ Zx0=R(3)*R(5)-R(2)*R(6);
+ Zy0=R(1)*R(6)-R(3)*R(4);
+ A11=R(8)*Calib.Ty-R(5)*Calib.Tz+Z11*Zphys;
+ A12=R(2)*Calib.Tz-R(8)*Calib.Tx+Z12*Zphys;
+ A21=-R(7)*Calib.Ty+R(4)*Calib.Tz+Z21*Zphys;
+ A22=-R(1)*Calib.Tz+R(7)*Calib.Tx+Z11*Zphys;
+ X0=Calib.f*(R(5)*Calib.Tx-R(2)*Calib.Ty+Zx0*Zphys);
+ Y0=Calib.f*(-R(4)*Calib.Tx+R(1)*Calib.Ty+Zy0*Zphys);
+ %px to camera:
+ Xd=(Calib.dpx/Calib.sx)*(X-Calib.Cx); % sensor coordinates
+ Yd=Calib.dpy*(Y-Calib.Cy);
+ dist_fact=1+Calib.kappa1*(Xd.*Xd+Yd.*Yd); %distortion factor
+ Xu=dist_fact.*Xd;%undistorted sensor coordinates
+ Yu=dist_fact.*Yd;
+ denom=Dx*Xu+Dy*Yu+D0;
+ % denom2=denom.*denom;
+ Xphys=(A11.*Xu+A12.*Yu+X0)./denom;%world coordinates
+ Yphys=(A21.*Xu+A22.*Yu+Y0)./denom;
+end
Index: /trunk/src/phys_polar.m
===================================================================
--- /trunk/src/phys_polar.m (revision 2)
+++ /trunk/src/phys_polar.m (revision 2)
@@ -0,0 +1,226 @@
+%transform image coordinates (px) to physical coordinates
+% then transform to polar coordinates:
+%[DataOut,DataOut_1]=phys_polar(varargin)
+%
+% OUTPUT:
+% DataOut: structure of modified data field: .X=radius, .Y=azimuth angle, .U, .V are radial and azimuthal velocity components
+% DataOut_1: second data field (if two fields are in input)
+%
+%INPUT:
+% Data: structure of input data (like UvData)
+% CalibData= structure containing the field .GeometryCalib with calibration parameters
+% Data_1: second input field (not mandatory)
+% CalibData_1= calibration parameters for the second field
+
+function [DataOut,DataOut_1]=phys_polar(varargin)
+Calib{1}=[];
+if nargin==2||nargin==4
+ Data=varargin{1};
+ DataOut=Data;%default
+ DataOut_1=[];%default
+ CalibData=varargin{2};
+ if isfield(CalibData,'GeometryCalib')
+ Calib{1}=CalibData.GeometryCalib;
+ end
+ Calib{2}=Calib{1};
+else
+ DataOut.Txt='wrong input: need two or four structures';
+end
+test_1=0;
+if nargin==4
+ test_1=1;
+ Data_1=varargin{3};
+ DataOut_1=Data_1;%default
+ CalibData_1=varargin{4};
+ if isfield(CalibData_1,'GeometryCalib')
+ Calib{2}=CalibData_1.GeometryCalib;
+ end
+end
+
+%parameters for polar coordinates (taken from the calibration data of the first field)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+origin_xy=[0 0];%center for the polar coordinates in the original x,y coordinates
+if isfield(Calib{1},'PolarCentre') && isnumeric(Calib{1}.PolarCentre)
+ if isequal(length(Calib{1}.PolarCentre),2);
+ origin_xy= Calib{1}.PolarCentre;
+ end
+end
+radius_offset=0;%reference radius used to offset the radial coordinate r
+angle_offset=0; %reference angle used as new origin of the polar angle (= axis Ox by default)
+if isfield(Calib{1},'PolarReferenceRadius') && isnumeric(Calib{1}.PolarReferenceRadius)
+ radius_offset=Calib{1}.PolarReferenceRadius;
+end
+if radius_offset > 0
+ angle_scale=radius_offset; %the azimuth is rescale in terms of the length along the reference radius
+else
+ angle_scale=180/pi; %polar angle in degrees
+end
+if isfield(Calib{1},'PolarReferenceAngle') && isnumeric(Calib{1}.PolarReferenceAngle)
+ angle_offset=Calib{1}.PolarReferenceAngle; %offset angle (in unit of the final angle, degrees or arc length along the reference radius))
+end
+% new x coordinate = radius-radius_offset;
+% new y coordinate = theta*angle_scale-angle_offset
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+iscalar=0;
+if ~isempty(Calib{1})
+ DataOut=phys_1(Data,Calib{1},origin_xy,radius_offset,angle_offset,angle_scale);
+ %case of images or scalar
+ if isfield(Data,'A')&isfield(Data,'AX')&~isempty(Data.AX) & isfield(Data,'AY')&...
+ ~isempty(Data.AY)&length(Data.A)>1
+ iscalar=1;
+ A{1}=Data.A;
+ end
+ %transform of X,Y coordinates for vector fields
+ if isfield(Data,'ZIndex')&~isempty(Data.ZIndex)
+ ZIndex=Data.ZIndex;
+ else
+ ZIndex=0;
+ end
+end
+
+if test_1
+ DataOut_1=phys_1(Data_1,Calib{2},origin_xy,radius_offset,angle_offset,angle_scale);
+ if isfield(Data_1,'A')&isfield(Data_1,'AX')&~isempty(Data_1.AX) & isfield(Data_1,'AY')&...
+ ~isempty(Data_1.AY)&length(Data_1.A)>1
+ iscalar=iscalar+1;
+ Calib{iscalar}=Calib{2};
+ A{iscalar}=Data_1.A;
+ if isfield(Data_1,'ZIndex')&~isequal(Data_1.ZIndex,ZIndex)
+ DataOut.Txt='inconsistent plane indexes in the two input fields';
+ end
+ if iscalar==1% case for which only the second field is a scalar
+ [A,AX,AY]=phys_Ima(A,Calib,ZIndex,origin_xy,radius_offset,angle_offset,angle_scale);
+ DataOut_1.A=A{1};
+ DataOut_1.AX=AX;
+ DataOut_1.AY=AY;
+ return
+ end
+ end
+end
+if iscalar~=0
+ [A,AX,AY]=phys_Ima(A,Calib,ZIndex,origin_xy,radius_offset,angle_offset,angle_scale);%
+ DataOut.A=A{1};
+ DataOut.AX=AX;
+ DataOut.AY=AY;
+ if iscalar==2
+ DataOut_1.A=A{2};
+ DataOut_1.AX=AX;
+ DataOut_1.AY=AY;
+ end
+end
+
+%------------------------------------------------
+function DataOut=phys_1(Data,Calib,origin_xy,radius_offset,angle_offset,angle_scale)
+
+DataOut=Data;
+DataOut.CoordType='phys'; %put flag for physical coordinates
+if isfield(Calib,'CoordUnit')
+ DataOut.CoordUnit=Calib.CoordUnit;
+else
+ DataOut.CoordUnit='cm'; %default
+end
+DataOut.TimeUnit='s';
+%perform a geometry transform if Calib contains a field .GeometryCalib
+if isfield(Data,'CoordType') && isequal(Data.CoordType,'px') && ~isempty(Calib)
+ if isfield(Data,'CoordUnit')
+ DataOut=rmfield(DataOut,'CoordUnit');
+ end
+ %transform of X,Y coordinates for vector fields
+ if isfield(Data,'ZIndex')&~isempty(Data.ZIndex)
+ Z=Data.ZIndex;
+ else
+ Z=0;
+ end
+ if isfield(Data,'X') &isfield(Data,'Y')&~isempty(Data.X) & ~isempty(Data.Y)
+ [DataOut.X,DataOut.Y,DataOut.Z]=phys_XYZ(Calib,Data.X,Data.Y,Z); %transform from pixels to physical
+ DataOut.X=DataOut.X-origin_xy(1);%origin of coordinates at the tank center
+ DataOut.Y=DataOut.Y-origin_xy(2);%origin of coordinates at the tank center
+ [theta,DataOut.X] = cart2pol(DataOut.X,DataOut.Y);%theta and X are the polar coordinates angle and radius
+ %shift and renormalize the polar coordinates
+ DataOut.X=DataOut.X-radius_offset;%
+ DataOut.Y=theta*angle_scale-angle_offset;% normalized angle: distance along reference radius
+ %transform velocity field if exists
+ if isfield(Data,'U')&isfield(Data,'V')&~isempty(Data.U) & ~isempty(Data.V)& isfield(Data,'dt')
+ if ~isempty(Data.dt)
+ [XOut_1,YOut_1]=phys_XYZ(Calib,Data.X-Data.U/2,Data.Y-Data.V/2,Z);
+ [XOut_2,YOut_2]=phys_XYZ(Calib,Data.X+Data.U/2,Data.Y+Data.V/2,Z);
+ UX=(XOut_2-XOut_1)/Data.dt;
+ VY=(YOut_2-YOut_1)/Data.dt;
+ %transform u,v into polar coordiantes
+ DataOut.U=UX.*cos(theta)+VY.*sin(theta);%radial velocity
+ DataOut.V=(-UX.*sin(theta)+VY.*cos(theta));%./(DataOut.X)%+radius_ref);%angular velocity calculated
+ %shift and renormalize the angular velocity
+ end
+ end
+ end
+end
+
+
+%%%%%%%%%%%%%%%%%%%%
+function [A_out,Rangx,Rangy]=phys_Ima(A,CalibIn,ZIndex,origin_xy,radius_offset,angle_offset,angle_scale)
+xcorner=[];
+ycorner=[];
+npx=[];
+npy=[];
+
+for icell=1:length(A)
+ siz=size(A{icell});
+ npx=[npx siz(2)];
+ npy=[npy siz(1)];
+ zphys=0; %default
+ if isfield(CalibIn{icell},'SliceCoord') %.Z= index of plane
+ SliceCoord=CalibIn{icell}.SliceCoord(ZIndex,:);
+ zphys=SliceCoord(3); %to generalize for non-parallel planes
+ end
+ xima=[0.5 siz(2)-0.5 0.5 siz(2)-0.5];%image coordiantes of corners
+ yima=[0.5 0.5 siz(1)-0.5 siz(1)-0.5];
+ [xcorner_new,ycorner_new]=phys_XYZ(CalibIn{icell},xima,yima,ZIndex);%corresponding physical coordinates
+ %transform the corner coordinates into polar ones
+ xcorner_new=xcorner_new-origin_xy(1);%shift to the origin of the polar coordinates
+ ycorner_new=ycorner_new-origin_xy(2);%shift to the origin of the polar coordinates
+ [theta,xcorner_new] = cart2pol(xcorner_new,ycorner_new);%theta and X are the polar coordinates angle and radius
+ if (max(theta)-min(theta))>pi %if the polar origin is inside the image
+ xcorner_new=[0 max(xcorner_new)];
+ theta=[-pi pi];
+ end
+ %shift and renormalize the polar coordinates
+ xcorner_new=xcorner_new-radius_offset;%
+ ycorner_new=theta*angle_scale-angle_offset;% normalized angle: distance along reference radius
+ xcorner=[xcorner xcorner_new];
+ ycorner=[ycorner ycorner_new];
+end
+Rangx(1)=min(xcorner);
+Rangx(2)=max(xcorner);
+Rangy(2)=min(ycorner);
+Rangy(1)=max(ycorner);
+% test_multi=(max(npx)~=min(npx)) | (max(npy)~=min(npy));
+npx=max(npx);
+npy=max(npy);
+x=linspace(Rangx(1),Rangx(2),npx);
+y=linspace(Rangy(1),Rangy(2),npy);
+[X,Y]=meshgrid(x,y);%grid in physical coordinates
+%transform X, Y in cartesian
+X=X+radius_offset;%
+Y=(Y+angle_offset)/angle_scale;% normalized angle: distance along reference radius
+[X,Y] = pol2cart(Y,X);
+X=X+origin_xy(1);%shift to the origin of the polar coordinates
+Y=Y+origin_xy(2);%shift to the origin of the polar coordinates
+for icell=1:length(A)
+ [XIMA,YIMA]=px_XYZ(CalibIn{icell},X,Y,zphys);%corresponding image indices for each point in the real space grid
+ XIMA=reshape(round(XIMA),1,npx*npy);%indices reorganized in 'line'
+ YIMA=reshape(round(YIMA),1,npx*npy);
+ flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
+ vec_A=reshape(A{icell}(:,:,1),1,npx*npy);%put the original image in line
+ ind_in=find(flagin);
+ ind_out=find(~flagin);
+ ICOMB=((XIMA-1)*npy+(npy+1-YIMA));
+ ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
+ vec_B(ind_in)=vec_A(ICOMB);
+ vec_B(ind_out)=zeros(size(ind_out));
+ A_out{icell}=reshape(vec_B,npy,npx);%new image in real coordinates
+end
+%Rangx=Rangx-radius_offset;
+
+
Index: /trunk/src/plot_field.m
===================================================================
--- /trunk/src/plot_field.m (revision 2)
+++ /trunk/src/plot_field.m (revision 2)
@@ -0,0 +1,1160 @@
+%'plot_field': plot any field with the structure defined in the uvmat package
+%------------------------------------------------------------------------
+%
+% This function is used by uvmat to plot fields. It automatically chooses the representation
+% appropriate to the input field structure:
+% 2D vector fields are represented by arrows, 2D scalar fiedlds by grey scale images or contour plots, 1D fields are represented by usual plot with (abscissa, ordinate).
+% The input field structure is first tested by check_field_structure.m,
+% then split into blocks of related variables by find_field_indices.m.
+% The dimensionality of each block is obtained by this fuction
+% considering the presence of variables with the attribute .Role='coord_x'
+% and/or coord_y and/or coord_z (case of unstructured coordinates), or
+% dimension variables (case of matrices).
+%
+% function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,KeepLim,PosColorbar)
+%
+% OUPUT:
+% PlotType: type of plot: 'text','line'(curve plot),'plane':2D view,'volume'
+% PlotParamOut: structure, representing the updated plotting parameters, in case of automatic scaling
+% haxes: handle of the plotting axis, when a new figure is created.
+%
+%INPUT
+% Data: structure describing the field to plot
+% (optional) .ListGlobalAttribute: cell listing the names of the global attributes
+% .Att_1,Att_2... : values of the global attributes
+% (requested) .ListVarName: list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} )
+% (requested) .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)
+% .VarAttribute: cell of attributes for each element of .ListVarName (cell array of structures of the form VarAtt.key=value)
+% (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
+%
+% Variable attribute .Role :
+% The only variable attribute used for plotting purpose is .Role which can take
+% the values
+ % Role = 'scalar': (default) represents a scalar field
+ % = 'coord_x', 'coord_y', 'coord_z': represents a separate set of
+ % unstructured coordinate x, y or z
+ % = 'vector': represents a vector field whose number of components
+ % is given by the last dimension (called 'nb_dim')
+ % = 'vector_x', 'vector_y', 'vector_z' :represents the x, y or z component of a vector
+ % = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
+ % = 'errorflag': provides an error flag marking false data,
+ % default=0, no error. Different non zero values can represent different criteria of elimination.
+
+
+% additional elements characterizing the projection object (should not be necessary)--
+% Data.Style : style of projection object
+% Data.XObject,.YObject: set of coordinates defining the object position;
+% Data.ProjMode=type of projection ;
+% Data.ProjAngle=angle of projection;
+% Data.DX,.DY,.DZ=increments;
+% Data.MaxY,MinY: min and max Y
+
+% haxes: handle of the plotting axes to update with the new plot. If this input is absent or not a valid axes handle, a new figure is created.
+%
+% PlotParam: parameters for plotting, as read on the uvmat interface (by function 'read_plot_param.m')
+% --scalars--
+% .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default
+% .Scalar.MinA: lower bound (saturation) for the scalar representation, min(field) by default
+% .Scalar.AutoScal: =1 (default) lower and upper bounds of the scalar representation set to the min and max of the field
+% =0 lower and upper bound imposed by .AMax and .MinA
+% .Scalar.BW= 1 black and white representation imposed, =0 by default.
+% .Scalar.Contours= 1: represent scalars by contour plots (Matlab function 'contour'); =0 by default
+% .IncrA : contour interval
+% -- vectors--
+% .Vectors.VecScale: scale for the vector representation
+% .Vectors.AutoVec: =0 (default) automatic length for vector representation, =1: length set by .VecScale
+% .Vectors.HideFalse= 0 (default) false vectors represented in magenta, =1: false vectors not represented;
+% .Vectors.HideWarning= 0 (default) vectors marked by warnflag~=0 marked in black, 1: no warning representation;
+% .Vectors.decimate4 = 0 (default) all vectors reprtesented, =1: half of the vectors represented along each coordinate
+% -- vector color--
+% .Vectors.ColorCode= 'black','white': imposed color (default ='blue')
+% 'rgb', : three colors red, blue, green depending
+% on thresholds .colcode1 and .colcode2 on the input scalar value (C)
+% 'brg': like rgb but reversed color order (blue, green, red)
+% '64 colors': continuous color from blue to red (multijet)
+% .Vectors.colcode1 : first threshold for rgb, first value for'continuous'
+% .Vectors.colcode2 : second threshold for rgb, last value (saturation) for 'continuous'
+% .Vectors.FixedCbounds; =0 (default): the bounds on C representation are min and max, =1: they are fixed by .Minc and .MaxC
+% .Vectors.MinC = imposed minimum of the scalar field used for vector color;
+% .Vectors.MaxC = imposed maximum of the scalar field used for vector color;
+%
+% KeepLim:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits
+% PosColorbar: if not empty, display a colorbar for B&W images
+% imposed position of the colorbar (ex [0.821 0.471 0.019 0.445])
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,KeepLim,PosColorbar)
+%default output
+if ~exist('PlotParam','var'),PlotParam=[];end;
+if ~exist('KeepLim','var'),KeepLim=0;end;
+if ~exist('PosColorbar','var'),PosColorbar=[];end;
+PlotType='text'; %default
+PlotParamOut=PlotParam;%default
+
+% check input structure
+[Data,errormsg]=check_field_structure(Data);
+
+if ~isempty(errormsg)
+ msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])
+ display(['input of plot_field/check_field_structure:: ' errormsg])
+ return
+end
+
+testnewfig=1;%test to create a new figure (default)
+testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
+if exist('haxes','var')
+ if ishandle(haxes)
+ if isequal(get(haxes,'Type'),'axes')
+% hfig=get(haxes,'Parent');
+ axes(haxes)
+ testnewfig=0;
+ AxeData=get(haxes,'UserData');
+ if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)
+ if isequal(get(AxeData.ZoomAxes,'Type'),'axes')
+ testzoomaxes=1;
+ zoomaxes=AxeData.ZoomAxes;
+ end
+ end
+ end
+ end
+end
+if testnewfig% create a new figure and axes if the plotting axes does not exist
+ hfig=figure;
+ if isfield(Data,'IndexObj')&isfield(Data,'Style')&isfield(Data,'ProjMode')
+ figname=[num2str(Data.IndexObj) '-' set_title(Data.Style,Data.ProjMode)];
+ set(hfig,'Name',figname)
+ end
+ testhandle=0;
+ if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)
+ set(hfig,'UserData',PlotParam)
+ testhandle=1;
+ end
+ set(hfig,'Units','normalized')
+ set(hfig,'WindowButtonDownFcn','mouse_down')
+ %set(hfig,'WindowButtonMotionFcn',{'mouse_motion',PlotParam})%set mouse action function
+ set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action function
+ set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse action function
+ haxes=axes;
+ set(haxes,'position',[0.13,0.2,0.775,0.73])
+end
+if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)
+ PlotParam=read_plot_param(PlotParam);
+end
+if testnewfig
+ PlotParam.NextPlot='add'; %parameter for plot_profile and plot_hist
+end
+if isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1)
+ set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
+end
+
+% check the cells of fields :
+testnbdim=1;
+[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
+
+if ~isempty(errormsg)
+ msgbox_uvmat('ERROR',['input of plot_field/find_field_indices: ' errormsg])
+ display(['input of plot_field: ' errormsg])
+ return
+end
+if ~isfield(Data,'NbDim') %& ~isfield(Data,'Style')%determine the space dimensionb if not defined: choose the kind of plot
+ [Data.NbDim,imax]=max(NbDim);
+end
+if isequal(Data.NbDim,0) % TODO: chech whether this function is still used, replace by plot_profile ?
+% if isfield(Data,'Style') & isequal(Data.Style,'points')
+ AxeData=plot_text(Data,haxes);
+ PlotType='text';
+% else
+% [AxeData,haxes]=plot_hist(Data,haxes,PlotParam);
+% end
+elseif isequal(Data.NbDim,1)
+ [AxeData,haxes]=plot_profile(Data,CellVarIndex,VarType,haxes,PlotParam);%
+ if testzoomaxes
+ [AxeData,zoomaxes,PlotParamOut]=plot_profile(Data,CellVarIndex,VarType,zoomaxes,PlotParam);
+ AxeData.ZoomAxes=zoomaxes;
+ end
+ PlotType='line';
+elseif isequal(Data.NbDim,2)
+ ind_select=find(NbDim>=2);
+ if numel(ind_select)>2
+ msgbox_uvmat('ERROR',['more than two fields to map'])
+ display(['more than two fields to map'])
+ return
+ end
+ [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),haxes,PlotParam,KeepLim,PosColorbar);
+ if testzoomaxes
+ [AxeData,zoomaxes,PlotParamOut]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),zoomaxes,PlotParam,1,PosColorbar);
+ AxeData.ZoomAxes=zoomaxes;
+ end
+elseif isequal(Data.NbDim,3)
+ msgbox_uvmat('ERROR','volume plot not implemented yet')
+ return
+ %plot_volume(haxes,Data,PlotParam)% A FAIRE
+ %PlotType='volume';
+else
+ testnbdim=0;
+end
+
+%display (or delete) error message
+htext=findobj(haxes,'Tag','hTxt');
+if isfield(Data,'Txt')
+ if isempty(htext)
+ Xlim=get(haxes,'XLim');
+ Ylim=get(haxes,'YLim');
+ htext=text(Xlim(1),(Ylim(1)+Ylim(2))/2,Data.Txt,'Tag','hTxt','Color','r');
+ set(htext,'Interpreter','none')
+ else
+ set(htext,'String',Data.Txt)
+ end
+elseif ~isempty(htext)
+ delete(htext)
+end
+
+% set graph aspect ratio
+
+
+set(haxes,'UserData',AxeData)
+%set(haxes,'Tag','uvmat');
+
+
+% %-------------------------------------------
+% function [AxeData,haxes]=plot_hist(Data,haxes,PlotParam)% TODO: chech whether this function is still used, replace by plot_profile ?
+% %------------------------------------------
+% AxeData=get(haxes,'UserData'); %defau
+% hfig=get(haxes,'parent');
+% if ~isfield(Data,'ListVarName')
+% return
+% end
+% ColorOrder=[1 0 0;0 0.5 0;0 0 1;0 0.75 0.75;0.75 0 0.75;0.75 0.75 0;0.25 0.25 0.25];
+% set(haxes,'ColorOrder',ColorOrder)
+% if isfield(PlotParam,'NextPlot')
+% set(haxes,'NextPlot',PlotParam.NextPlot)
+% end
+% charplot='''-''';
+% iplot=0;
+% legend_str={};
+% label_str='';
+% textmean={};
+% plotstr='plot(';
+% for ilist=1:length(Data.ListVarName)
+% VarName=Data.ListVarName{ilist};
+% eval(['[' VarName 'hist,' VarName 'val]=hist(double(Data.' VarName '),100);']);%coordinate variable set as c
+% plotstr=[plotstr VarName 'val,' VarName 'hist,' charplot ','];
+% eval(['nbcomponent2=size(Data.' VarName ',2);']);
+% eval(['nbcomponent1=size(Data.' VarName ',1);']);
+% eval(['varmean=mean(double(Data.' VarName '));']);%mean value
+% textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];
+% if nbcomponent1==1| nbcomponent2==1
+% legend_str=[legend_str {VarName}]; %variable with one component
+% else
+% for ic=1:min(nbcomponent1,nbcomponent2)
+% legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals components
+% % labeled by their index (e.g. color component)
+% end
+% end
+% label_str=[label_str ' ' VarName];
+% end
+% if ~isequal(plotstr,'plot(')
+% plotstr(end)=')';
+% eval(plotstr)
+% hlegend=findobj(hfig,'Tag','legend');%find existing legend on the plot
+% if ~isempty(hlegend)
+% legend_old=get(hlegend,'String');
+% if isequal(size(legend_old,1),size(legend_str,1))
+% legend_str=[legend_old legend_str];
+% end
+% end
+% legend(legend_str)
+% xlabel(label_str)
+% ylabel('nb values')
+% grid on
+% title_str='';
+% if isfield(Data,'filename')
+% [Path, title_str, ext]=fileparts(Data.filename);
+% title_str=[title_str ext];
+% end
+% if isfield(Data,'Action')
+% if ~isequal(title_str,'')
+% title_str=[title_str ', '];
+% end
+% title_str=[title_str Data.Action];
+% end
+% htitle=title(title_str);
+% set(htitle,'Interpreter','none')% desable tex interpreter
+% hlist=findobj(gcf,'Style','listbox');
+% if isempty(hlist)
+% uicontrol('Style','popupmenu','Position',[20 20 200 20],'String',textmean);
+% else
+% set(hlist(1),'String',textmean)
+% end
+% end
+% AxeData=Data;
+
+
+%----------------------------------------------------------
+function [AxeData,haxes]=plot_profile(data,CellVarIndex,VarType,haxes,PlotParam)
+%-----------------------------------------------------------
+axes(haxes)
+hfig=get(haxes,'parent');
+AxeData=data;
+ColorOrder=[1 0 0;0 0.5 0;0 0 1;0 0.75 0.75;0.75 0 0.75;0.75 0.75 0;0.25 0.25 0.25];
+set(haxes,'ColorOrder',ColorOrder)
+if isfield(PlotParam,'NextPlot')
+ set(haxes,'NextPlot',PlotParam.NextPlot)
+end
+legend_str={};
+
+%initiates string of the plot command
+plotstr='plot(';
+textmean={};
+abscissa_name='';
+coord_x_index=[];
+for icell=1:length(CellVarIndex)
+ testfalse=0;
+ VarIndex=CellVarIndex{icell};% indices of the selected variables in the list data.ListVarName
+ DimCell=data.VarDimName{VarIndex(1)};
+ if ischar(DimCell)
+ DimCell={DimCell};
+ end
+ XName=DimCell{1}; %first dimension considered as abscissa
+ if ~isempty(VarType{icell}.coord_x)
+ coord_x_index=VarType{icell}.coord_x;
+ else
+ coord_x_index_cell=VarType{icell}.coord(1);
+ if isequal(coord_x_index_cell,0)
+ continue % the cell has no abscissa, skip it
+ end
+ if ~isempty(coord_x_index)&&~isequal(coord_x_index_cell,coord_x_index)
+ continue %all the selected variables must have the same first dimension
+ else
+ coord_x_index=coord_x_index_cell;
+ end
+ end
+ testplot=ones(size(data.ListVarName));%default test for plotted variables
+ testcoordvar=0;
+ charplot_0='''-''';%default
+ if isfield(data,'ObjectProjMode')& isequal(data.ObjectProjMode,'projection')
+ charplot_0='''+''';
+ end
+ xtitle='';
+
+ xtitle=data.ListVarName{coord_x_index};
+ eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
+ if isfield(data,'VarAttribute')&& numel(data.VarAttribute)>=coord_x_index && isfield(data.VarAttribute{coord_x_index},'units')
+ xtitle=[xtitle '(' data.VarAttribute{coord_x_index}.units ')'];
+ end
+ eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
+ testcoordvar=1;
+ testplot(coord_x_index)=0;
+ if ~isempty(VarType{icell}.ancillary')
+ testplot(VarType{icell}.ancillary)=0;
+ end
+ if ~isempty(VarType{icell}.warnflag')
+ testplot(VarType{icell}.warnflag)=0;
+ end
+ if ~isempty(VarType{icell}.discrete')
+ charplot_0='''+''';
+ else
+ charplot_0='''-''';
+ end
+% if testcoordvar==0
+% coord_x{icell}=[1:data.DimValue(DimIndices(1))];%abscissa by default if no coordinate variable
+% % charplot_0='''-''';
+% end
+ if isfield(data,'VarAttribute')
+ VarAttribute=data.VarAttribute;
+ for ivar=1:length(VarIndex)
+ if length(VarAttribute)>=VarIndex(ivar) & isfield(VarAttribute{VarIndex(ivar)},'long_name')
+ plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;
+ else
+ plotname{VarIndex(ivar)}=data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE
+ end
+ end
+ end
+ for ivar=1:length(VarIndex)
+ if testplot(VarIndex(ivar))
+ VarName=data.ListVarName{VarIndex(ivar)};
+ eval(['data.' VarName '=squeeze(data.' VarName ');'])
+ if isequal(VarName,'A')
+ charplot='''-''';
+ else
+ charplot=charplot_0;
+ end
+ plotstr=[plotstr 'coord_x{' num2str(icell) '},data.' VarName ',' charplot ','];
+ eval(['nbcomponent2=size(data.' VarName ',2);']);
+ eval(['nbcomponent1=size(data.' VarName ',1);']);
+ if numel(coord_x{icell})==2
+ coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1);
+ end
+ eval(['varmean=mean(double(data.' VarName '));']);%mean value
+ textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];
+ if nbcomponent1==1| nbcomponent2==1
+ legend_str=[legend_str {VarName}]; %variable with one component
+ else %variable with severals components
+ for ic=1:min(nbcomponent1,nbcomponent2)
+ legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals components
+ end % labeled by their index (e.g. color component)
+ end
+ end
+ end
+end
+if ~isequal(plotstr,'plot(')
+ plotstr(end)=')';
+ %execute plot (instruction plotstr)
+ eval(plotstr)
+ %%%%%
+ grid on
+ hxlabel=xlabel(xtitle);
+ set(hxlabel,'Interpreter','none')% desable tex interpreter
+ if length(legend_str)>=1
+ hylabel=ylabel(legend_str{end});
+ set(hylabel,'Interpreter','none')% desable tex interpreter
+ end
+ if ~isempty(legend_str)
+ hlegend=findobj(hfig,'Tag','legend');
+ if isempty(hlegend)
+ hlegend=legend(legend_str);
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ set(hlegend,'Interpreter','none')% desable tex interpreter
+ end
+ else
+ legend_old=get(hlegend,'String');
+ if isequal(size(legend_old,1),size(legend_str,1))&~isequal(legend_old,legend_str)
+ set(hlegend,'String',[legend_old legend_str]);
+ end
+ end
+ end
+ title_str='';
+ if isfield(data,'filename')
+ [Path, title_str, ext]=fileparts(data.filename);
+ title_str=[title_str ext];
+ end
+ if isfield(data,'Action')
+ if ~isequal(title_str,'')
+ title_str=[title_str ', '];
+ end
+ title_str=[title_str data.Action];
+ end
+ htitle=title(title_str);
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ set(htitle,'Interpreter','none')% desable tex interpreter
+ end
+ % A REPRENDRE Mean
+% hlist=findobj(gcf,'Style','listbox','Tag','liststat');
+% if isempty(hlist)
+% 'text'
+% textmean
+% set(gca,'position',[0.13,0.2,0.775,0.73])
+% uicontrol('Style','popupmenu','Position',[20 20 200 20],'String',textmean,'Tag','liststat');
+% else
+% set(hlist(1),'String',textmean)
+% end
+end
+
+
+%---------------------------------------
+% plot_plane
+%----------------------------------------
+function [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex,VarTypeCell,haxes,PlotParam,KeepLim,PosColorbar)
+
+%default plotting parameters
+PlotType='plane';%default
+if ~exist('PlotParam','var')
+ PlotParam=[];
+end
+if ~isfield(PlotParam,'Scalar')
+ PlotParam.Scalar=[];
+end
+if ~isfield(PlotParam,'Vectors')
+ PlotParam.Vectors=[];
+end
+PlotParamOut=PlotParam;%default
+
+%plotting axes
+hfig=get(haxes,'parent');
+hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes
+hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
+AxeData=get(haxes,'UserData'); %default
+if ~isstruct(AxeData)% AxeData must be a structure
+ AxeData=[];
+end
+AxeData.NbDim=2;
+if isfield(Data,'ObjectCoord')
+ AxeData.ObjectCoord=Data.ObjectCoord;
+end
+
+test_ima=0; %default: test for image or map plot
+test_vec=0; %default: test for vector plots
+test_black=0;
+test_false=0;
+test_C=0;
+XName='';
+x_units='';
+YName='';
+y_units='';
+for icell=1:length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)
+% VarIndex=CellVarIndex{icell};
+ VarType=VarTypeCell{icell};
+ ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[])
+ ivar_Y=VarType.coord_y; % defines (unique)index for the variable representing unstructured y coordinate (default =[])
+ ivar_U=VarType.vector_x; % defines (unique) index for the variable representing x vector component (default =[])
+ ivar_V=VarType.vector_y; % defines (unique) index for the variable representing y vector component (default =[])
+ ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields
+ if numel(ivar_C)>1
+ msgbox_uvmat('ERROR','error in plot_field: too many scalar inputs')
+ return
+ end
+ ivar_F=VarType.warnflag; %defines index (unique) for warning flag variable
+ ivar_FF=VarType.errorflag; %defines index (unique) for error flag variable
+ ind_coord=find(VarType.coord);
+ if numel(ind_coord)==2
+ VarType.coord=VarType.coord(ind_coord);
+ end
+ idim_Y=[];
+ test_grid=0;
+ if ~isempty(ivar_U) && ~isempty(ivar_V)% vector components detected
+ if test_vec
+ msgbox_uvmat('ERROR','error in plot_field: attempt to plot two vector fields')
+ return
+ else
+ test_vec=1;
+ eval(['vec_U=Data.' Data.ListVarName{ivar_U} ';'])
+ eval(['vec_V=Data.' Data.ListVarName{ivar_V} ';'])
+ if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)
+ eval(['vec_X=Data.' Data.ListVarName{ivar_X} ';'])
+ eval(['vec_Y=Data.' Data.ListVarName{ivar_Y} ';'])
+ elseif numel(VarType.coord)==2 & VarType.coord~=[0 0];%coordinates defines by dimension variables
+ eval(['y=Data.' Data.ListVarName{VarType.coord(1)} ';'])
+ eval(['x=Data.' Data.ListVarName{VarType.coord(2)} ';'])
+ if numel(y)==2 % y defined by first and last values on aregular mesh
+ y=linspace(y(1),y(2),size(vec_U,1));
+ end
+ if numel(x)==2 % y defined by first and last values on aregular mesh
+ x=linspace(x(1),x(2),size(vec_U,2));
+ end
+ [vec_X,vec_Y]=meshgrid(x,y);
+ else
+ msgbox_uvmat('ERROR','error in plot_field: invalid coordinate definition for vector field')
+ return
+ end
+ if ~isempty(ivar_C)
+ eval(['vec_C=Data.' Data.ListVarName{ivar_C} ';']) ;
+ vec_C=reshape(vec_C,1,numel(vec_C));
+ test_C=1;
+ end
+ if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))
+ if test_vec
+ eval(['vec_F=Data.' Data.ListVarName{ivar_F} ';']) % warning flags for dubious vectors
+ if ~(isfield(PlotParam.Vectors,'HideWarning') && isequal(PlotParam.Vectors.HideWarning,1))
+ test_black=1;
+ end
+ end
+ end
+ if ~isempty(ivar_FF) %&& ~test_false
+ if test_vec% TODO: deal with FF for structured coordinates
+ eval(['vec_FF=Data.' Data.ListVarName{ivar_FF} ';']) % flags for false vectors
+ end
+ end
+ end
+ elseif ~isempty(ivar_C) %scalar or image
+ if test_ima
+ msgbox_uvmat('ERROR','attempt to plot two scalar fields or images')
+ return
+ end
+ eval(['A=squeeze(Data.' Data.ListVarName{ivar_C} ');']) ;% scalar represented as color image
+ test_ima=1;
+ if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)
+ XName=Data.ListVarName{ivar_X};
+ YName=Data.ListVarName{ivar_Y};
+ eval(['AX=Data.' XName ';'])
+ eval(['AY=Data.' YName ';'])
+ [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256'); % interpolate on a grid
+ if isfield(Data,'VarAttribute')
+ if numel(Data.VarAttribute)>=ivar_X & isfield(Data.VarAttribute{ivar_X},'units')
+ x_units=['(' Data.VarAttribute{ivar_X}.units ')'];
+ end
+ if numel(Data.VarAttribute)>=ivar_Y & isfield(Data.VarAttribute{ivar_Y},'units')
+ y_units=['(' Data.VarAttribute{ivar_Y}.units ')'];
+ end
+ end
+ elseif numel(VarType.coord)==2 %structured coordinates
+ XName=Data.ListVarName{VarType.coord(2)};
+ YName=Data.ListVarName{VarType.coord(1)};
+ eval(['AY=Data.' Data.ListVarName{VarType.coord(1)} ';'])
+ eval(['AX=Data.' Data.ListVarName{VarType.coord(2)} ';'])
+ test_interp_X=0; %default, regularly meshed X coordinate
+ test_interp_Y=0; %default, regularly meshed Y coordinate
+ if isfield(Data,'VarAttribute')
+ if numel(Data.VarAttribute)>=VarType.coord(2) & isfield(Data.VarAttribute{VarType.coord(2)},'units')
+ x_units=['(' Data.VarAttribute{VarType.coord(2)}.units ')'];
+ end
+ if numel(Data.VarAttribute)>=VarType.coord(1) & isfield(Data.VarAttribute{VarType.coord(1)},'units')
+ y_units=['(' Data.VarAttribute{VarType.coord(1)}.units ')'];
+ end
+ end
+ if numel(AY)>2
+ DAY=diff(AY);
+ DAY_min=min(DAY);
+ DAY_max=max(DAY);
+ if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise
+ errormsg=['errror in plot_field.m: non monotonic dimension variable # ' ListVarName{VarType.coord(1)} ];
+ return
+ end
+ test_interp_Y=(DAY_max-DAY_min)> 0.0001*abs(DAY_max);
+ end
+ if numel(AX)>2
+ DAX=diff(AX);
+ DAX_min=min(DAX);
+ DAX_max=max(DAX);
+ if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise
+ errormsg=['errror in plot_field.m: non monotonic dimension variable # ' ListVarName{VarType.coord(2)} ];
+ return
+ end
+ test_interp_X=(DAX_max-DAX_min)> 0.0001*abs(DAX_max);
+ end
+ if test_interp_Y
+ npxy(1)=max([256 floor((AY(end)-AY(1))/DAY_min) floor((AY(end)-AY(1))/DAY_max)]);
+ yI=linspace(AY(1),AY(end),npxy(1));
+ if ~test_interp_X
+ xI=linspace(AX(1),AX(end),size(A,2));%default
+ AX=xI;
+ end
+ end
+ if test_interp_X
+ npxy(1)=max([256 floor((AX(end)-AX(1))/DAX_min) floor((AX(end)-AX(1))/DAX_max)]);
+ xI=linspace(AX(1),AX(end),npxy(2));
+ if ~test_interp_Y
+ yI=linspace(AY(1),AY(end),size(A,1));
+ AY=yI;
+ end
+ end
+ if test_interp_X || test_interp_Y
+ [AX2D,AY2D]=meshgrid(AX,AY);
+ A=interp2(AX2D,AY2D,double(A),xI,yI');
+ end
+ AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation
+ AY=[AY(1) AY(end)];
+ else
+ msgbox_uvmat('ERROR','error in plot_field: invalid coordinate definition ')
+ return
+ end
+ x_label=[Data.ListVarName{ivar_X} '(' x_units ')'];
+ end
+% if isfield(Data,'VarAttribute')
+% VarAttribute=Data.VarAttribute;
+% end
+end
+
+%%%%%%%%%%%%%%%%%%%%% image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%
+
+if ~isfield(PlotParam.Scalar,'Contours')
+ PlotParam.Scalar.Contours=0; %default
+end
+PlotParamOut=PlotParam; %default
+if test_ima
+ % distinguish B/W and color images
+ np=size(A);%size of image
+ siz=size(np);
+ %set the color map
+ if siz(2)==2 %for black and white images
+ if ~isfield(PlotParam.Scalar,'AutoScal')
+ PlotParam.Scalar.AutoScal=0;%default
+ end
+ if ~isfield(PlotParam.Scalar,'MinA')
+ PlotParam.Scalar.MinA=[];%default
+ end
+ if ~isfield(PlotParam.Scalar,'MaxA')
+ PlotParam.Scalar.MaxA=[];%default
+ end
+ if isequal(PlotParam.Scalar.AutoScal,0)|isempty(PlotParam.Scalar.MinA)|~isa(PlotParam.Scalar.MinA,'double') %correct if there is no numerical data in edit box
+ MinA=double(min(min(A)));
+ else
+ MinA=PlotParam.Scalar.MinA;
+ end;
+ if isequal(PlotParam.Scalar.AutoScal,0)|isempty(PlotParam.Scalar.MaxA)|~isa(PlotParam.Scalar.MaxA,'double') %correct if there is no numerical data in edit box
+ MaxA=double(max(max(A)));
+ else
+ MaxA=PlotParam.Scalar.MaxA;
+ end;
+ PlotParamOut.Scalar.MinA=MinA;
+ PlotParamOut.Scalar.MaxA=MaxA;
+ axes(haxes)
+ if isequal(PlotParam.Scalar.Contours,1)
+ if ~isempty(hima) & ishandle(hima)
+ delete(hima)
+ end
+ if ~isfield(PlotParam.Scalar,'IncrA')
+ PlotParam.Scalar.IncrA=[];
+ end
+ if isempty(PlotParam.Scalar.IncrA)% | PlotParam.Scalar.AutoScal==0
+ cont=colbartick(MinA,MaxA);
+ intercont=cont(2)-cont(1);%default
+ PlotParamOut.Scalar.IncrA=intercont;
+ else
+ intercont=PlotParam.Scalar.IncrA;
+ end
+ B=A;
+ abscontmin=intercont*floor(MinA/intercont);
+ abscontmax=intercont*ceil(MaxA/intercont);
+ contmin=intercont*floor(min(min(B))/intercont);
+ contmax=intercont*ceil(max(max(B))/intercont);
+ cont_pos_plus=[0:intercont:contmax];
+ cont_pos_min=[double(contmin):intercont:-intercont];
+ cont_pos=[cont_pos_min cont_pos_plus];
+ sizpx=(AX(end)-AX(1))/(np(2)-1);
+ sizpy=(AY(1)-AY(end))/(np(1)-1);
+ x_cont=[AX(1):sizpx:AX(end)]; % pixel x coordinates for image display
+ y_cont=[AY(1):-sizpy:AY(end)]; % pixel x coordinates for image display
+ txt=ver;%version of Matlab
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ vec=linspace(0,1,(abscontmax-abscontmin)/intercont);%define a greyscale colormap with steps intercont
+ map=[vec' vec' vec'];
+ colormap(map);
+ [var,hcontour]=contour(x_cont,y_cont,B,cont_pos);
+ set(hcontour,'Fill','on')
+ set(hcontour,'LineStyle','none')
+ hold on
+ end
+ [var_p,hcontour_p]=contour(x_cont,y_cont,B,cont_pos_plus,'k-');
+ hold on
+ [var_m,hcontour_m]=contour(x_cont,y_cont,B,cont_pos_min,':');
+ set(hcontour_m,'LineColor',[1 1 1])
+ hold off
+ caxis([abscontmin abscontmax])
+ colormap(map);
+ end
+ if ~isequal(PlotParam.Scalar.Contours,1)
+ % rescale the grey levels with min and max, put a grey scale colorbar
+ if (isfield(PlotParam.Scalar,'BW')& (isequal(PlotParam.Scalar.BW,1))|isa(A,'uint8')| isa(A,'uint16'))%images
+ B=A;
+ vec=linspace(0,1,255);%define a linear greyscale colormap
+ map=[vec' vec' vec'];
+ colormap(map); %grey scale color map
+ else
+ B=A;
+ colormap('default'); % standard faulse colors for div, vort , scalar fields
+ end
+ end
+ elseif siz(2)==3 %color images
+ axes(haxes)
+ B=uint8(A);
+ MinA=0;
+ MaxA=255;
+ end
+ if ~isequal(PlotParam.Scalar.Contours,1)
+ %interpolate to increase resolution
+ test_interp=1;
+ if max(np) <= 64
+ npxy=8*np;% increase the resolution 8 times
+ elseif max(np) <= 128
+ npxy=4*np;% increase the resolution 4 times
+ elseif max(np) <= 256
+ npxy=2*np;% increase the resolution 2 times
+ else
+ npxy=np;
+ test_interp=0; % no interpolation done
+ end
+ if test_interp==1%if we interpolate
+ x=linspace(AX(1),AX(2),np(2));
+ y=linspace(AY(1),AY(2),np(1));
+ [X,Y]=meshgrid(x,y);
+ xi=linspace(AX(1),AX(2),npxy(2));
+ yi=linspace(AY(1),AY(2),npxy(1));
+ B = interp2(X,Y,double(B),xi,yi');
+ end
+ if isempty(hima)
+ tag=get(haxes,'Tag');
+ hima=imagesc(AX,AY,B,[MinA MaxA]);
+ set(hima,'Tag','ima','HitTest','off')
+ set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)
+ else
+ set(hima,'CData',B);
+ if MinAMinA
+ if isequal(PlotParam.Scalar.Contours,1)
+ colbarlim=get(hcol,'YLim');
+ scale_bar=(colbarlim(2)-colbarlim(1))/(abscontmax-abscontmin);
+ YTick=cont_pos(2:end-1);
+ YTick_scaled=colbarlim(1)+scale_bar*(YTick-abscontmin);
+ set(hcol,'YTick',YTick_scaled);
+ elseif (isfield(PlotParam.Scalar,'BW') & isequal(PlotParam.Scalar.BW,1))|isa(A,'uint8')| isa(A,'uint16')%images
+ hi=get(hcol,'children');
+ if iscell(hi)%multiple images in colorbar
+ hi=hi{1};
+ end
+ set(hi,'YData',[MinA MaxA])
+ set(hi,'CData',[1:256]')
+ set(hcol,'YLim',[MinA MaxA])
+ YTick=colbartick(MinA,MaxA);
+ set(hcol,'YTick',YTick)
+ else
+ hi=get(hcol,'children');
+ if iscell(hi)%multiple images in colorbar
+ hi=hi{1};
+ end
+ set(hi,'YData',[MinA MaxA])
+ set(hi,'CData',[1:64]')
+ YTick=colbartick(MinA,MaxA);
+ set(hcol,'YLim',[MinA MaxA])
+ set(hcol,'YTick',YTick)
+ end
+ set(hcol,'Yticklabel',num2str(YTick'));
+ end
+ elseif ishandle(hcol)
+ delete(hcol); %erase existing colorbar if not needed
+ end
+else%no scalar plot
+ if ~isempty(hima) && ishandle(hima)
+ delete(hima)
+ end
+ if ~isempty(hcol)&& ishandle(hcol)
+ delete(hcol)
+ end
+ AxeData.A=[];
+ AxeData.AX=[];
+ AxeData.AY=[];
+ PlotParamOut=rmfield(PlotParamOut,'Scalar');
+end
+
+%%%%%%%%%%%%%%%%%%%%% vector plot %%%%%%%%%%%%%%%%%%%%%%%%%%
+if test_vec
+ %vector scale representation
+ if size(vec_U,1)==numel(vec_Y) && size(vec_U,2)==numel(vec_X); % x, y coordinate variables
+ [vec_X,vec_Y]=meshgrid(vec_X,vec_Y);
+ end
+ vec_X=reshape(vec_X,1,numel(vec_X));%reshape in matlab vectors
+ vec_Y=reshape(vec_Y,1,numel(vec_Y));
+ vec_U=reshape(vec_U,1,numel(vec_U));
+ vec_V=reshape(vec_V,1,numel(vec_V));
+ MinMaxX=max(vec_X)-min(vec_X);
+ MinMaxY=max(vec_Y)-min(vec_Y);
+ AxeData.Mesh=sqrt((MinMaxX*MinMaxY)/length(vec_X));
+ if ~isfield(PlotParam.Vectors,'AutoVec') || isequal(PlotParam.Vectors.AutoVec,0)|| ~isfield(PlotParam.Vectors,'VecScale')...
+ ||isempty(PlotParam.Vectors.VecScale)||~isa(PlotParam.Vectors.VecScale,'double') %automatic vector scale
+ scale=[];
+ if test_false %remove false vectors
+ indsel=find(AxeData.FF==0);%indsel =indices of good vectors
+ else
+ indsel=[1:numel(vec_X)];%
+ end
+ if isempty(vec_U)
+ scale=1;
+ else
+ if isempty(indsel)
+ MaxU=max(abs(vec_U));
+ MaxV=max(abs(vec_V));
+ else
+ MaxU=max(abs(vec_U(indsel)));
+ MaxV=max(abs(vec_V(indsel)));
+ end
+ scale=MinMaxX/(max(MaxU,MaxV)*50);
+ PlotParam.Vectors.VecScale=scale;%update the 'scale' display
+ end
+ else
+ scale=PlotParam.Vectors.VecScale; %impose the length of vector representation
+ end;
+
+ %record vectors on the plotting axes
+ if test_C==0
+ vec_C=ones(1,numel(vec_X));
+ end
+ AxeData.X=vec_X';
+ AxeData.Y=vec_Y';
+ AxeData.U=vec_U';
+ AxeData.V=vec_V';
+ AxeData.C=vec_C';
+ if isempty(ivar_F)
+ AxeData.F=[];
+ else
+ AxeData.F=vec_F';
+ end
+ if isempty(ivar_FF)
+ AxeData.FF=[];
+ else
+ AxeData.FF=vec_FF';
+ end
+% if isfield(Data,'W')
+% AxeData.W=Data.W;
+% end
+
+ %decimate by a factor 2 in vector mesh(4 in nbre of vectors)
+ if isfield(PlotParam.Vectors,'decimate4')&isequal(PlotParam.Vectors.decimate4,1)
+ diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
+ dy_thresh=max(abs(diffy))/2;
+ ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
+ ind_sel=[1:ind_jump(1)];%select the first line
+ for i=2:2:length(ind_jump)-1
+ ind_sel=[ind_sel [ind_jump(i)+1:ind_jump(i+1)]];% select the odd lines
+ end
+ nb_sel=length(ind_sel);
+ ind_sel=ind_sel([1:2:nb_sel]);% take half the points on a line
+ vec_X=vec_X(ind_sel);
+ vec_Y=vec_Y(ind_sel);
+ vec_U=vec_U(ind_sel);
+ vec_V=vec_V(ind_sel);
+ vec_C=vec_C(ind_sel);
+ if ~isempty(ivar_F)
+ vec_F=vec_F(ind_sel);
+ end
+ if ~isempty(ivar_FF)
+ vec_FF=vec_FF(ind_sel);
+ end
+ end
+
+ %get main level color code
+ [colorlist,col_vec,PlotParamOut.Vectors]=set_col_vec(PlotParam.Vectors,vec_C);
+ % take flags into account: add flag colors to the list of colors
+ sizlist=size(colorlist);
+ nbcolor=sizlist(1);
+ if test_black
+ nbcolor=nbcolor+1;
+ colorlist(nbcolor,:)=[0 0 0]; %add black to the list of colors
+ if ~isempty(ivar_FF)
+ ind_flag=find(vec_F~=1 & vec_FF==0); %flag warning but not false
+ else
+ ind_flag=find(vec_F~=1);
+ end
+ col_vec(ind_flag)=nbcolor;
+ end
+ nbcolor=nbcolor+1;
+ if ~isempty(ivar_FF)
+ ind_flag=find(vec_FF~=0);
+ if isfield(PlotParam.Vectors,'HideFalse') && PlotParam.Vectors.HideFalse==1
+ colorlist(nbcolor,:)=[NaN NaN NaN];% no plot of false vectors
+ else
+ colorlist(nbcolor,:)=[1 0 1];% magenta color
+ end
+ col_vec(ind_flag)=nbcolor;
+ end
+ %plot vectors:
+ quiresetn(haxes,vec_X,vec_Y,vec_U,vec_V,scale,colorlist,col_vec);
+else
+ hvec=findobj(haxes,'Tag','vel');
+ if ~isempty(hvec)
+ delete(hvec);
+ end
+ AxeData.X=[];
+ AxeData.Y=[];
+ AxeData.U=[];
+ AxeData.V=[];
+ AxeData.C=[];
+ AxeData.W=[];
+ AxeData.F=[];
+ AxeData.FF=[];
+ AxeData.Mesh=[];
+ PlotParamOut=rmfield(PlotParamOut,'Vectors');
+end
+if isfield(Data,'Z')
+ AxeData.Z=Data.Z;% A REVOIR
+end
+listfields={'AY','AX','A','X','Y','U','V','C','W','F','FF'};
+listdim={'AY','AX',{'AY','AX'},'nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors'};
+Role={'coord_y','coord_x','scalar','coord_x','coord_y','vector_x','vector_y','scalar','vector_z','warnflag','errorflag'};
+ind_select=[];
+nbvar=0;
+AxeData.ListVarName={};
+AxeData.VarDimName={};
+AxeData.VarAttribute={};
+for ilist=1:numel(listfields)
+ eval(['testvar=isfield(AxeData,listfields{ilist}) && ~isempty(AxeData.' listfields{ilist} ');'])
+ if testvar
+ nbvar=nbvar+1;
+ AxeData.ListVarName{nbvar}=listfields{ilist};
+ AxeData.VarDimName{nbvar}=listdim{ilist};
+ AxeData.VarAttribute{nbvar}.Role=Role{ilist};
+ end
+end
+
+% adjust the size of the plot to include the whole field, except if KeepLim=1
+if ~(exist('KeepLim','var') && isequal(KeepLim,1)) %adjust the graph limits*
+ test_lim=0;
+ if test_vec
+ Xlim=[min(vec_X) max(vec_X)];
+ Ylim=[min(vec_Y) max(vec_Y)];
+ test_lim=1;
+ if test_ima%both background image and vectors coexist, take the wider bound
+ Xlim(1)=min(AX(1),Xlim(1));
+ Xlim(2)=max(AX(end),Xlim(2));
+ Ylim(1)=min(AY(end),Ylim(1));
+ Ylim(2)=max(AY(1),Ylim(2));
+ end
+ elseif test_ima %only image plot
+ Xlim(1)=min(AX(1),AX(end));
+ Xlim(2)=max(AX(1),AX(end));
+ Ylim(1)=min(AY(1),AY(end));
+ Ylim(2)=max(AY(1),AY(end));
+ test_lim=1;
+ end
+ if test_lim
+ set(haxes,'XLim',Xlim);% set x limits of frame in axes coordinates
+ set(haxes,'YLim',Ylim);% set y limits of frame in axes coordinate
+ end
+end
+if ~(isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1))
+ set(haxes,'DataAspectRatio',[1 1 1])
+end
+set(haxes,'YDir','normal')
+set(get(haxes,'XLabel'),'String',[XName x_units]);
+set(get(haxes,'YLabel'),'String',[YName y_units]);
+%---------------------------------------------
+%function for plotting vectors
+%------------------------------------------------
+%INPUT:
+% haxes: handles of the plotting axes
+%x,y,u,v: vectors coordinates and vector components to plot, arrays withb the same dimension
+% scale: scaling factor for vector length representation
+%colorlist(icolor,:): list of vector colors, dim (nbcolor,3), depending on color #i
+%col_vec: matlab vector setting the color number #i for each velocity vector
+function quiresetn(haxes,x,y,u,v,scale,colorlist,col_vec)
+
+%define arrows
+theta=0.5 ;%angle arrow
+alpha=0.3 ;%length arrow
+rot=alpha*[cos(theta) -sin(theta); sin(theta) cos(theta)]';
+%find the existing lines
+%h=findobj(gca,'Type','Line');% search existing lines in the current axes
+h=findobj(haxes,'Tag','vel');% search existing lines in the current axes
+sizh=size(h);
+set(h,'EraseMode','xor');
+set(haxes,'NextPlot','replacechildren');
+%htext=findobj('Tag','scalevec');
+
+%drawnow
+%create lines (if no lines) or modify them
+if ~isequal(size(col_vec),size(x))
+ col_vec=ones(size(x));% case of error in col_vec input
+end
+sizlist=size(colorlist);
+ncolor=sizlist(1);
+
+for icolor=1:ncolor
+ %determine the line positions for each color icolor
+ ind=find(col_vec==icolor);
+ xc=x(ind);
+ yc=y(ind);
+ uc=u(ind)*scale;
+ vc=v(ind)*scale;
+ n=size(xc);
+ xN=NaN*ones(size(xc));
+ matx=[xc(:) xc(:)+uc(:) xN(:)]';
+ matx=reshape(matx,1,3*n(2));
+ maty=[yc(:) yc(:)+vc(:) xN(:)]';
+ maty=reshape(maty,1,3*n(2));
+
+ %determine arrow heads
+ arrowplus=rot*[uc;vc];
+ arrowmoins=rot'*[uc;vc];
+ x1=xc+uc-arrowplus(1,:);
+ x2=xc+uc;
+ x3=xc+uc-arrowmoins(1,:);
+ y1=yc+vc-arrowplus(2,:);
+ y2=yc+vc;
+ y3=yc+vc-arrowmoins(2,:);
+ matxar=[x1(:) x2(:) x3(:) xN(:)]';
+ matxar=reshape(matxar,1,4*n(2));
+ matyar=[y1(:) y2(:) y3(:) xN(:)]';
+ matyar=reshape(matyar,1,4*n(2));
+ %draw the line or modify the existing ones
+ isn=isnan(colorlist(icolor,:));%test if color NaN
+ if 2*icolor > sizh(1) %if icolor exceeds the number of existing ones
+ axes(haxes)
+ if ~isn(1) %if the vectors are visible color not nan
+ if n(2)>0
+ hold on
+ line(matx,maty,'Color',colorlist(icolor,:),'Tag','vel');% plot new lines
+ line(matxar,matyar,'Color',colorlist(icolor,:),'Tag','vel');% plot arrows
+ end
+ end
+ else
+ if isn(1)
+ delete(h(2*icolor-1))
+ delete(h(2*icolor))
+ else
+ set(h(2*icolor-1),'Xdata',matx,'Ydata',maty);
+ set(h(2*icolor-1),'Color',colorlist(icolor,:));
+ set(h(2*icolor-1),'EraseMode','xor');
+ set(h(2*icolor),'Xdata',matxar,'Ydata',matyar);
+ set(h(2*icolor),'Color',colorlist(icolor,:));
+ set(h(2*icolor),'EraseMode','xor');
+ end
+ end
+end
+if sizh(1) > 2*ncolor
+ for icolor=ncolor+1 : sizh(1)/2%delete additional objects
+ delete(h(2*icolor-1))
+ delete(h(2*icolor))
+ end
+end
+
+%---------------------------------------
+%determine tick positions for colorbar
+%------------------------------------
+function YTick=colbartick(MinA,MaxA)
+%determine tick positions with "simple" values between MinA and MaxA
+YTick=0;%default
+maxabs=max([abs(MinA) abs(MaxA)]);
+if maxabs>0
+ord=10^(floor(log10(maxabs)));%order of magnitude
+div=1;
+siz2=1;
+while siz2<2
+% values=[-9:div:9];
+ values=-10:div:10;
+ ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);%indices of 'values' such that MinA0);
+ end
+ siz2=size(ind,2);
+% siz2=siz(2)
+ div=div/10;
+end
+YTick=ord*values(ind);
+end
Index: /trunk/src/plot_object.m
===================================================================
--- /trunk/src/plot_object.m (revision 2)
+++ /trunk/src/plot_object.m (revision 2)
@@ -0,0 +1,408 @@
+%'plot_object': draws a projection object (points, line, plane...)
+%-------------------------------------------------------------------
+% function [ObjectData_out,hh]=plot_object(ObjectData,hplot,col)
+%
+%OUTPUT
+% hh: handles of the graphic object (core part)
+%
+%INPUT:
+%
+% ObjectDataIn: structure representing the object properties:
+% .Style : style of projection object
+% .Coord: set of coordinates defining the object position;
+% .ProjMode=type of projection ;
+% .ProjAngle=angle of projection;
+% .DX,.DY,.DZ=increments;
+% .YMax,YMin: min and max Y
+% ProjObject: projection object corresponding to the current plot (e. g. plane)
+% hplot: handle of the object plot to modify or if it is an axis, the axis
+% where the object must be plotted, or if it is a figure the plotting figure
+% col: color of the plot, e;g; 'm', 'b' ..;
+
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function [hh]=plot_object(ObjectDataIn,ProjObject,hplot,col)
+hh=[];%default output
+if isequal(ProjObject,ObjectDataIn)% object representation does not appear in its own projection plot
+ return
+end
+if ~isfield(ProjObject,'Style')
+ ObjectData=ObjectDataIn;
+elseif isequal(ProjObject.Style,'plane')
+ ObjectData=ObjectDataIn;% TODO: modify take into account rotation of axis
+else
+ return % no object representation yet available
+end
+if ~isfield(ObjectData,'Style')|isempty(ObjectData.Style)|~ischar(ObjectData.Style)
+ warndlg_uvmat('undefined ObjectData.Style in plot_object.m','ERROR')
+ return
+end
+if ~isfield(ObjectData,'Style')|isempty(ObjectData.Style)|~ischar(ObjectData.Style)
+ warndlg_uvmat('undefined ObjectData.Style in plot_object.m','ERROR')
+ return
+end
+XMin=0;%default
+XMax=0;
+YMin=0;
+YMax=0;
+ZMin=0;
+ZMax=0;
+
+%determine the plotting axes (with handle 'haxes')
+test_newobj=1;
+if ishandle(hplot)
+ if isequal(get(hplot,'Tag'),'proj_object')
+ test_newobj=0;
+ haxes=get(hplot,'parent');
+ elseif isequal(get(hplot,'Type'),'axes')
+ axes(hplot)
+ haxes=hplot;
+ elseif isequal(get(hplot,'Type'),'figure')
+ figure(hplot);%set the input figure as the current one
+ haxes=findobj(hplot,'Type','axes');%look for axes in the figure
+ haxes=haxes(1);
+ axes(haxes); %set the first found axis as the current one
+ else
+ figure; %create new figure
+ hplot=axes;%create new axes
+ haxes=hplot;
+ end
+else
+ figure; %create new figure
+ hplot=axes;%create new axes
+ haxes=hplot;
+end
+
+%default input parameters
+if ~isfield(ObjectData,'ProjMode')|isempty(ObjectData.ProjMode)
+ ObjectData.ProjMode='projection';%default
+end
+if ~isfield(ObjectData,'Coord')|isempty(ObjectData.Coord)
+ ObjectData.Coord=[0 0 0];%default
+end
+if ~isfield(ObjectData,'Phi')|isempty(ObjectData.Phi)
+ ObjectData.Phi=0;%default
+end
+if ~isfield(ObjectData,'Range')
+ ObjectData.Range(1,1)=0; %edfault
+end
+if size(ObjectData.Range,2)>=2
+ YMax=ObjectData.Range(1,2);%default
+end
+if size(ObjectData.Range,2)>=2 & size(ObjectData.Range,1)>=2
+ YMin=ObjectData.Range(2,2);
+else
+ YMin=0;
+end
+XMax=ObjectData.Range(1,1);
+if size(ObjectData.Range,1)>=2
+ XMin=ObjectData.Range(2,1);
+end
+if isfield(ObjectData,'RangeX')
+ XMax=max(ObjectData.RangeX);
+ XMin=min(ObjectData.RangeX);
+end
+if isfield(ObjectData,'RangeY')
+ YMax=max(ObjectData.RangeY);
+ YMin=min(ObjectData.RangeY);
+end
+if isfield(ObjectData,'RangeZ')
+ ZMax=max(ObjectData.RangeZ);
+ ZMin=min(ObjectData.RangeZ);
+end
+if isequal(ObjectData.Style,'points')&isequal(ObjectData.ProjMode,'projection')
+ YMax=max(XMax,YMax);
+ YMax=max(YMax,ZMax);
+elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')|isequal(ObjectData.Style,'volume')
+ if isequal(YMax,0)
+ ylim=get(haxes,'YLim');
+ YMax=(ylim(2)-ylim(1))/100;
+ end
+ if isequal(XMax,0)
+ XMax=YMax;%default
+ end
+elseif isequal(ObjectData.Style,'plane')
+ if isequal(XMax,0)
+ xlim=get(haxes,'XLim');
+ XMax=xlim(2);
+ end
+ if isequal(YMax,0)
+ ylim=get(haxes,'YLim');
+ YMax=ylim(2);
+ end
+end
+sizcoord=size(ObjectData.Coord);
+
+%determine the coordinates xline, yline,xsup,xinf, yinf,ysup determining the new object plot
+test_line= isequal(ObjectData.Style,'points')|isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|...
+ isequal(ObjectData.Style,'polygon')| isequal(ObjectData.Style,'plane')| isequal(ObjectData.Style,'volume');
+test_patch=isequal(ObjectData.ProjMode,'inside')||isequal(ObjectData.ProjMode,'outside')||isequal(ObjectData.Style,'volume')...
+ ||isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside');
+if test_line
+ xline=ObjectData.Coord(:,1);
+ yline=ObjectData.Coord(:,2);
+ if isequal(ObjectData.Style,'polygon')
+ xline=[xline; ObjectData.Coord(1,1)];%closing the line
+ yline=[yline; ObjectData.Coord(1,2)];
+ elseif isequal(ObjectData.Style,'plane')| isequal(ObjectData.Style,'volume')
+ phi=ObjectData.Phi*pi/180;%angle in radians
+ Xend_x=xline(1)+XMax*cos(phi);
+ Xend_y=yline(1)+XMax*sin(phi);
+ Xbeg_x=xline(1)+XMin*cos(phi);
+ Xbeg_y=yline(1)+XMin*sin(phi);
+ Yend_x=xline(1)-YMax*sin(phi);
+ Yend_y=yline(1)+YMax*cos(phi);
+ Ybeg_x=xline(1)-YMin*sin(phi);
+ Ybeg_y=yline(1)+YMin*cos(phi);
+ xline=[Xbeg_x Xend_x NaN Ybeg_x Yend_x];
+ yline=[Xbeg_y Xend_y NaN Ybeg_y Yend_y];
+ end
+ SubLineStyle='none';%default
+ if isfield(ObjectData,'ProjMode')
+ if isequal(ObjectData.ProjMode,'projection')
+ SubLineStyle='--'; %range of projection marked by dash
+ if isfield (ObjectData,'DX')
+ rmfield(ObjectData,'DX');
+ end
+ if isfield (ObjectData,'DY')
+ rmfield(ObjectData,'DY');
+ end
+ elseif isequal(ObjectData.ProjMode,'filter')
+ SubLineStyle=':';%range of projection not visible
+ end
+ end
+ if isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|isequal(ObjectData.Style,'polygon')
+ if length(xline)<2
+ theta=0;
+ else
+ theta=angle(diff(xline)+i*diff(yline));
+ theta(length(xline))=theta(length(xline)-1);
+ end
+ xsup(1)=xline(1)+YMax*sin(theta(1));
+ xinf(1)=xline(1)-YMax*sin(theta(1));
+ ysup(1)=yline(1)-YMax*cos(theta(1));
+ yinf(1)=yline(1)+YMax*cos(theta(1));
+ for ip=2:length(xline)
+ xsup(ip)=xline(ip)+YMax*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+ xinf(ip)=xline(ip)-YMax*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+ ysup(ip)=yline(ip)-YMax*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+ yinf(ip)=yline(ip)+YMax*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+ end
+ end
+end
+
+%shading image
+if test_patch
+ npMx=512;
+ npMy=512;
+ flag=zeros(npMy,npMx);
+ if isequal(ObjectData.Style,'ellipse')
+ XimaMin=ObjectData.Coord(1,1)-XMax;
+ XimaMax=ObjectData.Coord(1,1)+XMax;
+ YimaMin=ObjectData.Coord(1,2)-YMax;
+ YimaMax=ObjectData.Coord(1,2)+YMax;
+ xlim=[1.2*XimaMin-0.2*XimaMax 1.2*XimaMax-0.2*XimaMin];%create an image around the ellipse
+ ylim=[1.2*YimaMin-0.2*YimaMax 1.2*YimaMax-0.2*YimaMin];
+ scale_x=2*1.4*XMax/npMx;
+ scale_y=2*1.4*YMax/npMy;
+ xi=[0.5:npMx-0.5]*scale_x+xlim(1);
+ yi=[0.5:npMy-0.5]*scale_y+ylim(1);
+ [Xi,Yi]=meshgrid(xi,yi);
+ X2Max=XMax*XMax;
+ Y2Max=YMax*YMax;
+ distX=(Xi-ObjectData.Coord(1,1));
+ distY=(Yi-ObjectData.Coord(1,2));
+ flag=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
+ elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'volume')
+ XimaMin=ObjectData.Coord(1,1)-XMax;
+ XimaMax=ObjectData.Coord(1,1)+XMax;
+ YimaMin=ObjectData.Coord(1,2)-YMax;
+ YimaMax=ObjectData.Coord(1,2)+YMax;
+ xlim=[1.2*XimaMin-0.2*XimaMax 1.2*XimaMax-0.2*XimaMin];%create an image around the ellipse
+ ylim=[1.2*YimaMin-0.2*YimaMax 1.2*YimaMax-0.2*YimaMin];
+ scale_x=2*1.4*XMax/npMx;
+ scale_y=2*1.4*YMax/npMy;
+ xi=[0.5:npMx-0.5]*scale_x+xlim(1);
+ yi=[0.5:npMy-0.5]*scale_y+ylim(1);
+ [Xi,Yi]=meshgrid(xi,yi);
+ distX=abs(Xi-ObjectData.Coord(1,1));
+ distY=abs(Yi-ObjectData.Coord(1,2));
+ flag=distXlength(PlotData.SubObject)
+ for ipt=length(PlotData.SubObject)+1:size(ObjectData.Coord,1)
+ PlotData.SubObject(ipt)=rectangle('Curvature',[1 1],...
+ 'Position',[ObjectData.Coord(ipt,1)-YMax ObjectData.Coord(ipt,2)-YMax 2*YMax 2*YMax],'EdgeColor',col,...
+ 'LineStyle',SubLineStyle,'Tag','proj_object');
+ end
+ end
+ end
+ end
+ if isfield(PlotData,'DeformPoint')
+ for ipt=1:length(PlotData.DeformPoint)
+ if ishandle(PlotData.DeformPoint(ipt))
+ if length(xline)>=ipt & length(yline)>=ipt
+ set(PlotData.DeformPoint(ipt),'XData',xline(ipt),'YData',yline(ipt));
+ end
+ end
+ end
+ if length(xline)>length(PlotData.DeformPoint)
+ for ipt=length(PlotData.DeformPoint)+1:length(xline)
+ PlotData.DeformPoint(ipt)=line(xline(ipt),yline(ipt),'Color',col,'LineStyle','.','Tag','DeformPoint',...
+ 'SelectionHighlight','off','UserData',hplot);
+ end
+ set(hplot,'UserData',PlotData)
+ end
+ end
+ elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')
+ set(hplot,'Position',[ObjectData.Coord(1,1)-XMax ObjectData.Coord(1,2)-YMax 2*XMax 2*YMax])
+ end
+ if test_patch
+ for iobj=1:length(PlotData.SubObject)
+ objtype=get(PlotData.SubObject(iobj),'Type');
+ if isequal(objtype,'image')
+ set(PlotData.SubObject(iobj),'CData',imflag,'AlphaData',(flag)*0.2)
+ set(PlotData.SubObject(iobj),'XData',[xlim(1)+dx/2 xlim(2)-dx/2])
+ set(PlotData.SubObject(iobj),'YData',[ylim(1)+dy/2 ylim(2)-dy/2])
+ end
+ end
+ end
+end
+
+%create the object
+if test_newobj
+ axes(haxes)
+ hother=findobj('Tag','proj_object');%find all the proj objects
+ for iobj=1:length(hother)
+ if isequal(get(hother(iobj),'Type'),'rectangle')|isequal(get(hother(iobj),'Type'),'patch')
+ set(hother(iobj),'EdgeColor','b')
+ if isequal(get(hother(iobj),'FaceColor'),'m')
+ set(hother(iobj),'FaceColor','b')
+ end
+ elseif isequal(get(hother(iobj),'Type'),'image')
+ Acolor=get(hother(iobj),'CData');
+ Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
+ set(hother(iobj),'CData',Acolor);
+ else
+ set(hother(iobj),'Color','b')
+ end
+ set(hother(iobj),'Selected','off')
+ end
+ hother=findobj('Tag','DeformPoint');
+ set(hother,'Color','b');
+ set(hother,'Selected','off')
+ if isequal(ObjectData.Style,'points')
+ hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color',col,'LineStyle','.','Marker','+');
+ for ipt=1:length(xline)
+ PlotData.DeformPoint(ipt)=line(ObjectData.Coord(ipt,1),ObjectData.Coord(ipt,2),'Color',...
+ col,'LineStyle','.','SelectionHighlight','off','UserData',hh,'Tag','DeformPoint');
+ %create circle around each point
+ if ~isequal(YMax,0)
+ PlotData.SubObject(ipt)=rectangle('Curvature',[1 1],...
+ 'Position',[ObjectData.Coord(ipt,1)-YMax ObjectData.Coord(ipt,2)-YMax 2*YMax 2*YMax],'EdgeColor',col,...
+ 'LineStyle',SubLineStyle,'Tag','proj_object');
+ end
+ end
+ elseif isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|...
+ isequal(ObjectData.Style,'polygon') |isequal(ObjectData.Style,'plane')|isequal(ObjectData.Style,'volume')% (isequal(ObjectData.Style,'polygon') & ~test_patch) |isequal(ObjectData.Style,'plane')
+ hh=line(xline,yline,'Color',col);
+ if ~isequal(ObjectData.Style,'plane')& ~isequal(ObjectData.Style,'volume')
+ for ipt=1:sizcoord(1)
+ PlotData.DeformPoint(ipt)=line(ObjectData.Coord(ipt,1),ObjectData.Coord(ipt,2),'Color',...
+ col,'LineStyle','none','Marker','.','Tag','DeformPoint','SelectionHighlight','off','UserData',hh);
+ end
+ PlotData.SubObject(1)=line(xinf,yinf,'Color',col,'LineStyle',SubLineStyle,'Tag','proj_object');%draw sub-lines
+ PlotData.SubObject(2)=line(xsup,ysup,'Color',col,'LineStyle',SubLineStyle,'Tag','proj_object');
+ end
+
+ elseif isequal(ObjectData.Style,'rectangle')
+ hh=rectangle('Position',[ObjectData.Coord(1,1)-XMax ObjectData.Coord(1,2)-YMax 2*XMax 2*YMax],'EdgeColor',col);
+ elseif isequal(ObjectData.Style,'ellipse')
+ hh=rectangle('Curvature',[1 1],'Position',[ObjectData.Coord(1,1)-XMax ObjectData.Coord(1,2)-YMax 2*XMax 2*YMax],'EdgeColor',col);
+ else
+ warndlg_uvmat('unknown ObjectData.Style in plot_object.m','ERROR')
+ return
+ end
+ set(hh,'Tag','proj_object')
+ %set(hh,'UserData',ObjectData)%
+% hh=hplot;
+% set(hh,'DeleteFcn',@deletefcn)
+% if isequal(ObjectData.ProjMode,'inside')
+% if isequal(ObjectData.Style,'ellipse')|isequal(ObjectData.Style,'rectangle')
+% set(hh,'FaceColor',col)
+% set(hh,'EdgeColor',col)
+% end
+% end
+ if test_patch
+ hold on
+ hhh=image([xlim(1)+dx/2 xlim(2)-dx/2],[ylim(1)+dy/2 ylim(2)-dy/2],imflag,'Tag','proj_object','HitTest','off');
+ set(hhh,'AlphaData',(flag)*0.2)
+ PlotData.SubObject=hhh;
+ end
+ if isfield(PlotData,'SubObject')
+ set(PlotData.SubObject,'UserData',hh)%record the parent handles in the SubObjects
+ end
+ if isfield(PlotData,'DeformPoint')
+ for ipt=1:sizcoord(1)
+ set(PlotData.DeformPoint(ipt),'UserData',hh);%record the parent handles in the SubObjects
+ end
+ set(PlotData.DeformPoint,'UserData',hh)%record the parent handles in the SubObjects
+ end
+end
+set(hh,'UserData',PlotData)
Index: /trunk/src/plot_text.m
===================================================================
--- /trunk/src/plot_text.m (revision 2)
+++ /trunk/src/plot_text.m (revision 2)
@@ -0,0 +1,86 @@
+%'plot_text': function for displaying the content of a Matlab structure in a figure
+%------------------------------------------------------------------------
+% function hdisplay=plot_text(FieldData,hdisplay_in)
+%
+% OUTPUT:
+% hdisplay: handle of the display edit box
+%
+% INPUT:
+% FieldData: input Matlab structure
+% hdisplay_in: handles of the display box, if it is not defined create a new figure
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function hdisplay=plot_text(FieldData,hdisplay_in)
+
+if exist('hdisplay_in','var') & ishandle(hdisplay_in) & isequal(get(hdisplay_in,'Type'),'uicontrol')
+ hdisplay=hdisplay_in;
+else
+ figure;%create new figure
+ hdisplay=uicontrol('Style','edit', 'Units','normalized','Position', [0 0 1 1],'Max',2,'FontName','monospaced');
+end
+
+ff=fields(FieldData);%list of field names
+vv=struct2cell(FieldData);%list of field values
+
+for icell=1:length(vv)
+ Tabcell{icell,1}=ff{icell};
+ ss=vv{icell};
+ sizss=size(ss);
+ if isnumeric(ss)
+ if sizss(1)<=1 & length(ss)<5
+ displ{icell}=num2str(ss);
+ else
+ displ{icell}=[class(ss) ', size ' num2str(size(ss))];
+ end
+ elseif ischar(ss)
+ displ{icell}=ss;
+ elseif iscell(ss)
+ sizcell=size(ss);
+ if sizcell(1)==1 & length(sizcell)==2 %line cell
+ ssline='{''';
+ for icolumn=1:sizcell(2)
+ if isnumeric(ss{icolumn})
+ if size(ss{icolumn},1)<=1 & length(ss{icolumn})<5
+ sscolumn=num2str(ss{icolumn});%line vector
+ else
+ sscolumn=[class(ss{icolumn}) ', size ' num2str(size(ss{icolumn}))];
+ end
+ elseif ischar(ss{icolumn})
+ sscolumn=ss{icolumn};
+ else
+ sscolumn=class(ss{icolumn});
+ end
+ if icolumn==1
+ ssline=[ssline sscolumn];
+ else
+ ssline=[ssline ''',''' sscolumn];
+ end
+ end
+ displ{icell}=[ssline '''}'];
+ else
+ displ{icell}=[class(ss) ', size ' num2str(sizcell)];
+ end
+ else
+ displ{icell}=class(ss);
+ end
+ Tabcell{icell,2}=displ{icell};
+end
+Tabchar=cell2tab(Tabcell,': ');
+set(hdisplay,'String', Tabchar)
+
+
Index: /trunk/src/probe_calib.m
===================================================================
--- /trunk/src/probe_calib.m (revision 2)
+++ /trunk/src/probe_calib.m (revision 2)
@@ -0,0 +1,877 @@
+%'probe_calib': performs geometric calibration from a set of reference points
+function varargout = probe_calib(varargin)
+% PROBE_CALIB M-file for probe_calib.fig
+% PROBE_CALIB, by itself, creates a MenuCoord PROBE_CALIB or raises the existing
+% singleton*.
+%
+% H = PROBE_CALIB returns the handle to a MenuCoord PROBE_CALIB or the handle to
+% the existing singleton*.
+%
+% PROBE_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local
+% function named CALLBACK in PROBE_CALIB.M with the given input arguments.
+%
+% PROBE_CALIB('Property','Value',...) creates a MenuCoord PROBE_CALIB or raises the
+% existing singleton*. Starting from the left, property value pairs are
+% applied to the GUI before probe_calib_OpeningFunction gets called. An
+% unrecognized property name or invalid value makes property application
+% stop. All inputs are passed to probe_calib_OpeningFcn via varargin.
+%
+% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
+% instance to run (singleton)".
+%
+% See also: GUIDE, GUIDATA, GUIHANDLES
+
+% Edit the above text to modify the response to help probe_calib
+
+% Last Modified by GUIDE v2.5 04-Feb-2008 15:46:42
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @probe_calib_OpeningFcn, ...
+ 'gui_OutputFcn', @probe_calib_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin & isstr(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+
+% --- Executes just before probe_calib is made visible.
+%INPUT:
+%handles: handles of the probe_calib interface elements
+% PlotHandles: set of handles of the elements contolling the plotting
+% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
+function probe_calib_OpeningFcn(hObject, eventdata, handles, data,pos,inputfile)
+
+% Choose default command line output for probe_calib
+handles.output = hObject;
+
+% Update handles structure
+guidata(hObject, handles);
+
+%default
+% set(hObject,'Unit','Normalized')% set the unit normalized to the screen size
+% set(hObject,'Position',[0.7 0.1 0.25 0.5])%set the position of the probe_calib interface
+set(hObject,'DeleteFcn',@closefcn)
+
+%set the position of the interface
+if exist('pos','var')& length(pos)>2
+ pos_gui=get(hObject,'Position');
+ pos_gui(1)=pos(1);
+ pos_gui(2)=pos(2);
+ set(hObject,'Position',pos_gui);
+end
+% set(handles.XImage,'String','')
+% set(handles.YImage,'String','')
+% set(handles.XObject,'String','')
+% set(handles.YObject,'String','')
+% set(handles.ZObject,'String','')
+inputxml='';
+if exist('inputfile','var')& ~isempty(inputfile)
+ [Path,Name,ext]=fileparts(inputfile);
+ if isequal(ext,'.png')
+ set(hObject,'UserData',inputfile)
+ [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile);
+ inputxml=[fullfile(Pathsub,RootFile) '.xml'];
+ end
+end
+if exist(inputxml,'file')
+ loadfile(handles,inputxml)
+end
+set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function
+
+
+% --- Outputs from this function are returned to the command line.
+function varargout = probe_calib_OutputFcn(hObject, eventdata, handles)
+% varargout cell array for returning output args (see VARARGOUT);
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+varargout{2}=handles;
+
+%------------
+function Phi_Callback(hObject, eventdata, handles)
+
+
+%-----------------------------------------------------
+% --- Executes on button press in import.
+function import_Callback(hObject, eventdata, handles)
+%get the object file
+huvmat=findobj('Tag','uvmat');
+UvData=get(huvmat,'UserData');
+hchild=get(huvmat,'Children');
+hrootpath=findobj(hchild,'Tag','RootPath');
+oldfile=get(hrootpath,'String');
+if isempty(oldfile)
+ oldfile='';
+end
+%[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile)
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.xml;*.mat', ' (*.xml,*.mat)';
+ '*.xml', '.xml files '; ...
+ '*.mat', '.mat matlab files '}, ...
+ 'Pick a file',oldfile);
+fileinput=[PathName FileName];%complete file name
+testblank=findstr(fileinput,' ');%look for blanks
+if ~isempty(testblank)
+ warndlg_uvmat('forbidden input file name or path: no blank character allowed','ERROR')
+ return
+end
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
+loadfile(handles,fileinput)
+
+%--------------------------------------------------
+%read input xml file and update the edit boxes
+function loadfile(handles,fileinput)
+
+%read the input xml file
+t=xmltree(fileinput);
+s=convert(t);%convert to matlab structure
+
+%read data currently displayed on the interface
+PointCoord=[];
+data=read_probe_calib(handles);
+Coord=[]; %default
+if isfield(data,'Coord')
+ Coord=data.Coord;
+end
+TabChar_0=get(handles.ListCoord,'String');
+nbcoord_0=size(TabChar_0,1);
+if isequal(get(handles.edit_append,'Value'),1) %edit mode
+ val=get(handles.ListCoord,'Value')-1;
+else
+ val=length(TabChar_0);
+end
+nbcoord=0;
+
+%case of calibration (ImaDoc) input file
+if isfield(s,'GeometryCalib')
+ Calib=s.GeometryCalib;
+ if isfield(Calib,'SourceCalib')
+ if isfield(Calib.SourceCalib,'PointCoord')
+ PointCoord=Calib.SourceCalib.PointCoord;
+ end
+ if isfield(Calib.SourceCalib,'ImageCalib')
+ hcalib=get(handles.import,'parent');
+ set(hcalib,'UserData',Calib.SourceCalib.ImageCalib);%store the source image name in the interface 'UserData'
+ end
+ end
+ nbcoord=length(PointCoord);
+ if ~isfield(Calib,'ErrorRms')&~isfield(Calib,'ErrorMax') %old convention of Gauthier (cord in mm)
+ for i=1:length(PointCoord)
+ line=str2num(PointCoord{i});
+ Coord(i+val,4:5)=line(4:5);%px x
+ Coord(i+val,1:3)=line(1:3)/10;%phys x
+ end
+ else
+ for i=1:length(PointCoord)
+ line=str2num(PointCoord{i});
+ Coord(i,4:5)=line(4:5);%px x
+ Coord(i,1:3)=line(1:3);%phys x
+ end
+ end
+end
+
+%case of xml files of points
+if isfield(s,'Coord')
+ PointCoord=s.Coord;
+ nbcoord=length(PointCoord);
+ %case of image coordinates
+ if isfield(s,'CoordType')& isequal(s.CoordType,'px')
+ for i=1:nbcoord
+ line=str2num(PointCoord{i});
+ Coord(i+val,4:5)=line(1:2);
+ end
+ %case of physical coordinates
+ else
+ for i=1:nbcoord
+ line=str2num(PointCoord{i})
+ Coord(i+val,1:3)=line(1:3);
+ nbcolumn=size(Coord,2);
+ if nbcolumn<5
+ Coord(i+val,nbcolumn+1:5)=zeros(1,5-nbcolumn);
+ end
+ end
+ end
+end
+CoordCell={};
+for iline=1:size(Coord,1)
+ for j=1:5
+ CoordCell{iline,j}=num2str(Coord(iline,j));
+ end
+end
+
+Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display
+set(handles.ListCoord,'Value',1)
+set(handles.ListCoord,'String',Tabchar)
+
+
+%----------------------------------------------------
+% executed when closing: set the parent interface button to value 0
+function closefcn(gcbo,eventdata)
+SetData=get(gcbf,'UserData');
+if isfield(SetData,'ParentButton') & ishandle(SetData.ParentButton)
+ set(SetData.ParentButton, 'Value',0)
+end
+
+%-----------------------------------------------------------------------
+% --- Executes on button press in edit: PLOT the defined object and its projected field
+function edit_Callback(hObject, eventdata, handles)
+%hsetobject=get(hObject,'parent');
+%SetData=get(hsetobject,'UserData');%get the hidden interface data
+%IndexObj=SetData.IndexObj;%index of the current projection object in the list of projection objects (UvData.ProjObject)
+huvmat=findobj(allchild(0),'name','uvmat');%find the current uvmat interface handle
+UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
+hplot=findobj(huvmat,'Tag','axes3');
+h_menu_coord=findobj(huvmat,'Tag','menu_coord');
+menu=get(h_menu_coord,'String');
+choice=get(h_menu_coord,'Value');
+if iscell(menu)
+ option=menu{choice};
+else
+ option='px'; %default
+end
+%get axis
+%get CoordType
+ObjectData=read_probe_calib(handles);%read the interface input parameters defining the object
+if isequal(option,'phys')
+ ObjectData.Coord=ObjectData.Coord(:,[1:3]);
+elseif isequal(option,'px')
+ ObjectData.Coord=ObjectData.Coord(:,[4:5]);
+else
+ errordlg('the choice in coord_coord must be px or phys ')
+end
+% [UvData,IndexObj]=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles);
+% SetData.IndexObj=IndexObj;
+% set(gcbf,'UserData',SetData)%update object index in the probe_calib interface
+% set(huvmat,'UserData',UvData)%update the data in the uvmat interface
+ObjectData.ProjMode='none';
+plot_object(ObjectData,[],hplot,'b');
+
+
+% --- Executes on button press in MenuCoord.
+function MenuCoord_Callback(hObject, eventdata, handles)
+
+
+% --- Executes on button press in delete.
+function delete_Callback(hObject, eventdata, handles)
+SetData=get(gcbf,'UserData');%get the interface data
+IndexObj=SetData.IndexObj;
+delete_object(IndexObj);
+
+% --- Executes on button press in calibrate_lin.
+function calib_offset_Callback(hObject, eventdata, handles)
+Object=read_probe_calib(handles);
+
+%make linear calibration
+% 'calibration_lin' provides a linear transform on coordinates,
+X=Object.Coord(:,1);
+Y=Object.Coord(:,2);
+x_ima=Object.Coord(:,4);
+y_ima=Object.Coord(:,5);
+[px,sx]=polyfit(X,x_ima,1);
+[py,sy]=polyfit(Y,y_ima,1);
+%err_X1=max(abs(x1-x_ima));%error
+%err_Y1=max(abs(y1-y_ima));%error
+T_x=px(2);
+T_y=py(2);
+GeometryCalib.focal=1;
+GeometryCalib.Tx_Ty_Tz=[T_x T_y 1];
+GeometryCalib.R=[px(1),0,0;0,py(1),0;0,0,1];
+%check error
+Calib.dpx=1;
+Calib.dpy=1;
+Calib.sx=1;
+Calib.Cx=0;
+Calib.Cy=0;
+Calib.Tz=1;
+Calib.kappa1=0;
+Calib.f=GeometryCalib.focal;
+Calib.Tx=T_x;
+Calib.Ty=T_y;
+Calib.R=GeometryCalib.R;
+[Xpoints,Ypoints]=px_XYZ(Calib,X,Y,0);
+GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
+GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
+GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
+GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima))
+%calibrate_lin calibration results and point coordinates
+huvmat=findobj('Tag','uvmat');
+hchild=get(huvmat,'Children');
+hrootpath=findobj(hchild,'Tag','RootPath');
+hrootfile=findobj(hchild,'Tag','RootFile');
+RootPath='';
+RootFile='';
+if ~isempty(hrootpath)& ~isempty(hrootfile)
+ testhandle=1;
+ RootPath=get(hrootpath,'String');
+ RootFile=get(hrootfile,'String');
+ filebase=fullfile(RootPath,RootFile);
+ outputfile=[filebase '.xml']
+else
+ question={'save the calibration data and point coordinates in'};
+ def={fullfile(RootPath,['ObjectCalib.xml'])};
+ options.Resize='on';
+ answer=inputdlg(question,'save average in a new file',1,def,options);
+ outputfile=answer{1};
+end
+testappend=0;
+if exist(outputfile,'file');%=1 if the output file already exists, 0 else
+ t=xmltree(outputfile); %read the file
+ uid=find(t,'ImaDoc');
+ if ~isequal(uid,1)%if the xml file is not ImaDoc, delete it (after backup)
+ backupfile=outputfile;
+ testexist=2;
+ while testexist==2
+ backupfile=[backupfile '~'];
+ testexist=exist(backupfile,'file');
+ end
+ [success,message]=copyfile(outputfile,backupfile);%make backup
+ if isequal(success,1)
+ delete(outputfile)
+ else
+ return
+ end
+ else
+ uid_calib=find(t,'ImaDoc/GeometryCalib');
+ if ~isempty(uid) %if GeometryCalib already exists, delete its content
+ backupfile=outputfile;
+ testexist=2;
+ while testexist==2
+ backupfile=[backupfile '~'];
+ testexist=exist(backupfile,'file');
+ end
+ [success,message]=copyfile(outputfile,backupfile)%make backup
+ if isequal(success,1)
+ delete(outputfile)
+ else
+ return
+ end
+ uid_child=children(t,uid_calib);
+ t=delete(t,uid_child);
+ testappend=1;
+ end
+ end
+end
+if ~testappend
+ t=xmltree;
+ t=set(t,1,'name','ImaDoc');
+ [t,uid_calib]=add(t,1,'element','GeometryCalib');
+% t=struct2xml(GeometryCalib,t,uid_calib);
+end
+Object.Coord(:,[1:3])=Object.Coord(:,[1:3])*10; %transform in
+GeometryCalib.SourceCalib.PointCoord=Object.Coord;
+t=struct2xml(GeometryCalib,t,uid_calib);
+save(t,outputfile)
+
+warndlg_uvmat([outputfile 'updated with linear calibration data'],'CONFIRMATION')
+
+%display image with new calibration in the currently opened uvmat interface
+Indices=get(findobj(hchild,'Tag','FileIndex'),'String');
+Ext=get(findobj(hchild,'Tag','FileExt'),'String');
+imagename=[fullfile(RootPath,RootFile) Indices Ext];
+% input.menu_coord=1;
+huvmat=uvmat(imagename,1);%open uvmat, set phys coord (Value 1)
+
+
+
+% --- Executes on button press in calibrate_lin.
+function calib_lin_Callback(hObject, eventdata, handles)
+Object=read_probe_calib(handles);
+
+%make linear calibration
+% 'calibration_lin' provides a linear transform on coordinates,
+X=Object.Coord(:,1);
+Y=Object.Coord(:,2);
+x_ima=Object.Coord(:,4);
+y_ima=Object.Coord(:,5);
+XY_mat=[ones(size(X)) X Y];
+a_X1=XY_mat\x_ima; %transformation matrix for X
+x1=XY_mat*a_X1;%reconstruction
+err_X1=max(abs(x1-x_ima));%error
+a_Y1=XY_mat\y_ima;%transformation matrix for X
+y1=XY_mat*a_Y1;
+err_Y1=max(abs(y1-y_ima));%error
+T_x=a_X1(1);
+T_y=a_Y1(1);
+GeometryCalib.focal=1;
+GeometryCalib.Tx_Ty_Tz=[T_x T_y 1];
+GeometryCalib.R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1];
+
+%check error
+GeometryCalib.ErrorRms(1)=sqrt(mean((x1-x_ima).*(x1-x_ima)));
+GeometryCalib.ErrorMax(1)=max(abs(x1-x_ima));
+GeometryCalib.ErrorRms(2)=sqrt(mean((y1-y_ima).*(y1-y_ima)));
+GeometryCalib.ErrorMax(2)=max(abs(y1-y_ima))
+
+%calibrate_lin calibration results and point coordinates
+huvmat=findobj('Tag','uvmat');
+hchild=get(huvmat,'Children');
+hrootpath=findobj(hchild,'Tag','RootPath');
+hrootfile=findobj(hchild,'Tag','RootFile');
+RootPath='';
+RootFile='';
+if ~isempty(hrootpath)& ~isempty(hrootfile)
+ testhandle=1;
+ RootPath=get(hrootpath,'String');
+ RootFile=get(hrootfile,'String');
+ filebase=fullfile(RootPath,RootFile);
+ outputfile=[filebase '.xml'];
+else
+ question={'save the calibration data and point coordinates in'};
+ def={fullfile(RootPath,['ObjectCalib.xml'])};
+ options.Resize='on';
+ answer=inputdlg(question,'save average in a new file',1,def,options);
+ outputfile=answer{1};
+end
+testappend=0;
+if exist(outputfile,'file');%=1 if the output file already exists, 0 else
+ t=xmltree(outputfile); %read the file
+ uid=find(t,'ImaDoc');
+ if ~isequal(uid,1)%if the xml file is not ImaDoc, delete it (after backup)
+ backupfile=outputfile;
+ testexist=2;
+ while testexist==2
+ backupfile=[backupfile '~'];
+ testexist=exist(backupfile,'file');
+ end
+ [success,message]=copyfile(outputfile,backupfile)%make backup
+ if isequal(success,1);
+ delete(outputfile)
+ else
+ return
+ end
+ else
+ uid_calib=find(t,'ImaDoc/GeometryCalib');
+ if ~isempty(uid) %if GeometryCalib already exists, delete its content
+ backupfile=outputfile;
+ testexist=2;
+ while testexist==2
+ backupfile=[backupfile '~'];
+ testexist=exist(backupfile,'file');
+ end
+ [success,message]=copyfile(outputfile,backupfile)%make backup
+ if isequal(success,1)
+ delete(outputfile)
+ else
+ return
+ end
+ uid_child=children(t,uid_calib);
+ t=delete(t,uid_child);
+ testappend=1;
+ end
+ end
+end
+if ~testappend
+ t=xmltree;
+ t=set(t,1,'name','ImaDoc');
+ [t,uid_calib]=add(t,1,'element','GeometryCalib');
+% t=struct2xml(GeometryCalib,t,uid_calib);
+end
+% Object.Coord(:,[1:3])=Object.Coord(:,[1:3]); %transform in
+GeometryCalib.SourceCalib.PointCoord=Object.Coord;
+t=struct2xml(GeometryCalib,t,uid_calib);
+save(t,outputfile)
+
+warndlg_uvmat([outputfile 'updated with linear calibration data'],'CONFIRMATION')
+
+%display image with new calibration in the currently opened uvmat interface
+Indices=get(findobj(hchild,'Tag','FileIndex'),'String');
+Ext=get(findobj(hchild,'Tag','FileExt'),'String');
+imagename=[fullfile(RootPath,RootFile) Indices Ext];
+% input.menu_coord=1;
+if exist(imagename,'file')
+ huvmat=uvmat(imagename,1);%open uvmat, set phys coord (Value 1)
+else
+ huvmat=uvmat;
+end
+
+
+% --- Executes on button press in translation.
+function translation_Callback(hObject, eventdata, handles)
+
+
+function T_x_Callback(hObject, eventdata, handles)
+% hObject handle to T_x (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of T_x as text
+% str2double(get(hObject,'String')) returns contents of T_x as a double
+
+
+
+
+
+function T_y_Callback(hObject, eventdata, handles)
+% hObject handle to T_y (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of T_y as text
+% str2double(get(hObject,'String')) returns contents of T_y as a double
+
+
+function T_z_Callback(hObject, eventdata, handles)
+% hObject handle to T_z (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of T_z as text
+% str2double(get(hObject,'String')) returns contents of T_z as a double
+
+
+% --- Executes on button press in rotation.
+function rotation_Callback(hObject, eventdata, handles)
+angle_rot=(pi/180)*str2num(get(handles.Phi,'String'))
+data=read_probe_calib(handles)
+data.Coord(:,1)=cos(angle_rot)*data.Coord(:,1)+sin(angle_rot)*data.Coord(:,2);
+data.Coord(:,1)=-sin(angle_rot)*data.Coord(:,1)+cos(angle_rot)*data.Coord(:,2);
+set(handles.XObject,'String',num2str(data.Coord(:,1)));
+set(handles.YObject,'String',num2str(data.Coord(:,2)));
+
+
+function XImage_Callback(hObject, eventdata, handles)
+update_list(hObject, eventdata,handles)
+
+function YImage_Callback(hObject, eventdata, handles)
+update_list(hObject, eventdata,handles)
+
+function XObject_Callback(hObject, eventdata, handles)
+update_list(hObject, eventdata,handles)
+
+function YObject_Callback(hObject, eventdata, handles)
+update_list(hObject, eventdata,handles)
+
+function ZObject_Callback(hObject, eventdata, handles)
+update_list(hObject, eventdata,handles)
+
+function update_list(hObject, eventdata, handles)
+str4=get(handles.XImage,'String');
+str5=get(handles.YImage,'String');
+str1=get(handles.XObject,'String');
+tt=double(str1);
+str2=get(handles.YObject,'String');
+str3=get(handles.ZObject,'String');
+if ~isempty(str1) & ~isequal(double(str1),32) & (isempty(str3)|isequal(double(str3),32))
+ str3='0';%put z to 0 by default
+end
+strline=[str1 ' | ' str2 ' | ' str3 ' | ' str4 ' | ' str5];
+Coord=get(handles.ListCoord,'String');
+testappend=get(handles.edit_append,'Value');
+if isequal(testappend,1); %edit mode
+ val=get(handles.ListCoord,'Value');
+ Coord{val}=strline;
+else
+ val=length(get(handles.ListCoord,'String'));
+ Coord{val+1}=strline;
+ set(handles.ListCoord,'Value',val+1)
+% if val+1<=length(Coord)
+% set(handles.ListCoord,'Value',val+1)
+% ListCoord_Callback(hObject, eventdata, handles)
+end
+set(handles.ListCoord,'String',Coord)
+%set(handles.ListCoord,'Value',val+1)
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function data=read_probe_calib(handles)
+data_XIma=[];
+data_YIma=[];
+data_XObject=[];
+data_YObject=[];
+data_ZObject=[];
+Coord=get(handles.ListCoord,'String');
+% XImage=get(handles.XImage,'String');
+% YImage=get(handles.YImage,'String');
+% XObject=get(handles.XObject,'String');
+% YObject=get(handles.YObject,'String');
+% ZObject=get(handles.ZObject,'String');
+% if ischar(Xcolumn)
+% Xcolumn={Xcolumn};
+% end
+nb_defining_points=length(Coord);
+iline=0;
+for i=1:nb_defining_points
+ coord_str=Coord{i};%character string of line number i
+ k=findstr('|',coord_str);%find separators '|'
+ data1=str2num(coord_str(1:k(1)-5));
+ data2=str2num(coord_str(k(1)+5:k(2)-5));
+ data3=str2num(coord_str(k(2)+5:k(3)-5));
+ data4=str2num(coord_str(k(3)+5:k(4)-5));
+ data5=str2num(coord_str(k(4)+5:end));
+ if ~isempty(data1)|~isempty(data2)|~isempty(data3)|~isempty(data4)|~isempty(data5)
+ iline=iline+1;
+ if ~isempty(data1)
+ data.Coord(iline,1)=data1;
+ end
+ if ~isempty(data2)
+ data.Coord(iline,2)=data2;
+ end
+ if ~isempty(data3)
+ data.Coord(iline,3)=data3;
+ end
+ if ~isempty(data4)
+ data.Coord(iline,4)=data4;
+ end
+ if isempty(data5)
+ data.Coord(iline,5)=0;
+ else
+ data.Coord(iline,5)=data5;
+ end
+ end
+end
+data.Style='points';
+
+
+% --- Executes on selection change in ListCoord.
+function ListCoord_Callback(hObject, eventdata, handles)
+% hObject handle to ListCoord (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: contents = get(hObject,'String') returns ListCoord contents as cell array
+% contents{get(hObject,'Value')} returns selected item from ListCoord
+set(handles.edit_append,'Value',1); %set to edit mode
+Coord=get(handles.ListCoord,'String');
+val=get(handles.ListCoord,'Value');
+if length(Coord)>0
+coord_str=Coord{val};
+k=findstr('|',coord_str);
+set(handles.XObject,'String',coord_str(1:k(1)-5))
+set(handles.YObject,'String',coord_str(k(1)+5:k(2)-5))
+set(handles.ZObject,'String',coord_str(k(2)+5:k(3)-5))
+set(handles.XImage,'String',coord_str(k(3)+5:k(4)-5))
+set(handles.YImage,'String',coord_str(k(4)+5:end))
+end
+
+%------------------------------------------------------
+% --- Executes on button press in translation_plus.
+function translation_plus_Callback(hObject, eventdata, handles)
+
+T=[0 0 0];
+T_x=get(handles.T_x,'String')
+T_y=get(handles.T_y,'String')
+T_z=get(handles.T_z,'String')
+if ~isempty(T_x)
+ T(1)=str2num(T_x);
+end
+if ~isempty(T_y)
+ T(2)=str2num(T_y);
+end
+if ~isempty(T_z)
+ T(3)=str2num(T_z);
+end
+translation(handles,T)
+
+
+
+% --- Executes on button press in translation_minus.
+function translation_minus_Callback(hObject, eventdata, handles)
+
+T=[0 0 0];
+T_x=get(handles.T_x,'String')
+T_y=get(handles.T_y,'String')
+T_z=get(handles.T_z,'String')
+if ~isempty(T_x)
+ T(1)=-str2num(T_x);
+end
+if ~isempty(T_y)
+ T(2)=-str2num(T_y);
+end
+if ~isempty(T_z)
+ T(3)=-str2num(T_z);
+end
+translation(handles,T)
+
+
+%%%--------------------------------------
+function translation(handles,T)
+data=read_probe_calib(handles);
+data.Coord(:,1)=T(1)+data.Coord(:,1);
+data.Coord(:,2)=T(2)+data.Coord(:,2);
+data.Coord(:,3)=T(3)+data.Coord(:,3);
+data.Coord(:,[4 5])=data.Coord(:,[4 5]);
+for i=1:size(data.Coord,1)
+ for j=1:5
+ Coord{i,j}=num2str(data.Coord(i,j));%phys x,y,z
+ end
+end
+Tabchar=cell2tab(Coord,' | ');
+set(handles.ListCoord,'String',Tabchar)
+
+%----------------------------------------------------
+% --- Executes on button press in rotation_plus.
+function rotation_plus_Callback(hObject, eventdata, handles)
+Phi=0;
+Phi=get(handles.Phi,'String')
+if ~isempty(Phi)
+ Phi=str2num(Phi);
+end
+rotation(handles,Phi)
+
+%-------------------------------------------------
+% --- Executes on button press in rotation_minus.
+function rotation_minus_Callback(hObject, eventdata, handles)
+Phi=0;
+Phi=get(handles.Phi,'String')
+if ~isempty(Phi)
+ Phi=-str2num(Phi);
+end
+rotation(handles,Phi)
+
+%-----------------------------------------------------
+%rotation
+function rotation(handles,Phi)
+O_x=str2num(get(handles.O_x,'String'));
+O_y=str2num(get(handles.O_y,'String'));
+if isempty(O_x)
+ O_x=0;%default
+end
+if isempty(O_y)
+ O_y=0;%default
+end
+data=read_probe_calib(handles);
+r1=cos(pi*Phi/180);
+r2=-sin(pi*Phi/180);
+r3=sin(pi*Phi/180);
+r4=cos(pi*Phi/180);
+data.Coord(:,1)=r1*data.Coord(:,1)+r2*data.Coord(:,2);
+data.Coord(:,2)=r3*data.Coord(:,1)+r4*data.Coord(:,2);
+% data.Coord(:,[4 5])=data.Coord(:,[4 5]);
+for i=1:size(data.Coord,1)
+ for j=1:5
+ Coord{i,j}=num2str(data.Coord(i,j));%phys x,y,z
+ end
+end
+Tabchar=cell2tab(Coord,' | ');
+set(handles.ListCoord,'String',Tabchar)
+
+function O_x_Callback(hObject, eventdata, handles)
+% hObject handle to O_x (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of O_x as text
+% str2double(get(hObject,'String')) returns contents of O_x as a double
+
+
+
+function O_y_Callback(hObject, eventdata, handles)
+% hObject handle to O_y (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of O_y as text
+% str2double(get(hObject,'String')) returns contents of O_y as a double
+
+
+function O_z_Callback(hObject, eventdata, handles)
+% hObject handle to O_z (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of O_z as text
+% str2double(get(hObject,'String')) returns contents of O_z as a double
+
+
+
+
+
+
+
+% --- Executes on selection change in edit_append.
+function edit_append_Callback(hObject, eventdata, handles)
+val=get(handles.edit_append,'Value');
+if isequal(val,2); %append mode
+ %appeler mouse
+end
+
+
+function NEW_Callback(hObject, eventdata, handles)
+%A METTRE SOUS UN BOUTON
+huvmat=findobj('name','uvmat');
+hchild=get(huvmat,'children');
+hcoord=findobj(hchild,'Tag','menu_coord')
+coordtype=get(hcoord,'Value')
+haxes=findobj(hchild,'Tag','axes3');
+AxeData=get(haxes,'UserData');
+if ~isequal(hcoord,2)
+ set(hcoord,'Value',2)
+ huvmat=uvmat(AxeData)
+ 'relancer uvmat'
+end
+if ~isfield(AxeData,'ZoomAxes')
+ warndlg_uvmat('first draw a window around a grid marker','ERRROR')
+ return
+end
+XLim=get(AxeData.ZoomAxes,'XLim');
+YLim=get(AxeData.ZoomAxes,'YLim');
+np=size(AxeData.A);
+ind_sub_x=round(XLim)
+ind_sub_y=np(1)-round(YLim)
+Mfiltre=AxeData.A([ind_sub_y(2):ind_sub_y(1)] ,ind_sub_x,:);
+Mfiltre_norm=double(Mfiltre);
+Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm));
+Mfiltre_norm=100*(Mfiltre_norm-mean(mean(Mfiltre_norm)));
+Atype=class(AxeData.A)
+Data.NbDim=2;
+Data.A=filter2(Mfiltre_norm,double(AxeData.A));
+Data.A=feval(Atype,Data.A);
+Data.AName='image';
+Data.AX=AxeData.AX;
+Data.AY=AxeData.AY;
+Data.CoordType='px';
+plot_field(Data)
+
+
+% --- Executes on button press in HELP.
+function HELP_Callback(hObject, eventdata, handles)
+% hObject handle to HELP (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+path_to_uvmat=which ('uvmat');% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+else
+ web([helpfile '#probe_calib'])
+end
+
+%'move_key:' function activated when a key is pressed on the keyboard
+%-----------------------------------
+function key_press_fcn(hObject,eventdata,handles)
+hh=get(hObject,'parent')
+xx=double(get(hh,'CurrentCharacter')) %get the keyboard character
+
+if isequal(xx,8)%move arrow right
+ data=read_probe_calib(handles);
+ Coord=[]; %default
+ if isfield(data,'Coord')
+ Coord=data.Coord
+ end
+ val=get(handles.ListCoord,'Value');
+ Coord(val,:)=[];
+ CoordCell={};
+ for iline=1:size(Coord,1)
+ for j=1:5
+ CoordCell{iline,j}=num2str(Coord(iline,j));
+ end
+ end
+ Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display
+ val=min(size(Coord,1),val);
+ set(handles.ListCoord,'Value',max(val,1))
+ set(handles.ListCoord,'String',Tabchar)
+end
Index: /trunk/src/proj_field.m
===================================================================
--- /trunk/src/proj_field.m (revision 2)
+++ /trunk/src/proj_field.m (revision 2)
@@ -0,0 +1,1617 @@
+%'proj_field': projects the field on a projection object
+%--------------------------------------------------------------------------
+% function [ProjData,errormsg]=proj_field(FieldData,ObjectData,IndexObj)
+%
+% OUTPUT:
+% ProjData structure containing the fields of the input field FieldData,
+% transmitted or projected on the object, plus the additional fields
+% .UMax, .UMin, .VMax, .VMin: min and max of velocity components in a domain
+% .UMean,VMean: mean of the velocity components in a domain
+% .AMin, AMax: min and max of a scalar
+% .AMean: mean of a scalar in a domain
+% .NbPix;
+% .DimName= names of the matrix dimensions (matlab cell)
+% .DimValue= values of the matricx dimensions (matlab vector, same length as .DimName);
+% .VarName= names of the variables [ProjData.VarName {'A','AMean','AMin','AMax'}];
+% .VarDimNameIndex= dimensions of the variables, indicated by indices in the list .DimName;
+%
+%INPUT
+% ObjectData: structure characterizing the projection object
+% .Style : style of projection object
+% .ProjMode=type of projection ;
+% .CoordType: 'px' or 'phys' type of coordinates defining the object position
+% .Phi angle of rotation (=0 by default)
+% .ProjAngle=angle of projection;
+% .DX,.DY,.DZ=increments along each coordinate
+% .Coord(nbpoints,3): set of coordinates defining the object position;
+
+%FieldData: data of the field to be projected on the projection object, with optional fields
+% .Txt: error message, transmitted to the projection
+% .CoordType: 'px' or 'phys' type of coordinates of the field, must be the same as for the projection object, transmitted
+% .Mesh: typical distance between data points (used for mouse action or display), transmitted
+% .CoordUnit, .TimeUnit, .dt: transmitted
+% standardised description of fields, nc-formated Matlab structure with fields:
+% .ListGlobalAttribute: cell listing the names of the global attributes
+% .Att_1,Att_2... : values of the global attributes
+% .ListDimName: cell listing the names of the array dimensions
+% .DimValue: array dimension values (Matlab vector with the same length as .ListDimName
+% .ListVarName: cell listing the names of the variables
+% .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName
+% .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
+% .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
+% The variables are grouped in 'fields', made of a set of variables with common dimensions (using the function find_field_indices)
+% The variable attribute 'Role' is used to define the role for plotting:
+% Role = 'scalar': (default) represents a scalar field
+% = 'coord': represents a set of unstructured coordinates, whose
+% space dimension is given by the last array dimension (called 'nb_dim').
+% = 'coord_x', 'coord_y', 'coord_z': represents a separate set of
+% unstructured coordinate x, y or z
+% = 'vector': represents a vector field whose number of components
+% is given by the last dimension (called 'nb_dim')
+% = 'vector_x', 'vector_y', 'vector_z' :represents the x, y or z component of a vector
+% = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
+% = 'errorflag': provides an error flag marking false data,
+% default=0, no error. Different non zero values can represent different criteria of elimination.
+%
+% Default role of variables (by name)
+% vector field:
+% .X,.Y: position of the velocity vectors, projected on the object
+% .U, .V, .W: velocity components, projected on the object
+% .C, .CName: scalar associated to the vector
+% .F : equivalent to 'warnflag'
+% .FF: equivalent to 'errorflag'
+% scalar field or image:
+% .AName: name of a scalar (to be calculated from velocity fields after projection), transmitted
+% .A: scalar, projected on the object
+% .AX, .AY: positions for the scalar
+% case of a structured grid: A is a dim 2 matrix and .AX=[first last] (length 2 vector) represents the first and last abscissa of the grid
+% case of an unstructured scalar: A is a vector, AX and AY the corresponding coordinates
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function [ProjData,errormsg]=proj_field(FieldData,ObjectData,IndexObj)
+
+if isfield(ObjectData,'ProjMode') && (isequal(ObjectData.ProjMode,'none')||isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'))
+ ProjData=[];
+ return
+end
+%introduce default field properties (reading old standards)
+if ~isfield(ObjectData,'Style')||~isfield(ObjectData,'Coord')||~isfield(ObjectData,'ProjMode')
+ ProjData=FieldData;
+ return
+end
+
+% OBSOLETE
+if isfield(ObjectData,'XMax') && ~isempty(ObjectData.XMax)
+ ObjectData.RangeX(1)=ObjectData.XMax;
+end
+if isfield(ObjectData,'XMin') && ~isempty(ObjectData.XMin)
+ ObjectData.RangeX(2)=ObjectData.XMin;
+end
+if isfield(ObjectData,'YMax') && ~isempty(ObjectData.YMax)
+ ObjectData.RangeY(1)=ObjectData.YMax;
+end
+if isfield(ObjectData,'YMin') && ~isempty(ObjectData.YMin)
+ ObjectData.RangeY(2)=ObjectData.YMin;
+end
+if isfield(ObjectData,'ZMax') && ~isempty(ObjectData.ZMax)
+ ObjectData.RangeZ(1)=ObjectData.ZMax;
+end
+if isfield(ObjectData,'ZMin') && ~isempty(ObjectData.ZMin)
+ ObjectData.RangeZ(2)=ObjectData.ZMin;
+end
+%%%%%%%%%%
+
+% FieldData=document_field(FieldData);%transform FieldData to the standard format
+% if ~isfield(FieldData,'VarAttribute')
+% FieldData.VarAttribute={};
+% end
+
+if isequal(ObjectData.Style,'points')
+ [ProjData,errormsg]=proj_points(FieldData,ObjectData);
+elseif isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')
+ [ProjData,errormsg] = proj_line(FieldData,ObjectData);
+elseif isequal(ObjectData.Style,'polygon')|isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')
+ if isequal(ObjectData.ProjMode,'inside')|isequal(ObjectData.ProjMode,'outside')
+ [ProjData,errormsg] = proj_patch(FieldData,ObjectData);
+ else
+ [ProjData,errormsg] = proj_line(FieldData,ObjectData);
+ end
+ %A FAIRE : GERER MASK
+elseif isequal(ObjectData.Style,'plane')
+% if isfield(FieldData,'NbDim') & isequal(FieldData.NbDim,3)
+% ProjData= proj_plane3D(FieldData,ObjectData);%
+% else
+ [ProjData,errormsg] = proj_plane(FieldData,ObjectData);
+% end
+end
+if exist('IndexObj','var')
+ ProjData.IndexObj=IndexObj;%transfer object index
+end
+
+%-----------------------------------------------------------------
+%project on a set of points
+function [ProjData,errormsg]=proj_points(FieldData,ObjectData)%%
+%-------------------------------------------------------------------
+
+siz=size(ObjectData.Coord);
+width=0;
+if isfield(ObjectData,'Range')
+ width=ObjectData.Range(1,2);
+end
+if isfield(ObjectData,'RangeX')&~isempty(ObjectData.RangeX)
+ width=max(ObjectData.RangeX);
+end
+if isfield(ObjectData,'RangeY')&~isempty(ObjectData.RangeY)
+ width=max(width,max(ObjectData.RangeY));
+end
+if isfield(ObjectData,'RangeZ')&~isempty(ObjectData.RangeZ)
+ width=max(width,max(ObjectData.RangeZ));
+end
+if isequal(ObjectData.ProjMode,'projection')
+ if width==0
+ errormsg='projection range around points needed';
+ return
+ end
+elseif ~isequal(ObjectData.ProjMode,'interp')
+ errormsg=(['ProjMode option ' ObjectData.ProjMode ' not available in proj_field']);
+ return
+end
+ProjData=proj_heading(FieldData,ObjectData);
+ProjData.NbDim=0;
+%ProjData.ListDimName= {'nb_points'};
+%ProjData.DimValue=siz(1); %nbre of projection points
+
+
+% idimvar=0;
+[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
+if ~isempty(errormsg)
+ errormsg=['error in proj_field/proj_points:' errormsg];
+ return
+end
+%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+% CellVarIndex=cells of variable index arrays
+% ivar_new=0; % index of the current variable in the projected field
+% icoord=0;
+for icell=1:length(CellVarIndex)
+ if NbDim(icell)==1
+ continue
+ end
+ VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
+ VarType=VarTypeCell{icell};
+ ivar_X=VarType.coord_x;
+ ivar_Y=VarType.coord_y;
+ ivar_Z=VarType.coord_z;
+% ivar_U=VarType.vector_x;
+% ivar_V=VarType.vector_y;
+% ivar_W=VarType.vector_z;
+% ivar_C=VarType.scalar ;
+ ivar_Anc=VarType.ancillary;
+% test_anc=zeros(size(VarIndex));
+ test_anc(ivar_Anc)=ones(size(ivar_Anc));
+ ivar_F=VarType.warnflag;
+ ivar_FF=VarType.errorflag;
+ VarIndex([ivar_X ivar_Y ivar_Z ivar_Anc ivar_F ivar_FF])=[];% not projected variables removed frlom list
+ if isempty(ivar_X)
+ test_grid=1;%test for input data on regular grid (e.g. image)coordinates
+
+ else
+ if length(ivar_X)>1 | length(ivar_Y)>1 | length(ivar_Z)>1
+ errormsg='multiple coordinate input in proj_field.m';
+ return
+ end
+ if length(ivar_Y)~=1
+ errormsg='y coordinate not defined in proj_field.m';
+ return
+ end
+ test_grid=0;
+ end
+ ProjData.ListVarName={'Y','X','NbVal'};
+ ProjData.VarDimName={'nb_points','nb_points','nb_points'};
+ %ProjData.VarDimIndex={[1],[1],[1]};
+ ProjData.VarAttribute{1}.Role='ancillary';
+ ProjData.VarAttribute{2}.Role='ancillary';
+ ProjData.VarAttribute{3}.Role='ancillary';
+ for ivar=VarIndex
+ VarName=FieldData.ListVarName{ivar};
+ ProjData.ListVarName=[ProjData.ListVarName {VarName}];
+ %ProjData.VarDimIndex=[ProjData.VarDimIndex {[1]}];
+ ProjData.VarDimName=[ProjData.VarDimName {'nb_points'}];
+ end
+ if ~test_grid
+ eval(['coord_x=FieldData.' FieldData.ListVarName{ivar_X} ';'])
+ eval(['coord_y=FieldData.' FieldData.ListVarName{ivar_Y} ';'])
+ test3D=0;% TEST 3D CASE : NOT COMPLETED , 3D CASE : NOT COMPLETED
+ if length(ivar_Z)==1
+ eval(['coord_z=FieldData.' FieldData.ListVarName{ivar_Z} ';'])
+ test3D=1;
+ end
+% if length(ivar_U)>1 | length(ivar_V)>1 | length(ivar_W)>1
+% warndlg_uvmat('multiple vector input in proj_field.m','ERROR')
+% return
+% end
+ if length(ivar_F)>1 | length(ivar_FF)>1
+ warndlg_uvmat('multiple flag input in proj_field.m','ERROR')
+ return
+ end
+
+ for ipoint=1:siz(1)
+ Xpoint=ObjectData.Coord(ipoint,:);
+ distX=coord_x-Xpoint(1);
+ distY=coord_y-Xpoint(2);
+ dist=distX.*distX+distY.*distY;
+ indsel=find(dist=2 & VarType.coord(1:2) > 0;
+ AYName=FieldData.ListVarName{VarType.coord(1)};
+ AXName=FieldData.ListVarName{VarType.coord(2)};
+ eval(['AX=FieldData.' AXName ';']);% set of x positions
+ eval(['AY=FieldData.' AYName ';']);% set of y positions
+ AName=FieldData.ListVarName{VarIndex(1)};
+ eval(['A=FieldData.' AName ';']);% scalar
+ npxy=size(A);
+
+% % nbcolor=1; %default
+% for idim=1:length(ListDimName)
+% DimName=ListDimName{idim};
+% if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')
+% nbcolor=npxy(idim);
+% DimIndices(idim)=[];
+% npxy(idim)=[];
+% end
+% if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
+% DimIndices(idim)=[];
+% npxy(idim)=[];
+% end
+% end
+ ind_1=find(npxy==1);
+ %DimIndices(ind_1)=[]; %suppress singleton dimensions
+% indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)
+ %nb_dim=length(DimIndices)%number of space dimensions
+ nb_dim=numel(VarType.coord);
+ Coord_z=[];
+ Coord_y=[];
+ Coord_x=[];
+ for idim=1:nb_dim %loop on space dimensions
+ test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
+ test_coord(idim)=0;%test for defined coordinates, =0 by default
+ %ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension
+ ivar=VarType.coord(idim);
+% if ~isequal(ivar,0)% a variable corresponds to the current dimension
+ eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index
+ if numel(Coord{idim})==2
+ DCoord_min(idim)= (Coord{idim}(2)-Coord{idim}(1))/(npxy(idim)-1);
+ else
+ DCoord=diff(Coord{idim});
+ DCoord_min(idim)=min(DCoord);
+ DCoord_max=max(DCoord);
+ test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
+ test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
+ if ~isequal(test_direct(idim),test_direct_min)
+ errormsg=['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'];
+ return
+ end
+ test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
+ test_coord(idim)=1;
+ end
+% else % no variable associated with the first dimension, look fo variable attributes Coord_1, _2 or _3
+% Coord_i_str=['Coord_' num2str(idim)];
+% DCoord_min(idim)=1;%default
+% Coord{idim}=[0.5 npxy(idim)];
+% test_direct(idim)=1;
+% end
+ end
+ DX=DCoord_min(2);
+ DY=DCoord_min(1);
+ for ipoint=1:siz(1)
+ xwidth=width/(abs(DX));
+ ywidth=width/(abs(DY));
+ i_min=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5-xwidth); %minimum index of the selected region
+ i_min=max(1,i_min);%restrict to field limit
+ i_plus=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5+xwidth);
+ i_plus=min(npxy(2),i_plus); %restrict to field limit
+ j_min=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY-ywidth+0.5);
+ j_min=max(1,j_min);
+ j_plus=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY+ywidth+0.5);
+ j_plus=min(npxy(1),j_plus);
+ ProjData.X(ipoint,1)=ObjectData.Coord(ipoint,1);
+ ProjData.Y(ipoint,1)=ObjectData.Coord(ipoint,2);
+ i_int=[i_min:i_plus];
+ j_int=[j_min:j_plus];
+ ProjData.NbVal(ipoint,1)=length(j_int)*length(i_int);
+ if isempty(i_int) | isempty(j_int)
+ for ivar=VarIndex
+ eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=NaN;']);
+ end
+ errormsg=['no data points in the selected projection range ' num2str(width) ];
+ else
+ %TODO: introduce circle in the selected subregion
+ %[I,J]=meshgrid([1:j_int],[1:i_int]);
+ for ivar=VarIndex
+ eval(['Avalue=FieldData.' FieldData.ListVarName{ivar} '(j_int,i_int,:);']);
+ eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=mean(mean(Avalue));']);
+ end
+ end
+ end
+ end
+ end
+end
+
+%-----------------------------------------------------------------
+%project in a patch
+function [ProjData,errormsg]=proj_patch(FieldData,ObjectData)%%
+%-------------------------------------------------------------------
+ProjData=proj_heading(FieldData,ObjectData);
+
+objectfield=fieldnames(ObjectData);
+widthx=0;
+widthy=0;
+if isfield(ObjectData,'RangeX')&~isempty(ObjectData.RangeX)
+ widthx=max(ObjectData.RangeX);
+end
+if isfield(ObjectData,'RangeY')&~isempty(ObjectData.RangeY)
+ widthy=max(ObjectData.RangeY);
+end
+
+%A REVOIR, GENERALISER: UTILISER proj_line
+ProjData.NbDim=1;
+ProjData.ListDimName={};%name of dimension
+ProjData.DimValue=[];%values of dimension (nbre of vectors)
+ProjData.ListVarName={};
+%ProjData.VarDimIndex={};
+ProjData.VarDimName={};
+if isfield (FieldData,'ListVarAttribute')
+ ProjData.ListVarAttribute=FieldData.ListVarAttribute;%list of variable attribute names
+ for iattr=1:length(ProjData.ListVarAttribute)%initialization of variable attribute values
+ AttrName=ProjData.ListVarAttribute{iattr};
+ eval(['ProjData.' AttrName '={};'])
+ end;
+end
+
+%group the variables (fields of 'FieldData') in cells of variables with the same dimensions
+testfalse=0;
+ListIndex={};
+% DimVarIndex=0;%initilise list of indices for dimension variables
+idimvar=0;
+[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
+if ~isempty(errormsg)
+ errormsg=['error in proj_field/proj_patch:' errormsg];
+ return
+end
+
+%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+dimcounter=0;
+for icell=1:length(CellVarIndex)
+ testX=0;
+ testY=0;
+ test_Amat=0;
+ testfalse=0;
+ VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
+ VarType=VarTypeCell{icell};
+ % DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
+ if NbDim(icell)~=2% proj_patch acts only on fields of space dimension 2
+ continue
+ end
+ testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);
+ testfalse=~isempty(VarType.errorflag);
+ testproj(VarIndex)=zeros(size(VarIndex));%default
+ testproj(VarType.scalar)=1;
+ testproj(VarType.vector_x)=1;
+ testproj(VarType.vector_y)=1;
+ testproj(VarType.vector_z)=1;
+ testproj(VarType.image)=1;
+ testproj(VarType.color)=1;
+ VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
+ if testX %case of unstructured coordinates
+ eval(['nbpoint=numel(FieldData.' FieldData.ListVarName{VarIndex(1)} ');'])
+ for ivar=[VarIndex VarType.coord_x VarType.coord_y VarType.errorflag]
+ VarName=FieldData.ListVarName{ivar};
+ eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',nbpoint,1);'])
+ end
+ XName=FieldData.ListVarName{VarType.coord_x};
+ YName=FieldData.ListVarName{VarType.coord_y};
+ eval(['coord_x=FieldData.' XName ';'])
+ eval(['coord_y=FieldData.' YName ';'])
+ end
+ if testfalse
+ FFName=FieldData.ListVarName{VarType.errorflag};
+ eval(['errorflag=FieldData.' FFName ';'])
+ end
+ % image or 2D matrix
+ if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
+ test_Amat=1;%image or 2D matrix
+ AYName=FieldData.ListVarName{VarType.coord(1)};
+ AXName=FieldData.ListVarName{VarType.coord(2)};
+ eval(['AX=FieldData.' AXName ';'])% x coordinate
+ eval(['AY=FieldData.' AYName ';'])% y coordinate
+ VarName=FieldData.ListVarName{VarIndex(1)};
+ eval(['DimValue=size(FieldData.' VarName ');'])
+ testcolor=find(numel(DimValue)==3);
+% errormsg='multicomponent field not projected';
+
+ for idim=1:length(DimValue)
+ Coord_i_str=['Coord_' num2str(idim)];
+ DCoord_min(idim)=1;%default
+ Coord{idim}=[0.5 DimValue(idim)];
+ test_direct(idim)=1;
+% if isfield(FieldData,'VarAttribute')
+% for ivar=VarIndex
+% if length(FieldData.VarAttribute)>=ivar & isfield(FieldData.VarAttribute{ivar},Coord_i_str)% if there is a variable attribute named Coord_1, _2 or _3
+% eval(['Coord_i=FieldData.VarAttribute{ivar}.' Coord_i_str ';']);%'range x
+% if isnumeric(Coord_i)
+% if length(Coord_i)>=2
+% Coord{idim}=[Coord_i(1) Coord_i(end)];
+% %test_direct(idim)=(Coord{idim}(2)>Coord{idim}(1));
+% else
+% warndlg_uvmat(['two values needed for ' Coord_i_str 'in proj_field.m'],'ERROR')
+% return
+% end
+% else
+% warndlg_uvmat(['non numerical coordinate attributes' Coord_i_str 'in proj_field.m'],'ERROR')
+% return
+% end
+% %test_coord(idim)=1;
+% DCoord_min(idim)=(Coord{idim}(end)-Coord{idim}(1))/(DimValue(idim)-1);
+% end
+% end
+% end
+ end
+ AX=linspace(Coord{2}(1),Coord{2}(2),DimValue(2));
+ AY=linspace(Coord{1}(1),Coord{1}(2),DimValue(1)); %TODO : 3D case
+ if length(DimValue)==3
+ testcolor=1;
+ npxy(3)=3;
+ else
+ testcolor=0;
+ npxy(3)=1;
+ end
+ [Xi,Yi]=meshgrid(AX,AY);
+ npxy(1)=length(AY);
+ npxy(2)=length(AX);
+ Xi=reshape(Xi,npxy(1)*npxy(2),1);
+ Yi=reshape(Yi,npxy(1)*npxy(2),1);
+ for ivar=1:length(VarIndex)
+ VarName=FieldData.ListVarName{VarIndex(ivar)};
+ eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',npxy(1)*npxy(2),npxy(3));']); % keep only non false vectors
+ end
+ end
+%select the indices in the range of action
+ testin=[];%default
+ if isequal(ObjectData.Style,'rectangle')
+% if ~isfield(ObjectData,'RangeX')|~isfield(ObjectData,'RangeY')
+% errormsg='rectangle half sides RangeX and RangeY needed'
+% return
+% end
+ if testX
+ distX=abs(coord_x-ObjectData.Coord(1,1));
+ distY=abs(coord_y-ObjectData.Coord(1,2));
+ testin=distX=2
+ width=abs(ObjectData.Range(1,2));
+end
+if isfield(ObjectData,'RangeY')
+ width=max(ObjectData.RangeY);
+end
+
+% default output
+errormsg=[];%default
+Xline=[];
+flux=0;
+circul=0;
+liny=ObjectData.Coord(:,2);
+siz_line=size(ObjectData.Coord);
+if siz_line(1)<2
+ return% line needs at least 2 points to be defined
+end
+testfalse=0;
+ListIndex={};
+
+%angles of the polyline and boundaries of action
+dlinx=diff(ObjectData.Coord(:,1));
+dliny=diff(ObjectData.Coord(:,2));
+theta=angle(dlinx+i*dliny);%angle of each segment
+theta(siz_line(1))=theta(siz_line(1)-1);
+% determine a rectangles at +-width from the line (only used for the ProjMode='projection or 'filter')
+if isequal(ProjMode,'projection') || isequal(ProjMode,'filter')
+ xsup(1)=ObjectData.Coord(1,1)-width*sin(theta(1));
+ xinf(1)=ObjectData.Coord(1,1)+width*sin(theta(1));
+ ysup(1)=ObjectData.Coord(1,2)+width*cos(theta(1));
+ yinf(1)=ObjectData.Coord(1,2)-width*cos(theta(1));
+ for ip=2:siz_line(1)
+ xsup(ip)=ObjectData.Coord(ip,1)-width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+ xinf(ip)=ObjectData.Coord(ip,1)+width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+ ysup(ip)=ObjectData.Coord(ip,2)+width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+ yinf(ip)=ObjectData.Coord(ip,2)-width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+ end
+end
+
+%group the variables (fields of 'FieldData') in cells of variables with the same dimensions
+[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
+if ~isempty(errormsg)
+ errormsg=['error in proj_field/proj_line:' errormsg];
+ return
+end
+
+% loop on variable cells with the same space dimension
+ProjData.ListVarName={};
+ProjData.VarDimName={};
+for icell=1:length(CellVarIndex)
+ VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
+ VarType=VarTypeCell{icell}; %types of variables
+ if NbDim(icell)~=2% proj_line acts only on fields of space dimension 2, TODO: check 3D case
+ continue
+ end
+ testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);% test for unstructured coordinates
+ testU=~isempty(VarType.vector_x) && ~isempty(VarType.vector_y);% test for vectors
+ testfalse=~isempty(VarType.errorflag);% test for error flag
+ testproj(VarIndex)=zeros(size(VarIndex));% test =1 for simply projected variables, default =0
+ %=0 for vector components, treated separately
+ testproj(VarType.scalar)=1;
+ testproj(VarType.image)=1;
+ testproj(VarType.color)=1;
+ VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
+ if testU
+ VarIndex=[VarIndex VarType.vector_x VarType.vector_y];%append u and v at the end of the list of variables
+ end
+ %identify vector components
+ if testU
+ UName=FieldData.ListVarName{VarType.vector_x};
+ VName=FieldData.ListVarName{VarType.vector_y};
+ eval(['vector_x=FieldData.' UName ';'])
+ eval(['vector_y=FieldData.' VName ';'])
+ end
+ %identify error flag
+ if testfalse
+ FFName=FieldData.ListVarName{VarType.errorflag};
+ eval(['errorflag=FieldData.' FFName ';'])
+ end
+ % check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y
+ if testX
+ if ~isequal(ProjMode,'interp')
+ if width==0
+ errormsg='range of the projection object is missing';
+ return
+ else
+ lambda=2/(width*width); %smoothing factor used for filter: weight exp(-2) at distance width from the line
+ end
+ end
+ if ~isequal(ProjMode,'projection')
+ if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
+ DX=abs(ObjectData.DX);%mesh of interpolation points along the line
+ else
+ errormsg='DX missing';
+ return
+ end
+ end
+ XName= FieldData.ListVarName{VarType.coord_x};
+ YName= FieldData.ListVarName{VarType.coord_y};
+ eval(['coord_x=FieldData.' XName ';'])
+ eval(['coord_y=FieldData.' YName ';'])
+ end
+ %initiate projection
+ for ivar=1:length(VarIndex)
+ ProjLine{ivar}=[];
+ end
+ XLine=[];
+ linelengthtot=0;
+
+% circul=0;
+% flux=0;
+ %%%%%%% % A FAIRE CALCULER MEAN DES QUANTITES %%%%%%
+ %case of unstructured coordinates
+ if testX
+ for ip=1:siz_line(1)-1 %Loop on the segments of the polyline
+ linelength=sqrt(dlinx(ip)*dlinx(ip)+dliny(ip)*dliny(ip));
+ %select the vector indices in the range of action
+ if testfalse
+ flagsel=(errorflag==0); % keep only non false vectors
+ else
+ flagsel=ones(size(coord_x));
+ end
+ if isequal(ProjMode,'projection') | isequal(ProjMode,'filter')
+ flagsel=flagsel & ((coord_y -yinf(ip))*(xinf(ip+1)-xinf(ip))>(coord_x-xinf(ip))*(yinf(ip+1)-yinf(ip))) ...
+ & ((coord_y -ysup(ip))*(xsup(ip+1)-xsup(ip))<(coord_x-xsup(ip))*(ysup(ip+1)-ysup(ip))) ...
+ & ((coord_y -yinf(ip+1))*(xsup(ip+1)-xinf(ip+1))>(coord_x-xinf(ip+1))*(ysup(ip+1)-yinf(ip+1))) ...
+ & ((coord_y -yinf(ip))*(xsup(ip)-xinf(ip))<(coord_x-xinf(ip))*(ysup(ip)-yinf(ip)));
+ end
+ indsel=find(flagsel);%indsel =indices of good vectors
+ X_sel=coord_x(indsel);
+ Y_sel=coord_y(indsel);
+ nbvar=0;
+ for iselect=1:numel(VarIndex)-2*testU
+ VarName=FieldData.ListVarName{VarIndex(iselect)};
+ eval(['ProjVar{iselect}=FieldData.' VarName '(indsel);']);%scalar value
+ end
+ if testU
+ ProjVar{numel(VarIndex)-1}=cos(theta(ip))*vector_x(indsel)+sin(theta(ip))*vector_y(indsel);% longitudinal component
+ ProjVar{numel(VarIndex)}=-sin(theta(ip))*vector_x(indsel)+cos(theta(ip))*vector_y(indsel);%transverse component
+ end
+ if isequal(ProjMode,'projection')
+ sintheta=sin(theta(ip));
+ costheta=cos(theta(ip));
+ Xproj=(X_sel-ObjectData.Coord(ip,1))*costheta + (Y_sel-ObjectData.Coord(ip,2))*sintheta; %projection on the line
+ [Xproj,indsort]=sort(Xproj);
+ for ivar=1:numel(ProjVar)
+ if ~isempty(ProjVar{ivar})
+ ProjVar{ivar}=ProjVar{ivar}(indsort);
+ end
+ end
+ elseif isequal(ProjMode,'interp') %linear interpolation:
+ npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
+ Xproj=[linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint)];
+ xreg=cos(theta(ip))*Xproj+ObjectData.Coord(ip,1);
+ yreg=sin(theta(ip))*Xproj+ObjectData.Coord(ip,2);
+ for ivar=1:numel(ProjVar)
+ if ~isempty(ProjVar{ivar})
+ ProjVar{ivar}=griddata_uvmat(X_sel,Y_sel,ProjVar{ivar},xreg,yreg);
+ end
+ end
+ elseif isequal(ProjMode,'filter') %filtering
+ npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
+ Xproj=[linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint)];
+ siz=size(X_sel);
+ xregij=cos(theta(ip))*Xproj'*ones(1,siz(2))+ObjectData.Coord(ip,1);
+ yregij=sin(theta(ip))*Xproj'*ones(1,siz(2))+ObjectData.Coord(ip,2);
+ xij=ones(npoint,1)*X_sel;
+ yij=ones(npoint,1)*Y_sel;
+ Aij=exp(-lambda*((xij-xregij).*(xij-xregij)+(yij-yregij).*(yij-yregij)));
+ norm=ones(1,siz(2))*Aij';
+ for ivar=1:numel(ProjVar)
+ if ~isempty(ProjVar{ivar})
+ ProjVar{ivar}=ProjVar{ivar}*Aij'./norm;
+ end
+ end
+ end
+ %prolongate the total record
+ for ivar=1:numel(ProjVar)
+ if ~isempty(ProjVar{ivar})
+ ProjLine{ivar}=[ProjLine{ivar}; ProjVar{ivar}];
+ end
+ end
+ XLine=[XLine ;(Xproj+linelengthtot)];%along line abscissa
+ linelengthtot=linelengthtot+linelength;
+ % circul=circul+(sum(U_sel))*linelength/npoint;
+ % flux=flux+(sum(V_sel))*linelength/npoint;
+ end
+ ProjData.X=XLine';
+ cur_index=1;
+ ProjData.ListVarName=[ProjData.ListVarName {XName}];
+ ProjData.VarDimName=[ProjData.VarDimName {XName}];
+ ProjData.VarAttribute{1}.long_name='abscissa along line';
+ for iselect=1:numel(VarIndex)
+ VarName=FieldData.ListVarName{VarIndex(iselect)};
+ eval(['ProjData.' VarName '=ProjLine{iselect};'])
+ ProjData.ListVarName=[ProjData.ListVarName {VarName}];
+ ProjData.VarDimName=[ProjData.VarDimName {XName}];
+ ProjData.VarAttribute{iselect}=FieldData.VarAttribute{VarIndex(iselect)};
+ end
+
+ %case of structured coordinates
+ elseif numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
+ if ~isequal(ObjectData.Style,'line')% exclude polyline
+ errormsg=['no projection available on ' ObjectData.Style 'for structured coordinates']; %
+ else
+ test_Amat=1;%image or 2D matrix
+ test_interp2=0;%default
+% if ~isempty(VarType.coord_y)
+ AYName=FieldData.ListVarName{VarType.coord(1)};
+ AXName=FieldData.ListVarName{VarType.coord(2)};
+ eval(['AX=FieldData.' AXName ';']);% set of x positions
+ eval(['AY=FieldData.' AYName ';']);% set of y positions
+ AName=FieldData.ListVarName{VarIndex(1)};
+ eval(['A=FieldData.' AName ';']);% scalar
+ npxy=size(A);
+ npx=npxy(2);
+ npy=npxy(1);
+ if numel(AX)==2
+ DX=(AX(2)-AX(1))/(npx-1);
+ else
+ DX_vec=diff(AX);
+ DX=max(DX_vec);
+ DX_min=min(DX_vec);
+ if (DX-DX_min)>0.0001*abs(DX)
+ test_interp2=1;
+ DX=DX_min;
+ end
+ end
+ if numel(AY)==2
+ DY=(AY(2)-AY(1))/(npy-1);
+ else
+ DY_vec=diff(AY);
+ DY=max(DY_vec);
+ DY_min=min(DY_vec);
+ if (DY-DY_min)>0.0001*abs(DY)
+ test_interp2=1;
+ DY=DY_min;
+ end
+ end
+ AXI=linspace(AX(1),AX(end), npx);%set of x positions for the interpolated input data
+ AYI=linspace(AY(1),AY(end), npy);%set of x positions for the interpolated input data
+ if isfield(ObjectData,'DX')
+ DXY_line=ObjectData.DX;%mesh on the projection line
+ else
+ DXY_line=sqrt(abs(DX*DY));% mesh on the projection line
+ end
+ dlinx=ObjectData.Coord(2,1)-ObjectData.Coord(1,1);
+ dliny=ObjectData.Coord(2,2)-ObjectData.Coord(1,2);
+ linelength=sqrt(dlinx*dlinx+dliny*dliny);
+ theta=angle(dlinx+i*dliny);%angle of the line
+ if isfield(FieldData,'RangeX')
+ XMin=min(FieldData.RangeX);%shift of the origin on the line
+ else
+ XMin=0;
+ end
+ eval(['ProjData.' AXName '=linspace(XMin,XMin+linelength,linelength/DXY_line+1);'])%abscissa of the new pixels along the line
+ y=linspace(-width,width,2*width/DXY_line+1);%ordintes of the new pixels (coordinate across the line)
+ eval(['npX=length(ProjData.' AXName ');'])
+ npY=length(y); %TODO: utiliser proj_grid
+ eval(['[X,Y]=meshgrid(ProjData.' AXName ',y);'])%grid in the line coordinates
+ XIMA=ObjectData.Coord(1,1)+(X-XMin)*cos(theta)-Y*sin(theta);
+ YIMA=ObjectData.Coord(1,2)+(X-XMin)*sin(theta)+Y*cos(theta);
+ XIMA=(XIMA-AX(1))/DX+1;% index of the original image along x
+ YIMA=(YIMA-AY(1))/DY+1;% index of the original image along y
+ XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
+ YIMA=reshape(round(YIMA),1,npX*npY);
+ flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
+ ind_in=find(flagin);
+ ind_out=find(~flagin);
+ ICOMB=(XIMA-1)*npy+YIMA;
+ ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
+ nbcolor=1; %color images
+ if numel(npxy)==2
+ nbcolor=1;
+ elseif length(npxy)==3
+ nbcolor=npxy(3);
+ else
+ errormsg='multicomponent field not projected';
+ display(errormsg)
+ return
+ end
+ nbvar=length(ProjData.ListVarName);% number of var from previous cells
+ ProjData.ListVarName=[ProjData.ListVarName {AXName}];
+ ProjData.VarDimName=[ProjData.VarDimName {AXName}];
+ for ivar=VarIndex
+ VarName{ivar}=FieldData.ListVarName{ivar};
+ if test_interp2% interpolate on new grid
+ eval(['FieldData.' VarName{ivar} '=interp2(FieldData.' AXName ',FieldData.' AYName ',FieldData.' VarName{ivar} ',AXI,AYI'');']) %TO TEST
+ end
+ eval(['vec_A=reshape(squeeze(FieldData.' VarName{ivar} '),npx*npy,nbcolor);']) %put the original image in colum
+ if nbcolor==1
+ vec_B(ind_in)=vec_A(ICOMB);
+ vec_B(ind_out)=zeros(size(ind_out));
+ A_out=reshape(vec_B,npY,npX);
+ eval(['ProjData.' VarName{ivar} '=((sum(A_out,1)/npY))'';']);
+ elseif nbcolor==3
+ vec_B(ind_in,[1:3])=vec_A(ICOMB,:);
+ vec_B(ind_out,1)=zeros(size(ind_out));
+ vec_B(ind_out,2)=zeros(size(ind_out));
+ vec_B(ind_out,3)=zeros(size(ind_out));
+ A_out=reshape(vec_B,npY,npX,nbcolor);
+ eval(['ProjData.' VarName{ivar} '=squeeze(sum(A_out,1)/npY);']);
+ end
+ ProjData.ListVarName=[ProjData.ListVarName VarName{ivar} ];
+ ProjData.VarDimName=[ProjData.VarDimName {AXName}];%to generalize with the initial name of the x coordinate
+ end
+ if testU
+ eval(['vector_x =ProjData.' VarName{VarType.vector_x} ';'])
+ eval(['vector_y =ProjData.' VarName{VarType.vector_y} ';'])
+ eval(['ProjData.' VarName{VarType.vector_x} '=cos(theta)*vector_x+sin(theta)*vector_y;'])
+ eval(['ProjData.' VarName{VarType.vector_y} '=-sin(theta)*vector_x+cos(theta)*vector_y;'])
+ end
+ ProjData.VarAttribute{nbvar+1}.long_name='abscissa along line';
+ if nbcolor==3
+ ProjData.VarDimName{end}={XName,'rgb'};
+ end
+ end
+ end
+end
+
+% %shotarter case for horizontal or vertical line (A FAIRE
+% % Rangx=[0.5 npx-0.5];%image coordiantes of corners
+% % Rangy=[npy-0.5 0.5];
+% % if isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib
+% % Rangx=Rangx/Calib.Pxcmx;
+% % Rangy=Rangy/Calib.Pxcmy;
+% % else
+% % [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],[0 0]);%case of translations without rotation and quadratic deformation
+% % [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,[0 0]);
+% % end
+%
+% % test_scal=0;%default% 3- 'UserData':(get(handles.Tag,'UserData')
+
+
+%-----------------------------------------------------------------
+%project on a plane
+% AJOUTER flux,circul,error
+ function [ProjData,errormsg] = proj_plane(FieldData, ObjectData)
+%-----------------------------------------------------------------
+
+%initialisation of the input parameters of the projection plane
+%-----------------------------------------------------------------
+ProjMode='projection';%direct projection by default
+if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
+
+%axis origin
+if isempty(ObjectData.Coord)
+ ObjectData.Coord(1,1)=0;%origin of the plane set to [0 0] by default
+ ObjectData.Coord(1,2)=0;
+ ObjectData.Coord(1,3)=0;
+end
+
+%rotation angles
+Phi=0;%default
+Theta=0;
+Psi=0;
+if isfield(ObjectData,'Phi')&& ~isempty(ObjectData.Phi)
+ Phi=(pi/180)*ObjectData.Phi;%first Euler angle in radian
+end
+if isfield(ObjectData,'Theta')&& ~isempty(ObjectData.Theta)
+ Theta=(pi/180)*ObjectData.Theta;%second Euler angle in radian
+end
+if isfield(ObjectData,'Psi')&& ~isempty(ObjectData.Psi)
+ Psi=(pi/180)*ObjectData.Psi;%third Euler angle in radian
+end
+
+%components of the unity vector normal to the projection plane
+NormVec_X=-sin(Phi)*sin(Theta);
+NormVec_Y=cos(Phi)*sin(Theta);
+NormVec_Z=cos(Theta);
+
+% test for 3D fields
+test3D=0;
+if isfield(FieldData,'NbDim')
+ test3D=isequal(FieldData.NbDim,3);
+end
+test3C=test3D; %default 3 vel components
+
+%mesh sizes DX and DY
+DX=0;
+DY=0; %default
+if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
+ DX=abs(ObjectData.DX);%mesh of interpolation points
+end
+if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
+ DY=abs(ObjectData.DY);%mesh of interpolation points
+end
+if ~isequal(ProjMode,'projection') & (DX==0|DY==0)
+ errormsg='DX or DY missing';
+ display(errormsg)
+ return
+end
+
+%extrema along each axis
+testXMin=0;
+testXMax=0;
+testYMin=0;
+testYMax=0;
+if isfield(ObjectData,'RangeX')
+ XMin=min(ObjectData.RangeX);
+ XMax=max(ObjectData.RangeX);
+ testXMin=XMax>XMin;
+ testXMax=1;
+end
+if isfield(ObjectData,'RangeY')
+ YMin=min(ObjectData.RangeY);
+ YMax=max(ObjectData.RangeY);
+ testYMin=YMax>YMin;
+ testYMax=1;
+end
+width=0;%default width of the projection band
+if isfield(ObjectData,'RangeZ')
+ width=max(ObjectData.RangeZ);
+end
+
+% initiate Matlab structure for physical field
+ProjData=proj_heading(FieldData,ObjectData);
+ProjData.NbDim=2;
+ProjData.ListDimName={};%name of dimension
+ProjData.DimValue=[];%values of dimension (nbre of vectors)
+ProjData.ListVarName={};
+ProjData.VarDimName={};
+
+error=0;%default
+flux=0;
+testfalse=0;
+ListIndex={};
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%group the variables (fields of 'FieldData') in cells of variables with the same dimensions
+%-----------------------------------------------------------------
+idimvar=0;
+[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
+if ~isempty(errormsg)
+ errormsg=['error in proj_field/proj_plane:' errormsg];
+ return
+end
+%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+% CellVarIndex=cells of variable index arrays
+ivar_new=0; % index of the current variable in the projected field
+icoord=0;
+nbcoord=0;%number of added coordinate variables brought by projection
+for icell=1:length(CellVarIndex)
+ if NbDim(icell)<2
+ continue
+ end
+ VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
+ VarType=VarTypeCell{icell};
+ ivar_X=VarType.coord_x;
+ ivar_Y=VarType.coord_y;
+ ivar_Z=VarType.coord_z;
+ ivar_U=VarType.vector_x;
+ ivar_V=VarType.vector_y;
+ ivar_W=VarType.vector_z;
+ ivar_C=VarType.scalar ;
+ ivar_Anc=VarType.ancillary;
+ test_anc=zeros(size(VarIndex));
+ test_anc(ivar_Anc)=ones(size(ivar_Anc));
+ ivar_F=VarType.warnflag;
+ ivar_FF=VarType.errorflag;
+ testX=~isempty(ivar_X) && ~isempty(ivar_Y);
+ %DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
+ DimCell=FieldData.VarDimName{VarIndex(1)};
+ if ischar(DimCell)
+ DimCell={DimCell};%name of dimensions
+ end
+
+%case of input fields with unstructured coordinates
+ if testX
+ XName=FieldData.ListVarName{ivar_X};
+ YName=FieldData.ListVarName{ivar_Y};
+ eval(['coord_x=FieldData.' XName ';'])
+ eval(['coord_y=FieldData.' YName ';'])
+ if length(ivar_Z)==1
+ ZName=FieldData.ListVarName{ivar_X};
+ eval(['coord_z=FieldData.' ZName ';'])
+ end
+
+ % translate initial coordinates
+ coord_x=coord_x-ObjectData.Coord(1,1);
+ coord_y=coord_y-ObjectData.Coord(1,2);
+ if ~isempty(ivar_Z)
+ coord_z=coord_z-ObjectData.Coord(1,3);
+ end
+
+ % selection of the vectors in the projection range (3D case)
+ if length(ivar_Z)==1 && width > 0
+ %components of the unitiy vector normal to the projection plane
+ fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane
+ indcut=find(abs(fieldZ) <= width);
+ for ivar=VarIndex
+ VarName=FieldData.ListVarName{ivar};
+ eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
+% end
+ % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE
+ end
+ coord_x=coord_x(indcut);
+ coord_y=coord_y(indcut);
+ coord_z=coord_z(indcut);
+ end
+
+ %rotate coordinates if needed
+ if isequal(Phi,0)
+ coord_X=coord_x;
+ coord_Y=coord_y;
+ if ~isequal(Theta,0)
+ coord_Y=coord_Y *cos(Theta);
+ end
+ else
+ coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
+ coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
+ end
+ if ~isempty(ivar_Z)
+ coord_Y=coord_Y+coord_z *sin(Theta);
+ end
+ if ~isequal(Psi,0)
+ coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
+ coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
+ end
+
+ %restriction to the range of x and y if imposed
+ testin=ones(size(coord_X)); %default
+ testbound=0;
+ if testXMin
+ testin=testin & (coord_X >= XMin);
+ testbound=1;
+ end
+ if testXMax
+ testin=testin & (coord_X <= XMax);
+ testbound=1;
+ end
+ if testYMin
+ testin=testin & (coord_Y >= YMin);
+ testbound=1;
+ end
+ if testYMin
+ testin=testin & (coord_Y <= YMax);
+ testbound=1;
+ end
+ if testbound
+ indcut=find(testin);
+ for ivar=VarIndex
+ VarName=FieldData.ListVarName{ivar};
+ eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
+ end
+ coord_X=coord_X(indcut);
+ coord_Y=coord_Y(indcut);
+ if length(ivar_Z)==1
+ coord_Z=coord_Z(indcut);
+ end
+ end
+ % different cases of projection
+ if isequal(ObjectData.ProjMode,'projection')
+ ProjData.ListDimName=[ProjData.ListDimName FieldData.ListDimName(DimIndices(1))];%add the point index to the list of dimensions
+ ProjData.DimValue=[ProjData.DimValue length(coord_X)];
+ nbvar=0;
+ for ivar=VarIndex %transfer variables to the projection plane
+ VarName=FieldData.ListVarName{ivar};
+ if ivar==ivar_X %x coordinate
+ eval(['ProjData.' VarName '=coord_X;'])
+ elseif ivar==ivar_Y % y coordinate
+ eval(['ProjData.' VarName '=coord_Y;'])
+ elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
+ eval(['ProjData.' VarName '=FieldData.' VarName ';'])
+ end
+ if isempty(ivar_Z) || ivar~=ivar_Z
+ ProjData.ListVarName=[ProjData.ListVarName VarName];
+ ProjData.VarDimIndex=[ProjData.VarDimIndex DimIndices(1)];
+ nbvar=nbvar+1;
+ if isfield(FieldData,'VarAttribute') & length(FieldData.VarAttribute) >=ivar
+ ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
+ end
+ end
+ end
+ elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
+ coord_x_proj=[XMin:DX:XMax];
+ coord_y_proj=[YMin:DY:YMax];
+ DimCell={'coord_y','coord_x'};
+ %ProjData.DimValue=[length(coord_y_proj) length(coord_x_proj)];
+ ProjData.ListVarName={'coord_y','coord_x'};
+ ProjData.VarDimName={'coord_y','coord_x'};
+ nbcoord=2;
+ %ProjData.VarDimIndex={};
+ ProjData.coord_y=[YMin YMax];
+ ProjData.coord_x=[XMin XMax];
+ if isempty(ivar_X), ivar_X=0; end;
+ if isempty(ivar_Y), ivar_Y=0; end;
+ if isempty(ivar_Z), ivar_Z=0; end;
+ if isempty(ivar_U), ivar_U=0; end;
+ if isempty(ivar_V), ivar_V=0; end;
+ if isempty(ivar_W), ivar_W=0; end;
+ if isempty(ivar_F), ivar_F=0; end;
+ if isempty(ivar_FF), ivar_FF=0; end;
+ if ~isequal(ivar_FF,0)
+ VarName_FF=FieldData.ListVarName{ivar_FF};
+ eval(['indsel=find(FieldData.' VarName_FF '==0);'])
+ coord_X=coord_X(indsel);
+ coord_Y=coord_Y(indsel);
+ end
+ FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
+ testFF=0;
+ for ivar=VarIndex
+ VarName=FieldData.ListVarName{ivar};
+ if ~( ivar==ivar_X | ivar==ivar_Y | ivar==ivar_Z | ivar==ivar_F | ivar==ivar_FF | test_anc(ivar)==1)
+ ivar_new=ivar_new+1;
+ ProjData.ListVarName=[ProjData.ListVarName {VarName}];
+ ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
+ %ProjData.VarDimIndex=[ProjData.VarDimIndex {[1 2]}];
+ if isfield(FieldData,'VarAttribute') & length(FieldData.VarAttribute) >=ivar
+ ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
+ end
+% ProjData.VarAttribute{ivar_new}.Coord_2=[XMin XMax];
+% ProjData.VarAttribute{ivar_new}.Coord_1=[YMin YMax];
+ if ~isequal(ivar_FF,0)
+ eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
+ end
+ eval(['ProjData.' VarName '=griddata_uvmat(coord_X,coord_Y,FieldData.' VarName ',coord_x_proj,coord_y_proj'');'])
+ eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
+ FFlag= isnan(varline); %detect undefined values NaN
+ indnan=find(FFlag);
+ if~isempty(indnan)
+ varline(indnan)=zeros(size(indnan));
+ eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
+ FF(indnan)=ones(size(indnan));
+% eval(['ProjData.' VarName '(indnan)=zeros(size(indnan));'])%put NaN to 0
+% FF=FF|FFlag;
+ testFF=1;
+ end
+ if ivar==ivar_U
+ ivar_U=ivar_new;
+ end
+ if ivar==ivar_V
+ ivar_V=ivar_new;
+ end
+ if ivar==ivar_W
+ ivar_W=ivar_new;
+ end
+ end
+ end
+ if testFF
+ ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
+ ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
+ % ProjData.VarDimIndex=[ProjData.VarDimIndex {[1 2]}];
+ ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
+ ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
+ end
+ end
+%case of fields defined on a structured grid
+ else
+ AYName=FieldData.ListVarName{VarType.coord(1)};
+ AXName=FieldData.ListVarName{VarType.coord(2)};
+ eval(['AX=FieldData.' AXName ';'])
+ eval(['AY=FieldData.' AYName ';'])
+ VarName=FieldData.ListVarName{VarIndex(1)};
+ eval(['DimValue=size(FieldData.' VarName ');'])
+ ListDimName=FieldData.ListDimName(DimIndices);
+ ProjData.ListVarName=[{AYName} {AXName} ProjData.ListVarName]; %TODO: check if it already exists in Projdata (several cells)
+ ProjData.VarDimName=[{AYName} {AXName} ProjData.VarDimName];
+ nbcolor=1; %default
+ for idim=1:length(ListDimName)
+ DimName=ListDimName{idim};
+ if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')
+ nbcolor=DimValue(idim);
+ DimIndices(idim)=[];
+ DimValue(idim)=[];
+ end
+ if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
+ DimIndices(idim)=[];
+ DimValue(idim)=[];
+ end
+ end
+ ind_1=find(DimValue==1);
+ DimIndices(ind_1)=[]; %suppress singleton dimensions
+% indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)
+ nb_dim=length(DimIndices);%number of space dimensions
+ Coord_z=[];
+ Coord_y=[];
+ Coord_x=[];
+
+ for idim=1:nb_dim %loop on space dimensions
+ test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
+ test_coord(idim)=0;%test for defined coordinates, =0 by default
+ ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension
+ if ~isequal(ivar,0)% a variable corresponds to the current dimension
+ eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index
+ DCoord=diff(Coord{idim});
+ DCoord_min(idim)=min(DCoord);
+ DCoord_max=max(DCoord);
+ test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
+ test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
+ if ~isequal(test_direct(idim),test_direct_min)
+ warndlg_uvmat(['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'],'ERROR')
+ return
+ end
+ test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
+ test_coord(idim)=1;
+
+ else % no variable associated with the first dimension, look for variable attributes Coord_1, _2 or _3
+ Coord_i_str=['Coord_' num2str(idim)];
+ DCoord_min(idim)=1;%default
+ Coord{idim}=[0.5 DimValue(idim)-0.5];
+ test_direct(idim)=1;
+% for ivar=VarIndex
+% if isfield(FieldData.VarAttribute{ivar},Coord_i_str)% if there is a variable attribute named Coord_1, _2 or _3
+% eval(['Coord{idim}=FieldData.VarAttribute{ivar}.' Coord_i_str ';']);%'range x
+% if isnumeric(Coord{idim})
+% if length(Coord{idim})>=2
+% test_direct(idim)=(Coord{idim}(2)>Coord{idim}(1));
+% else
+% warndlg_uvmat(['two values needed for ' Coord_i_str 'in proj_field.m'],'ERROR')
+% return
+% end
+% else
+% warndlg_uvmat(['non numerical coordinate attributes' Coord_i_str 'in proj_field.m'],'ERROR')
+% return
+% end
+% DCoord_min(idim)=(Coord{idim}(end)-Coord{idim}(1))/(DimValue(idim)-1);
+% end
+% end
+ end
+ end
+ if nb_dim==2
+ if DY==0
+ DY=abs(DCoord_min(1));
+ end
+ npY=1+round(abs(Coord{1}(end)-Coord{1}(1))/DY);%nbre of points after interpolation
+ npy=1+round(abs(Coord{1}(end)-Coord{1}(1))/abs(DCoord_min(1)));%nbre of points after possible interpolation on a regular grid
+ if DX==0
+ DX=abs(DCoord_min(2));
+ end
+ npX=1+round(abs(Coord{2}(end)-Coord{2}(1))/DX);%nbre of points after interpol
+ npx=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points after possible interpolation on a regular grid
+ Coord_y=linspace(Coord{1}(1),Coord{1}(end),npY);
+ test_direct_y=test_direct(1);
+ Coord_x=linspace(Coord{2}(1),Coord{2}(end),npX);
+ test_direct_x=test_direct(2);
+ DAX=DCoord_min(2);
+ DAY=DCoord_min(1);
+ elseif nb_dim==3
+ DZ=abs(DCoord_min(1));
+ npz=1+round(abs(Coord{1}(end)-Coord{1}(1))/DZ);%nbre of points after interpolation
+ if DY==0
+ DY=abs(DCoord_min(2));
+ end
+ npY=1+round(abs(Coord{2}(end)-Coord{2}(1))/DY);%nbre of points after interpol
+ npy=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points before interpol
+ if DX==0
+ DX=abs(DCoord_min(3));
+ end
+ npX=1+round(abs(Coord{3}(end)-Coord{3}(1))/DX);%nbre of points after interpol
+ npx=1+round(abs(Coord{3}(end)-Coord{3}(1))/abs(DCoord_min(3)));%nbre of points before interpol
+ Coord_z=linspace(Coord{1}(1),Coord{1}(end),npz);
+ test_direct_z=test_direct(1);
+ Coord_y=linspace(Coord{2}(1),Coord{2}(end),npY);
+ test_direct_y=test_direct(2);
+ Coord_x=linspace(Coord{3}(1),Coord{3}(end),npX);
+ test_direct_x=test_direct(3);
+ end
+ minAX=min(Coord_x);
+ maxAX=max(Coord_x);
+ minAY=min(Coord_y);
+ maxAY=max(Coord_y);
+ xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
+ ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
+ xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
+ ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
+ if ~testXMax
+ XMax=max(xcor_new);
+ end
+ if ~testXMin
+ XMin=min(xcor_new);
+ end
+ if ~testYMax
+ YMax=max(ycor_new);
+ end
+ if ~testYMin
+ YMin=min(ycor_new);
+ end
+ DXinit=(maxAX-minAX)/(npx-1);
+ DYinit=(maxAY-minAY)/(npy-1);
+ if DX==0
+ DX=DXinit;
+ end
+ if DY==0
+ DY=DYinit;
+ end
+ npX=floor((XMax-XMin)/DX+1);
+ npY=floor((YMax-YMin)/DY+1);
+ if test_direct_y
+ coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
+ else
+ coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
+ end
+ if test_direct_x
+ coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
+ else
+ coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
+ end
+
+ % case with no rotation and interpolation
+ if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
+ if test_direct(1)
+ min_ind1=ceil((YMin-Coord{1}(1))/DYinit)+1;
+ max_ind1=floor((YMax-Coord{1}(1))/DYinit)+1;
+ Ybound(1)=Coord{1}(1)+DYinit*(min_ind1-1);
+ Ybound(2)=Coord{1}(1)+DYinit*(max_ind1-1);
+ else
+ min_ind1=ceil((Coord{1}(1)-YMax)/DYinit)+1;
+ max_ind1=floor((Coord{1}(1)-YMin)/DYinit)+1;
+ Ybound(2)=Coord{1}(1)-DYinit*(max_ind1-1);
+ Ybound(1)=Coord{1}(1)-DYinit*(min_ind1-1);
+ end
+ if test_direct(2)==1
+ min_ind2=ceil((XMin-Coord{2}(1))/DXinit)+1;
+ max_ind2=floor((XMax-Coord{2}(1))/DXinit)+1;
+ Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
+ Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
+ else
+ min_ind2=ceil((Coord{2}(1)-XMax)/DXinit)+1;
+ max_ind2=floor((Coord{2}(1)-XMin)/DXinit)+1;
+ Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
+ Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
+ end
+ min_ind1=max(min_ind1,1);% deals with margin (bound lower than the first index)
+ min_ind2=max(min_ind2,1);
+ max_ind1=min(max_ind1,npy);
+ max_ind2=min(max_ind2,npx);
+ for ivar=VarIndex
+ VarName=FieldData.ListVarName{ivar};
+% if isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')% coordinates common to all fields
+% ProjData.ListDimName={'coord_y','coord_x'};
+% ProjData.DimValue=[length(coord_y_proj) length(coord_x_proj)];
+% else
+% icoord=icoord+1;
+% ProjData.ListDimName=[ProjData.ListDimName {['coord_y_' num2str(icoord)],['coord_x_' num2str(icoord)]}];
+% ProjData.DimValue=[ProjData.DimValue length(coord_y_proj) length(coord_x_proj)];
+% end
+ ProjData.ListVarName=[ProjData.ListVarName VarName];
+ ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-1 nb_dim]];
+ if length(FieldData.VarAttribute)>=ivar
+ ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
+ end
+% ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_2=Xbound;
+% ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_1=Ybound;
+ eval(['ProjData.' VarName '=FieldData.' VarName '(min_ind1:max_ind1,min_ind2:max_ind2) ;']);
+ end
+ else
+ % case with rotation and/or interpolation
+ if isempty(Coord_z) %2D case
+ [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
+ XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
+ YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
+ XIMA=(XIMA-minAX)/DXinit+1;% image index along x
+ YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
+ XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
+ YIMA=reshape(round(YIMA),1,npX*npY);
+ flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
+ if isequal(ObjectData.ProjMode,'filter')
+ npx_filter=ceil(abs(DX/DAX));
+ npy_filter=ceil(abs(DY/DAY));
+ Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
+ test_filter=1;
+ else
+ test_filter=0;
+ end
+ for ivar=VarIndex
+ VarName=FieldData.ListVarName{ivar} ;
+ if test_interp(1) | test_interp(2)%interpolate on a regular grid
+ eval(['FieldData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
+ end
+ %filter the field (image) if option 'filter' is used
+ if test_filter
+ Aclass=class(FieldData.A);
+ eval(['FieldData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
+ if ~isequal(Aclass,'double')
+ eval(['FieldData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
+ end
+ end
+ eval(['vec_A=reshape(FieldData.' VarName ',npx*npy,nbcolor);'])%put the original image in line
+ ind_in=find(flagin);
+ ind_out=find(~flagin);
+ ICOMB=(XIMA-1)*npy+YIMA;
+ ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
+ vec_B(ind_in,[1:nbcolor])=vec_A(ICOMB,:);
+ for icolor=1:nbcolor
+ vec_B(ind_out,icolor)=zeros(size(ind_out));
+ end
+ % TODO: A REVOIR:
+% if isequal(ObjectData.ProjMode,'interp') || isequal(ObjectData.ProjMode,'filter')% coordinates common to all fields
+% ProjData.ListDimName={'coord_y','coord_x'};
+% ProjData.DimValue=[length(coord_y_proj) length(coord_x_proj)];
+% else
+% icoord=icoord+1;
+% ProjData.ListDimName=[ProjData.ListDimName {['coord_y_' num2str(icoord)],['coord_x_' num2str(icoord)]}];
+% ProjData.DimValue=[ProjData.DimValue length(coord_y_proj) length(coord_x_proj)];
+% end
+ ProjData.ListVarName=[ProjData.ListVarName VarName];
+ % ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-1 nb_dim]];
+ if length(FieldData.VarAttribute)>=ivar
+ ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
+ end
+ % A REVOIR:
+% if test_direct(2)==1
+% ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_2=[XMin XMax];
+% else
+% ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_2=[XMax XMin];
+% end
+% if test_direct(1)==1
+% ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_1=[YMin YMax];
+% else
+% ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_1=[YMax YMin];
+% end
+ eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
+ end
+ ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur
+ ProjData.ListVarName=[ProjData.ListVarName 'FF'];
+ % ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-1 nb_dim]];
+ ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
+ else %3D case
+ if isequal(Theta,0) & isequal(Phi,0)
+ test_sup=(Coord{1}>=ObjectData.Coord(1,3));
+ iz_sup=find(test_sup);
+ iz=iz_sup(1);
+ if iz>=1 & iz<=npz
+ ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
+ ProjData.DimValue=[ProjData.DimValue npY npX];
+ for ivar=VarIndex
+ VarName=FieldData.ListVarName{ivar};
+ ProjData.ListVarName=[ProjData.ListVarName VarName];
+ % ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-2 nb_dim-1]];
+ ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
+ % A REVOIR
+% if test_direct_x==1
+% ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_2=[XMin XMax];
+% else
+% ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_2=[XMax XMin];
+% end
+% if test_direct_y==1
+% ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_1=[YMin YMax];
+% else
+% ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_1=[YMax YMin];
+% end
+ eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
+ %TODO : do a vertical average for a thick plane
+ if test_interp(2) | test_interp(3)
+ eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
+ end
+ end
+ end
+ else
+ errormsg='projection of structured coordinates on oblique plane not yet implemented';
+ %TODO: use interp3
+ return
+ end
+ end
+ end
+ end
+ %projection of velocity components in the rotated coordinates
+ if ~isequal(Phi,0) & length(ivar_U)==1
+ if isempty(ivar_V)
+ warndlg_uvmat('v velocity component missing in proj_field.m','ERROR')
+ return
+ end
+ UName=FieldData.ListVarName{ivar_U};
+ VName=FieldData.ListVarName{ivar_V};
+ eval(['ProjData.' UName '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
+ eval(['ProjData.' VName '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
+ if ~isempty(ivar_W)
+ WName=FieldData.ListVarName{ivar_W};
+ eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
+ eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
+ end
+ if ~isequal(Psi,0)
+ eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
+ eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
+ end
+ end
+end
+
+%-----------------------------------------------------------------
+%transmit the global attributes
+function [ProjData,errormsg]=proj_heading(FieldData,ObjectData)
+%-----------------------------------------------------------------
+% ProjData=FieldData;
+ProjData=[];%default
+if ~isfield(FieldData,'ListGlobalAttribute')
+ ProjData.ListGlobalAttribute={};
+else
+ ProjData.ListGlobalAttribute=FieldData.ListGlobalAttribute;
+end
+if isfield(FieldData,'Txt')
+ errormsg=FieldData.Txt; %transmit erreur message
+ return;
+end
+for iattr=1:length(ProjData.ListGlobalAttribute)
+ AttrName=ProjData.ListGlobalAttribute{iattr};
+ if isfield(FieldData,AttrName)
+ eval(['ProjData.' AttrName '=FieldData.' AttrName ';']);
+ end
+end
+if isfield(FieldData,'CoordType')
+ if isfield(ObjectData,'CoordType')&~isequal(FieldData.CoordType,ObjectData.CoordType)
+ errormsg=[ObjectData.Style ' in ' ObjectData.CoordType ' coordinates, while field in ' FieldData.CoordType ' coordinates'];
+ return
+ else
+ ProjData.CoordType=FieldData.CoordType;
+ end
+end
+
+ListObject={'Style','ProjMode','RangeX','RangeY','RangeZ','Phi','Theta','Psi','Coord'};
+for ilist=1:length(ListObject)
+ if isfield(ObjectData,ListObject{ilist})
+ eval(['val=ObjectData.' ListObject{ilist} ';'])
+ if ~isempty(val)
+ eval(['ProjData.Object' ListObject{ilist} '=val;']);
+ ProjData.ListGlobalAttribute=[ProjData.ListGlobalAttribute {['Object' ListObject{ilist}]}];
+ end
+ end
+end
Index: /trunk/src/proj_grid.m
===================================================================
--- /trunk/src/proj_grid.m (revision 2)
+++ /trunk/src/proj_grid.m (revision 2)
@@ -0,0 +1,83 @@
+%'proj_grid': project fields with unstructured coordinantes on a regular grid
+% -------------------------------------------------------------------------
+% function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)
+
+
+function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)
+ if length(vec_Y)<2
+ warndlg_uvmat('less than 2 points in proj_grid.m','ERROR');
+ return;
+ end
+ diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
+ index=find(diffy);% find the indices of vec_Y after wich a change of horizontal line occurs(diffy non zero)
+ if isempty(index); warndlg_uvmat('points aligned along abscissa in proj_grid.m','ERROR'); return; end;%points aligned% A FAIRE: switch to line plot.
+ diff2=diff(diffy(index));% diff2 = fluctuations of the detected vertical grid mesh dy
+ if max(abs(diff2))>0.001*abs(diffy(index(1))) % if max(diff2) is larger than 1/1000 of the first mesh dy
+ % the data are not regularly spaced and must be interpolated on a regular grid
+ if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2% positions imposed from input
+ rangx=rgx_in; % first and last positions
+ rangy=rgy_in;
+% npxy=npxy_in;
+ dxy(1)=1/(npxy_in(1)-1);%grid mesh in y
+ dxy(2)=1/(npxy_in(2)-1);%grid mesh in x
+ dxy(1)=(rangy(2)-rangy(1))/(npxy_in(1)-1);%grid mesh in y
+ dxy(2)=(rangx(2)-rangx(1))/(npxy_in(2)-1);%grid mesh in x
+ else % interpolation grid automatically determined
+ rangx(1)=min(vec_X);
+ rangx(2)=max(vec_X);
+ rangy(2)=min(vec_Y);
+ rangy(1)=max(vec_Y);
+ dxymod=sqrt((rangx(2)-rangx(1))*(rangy(1)-rangy(2))/length(vec_X));
+ dxy=[-dxymod/4 dxymod/4];% increase the resolution 4 times
+ end
+ xi=[rangx(1):dxy(2):rangx(2)];
+ yi=[rangy(1):dxy(1):rangy(2)];
+ [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
+ A=griddata_uvmat(vec_X,vec_Y,vec_A,xi,yi');
+ A=reshape(A,length(yi),length(xi));
+ else
+ x=vec_X(1:index(1));% the set of abscissa (obtained on the first line)
+ indexend=index(end);% last vector index of line change
+ ymax=vec_Y(indexend+1);% y coordinate AFTER line change
+ ymin=vec_Y(index(1));
+ %y=[vec_Y(index) ymax]; % the set of y ordinates including the last one
+ y=vec_Y(index);
+ y(length(y)+1)=ymax;
+ nx=length(x); %number of grid points in x
+ ny=length(y); % number of grid points in y
+ B=(reshape(vec_A,nx,ny))'; %vec_A reshaped as a rectangular matrix
+ [X,Y]=meshgrid(x,y);% positions X and Y also reshaped as matrix
+
+ %linear interpolation to improve the image resolution and/or adjust
+ %to prescribed positions
+ test_interp=1;
+ if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2% positions imposed from input
+ rangx=rgx_in; % first and last positions
+ rangy=rgy_in;
+ npxy=npxy_in;
+ else
+ rangx=[vec_X(1) vec_X(nx)];% first and last position found for x
+% rangy=[ymin ymax];
+ rangy=[max(ymax,ymin) min(ymax,ymin)];
+ if max(nx,ny) <= 64 & isequal(npxy_in,'np>256')
+ npxy=[8*ny 8*nx];% increase the resolution 8 times
+ elseif max(nx,ny) <= 128 & isequal(npxy_in,'np>256')
+ npxy=[4*ny 4*nx];% increase the resolution 4 times
+ elseif max(nx,ny) <= 256 & isequal(npxy_in,'np>256')
+ npxy=[2*ny 2*nx];% increase the resolution 2 times
+ else
+ npxy=[ny nx];
+ test_interp=0; % no interpolation done
+ end
+ end
+ if test_interp==1%if we interpolate
+ xi=[rangx(1):(rangx(2)-rangx(1))/(npxy(2)-1):rangx(2)];
+ yi=[rangy(1):(rangy(2)-rangy(1))/(npxy(1)-1):rangy(2)];
+ [XI,YI]=meshgrid(xi,yi);
+ A = interp2(X,Y,B,XI,YI);
+ else %no interpolation for a resolution higher than 256
+ A=B;
+ XI=X;
+ YI=Y;
+ end
+ end
Index: /trunk/src/px.m
===================================================================
--- /trunk/src/px.m (revision 2)
+++ /trunk/src/px.m (revision 2)
@@ -0,0 +1,87 @@
+%'px': transform fields from physical coordinates (phys) to image (px) coordinates
+
+% OUTPUT:
+% DataOut: structure of modified data (transforms DataIn)
+% DataOut.CoordType='px': labels image coordinates
+% DataOut.CoordUnit= 'px' : units of output coordinates
+% DataOut.X and .Y arrays of image coordinates X, Y
+% DataOut.U, .V velocity in pixel displacement on the image (unit=px), if velocity exists as input
+%
+%INPUT:
+% DataIn: structure of possible input data (like UvData) or cell of structures (several fields):
+% DataIn.CoordType='phys': allows transform to px, else no transform (DataOut=DataIn)
+% DataIn.X and .Y arrays of physical coordinates X, Y
+% DataIn.Z corresponding array of Z coordinates (=0 by default)
+% DataIn.U, V corresponding array of velocity components
+% DataIn.W corresponding array of the third velocity component in 3D case
+% DataIn.dt: time interval of the image pair used for velocity measurement (NEEDED TO GET OUTPUT RESULT))
+% DataIn.A, AX, AY : image or scalar input -> EMPTY CORRESPONDING OUTPUT (A REVOIR)
+% Other fields in DataIn: copied to DataOut without modification
+% Calib: structure containing the calibration parameters (Tsai) or containing a subtree Calib.GeometryCalib with these parameters
+%
+% call the functions phys_XYZ or px_XYZ (case of images) for pointwise coordinate transforms
+
+function [DataOut,DataOut_1]=px(Data,CalibData,Data_1,CalibData_1)%DataIn,Calib)
+% A FAIRE: 1- verifier si DataIn est une 'field structure'(.ListVarName'):
+% chercher ListVarAttribute, for each field (cell of variables):
+% .CoordType: 'phys' or 'px' (default==px, no transform)
+% .scale_factor: =dt (to transform displacement into velocity) default=1
+% .covariance: 'scalar', 'coord', 'D_i': covariant (like velocity), 'D^i': contravariant (like gradient), 'D^jD_i' (like strain tensor)
+% (default='coord' if .Role='coord_x,_y...,
+% 'D_i' if '.Role='vector_x,...',
+% 'scalar', else (thenno change except scale factor)
+if ~(exist('CalibData','var') && isfield(CalibData,'GeometryCalib'))
+ DataOut=Data;
+else
+ DataOut=px_1(Data,CalibData.GeometryCalib);
+end
+if exist('Data_1','var')
+ if ~(exist('CalibData_1','var') && isfield(CalibData_1,'GeometryCalib'))
+ DataOut_1=Data_1;
+ else
+ DataOut_1=px_1(Data_1,CalibData_1.GeometryCalib);
+ end
+else
+ DataOut_1=[];
+end
+
+
+%------------------------------------------------
+function DataOut=px_1(Data,Calib)
+DataOut=Data;%default
+
+%Act only if .CoordType=phys, and Calib defined
+if isfield(Data,'CoordType')& isequal(Data.CoordType,'phys')& ~isempty(Calib)
+ DataOut.CoordType='px'; %put flag for pixel coordinates
+ DataOut.CoordUnit='px';
+ %transform of X,Y coordinates
+ if isfield(Data,'Z')&~isempty(Data.Z)
+ Z=Data.Z;
+ else
+ Z=0;
+ end
+ if isfield(Data,'X') & isfield(Data,'Y')
+ [DataOut.X,DataOut.Y]=px_XYZ(Calib,Data.X,Data.Y,Z);
+ if isfield(Data,'U')&isfield(Data,'V')& isfield(Data,'dt')& ~isequal(Data.dt,0)
+ Data.U=Data.U*Data.dt;
+ Data.V=Data.V*Data.dt;
+ if isfield(Data,'W')
+ W=Data.W*Data.dt;
+ else
+ W=0;
+ end
+ [XOut_1,YOut_1]=px_XYZ(Calib,Data.X-Data.U/2,Data.Y-Data.V/2,Z-W/2);
+ [XOut_2,YOut_2]=px_XYZ(Calib,Data.X+Data.U/2,Data.Y+Data.V/2,Z+W/2);
+ DataOut.U=XOut_2-XOut_1;
+ DataOut.V=YOut_2-YOut_1;
+ end
+ end
+ %transform of an image
+ if isfield(Data,'A')&isfield(Data,'AX')&~isempty(Data.AX) & isfield(Data,'AY')&...
+ isfield(Data,'AY')&~isempty(Data.AY)&length(Data.A)>1
+% if isfield(Data,'Field')&isequal(Data.Field,'images')
+ %NO TRANSFORM FROM phys to px for images
+ DataOut.A=[];%
+ end
+end
+
Index: /trunk/src/px_XYZ.m
===================================================================
--- /trunk/src/px_XYZ.m (revision 2)
+++ /trunk/src/px_XYZ.m (revision 2)
@@ -0,0 +1,50 @@
+%'px_XYZ': transform phys coordinates to image coordinates (px)
+%
+% OUPUT:
+% X,Y: array of coordinates in the image cooresponding to the input physical positions
+% (origin at lower leftcorner, unit=pixel)
+
+% INPUT:
+% Calib: structure containing the calibration parameters (read from the ImaDoc .xml file)
+% Xphys, Yphys: array of x,y physical coordinates
+% [Zphys]: corresponding array of z physical coordinates (0 by default)
+
+
+function [X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys)
+X=[];%default
+Y=[];
+% if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'PlanePos')&length(Calib.PlanePos)>=Z
+% Zindex=Z;
+% planepos=Calib.PlanePos{Zindex};
+% zphys=planepos(3);%A GENERALISER CAS AVEC ANGLE
+% else
+% zphys=0;
+% end
+if ~exist('Zphys','var')
+ Zphys=0;
+end
+
+%%%%%%%%%%%%%
+if isfield(Calib,'R')
+ R=(Calib.R)';
+ xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx;
+ yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Ty;
+ zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tz;
+%undistorted image coordinates
+ Xu=Calib.f*xc./zc;
+ Yu=Calib.f*yc./zc;
+%distorted image coordinates
+ distortion=(Calib.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %A REVOIR
+% distortion=1;
+ Xd=Xu./distortion;
+ Yd=Yu./distortion;
+%pixel coordinates
+ X=Xd*Calib.sx/Calib.dpx+Calib.Cx;
+ Y=Yd/Calib.dpy+Calib.Cy;
+
+elseif isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib
+ X=Xphys*Calib.Pxcmx;
+ Y=Yphys*Calib.Pxcmy;
+end
+
+
Index: /trunk/src/pxcm_tsai.m
===================================================================
--- /trunk/src/pxcm_tsai.m (revision 2)
+++ /trunk/src/pxcm_tsai.m (revision 2)
@@ -0,0 +1,79 @@
+%'pxcm_tsai': find differentials of the Tsai calibration
+%
+function [A11,A12,A13,A21,A22,A23]=pxcm_tsai(a,var_phys)
+a_read=a;
+
+R=(a.R)';
+
+x=var_phys(:,1);
+y=var_phys(:,2);
+
+if isfield(a,'PlanePos')
+ prompt={'Plane 1 Index','Plane 2 Index'};
+ Rep=inputdlg(prompt,'Target displacement test');
+ Z1=str2double(Rep(1));
+ Z2=str2double(Rep(2));
+ z=(a.PlanePos(Z2,3)+a.PlanePos(Z1,3))/2
+else
+ z=0;
+end
+
+%transform coeff for differentiels
+a.C11=R(1)*R(8)-R(2)*R(7);
+a.C12=R(2)*R(7)-R(1)*R(8);
+a.C21=R(4)*R(8)-R(5)*R(7);
+a.C22=R(5)*R(7)-R(4)*R(8);
+a.C1x=R(3)*R(7)-R(9)*R(1);
+a.C1y=R(3)*R(8)-R(9)*R(2);
+a.C2x=R(6)*R(7)-R(9)*R(4);
+a.C2y=R(6)*R(8)-R(9)*R(5);
+
+
+%dependence in x,y
+denom=(R(7)*x+R(8)*y+R(9)*z+a.Tz).*(R(7)*x+R(8)*y+R(9)*z+a.Tz);
+A11=(a.f*a.sx*(a.C11*y-a.C1x*z+R(1)*a.Tz-R(7)*a.Tx)./denom)/a.dpx;
+A12=(a.f*a.sx*(a.C12*x-a.C1y*z+R(2)*a.Tz-R(8)*a.Tx)./denom)/a.dpx;
+A21=(a.f*a.sx*(a.C21*y-a.C2x*z+R(4)*a.Tz-R(7)*a.Ty)./denom)/a.dpy;
+A22=(a.f*(a.C22*x-a.C2y*z+R(5)*a.Tz-R(8)*a.Ty)./denom)/a.dpy;
+A13=(a.f*(a.C1x*x+a.C1y*y+R(3)*a.Tz-R(9)*a.Tx)./denom)/a.dpx;
+A23=(a.f*(a.C2x*x+a.C2y*y+R(6)*a.Tz-R(9)*a.Ty)./denom)/a.dpy;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%Old Version for z=0
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %'camera' coordinates
+% xc=R(1)*x+R(2)*y+a.Tx;
+% yc=R(4)*x+R(5)*y+a.Ty;
+% zc=R(7)*x+R(8)*y+a.Tz;
+% %undistorted image coordinates
+% Xu=a.f*xc./zc;
+% Yu=a.f*yc./zc;
+% %distorted image coordinates
+% distortion=(a.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %!! intégrer derivation kappa
+% % distortion=1;
+% Xd=Xu./distortion;
+% Yd=Yu./distortion;
+% %pixel coordinates
+% X=Xd*a.sx/a.dpx+a.Cx;
+% Y=Yd/a.dpy+a.Cy;
+%
+% %transform coeff for differentiels
+% a.C11=R(1)*R(8)-R(2)*R(7);
+% a.C12=R(2)*R(7)-R(1)*R(8);
+% a.C21=R(4)*R(8)-R(5)*R(7);
+% a.C22=R(5)*R(7)-R(4)*R(8);
+% a.C1x=R(3)*R(7)-R(9)*R(1);
+% a.C1y=R(3)*R(8)-R(9)*R(2);
+% a.C2x=R(6)*R(7)-R(9)*R(4);
+% a.C2y=R(6)*R(8)-R(9)*R(5);
+%
+%
+% %dependence in x,y
+% denom=(R(7)*x+R(8)*y+a.Tz).*(R(7)*x+R(8)*y+a.Tz);
+% A11=(a.f*a.sx*(a.C11*y+R(1)*a.Tz-R(7)*a.Tx)./denom)/a.dpx;
+% A12=(a.f*a.sx*(a.C12*x+R(2)*a.Tz-R(8)*a.Tx)./denom)/a.dpx;
+% A21=(a.f*a.sx*(a.C21*y+R(4)*a.Tz-R(7)*a.Ty)./denom)/a.dpy;
+% A22=(a.f*(a.C22*x+R(5)*a.Tz-R(8)*a.Ty)./denom)/a.dpy;
+% A13=(a.f*(a.C1x*x+a.C1y*y+R(3)*a.Tz-R(9)*a.Tx)./denom)/a.dpx;
+% A23=(a.f*(a.C2x*x+a.C2y*y+R(6)*a.Tz-R(9)*a.Ty)./denom)/a.dpy;
+%
Index: /trunk/src/raw2phys.m
===================================================================
--- /trunk/src/raw2phys.m (revision 2)
+++ /trunk/src/raw2phys.m (revision 2)
@@ -0,0 +1,151 @@
+%'raw2phys': transform raw signal to physical values using different calibrations laws
+%
+function FieldPhys=raw2phys(Field)
+
+% do not transform if Field already in phys coordinates
+FieldPhys=Field;%default
+if isfield(Field,'CoordType') & isequal(Field.CoordType,'phys')
+ return %no transform if the data are already physical
+else
+ FieldPhys.CoordType='phys';
+end
+
+%Filtering of the initial data
+nbfilter=51;
+nbhalf=floor(nbfilter/2);
+for ivar=1:length(FieldPhys.ListVarName)
+ VarName=FieldPhys.ListVarName{ivar};
+ if ~isequal(VarName,'time')
+ eval(['FirstVal=FieldPhys.' VarName '(1);'])
+ eval(['LastVal=FieldPhys.' VarName '(end);'])
+ FirstVal=ones(nbhalf,1)*FirstVal;
+ LastVal=ones(nbhalf,1)*LastVal;
+ eval(['FieldPhys.' VarName '=[FirstVal;FieldPhys.' VarName ';LastVal];'])
+ eval(['FieldPhys.' VarName '=conv(ones(1,nbfilter)/nbfilter,FieldPhys.' VarName ');']);
+ eval(['FieldPhys.' VarName '([1:nbfilter-1])=[];']);
+ eval(['FieldPhys.' VarName '([end-nbfilter+2:end])=[];']);
+ end
+end
+
+
+
+ScanRate=240; %data points per second
+VelTranslation=1; % 1 cm/s A VERIFIER
+test_Offset=0;
+test_Thermistance_B=0;
+test_Thermistance_M=0;
+if isfield(Field,'ListVarAttribute')
+ for ilist=1:length(Field.ListVarAttribute)
+ attr_name=Field.ListVarAttribute{ilist}
+ if isequal(attr_name,'PhysUnits')
+ FieldPhys.units =Field.PhysUnits;
+ end
+ if isequal(attr_name,'Offset')
+ test_Offset=1;
+ end
+ if isequal(attr_name,'ThermistanceCalib_B')
+ test_Thermistance_B=1;
+ end
+ if isequal(attr_name,'ThermistanceCalib_M')
+ test_Thermistance_M=1;
+ end
+ end
+end
+
+
+
+% substract offset
+if test_Offset
+ for ivar=1:length(Field.ListVarName)
+ Val_Offset=Field.Offset{ivar};
+ if isnumeric(Val_Offset)&~isempty(Val_Offset)
+ VarName=Field.ListVarName{ivar};
+ eval(['FieldPhys.' VarName '=FieldPhys.' VarName '-Val_Offset;'])
+ end
+ end
+end
+
+%thermistance calibration
+if test_Thermistance_M & test_Thermistance_B
+ for ivar=1:length(Field.ListVarName)
+ Val_B=Field.ThermistanceCalib_B{ivar};
+ Val_M=Field.ThermistanceCalib_M{ivar};
+ if isnumeric(Val_B) & ~isempty(Val_B) & isnumeric(Val_M) & ~isempty(Val_M)
+ VarName=Field.ListVarName{ivar};
+ eval(['FieldPhys.' VarName '=(Val_M ./ (log( FieldPhys.' VarName ')-Val_B)) -273.15;'])
+ end
+ end
+end
+return
+
+%NON USED
+%density profile
+Density=(Conductivity-B)/A;%calibration
+Density=Density(find(Motor>1));%restrict the record to the time motor on
+Density=flipdim(Density,2)';
+%detect free surface
+[dmax,imax]=max(diff(Density));
+nbpoints=length(Density);
+Pos=linspace(0,nbpoints*VelTranslation/ScanRate,nbpoints);
+Pos=Pos-imax*VelTranslation/ScanRate;
+
+%[dmax,jmax]=max(diff(Conductivity))
+napoints=length(Conductivity);
+Pos1=linspace(0,napoints*VelTranslation/ScanRate,napoints);
+%Pos1=Pos1-jmax*VelTranslation/ScanRate;
+
+figure(2);
+clf
+plot(Pos1,Conductivity)
+grid on
+figure(3);
+size(Pos)
+size(Density)
+plot(Pos,Density)
+hold on
+grid on
+%determination of N
+PosCentr=Pos([floor(nbpoints/4):floor(3*nbpoints/4)]);
+DensityCentr=Density([floor(nbpoints/4):floor(3*nbpoints/4)]);
+p=polyfit(PosCentr,DensityCentr,1);
+LinDens=polyval(p,PosCentr);
+plot(PosCentr,LinDens,'r')
+grad=p(1)
+%find(Motor>1)
+
+% data.conductivity=flipdim(Conductivity(find(Motor>5)),1)';
+% data.deplacement=[100/size(data.conductivity,2):100/size(data.conductivity,2):100];
+%
+% figure;plot(data.deplacement,data.conductivity);hold on;
+
+%data.density=flipdim(Conductivity(find(Motor>1)),1)'*3.4764+15.1367;
+%data.density=flipdim(Conductivity(find(Motor>1)),2)'*5+14.6090;
+%data.density=flipdim(Conductivity(find(Motor>1)),2)'*4.1525+19.50;
+% data.density=flipdim(Conductivity(find(Motor>1)),2)'
+% data.deplacement=[92/size(data.density,2):92/size(data.density,2):92];
+% figure(101)
+% plot(data.deplacement,data.density);hold on;
+
+% t=data.deplacement(find(data.deplacement>20&data.deplacement<80));
+%t=data.deplacement(find(data.deplacement>0&data.deplacement<90));
+% X=[ones(size(t,2),1)';t];
+% Y=data.density(find(data.deplacement>20&data.deplacement<80));
+% %Y=data.density(find(data.deplacement>0&data.deplacement<90));
+% coeff=Y/X;
+
+% plot(data.deplacement,data.deplacement*coeff(2)+coeff(1),'r');
+
+% grad=abs(coeff(2)*100)
+Tbv=2*pi/sqrt(981*0.001*grad)
+N=2*pi/Tbv
+title(strcat('',name,''))
+xpos=get(gca,'XLim')
+ypos=get(gca,'YLim')
+%xtext=xpos(1)+(xpos(2)-xpos(1))*3/4
+xtext=xpos(1)+(xpos(2)-xpos(1))/2
+ytext=ypos(1)+(ypos(2)-ypos(1))/4
+TabText={strcat('Tbv : ',num2str(Tbv),'s'); strcat('Stratification : ',num2str(grad)); strcat('N : ',num2str(2*pi/Tbv),'rad.s-1')}
+text(xtext,ytext,TabText)
+% text(xtext,13,strcat('Tbv : ',num2str(Tbv),'s'));
+% text(55,10,strcat('Stratification : ',num2str(grad)));
+% text(55,16,strcat('N : ',num2str(2*pi/Tbv),'rad.s-1'));
Index: /trunk/src/read_civxdata.m
===================================================================
--- /trunk/src/read_civxdata.m (revision 2)
+++ /trunk/src/read_civxdata.m (revision 2)
@@ -0,0 +1,275 @@
+%'read_civxdata': reads civx data from netcdf files
+%------------------------------------------------------------------
+% COMBINE ET REMPLACE read_ncfield, read_vel et read_scalar_new
+%------------------------------------------------------------------
+% OUTPUT:
+% nb_coord,nb_dim,
+% Civ: =0 or 1, indicates whether the data is civ (A SUPPRIMER ?)
+% CivStage: =0, ??? A UTILISER POUR REMPLACER civ
+% =1, civ1 has been performed only
+% =2, fix1 has been performed
+% =3, pacth1 has been performed
+% =4, civ2 has been performed
+% =5, fix2 has been performed
+% =6, pacth2 has been performed
+% time: absolute time
+% Field
+% .Txt: (char string) error message if any
+% .NbDim: number of dimensions (=0 by default)
+% .NbCoord: number of vector components
+% .CoordType: expresses the type of coordinate ('px' for image, 'sig' for instruments, or 'phys')
+% .dt: time interval for the corresponding image pair
+% .CivStage: =0, ??? A UTILISER POUR REMPLACER civ
+ % =1, civ1 has been performed only
+ % =2, fix1 has been performed
+ % =3, pacth1 has been performed
+ % =4, civ2 has been performed
+ % =5, fix2 has been performed
+ % =6, pacth2 has been performed
+% .X, .Y, .Z: set of vector coordinates
+% .U,.V,.W: corresponding set of vector components
+% .F: warning flags
+% .FF: error flag, =0 for good vectors
+% .C: scalar associated with velocity (used for vector colors)
+% .CoordType
+% .DijU; matrix of spatial derivatives (DijU(1,1,:)=DUDX,
+% DijU(1,2,:)=DUDY, Dij(2,1,:)=DVDX, DijU(2,2,:)=DVDY
+% .A, .AX, .AY: additional scalar
+% dt:time interval of the image pair red from a single file, or vector with
+
+% pixcmx,pixcmy: scaling factors (from the first file)
+% vel_type_out: string representing the selected velocity type (civ1,civ2,filter1...)
+%
+% INPUT:
+% filename: file name (string).
+% FieldNames =cell of field names to get, which can contain the strings:
+% 'ima_cor': image correlation, vec_c or vec2_C
+% 'vort','div','strain': requires velocity derivatives DUDX...
+% 'error': error estimate (vec_E or vec2_E)
+%
+% VelType : character string indicating the types of velocity fields to read ('civ1','civ2'...)
+% if vel_type=[] or'*', a priority choice, given by vel_type_out{1,2}, is done depending
+% if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
+
+
+% FUNCTIONS called:
+% 'varcivx_generator':, sets the names of vaiables to read in the netcdf file
+% 'nc2struct': reads a netcdf file
+
+function [Field,VelTypeOut]=read_civxdata(filename,FieldNames,VelType)
+
+if ~exist('VelType','var')
+ VelType=[];
+end
+if isequal(VelType,'*')
+ VelType=[];
+end
+if ~exist('FieldNames','var')
+ FieldNames=[]; %default
+end
+
+VelTypeOut=VelType;%default
+[var,role,units,vel_type_out_cell]=varcivx_generator(FieldNames,VelType);%determine the names of constants and variables to read
+[Field,vardetect,ichoice]=nc2struct(filename,var);
+if isfield(Field,'Txt')
+ return % error in file reading
+end
+if isequal(vardetect,0)
+ Field.Txt=[FieldNames ' not accessible in ' filename '/' VelType];
+ return
+end
+var_ind=find(vardetect);
+for ivar=1:length(var_ind)
+ Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
+% Field.VarAttribute{ivar}.units=units{var_ind(ivar)};% not necessary: set with calc_field
+end
+VelTypeOut=VelType;
+if ~isempty(ichoice)
+ VelTypeOut=vel_type_out_cell{ichoice};
+end
+
+%adjust for Djui:
+if isfield(Field,'DjUi')
+ Field.ListVarName(end-2:end)=[];
+ Field.ListVarName{end}='DjUi';
+ Field.VarDimIndex(end-2:end)=[];
+ Field.VarAttribute(end-2:end)=[];
+end
+
+%determine the appropriate constant for time and dt for the PIV pair
+test_civ1=isequal(VelTypeOut,'civ1')||isequal(VelTypeOut,'interp1')||isequal(VelTypeOut,'filter1');
+test_civ2=isequal(VelTypeOut,'civ2')||isequal(VelTypeOut,'interp2')||isequal(VelTypeOut,'filter2');
+if test_civ1
+ Field.Time=Field.absolut_time_T0;
+elseif test_civ2
+ Field.Time=Field.absolut_time_T0_2;
+ Field.dt=Field.dt2;
+else
+ Field.Txt='the input file is not civx';
+ display(Field.Txt)
+end
+
+% CivStage
+if isfield(Field,'patch2')&& isequal(Field.patch2,1)
+ Field.CivStage=6;
+elseif isfield(Field,'fix2')&& isequal(Field.fix2,1)
+ Field.CivStage=5;
+elseif isfield(Field,'civ2')&& isequal(Field.civ2,1)
+ Field.CivStage=4;
+elseif isfield(Field,'patch')&& isequal(Field.patch,1)
+ Field.CivStage=3;
+elseif isfield(Field,'fix')&& isequal(Field.fix,1)
+ Field.CivStage=2;
+else
+ Field.CivStage=1;
+end
+
+%update list of global attributes
+List=Field.ListGlobalAttribute;
+ind_remove=[];
+for ilist=1:length(List)
+ switch(List{ilist})
+ case {'patch2','fix2','civ2','patch','fix','dt2','absolut_time_T0','absolut_time_T0_2'}
+ ind_remove=[ind_remove ilist];
+ Field=rmfield(Field,List{ilist});
+ end
+end
+List(ind_remove)=[];
+Field.ListGlobalAttribute=[List {'Time','CivStage','CoordUnit'}];
+
+% rescale to pixel coordiantes
+if isfield(Field,'pixcmx')
+Field.U=Field.U*Field.pixcmx;
+Field.V=Field.V*Field.pixcmy;
+Field.X=Field.X*Field.pixcmx;
+Field.Y=Field.Y*Field.pixcmy;
+end
+if ~isequal(Field.dt,0)
+ Field.U=Field.U*Field.dt;%translate in px displacement
+ Field.V=Field.V*Field.dt;
+ if isfield(Field,'DjUi')
+ Field.DjUi(:,1,1)=Field.dt*Field.DjUi(:,1,1);
+ Field.DjUi(:,2,2)=Field.dt*Field.DjUi(:,2,2);
+ Field.DjUi(:,1,2)=(Field.pixcmy/Field.pixcmx)*Field.dt*Field.DjUi(:,1,2);
+ Field.DjUi(:,2,1)=(Field.pixcmx/Field.pixcmy)*Field.dt*Field.DjUi(:,2,1);
+ end
+end
+Field.CoordType='px';% TODO: abandon, use COORdUnit instead ? (to adapt 'px' and 'phys')
+Field.CoordUnit='pixel';
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
+%INPUT:
+% FieldNames =cell of field names to get, which can contain the strings:
+% 'ima_cor': image correlation, vec_c or vec2_C
+% 'vort','div','strain': requires velocity derivatives DUDX...
+% 'error': error estimate (vec_E or vec2_E)
+%
+% vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
+% if vel_type=[] or'*', a priority choice, given by vel_type_out{1,2}, is done depending
+% if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
+
+function [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
+
+%default input values
+if ~exist('vel_type','var'),vel_type=[];end;
+if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
+% if ~exist('display','var'),display=[];end;
+if ~exist('FieldNames','var'),FieldNames={'ima_cor'};end;%default scalar
+if ischar(FieldNames), FieldNames={FieldNames}; end;
+
+%select the priority order for automatic vel_type selection
+testder=0;
+for ilist=1:length(FieldNames)
+ if ~isempty(FieldNames{ilist})
+ switch FieldNames{ilist}
+ case {'vort','div','strain'}
+ testder=1;
+ end
+ end
+end
+if isempty(vel_type) || isequal(vel_type,'*') %undefined velocity type (civ1,civ2...)
+ if testder
+ vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
+ vel_type_out{2}='filter1';
+ else
+ vel_type_out{1}='civ2'; %priority to civ2 for vector reading, civ1 as second priority
+ vel_type_out{2}='civ1';
+ end
+elseif isequal(vel_type,'filter')
+ vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
+ vel_type_out{2}='filter1';
+ if ~testder
+ vel_type_out{3}='civ1';%civ1 as third priority if derivatives are not needed
+ end
+elseif testder
+ test_civ1=isequal(vel_type,'civ1')||isequal(vel_type,'interp1')||isequal(vel_type,'filter1');
+ if test_civ1
+ vel_type_out{1}='filter1'; %switch to filter for reading spatial derivatives
+ else
+ vel_type_out{1}='filter2';
+ end
+else
+ vel_type_out{1}=vel_type;%imposed velocity field
+end
+vel_type_out=vel_type_out';
+
+%determine names of netcdf variables to read
+var={'X','Y','Z','U','V','W','C','F','FF'};
+role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
+units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
+if testder
+ var=[var {'DjUi(:,1,1)','DjUi(:,1,2)','DjUi(:,2,1)','DjUi(:,2,2)'}];
+ role=[role {'tensor','tensor','tensor','tensor'}];
+ units=[units {'pixel','pixel','pixel','pixel'}];
+end
+for ilist=1:length(vel_type_out)
+ var=[var;varname1(vel_type_out{ilist},FieldNames)];
+end
+
+
+%-------------------------
+%determine var names to read
+%--------------------------------------
+function varin=varname1(vel_type,FieldNames)
+
+testder=0;
+C1='';
+C2='';
+for ilist=1:length(FieldNames)
+ if ~isempty(FieldNames{ilist})
+ switch FieldNames{ilist}
+ case 'ima_cor' %image correlation corresponding to a vel vector
+ C1='vec_C';
+ C2='vec2_C';
+ case 'error'
+ C1='vec_E';
+ C2='vec2_E';
+ case {'vort','div','strain'}
+ testder=1;
+ end
+ end
+end
+switch vel_type
+ case 'civ1'
+ varin={'vec_X','vec_Y','vec_Z','vec_U','vec_V','vec_W',C1,'vec_F','vec_FixFlag'};
+ case 'interp1'
+ varin={'vec_patch_X','vec_patch_Y','','vec_patch0_U','vec_patch0_V','','','',''};
+ case 'filter1'
+ varin={'vec_patch_X','vec_patch_Y','','vec_patch_U','vec_patch_V','','','',''};
+ case 'civ2'
+ varin={'vec2_X','vec2_Y','vec2_Z','vec2_U','vec2_V','vec2_W',C2,'vec2_F','vec2_FixFlag'};
+ case 'interp2'
+ varin={'vec2_patch_X','vec2_patch_Y','vec2_patch_Z','vec2_patch0_U','vec2_patch0_V','vec2_patch0_W','','',''};
+ case 'filter2'
+ varin={'vec2_patch_X','vec2_patch_Y','vec2_patch_Z','vec2_patch_U','vec2_patch_V','vec2_patch0_W','','',''};
+end
+if testder
+ switch vel_type
+ case 'filter1'
+ varin=[varin {'vec_patch_DUDX','vec_patch_DVDX','vec_patch_DUDY','vec_patch_DVDY'}];
+ case 'filter2'
+ varin=[varin {'vec2_patch_DUDX','vec2_patch_DVDX','vec2_patch_DUDY','vec2_patch_DVDY'}];
+ end
+end
Index: /trunk/src/read_geometry_calib.m
===================================================================
--- /trunk/src/read_geometry_calib.m (revision 2)
+++ /trunk/src/read_geometry_calib.m (revision 2)
@@ -0,0 +1,51 @@
+%'read_geometry_calib': read data on the GUI geometry_calib
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function data=read_geometry_calib(Coord_cell)
+data_XIma=[];
+data_YIma=[];
+data_XObject=[];
+data_YObject=[];
+data_ZObject=[];
+%Coord=get(handles.ListCoord,'String');
+% XImage=get(handles.XImage,'String');
+% YImage=get(handles.YImage,'String');
+% XObject=get(handles.XObject,'String');
+% YObject=get(handles.YObject,'String');
+% ZObject=get(handles.ZObject,'String');
+% if ischar(Xcolumn)
+% Xcolumn={Xcolumn};
+% end
+nb_defining_points=length(Coord_cell);
+iline=0;
+for i=1:nb_defining_points
+ coord_str=Coord_cell{i};%character string of line number i
+ k=findstr('|',coord_str);%find separators '|'
+ if length(k)>=4 % test for separators '|'
+ data1=str2num(coord_str(1:k(1)-5));
+ data2=str2num(coord_str(k(1)+5:k(2)-5));
+ data3=str2num(coord_str(k(2)+5:k(3)-5));
+ data4=str2num(coord_str(k(3)+5:k(4)-5));
+ data5=str2num(coord_str(k(4)+5:end));
+ if ~isempty(data1)|~isempty(data2)|~isempty(data3)|~isempty(data4)|~isempty(data5)
+ iline=iline+1;
+ if ~isempty(data1)
+ data.Coord(iline,1)=data1;
+ end
+ if ~isempty(data2)
+ data.Coord(iline,2)=data2;
+ end
+ if ~isempty(data3)
+ data.Coord(iline,3)=data3;
+ end
+ if ~isempty(data4)
+ data.Coord(iline,4)=data4;
+ end
+ if isempty(data5)
+ data.Coord(iline,5)=0;
+ else
+ data.Coord(iline,5)=data5;
+ end
+ end
+ end
+end
+data.Style='points';
Index: /trunk/src/read_get_field.m
===================================================================
--- /trunk/src/read_get_field.m (revision 2)
+++ /trunk/src/read_get_field.m (revision 2)
@@ -0,0 +1,743 @@
+%'read_get_field': read the list of selected variables from the GUI get_field (SAME AS THE FIRST
+% INPUT:
+% hget_field: handles of the GUI get_field
+
+function [SubField,errormsg]=read_get_field(hget_field)
+%---------------------------------------------------------
+SubField=[];%default
+errormsg=[]; %default
+handles=guidata(hget_field);%handles of GUI elements in get_field
+Field=get(hget_field,'UserData');% read the current field Structure in the get_field interface
+if isfield(Field,'VarAttribute')
+ VarAttribute=Field.VarAttribute;
+else
+ VarAttribute={};
+end
+
+% select the indices of field variables for 2D plots
+test_1Dplot=get(handles.check_1Dplot,'Value');
+test_scalar=get(handles.check_scalar,'Value');
+test_vector=get(handles.check_vector,'Value');
+
+nbvar=0;
+empty_coord_x=0;
+empty_coord_y=0;
+dimname_y={};
+ListVarName={};
+VarDimName={};
+SubVarAttribute={};
+dim_x=0;
+dim_y=0;
+dim_z=0;
+dim_vec_x=0;
+dim_vec_y=0;
+dim_vec_z=0;
+c_index=[];
+if test_1Dplot
+ % select ordinate variable(s)
+ inputlist=get(handles.ordinate,'String');
+ val=get(handles.ordinate,'Value');% selection(s) for ordinate
+ VarNameCell=inputlist(val); %names of the variable(s) in the list
+ for ilist=1:length(VarNameCell)
+ VarIndex_y(ilist)=name2index(VarNameCell{ilist},Field.ListVarName);%index of the variable in ListVarName
+ dim_ordinate{ilist}=Field.VarDimName{VarIndex_y(ilist)};% name of the corresponding dimension
+% if iscell(dim_ordinate{ilist})
+% dim_ordinate{ilist}=dim_ordinate{ilist}{1};%take the first dimension name (char chain) in case of a matrix
+% end
+ testpermute(ilist)=0;%default
+ nbvar=nbvar+1;
+ ListVarName{nbvar}=Field.ListVarName{VarIndex_y(ilist)};
+ VarDimName{nbvar}=Field.VarDimName{VarIndex_y(ilist)};
+ subvarindex(ilist)=nbvar;
+ if numel(VarAttribute)>=VarIndex_y(ilist)
+ SubVarAttribute{nbvar}=VarAttribute{VarIndex_y(ilist)};
+ end
+ SubVarAttribute{nbvar}.Role='scalar';
+ end
+
+ % select abscissa variable
+ inputlist=get(handles.abscissa,'String');
+ val=get(handles.abscissa,'Value');% a single selection is expected for abscissa
+ VarName=inputlist{val}; %name of the variable in the list
+ VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
+ if isempty(VarIndex)% default abscissa = matrix index
+ coord_x_name=dim_ordinate{1};% name of the x coordinate = dimension of the plotted quantity
+ if iscell(coord_x_name)
+ coord_x_name=coord_x_name{1};
+ end
+ empty_coord_x=1;
+ else
+ dimname_x=Field.VarDimName{VarIndex};
+ if numel(dimname_x)~=1
+ errormsg='abscissa must be a one-dimensional variable';
+ return
+ end
+ nbvar=nbvar+1;
+ ListVarName{nbvar}=Field.ListVarName{VarIndex};
+ VarDimName{nbvar}=Field.VarDimName{VarIndex};
+ if numel(VarAttribute)>=VarIndex
+ SubVarAttribute{nbvar}=VarAttribute{VarIndex};
+ end
+ SubVarAttribute{nbvar}.Role='coord_x';
+ %check consistency of ordinate dimensions
+ for ilist=1:length(VarNameCell)
+ if iscell(dim_ordinate{ilist})
+ if ~strcmp(dim_ordinate{ilist}{1},dimname_x)
+ if strcmp(dim_ordinate{ilist}{2},dimname_x)
+ testpermute(ilist)=1;
+ else
+ errormsg='inconsistent dimensions for ordinate and abscissa';
+ return
+ end
+ end
+ end
+ end
+ end
+end
+
+test3D=strcmp(get(handles.coord_z_scalar,'Visible'),'on')||strcmp(get(handles.coord_z_vectors,'Visible'),'on');
+VarSubIndexA=[];
+
+%scalar variable
+test_xdimvar=0;%default
+test_ydimvar=0;%default
+test_zdimvar=0;%defaul
+dimname_x=[];
+dimname_y=[];
+dimname_z=[];
+if test_scalar
+ inputlist=get(handles.scalar,'String');
+ if isempty(inputlist)
+ errormsg='empty input field';
+ return
+ end
+ val=get(handles.scalar,'Value');%selected indices in the ordinate listbox
+ VarNameScalar=inputlist{val}; %name of the variable in the list
+ VarIndexA=name2index(VarNameScalar,Field.ListVarName);%index of the variable in ListVarName
+ dimname_A=Field.VarDimName{VarIndexA};
+ nbvar=nbvar+1;
+ ListVarName{nbvar}=Field.ListVarName{VarIndexA};
+ VarSubIndexA=nbvar;
+ VarDimName{nbvar}=dimname_A;
+ if numel(VarAttribute)>=VarIndexA
+ SubVarAttribute{nbvar}=VarAttribute{VarIndexA};
+ end
+ SubVarAttribute{nbvar}.Role='scalar';
+ field_var_index=VarIndexA; %store the last variable index to determine the absissa dimension if not defiend
+
+ % select x variable
+ inputlist=get(handles.coord_x_scalar,'String');
+ val=get(handles.coord_x_scalar,'Value');% a single selection is expected for abscissa
+ VarName=inputlist{val}; %name of the variable in the list
+ VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
+ if isempty(VarIndex)% default abscissa = matrix index
+ empty_coord_x=1;
+ else
+ dimname_x=Field.VarDimName{VarIndex};
+ nbvar=nbvar+1;
+ ListVarName{nbvar}=Field.ListVarName{VarIndex};
+ VarDimName{nbvar}=dimname_x;
+ if numel(VarAttribute)>=VarIndex
+ SubVarAttribute{nbvar}=VarAttribute{VarIndex};
+ end
+ %check consistency of dimensions
+ if ~isequal(dimname_x,dimname_A)% case of dimension variables
+ if iscell(dimname_x)
+ if numel(dimname_x)==1
+ dimname_x=dimname_x{1};%transform to char chain
+ else
+ errormsg='invalid x coordinate selection in get_field';
+ return
+ end
+ end
+ test_xdimvar=1;
+ SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
+ else
+ SubVarAttribute{nbvar}.Role='coord_x';%abcissa with unstructured coordinates
+ end
+ end
+
+ % select y variable
+ inputlist=get(handles.coord_y_scalar,'String');
+ val=get(handles.coord_y_scalar,'Value');% a single selection is expected for abscissa
+ VarName=inputlist{val}; %name of the variable in the list
+ VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
+ if isempty(VarIndex)% default abscissa = matrix index
+ empty_coord_y=1;
+ else
+ dimname_y=Field.VarDimName{VarIndex};
+ %check consistency of dimensions
+ nbvar=nbvar+1;
+ ListVarName{nbvar}=Field.ListVarName{VarIndex};
+ VarDimName{nbvar}=dimname_y;
+ if numel(VarAttribute)>=VarIndex
+ SubVarAttribute{nbvar}=VarAttribute{VarIndex};
+ end
+ %check consistency of dimensions
+ if ~isequal(dimname_y,dimname_A)% case of dimension variables
+ if iscell(dimname_y)
+ if numel(dimname_y)==1
+ dimname_y=dimname_y{1};%transform to char chain
+ else
+ errormsg='invalid y coordinate selection in get_field';
+ return
+ end
+ end
+ test_ydimvar=1;
+ SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
+ else
+ SubVarAttribute{nbvar}.Role='coord_y';%abcissa with unstructured coordinates
+ end
+ if isequal(dimname_y,dimname_x)
+ errormsg='identical x and y coordinates selected in get_field';
+ return
+ end
+ end
+
+ % select z variable
+ if test3D % TODO: Lire z comme x et y
+ inputlist=get(handles.coord_z_scalar,'String');
+ val=get(handles.coord_z_scalar,'Value');% a single selection is expected for abscissa
+ VarName=inputlist{val}; %name of the variable in the list
+ VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
+ if isempty(VarIndex)% default abscissa = matrix index
+% coord_z_name=dimname_A{1};% name of the x coordinate = dimension of the plotted quantity
+ empty_coord_z=1;
+ else
+ dimname_z=Field.VarDimName{VarIndex};
+ %check consistency of dimensions
+ if ~isequal(dimname_z,dimname_A)
+ for icoord=1:numel(dimname_A)
+ if strcmp(dimname_z,dimname_A{icoord})% a dimension variable
+ dim_z=icoord;
+ break
+ end
+ end
+ if ~dim_z
+ errormsg='inconsistent dimensions for coordinate z';
+ return
+ end
+ end
+ nbvar=nbvar+1;
+ ListVarName{nbvar}=Field.ListVarName{VarIndex};
+ VarDimName{nbvar}=dimname_z;
+ if numel(VarAttribute)>=VarIndex
+ SubVarAttribute{nbvar}=VarAttribute{VarIndex};
+ end
+ if dim_z
+ SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
+ else
+ SubVarAttribute{nbvar}.Role='coord_z';%z coordinate with unstructured coordinates
+ end
+ end
+ end
+end
+test_vec_x_dimvar=0;%default
+test_vec_y_dimvar=0;%default
+test_vec_z_dimvar=0;%defaul
+dimname_vec_x=[];
+dimname_vec_y=[];
+dimname_vec_z=[];
+if test_vector
+ %select u variable
+ inputlist=get(handles.vector_x,'String');
+ if isempty(inputlist)
+ errormsg='empty input field';
+ return
+ end
+ val=get(handles.vector_x,'Value');%selected indices in the ordinate listbox
+ VarNameU=inputlist{val}; %name of the variable in the list
+ VarIndexU=name2index(VarNameU,Field.ListVarName);%index of the variable in ListVarName
+ nbvar=nbvar+1;
+ VarSubIndexU=nbvar;
+ ListVarName{nbvar}=Field.ListVarName{VarIndexU};
+ dimname_u=Field.VarDimName{VarIndexU};
+ VarDimName{nbvar}=dimname_u;
+ if numel(VarAttribute)>=VarIndexU
+ SubVarAttribute{nbvar}=VarAttribute{VarIndexU};
+ end
+ SubVarAttribute{nbvar}.Role='vector_x';
+ field_var_index=VarIndexU; %store the last variable index to determine the absissa dimension if not defiend
+
+ %scalar v variable
+ inputlist=get(handles.vector_y,'String');
+ val=get(handles.vector_y,'Value');%selected indices in the ordinate listbox
+ VarNameV=inputlist{val}; %name of the variable in the list
+ VarIndexV=name2index(VarNameV,Field.ListVarName);%index of the variable in ListVarName
+ %check consistency of dimensions with u
+ dimname_v=Field.VarDimName{VarIndexV};
+ if ~isequal(dimname_v,dimname_u)
+ errormsg='inconsistent dimensions for u and v';
+ return
+ end
+ nbvar=nbvar+1;
+ VarSubIndexV=nbvar;
+ ListVarName{nbvar}=Field.ListVarName{VarIndexV};
+ VarDimName{nbvar}=dimname_u;
+ if numel(VarAttribute)>=VarIndexV
+ SubVarAttribute{nbvar}=VarAttribute{VarIndexV};
+ end
+ SubVarAttribute{nbvar}.Role='vector_y';
+
+
+ % select x variable for vector
+ inputlist=get(handles.coord_x_vectors,'String');
+ val=get(handles.coord_x_vectors,'Value');% a single selection is expected for abscissa
+ VarName=inputlist{val}; %name of the variable in the list
+ VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
+ if isempty(VarIndex)% default abscissa = matrix indexTODO like scalar
+% coord_x_name=dimname_u{2};% name of the x coordinate = dimension of the plotted quantity
+ empty_coord_vec_x=1;
+ else
+ empty_coord_vec_x=0;
+ dimname_vec_x=Field.VarDimName{VarIndex};
+ nbvar=nbvar+1;
+ ListVarName{nbvar}=Field.ListVarName{VarIndex};
+ VarDimName{nbvar}=dimname_vec_x;
+ if numel(VarAttribute)>=VarIndex
+ SubVarAttribute{nbvar}=VarAttribute{VarIndex};
+ end
+ %check consistency of dimensions
+ if ~isequal(dimname_vec_x,dimname_u)% case of dimension variables
+ if iscell(dimname_vec_x)
+ if numel(dimname_vec_x)==1
+ dimname_vec_x=dimname_vec_x{1};%transform to char chain
+ else
+ errormsg='invalid x coordinate selection in get_field';
+ return
+ end
+ end
+ test_vec_x_dimvar=1;
+ SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
+ else
+ SubVarAttribute{nbvar}.Role='coord_x';%abcissa with unstructured coordinates
+ end
+ end
+
+ % select y variable for vector
+ inputlist=get(handles.coord_y_vectors,'String');
+ val=get(handles.coord_y_vectors,'Value');% a single selection is expected for abscissa
+ VarName=inputlist{val}; %name of the variable in the list
+ VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
+ if isempty(VarIndex)% default abscissa = matrix indexTODO like scalar
+% coord_x_name=dimname_u{2};% name of the x coordinate = dimension of the plotted quantity
+ empty_coord_vec_y=1;
+ else
+ empty_coord_vec_y=0;
+ dimname_vec_y=Field.VarDimName{VarIndex};
+ nbvar=nbvar+1;
+ ListVarName{nbvar}=Field.ListVarName{VarIndex};
+ VarDimName{nbvar}=dimname_vec_y;
+ if numel(VarAttribute)>=VarIndex
+ SubVarAttribute{nbvar}=VarAttribute{VarIndex};
+ end
+ %check consistency of dimensions
+ if ~isequal(dimname_vec_y,dimname_u)% case of dimension variables
+ if iscell(dimname_vec_y)
+ if numel(dimname_vec_y)==1
+ dimname_vec_y=dimname_vec_y{1};%transform to char chain
+ else
+ errormsg='invalid y coordinate selection in get_field';
+ return
+ end
+ end
+ test_vec_y_dimvar=1;
+ SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
+ else
+ SubVarAttribute{nbvar}.Role='coord_y';%abcissa with unstructured coordinates
+ end
+ end
+
+ % select z variable for vector
+ if test3D
+ inputlist=get(handles.coord_z_vectors,'String');
+ val=get(handles.coord_z_vectors,'Value');% a single selection is expected for abscissa
+ VarName=inputlist{val}; %name of the variable in the list
+ VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
+ if isempty(VarIndex)% default abscissa = matrix indexTODO like scalar
+ % coord_x_name=dimname_u{2};% name of the x coordinate = dimension of the plotted quantity
+ empty_coord_vec_z=1;
+ else
+ dimname_vec_z=Field.VarDimName{VarIndex};
+ nbvar=nbvar+1;
+ ListVarName{nbvar}=Field.ListVarName{VarIndex};
+ VarDimName{nbvar}=dimname_vec_z;
+ if numel(VarAttribute)>=VarIndex
+ SubVarAttribute{nbvar}=VarAttribute{VarIndex};
+ end
+ %check consistency of dimensions
+ if ~isequal(dimname_vec_z,dimname_u)% case of dimension variables
+ if iscell(dimname_vec_z)
+ if numel(dimname_vec_z)==1
+ dimname_vec_z=dimname_vec_y{1};%transform to char chain
+ else
+ errormsg='invalid y coordinate selection in get_field';
+ return
+ end
+ end
+ test_vec_z_dimvar=1;
+ SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
+ else
+ SubVarAttribute{nbvar}.Role='coord_z';%abcissa with unstructured coordinates
+ end
+ end
+ end
+
+
+ if test3D % (a revoir)
+ %scalar w variable
+ inputlist=get(handles.vector_z,'String');
+ val=get(handles.vector_z,'Value');%selected indices in the ordinate listbox
+ VarNameW=inputlist{val}; %name of the variable in the list
+ VarIndex=name2index(VarNameW,Field.ListVarName);%index of the variable in ListVarName
+ %check consistency of dimensions with u
+ dimname_w=Field.VarDimName{VarIndex};
+ if ~isequal(dimname_w,dimname_u)
+ errormsg='inconsistent dimensions for u and v';
+ return
+ end
+ nbvar=nbvar+1;
+ w_index=nbvar;
+ ListVarName{nbvar}=Field.ListVarName{VarIndex};
+ VarDimName{nbvar}=dimname_u;
+ if numel(VarAttribute)>=VarIndex
+ SubVarAttribute{nbvar}=VarAttribute{VarIndex};
+ end
+ SubVarAttribute{nbvar}.Role='vector_z';
+ end
+
+ % select color variable
+ inputlist=get(handles.vec_color,'String');
+ val=get(handles.vec_color,'Value');% a single selection is expected for abscissa
+ VarNameC=inputlist{val}; %name of the variable in the list
+ VarIndex=name2index(VarNameC,Field.ListVarName);%index of the variable in ListVarName
+ %check consistency of dimensions with u
+ if ~isempty(VarIndex)
+ if ~isequal(Field.VarDimName{VarIndex},dimname_u)
+ errormsg='inconsistent dimensions for u and v';
+ return
+ end
+ nbvar=nbvar+1;
+ c_index=nbvar;
+ ListVarName{nbvar}=Field.ListVarName{VarIndex};
+ VarDimName{nbvar}=Field.VarDimName{VarIndex};
+ if numel(VarAttribute)>=VarIndex
+ SubVarAttribute{nbvar}=VarAttribute{VarIndex};
+ end
+ SubVarAttribute{nbvar}.Role='scalar';
+ end
+end
+
+% get the input field
+inputfield=get(handles.inputfile,'String');
+if exist(inputfield,'file')% read the input data corresponding to the list of selected varaibles
+ SubField=nc2struct(inputfield,ListVarName);
+else % subfield stored in memory
+ SubField.ListVarName=ListVarName;
+ SubField.VarDimName=VarDimName;
+end
+SubField.ListGlobalAttribute=['InputFile' SubField.ListGlobalAttribute];
+SubField.InputFile=get(handles.inputfile,'String');
+SubField.VarAttribute=SubVarAttribute;
+
+%permute indices if coord_y is not the first matrix index
+if test_scalar
+ VarNameA=Field.ListVarName{VarIndexA};
+ DimCellA=Field.VarDimName{VarIndexA};
+ eval(['npxy=size(SubField.' VarNameA ')'])
+ SingleCellA={};
+ if numel(npxy) < numel(DimCellA)
+ SingleCellA=DimCellA(1:end-numel(npxy));
+ DimCellA=DimCellA(end-numel(npxy)+1:end); %suppress the first singletons) dimensions
+ end
+ ind_single=find(npxy==1);
+ SingleCellA=[SingleCellA DimCellA(ind_single)];
+ ind_select=find(npxy~=1);%look for non singleton dimensions
+ DimCellA=DimCellA(ind_select);
+ npxy=npxy(ind_select);
+ dimA=[];
+ if test_zdimvar%dim_x && dim_y && ~isempty(VarSubIndexA)
+ for icoord=1:numel(SingleCellA)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_z,SingleCellA{icoord})% a singleton dimension
+ errormsg=['the singleton dimension ' dimname_z ' has been selected for z'];
+ return
+ end
+ end
+ for icoord=1:numel(DimCellA)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_z,DimCellA{icoord})% a dimension variable
+ dimA=[dimA icoord];
+ break
+ end
+ end
+ end
+ if test_ydimvar%dim_x && dim_y && ~isempty(VarSubIndexA)
+ for icoord=1:numel(SingleCellA)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_y,SingleCellA{icoord})% a singleton dimension
+ errormsg=['the singleton dimension ' dimname_y ' has been selected for ordiante'];
+ return
+ end
+ end
+ for icoord=1:numel(DimCellA)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_y,DimCellA{icoord})% a dimension variable
+ dimA=[dimA icoord];
+ break
+ end
+ end
+ end
+ if test_xdimvar%dim_x && dim_y && ~isempty(VarSubIndexA)
+ for icoord=1:numel(SingleCellA)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_x,SingleCellA{icoord})% a singleton dimension
+ errormsg=['the singleton dimension ' dimname_x ' has been selected for abscissa'];
+ return
+ end
+ end
+ for icoord=1:numel(DimCellA)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_x,DimCellA{icoord})% a dimension variable
+ dimA=[dimA icoord];
+ break
+ end
+ end
+ end
+ dimextra=(1:numel(DimCellA));
+ dimextra(dimA)=[]; %list of unselected dimension indices
+ DimCellA=DimCellA([dimA dimextra]);
+ eval(['SubField.' VarNameA '=permute(squeeze(SubField.' VarNameA '),[dimA dimextra]);'])
+ SubField.VarDimName{VarSubIndexA}=DimCellA;
+ %add default coord_x and/or coord_y if empty
+ if empty_coord_x || empty_coord_y
+ VarName=Field.ListVarName{field_var_index};
+ DimCell=Field.VarDimName{field_var_index};
+ eval(['npxy=size(SubField.' VarName ')'])
+ if numel(npxy) < numel(DimCell)
+ DimCell=DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions
+ end
+ ind_select=find(npxy~=1) ;%look for non singleton dimensions
+ DimCell=DimCell(ind_select);
+ npxy=npxy(ind_select);
+ testold=0;
+ %old convention; use of coord_1 and Coord_2
+ if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=field_var_index
+ if isfield(Field.VarAttribute{field_var_index},'Coord_2')&& isfield(Field.VarAttribute{field_var_index},'Coord_1')
+ Coord_2=Field.VarAttribute{field_var_index}.Coord_2;
+ Coord_1=Field.VarAttribute{field_var_index}.Coord_1;
+ testold=1;
+ end
+ end
+ if empty_coord_x
+ coord_x_name=DimCell{2};
+ SubField.ListVarName=[{coord_x_name} SubField.ListVarName];
+ SubField.VarDimName=[{coord_x_name} SubField.VarDimName];
+ if testold
+ eval(['SubField.' coord_x_name '=linspace(Coord_2(1),Coord_2(end),npxy(2));'])
+ else
+ eval(['SubField.' coord_x_name '=[0.5 npxy(2)-0.5];'])
+ end
+
+ if ~testold
+ coord_x_attr.units='index';
+ else
+ coord_x_attr.units='cm';
+ end
+ SubField.VarAttribute=[{coord_x_attr} SubField.VarAttribute];
+ end
+ if empty_coord_y
+ coord_y_name=DimCell{1};
+ SubField.ListVarName=[{coord_y_name} SubField.ListVarName];
+ SubField.VarDimName=[{coord_y_name} SubField.VarDimName];
+ if testold
+ eval(['SubField.' coord_y_name '=linspace(Coord_1(1),Coord_1(end),npxy(1));'])
+ else
+ eval(['SubField.' coord_y_name '=[npxy(1)-0.5 0.5];'])
+ end
+ if ~testold
+ coord_y_attr.units='index';
+ else
+ coord_y_attr.units='cm';
+ end
+ SubField.VarAttribute=[{coord_y_attr} SubField.VarAttribute];
+ end
+ end
+end
+
+%permute indices if coord_y is not the first matrix index
+if test_vector
+ VarNameU=Field.ListVarName{VarIndexU};
+ DimCellU=Field.VarDimName{VarIndexU};
+ eval(['npxy=size(SubField.' VarNameU ')'])
+ SingleCellU={};
+ if numel(npxy) < numel(DimCellU)
+ SingleCellU=DimCellU(1:end-numel(npxy));
+ DimCellU=DimCellU(end-numel(npxy)+1:end); %suppress the first singletons) dimensions
+ end
+ ind_single=find(npxy==1);
+ SingleCellU=[SingleCellU DimCellU(ind_single)];
+ ind_select=find(npxy~=1);%look for non singleton dimensions
+ DimCellU=DimCellU(ind_select);
+ npxy=npxy(ind_select);
+ dimU=[];
+ if test_zdimvar%dim_x && dim_y && ~isempty(VarSubIndexA)
+ for icoord=1:numel(SingleCellU)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_vec_z,SingleCellU{icoord})% a singleton dimension
+ errormsg=['the singleton dimension ' dimname_vec_z ' has been selected for z'];
+ return
+ end
+ end
+ for icoord=1:numel(DimCellU)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_vec_z,DimCellU{icoord})% a dimension variable
+ dimU=[dimU icoord];
+ break
+ end
+ end
+ end
+ if test_ydimvar%dim_x && dim_y && ~isempty(VarSubIndexA)
+ for icoord=1:numel(SingleCellU)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_vec_y,SingleCellU{icoord})% a singleton dimension
+ errormsg=['the singleton dimension ' dimname_vec_y ' has been selected for ordinate'];
+ return
+ end
+ end
+ for icoord=1:numel(DimCellU)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_vec_y,DimCellU{icoord})% a dimension variable
+ dimU=[dimU icoord];
+ break
+ end
+ end
+ end
+ if test_xdimvar
+ for icoord=1:numel(SingleCellU)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_x,SingleCellU{icoord})% a singleton dimension
+ errormsg=['the singleton dimension ' dimname_vec_x ' has been selected for abscissa'];
+ return
+ end
+ end
+ for icoord=1:numel(DimCellA)% look for coincidence of dimension with one of the dimensions of the scalar
+ if strcmp(dimname_vec_x,DimCellU{icoord})% a dimension variable
+ dimU=[dimU icoord];
+ break
+ end
+ end
+ end
+ dimextra=(1:numel(DimCellU));
+ dimextra(dimU)=[]; %list of unselected dimension indices
+ DimCellU=DimCellU([dimU dimextra]);
+ eval(['SubField.' VarNameU '=permute(squeeze(SubField.' VarNameU '),[dimU dimextra]);'])
+ eval(['SubField.' VarNameV '=permute(squeeze(SubField.' VarNameV '),[dimU dimextra]);'])
+ SubField.VarDimName{VarSubIndexU}=DimCellU;
+ SubField.VarDimName{VarSubIndexV}=DimCellU;
+
+ %add default coord_x and/or coord_y if empty
+ if empty_coord_vec_x || empty_coord_vec_y
+ VarName=Field.ListVarName{field_var_index};
+ DimCell=Field.VarDimName{field_var_index};
+ eval(['npxy=size(SubField.' VarName ')'])
+ if numel(npxy) < numel(DimCell)
+ DimCell=DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions
+ end
+ ind_select=find(npxy~=1) ;%look for non singleton dimensions
+ DimCell=DimCell(ind_select);
+ npxy=npxy(ind_select);
+ testold=0;
+ %old convention; use of coord_1 and Coord_2
+ if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=field_var_index
+ if isfield(Field.VarAttribute{field_var_index},'Coord_2')&& isfield(Field.VarAttribute{field_var_index},'Coord_1')
+ Coord_2=Field.VarAttribute{field_var_index}.Coord_2;
+ Coord_1=Field.VarAttribute{field_var_index}.Coord_1;
+ testold=1;
+ end
+ end
+ if empty_coord_vec_x
+ coord_x_name=DimCell{2};
+ SubField.ListVarName=[{coord_x_name} SubField.ListVarName];
+ SubField.VarDimName=[{coord_x_name} SubField.VarDimName];
+ if testold
+ eval(['SubField.' coord_x_name '=linspace(Coord_2(1),Coord_2(end),npxy(2));'])
+ else
+ eval(['SubField.' coord_x_name '=[0.5 npxy(2)-0.5];'])
+ end
+
+ if ~testold
+ coord_x_attr.units='index';
+ else
+ coord_x_attr.units='cm';
+ end
+ SubField.VarAttribute=[{coord_x_attr} SubField.VarAttribute];
+ end
+ if empty_coord_vec_y
+ coord_y_name=DimCell{1};
+ SubField.ListVarName=[{coord_y_name} SubField.ListVarName];
+ SubField.VarDimName=[{coord_y_name} SubField.VarDimName];
+ if testold
+ eval(['SubField.' coord_y_name '=linspace(Coord_1(1),Coord_1(end),npxy(1));'])
+ else
+ eval(['SubField.' coord_y_name '=[npxy(1)-0.5 0.5];'])
+ end
+ if ~testold
+ coord_y_attr.units='index';
+ else
+ coord_y_attr.units='cm';
+ end
+ SubField.VarAttribute=[{coord_y_attr} SubField.VarAttribute];
+ end
+ end
+end
+if test_1Dplot
+ for ilist=1:numel(VarIndex_y)
+ VarName=Field.ListVarName{VarIndex_y(ilist)};
+ eval(['npxy=size(SubField.' VarName ');'])
+ ind_select=find(npxy~=1);
+ SubField.VarDimName{subvarindex(ilist)}=SubField.VarDimName{subvarindex(ilist)}(ind_select);
+ eval(['SubField.' VarName '=squeeze(SubField.' VarName ');'])%remove singleton dimensions
+ if testpermute(ilist)
+ eval(['SubField.' VarName '=permute(SubField.' VarName ',[2 1]);'])
+ subvarindex(ilist)
+ SubField.VarDimName{subvarindex(ilist)}
+ SubField.VarDimName{subvarindex(ilist)}=SubField.VarDimName{subvarindex(ilist)}([2 1]);
+ end
+ end
+ if empty_coord_x
+ SubField.ListVarName=[{[coord_x_name '_index']} SubField.ListVarName];
+ SubField.VarDimName=[{coord_x_name } SubField.VarDimName];
+ VarName=Field.ListVarName{VarIndex_y(1)};
+ DimCell=Field.VarDimName{VarIndex_y(1)};
+ eval(['npxy=size(SubField.' VarName ')'])
+ if numel(npxy) < numel(DimCell)
+ DimCell=DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions
+ end
+ ind_select=find(npxy~=1) ;%look for non singleton dimensions
+ DimCell=DimCell(ind_select);
+ npxy=npxy(ind_select);
+ if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=VarIndex_y(1) ...
+ && isfield(Field.VarAttribute{VarIndex_y(1)},'Coord_1')
+ Coord_1=Field.VarAttribute{VarIndex_y(1)}.Coord_1;%old convention; use of coord_1
+ eval(['SubField.' coord_x_name '_index=linspace(Coord_1(1),Coord_1(end),npxy(1));'])
+ else
+ eval(['SubField.' coord_x_name '_index=linspace(0.5,npxy(1)-0.5,npxy(1));'])
+ end
+ struct.Role='coord_x';
+ SubField.VarAttribute=[{struct} SubField.VarAttribute];
+ end
+end
+
+%-------------------------------------------------
+% give index numbers of the strings str in the list ListvarName
+function VarIndex_y=name2index(cell_str,ListVarName)
+VarIndex_y=[];
+if ischar(cell_str)
+ for ivar=1:length(ListVarName)
+ varlist=ListVarName{ivar};
+ if isequal(varlist,cell_str)
+ VarIndex_y= ivar;
+ break
+ end
+ end
+elseif iscell(cell_str)
+ for isel=1:length(cell_str)
+ varsel=cell_str{isel};
+ for ivar=1:length(ListVarName)
+ varlist=ListVarName{ivar};
+ if isequal(varlist,varsel)
+ VarIndex_y=[VarIndex_y ivar];
+ end
+ end
+ end
+end
Index: /trunk/src/read_imadoc.m
===================================================================
--- /trunk/src/read_imadoc.m (revision 2)
+++ /trunk/src/read_imadoc.m (revision 2)
@@ -0,0 +1,243 @@
+%'read_imadoc': reads the xml file for image documentation, OBSOLETE: replaced by imadoc2struct
+%
+%function [error,Heading,nom_type_ima,ext_ima,abs_time,TimeUnit,mode,NbSlice,npx,npy,GeometryCalib]=read_imadoc(filecivxml,testime)
+%--------------------------------------------------------
+% OUTPUT:
+%error= 0: all right
+% 2: input file not found
+% 1: input file is not an image documentation file 'ImaDoc'
+% 1.1: 'ImaDoc/Heading' element absent
+% 1.2: 'ImaDoc/Camera' element absent
+% 1.21: 'ImaDoc/Camera/BurstTiming' absent
+% 1.211: 'ImaDoc/Camera/BurstTiming/FrameFrequency' absent
+% 1.212: 'ImaDoc/Camera/BurstTiming/Time' absent
+%
+% INPUT:
+% filecivxml: full name of the xml input file
+% testime=1 read the list of times), =0 (default) do not read it to save computing time
+%
+% -- TODO: should be replaced by xml2struct --
+
+function [error,Heading,nom_type_ima,ext_ima,abs_time,TimeUnit,mode,NbSlice,npx,npy,GeometryCalib]=read_imadoc(filecivxml,testime)
+% global t
+error=0;%default
+Heading=[];%default
+nom_type_ima=[];%default
+ext_ima=[];%default
+abs_time=[];%initiation
+TimeUnit='s'; %default
+% GeometryCalib.CoordUnit='cm';%default
+mode=[]; %default
+NbSlice=1;%default
+npx=[];%default
+npy=[];%default
+% GeometryCalib.Pxcmx=1;
+% GeometryCalib.Pxcmy=1;
+GeometryCalib=[];
+NbDtj=1;
+tsai=[];%default
+if ~exist('testime','var')
+ testime=1;%default
+end
+if exist(filecivxml,'file')~=2, error=2, return;end;%input file does not exist
+filecivxml;
+t=xmltree(filecivxml);
+uid_root=find(t,'/ImaDoc');
+if isempty(uid_root), error=1; return; end;%not an ImaDoc .xml file
+%Heading
+uid_Heading=find(t,'/ImaDoc/Heading');
+if isempty(uid_Heading),
+ error=1.1;
+else
+ uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
+ uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
+ uid_Device=find(t,'/ImaDoc/Heading/Device');
+ uid_Record=find(t,'/ImaDoc/Heading/Record');
+ uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
+ Heading.Campaign=get(t,children(t,uid_Campaign),'value');
+ Heading.Experiment=get(t,children(t,uid_Exp),'value');
+ Heading.Device=get(t,children(t,uid_Device),'value');
+ if ~isempty(uid_Record)
+ Heading.Record=get(t,children(t,uid_Record),'value');
+ end
+ Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
+ FirstImage=Heading.ImageName;
+ if ~isempty(FirstImage)
+ [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type_ima]=name2display(FirstImage);
+ end
+end
+%Camera
+uid_Camera=find(t,'/ImaDoc/Camera');
+if isempty(uid_Camera)
+ error=1.2;
+else
+ uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
+ if ~isempty(uid_ImageSize);
+ ImageSize=get(t,children(t,uid_ImageSize),'value');
+ xindex=findstr(ImageSize,'x');
+ if length(xindex)>=2
+ npx=str2num(ImageSize(1:xindex(1)-1));
+ npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
+ end
+ end
+ uid_NbSlice=find(t,'/ImaDoc/Camera/NbSlice');
+ if ~isempty(uid_NbSlice)
+ NbSlice=str2num(get(t,children(t,uid_NbSlice),'value'));
+ if isempty(NbSlice),NbSlice=1;end; %default
+ end
+ uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
+ if ~isempty(uid_TimeUnit)
+ TimeUnit=get(t,children(t,uid_TimeUnit),'value');
+ if isempty(TimeUnit),TimeUnit='s';end; %default
+ end
+ uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
+ if isempty(uid_BurstTiming), error=1.12,return,end;
+ if testime
+ for k=1:length(uid_BurstTiming)
+ Dtj=[];%default
+ NbDtj=1;%default
+ subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
+ uid_FrameFrequency=find(subt,'/BurstTiming/FrameFrequency');
+ % if isempty(uid_FrameFrequency), error=1.211,return;
+ if isempty(uid_FrameFrequency),
+ Frequency=1;
+ else
+ Frequency=str2num(get(subt,children(subt,uid_FrameFrequency),'value'));
+ end
+ uid_Dtj=find(subt,'/BurstTiming/Dtj');
+ uid_NbDtj=find(subt,'/BurstTiming/NbDtj');
+ uid_Dti=find(subt,'/BurstTiming/Dti');%new
+ uid_NbDti=find(subt,'/BurstTiming/NbDti');%new
+ if ~isempty(uid_Dtj)
+ Dtj=str2num(get(subt,children(subt,uid_Dtj),'value'));%time intervals in frames
+ end
+ uid_child=children(subt,uid_NbDtj);
+ for ivalue=1:length(uid_child)
+ if isequal(get(subt,uid_child(ivalue),'type'),'chardata')
+ NbDtj=str2num(get(subt,uid_child(ivalue),'value'));%nbre of intervals Dtj
+ end
+ end
+ if isempty(uid_Dti)|isempty(uid_NbDti)
+ Dti=[]; %default
+ else
+ Dti=str2num(get(subt,children(subt,uid_Dti),'value'));%time intervals in frames
+ uid_child=children(subt,uid_NbDti);
+ for ivalue=1:length(uid_child)
+ if isequal(get(subt,uid_child(ivalue),'type'),'chardata')
+ NbDti=str2num(get(subt,uid_child(ivalue),'value'));%nbre of intervals Dti
+ end
+ end
+ end
+ if ~isempty(Dtj)
+ Dtj=reshape(Dtj'*ones(1,NbDtj),1,length(Dtj)*NbDtj);
+ end
+ Dtj=[0 Dtj];
+ dtunit=Dtj/Frequency;
+ uid_Time=find(subt,'/BurstTiming/Time');
+ if isempty(uid_Time)
+ error=1.212;
+ else
+ nbfield=length(uid_Time);
+ Time=get(subt,children(subt,uid_Time),'value');
+ abstime_read=str2num(char(Time))*ones(1,length(Dtj))+ones(nbfield,1)*cumsum(dtunit);
+ abs_time=[abs_time;abstime_read];
+ if ~isempty(Dti)&size(abs_time,1)==1
+ abs_time=ones(NbDti+1,1)*abs_time+(Dti/Frequency)*[0:NbDti]'*ones(size(abs_time));
+ end
+ end
+ end
+ end
+end
+% if isempty(abs_time)
+% abs_time=0;%default
+% end
+%read calibration
+uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
+if ~isempty(uid_GeometryCalib)
+ if length(uid_GeometryCalib)>1
+ errordlg(['More than one GeometryCalib in ' filecivxml])
+ return
+ end
+ subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
+ cont=get(subt,1,'contents');
+ if ~isempty(cont)
+ uid_pixcmx=find(subt,'/GeometryCalib/Pxcmx');
+ uid_pixcmy=find(subt,'/GeometryCalib/Pxcmy');
+ if ~isempty(uid_pixcmx) & ~isempty(uid_pixcmy)%NON UTILISE
+ pixcmx=str2num(get(subt,children(subt,uid_pixcmx),'value'));
+ if isempty(pixcmx),pixcmx=1;end; %default
+ pixcmy=str2num(get(subt,children(subt,uid_pixcmy),'value'));
+ if isempty(pixcmy),pixcmy=1;end; %default
+ tsai.Pxcmx=pixcmx;
+ tsai.Pxcmy=pixcmy;
+ end
+ %default values:
+ tsai.f=1;
+ tsai.dpx=1;
+ tsai.dpy=1;
+ tsai.sx=1;
+ tsai.Cx=0;
+ tsai.Cy=0;
+ tsai.Tz=1;
+ tsai.Tx=0;
+ tsai.Ty=0;
+ tsai.R=[1 0 0; 0 1 0; 0 0 0];
+ tsai.kappa1=0;
+ uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
+ if ~isempty(uid_CoordUnit)
+ tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
+ end
+ uid_focal=find(subt,'/GeometryCalib/focal');
+ uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
+ uid_sx=find(subt,'/GeometryCalib/sx');
+ uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
+ uid_kappa1=find(subt,'/GeometryCalib/kappa1');
+ uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
+ uid_R=find(subt,'/GeometryCalib/R');
+ if ~isempty(uid_focal) & ~isempty(uid_dpx_dpy) & ~isempty(uid_Cx_Cy)
+ tsai.f=str2num(get(subt,children(subt,uid_focal),'value'));
+ dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
+ tsai.dpx=dpx_dpy(1);
+ tsai.dpy=dpx_dpy(2);
+ if ~isempty(uid_sx)
+ tsai.sx=str2num(get(subt,children(subt,uid_sx),'value'));
+ end
+ Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
+ tsai.Cx=Cx_Cy(1);
+ tsai.Cy=Cx_Cy(2);
+ end
+ if ~isempty(uid_Tx_Ty_Tz)
+ Tx_Ty_T_char=get(subt,children(subt,uid_Tx_Ty_Tz),'value');
+% if ~ischar(Tx_Ty_T_char)
+% error='multiple values for Tx_Ty_Tz';
+% else
+ Tx_Ty_Tz=str2num(Tx_Ty_T_char);
+% end
+ tsai.Tx=Tx_Ty_Tz(1);
+ tsai.Ty=Tx_Ty_Tz(2);
+ tsai.Tz=Tx_Ty_Tz(3);
+ end
+ if ~isempty(uid_R)
+ RR=get(subt,children(subt,uid_R),'value');
+ if length(RR)==3
+ tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
+ end
+ end
+ if ~isempty(uid_kappa1)
+ tsai.kappa1=str2num(get(subt,children(subt,uid_kappa1),'value'));
+ end
+ %look for laser plane definitions
+ uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
+ uid_Pos=find(subt,'/GeometryCalib/PlanePos');
+ if ~isempty(uid_Angle)
+ tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
+ end
+ if ~isempty(uid_Pos)
+ for j=1:length(uid_Pos)
+ tsai.PlanePos(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
+ end
+ end
+ GeometryCalib=tsai;
+ end
+end
+
Index: /trunk/src/read_image.m
===================================================================
--- /trunk/src/read_image.m (revision 2)
+++ /trunk/src/read_image.m (revision 2)
@@ -0,0 +1,36 @@
+%'read_image': reads an image from a single file or a movie file
+function [A,error]=read_image(filename,NomType,num);
+ %read images in different formats.
+A=[]; %default
+error=0; %default
+if ~exist(filename,'file')
+ error='input file not found in read_image'
+ return
+end
+testframe=0;
+if ~exist('NomType','var')
+ NomType=[];
+end
+if ~exist('num','var')
+ num=1;
+end
+[pth,fl,ext]=fileparts(filename);
+if isequal(lower(ext),'.avi')
+ mov=aviread(filename,num);
+ A=frame2im(mov(1));
+elseif isequal(lower(ext),'.vol')
+ A=imread(filename);
+else
+ form=imformats(ext([2:end]));
+ if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
+ if isequal(NomType,'*');
+ A=imread(filename,num);
+ else
+ A=imread(filename);
+ end
+ else
+ error=['ERROR in read_image: file extension not recognized by matlab as image'];
+ return
+ end
+end
+
Index: /trunk/src/read_imatext.m
===================================================================
--- /trunk/src/read_imatext.m (revision 2)
+++ /trunk/src/read_imatext.m (revision 2)
@@ -0,0 +1,30 @@
+%'read_imatext': reads the .civ file for image documentation (obsolete)
+% fileinput: name of the documentation file
+% time: matrix of times for the set of images
+%pxcmx: scale along x in pixels/cm
+%pxcmy: scale along y in pixels/cm
+function [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext(fileinput);
+error=0;%default
+time=[]; %default
+TimeUnit='s';
+mode='pairs';
+npx=[]; %default
+npy=[]; %default
+pxcmx=1;%default
+pxcmy=1;%default
+if exist(fileinput,'file')~=2, error=2, return;end;%input file does not exist
+dotciv=textread(fileinput);
+sizdot=size(dotciv);
+if ~isequal(sizdot(1)-8,dotciv(1,1));
+ error=1; %inconsistent number of bursts
+end
+nbfield=sizdot(1)-8;
+npx=(dotciv(2,1));
+npy=(dotciv(2,2));
+pxcmx=(dotciv(6,1));% pixels/cm in the .civ file
+pxcmy=(dotciv(6,2));
+% nburst=dotciv(3,1); % nbre of bursts
+abs_time1=dotciv([9:nbfield+8],2);
+dtime=dotciv(5,1)*(dotciv([9:nbfield+8],[3:end-1])+1);
+timeshift=[abs_time1 dtime];
+time=cumsum(timeshift,2);
Index: /trunk/src/read_plot_param.m
===================================================================
--- /trunk/src/read_plot_param.m (revision 2)
+++ /trunk/src/read_plot_param.m (revision 2)
@@ -0,0 +1,52 @@
+%'read_plot_param': read plotting parameters from the interface uvmat
+%------------------------------------------
+% function PlotParam=read_plot_param(handles)
+%
+% OUTPUT:
+% PlotParam: structure containing the values of all the relevant plotting parameters
+%
+% INPUT:
+% handles: structure containing the handles of the relevant uicontrols in the uvmat interface
+%
+% -- TODO: get the handles using get_plot_handles and findobj as default input --
+
+function PlotParam=read_plot_param(handles)
+
+PlotParam.Auto_xy=get(handles.auto_xy,'Value');
+
+% scalars
+Scalar.MaxA=str2double(get(handles.MaxA,'String'));
+Scalar.MinA=str2double(get(handles.MinA,'String'));
+Scalar.AutoScal=get(handles.AutoScal,'Value');
+Scalar.BW=get(handles.BW,'Value');
+Scalar.Contours=get(handles.Contours,'Value')==2;
+Scalar.IncrA=str2double(get(handles.IncrA,'String'));
+PlotParam.Scalar=Scalar;
+
+%vectors
+Vectors.VecScale=str2double(get(handles.VecScale,'String'));
+Vectors.AutoVec=get(handles.AutoVec,'Value');%automatic vector length
+Vectors.HideFalse=get(handles.HideFalse,'Value');
+Vectors.HideWarning=get(handles.HideWarning,'Value');
+Vectors.decimate4=get(handles.decimate4,'Value');% =1; for reducing the nbre of vectors
+
+%vector color
+code_list=get(handles.color_code,'String');
+val=get(handles.color_code,'Value');
+% menu_col=get(handles.col_vec,'String');
+% menu_val=get(handles.col_vec,'Value');
+colcode1=str2double(get(handles.colcode1,'String'));% first threshold for rgb, first value for'continuous'
+colcode2=str2double(get(handles.colcode2,'String'));% second threshold for rgb, last value (saturation) for 'continuous'
+
+Vectors.ColorCode=code_list{val}; % option of color code for vectors
+Vectors.FixedCbounds=get(handles.AutoVecColor,'Value');% =1; fixed scale for color vector, =0 otherwise (default)
+Vectors.MinC=str2num(get(handles.min_vec,'String')); % imposed min of C, (needed if .FixedCbounds=1)
+Vectors.MaxC=str2num(get(handles.max_vec,'String')); % imposed max of C, needed if .FixedCbounds=1
+if Vectors.MaxC <= Vectors.MinC
+ Vectors.ColorCode='black';
+else
+ Vectors.colcode1=Vectors.MinC+(colcode1-Vectors.MinC)/(Vectors.MaxC-Vectors.MinC);% relative thresholds
+ Vectors.colcode2=Vectors.MinC+(colcode2-Vectors.MinC)/(Vectors.MaxC-Vectors.MinC);
+end
+PlotParam.Vectors=Vectors;
+
Index: /trunk/src/read_set_object.m
===================================================================
--- /trunk/src/read_set_object.m (revision 2)
+++ /trunk/src/read_set_object.m (revision 2)
@@ -0,0 +1,210 @@
+%'read_set_object': read the data on the 'set_object' interface
+%--------------------------------------------------------
+% data=read_set_object(handles)
+%--------------------------------------------------------
+%OUTPUT
+%data: structure of data read on the set_object interface
+% .Style : style of projection object
+% .Coord(nbpos,3): set of coordinates defining the object position;
+% .ProjMode=type of projection ;
+% .Phi=angle of projection;
+% .DX,.DY,.DZ=increments;
+% .YMax,YMin: min and max Y
+%INPUT:
+% handles: structure describing the tags of the edit boxes and menus
+function data=read_set_object(handles)
+%menus
+if isfield(handles,'ObjectStyle')%case of the set_object interface
+ menu=get(handles.ObjectStyle,'String');
+ value=get(handles.ObjectStyle,'Value');
+ data.Style=menu{value};
+ menu=get(handles.ProjMode,'String');
+ value=get(handles.ProjMode,'Value');
+ data.ProjMode=menu{value};
+ menu=get(handles.MenuCoord,'String');
+ value=get(handles.MenuCoord,'Value');
+ data.CoordType=menu{value};
+ testcalib=0;
+else %default
+ data.Style='points';
+ testcalib=1;
+end
+
+%Euler angles and projection ranges
+if ~testcalib
+ if isequal(get(handles.Phi,'Visible'),'on')
+ data.Phi=str2num(get(handles.Phi,'String'));
+ end
+ if isequal(get(handles.Theta,'Visible'),'on')
+ data.Theta=str2num(get(handles.Theta,'String'));
+ end
+ if isequal(get(handles.Psi,'Visible'),'on')
+ data.Psi=str2num(get(handles.Psi,'String'));
+ end
+ if isequal(get(handles.DX,'Visible'),'on')
+ data.DX=str2num(get(handles.DX,'String'));
+ end
+ if isequal(get(handles.DY,'Visible'),'on')
+ data.DY=str2num(get(handles.DY,'String'));
+ end
+ if isequal(get(handles.DZ,'Visible'),'on')
+ data.DZ=str2num(get(handles.DZ,'String'));
+ end
+ dimrange=[1 1];%default
+ if isequal(get(handles.ZMin,'Visible'),'on')
+ ZMin=str2num(get(handles.ZMin,'String'));
+ if ~isempty(ZMin)
+ data.RangeZ(1)=ZMin;
+ dimrange=[2 3];
+ end
+ end
+ if isequal(get(handles.ZMax,'Visible'),'on')
+ ZMax=str2num(get(handles.ZMax,'String'));
+ if isempty(ZMax)
+ if dimrange(1)>1
+% set(handles.ZMax,'String',get(handles.ZMin,'String'))
+ data.RangeZ(1)=ZMax;
+ end
+ else
+ data.RangeZ=ZMax;
+ dimrange=[dimrange(1) 3];
+ end
+ end
+ if isequal(get(handles.YMin,'Visible'),'on')
+ YMin=str2num(get(handles.YMin,'String'));
+ if isempty(YMin)
+% if dimrange(2)>2
+% % set(handles.YMin,'String','0')
+% data.RangeY(2)=0;
+% end
+ else
+ data.RangeY(2)=YMin;
+ dimrange=[2 max(dimrange(2),2)];
+ end
+ end
+ if isequal(get(handles.YMax,'Visible'),'on')
+% data.YMax=str2num(get(handles.YMax,'String'));
+ YMax=str2num(get(handles.YMax,'String'));
+ if isempty(YMax)
+% if dimrange(1)>1
+% % set(handles.YMax,'String',get(handles.YMin,'String'))
+% if ~isempty(YMin)
+% data.RangeY(1)=YMin;
+% end
+% elseif dimrange(2)>2
+% % set(handles.YMax,'String',get(handles.ZMin,'String'))
+% data.RangeY(2)=ZMin;
+% end
+ else
+ data.RangeY(1)=YMax;
+ dimrange=[dimrange(1) max(dimrange(2),2)];
+ end
+ end
+ if isequal(get(handles.XMin,'Visible'),'on')
+ XMin=str2num(get(handles.XMin,'String'));
+ if isempty(XMin)
+% if ~isempty(YMin)
+% if dimrange(2)>1
+% % set(handles.XMin,'String',get(handles.YMin,'String'))
+% data.RangeX(2)=YMin;
+% XMin=YMin;
+% end
+% end
+ else
+ data.RangeX(2)=XMin;
+ %dimrange=[2 max(dimrange(2),1)];
+ end
+ end
+ if isequal(get(handles.XMax,'Visible'),'on')
+ XMax=str2num(get(handles.XMax,'String'));
+ if isempty(XMax)
+% if dimrange(1)>1
+% % set(handles.XMax,'String',get(handles.XMin,'String'))
+% if ~isempty(XMin)
+% data.RangeX(2)=XMin;
+% end
+% elseif dimrange(2)>1
+% % set(handles.XMax,'String',get(handles.YMax,'String'))
+% data.RangeX(1)=YMax;
+% end
+ else
+ data.RangeX(1)=XMax;
+ end
+ end
+end
+
+
+%positions x,y,z
+Xcolumn=get(handles.XObject,'String');
+Ycolumn=get(handles.YObject,'String');
+if ischar(Xcolumn)
+ sizchar=size(Xcolumn);
+ for icol=1:sizchar(1)
+ Xcolumn_cell{icol}=Xcolumn(icol,:);
+ end
+ Xcolumn=Xcolumn_cell;
+end
+if ischar(Ycolumn)
+ sizchar=size(Ycolumn);
+ for icol=1:sizchar(1)
+ Ycolumn_cell{icol}=Ycolumn(icol,:);
+ end
+ Ycolumn=Ycolumn_cell;
+end
+Zcolumn={};%default
+if isequal(get(handles.ZObject,'Visible'),'on')
+ data.NbDim=3; %test 3D object
+ Zcolumn=get(handles.ZObject,'String');
+ if ischar(Zcolumn)
+ Zcolumn={Zcolumn};
+ end
+end
+nb_points=min(length(Xcolumn),length(Ycolumn));%number of point positions needed to define the object position
+if isequal (data.Style,'line');
+ nb_defining_points=2;
+elseif isequal(data.Style,'plane')|isequal(data.Style,'rectangle')|isequal(data.Style,'ellipse')
+ nb_defining_points=1;
+else
+ nb_defining_points=nb_points;
+end
+data_XObject=[];
+data_YObject=[];
+data_ZObject=[];
+for i=1:nb_points
+ Xnumber=str2num(Xcolumn{i});
+ Ynumber=str2num(Ycolumn{i});
+ if isempty(Xnumber)|isempty(Ynumber)
+ break
+ else
+ data_XObject=[data_XObject; Xnumber(1)];
+ data_YObject=[data_YObject; Ynumber(1)];
+ end
+ if length(Zcolumn) nb_points
+ for i=nb_points+1:nb_defining_points
+ data_XObject=[0;data_XObject];
+ data_YObject=[0;data_YObject];
+ data_ZObject=[0;data_ZObject];
+ end
+end
+if isempty(data_XObject)
+ data_XObject=0;
+end
+if isempty(data_YObject)
+ data_YObject=0;
+end
+if isempty(data_ZObject)
+ data_ZObject=0;
+end
+data.Coord=[data_XObject data_YObject data_ZObject];
+
+set(handles.XObject,'String',mat2cell(data_XObject,length(data_XObject)))%correct the interface display
+set(handles.YObject,'String',mat2cell(data_YObject,length(data_XObject)))
+set(handles.ZObject,'String',mat2cell(data_ZObject,length(data_XObject)))
+
+
Index: /trunk/src/read_xls.m
===================================================================
--- /trunk/src/read_xls.m (revision 2)
+++ /trunk/src/read_xls.m (revision 2)
@@ -0,0 +1,328 @@
+%'read_xls': function for reading and displaying Excel files
+%------------------------------------------------------------------------
+% function [hfig_xls]=read_xls(fileinput,hfig)
+%
+% OUTPUT:
+% hfig_xls: figure handle for display
+%
+% INPUT:
+% fileinput: name of the input file (char string)
+% hfig: handle of the display figure (a new display figure hfig_xls is created if hfig undefined)
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function [hfig_xls]=read_xls(fileinput,hfig)
+[Tabnum,Tabtext]=xlsread(fileinput);
+ [textnx,textny]=size(Tabtext);
+ [numnx,numny]=size(Tabnum);
+ ilastxt=textnx-numnx;%index of last text row
+ jlastxt=textny-numny;%index of last text column
+ for jtab=1:textny%read line
+ for itab=1:textnx% read column
+ textlu=cell2mat(Tabtext(itab,jtab));
+ if isequal(textlu,[])& itab > ilastxt & jtab > jlastxt %replace txt by number
+ textlu=num2str(Tabnum(itab-ilastxt,jtab-jlastxt));
+ end
+ Tabdisplay(itab,jtab)={textlu};
+ lengthtext(itab)=length(textlu);
+ end
+ widthcolumn(jtab)=max(lengthtext);
+ end
+ Tabchar={};%default
+ for itab=1:textnx %justify table
+ charchain=[];
+ for jtab=1:textny% read line
+ textlu=Tabdisplay{itab,jtab};
+ if widthcolumn(jtab)>length(textlu)
+ blankstr=char(46*ones(1,widthcolumn(jtab)-length(textlu)));
+ textlu=[textlu blankstr ];
+ end
+ charchain=[charchain textlu char(9) ' | '];
+ end
+ Tabchar(itab)={charchain};
+ end
+ if exist('hfig','var') & ishandle(hfig)
+ figure(hfig);
+ hfig_xls=hfig;
+ else
+ hfig_xls=figure;
+ end
+ set(hfig_xls,'Name',fileinput)
+ set(hfig_xls,'MenuBar','none')
+ hpos=get(hfig_xls,'Pos');
+ ExpName.cell=Tabtext([2:textnx],1);%first column (dir name)
+ ExpName.Num=Tabnum;
+% ExpName.Units=Tabtext(2,[2:textny]);%look for the units line (needs to be the second line)
+ iparam=0;
+ for icol=2:textny
+% Tabtext(2,icol)
+ if ~isempty(Tabtext{2,icol})&~isequal(Tabtext{2,icol},'')
+ iparam=iparam+1;
+ ExpName.Param{iparam}=Tabtext{1,icol};
+ ExpName.Units{iparam}=Tabtext{2,icol};
+ ExpName.Column(iparam)=icol;
+ end
+ end
+
+ ExpName.path=fileparts(fileinput);
+ h=uicontrol('Style','listbox', 'Position', [5 5 0.9*hpos(3) 0.9*hpos(4)], 'String', Tabchar, ...
+ 'FontName','Monospaced','Callback',@link2file,'UserData',ExpName,'Tag','listbox');
+% hh=uicontrol('Style','Pushbutton', 'Position', [0.93*hpos(1) 0.93*hpos(2) 0.05*hpos(3) 0.05*hpos(4)], 'String', 'Update','Callback',@project_update);
+% set(h,'HorizontalAlignment','left')
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%called by xlsdisplay to navigate from a .xls file or create the
+% the experiment directories
+function link2file(obj,event,fileinput)
+global t
+bla=get(gcbo,'String');
+ind=get(gcbo,'Value')
+if (ind==1|ind==2),return,end; %no action on the first line
+ExpNameStruct=get(gcbo,'UserData')
+ExpName=ExpNameStruct.cell{ind-1}
+ProjectFullName=ExpNameStruct.path;%full name of the project (including path)
+[Pth,ProjectName]=fileparts(ProjectFullName);
+ExpPath=fullfile(ProjectFullName,ExpName);% full name of the experiment directory
+ExpDocName=fullfile(ExpPath,[ExpName '.xml']);% full name of the .xml file ExpDoc
+if exist(ExpDocName,'file')
+ hh=editxml({ExpDocName})
+% [FileName, PathName, filterindex] = uigetfile( ...
+% {'*.xml','(*.xml)';
+% '*.xml', '.xml files ';
+% '*.*', 'All Files (*.*)'}, ...
+% 'Pick a file',ExpDocName);
+% fileinput=[PathName FileName];%complete file name
+% sizf=size(fileinput);
+% if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
+% [path,name,ext]=fileparts(fileinput);
+% if isequal(ext,'.civ') | isequal(ext,'.log') | isequal(ext,'.cmx') isequal(ext,'.txt')
+% edit(fileinput)
+% elseif isequal(ext,'.xml')
+% varargin{1}=fileinput;
+% editxml(varargin)
+% elseif isequal(ext,'.fig')
+% open(fileinput)
+% elseif isequal(ext,'.xls')
+% xlsdisplay(fileinput)
+% else
+% uvmat({fileinput})
+% end
+else
+ answer=questdlg({['ExpDoc file ' ExpDocName ' does not exist, create the experiment?'];''})
+ if isequal(answer,'Yes')
+ if exist(ExpPath,'dir')~=7 %create a directory if it does not exist
+ dircur=pwd; %current working directory
+ cd(ProjectFullName);
+ [m1,m2,m3]=mkdir(ExpName);
+ cd(pwd);%come back to the initial working dir
+ end
+% %copy exp parameters
+ ParamNames=ExpNameStruct.Param;
+ ParamValues=ExpNameStruct.Num(ind-1,ExpNameStruct.Column-1);
+ ParamUnits=ExpNameStruct.Units;
+ t=xmltree;%new xmltree
+ t=set(t,1,'name','ExpDoc');
+ t=attributes(t,'add',1,'xmlns:xsi','none');
+ [t,ExpElement]=add(t,1,'element','Exp');
+ [t]=add(t,ExpElement,'chardata',ExpName);
+ for iparam=1:length(ParamNames)
+ [t,ParamElement]=add(t,1,'element',ParamNames{iparam});
+ t=add(t,ParamElement,'chardata',num2str(ParamValues(iparam)));
+ t=attributes(t,'add',ParamElement,'unit',ParamUnits{iparam}); %ADD UNIT ATTRIBUTE
+ end
+ list_dir=dir(ExpPath);%list of the Exp directory, detect sub-directories,.xml and image files
+ nbdir_exp=0;
+ %scan the Exp directory
+ for idir_exp=3:length(list_dir)
+ %detect subdirectories
+ if list_dir(idir_exp).isdir% 'device' subdirectories
+ nbdir_exp=nbdir_exp+1;
+ ExpData.Device{nbdir_exp}=list_dir(idir_exp).name;
+ [t,DeviceElement]=add(t,1,'element',list_dir(idir_exp).name);
+ t=attributes(t,'add',DeviceElement,'type','DEVICE_DIR');
+ t=attributes(t,'add',DeviceElement,'source','dir');
+ list_subdir=dir(fullfile(ExpPath,list_dir(idir_exp).name));
+ nbsubdir=0;
+ testrecord=1;
+ RootIma='';
+ RootNc='';
+ nbfile=0;
+% nbfile={};
+ %scan the Device subdirectory
+ for isubdir=3:length(list_subdir)
+ if list_subdir(isubdir).isdir
+ nbsubdir=nbsubdir+1;
+ Device.Record{nbsubdir}=list_subdir(isubdir).name;
+ else
+ nbfile=nbfile+1;
+ fname{nbfile}=list_subdir(isubdir).name;
+ end
+ end
+ if isunix%sort by root names and indices , change the separator '_' so that 1_1 come as the first name
+ fname_mod=regexprep(fname,'_','/');
+ fname_mod=sort(fname_mod); %sort by name
+ fname=regexprep(fname_mod,'/','_');
+ end
+ for ifile=1:nbfile;
+ [Path,Name,Ext]=fileparts(fname{ifile});
+ if isequal(Ext,'.xml')
+ [t,ImaDocElement]=add(t,DeviceElement,'element','ImaDoc');
+ t=add(t,ImaDocElement,'chardata',fname{ifile});
+ t=attributes(t,'add',ImaDocElement,'source','file');
+ testrecord=0;%we have an image series without 'record' subdir
+ elseif isequal(Ext,'.png')
+ [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
+ if ~isequal(Root,RootIma)%only one image recorded for each root name
+ [t,ImaDocElement]=add(t,DeviceElement,'element','Image');
+ t=add(t,ImaDocElement,'chardata',fname{ifile});
+ t=attributes(t,'add',ImaDocElement,'source','file');
+ RootIma=Root;
+ end
+ testrecord=0;%we have an image series without 'record' subdir
+ elseif isequal(Ext,'.nc')
+ [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
+ if ~isequal(Root,RootNc)%only one image recorded for each root name
+ [t,ImaDocElement]=add(t,DeviceElement,'element','Ncdata');
+ t=add(t,ImaDocElement,'chardata',fname{ifile});
+ t=attributes(t,'add',ImaDocElement,'source','file');
+ RootNc=Root;
+ end
+ testrecord=0;%we have an image series without 'record' subdir
+ end
+ end
+ if testrecord
+ %the subdevice directory is 'record' (no images detected at this level)
+ for idir_s=1:nbsubdir
+ [t,RecordElement]=add(t,DeviceElement,'element',Device.Record{idir_s});
+ t=attributes(t,'add',RecordElement,'type','RECORD_DIR');
+ t=attributes(t,'add',RecordElement,'source','dir');
+ list_subdir=dir(fullfile(ExpPath,list_dir(idir_exp).name,Device.Record{idir_s}));
+ nbsubdir=0;
+ RootIma='';
+ RootNc='';
+ nbfile=0;
+ fname={};
+ for isubdir=3:length(list_subdir)
+ if list_subdir(isubdir).isdir
+ nbsubdir=nbsubdir+1;
+ [t,RecordElement]=add(t,DeviceElement,'element',Device.Record{idir_exp});
+ t=attributes(t,'add',RecordElement,'type','RECORD_DIR');
+ t=attributes(t,'add',RecordElement,'source','dir');
+ %VOIR les .netcdf a l'interieur
+ else
+ nbfile=nbfile+1;
+ fname{nbfile}=list_subdir(isubdir).name;
+ end
+ end
+ if isunix
+ fname_mod=regexprep(fname,'_','/');
+ fname_mod=sort(fname_mod); %sort by name
+ fname=regexprep(fname_mod,'/','_');
+ end
+ for ifile=1:nbfile;
+ [Path,Name,Ext]=fileparts(fname{ifile});
+ if isequal(Ext,'.xml')
+ [t,ImaDocElement]=add(t,DeviceElement,'element','ImaDoc');
+ t=add(t,ImaDocElement,'chardata',fname{ifile});
+ t=attributes(t,'add',ImaDocElement,'source','file');
+ elseif isequal(Ext,'.png')
+ [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
+ if ~isequal(Root,RootIma)
+ [t,ImaDocElement]=add(t,DeviceElement,'element','Image');
+ t=add(t,ImaDocElement,'chardata',fname{ifile});
+ t=attributes(t,'add',ImaDocElement,'source','file');
+ RootIma=Root;
+ end
+ elseif isequal(Ext,'.nc')
+ [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
+ if ~isequal(Root,RootNc)%only one image recorded for each root name
+ [t,ImaDocElement]=add(t,DeviceElement,'element','Ncdata');
+ t=add(t,ImaDocElement,'chardata',fname{ifile});
+ t=attributes(t,'add',ImaDocElement,'source','file');
+ RootNc=Root;
+ end
+ end
+ end
+ end
+ else%the subdevice directory is a civ directory (coexist with images)
+ for idir_s=1:nbsubdir
+ [t,RecordElement]=add(t,DeviceElement,'element',Device.Record{idir_s});
+ t=attributes(t,'add',RecordElement,'type','CIV_DIR');
+ t=attributes(t,'add',RecordElement,'source','dir');
+ %list files under the civ directory
+ list_subdir=dir(fullfile(ExpPath,list_dir(idir_exp).name,Device.Record{idir_s}));
+
+ nbsubdir=0;
+ nbfile=0;
+ RootXml='';
+ RootNc='';
+ fname={};
+ for isubdir=3:length(list_subdir)
+ if list_subdir(isubdir).isdir
+ nbsubdir=nbsubdir+1;
+ [t,SubElement]=add(t,RecordElement,'element',list_subdir(isubdir).name);
+ t=attributes(t,'add',SubElement,'type','UNKNOWN_DIR');
+ t=attributes(t,'add',SubElement,'source','dir');
+ else
+ nbfile=nbfile+1;
+ fname{nbfile}=list_subdir(isubdir).name;
+ end
+ end
+ if isunix
+ fname_mod=regexprep(fname,'_','/');
+ fname_mod=sort(fname_mod); %sort by name
+ fname=regexprep(fname_mod,'/','_');
+ end
+ for ifile=1:nbfile;
+ [Path,Name,Ext]=fileparts(fname{ifile});
+ if isequal(Ext,'.xml')
+ [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
+ if ~isequal(Root,RootXml)%only one image recorded for each root name
+ [t,ImaDocElement]=add(t,RecordElement,'element','CivDoc');
+ t=add(t,ImaDocElement,'chardata',fname{ifile});
+ t=attributes(t,'add',ImaDocElement,'source','file');
+ RootXml=Root;
+ end
+ elseif isequal(Ext,'.nc')
+ [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
+ if ~isequal(Root,RootNc)%only one image recorded for each root name
+ [t,ImaDocElement]=add(t,RecordElement,'element','Ncdata');
+ t=add(t,ImaDocElement,'chardata',fname{ifile});
+ t=attributes(t,'add',ImaDocElement,'source','file');
+ RootNc=Root;
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ save(t);%display xml file on the screen
+ save(t,ExpDocName);
+ end
+end
+% [erread,message]=fileattrib('./DATA');
+% if ~isempty(message) & ~isequal(message.UserWrite,1)
+% errordlg(['Need writting access to ' message.Name])
+% return
+% end
+
+
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ function project_update(obj,event,fileinput)
+ hchild=get(gcbf,'children');
+ h=findobj(gcbf,'Tag','listbox')
+
Index: /trunk/src/reinit.m
===================================================================
--- /trunk/src/reinit.m (revision 2)
+++ /trunk/src/reinit.m (revision 2)
@@ -0,0 +1,9 @@
+%'reinit': delete the personal parameter file 'uvmat_perso.mat'
+%
+function reinit
+dir_perso=prefdir;
+profil_perso=fullfile(dir_perso,'uvmat_perso.mat')
+if exist(profil_perso,'file')
+ delete(profil_perso)
+end
+display('deleted')
Index: /trunk/src/series.m
===================================================================
--- /trunk/src/series.m (revision 2)
+++ /trunk/src/series.m (revision 2)
@@ -0,0 +1,4549 @@
+%'series': master function associated to the GUI series.m for analysis field series
+%------------------------------------------------------------------------
+% function varargout = series(varargin)
+% associated with the GUI series.fig
+%
+%INPUT
+% param: structure with input parameters (link with the GUI uvmat)
+% .menu_coord_str: string for the CoordType (menu for coordinate transforms)
+% .menu_coord_val: value for CoordType (menu for coordinate transforms)
+% .FileName: input file name
+% .FileName_1: second input file name
+% .list_field: menu of input fields
+% .index_fields: chosen index
+% .civ1=0 or 1, .interp1, ... : input civ field type
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function varargout = series(varargin)
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @series_OpeningFcn, ...
+ 'gui_OutputFcn', @series_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin && ischar(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+%--------------------------------------------------------------------------
+% --- Executes just before series is made visible.
+%--------------------------------------------------------------------------
+function series_OpeningFcn(hObject, eventdata, handles,param)
+
+% Choose default command line output for series
+handles.output = hObject;
+% Update handles structure
+guidata(hObject, handles);
+%default initial parameters
+
+%load the list of previously browsed files in menus Open and Open_1
+dir_perso=prefdir;
+profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+if exist(profil_perso,'file')
+ h=load (profil_perso);
+ if isfield(h,'MenuFile_1')
+ set(handles.MenuFile_1,'Label',h.MenuFile_1);
+ set(handles.MenuFile_insert_1,'Label',h.MenuFile_1);
+ end
+ if isfield(h,'MenuFile_1')
+ set(handles.MenuFile_2,'Label',h.MenuFile_2);
+ set(handles.MenuFile_insert_2,'Label',h.MenuFile_2);
+ end
+ if isfield(h,'MenuFile_1')
+ set(handles.MenuFile_3,'Label',h.MenuFile_3);
+ set(handles.MenuFile_insert_3,'Label',h.MenuFile_3);
+ end
+ if isfield(h,'MenuFile_1')
+ set(handles.MenuFile_4,'Label',h.MenuFile_4);
+ set(handles.MenuFile_insert_4,'Label',h.MenuFile_4);
+ end
+ if isfield(h,'MenuFile_1')
+ set(handles.MenuFile_5,'Label',h.MenuFile_5);
+ set(handles.MenuFile_insert_5,'Label',h.MenuFile_5);
+ end
+end
+
+%check default input data
+if ~exist('param','var')
+ param=[]; %default
+end
+
+%file name and browser initialisation
+if isfield(param,'menu_coord_str')
+ set(handles.CoordType,'String',param.menu_coord_str)
+end
+if isfield(param,'menu_coord_val')
+ set(handles.CoordType,'Value',param.menu_coord_val);
+else
+ set(handles.CoordType,'Value',1);%default
+end
+
+if isfield(param,'FileName')
+ if isfield(param,'FileName_1')
+ update_file(hObject, eventdata, handles,param.FileName_1,0)
+ update_file(hObject, eventdata, handles,param.FileName,1)
+ else
+ update_file(hObject, eventdata, handles,param.FileName,0)
+ end
+end
+
+%fields input initialisation
+if isfield(param,'list_fields')&& isfield(param,'index_fields') &&~isempty(param.list_fields) &&~isempty(param.index_fields)
+ set(handles.FieldMenu,'String',param.list_fields);% list menu fields
+ set(handles.FieldMenu,'Value',param.index_fields);% selected string index
+ FieldCell{1}=param.list_fields{param.index_fields};
+end
+if isfield(param,'civ1')&& islogical(param.civ1) && isfield(param,'civ2')&& islogical(param.civ2)&...
+ isfield(param,'interp1')&& islogical(param.interp1)&&isfield(param,'interp2')&& islogical(param.interp2)&...
+ isfield(param,'filter1')&& islogical(param.filter1)&&isfield(param,'filter2')&& islogical(param.filter2)
+ set(handles.civ1,'Value',param.civ1);
+ set(handles.civ2,'Value',param.civ1);
+ set(handles.interp1,'Value',param.interp1);
+ set(handles.interp2,'Value',param.interp2);
+ set(handles.filter1,'Value',param.filter1);
+ set(handles.filter2,'Value',param.filter2);
+end
+%set(hObject,'UserData', SeriesData)
+set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles})
+NomType_Callback(hObject, eventdata, handles)
+%mode_Callback(hObject, eventdata, handles)
+
+%loads the information stored in prefdir to initiate the browser and the list of functions
+menu_str=get(handles.ACTION,'String');%list of functions included in 'series.m'
+menu_str(end)=[];%remove from the list the last option 'more...'
+path_series=which('series');%path of the function 'series'
+for ilist=1:length(menu_str)
+ fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
+end
+dir_perso=prefdir;
+profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+if exist(profil_perso,'file')
+ h=load (profil_perso);
+ if isfield(h,'series_fct') && iscell(h.series_fct)
+ for ilist=1:length(h.series_fct)
+ [path,file]=fileparts(h.series_fct{ilist});
+ fct_path=[fct_path; {path}];%concatene the list of paths
+ menu_str=[menu_str; {file}];
+ end
+ menu_str=[menu_str;{'more...'}];
+ set(handles.ACTION,'String',menu_str)
+ end
+end
+set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION
+
+% display the GUI for the default action 'check_files'
+ACTION_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------------------------
+% --- Outputs from this function are returned to the command line.
+%-----------------------------------------------------------------
+function varargout = series_OutputFcn(hObject, eventdata, handles)
+% varargout cell array for returning output args (see VARARGOUT);
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+
+
+% --------------------------------------------------------------------
+function MenuBrowse_Callback(hObject, eventdata, handles)
+
+RootPathCell=get(handles.RootPath,'String');
+SubDirCell=get(handles.SubDir,'String');
+RootFileCell=get(handles.RootFile,'String');
+oldfile=''; %default
+if isempty(RootPathCell)|isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ if exist(profil_perso,'file')
+ h=load (profil_perso);
+ if isfield(h,'filebase')&ischar(h.filebase)
+ oldfile=h.filebase;
+ end
+ if isfield(h,'RootPath')&ischar(h.RootPath)
+ oldfile=h.RootPath;
+ end
+ end
+ else
+ oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
+ end
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
+ '*.xml', '.xml files '; ...
+ '*.xls', '.xls files '; ...
+ '*.png','.png image files'; ...
+ '*.tif','.tif image files'; ...
+ '*.avi;*.AVI','.avi movie files'; ...
+ '*.nc','.netcdf files'; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',oldfile);
+fileinput=[PathName FileName];%complete file name
+testblank=findstr(fileinput,' ');%look for blanks
+if ~isempty(testblank)
+ errordlg('forbidden input file name: contain blanks')
+ return
+end
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
+[path,name,ext]=fileparts(fileinput);
+SeriesData=[];%dfault
+if isequal(ext,'.xml')
+ errordlg('input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
+elseif isequal(ext,'.xls')
+ errordlg('input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
+else
+ update_file(hObject, eventdata, handles,fileinput,0)
+ %update list of recent files in the menubar
+ MenuFile_1=fileinput;
+ MenuFile_2=get(handles.MenuFile_1,'Label');
+ MenuFile_3=get(handles.MenuFile_2,'Label');
+ MenuFile_4=get(handles.MenuFile_3,'Label');
+ MenuFile_5=get(handles.MenuFile_4,'Label');
+ set(handles.MenuFile_1,'Label',MenuFile_1)
+ set(handles.MenuFile_2,'Label',MenuFile_2)
+ set(handles.MenuFile_3,'Label',MenuFile_3)
+ set(handles.MenuFile_4,'Label',MenuFile_4)
+ set(handles.MenuFile_5,'Label',MenuFile_5)
+ set(handles.MenuFile_insert_1,'Label',MenuFile_1)
+ set(handles.MenuFile_insert_2,'Label',MenuFile_2)
+ set(handles.MenuFile_insert_3,'Label',MenuFile_3)
+ set(handles.MenuFile_insert_4,'Label',MenuFile_4)
+ set(handles.MenuFile_insert_5,'Label',MenuFile_5)
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ if exist(profil_perso,'file')
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
+ else
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
+ else
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
+ end
+ end
+end
+% set(hseries,'UserData',SeriesData);
+% RootFile_Callback(hObject, eventdata, handles);
+% FileExt_Callback(hObject, eventdata, handles);
+% NomType_Callback(hObject, eventdata, handles)
+% mode_Callback(hObject, eventdata, handles)
+
+
+% --------------------------------------------------------------------
+function MenuFile_1_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_1,'Label');
+update_file(hObject, eventdata, handles,fileinput,0)
+
+% --------------------------------------------------------------------
+function MenuFile_2_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_2,'Label');
+update_file(hObject, eventdata, handles,fileinput,0)
+
+% --------------------------------------------------------------------
+function MenuFile_3_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_3,'Label');
+update_file(hObject, eventdata, handles,fileinput,0)
+
+% --------------------------------------------------------------------
+function MenuFile_4_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_4,'Label');
+update_file(hObject, eventdata, handles,fileinput,0)
+
+% --------------------------------------------------------------------
+function MenuFile_5_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_5,'Label');
+update_file(hObject, eventdata, handles,fileinput,0)
+
+% --------------------------------------------------------------------
+function MenuBrowse_insert_Callback(hObject, eventdata, handles)
+
+%hseries=get(handles.browse_root,'parent');
+RootPathCell=get(handles.RootPath,'String');
+% SubDirCell=get(handles.SubDir,'String');
+RootFileCell=get(handles.RootFile,'String');
+oldfile=''; %default
+if isempty(RootPathCell)|isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ if exist(profil_perso,'file')
+ h=load (profil_perso);
+ if isfield(h,'filebase')&ischar(h.filebase)
+ oldfile=h.filebase;
+ end
+ if isfield(h,'RootPath')&ischar(h.RootPath)
+ oldfile=h.RootPath;
+ end
+ end
+ else
+ oldfile=fullfile(RootPathCell{1},RootFileCell{1});
+ end
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)';
+ '*.xml', '.xml files '; ...
+ '*.xls', '.xls files '; ...
+ '*.png','.png image files'; ...
+ '*.avi;*.AVI','.avi movie files'; ...
+ '*.nc','.netcdf files'; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',oldfile);
+fileinput=[PathName FileName];%complete file name
+testblank=findstr(fileinput,' ');%look for blanks
+if ~isempty(testblank)
+ errordlg('forbidden input file name: contain blanks')
+ return
+end
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
+[path,name,ext]=fileparts(fileinput);
+SeriesData=[];%dfault
+if isequal(ext,'.xml')
+ errordlg('input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
+elseif isequal(ext,'.xls')
+ errordlg('input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
+else
+ update_file(hObject, eventdata, handles,fileinput,1)
+ %update list of recent files in the menubar
+ MenuFile_1=fileinput;
+ MenuFile_2=get(handles.MenuFile_1,'Label');
+ MenuFile_3=get(handles.MenuFile_2,'Label');
+ MenuFile_4=get(handles.MenuFile_3,'Label');
+ MenuFile_5=get(handles.MenuFile_4,'Label');
+ set(handles.MenuFile_1,'Label',MenuFile_1)
+ set(handles.MenuFile_2,'Label',MenuFile_2)
+ set(handles.MenuFile_3,'Label',MenuFile_3)
+ set(handles.MenuFile_4,'Label',MenuFile_4)
+ set(handles.MenuFile_5,'Label',MenuFile_5)
+ set(handles.MenuFile_insert_1,'Label',MenuFile_1)
+ set(handles.MenuFile_insert_2,'Label',MenuFile_2)
+ set(handles.MenuFile_insert_3,'Label',MenuFile_3)
+ set(handles.MenuFile_insert_4,'Label',MenuFile_4)
+ set(handles.MenuFile_insert_5,'Label',MenuFile_5)
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ if exist(profil_perso,'file')
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
+ else
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
+ else
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
+ end
+ end
+end
+%------------------------------------------------
+
+% --------------------------------------------------------------------
+function MenuFile_insert_1_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_insert_1,'Label');
+update_file(hObject, eventdata, handles,fileinput,1)
+
+% --------------------------------------------------------------------
+function MenuFile_insert_2_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_insert_2,'Label');
+update_file(hObject, eventdata, handles,fileinput,1)
+
+% --------------------------------------------------------------------
+function MenuFile_insert_3_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_insert_3,'Label');
+update_file(hObject, eventdata, handles,fileinput,1)
+
+% --------------------------------------------------------------------
+function MenuFile_insert_4_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_insert_4,'Label');
+update_file(hObject, eventdata, handles,fileinput,1)
+
+% --------------------------------------------------------------------
+function MenuFile_insert_5_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_insert_5,'Label');
+update_file(hObject, eventdata, handles,fileinput,1)
+
+% --------------------------------------------------------------------
+% refresh the GUI data after introduction of a new file series
+function update_file(hObject, eventdata, handles,fileinput,addtest)
+hseries=get(handles.RootPath,'parent');
+% refresh input root name, indices, file extension and nomenclature
+[RootPath,RootFile,field_count,str2,str_a,str_b,FileExt,NomType,SubDir]=name2display(fileinput);
+%check for movie image files
+if ~isempty(imformats(FileExt(2:end)))
+ imainfo=imfinfo(fileinput);
+ if length(imainfo) >1 %case of image with multiple frames
+ NomType='*';
+ [RootPath,RootFile]=fileparts(fileinput);
+ end
+end
+NcType='none';%default
+if isequal(FileExt,'.nc')
+ Data=nc2struct(fileinput,[]);
+ if isfield(Data,'absolut_time_T0')
+ NcType='civx'; % test for civx velocity fields
+ end
+end
+
+set(handles.RootPath,'Value',1)
+set(handles.SubDir,'Value',1)
+set(handles.RootFile,'Value',1)
+set(handles.NomType,'Value',1)
+set(handles.FileExt,'Value',1)
+set(handles.nb_field,'Value',1)
+set(handles.nb_field2,'Value',1)
+if addtest
+ SeriesData=get(hseries,'UserData');
+ SeriesData.displ_num=[0 0 0 0;SeriesData.displ_num];
+ SeriesData.CurrentInputFile_1=SeriesData.CurrentInputFile;
+ RootPathCell=[{RootPath}; get(handles.RootPath,'String')] ;
+ SubDirCell=[{SubDir}; get(handles.SubDir,'String')];
+ RootFileCell=[{RootFile}; get(handles.RootFile,'String')];
+ NomTypeCell=[{NomType}; SeriesData.NomType];
+ FileExtCell=[{FileExt}; get(handles.FileExt,'String')];
+ NcTypeCell=[{NcType};SeriesData.NcType];
+ set(handles.NomType,'String',[{};get(handles.NomType,'String')])
+else
+ SeriesData=[];%re-initialisation
+ SeriesData.displ_num=[0 0 0 0];
+ RootPathCell={RootPath};
+ SubDirCell={SubDir};
+ RootFileCell={RootFile};
+ NomTypeCell={NomType};
+ FileExtCell={FileExt};
+ NcTypeCell={NcType};
+end
+
+SeriesData.NomType=NomTypeCell;
+SeriesData.NcType=NcTypeCell;
+SeriesData.CurrentInputFile=fileinput;
+set(handles.RootPath,'String',RootPathCell);
+set(handles.SubDir,'String',SubDirCell);
+set(handles.RootFile,'String',RootFileCell);
+set(handles.NomType,'String',NomTypeCell);
+set(handles.FileExt,'String',FileExtCell);
+
+%determine field indices
+ref_i=1; %default ref_i is a reference frame index used to find existing pairs from PIV
+if ~isempty(str2num(field_count))
+ ref_i=str2num(field_count);
+ if ~isempty(str2num(str2))
+ ref_i=floor((ref_i+str2num(str2))/2);% reference image number corresponding to the file
+ SeriesData.browse_Di=str2num(str2)-str2num(field_count);
+ end
+end
+set(handles.ref_i,'String',num2str(ref_i));
+set(handles.first_i,'String',num2str(ref_i));
+set(handles.last_i,'String',num2str(ref_i));
+ref_j=1; %default ref_j is a reference frame index used to find existing pairs from PIV
+if ~isempty(str2num(str_a))
+ ref_j=str2num(str_a);
+ if ~isempty(str2num(str_b))
+ ref_j=floor((str2num(str_a)+str2num(str_b))/2);
+ SeriesData.browse_Dj=str2num(str_b)-str2num(str_a);
+ end
+end
+set(handles.ref_j,'String',num2str(ref_j));
+set(handles.first_j,'String',num2str(ref_j))
+set(handles.last_j,'String',num2str(ref_j));
+%set(hseries,'UserData',SeriesData);
+
+%enable other menus and uicontrols
+set(handles.MenuOpen_insert,'Enable','on')
+set(handles.MenuFile_insert_1,'Enable','on')
+set(handles.MenuFile_insert_2,'Enable','on')
+set(handles.MenuFile_insert_3,'Enable','on')
+set(handles.MenuFile_insert_4,'Enable','on')
+set(handles.MenuFile_insert_5,'Enable','on')
+set(handles.RUN, 'Enable','On')
+set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
+set(handles.RootPath,'BackgroundColor',[1 1 0]) % set RootPath edit box to yellow
+drawnow
+
+% hseries=get(handles.RootFile,'parent');
+% SeriesData=get(hseries,'UserData');%read information set by the browser
+% ext_ima_read=[];
+% field_count=1;%default
+% pxcmx=1;
+% pxcmy=1;
+TimeUnit=''; %default
+% CoordUnit='';%default
+time=[];%default
+GeometryCalib=[];%default
+nb_field=[];%default
+nb_field2=[];%default
+% Heading=[];
+% [PD,Device]=fileparts(RootPathCell{1});
+SeriesData.PathCampaign=get(handles.PathCampaign,'String');
+
+% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
+%icell=length(RootPathCell);
+FileBase=fullfile(RootPath,RootFile);
+
+% nb_field{icell,1}='?';%default
+% nb_field2{icell,1}='?';%default
+testima=0; %test for image input
+if isequal(lower(FileExt),'.avi') %.avi file
+ testima=1;
+ info=aviinfo([FileBase FileExt]);
+ time=[0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond]';
+ nb_field=info.NumFrames;
+ nb_field2=1;
+elseif ~isempty(imformats(FileExt(2:end)))
+ testima=1;
+ if isequal(NomType,'*')% multi-frame image
+ imainfo=imfinfo([FileBase FileExt]);
+ if length(imainfo) >1 %case of image with multiple frames
+ nb_field=length(imainfo);
+ nb_field2=1;
+ end
+ end
+elseif isequal(FileExt,'.vol')
+ testima=1;
+end
+
+% enable field and veltype menus
+testfield=isequal(get(handles.FieldMenu,'enable'),'on');
+testfield_1=isequal(get(handles.FieldMenu_1,'enable'),'on');
+testveltype=isequal(get(handles.VelTypeMenu,'enable'),'on');
+testveltype_1=isequal(get(handles.VelTypeMenu_1,'enable'),'on');
+testtransform=isequal(get(handles.CoordType,'Enable'),'on');
+testnc=0;
+testnc_1=0;
+testcivx=0;
+testcivx_1=0;
+if length(FileExtCell)==1 || length(FileExtCell)>2
+ for iview=1:length(FileExtCell)
+ if isequal(FileExtCell{iview},'.nc')
+ testnc=1;
+ end
+ if isequal(NcTypeCell{iview},'civx')
+ testcivx=1;
+ end
+ end
+elseif length(FileExtCell)==2
+ testnc=isequal(FileExtCell{1},'.nc');
+ testnc_1=isequal(FileExtCell{2},'.nc');
+ testcivx=isequal(NcTypeCell{1},'civx');
+ testcivx_1=isequal(NcTypeCell{2},'civx');
+end
+if testfield && testnc
+ view_FieldMenu(handles,'on')
+ if testcivx
+ menustr=get(handles.FieldMenu,'String');
+ if isequal(menustr,{'get_field...'})
+ set(handles.FieldMenu,'String',{'get_field...';'velocity';'vort';'div';'more...'})
+ end
+ else
+ set(handles.FieldMenu,'Value',1)
+ set(handles.FieldMenu,'String',{'get_field...'})
+ end
+else
+ view_FieldMenu(handles,'off')
+end
+if testfield_1 && testnc_1
+ view_FieldMenu_1(handles,'on')
+ if testcivx_1
+ menustr=get(handles.FieldMenu_1,'String');
+ if isequal(menustr,{'get_field...'})
+ set(handles.FieldMenu_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
+ end
+ else
+ set(handles.FieldMenu_1,'Value',1)
+ set(handles.FieldMenu_1,'String',{'get_field...'})
+ end
+else
+ view_FieldMenu_1(handles,'off')
+end
+if testveltype && testcivx
+ set(handles.VelTypeMenu,'Visible','on')
+ set(handles.VelType_text,'Visible','on');
+else
+ set(handles.VelTypeMenu,'Visible','off')
+ set(handles.VelType_text,'Visible','off');
+end
+if testveltype_1 && testcivx_1
+ set(handles.VelTypeMenu_1,'Visible','on')
+ set(handles.VelType_text_1,'Visible','on');
+else
+ set(handles.VelTypeMenu_1,'Visible','off')
+ set(handles.VelType_text_1,'Visible','off');
+end
+if testtransform && (testcivx || testima)
+ view_TRANSFORM(handles,'on')
+else
+ view_TRANSFORM(handles,'off')
+end
+if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
+ msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
+ return
+end
+
+%%%%%%%% read image documentation file if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %look for the file existence
+ext_imadoc='';
+if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
+ ext_imadoc=FileExt;
+elseif exist([FileBase '.xml'],'file')
+ ext_imadoc='.xml';
+elseif exist([FileBase '.civ'],'file')
+ ext_imadoc='.civ';
+end
+ %read the ImaDoc file
+% mode=''; %default
+% testheading=0;
+XmlData=[];
+NbSlice_calib={};
+if isequal(ext_imadoc,'.xml')
+ [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
+ if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName')
+ [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
+ end
+ if isfield(XmlData,'Time')
+ time=XmlData.Time;
+ end
+ if isfield(XmlData,'Camera')
+ if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
+ NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
+ if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
+ msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
+ end
+ end
+ if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
+ TimeUnit=XmlData.Camera.TimeUnit;
+ end
+ end
+ if ~isempty(warntext)
+ msgbox_uvmat('WARNING',warntext)
+ end
+elseif isequal(ext_imadoc,'.civ')
+ [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
+ time=XmlData.Time;
+ size(time)
+ GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
+ GeometryCalib.Tx=0;
+ GeometryCalib.Ty=0;
+ GeometryCalib.Tz=1;
+ GeometryCalib.dpx=1;
+ GeometryCalib.dpy=1;
+ GeometryCalib.sx=1;
+ GeometryCalib.Cx=0;
+ GeometryCalib.Cy=0;
+ GeometryCalib.f=1;
+ GeometryCalib.kappa1=0;
+ GeometryCalib.CoordUnit='cm';
+ XmlData.GeometryCalib=GeometryCalib;
+ if error==2, warntext=['no file ' FileBase '.civ'];
+ elseif error==1, warntext='inconsistent number of fields in the .civ file';
+ end
+% set(handles.npx,'String',num2str(npx));%fills nbre of pixels x box
+% set(handles.npy,'String',num2str(npy));%fills nbre of pixels y box
+% set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
+% set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
+% set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
+% set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
+% set(handles.view_xml,'Visible','on')
+% set(handles.view_xml,'String','view .civ')
+end
+if addtest
+ SeriesData.Time=[{time} SeriesData.Time];
+else
+ SeriesData.Time={time};
+end
+
+if ~isempty(time)
+ siztime=size(time);
+ nb_field=siztime(1);
+ nb_field2=siztime(2);
+end
+set(handles.TimeUnit,'String',TimeUnit)
+if isempty(nb_field)
+ nb_field_str='?';
+ nb_field_str2='?';
+else
+ nb_field_str=num2str(nb_field);
+ nb_field_str2=num2str(nb_field2);
+end
+if addtest
+ nb_field_cell=[{nb_field_str} ;get(handles.nb_field,'String')];
+ nb_field2_cell=[{nb_field_str2} ;get(handles.nb_field2,'String')];
+else
+ nb_field_cell={nb_field_str};
+ nb_field2_cell={nb_field_str2};
+end
+set(handles.nb_field,'String',nb_field_cell);
+set(handles.nb_field2,'String',nb_field2_cell);
+set(hseries,'UserData',SeriesData);
+
+%number of slices
+if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
+ siz=size(XmlData.GeometryCalib.SliceCoord);
+ if siz(1)>1
+ NbSlice=siz(1);
+ else
+ NbSlice=1;
+ end
+ set(handles.NbSlice,'String',num2str(NbSlice))
+end
+
+% set menus of index pairs
+NomType_Callback(hObject, eventdata, handles)
+
+dir_perso=prefdir;
+profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+% save(profil_perso, 'FileBase'); %store the root name for future opening of uvmat
+if exist(profil_perso,'file')
+ save (profil_perso,'RootPath','SubDir','RootFile','NomType', '-append'); %store the root name for future opening of uvmat
+else
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ save (profil_perso,'RootPath','SubDir','RootFile','NomType','-V6') %store the root name for future opening of uvmat
+ else
+ save(profil_perso,'RootPath','SubDir','RootFile','NomType')
+ end
+end
+set(handles.RootPath,'BackgroundColor',[1 1 1])
+set(handles.PathCampaign,'String',SeriesData.PathCampaign)
+last_j_Callback(hObject, eventdata, handles)
+last_i_Callback(hObject, eventdata, handles)
+
+%------------------------------------------------------------
+function RootPath_Callback(hObject, eventdata, handles)
+Val=get(handles.RootPath,'Value');
+synchronise_view(handles,Val)
+NomType_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------
+
+function synchronise_view(handles,Val)
+set(handles.RootPath,'Value',Val)
+set(handles.SubDir,'Value',Val)
+set(handles.RootFile,'Value',Val)
+set(handles.NomType,'Value',Val)
+set(handles.FileExt,'Value',Val)
+set(handles.nb_field,'Value',Val)
+set(handles.nb_field2,'Value',Val)
+set(handles.time_first,'Value',Val)
+set(handles.time_last,'Value',Val)
+
+
+%---------------------------------------------------------
+% Executes on carriage return on the subdir civ1 edit window
+%--------------------------------------------------------
+function SubDir_Callback(hObject, eventdata, handles)
+
+Val=get(handles.SubDir,'Value');
+synchronise_view(handles,Val)
+NomType_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------------------------
+%function activated when a new filebase (image series) is introduced
+%------------------------------------------------------------
+function RootFile_Callback(hObject, eventdata, handles)
+Val=get(handles.RootFile,'Value');
+synchronise_view(handles,Val)
+NomType_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------------------------
+%function activated when a new filebase (image series) is introduced
+%------------------------------------------------------------
+function FileExt_Callback(hObject, eventdata, handles)
+Val=get(handles.FileExt,'Value');
+synchronise_view(handles,Val)
+
+%--------------------------------------------------------------
+%function activated when a new filebase (image series) is introduced
+%------------------------------------------------------------
+function nb_field_Callback(hObject, eventdata, handles)
+Val=get(handles.nb_field,'Value');
+synchronise_view(handles,Val)
+
+%--------------------------------------------------------------
+%function activated when a new filebase (image series) is introduced
+%------------------------------------------------------------
+function nb_field2_Callback(hObject, eventdata, handles)
+Val=get(handles.nb_field2,'Value');
+synchronise_view(handles,Val)
+
+%--------------------------------------------------------------
+%function activated when a new filebase (image series) is introduced
+%------------------------------------------------------------
+function time_first_Callback(hObject, eventdata, handles)
+Val=get(handles.time_first,'Value');
+synchronise_view(handles,Val)
+
+%--------------------------------------------------------------
+%function activated when a new filebase (image series) is introduced
+%------------------------------------------------------------
+function time_last_Callback(hObject, eventdata, handles)
+Val=get(handles.time_last,'Value');
+synchronise_view(handles,Val)
+
+%--------------------------------------------------------------
+%function activated by NomType
+%------------------------------------------------------------
+NomType_Callback(hObject, eventdata, handles)
+
+function NomType_Callback(hObject, eventdata, handles)
+hseries=get(handles.ProjObject,'Parent');
+SeriesData=get(hseries,'UserData');
+if isfield(SeriesData,'NomType')
+ NomTypeCell=SeriesData.NomType;
+else
+ NomTypeCell={};
+end
+nbfield2_cell=get(handles.nb_field2,'String');
+val=get(handles.nb_field2,'Value');
+if iscell(nbfield2_cell)
+ nbfield2=str2num(nbfield2_cell{val});
+else
+ nbfield2=str2num(nbfield2_cell);
+end
+nbfield_cell=get(handles.nb_field,'String');
+if iscell(nbfield_cell)
+ nbfield=str2num(nbfield_cell{val});
+else
+ nbfield=str2num(nbfield_cell);
+end
+
+set(handles.mode,'Visible','off') % do not show index pairs by default
+set(handles.list_pair_civ,'Visible','off')
+set(handles.ref_i,'Visible','off')
+set(handles.ref_i_text,'Visible','off')
+testpair=0;
+state_j='off';
+%set the menus of image pairs and default selection for series
+%list pairs if relevant
+Val=get(handles.NomType,'Value');
+synchronise_view(handles,Val)
+if ~isempty(NomTypeCell)
+ NomType=NomTypeCell{Val};
+ switch NomType
+ case {'_i1-i2_j', '_i1-i2'}
+ set(handles.mode,'String',{'series(Di)'})
+ set(handles.mode,'Value',1);
+ set(handles.mode,'Visible','on')
+ testpair=1;
+ case {'#_ab'}
+ set(handles.mode,'String',{'bursts'})
+ set(handles.mode,'Value',1);
+ testpair=1;
+ case '_i_j1-j2'
+ set(handles.mode,'String',{'bursts';'series(Dj)'})%multiple choice
+ if ~isempty(nbfield) && ~isempty(nbfield2) && ((nbfield2>10) || (nbfield==1))
+ set(handles.mode,'Value',2);
+ else
+ set(handles.mode,'Value',1);% advice 'bursts' for small bursts
+ end
+ set(handles.mode,'Visible','on')
+ testpair=1;
+ end
+ switch NomType
+ case {'_i_j','_i_j1-j2','_i1-i2_j','#_ab'},% two navigation indices
+ state_j='on';
+ end
+end
+if testpair
+ mode_Callback(hObject, eventdata, handles)
+else
+ set(handles.NomType,'String',NomTypeCell)
+end
+set(handles.first_j,'Visible',state_j)
+set(handles.incr_j,'Visible',state_j)
+set(handles.last_j,'Visible',state_j)
+set(handles.nb_field2,'Visible',state_j)
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
+% --- Executes on button press in mode.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function mode_Callback(hObject, eventdata, handles)
+hseries=get(handles.mode,'parent');
+SeriesData=get(hseries,'UserData');
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+NomType=[];
+test_find_pair=0;
+if isfield(SeriesData,'NomType')
+ NomTypeCell=SeriesData.NomType;
+ Val=get(handles.NomType,'Value');
+ NomType=NomTypeCell{Val};
+ test_find_pair=isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')|| isequal(NomType,'#_ab');
+end
+% displ_num=[];%default
+% first_i=str2num(get(handles.first_i,'String'));
+% last_i=str2num(get(handles.last_i,'String'));
+time=[];
+if isfield(SeriesData,'Time')
+time=SeriesData.Time{1}; %get the set of times
+end
+siztime=size(time);
+nbfield=siztime(1);
+nbfield2=siztime(2);
+indchosen=1; %%first pair selected by default
+if isequal(mode,'bursts')
+ enable_i(handles,'On')
+ enable_j(handles,'Off')
+elseif isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')
+ enable_i(handles,'On')
+ enable_j(handles,'On')
+else
+ enable_i(handles,'On')
+ enable_j(handles,'Off')
+end
+
+
+% elseif isequal(mode,'series(Dj)')
+% enable_j(handles,'On')
+% if nbfield==1
+% enable_i(handles,'Off')
+% else
+% enable_i(handles,'On')
+% end
+% elseif isequal(mode,'series(Di)')
+% if nbfield2 > 1
+% enable_j(handles,'On')
+% else
+% enable_j(handles,'Off')
+% end
+% end
+set(handles.list_pair_civ,'Value',indchosen);%set the default choice of image pairs for civ1
+% SetSeries.displ_num=displ_num;
+set(hseries,'UserData',SeriesData)
+
+%list pairs if relevant
+if test_find_pair
+ find_netcpair_civ(hObject, eventdata, handles,Val)
+end
+
+%-------------------------------------
+function enable_i(handles,state)
+set(handles.i_txt,'Visible',state)
+set(handles.first_i,'Visible',state)
+set(handles.last_i,'Visible',state)
+set(handles.incr_i,'Visible',state)
+set(handles.nb_field,'Visible',state)
+set(handles.ref_i,'Visible',state)
+set(handles.ref_i_text,'Visible',state)
+
+%-----------------------------------
+function enable_j(handles,state)
+set(handles.j_txt,'Visible',state)
+set(handles.first_j,'Visible',state)
+set(handles.last_j,'Visible',state)
+set(handles.incr_j,'Visible',state)
+set(handles.nb_field2,'Visible',state)
+set(handles.ref_j,'Visible',state)
+set(handles.ref_j_text,'Visible',state)
+
+%-----------------------------------
+function view_FieldMenu(handles,state)
+set(handles.FieldMenu,'Visible',state)
+set(handles.Field_text,'Visible',state)
+set(handles.Field_frame,'Visible',state)
+
+%-----------------------------------
+function view_FieldMenu_1(handles,state)
+set(handles.FieldMenu_1,'Visible',state)
+set(handles.Field_text_1,'Visible',state)
+
+%-----------------------------------
+function view_TRANSFORM(handles,state)
+set(handles.TRANSFORM_frame,'Visible',state)
+set(handles.CoordType,'Visible',state);
+set(handles.TRANSFORM_title,'Visible',state)
+
+%--------------------------------------------------------------
+% determine the menu for civ1 pairs depending on existing netcdf file at the middle of
+% the field series set by first_i, incr, last_i
+%----------------------------------------------------------------
+function find_netcpair_civ(hObject, eventdata, handles,Val)
+hseries=get(handles.list_pair_civ,'parent');
+SeriesData=get(hseries,'UserData');
+% NomTypeCell=get(handles.NomType,'String');
+NomTypeCell=SeriesData.NomType;
+NomType=NomTypeCell{Val};
+ set(handles.list_pair_civ,'Visible','on')
+%nomenclature types
+RootPathCell=get(handles.RootPath,'String');
+filepath=RootPathCell{Val};
+RootFileCell=get(handles.RootFile,'String');
+filename=RootFileCell{Val};
+filebase=fullfile(filepath,filename);
+SubDirCell=get(handles.SubDir,'String');
+subdir=SubDirCell{Val};
+if ~exist(fullfile(filepath,subdir),'dir')
+ msgbox_uvmat('ERROR',['no civ file available: subdirectory ' subdir ' does not exist'])
+ set(handles.list_pair_civ,'String',{''});
+ return
+end
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+
+%reads image numbers from the interface
+ref_i=str2num(get(handles.ref_i,'String'));
+ref_j=str2num(get(handles.ref_j,'String'));
+% time=[];
+% ref_time=[];
+ ref_time=0;
+if isfield(SeriesData,'Time')&~isempty(SeriesData.Time{Val})&~isequal(SeriesData.Time{Val},0)
+ time=SeriesData.Time{Val}; %get the set of times
+ siztime=size(time);
+ nbfield=siztime(1);
+ nbfield2=siztime(2);
+% test_imadoc=1;
+else
+% test_imadoc=0;%no image documentation file
+ nbfield=50;
+ nbfield2=50;%default max number of pairs
+end
+%look for existing processed pairs involving the field at the middle of the series if civ1 will not
+% be performed, while the result is needed for next steps.
+displ_pair={''};
+displ_num=[];
+ind_exist=0;
+TimeUnit=get(handles.TimeUnit,'String');
+if length(TimeUnit)>=1
+ dtunit=['m' TimeUnit];
+else
+ dtunit='e-03';
+end
+if isequal(mode,'series(Di)')
+ for index=1:min(nbfield-1,50)
+ filename=name_generator(filebase,ref_i-floor(index/2),ref_j,'.nc',NomType,1,ref_i+ceil(index/2),ref_j,subdir);
+ select=(exist(filename,'file')==2);
+ if select==1
+ ind_exist=ind_exist+1;
+ displ_num(1,ind_exist)=0;
+ displ_num(2,ind_exist)=0;
+ displ_num(3,ind_exist)=-floor(index/2);
+ displ_num(4,ind_exist)=ceil(index/2);
+ %[cte_detect,vdt,cte_read]=read_netcdf(filename,{'dt','dt2','absolut_time_T0','absolute_time_TO_2'});
+ [Cte,var_detect,ichoice]=nc2struct(filename,{});
+ if isfield(Cte,'dt2')
+ dt=Cte.dt2;
+ elseif isfield(Cte,'dt')
+ dt=Cte.dt;
+ end
+ if isfield(Cte,'absolut_time_TO_2')
+ ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
+ elseif isfield(Cte,'absolut_time_TO')
+ ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
+ elseif isfield(Cte,'Time')
+ ref_time(ind_exist)=Cte.Time;
+ end
+ displ_pair{ind_exist}=['Di= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
+ end
+ end
+ set(handles.list_pair_civ,'String',[displ_pair';{'Di=*|*'}]);
+elseif isequal(mode,'series(Dj)')% series on the j index
+ for index=1:min(nbfield2-1,50)
+ filename=name_generator(filebase,ref_i,ref_j-floor(index/2),'.nc',NomType,1,ref_i,ref_j+ceil(index/2),subdir);
+ select=(exist(filename,'file')==2);
+ if select==1
+ ind_exist=ind_exist+1;
+ displ_num(1,ind_exist)=-floor(index/2);
+ displ_num(2,ind_exist)=ceil(index/2);
+ displ_num(3,ind_exist)=0;
+ displ_num(4,ind_exist)=0;
+ %[cte_detect,vdt,cte_read]=read_netcdf(filename,{'dt','dt2','absolut_time_T0','absolute_time_TO_2'});
+ [Cte,var_detect,ichoice]=nc2struct(nc,{});
+ if isfield(Cte,'dt2')
+ dt=Cte.dt2;
+ elseif isfield(Cte,'dt')
+ dt=Cte.dt;
+ end
+ if isfield(Cte,'absolut_time_TO_2')
+ ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
+ elseif isfield(Cte,'absolut_time_TO')
+ ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
+ elseif isfield(Cte,'Time')
+ ref_time(ind_exist)=Cte.Time;
+ end
+% if cte_detect(2)==1;
+% dt=cte_read(2);
+% ref_time(ind_exist)=cte_read(4);%civ2 data used in priority
+% else
+% dt=cte_read(1);
+% ref_time(ind_exist)=cte_read(3);
+% end
+ displ_pair{ind_exist}=['Dj= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
+ end
+ end
+ set(handles.list_pair_civ,'String',[displ_pair';{'Dj=*|*'}]);
+elseif isequal(mode,'bursts') %case of bursts
+ for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'bursts' mode
+ for numod_b=(numod_a+1):nbfield2
+ [filename]=name_generator(filebase,ref_i,numod_a,'.nc',NomType,1,ref_i,numod_b,subdir);
+ select=(exist(filename,'file')==2);
+ if select==1
+ ind_exist=ind_exist+1;
+ numlist_a(ind_exist)=numod_a;
+ numlist_b(ind_exist)=numod_b;
+ Attr=nc2struct(filename,[]);
+ isfield(Attr,'absolut_time_T0_2')
+ if isfield(Attr,'dt2')
+ dt(ind_exist)=Attr.dt2;
+ ref_time(ind_exist)=Attr.absolut_time_T0_2;
+ elseif isfield(Attr,'dt')& isfield(Attr,'absolut_time_T0')
+ dt(ind_exist)=Attr.dt;
+ ref_time(ind_exist)=Attr.absolut_time_T0;
+ else
+ dt(ind_exist)=NaN;%no information on dt
+ end
+ %determine nom_type_ima for pair display (used in num2stra.m)
+ switch NomType
+ case {'#ab'}
+ nom_type_ima='#a';
+ case {'#AB'}
+ nom_type_ima='#A';
+ otherwise
+ nom_type_ima='_i_j';
+ end
+ displ_pair{ind_exist}=['j= ' num2stra(numod_a,nom_type_ima,2) '-' num2stra(numod_b,nom_type_ima,2) ...
+ ' :dt= ' num2str(dt(ind_exist)*1000)];
+ end
+ end
+ set(handles.list_pair_civ,'String',[displ_pair';{'j=*-*'}]);
+ end
+ if exist('dt','var') & ~isempty(dt)
+ [dtsort,indsort]=sort(dt);
+ displ_num(1,:)=numlist_a(indsort);
+ displ_num(2,:)=numlist_b(indsort);
+ displ_num(3,:)=0;
+ displ_num(4,:)=0;
+ displ_pair=displ_pair(indsort);
+ ref_time=ref_time(indsort);
+ end
+end
+if ind_exist==0
+ if isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
+ msgbox_uvmat('ERROR',['no .nc file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir])
+ else
+ msgbox_uvmat('ERROR',['no .nc file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir])
+ end
+ if isequal(mode,'bursts') %case of bursts
+ set(handles.list_pair_civ,'String',{'j=*-*'});
+ elseif isequal(mode,'series(Di)') %case of bursts
+ set(handles.list_pair_civ,'String',{'Di=*|*'});
+ elseif isequal(mode,'series(Dj)') %case of bursts
+ set(handles.list_pair_civ,'String',{'Dj=*|*'});
+ end
+end
+
+val=get(handles.list_pair_civ,'Value');
+if val > length(displ_pair)
+ set(handles.list_pair_civ,'Value',1);% first pair proposed by default in the menu
+ val=1;
+end
+iview=get(handles.NomType,'Value');
+SeriesData.displ_num(iview,:)=(displ_num(:,val))';
+SeriesData.ref_time=ref_time;
+set(hseries,'UserData',SeriesData)
+list_pair_civ_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------------
+% --- Executes on selection in list_pair_civ.
+function list_pair_civ_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------
+
+%update first_i and last_i according to the chosen image pairs
+testupdate=0;
+Val=get(handles.RootPath,'Value');
+IndexCell=get(handles.NomType,'String');
+hseries=get(handles.list_pair_civ,'parent');
+SeriesData=get(hseries,'UserData');
+NomType=SeriesData.NomType{Val};
+list_pair=get(handles.list_pair_civ,'String');%get the menu of image pairs
+index_pair=get(handles.list_pair_civ,'Value');
+str_pair=list_pair{index_pair};
+ind_equ=strfind(str_pair,'=');%find '='
+ind_sep=strfind(str_pair,'|');%find pair separator '|'
+ind_com=strfind(str_pair,':');%find ':'
+test_bursts=0;
+if isempty(ind_sep)
+ ind_sep=strfind(str_pair,'-');%find pair separator if it is not '|'
+ test_bursts=1;% we are in the case of bursts
+end
+displ_num=[0 0 0 0]; %default
+if ~isempty(ind_sep)&& ~strcmp(str_pair(ind_sep-1),'*')% if there is a pair separator ('|' or '-')
+ num1_str=str_pair(ind_equ(1)+1:ind_sep-1);
+ num2_str=str_pair(ind_sep+1:ind_com-1);
+ num1=str2double(num1_str);
+ num2=str2double(num2_str);
+ if isequal(num1_str(1),' ')
+ num1_str(1)=[];
+ end
+ if isequal(num2_str(end),' ')
+ num2_str(end)=[];
+ end
+ switch NomType
+ case {'_i1-i2_j'}
+ if isequal(num1_str(1),'0')
+ IndexCell{Val}=['_(i-(i+' num2_str ')_j'];
+ else
+ IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')_j'];
+ end
+ displ_num(3)=num1;
+ displ_num(4)=num2;
+ case {'_i1-i2'}
+ if isequal(num1_str(1),'0')
+ IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
+ else
+ IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
+ end
+ displ_num(3)=num1;
+ displ_num(4)=num2;
+ case '_i_j1-j2'
+ if test_bursts
+ IndexCell{Val}=['_i_' num1_str '-' num2_str ];
+ else
+ if isequal(num1_str(1),'0')
+ IndexCell{Val}=['_i_j-(j+' num2_str ')'];
+ else
+ IndexCell{Val}=['_i_(j' num1_str ')-(j+' num2_str ')'];
+ end
+ end
+ displ_num(1)=num1;
+ displ_num(2)=num2;
+ case {'#_ab'} %TO COMPLETE
+ IndexCell{Val}=['_i_' num1_str '-' num2_str ];
+
+ end
+end
+set(handles.NomType,'String',IndexCell)
+SeriesData.displ_num(Val,:)=displ_num;
+set(hseries,'UserData',SeriesData)
+% set(handles.NomType,'Value',Val)
+
+if ~isequal(str_pair,'Dj=*|*')&~isequal(str_pair,'Di=*|*')
+ mode_list=get(handles.mode,'String');
+ mode_value=get(handles.mode,'Value');
+ mode=mode_list{mode_value};
+ if isequal(mode,'series(Di)')
+ first_i=str2num(get(handles.first_i,'String'));
+ last_i=str2num(get(handles.last_i,'String'));
+ incr_i=str2num(get(handles.incr_i,'String'));
+ num1=first_i:incr_i:last_i;
+ lastfieldCell=get(handles.nb_field,'String');
+ lastfield=str2num(lastfieldCell{1});
+ if ~isempty(lastfield)
+ ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
+ num1=num1(ind);
+ end
+ set(handles.first_i,'String',num2str(num1(1)));
+ set(handles.last_i,'String',num2str(num1(end)));
+ testupdate=1;
+ elseif isequal(mode,'series(Dj)')
+ first_j=str2num(get(handles.first_j,'String'));
+ last_j=str2num(get(handles.last_j,'String'));
+ incr_j=str2num(get(handles.incr_j,'String'));
+ num_j=first_j:incr_j:last_j;
+ lastfieldCell=get(handles.nb_field2,'String');
+ if ~isempty(lastfieldCell)
+ lastfield2=lastfieldCell{1};
+ ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
+ (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
+ end
+ testupdate=1;
+ end
+
+ %update the first and last times of the series
+ if testupdate & isfield(SeriesData,'Time')
+ if ~isempty(SeriesData.Time{1})
+ displ_time(handles,SeriesData.Time{1});
+ end
+ end
+end
+%---------------------------------------------------
+% --- Executes on button press in RUN.
+%------------------------------------------------------
+function RUN_Callback(hObject, eventdata, handles)
+
+%read root name and field type
+set(handles.RUN,'BusyAction','queue');
+hseries=get(handles.RUN,'parent');
+set(0,'CurrentFigure',hseries)
+if isequal(get(handles.GetObject,'Value'),1)
+ Series.GetObject=1;
+ GetObject_Callback(hObject, eventdata, handles)
+else
+ Series.GetObject=0;
+end
+SeriesData=get(hseries,'UserData');
+if isfield(SeriesData,'sethandles')
+ if iscell(SeriesData.sethandles)
+ Series.sethandles=SeriesData.sethandles{1};
+ else
+ Series.sethandles=SeriesData.sethandles;%retrieve the handles of the set_object interface (to define projection objects)
+ end
+end
+
+%reinitiate waitbar position
+Series.WaitbarPos=get(handles.waitbar_frame,'Position');%TO SUPPRESS
+waitbarpos=Series.WaitbarPos;
+waitbarpos(4)=0.005;%reinitialize waitbar to zero height
+waitbarpos(2)=Series.WaitbarPos(2)+Series.WaitbarPos(4)-0.005;
+set(handles.waitbar,'Position',waitbarpos)
+
+% read input file parameters and set menus
+Series.PathProject=get(handles.PathCampaign,'String');
+RootPath=get(handles.RootPath,'String');% path of the root name of the first field series
+RootFile=get(handles.RootFile,'String');% root name of the first field series
+SubDir=get(handles.SubDir,'String');% subdirectory for netcdf files
+FileExt=get(handles.FileExt,'String');%file extension
+if isempty(SeriesData)
+ msgbox_uvmat('ERROR','no input file series')
+ return
+end
+NomType=SeriesData.NomType;
+if length(RootPath)==1 %string character input for user fct
+ Series.RootPath=RootPath{1};
+ Series.RootFile=RootFile{1};
+ Series.SubDir=SubDir{1};
+ Series.FileExt=FileExt{1};
+ Series.NomType=NomType{1};
+else %cell input for user fct
+ Series.RootPath=RootPath;
+ Series.RootFile=RootFile;
+ Series.SubDir=SubDir;
+ Series.FileExt=FileExt;
+ Series.NomType=NomType;
+end
+if isequal(get(handles.FieldMenu,'Visible'),'on')
+ FieldMenu=get(handles.FieldMenu,'String');
+ FieldValue=get(handles.FieldMenu,'Value');
+ Series.Field=FieldMenu(FieldValue);
+end
+menu_coord_state=get(handles.CoordType,'Visible');
+Series.CoordType='';%default
+if isequal(menu_coord_state,'on')
+ menu_coord=get(handles.CoordType,'String');
+ menu_index=get(handles.CoordType,'Value');
+ Series.CoordType=menu_coord{menu_index};
+end
+Series.hseries=get(hObject,'Parent');
+if isequal(get(handles.ParamVal,'Visible'),'on')
+ ParamKey=get(handles.ParamKey,'String');
+ if ischar(ParamKey)
+ ParamKey{1}=ParamKey;
+ end
+ ParamString=get(handles.ParamVal,'String');
+ if ischar(ParamString)
+ for ilist=1:size(ParamString,1)
+ ParamVal{ilist}=ParamString(ilist,:);
+ end
+ else
+ ParamVal=ParamString;
+ end
+end
+
+%read the set of field numbers
+first_i=str2num(get(handles.first_i,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+incr_i=str2num(get(handles.incr_i,'String'));
+first_j=str2num(get(handles.first_j,'String'));
+last_j=str2num(get(handles.last_j,'String'));
+incr_j=str2num(get(handles.incr_j,'String'));
+if ~isequal(get(handles.first_i,'Visible'),'on')
+ first_i=1;
+ last_i=1;
+ incr_i=1;
+end
+if ~isequal(get(handles.first_j,'Visible'),'on')
+ first_j=1;
+ last_j=1;
+ incr_j=1;
+end
+Series.NbSlice=str2num(get(handles.NbSlice,'String'));
+if isequal(first_i,[])|isequal(first_j,[]), msgbox_uvmat('ERROR','first field number not defined'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+if isequal(last_i,[])| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+if isequal(incr_i,[])| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
+ set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+num_i=[first_i:incr_i:last_i];
+num_j=[first_j:incr_j:last_j];
+nbfield_cell=get(handles.nb_field,'String');
+nbfield=[]; %default
+for iview=1:length(nbfield_cell)
+ nb=str2num(nbfield_cell{iview});
+ if ~isempty(nb)
+ nbfield=[nbfield nb];
+ end
+end
+nbfield=min(nbfield);
+nbfield2_cell=get(handles.nb_field2,'String');
+nbfield2=[]; %default
+for iview=1:length(nbfield2_cell)
+ nb=str2num(nbfield2_cell{iview});
+ if ~isempty(nb)
+ nbfield2=[nbfield2 nb];
+ end
+end
+nbfield2=min(nbfield2);
+
+%get complementary information from the 'series' interface
+list_action=get(handles.ACTION,'String');% list menu action
+index_action=get(handles.ACTION,'Value');% selected string index
+action= list_action{index_action}; % selected string
+mode_list=get(handles.mode,'String');
+index_mode=get(handles.mode,'Value');
+mode=mode_list{index_mode};
+ind_shift=0;%default
+
+%determine the list of input file names
+nbmissing=0;
+for iview=1:length(RootPath)
+ %case of pairs (.nc files)
+
+ if isequal(NomType{iview},'_i_j1-j2')| isequal(NomType{iview},'_i1-i2_j')| isequal(NomType{iview},'_i1-i2')| isequal(NomType{iview},'#_ab')
+ ind_shift=SeriesData.displ_num(iview,:);
+ if isequal(ind_shift,[0 0 0 0]) % undefined pairs
+ if isequal(NomType{iview},'#_ab')
+ mode='#_ab';
+ end
+ [num_i1,num_i2,num_j1,num_j2,nbmissing]=netseries_generator(fullfile(RootPath{iview},RootFile{iview}),SubDir{iview},mode,first_i,incr_i,last_i,first_j,incr_j,last_j);
+ else
+ [num_i1,num_i2,num_j1,num_j2,num_i,num_j]=find_file_indices(num_i,num_j,ind_shift,NomType{iview},mode);
+ if isempty(num_i)
+ msgbox_uvmat('ERROR','ERROR: empty set of input files chosen')
+ return
+ end
+ if num_i(1)>first_i
+ set(handles.first_i,'String',num2str(num_i(1)))%update the display of first field
+ last_i_Callback(hObject, eventdata, handles)
+ end
+ if num_i(end)first_j
+ set(handles.first_j,'String',num2str(num_j(1)))%update the display of first field
+ last_j_Callback(hObject, eventdata, handles)
+ end
+ if num_j(end)1
+ num_i1_cell{iview}=num_i1;
+ num_i2_cell{iview}=num_i2;
+ num_j1_cell{iview}=num_j1;
+ num_j2_cell{iview}=num_j2;
+ end
+end
+
+% RUN RUN'
+path_series=which('series');
+list_path=get(handles.ACTION,'UserData');
+index=get(handles.ACTION,'Value');
+fct_path=list_path{index}; %path stored for the function ACTION
+if ~isequal(fct_path,path_series)
+ eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
+ if ~isequal(spath,fct_path)& exist(fct_path,'dir')
+ addpath(fct_path)% add the prescribed path if not the current one
+ end
+end
+Series.Action=action;%name of the processing programme
+set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
+drawnow
+if length(RootPath)>1
+ feval(action,num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
+else
+ feval(action,num_i1,num_i2,num_j1,num_j2,Series);
+end
+set(handles.RUN,'BackgroundColor',[1 0 0])
+
+% %save the current interface setting as figure namefig, append .0 to the name if it already exists
+% detect=1;
+% while detect==1
+% namefigfull=[namedoc '.fig'];
+% hh=dir(namefigfull);
+% if ~isempty(hh)
+% detect=1;
+% namedoc=[namedoc '.0'];
+% else
+% detect=0;
+% end
+% end
+% saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER .xml)
+
+%----------------------------------------------------
+function STOP_Callback(hObject, eventdata, handles)
+set(handles.RUN, 'BusyAction','cancel')
+set(handles.RUN,'BackgroundColor',[1 0 0])
+
+%----------------------------------------------
+
+%----------------------------------------------------
+function first_i_Callback(hObject, eventdata, handles)
+last_i_Callback(hObject, eventdata, handles)
+
+%----------------------------------------------
+function last_i_Callback(hObject, eventdata, handles)
+ hseries=get(handles.last_i,'parent');
+first_i=str2num(get(handles.first_i,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+ref_i=ceil((first_i+last_i)/2);
+set(handles.ref_i,'String', num2str(ref_i))
+ref_i_Callback(hObject, eventdata, handles)
+SeriesData=get(hseries,'UserData');
+if ~isfield(SeriesData,'Time')
+ SeriesData.Time{1}=[];
+end
+displ_time(handles,SeriesData.Time{1});
+
+%-------------------------------------------------------
+function first_j_Callback(hObject, eventdata, handles)
+ last_j_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------
+function last_j_Callback(hObject, eventdata, handles)
+ hseries=get(handles.last_i,'parent');
+first_j=str2num(get(handles.first_j,'String'));
+last_j=str2num(get(handles.last_j,'String'));
+ref_j=ceil((first_j+last_j)/2);
+set(handles.ref_j,'String', num2str(ref_j))
+
+ref_j_Callback(hObject, eventdata, handles)
+SeriesData=get(hseries,'UserData');
+if ~isfield(SeriesData,'Time')
+ SeriesData.Time{1}=[];
+end
+displ_time(handles,SeriesData.Time{1});
+
+
+
+
+%-------------------------------------------------------
+function ref_i_Callback(hObject, eventdata, handles)
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+hseries=get(handles.ref_i,'parent');
+SeriesData=get(hseries,'UserData');
+%NomTypeCell=get(handles.NomType,'String');
+NomTypeCell=SeriesData.NomType;
+if ~isempty(NomTypeCell)
+Val=get(handles.NomType,'Value');
+NomType=NomTypeCell{Val};
+% for ilist=1:length(NomType)
+ if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
+ if isequal(mode,'series(Di)')
+ find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
+% break
+ end
+ end
+end
+
+%----------------------------------------------------
+function ref_j_Callback(hObject, eventdata, handles)
+mode_list=get(handles.mode,'String');
+mode_value=get(handles.mode,'Value');
+mode=mode_list{mode_value};
+hseries=get(handles.ref_i,'parent');
+SeriesData=get(hseries,'UserData');
+%NomTypeCell=get(handles.NomType,'String');
+NomTypeCell=SeriesData.NomType;
+if ~isempty(NomTypeCell)
+Val=get(handles.NomType,'Value');
+NomType=NomTypeCell{Val};
+% NomType=get(handles.NomType,'String');
+ if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
+ if isequal(mode,'series(Dj)')
+ find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
+% break
+ end
+ end
+end
+
+%----------------------------------------------------
+% --- Executes on selection change in ACTION.
+function ACTION_Callback(hObject, eventdata, handles)
+list_ACTION=get(handles.ACTION,'String');% list menu fields
+index_ACTION=get(handles.ACTION,'Value');% selected string index
+ACTION= list_ACTION{index_ACTION}; % selected function name
+path_series=which('series');%path to series.m
+list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
+nb_builtin=0;
+for ilist=1:length(list_path)
+ if isequal(list_path{ilist},path_series)
+ nb_builtin=nb_builtin+1;
+ else
+ break
+ end
+end
+if nb_builtin==0% the path of series has been changed, reinitialize
+ series_OpeningFcn(hObject, eventdata, handles)
+ return
+end
+
+% add a new function to the menu
+if isequal(ACTION,'more...')
+ pathfct=fileparts(path_series);
+ browse_name=fullfile(path_series,'SERIES_FCT');%go to UVMAT/SERIES_FCT by default
+ if length(list_path)>nb_builtin
+ browse_name=list_path{end};% initialize browser with the path of the last introduced function
+ end
+ [FileName, PathName, filterindex] = uigetfile( ...
+ {'*.m', ' (*.m)';
+ '*.m', '.m files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',browse_name);
+ if length(FileName)<2
+ return
+ end
+ ext_fct=FileName(end-1:end);
+ if ~isequal(ext_fct,'.m')
+ msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
+ return
+ end
+ ACTION=FileName(1:end-2);% ACTION choice updated by the selected item
+
+ % insert the choice in the action menu
+ menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
+ index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
+ list_path{index_ACTION}=PathName;
+ if length(menu_str)>nb_builtin+5;
+ nbremove=length(menu_str)-nb_builtin-5;
+ menu_str(nb_builtin+1:end-5)=[];
+ list_path(nb_builtin+1:end-4)=[];
+ index_ACTION=index_ACTION-nbremove;
+ set(handles.ACTION,'Value',index_ACTION)
+ set(handles.ACTION,'String',menu_str)
+ end
+ list_path{index_ACTION}=PathName;
+ set(handles.ACTION,'UserData',list_path);
+ set(handles.path,'enable','inactive')% indicate that the current path is accessible (not 'off')
+
+ %record the current menu in personal file profil_perso
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ for ilist=nb_builtin+1:length(menu_str)-1
+ series_fct{ilist-nb_builtin}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);
+ end
+ if exist(profil_perso,'file')
+ save(profil_perso,'series_fct','-append')
+ else
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ save(profil_perso,'series_fct','-V6')
+ else
+ save(profil_perso, 'series_fct')
+ end
+ end
+end
+
+%check the current path to the selected function
+PathName=list_path{index_ACTION};%current recorded path
+if ~isequal(path_series,PathName)
+ CurrentPath=fileparts(which(ACTION));
+ if ~isequal(PathName,CurrentPath)
+ addpath(PathName)
+ errormsg=check_functions;
+ msgbox_uvmat('CONFIRMATION',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
+ end
+end
+set(handles.path,'String',PathName); %show the path to the senlected function
+
+%default setting for the visibility of the GUI elements
+%set( handles.Field,'Visible','off')%default
+set(handles.RootPath,'UserData','many')
+set(handles.SubDir,'Visible','on')
+set(handles.RootFile,'Visible','on')
+set(handles.NomType,'Visible','on')
+set(handles.FileExt,'Visible','on')
+set(handles.NbSlice,'Visible','off')
+set(handles.NbSlice_title,'Visible','off')
+set(handles.VelTypeMenu,'Visible','off');
+set(handles.VelType_text,'Visible','off');
+set(handles.VelTypeMenu_1,'Visible','off');
+set(handles.VelType_text_1,'Visible','off');
+view_FieldMenu(handles,'off')
+view_FieldMenu_1(handles,'off')
+view_TRANSFORM(handles,'off')
+set(handles.ProjObject_frame,'Visible','off');
+set(handles.GetMask,'Visible','off')
+set(handles.Mask,'Visible','off')
+set(handles.GetObject,'Visible','off');
+set(handles.ProjObject,'Visible','off');
+set(handles.OutputDir,'Visible','off');
+set(handles.PARAMETERS_frame,'Visible','off');
+set(handles.PARAMETERS_title,'Visible','off');
+set(handles.ParamKey,'Visible','off')
+set(handles.ParamVal,'Visible','off')
+ParamKey={};
+set(handles.FieldMenu,'Enable','off')
+set(handles.VelTypeMenu,'Enable','off')
+set(handles.FieldMenu_1,'Enable','off')
+set(handles.VelTypeMenu_1,'Enable','off')
+set(handles.CoordType,'Enable','off')
+%set the displayed GUI item needed for input parameters
+%list_input=feval(ACTION);% input list asked by the selected function
+varargout=feval(ACTION);% input list asked by the selected function
+Param_list={};
+% RootPath=get(handles.RootPath,'String');
+% RootFile=get(handles.RootFile,'String');
+
+%nb_series=length(RootFile);
+FileExt=get(handles.FileExt,'String');
+nb_series=length(FileExt);
+testima_series=1; %test for a list of images only
+testima=1;
+testima_1=1;
+testciv_series=1;
+for iview=1:nb_series
+ ext=FileExt{iview};
+ if length(ext)<2
+ ext='.none';
+ end
+ testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
+ if ~testimaview
+ if iview==1
+ testima=0;
+ end
+ if iview==2
+ testima_1=0;
+ end
+ testima_series=0;
+ end
+end
+for ilist=1:length(varargout)-1
+ switch varargout{ilist}
+ %RootFile always visible
+ case 'RootPath' %visible by default
+ value=lower(varargout{ilist+1});
+ if isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
+ set(handles.RootFile,'UserData',value)% for use in menu Open_insert
+ end
+ case 'SubDir' %visible by default
+ if isequal(lower(varargout{ilist+1}),'off')
+ set(handles.SubDir,'Visible','off')
+ end
+ case 'RootFile' %visible by default
+ value=lower(varargout{ilist+1});
+ if isequal(value,'off')
+ set(handles.RootFile,'Visible','off')
+ elseif isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
+ set(handles.RootFile,'Visible','on')
+ set(handles.RootFile,'UserData',value)% for use in menu Open_insert
+ end
+ case 'NomType' %visible by default
+ if isequal(lower(varargout{ilist+1}),'off')
+ set(handles.NomType,'Visible','off')
+ end
+ case 'FileExt' %visible by default
+ if isequal(lower(varargout{ilist+1}),'off')
+ set(handles.FileExt,'Visible','off')
+ end
+ case 'NbSlice' %hidden by default
+ if isequal(lower(varargout{ilist+1}),'on')
+ set(handles.NbSlice,'Visible','on')
+ set(handles.NbSlice_title,'Visible','on')
+ end
+ case 'VelTypeMenu' %hidden by default
+ if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
+ set(handles.VelTypeMenu,'Enable','on')
+ if nb_series >=1 && ~testima_series
+ set(handles.VelTypeMenu,'Visible','on')
+ set(handles.VelType_text,'Visible','on');
+ set(handles.Field_frame,'Visible','on')
+ end
+ end
+ if isequal(lower(varargout{ilist+1}),'two')
+ set(handles.VelTypeMenu_1,'Enable','on')
+ if nb_series >=2 && ~testima_series
+ set(handles.VelTypeMenu_1,'Visible','on')
+ set(handles.VelType_text_1,'Visible','on');
+ end
+ end
+ case 'FieldMenu' %hidden by default
+ if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
+ set(handles.FieldMenu,'Enable','on') % test for MenuBorser
+ if nb_series >=1 && ~testima_series
+ view_FieldMenu(handles,'on')
+ end
+ end
+ if isequal(lower(varargout{ilist+1}),'two')
+ set(handles.FieldMenu_1,'Enable','on')
+ if nb_series >=2 && ~testima_1
+ view_FieldMenu_1(handles,'on')
+ end
+ end
+ case 'CoordType' %hidden by default
+ if isequal(lower(varargout{ilist+1}),'on')
+ set(handles.CoordType,'Enable','on')
+ view_TRANSFORM(handles,'on')
+ end
+ case 'GetObject' %hidden by default
+ if isequal(lower(varargout{ilist+1}),'on')
+ set(handles.ProjObject_frame,'Visible','on')
+ set(handles.GetObject,'Visible','on');
+ end
+ case 'Mask' %hidden by default
+ if isequal(lower(varargout{ilist+1}),'on')
+ set(handles.ProjObject_frame,'Visible','on')
+ set(handles.GetMask,'Visible','on');
+ end
+ case 'PARAMETER'
+ set(handles.PARAMETERS_frame,'Visible','on')
+ set(handles.PARAMETERS_title,'Visible','on')
+ set(handles.ParamKey,'Visible','on')
+ %set(handles.ParamVal,'Visible','on')
+ Param_str=varargout{ilist+1};
+ Param_list=[Param_list; {Param_str}];
+ end
+end
+if ~isempty(Param_list)
+ set(handles.ParamKey,'String',Param_list)
+ set(handles.ParamVal,'Visible','on')
+end
+
+%-------------------------------------------------------------------
+% --- Executes on selection change in FieldMenu.
+%-------------------------------------------------------------------
+function FieldMenu_Callback(hObject, eventdata, handles)
+
+field_str=get(handles.FieldMenu,'String');
+field_index=get(handles.FieldMenu,'Value');
+field=field_str{field_index(1)};
+if isequal(field,'get_field...')
+ hget_field=findobj(allchild(0),'name','get_field');
+ if ~isempty(hget_field)
+ delete(hget_field)%delete opened versions of get_field
+ end
+ hseries=get(handles.FieldMenu,'parent');
+ SeriesData=get(hseries,'UserData');
+ filename=SeriesData.CurrentInputFile;
+ if exist(filename,'file')
+ get_field(filename)
+ end
+elseif isequal(field,'more...')
+ str=calc_field;
+ [ind_answer,v] = listdlg('PromptString','Select a file:',...
+ 'SelectionMode','single',...
+ 'ListString',str);
+ % edit the choice in the fields and action menu
+ scalar=cell2mat(str(ind_answer));
+ update_menu(handles.FieldMenu,scalar)
+end
+
+%------------------------------------------------------
+% --- Executes on selection change in FieldMenu_1.
+%-----------------------------------------------------
+function FieldMenu_1_Callback(hObject, eventdata, handles)
+field_str=get(handles.FieldMenu_1,'String');
+field_index=get(handles.FieldMenu_1,'Value');
+field=field_str{field_index};
+if isequal(field,'get_field...')
+ hget_field=findobj(allchild(0),'name','get_field_1');
+ if ~isempty(hget_field)
+ delete(hget_field)
+ end
+ hseries=get(handles.FieldMenu,'parent');
+ SeriesData=get(hseries,'UserData');
+ filename=SeriesData.CurrentInputFile_1;
+ if exist(filename,'file')
+ hget_field=get_field(filename);
+ set(hget_field,'name','get_field_1')
+ end
+elseif isequal(field,'more...')
+ str=calc_field;
+ [ind_answer,v] = listdlg('PromptString','Select a file:',...
+ 'SelectionMode','single',...
+ 'ListString',str);
+ % edit the choice in the fields and action menu
+ scalar=cell2mat(str(ind_answer));
+ update_menu(handles.FieldMenu_1,scalar)
+end
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %detect the chosen series of files and check their date of modification:
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%INPUT:
+%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
+%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
+%OTHER INPUTS given by the structure Series
+function GUI_input=check_files(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param);
+
+%requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1_cell','var')
+ GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+ 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+ 'RootFile';'on';... %root input file name ('on' by default)
+ 'FileExt';'on';... %input file extension ('on' by default)
+ 'NomType';'on';...%type of file indexing ('on' by default)
+ 'NbSlice';'on'; ...%nbre of slices ('off' by default)
+ %'VelTypeMenu';'on';...% menu for selecting the velocity type (civ1,..) 'off' by default)
+ %'FieldMenu';'on';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+ %'CoordType';'on'...%can use a transform function 'off' by default
+ %'GetObject';'on'...%can use projection object ,'off' by default
+ %'GetMask';'on'...%can use mask option ,'off' by default
+ %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
+ ''};
+ return %exit the function
+end
+
+%standard parameters for waitbar and STOP action (do not modify)
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position');
+
+%%%%%%%%%%%%%%%%%%%%%%%%
+
+% number of slices
+NbSlice=str2num(get(hseries.NbSlice,'String'));
+if isempty(NbSlice)
+ NbSlice=1;
+end
+NbSlice_name=num2str(NbSlice);
+if isequal(NbSlice,[]),NbSlice=1; end; %default
+
+% number of views
+count=0;
+testcell=iscell(Series.RootFile);
+if ~testcell
+ Series.RootPath={Series.RootPath};
+ Series.RootFile={Series.RootFile};
+ Series.SubDir={Series.SubDir};
+ Series.FileExt={Series.FileExt};
+ Series.NomType={Series.NomType};
+end
+nbview=length(Series.RootFile);
+for iview=1:nbview
+ filebase=fullfile(Series.RootPath{iview},Series.RootFile{iview});%root file name
+ if testcell
+ num_i1=num_i1_cell{iview}; num_i2=num_i2_cell{iview}; num_j1=num_j1_cell{iview}; num_j2=num_j2_cell{iview};
+ else
+ num_i1=num_i1_cell; num_i2=num_i2_cell; num_j1=num_j1_cell; num_j2=num_j2_cell;
+ end
+ siz=size(num_i1);
+ nbfield2=siz(1); %nb of consecutive fields at each level(burst
+ nbfield=siz(1)*siz(2);
+ nbfield=floor(nbfield/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
+ if isequal(lower(Series.FileExt{iview}),'.avi')
+ info=aviinfo([filebase Series.FileExt{iview}]);
+ message{1}=info.Filename;
+ message{2}=info.FileModDate;
+ message{3}=[num2str(info.FramesPerSecond) ' frames/s '];
+ message{4}=info.ImageType;
+ message{5}=[' compression' info.VideoCompression];
+ message{6}=[ 'quality ' num2str(info.Quality)];
+ Tabchar=message;
+ else
+ datnum=[];
+ Tabchar={};
+ %LOOP ON SLICES
+ for i_slice=1:NbSlice
+ for ifield=1:nbfield
+ indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice
+ end
+ for index=1:nbfield*nbfield2
+ stopstate=get(hseries.RUN,'BusyAction');
+ if isequal(stopstate,'queue')% enable STOP command
+ update_waitbar(hseries.waitbar,WaitbarPos,index/(nbfield*nbfield2))
+ ifile=indselect(index);
+ file=...
+ name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2(ifile),num_j2(ifile),Series.SubDir{iview});
+ [Path,Name,ext]=fileparts(file);
+ detect=exist(file,'file'); % check the existence of the file
+ if detect==0
+ count=count+1;
+ lastfield='not found';
+ else
+ datfile=dir(file);
+ datnum(ifile)=datenum(datfile.date);
+ filefound(ifile)={datfile.name};
+ lastfield='';
+ if isequal(Series.FileExt{iview},'.nc') || isequal(Series.FileExt{iview},'.cdf')
+ % check the content netcdf file
+ Data=nc2struct(file,'ListGlobalAttribute','patch2','fix2','civ2','patch','fix','absolut_time_T0','hart');
+ lastfield='civ1'; %default
+ if ~isempty(Data.patch2) && isequal(Data.patch2,1)
+ lastfield='patch2';
+ elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
+ lastfield='fix2';
+ elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
+ lastfield='civ2';
+ elseif ~isempty(Data.patch) && isequal(Data.patch,1);
+ lastfield='patch1';
+ elseif ~isempty(Data.fix) && isequal(Data.fix,1);
+ lastfield='fix1';
+ elseif ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
+ lastfield='civ1';
+ end
+% Data=nc2struct(file,[]);
+% lastfield='civ1'; %default
+% if isfield(Data,'patch2') & isequal(Data.patch2,1);
+% lastfield='patch2';
+% elseif isfield(Data,'fix2') & isequal(Data.fix2,1);
+% lastfield='fix2';
+% elseif isfield(Data,'civ2') & isequal(Data.civ2,1);
+% lastfield='civ2';
+% elseif isfield(Data,'patch') & isequal(Data.patch,1);
+% lastfield='patch1';
+% elseif isfield(Data,'fix') & isequal(Data.fix,1);
+% lastfield='fix1';
+% elseif isfield(Data,'absolut_time_T0') & isfield(Data,'hart')
+% lastfield='civ1';
+% end
+
+ end
+ end
+ Tabchar(1,i_slice)={['slice #' num2str(i_slice)]};
+ Tabchar(index+1,i_slice)={[file ' ' lastfield]};
+ end
+ end
+ end
+ if isempty(datnum)
+ if NbSlice>1
+ message=['no set of ' num2str(NbSlice) ' (NbSlices) files found'];
+ else
+ message='no file found';
+ end
+ else
+ datnum=datnum(find(datnum));%keep the non zero values corresponding to existing files
+ [first,ind]=min(datnum);
+ [last,indlast]=max(datnum);
+ message={['oldest modification: ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
+ ['latest modification: ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
+ end
+ if ~isempty(Tabchar)
+ Tabchar=reshape(Tabchar,NbSlice*(nbfield*nbfield2+1),1);
+ end
+ end
+ hfig=figure(iview);
+ clf
+ if iview>1
+ pos=get(iview-1,'Position');
+ pos(1)=pos(1)+(iview-1)*pos(1)/nbview;
+ set(hfig,'Position',pos)
+ end
+ set(hfig,'name',['view= ' num2str(iview)])
+
+ h=uicontrol('Style','listbox', 'Position', [20 20 500 300], 'String', Tabchar, 'Callback', @ncbrowser_uvmat);
+ hh=uicontrol('Style','listbox', 'Position', [20 340 500 40], 'String', message);
+end
+%----------------------------------------------------
+% determine the list of index pairs of processing file
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [num_i1,num_i2,num_j1,num_j2,num_i_out,num_j_out]=find_file_indices(num_i,num_j,ind_shift,NomType,mode)
+num_i1=num_i;% set of first image numbers by default
+num_i2=num_i;
+num_j1=num_j;
+num_j2=num_j;
+num_i_out=num_i;
+num_j_out=num_j;
+if isequal (NomType,'_i1-i2_j') |isequal (NomType,'_i1-i2')
+ num_i1_line=num_i+ind_shift(3);% set of first image numbers
+ num_i2_line=num_i+ind_shift(4);
+ % adjust the first and last field number
+ indsel=find(num_i1_line >= 1);
+ num_i_out=num_i(indsel);
+ num_i1_line=num_i1_line(indsel);
+ num_i2_line=num_i2_line(indsel);
+ num_j1=meshgrid(num_j,ones(size(num_i1_line)));
+ num_j2=meshgrid(num_j,ones(size(num_i1_line)));
+ [xx,num_i1]=meshgrid(num_j,num_i1_line);
+ [xx,num_i2]=meshgrid(num_j,num_i2_line);
+elseif isequal (NomType,'_i_j1-j2') || isequal (NomType,'#_ab')
+ if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
+ num_j1=ind_shift(1)*ones(size(num_i));
+ num_j2=ind_shift(2)*ones(size(num_i));
+ else
+ num_j1_col=num_j+ind_shift(1);% set of first image numbers
+ num_j2_col=num_j+ind_shift(2);
+ % adjust the first field number
+ indsel=find((num_j1_col >= 1));
+ num_j_out=num_j(indsel);
+ num_j1_col=num_j1_col(indsel);
+ num_j2_col=num_j2_col(indsel);
+ [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
+ [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
+ end
+end
+
+
+%----------------------------------------------------------------------
+% --- make average on a series of files
+%----------------------------------------------------------------------
+%INPUT:
+%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
+%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
+%OTHER INPUTS given by the structure Series
+% Series.Time:
+% Series.GeometryCalib:
+function GUI_input=aver_stat(num_i1,num_i2,num_j1,num_j2,Series)
+%requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1','var')
+ GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+ 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+ 'RootFile';'on';... %root input file name ('on' by default)
+ 'FileExt';'on';... %input file extension ('on' by default)
+ 'NomType';'on';...%type of file indexing ('on' by default)
+ 'NbSlice';'on'; ...%nbre of slices ('off' by default)
+ 'VelTypeMenu';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default)
+ 'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+ 'CoordType'; 'on';...%can use a transform function
+ 'GetObject';'on';...%can use projection object(option 'off'/'one'/'two',
+ %'GetMask';'on'...%can use mask option
+ %'PARAMETER'; %options: name of the user defined parameter',repeat a line for each parameter
+ ''};
+ return
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position');
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%root input file and type
+if ~iscell(Series.RootPath)% case of a single input field series
+ num_i1={num_i1};num_j1={num_j1};num_i2={num_i2};num_j2={num_j2};
+ RootPath={Series.RootPath};
+ RootFile={Series.RootFile};
+ SubDir={Series.SubDir};
+ FileExt={Series.FileExt};
+ NomType={Series.NomType};
+else
+ RootPath=Series.RootPath;
+ RootFile=Series.RootFile;
+ SubDir=Series.SubDir;
+ NomType=Series.NomType;
+ FileExt=Series.FileExt;
+end
+ext=FileExt{1};
+form=imformats(ext([2:end]));%test valid Matlab image formats
+testima=0;
+if ~isempty(form)||isequal(lower(ext),'.avi')||isequal(lower(ext),'.vol')
+ testima(1)=1;
+end
+if length(FileExt)>=2
+ ext_1=FileExt{2};
+ form=imformats(ext_1([2:end]));%test valid Matlab image formats
+ if ~isempty(form)||isequal(lower(ext_1),'.avi')||isequal(lower(ext_1),'.vol')
+ testima(2)=1;
+ end
+ if testima(2)~=testima(1)
+ msgbox_uvmat('ERROR','images and netcdf files cannot be compared')
+ return
+ end
+end
+
+%Number of input series: this function accepts two input file series at most (then it operates on the difference of fields)
+nbview=length(RootPath);
+if nbview>2
+ RootPath=RootPath(1:2);
+ set(hseries.RootPath,'String',RootPath)
+ SubDir=SubDir(1:2);
+ set(hseries.SubDir,'String',SubDir)
+ RootFile=RootFile(1:2);
+ set(hseries.RootFile,'String',RootFile)
+ NomType=NomType(1:2);
+ FileExt=FileExt(1:2);
+ set(hseries.FileExt,'String',FileExt)
+ nbview=2;
+end
+hhh=which('mmreader');
+for iview=1:nbview
+ test_movie(iview)=0;
+ if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
+ if isequal(lower(FileExt{iview}),'.avi')
+ MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
+ test_movie(iview)=1;
+ end
+ end
+end
+
+% number of slices
+NbSlice=str2num(get(hseries.NbSlice,'String'));
+if isempty(NbSlice)
+ NbSlice=1;
+end
+NbSlice_name=num2str(NbSlice);
+
+% Field and velocity type (the same for the two views)
+Field_str=get(hseries.FieldMenu,'String');
+FieldName=[]; %default
+testfield=get(hseries.FieldMenu,'Visible');
+if isequal(testfield,'on')
+ val=get(hseries.FieldMenu,'Value');
+ FieldName=Field_str(val);%the same set of fields for all views
+ if isequal(FieldName,{'get_field...'})
+ hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
+ if length(hget_field)>1
+ delete(hget_field(2:end))
+ elseif isempty(hget_field)
+ filename=...
+ name_generator(fullfile(RootPath{1},RootFile{1}),num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1});
+ get_field(filename);
+ return
+ end
+ hhget_field=guidata(hget_field);%handles of GUI elements in get_field
+ SubField=read_var_names(hhget_field); %read the names of the variables to plot in the get_field GUI
+ end
+end
+%detect whether the two files are 'images' or 'netcdf'
+testima=0;
+testvol=0;
+testcivx=0;
+testnc=0;
+FileExt=get(hseries.FileExt,'String');
+% test_movie=0;
+for iview=1:nbview
+ ext=FileExt{iview};
+ form=imformats(ext([2:end]));
+ if isequal(lower(ext),'.vol')
+ testvol=testvol+1;
+ elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
+ testima=testima+1;
+ elseif isequal(ext,'.nc')
+ testnc=testnc+1;
+ end
+end
+if testvol
+ msgbox_uvmat('ERROR','volume images not implemented yet')
+ return
+end
+if testnc~=nbview && testima~=nbview && testvol~=nbview
+ msgbox_uvmat('ERROR','compare two image series or two netcdf files with the same fields as input')
+ return
+end
+if ~isequal(FieldName,{'get_field...'})
+ testcivx=testnc;
+end
+
+if testcivx
+ VelType_str=get(hseries.VelTypeMenu,'String');
+ VelType_val=get(hseries.VelTypeMenu,'Value');
+ VelType{1}=VelType_str{VelType_val};
+ if nbview==2
+ VelType_str=get(hseries.VelTypeMenu_1,'String');
+ VelType_val=get(hseries.VelTypeMenu_1,'Value');
+ VelType{2}=VelType_str{VelType_val};
+ end
+end
+
+%Calibration data and timing: read the ImaDoc files
+mode=''; %default
+timecell={};
+itime=0;
+NbSlice_calib={};
+for iview=1:nbview%Loop on views
+ XmlData{iview}=[];%default
+ filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
+ if exist([filebase{iview} '.xml'],'file')
+ [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
+ if isfield(XmlData{iview},'Time')
+ itime=itime+1;
+ timecell{itime}=XmlData{iview}.Time;
+ end
+ if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
+ NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
+ if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
+ msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
+ end
+ end
+ elseif exist([filebase{iview} '.civ'],'file')
+ [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
+ itime=itime+1;
+ timecell{itime}=time;
+ XmlData{iview}.Time=time;
+ GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
+ GeometryCalib.Tx=0;
+ GeometryCalib.Ty=0;
+ GeometryCalib.Tz=1;
+ GeometryCalib.dpx=1;
+ GeometryCalib.dpy=1;
+ GeometryCalib.sx=1;
+ GeometryCalib.Cx=0;
+ GeometryCalib.Cy=0;
+ GeometryCalib.f=1;
+ GeometryCalib.kappa1=0;
+ GeometryCalib.CoordUnit='cm';
+ XmlData{iview}.GeometryCalib=GeometryCalib;
+ if error==1
+ msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
+ end
+ end
+end
+
+%check coincidence in time
+multitime=0;
+if length(timecell)==0
+ time=[];
+elseif length(timecell)==1
+ time=timecell{1};
+elseif length(timecell)>1
+ multitime=1;
+ for icell=1:length(timecell)
+ if ~isequal(size(timecell{icell}),size(timecell{1}))
+ msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
+ time=timecell{1};
+ multitime=0;
+ break
+ end
+ end
+end
+if multitime
+ for icell=1:length(timecell)
+ time(icell,:,:)=timecell{icell};
+ end
+ diff_time=max(max(diff(time)));
+ if diff_time>0
+ msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
+ end
+end
+if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file'
+ time=[];
+end
+
+% Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
+filebasesub=fullfile(RootPath{1},SubDir{1},RootFile{1});
+if isempty(SubDir{1}) % create a subdirectory '/mean'
+ subdir_result='mean';
+% filebasemean=fullfile(RootPath{1},subdir_result);
+ if ~exist(fullfile(RootPath{1},subdir_result),'dir')
+ dircur=pwd; %record current working directory
+ cd(RootPath{1})% goes to the iamge directory
+ [m1,m2,m3]=mkdir(subdir_result);
+ if ~isequal(m2,'')
+ msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation
+ end
+ cd(dircur) %back to the initial working directory
+ end
+ filebase_out=filebase{1};
+else
+ subdir_result=SubDir{1};
+ filebase_out=[filebase{1} '_mean'];% output root name obtained by adding the suffix _mean to the input
+end
+%output nomtype (to generalise)
+NomTypeOut=nomtype2pair(NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1));
+
+if NbSlice==1
+ filebase_out=[filebasesub '_mean'];
+else
+ filebase_out=[filebasesub '_' NbSlice_name 'mean'];
+ answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
+ if ~isequal(answeryes,'Yes')
+ return
+ end
+end
+
+% coordinate transform or other user defined transform
+Coord_menu=get(hseries.CoordType,'String');
+menu_val=get(hseries.CoordType,'Value');
+usrfct=Coord_menu{menu_val};
+testfct=~isequal(usrfct,'');
+
+%slice loop
+siz=size(num_i1{1});
+lengthtot=siz(1)*siz(2);
+nbfield=floor(lengthtot/(siz(1)*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
+nbfield_slice=nbfield*siz(1);% number of fields per slice
+
+for i_slice=1:NbSlice
+ S=0; %initiate the image sum S
+ nbfiles=0;
+ nbmissing=0;
+ %averaging loop
+ for ifile=i_slice:NbSlice:lengthtot
+ stopstate=get(hseries.RUN,'BusyAction');
+ if isequal(stopstate,'queue') % enable STOP command
+ update_waitbar(hseries.waitbar,WaitbarPos,ifile/lengthtot)
+ for iview=1:nbview
+ [filename]=...
+ name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
+ if testima
+ Data{iview}.ListVarName={'A'};
+ Data{iview}.AName='image';
+ if test_movie(iview)
+ Data{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile));
+ else
+ Data{iview}.A=read_image(filename,NomType{iview},num_i1{iview}(ifile));% read the image, num2 is the counter for avi files
+ end
+ Atype{iview}=class(Data{iview}.A);
+ Data{iview}.A=double(Data{iview}.A);
+ elseif testcivx
+ [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
+ else
+ [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data
+ Data{iview}.VarAttribute=SubField.VarAttribute;
+ end
+ if isfield(Data{iview},'Txt')
+ msgbox_uvmat('ERROR',['error of input reading: ' Data{iview}.Txt])
+ return
+ end
+ end
+ % coordinate transform (or other user defined transform)
+ if ~isequal(Series.CoordType,'')
+ % z index
+ if ~isempty(NbSlice_calib)
+ Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;%Zindex for phys transform
+ end
+ if nbview==2
+ [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
+ if isempty(Data{2})
+ Data(2)=[];
+ end
+ else
+ Data{1}=feval(Series.CoordType,Data{1},XmlData);
+ end
+ end
+ if testcivx
+ Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
+ end
+ if length(Data)==2
+ [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
+ if ~isempty(errormsg)
+ msgbox_uvmat('ERROR',['error in aver_stat/sub_field:' errormsg])
+ return
+ end
+ else
+ Field=Data{1};
+ end
+ if isfield(Series,'ProjObject')
+ [Field,errormsg]=proj_field(Field,Series.ProjObject);
+ if ~isempty(errormsg)
+ msgbox_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg])
+ return
+ end
+ end
+ nbfiles=nbfiles+1;
+ if nbfiles==1 %first field
+ time_1=[];
+ if isfield(Field,'Time')
+ time_1=Field.Time(1);
+ end
+ DataMean=Field;%default
+ else
+ for ivar=1:length(Field.ListVarName)
+ VarName=Field.ListVarName{ivar};
+ eval(['sizmean=size(DataMean.' VarName ');']);
+ eval(['siz=size(Field.' VarName ');']);
+ if ~isequal(siz,sizmean)
+ warndlg_uvmat(['unequal size of input field ' VarName ', need to interpolate on a grid'],'WARNING')
+ nbmissing=nbmissing+1;
+ break
+ else
+ eval(['DataMean.' VarName '=DataMean.' VarName '+ Field.' VarName ';']); % update the sum
+ end
+ end
+ end
+% else
+% nbmissing=nbmissing+1;
+% end
+ end
+ end %end averaging loop
+ for ivar=1:length(Field.ListVarName)
+ VarName=Field.ListVarName{ivar};
+ eval(['DataMean.' VarName '=DataMean.' VarName '/nbfiles;']); % normalize the mean
+ end
+ if nbmissing~=0
+ msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted'])
+ end
+ if isempty(time) % time read from files prevails
+ time_end=[];
+ if isfield(Field,'Time')
+ time_end=Field.Time(1);%last time read
+ if ~isempty(time_1)
+ DataMean.Time=time_1;
+ DataMean.Time_end=time_end;
+ end
+ end
+ else % time from ImaDoc prevails
+ DataMean.Time=time(1,num_i1{1}(1),num_j1{1}(1));
+ DataMean.Time_end=time(end,num_i1{end}(end),num_j1{end}(end));
+ end
+
+ %writing the result file
+ if testima
+ if NbSlice==1
+ [filemean]=name_generator(filebase_out,num_i1{1}(1),num_j1{1}(1),'.png',NomTypeOut,1,num_i2{end}(end),num_j2{end}(end));
+ else % label the file number by the slice # for simplicity
+ [filemean]=name_generator(filebase_out,i_slice,1,'.png','_i');
+ end
+ if exist(filemean,'file')
+ backupfile=filemean;
+ testexist=2;
+ while testexist==2
+ backupfile=[backupfile(1:end-4) '~.png'];
+ testexist=exist(backupfile,'file');
+ end
+ [success,message]=copyfile(filemean,backupfile);%make backup
+ if ~isequal(success,1)
+ msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup'])
+ return
+ end
+ end
+ if isequal(Atype{1},'uint16')
+ imwrite(uint16(DataMean.A),filemean,'BitDepth',16);
+ else
+ imwrite(uint8(DataMean.A),filemean,'BitDepth',8);
+ end
+ display([filemean ' written']);
+ else %determine global attributes
+ DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {Series.Action}];
+ ActionKey='Action';
+ while isfield(DataMean,ActionKey)
+ ActionKey=[ActionKey '_1'];
+ end
+ eval(['DataMean.' ActionKey '=Series.Action;'])
+ DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {ActionKey}];
+ if isfield(DataMean,'Time')
+ DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {'Time','Time_end'}];
+ end
+ if NbSlice==1
+ filemean=name_generator(filebase_out,num_i1{1}(1),num_j1{1}(1),'.nc',NomTypeOut,1,num_i2{end}(end),num_j2{end}(end));
+ else % label the file number by the slice # for simplicity
+ [filemean]=name_generator(filebase_out,i_slice,1,'.nc','_i');
+ end
+ if exist(filemean,'file')
+ backupfile=filemean;
+ testexist=2;
+ while testexist==2
+ backupfile=[backupfile(1:end-3) '~.nc'];
+ testexist=exist(backupfile,'file');
+ end
+ [success,message]=copyfile(filemean,backupfile);%make backup
+ if ~isequal(success,1)
+ msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup'])
+ display(['previous file result ' filemean ' already exists, problem in backup'])
+ return
+ end
+ end
+ errormsg=struct2nc(filemean,DataMean); %save result file
+ if isempty(errormsg)
+ display([filemean ' written']);
+ else
+ msgbox_uvmat('ERROR',['error in writting result file: ' errormsg])
+ display(errormsg)
+ end
+ end
+end
+hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
+delete(hget_field)
+uvmat(filemean)
+
+
+% %----------------------------------------------------------------------
+% % --makes a time averaged velocity field
+% %----------------------------------------------------------------------
+% function aver_vel(num_i1,num_i2,num_j1,num_j2,Series)
+% %handles of the GUI series
+%
+% hseries=guidata(Series.hseries);%handles of the GUI series
+% WaitbarPos=get(hseries.waitbar_frame,'Position');
+% Field_list=get(hseries.FieldMenu,'String');
+% val=get(hseries.FieldMenu,'Value');
+% FieldName=Field_list{val(1)};
+% set(hseries.FieldMenu,'Value',val(1))% select only one input field
+% if isequal(FieldName,'get_field...')
+% hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
+% end
+% %root input file and type
+% RootPath=get(hseries.RootPath,'String');
+% SubDir=get(hseries.SubDir,'String');
+% RootFile=get(hseries.RootFile,'String');
+% %NomType=get(hseries.NomType,'String');
+% NomType=Series.NomType;
+% FileExt=get(hseries.FileExt,'String');
+% ext=FileExt{1};
+% VelType_str=get(hseries.VelTypeMenu,'String');
+% VelType_val=get(hseries.VelTypeMenu,'Value');
+% VelType{1}=VelType_str{VelType_val};
+%
+% time=0; %default
+% % number of slices
+% NbSlice=str2num(get(hseries.NbSlice,'String'));
+% if isempty(NbSlice)
+% NbSlice=1;
+% end
+% NbSlice_name=num2str(NbSlice);
+% filebase=fullfile(RootPath{1},RootFile{1});
+% Calib=[];
+% if exist([filebase '.xml'],'file')
+% %[error,Heading,nom_type_read,ext_ima_read,time_imadoc,TimeUnit,mode,NbSlice,npx,npy,Calib]=read_imadoc([filebase '.xml']);
+% [XmlData,warntext]=imadoc2struct([filebase '.xml']);
+% end
+% if NbSlice==1
+% filebase_mean=[filebase '_mean']; %root name for the result
+% else
+% filebase_mean=[filebase '_' NbSlice_name 'mean']; %root name for the results
+% answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_mean ' ...']});
+% if ~isequal(answeryes,'Yes')
+% return
+% end
+% end
+% siz=size(num_i1);
+% nbfield2=siz(1); %nb of consecutive fields at each level(burst)
+% lengthtot=siz(1)*siz(2);
+% nbfield=floor(lengthtot/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
+% nbfield_slice=nbfield*nbfield2;% number of fields per slice
+% %projection object
+% GridX=[];
+% GridY=[];
+% if isfield(Series,'sethandles')
+% Series.ProjObject=read_set_object(Series.sethandles);
+% if isfield(Series.ProjObject,'Style')
+% answeryes=questdlg({['statistics on field series projected on ' Series.ProjObject.Style]});
+% if ~isequal(answeryes,'Yes')
+% return
+% end
+% end
+% end
+%
+% %LOOP ON SLICES
+% for i_slice=1:NbSlice
+% %select the series of image indices at the level islice
+% for ifield=1:nbfield
+% indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice
+% end
+% %name of result file
+% [filemean,idetect]=...
+% name_generator(filebase_mean,num_i1(i_slice),num_j1(1),Series.FileExt{1},'_i1-i2_j1-j2',1,num_i2(i_slice+nbfield_slice*NbSlice-1),num_j2(end),Series.SubDir{1});
+%
+% % field=get(handles.civ1,'UserData');%read current selected field type (civ1,civ2...)
+% itime=0;
+% dt=[];
+% %LOOP ON FIELDS IN A SLICE
+% test_interpolate=0;%default
+% for index=1:nbfield*nbfield2
+% ifile=indselect(index);
+% stopstate=get(hseries.RUN,'BusyAction');
+% if isequal(stopstate,'queue')% enable STOP command
+% update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield*nbfield2))
+% %name of the current file
+% [filename,idetect]=name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt{1},Series.NomType{1},1,num_i2(ifile),num_j2(ifile),Series.SubDir{1});
+% %read input file
+% itime=itime+1;
+% if isequal(FieldName,'get_field...')
+% hhget_field=guidata(hget_field);%handles of GUI elements in get_field
+% hObject=0;
+% eventdata=0;
+% SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI
+% [Data,var_detect]=nc2struct(filename,SubField.ListVarName); %read input data
+% time(itime)=itime;
+% dt=1;
+% Calib_read=[];
+% else
+% [nb_coord,nb_dim,Civ,CivStage,timeread,Data,VelTypeOut,Calib_read]=read_ncfield(filename,VelType{1});%reading the first file
+% time(itime)=timeread;
+% if isequal(Civ,1)
+% Data.CoordType='px';%test for pixel coordinates
+% if isequal(itime,1)
+% dt=Data.dt;
+% elseif ~isequal(Data.dt,dt)
+% warndlg_uvmat('series with non constant dt, need phys coordinates','ERROR')
+% return
+% end
+% end
+% end
+% %increment the detected fields, skip the others
+% if idetect==0
+% warndlg_uvmat(['input file ' filename ' not found'],'ERROR')
+% %A FAIRE STOCKER LE RESULT ACTUEL S'IL EXISTE
+% end
+% % itime=itime+1;
+% % time(itime)=timeread;
+%
+% %coordinate transform
+% if isempty(Calib)
+% Calib=Calib_read;%use Calib from xml file in priority, then Calib from the current file
+% end
+% if ~isequal(Series.CoordType,'')
+% Data=feval(Series.CoordType,Data,Calib);
+% end
+% %projection on object if defined
+% if isfield(Series,'ProjObject');
+% Data=proj_field(Data,Series.ProjObject);
+% if isequal(itime,1)%use the positions on the first field for the whole series, ou utiliser grille
+% if isfield(Data,'Txt')%display error message
+% warndlg(Data.Txt,'ERROR')
+% return
+% end
+% end
+% else%remove false vectors and interpolate on the positions of the first field
+% Data=document_field(Data);
+% Data.Style='plane';
+% end
+% %%%%%%%%% initiate the average at the first iteration: check list and structure of variables
+% if ifile==i_slice%first field in the slice
+% testfalse=0;
+% ListIndex={};
+% testnewcell=1;
+% %group the variables (fields of 'Data') in cells of variables with the same dimensions
+% [DimVarIndex,CellVarIndex]=find_field_indices(Data);
+% VarIndex=CellVarIndex{1}; % ONLY THE FIRST VAR GROUP IS AVERAGED
+% DimIndex=Data.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
+% MeanData=Data;%transfer heading
+% MeanData.Time=[time(1) time(end)];
+% MeanData.Action=Series.Action;%name of the processing programme
+% MeanData.ListDimName=Data.ListDimName(DimIndex);%name of dimension
+% MeanData.DimValue=Data.DimValue(DimIndex);%values of dimension (nbre of vectors)
+% MeanData.ListVarName=Data.ListVarName;
+% MeanData.VarDimIndex=Data.VarDimIndex;
+% MeanData.ListVarAttribute={'Role'};%list of variable attribute names A FAIRE: transferer les autres attributs
+% testsum=ones(size(VarIndex));
+% indexfalse=0;
+% CoordName={};
+% indexremove=[];
+% if isfield(Data,'Role') % look for coordinate and flag variables
+% for ivar=1:length(VarIndex)
+% VarName=Data.ListVarName{VarIndex(ivar)};
+% var_role=Data.Role{VarIndex(ivar)};%'role' of the variable
+% MeanData.Role{ivar}=var_role;
+% if isequal(var_role,'falseflag')
+% indexfalse=ivar; %test for false flag
+% indexremove=ivar;
+% FFName=VarName;
+% testsum(ivar)=0;
+% eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable
+% end
+% if isequal(var_role,'warnflag')
+% testsum(ivar)=0; %do not sum warn flag
+% eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable
+% indexremove=[indexremove ivar];
+% end
+% if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|isequal(var_role,'coord_z')
+% eval(['MeanData.' VarName '=Data.' VarName ';']);
+% testsum(ivar)=0;
+% eval(['CoordName=[CoordName ''' VarName '''];']);
+% end
+% if testsum(ivar)~=0
+% eval(['MeanData.' VarName '=zeros(size(Data.' VarName '));']);%initialise sum
+% end
+% end
+% end
+% findsum=find(testsum);
+% VarIndexSum=VarIndex(findsum);%indices of variables to sum (not coordinates nor flags)
+% if length(CoordName)==0
+% if isempty(DimVarIndex)|isequal(DimVarIndex,0)% no coordinate variable for structured coordinates, prepare histograms
+% for ilist=1:length(VarIndexSum)
+% VarName=Data.ListVarName{VarIndexSum(ilist)};
+% eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable
+% indexremove=[indexremove ilist];
+% eval(['[MeanData.' VarName 'hist,MeanData.' VarName 'val]=hist(Data.' VarName ',100);']);%make histo
+% eval(['sizhist=size(MeanData.' VarName 'hist);'])
+% if sizhist(1)==1
+% eval(['MeanData.' VarName 'hist=MeanData.' VarName 'hist'';'])
+% end
+% eval(['maxval=max(MeanData.' VarName 'val);']);
+% eval(['minval=min(MeanData.' VarName 'val);']);
+% dC(ilist)=(maxval-minval)/100;%size of the histogram bin
+% end
+% else
+% % icoord=0;
+% % for ilist=1:length(DimVarIndex)
+% % VarDim=Data.ListVarName{DimVarIndex(ilist)};
+% % icoord=icoord+1;
+% % % eval(['Coord{' num2str(icord) '}=[' CoordName ''' VarName ''']']);
+% % %eval(['Data.' CoordName{icoord} '=Data.' CoordName{icoord} '(indsel);']);
+% % end
+% end
+% end
+% if ~isempty(indexremove)
+% MeanData.ListVarName(VarIndex(indexremove))=[];
+% MeanData.VarDimIndex(VarIndex(indexremove))=[];
+% if isfield(MeanData,'Role')%generaliser aus autres attributs
+% MeanData.Role(VarIndex(indexremove))=[];
+% end
+% end
+% % END OF INITIALISATION
+%
+% end
+%
+% % A FAIRE: regular grid if coord_x undefined
+% if indexfalse~=0 %suppress false data
+% eval(['testexist=isfield(Data,''' FFName ''');'])
+% if testexist
+% eval(['indsel=find(Data.' FFName '==0);']);
+% for icoord=1:length(CoordName)
+% eval(['Data.' CoordName{icoord} '=Data.' CoordName{icoord} '(indsel);']);
+% end
+% end
+% end
+% for ilist=1:length(VarIndexSum)
+% VarName=Data.ListVarName{VarIndexSum(ilist)};
+% if indexfalse~=0 & testexist
+% eval(['Data.' VarName '=Data.' VarName '(indsel);']);
+% end
+% if length(CoordName)==0%no variable use dfor unstructured coordinates
+% if isempty(DimVarIndex)|isequal(DimVarIndex,0)% no coordinate variable for structured coordinates
+% % %update histogram with the current field #ifile
+% str_left=['[MeanData.' VarName 'val,MeanData.' VarName 'hist]='];
+% str_right=['hist_update(MeanData.' VarName 'val,MeanData.' VarName 'hist,Data.' VarName ',dC(ilist));'];
+% eval([str_left str_right]);%update global histo
+% else
+% %INTERPOLER
+%
+% eval(['MeanData.' VarName '=MeanData.' VarName '+Data.' VarName ';']);%increment sum%CAS x,y change
+% end
+% else
+% if length(CoordName)==2
+% eval(['test_interp= ~isequal(Data.' CoordName{1} ',MeanData.' CoordName{1} ...
+% ')|~isequal(Data.' CoordName{2} ',MeanData.' CoordName{2} ');'])
+% if test_interp
+% eval(['Data.' VarName '=griddata_uvmat(Data.' CoordName{1} ',Data.' CoordName{2}...
+% ',Data.' VarName ',MeanData.' CoordName{1} ',MeanData.' CoordName{2} ');']);
+% test_interpolate=1;
+% end
+% end
+% eval(['MeanData.' VarName '=MeanData.' VarName '+Data.' VarName ';']);%increment sum
+% end
+% end
+% end
+% end
+% if length(CoordName)~=0 | ~isequal(DimVarIndex,0)% no coordinate variable for structured coordinates
+% for ilist=1:length(VarIndexSum)
+% VarName=Data.ListVarName{VarIndexSum(ilist)};
+% eval(['MeanData.' VarName '=MeanData.' VarName '/itime;']);%normalize sum by the number of fields
+% end
+% else
+% MeanData.NbDim=1;
+% MeanData.ListDimName={};
+% MeanData.DimValue=[];
+% for ilist=1:length(VarIndexSum)
+% VarName=Data.ListVarName{VarIndexSum(ilist)};
+% MeanData.ListVarName=[MeanData.ListVarName {[VarName 'val']} {[VarName 'hist']}];
+% MeanData.VarDimIndex=[MeanData.VarDimIndex {[ilist]} {[ilist]}];
+% MeanData.ListDimName=[MeanData.ListDimName {[VarName 'val']}];
+% eval(['MeanData.DimValue=[MeanData.DimValue length(MeanData.' VarName 'val)];']);
+% end
+% end
+% figure
+% haxes=axes;
+% plot_field(MeanData,haxes)%plot the resulting average
+% % change variable names for consitency with civ1 data (need to generalize these programs)
+% if length(MeanData.ListVarName) >= 4 & isequal(MeanData.ListVarName(1:4), {'X' 'Y' 'U' 'V'})
+% MeanData.ListGlobalAttribute={'nb_coord','nb_dim','dt','absolut_time_T0','pixcmx','pixcmy','hart','civ','fix'};
+% MeanData.nb_coord=2;
+% MeanData.nb_dim=2;
+% MeanData.dt=1;
+% MeanData.absolut_time_T0=0;
+% MeanData.pixcmx=1; %pix per cm (1 by default)
+% MeanData.pixcmy=1; %pix per cm (1 by default)
+% MeanData.hart=0;
+% if isequal(Data.CoordType,'px')
+% MeanData.civ=1;
+% else
+% MeanData.civ=0;
+% end
+% MeanData.fix=0;
+% MeanData.ListVarName(1:4)={'vec_X' 'vec_Y' 'vec_U' 'vec_V'};
+% MeanData.vec_X=MeanData.X;
+% MeanData.vec_Y=MeanData.Y;
+% MeanData.vec_U=MeanData.U;
+% MeanData.vec_V=MeanData.V;
+% end
+% error=struct2nc(filemean,MeanData); %save result file
+% if isequal(error,0)
+% if test_interpolate
+% 'fields interpolated to the positions of the first one'
+% end
+% [filemean ' written']
+% else
+% warndlg_uvmat(error,'ERROR')
+% end
+% end
+
+%----------------------------------------------------------------------
+% --project fields on a projection object (e. g. a regular grid), possibly
+% merge several fields
+%----------------------------------------------------------------------
+%INPUT:
+%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
+%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
+%OTHER INPUTS given by the structure Series
+function GUI_input=merge_proj(num_i1,num_i2,num_j1,num_j2,Series);
+
+%requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1','var')
+ GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+ 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+ 'RootFile';'on';... %root input file name ('on' by default)
+ 'FileExt';'on';... %input file extension ('on' by default)
+ 'NomType';'on';...%type of file indexing ('on' by default)
+ 'NbSlice';'on'; ...%nbre of slices ('off' by default)
+ 'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
+ 'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+ 'CoordType';'on';...%can use a transform function 'off' by default
+ 'GetObject';'on';...%can use projection object ,'off' by default
+ %'GetMask';'on'...%can use mask option ,'off' by default
+ %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
+ ''};
+ return %exit the function
+end
+
+%-------------------------------------------------
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position'); %positiopn of waitbar frame
+%-------------------------------------------------
+
+%numbers of view fields (nbre of inputs in RootPath)
+testcell=iscell(Series.RootFile);
+if ~testcell
+ Series.RootPath={Series.RootPath};
+ Series.RootFile={Series.RootFile};
+ Series.SubDir={Series.SubDir};
+ Series.FileExt={Series.FileExt};
+ Series.NomType={Series.NomType};
+ num_i1={num_i1};
+ num_i2={num_i2};
+ num_j1={num_j1};
+ num_j2={num_j2};
+end
+nbview=length(Series.RootFile);%number of views (file series to merge)
+nbfield=size(num_i1{1},1)*size(num_i1{1},2);%number of fields in the time series
+transform=Series.CoordType; % field transform function
+hhh=which('mmreader');
+for iview=1:nbview
+ test_movie(iview)=0;
+ if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
+ if isequal(lower(FileExt{iview}),'.avi')
+ MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
+ test_movie(iview)=1;
+ end
+ end
+end
+
+%Calibration data and timing: read the ImaDoc files
+mode=''; %default
+timecell={};
+itime=0;
+NbSlice_calib={}; %test for z index
+for iview=1:nbview%Loop on views
+ XmlData{iview}=[];%default
+ filebase{iview}=fullfile(Series.RootPath{iview},Series.RootFile{iview});
+ if exist([filebase{iview} '.xml'],'file')
+ [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
+ if isfield(XmlData{iview},'Time')
+ itime=itime+1;
+ timecell{itime}=XmlData{iview}.Time;
+ end
+ if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
+ NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);
+ if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
+ msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
+ end
+ end
+ elseif exist([filebase{iview} '.civ'],'file')
+ [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
+ itime=itime+1;
+ timecell{itime}=time;
+ XmlData{iview}.Time=time;
+ GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
+ GeometryCalib.Tx=0;
+ GeometryCalib.Ty=0;
+ GeometryCalib.Tz=1;
+ GeometryCalib.dpx=1;
+ GeometryCalib.dpy=1;
+ GeometryCalib.sx=1;
+ GeometryCalib.Cx=0;
+ GeometryCalib.Cy=0;
+ GeometryCalib.f=1;
+ GeometryCalib.kappa1=0;
+ GeometryCalib.CoordUnit='cm';
+ XmlData{iview}.GeometryCalib=GeometryCalib;
+ if error==1
+ msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
+ end
+ end
+end
+
+%check coincidence in time
+multitime=0;
+if length(timecell)==0
+ time=[];
+elseif length(timecell)==1
+ time=timecell{1};
+elseif length(timecell)>1
+ multitime=1;
+ for icell=1:length(timecell)
+ if ~isequal(size(timecell{icell}),size(timecell{1}))
+ msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
+ time=timecell{1};
+ multitime=0;
+ break
+ end
+ end
+end
+if multitime
+ for icell=1:length(timecell)
+ time(icell,:,:)=timecell{icell};
+ end
+ diff_time=max(max(diff(time)));
+ if diff_time>0
+ msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
+ end
+end
+if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file'
+ time=[];
+end
+
+% Field and velocity type (the same for all views)
+Field_str=get(hseries.FieldMenu,'String');
+val=get(hseries.FieldMenu,'Value');
+FieldName=Field_str(val);%the same set of fields for all views
+VelType_str=get(hseries.VelTypeMenu,'String');
+VelType_val=get(hseries.VelTypeMenu,'Value');
+VelType=VelType_str{VelType_val}; %the same for all views
+if isequal(FieldName,'get_field...')
+ hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
+ hhget_field=guidata(hget_field);%handles of GUI elements in get_field
+ SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI
+ if isequal(get(hhget_field.menu_coord,'Visible'),'on')
+ list_transform=get(hhget_field.menu_coord,'String');
+ val_list=get(hhget_field.menu_coord,'Value');
+ transform=list_transform{val_list};
+ end
+end
+%detect whether all the files are 'images' or 'netcdf'
+testima=0;
+testvol=0;
+testcivx=0;
+testnc=0;
+FileExt=get(hseries.FileExt,'String');
+for iview=1:nbview
+ ext=FileExt{iview};
+ form=imformats(ext([2:end]));
+ if isequal(lower(ext),'.vol')
+ testvol=testvol+1;
+ elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
+ testima=testima+1;
+ elseif isequal(ext,'.nc')
+ testnc=testnc+1;
+ end
+end
+if testvol
+ msgbox_uvmat('ERROR','volume images not implemented yet')
+ return
+end
+if testnc~=nbview && testima~=nbview && testvol~=nbview
+ msgbox_uvmat('ERROR','need a set of images or a set of netcdf files with the same fields as input')
+ return
+end
+if ~isequal(FieldName,'get_field...')
+ testcivx=testnc;
+end
+%name of output files and directory:
+% res_subdir=fullfile(Series.RootPath{1},[Series.SubDir{1} '_STAT']);
+ProjectDir=fileparts(fileparts(Series.RootPath{1}));% preoject directory (GERK)
+prompt={['result directory (in' ProjectDir ')']};
+RootPath=get(hseries.RootPath,'String');
+SubDir=get(hseries.SubDir,'String');
+if isequal(length(RootPath),1)
+ fulldir=RootPath{1};
+ subdir='GRID';
+ res_subdir=fullfile(fulldir,subdir);
+else
+ def={fullfile(ProjectDir,'0_RESULTS')};
+ dlgTitle='result directory';
+ lineNo=1;
+ answer=msgbox_uvmat('INPUT_TXT',dlgTitle,def);
+ fulldir=answer{1};
+ subdir=[];
+ dirlist=sort(Series.RootFile);
+ for iview=1:nbview
+ if ~isempty(subdir)
+ subdir=[subdir '-'];
+ end
+ subdir=[subdir dirlist{iview}];
+ end
+ res_subdir=fullfile(fulldir,subdir);
+end
+ext=FileExt{1};
+if ~exist(fulldir,'dir')
+ msgbox_uvmat('ERROR',['directory ' fulldir ' needs to be created'])
+ return
+end
+if ~exist(res_subdir,'dir')
+ dircur=pwd;
+ cd(fulldir)
+ error=mkdir(subdir);
+ cd(dircur)
+end
+filebasesub=fullfile(res_subdir,Series.RootFile{1});
+filebase_merge=fullfile(res_subdir,'merged');%root name for the merged files
+
+%projection object
+if isfield(Series,'sethandles')
+ if ishandle(Series.sethandles.set_object)
+ Series.ProjObject=read_set_object(Series.sethandles);
+ if ~isfield(Series.ProjObject,'Style')
+ msgbox_uvmat('ERROR','Undefined projection object style')
+ return
+ end
+ if ~isequal(Series.ProjObject.Style,'plane')
+ msgbox_uvmat('ERROR','The projection object must be a plane')
+ return
+ end
+ end
+end
+
+ %MAIN LOOP
+for ifile=1:nbfield
+ stopstate=get(hseries.RUN,'BusyAction');
+ if isequal(stopstate,'queue')% enable STOP command from the 'series' interface
+ update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
+ Amerge=0;
+
+ %----------LOOP ON VIEWS----------------------
+ nbtime=0;
+ for iview=1:nbview
+ %name of the current file
+ filename=name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
+ if ~exist(filename,'file')
+ msgbox_uvmat('ERROR',['missing input file' filename])
+ break
+ end
+
+ %reading the current file
+ if testima
+ if test_movie(iview)
+ Field{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile));
+ else
+ Field{iview}.A=read_image(filename,Series.NomType{iview},num_i1{iview}(ifile));
+ end % TODO: introduce ListVarName
+ npxy=size(Field{iview}.A);
+ Field{iview}.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
+ Field{iview}.AY=[npxy(1)-0.5 0.5];
+ Field{iview}.CoordType='px';
+ Field{iview}.AName='image';
+ else
+ if testcivx
+ [Field{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
+ else
+ [Field{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data
+ Field{iview}.VarAttribute=SubField.VarAttribute;
+ end
+ if isfield(Field{iview},'Time')
+ timeread(iview)=Field{iview}.Time;
+ nbtime=nbtime+1;
+ end
+ end
+ % coord transform
+ % z index
+ if ~isempty(NbSlice_calib)
+ Field{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
+ end
+ if ~isequal(transform,'')
+ Field{iview}=feval(Series.CoordType,Field{iview},XmlData{iview});%transform to phys if requested
+ end
+ if testcivx
+ Field{iview}=calc_field(FieldName,Field{iview});
+ end
+
+ %projection on object (gridded plane)
+ if isfield(Series,'ProjObject')
+ Field{iview}=proj_field(Field{iview},Series.ProjObject);
+ end
+ end
+
+ %----------END LOOP ON VIEWS----------------------
+
+ %merge the nbview fields
+ MergeData=merge_field(Field);
+ if isfield(MergeData,'Txt')
+ msgbox_uvmat('ERROR',MergeData.Txt)
+ return
+ end
+
+ % generating the name of the merged field
+ mergename=name_generator(filebase_merge,num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile));
+
+ % time:
+ time_i=0;%default
+ if isempty(time)% time from ImaDoc prevails
+ time_i=sum(timeread)/nbtime;
+ else
+ time_i=(time(iview,num_i1{iview}(ifile),num_j1{iview}(ifile))+time(iview,num_i2{iview}(ifile),num_j2{iview}(ifile)))/2;
+ end
+
+ % recording the merged field
+ if testima %in case of input images an image is produced
+ if isa(MergeData.A,'uint8')
+ bitdepth=8;
+ elseif isa(MergeData.A,'uint16')
+ bitdepth=16;
+ end
+ imwrite(MergeData.A,mergename,'BitDepth',bitdepth);
+ %write xml calibration file
+ siz=size(MergeData.A);
+ npy=siz(1);
+ npx=siz(2);
+ if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1')
+ Rangx=MergeData.VarAttribute{1}.Coord_2;
+ Rangy=MergeData.VarAttribute{1}.Coord_1;
+ elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
+ Rangx=[MergeData.AX(1) MergeData.AX(end)];
+ Rangy=[MergeData.AY(1) MergeData.AY(end)];
+ else
+ Rangx=[0.5 npx-0.5];
+ Rangy=[npy-0.5 0.5];%default
+ end
+ pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
+ pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
+ T_x=-pxcmx*Rangx(1)+0.5;
+ T_y=-pxcmy*Rangy(2)+0.5;
+ GeometryCal.focal=1;
+ GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
+ GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
+ ImaDoc.GeometryCalib=GeometryCal;
+ t=struct2xml(ImaDoc);
+ t=set(t,1,'name','ImaDoc');
+ save(t,[filebase_merge '.xml'])
+ display([filebase_merge '.xml saved'])
+ else
+ MergeData.ListGlobalAttribute={'Project','InputFile_1','InputFile_end','nb_coord','nb_dim','dt','Time','civ'};
+ MergeData.nb_coord=2;
+ MergeData.nb_dim=2;
+ MergeData.dt=1;
+ MergeData.Time=time_i;
+ error=struct2nc(mergename,MergeData); %save result file
+ if isempty(error)
+ display(['output file ' mergename ' written'])
+ else
+ display(error)
+ end
+ end
+ end
+end
+
+%--------------------------------------------------------------------------
+function MergeData=merge_field(Data)
+% initiate Matlab structure for physical field
+if isempty(Data)||~iscell(Data)
+ MergeData=[];
+ return
+end
+MergeData=Data{1};%default
+error=0;
+nbview=length(Data);
+if nbview==1
+ return
+end
+for iview=1:nbview
+ if ~isequal(MergeData.ListDimName,Data{iview}.ListDimName)
+ error=1;
+ end
+ if ~isequal(MergeData.ListVarName,Data{iview}.ListVarName)
+ error=1;
+ end
+% if ~isequal(MergeData.VarDimIndex,Data{iview}.VarDimIndex)
+% error=1;
+% end
+end
+if error
+ MergeData.Txt='ERROR: attempt at merging fields of incompatible type';
+ return
+end
+%group the variables (fields of 'FieldData') in cells of variables with the same dimensions
+%-----------------------------------------------------------------
+[CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1});
+%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+% CellVarIndex=cells of variable index arrays
+ivar_new=0; % index of the current variable in the projected field
+icoord=0;
+for icell=1:length(CellVarIndex)
+ if NbDim(icell)==1
+ continue
+ end
+ VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
+ VarType=VarTypeCell{icell};
+ ivar_X=VarType.coord_x;
+ ivar_Y=VarType.coord_y;
+ ivar_FF=VarType.errorflag;
+ if isempty(ivar_X)
+ test_grid=1;%test for input data on regular grid (e.g. image)coordinates
+ else
+ if length(ivar_Y)~=1
+ msgbox_uvmat('ERROR','y coordinate missing in proj_field.m')
+ return
+ end
+ test_grid=0;
+ end
+ % DimIndices=Data{1}.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
+ %case of input fields with unstructured coordinates
+ if ~test_grid
+ for ivar=VarIndex
+ VarName=MergeData.ListVarName{ivar};
+ for iview=1:nbview
+ eval(['MergeData.' VarName '=[MergeData.' VarName '; Data{iview}.' VarName ';'])
+ end
+ end
+ %case of fields defined on a structured grid
+ else
+% DimValue=MergeData.DimValue(DimIndices);%set of dimension values
+ testFF=0;
+ for iview=2:nbview
+% if ~isequal(DimValue,Data{iview}.DimValue(DimIndices))
+% MergeData.Txt='ERROR: attempt at merging structured fields with different sizes';
+% return
+% end
+ for ivar=VarIndex
+ VarName=MergeData.ListVarName{ivar};
+ if isfield(MergeData,'VarAttribute')
+ if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag')
+ testFF=1;
+ end
+ end
+ eval(['MergeData.' VarName '=MergeData.' VarName '+ Data{iview}.' VarName ';'])
+ end
+ end
+ if testFF
+ nbaver=nbview-MergeData.FF;
+ indgood=find(nbaver>0);
+ for ivar=VarIndex
+ VarName=MergeData.ListVarName{ivar};
+ eval(['MergeData.' VarName '(indgood)=double(MergeData.' VarName '(indgood))./nbaver(indgood);'])
+ end
+ else
+ for ivar=VarIndex
+ VarName=MergeData.ListVarName{ivar};
+ eval(['MergeData.' VarName '=double(MergeData.' VarName ')./nbview;'])
+ end
+ end
+ end
+end
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %detect the chosen series of files and check their date of modification:
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%INPUT:
+%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
+%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
+%OTHER INPUTS given by the structure Series
+function GUI_input=clean_civ_cmx(num_i1,num_i2,num_j1,num_j2,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param);
+
+%requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1','var')
+ GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+ 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+ %'RootFile';'on';... %root input file name ('on' by default)
+ %'FileExt';'on';... %input file extension ('on' by default)
+ %'NomType';'on';...%type of file indexing ('on' by default)
+ %'NbSlice';'on'; ...%nbre of slices ('off' by default)
+ %'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
+ %'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+ %'CoordType';'on'...%can use a transform function 'off' by default
+ %'GetObject';'on'...%can use projection object ,'off' by default
+ %'GetMask';'on'...%can use mask option ,'off' by default
+ %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
+ ''};
+ return %exit the function
+end
+%---------------------------------------------------------
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position');
+
+%%%%%%%%%%%%%%%%%%%%%%%%
+message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)';
+answer=msgbox_uvmat('INPUT_Y-N',message);
+if ~isequal(answer,'Yes')
+ return
+end
+nbdelete=0;
+testcell=iscell(Series.RootFile);
+if ~testcell
+ Series.RootPath={Series.RootPath};
+ Series.RootFile={Series.RootFile};
+ Series.SubDir={Series.SubDir};
+ Series.FileExt={Series.FileExt};
+ Series.NomType={Series.NomType};
+end
+for iview=1:length(Series.RootFile)
+ hdir=dir(fullfile(Series.RootPath{iview},Series.SubDir{iview}));%list files
+ for ilist=1:length(hdir)
+ update_waitbar(hseries.waitbar,WaitbarPos,ilist/length(hdir))
+ FileName=hdir(ilist).name;
+ [dd,ff,Ext]=fileparts(FileName);
+ if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors')
+ delete(fullfile(Series.RootPath{iview},Series.SubDir{iview},FileName))
+ nbdelete=nbdelete+1;
+ end
+ end
+end
+msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete) ' files deleted by clean_civ_cmx'])
+
+
+
+
+
+%-----------------------------
+function mouse_up_gui(ggg,eventdata,handles)
+if isequal(get(ggg,'SelectionType'),'alt')
+ display('global CurData, UserData of GUI series')
+ global CurData
+ CurData=get(ggg,'UserData');
+ evalin('base','global CurData');%make CurData global in the workspace
+ evalin('base','CurData'); %display CurData in the workspace
+ commandwindow
+ % plot_text(CurData)
+end
+
+
+
+% %----------------------------------------------------------------------
+% % --- display image movie and display time average
+% %OBSOLETE: A SUPPRIMER
+% %----------------------------------------------------------------------
+% function movie_ima(handles,filecell,filecell_1,num1,num_a,field)
+%
+% global hfig1 hfig2 hfig3 poscolbar
+% global A val HIST
+%
+% A=[];aviobj=[];
+% % set(hfig1,'UserData','ima')% set the current field state to 'image'
+% set(handles.zoom,'Value',1); %put zoom on
+% nom_type=get(handles.file_input,'UserData');
+% % field=get(handles.civ1,'UserData');
+% % fields=field(1).fields;
+% set(handles.speed,'Visible','On')%show slider to set movie speed
+% set(handles.mo_speed_txt,'Visible','On')
+%
+% if ~isempty(filecell_1)
+% file1=get(handles.file1_input,'UserData');
+% field1=file1.field;
+% scal_type1=field1.fields;
+% vel_type1=field1.vel_type;
+% filename_1=filecell_1(1);% first file name in the series
+% else
+% filename_1=[];
+% end
+% scal_type{1}=field(1).fields;
+% vel_type{1}=field(1).vel_type;
+% % display the first field
+% [A,time,dt,rangx0,rangy0]=view_ima(handles,cell2mat(filecell(1)),filename_1,num1(1),num_a(1));
+%
+% % calculate the histogram of the first image
+% nxy=size(A);
+% ndim=length(nxy);
+% if ndim==2 % case of B/W images
+% nxy(3)=1;
+% end
+% C=reshape(A,nxy(1)*nxy(2),nxy(3));
+% Amaxmax=double(max(max(max(A))));
+% Aminmin=double(min(min(min(A))));
+% if isa(C,'uint8')|isa(C,'uint16')
+% C=double(C);
+% dC=1;
+% else
+% dC=(Amaxmax-Aminmin)/100;
+% end
+% val=[Aminmin:dC:Amaxmax];% define bins for histogram
+% HIST=hist(C,val);% initiate the global histogram
+% if ndim==2, HIST=HIST'; end;
+%
+% auto_scale=get(handles.auto_scale,'Value');
+% min_input=str2num(get(handles.min_input,'String'));% select the minimum
+% max_input=str2num(get(handles.scale_input,'String'));% select the max
+% zoomstate=get(handles.zoom,'Value');
+%
+% if isequal(get(handles.window_input,'String'),'avi'),
+% basename=get(handles.file_input,'String');
+% prompt = {'file name';'frames per second';'frame resolution ([nbpixels x y])';'axis position relative to the frame'};
+% dlg_title = 'select properties of the output avi movie';
+% num_lines= 1;
+% def = {[basename '_out.avi'];'5';'[1024 768]';'[0.05 0.07 0.87 0.88]'};
+% answer = inputdlg(prompt,dlg_title,num_lines,def);
+% aviname=answer{1};
+% fps=str2num(answer{2});
+% if exist(aviname,'file')==2
+% delete(aviname);
+% end;
+% aviobj=avifile(aviname,'Compression','None','fps',fps);
+%
+% %display first view for tests
+% figure(2);
+% hh=get(gcf,'CurrentAxes');
+% if isempty(hh),
+% hfig1=axes;
+% else
+% hfig1=hh;
+% end;
+% if isequal(filecell_1,{})
+% filename_1=[];
+% else
+% filename_1=cell2mat(filecell_1(1));
+% end
+% poscolbar=[0.93 0.15 0.02 0.7];
+% view_ima(handles,cell2mat(filecell(1)),filename_1,num1(1),num_a(1));% show the first field
+% nbpix=eval(answer{3});
+% set(gcf,'Position',[1 1 nbpix])% resolution XVGA
+% set(hfig1,'Position',eval(answer{4}));
+%
+% msgbox({'adjust figure 2 with its matlab edit menu ' ;...
+% 'then type any keyboard key to get the avi movie as a copy of figure 2 display'})
+% pause;
+% hh=colorbar;
+% poscolbar=get(hh,'Position');
+% end
+%
+% %%%%%%%%%%%%%%%%
+% %mask and usrdfct
+% maskname=[]; %default
+% if isequal(get(handles.mask_test,'Value'),1)
+% maskbase=get(handles.mask_test,'UserData');
+% end
+% % image or scalar processing programme set by user
+% % if (get(handles.usr_fct,'Value')==1)
+% % usrfct=get(handles.usr_fct,'UserData');
+% % else
+% % usrfct='';
+% % end
+% nburst=1; % nburst(1) =nbre of names in filename= nbre of bursts
+% set(handles.text_display_1,'String',['image movie'])
+% nbfield=length(filecell);
+% if nbfield >1
+% for ifile=2:nbfield
+% stopstate=get(handles.run0,'BusyAction');
+% if isequal(stopstate,'queue')% enable STOP command
+% pausetime=1.02-get(handles.speed,'Value');
+% pause(pausetime)
+% if isequal(get(handles.mask_test,'Value'),1)
+% maskname=name_generator(maskbase,num1(ifile),1,'.png','png_series');
+% end
+% if isequal(AName{1},'image')
+% A=read_image(cell2mat(filecell(ifile)),num1(ifile),maskname);% read the first image, num2 is the counter for avi files
+% else % read the first field from the netcdf file, imposing the pixel positions in the selected domain
+% [A,time(ifile),dtr,rgx,rgy,vt_out,erread]=read_scalar(filecell{ifile},vel_type,scal_type,rangx0,rangy0,nxy,maskname);
+% if erread==1;
+% errordlg({['no spatial derivative in ' filecell{ifile}]; 'run patch first'}); return
+% elseif erread==2;
+% errordlg(['no field ' vel_type{1} ' in ' filecell{ifile}]); return
+% elseif erread==3;
+% errordlg(['scalar ' scal_type{1} ' not found in' filecell{ifile}]); return
+% elseif erread==4;
+% errordlg(['all points aligned in' filecell{ifile}]); return
+% end
+% end
+%
+% % read the second image
+% if ~isempty(filecell_1)
+% if isequal(scal_type{1},'image')
+% A1=read_image(cell2mat(filecell_1(ifile)),num1(ifile),maskname);% read the second image, num2 is the counter for avi files
+% Avalue_1=double(A1(indy,indx,:));
+% else % read the second field from the netcdf file, imposing the pixel positions in the selected domain
+% [Avalue_1,time1(ifile),dtr,rgx,rgy,vt_out,erread]=read_scalar(filecell_1{ifile},{vel_type1},{scal_type1},rangx0,rangy0,npxy,maskname,usrfct);
+% if erread==1;
+% errordlg({['no spatial derivative in ' filecell_1{ifile}]; 'run patch first'}); return
+% elseif erread==2;
+% errordlg(['no field ' vel_type1 ' in ' filecell_1{ifile}]); return
+% elseif erread==3;
+% errordlg(['scalar ' scal_type1 ' not found in' filecell_1{ifile}]); return
+% elseif erread==4;
+% errordlg(['all points aligned in' filecell_1{ifile}]); return
+% end
+% end
+% time(ifile)=(time(ifile)+time1(ifile))/2;
+% Avalue=Avalue-Avalue_1;
+% end
+% set(handles.abs_time,'String',time);
+% set(handles.field_counter,'String',num2str(num1(ifile)));
+% set(handles.a_input,'String',num2stra(num_a(ifile),nom_type));
+% C=reshape(A,nxy(1)*nxy(2),nxy(3));% reshape in a vector
+% [val,HIST]=hist_update(val,HIST,C,dC);
+% [h,Amin,Amax]=plot_image(hfig1,rangx0,rangy0,1,scal_type{1},auto_scale,min_input,max_input,poscolbar,A);
+% set(handles.min_input,'String',num2str(Amin));% select the minimum
+% set(handles.scale_input,'String',num2str(Amax));% select the minimum
+% if ~isequal(aviobj,[]),
+% % mov=getframe(hfig1);
+% mov=getframe(gcf);
+% aviobj=addframe(aviobj,mov);end
+% if (get(handles.zoom,'Value') == get(handles.zoom,'Max')),zoom on,end
+% set(handles.field_counter,'String',num2str(num1(ifile)))
+% % end
+% end
+% end
+% end
+% aviobj=close(aviobj);
+%
+% %plot global image histogram
+% HIST=HIST/(nbfield*nxy(1)*nxy(2));% normalized by the number of points
+% axes(hfig2) %in main window
+% if ndim==2
+% plot(val,HIST)
+% else
+% plot(val,HIST(:,1),'r',val,HIST(:,2),'g',val,HIST(:,3),'b')
+% end
+% residu=1-sum(HIST,1);
+% title(['histo, residu ' num2str(residu)])
+% grid on
+% axes(hfig3)
+% cla %clear the second histogram window
+%
+
+
+%----------------------------------------------------------------------
+% --- make a time series analysis
+%----------------------------------------------------------------------
+%INPUT:
+%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
+%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
+%OTHER INPUTS given by the structure Series
+function GUI_input=time_series(num_i1,num_i2,num_j1,num_j2,Series)
+
+%requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1','var')
+ GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+ 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+ 'RootFile';'on';... %root input file name ('on' by default)
+ 'FileExt';'on';... %input file extension ('on' by default)
+ 'NomType';'on';...%type of file indexing ('on' by default)
+ 'NbSlice';'on'; ...%nbre of slices ('off' by default)
+ 'VelTypeMenu';'two';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
+ 'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+ 'CoordType';'on';...%can use a transform function 'off' by default
+ 'GetObject';'on';...%can use projection object ,'off' by default
+ %'GetMask';'on'...%can use mask option ,'off' by default
+ %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
+ ''};
+ return %exit the function
+end
+
+%------------------------------------------------------
+hseries=guidata(Series.hseries);%handles in the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position'); %position of the waitbar frame
+
+%projection object
+test_object=get(hseries.GetObject,'Value');
+if test_object%isfield(Series,'sethandles')
+ Series.ProjObject=read_set_object(Series.sethandles);
+ answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]});
+ if ~isequal(answeryes,'Yes')
+ return
+ end
+else
+ msgbox_uvmat('ERROR','a projection object is needed');
+ return
+end
+
+% root names
+if iscell(Series.RootPath)
+ RootPath=Series.RootPath;
+ RootFile=Series.RootFile;
+ SubDir=Series.SubDir;
+ FileExt=Series.FileExt;
+ NomType=Series.NomType;
+else
+ RootPath={Series.RootPath};
+ RootFile={Series.RootFile};
+ SubDir={Series.SubDir};
+ FileExt={Series.FileExt};
+ NomType={Series.NomType};
+ num_i1={num_i1};
+ num_i2={num_i2};
+ num_j1={num_j1};
+ num_j2={num_j2};
+end
+ext=FileExt{1};
+form=imformats(ext([2:end]));%test valid Matlab image formats
+testima=0;
+if ~isempty(form)||isequal(lower(ext),'.avi')
+ testima=1;
+end
+nbview=length(RootPath);%number of series (1 or 2)
+nbfield=size(num_i1{1},1)*size(num_i1{1},2); %number of fields in the time series
+
+%Number of input series: this function accepts only a single input file series
+nbview=length(RootPath);
+if nbview>2
+ RootPath=RootPath(1:2);
+ set(hseries.RootPath,'String',RootPath)
+ SubDir=SubDir(1:2);
+ set(hseries.SubDir,'String',SubDir)
+ RootFile=RootFile(1:2);
+ set(hseries.RootFile,'String',RootFile)
+ NomType=NomType(1:2);
+ %set(hseries.NomType,'String',NomType)
+ FileExt=FileExt(1:2);
+ set(hseries.FileExt,'String',FileExt)
+ nbview=2;
+end
+hhh=which('mmreader');
+for iview=1:nbview
+ test_movie(iview)=0;
+ if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
+ if isequal(lower(FileExt{iview}),'.avi')
+ MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
+ test_movie(iview)=1;
+ end
+ end
+end
+filebase{1}=fullfile(RootPath{1},RootFile{1});
+% FileDisplay=fullfile(RootPath{1},SubDir{1},RootFile{1});
+
+% number of slices
+NbSlice=str2num(get(hseries.NbSlice,'String'));
+if isempty(NbSlice)
+ NbSlice=1;
+end
+NbSlice_name=num2str(NbSlice);
+
+% Field and velocity type (the same for the two views)
+if isfield(Series,'Field')
+ FieldName=Series.Field;%the same set of fields for all views
+else
+ FieldName={''};
+end
+if isequal(FieldName,{'get_field...'})
+ hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
+ if length(hget_field)>1
+ delete(hget_field(2:end))
+ elseif isempty(hget_field)
+ filename=...
+ name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1});
+ idetect(iview)=exist(filename,'file');
+ hget_field=get_field(filename);
+ return
+ end
+ hhget_field=guidata(hget_field);%handles of GUI elements in get_field
+ SubField=read_var_names(hhget_field); %read the names of the variables to plot in the get_field GUI
+ if isequal(get(hhget_field.menu_coord,'Visible'),'on')
+ list_transform=get(hhget_field.menu_coord,'String');
+ val_list=get(hhget_field.menu_coord,'Value');
+ transform=list_transform{val_list};
+ end
+end
+
+%detect whether the two files are 'images' or 'netcdf'
+testima=0;
+testvol=0;
+testcivx=0;
+testnc=0;
+FileExt=get(hseries.FileExt,'String');
+for iview=1:nbview
+ ext=FileExt{iview};
+ form=imformats(ext([2:end]));
+ if isequal(lower(ext),'.vol')
+ testvol=testvol+1;
+ elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
+ testima=testima+1;
+ elseif isequal(ext,'.nc')
+ testnc=testnc+1;
+ end
+end
+if testvol
+ msgbox_uvmat('ERROR','volume images not implemented yet')
+ return
+end
+if testnc~=nbview && testima~=nbview && testvol~=nbview
+ msgbox_uvmat('need a set of images or a set of netcdf files with the same fields as input','ERROR')
+ return
+end
+if ~isequal(FieldName,{'get_field...'})
+ testcivx=testnc;
+end
+
+% Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
+filebasesub=fullfile(RootPath{1},RootFile{1});
+if NbSlice==1
+ filebase_out=[filebasesub '_time'];
+else
+ filebase_out=[filebasesub '_' NbSlice_name 'mtim'];
+ increment=num_i1{1}(2)-num_i1{1}(1);
+ if ~isequal(increment,1) % if an increment is set
+ answeryes=msgbox_uvmat('INPUT_Y-N',['will take time series in ' num2str(NbSlice) 'slices with increment = ' num2str(increment) '!'])
+ else
+ answeryes=msgbox_uvmat('INPUT_Y-N',{['will take time series in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
+ end
+ if ~isequal(answeryes,'Yes')
+ return
+ end
+end
+VelType_str=get(hseries.VelTypeMenu,'String');
+VelType_val=get(hseries.VelTypeMenu,'Value');
+VelType{1}=VelType_str{VelType_val};
+if nbview==2
+ VelType_str=get(hseries.VelTypeMenu_1,'String');
+ VelType_val=get(hseries.VelTypeMenu_1,'Value');
+ VelType{2}=VelType_str{VelType_val};
+end
+
+%Calibration data and timing: read the ImaDoc files
+mode=''; %default
+timecell={};
+XmlData={};
+itime=0;
+NbSlice_calib={};
+for iview=1:nbview%Loop on views
+ XmlData{iview}=[];%default
+ filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
+ if exist([filebase{iview} '.xml'],'file')
+ [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
+ if isfield(XmlData{iview},'Time')
+ itime=itime+1;
+ timecell{itime}=XmlData{iview}.Time;
+ end
+ if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
+ NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
+ if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
+ msgbox_uvmat('WARNING','inconsistent number of Z indices for the field series');
+ end
+ end
+ elseif exist([filebase{iview} '.civ'],'file')
+ [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
+ itime=itime+1;
+ timecell{itime}=time;
+ XmlData{iview}.Time=time;
+ GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
+ GeometryCalib.Tx=0;
+ GeometryCalib.Ty=0;
+ GeometryCalib.Tz=1;
+ GeometryCalib.dpx=1;
+ GeometryCalib.dpy=1;
+ GeometryCalib.sx=1;
+ GeometryCalib.Cx=0;
+ GeometryCalib.Cy=0;
+ GeometryCalib.f=1;
+ GeometryCalib.kappa1=0;
+ GeometryCalib.CoordUnit='cm';
+ XmlData{iview}.GeometryCalib=GeometryCalib;
+ if error==1
+ msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
+ end
+ end
+end
+
+%check coincidence in time
+multitime=0;
+if length(timecell)==0
+ time=[];
+elseif length(timecell)==1
+ time=timecell{1};
+elseif length(timecell)>1
+ multitime=1;
+ for icell=1:length(timecell)
+ if ~isequal(size(timecell{icell}),size(timecell{1}))
+ warndlg_uvmat('inconsistent time array dimensions in ImaDoc fields, the time for the first series is used','WARNING')
+ time=timecell{1};
+ multitime=0;
+ break
+ end
+ end
+end
+if multitime
+ for icell=1:length(timecell)
+ time(icell,:,:)=timecell{icell};
+ end
+ diff_time=max(max(diff(time)));
+ if diff_time>0
+ warndlg_uvmat(['times of series differ by more than ' num2str(diff_time)],'WARNING')
+ end
+end
+if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file'
+ time=[];
+end
+
+% image or scalar processing programme set by user
+Coord_menu=get(hseries.CoordType,'String');
+menu_val=get(hseries.CoordType,'Value');
+usrfct=Coord_menu{menu_val};
+testfct=~isequal(usrfct,'');
+
+% to update:
+VelType_str=get(hseries.VelTypeMenu,'String');
+VelType_val=get(hseries.VelTypeMenu,'Value');
+VelType{1}=VelType_str{VelType_val};
+if nbview==2
+ VelType_str=get(hseries.VelTypeMenu_1,'String');
+ VelType_val=get(hseries.VelTypeMenu_1,'Value');
+ VelType{2}=VelType_str{VelType_val};
+end
+
+%LOOP ON SLICES
+for i_slice=1:NbSlice
+ dt=[];
+ nbmissing=0; %number of undetected files
+ nbfiles=0;
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%LOOP ON FIELDS IN A SLICE
+ for ifile=i_slice:NbSlice:nbfield
+ stopstate=get(hseries.RUN,'BusyAction');
+ if isequal(stopstate,'queue')% enable STOP command
+ update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
+ for iview=1:nbview
+ filename=...
+ name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
+ idetect(iview)=exist(filename,'file');
+ Data{iview}=[]; %default
+ if testima
+ Data{iview}.ListVarName={'A'};
+ Data{iview}.AName='image';
+ if test_movie(iview)
+ A=read(MovieObject{iview},num_i1{iview}(ifile));
+ else
+ A=double(read_image(filename,NomType{iview},num_i1{iview}(ifile)));% read the image, num2 is the counter for avi files
+ end
+ Data{iview}.ListVarName={'coord_y','coord_x','A'}; %
+ npy=size(A,1);
+ npx=size(A,2);
+ nbcolor=size(A,3);
+ if nbcolor==3
+% Data{iview}.ListDimName={'coord_y','coord_x','rgb'};
+% Data{iview}.DimValue=[npy npx 3];
+% Data{iview}.VarDimIndex={[1 2 3]};
+ Data{iview}.VarDimName={'coord_y','coord_x',{'coord_y','coord_x','rgb'}};
+ else
+% Data{iview}.ListDimName={'coord_y','coord_x'};
+% Data{iview}.DimValue=[npy npx];
+% Data{iview}.VarDimIndex={[1 2]};
+% Data{iview}.VarAttribute{1}.Coord_1=[npy-0.5 0.5];
+% Data{iview}.VarAttribute{1}.Coord_2=[0.5 npx-0.5];
+ Data{iview}.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'}};
+ end
+ Data{iview}.coord_y=[npy-0.5 0.5];
+ Data{iview}.coord_x=[0.5 npx-0.5];
+ Data{iview}.A=A;
+ Data{iview}.CoordType='px';
+ elseif testcivx
+ [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
+ else
+ [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data
+ Data{iview}.VarAttribute=SubField.VarAttribute;
+ end
+ if ~isempty(NbSlice_calib) % z index
+ Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
+ end
+ end
+ % geometry transform or other user defined transform
+ if ~isequal(Series.CoordType,'')
+ if nbview==2
+ [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
+ if isempty(Data{2})
+ Data(2)=[];
+ end
+ else
+ Data{1}=feval(Series.CoordType,Data{1},XmlData{1});
+ end
+ end
+ if testcivx
+ Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
+ end
+ if length(Data)==2
+ [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
+ if ~isempty(errormsg)
+ msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg])
+ return
+ end
+ else
+ Field=Data{1};
+ end
+ if isfield(Series,'ProjObject')
+ [Field,errormsg]=proj_field(Field,Series.ProjObject);
+ if ~isempty(errormsg)
+ msgbox_uvmat('ERROR',['error in time_series/proj_field:' errormsg])
+ return
+ end
+ end
+ if min(idetect)>=1% the input file(s) have been detected
+ nbfiles=nbfiles+1;
+ if nbfiles==1 %first field: initiate the time series
+ RecordData=Field;%default
+ RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots
+ nbvar=length(Field.ListVarName);
+ if nbvar==0
+ msgbox_uvmat('ERROR','no input variable selected in get_field')
+ return
+ end
+ testsum=2*ones(1,nbvar);%initiate flag for action on each variable
+ indexfalse=0;
+ CoordName={};
+ indexremove=[];
+ if isfield(Field,'VarAttribute') % look for coordinate and flag variables
+ for ivar=1:nbvar
+ if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
+ var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
+ if isequal(var_role,'errorflag')
+ msgbox_uvmat('ERROR','do not handle error flags in time series')
+ return
+ end
+ if isequal(var_role,'warnflag')
+ testsum(ivar)=0; % not recorded variable
+ eval(['RecordData=rmfield(RecordData,''' Field.ListVarName{ivar} ''');']);%remove variable
+ end
+ if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|...
+ isequal(var_role,'coord_z')|isequal(var_role,'coord')
+ testsum(ivar)=1; %constant coordinates, record without time evolution
+ end
+ % check whether the variable ivar is a dimension variable
+ %index=Field.VarDimIndex{ivar};%dimension indices of the variable #ivar
+ DimCell=Field.VarDimName{ivar};
+ if ischar(DimCell)
+ DimCell={DimCell};
+ end
+ if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell)%TODO generalise with attribute
+ % if length(Field.ListDimName)>=index & isequal(Field.ListVarName{ivar},Field.ListDimName{index})%detect dimension variables
+ testsum(ivar)=1;
+ end
+ end
+ end
+ end
+ for ivar=1:nbvar
+ if testsum(ivar)==2
+ eval(['RecordData.' Field.ListVarName{ivar} '=[];'])
+ end
+ end
+ % RecordData.ListDimName=[{'Time'} RecordData.ListDimName];%name of dimension
+ RecordData.ListVarName=[{'Time'} RecordData.ListVarName];
+ end
+ for ivar=1:length(Field.ListVarName)
+ VarName=Field.ListVarName{ivar};
+ eval(['VarVal=Field.' VarName ';']);
+ if testsum(ivar)==2% test for recorded variable
+ eval(['VarVal=Field.' VarName ';']);
+ if isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
+ if isempty(VarVal)
+ msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))])
+ return
+ end
+ VarVal=mean(VarVal,1);
+ end
+ VarVal=shiftdim(VarVal,-1); %shift dimension
+ eval(['RecordData.' VarName '=cat(1,RecordData.' VarName ',VarVal);']);%concanete the current field to the time series
+ elseif testsum(ivar)==1% variable representing fixed coordinates
+ eval(['VarInit=RecordData.' VarName ';']);
+ if ~isequal(VarVal,VarInit)
+ msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName])
+ return
+ end
+ end
+ end
+ % time:
+ if isempty(time)% time read in ncfiles
+ if isfield(Field,'Time')
+ RecordData.Time(nbfiles,1)=Field.Time;
+ else
+ RecordData.Time(nbfiles,1)=nbfiles;%default
+ end
+ else % time from ImaDoc prevails
+ RecordData.Time(nbfiles,1)=(time(1,num_i1{1}(ifile),num_j1{1}(ifile))+time(end,num_i2{end}(ifile),num_j2{end}(ifile)))/2;
+ end
+ else
+ nbmissing=nbmissing+1;
+ end
+ end
+ end
+ %remove time for global attributes if exists
+ for iattr=1:numel(RecordData.ListGlobalAttribute)
+ if strcmp(RecordData.ListGlobalAttribute{iattr},'Time')
+ RecordData.ListGlobalAttribute(iattr)=[];
+ break
+ end
+ end
+ for ivar=1:numel(RecordData.ListVarName)
+ VarName=RecordData.ListVarName{ivar};
+ eval(['RecordData.' VarName '=squeeze(RecordData.' VarName ');']) %remove singletons
+ end
+ % add time dimension and update VarDimIndex:
+ %if ~isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
+ for ivar=1:length(Field.ListVarName)
+% vardimindex=Field.VarDimIndex{ivar};% array of dimension indices for variable VarIndex(ivar)
+ DimCell=Field.VarDimName(ivar);
+ if testsum(ivar)==2%variable used as time series
+% RecordData.VarDimIndex{ivar}=[1 vardimindex+1];
+ RecordData.VarDimName{ivar}=[{'Time'} DimCell];
+ elseif testsum(ivar)==1
+% RecordData.VarDimIndex{ivar}=[vardimindex+1];
+ RecordData.VarDimName{ivar}=DimCell;
+ end
+ end
+ % end
+ indexremove=find(~testsum);
+ if ~isempty(indexremove)
+ RecordData.ListVarName(1+indexremove)=[];
+ RecordData.VarDimName(indexremove)=[];
+ if isfield(RecordData,'Role')&~isempty(RecordData.Role{1})%generaliser aus autres attributs
+ RecordData.Role(1+indexremove)=[];
+ end
+ end
+ %RecordData.VarDimIndex=[{[1]} RecordData.VarDimIndex]; %time dimension
+ %shift variable attributes
+ if isfield(RecordData,'VarAttribute')
+ RecordData.VarAttribute=[{[]} RecordData.VarAttribute];
+ end
+ RecordData.VarDimName=[{'Time'} RecordData.VarDimName];
+ RecordData.Action=Series.Action;%name of the processing programme
+ %name of result file
+ [filemean]=...
+ name_generator(filebase_out,num_i1{1}(i_slice),num_j1{1}(i_slice),'.nc','_i1-i2_j1-j2',1,num_i2{end}(ifile),num_j2{end}(ifile),SubDir{1});
+ RecordData
+ RecordData.VarDimName{1}
+ RecordData.VarDimName{2}
+ RecordData.VarDimName{3}
+ errormsg=struct2nc(filemean,RecordData); %save result file
+ if isempty(errormsg)
+ display([filemean ' written'])
+ else
+ msgbox_uvmat('ERROR',['error in Series/struct2nc' errormsg])
+ end
+end
+figure
+haxes=axes;
+
+plot_field(RecordData,haxes)
+hget_field=findobj(allchild(0),'name','get_field');
+if ~isempty(hget_field)
+ delete(hget_field)
+end
+get_field(filemean,RecordData)
+
+%-----------------------------------------------------------------------
+% --- Executes on selection change in CoordType.
+function CoordType_Callback(hObject, eventdata, handles)
+menu_str=get(handles.CoordType,'String');
+ind_coord=get(handles.CoordType,'Value');
+coord_option=menu_str{ind_coord};
+if isequal(coord_option,'more...');
+ fct_name='';
+ if exist('./TMP/current_usr_fct.mat','file')% if a file is found
+ h=load('./TMP/current_usr_fct.mat');
+ if isfield(h,'fct_name');
+ fct_name=h.fct_name;
+ end
+ end
+ prompt = {'Enter the name of the transform function'};
+ dlg_title = 'user defined transform';
+ num_lines= 1;
+ [FileName, PathName, filterindex] = uigetfile( ...
+ {'*.m', ' (*.m)';
+ '*.m', '.m files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file', fct_name);
+ fct_name=fullfile(PathName,FileName);
+ addpath(PathName);%add the path to the selected fct
+ [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER
+ if ~exist(fct_name,'file')
+ warndlg(['image procesing fct ' fct_name ' not found'])
+ else
+ transform=FileName(1:end-2);%
+ update_menu(handles.CoordType,transform)%add the selected fct to the menu
+ % set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu
+ %save ('./TMP/current_usr_fct.mat','fct_name');
+ end
+end
+ind_coord=get(handles.CoordType,'Value');
+
+%---------------------------------------------------------------------
+% --- Executes on selection change in ProjObject.
+function ProjObject_Callback(hObject, eventdata, handles)
+
+list_object=get(handles.ProjObject,'String');
+index=get(handles.ProjObject,'Value');
+hseries=get(handles.ProjObject,'Parent');
+SeriesData=get(hseries,'UserData');
+Obj=SeriesData.ProjObject{index};
+[SeriesData.hset_object,SeriesData.sethandles]=set_object(SeriesData.ProjObject{index});
+set(hseries,'UserData',SeriesData);
+
+%-------------------------------------------------------------
+%generates a series of file names with reference numbers between range1 and
+%range2 with increment incr. The reference number num_ref is the image number at the middle of the
+%image pair. The set of first numbers num1 of the image pairs is also
+%given as output
+%------------------------------------------------------
+function [num_i1,num_i2,num_j1,num_j2,nbmissing]=netseries_generator(filebase,subdir,mode,first_i,incr_i,last_i,first_j,incr_j,last_j)
+[Path,Name]=fileparts(filebase);
+filebasesub=fullfile(Path,subdir,Name);
+filecell={};%default
+num_i1=[];
+num_i2=[];
+num_j1=[];
+num_j2=[];
+ind0_i=first_i:incr_i:last_i;
+nbcolumn=length(ind0_i);
+ind0_j=first_j:incr_j:last_j;
+nbline=length(ind0_j);
+if isequal(mode,'#_ab')
+ dirpair=dir([filebasesub '*_*.nc']);
+elseif isequal(mode,'bursts')|isequal(mode,'series(Dj)')
+ dirpair=dir([filebasesub '_*_*-*.nc']);
+elseif isequal(mode,'series(Di)')
+ dirpair=dir([filebasesub '_*-*_*.nc']);
+else
+ errordlg('option *|* not yet implemented')
+ return
+end
+if isempty(dirpair)
+ errordlg('no pair detected in the selected range')
+ return
+end
+ %ind0_i=first_i:incr_i:last_i;
+ %nbcolumn=length(ind0_i);
+ %dirpair=dir([filebasesub '_*_*-*.nc']);
+if isequal(mode,'bursts')|isequal(mode,'#_ab')
+ icount=0;
+ for ifile=1:length(dirpair)
+ [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
+
+% if isempty(str2num(str_1))
+% dirpair(ifile).name
+% end
+ num1_r=str2num(str_1);
+ if isequal(RootFile,Name) & ~isempty(num1_r)
+ num_i1(ifile)=num1_r;
+ num_a(ifile)=stra2num(str_a);
+ num_b(ifile)=stra2num(str_b);
+% icount=icount+1;
+ end
+ end
+ length(dirpair)
+% num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
+ test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range
+ ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices
+ select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory
+ ind_i=ind_i(select);%set of selected indices ind_i
+ [ind_i,indsort]=sort(ind_i);%sorted list of ind_i
+ select=select(indsort);
+ num_i1=num_i1(select);
+ num_a=num_a(select);
+ num_b=num_b(select);
+ dirpair=dirpair(select);
+ [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn);
+ ind_i(ind_remove)=[];
+ num_a(ind_remove)=[];
+ num_b(ind_remove)=[];
+ num_j1=zeros(1,nbcolumn);%default
+ num_j2=num_j1;
+ num_j1(ind_i)=num_a;
+ num_j2(ind_i)=num_b;
+ num_i1=first_i:incr_i:last_i;
+ num_i2=num_i1;
+ nbmissing=nbcolumn-length(ind_i);
+
+elseif isequal(mode,'series(Di)')
+ %ind0_i=first_i:incr_i:last_i;
+ %nbcolumn=length(ind0_i);
+ %ind0_j=first_j:incr_j:last_j;
+ %nbline=length(ind0_j);
+ %dirpair=dir([filebasesub '_*-*_*.nc']);
+ for ifile=1:length(dirpair)
+ [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
+ num_i1_r(ifile)=str2num(str_1);
+ num_i2_r(ifile)=str2num(str_2);
+ num_j(ifile)=str2num(str_a);
+ end
+ num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files
+ test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range
+ ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
+ ind_j=((num_j-first_j)/incr_j)+1;
+ ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
+ select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
+ ind_ij=ind_ij(select);%set of selected indices ind_ij
+ [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
+ select=select(indsort);
+ num_i1_r=num_i1_r(select);
+ num_i2_r=num_i2_r(select);
+% num_j=num_j(select);
+ dirpair=dirpair(select);
+ [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
+ ind_ij(ind_remove)=[];
+ num_i1_r(ind_remove)=[];
+ num_i2_r(ind_remove)=[];
+ num_i1=zeros(1,nbline*nbcolumn);%default
+ num_i2=num_i1;
+ num_i1(ind_ij)=num_i1_r;
+ num_j2(ind_ij)=num_i2_r;
+ num_i1=reshape(num_i1,nbline,nbcolumn);
+ num_i2=reshape(num_i2,nbline,nbcolumn);
+ num_j1=meshgrid(ind0_i,ind0_j);
+ num_j2=num_j1;
+ nbmissing=nbline*nbcolumn-length(ind_ij);
+elseif isequal(mode,'series(Dj)')
+ % ind0_i=first_i:incr_i:last_i;
+ % nbcolumn=length(ind0_i);
+ % ind0_j=first_j:incr_j:last_j;
+ % nbline=length(ind0_j);
+ % dirpair=dir([filebasesub '_*_*-*.nc']);
+ for ifile=1:length(dirpair)
+ [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
+ num_i(ifile)=str2num(str_1);
+ num_a(ifile)=str2num(str_a);
+ num_b(ifile)=str2num(str_b);
+ end
+ num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
+ test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range
+ ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
+ ind_j=((num_j-first_j)/incr_j)+1;
+ ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
+ select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
+ ind_ij=ind_ij(select);%set of selected indices ind_ij
+ [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
+ select=select(indsort);
+ num_i=num_i(select);
+ num_a=num_a(select);
+ num_b=num_b(select);
+ dirpair=dirpair(select);
+ [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
+ ind_ij(ind_remove)=[];
+ num_a(ind_remove)=[];
+ num_b(ind_remove)=[];
+ num_j1=zeros(1,nbline*nbcolumn);%default
+ num_j2=num_j1;
+ num_j1(ind_ij)=num_a;
+ num_j2(ind_ij)=num_b;
+ num_j1=reshape(num_j1,nbline,nbcolumn);
+ num_j2=reshape(num_j2,nbline,nbcolumn);
+ num_i1=meshgrid(ind0_i,ind0_j);
+ num_i2=num_i1;
+ nbmissing=nbline*nbcolumn-length(ind_ij);
+% for i=1:length(indsel);%A SUPPRIMER ULTERIEUREMENT
+% if indsel(i)==0
+% filecell{i}='';
+% else
+% Name=dirpair(indsel(i)).name;
+% filecell{i}=fullfile(Path,subdir,Name);
+% end
+% end
+%else
+% errordlg('option *|* not yet implemented')
+% return
+end
+
+%%%%%%%%%%%%%
+function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
+
+ indsel=ind_i;
+ indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
+ indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
+ if ~isempty(indiff)
+ indiff2=diff(indiff);
+ indiffp=[indiff2 1];
+ indiffm=[1 indiff2];
+ ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
+ ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
+ %for each multiplet, select the most recent file
+ ind_remove=[];
+ for i=1:length(ind_multi_m)
+ ind_pairs=ind_multi_m(i):ind_multi_p(i);
+ for imulti=1:length(ind_pairs)
+ datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
+ end
+ [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
+ ind_s=indsort2(1:end-1);%
+ ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
+ end
+ end
+
+%--------------------------------------------------------
+
+
+%-----------------------------------------------------------
+% find the times corresponding to the first and last indices of a series
+%
+function displ_time(handles,times)
+hseries=get(handles.last_i,'parent');
+SeriesData=get(hseries,'UserData');%
+first_i=str2num(get(handles.first_i,'String'));
+first_j=str2num(get(handles.first_j,'String'));
+last_i=str2num(get(handles.last_i,'String'));
+last_j=str2num(get(handles.last_j,'String'));
+% index_civ=get(handles.list_pair_civ,'Value');
+% NomType=get(handles.NomType,'String');
+NomType=SeriesData.NomType;
+mode_list=get(handles.mode,'String');
+index_mode=get(handles.mode,'Value');
+mode=mode_list{index_mode};
+% ind_shift=0;%default
+
+time_first=[];
+time_last=[];
+if ~isfield(SeriesData,'Time')
+ SeriesData.Time{1}=[];
+end
+for iview=1:length(NomType)
+ time_first_cell{iview}='?';
+ time_last_cell{iview}='?';%default
+ time=SeriesData.Time{iview};
+ if isequal(NomType{iview},'_i1-i2_j')|isequal(NomType{iview},'_i_j1-j2')|isequal(NomType{iview},'#_ab')|isequal(NomType{iview},'_i1-i2')
+ if isfield(SeriesData,'displ_num')& ~isempty(SeriesData.displ_num)
+ ind_shift=SeriesData.displ_num(iview,:);
+ if isequal(mode,'bursts')
+ first_j=0;
+ last_j=0;
+ end
+ first_i1=first_i +ind_shift(3);
+ first_i2 =first_i +ind_shift(4);
+ first_j1 =first_j +ind_shift(1);
+ first_j2 =first_j +ind_shift(2);
+ last_i1=last_i +ind_shift(3);
+ last_i2 =last_i +ind_shift(4);
+ last_j1 =last_j +ind_shift(1);
+ last_j2 =last_j +ind_shift(2);
+ siz=size(SeriesData.Time{1});
+ if siz(1)>=last_i2 & siz(2)>=last_j2
+ time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2;
+ time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2;
+ else%read the time in the nc files
+ RootPath=get(handles.RootPath,'String');
+ RootFile=get(handles.RootFile,'String');
+ SubDir=get(handles.SubDir,'String');
+ %VelType=get(handles.VelType,'String');
+ VelType_str=get(handles.VelTypeMenu,'String');
+ VelType_val=get(handles.VelTypeMenu,'Value');
+ VelType=VelType_str{VelType_val};
+ filebase=fullfile(RootPath{1},RootFile{1});
+ [filefirst]=name_generator(filebase,first_i1,first_j1,'.nc',NomType{iview},1,first_i2,first_j2,SubDir{iview});
+ if exist(filefirst,'file')
+ Attrib=nc2struct(filefirst,[]);
+ if isfield(Attrib,'Time')
+ time_first=Attrib.Time;
+ else
+ if isfield(Attrib,'absolut_time_T0')
+ time_first=Attrib.absolut_time_T0;
+ end
+ if isfield(Attrib,'absolut_time_T0_2')&~(isequal(VelType,'civ1')|isequal(VelType,'interp1')|isequal(VelType,'filter1'))
+ time_first=Attrib.absolut_time_T0_2;
+ end
+ end
+ end
+ [filelast]=name_generator(filebase,last_i1,last_j1,'.nc',NomType{iview},1,last_i2,last_j2,SubDir{iview});
+ if exist(filelast,'file')
+ Attrib=nc2struct(filelast,[]);
+ if isfield(Attrib,'Time')
+ time_last=Attrib.Time;
+ else
+ if isfield(Attrib,'absolut_time_T0')
+ time_last=Attrib.absolut_time_T0;
+ end
+ if isfield(Attrib,'absolut_time_T0_2')&~(isequal(VelType,'civ1')|isequal(VelType,'interp1')|isequal(VelType,'filter1'))
+ time_last=Attrib.absolut_time_T0_2;
+ end
+ end
+ end
+ end
+ end
+ else
+ siz=size(times);
+ if siz(1)>=last_i & siz(2)>=last_j
+ time_first=times(first_i,first_j);
+ time_last=times(last_i,last_j);
+ end
+ end
+ time_first_cell{iview}=num2str(time_first,4);
+ time_last_cell{iview}=num2str(time_last,4);
+end
+set(handles.time_first,'Value',1)
+set(handles.time_last,'Value',1)
+set(handles.time_first,'String',time_first_cell);
+set(handles.time_last,'String',time_last_cell);
+
+%--------------------------------------------------------------------
+% --- Executes on selection change in VelTypeMenu.
+function VelTypeMenu_Callback(hObject, eventdata, handles)
+% VelTypeList=get(handles.VelTypeMenu,'String');
+% VelTypeIndex=get(handles.VelTypeMenu,'Value');
+% VelTypeCell=get(handles.VelType,'String');
+% VelTypeCell{1}=VelTypeList{VelTypeIndex};
+% set(handles.VelType,'String',VelTypeCell)
+
+
+%--------------------------------------------------------------------
+% --- Executes on button press in GetObject.
+function GetObject_Callback(hObject, eventdata, handles)
+hseries=get(handles.GetObject,'parent');
+SeriesData=get(hseries,'UserData');
+value=get(handles.GetObject,'Value');
+if value
+ set(handles.GetObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
+ DataInit.ParentButton=handles.GetObject;
+ hset_object=findobj(allchild(0),'Name','set_object');%find the set_object interface handle
+ if ishandle(hset_object)
+ [SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
+ else
+ DataInit.TITLE='POINTS';%default option
+ [SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
+ end
+else
+ set(handles.GetObject,'BackgroundColor',[0 1 0])%put activated buttons to green
+ if isfield(SeriesData,'hset_object')&& ishandle(SeriesData.hset_object)
+ close(SeriesData.hset_object)
+ end
+end
+set(hseries,'UserData',SeriesData)
+
+%--------------------------------------------------------------
+function GetMask_Callback(hObject, eventdata, handles)
+value=get(handles.GetMask,'Value');
+if value
+ errordlg('not implemented yet')
+end
+%--------------------------------------------------------------
+
+%--------------------------------------------------------------------------
+%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
+function ncbrowser_uvmat(hObject, eventdata)
+ bla=get(gcbo,'String');
+ ind=get(gcbo,'Value');
+ filename=cell2mat(bla(ind));
+ blank=find(filename==' ');
+ filename=filename(1:blank-1);
+ get_field(filename)
+
+
+
+% --------------------------------------------------------------------
+function MenuHelp_Callback(hObject, eventdata, handles)
+
+path_to_uvmat=which ('uvmat');% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+else
+web([helpfile '#series'])
+end
+
+
+
+
+
+
Index: /trunk/src/set_col_vec.m
===================================================================
--- /trunk/src/set_col_vec.m (revision 2)
+++ /trunk/src/set_col_vec.m (revision 2)
@@ -0,0 +1,89 @@
+%'set_col_vec': sets the color code for vectors depending on a scalar vec_C and parameters given by the struct colcode
+%function [colorlist,col_vec,minC,colcode1,colcode2,maxC]=colvec(colcode,vec_C)
+%OUTPUT
+%colorlist(nb,3); %list of nb colors
+%col_vec, size=[length(vec_C),3)];%list of color indices corresponding to vec_C
+%minC, maxC: min and max of vec_C
+%colcode1, colcode2: absolute threshold in vec_C corresponding to colcode.colcode1 and colcode.colcode2
+%INPUT
+% colcode: struture setting the colorcode for vectors
+ % colcode.CName: 'ima_cor','black','white',...
+ % colcode.ColorCode ='black', 'white', 'rgb','brg', '64 colors'
+ % colcode.FixedCbounds =0; thresholds scaling relative to min and max, =1 fixed thresholds
+ % colcode.MinC; min
+ % colcode.MaxC; max
+ % colcode.colcode1: first threshold for rgb, relative to min (0) and max (1)
+ % colcode.colcode2: second threshold for rgb, relative to min (0) and max (1),
+ % rmq: we need min <= colcode1 <= colcode2 <= max, otherwise
+ % colcode1 and colcode2 are adjusted to the bounds
+% vec_C: matlab vector representing the scalar setting the color
+function [colorlist,col_vec,colcode_out]=set_col_vec(colcode,vec_C)
+
+col_vec=[];
+colcode_out=colcode;%default
+if isempty(vec_C) || ~isnumeric(vec_C)
+ colorlist=[0 0 1]; %blue
+ return
+end
+if (isfield(colcode,'FixedCbounds') && isequal(colcode.FixedCbounds,1))
+ minC=colcode.MinC;
+ maxC=colcode.MaxC;
+else
+ minC=min(vec_C);
+ maxC=max(vec_C);
+end
+
+%default input parameters
+if ~isstruct(colcode),colcode=[];end;
+if ~isfield(colcode,'ColorCode') || isempty(colcode.ColorCode)
+ colorlist=[0 0 1]; %blue
+ return
+end
+if isfield(colcode,'colcode1')
+ colcode1=minC+colcode.colcode1*(maxC-minC);
+else
+ colcode1=minC+(maxC-minC)/3;%default
+end
+if isfield(colcode,'colcode2')
+ colcode2=minC+colcode.colcode2*(maxC-minC);
+else
+ colcode2=minC+2*(maxC-minC)/3;%default
+end
+colcode_out.MinC=minC;
+colcode_out.MaxC=maxC;
+
+if strcmp(colcode.ColorCode,'black')
+ colorlist(1,:)=[0 0 0];%black
+ col_vec=ones(size(vec_C));%all vectors at color#1
+elseif strcmp(colcode.ColorCode,'white')
+ colorlist(1,:)=[1 1 1];%white
+ col_vec=ones(size(vec_C));%all vectors at color#1
+elseif strcmp(colcode.ColorCode,'rgb')|| strcmp(colcode.ColorCode,'bgr')% 3 color representation
+ ind1=find(vec_C < colcode1); % =1 for red vectors
+ ind_green=find((vec_C >= colcode1) & (vec_C < colcode2));% =1 for green vectors
+ ind3=find(vec_C >= colcode2);% =1 for blue vectors
+ colorlist(2,:)=[0 1 0];%green
+ col_vec(ind1)=1;
+ col_vec(ind_green)=2;
+ col_vec(ind3)=3;
+ if strcmp(colcode.ColorCode,'rgb')
+ colorlist(1,:)=[1 0 0];%red
+ colorlist(3,:)=[0 0 1];%blue
+ else
+ colorlist(1,:)=[0 0 1];%blue
+ colorlist(3,:)=[1 0 0];%red
+ end
+else
+ colorjet=jet;% ususal colormap from blue to red
+ sizlist=size(colorjet);
+ indsel=ceil((sizlist(1)/64)*(1:64));
+ colorlist(:,1)=colorjet(indsel,1);
+ colorlist(:,2)=colorjet(indsel,2);
+ colorlist(:,3)=colorjet(indsel,3);
+ sizlist=size(colorlist);
+ nblevel=sizlist(1);
+ col2_1=maxC-minC;
+ col_vec=1+floor(nblevel*(vec_C-minC)/col2_1);
+ col_vec=col_vec.*(col_vec<= nblevel)+nblevel*(col_vec >nblevel);% take color #nblevel at saturation
+ col_vec=col_vec.*(col_vec>= 1)+ (col_vec <1);% take color #1 for values below 1
+end
Index: /trunk/src/set_grid.m
===================================================================
--- /trunk/src/set_grid.m (revision 2)
+++ /trunk/src/set_grid.m (revision 2)
@@ -0,0 +1,684 @@
+%'set_grid':produce grid for PIV with one or two images (stereo case)
+%------------------------------------------------------------------------
+% function varargout = set_grid(varargin)
+% associated with the GUI set_grid.fig
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function varargout = set_grid(varargin)
+
+% Last Modified by GUIDE v2.5 04-Feb-2008 16:05:02
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @set_grid_OpeningFcn, ...
+ 'gui_OutputFcn', @set_grid_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin & isstr(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+%-------------------------------------------------------------------
+% --- Executes just before set_grid is made visible.
+%INPUT:
+% handles: handles of the set_grid interface elements
+%'IndexObj': index of the object (on the UvData list) that set_grid will modify
+% if =[] or absent: index still undefined (create mode in uvmat)
+% if=0; no associated object (used for series), the button 'PLOT' is then unvisible
+%'data': read from an existing object selected in the interface
+% .TITLE : class of object ('POINTS','LINE',....)
+% .DX,DY,DZ; meshes for regular grids
+% .Coord: object position coordinates
+% .ParentButton: handle of the uicontrol object calling the interface
+% PlotHandles: set of handles of the elements contolling the plotting of the projected field:
+% if =[] or absent, no plot (mask mode in uvmat)
+% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
+function set_grid_OpeningFcn(hObject, eventdata, handles,inputfile)
+
+% Choose default command line output for set_grid
+handles.output = hObject;
+
+% Update handles structure
+guidata(hObject, handles);
+
+%default
+% set(hObject,'Unit','Normalized')% set the unit normalized to the screen size
+% set(hObject,'Position',[0.7 0.1 0.25 0.5])%set the position of the set_grid interface
+set(hObject,'DeleteFcn',@closefcn)
+set(handles.TITLE,'Value',1)
+set(handles.ObjectStyle,'Value',1)
+set(handles.ProjMode,'Value',1)
+set(handles.MenuCoord,'ListboxTop',1)
+set(handles.MenuCoord,'Value',1);
+set(handles.MenuCoord,'String',{'phys';'px'});
+if exist('inputfile','var')& ~isempty(inputfile)
+ set(handles.image_1,'String',inputfile)
+ set(handles.image_2,'String',inputfile)
+end
+
+
+% --- Outputs from this function are returned to the command line.
+function varargout = set_grid_OutputFcn(hObject, eventdata, handles)
+% varargout cell array for returning output args (see VARARGOUT);
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+varargout{2}=handles;
+
+% --- Executes on selection change in ObjectStyle.
+function ObjectStyle_Callback(hObject, eventdata, handles)
+
+ProjMode_Callback(hObject, eventdata, handles)
+
+%----------------------------------------------
+function xObject_Callback(hObject, eventdata, handles)
+
+
+function yObject_Callback(hObject, eventdata, handles)
+
+
+% --- Executes on selection change in zObject.
+function zObject_Callback(hObject, eventdata, handles)
+
+
+%---------------------------------------------------
+% --- Executes on selection change in ProjMode.
+function ProjMode_Callback(hObject, eventdata, handles)
+menu=get(handles.ProjMode,'String');
+value=get(handles.ProjMode,'Value');
+ProjMode=menu{value};
+menu=get(handles.ObjectStyle,'String');
+value=get(handles.ObjectStyle,'Value');
+ObjectStyle=menu{value};
+test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
+if isequal(ObjectStyle,'plane')||isequal(ObjectStyle,'volume')
+ set(handles.Phi,'Visible','on')
+ if test3D%3D case
+ set(handles.Theta,'Visible','on')
+ set(handles.Psi,'Visible','on')
+ end
+ set(handles.XMin,'Visible','on')
+ set(handles.XMax,'Visible','on')
+ set(handles.YMin,'Visible','on')
+ set(handles.YMax,'Visible','on')
+ if test3D
+ set(handles.Theta,'Visible','on')
+ set(handles.Psi,'Visible','on')
+ set(handles.ZMin,'Visible','on')
+ set(handles.ZMax,'Visible','on')
+ end
+else
+ set(handles.Phi,'Visible','off')
+ set(handles.Theta,'Visible','off')
+ set(handles.Psi,'Visible','off')
+ set(handles.XMin,'Visible','off')
+ set(handles.XMax,'Visible','off')
+ set(handles.YMin,'Visible','off')
+ if isequal(ProjMode,'interp')
+ set(handles.YMax,'Visible','off')
+ else
+ set(handles.YMax,'Visible','on')
+ end
+ if isequal(ObjectStyle,'rectangle')|isequal(ObjectStyle,'ellipse')
+ set(handles.XMax,'Visible','on')
+ else
+ set(handles.XMax,'Visible','off')
+ end
+ set(handles.ZMin,'Visible','off')
+ set(handles.ZMax,'Visible','off')
+end
+if isequal(ProjMode,'projection')|isequal(ProjMode,'inside')|isequal(ProjMode,'outside')|isequal(ObjectStyle,'points')
+ set(handles.DX,'Visible','off')
+ set(handles.DY,'Visible','off')
+ set(handles.DZ,'Visible','off')
+else
+ set(handles.DX,'Visible','on')
+ set(handles.DY,'Visible','on')
+ if test3D%3D case
+ set(handles.DZ,'Visible','on')
+ end
+end
+
+%---------------------------------------------
+% --- Executes on selection change in TITLE.
+function TITLE_Callback(hObject, eventdata, handles)
+hsetobject=get(handles.TITLE,'parent');
+SetData=get(hsetobject,'UserData');%get the hidden interface data
+% function named CALLBACK in UNTITLED.M with the given input arguments.
+menu=get(handles.TITLE,'String');
+value=get(handles.TITLE,'Value');
+titl=menu{value};
+if isequal(titl,'POINTS')
+ menu_style={'points'};
+ menu_proj={'projection';'interp';'filter';'none'};
+elseif isequal(titl,'LINE')
+ menu_style={'line';'polyline';'rectangle';'polygon';'ellipse'};%'line' =default
+ menu_proj={'projection';'interp';'filter';'none'};
+elseif isequal(titl,'PATCH')
+ menu_style={'rectangle';'polygon';'ellipse'};%'line' =default
+ menu_proj={'inside';'outside';'none'};
+ elseif isequal(titl,'PLANE')
+ menu_style={'plane'};
+ menu_proj={'projection';'interp'};
+elseif isequal(titl,'VOLUME')
+ menu_style={'volume'};
+ menu_proj={'none'};
+
+end
+set(handles.ObjectStyle,'String',menu_style)
+set(handles.ObjectStyle,'Value',1)
+set(handles.ProjMode,'String',menu_proj)
+set(handles.ProjMode,'Value',1)
+if isfield(SetData,'ParentButton')
+ update_parentbutton(SetData.ParentButton,titl)
+end
+ObjectStyle_Callback(hObject, eventdata, handles)
+
+%-----------
+function update_parentbutton(ParentButton,titl)
+
+if isstruct(ParentButton)
+ parentfields=fields(ParentButton);
+ for ibutton=1:length(parentfields)
+ buttonhandle=eval(['ParentButton.' parentfields{ibutton}]);
+ if ishandle(buttonhandle)
+ set(buttonhandle,'Value',0)
+ set(buttonhandle,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+ end
+ end
+ if isfield(ParentButton,titl)
+ buttonhandle=eval(['ParentButton.' titl]);
+ if ishandle(buttonhandle)
+ set(buttonhandle,'Value',1)
+ set(buttonhandle,'BackgroundColor',[1 1 0])%put activated button to yellow
+ end
+ end
+end
+%------------
+function Phi_Callback(hObject, eventdata, handles)
+update_slider(hObject, eventdata,handles)
+
+function Theta_Callback(hObject, eventdata, handles)
+update_slider(hObject, eventdata,handles)
+
+function update_slider(hObject, eventdata,handles)
+%rotation angles
+Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
+Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
+
+%components of the unitiy vector normal to the projection plane
+NormVec_X=-sin(Phi)*sin(Theta);
+NormVec_Y=cos(Phi)*sin(Theta);
+NormVec_Z=cos(Theta);
+huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
+UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
+Z=NormVec_X *(UvData.X)+NormVec_Y *(UvData.Y)+NormVec_Z *(UvData.Z);
+set(handles.z_slider,'Min',min(Z))
+set(handles.z_slider,'Max',max(Z))
+ZMax_Callback(hObject, eventdata, handles)
+
+function DX_Callback(hObject, eventdata, handles)
+
+
+function DY_Callback(hObject, eventdata, handles)
+
+
+function DZ_Callback(hObject, eventdata, handles)
+
+
+
+%-----------------------------------------------------
+% --- Executes on button press in import.
+function import_Callback(hObject, eventdata, handles)
+%get the object file
+oldfile='';
+huvmat=findobj('Tag','uvmat');
+if isempty(huvmat)
+ huvmat=findobj(allchild(0),'Name','series');
+end
+hchild=get(huvmat,'Children');
+hrootpath=findobj(hchild,'Tag','RootPath');
+oldfile=get(hrootpath,'String');
+if iscell(oldfile)
+ oldfile=oldfile{1};
+end
+%[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile)
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.xml;*.mat', ' (*.xml,*.mat)';
+ '*.xml', '.xml files '; ...
+ '*.mat', '.mat matlab files '}, ...
+ 'Pick a file',oldfile);
+fileinput=[PathName FileName];%complete file name
+testblank=findstr(fileinput,' ');%look for blanks
+if ~isempty(testblank)
+ errordlg('forbidden input file name: contain blanks')
+ return
+end
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
+
+%read the file
+ t=xmltree(fileinput);
+ s=convert(t);
+%Display title
+title=set_title(s.Style,s.ProjMode);%update the title
+% menu=get(handles.TITLE,'String')
+% for iline=1:length(menu)
+% if isequal(menu{iline},title)
+% set(handles.TITLE,'Value',iline)
+% break
+% end
+% end
+% TITLE_Callback(hObject, eventdata, handles)
+% teststyle=0;
+% if isfield(s,'Style')
+% menu=get(handles.ObjectStyle,'String');
+% for iline=1:length(menu)
+% if isequal(menu{iline},s.Style)
+% set(handles.ObjectStyle,'Value',iline)
+% teststyle=1;
+% break
+% end
+% end
+% end
+% if teststyle==0;
+% s.Style='points';
+% set(handles.ObjectStyle,'Value',1); %default (points)
+% end
+testmode=0;
+if isfield(s,'ProjMode')
+ menu=get(handles.ProjMode,'String');
+ for iline=1:length(menu)
+ if isequal(menu{iline},s.ProjMode)
+ set(handles.ProjMode,'Value',iline)
+ testmode=1;
+ break
+ end
+ end
+end
+
+ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes
+if isfield(s,'CoordType')
+ if isequal(s.CoordType,'phys')
+ set(handles.MenuCoord,'Value',1)
+ elseif isequal(s.CoordType,'px')
+ set(handles.MenuCoord,'Value',2)
+ else
+ warndlg('unknown CoordType (px or phys) in set_grid.m')
+ end
+end
+if isfield(s,'XMax')
+ set(handles.XMax,'String',s.XMax)
+end
+if isfield(s,'XMin')
+ set(handles.XMin,'String',s.XMin)
+end
+if isfield(s,'YMax')
+ set(handles.YMax,'String',s.YMax)
+end
+if isfield(s,'YMin')
+ set(handles.YMin,'String',s.YMin)
+end
+if isfield(s,'DX')
+ set(handles.DX,'String',s.DX)
+end
+if isfield(s,'DY')
+ set(handles.DY,'String',s.DY)
+end
+if ~isfield(s,'Coord')
+ XObject='0';%default
+ YObject='0';
+elseif ischar(s.Coord)
+ line=str2num(s.Coord);
+ XObject=num2str(line(1));
+ YObject=num2str(line(2));
+else
+ for i=1:length(s.Coord)
+ line=str2num(s.Coord{i});
+ XObject{i}=num2str(line(1));
+ YObject{i}=num2str(line(2));
+ end
+end
+set(handles.XObject,'String',XObject)
+set(handles.YObject,'String',YObject)
+%METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_grid_Opening
+
+%----------------------------------------------------
+% executed when closing: set the parent interface button to value 0
+function closefcn(gcbo,eventdata)
+huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
+parent_button=findobj(huvmat,'Tag','grid');
+if ~isempty(parent_button)
+ set(parent_button,'Value',0)%put unactivated buttons to green
+ tag=get(parent_button,'Tag');
+ if isequal(tag,'edit')
+ set(parent_button,'BackgroundColor',[0.7 0.7 0.7]);
+ else
+ set(parent_button,'BackgroundColor',[0 1 0]);
+ end
+end
+
+%-----------------------------------------------------------------------
+% --- Executes on button press in edit: PLOT the defined object and its projected field
+function edit_Callback(hObject, eventdata, handles)
+hsetobject=get(hObject,'parent');
+SetData=get(hsetobject,'UserData');%get the hidden interface data
+%IndexObj=SetData.IndexObj%index of the current projection object in the list of projection objects (UvData.ProjObject)
+huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
+UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
+if isfield(UvData,'CuurentObjectIndex')
+ IndexObj=UvData.CurrentObjectIndex;
+else
+ IndexObj=[];
+end
+ObjectData=read_set_grid(handles);%read the interface input parameters defining the object
+[UvData,IndexObj]=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles);
+uvmat('write_plot_param',PlotHandles,UvData.Object{IndexObj}.PlotParam); %update the display of plotting parameters for the current object
+SetData.IndexObj=IndexObj;
+set(gcbf,'UserData',SetData)%update object index in the set_grid interface
+set(huvmat,'UserData',UvData)%update the data in the uvmat interface
+
+
+% --- Executes on button press in MenuCoord.
+function MenuCoord_Callback(hObject, eventdata, handles)
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% --- Executes on button press in delete.
+function delete_Callback(hObject, eventdata, handles)
+
+%SetData=get(gcbf,'UserData');%get the interface data
+%IndexObj=SetData.IndexObj;
+huvmat=findobj('Name','uvmat');%find the current uvmat interface handle
+UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
+if isfield(UvData,'CurrentObjectIndex')
+ IndexObj=UvData.CurrentObjectIndex;
+else
+ IndexObj=[];
+end
+delete_object(IndexObj);
+
+%----------------------------------------------------
+function YMin_Callback(hObject, eventdata, handles)
+% hObject handle to YMin (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of YMin as text
+% str2double(get(hObject,'String')) returns contents of YMin as a double
+
+
+function ZMin_Callback(hObject, eventdata, handles)
+
+
+function ZMax_Callback(hObject, eventdata, handles)
+DZ=str2num(get(handles.ZMax,'String'));
+ZMin=get(handles.z_slider,'Min');
+ZMax=get(handles.z_slider,'Max');
+rel_step(1)=DZ/(ZMax-ZMin);
+rel_step(2)=0.2;
+set(handles.z_slider,'SliderStep',rel_step)
+
+function YMax_Callback(hObject, eventdata, handles)
+
+
+function XMin_Callback(hObject, eventdata, handles)
+
+
+function XMax_Callback(hObject, eventdata, handles)
+
+
+% ------------------------------------------------------
+function save_Callback(hObject, eventdata, handles)
+% ------------------------------------------------------
+Object=read_set_object(handles);%read the set_grid interface;
+DX=Object.DX;
+DY=Object.DY;
+RangeX=Object.RangeX;
+RangeY=Object.RangeY;
+ array_realx=[RangeX(2):DX:RangeX(1)];
+ array_realy=[RangeY(2):DY:RangeY(1)];
+ nx_patch=length(array_realx);
+ ny_patch=length(array_realy);
+ [grid_realx,grid_realy]=meshgrid(array_realx,array_realy);
+ grid_real(:,1)=reshape(grid_realx,nx_patch*ny_patch,1);
+ grid_real(:,2)=reshape(grid_realy,nx_patch*ny_patch,1);
+ grid_real(:,3)=zeros(nx_patch*ny_patch,1);
+
+imageA=get(handles.image_1,'String');
+imageB=get(handles.image_2,'String');
+testB=1;
+if isempty(imageA) | isequal(imageA,'')
+ if isempty(imageB) | isequal(imageB,'')
+ warndlg_uvmat('at least one image file name must be introduced','ERROR')
+ else
+ imageA=imageB;
+ testB=0;
+ end
+end
+if isempty(imageB) || isequal(imageB,'') || isequal(imageA,imageB)
+ testB=0;
+end
+
+testexist=exist(imageA,'file');
+if isequal(testexist,0)
+ msgbox_uvmat('ERROR',['input image file' imageA 'does not exist'])
+ return
+end
+[Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(imageA);
+form=imformats(ext([2:end]));
+if isempty(form)% if the extension corresponds to an image format recognized by Matlab
+ msgbox_uvmat('ERROR',['error in read_image.m: ' imageA ' is not an image name recognized by Matlab '])
+ return
+end
+fileAxml=[fullfile(Pathsub,RootFile) '.xml'];
+[XmlDataA,error]=imadoc2struct(fileAxml);
+if isfield(XmlDataA,'GeometryCalib')
+ tsaiA=XmlDataA.GeometryCalib;
+ else
+ msgbox_uvmat('WARNING','no geometric calibration available for image A')
+ tsaiA=[];
+end
+[grid_imaA(:,1),grid_imaA(:,2)]=px_XYZ(tsaiA,grid_real(:,1),grid_real(:,2),0);
+ A=imread(imageA);
+ siz=size(A);
+ npxA=siz(2);
+ npyA=siz(1);
+
+flagA=grid_imaA(:,1)>0 & grid_imaA(:,1)0 & grid_imaA(:,2)0 & grid_imaB(:,1)0 & grid_imaB(:,2)=2
+ sizcoord=size(data.Coord);
+ for i=1:sizcoord(1)
+ XObject{i}=num2str(data.Coord(i,1),4);
+ YObject{i}=num2str(data.Coord(i,2),4);
+ end
+ set(handles.XObject,'String',XObject)
+ set(handles.YObject,'String',YObject)
+ %set(handles.XObject,'String',mat2cell(data.Coord(:,1),sizcoord(1)))
+ %set(handles.YObject,'String',mat2cell(data.Coord(:,2),sizcoord(1)))
+ if sizcoord(2)>3
+ for i=1:sizcoord(1)
+ ZObject{i}=num2str(data.Coord(i,3),4);
+ end
+ set(handles.ZObject,'String',ZObject)
+ end
+ end
+ if isfield(data,'DX')
+ set(handles.DX,'String',num2str(data.DX,3))
+ end
+ if isfield(data,'DY')
+ set(handles.DY,'String',num2str(data.DY,3))
+ end
+ %OBSOLETE (replaced by Range)
+% if isfield(data,'XMin')
+% set(handles.XMin,'String',num2str(data.XMin,3))
+% end
+% if isfield(data,'XMax')
+% set(handles.XMax,'String',num2str(data.XMax,3))
+% end
+% if isfield(data,'YMin')
+% set(handles.YMin,'String',num2str(data.YMin,3))
+% end
+% if isfield(data,'YMax')
+% set(handles.YMax,'String',num2str(data.YMax,3))
+% end
+ if isfield(data,'RangeZ') && length(ZBounds) >= 2
+ set(handles.ZMax,'String',num2str(max(data.RangeZ),3))
+ DZ=max(data.RangeZ);%slider step
+ if ZBounds(2)~=ZBounds(1)
+ rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
+ rel_step(2)=0.1;
+ set(handles.z_slider,'Visible','on')
+ set(handles.z_slider,'Min',ZBounds(1))
+ set(handles.z_slider,'Max',ZBounds(2))
+ set(handles.z_slider,'SliderStep',rel_step)
+ set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
+ end
+ end
+ if isfield(data,'RangeX')
+ set(handles.XMax,'String',num2str(max(data.RangeX),3))
+ set(handles.XMin,'String',num2str(min(data.RangeX),3))
+ end
+ if isfield(data,'RangeY')
+ set(handles.YMax,'String',num2str(max(data.RangeY),3))
+ set(handles.YMin,'String',num2str(min(data.RangeY),3))
+ end
+ if isfield(data,'RangeZ')
+ set(handles.ZMax,'String',num2str(max(data.RangeZ),3))
+ set(handles.ZMin,'String',num2str(min(data.RangeZ),3))
+ end
+ if isfield(data,'Phi')
+ set(handles.Phi,'String',num2str(data.Phi,3))
+ end
+ if isfield(data,'Theta')
+ set(handles.Theta,'String',num2str(data.Theta,3))
+ end
+ if isfield(data,'Psi')
+ set(handles.Psi,'String',num2str(data.Psi,3))
+ end
+ if isfield(data,'DZ')
+ set(handles.DZ,'String',num2str(data.DZ,3))
+ end
+ if isfield(data,'CoordType')
+ if isequal(data.CoordType,'phys')
+ set(handles.MenuCoord,'Value',1)
+ elseif isequal(data.CoordType,'px')
+ set(handles.MenuCoord,'Value',2)
+ end
+ end
+end
+if desable_open
+ set(handles.OPEN,'Visible','off')
+else
+ set(handles.OPEN,'Visible','on')
+end
+if desable_plot
+ set(handles.PLOT,'Visible','off')
+else
+ set(handles.PLOT,'Visible','on')
+end
+
+
+% --- Outputs from this function are returned to the command line.
+function varargout = set_object_OutputFcn(hObject, eventdata, handles)
+% varargout cell array for returning output args (see VARARGOUT);
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+varargout{2}=handles;
+
+%-----------------------------------------------
+% --- Executes on selection change in ObjectStyle.
+function ObjectStyle_Callback(hObject, eventdata, handles)
+style_prev=get(handles.ObjectStyle,'UserData');
+str=get(handles.ObjectStyle,'String');
+val=get(handles.ObjectStyle,'Value');
+% make correspondance between different object styles
+% if ~isequal(str{val},style_prev)
+Xcolumn=get(handles.XObject,'String');
+Ycolumn=get(handles.YObject,'String');
+if ischar(Xcolumn)
+ sizchar=size(Xcolumn);
+ for icol=1:sizchar(1)
+ Xcolumn_cell{icol}=Xcolumn(icol,:);
+ end
+ Xcolumn=Xcolumn_cell;
+end
+if ischar(Ycolumn)
+ sizchar=size(Ycolumn);
+ for icol=1:sizchar(1)
+ Ycolumn_cell{icol}=Ycolumn(icol,:);
+ end
+ Ycolumn=Ycolumn_cell;
+end
+Zcolumn={};%default
+z_new={};
+if isequal(get(handles.ZObject,'Visible'),'on')
+ data.NbDim=3; %test 3D object
+ Zcolumn=get(handles.ZObject,'String');
+ if ischar(Zcolumn)
+ Zcolumn={Zcolumn};
+ end
+end
+x_new{1}=Xcolumn{1};
+y_new{1}=Ycolumn{1};
+if ~isempty(Zcolumn)
+ z_new{1}=Zcolumn{1};
+end
+if isequal(str{val},'line')
+ if isequal(style_prev,'rectangle')|isequal(style_prev,'ellipse')
+ XMax=get(handles.XMax,'String');
+ YMax=get(handles.YMax,'String');
+ x_new{2}=num2str(XMax,4);
+ y_new{2}=num2str(YMax,4);
+ set(handles.XObject,'String',x_new)
+ set(handles.YObject,'String',y_new)
+ set(handles.ZObject,'String',z_new)
+ end
+elseif isequal(str{val},'polyline')
+elseif isequal(str{val},'rectangle')| isequal(str{val},'ellipse')
+ set(handles.XObject,'String',x_new)
+ set(handles.YObject,'String',y_new)
+ set(handles.ZObject,'String',z_new)
+end
+% end
+
+
+
+ProjMode_Callback(hObject, eventdata, handles)
+%store the current option
+str=get(handles.ObjectStyle,'String');
+val=get(handles.ObjectStyle,'Value');
+set(handles.ObjectStyle,'UserData',str{val})
+
+%----------------------------------------------
+function xObject_Callback(hObject, eventdata, handles)
+
+
+function yObject_Callback(hObject, eventdata, handles)
+
+
+% --- Executes on selection change in zObject.
+function zObject_Callback(hObject, eventdata, handles)
+
+
+
+% --- Executes on selection change in ProjMode.
+function ProjMode_Callback(hObject, eventdata, handles)
+menu=get(handles.ProjMode,'String');
+value=get(handles.ProjMode,'Value');
+ProjMode=menu{value};
+menu=get(handles.ObjectStyle,'String');
+value=get(handles.ObjectStyle,'Value');
+ObjectStyle=menu{value};
+test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
+if isequal(ObjectStyle,'plane')|isequal(ObjectStyle,'volume')
+ set(handles.Phi,'Visible','on')
+ if test3D%3D case
+ set(handles.Theta,'Visible','on')
+ set(handles.Psi,'Visible','on')
+ end
+ set(handles.XMin,'Visible','on')
+ set(handles.XMax,'Visible','on')
+ set(handles.YMin,'Visible','on')
+ set(handles.YMax,'Visible','on')
+ if test3D
+ set(handles.Theta,'Visible','on')
+ set(handles.Psi,'Visible','on')
+ set(handles.ZMin,'Visible','on')
+ set(handles.ZMax,'Visible','on')
+ end
+else
+ set(handles.Phi,'Visible','off')
+ set(handles.Theta,'Visible','off')
+ set(handles.Psi,'Visible','off')
+ set(handles.XMin,'Visible','off')
+ set(handles.XMax,'Visible','off')
+ set(handles.YMin,'Visible','off')
+ if isequal(ProjMode,'interp')
+ set(handles.YMax,'Visible','off')
+ else
+ set(handles.YMax,'Visible','on')
+ end
+ if isequal(ObjectStyle,'rectangle')|isequal(ObjectStyle,'ellipse')
+ set(handles.XMax,'Visible','on')
+ else
+ set(handles.XMax,'Visible','off')
+ end
+ set(handles.ZMin,'Visible','off')
+ set(handles.ZMax,'Visible','off')
+end
+TITLE_list=get(handles.TITLE,'String');
+val=get(handles.TITLE,'Value');
+TITLE=TITLE_list{val};
+switch TITLE
+ case {'POINTS','PATCH','MASK'}
+ set(handles.DX,'Visible','off')
+ set(handles.DY,'Visible','off')
+ set(handles.DZ,'Visible','off')
+ case {'LINE'}
+ if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
+ set(handles.DX,'Visible','on')
+ else
+ set(handles.DX,'Visible','off')
+ end
+ case {'PLANE'}
+ if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
+ set(handles.DX,'Visible','on')
+ set(handles.DY,'Visible','on')
+ else
+ set(handles.DX,'Visible','off')
+ set(handles.DY,'Visible','off')
+ end
+ case {'VOLUME'}
+ if isequal(ProjMode,'interp')
+ set(handles.DX,'Visible','on')
+ set(handles.DY,'Visible','on')
+ set(handles.DZ,'Visible','on')
+ else
+ set(handles.DX,'Visible','off')
+ set(handles.DY,'Visible','off')
+ set(handles.DZ,'Visible','off')
+ end
+end
+
+%---------------------------------------------
+% --- Executes on selection change in TITLE.
+function TITLE_Callback(hObject, eventdata, handles)
+%---------------------------------------------
+hsetobject=get(handles.TITLE,'parent');
+SetData=get(hsetobject,'UserData');%get the hidden interface data
+% function named CALLBACK in UNTITLED.M with the given input arguments.
+menu=get(handles.TITLE,'String');
+value=get(handles.TITLE,'Value');
+titl=menu{value};
+if isequal(titl,'POINTS');
+ menu_style={'points'};
+ menu_proj={'projection';'interp';'filter';'none'};
+elseif isequal(titl,'LINE')
+ menu_style={'line';'polyline';'rectangle';'polygon';'ellipse'};%'line' =default
+ menu_proj={'projection';'interp';'filter';'none'};
+elseif isequal(titl,'PATCH')
+ menu_style={'rectangle';'polygon';'ellipse'};%'line' =default
+ menu_proj={'inside';'outside'};
+elseif isequal(titl,'MASK')
+ menu_style={'polygon'};%'line' =default
+ menu_proj={'mask_inside';'mask_outside'};
+elseif isequal(titl,'PLANE')
+ menu_style={'plane'};
+ menu_proj={'projection';'interp';'filter';'none'};
+elseif isequal(titl,'VOLUME')
+ menu_style={'volume'};
+ menu_proj={'none'};
+
+end
+old_menu=get(handles.ObjectStyle,'String');
+value=get(handles.ObjectStyle,'Value');
+old_style=old_menu{value};
+teststyle=0;
+for iline=1:length(menu_style)
+ if isequal(menu_style{iline},old_style)
+ styleval=iline;
+ teststyle=1;
+ break
+ end
+end
+if ~teststyle
+ new_style=[];%default
+ switch old_style
+ case 'polyline'
+ new_style='polygon';
+ case 'polygon'
+ new_style='polyline';
+ end
+ if ~isempty(new_style)
+ for iline=1:length(menu_style)
+ if isequal(menu_style{iline},new_style)
+ styleval=iline;
+ teststyle=1;
+ break
+ end
+ end
+ end
+end
+if ~teststyle
+ styleval=1;
+end
+set(handles.ObjectStyle,'String',menu_style)
+set(handles.ObjectStyle,'Value',styleval)
+set(handles.ProjMode,'String',menu_proj)
+set(handles.ProjMode,'Value',1)
+ObjectStyle_Callback(hObject, eventdata, handles)
+
+%---------------------------------------------
+function Phi_Callback(hObject, eventdata, handles)
+update_slider(hObject, eventdata,handles)
+%---------------------------------------------
+
+function Theta_Callback(hObject, eventdata, handles)
+update_slider(hObject, eventdata,handles)
+
+function update_slider(hObject, eventdata,handles)
+%rotation angles
+Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
+Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
+
+%components of the unitiy vector normal to the projection plane
+NormVec_X=-sin(Phi)*sin(Theta);
+NormVec_Y=cos(Phi)*sin(Theta);
+NormVec_Z=cos(Theta);
+huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
+UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
+if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
+ Z=NormVec_X *(UvData.X)+NormVec_Y *(UvData.Y)+NormVec_Z *(UvData.Z);
+ set(handles.z_slider,'Min',min(Z))
+ set(handles.z_slider,'Max',max(Z))
+ ZMax_Callback(hObject, eventdata, handles)
+end
+
+function DX_Callback(hObject, eventdata, handles)
+
+
+function DY_Callback(hObject, eventdata, handles)
+
+
+function DZ_Callback(hObject, eventdata, handles)
+
+
+
+%-----------------------------------------------------
+% --- Executes on button press in OPEN.
+function OPEN_Callback(hObject, eventdata, handles)
+%get the object file
+oldfile=' ';
+huvmat=findobj('Tag','uvmat');
+% if isempty(huvmat)
+% huvmat=findobj(allchild(0),'Name','series');
+% end
+hchild=get(huvmat,'Children');
+hrootpath=findobj(hchild,'Tag','RootPath');
+if ~isempty(hrootpath)
+ oldfile=get(hrootpath,'String');
+ if iscell(oldfile)
+ oldfile=oldfile{1};
+ end
+end
+%[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile)
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.xml;*.mat', ' (*.xml,*.mat)';
+ '*.xml', '.xml files '; ...
+ '*.mat', '.mat matlab files '}, ...
+ 'Pick a file',oldfile);
+fileinput=[PathName FileName];%complete file name
+testblank=findstr(fileinput,' ');%look for blanks
+if ~isempty(testblank)
+ errordlg('forbidden input file name: contain blanks')
+ return
+end
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
+
+%read the file
+ t=xmltree(fileinput);
+ s=convert(t);
+ if ~isfield(s,'Style')
+ s.Style='points';
+ end
+ if ~isfield(s,'ProjMode')
+ s.ProjMode='none';
+ end
+%Display title
+title=set_title(s.Style,s.ProjMode);%update the title
+if ~isempty(huvmat)
+ hhuvmat=guidata(huvmat);
+% set(hhuvmat.POINTS,'Value',0)
+% set(hhuvmat.POINTS,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.LINE,'Value',0)
+% set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.PATCH,'Value',0)
+% set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.PLANE,'Value',0)
+% set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.VOLUME,'Value',0)
+% set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% if ~isequal(title,'MASK')
+% eval(['set(hhuvmat.' title ',''Value'',1)'])
+% eval(['set(hhuvmat.' title ',''BackgroundColor'',[1 1 0])'])
+% end
+end
+menu=get(handles.TITLE,'String');
+for iline=1:length(menu)
+ if isequal(menu{iline},title)
+ set(handles.TITLE,'Value',iline)
+ break
+ end
+end
+TITLE_Callback(hObject, eventdata, handles)
+teststyle=0;
+% if isfield(s,'Style')
+menu=get(handles.ObjectStyle,'String');
+for iline=1:length(menu)
+ if isequal(menu{iline},s.Style)
+ set(handles.ObjectStyle,'Value',iline)
+ teststyle=1;
+ break
+ end
+end
+testmode=0;
+menu=get(handles.ProjMode,'String');
+for iline=1:length(menu)
+ if isequal(menu{iline},s.ProjMode)
+ set(handles.ProjMode,'Value',iline)
+ testmode=1;
+ break
+ end
+end
+
+ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes
+if isfield(s,'CoordType')
+ if isequal(s.CoordType,'phys')
+ set(handles.MenuCoord,'Value',1)
+ elseif isequal(s.CoordType,'px')
+ set(handles.MenuCoord,'Value',2)
+ else
+ warndlg('unknown CoordType (px or phys) in set_object.m')
+ end
+end
+if isfield(s,'XMax')
+ set(handles.XMax,'String',s.XMax)
+end
+if isfield(s,'XMin')
+ set(handles.XMin,'String',s.XMin)
+end
+if isfield(s,'YMax')
+ set(handles.YMax,'String',s.YMax)
+end
+if isfield(s,'YMin')
+ set(handles.YMin,'String',s.YMin)
+end
+Range=0;
+if isfield(s,'Range')
+ if ischar(s.Range)
+ Range=str2num(s.Range);
+ else
+ Range(1,:)=str2num(s.Range{1});
+ Range(2,:)=str2num(s.Range{2});
+ end
+end
+if size(Range,2)>=3
+ if size(Range,1)>=2
+ set(handles.ZMin,'String',num2str(Range(2,3),3))
+ end
+ if size(Range,1)>=2
+ set(handles.ZMax,'String',num2str(Range(1,3),3))
+ end
+end
+if size(Range,2)>=2
+ if size(Range,1)>=2
+ set(handles.YMin,'String',num2str(Range(2,2),3))
+ end
+ if size(Range,1)>=2
+ set(handles.YMax,'String',num2str(Range(1,2),3))
+ end
+end
+if size(Range,2)>=1
+ if size(Range,1)>=2
+ set(handles.XMin,'String',num2str(Range(2,1),3))
+ end
+ if size(Range,1)>=2
+ set(handles.XMax,'String',num2str(Range(1,1),3))
+ end
+end
+if isfield(s,'RangeX') & ischar(s.RangeX)
+ RangeX=str2num(s.RangeX);
+ set(handles.XMax,'String',num2str(max(RangeX),3))
+ set(handles.XMin,'String',num2str(min(RangeX),3))
+end
+
+if isfield(s,'RangeY')
+ if ischar(s.RangeY)
+ RangeY=str2num(s.RangeY);
+ set(handles.YMax,'String',num2str(max(RangeY),3))
+ set(handles.YMin,'String',num2str(min(RangeY),3))
+ end
+end
+if isfield(s,'RangeZ')
+ if ischar(s.RangeZ)
+ RangeZ=str2num(s.RangeZ);
+ set(handles.ZMax,'String',num2str(max(RangeZ),3))
+ set(handles.ZMin,'String',num2str(min(RangeZ),3))
+ end
+end
+if isfield(s,'Phi')
+ set(handles.Phi,'String',s.Phi)
+end
+if isfield(s,'Theta')
+ set(handles.Theta,'String',s.Theta)
+end
+if isfield(s,'Psi')
+ set(handles.Psi,'String',s.Psi)
+end
+
+if isfield(s,'DX')
+ set(handles.DX,'String',s.DX)
+end
+if isfield(s,'DY')
+ set(handles.DY,'String',s.DY)
+end
+if ~isfield(s,'Coord')
+ XObject='0';%default
+ YObject='0';
+elseif ischar(s.Coord)
+ line=str2num(s.Coord);
+ XObject=num2str(line(1),4);
+ YObject=num2str(line(2),4);
+else
+ for i=1:length(s.Coord)
+ line=str2num(s.Coord{i});
+ XObject{i}=num2str(line(1),4);
+ YObject{i}=num2str(line(2),4);
+ end
+end
+set(handles.XObject,'String',XObject)
+set(handles.YObject,'String',YObject)
+%METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_object_Opening
+
+%----------------------------------------------------
+% executed when closing: set the parent interface button to value 0
+function closefcn(gcbo,eventdata,parent_button)
+
+huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
+if ~isempty(huvmat)
+ hhuvmat=guidata(huvmat);
+ set(hhuvmat.create,'Value',0)
+ set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.LINE,'Value',0)
+% set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.PATCH,'Value',0)
+% set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.PLANE,'Value',0)
+% set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.VOLUME,'Value',0)
+% set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+ set(hhuvmat.edit,'Value',0)
+ set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
+end
+hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
+if ~isempty(hseries)
+ hhseries=guidata(hseries);
+ set(hhseries.GetObject,'Value',0)
+ set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+end
+
+%-----------------------------------------------------------------------
+% --- Executes on button press in PLOT: PLOT the defined object and its projected field
+function PLOT_Callback(hObject, eventdata, handles)
+
+hsetobject=get(handles.PLOT,'parent');
+SetData=get(hsetobject,'UserData');%get the hidden interface data
+huvmat=findobj('Name','uvmat');%find the current uvmat interface handle
+hlist_object=findobj(huvmat,'Tag','list_object');%handles of the object list in the GUI uvmat
+IndexObj=get(hlist_object,'Value');%position in the objet list
+UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
+ObjectData=read_set_object(handles);%read the input parameters defining the object in the GUI set_object
+ObjectData.HandlesDisplay=[]; % new object plot by default
+if length(UvData.Object) >= IndexObj && isfield(UvData.Object{IndexObj},'HandlesDisplay')
+ hdisplay=UvData.Object{IndexObj}.HandlesDisplay;
+ if isequal(UvData.Object{IndexObj}.Style, ObjectData.Style) && isequal(UvData.Object{IndexObj}.ProjMode, ObjectData.ProjMode)
+ ObjectData.HandlesDisplay=UvData.Object{IndexObj}.HandlesDisplay;
+ else % for a new object styl, delete the existing object plots
+ for ih=1:length(hdisplay)
+ PlotData=get(hdisplay(ih),'UserData');
+ if isfield(PlotData,'SubObject') & ishandle(PlotData.SubObject)
+ delete(PlotData.SubObject);
+ end
+ if isfield(PlotData,'DeformPoint') & ishandle(PlotData.DeformPoint)
+ delete(PlotData.DeformPoint);
+ end
+ if ~isequal(hdisplay(ih),0)
+ delete(hdisplay(ih));
+ end
+ end
+ if isfield(ObjectData,'plotaxes') && ishandle(ObjectData.plotaxes)
+ delete(ObjectData.plotaxes)%delete the axes for plotting the current projection result
+ end
+ end
+end
+
+% update the object plot and projection field
+UvData.Object{IndexObj}=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles);
+
+set(huvmat,'UserData',UvData)%update the data in the uvmat interface
+list_str=get(hlist_object,'String');
+TITLE=set_title(ObjectData.Style,ObjectData.ProjMode);
+list_str{IndexObj}=[num2str(IndexObj) '-' TITLE];
+if isequal(length(list_str),IndexObj)
+ list_str{IndexObj+1}='more...';
+end
+set(hlist_object,'String',list_str)
+set(hlist_object,'Value',IndexObj)
+
+%update create buttons on the GUI uvmat: set to object edit mode after object plotting
+hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
+%desactivate all create buttons in mode edit
+% if isequal(get(hhuvmat.edit,'Value'),0)
+ set(hhuvmat.create,'Value',0)
+ set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.LINE,'Value',0)
+% set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.PATCH,'Value',0)
+% set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.PLANE,'Value',0)
+% set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% set(hhuvmat.VOLUME,'Value',0)
+% set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+% end
+set(hhuvmat.edit,'Value',1)
+set(hhuvmat.edit,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
+set(hhuvmat.edit,'Value',1);%
+UvData.MouseAction='edit_object'; % set the edit button to 'on'
+set(huvmat,'UserData',UvData)
+
+% --- Executes on button press in MenuCoord.
+function MenuCoord_Callback(hObject, eventdata, handles)
+
+%----------------------------------------------------
+function YMin_Callback(hObject, eventdata, handles)
+
+
+function ZMin_Callback(hObject, eventdata, handles)
+
+
+function ZMax_Callback(hObject, eventdata, handles)
+DZ=str2num(get(handles.ZMax,'String'));
+ZMin=get(handles.z_slider,'Min');
+ZMax=get(handles.z_slider,'Max');
+if ~isequal(ZMax-ZMin,0)
+ rel_step(1)=DZ/(ZMax-ZMin);
+ rel_step(2)=0.2;
+ set(handles.z_slider,'SliderStep',rel_step)
+end
+
+function YMax_Callback(hObject, eventdata, handles)
+
+
+function XMin_Callback(hObject, eventdata, handles)
+
+
+function XMax_Callback(hObject, eventdata, handles)
+
+
+% ------------------------------------------------------
+function SAVE_Callback(hObject, eventdata, handles)
+% ------------------------------------------------------
+Object=read_set_object(handles);
+huvmat=findobj('Tag','uvmat');
+% UvData=get(huvmat,'UserData');
+if isempty(huvmat)
+ huvmat=findobj(allchild(0),'Name','series');
+end
+hchild=get(huvmat,'Children');
+hrootpath=findobj(hchild,'Tag','RootPath');
+if isempty(hrootpath)
+ RootPath='';
+else
+ RootPath=get(hrootpath,'String');
+ if iscell(RootPath)
+ RootPath=RootPath{1};
+ end
+end
+title={'object name'};
+dir_save=uigetdir(RootPath);
+def={fullfile(dir_save,['Object' Object.CoordType '.xml'])};
+options.Resize='on';
+displ_txt='save object as an .xml file';%default display
+menu=get(handles.ProjMode,'String');
+value=get(handles.ProjMode,'Value');
+ProjMode=menu{value};
+if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
+ displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
+end
+answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
+%answer=inputdlg('','save object in a new .xml file',1,def,'on');
+if ~isempty(answer)
+ t=struct2xml(Object);
+ save(t,answer{1})
+end
+msgbox_uvmat('CONFIRMATION',[answer{1} ' saved'])
+%---------------------------------------------------------
+% --- Executes on slider movement.
+function z_slider_Callback(hObject, eventdata, handles)
+%---------------------------------------------------------
+%A ADAPTER
+Z_value=get(handles.z_slider,'Value');
+
+%rotation angles
+Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
+Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
+
+%components of the unity vector normal to the projection plane
+NormVec_X=-sin(Phi)*sin(Theta);
+NormVec_Y=cos(Phi)*sin(Theta);
+NormVec_Z=cos(Theta);
+
+%set new plane position and update graph
+set(handles.XObject,'String',num2str(NormVec_X*Z_value,4))
+set(handles.YObject,'String',num2str(NormVec_Y*Z_value,4))
+set(handles.ZObject,'String',num2str(NormVec_Z*Z_value,4))
+PLOT_Callback(hObject, eventdata, handles)
+
+
+
+function XObject_Callback(hObject, eventdata, handles)
+
+
+function YObject_Callback(hObject, eventdata, handles)
+
+
+
+
+function ZObject_Callback(hObject, eventdata, handles)
+
+
+% --- Executes on button press in HELP.
+function HELP_Callback(hObject, eventdata, handles)
+path_to_uvmat=which ('uvmat');% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+else
+ web([helpfile '#set_object'])
+end
+
+
+
+
Index: /trunk/src/set_title.m
===================================================================
--- /trunk/src/set_title.m (revision 2)
+++ /trunk/src/set_title.m (revision 2)
@@ -0,0 +1,30 @@
+%'set_title': defines the 'TITLE' of a projection object
+%-----------------------------------------------------------
+% function TITLE=set_title(Style,ProjMode)
+% OUTPUT:
+% TITLE: char string defining the title
+%
+% INPUT:
+% Style: char string defining the style of the projection opbject
+% ProjMode: char string defining the projection mode
+%------------------------------------------------
+function TITLE=set_title(Style,ProjMode)
+%------------------------------------------------
+TITLE=[]; %default
+if isequal(Style,'points')
+ TITLE='POINTS';
+elseif isequal(Style,'line')|isequal(Style,'polyline')
+ TITLE='LINE';
+elseif isequal(Style,'plane')
+ TITLE='PLANE';
+elseif isequal(Style,'volume')
+ TITLE='VOLUME';
+elseif isequal(Style,'polygon')|isequal(Style,'rectangle')|isequal(Style,'ellipse')
+ if isequal(ProjMode,'inside')|isequal(ProjMode,'outside')
+ TITLE='PATCH';
+ elseif isequal(ProjMode,'mask_inside')|isequal(ProjMode,'mask_outside')
+ TITLE='MASK';
+ else
+ TITLE='LINE';
+ end
+end
Index: /trunk/src/stra2num.m
===================================================================
--- /trunk/src/stra2num.m (revision 2)
+++ /trunk/src/stra2num.m (revision 2)
@@ -0,0 +1,21 @@
+%'stra2num': transform letters (a, b, c) or numerical strings ('1','2'..) to the corresponding numbers
+%--------------------------------------------
+% function numres=stra2num(str)
+%
+% OUTPUT:
+% numres: number (double)
+%
+% INPUT:
+% str: string corresponding to a number or a letter 'a' 'b',.., otherwise the output is empty
+%
+% see also num2stra, name_generator, name2display
+
+function numres=stra2num(str)
+numres=[]; %default
+if double(str) >= 48 & double(str) <= 57 % = test for number strings
+ numres=str2num(str);
+elseif double(str) >= 65 & double(str) <= 90 % test on ascii code for capital letters
+ numres=double(str)-64; %change capital letters to corresponding number in the alphabet
+elseif double(str) >= 97 & double(str) <= 122 % test on ascii code for small letters
+ numres=double(str)-96; %change small letters to corresponding number in the alphabet
+end
Index: /trunk/src/struct2nc.m
===================================================================
--- /trunk/src/struct2nc.m (revision 2)
+++ /trunk/src/struct2nc.m (revision 2)
@@ -0,0 +1,144 @@
+%'struct2nc': create a netcdf file from a Matlab structure
+%---------------------------------------------------------------------
+% errormsg=struct2nc(flname,Data)
+%
+%OUPUT:
+%errormsg=error message, =[]: default, no error
+%
+%INPUT:
+%flname: name of the netcdf file to create (must end with the extension '.nc')
+% Data: structure containing all the information of the netcdf file (or netcdf object)
+% with fields:
+% .ListGlobalAttribute: cell listing the names of the global attributes (note that a global atribute with the same name as a variable is excluded)
+% .Att_1,Att_2... : values of the global attributes
+% .ListDimName: cell listing the names of the array dimensions
+% .DimValue: array dimension values (Matlab vector with the same length as .ListDimName
+% .ListVarName: cell listing the names of the variables
+% .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName
+% .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
+% .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function errormsg=struct2nc(flname,Data)
+if ~ischar(flname)
+ errormsg='no name input for the netcf file';
+ return
+end
+if ~exist('Data','var')
+ errormsg='no data input for the netcdf file';
+ return
+end
+hhh=which('netcdf.create');% look for built-in matlab library
+
+%USE OF built-in netcdf library
+if ~isequal(hhh,'')
+ FilePath=fileparts(flname);
+ if ~strcmp(FilePath,'') && ~exist(FilePath,'dir')
+ errormsg=['directory ' FilePath ' needs to be created'];
+ return
+ end
+ [Data,errormsg]=check_field_structure(Data);%check the validity of the input field structure
+ ListVarName=Data.ListVarName;
+ nc=netcdf.create(flname,'NC_CLOBBER');%,'clobber'); %create the netcdf file with name flname
+ %write global constants
+ if isfield(Data,'ListGlobalAttribute')
+ keys=Data.ListGlobalAttribute;
+ for iattr=1:length(keys)
+ if isfield(Data,keys{iattr})
+ testvar=0;
+ for ivar=1:length(ListVarName)% eliminate possible global attributes with the same name as a variable
+ if isequal(ListVarName{ivar}, keys{iattr})
+ testvar=1;
+ break
+ end
+ end
+ if ~testvar
+ eval(['cte=Data.' keys{iattr} ';'])
+ if (ischar(cte) ||isnumeric(cte)) && ~isempty(cte)&& ~isequal(cte,'')
+ netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),keys{iattr},cte)
+ else
+ errormsg='global attributes must be characters or numbers';
+ return
+ end
+ end
+ end
+ end
+ end
+ %create dimensions
+ dimid=[];
+ for idim=1:length(Data.ListDimName)
+ dimid(idim) = netcdf.defDim(nc,Data.ListDimName{idim},Data.DimValue(idim));
+ end
+ VarAttribute={}; %default
+ testattr=0;
+ if isfield(Data,'VarAttribute')
+ VarAttribute=Data.VarAttribute;
+ testattr=1;
+ end
+ varid=[];
+ for ivar=1:length(ListVarName)
+ varid(ivar)=netcdf.defVar(nc,ListVarName{ivar},'double',dimid(Data.VarDimIndex{ivar}));%define variable
+ end
+ %write variable attributes
+ if testattr
+ for ivar=1:length(VarAttribute)
+ if isstruct(VarAttribute{ivar})
+ attr_names=fields(VarAttribute{ivar});
+ for iattr=1:length(attr_names)
+ eval(['attr_val=VarAttribute{ivar}.' attr_names{iattr} ';']);
+ netcdf.putAtt(nc,varid(ivar),attr_names{iattr},attr_val);
+ end
+ end
+ end
+ end
+ netcdf.endDef(nc); %put in data mode
+ for ivar=1:length(ListVarName)
+ if isfield(Data,ListVarName{ivar})
+ eval(['VarVal=Data.' ListVarName{ivar} ';'])%varval=values of the current variable
+ VarDimIndex=Data.VarDimIndex{ivar}; %indices of the variable dimensions in the list of dimensions
+ siz=size(VarVal);
+ VarDimName=Data.VarDimName{ivar};%NEW
+ if ischar(VarDimName)%NEW
+ VarDimName={VarDimName};%NEW
+ end%NEW
+ testrange=(numel(VarDimName)==1 && strcmp(VarDimName{1},ListVarName{ivar}) && numel(VarVal)==2); %NEW
+ testline=isequal(length(siz),2) && isequal(siz(1),1)&& isequal(siz(2), Data.DimValue(VarDimIndex));
+ testcolumn=isequal(length(siz),2) && isequal(siz(1), Data.DimValue(VarDimIndex))&& isequal(siz(2),1);
+ if ~testline && ~testcolumn && ~isequal(siz,Data.DimValue(VarDimIndex))
+ errormsg=['wrong dimensions declared for ' ListVarName{ivar} ' in struct2nc.m'];
+ break
+ end
+ if testline || testrange%NEW
+ if testrange
+ VarVal=linspace(VarVal(1),VarVal(2),Data.DimValue(VarDimIndex));%NEW
+ end
+ %nc{ListVarName{ivar}}=ncfloat(Data.ListDimName(VarDimIndex));%vector of x coordinates
+ netcdf.putVar(nc,varid(ivar), VarVal');
+ else
+ netcdf.putVar(nc,varid(ivar), VarVal);
+ %nc{ListVarName{ivar}}(:) = VarVal;
+ end
+
+ end
+ end
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%OLD netcdf toolbox
+else
+ errormsg=struct2nc_toolbox(flname,Data);
+end
+
Index: /trunk/src/struct2nc_toolbox.m
===================================================================
--- /trunk/src/struct2nc_toolbox.m (revision 2)
+++ /trunk/src/struct2nc_toolbox.m (revision 2)
@@ -0,0 +1,132 @@
+%'struct2nc_toolbox': create a netcdf file from a Matlab structure: use of netcdf toolbox
+%---------------------------------------------------------------------
+% errormsg=struct2nc_toolbox(flname,Data)
+%
+%OUPUT:
+%errormsg=error message, =[]: default, no error
+%
+%INPUT:
+%flname: name of the netcdf file to create (must end with the extension '.nc')
+% Data: structure containing all the information of the netcdf file (or netcdf object)
+% with fields:
+% .ListGlobalAttribute: cell listing the names of the global attributes (note that a global atribute with the same name as a variable is excluded)
+% .Att_1,Att_2... : values of the global attributes
+% .ListDimName: cell listing the names of the array dimensions
+% .DimValue: array dimension values (Matlab vector with the same length as .ListDimName
+% .ListVarName: cell listing the names of the variables
+% .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName
+% .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
+% .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This file is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function errormsg=struct2nc_toolbox(flname,Data)
+
+FilePath=fileparts(flname);
+if ~strcmp(FilePath,'') &&~exist(FilePath,'dir')
+ errormsg=['directory ' FilePath ' needs to be created'];
+ return
+end
+[Data,errormsg]=check_field_structure(Data);
+if ~isempty(errormsg)
+ return
+end
+ListVarName=Data.ListVarName;
+nc=netcdf(flname,'clobber'); %create the netcdf file with name flname
+%write global constants
+if isfield(Data,'ListGlobalAttribute')
+ keys=Data.ListGlobalAttribute;
+ for iattr=1:length(keys)
+ if isfield(Data,keys{iattr})
+ testvar=0;
+ for ivar=1:length(ListVarName)% eliminate possible global attributes with the same name as a variable
+ if isequal(ListVarName{ivar}, keys{iattr})
+ testvar=1;
+ break
+ end
+ end
+ if ~testvar
+ eval(['cte=Data.' keys{iattr} ';'])
+ if ischar(cte) && ~isequal(cte,'')
+ eval(['nc.' keys{iattr} '=''' cte ''';']);
+ elseif isnumeric(cte)&& ~isempty(cte)
+ eval(['nc.' keys{iattr} '= cte; ']);
+ else
+ errormsg='global attributes must be characters or numbers';
+ return
+ end
+ end
+ end
+ end
+end
+for idim=1:length(Data.ListDimName)
+ nc(Data.ListDimName{idim})=Data.DimValue(idim);%create dimensions
+end
+
+VarAttribute={}; %default
+testattr=0;
+if isfield(Data,'VarAttribute')
+ VarAttribute=Data.VarAttribute;
+ testattr=1;
+end
+for ivar=1:length(ListVarName)
+ if isfield(Data,ListVarName{ivar})
+ eval(['VarVal=Data.' ListVarName{ivar} ';'])%varval=values of the current variable
+ siz=size(VarVal);
+ VarDimIndex=Data.VarDimIndex{ivar}; %indices of the variable dimensions in the list of dimensions
+ VarDimName=Data.VarDimName{ivar};%NEW
+ if ischar(VarDimName)%NEW
+ VarDimName={VarDimName};%NEW
+ end%NEW
+ testrange=(numel(VarDimName)==1 && strcmp(VarDimName{1},ListVarName{ivar}) && numel(VarVal)==2); %NEW
+ testline=isequal(length(siz),2) & isequal(siz(1),1)& isequal(siz(2), Data.DimValue(VarDimIndex));
+ testcolumn=isequal(length(siz),2) & isequal(siz(1), Data.DimValue(VarDimIndex))& isequal(siz(2),1);
+ if ~testrange && ~testline && ~testcolumn && ~isequal(siz,Data.DimValue(VarDimIndex))
+ errormsg=['wrong dimensions declared for ' ListVarName{ivar} ' in struct2nc.m'];
+ break
+ end
+ if testline || testrange%NEW
+ dimname=Data.ListDimName{VarDimIndex};
+ if testrange%NEW
+ VarVal=linspace(VarVal(1),VarVal(2),Data.DimValue(VarDimIndex));%NEW
+ end%NEW
+ nc{ListVarName{ivar}}=ncfloat(dimname);%vector of x coordinates
+ nc{ListVarName{ivar}}(:) = VarVal';
+ else
+ nc{ListVarName{ivar}}=ncfloat(Data.ListDimName(VarDimIndex));%vector of x coordinates
+ nc{ListVarName{ivar}}(:) = VarVal;
+ end
+ %write variable attributes
+ if testattr
+ for ivar=1:length(VarAttribute)
+ if isstruct(VarAttribute{ivar})
+ attr_names=fields(VarAttribute{ivar});
+ for iattr=1:length(attr_names)
+ eval(['attr_val=VarAttribute{ivar}.' attr_names{iattr} ';']);
+ if ischar(attr_val) && ~isequal(attr_val,'')
+ eval(['nc{''' ListVarName{ivar} '''}.' attr_names{iattr} '=''' attr_val ''';'])
+ elseif isnumeric(attr_val)&& ~isempty(attr_val)
+ eval(['nc{''' ListVarName{ivar} '''}.' attr_names{iattr} '=attr_val ;'])
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+close(nc);
Index: /trunk/src/struct2xml.m
===================================================================
--- /trunk/src/struct2xml.m (revision 2)
+++ /trunk/src/struct2xml.m (revision 2)
@@ -0,0 +1,62 @@
+%'struct2xml': transform a matlab structure to a xml tree.
+%--------------------------------------------------------------
+% each field with char string or num vector is transformed into a corresponding xml element
+% each field with a matrix containing n lines is transformed into a xml element repeated n times
+% WARNING: PROBLEM WITH HIERARCHICAL structures
+%%%%%%%%%%%%%%%%%%%%%%%
+% OUTPUT:
+% t: xmltree reproducing the structure of Object
+% type 'save(t)' to visualize the xml text and save(filename,t) to save it in a file
+%
+% INPUT:
+% Object: matlab structure, possibly hierarchical
+% t: optional input xml tree in which a new branch needs to be appended
+% root_uid: optional uid of the xml element under which the new subtree must be appended
+
+function t=struct2xml(Object,t,root_uid)
+get(t,root_uid)
+if ~exist('t','var')
+ t=xmltree;
+end
+if ~exist('root_uid','var')
+ root_uid=1;
+end
+fieldnames=fields(Object);
+for ilist=1:length(fieldnames)
+ eval(['val=Object.' fieldnames{ilist} ';'])
+ if isstruct(val)
+ [t,uid]=add(t,root_uid,'element',fieldnames{ilist});
+ fieldnames_sub=fields(val);
+ for ilist_sub=1:length(fieldnames_sub)
+ if isstruct(fieldnames_sub{ilist_sub})
+ t=struct2xml(fieldnames_sub{ilist_sub},t,uid);
+ save(t)
+ else
+ eval(['val_sub=val.' fieldnames_sub{ilist_sub} ';'])
+ t=add_element(t,uid,fieldnames_sub{ilist_sub},val_sub);
+ end
+ end
+ else
+ t=add_element(t,root_uid,fieldnames{ilist},val);
+ end
+end
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function t=add_element(t,uid,key,val)
+ if ischar(val)
+ [t,new_uid]=add(t,uid,'element',key);
+ [t]=add(t,new_uid,'chardata',val);
+ elseif isnumeric(val)
+ siz=size(val);
+ if length(siz)<=2 %do not translate matrices with more than 2 indices
+ for iline=1:siz(1)
+ val_str=num2str(val(iline,:),'%g\t');
+ [t,new_uid]=add(t,uid,'element',key);
+ if siz(1)>1
+ t = attributes(t,'add',new_uid,'i',num2str(iline));
+ end
+ [t]=add(t,new_uid,'chardata',val_str);
+ end
+ end
+ end
Index: /trunk/src/sub_field.m
===================================================================
--- /trunk/src/sub_field.m (revision 2)
+++ /trunk/src/sub_field.m (revision 2)
@@ -0,0 +1,354 @@
+%'sub_field': combines two input fields
+%-----------------------------------------------------------------------
+% function SubData=sub_field(Field,Field_1)
+%
+% OUPUT:
+% SubData: structure representing the resulting field
+%
+% INPUT:
+% UvData: main structure UvData associated to the uvmat GUI as 'UserData'
+% Field: cell of Matlab structures representing the input fields
+%
+% -- TODO: need to be rationalized --
+
+function [SubData,errormsg]=sub_field(Field,Field_1)
+test_attr=0;
+if isfield(Field,'ListGlobalAttribute')
+ SubData.ListGlobalAttribute=Field.ListGlobalAttribute;
+ for ilist=1:numel(Field.ListGlobalAttribute)
+ AttrName=Field.ListGlobalAttribute{ilist};
+ eval(['SubData.' AttrName '=Field.' AttrName ';'])
+ end
+ test_attr=1;
+end
+if isfield(Field_1,'ListGlobalAttribute')
+ for ilist=1:numel(Field_1.ListGlobalAttribute)
+ test_1=1;
+ AttrName=Field_1.ListGlobalAttribute{ilist};
+ if test_attr
+ for i_prev=1:numel(Field.ListGlobalAttribute)
+ if isequal(Field.ListGlobalAttribute{i_prev},AttrName)
+ test_1=0; %attribute already written
+ eval(['Val=Field.' AttrName ';'])
+ eval(['Val_1=Field_1.' AttrName ';'])
+ if isequal(Val,Val_1)
+ break% data already written
+ else
+ eval(['SubData.' AttrName '_1=Field_1.' AttrName ';'])
+ end
+ end
+ end
+ end
+ if test_1
+ eval(['SubData.' AttrName '=Field_1.' AttrName ';'])
+ end
+ end
+end
+SubData.ListVarName=Field.ListVarName;
+SubData.VarDimName=Field.VarDimName;
+if isfield(Field,'VarAttribute')
+ SubData.VarAttribute=Field.VarAttribute;
+end
+%reproduce Field by default
+for ivar=1:numel(Field.ListVarName)
+ VarName=Field.ListVarName{ivar};
+ eval(['SubData.' VarName '=Field.' VarName ';'])
+end
+
+%fields
+[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(Field);
+if ~isempty(errormsg)
+ errormsg=['invalid first input to sub_field:' errormsg];
+ return
+end
+[CellVarIndex_1,NbDim_1,VarTypeCell_1,errormsg]=find_field_indices(Field_1);
+if ~isempty(errormsg)
+ errormsg=['invalid second input to sub_field:' errormsg];
+ return
+end
+iselect=find(NbDim==2);
+if ~isequal(numel(iselect),1)
+ errormsg='invalid first input to sub_field: it must contain a single 2D field cell';
+ return
+end
+iselect_1=find(NbDim_1==2);
+if ~isequal(numel(iselect_1),1)
+ errormsg='invalid second input to sub_field: it must contain a single 2D field cell';
+ return
+end
+% VarIndex=CellVarIndex{iselect};
+% VarIndex_1=CellVarIndex_1{iselect_1};
+VarType=VarTypeCell{iselect};
+VarType_1=VarTypeCell_1{iselect_1};
+testX=~isempty(VarType.coord_x)&& ~isempty(VarType.coord_y);%unstructured coordiantes
+testX_1=~isempty(VarType_1.coord_x)&& ~isempty(VarType_1.coord_y);%unstructured coordiantes
+testU=~isempty(VarType.vector_x)&& ~isempty(VarType.vector_y);%vector field
+testU_1=~isempty(VarType_1.vector_x)&& ~isempty(VarType_1.vector_y);%vector field
+% testfalse=~isempty(VarType.errorflag);
+testfalse_1=~isempty(VarType_1.errorflag);
+ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields
+if numel(ivar_C)>1
+ errormsg='too many scalar fields in the first input of sub_field.m';
+ return
+end
+ivar_C_1=[VarType_1.scalar VarType_1.image VarType_1.color VarType_1.ancillary]; %defines index (indices) for the scalar or ancillary fields
+if numel(ivar_C_1)>1
+ errormsg='too many scalar fields in the second input of sub_field.m';
+ return
+end
+
+%substract two vector fields or two scalars
+if (testU && testU_1) || (~testU && ~testU_1)
+ %check coincidence in positions
+ %unstructured coordinates
+ if testX
+ XName=Field.ListVarName{VarType.coord_x};
+ YName=Field.ListVarName{VarType.coord_y};
+ eval(['vec_X=Field.' XName ';'])
+ eval(['vec_Y=Field.' YName ';'])
+ nbpoints=numel(vec_X);
+ vec_X=reshape(vec_X,1,nbpoints);
+ vec_Y=reshape(vec_Y,1,nbpoints);
+ if testX_1 %unstructured coordinates for the second field
+ X_1_Name=Field_1.ListVarName{VarType_1.coord_x};
+ Y_1_Name=Field_1.ListVarName{VarType_1.coord_y};
+ eval(['vec_X_1=Field_1.' X_1_Name ';'])
+ eval(['vec_Y_1=Field_1.' Y_1_Name ';'])
+ nbpoints_1=numel(vec_X_1);
+ else %structured coordinates for the second field
+ y_1_Name=Field_1.ListVarName{VarType_1.coord(1)};
+ x_1_Name=Field_1.ListVarName{VarType_1.coord(2)};
+ eval(['y_1=Field_1.' y_1_Name ';'])
+ eval(['x_1=Field_1.' x_1_Name ';'])
+ npxy(1)=numel(y_1);
+ npxy(2)=numel(x_1);
+ nbpoints_1=npxy(1)*npxy(2);
+ [vec_X_1,vec_Y_1]=meshgrid(x_1,y_1);
+ end
+ vec_X_1=reshape(vec_X_1,1,nbpoints_1);
+ vec_Y_1=reshape(vec_Y_1,1,nbpoints_1);
+ if testfalse_1
+ FFName_1=Field_1.ListVarName{VarType_1.errorflag};
+ eval(['vec_FF_1=Field_1.' FFName_1 ';'])
+ vec_FF_1=reshape(vec_FF_1,1,nbpoints_1);
+ indsel=find(~vec_FF_1);
+ vec_X_1=vec_X_1(indsel);
+ vec_Y_1=vec_Y_1(indsel);
+ end
+ if testU % vector fields
+ U_1_Name=Field_1.ListVarName{VarType_1.vector_x};
+ V_1_Name=Field_1.ListVarName{VarType_1.vector_y};
+ eval(['vec_U_1=Field_1.' U_1_Name ';'])
+ eval(['vec_V_1=Field_1.' V_1_Name ';'])
+ vec_U_1=reshape(vec_U_1,1,nbpoints_1);
+ vec_V_1=reshape(vec_V_1,1,nbpoints_1);
+ if testfalse_1
+ vec_U_1=vec_U_1(indsel);
+ vec_V_1=vec_V_1(indsel);
+ end
+ else
+ A_1_Name=Field_1.ListVarName{ivar_C_1};
+ eval(['vec_A_1=Field_1.' A_1_Name ';'])
+ vec_A_1=reshape(vec_A_1,1,nbpoints_1);
+ if testfalse_1
+ vec_A_1=vec_A_1(indsel);
+ end
+ end
+ if ~isequal(vec_X_1,vec_X) && ~isequal(vec_Y_1,vec_Y) % if the unstructured positions are not the same
+ if testU
+ vec_U_1=griddata_uvmat(vec_X_1,vec_Y_1,vec_U_1,vec_X,vec_Y); %interpolate vectors in the second field
+ vec_V_1=griddata_uvmat(vec_X_1,vec_Y_1,vec_V_1,vec_X,vec_Y); %interpolate vectors in the second field
+ else
+ vec_A_1=griddata_uvmat(vec_X_1,vec_Y_1,vec_A_1,vec_X,vec_Y); %interpolate vectors in the second field
+ end
+ end
+ if testU
+ UName=Field.ListVarName{VarType.vector_x};
+ VName=Field.ListVarName{VarType.vector_y};
+ eval(['vec_U=Field.' UName ';'])
+ eval(['vec_V=Field.' VName ';'])
+ vec_U=reshape(vec_U,1,numel(vec_U));
+ vec_V=reshape(vec_V,1,numel(vec_V));
+ eval(['SubData.' UName '=vec_U-vec_U_1;'])
+ eval(['SubData.' VName '=vec_V-vec_V_1;'])
+ else
+ AName=Field.ListVarName{ivar_C};
+ eval(['SubData.' AName '=Field.' AName '-vec_A_1;'])
+ end
+ else %structured coordiantes
+ XName=Field.ListVarName{VarType.coord(2)};
+ YName=Field.ListVarName{VarType.coord(1)};
+ eval(['x=Field.' XName ';'])
+ eval(['y=Field.' YName ';'])
+ if testX_1 %unstructured coordinates for the second field
+ errormsg='the second input scalar is not on a regular grid: comparison option not implemented';
+ return
+ else
+ XName_1=Field.ListVarName{VarType_1.coord(2)};
+ YName_1=Field.ListVarName{VarType_1.coord(1)};
+ eval(['x_1=Field_1.' XName_1 ';'])
+ eval(['y_1=Field_1.' YName_1 ';'])
+ end
+ if testU % vector fields
+ UName=Field.ListVarName{VarType.vector_x};
+ VName=Field.ListVarName{VarType.vector_y};
+ U_1_Name=Field_1.ListVarName{VarType_1.vector_x};
+ V_1_Name=Field_1.ListVarName{VarType_1.vector_y};
+ eval(['U_1=Field_1.' U_1_Name ';'])
+ eval(['V_1=Field_1.' V_1_Name ';'])
+ if ~isequal(x_1,x)||~isequal(y_1,y)
+ [X_1,Y_1]=meshgrid(x_1,y_1);
+ U_1 =interp2(X_1,Y_1,U_1,x,y');
+ V_1 =interp2(X_1,Y_1,V_1,x,y');
+ end
+ val(['SubData.' UName '=Field.' UName '-U_1;'])
+ val(['SubData.' VName '=Field.' VName '-V_1;'])
+ else
+ AName=Field.ListVarName{ivar_C};
+ A_1_Name=Field_1.ListVarName{ivar_C_1};
+ eval(['A_1=double(Field_1.' A_1_Name ');'])
+ if ~isequal(x_1,x)||~isequal(y_1,y)
+ [X_1,Y_1]=meshgrid(x_1,y_1);
+ A_1 =interp2(X_1,Y_1,A_1,x,y');
+ end
+ eval(['SubData.' AName '=double(Field.' AName ')-A_1;'])
+ end
+ end
+end
+
+% merge a vector field and a scalar as second input
+if testU && ~testU_1
+ AName_1=Field_1.ListVarName{ivar_C_1};
+ if isfield(Field_1,'VarAttribute') && numel(Field_1.VarAttribute)>=ivar_C_1
+ AAttr=Field_1.VarAttribute{ivar_C_1} ;
+ else
+ AAttr=[];
+ end
+ if testX_1 %unstructured coordinate
+ XName_1=Field_1.ListVarName{VarType_1.coord_x};
+ YName_1=Field_1.ListVarName{VarType_1.coord_y};
+ SubData.ListVarName=[SubData.ListVarName {XName_1} {YName_1}];
+ DimCell=Field_1.VarDimName([VarType_1.coord_x VarType_1.coord_y ]);
+ if isfield(Field_1,'VarAttribute')
+ if numel(Field_1.VarAttribute)>=VarType_1.coord_x
+ XAttr=Field_1.VarAttribute{VarType_1.coord_x} ;
+ else
+ XAttr=[];
+ end
+ if numel(Field_1.VarAttribute)>=VarType_1.coord_y
+ YAttr=Field_1.VarAttribute{VarType_1.coord_y} ;
+ else
+ YAttr=[];
+ end
+ SubData.VarAttribute=[SubData.VarAttribute {XAttr} {YAttr}];
+ end
+ else
+ XName_1=Field_1.ListVarName{VarType_1.coord(2)};
+ YName_1=Field_1.ListVarName{VarType_1.coord(1)};
+% DimCell=[{YName_1} {XName_1}];
+ if isfield(Field_1,'VarAttribute')
+ if numel(Field_1.VarAttribute)>=VarType_1.coord(2)
+ XAttr=Field_1.VarAttribute{VarType_1.coord(2)} ;
+ else
+ XAttr=[];
+ end
+ if numel(Field_1.VarAttribute)>=VarType_1.coord(1)
+ YAttr=Field_1.VarAttribute{VarType_1.coord(1)} ;
+ else
+ YAttr=[];
+ end
+ SubData.VarAttribute=[SubData.VarAttribute {YAttr} {XAttr}];
+ end
+ end
+ %look for previously used variable names
+ XName_1_1=XName_1;%default
+ YName_1_1=YName_1;%default
+ AName_1_1=AName_1;%default
+ for iprev=1:numel(SubData.ListVarName)
+ switch SubData.ListVarName{iprev}
+ case XName_1
+ XName_1_1=[XName_1 '_1'];
+ case YName_1
+ YName_1_1=[YName_1 '_1'];
+ case AName_1
+ AName_1_1=[AName_1 '_1'];
+ end
+ end
+ if ~testX_1
+ DimCell=[{XName_1_1} {YName_1_1}];
+ end
+ SubData.ListVarName=[SubData.ListVarName {XName_1_1} {YName_1_1} {AName_1_1}];
+ DimCell=[DimCell Field_1.VarDimName(ivar_C_1)]; %(TODO: check for dimension names)
+ SubData.VarDimName=[SubData.VarDimName DimCell];
+ if isfield(Field_1,'VarAttribute')
+ SubData.VarAttribute=[SubData.VarAttribute {AAttr}];
+ end
+ eval(['SubData.' XName_1_1 '=Field_1.' XName_1 ';'])
+ eval(['SubData.' YName_1_1 '=Field_1.' YName_1 ';'])
+ eval(['SubData.' AName_1_1 '=Field_1.' AName_1 ';'])
+end
+
+%merge a scalar as the first input and a vector field as second input
+if ~testU && testU_1
+ UName_1=Field_1.ListVarName{VarType_1.vector_x};
+ VName_1=Field_1.ListVarName{VarType_1.vector_y};
+ UAttr=Field_1.VarAttribute{VarType_1.vector_x};
+ VAttr=Field_1.VarAttribute{VarType_1.vector_y};
+ if testX_1 %unstructured coordinate for the second field
+ XName_1=Field_1.ListVarName{VarType_1.coord_x};
+ YName_1=Field_1.ListVarName{VarType_1.coord_y};
+
+ XAttr=Field_1.VarAttribute{VarType_1.coord_x};
+ YAttr=Field_1.VarAttribute{VarType_1.coord_y};
+% SubData.ListVarName=[SubData.ListVarName {XName_1} {YName_1}];
+ DimCell=Field_1.VarDimName([VarType_1.coord_x VarType_1.coord_y ]);
+ else
+ XName_1=Field_1.ListVarName{VarType_1.coord(2)};
+ YName_1=Field_1.ListVarName{VarType_1.coord(1)};
+ if numel(Field_1.VarAttribute)>=VarType_1.coord(2)
+ XAttr=Field_1.VarAttribute{VarType_1.coord(2)};
+ else
+ XAttr=[];
+ end
+ if numel(Field_1.VarAttribute)>=VarType_1.coord(1)
+ YAttr=Field_1.VarAttribute{VarType_1.coord(1)};
+ else
+ YAttr=[];
+ end
+ end
+ %check for the existence of the same variable name
+ XName_1_1=XName_1; %default
+ YName_1_1=YName_1; %default
+ UName_1_1=UName_1; %default
+ VName_1_1=VName_1; %default
+ for iprev=1:numel(SubData.ListVarName)
+ switch SubData.ListVarName{iprev}
+ case XName_1
+ XName_1_1=[XName_1 '_1'];
+ case YName_1
+ YName_1_1=[YName_1 '_1'];
+ case UName_1
+ UName_1_1=[UName_1 '_1'];
+ case VName_1
+ VName_1_1=[VName_1 '_1'];
+ end
+ end
+ if ~testX_1
+ DimCell=[{XName_1_1} {YName_1_1}];
+ end
+ SubData.ListVarName=[SubData.ListVarName {XName_1_1} {YName_1_1} {UName_1_1} {VName_1_1}];
+ DimCell=[DimCell Field_1.VarDimName([VarType_1.vector_x VarType_1.vector_y ])];
+ SubData.VarDimName=[SubData.VarDimName DimCell];
+ if ~(isfield(SubData,'VarAttribute') && numel(SubData.VarAttribute)==numel(SubData.ListVarName))
+ for ivar=numel(SubData.VarAttribute)+1:numel(SubData.ListVarName)-4
+ SubData.VarAttribute{ivar}=[];
+ end
+ end
+ SubData.VarAttribute=[SubData.VarAttribute {XAttr} {YAttr} {UAttr} {VAttr}];
+ eval(['SubData.' XName_1_1 '=Field_1.' XName_1 ';'])
+ eval(['SubData.' YName_1_1 '=Field_1.' YName_1 ';'])
+ eval(['SubData.' UName_1_1 '=Field_1.' UName_1 ';'])
+ eval(['SubData.' VName_1_1 '=Field_1.' VName_1 ';'])
+end
+
+
Index: /trunk/src/translate_points.m
===================================================================
--- /trunk/src/translate_points.m (revision 2)
+++ /trunk/src/translate_points.m (revision 2)
@@ -0,0 +1,166 @@
+%'translate_points': associated with GUI translate_points.fig to display message boxes, for error, warning or input calls
+% translate_points(title,display)
+%
+% OUTPUT:
+% answer (text string)= 'yes', 'No', 'cancel', or the text string introduced as input
+%
+%INPUT:
+% title: string indicating the type of message box:
+% title= 'INPUT_TXT','CONFIMATION' ,'ERROR', 'WARNING', 'INPUT_Y-N', default = 'INPUT_TXT' (the title is displayed in the upper bar of the fig).
+% if title='INPUT_TXT', input data is asked in an edit box
+% if title='CONFIMATION'', 'ERROR', 'WARNING', the figure remains opened until a button 'OK' is pressed
+% if title='INPUT_Y-N', an answer Yes/No is requested
+% display, displayed text
+% default_answer: default answer in the edit box (only used with title='INPUT_TXT')
+
+function varargout = translate_points(varargin)
+
+% Last Modified by GUIDE v2.5 05-Jan-2010 09:49:31
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @translate_points_OpeningFcn, ...
+ 'gui_OutputFcn', @translate_points_OutputFcn, ...
+ 'gui_LayoutFcn', [] , ...
+ 'gui_Callback', []);
+if nargin && ischar(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+% --- Executes just before translate_points is made visible.
+function translate_points_OpeningFcn(hObject, eventdata, handles,input_shift)
+% This function has no output args, see OutputFcn.
+
+% Choose default command line output for translate_points
+handles.output = 'Cancel';
+
+% Update handles structure
+guidata(hObject, handles);
+testNo=0;
+testCancel=1;
+testinputstring=0;
+icontype='quest';%default question icon (text input asked)
+
+% Determine the position of the dialog - centered on the screen
+FigPos=get(0,'DefaultFigurePosition');
+OldUnits = get(hObject, 'Units');
+set(hObject, 'Units', 'pixels');
+OldPos = get(hObject,'Position');
+FigWidth = OldPos(3);
+FigHeight = OldPos(4);
+ScreenUnits=get(0,'Units');
+set(0,'Units','pixels');
+ScreenSize=get(0,'ScreenSize');
+set(0,'Units',ScreenUnits);
+
+FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
+FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
+FigPos(3:4)=[FigWidth FigHeight];
+set(hObject, 'Position', FigPos);
+set(hObject, 'Units', OldUnits);
+
+% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
+load dialogicons.mat
+eval(['IconData=' icontype 'IconData;'])
+eval(['IconCMap=' icontype 'IconMap;'])
+questIconMap(256,:) = get(handles.figure1, 'Color');
+Img=image(IconData, 'Parent', handles.axes1);
+set(handles.figure1, 'Colormap', IconCMap);
+set(handles.axes1, ...
+ 'Visible', 'off', ...
+ 'YDir' , 'reverse' , ...
+ 'XLim' , get(Img,'XData'), ...
+ 'YLim' , get(Img,'YData') ...
+ );
+
+if exist('input_shift','var') && ~isempty(input_shift)
+ set(handles.x_shift,'String',num2str(input_shift(1)));
+ if numel(input_shift)>=2
+ set(handles.y_shift,'String',num2str(input_shift(2)));
+ end
+ if numel(input_shift)>=3
+ set(handles.z_shift,'String',num2str(input_shift(3)));
+ end
+end
+
+set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
+% UIWAIT makes translate_points wait for user response (see UIRESUME)
+uiwait(handles.figure1);
+
+
+% --- Outputs from this function are returned to the command line.
+function varargout = translate_points_OutputFcn(hObject, eventdata, handles)
+
+% Get default command line output from handles structure
+varargout{1}=[0 0 0];%default
+if ~isequal(handles.output,'Cancel')
+ x_shift=str2num(get(handles.x_shift,'String'));
+ y_shift=str2num(get(handles.y_shift,'String'));
+ z_shift=str2num(get(handles.z_shift,'String'));
+ if ~isempty(x_shift)
+ varargout{1}(1)=x_shift;
+ end
+ if ~isempty(y_shift)
+ varargout{1}(2)=y_shift;
+ end
+ if ~isempty(z_shift)
+ varargout{1}(3)=z_shift;
+ end
+end
+% The figure can be deleted now
+delete(handles.figure1);
+
+% --- Executes on button press in OK.
+function OK_Callback(hObject, eventdata, handles)
+handles.output = get(hObject,'String');
+guidata(hObject, handles);% Update handles structure
+uiresume(handles.figure1);
+
+% --- Executes on button press in Cancel.
+function Cancel_Callback(hObject, eventdata, handles)
+handles.output = get(hObject,'String');
+%handles.output = 'Cancel'
+guidata(hObject, handles); % Update handles structure
+% Use UIRESUME instead of delete because the OutputFcn needs
+% to get the updated handles structure.
+uiresume(handles.figure1);
+
+% --- Executes when user attempts to close figure1.
+function figure1_CloseRequestFcn(hObject, eventdata, handles)
+if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
+ % The GUI is still in UIWAIT, us UIRESUME
+ uiresume(handles.figure1);
+else
+ % The GUI is no longer waiting, just close it
+ delete(handles.figure1);
+end
+
+% --- Executes on key press over figure1 with no controls selected.
+function figure1_KeyPressFcn(hObject, eventdata, handles)
+% Check for "enter" or "escape"
+if isequal(get(hObject,'CurrentKey'),'escape')
+ % User said no by hitting escape
+ handles.output = 'Cancel';
+
+ % Update handles structure
+ guidata(hObject, handles);
+
+ uiresume(handles.figure1);
+end
+if isequal(get(hObject,'CurrentKey'),'return')
+ uiresume(handles.figure1);
+end
+
+
+
+
+
Index: /trunk/src/update_menu.m
===================================================================
--- /trunk/src/update_menu.m (revision 2)
+++ /trunk/src/update_menu.m (revision 2)
@@ -0,0 +1,27 @@
+%'update_menu': find an input string in a menu, add it to the menu at the penultimate position if it does not exist
+%-----------------------------------------------
+% function menu_str=update_menu(handle,strinput)
+%
+% OUTPUT:
+% menu_str: new menu; cell of strings
+%
+% INPUT:
+% handle: handle of the menu to modify (listbox uicontrol)
+% strinput: char string to detect or add in the menu
+
+function menu_str=update_menu(handle,strinput)
+menu_str=get(handle,'String');
+nbmenu=length(menu_str);
+ichoice=0;%default
+for imenu=1:nbmenu
+ if isequal(menu_str{imenu},strinput)
+ ichoice=imenu;
+ end
+end
+if ichoice==0%the input string does not exist in the menu
+ menu_str{nbmenu+1}=menu_str{nbmenu};%shift the last item ('more...')
+ menu_str{nbmenu}=strinput;
+ set(handle,'String',menu_str)
+ ichoice=nbmenu;
+end
+set(handle,'Value',ichoice)
Index: /trunk/src/update_obj.m
===================================================================
--- /trunk/src/update_obj.m (revision 2)
+++ /trunk/src/update_obj.m (revision 2)
@@ -0,0 +1,75 @@
+%'update_obj': update the object graph representation and its projection field, record it in the uvmat interface
+%-------------------------------------------------------------------
+%Object=update_obj(UvData,IndexObj,ObjectData,PlotHandles);
+%
+%OUTPUT:
+%UvData: data to be stored as 'Userdata' on the uvmat interface
+%IndexObj: object index for a new object added to the list in UvData
+% the function updates UvData.Object{IndexObj}, and possibly adds a new plot (UvData.Plane or Line) in the list atached to the interface
+%
+%INPUT:
+%UvIn: structure stored as 'Userdata' on the uvmat interface
+%IndexObjIn: object index for an existing objects stored in UvData
+%ObjectData: structure containing the input object properties
+%PlotHandles: structure containing the handles of the plotting parameter buttons on the uvmat interface (obtained by get_plot_handles.m)
+%-------------------------------------
+
+function Object_out=update_obj(UvData,IndexObj,ObjectData,PlotHandles)
+
+%default input and output
+Object_out=ObjectData;%default
+if isfield(UvData,'Object')
+ Object_set=UvData.Object;
+else
+ Object_set={};%create the object
+end
+
+% object representation in the different projected field plots
+for iview=1:length(Object_set) %loop on projection planes iview
+ if isfield(Object_set{iview},'plotaxes')
+ haxes=Object_set{iview}.plotaxes;% axes for the field plot
+ if ishandle(haxes) & isequal(get(haxes,'Type'),'axes')% update the representation of the object IndexObj on this axes if it exists
+ testupdate=0;
+ HandlesDisplay=[];%default
+ if length(Object_set)>= IndexObj && isfield(Object_set{IndexObj},'HandlesDisplay')
+ HandlesDisplay=Object_set{IndexObj}.HandlesDisplay;%list of handles of object representations
+ end
+ hplot_list=findobj(haxes,'Tag','proj_object');
+ for ih=1:length(HandlesDisplay)
+ plot_detect=find(hplot_list==HandlesDisplay(ih));
+ if ~isempty(plot_detect)
+ Object_out.HandlesDisplay(ih)=plot_object(ObjectData,Object_set{iview},HandlesDisplay(ih),'m');%update the the object representation
+ testupdate=1;
+ break
+ end
+ end
+ if ~testupdate% draw new object plot
+ hh=plot_object(ObjectData,Object_set{iview},haxes,'m');%draw the object with the new object data
+ Object_out.HandlesDisplay=[Object_out.HandlesDisplay hh];
+ PlotData=get(hh,'UserData');
+ PlotData.IndexObj=IndexObj;
+ set(hh,'UserData',PlotData); %record the object index in the graph
+ end
+ end
+ end
+end
+
+% plot the field projected on the object
+if ~isempty(PlotHandles) %&& ~testmask
+ ProjData= proj_field(UvData.Field,ObjectData,IndexObj);%project the current interface field on ObjectData
+ if ~isempty(ProjData)
+ plotaxes=[];%default
+ if length(Object_set)>= IndexObj && isfield(Object_set{IndexObj},'plotaxes')
+ plotaxes=Object_set{IndexObj}.plotaxes;
+ end
+ [PlotType,Object_out.PlotParam,plotaxes]=plot_field(ProjData,plotaxes,PlotHandles);
+ Object_out.plotaxes=plotaxes;
+ plotfig=get(plotaxes,'parent');
+ name_str=get(plotfig,'Name');
+ if ~isequal(name_str,'uvmat')
+ set(plotfig,'Name',['Projection on' num2str(IndexObj) '-' set_title(ObjectData.Style,ObjectData.ProjMode)]);
+ end
+ end
+end
+
+
Index: /trunk/src/update_waitbar.m
===================================================================
--- /trunk/src/update_waitbar.m (revision 2)
+++ /trunk/src/update_waitbar.m (revision 2)
@@ -0,0 +1,14 @@
+%'update_waitbar': update the waitbar display, used for ACTION functions in the GUI 'series'
+%------------------------------------------------------------------
+%INPUT:
+% hwaitbar: handles of the waitbar to update
+% bar_size: vector with 4 elements, representing the abscissa, ordinate, width, height of the waitbar relative to the GUI
+% advance_ratio: number between 0 and 1 representing the advancement of the calculation (loop index relative to the total length)
+
+function update_waitbar(hwaitbar,bar_size,advance_ratio)
+waitbarpos(1)=bar_size(1);
+waitbarpos(3)=bar_size(3);
+waitbarpos(4)=advance_ratio*bar_size(4);
+waitbarpos(2)=bar_size(4)+bar_size(2)-waitbarpos(4);
+set(hwaitbar,'Position',waitbarpos)
+drawnow
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m (revision 2)
+++ /trunk/src/uvmat.m (revision 2)
@@ -0,0 +1,4821 @@
+%'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization
+%------------------------------------------------------------------------
+% function huvmat=uvmat(input)
+%
+%OUTPUT
+% huvmat=current handles of the GUI uvmat.fig
+%
+%INPUT:
+% input: input file name (if character chain), or input image matrix to
+% visualize, or Matlab structure representing netcdf fields (with fields
+% ListVarName....)
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+% This open is part of the toolbox UVMAT.
+%
+% UVMAT is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% UVMAT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License (open UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%
+% Information stored on the interface:
+% 'Strings' of all edit boxes and menus: get(handles.Tag,'String')
+% 'Values' of all menus and toggle buttons: get(handles.Tag,'Value')
+% Matlab structure stored as 'UserData' of the figure uvmat.fig,(can be obtained by right mouse click on the interface).
+% It contains the following fields:
+% - Fixed specifiacation of plotting figures and axes (defined bu uvmat_OpeningFcn)
+% .PosColorbar: [0.8210 0.4710 0.0190 0.4450]; specified position of the colorbar on figures
+% - Information read in the documentation open of a series (activated by RootPath_Callback) :
+% .XmlData, with fields:
+% .Time: matrix of times of the images with index i and j
+% .GeometryCalib: [1x1 struct]
+% - Information defined from the interface:
+% .NewSeries: =1 when the first view of a new field series is displayed, else 0
+% .filename:(char string)
+% .VelType:(char string) type of velocity field selected
+% .VelType_1:(char string) REMPLACER LE CELL ACTUEL
+% .FieldName: (char string) main field selected('image', 'velocity'...)
+% .FieldName_1:(char string) second field selected('image', 'velocity'...)
+% .CName: (char string)name of the scalar used for vector colors
+% .CoordType: (char string) coordinate transform: e.g. 'phys' or 'px'
+% .MouseAction: store the current effect of mouse button (create or edit objects)
+% - Information on projection objects
+% .Object: {[1x1 struct]}
+% .CurrentObjectIndex: index of the projection object .Object currently selected for editing
+% -Information on the current field (Field{i})
+% .Txt : text information to display (e.g. error message)
+% .NbDim: number of dimensions (=0 by default)
+% .NbCoord: number of vector components
+% .CoordType: expresses the type of coordinate ('px' for image, 'sig' for instruments, or 'phys')
+% .dt: time interval for the corresponding image pair
+% .Mesh: estimated typical distance between vectors
+% .ZMax:
+% .ZMin:
+% .X, .Y, .Z: set of vector coordinates
+% .U,.V,.W: corresponding set of vector components
+% .F: corresponding set of warning flags
+% .FF: corresponding set of false flags, =0 for good vectors
+% .C: corresponding values of the scalar used for vector color
+% (.X, .Y, .Z,.U,.V,.W,.F,.FF,.C are matlab vectors of the same length,
+% equal to the number of vectors stored in the input open)
+% .CName: name of the scalar .C
+% .CType: type of the scalar .C, setting how the scalar is obtained (see 'Scalars' below)
+% .A image or scalar
+% .AX: vector of dimension 2 representing the first and last values
+% of the X coordinates for the image or scalar known on a regular grid,
+% or vector of dimension .A for a scaler defined on irregular grid.
+% .AY: same as .AX along the Y direction
+% .AName: name of the scalar, ='image' for an image
+
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DATA FLOW (for run0_Callback) %%%%%%%%%%%%%%%%%%%%:
+%
+% Main input open second input open(_1) second image (pair animation)
+% read_ncfield.m | |
+% read_image.m | |
+% Field{1} Field{2}
+% |
+% coord transform (phys.m) or other user defined fct acting on Field{i} |
+% Field{i}
+% |
+% calc_field.m: calculate scalar or other derived fields (vort, div..).
+%
+% sub_field.m: combine the input Field{i} in a single set of fields (vector + scalar):
+% Field{i=1->3}.X --> UvData.X |
+% |
+% UvData
+% |
+% plot histograms of the whole field
+% proj_field.m: project the set of fields on the current projection objects defined by UvData.Object
+% | |
+% ObjectData
+% |
+% plot_field.m: plot the projected fields and store them as user |
+% data of the plotting axes |
+% |
+% AxeData
+%
+%%%%%%%%%%%%%% SCALARS: %%%%%%%%%%%%ùù%%%
+% scalars are displayed either as an image or countour plot, either as a color of
+% velocity vectors. The scalar values in the first case is represented by
+% UvData.Field.A, and by UvData.Field.C in the second case. The corresponding set of X
+% and Y coordinates are represented by UvData.Field.AX and UvData.Field.AY, and .X and
+% .Y for C (the same as velocity vectors). If A is a nxxny matrix (scalar
+% on a regtular grid), then .AX andf.AY contains only two elements, represneting the
+% coordinates of the four image corners. The scalar name is represented by
+% the strings .AName and/or .CName.
+% If the scalar exists in an input open (image or scalar stored under its
+% name in a netcdf open), it is directly read at the level of Field{1}or Field{2}.
+% Else only its name AName is recorded in Field{i}, and its field is then calculated
+%by the fuction calc_scal after the coordinate transform or after projection on an edit
+
+% Properties attached to plotting figures (standard Matlab properties):
+% 'CurrentAxes'= gca or get(gcf,'CurrentAxes');
+% 'CurrentPoint'=get(gcf,'CurrentPoint'): figure coordinates of the point over which the mouse is positioned
+% 'CurrentCharacter'=get(gcf,'CurrentCharacter'): last character typed over the figure where the mouse is positioned
+% 'WindowButtonMotionFcn': function permanently called by mouse motion over the figure
+% 'KeyPressFcn': function called by pressing a key on the key board
+% 'WindowButtonDownFcn': function called by pressing the mouse over the figure
+% 'WindowButtonUpFcn': function called by releasing the mouse pressure over the figure
+
+% Properties attached to plotting axes:
+% 'CurrentPoint'=get(gca,'CurrentPoint'); (standard Matlab) same as for the figure, but position in plot coordinates.
+% AxeData:=get(gca,'UserData');
+% AxeData.Drawing = create: create a new edit
+% = deform: modify an existing edit by moving its defining create
+% = off: no current drawing action
+% = translate: translate an existing edit
+% = zoom: isolate a subregion for zoom in=1 if an edit is being currently drawn, 0 else (set to 0 by releasing mouse button)
+% .hset_edit=handle of the set_edit interface (if a projection edit is edited);
+% .CurrentOrigin: Origin of a curently drawn edit
+% .CurrentLine: currently drawn menuline (A REVOIR)
+% .CurrentObject: handle of the currently drawn edit
+% .CurrentRectZoom: current rectangle used for zoom
+% .zoomon : zoom state (a revoir)
+% .X, .Y, .Z: array of coordinates defining the position of the vector: ASSOCIER AU PLAN (OBJET) PLUTOT QU'A L'AXE ?
+% .U, .V, .W: array of components of the vector
+% .C:
+% .F:
+% .FF:
+% .A
+
+% Properties attached to projection objects (create, menuline, menuplane...):
+% 'Tag'='proj_edit': for all projection objects
+% ObjectData.Style=...: style of projection edit:
+% .ProjMode
+% .Coord: defines the position of the edit
+% .XMin,YMin....
+% .XMax,YMax....
+% .DX,DY,DZ
+% .Phi, .Theta, .Psi : Euler angles
+% .X,.Y,.U,.V.... : field data projected on the edit
+% .IndexObj: index in the list of UvData.Object
+ %during plotting
+% .plotaxes: handles of the current axes used to plot the result of field projection on the object
+% .plothandle: vector of handle(s) of the object graphic represnetation in all the opened plotting axes
+% To each projection object #iobj, corresponds an axis
+% Object{iobj}.plotaxes and nbobj representation graphs Object{iobj}.plothandles(:) (where nbobj is the
+% nbre of current objects opened in uvmat. Note that Object{iobj}.plothandles(iobj)=[] : an object is not represented in its own projection field;
+%-------------------------------------------------------------------
+%-------------------------------------------------------------------
+% I - MAIN FUNCTION UVMAT (DO NOT MODIFY)
+%-------------------------------------------------------------------
+%-------------------------------------------------------------------
+function varargout = uvmat(varargin)
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @uvmat_OpeningFcn, ...
+ 'gui_OutputFcn', @uvmat_OutputFcn, ...
+ 'gui_LayoutFcn', [], ...
+ 'gui_Callback', []);
+if nargin && ischar(varargin{1})
+ gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ varargout{1:nargout} = gui_mainfcn(gui_State, varargin{:});
+else
+ gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+%-------------------------------------------------------------------
+% --- Executes just before uvmat is made visible.
+function uvmat_OpeningFcn(hObject, eventdata, handles, input )
+%-------------------------------------------------------------------
+%WARNING: avoid the second input parameter, leads to erros
+global dircur dir_opening
+% Choose default command menuline output for uvmat
+handles.output = hObject;
+
+% %group handles for input file in a structure handles.InputFile
+% handlesInputFile={handles.RootPath,handles.SubDir,handles.RootFile,handles.FileIndex,handles.FileExt};
+% TagsInputFile={'RootPath','SubDir','RootFile','FileIndex','FileExt'};
+% handles.InputFile=cell2struct(handlesInputFile,TagsInputFile,2);
+%
+% %group handles for the second input file in a structure handles.InputFile_1
+% handlesInputFile={handles.RootPath_1,handles.SubDir_1,handles.RootFile_1,handles.FileIndex_1,handles.FileExt_1};
+% TagsInputFile={'RootPath','SubDir','RootFile','FileIndex','FileExt'};
+% handles.InputFile_1=cell2struct(handlesInputFile,TagsInputFile,2);
+
+% Update handles structure
+guidata(hObject, handles);
+
+dircur=pwd; %current working directory
+dir_opening=dircur;
+
+% set the position of colorbar and ancillary GUIs:
+set(hObject,'Units','Normalized')
+movegui(hObject,'center')
+UvData.PosColorbar=[0.805 0.022 0.019 0.445];
+UvData.SetObjectOrigin=[-0.05 -0.03]; %position for set_object
+UvData.SetObjectSize=[0.3 0.7];
+UvData.CalOrigin=[0.95 -0.03];%position for geometry_calib (TO IMPROVE)
+UvData.CalSize=[0.28 1];
+
+%functions for the mouse and keyboard
+set(handles.histo_u,'NextPlot','replacechildren');
+set(handles.histo_v,'NextPlot','replacechildren');
+set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
+set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})%set mouse action functio
+set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
+set(hObject,'WindowButtonUpFcn',{'mouse_up',handles})
+%set(hObject,'ResizeFcn',{@resize_uvmat})
+
+%load the list of previously browsed files in menus Open and Open_1
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ if exist(profil_perso,'file')
+ h=load (profil_perso);
+ if isfield(h,'MenuFile_1')
+ set(handles.MenuFile_1,'Label',h.MenuFile_1);
+ set(handles.MenuFile_1_1,'Label',h.MenuFile_1);
+ end
+ if isfield(h,'MenuFile_1')
+ set(handles.MenuFile_2,'Label',h.MenuFile_2);
+ set(handles.MenuFile_2_1,'Label',h.MenuFile_2);
+ end
+ if isfield(h,'MenuFile_1')
+ set(handles.MenuFile_3,'Label',h.MenuFile_3);
+ set(handles.MenuFile_3_1,'Label',h.MenuFile_3);
+ end
+ if isfield(h,'MenuFile_1')
+ set(handles.MenuFile_4,'Label',h.MenuFile_4);
+ set(handles.MenuFile_4_1,'Label',h.MenuFile_4);
+ end
+ if isfield(h,'MenuFile_1')
+ set(handles.MenuFile_5,'Label',h.MenuFile_5);
+ set(handles.MenuFile_5_1,'Label',h.MenuFile_5);
+ end
+ end
+
+%initiates menu of vector colors
+list_menu=calc_field;
+%list_menu=[{'ima_cor'};{'black'};{'white'};list_menu(3:end)];
+set(handles.col_vec,'String',list_menu)
+
+%check the path and date of modification of all functions in uvmat
+path_to_uvmat=which ('uvmat');% check the path detected for source file uvmat
+[errormsg,date_str]=check_functions;%check the path of the functions called by uvmat.m
+
+%check the path of menu_coord transform
+%set(handles.menu_coord,'String',{'';'phys';'px';'more...'})
+path_fct{1}='';
+path_fct{2}=fileparts(path_to_uvmat);
+path_fct{3}=fileparts(path_to_uvmat);
+path_fct{4}=fileparts(path_to_uvmat);
+set(handles.menu_coord,'UserData',path_fct)
+
+%case of an input argument for uvmat
+testinputfield=0;
+inputfile=[];
+Field=[];
+if exist('input','var')
+ if ~isempty(errormsg)
+ warndlg_uvmat(errormsg,'WARNING')
+ end
+ if ishandle(handles.UVMAT_title)
+ delete(handles.UVMAT_title)
+ end
+ if isstruct(input)
+ if isfield(input,'InputFile')
+ inputfile=input.InputFile;
+ end
+ Field=input;
+ elseif ischar(input)% file name introduced as input
+ inputfile=input;
+ elseif isnumeric(input)
+ sizinput=size(input);
+ if sizinput(1)<=1 || sizinput(2)<=1
+ warndlg_uvmat('bad input for uvmat: file name, structure or numerical matrix accepted','ERROR')
+ return
+ end
+ Field.A=input;
+ Field.AX=[0.5 size(input,2)-0.5];
+ Field.AY=[size(input,1)-0.5 0.5];
+ end
+ if ~isempty(inputfile)
+ display_file_name(hObject, eventdata, handles,inputfile)
+ testinputfield=1;
+ else
+ UvData.TestInputFile=0;
+ end
+ if ~isempty(Field)
+ set(handles.Fields,'Value',1)
+ set(handles.Fields,'String',{'get_field...'})
+% set(handles.Fields,'Value',2)% option 'get_field...'
+ set(handles.Fields,'UserData',Field)
+ testinputfield=1;
+
+ % set the colorbar position on the interface:
+ UvData.PosColorbar=[0.805 0.022 0.019 0.445];
+ elseif ischar(input)
+ scan_i_Callback(handles.scan_i, eventdata, handles);
+ end
+else
+ if ishandle(handles.UVMAT_title)
+ set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; 'version 2.2.beta';date_str};errormsg]);
+ end
+end
+UvData.NewSeries=1;
+set(hObject,'UserData',UvData)
+if testinputfield
+ %delete drawn objects
+ hother=findobj(handles.axes3,'Tag','proj_object');%find all the proj objects
+ for iobj=1:length(hother)
+ delete_object(hother(iobj))
+ end
+ if isempty(inputfile)
+ run0_Callback(hObject, eventdata, handles)
+ set(handles.MenuTools,'Enable','on')
+ set(handles.OBJECT_txt,'Visible','on')
+ set(handles.edit,'Visible','on')
+ set(handles.list_object,'Visible','on')
+ set(handles.frame_object,'Visible','on')
+ else
+ update_rootinfo(hObject,eventdata,handles);
+ end
+end
+set_vec_col_bar(handles)
+
+%-------------------------------------------------------------------
+% --- Outputs from this function are returned to the command menuline.
+function varargout = uvmat_OutputFcn(hObject, eventdata, handles)
+varargout{1} = handles.output;% the only output argument is the handle to the GUI figure
+
+%-------------------------------------------------------------------
+%-------------------------------------------------------------------
+% II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
+% automatically sets the global properties when the rootfile name is introduced
+% then activate the view-field action if selected
+% it is activated either by clicking on the RootPath window or by the
+% browser
+%------------------------------------------------------------------
+%------------------------------------------------------------------
+
+% --- Executes on the menu Open/Browse...
+% search the files, recognize their type according to their name and fill the rootfile input windows
+function MenuBrowse_Callback(hObject, eventdata, handles)
+oldfile=read_file_boxes(handles);
+
+if isempty(oldfile)||isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ if exist(profil_perso,'file')
+ h=load (profil_perso);
+ if isfield(h,'MenuFile_1')
+ oldfile=h.MenuFile_1;
+ end
+ end
+end
+[FileName, PathName] = uigetfile( ...
+ {'*.xml;*.xls;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;*.cmx;*.fig;*.log;*.dat', ' (*.xml,*.xls,*.civ,*.jpg ,*.png, .tif, *.avi,*.nc,*.cmx ,*.fig,*.log,*.dat)';
+ '*.xml', '.xml files '; ...
+ '*.xls', '.xls files '; ...
+ '*.civ', '.civ files '; ...
+ '*.jpg',' jpeg image files'; ...
+ '*.png','.png image files'; ...
+ '*.tif','.tif image files'; ...
+ '*.avi;*.AVI','.avi movie files'; ...
+ '*.nc','.netcdf files'; ...
+ '*.cdf','.netcdf files'; ...
+ '*.cmx','.cmx text files';...
+ '*.cmx2','.cmx2 text files';...
+ '*.fig','.fig files (matlab fig)';...
+ '*.log','.log text files ';...
+ '*.dat','.dat text files ';...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',oldfile);
+%global filebase
+fileinput=[PathName FileName];%complete file name
+testblank=findstr(fileinput,' ');%look for blanks
+if ~isempty(testblank)
+ warndlg_uvmat(['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'],'ERROR')
+ return
+end
+sizf=size(fileinput);
+if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
+
+% display the selected field and related information
+display_file_name(hObject, eventdata, handles,fileinput)
+
+%update list of recent files in the menubar
+MenuFile_1=fileinput;
+MenuFile_2=get(handles.MenuFile_1,'Label');
+MenuFile_3=get(handles.MenuFile_2,'Label');
+MenuFile_4=get(handles.MenuFile_3,'Label');
+MenuFile_5=get(handles.MenuFile_4,'Label');
+set(handles.MenuFile_1,'Label',MenuFile_1)
+set(handles.MenuFile_2,'Label',MenuFile_2)
+set(handles.MenuFile_3,'Label',MenuFile_3)
+set(handles.MenuFile_4,'Label',MenuFile_4)
+set(handles.MenuFile_5,'Label',MenuFile_5)
+set(handles.MenuFile_1_1,'Label',MenuFile_1)
+set(handles.MenuFile_2_1,'Label',MenuFile_2)
+set(handles.MenuFile_3_1,'Label',MenuFile_3)
+set(handles.MenuFile_4_1,'Label',MenuFile_4)
+set(handles.MenuFile_5_1,'Label',MenuFile_5)
+dir_perso=prefdir;
+profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+if exist(profil_perso,'file')
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
+else
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2double(Release(3:4));
+ if relnumb >= 14
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
+ else
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
+ end
+end
+
+% --------------------------------------------------------------------
+function MenuFile_1_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_1,'Label');
+display_file_name(hObject, eventdata, handles,fileinput)
+
+% --------------------------------------------------------------------
+function MenuFile_2_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_2,'Label');
+display_file_name(hObject, eventdata, handles,fileinput)
+
+% --------------------------------------------------------------------
+function MenuFile_3_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_3,'Label');
+display_file_name(hObject, eventdata, handles,fileinput)
+
+% --------------------------------------------------------------------
+function MenuFile_4_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_4,'Label');
+display_file_name(hObject, eventdata, handles,fileinput)
+
+% --------------------------------------------------------------------
+function MenuFile_5_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_5,'Label');
+display_file_name(hObject, eventdata, handles,fileinput)
+
+%-----------------------------------------------------------------
+% fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
+%----------------------------------------------------------------
+function display_file_name(hObject, eventdata, handles,fileinput)
+[RootPath,RootFile,i1,i2,str_a,str_b,ext,NomType,SubDir]=name2display(fileinput);
+form=imformats(ext(2:end));%test valid Matlab image formats
+if ~isempty(form)
+ ext_test='.image';
+ imainfo=imfinfo(fileinput);
+ if length(imainfo) >1 %case of image with multiple frames
+ i1='1'; % set the frame counter to 1 by default
+ i2='';
+ str_a='';
+ str_b='';
+ NomType='*'; %indicate a set of indexed frames within a single file
+ [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
+ end
+elseif isequal(lower(ext),'.avi')
+ ext_test='.image';
+ i1='1'; % set the frame counter to 1 by default
+ i2='';
+ str_a='';
+ str_b='';
+ NomType='*'; %indicate a set of indexed frames within a single file
+ [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
+else
+ ext_test=lower(ext);
+end
+switch ext_test
+ case {'.civ','.log','.cmx','.cmx2','.txt'} %display text file
+ edit(fileinput)
+ case '.fig' %display matlab figure
+ hfig=open(fileinput);
+ set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
+ set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
+ set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
+ case {'.xml','.xls'} % edit xml or Excel files
+ editxml(fileinput);
+ case {'.avi','.image','.vol','.nc','.cdf'}
+ set(handles.RootPath,'String',RootPath);
+ if isequal(SubDir,'')
+ rootname=fullfile(RootPath,RootFile);
+ else
+ rootname=fullfile(RootPath,SubDir,RootFile);
+ SubDir=['/' SubDir]; %display the separator
+ end
+ set(handles.SubDir,'String',SubDir);
+ set(handles.RootFile,'String',['/' RootFile]); %display the separator
+ indices=fileinput(length(rootname)+1:end);
+ indices(end-length(ext)+1:end)=[]; %remove extension
+ set(handles.FileIndex,'String',indices);
+ set(handles.FileIndex,'UserData',NomType);
+ set(handles.FileExt,'String',ext);
+ % fill file index counters
+ set(handles.i1,'String',i1);
+
+ set(handles.i2,'String',i2);
+ set(handles.j1,'String',str_a);
+ set(handles.j2,'String',str_b);
+
+ % synchronise indices of the second input file if it exists
+ if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers
+ [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
+ NomType_1=get(handles.FileIndex_1,'UserData');
+ [FileName_1,idetect]=name_generator(FileBase_1,stra2num(i1),stra2num(i2),FileExt_1,NomType_1,1,stra2num(str_a),stra2num(str_b),SubDir_1);
+ if idetect
+ FileIndex_1=name_generator('',stra2num(i1),stra2num(i2),'',NomType_1,1,stra2num(str_a),stra2num(str_b),'');
+ set(handles.FileIndex_1,'String',FileIndex_1)
+ else
+ set(handles.SubField,'Value',0)
+ SubField_Callback(hObject, eventdata, handles)
+ end
+ end
+
+ %enable other menus
+ set(handles.MenuOpen_1,'Enable','on')
+ set(handles.MenuFile_1_1,'Enable','on')
+ set(handles.MenuFile_2_1,'Enable','on')
+ set(handles.MenuFile_3_1,'Enable','on')
+ set(handles.MenuFile_4_1,'Enable','on')
+ set(handles.MenuFile_5_1,'Enable','on')
+ set(handles.MenuExport,'Enable','on')
+ set(handles.MenuExportFigure,'Enable','on')
+ set(handles.MenuExportMovie,'Enable','on')
+ set(handles.MenuTools,'Enable','on')
+ set(handles.OBJECT_txt,'Visible','on')
+ set(handles.edit,'Visible','on')
+ set(handles.list_object,'Visible','on')
+ set(handles.frame_object,'Visible','on')
+ % initiate input file:
+ update_rootinfo(hObject,eventdata,handles);
+ otherwise
+ msgbox_uvmat('ERROR',['invalid input file extension' ext])
+end
+
+%-------------------------------------------------------------------
+function RootPath_Callback(hObject,eventdata,handles)
+update_rootinfo(hObject,eventdata,handles);
+
+%-------------------------------------------------------------------
+%-- called by action in RootFile edit box
+%-------------------------------------------------------------------
+function SubDir_Callback(hObject, eventdata, handles)
+%refresh the menu of input fields
+Fields_Callback(hObject, eventdata, handles);
+% refresh the current field
+run0_Callback(hObject, eventdata, handles);
+
+
+%-------------------------------------------------------------------
+%-- called by action in RootFile edit box
+%-------------------------------------------------------------------
+function RootFile_Callback(hObject, eventdata, handles)
+update_rootinfo(hObject,eventdata,handles)
+
+%-------------------------------------------------------------------
+%-- called by action in FileIndex edit box
+%-------------------------------------------------------------------
+function FileIndex_Callback(hObject, eventdata, handles)
+NomType_str=get(handles.FileIndex,'String') ;
+[P,F,str1,str2,str_a,str_b]=name2display(['xx' NomType_str get(handles.FileExt,'String')]);
+% display the new index values on the counters
+set(handles.i1,'String',str1);
+set(handles.i2,'String',str2);
+set(handles.j1,'String',str_a);
+set(handles.j2,'String',str_b);
+
+%-------------------------------------------------------------------
+% -- update information about a new field series (indices to scan, timing, calibration from an xml file, then refresh current plots
+%-------------------------------------------------------------------
+function update_rootinfo(hObject,eventdata,handles)
+global dircur dir_opening
+
+set(handles.RootPath,'BackgroundColor',[1 1 0])
+drawnow
+set(handles.Fields,'UserData',[])% reinialize data from uvmat opening
+huvmat=get(handles.RootPath,'parent');
+UvData=get(huvmat,'UserData');%huvmat=handles of the uvmat interface
+UvData.NewSeries=1; %flag for run0: begin a new series
+UvData.TestInputFile=1;
+set(handles.fix_pair,'Value',0) % desactivate by default the comp_input '-'input window
+%FileIndex_Callback(hObject, eventdata, handles)% update field counters
+
+[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
+if ~exist(FileName,'file')
+ msgbox_uvmat('ERROR',['input file ' FileName ' not found']);
+ return
+end
+nbfield=[];%default
+nburst=[];%default
+
+% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
+XmlData.Time=[];%default
+XmlData.GeometryCalib=[];%default
+TimeUnit=[];%default
+testima=0; %test for image input
+if isequal(lower(FileExt),'.avi') %.avi file
+ testima=1;
+ info=aviinfo([FileBase FileIndices FileExt]);
+ nbfield=info.NumFrames;
+ nburst=1;
+ set(handles.Dt_txt,'String',['Dt=' num2str(1000/info.FramesPerSecond) 'ms']);%display the elementary time interval in millisec
+ XmlData.Time=[0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond]';
+ TimeUnit='s';
+ set(handles.npx,'String',num2str(info.Width));%fills nbre of pixels x box
+ set(handles.npy,'String',num2str(info.Height));%fills nbre of pixels y box
+ hhh=which('mmreader');
+ if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the function is found (recent version of matlab)
+ UvData.MovieObject=mmreader([FileBase FileIndices FileExt]);
+ end
+elseif ~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol')%&& isequal(NomType,'*')% multi-frame image
+ testima=1;
+ if ~isequal(SubDir,'')
+ RootFile=get(handles.RootFile,'String');
+ imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]);
+ else
+ imainfo=imfinfo([FileBase FileIndices FileExt]);
+ end
+ if length(imainfo) >1 %case of image with multiple frames
+ nbfield=length(imainfo);
+ nburst=1;
+ end
+ if isfield(UvData,'MovieObject')
+ UvData=rmfield(UvData,'MovieObject');
+ end
+else
+ %set(handles.last_i,'String','');%fills last_field box
+ set(handles.npx,'String','');%fills nbre of pixels x box
+ set(handles.npy,'String','');%fills nbre of pixels y box
+ if isfield(UvData,'MovieObject')
+ UvData=rmfield(UvData,'MovieObject');
+ end
+end
+
+% read parameters (time, geometric calibration..) from a documentation file (.xml advised)
+filexml=[FileBase '.xml'];
+fileciv=[FileBase '.civ'];
+warntext='';%default warning message
+NbSlice=1;%default
+
+if exist(filexml,'file')
+ set(handles.view_xml,'Visible','on')
+ set(handles.view_xml,'BackgroundColor',[1 1 0])
+ set(handles.RootPath,'BackgroundColor',[1 1 1])
+ set(handles.view_xml,'String','view .xml')
+ drawnow
+ [XmlData,warntext]=imadoc2struct(filexml);
+ if ~isempty(warntext)
+ msgbox_uvmat('WARNING',warntext)
+ end
+ if isfield(XmlData,'TimeUnit')
+ if isfield(XmlData,'TimeUnit')&& ~isempty(XmlData.TimeUnit)
+ TimeUnit=XmlData.TimeUnit;
+ end
+ end
+ set(handles.view_xml,'BackgroundColor',[1 1 1])
+ drawnow
+elseif exist(fileciv,'file')% if .civ file found
+ [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
+ GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
+ GeometryCalib.Tx=0;
+ GeometryCalib.Ty=0;
+ GeometryCalib.Tz=1;
+ GeometryCalib.dpx=1;
+ GeometryCalib.dpy=1;
+ GeometryCalib.sx=1;
+ GeometryCalib.Cx=0;
+ GeometryCalib.Cy=0;
+ GeometryCalib.f=1;
+ GeometryCalib.kappa1=0;
+ GeometryCalib.CoordUnit='cm';
+ XmlData.GeometryCalib=GeometryCalib;
+ if error==2, warntext=['no file ' FileBase '.civ'];
+ elseif error==1, warntext='inconsistent number of fields in the .civ file';
+ end
+ set(handles.npx,'String',num2str(npx));%fills nbre of pixels x box
+ set(handles.npy,'String',num2str(npy));%fills nbre of pixels y box
+ set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
+ set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
+ set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
+ set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
+ set(handles.view_xml,'Visible','on')
+ set(handles.view_xml,'String','view .civ')
+else
+ set(handles.view_xml,'Visible','off')
+end
+
+% store last index in handles.lat_i and .last_j
+if ~isempty(XmlData.Time)
+ nbfield=size(XmlData.Time,1);
+ nburst=size(XmlData.Time,2);
+end
+last_i_cell=get(handles.last_i,'String');
+if isempty(nbfield)
+ last_i_cell{1}='';
+else
+ last_i_cell{1}=num2str(nbfield);
+end
+set(handles.last_i,'String',last_i_cell)
+last_j_cell=get(handles.last_j,'String');
+if isempty(nburst)
+ last_j_cell{1}='';
+else
+ last_j_cell{1}=num2str(nburst);
+end
+set(handles.last_j,'String',last_j_cell);
+
+% store geometric calibration in UvData
+if isfield(XmlData,'GeometryCalib')
+ GeometryCalib=XmlData.GeometryCalib;
+ if isempty(GeometryCalib)
+ set(handles.pxcm,'String','')
+ set(handles.pycm,'String','')
+ set(handles.menu_coord,'Value',1); % no transform by default
+ else
+ if (isfield(GeometryCalib,'R')& ~isequal(GeometryCalib.R(2,1),0) & ~isequal(GeometryCalib.R(1,2),0)) |...
+ (isfield(GeometryCalib,'kappa1')& ~isequal(GeometryCalib.kappa1,0))
+ set(handles.pxcm,'String','var')
+ set(handles.pycm,'String','var')
+ else
+ pixcmx=GeometryCalib.f*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
+ pixcmy=GeometryCalib.f*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
+ set(handles.pxcm,'String',num2str(pixcmx))
+ set(handles.pycm,'String',num2str(pixcmy))
+ end
+ set(handles.menu_coord,'Value',2); % phys transform by default
+ if isfield(GeometryCalib,'SliceCoord')
+ siz=size(GeometryCalib.SliceCoord);
+ if siz(1)>1
+ NbSlice=siz(1);
+ set(handles.slices,'Visible','on')
+ set(handles.slices,'Value',1)
+ end
+ set(handles.nb_slice,'String',num2str(NbSlice))
+ slices_Callback(hObject, eventdata, handles)
+ % Coord=UvData.XmlData.GeometryCalib.SliceCoord;
+ % ZIndex=num_i1-NbSlice*(floor((num_i1-1)/NbSlice));
+ end
+ end
+end
+
+%update the data attached to the uvmat interface
+set(handles.nb_slice,'String',num2str(NbSlice))
+if ~isempty(TimeUnit)
+ set(handles.time_txt,'String',['time (' TimeUnit ')'])
+end
+%set(handles.DtUnit,'String',['10^(-3)' TimeUnit])
+UvData.TimeUnit=TimeUnit;
+UvData.XmlData=XmlData;
+UvData.NewSeries=1;
+set(huvmat,'UserData',UvData)
+
+%display warning message
+if ~isequal(warntext,'')
+ msgbox_uvmat('WARNING',warntext);
+end
+
+% set default options in menu 'Fields'
+if testima
+ set(handles.Fields,'Value',1) % set menu to 'image'
+ set(handles.Fields,'String',{'image';'get_field...';'velocity';'vort';'div';'more...'})
+elseif isequal(FileExt,'.nc')|isequal(FileExt,'.cdf')
+ Data=nc2struct(FileName,[]);
+ col_vec=get(handles.col_vec,'String');
+ if isfield(Data,'absolut_time_T0')&& (isfield(Data,'civ1')||isfield(Data,'civ'))
+ set(handles.Fields,'String',{'image';'get_field...';'velocity';'vort';'div';'more...'})
+ set(handles.Fields,'Value',3) % set menu to 'velocity'
+ col_vec{1}='ima_cor';
+ else
+ set(handles.Fields,'Value',1) % set menu to 'get_field...
+ set(handles.Fields,'String',{'get_field...'})
+ col_vec{1}='get_field...';
+ end
+ set(handles.col_vec,'String',col_vec)
+else
+ msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
+ return
+end
+
+% set index navigation options and refresh plots
+set(handles.RootPath,'BackgroundColor',[1 1 1])
+drawnow
+set_scan_options(hObject, eventdata, handles)
+
+
+%-------------------------------------------------------------------
+%-- set index navigation options for new series input and refresh plot
+%-------------------------------------------------------------------
+function set_scan_options(hObject, eventdata, handles)
+
+% set the corresponding index navigation options (TO CHECK WITH THE SECOND FIELD)
+NomType=get(handles.FileIndex,'UserData');
+NomType_1=get(handles.FileIndex_1,'UserData');
+state_j='off'; %default
+scan_option='i';
+switch NomType
+ case {'_i_j','_i_j1-j2','_i1-i2_j','#_ab'},% two navigation indices
+ state_j='on';
+ if exist('nbfield','var') && isequal(nbfield,1)
+ scan_option='j';
+ else
+ scan_option='i';
+ end
+end
+if ~isempty(NomType_1)
+ switch NomType_1
+ case {'_i_j','_i_j1-j2','_i1-i2_j','#_ab'},% two navigation indices
+ state_j='on';
+ if exist('nbfield','var') && isequal(nbfield,1)
+ scan_option='j';
+ else
+ scan_option='i';
+ end
+ end
+end
+if isequal(scan_option,'i')
+ set(handles.scan_i,'Value',1)
+ scan_i_Callback(hObject, eventdata, handles);
+else
+ set(handles.scan_j,'Value',1)
+ scan_j_Callback(hObject, eventdata, handles);
+end
+set(handles.scan_j,'Visible',state_j)
+set(handles.j1,'Visible',state_j)
+set(handles.j2,'Visible',state_j)
+set(handles.last_j,'Visible',state_j);
+set(handles.frame_j,'Visible',state_j);
+set(handles.j_text,'Visible',state_j);
+
+% view the field
+run0_Callback(hObject, eventdata, handles); %view field
+mask_test=get(handles.mask_test,'value');
+if mask_test
+ MaskData=get(handles.mask_test,'UserData');
+ if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
+ delete(MaskData.maskhandle) %delete old mask
+ end
+ mask_test_Callback(hObject, eventdata, handles)
+end
+%-------------------------------------------------------------------
+function MenuBrowse_1_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+huvmat=get(handles.run0,'parent');
+UvData=get(huvmat,'UserData');
+
+RootPath=get(handles.RootPath,'String');
+[FileName, PathName, filterindex] = uigetfile( ...
+ {'*.xml;*.xls;*.civ;*.jpg;*.png;*.avi;*.AVI;*.nc;*.cmx;*.fig;*.log;*.dat', ' (*.xml,*.xls,*.civ, *.jpg,*.png, *.avi,*.nc,*.cmx ,*.fig,*.log,*.dat)';
+ '*.xml', '.xml files '; ...
+ '*.xls', '.xls files '; ...
+ '*.civ', '.civ files '; ...
+ '*.jpg','.jpg image files'; ...
+ '*.png','.png image files'; ...
+ '*.avi;*.AVI','.avi movie files'; ...
+ '*.nc','.netcdf files'; ...
+ '*.cdf','.netcdf files'; ...
+ '*.cmx','.cmx text files';...
+ '*.cmx2','.cmx2 text files';...
+ '*.fig','.fig files (matlab fig)';...
+ '*.log','.log text files ';...
+ '*.dat','.dat text files ';...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file',RootPath);
+fileinput_1=[PathName FileName];%complete file name
+testblank=findstr(fileinput_1,' ');%look for blanks
+if ~isempty(testblank)
+ warndlg_uvmat(['The input file name ' fileinput_1 ' contains blank character : This is not allowed. Please change name'],'ERROR')
+ return
+end
+sizf=size(fileinput_1);
+if (~ischar(fileinput_1)|~isequal(sizf(1),1)),return;end
+
+% refresh the current displayed field
+display_file_name_1(hObject,eventdata,handles,fileinput_1)
+
+%update list of recent files in the menubar
+MenuFile_1=fileinput_1;
+MenuFile_2=get(handles.MenuFile_1,'Label');
+MenuFile_3=get(handles.MenuFile_2,'Label');
+MenuFile_4=get(handles.MenuFile_3,'Label');
+MenuFile_5=get(handles.MenuFile_4,'Label');
+set(handles.MenuFile_1,'Label',MenuFile_1)
+set(handles.MenuFile_2,'Label',MenuFile_2)
+set(handles.MenuFile_3,'Label',MenuFile_3)
+set(handles.MenuFile_4,'Label',MenuFile_4)
+set(handles.MenuFile_5,'Label',MenuFile_5)
+set(handles.MenuFile_1_1,'Label',MenuFile_1)
+set(handles.MenuFile_2_1,'Label',MenuFile_2)
+set(handles.MenuFile_3_1,'Label',MenuFile_3)
+set(handles.MenuFile_4_1,'Label',MenuFile_4)
+set(handles.MenuFile_5_1,'Label',MenuFile_5)
+dir_perso=prefdir;
+profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+if exist(profil_perso,'file')
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
+else
+ txt=ver;
+ Release=txt(1).Release;
+ relnumb=str2num(Release(3:4));
+ if relnumb >= 14
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
+ else
+ save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
+ end
+end
+
+% --------------------------------------------------------------------
+function MenuFile_1_1_Callback(hObject, eventdata, handles)
+fileinput_1=get(handles.MenuFile_1_1,'Label');
+display_file_name_1(hObject,eventdata,handles,fileinput_1)
+
+% --------------------------------------------------------------------
+function MenuFile_2_1_Callback(hObject, eventdata, handles)
+fileinput_1=get(handles.MenuFile_2_1,'Label');
+display_file_name_1(hObject,eventdata,handles,fileinput_1)
+
+% --------------------------------------------------------------------
+function MenuFile_3_1_Callback(hObject, eventdata, handles)
+fileinput_1=get(handles.MenuFile_3_1,'Label');
+display_file_name_1(hObject,eventdata,handles,fileinput_1)
+
+% --------------------------------------------------------------------
+function MenuFile_4_1_Callback(hObject, eventdata, handles)
+fileinput_1=get(handles.MenuFile_4_1,'Label');
+display_file_name_1(hObject,eventdata,handles,fileinput_1)
+
+% --------------------------------------------------------------------
+function MenuFile_5_1_Callback(hObject, eventdata, handles)
+fileinput_1=get(handles.MenuFile_5_1,'Label');
+display_file_name_1(hObject,eventdata,handles,fileinput_1)
+
+%-----------------------------------------------------------------
+% fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
+%----------------------------------------------------------------
+function display_file_name_1(hObject,eventdata,handles,fileinput_1)
+
+%[path,name,ext]=fileparts(fileinput_1);
+[RootPath_1,RootFile_1,field_count,str2,str_a,str_b,FileExt_1,NomType_1,SubDir_1]=name2display(fileinput_1);
+nbfield_1=1; %default
+ext_test=FileExt_1;%default
+form=imformats(FileExt_1(2:end));
+if ~isempty(form) % if the extension corresponds to an image format recognized by Matlab
+ imainfo=imfinfo(fileinput_1);
+ nbfield_1=length(imainfo);
+ ext_test='.image';
+elseif isequal(lower(FileExt_1),'.avi')
+ info=aviinfo(fileinput_1);
+ nbfield_1=info.NumFrames;
+ ext_test='.image';
+end
+
+%open directly fig or text files
+switch ext_test
+ case {'.civ','.log','.cmx','.cmx2','.txt'} %display text file
+ edit(fileinput)
+ return
+ case '.fig' %display matlab figure
+ hfig=open(fileinput);
+ set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
+ set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
+ set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
+ return
+ case {'.xml','.xls'} % edit xml or Excel files
+ heditxml=editxml(fileinput);
+ return
+ case {'.image','.nc','.cdf'}
+% set(handles.FileIndex,'UserData',NomType_1);
+ otherwise
+ warndlg_uvmat(['invalid input file extension ' FileExt_1 ' for uvmat'],'ERROR')
+ return
+end
+
+% test for image series in a single file and synchronise file indices of the two series
+if nbfield_1 >1 %case of image with multiple frames
+ if nbfield_1 < num_i1
+ warndlg_uvmat('current frame index beyond the input movie length','ERROR')
+ return
+ else
+ NomType_1='*'; %indicate a set of indexed frames within a single file
+ filename_new=fileinput_1;
+ end
+else % cases of data files
+ RootPath=get(handles.RootPath,'String');
+ RootFile=get(handles.RootFile,'String');
+ FileBase=fullfile(RootPath,RootFile);
+ FileBase_1=fullfile(RootPath_1,RootFile_1);
+ if isequal(FileBase,FileBase_1)
+ filename_new=fileinput_1;
+ else
+ num_i1=stra2num(get(handles.i1,'String'));%get the current file indices from counters
+ num_j1=stra2num(get(handles.j1,'String'));
+ num_i2=stra2num(get(handles.i2,'String'));
+ num_j2=stra2num(get(handles.j2,'String'));
+ [filename_new,idetect]=...
+ name_generator(FileBase_1,num_i1,num_j1,FileExt_1,NomType_1,1,num_i2,num_j2,SubDir_1);%create name with indices synchronised with the first file
+ indices=''; %default
+ if ~idetect
+ warndlg_uvmat('second input file with indices corresponding to the first one does not exist','ERROR')
+ return
+ end
+ end
+end
+set(handles.FileIndex,'UserData',NomType_1);
+
+% make visible and fill the second raw of edit boxes
+set(handles.RootPath_1,'Visible','on')
+set(handles.RootFile_1,'Visible','on')
+set(handles.SubDir_1,'Visible','on');
+set(handles.FileIndex_1,'Visible','on');
+set(handles.FileExt_1,'Visible','on');
+[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
+if isequal(FileBase,FileBase_1)
+ set(handles.RootPath_1,'String','"')
+ set(handles.RootFile_1,'String','"');
+else
+ set(handles.RootPath_1,'String',RootPath_1)
+ set(handles.RootFile_1,'String',['/' RootFile_1]);
+end
+if isequal(SubDir_1,'')
+ set(handles.SubDir_1,'String','');
+ FileBaseSub_1=FileBase_1;
+else
+ set(handles.SubDir_1,'String',['/' SubDir_1]);
+ FileBaseSub_1=fullfile(FileBase_1,SubDir_1);
+end
+indices=filename_new(length(FileBaseSub_1)+1:end);
+indices(end-length(FileExt_1)+1:end)=[]; %remove extension
+set(handles.FileIndex_1,'String',indices)
+set(handles.FileIndex_1,'UserData',NomType_1)
+set(handles.FileExt_1,'String',FileExt_1);
+
+% default choice of fields
+if isequal(ext_test,'.image')
+ set(handles.Fields_1,'String',{'';'image';'get_field...';'velocity';'vort';'div';'more...'})
+ set(handles.Fields_1,'Value',2) % set menu to 'image'
+elseif isequal(FileExt_1,'.nc')|isequal(FileExt_1,'.cdf')
+ Data=nc2struct(fileinput_1,[]);
+ if isfield(Data,'absolut_time_T0')
+ set(handles.Fields_1,'String',{'';'image';'get_field...';'velocity';'vort';'div';'more...'})
+ set(handles.Fields_1,'Value',4) % set menu to 'velocity'
+ else
+ set(handles.Fields_1,'Value',2) % set menu to 'get_field...'
+ set(handles.Fields_1,'String',{'';'get_field...'});
+ end
+end
+set(handles.SubField,'Visible','on')
+set(handles.SubField,'Value',1)
+RootPath_1_Callback(hObject,eventdata,handles);
+
+
+%-----------------------------------------------------
+function RootPath_1_Callback(hObject,eventdata,handles)
+update_rootinfo_1(hObject,eventdata,handles)
+
+%-------------------------------------------------------------------
+function RootFile_1_Callback(hObject, eventdata, handles)
+update_rootinfo_1(hObject,eventdata,handles)
+%-------------------------------------------------------------------
+
+%-------------------------------------------------------------------
+function update_rootinfo_1(hObject,eventdata,handles) %A REVOIR
+
+set(handles.RootPath_1,'BackgroundColor',[1 1 0])% indicate active program by yellow color
+drawnow
+huvmat=get(handles.RootPath,'parent');
+UvData=get(huvmat,'UserData');%huvmat=handles of the uvmat interface
+UvData.NewSeries=1; %flag for run0: begin a new series
+
+[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes_1(handles);
+if ~exist(FileName,'file')
+ msgbox_uvmat('ERROR',['input file ' FileName ' not found']);
+end
+nbfield_1=[];%default
+nburst_1=[];%default
+XmlData.Time=[];
+XmlData.GeometryCalib=[];%default
+TimeUnit=[];
+if isfield(UvData,'TimeUnit')
+ TimeUnit=UvData.TimeUnit;
+end
+TimeUnit_1=[];
+testima=0; %test for image input
+if isequal(lower(FileExt),'.avi') %.avi file
+ testima=1;
+ info=aviinfo([FileBase FileIndices FileExt]);
+ nbfield_1=info.NumFrames;
+ nburst_1=1;
+ %set(handles.last_i,'String',num2str(info.NumFrames));%fills last_field box
+ set(handles.Dt_txt,'String',['Dt=' num2str(1000/info.FramesPerSecond) 'ms']);%display the elementary time interval in millisec
+% set(handles.dt,'UserData',info.FramesPerSecond);
+ time=[0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond]';
+ npx=get(handles.npx,'String');
+ npy=get(handles.npy,'String');
+ if isequal(npx,'') || isequal(npy,'')
+ set(handles.npx,'String',num2str(info.Width));%fills nbre of pixels x box
+ set(handles.npy,'String',num2str(info.Height));%fills nbre of pixels y box
+ end
+elseif ~isempty(imformats(FileExt(2:end))) %&& isequal(NomType,'*')% multi-frame image
+ testima=1;
+ imainfo=imfinfo([FileBase FileIndices FileExt]);
+ if length(imainfo) >1 %case of image with multiple frames
+ nbfield_1=length(imainfo);
+ nburst_1=1;
+ %set(handles.last_i,'String',num2str(length(imainfo)));%fills last_field box
+ end
+else
+ %set(handles.last_i,'String','');%fills last_field box
+ set(handles.npx,'String','');%fills nbre of pixels x box
+ set(handles.npy,'String','');%fills nbre of pixels y box
+end
+
+% find scaling parameters
+filexml=[FileBase '.xml'];
+fileciv=[FileBase '.civ'];
+warntext='';%default warning text
+if exist(filexml,'file')
+ [XmlData,warntext]=imadoc2struct(filexml);
+ if ~isempty(warntext)
+ msgbox_uvmat('WARNING',warntext)
+ end
+ if isfield(XmlData,'Camera')
+% if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
+% NbSlice=XmlData.Camera.NbSlice;
+% end
+ if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
+ TimeUnit=XmlData.Camera.TimeUnit;
+ end
+ end
+elseif exist(fileciv,'file')% if .civ file found
+ [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
+ GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
+ GeometryCalib.Tx=0;
+ GeometryCalib.Ty=0;
+ GeometryCalib.Tz=1;
+ GeometryCalib.dpx=1;
+ GeometryCalib.dpy=1;
+ GeometryCalib.sx=1;
+ GeometryCalib.Cx=0;
+ GeometryCalib.Cy=0;
+ GeometryCalib.f=1;
+ GeometryCalib.kappa1=0;
+ GeometryCalib.CoordUnit='cm';
+ XmlData.GeometryCalib=GeometryCalib;
+ if error==2, warntext=['no file ' FileBase '.civ'];
+ elseif error==1, warntext='inconsistent number of fields in the .civ file';
+ end
+
+ set(handles.npx,'String',num2str(npx));%fills nbre of pixels x box
+ set(handles.npy,'String',num2str(npy));%fills nbre of pixels y box
+ set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
+ set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
+ set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
+ set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
+end
+if ~isempty(TimeUnit_1) && ~isequal(TimeUnit_1,TimeUnit)
+ warndlg_uvmat('the time units for the second series differs from the first one','WARNING')
+end
+
+% store last index in handles.lat_i and .last_j
+if ~isempty(XmlData.Time)
+ nbfield_1=size(XmlData.Time,1);
+ nburst_1=size(XmlData.Time,2);
+end
+last_i_cell=get(handles.last_i,'String');
+if isempty(nbfield_1)
+ last_i_cell{2}='';
+else
+ last_i_cell{2}=num2str(nbfield_1);
+end
+set(handles.last_i,'String',last_i_cell)
+last_j_cell=get(handles.last_j,'String');
+if isempty(nburst_1)
+ last_j_cell{2}='';
+else
+ last_j_cell{2}=num2str(nburst_1);
+end
+set(handles.last_j,'String',last_j_cell);
+if ~isequal(last_i_cell{1},last_i_cell{2}) || ~isequal(last_j_cell{1},last_j_cell{2})
+ warndlg_uvmat('the numbers of input file of the second series differs from the first one','WARNING')
+end
+
+% store calibration data
+GeometryCalib=XmlData.GeometryCalib;
+if isempty(GeometryCalib)
+ if isfield(UvData, 'GeometryCalib_1')
+ UvData=rmfield(UvData,'GeometryCalib_1');
+ end
+else
+ UvData.GeometryCalib_1=GeometryCalib;
+ if (isfield(GeometryCalib,'R')& ~isequal(GeometryCalib.R(2,1),0) & ~isequal(GeometryCalib.R(1,2),0)) |...
+ (isfield(GeometryCalib,'kappa1')& ~isequal(GeometryCalib.kappa1,0))
+ set(handles.pxcm,'String','var')
+ set(handles.pycm,'String','var')
+ else
+ pixcmx=GeometryCalib.f*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
+ pixcmy=GeometryCalib.f*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
+ set(handles.pxcm,'String',num2str(pixcmx))
+ set(handles.pycm,'String',num2str(pixcmy))
+ end
+end
+UvData.XmlData_1=XmlData;
+set(huvmat,'UserData',UvData)%update the data attached to the uvmat interface
+
+if ~isequal(warntext,'')
+ warndlg_uvmat(warntext,'WARNING')
+end
+
+set(handles.RootPath_1,'BackgroundColor',[1 1 1])% signa the end the input operation
+drawnow
+
+set_scan_options(hObject, eventdata, handles)
+
+
+%---------------------------------------------------
+% switch file index scanning options scan_i and scan_j in an exclusive way
+function scan_i_Callback(hObject, eventdata, handles)
+%---------------------------------------------------
+if get(handles.scan_i,'Value')==1
+ set(handles.scan_i,'BackgroundColor',[1 1 0])
+ set(handles.scan_j,'Value',0)
+ set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
+else
+ set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.scan_j,'Value',1)
+ set(handles.scan_j,'BackgroundColor',[1 1 0])
+end
+%-------------------------------------------------------------------
+%---------------------------------------------------
+% switch file index scanning options scan_i and scan_j in an exclusive way
+function scan_j_Callback(hObject, eventdata, handles)
+%---------------------------------------------------
+%-------------------------------------------------------------------
+if get(handles.scan_j,'Value')==1
+ set(handles.scan_j,'BackgroundColor',[1 1 0])
+ set(handles.scan_i,'Value',0)
+ set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
+else
+ set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
+ set(handles.scan_i,'Value',1)
+ set(handles.scan_i,'BackgroundColor',[1 1 0])
+end
+
+%-------------------------------------------------------------------
+function i1_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+% [filebase,num1,num_a,num2,num_b,ext,NomType,subdir]=read_input_file(handles);
+[FileName,RootPath,filebase,xx,FileExt]=read_file_boxes(handles);
+NomType=get(handles.FileIndex,'UserData');
+num1=stra2num(get(handles.i1,'String'));
+num2=stra2num(get(handles.i2,'String'));
+num_a=stra2num(get(handles.j1,'String'));
+num_b=stra2num(get(handles.j2,'String'));
+indices=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
+set(handles.FileIndex,'String',indices)
+if get(handles.SubField,'Value')==1
+ NomType_1=get(handles.FileIndex_1,'String');
+ FileExt_1=get(handles.FileExt_1,'String');
+ [P,F,str1,str2,str_a,str_b,Ext,NomType_1]=name2display(['xx' NomType_1 FileExt_1]);
+ indices=name_generator('',num1,num_a,'',NomType_1,1,num2,num_b,'');
+ set(handles.FileIndex_1,'String',indices)
+end
+run0_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------------------
+function i2_Callback(hObject, eventdata, handles)
+i1_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+
+%-------------------------------------------------------------------
+function j1_Callback(hObject, eventdata, handles)
+i1_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+
+%-------------------------------------------------------------------
+function j2_Callback(hObject, eventdata, handles)
+i1_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+
+%-------------------------------------------------------------------
+function slices_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+if get(handles.slices,'Value')==1
+ set(handles.slices,'BackgroundColor',[1 1 0])
+ set(handles.nb_slice,'Visible','on')
+ set(handles.z_text,'Visible','on')
+ set(handles.z_index,'Visible','on')
+ nb_slice_Callback(hObject, eventdata, handles)
+% z=mod(num_i1-1,nbslice)+1;
+% set(handles.z_index,'String',num2str(z))
+else
+ set(handles.nb_slice,'Visible','off')
+ set(handles.slices,'BackgroundColor',[0.7 0.7 0.7])
+ set(handles.z_text,'Visible','off')
+ set(handles.z_index,'Visible','off')
+ set(handles.masklevel,'Value',1)
+ set(handles.masklevel,'String',{'1'})
+end
+
+%-------------------------------------------------------------------
+function nb_slice_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+num_i1=str2num(get(handles.i1,'String'));
+nbslice=str2num(get(handles.nb_slice,'String'));
+z=mod(num_i1-1,nbslice)+1;
+set(handles.z_index,'String',num2str(z))
+for ilist=1:nbslice
+ list_index{ilist,1}=num2str(ilist);
+end
+set(handles.masklevel,'String',list_index)
+set(handles.masklevel,'Value',z)
+
+
+%-------------------------------------------------------------------
+% --- Executes on button press in view_xml.
+function view_xml_Callback(hObject, eventdata, handles)
+[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
+option=get(handles.view_xml,'String');
+if isequal(option,'view .xml')
+ FileXml=[FileBase '.xml'];
+ heditxml=editxml(FileXml);
+end
+
+%-------------------------------------------------------------------
+% --- Executes on button press in mask_test.
+function mask_test_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+if isequal(get(handles.mask_test,'Value'),1)
+ [FF,RootPath,FileBase]=read_file_boxes(handles);
+ num_i1=stra2num(get(handles.i1,'String'));
+ num_j1=stra2num(get(handles.j1,'String'));
+ currentdir=pwd;
+ cd(RootPath);
+ maskfiles=dir('*_*mask_*.png');%look for a mask file
+ cd(currentdir);%come back to the working directory
+ mdetect=0;
+ if isempty(maskfiles)
+ msgbox_uvmat('ERROR','no mask file detected (format ..._xxmask_ii.png needed), use the menu bar Tools/Make mask')
+ return
+ end
+ for ilist=1:length(maskfiles)
+ maskname=maskfiles(ilist).name;% take the first mask file in the list
+ [rr,ff,x1,x2,xa,xb,xext,Mask_NomType{ilist}]=name2display(maskname);
+ if ~strcmp(Mask_NomType{ilist},Mask_NomType{1})
+ msgbox_uvmat('ERROR',['inconsistent mask types ' Mask_NomType{1} Mask_NomType{ilist } ' coexist in the current image directory'])
+ return
+ end
+ [Path2,Name,ext]=fileparts(maskname);
+ Namedouble=double(Name);
+ val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
+ ind_mask=findstr('mask',Name);
+ i=ind_mask-1;
+ while val(i)==0 & i>0
+ i=i-1;
+ end
+ nbmask_str=str2num(Name(i+1:ind_mask-1));
+ if ~isempty(nbmask_str)
+ nbslice(ilist)=nbmask_str; % number of different masks (slices)
+ end
+ end
+ if isequal(min(nbslice),max(nbslice))
+ nbslice=nbslice(1);
+ else
+ msgbox_uvmat('ERROR','several inconsistent mask sets coexist in the current image directory')
+ return
+ end
+ if ~isempty(nbslice) && Name(i)=='_'
+ Mask.Base=[FileBase Name(i:ind_mask+3)];
+ Mask.NbSlice=nbslice;
+ num_i1=mod(num_i1-1,nbslice)+1
+ Mask.NomType=Mask_NomType{1};
+ [maskname,mdetect]=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType)%
+ mdetect=exist(maskname,'file')
+ if mdetect
+ set(handles.nb_slice,'String',Name(i+1:ind_mask-1));
+ set(handles.nb_slice,'BackgroundColor',[1 1 0])
+ set(handles.mask_test,'UserData',Mask);
+ set(handles.mask_test,'BackgroundColor',[1 1 0])
+ if nbslice > 1
+ set(handles.slices,'value',1)
+ slices_Callback(hObject, eventdata, handles)
+ end
+ end
+ end
+ if mdetect==0
+ msgbox_uvmat('ERROR','no mask file detected (format ..._xxmask_ii.png needed), use the menu bar Tools/Make mask')
+ set(handles.mask_test,'Value',0)
+ return
+ end
+ update_mask(handles,num_i1,num_j1);
+else
+ MaskData=get(handles.mask_test,'UserData');
+ if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
+ delete(MaskData.maskhandle)
+ end
+ set(handles.mask_test,'UserData',[])
+ huvmat=get(handles.mask_test,'parent');
+ UvData=get(huvmat,'UserData');
+ if isfield(UvData,'MaskName')
+ UvData=rmfield(UvData,'MaskName');
+ set(huvmat,'UserData',UvData)
+ end
+ set(handles.mask_test,'BackgroundColor',[0.7 0.7 0.7])
+end
+
+%-------------------------------------------------------------------
+function update_mask(handles,num_i1,num_j1)
+%-------------------------------------------------------------------
+
+MaskData=get(handles.mask_test,'UserData');
+if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
+ uistack(MaskData.maskhandle,'top');
+end
+num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1;
+[MaskName,mdetect]=name_generator(MaskData.Base,num_i1_mask,num_j1,'.png',MaskData.NomType);
+huvmat=get(handles.mask_test,'parent');
+UvData=get(huvmat,'UserData');
+
+%update mask image if the mask is new
+if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
+ UvData.MaskName=MaskName; %update the recorded name on UvData
+ set(huvmat,'UserData',UvData);
+ if mdetect==0
+ if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
+ delete(MaskData.maskhandle)
+ end
+ else
+ %read mask image
+ Mask.AName='image';
+ Mask.A=imread(MaskName);
+ npxy=size(Mask.A);
+ Mask.AX=[0.5 npxy(2)-0.5];
+ Mask.AY=[npxy(1)-0.5 0.5 ];
+ Mask.CoordType='px';
+ if isequal(get(handles.slices,'Value'),1)
+ NbSlice=str2num(get(handles.nb_slice,'String'));
+ num_i1=str2num(get(handles.i1,'String'));
+ Mask.ZIndex=mod(num_i1-1,NbSlice)+1;
+ end
+ %px to phys or other transform on field
+ menu_transform=get(handles.menu_coord,'String');
+ choice_value=get(handles.menu_coord,'Value');
+ transform=menu_transform{choice_value};%name of the transform fct given by the menu 'menu_coord'
+ if ~isequal(transform,'') && ~isequal(transform,'px')
+ if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
+ Calib=UvData.XmlData.GeometryCalib;
+ Mask=feval(transform,Mask,UvData.XmlData);
+ end
+ end
+ flagmask=Mask.A < 200;
+
+ %make brown color image
+ imflag(:,:,1)=0.9*flagmask;
+ imflag(:,:,2)=0.7*flagmask;
+ imflag(:,:,3)=zeros(size(flagmask));
+
+ %update mask image
+ hmask=[]; %default
+ if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
+ hmask=MaskData.maskhandle;
+ end
+ if ~isempty(hmask)
+ set(hmask,'CData',imflag)
+ set(hmask,'AlphaData',flagmask*0.6)
+ set(hmask,'XData',Mask.AX);
+ set(hmask,'YData',Mask.AY);
+% uistack(hmask,'top')
+ else
+ axes(handles.axes3)
+ hold on
+ MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*flagmask);
+% set(MaskData.maskhandle,'AlphaData',0.6*flagmask)
+ set(handles.mask_test,'UserData',MaskData)
+ end
+ end
+end
+
+
+%-------------------------------------------------------------------
+function MenuExportFigure_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+huvmat=get(handles.MenuExport,'parent');
+UvData=get(huvmat,'UserData');
+hfig=figure;
+newaxes=copyobj(handles.axes3,hfig);
+map=colormap(handles.axes3);
+colormap(map);%transmit the current colormap to the zoom fig
+colorbar
+
+%-------------------------------------------------------------------
+%-------------------------------------------------------------------
+% III - MAIN REFRESH FUNCTIONS : 'FRAME PLOT'
+%-------------------------------------------------------------------
+%-------------------------------------------------------------------
+
+%Executes on button press in runplus: make one step forward and call
+%run0. The step forward is along the fields series 1 or 2 depending on
+%the scan_i and scan_j check box (exclusive each other)
+%-------------------------------------------------------------------
+function runplus_Callback(hObject, eventdata, handles)
+increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
+runpm(hObject,eventdata,handles,increment)
+
+%-------------------------------------------------------------------
+%Executes on button press in runmin: make one step backward and call
+%run0. The step backward is along the fields series 1 or 2 depending on
+%the scan_i and scan_j check box (exclusive each other)
+%-------------------------------------------------------------------
+function runmin_Callback(hObject, eventdata, handles)
+increment=-str2num(get(handles.increment_scan,'String')); %get the field increment d
+runpm(hObject,eventdata,handles,increment)
+
+%-------------------------------------------------------------------
+%Executes on button press in runmin: make one step backward and call
+%run0. The step backward is along the fields series 1 or 2 depending on
+%the scan_i and scan_j check box (exclusive each other)
+%-------------------------------------------------------------------
+function RunMovie_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------
+set(handles.RunMovie,'BackgroundColor',[1 1 0])%paint the command button in yellow
+drawnow
+increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
+set(handles.STOP,'Visible','on')
+set(handles.speed,'Visible','on')
+set(handles.speed_txt,'Visible','on')
+set(handles.RunMovie,'BusyAction','queue')
+testavi=0;
+huvmat=get(handles.RunMovie,'parent');
+UvData=get(huvmat,'UserData');
+
+while get(handles.speed,'Value')~=0 & isequal(get(handles.RunMovie,'BusyAction'),'queue') % enable STOP command
+ runpm(hObject,eventdata,handles,increment)
+ pause(1.02-get(handles.speed,'Value'))% wait for next image
+end
+if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
+ UvData.aviobj=close(UvData.aviobj);
+ set(huvmat,'UserData',UvData);
+end
+set(handles.RunMovie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
+
+%-------------------------------------------------------------------
+function STOP_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+set(handles.run0,'BusyAction','Cancel')
+set(handles.RunMovie,'BusyAction','Cancel')
+set(handles.MenuExportMovie,'BusyAction','Cancel')
+
+
+%------------------------------------------------------------------
+function runpm(hObject,eventdata,handles,increment)
+%------------------------------------------------------------------
+%read the data on the current input rootfile(s)
+
+[FileName,RootPath,filebase,FileIndices,FileExt,subdir]=read_file_boxes(handles);
+NomType=get(handles.FileIndex,'UserData');
+
+num1=stra2num(get(handles.i1,'String'));
+num2=stra2num(get(handles.i2,'String'));
+num_a=stra2num(get(handles.j1,'String'));
+num_b=stra2num(get(handles.j2,'String'));
+
+sub_value= get(handles.SubField,'Value');
+if sub_value ==1
+ [FileName_1,RootPath_1,filebase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
+end
+
+comp_input=get(handles.fix_pair,'Value');
+if isequal(NomType,'_i1-i2')|isequal(NomType,'_i1-i2_j')
+ comp_input=1; %impose a fixed pair interval
+ set(handles.fix_pair,'Value',1)
+end
+
+%case of scanning along the first direction (rootfile numbers)
+if get(handles.scan_i,'Value')==1% case of scanning along field numbers
+ num1=num1+increment;
+ num2=num2+increment;
+ if comp_input==0% find a free pair
+ [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out]=...
+ name_generator(filebase,num1,num_a,FileExt,NomType,0,num2,num_b,subdir);
+ if exist(filename,'file')
+ num_a=num_j1_out;
+ num_b=num_j2_out;
+ end
+ end
+ if sub_value>=2
+ num_i1=num_i1+increment;
+ num_i2=num_i2+increment;
+ end
+else % case of scanning along the second direction (burst numbers)
+ lastfield_cell=get(handles.last_j,'String'); % get the last field number
+ lastfield=str2num(lastfield_cell{1});
+ num_a=num_a+increment;
+ num_b=num_b+increment;
+ if sub_value >=2
+ num_j1=num_j1+increment;
+ num_j2=num_j2+increment;
+ elseif ~isempty(lastfield) && num_a>lastfield
+ num_a=1;
+ num1=num1+1;
+ num2=num2+1;
+ end
+end
+
+% display the new open numbers
+set(handles.i1,'String',num2stra(num1,NomType,1));
+set(handles.i2,'String',num2stra(num2,NomType,1));
+set(handles.j1,'String',num2stra(num_a,NomType,2));
+set(handles.j2,'String',num2stra(num_b,NomType,2));
+[indices]=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
+set(handles.FileIndex,'String',indices);
+if sub_value ==1
+ NomType_1=get(handles.FileIndex_1,'UserData');
+ [indices]=...
+ name_generator('',num1,num_a,'',NomType_1,1,num2,num_b,'');
+ set(handles.FileIndex_1,'String',indices);
+end
+
+% refresh plots
+run0_Callback(hObject, eventdata, handles); %run
+
+
+%-------------------------------------------------------
+% --- Executes on button press in movie_pair.
+%-------------------------------------------------------
+function movie_pair_Callback(hObject, eventdata, handles)
+%initialisation
+set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow
+drawnow
+list_fields=get(handles.Fields,'String');% list menu fields
+index_fields=get(handles.Fields,'Value');% selected string index
+FieldName=list_fields{index_fields}; % selected field
+huvmat=get(handles.movie_pair,'parent');
+if isequal(FieldName,'image')
+ run0_Callback(hObject, eventdata, handles)%display the first image
+ UvData=get(huvmat,'UserData');
+else
+ warndlg_uvmat('an image or movie must be first introduced as input','ERROR')
+ return
+end
+[ff,rr,filebase,xx,Ext,SubDir]=read_file_boxes(handles);
+NomType=get(handles.FileIndex,'UserData');
+num_i2=str2num(get(handles.i2,'String'));
+num_j2=str2num(get(handles.j2,'String'));
+if ~isempty(num_j2)
+ num_i1=str2num(get(handles.i1,'String'));
+ [imaname_1,idetect]=name_generator(filebase,num_i1,num_j2,Ext,NomType);
+ if idetect==0
+ warndlg_uvmat(['second input open (-) ' imaname_1 ' not found'],'ERROR');
+ return
+ end
+ set(handles.i2,'String',''); % indicates that the second index i2 is not used
+elseif ~isempty(num_i2)
+ num_j1=str2num(get(handles.j1,'String'));
+ [imaname_1,idetect]=name_generator(filebase,num_i2,num_j1,Ext,NomType);
+ if idetect==0
+ warndlg_uvmat(['second input open (-) ' imaname_1 ' not found'],'ERROR');
+ return
+ end
+else
+ warndlg_uvmat('a second image index i2 or j2 is needed to show the pair as a movie','ERROR')
+ return
+end
+
+%read the second image
+Field.AName='image';
+% Field.ListDimName={'AY','AX'}; %A FAIRE
+% Field.DimValue=[];
+% Field.ListVarName={'A'};
+Field.AX=UvData.Field.AX;
+Field.AY=UvData.Field.AY;
+Field.CoordType='px';
+[Field.A,error]=read_image(imaname_1,NomType,num_i2);
+
+
+%px to phys or other transform on field
+menu_transform=get(handles.menu_coord,'String');
+choice_value=get(handles.menu_coord,'Value');
+transform=menu_transform{choice_value};%name of the transform fct given by the menu 'menu_coord'
+if ~isequal(transform,'') && ~isequal(transform,'px')
+ if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
+ Field=feval(transform,Field,UvData.XmlData);
+ end
+end
+
+ % make movie until movie speed is set to 0 or STOP is activated
+hima=findobj(handles.axes3,'Tag','ima');% %handles.axes3 =main plotting window (A GENERALISER)
+set(handles.STOP,'Visible','on')
+set(handles.speed,'Visible','on')
+set(handles.speed_txt,'Visible','on')
+while get(handles.speed,'Value')~=0 & isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command
+ % read and plot the series of images in non erase mode
+ set(hima,'CData',Field.A);
+ pause(1.02-get(handles.speed,'Value'));% wait for next image
+ set(hima,'CData',UvData.Field.A);
+ pause(1.02-get(handles.speed,'Value'));% wait for next image
+end
+set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
+
+%run0_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------
+% --- Executes on button press in run0.
+%-------------------------------------------------
+function run0_Callback(hObject, eventdata, handles)
+
+%initialisation
+set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
+drawnow
+abstime=[];
+abstime_1=[];
+dt=[];
+CalibCell={};%default
+Field={};
+huvmat=get(handles.run0,'parent');
+UvData=get(huvmat,'UserData');
+if isfield(UvData,'Txt')
+ UvData=rmfield(UvData,'Txt');%erase previous error message
+end
+set(handles.run0,'BusyAction','queue');
+if ishandle(handles.UVMAT_title) %remove title panel on uvmat
+ delete(handles.UVMAT_title)
+end
+
+% determine the main input file information for action
+TestInputFile=1;%default
+if isfield(UvData,'TestInputFile')&& isequal(UvData.TestInputFile,0),
+ TestInputFile=0;
+end
+num_i1=[];%default
+if TestInputFile
+ [filename,RootPath,filebase,xx,Ext,SubDir]=read_file_boxes(handles);
+ if ~exist(filename,'file')
+ msgbox_uvmat('ERROR',['input file ' filename ' does not exist'])
+ return
+ end
+ num_i1=stra2num(get(handles.i1,'String'));
+ num_i2=stra2num(get(handles.i2,'String'));
+ num_j1=stra2num(get(handles.j1,'String'));
+ num_j2=stra2num(get(handles.j2,'String'));
+ NomType=get(handles.FileIndex,'UserData');
+ %update the z position index
+% if isequal(get(handles.nb_slice,'String'),'vol.')%case of volume
+% set(handles.z_index,'String',get(handles.j1,'String'));
+% else
+ nbslice=str2num(get(handles.nb_slice,'String'));
+ z_index=mod(num_i1-1,nbslice)+1;
+ if ~isempty(nbslice)
+ z_index=mod(num_i1-1,nbslice)+1;
+ set(handles.z_index,'String',num2str(z_index))
+ % refresh menu for save_mask if relevant
+ masknumber=get(handles.masklevel,'String');
+ if length(masknumber)>=z_index
+ set(handles.masklevel,'Value',z_index)
+ end
+ end
+% end
+ % choose the main field
+ testima=0;
+ if isequal(lower(Ext),'.avi')||isequal(lower(Ext),'.vol')
+ testima=1;
+ FieldName='image';
+ else
+ form=imformats(Ext([2:end]));
+ if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
+ testima=1;
+ FieldName='image';
+ end
+ end
+else
+ filename=[];
+ FieldName='get_field...';
+ testima=0;
+end
+VelType=[];%default
+
+if ~testima
+ list_fields=get(handles.Fields,'String');% list menu fields
+ index_fields=get(handles.Fields,'Value');% selected string index
+ FieldName= list_fields{index_fields}; % selected field
+ if isequal(FieldName,'get_field...')% read the field names on the interface get_field...
+ VelType=get(handles.Fields,'UserData');
+ Field{1}=get(handles.Fields,'UserData');
+ else
+ VelType=setfield(handles);
+ %enable_transform(handles,'on')% no field transform (possible transform in the GUI get_field)
+ end
+end
+
+% choose a second field if Subfield option is 'on'
+filename_1=[];
+VelType_1=[];%default
+FieldName_1=[];
+scal_color=[];
+testvel=0;
+testX=0;%default
+VelType_1=setfield_1(handles);
+sub_value=get(handles.SubField,'Value');
+if sub_value==1
+ filename_1=read_file_boxes_1(handles);
+ if ~exist(filename_1,'file')
+ msgbox_uvmat('ERROR',['second file ' filename_1 ' does not exist'])
+ return
+ end
+ NomType_1=get(handles.FileIndex_1,'UserData');
+ list_fields=get(handles.Fields_1,'String');% list menu fields
+ index_fields=get(handles.Fields_1,'Value');% selected string index
+ FieldName_1= list_fields{index_fields}; % selected field
+ if isequal(VelType_1,'*')% free veltype choice
+ VelType_1=[];
+ elseif isequal(VelType_1,'"')% veltype the same as for the first field
+ if isempty(VelType)
+ VelType_1=[];
+ else
+ VelType_1=VelType;
+ end
+ end
+end
+
+% test for keeping the previous stored data if the input files are unchanged
+test_keepdata_1=0;%defautl
+test_keepdata=0;
+if sub_value>=2
+ if ~isequal(NomType_1,'*')%in cas of a series of files (not avi movie)
+ if isfield(UvData,'filename_1')& isfield(UvData,'VelType_1') & isfield(UvData,'FieldName_1')
+ test_keepdata_1= isequal(filename_1,UvData.filename_1)&...
+ isequal(VelType_1,UvData.filename_1) & isequal(FieldName_1,UvData.FieldName_1);
+
+ end
+ end
+end
+
+%read the input field(s)
+testima_1=isequal(FieldName_1,'image');
+%read images
+if ~isempty(filename) && testima
+ if isfield(UvData,'MovieObject')
+ A=read(UvData.MovieObject,num_i1);
+ else
+ [A,error]=read_image(filename,NomType,num_i1);
+ if ~isequal(error,0)
+ msgbox_uvmat('ERROR',error)
+ return
+ end
+ end
+ npxy=size(A);
+ set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
+ set(handles.npy,'String',num2str(npxy(1)));
+ Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
+ Rangy=[npxy(1)-0.5 0.5]; %
+ npx=str2num(get(handles.npx,'String'));
+ npy=str2num(get(handles.npy,'String'));
+ if isfield(UvData.XmlData,'Time')
+ abs_time=UvData.XmlData.Time;
+ end
+ Field{1}.AName='image';
+ Field{1}.ListVarName={'AY','AX','A'}; %
+ if size(A,3)==3;%color
+ Field{1}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
+ else
+ Field{1}.VarDimName={'AY','AX',{'AY','AX'}}; %
+ end
+ Field{1}.AY=Rangy;
+ Field{1}.AX=Rangx;
+ Field{1}.A=A;
+ Field{1}.CoordType='px'; %used for mouse_motion
+ Field{1}.CoordUnit='pixel'; %used for mouse_motion
+end
+if ~isfield(UvData,'Txt')& ~isempty(filename_1) & testima_1
+ [A,error]=read_image(filename_1,NomType_1,num_i1);
+ if ~isequal(error,0)
+ msgbox_uvmat('ERROR',error)
+ return
+ end
+ npxy=size(A);
+ set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
+ set(handles.npy,'String',num2str(npxy(1)));
+ Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
+ Rangy=[npxy(1)-0.5 0.5]; %
+ npx=str2num(get(handles.npx,'String'));
+ npy=str2num(get(handles.npy,'String'));
+ if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
+ abs_time=UvData.XmlData_1.Time;
+ end
+ Field{2}.AName='image';
+ Field{2}.ListVarName={'AY','AX','A'}; %
+ if size(A,3)==3;%color
+ Field{2}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
+ else
+ Field{2}.VarDimName={'AY','AX',{'AY','AX'}}; %
+ end
+ Field{2}.AY=Rangy;
+ Field{2}.AX=Rangx;
+ Field{2}.A=A;
+ Field{2}.CoordType='px'; %used for mouse_motion
+ Field{2}.CoordUnit='px'; %used for move_mou
+end
+
+%read ncfile(s)
+CivStage_1=0;%default
+VelType_out_1=[];
+InputField={FieldName};
+InputField_1={FieldName_1};
+if ~isfield(UvData,'Txt') && ((~isempty(filename)&~testima) || (~isempty(filename_1)&~testima_1)) ;
+ %read the velocity field(s) from netcdf rootfile(s)
+ list_code=get(handles.col_vec,'String');% list menu fields
+ index_code=get(handles.col_vec,'Value');% selected string index
+ scal_color= list_code{index_code(1)}; % selected field
+ if isequal(FieldName,'velocity')&& ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
+ InputField=[InputField scal_color];
+ end
+ if isequal(FieldName_1,'velocity') && ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
+ InputField_1=[InputField_1 scal_color];
+ end
+ if ~testima %read the first nc field
+ if isequal(FieldName,'get_field...')% read the field names on the interface get_field.
+ test_detect=0;%default
+ VelType=get(handles.Fields,'UserData');
+ hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
+ if isempty(hget_field)
+ hget_field= get_field(filename);%open the get_field GUI
+ end
+ test_detect=1;
+ hhget_field=guidata(hget_field);
+ set(hhget_field.inputfile,'String',filename)% update the list of input fields in get_field
+ set(hhget_field.ACTION,'Value',1)% PLOT option selected
+ set(hhget_field.list_fig,'Value',2)% plotting axes =uvmat selected
+ [Field{1},errormsg]=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
+ if ~isempty(errormsg)
+ msgbox_uvmat('ERROR',['error in uvmat/run0_Callback/read_get_field: ' errormsg])
+ return
+ end
+ CivStage=0;
+ VelType_out=[];
+ else
+ [Field{1},VelType_out]=read_civxdata(filename,InputField,VelType);
+ if isfield(Field{1},'Txt')
+ msgbox_uvmat('ERROR',Field{1}.Txt)
+ return
+ end
+ CivStage=Field{1}.CivStage;
+ UvData.NbDim=Field{1}.nb_dim;
+ end
+ end
+ if ~isempty(filename_1) && ~testima_1 %read the second file
+ if isequal(FieldName_1,'get_field...')% read the field names on the interface get_field.
+ test_detect=0;%default
+ hget_field=findobj(allchild(0),'Name','get_field_1');%find the get_field... GUI
+ if isempty(hget_field)
+ hget_field= get_field(filename_1);%open the get_field GUI
+ set(hget_field,'name','get_field_1')
+% enable_transform(handles,'off')% no field transform (possible transform in the GUI get_field)
+ end
+ test_detect=1;
+ hhget_field=guidata(hget_field);%handles of GUI elements in get_field
+ SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI
+ [Field{2},var_detect]=nc2struct(filename_1,SubField.ListVarName); %read the corresponding input data
+ Field{2}.VarAttribute=SubField.VarAttribute;
+ if isequal(get(hhget_field.menu_coord,'Visible'),'on')
+ list_transform=get(hhget_field.menu_coord,'String');
+ val_list=get(hhget_field.menu_coord,'Value');
+ transf=list_transform{val_list};
+ if ~isempty(transf)
+ Field{2}=feval(transf,Field{2});
+ end
+ end
+
+ %update the display on get_field
+ set(hhget_field.inputfile,'String',filename_1)
+ set(hhget_field.variables,'Value',1)
+ Tabchar={''};%default
+ Tabcell=[];
+ if isfield(Field{2},'ListGlobalAttribute')& ~isempty(Field{2}.ListGlobalAttribute)
+ for iline=1:length(Field{2}.ListGlobalAttribute)
+ Tabcell{iline,1}=Field{2}.ListGlobalAttribute{iline};
+ if isfield(Field{2}, Field{2}.ListGlobalAttribute{iline})
+ eval(['val=Field{2}.' Field{2}.ListGlobalAttribute{iline} ';'])
+ if ischar(val);
+ Tabcell{iline,2}=val;
+ else
+ Tabcell{iline,2}=num2str(val);
+ end
+ end
+ end
+ if ~isempty(Tabcell)
+ Tabchar=cell2tab(Tabcell,'=');
+ Tabchar=[{''};Tabchar];
+ end
+ end
+ set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
+ else
+ [Field{2},VelType_out_1]=read_civxdata(filename_1,[],VelType_1);
+ CivStage_1=Field{2}.CivStage;
+ end
+ if testima
+ VelType_out=VelType_out_1;
+ end
+ end
+end
+
+%update the display buttons for the first velocity type (first menuline)
+veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
+if testima
+ reset_vel_type(veltype_handles)
+elseif isempty(VelType)
+ set_veltype_display(veltype_handles,CivStage)%update the display of available velocity types for the first field
+ if isempty(VelType_out)
+ reset_vel_type(veltype_handles)
+ else
+ handle1=eval(['handles.' VelType_out]);
+ reset_vel_type(veltype_handles,handle1)
+ end
+end
+
+%update the display buttons for the second velocity type (second menuline)
+veltype_handles_1=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
+if testima_1
+ reset_vel_type(veltype_handles_1)
+elseif isempty(VelType_1)
+ set_veltype_display(veltype_handles_1,CivStage_1)%update the display of available velocity types for the first field
+ if isempty(VelType_out_1)
+ reset_vel_type(veltype_handles_1)
+ else
+ handle1=eval(['handles.' VelType_out_1 '_1']);
+ reset_vel_type(veltype_handles_1,handle1)
+ end
+end
+
+%introduce w as background image by default for a new series (only for nbdim=2)
+if ~isfield(UvData,'NewSeries')
+ UvData.NewSeries=1;
+end
+%put W as background image by default if NbDim=2:
+if ~isfield(UvData,'NbDim')|isempty(UvData.NbDim)|~isequal(UvData.NbDim,3)
+ if UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W);
+ set(handles.SubField,'Value',1);
+ menu=update_menu(handles.Fields_1,'w');%update the menu for the background scalar nd set the choice to 'w'
+ set(handles.RootPath_1,'String','"')
+ set(handles.RootFile_1,'String','"')
+ set(handles.SubDir_1,'String','"');
+ [indices]=name_generator('',num_i1,num_j1,'',NomType,1,num_i2,num_j2,'');
+ set(handles.FileIndex_1,'String',indices)
+ set(handles.FileExt_1,'String','"');
+ set(handles.Fields_1,'Visible','on');
+ set(handles.Fields_1,'Visible','on');
+ set(handles.RootPath_1,'Visible','on')
+ set(handles.RootFile_1,'Visible','on')
+ set(handles.SubDir_1,'Visible','on');
+ set(handles.FileIndex_1,'Visible','on');
+ set(handles.FileExt_1,'Visible','on');
+ set(handles.Fields_1,'Visible','on');
+ Field{1}.AName='w';
+ testscal=1;
+ end
+end
+
+%multislice case
+if TestInputFile &&(~isfield(UvData,'NbDim') || isequal(UvData.NbDim,2))&&...%2D case
+ isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')&& isfield(UvData.XmlData.GeometryCalib,'SliceCoord')
+% nbfield2=str2num(get(handles.last_j,'String'));
+ siz=size(UvData.XmlData.GeometryCalib.SliceCoord);
+ if siz(1)>1
+ NbSlice=siz(1);
+ set(handles.slices,'Visible','on')
+ set(handles.slices,'Value',1)
+ else
+ NbSlice=1;
+ end
+ set(handles.nb_slice,'String',num2str(NbSlice))
+ slices_Callback(hObject, eventdata, handles)
+% Coord=UvData.XmlData.GeometryCalib.SliceCoord;
+% ZIndex=num_i1-NbSlice*(floor((num_i1-1)/NbSlice));
+% Field{1}.Z=ZIndex;
+end
+
+%store the current open names, fields and vel types in uvmat interface
+UvData.filename=filename;
+UvData.filename_1=filename_1;
+UvData.VelType=VelType;
+UvData.VelType_1=VelType_1;
+UvData.FieldName=FieldName;
+UvData.FieldName_1=FieldName_1;
+if ~isempty(scal_color)
+ UvData.CName=scal_color;
+end
+
+%coordinate transform or user fct
+XmlData=[];%default
+if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
+ XmlData=UvData.XmlData;
+end
+XmlData_1=[];%default
+if isfield(UvData,'XmlData_1')
+ XmlData_1=UvData.XmlData_1;
+end
+menu_transform=get(handles.menu_coord,'String');
+choice_value=get(handles.menu_coord,'Value');
+transform=menu_transform{choice_value};%name of the transform fct given by the menu 'menu_coord'
+
+% z index
+if TestInputFile
+ Field{1}.ZIndex=mod(num_i1-1,nbslice)+1;
+end
+%px to phys or other transform on field
+if ~isequal(transform,'')
+ if length(Field)>=2
+ Field{2}.ZIndex=mod(num_i1-1,nbslice)+1;
+ [Field{1},Field{2}]=feval(transform,Field{1},XmlData,Field{2},XmlData_1);
+ if isempty(Field{2})
+ Field(2)=[];
+ end
+ else
+ Field{1}=feval(transform,Field{1},XmlData);
+ end
+end
+
+%calculate scalar
+if ~testima && ~isequal(FieldName,'get_field...')%
+ Field{1}=calc_field(InputField,Field{1});
+end
+if length(Field)==2 && ~testima_1 && ~isequal(FieldName,'get_field...')
+ Field{2}=calc_field(InputField_1,Field{2});
+end
+
+% combine the two input fields (e.g. substract velocity fields)
+if numel(Field)==2
+ if ~(isequal(get(handles.movie_pair,'Value'),1) & isequal(FieldName,'image') & isequal(FieldName_1,'image')) %combine fields if not viewing image pairs
+ UvData.Field=sub_field(Field{1},Field{2}); %TO UPDATE FOR MORE GENERAL INPUT
+ end
+else
+ UvData.Field=Field{1};
+end
+UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
+% test 3D , default projection menuplane and typical mesh (needed to menuopen set_object)
+test_x=0;
+test_z=0;% test for unstructured z coordinate
+UvData.ZMax=0;
+UvData.ZMin=0;%default
+UvData.Mesh=1; %default
+[UvData.Field,errormsg]=check_field_structure(UvData.Field);
+if ~isempty(errormsg)
+ msgbox_uvmat('ERROR',['error in uvmat/run0_Callback/check_field_structure: ' errormsg])
+ return
+end
+[CellVarIndex,NbDim,VarType]=find_field_indices(UvData.Field);
+[NbDim,imax]=max(NbDim);
+if isempty(imax)
+ DimVarIndex=0;
+ coord_x=[];
+else
+ VarIndex=CellVarIndex{imax};
+ coord_x=VarType{imax}.coord_x;
+end
+if isfield(UvData,'NbDim') & ~isempty(UvData.NbDim)
+ NbDim=UvData.NbDim;
+else
+ UvData.NbDim=NbDim;
+end
+if ~isempty(CellVarIndex) & ~isempty(VarType{imax}.coord_x) & ~isempty(VarType{imax}.coord_y) %unstructured coordinate z
+ XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
+ YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
+ test_x=1;
+elseif isfield(UvData.Field,'X')&isfield(UvData.Field,'Y')
+ XName='X';
+ YName='Y';
+ test_x=1;
+end
+if test_x
+ eval(['UvData.XMax=max(UvData.Field.' XName ');'])
+ eval(['UvData.XMin=min(UvData.Field.' XName ');'])
+ eval(['UvData.YMax=max(UvData.Field.' YName ');'])
+ eval(['UvData.YMin=min(UvData.Field.' YName ');'])
+ eval(['nbvec=length(UvData.Field.' XName ');'])
+ if NbDim==3%
+ if ~isempty(CellVarIndex) & ~isempty(VarType{imax}.coord_z)%unstructured coordinate z
+ ZName=UvData.ListVarName{VarType{imax}.coord_z};
+ eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
+ eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
+ test_z=1;
+ elseif isfield(UvData,'Z')% usual civ data
+ UvData.ZMax=max(UvData.Z);
+ UvData.ZMin=min(UvData.Z);
+ test_z=1;
+ end
+ end
+ if isequal(UvData.ZMin,UvData.ZMax)%no z dependency
+ NbDim=2;
+ test_z=0;
+ end
+ if test_z
+ UvData.Mesh=((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)*(UvData.ZMax-UvData.ZMin))/nbvec;% volume per vector
+ UvData.Mesh=(UvData.Mesh)^(1/3);
+ else
+ UvData.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/nbvec);%2D
+ end
+end
+%case of structured coordinates
+if isfield(UvData.Field,'AX') & isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')
+ UvData.XMax=max(UvData.Field.AX);
+ UvData.XMin=min(UvData.Field.AX);
+ UvData.YMax=max(UvData.Field.AY);
+ UvData.YMin=min(UvData.Field.AY);
+ np_A=size(UvData.Field.A);
+ UvData.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/((np_A(1)-1) * (np_A(2)-1))) ;
+end
+if isempty(coord_x)&~isempty(CellVarIndex)
+ VarIndex=CellVarIndex{imax}; % list of variable indices
+ DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
+ if NbDim==3
+ nbpoints=UvData.Field.DimValue(DimIndex(1));
+ %Zvar=DimVarIndex(DimIndex(1));
+ %Zvar=DimVarIndex(1);
+ Zvar=VarType{imax}.coord_3;
+ if Zvar~=0 % z is a dimension variable
+ ZName=UvData.Field.ListVarName{Zvar};
+ eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
+ eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
+ else
+ testcoord_z=0;
+ if length(UvData.Field.VarAttribute)>=VarIndex(1)
+ if isfield(UvData.Field.VarAttribute{VarIndex(1)},'Coord_1')%regular grid
+ Coord_z=UvData.Field.VarAttribute{VarIndex(1)}.Coord_1;
+ UvData.ZMax=max(Coord_z);
+ UvData.ZMin=min(Coord_z);
+ testcoord_z=1;
+ end
+ end
+ if ~testcoord_z
+ UvData.ZMin=1;
+ UvData.ZMax=UvData.Field.DimValue(DimIndex(1));
+ end
+ end
+ UvData.Mesh=(UvData.ZMax-UvData.ZMin)/(nbpoints-1);
+ elseif NbDim==2
+ nbpoints_y=UvData.Field.DimValue(DimIndex(1));
+ Yvar=VarType{imax}.coord_y;
+ if Yvar~=0 % x is a dimension variable
+ YName=UvData.Field.ListVarName{Yvar};
+ eval(['UvData.YMax=max(UvData.Field.' YName ');'])
+ eval(['UvData.YMin=min(UvData.Field.' YName ');'])
+ else
+ testcoord_y=0;
+ if ~testcoord_y
+ UvData.YMin=1;
+ UvData.YMax=UvData.Field.DimValue(DimIndex(1));
+ end
+ end
+ DY=(UvData.YMax-UvData.YMin)/(nbpoints_y-1);
+ nbpoints_x=UvData.Field.DimValue(DimIndex(2));
+ Xvar=VarType{imax}.coord_x;
+ if Xvar~=0 % x is a dimension variable
+ XName=UvData.Field.ListVarName{Xvar};
+ eval(['UvData.XMax=max(UvData.Field.' XName ');'])
+ eval(['UvData.XMin=min(UvData.Field.' XName ');'])
+ else
+ testcoord_x=0;
+ if ~testcoord_x
+ UvData.XMin=1;
+ UvData.XMax=UvData.Field.DimValue(DimIndex(2));
+ end
+ end
+ DX=(UvData.XMax-UvData.XMin)/(nbpoints_x-1);
+ UvData.Mesh= sqrt(DX*DY);
+ end
+end
+
+%create a default projection menuplane
+UvData.Object{1}.Style='plane';%main plotting plane
+UvData.Object{1}.ProjMode='projection';%main plotting plane
+if ~isfield(UvData.Object{1},'plotaxes')
+ UvData.Object{1}.plotaxes=handles.axes3;%default plotting axis
+ set(handles.list_object,'String',{'1-PLANE';'...'});
+ set(handles.list_object,'Value',1);
+end
+
+%3D case (menuvolume)
+if NbDim==3
+ UvData.Object{1}.NbDim=UvData.NbDim;%test for 3D objects
+ UvData.Object{1}.RangeZ=UvData.Mesh;%main plotting plane
+ UvData.Object{1}.Coord(1,3)=(UvData.ZMin+UvData.ZMax)/2;%section at a middle plane chosen
+ UvData.Object{1}.Phi=0;
+ UvData.Object{1}.Theta=0;
+ UvData.Object{1}.Psi=0;
+ UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR
+ PlotHandles=get_plot_handles(handles);
+ ZBounds(1)=UvData.ZMin; %minimum for the Z slider
+ ZBounds(2)=UvData.ZMax;%maximum for the Z slider
+ set_object(UvData.Object{1},PlotHandles,ZBounds);
+ set(handles.list_object,'Value',1);
+%multilevel case (single menuplane in a 3D space)
+elseif isfield(UvData,'Z')
+ if isfield(UvData,'CoordType')& isequal(UvData.CoordType,'phys') & isfield(UvData,'XmlData')
+ XmlData=UvData.XmlData;
+ if isfield(XmlData,'PlanePos')
+ UvData.Object{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
+ end
+ if isfield(XmlData,'PlaneAngle')
+ siz=size(XmlData.PlaneAngle);
+ indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)
+ UvData.Object{1}.Phi=XmlData.PlaneAngle(indangle,1);
+ UvData.Object{1}.Theta=XmlData.PlaneAngle(indangle,2);
+ UvData.Object{1}.Psi=XmlData.PlaneAngle(indangle,3);
+ end
+ elseif isfield(UvData,'ZIndex')
+ UvData.Object{1}.ZObject=UvData.ZIndex;
+ end
+end
+
+%Plot the projections on all existing projection objects
+keeplim=get(handles.FixedLimits,'Value');
+%reset the min and max of scalar if only the mask is displayed
+if isfield(UvData,'Mask')&~isfield(UvData,'A')
+ set(handles.MinA,'String','0')
+ set(handles.MaxA,'String','255')
+end
+
+Object=UvData.Object;
+for iobj=1:length(Object)
+ if ~isempty(Object{iobj})%& isfield(Object{iobj},'plotaxes')& ishandle(Object{iobj}.plotaxes)
+ %Projeter les champs sur l'objet:*
+ ObjectData=proj_field(UvData.Field,Object{iobj},iobj);
+
+ %use of mask
+ if isfield(ObjectData,'NbDim')&isequal(ObjectData.NbDim,2)
+ if isfield(ObjectData,'Mask') & isfield(ObjectData,'A')
+ flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
+ AX=ObjectData.AX;
+ AY=ObjectData.AY;
+ MaskX=ObjectData.MaskX;
+ MaskY=ObjectData.MaskY;
+ if ~isequal(MaskX,AX)|~isequal(MaskY,AY)
+ nxy=size(flag_mask);
+ sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
+ sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
+ x_mask=[ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end)]; % pixel x coordinates for image display
+ y_mask=[ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end)];% pixel x coordinates for image display
+ %project on the positions of the scalar
+ npxy=size(ObjectData.A);
+ dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
+ dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
+ xi=[ObjectData.AX(1):dxy(2):ObjectData.AX(end)];
+ yi=[ObjectData.AY(1):dxy(1):ObjectData.AY(end)];
+ [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
+ flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
+ end
+ AClass=class(ObjectData.A);
+ ObjectData.A=flag_mask.*double(ObjectData.A);
+ ObjectData.A=feval(AClass,ObjectData.A);
+ ind_off=[];
+ if isfield(ObjectData,'ListVarName')
+ for ilist=1:length(ObjectData.ListVarName)
+ if isequal(ObjectData.ListVarName{ilist},'Mask')|isequal(ObjectData.ListVarName{ilist},'MaskX')|isequal(ObjectData.ListVarName{ilist},'MaskY')
+ ind_off=[ind_off ilist];
+ end
+ end
+ ObjectData.ListVarName(ind_off)=[];
+ ObjectData.VarDimIndex(ind_off)=[];
+ ind_off=[];
+ for ilist=1:length(ObjectData.ListDimName)
+ if isequal(ObjectData.ListDimName{ilist},'MaskX')|isequal(ObjectData.ListDimName{ilist},'MaskY')
+ ind_off=[ind_off ilist];
+ end
+ end
+ ObjectData.ListDimName(ind_off)=[];
+ ObjectData.DimValue(ind_off)=[];
+ end
+ end
+ end
+ if ~isempty(ObjectData)
+ haxes=[];%default
+ if isfield(Object{iobj},'plotaxes')
+ haxes=Object{iobj}.plotaxes;%axes used for representing the projection on the object
+ end
+ PosColorbar=[];%default: no colorbar
+ if ishandle(haxes) & isequal(get(haxes,'Tag'),'axes3')& isfield(UvData,'PosColorbar')
+ PosColorbar=UvData.PosColorbar;%prescribe the colorbar position on the uvmat interface
+ else
+ PosColorbar='*';%default position
+ end
+ PlotParam=read_plot_param(handles);%read plotting parameters on the uvmat interface
+ [PlotType,ScalOut,UvData.Object{iobj}.plotaxes]=plot_field(ObjectData,haxes,PlotParam,keeplim,PosColorbar);
+ if isequal(PlotType,'none')
+ hget_field=findobj(allchild(0),'name','get_field');
+ if isempty(hget_field)
+ get_field([],ObjectData)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
+ else
+ msgbox_uvmat('ERROR','The field defined by get_field cannot be plotted')
+ end
+ end
+ UvData.Object{iobj}.PlotParam=ScalOut; %record the plotting parameters
+ end
+
+ end
+end
+
+%display the updated plotting parameters for the base menuplane
+write_plot_param(handles,UvData.Object{1}.PlotParam);% update the display of the plotting parameters
+set(huvmat,'UserData',UvData)
+
+%update the mask
+if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
+ update_mask(handles,num_i1,num_i2);
+end
+
+%prepare the menus of histograms (for the whole menuvolume in 3D case)
+menu_histo=(UvData.Field.ListVarName)';
+ind_bad=[];
+nb_histo=1;
+for ivar=1:numel(menu_histo)
+ if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
+ Role=UvData.Field.VarAttribute{ivar}.Role;
+ switch Role
+ case {'coord_x','coord_y','coord_z','dimvar'}
+ ind_bad=[ind_bad ivar];
+ case {'vector_y'}
+ nb_histo=nb_histo+1;
+ end
+ end
+ DimCell=UvData.Field.VarDimName{ivar};
+ DimName='';
+ if ischar(DimCell)
+ DimName=DimCell;
+ elseif iscell(DimCell)&& numel(DimCell)==1
+ DimName=DimCell{1};
+ end
+ if strcmp(DimName,menu_histo{ivar})
+ ind_bad=[ind_bad ivar];
+ end
+end
+menu_histo(ind_bad)=[];
+test_v=0;
+if ~isempty(menu_histo)
+ set(handles.histo1_menu,'Value',1)
+ set(handles.histo1_menu,'String',menu_histo)
+ histo1_menu_Callback(hObject, eventdata, handles)
+ if nb_histo > 1
+ test_v=1;
+ set(handles.histo2_menu,'Visible','on')
+ set(handles.histo_v,'Visible','on')
+ set(handles.histo2_menu,'String',menu_histo)
+ set(handles.histo2_menu,'Value',2)
+ histo2_menu_Callback(hObject, eventdata, handles)
+ end
+end
+if ~test_v
+ set(handles.histo2_menu,'Visible','off')
+ set(handles.histo_v,'Visible','off')
+ cla(handles.histo_v)
+ set(handles.histo2_menu,'Value',1)
+end
+
+%display time
+testimedoc=0;
+if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'Time')
+ if isempty(num_i2)
+ num_i2=num_i1;
+ end
+ if isempty(num_j1)
+ num_j1=1;
+ end
+ if isempty(num_j2)
+ num_j2=num_j1;
+ end
+ siz=size(UvData.XmlData.Time);
+ if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
+ abstime=(UvData.XmlData.Time(num_i1,num_j1)+UvData.XmlData.Time(num_i2,num_j2))/2;%overset the time read from files
+ dt=(UvData.XmlData.Time(num_i2,num_j2)-UvData.XmlData.Time(num_i1,num_j1));
+ testimedoc=1;
+ end
+end
+if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
+ [P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
+ num_i2=str2num(str2);
+ if isempty(num_i2)
+ num_i2=num_i1;
+ end
+ num_j1=str2num(str_a);
+ if isempty(num_j1)
+ num_j1=1;
+ end
+ num_j2=str2num(str_b);
+ if isempty(num_j2)
+ num_j2=num_j1;
+ end
+ num_i1=str2num(str1);
+ siz=size(UvData.XmlData_1.Time);
+ if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
+ abstime_1=(UvData.XmlData_1.Time(num_i1,num_j1)+UvData.XmlData_1.Time(num_i2,num_j2))/2;%overset the time read from files
+ end
+end
+set(handles.abs_time,'String',num2str(abstime,4))
+set(handles.abs_time_1,'String',num2str(abstime_1,4))
+if testimedoc && isfield(UvData,'dt')
+ dt=UvData.dt;
+end
+if isequal(dt,0)
+ set(handles.Dt_txt,'String','')
+else
+ if ~(isfield(UvData,'TimeUnit') && ~isempty(UvData.TimeUnit))
+ set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) ' 10^(-3)'] )
+ else
+ set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) ' m' UvData.TimeUnit] )
+ end
+end
+set(handles.run0,'BackgroundColor',[1 0 0])
+
+
+
+%-------------------------------------------------------------------
+% --- translate coordinate to matrix index
+%-------------------------------------------------------------------
+function [indx,indy]=pos2ind(x0,rangx0,nxy)
+indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel
+indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
+
+%-------------------------------------------------------------------
+% --- Executes on button press in 'FixedLimits'.
+%-------------------------------------------------------------------
+function FixedLimits_Callback(hObject, eventdata, handles)
+test=get(handles.FixedLimits,'Value');
+if test
+ set(handles.FixedLimits,'BackgroundColor',[1 1 0])
+else
+ set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
+end
+
+%-------------------------------------------------------------------
+% --- Executes on button press in auto_xy.
+function auto_xy_Callback(hObject, eventdata, handles)
+test=get(handles.auto_xy,'Value');
+if test
+ set(handles.auto_xy,'BackgroundColor',[1 1 0])
+ cla(handles.axes3)
+ update_plot(handles)
+else
+ set(handles.auto_xy,'BackgroundColor',[0.7 0.7 0.7])
+ update_plot(handles)
+% axis(handles.axes3,'image')
+end
+
+
+%-------------------------------------------------------------------
+
+%-------------------------------------------------------------------
+% --- Executes on button press in 'zoom'.
+%-------------------------------------------------------------------
+function zoom_Callback(hObject, eventdata, handles)
+huvmat=get(handles.zoom,'parent');%general input
+UvData=get(huvmat,'UserData');
+if (get(handles.zoom,'Value') == 1);
+ set(handles.zoom,'BackgroundColor',[1 1 0])
+ set(handles.FixedLimits,'Value',1)% propose by default fixed limits for the plotting axes
+ set(handles.FixedLimits,'BackgroundColor',[1 1 0])
+ %UvData.ZoomOn=1; %test for mouse action
+else
+ set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
+ %UvData.ZoomOn=0; %test for mouse action
+end
+set(huvmat,'UserData',UvData);
+
+%-------------------------------------------------------------------
+%----Executes on button press in 'record': records the current flags of manual correction.
+%-------------------------------------------------------------------
+function record_Callback(hObject, eventdata, handles)
+% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
+filename=read_file_boxes(handles);
+AxeData=get(gca,'UserData');
+[erread,message]=fileattrib(filename);
+if ~isempty(message) & ~isequal(message.UserWrite,1)
+ msgbox_uvmat('ERROR',['no writting access to ' filename])
+ return
+end
+nc=netcdf(filename,'write'); %open netcdf file
+result=redef(nc);
+if isempty(result), warndlg_uvmat('##Bad redef operation.','ERROR'),end
+test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
+if ~test_civ2
+ test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
+end
+if test_civ2 % for civ2
+
+ theDim=nc('nb_vectors2') ;% get the number of velocity vectors
+ nb_vectors2=size(theDim);
+ var_FixFlag=ncvar('vec2_FixFlag',nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
+ var_FixFlag(1:nb_vectors2)=AxeData.FF;%
+elseif test_civ1 % for civ1
+
+ theDim=nc('nb_vectors') ;% get the number of velocity vectors
+ nb_vectors=size(theDim);
+ var_FixFlag=ncvar('vec_FixFlag',nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
+ var_FixFlag(1:nb_vectors)=AxeData.FF;%
+else
+ msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
+end
+fin=close(nc);
+
+
+
+%-------------------------------------------------------------------
+%determines the fields to read from the interface
+%------------------------------------------------------------------
+function [VelType,civ]=setfield(handles)
+
+VelType=[]; %default
+if (get(handles.civ1,'Value') == 1);
+ VelType='civ1';
+% interp1
+elseif (get(handles.interp1,'Value') == 1);
+ VelType='interp1';
+% filter1
+elseif (get(handles.filter1,'Value') == 1);
+ VelType='filter1';
+% CIV2
+elseif (get(handles.civ2,'Value') == 1);
+ VelType='civ2';
+% interp2
+elseif (get(handles.interp2,'Value') == 1);
+ VelType='interp2';
+% filter2
+elseif (get(handles.filter2,'Value') == 1);
+ VelType='filter2';
+end
+
+if isequal(get(handles.filter2,'Visible'),'on');
+ civ=6;
+% interp1
+elseif isequal(get(handles.interp2,'Visible'),'on');
+ civ=5;
+% filter1
+elseif isequal(get(handles.civ2,'Visible'),'on');
+ civ=4;
+% CIV2
+elseif isequal(get(handles.filter1,'Visible'),'on');
+ civ=3;
+% interp2
+elseif isequal(get(handles.interp1,'Visible'),'on');
+ civ=2;
+% filter2
+elseif isequal(get(handles.civ1,'Visible'),'on');
+ civ=1;
+else
+ civ=0;
+end
+
+%-------------------------------------------------------------------
+%determines the veltype of the second field to read from the iinterface
+%------------------------------------------------------------------
+function VelType=setfield_1(handles)
+
+VelType=[]; %default
+if (get(handles.civ1_1,'Value') == 1);
+ VelType='civ1';
+% interp1
+elseif (get(handles.interp1_1,'Value') == 1);
+ VelType='interp1';
+% filter1
+elseif (get(handles.filter1_1,'Value') == 1);
+ VelType='filter1';
+% CIV2
+elseif (get(handles.civ2_1,'Value') == 1);
+ VelType='civ2';
+% interp2
+elseif (get(handles.interp2_1,'Value') == 1);
+ VelType='interp2';
+% filter2
+elseif (get(handles.filter2_1,'Value') == 1);
+ VelType='filter2';
+end
+
+
+%---------------------------------------------------
+% --- Executes on button press in SubField
+function SubField_Callback(hObject, eventdata, handles)
+huvmat=get(handles.run0,'parent');
+UvData=get(huvmat,'UserData');
+if get(handles.SubField,'Value')==0% if the subfield button is desactivated
+ set(handles.RootPath_1,'String','')
+ set(handles.RootFile_1,'String','')
+ set(handles.SubDir_1,'String','');
+ set(handles.FileIndex_1,'String','');
+ set(handles.FileExt_1,'String','');
+ set(handles.RootPath_1,'Visible','off')
+ set(handles.RootFile_1,'Visible','off')
+ set(handles.SubDir_1,'Visible','off');
+ set(handles.FileIndex_1,'Visible','off');
+ set(handles.FileExt_1,'Visible','off');
+ set(handles.Fields_1,'Value',1);%set to blank state
+ set_veltype_display([handles.civ1_1 handles.interp1_1 handles.filter1_1 ...
+ handles.civ2_1 handles.interp2_1 handles.filter2_1],0)
+ if isfield(UvData,'XmlData_1')
+ UvData=rmfield(UvData,'XmlData_1');
+ end
+ set(huvmat,'UserData',UvData);
+ run0_Callback(hObject, eventdata, handles); %run
+else
+ MenuBrowse_1_Callback(hObject, eventdata, handles)
+end
+
+% %----------------------------------------------
+% %read the data displayed for the input rootfile windows (new)
+% %-------------------------------------------------
+function [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles)
+RootPath=get(handles.RootPath,'String');
+FileName=RootPath; %default
+SubDir=get(handles.SubDir,'String');
+if ~isempty(SubDir) && ~isequal(SubDir,'')
+ if (isequal(SubDir(1),'/')|| isequal(SubDir(1),'\'))
+ SubDir(1)=[]; %suppress possible / or \ separator
+ end
+ FileName=fullfile(RootPath,SubDir);
+end
+RootFile=get(handles.RootFile,'String');
+if ~isempty(RootFile) && ~isequal(RootFile,'')
+ if (isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
+ RootFile(1)=[]; %suppress possible / or \ separator
+ end
+ FileName=fullfile(FileName,RootFile);
+end
+FileBase=fullfile(RootPath,RootFile);
+FileIndices=get(handles.FileIndex,'String');
+FileExt=get(handles.FileExt,'String');
+FileName=[FileName FileIndices FileExt];
+
+%----------------------------------------------
+%read the data displayed for the second input rootfile windows
+%-------------------------------------------------
+function [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles)
+RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
+if isequal(RootPath_1,'"'),RootPath_1=get(handles.RootPath,'String'); end;
+FileName_1=RootPath_1; %default
+SubDir_1=get(handles.SubDir_1,'String');
+if isequal(SubDir_1,'"')
+ SubDir_1=get(handles.SubDir,'String');
+end
+if ~isempty(SubDir_1) && ~isequal(SubDir_1,'')
+ if (isequal(SubDir_1(1),'/')|| isequal(SubDir_1(1),'\'))
+ SubDir_1(1)=[]; %suppress possible / or \ separator
+ end
+ FileName_1=fullfile(RootPath_1,SubDir_1);
+end
+RootFile_1=get(handles.RootFile_1,'String');
+if isequal(RootFile_1,'"'),RootFile_1=get(handles.RootFile,'String'); end;
+if ~isempty(RootFile_1) && ~isequal(RootFile_1,'')
+ if ~(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
+ RootFile_1(1)=[];%suppress possible / or \ separator
+ end
+ FileName_1=fullfile(FileName_1,RootFile_1);
+end
+FileBase_1=fullfile(RootPath_1,RootFile_1);
+FileIndices_1=get(handles.FileIndex_1,'String');
+FileExt_1=get(handles.FileExt_1,'String');
+if isequal(FileExt_1,'"'),FileExt_1=get(handles.FileExt,'String'); end;
+FileName_1=[FileName_1 FileIndices_1 FileExt_1];
+
+%---------------------------------------------------
+% --- Executes on menu selection Fields
+function Fields_Callback(hObject, eventdata, handles)
+%-------------------------------------------------
+huvmat=get(handles.Fields,'parent');
+list_fields=get(handles.Fields,'String');% list menu fields
+index_fields=get(handles.Fields,'Value');% selected string index
+field= list_fields{index_fields(1)}; % selected string
+if isequal(field,'get_field...')
+ veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
+ set_veltype_display(veltype_handles,0) % unvisible civ buttons
+ filename=read_file_boxes(handles);
+ hget_field=findobj(allchild(0),'name','get_field');
+ if ~isempty(hget_field)
+ delete(hget_field)
+ end
+ get_field(filename)
+ return %no action
+end
+list_fields=get(handles.Fields_1,'String');% list menu fields
+index_fields=get(handles.Fields_1,'Value');% selected string index
+field_1= list_fields{index_fields(1)}; % selected string
+UvData=get(huvmat,'UserData');
+
+%read the rootfile input display
+FileExt=get(handles.FileExt,'String');
+[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
+NomTypeNew=NomType;%default
+if isequal(field,'image')
+ % transform netc type to the corresponding image type
+ if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')|| isequal(NomType,'#_ab')|| isequal(NomType,'_i1-i2')
+ UvData.SubDir=get(handles.SubDir,'String'); %preserve the subdir in memory
+ if ~isempty(UvData.SubDir) && (isequal(UvData.SubDir(1),'/')|isequal(UvData.SubDir(1),'/'))
+ UvData.SubDir(1)=[];
+ end
+ set(handles.SubDir,'String','')
+ set(handles.FileExt,'String','.png');
+ if isequal(NomType,'_i1-i2_j')|isequal(NomType,'_i_j1-j2')
+ NomTypeNew='_i_j';
+ elseif isequal(NomType,'#_ab')
+ NomTypeNew='#a';
+ elseif isequal(NomType,'_i1-i2')
+ NomTypeNew='_i';
+ end
+ end
+ veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
+ set_veltype_display(veltype_handles,0) % unvisible civ buttons
+else
+ ext=get(handles.FileExt,'String');
+ if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
+ MenuBrowse_Callback(hObject, eventdata, handles)
+ end
+ if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
+ set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
+ set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
+ set(handles.interp1,'BackgroundColor',[0.702 0.702 0.702])
+ set(handles.interp2,'BackgroundColor',[0.702 0.702 0.702])
+ elseif isequal(field,'more...');
+ set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
+ set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
+ str=calc_field;%get the list of available scalars by the function calc_scal
+ [ind_answer,v] = listdlg('PromptString','Select a file:',...
+ 'SelectionMode','single',...
+ 'ListString',str);
+ % edit the choice in the field and action menu
+ scalar=cell2mat(str(ind_answer));
+ menu=update_menu(handles.Fields,scalar);
+ menu=[{''};menu];
+ set(handles.Fields_1,'String',menu);% store the selected scalar type
+ end
+end
+indices=name_generator('',str2num(str1),str2num(str_a),'',NomTypeNew,1,str2num(str2),str2num(str_b),'');
+set(handles.FileIndex,'String',indices)
+set(handles.FileIndex,'UserData',NomTypeNew)
+%common to Fields_1_Callback
+if isequal(field,'image')|isequal(field_1,'image')
+ set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
+ set(handles.npy_title,'Visible','on')
+ set(handles.npx,'Visible','on')
+ set(handles.npy,'Visible','on')
+ set(handles.fix_pair,'Value',0)
+else
+ set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
+ set(handles.npy_title,'Visible','off')
+ set(handles.npx,'Visible','off')
+ set(handles.npy,'Visible','off')
+ set(handles.fix_pair,'Value',1)
+end
+if isequal(field,'velocity')|isequal(field_1,'velocity');
+ state_vect='on';
+else
+ state_vect='off';
+end
+if ~isequal(field,'velocity')|(~isequal(field_1,'velocity'));
+ state_scal='on';
+else
+ state_scal='off';
+end
+setfield(handles);% update the field structure ('civ1'....)
+
+if ~isfield(UvData,'NewSeries')|isequal(UvData.NewSeries,0)
+ run0_Callback(hObject, eventdata, handles)
+end
+
+%---------------------------------------------------
+% --- Executes on menu selection Fields
+function Fields_1_Callback(hObject, eventdata, handles)
+%-------------------------------------------------
+huvmat=get(handles.Fields_1,'parent');
+list_fields=get(handles.Fields,'String');% list menu fields
+index_fields=get(handles.Fields,'Value');% selected string index
+field= list_fields{index_fields(1)}; % selected string
+list_fields=get(handles.Fields_1,'String');% list menu fields
+index_fields=get(handles.Fields_1,'Value');% selected string index
+field_1= list_fields{index_fields(1)}; % selected string for the second field
+if isequal(field_1,'') %remove second field if 'blank' field is selected
+ set(handles.SubField,'Value',0)
+ SubField_Callback(hObject, eventdata, handles)
+ return
+end
+UvData=get(huvmat,'UserData');
+
+%read the rootfile input display
+FileExt_prev=get(handles.FileExt_1,'String');
+if isempty(FileExt_prev)|isequal(FileExt_prev,'')
+ FileExt_1=get(handles.FileExt,'String');
+else
+ FileExt_1=FileExt_prev;
+end
+NomType_1=get(handles.FileIndex_1,'UserData');
+if isempty(NomType_1)|isequal(NomType_1,'')
+ NomType_1=get(handles.FileIndex,'UserData');
+end
+NomTypeNew=NomType_1;%default
+
+set(handles.SubField,'Value',1)%introduce second field
+if isfield(UvData,'XmlData')
+ UvData.XmlData_1=UvData.XmlData;
+end
+set(handles.FileIndex_1,'Visible','on')
+set(handles.FileExt_1,'Visible','on')
+RootPath_1=get(handles.RootPath_1,'String');
+RootFile_1=get(handles.RootFile_1,'String');
+if isempty(RootPath_1)|isequal(RootPath_1,'')
+ set(handles.RootPath_1,'String','"')
+end
+if isempty(RootFile_1) | isequal(RootFile_1,'')
+ set(handles.RootFile_1,'String','"')
+end
+if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
+ RootFile_1(1)=[];
+end
+
+if isequal(field_1,'get_field...')
+ veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
+ set_veltype_display(veltype_handles,0) % unvisible civ buttons
+ filename=read_file_boxes_1(handles);
+ hget_field=findobj(allchild(0),'name','get_field_1');
+ if ~isempty(hget_field)
+ delete(hget_field)
+ end
+ hget_field=get_field(filename);
+ set(hget_field,'name','get_field_1')
+ return %no action
+end
+if isequal(field_1,'image')
+ % transform netc type to the corresponding image type
+ set(handles.FileExt_1,'String','.png');
+ if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')| isequal(NomType_1,'#_ab')| isequal(NomType_1,'_i1-i2')
+ UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory
+ set(handles.SubDir_1,'String','')
+% set(handles.FileExt_1,'String','.png');
+ if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')
+ NomTypeNew='_i_j';
+ elseif isequal(NomType_1,'#_ab')
+ NomTypeNew='#a';
+ elseif isequal(NomType_1,'_i1-i2')
+ NomTypeNew='_i';
+ end
+ end
+ veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
+ set_veltype_display(veltype_handles,0) % unvisible civ buttons
+else
+ set(handles.SubDir_1,'Visible','on')
+ if ~isequal(FileExt_prev,'.nc') %find the new NomType if the previous display was not already a netcdf file
+ veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
+ set_veltype_display(veltype_handles,6); % make all civ buttons visible
+ RootPath_1=get(handles.RootPath_1,'String');
+ RootFile_1=get(handles.RootFile_1,'String');
+ if isempty(RootPath_1)|isequal(RootPath_1,'')
+ set(handles.RootPath_1,'String','"')
+ end
+ if isempty(RootFile_1) | isequal(RootFile_1,'')
+ set(handles.RootFile_1,'String','"')
+ end
+ if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
+ RootFile_1(1)=[];
+ end
+ filebase_1=fullfile(RootPath_1,RootFile_1);
+ SubDir_1=get(handles.SubDir,'String');
+ if isempty(SubDir_1)|isequal(SubDir_1,'')
+ if isfield(UvData,'SubDir_1')
+ SubDir_1=UvData.SubDir_1;%retrieve previous subdir
+ else
+ SubDir_1='?';
+ end
+ end
+ if isequal(NomType_1,'#_ab')|isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')|isequal(NomType_1,'_i1-i2')
+ NomTypeNew=NomType_1;
+ elseif isequal(NomType_1,'#a')
+ [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),str2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
+ NomTypeNew='#_ab';
+ elseif isequal(NomType_1,'_i_j')
+ [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),str2num(str_a),'.nc','_i1-i2_j',0,str2num(str1),[],SubDir_1);
+ if idetect==1
+ NomTypeNew='_i1-i2_j';
+ else
+ NomTypeNew='_i_j1-j2';
+ end
+ else %for instance avi files or any ima_num series
+ [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),str2num(str_a),'.nc','_i1-i2',0,str2num(str1),[],SubDir_1);
+ NomTypeNew='_i1-i2';
+ end
+ [Path,Name]=fileparts(filebase_1);
+ set(handles.FileExt_1,'String','.nc');
+ if ~isempty(SubDir_1) & ~isequal(SubDir_1,'''')& ~isequal(SubDir_1,'"')
+ SubDir_1=['/' SubDir_1];
+ end
+ set(handles.SubDir_1,'String',SubDir_1);
+ end
+ if isequal(field,'vort') | isequal(field,'div') | isequal(field,'strain')
+ set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
+ set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
+ set(handles.interp1_1,'BackgroundColor',[0.702 0.702 0.702])
+ set(handles.interp2_1,'BackgroundColor',[0.702 0.702 0.702])
+ elseif isequal(field_1,'more...'); %add new item to the menu
+ set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
+ set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
+ str=calc_field;%get the list of available scalars by the function calc_scal
+ [ind_answer,v] = listdlg('PromptString','Select a file:',...
+ 'SelectionMode','single',...
+ 'ListString',str);
+ % edit the choice in the field and action menu
+ scalar=cell2mat(str(ind_answer));
+ menu=update_menu(handles.Fields_1,scalar);
+ set(handles.Fields_1,'String',menu);% store the selected scalar type
+ end
+end
+str1=get(handles.i1,'String');
+str2=get(handles.i2,'String');
+str_a=get(handles.j1,'String');
+str_b=get(handles.j2,'String');
+indices=name_generator('',str2num(str1),stra2num(str_a),'',NomTypeNew,1,str2num(str2),stra2num(str_b),'');
+set(handles.FileIndex_1,'String',indices)
+set(handles.FileIndex_1,'UserData',NomTypeNew)
+
+%common to Fields_Callback
+if isequal(field,'image')|isequal(field_1,'image')
+ set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
+ set(handles.npy_title,'Visible','on')
+ set(handles.npx,'Visible','on')
+ set(handles.npy,'Visible','on')
+ set(handles.fix_pair,'Value',0)
+else
+ set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
+ set(handles.npy_title,'Visible','off')
+ set(handles.npx,'Visible','off')
+ set(handles.npy,'Visible','off')
+ set(handles.fix_pair,'Value',1)
+end
+if isequal(field,'velocity')|isequal(field_1,'velocity');
+ state_vect='on';
+else
+ state_vect='off';
+end
+if ~isequal(field,'velocity')|(~isequal(field_1,'velocity')&~isequal(field_1,''));
+ state_scal='on';
+else
+ state_scal='off';
+end
+set(huvmat,'UserData',UvData)
+setfield(handles);% update the field structure ('civ1'....)
+if ~isfield(UvData,'NewSeries')|isequal(UvData.NewSeries,0)
+ run0_Callback(hObject, eventdata, handles)
+end
+
+
+%-----------------------------------
+%set the visibility of relevant velocity type menus:
+%-----------------------------------
+%Civ=0; all states 'off'
+%Civ=6; all states 'on'
+function set_veltype_display(handles,Civ)
+if isequal(Civ,0)
+ imax=0;
+% set(handles(1),'Visible','on') % unvisible civ buttons
+% else
+% set(handles(1),'String','civ1')
+% end
+elseif isequal(Civ,1)
+ imax=1;
+elseif isequal(Civ,2) | isequal(Civ,3)
+ imax=3;
+elseif isequal(Civ,4) | isequal(Civ,5)
+ imax=4;
+elseif isequal(Civ,6)
+ imax=6;
+end
+for ibutton=1:imax;
+ set(handles(ibutton),'Visible','on') % unvisible civ buttons
+end
+% for ibutton=max(imax+1,2):6;
+for ibutton=imax+1:6;
+ set(handles(ibutton),'Visible','off') % unvisible civ buttons
+ set(handles(ibutton),'Value',0)%unactivate unvisible buttons
+end
+
+%-------------------------------------------------------------------
+% --- Executes on button press in civ1.
+function civ1_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+if get(handles.civ1,'Value')==1
+ reset_vel_type([handles.interp1 handles.civ2 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ1)
+else
+ reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------------------
+% --- Executes on button press in interp1.
+function interp1_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+if get(handles.interp1,'Value')==1
+ reset_vel_type([handles.civ1 handles.civ2 handles.filter1 handles.interp2 handles.filter2],handles.interp1)
+else
+ reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------------------
+% --- Executes on button press in filter1.
+function filter1_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+if get(handles.filter1,'Value')==1
+ reset_vel_type([handles.civ1 handles.civ2 handles.interp1 handles.interp2 handles.filter2],handles.filter1)
+else
+ reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%-------------------------------------------------------------------
+% --- Executes on button press in civ2.
+function civ2_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+if get(handles.civ2,'Value')==1
+ reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ2)
+else
+ reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%-----------------------------------------
+% --- Executes on button press in interp2.
+%-------------------------------------------
+function interp2_Callback(hObject, eventdata, handles)
+if get(handles.interp2,'Value')==1
+ reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.filter2],handles.interp2)
+else
+ reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
+end
+run0_Callback(hObject, eventdata, handles)
+%---------------------------------------------
+% --- Executes on button press in filter2.
+%-------------------------------------------
+function filter2_Callback(hObject, eventdata, handles)
+if get(handles.filter2,'Value')==1
+ reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2],handles.filter2)
+else
+ reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%---------------------------------------------
+function civ1_1_Callback(hObject, eventdata, handles)
+%---------------------------------------------
+if get(handles.civ1_1,'Value')==1
+ reset_vel_type([handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.civ1_1)
+else
+ reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------
+function interp1_1_Callback(hObject, eventdata, handles)
+%--------------------------------------------
+if get(handles.interp1_1,'Value')==1
+ reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.interp1_1)
+else
+ reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------
+function filter1_1_Callback(hObject, eventdata, handles)
+%--------------------------------------------
+if get(handles.filter1_1,'Value')==1
+ reset_vel_type([handles.interp1_1 handles.civ2_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.filter1_1)
+else
+ reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------
+function civ2_1_Callback(hObject, eventdata, handles)
+%--------------------------------------------
+if get(handles.civ2_1,'Value')==1
+ reset_vel_type([handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.civ2_1)
+else
+ reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------
+function interp2_1_Callback(hObject, eventdata, handles)
+%--------------------------------------------
+if get(handles.interp2_1,'Value')==1
+ reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.filter2_1],handles.interp2_1)
+else
+ reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------
+function filter2_1_Callback(hObject, eventdata, handles)
+%--------------------------------------------
+if get(handles.filter2_1,'Value')==1
+ reset_vel_type([handles.civ1_1 handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1],handles.filter2_1)
+else
+ reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
+end
+run0_Callback(hObject, eventdata, handles)
+
+%-----------------------------------------------
+% --- reset civ buttons
+function reset_vel_type(handles_civ0,handle1)
+for ibutton=1:length(handles_civ0)
+ set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
+ set(handles_civ0(ibutton),'Value',0)
+end
+if exist('handle1','var')%handles of selected button
+ set(handle1,'BackgroundColor',[1 1 0])
+end
+
+%------------------------------------------------
+function create_Callback(hObject,eventdata,handles)
+%------------------------------------------------
+if ishandle(handles.UVMAT_title)
+ delete(handles.UVMAT_title)
+end
+huvmat=get(handles.create,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface (handles huvmat)
+if isequal(get(handles.create,'Value'),1)
+ set(handles.zoom,'Value',0)
+ zoom_Callback(hObject, eventdata, handles)
+ set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
+ set(handles.edit_vect,'Value',0)
+ edit_vect_Callback(hObject, eventdata, handles)
+ set(handles.edit,'Value',0)
+ set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+ list_object=get(handles.list_object,'String');
+ if ~isempty(list_object)
+ set(handles.list_object,'Value',length(list_object))
+ end
+ MouseAction='create_object';
+ hset_object=findobj(allchild(0),'Name','set_object');
+ uistack(hset_object,'top')
+else
+ set(handles.create,'BackgroundColor',[0 1 0])
+ set(handles.edit,'Value',1)
+ set(handles.edit,'BackgroundColor',[1 1 0])
+ MouseAction='none';
+end
+
+UvData.MouseAction=MouseAction;
+set(huvmat,'UserData',UvData);
+
+%------------------------------------------------
+function POINTS_Callback(hObject,eventdata,handles)
+%------------------------------------------------
+if ishandle(handles.UVMAT_title)
+ delete(handles.UVMAT_title)
+end
+huvmat=get(handles.create,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface (handles huvmat)
+if isequal(get(handles.create,'Value'),1)
+ set(handles.zoom,'Value',0)
+ zoom_Callback(hObject, eventdata, handles)
+ set(handles.edit_vect,'Value',0)
+ edit_vect_Callback(hObject, eventdata, handles)
+ set(handles.edit,'Value',0)
+ set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+ %set(handles.grid,'Value',0)
+ %set(handles.grid,'BackgroundColor',[0 1 0])
+ % initiate set_object GUI
+ data.TITLE='POINTS';
+ if isfield(UvData,'CoordType')
+ data.CoordType=UvData.CoordType;
+ end
+ if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
+ data.RangeY=UvData.Mesh;
+ elseif isfield(UvData,'AX')&isfield(UvData,'AY')& isfield(UvData,'A')%only image
+ np=size(UvData.Field.A);
+ meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
+ meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
+ data.RangeY=max(meshx,meshy);
+ data.DX=max(meshx,meshy);
+ end
+ data.Coord=[0 0 0]; %default
+ data.ParentButton=handles.create;
+ PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
+ [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
+ if isfield(UvData,'SetObjectOrigin')
+ pos_uvmat=get(huvmat,'Position');
+ pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
+ pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
+ set(hset_object,'Position',pos_set_object)
+ end
+ %set(hset_object,'Position',[pos_uvmat(1) pos_uvmat(2)-0.05*pos_uvmat(4) 0.2*pos_uvmat(3) 0.5*pos_uvmat(4)]);
+ list_object=get(handles.list_object,'String');
+ if ~isempty(list_object)
+ set(handles.list_object,'Value',length(list_object))
+ end
+ MouseAction='create_object';
+ %UvData.ZoomOn=0;
+else
+ set(handles.create,'BackgroundColor',[0 1 0])
+ set(handles.edit,'Value',1)
+ set(handles.edit,'BackgroundColor',[1 1 0])
+ MouseAction='none';
+end
+
+UvData.MouseAction=MouseAction;
+set(huvmat,'UserData',UvData);
+
+%-----------------------------------------------------------
+function LINE_Callback(hObject, eventdata, handles)
+%-------------------------------------------------
+if ishandle(handles.UVMAT_title)
+ delete(handles.UVMAT_title)
+end
+huvmat=get(handles.create,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
+% if (get(handles.LINE,'Value')==1)
+ %suppress the other options if MENULINE is chosen
+ set(handles.zoom,'Value',0)
+ zoom_Callback(hObject, eventdata, handles)
+% set(handles.create,'Value',0)
+% set(handles.create,'BackgroundColor',[0 1 0])
+% set(handles.LINE,'Value',1)
+% set(handles.LINE,'BackgroundColor',[1 1 0])
+% set(handles.PATCH,'Value',0)
+% set(handles.PATCH,'BackgroundColor',[0 1 0])
+% set(handles.PLANE,'Value',0)
+% set(handles.PLANE,'BackgroundColor',[0 1 0])%put activated buttons to yellow
+% set(handles.VOLUME,'Value',0)
+% set(handles.VOLUME,'BackgroundColor',[0 1 0])
+ %et(handles.makemask,'Value',0)
+ %makemask_Callback(hObject, eventdata, handles)
+ set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
+ set(handles.edit_vect,'Value',0)
+ edit_vect_Callback(hObject, eventdata, handles)
+ set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+ set(handles.edit,'Value',0)
+ set(handles.list_object,'Value',1);
+ edit_vect_Callback(hObject, eventdata, handles)
+ set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+ set(handles.cal,'Value',0)
+ set(handles.cal,'BackgroundColor',[0 1 0])
+ % set(handles.grid,'Value',0)
+ % set(handles.grid,'BackgroundColor',[0 1 0])
+% initiate the set_object GUI
+ data.TITLE='LINE';
+ if isfield(UvData,'CoordType')
+ data.CoordType=UvData.CoordType;
+ end
+ if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
+ data.RangeX=UvData.Mesh;
+ data.RangeY=UvData.Mesh;
+% data.YMax=UvData.Mesh;
+% data.XMax=UvData.Mesh;
+ data.DX=UvData.Mesh;
+ data.DY=UvData.Mesh;
+ elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
+ np=size(UvData.Field.A);
+ meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
+ meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
+ data.RangeY=max(meshx,meshy);
+ data.RangeX=max(meshx,meshy);
+% data.YMax=max(meshx,meshy);
+% data.XMax=max(meshx,meshy);
+ data.DX=max(meshx,meshy);
+ end
+ if isfield(data,'DX')
+ data.Coord=[[0 0 0];[data.DX 0 0]]; %default
+ else
+ data.Coord=[[0 0 0];[1 0 0]]; %default
+ end
+ data.ParentButton=handles.create;
+ PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
+ [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
+ % associate the set_edit interface handle to the plotting axes
+ pos_uvmat=get(huvmat,'Position');
+ if isfield(UvData,'SetObjectOrigin')
+ pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
+ pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
+ set(hset_object,'Position',pos_set_object)
+ end
+ list_object=get(handles.list_object,'String');
+ if ~isempty(list_object)
+ set(handles.list_object,'Value',length(list_object))
+ end
+ MouseAction='create_object';
+% else
+% set(handles.LINE,'BackgroundColor',[0 1 0])
+% MouseAction='none';
+% end
+
+UvData.MouseAction=MouseAction;
+set(huvmat,'UserData',UvData)
+
+%-----------------------------------------------------------
+function PATCH_Callback(hObject, eventdata, handles)
+%-----------------------------------------------------------
+if ishandle(handles.UVMAT_title)
+ delete(handles.UVMAT_title)
+end
+huvmat=get(handles.create,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
+% if isequal(get(handles.PATCH,'Value'),1)
+ set(handles.zoom,'Value',0)
+ set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
+% set(handles.create,'Value',0)%suppress the other options if LINE is chosen
+% set(handles.create,'BackgroundColor',[0 1 0])
+% set(handles.LINE,'Value',0)
+% set(handles.LINE,'BackgroundColor',[0 1 0])
+% set(handles.PATCH,'Value',1)
+% set(handles.PATCH,'BackgroundColor',[1 1 0])
+% set(handles.PLANE,'Value',0)
+% set(handles.PLANE,'BackgroundColor',[0 1 0])%put activated buttons to yellow
+% set(handles.VOLUME,'Value',0)
+% set(handles.VOLUME,'BackgroundColor',[0 1 0])
+ %set(handles.makemask,'Value',0)
+ %makemask_Callback(hObject, eventdata, handles)
+ set(handles.edit_vect,'Value',0)
+ edit_vect_Callback(hObject, eventdata, handles)
+ set(handles.edit,'Value',0)
+ set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+ set(handles.edit_vect,'Value',0)
+ edit_vect_Callback(hObject, eventdata, handles)
+ set(handles.cal,'Value',0)
+ set(handles.cal,'BackgroundColor',[0 1 0])
+ %set(handles.grid,'Value',0)
+ %set(handles.grid,'BackgroundColor',[0 1 0])
+ %initiate set_object GUI
+ data.TITLE='PATCH';
+ if isfield(UvData,'CoordType')
+ data.CoordType=UvData.CoordType;
+ end
+ if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
+ data.YMax=UvData.Mesh;
+ elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
+ np=size(UvData.Field.A);
+ meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
+ meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
+ data.YMax=max(meshx,meshy);
+ data.DX=max(meshx,meshy);
+ end
+ data.Coord=[0 0 0]; %default
+ data.ParentButton=handles.create;
+ PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
+ [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
+ pos_uvmat=get(huvmat,'Position');
+ if isfield(UvData,'SetObjectOrigin')
+ pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
+ pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
+ set(hset_object,'Position',pos_set_object)
+ end
+ list_object=get(handles.list_object,'String');
+ if ~isempty(list_object)
+ set(handles.list_object,'Value',length(list_object))
+ end
+ UvData.MouseAction='create_object';
+ set(huvmat,'UserData',UvData);
+%-------------------------------------------------------
+function PLANE_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+if ishandle(handles.UVMAT_title)
+ delete(handles.UVMAT_title)
+end
+huvmat=get(handles.create,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
+set(handles.zoom,'Value',0)
+set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
+set(handles.edit_vect,'Value',0)
+edit_vect_Callback(hObject, eventdata, handles)
+set(handles.edit,'Value',0)
+set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+set(handles.cal,'Value',0)
+set(handles.cal,'BackgroundColor',[0 1 0])
+%set(handles.grid,'Value',0)
+%set(handles.grid,'BackgroundColor',[0 1 0])
+%initiate set_object GUI
+data.TITLE='PLANE';
+if isfield(UvData,'CoordType')
+ data.CoordType=UvData.CoordType;
+end
+%Si 3D data.nbdim=3;
+%Si 2D
+if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
+ data.ZMax=UvData.Mesh;
+ data.DX=UvData.Mesh;
+ data.DY=UvData.Mesh;
+elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
+ np=size(UvData.Field.A);
+ meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
+ meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
+ data.DX=max(meshx,meshy);
+end
+if isfield(UvData,'DX')
+ data.DX=UvData.DX;
+end
+if isfield(UvData,'DY')
+ data.DY=UvData.DY;
+elseif isfield(UvData,'Mesh')
+ data.DY=UvData.Mesh;
+end
+if isfield(UvData.Field,'X')& isfield(UvData.Field,'Y')
+ data.Coord=[0 0 0];
+ data.Style='plane';
+ data.Phi=0;
+ data.IndexObj=1; %act on the first reference plane by default
+ haxes= handles.axes3;%GENERALISER
+ plot_object(data,[],haxes,'m'); %plot the axes of the default plane
+end
+data.ParentButton=handles.create;
+PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
+ZBounds=0; % default
+if isfield(UvData,'ZMin') && isfield(UvData,'ZMax')
+ ZBounds(1)=UvData.ZMin; %minimum for the Z slider
+ ZBounds(2)=UvData.ZMax;%maximum for the Z slider
+end
+[hset_object,UvData.sethandles]=set_object(data,PlotHandles,ZBounds);% call the set_object interface with action on haxes,
+if isfield(UvData,'SetObjectOrigin')
+pos_uvmat=get(huvmat,'Position');
+pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
+pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
+set(hset_object,'Position',pos_set_object)
+end
+list_object=get(handles.list_object,'String');
+nbobject=length(list_object);
+set(handles.list_object,'Value',nbobject)
+UvData.MouseAction='create_object';
+set(huvmat,'UserData',UvData)
+
+%-------------------------------------------------------
+% --- Executes on button press in MENUVOLUME.
+%-------------------------------------------------------
+function VOLUME_Callback(hObject, eventdata, handles)
+%errordlg('command VOL not implemented yet')
+if ishandle(handles.UVMAT_title)
+ delete(handles.UVMAT_title)
+end
+huvmat=get(handles.create,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
+if isequal(get(handles.VOLUME,'Value'),1)
+ set(handles.zoom,'Value',0)
+ set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
+ set(handles.edit_vect,'Value',0)
+ edit_vect_Callback(hObject, eventdata, handles)
+ set(handles.edit,'Value',0)
+ set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+ set(handles.cal,'Value',0)
+ set(handles.cal,'BackgroundColor',[0 1 0])
+ set(handles.edit_vect,'Value',0)
+ edit_vect_Callback(hObject, eventdata, handles)
+ %initiate set_object GUI
+ data.TITLE='VOLUME';
+ if isfield(UvData,'CoordType')
+ data.CoordType=UvData.CoordType;
+ end
+ if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
+ data.RangeY=UvData.Mesh;
+ data.RangeX=UvData.Mesh;
+ data.DX=UvData.Mesh;
+ data.DY=UvData.Mesh;
+ elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
+ np=size(UvData.Field.A);
+ meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
+ meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
+ data.RangeY=max(meshx,meshy);
+ data.RangeX=max(meshx,meshy);
+ data.DX=max(meshx,meshy);
+ end
+ data.ParentButton=handles.VOLUME;
+ PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
+ [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
+ % associate the set_edit interface handle to the plotting axes
+ if isfield(UvData,'SetObjectOrigin')
+ pos_uvmat=get(huvmat,'Position');
+ pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
+ pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
+ set(hset_object,'Position',pos_set_object)
+ end
+ UvData.MouseAction='create_object';
+else
+ set(handles.VOLUME,'BackgroundColor',[0 1 0])
+ UvData.MouseAction='none';
+end
+set(huvmat,'UserData',UvData)
+
+%-------------------------------------------------------
+function edit_vect_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+huvmat=get(handles.edit_vect,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
+if isequal(get(handles.edit_vect,'Value'),1)
+ set(handles.record,'Visible','on')
+ set(handles.edit_vect,'BackgroundColor',[1 1 0])
+ set(handles.edit,'Value',0)
+ set(handles.create,'Value',0)
+ set(handles.create,'BackgroundColor',[0 1 0])
+ set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+ set(gcf,'Pointer','arrow')
+ UvData.MouseAction='edit_vect';
+else
+ set(handles.record,'Visible','off')
+ set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
+ UvData.MouseAction='none';
+end
+set(huvmat,'UserData',UvData)
+
+%----------------------------------------------
+function save_mask_Callback(hObject, eventdata, handles)
+%-----------------------------------------------------------------------
+huvmat=get(handles.save_mask,'parent');
+UvData=get(huvmat,'UserData');
+
+hpatch=findobj(huvmat,'Type','patch');
+flag=1;
+npx=size(UvData.Field.A,2);
+npy=size(UvData.Field.A,1);
+xi=[0.5:npx-0.5];
+yi=[0.5:npy-0.5];
+[Xi,Yi]=meshgrid(xi,yi);
+if isfield(UvData,'Object')
+ for iobj=1:length(UvData.Object)
+ ObjectData=UvData.Object{iobj};
+ if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
+ flagobj=1;
+ testphys=0; %coordinates in pixels by default
+ if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
+ if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
+ Calib=UvData.XmlData.GeometryCalib;
+ testphys=1;
+ end
+ end
+ if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
+ if isequal(ObjectData.Style,'polygon')
+ X=ObjectData.Coord(:,1);
+ Y=ObjectData.Coord(:,2);
+ if testphys
+ [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
+ end
+ flagobj=~inpolygon(Xi,Yi,X,Y);%=0 inside the polygon, 1 outside
+ elseif isequal(ObjectData.Style,'ellipse')
+ if testphys
+ %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
+ end
+ RangeX=max(ObjectData.RangeX);
+ RangeY=max(ObjectData.RangeY);
+ X2Max=RangeX*RangeX;
+ Y2Max=RangeY*RangeY;
+ distX=(Xi-ObjectData.Coord(1,1));
+ distY=(Yi-ObjectData.Coord(1,2));
+ flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
+ elseif isequal(ObjectData.Style,'rectangle')
+ if testphys
+ %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
+ end
+ distX=abs(Xi-ObjectData.Coord(1,1));
+ distY=abs(Yi-ObjectData.Coord(1,2));
+ flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
+ end
+ if isequal(ObjectData.ProjMode,'mask_outside')
+ flagobj=~flagobj;
+ end
+ flag=flag & flagobj;
+ end
+ end
+ end
+end
+% flag=~flag;
+%mask name
+RootPath=get(handles.RootPath,'String');
+RootFile=get(handles.RootFile,'String');
+if ~isempty(RootFile)&(isequal(RootFile(1),'/')| isequal(RootFile(1),'\'))
+ RootFile(1)=[];
+end
+filebase=fullfile(RootPath,RootFile);
+list=get(handles.masklevel,'String');
+masknumber=num2str(length(list));
+maskindex=get(handles.masklevel,'Value');
+mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
+imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20 col)%move also the first slider at the same value if needed
+ set(handles.slider1,'Value',col)
+ set(handles.colcode1,'String',num2str(col))
+end
+colcode2_Callback(hObject, eventdata, handles)
+
+%----------------------------------------------------------------
+%execute on return carriage on the edit box corresponding to slider 1
+%----------------------------------------------------------------
+function colcode1_Callback(hObject, eventdata, handles)
+% col=str2num(get(handles.colcode1,'String'));
+% set(handles.slider1,'Value',col)
+set_vec_col_bar(handles)
+update_plot(handles)
+
+%----------------------------------------------------------------
+%execute on return carriage on the edit box corresponding to slider 2
+%----------------------------------------------------------------
+function colcode2_Callback(hObject, eventdata, handles)
+% col=str2num(get(handles.colcode2,'String'));
+% set(handles.slider2,'Value',col)
+% slider2_Callback(hObject, eventdata, handles)
+set_vec_col_bar(handles)
+update_plot(handles)
+%------------------------------------------------------------
+%update the slider values after displaying vectors
+%--------------------------------------------------------
+% function slider_update(handles,auto,minC,colcode1,colcode2,maxC)
+% set(handles.slider1,'Min',minC)
+% set(handles.slider1,'Max',maxC)
+% set(handles.slider2,'Min',minC)
+% set(handles.slider2,'Max',maxC)
+% set(handles.min_title_vec,'String',num2str(minC))
+% set(handles.max_vec,'String',num2str(maxC))
+% if auto
+% set(handles.colcode1,'String',num2str(colcode1,3))%update display
+% set(handles.colcode2,'String',num2str(colcode2,3))
+% end
+% set(handles.slider1,'Value',colcode1)%update slider with constant display
+% set(handles.slider2,'Value',colcode2)
+% set_vec_col_bar(handles)
+
+
+%-------------------------------------------------------
+% --- Executes on button press in AutoVecColor.
+%-------------------------------------------------------
+function vec_col_bar_Callback(hObject, eventdata, handles)
+set_vec_col_bar(handles)
+
+% %--------------------------------------------
+% %update the display of color code for vectors
+% %--------------------------------------------
+% function set_vec_col_bar(handles)
+% %get the image of the color display button 'vec_col_bar' in pixels
+% uni=get(handles.vec_col_bar,'Unit');
+% set(handles.vec_col_bar,'Unit','pixel')
+% pos_vert=get(handles.vec_col_bar,'Position');
+% set(handles.vec_col_bar,'Unit','Normalized')
+% width=ceil(pos_vert(3));
+% height=ceil(pos_vert(4));
+% %get slider indications
+% colcode.min=get(handles.slider1,'Min');
+% colcode.max=get(handles.slider1,'Max');
+% colcode.colcode1=get(handles.slider1,'Value');
+% colcode.colcode2=get(handles.slider2,'Value');
+% colcode.option=get(handles.vec_col_bar,'Value');
+% colcode.auto=1;
+% list_code=get(handles.col_vec,'String');% list menu fields
+% index_code=get(handles.col_vec,'Value');% selected string index
+% colcode.CName= list_code{index_code(1)}; % selected field used for vector color
+% vec_C=colcode.min+(colcode.max-colcode.min)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
+% [colorlist,col_vec]=set_col_vec(colcode,vec_C);
+% oneheight=ones(1,height);
+% A1=colorlist(col_vec,1)*oneheight;
+% A2=colorlist(col_vec,2)*oneheight;
+% A3=colorlist(col_vec,3)*oneheight;
+% A(:,:,1)=A1';
+% A(:,:,2)=A2';
+% A(:,:,3)=A3';
+% set(handles.vec_col_bar,'Cdata',A)
+
+%--------------------------------------------------------
+% --- Executes on button press in cal.
+function cal_Callback(hObject, eventdata, handles)
+
+huvmat=get(handles.cal,'parent');%handles of the uvmat interface
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
+%reinitialize the edit interface associated with uvmat
+value=get(handles.cal,'Value');
+if value
+ set(handles.cal,'BackgroundColor',[1 1 0])
+ %suppress the other options if MENULINE is chosen
+ set(handles.zoom,'Value',0)
+ set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
+ set(handles.create,'Value',0)
+ set(handles.create,'BackgroundColor',[0 1 0])
+ set(handles.create,'enable','off')
+ set(handles.edit_vect,'Value',0)
+ set(handles.edit_vect,'enable','off')
+ edit_vect_Callback(hObject, eventdata, handles)
+ set(handles.edit,'Value',0)
+ set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+ set(handles.edit,'enable','off')
+ set(handles.list_object,'Value',1)
+ % initiate display of GUI geometry_calib
+ data=[]; %default
+ if isfield(UvData,'CoordType')
+ data.CoordType=UvData.CoordType;
+ end
+ %data.ParentButton=handles.cal; % transmit the handles of the calling button to the GUI geometry_calib
+ pos=get(huvmat,'Position');
+ pos(1)=pos(1)+pos(3)-0.311+0.04; %0.311= width of the geometry_calib interface (units relative to the srcreen)
+ pos(2)=pos(2)-0.02;
+ [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
+% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
+% [inputfile,idetect]=name_generator(filebase,num_i1,num_j1,Ext,NomType,1,num_i2,num_j2,SubDir);
+ [UvData.hset_object,UvData.sethandles]=geometry_calib(handles,pos,FileName);% call the set_object interface
+ pos_uvmat=get(huvmat,'Position');
+ %pos_cal(1:2)=UvData.CalOrigin + pos_uvmat(1:2);
+ if isfield(UvData,'CalOrigin')
+ pos_cal(1)=pos_uvmat(1)+UvData.CalOrigin(1)*pos_uvmat(3);
+ pos_cal(2)=pos_uvmat(2)+UvData.CalOrigin(2)*pos_uvmat(4);
+ pos_cal(3:4)=UvData.CalSize .* pos_uvmat(3:4);
+ set(UvData.hset_object,'Position',pos_cal)
+ end
+ UvData.MouseAction='calib';
+else
+ UvData.MouseAction='none';
+ hgeometry_calib=findobj(allchild(0),'Name','geometry_calib');
+% if ~isempty(hgeometry_calib)
+% answer=questdlg('close the GUI geometry-calib?');
+% if isequal(answer,'Yes')
+% delete(hgeometry_calib)
+% set(handles.cal,'BackgroundColor',[0 1 0])
+% else
+% set(handles.cal,'Value',1)% keep the calibration function active
+% end
+% end
+ set(handles.edit_vect,'enable','on')
+ set(handles.edit,'enable','on')
+ set(handles.create,'enable','on')
+% set(handles.LINE,'enable','on')
+% set(handles.PATCH,'enable','on')
+% set(handles.PLANE,'enable','on')
+% set(handles.VOLUME,'enable','on')
+ %set(handles.makemask,'enable','on')
+ hh=findobj(handles.axes3,'Tag','calib_points');
+ if ~isempty(hh)
+ delete(hh)
+ end
+ hhh=findobj(handles.axes3,'Tag','calib_marker');
+ if ~isempty(hhh)
+ delete(hhh)
+ end
+end
+set(huvmat,'UserData',UvData);
+
+%-------------------------------------------------------------
+% --- Executes on selection change in menu_coord.
+function menu_coord_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------
+huvmat=get(handles.menu_coord,'parent');
+menu=get(handles.menu_coord,'String');
+ind_coord=get(handles.menu_coord,'Value');
+coord_option=menu{ind_coord};
+list_path=get(handles.menu_coord,'UserData');
+
+if isequal(coord_option,'more...');
+ coord_fct='';
+ dir_perso=prefdir;
+ profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+ if exist(profil_perso,'file')
+ h=load (profil_perso);
+ if isfield(h,'coord_fct')
+ coord_fct=h.coord_fct;
+ end
+ end
+ prompt = {'Enter the name of the transform function'};
+ dlg_title = 'user defined transform';
+ num_lines= 1;
+ [FileName, PathName, filterindex] = uigetfile( ...
+ {'*.m', ' (*.m)';
+ '*.m', '.m files '; ...
+ '*.*', 'All Files (*.*)'}, ...
+ 'Pick a file', coord_fct);
+ if isequal(PathName(end),'/')||isequal(PathName(end),'\')
+ PathName(end)=[];
+ end
+ coord_fct=fullfile(PathName,FileName);
+ if ~exist(coord_fct,'file')
+ msgbox_uvmat('ERROR',['image procesing fct ' coord_fct ' not found'])
+ else
+ transform=FileName(1:end-2);%
+ menu=update_menu(handles.menu_coord,transform);%add the selected fct to the menu
+ ind_coord=get(handles.menu_coord,'Value');
+ list_path{ind_coord}=PathName;
+ set(handles.menu_coord,'UserData',list_path)
+ if exist(profil_perso,'file')
+ save (profil_perso,'coord_fct','-append'); %store the root name for future opening of uvmat
+ end
+ end
+end
+
+%check the current path to the selected function
+PathName=list_path{ind_coord};
+CurrentPath=fileparts(which(coord_option));
+if ~isequal(PathName,CurrentPath)
+ addpath(PathName)
+ errormsg=check_functions;
+ msgbox_uvmat('WARNING',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
+end
+set(handles.path_transform,'String',fullfile(PathName,' ')); %show the path to the senlected function
+set(handles.FixedLimits,'Value',0)
+set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
+
+UvData=get(huvmat,'UserData');
+
+%delete drawn objects
+hother=findobj('Tag','proj_object');%find all the proj objects
+for iobj=1:length(hother)
+ delete_object(hother(iobj))
+end
+hother=findobj('Tag','DeformPoint');%find all the proj objects
+for iobj=1:length(hother)
+ delete_object(hother(iobj))
+end
+hh=findobj('Tag','calib_points');
+if ~isempty(hh)
+ delete(hh)
+end
+hhh=findobj('Tag','calib_marker');
+if ~isempty(hhh)
+ delete(hhh)
+end
+if isfield(UvData,'Object')
+ nbobject=length(UvData.Object);
+ UvData.Object([2:nbobject])=[];
+end
+
+%delete mask if it is displayed
+if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
+ UvData=rmfield(UvData,'MaskName'); %will impose mask refresh
+end
+set(huvmat,'UserData',UvData)
+run0_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------
+function histo1_menu_Callback(hObject, eventdata, handles)
+%--------------------------------------------
+%plot first histo
+huvmat=get(handles.histo1_menu,'parent');
+histo_menu=get(handles.histo1_menu,'String');
+histo_value=get(handles.histo1_menu,'Value');
+FieldName=histo_menu{histo_value};
+UvData=get(huvmat,'UserData');
+update_histo(handles.histo_u,huvmat,FieldName)
+
+%----------------------------------------------
+function histo2_menu_Callback(hObject, eventdata, handles)
+%----------------------------------------------
+%plot second histo
+huvmat=get(handles.histo2_menu,'parent');
+histo_menu=get(handles.histo2_menu,'String');
+histo_value=get(handles.histo2_menu,'Value');
+FieldName=histo_menu{histo_value};
+UvData=get(huvmat,'UserData');
+update_histo(handles.histo_v,huvmat,FieldName)
+
+
+%--------------------------------------------
+%read the field .Fieldname stored in UvData and plot its histogram
+function update_histo(haxes,huvmat,FieldName)
+UvData=get(huvmat,'UserData');
+
+if ~isfield(UvData.Field,FieldName)
+ msgbox_uvmat('ERROR',['no field ' FieldName ' for histogram'])
+ return
+end
+Field=UvData.Field;
+FieldHisto=eval(['Field.' FieldName]);
+if isfield(Field,'FF') & ~isempty(Field.FF) & isequal(size(Field.FF),size(FieldHisto))
+ indsel=find(Field.FF==0);%find values marked as false
+ if ~isempty(indsel)
+ FieldHisto=FieldHisto(indsel);
+ end
+end
+if isempty(Field)
+ msgbox_uvmat('ERROR',['empty field ' FieldName])
+else
+ nxy=size(FieldHisto);
+ Amin=double(min(min(min(FieldHisto))));%min of image
+ Amax=double(max(max(max(FieldHisto))));%max of image
+ if isequal(Amin,Amax)
+ Histo.Txt=['uniform field =' num2str(Amin)];
+ else
+ Histo.ListVarName={FieldName,'histo'};
+ if numel(nxy)==2
+ Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
+ else %color images
+ Histo.VarDimName={FieldName,{FieldName,'rgb'}}; %dimensions for the histogram
+ end
+ %unit
+ units=[]; %default
+ for ivar=1:numel(Field.ListVarName)
+ if strcmp(Field.ListVarName{ivar},FieldName)
+ if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
+ units=Field.VarAttribute{ivar}.units;
+ break
+ end
+ end
+ end
+ if ~isempty(units)
+ Histo.VarAttribute{1}.units=units;
+ end
+ eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
+ for col=1:size(FieldHisto,3)
+ B=FieldHisto(:,:,col);
+ C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
+ eval(['Histo.histo(:,col)=hist(C, Histo.' FieldName ');']); %calculate histogram
+ end
+ set(haxes,'XLimMode','auto')%reset auto mode (after zoom effect)
+ set(haxes,'YLimMode','auto')
+ plot_field(Histo,haxes);
+ end
+end
+
+
+
+%------------------------------------------------
+%CALLBACKS FOR PLOTTING PARAMETERS
+%-------------------------------------------------
+
+%-----------------------------------------------------------------
+function MinA_Callback(hObject, eventdata, handles)
+%------------------------------------------
+set(handles.AutoScal,'Value',1) %suppress auto mode
+set(handles.AutoScal,'BackgroundColor',[1 1 0])
+update_plot(handles)
+
+%-----------------------------------------------------------------
+function MaxA_Callback(hObject, eventdata, handles)
+%--------------------------------------------
+set(handles.AutoScal,'Value',1) %suppress auto mode
+set(handles.AutoScal,'BackgroundColor',[1 1 0])
+update_plot(handles)
+
+%-----------------------------------------------
+function AutoScal_Callback(hObject, eventdata, handles)
+%--------------------------------------------
+test=get(handles.AutoScal,'Value');
+if test
+ set(handles.AutoScal,'BackgroundColor',[1 1 0])
+else
+ set(handles.AutoScal,'BackgroundColor',[0.7 0.7 0.7])
+ update_plot(handles);
+% set(handles.MinA,'String',num2str(ScalOut.MinA,3))
+% set(handles.MaxA,'String',num2str(ScalOut.MaxA,3))
+end
+
+%-------------------------------------------------------------------
+function BW_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+update_plot(handles)
+
+%-------------------------------------------------------------------
+function Contours_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+val=get(handles.Contours,'Value');
+if val==2
+ set(handles.interval_txt,'Visible','on')
+ set(handles.IncrA,'Visible','on')
+else
+ set(handles.interval_txt,'Visible','off')
+ set(handles.IncrA,'Visible','off')
+end
+update_plot(handles)
+
+%-------------------------------------------------------------------
+function IncrA_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+update_plot(handles)
+
+%-------------------------------------------------------------------
+function HideWarning_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+update_plot(handles)
+
+%-------------------------------------------------------------------
+function HideFalse_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+update_plot(handles)
+
+%-------------------------------------------------------------------
+function VecScale_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+set(handles.AutoVec,'Value',1);
+set(handles.AutoVec,'BackgroundColor',[1 1 0])
+update_plot(handles)
+
+%-------------------------------------------------------------------
+function AutoVec_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+test=get(handles.AutoVec,'Value');
+if test
+ set(handles.AutoVec,'BackgroundColor',[1 1 0])
+else
+ update_plot(handles);
+ %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
+ set(handles.AutoVec,'BackgroundColor',[0.7 0.7 0.7])
+end
+
+%-------------------------------------------------------
+% --- Executes on selection change in decimate4 (nb_vec/4).
+%-------------------------------------------------------
+function decimate4_Callback(hObject, eventdata, handles)
+update_plot(handles)
+
+
+%-------------------------------------------------------
+% --- Executes on selection change in color_code menu
+%-------------------------------------------------------
+function color_code_Callback(hObject, eventdata, handles)
+set_vec_col_bar(handles)
+update_plot(handles);
+
+%-------------------------------------------------------
+% --- Executes on button press in AutoVecColor.
+%-------------------------------------------------------
+function AutoVecColor_Callback(hObject, eventdata, handles)
+test=get(handles.AutoVecColor,'Value');
+if test
+ set(handles.AutoVecColor,'BackgroundColor',[1 1 0])
+else
+ update_plot(handles);
+ %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
+ set(handles.AutoVecColor,'BackgroundColor',[0.7 0.7 0.7])
+end
+%set_vec_col_bar(handles)
+
+%-------------------------------------------------------
+% --- Executes on selection change in max_vec.
+%-------------------------------------------------------
+function min_vec_Callback(hObject, eventdata, handles)
+max_vec_Callback(hObject, eventdata, handles)
+
+% --- Executes on selection change in max_vec.
+function max_vec_Callback(hObject, eventdata, handles)
+set(handles.AutoVecColor,'Value',1)
+AutoVecColor_Callback(hObject, eventdata, handles)
+min_val=str2num(get(handles.min_vec,'String'));
+max_val=str2num(get(handles.max_vec,'String'));
+slider1=get(handles.slider1,'Value');
+slider2=get(handles.slider2,'Value');
+colcode1=min_val+(max_val-min_val)*slider1;
+colcode2=min_val+(max_val-min_val)*slider2;
+set(handles.colcode1,'String',num2str(colcode1))
+set(handles.colcode2,'String',num2str(colcode2))
+update_plot(handles);
+
+%-------------------------------------------------------------------
+%update the display of color code for vectors
+function set_vec_col_bar(handles)
+%-------------------------------------------------------------------
+%get the image of the color display button 'vec_col_bar' in pixels
+set(handles.vec_col_bar,'Unit','pixel');
+pos_vert=get(handles.vec_col_bar,'Position');
+set(handles.vec_col_bar,'Unit','Normalized');
+width=ceil(pos_vert(3));
+height=ceil(pos_vert(4));
+
+%get slider indications
+list=get(handles.color_code,'String');
+ichoice=get(handles.color_code,'Value');
+colcode.ColorCode=list{ichoice};
+colcode.MinC=str2num(get(handles.min_vec,'String'));
+colcode.MaxC=str2num(get(handles.max_vec,'String'));
+test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
+if test3color
+% set(handles.colcode1,'Visible','on')
+% set(handles.colcode2,'Visible','on')
+% set(handles.slider1,'Visible','on')
+% set(handles.slider2,'Visible','on')
+ colcode.colcode1=str2num(get(handles.colcode1,'String'));
+ colcode.colcode2=str2num(get(handles.colcode2,'String'));
+else
+% set(handles.colcode1,'Visible','off')
+% set(handles.colcode2,'Visible','off')
+% set(handles.slider1,'Visible','off')
+% set(handles.slider2,'Visible','off')
+% colcode.colcode1=colcode.min;
+% colcode.colcode2=colcode.max;
+end
+% colcode.option=get(handles.vec_col_bar,'Value');
+colcode.FixedCbounds=0;
+% list_code=get(handles.col_vec,'String');% list menu fields
+% index_code=get(handles.col_vec,'Value');% selected string index
+% colcode.CName= list_code{index_code(1)}; % selected field used for vector color
+colcode.FixedCbounds=1;
+vec_C=colcode.MinC+(colcode.MaxC-colcode.MinC)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
+[colorlist,col_vec]=set_col_vec(colcode,vec_C);
+oneheight=ones(1,height);
+A1=colorlist(col_vec,1)*oneheight;
+A2=colorlist(col_vec,2)*oneheight;
+A3=colorlist(col_vec,3)*oneheight;
+A(:,:,1)=A1';
+A(:,:,2)=A2';
+A(:,:,3)=A3';
+set(handles.vec_col_bar,'Cdata',A)
+
+
+%-------------------------------------------------------------------
+function [PlotType,ScalOut]=update_plot(handles)
+%-------------------------------------------------------------------
+haxes= handles.axes3;
+AxeData=get(haxes,'UserData');
+PlotParam=read_plot_param(handles);
+[PlotType,PlotParamOut]= plot_field(AxeData,haxes,PlotParam,1);
+write_plot_param(handles,PlotParamOut); %update the auto plot parameters
+
+%-------------------------------------------------------------------
+% --- Executes on button press in grid.
+function grid_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+huvmat=get(handles.create,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
+
+%suppress the other options if grid is chosen
+set(handles.create,'Value',0)
+set(handles.create,'BackgroundColor',[0 1 0])
+set(handles.edit_vect,'Value',0)
+edit_vect_Callback(hObject, eventdata, handles)
+set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+set(handles.edit_vect,'Value',0)
+edit_vect_Callback(hObject, eventdata, handles)
+set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+set(handles.list_object,'Value',1)
+set(handles.cal,'Value',0)
+set(handles.cal,'BackgroundColor',[0 1 0])
+
+%prepare display of the set_grid GUI
+data.fixedtitle=1;
+FileName=read_file_boxes(handles);
+[hset_object,UvData.sethandles]=set_grid(FileName);% call the set_object interface
+set(huvmat,'UserData',UvData);
+
+
+%-------------------------------------------------------------------
+% --- Executes on selection change in edit.
+function edit_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------------------
+huvmat=get(handles.list_object,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
+test=get(handles.edit,'Value');
+if test
+ UvData.MouseAction='edit_object';
+ set(handles.edit,'BackgroundColor',[1,1,0])
+ %suppress the other options
+ set(handles.zoom,'Value',0)
+ zoom_Callback(hObject, eventdata, handles)
+ set(handles.create,'Value',0)
+ set(handles.create,'BackgroundColor',[0 1 0])
+% set(handles.LINE,'Value',0)
+% set(handles.LINE,'BackgroundColor',[0 1 0])
+% set(handles.PATCH,'Value',0)
+% set(handles.PATCH,'BackgroundColor',[0 1 0])
+% set(handles.PLANE,'Value',0)
+% set(handles.PLANE,'BackgroundColor',[0 1 0])%put activated buttons to yellow
+% set(handles.VOLUME,'Value',0)
+% set(handles.VOLUME,'BackgroundColor',[0 1 0])
+ set(handles.edit_vect,'Value',0)
+ edit_vect_Callback(hObject, eventdata, handles)
+ set(handles.cal,'Value',0)
+ set(handles.cal,'BackgroundColor',[0 1 0])
+ %set(handles.grid,'Value',0)
+ %set(handles.grid,'BackgroundColor',[0 1 0])
+ list_object_Callback(hObject, eventdata, handles)
+else
+ UvData.MouseAction='none';
+ set(handles.edit,'BackgroundColor',[0.7,0.7,0.7])
+end
+set(huvmat,'UserData',UvData);
+
+%--------------------------------------------------------
+% --- Executes on selection change in list_object.
+%--------------------------------------------------------
+function list_object_Callback(hObject, eventdata, handles)
+huvmat=get(handles.list_object,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
+list_str=get(handles.list_object,'String');
+IndexObj=get(handles.list_object,'Value');
+
+if ~(length(UvData.Object)>=IndexObj);
+ return
+end
+ObjectData=UvData.Object{IndexObj};
+ObjectData.desable_open=1; % desable the OPEN option in the set_object GUI (editing mode)
+if isequal(get(handles.edit,'Value'),0)
+ ObjectData.desable_plot=1; % desable the PLOT option in the set_object GUI (editing mode
+end
+PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
+ZBounds=0; % default
+ if isfield(UvData,'ZMin') && isfield(UvData,'ZMax')
+ ZBounds(1)=UvData.ZMin; %minimum for the Z slider
+ ZBounds(2)=UvData.ZMax;%maximum for the Z slider
+ end
+AxeData.hset_object=set_object(ObjectData,PlotHandles,ZBounds);% call the set_object interface,
+pos_uvmat=get(huvmat,'Position');
+if isfield(UvData,'SetObjectOrigin')
+pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
+pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
+set(AxeData.hset_object,'Position',pos_set_object)
+end
+hother=findobj('Tag','proj_object');%find all the proj objects
+for iobj=1:length(hother)
+ if isequal(get(hother(iobj),'Type'),'rectangle')|isequal(get(hother(iobj),'Type'),'patch')
+ set(hother(iobj),'EdgeColor','b')
+ if isequal(get(hother(iobj),'FaceColor'),'m')
+ set(hother(iobj),'FaceColor','b')
+ end
+ elseif isequal(get(hother(iobj),'Type'),'image')
+ Acolor=get(hother(iobj),'CData');
+ Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
+ set(hother(iobj),'CData',Acolor);
+ else
+ set(hother(iobj),'Color','b')
+ end
+ set(hother(iobj),'Selected','off')
+end
+hother=findobj('Tag','DeformPoint');
+set(hother,'Color','b');
+set(hother,'Selected','off')
+if isfield(ObjectData,'HandlesDisplay')
+ for iview=1:length(ObjectData.HandlesDisplay)
+ if ishandle(ObjectData.HandlesDisplay(iview))
+ uistack(ObjectData.HandlesDisplay(iview),'top')
+ linetype=get(ObjectData.HandlesDisplay(iview),'Type');
+ if isequal(linetype,'line')
+ set(ObjectData.HandlesDisplay(iview),'Color','m'); %set the selected object to magenta color
+ elseif isequal(linetype,'rectangle')
+ set(ObjectData.HandlesDisplay(iview),'EdgeColor','m'); %set the selected object to magenta color
+ elseif isequal(linetype,'patch')
+ set(ObjectData.HandlesDisplay(iview),'FaceColor','m'); %set the selected object to magenta color
+ end
+ SubObjectData=get(ObjectData.HandlesDisplay(iview),'UserData');
+ if isfield(SubObjectData,'SubObject')& ishandle(SubObjectData.SubObject)
+ uistack(SubObjectData.SubObject,'top')
+ for iobj=1:length(SubObjectData.SubObject)
+ hsub=SubObjectData.SubObject(iobj);
+ if isequal(get(hsub,'Type'),'rectangle')
+ set(hsub,'EdgeColor','m'); %set the selected object to magenta color
+ elseif isequal(get(hsub,'Type'),'image')
+ Acolor=get(hsub,'CData');
+ Acolor(:,:,1)=Acolor(:,:,3);
+ set(hsub,'CData',Acolor);
+ else
+ set(hsub,'Color','m')
+ end
+ end
+ end
+ if isfield(SubObjectData,'DeformPoint')& ishandle(SubObjectData.DeformPoint)
+ set(SubObjectData.DeformPoint,'Color','m')
+ end
+ end
+ end
+end
+
+%------------------------------------------------------
+% --- Executes on button press in Menu/Export/field in workspace.
+%------------------------------------------------------
+function MenuExportField_Callback(hObject, eventdata, handles)
+
+global CurData
+huvmat=get(handles.RootPath,'parent');
+CurData=get(huvmat,'UserData');
+evalin('base','global CurData')%make CurData global in the workspace
+display(['UserData of uvmat :'])
+evalin('base','CurData') %display CurData in the workspace
+commandwindow;
+
+%------------------------------------------------------
+% --- Executes on button press in Menu/Export/extract figure.
+%------------------------------------------------------
+function MenuExport_plot_Callback(hObject, eventdata, handles)
+huvmat=get(handles.MenuExport_plot,'parent');
+UvData=get(huvmat,'UserData');
+hfig=figure;
+newaxes=copyobj(handles.axes3,hfig);
+map=colormap(handles.axes3);
+colormap(map);%transmit the current colormap to the zoom fig
+colorbar
+
+
+% --------------------------------------------------------------------
+function Insert_Callback(hObject, eventdata, handles)
+
+
+% --------------------------------------------------------------------
+function MenuRun_Callback(hObject, eventdata, handles)
+% --------------------------------------------------------------------
+
+% --------------------------------------------------------------------
+function MenuHelp_Callback(hObject, eventdata, handles)
+% --------------------------------------------------------------------
+path_to_uvmat=which ('uvmat');% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+else
+ web(helpfile);
+end
+
+% --------------------------------------------------------------------
+function MenuOpen_Callback(hObject, eventdata, handles)
+% --------------------------------------------------------------------
+% --------------------------------------------------------------------
+function MenuOpen_1_Callback(hObject, eventdata, handles)
+% --------------------------------------------------------------------
+% --------------------------------------------------------------------
+function MenuExport_Callback(hObject, eventdata, handles)
+% --------------------------------------------------------------------
+
+% --------------------------------------------------------------------
+function MenuExportMovie_Callback(hObject, eventdata, handles)
+% --------------------------------------------------------------------
+set(handles.MenuExportMovie,'BusyAction','queue')% activate the button
+huvmat=get(handles.run0,'parent');
+UvData=get(huvmat,'UserData');
+[xx,xx,FileBase]=read_file_boxes(handles);
+ %read the current input file name
+prompt = {'movie file name';'frames per second';'frame resolution (*[512x384] pixels)';'axis position relative to the frame';'total frame number (starting from the current uvmat display)'};
+dlg_title = 'select properties of the output avi movie';
+num_lines= 1;
+nbfield_cell=get(handles.last_i,'String');
+def = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'};
+answer = inputdlg(prompt,dlg_title,num_lines,def,'on');
+aviname=answer{1};
+fps=str2num(answer{2});
+% check for existing file with output name aviname
+if exist(aviname,'file')
+ backup=aviname;
+ testexist=2;
+ while testexist==2
+ backup=[backup '~'];
+ testexist=exist(backup,'file');
+ end
+ [success,message]=copyfile(aviname,backup);%make backup of the existing file
+ if isequal(success,1)
+ delete(aviname)%delete existing file
+ else
+ msgbox_uvmat('ERROR',message)
+ return
+ end
+end
+%create avi open
+aviobj=avifile(aviname,'Compression','None','fps',fps);
+
+%display first view for tests
+newfig=figure;
+newaxes=copyobj(handles.axes3,newfig);%new plotting axes in the new figure
+set(newaxes,'Tag','movieaxes')
+nbpix=[512 384]*str2num(answer{3});
+set(gcf,'Position',[1 1 nbpix])% resolution XVGA
+set(newaxes,'Position',eval(answer{4}));
+map=colormap(handles.axes3);
+colormap(map);%transmit the current colormap to the zoom fig
+msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;...
+ ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']});
+UvData.Object{1}.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
+set(huvmat,'UserData',UvData);
+increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
+set(handles.STOP,'Visible','on')
+set(handles.speed,'Visible','on')
+set(handles.speed_txt,'Visible','on')
+set(handles.RunMovie,'BusyAction','queue')
+
+imin=str2num(get(handles.i1,'String'));
+imax=str2num(answer{5});
+% if isfield(UvData,'Time')
+htitle=get(newaxes,'Title');
+xlim=get(newaxes,'XLim');
+ylim=get(newaxes,'YLim');
+set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0])
+time_str=get(handles.abs_time,'String');
+set(htitle,'String',['t=' time_str])
+set(handles.speed,'Value',1)
+for i=1:imax
+ if get(handles.speed,'Value')~=0 & isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command
+ runpm(hObject,eventdata,handles,increment)
+ drawnow
+ time_str=get(handles.abs_time,'String');
+ if ishandle(htitle)
+ set(htitle,'String',['t=' time_str])
+ end
+ mov=getframe(newfig);
+ aviobj=addframe(aviobj,mov);
+ end
+end
+aviobj=close(aviobj);
+UvData.Object{1}.plotaxes=handles.axes3;
+set(huvmat,'UserData',UvData);
+msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']})
+
+% --------------------------------------------------------------------
+function MenuPoints_Callback(hObject, eventdata, handles)
+set(handles.create,'Visible','on')
+set(handles.create,'Value',1)
+POINTS_Callback(hObject,eventdata,handles)
+
+% --------------------------------------------------------------------
+function MenuLine_Callback(hObject, eventdata, handles)
+set(handles.create,'Visible','on')
+set(handles.create,'Value',1)
+LINE_Callback(hObject,eventdata,handles)
+
+% ------------------------------------------------------------------
+function MenuPatch_Callback(hObject, eventdata, handles)
+set(handles.create,'Visible','on')
+set(handles.create,'Value',1)
+PATCH_Callback(hObject,eventdata,handles)
+
+% ------------------------------------------------------------------
+function MenuPlane_Callback(hObject, eventdata, handles)
+set(handles.create,'Visible','on')
+set(handles.create,'Value',1)
+PLANE_Callback(hObject,eventdata,handles)
+
+% ------------------------------------------------------------------
+function MenuVolume_Callback(hObject, eventdata, handles)
+set(handles.create,'Visible','on')
+set(handles.create,'Value',1)
+VOLUME_Callback(hObject,eventdata,handles)
+
+% ------------------------------------------------------------------
+function MenuCalib_Callback(hObject, eventdata, handles)
+set(handles.TOOLS_txt,'Visible','on')
+set(handles.frame_tools,'Visible','on')
+set(handles.cal,'Visible','on')
+set(handles.cal,'Value',1)
+cal_Callback(hObject,eventdata,handles)
+
+% ------------------------------------------------------------------
+function MenuMask_Callback(hObject, eventdata, handles)
+set(handles.TOOLS_txt,'Visible','on')
+set(handles.frame_tools,'Visible','on')
+set(handles.create,'Visible','on')
+set(handles.create,'Value',1)
+set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
+set(handles.save_mask,'Visible','on')
+set(handles.masklevel,'Visible','on')
+if isequal(get(handles.z_index,'Visible'),'on')
+ nb_slice=str2num(get(handles.nb_slice,'String'));
+ for ilist=1:nb_slice
+ list_index{ilist,1}=num2str(ilist);
+ end
+ set(handles.masklevel,'String',list_index)
+ val=str2num(get(handles.z_index,'String'));
+ if val<=nb_slice
+ set(handles.masklevel,'Value',val)
+ end
+else
+ set(handles.masklevel,'String',{'1'})
+ set(handles.masklevel,'Value',1)
+end
+if ishandle(handles.UVMAT_title)
+ delete(handles.UVMAT_title)
+end
+huvmat=get(handles.create,'parent');
+UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
+set(handles.zoom,'Value',0)
+set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
+set(handles.edit_vect,'Value',0)
+edit_vect_Callback(hObject, eventdata, handles)
+set(handles.edit,'Value',0)
+set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
+set(handles.edit_vect,'Value',0)
+edit_vect_Callback(hObject, eventdata, handles)
+set(handles.cal,'Value',0)
+set(handles.cal,'BackgroundColor',[0 1 0])
+
+%initiate the GUI set_object
+data.TITLE='MASK';
+if isfield(UvData,'CoordType')
+ data.CoordType=UvData.CoordType;
+end
+if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
+ data.YMax=UvData.Mesh;
+elseif isfield(UvData.Field,'AX')&&isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')%only image
+ np=size(UvData.Field.A);
+ meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
+ meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
+ data.YMax=max(meshx,meshy);
+ data.DX=max(meshx,meshy);
+end
+data.Coord=[0 0 0]; %default
+PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
+[hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
+pos_uvmat=get(huvmat,'Position');
+if isfield(UvData,'SetObjectOrigin')
+ pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
+ pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
+ set(hset_object,'Position',pos_set_object)
+end
+list_object=get(handles.list_object,'String');
+if ~isempty(list_object)
+ set(handles.list_object,'Value',length(list_object))
+end
+UvData.MouseAction='create_object';
+set(huvmat,'UserData',UvData);
+
+% ------------------------------------------------------------------
+%-- open the GUI set_grid.fig to create grid
+function MenuGrid_Callback(hObject, eventdata, handles)
+set(handles.TOOLS_txt,'Visible','on')
+set(handles.frame_tools,'Visible','on')
+grid_Callback(hObject,eventdata,handles)
+
+%----------------------------------------------------------------
+% open the GUI 'series'
+%----------------------------------------------------------------
+function MenuSeries_Callback(hObject, eventdata, handles)
+
+[param.FileName]=read_file_boxes(handles);
+if isequal(get(handles.SubField,'Value'),1)
+ FileName_1=read_file_boxes_1(handles);%
+ if ~isequal(FileName_1,param.FileName)
+ param.FileName_1=FileName_1;
+ end
+end
+param.NomType=get(handles.FileIndex,'UserData');
+param.NomType_1=get(handles.FileIndex_1,'UserData');
+param.comp_input=get(handles.fix_pair,'Value');
+huvmat=get(handles.MenuSeries,'parent');
+UvData=get(huvmat,'UserData');
+if isfield(UvData,'Time')
+ param.Time=UvData.XmlData.Time;
+end
+if isequal(get(handles.scan_i,'Value'),1)
+ param.incr_i=str2num(get(handles.increment_scan,'String'));
+elseif isequal(get(handles.scan_j,'Value'),1)
+ param.incr_j=str2num(get(handles.increment_scan,'String'));
+end
+param.list_fields=get(handles.Fields,'String');% list menu fields
+param.list_fields(1)=[]; %suppress 'image' option
+param.index_fields=get(handles.Fields,'Value');% selected string index
+if param.index_fields>1
+ param.index_fields=param.index_fields-1;
+end
+param.list_fields_1=get(handles.Fields_1,'String');% list menu fields
+param.list_fields_1(1)=[]; %suppress 'image' option
+param.index_fields_1=get(handles.Fields_1,'Value')-1;% selected string index
+if param.index_fields_1>1
+ param.index_fields_1=param.index_fields_1-1;
+end
+param.civ1=get(handles.civ1,'Value');
+param.civ2=get(handles.civ2,'Value');
+param.interp1=get(handles.interp1,'Value');
+param.interp2=get(handles.interp2,'Value');
+param.filter1=get(handles.filter1,'Value');
+param.filter2=get(handles.filter2,'Value');
+param.menu_coord_str=get(handles.menu_coord,'String');
+param.menu_coord_val=get(handles.menu_coord,'Value');
+
+series(param); %run the series interface
+
+% ------------------------------------------------------------------
+% -- open the GUI civ.fig for civx (PIV)
+% ------------------------------------------------------------------
+function MenuPIV_Callback(hObject, eventdata, handles)
+
+[FileName,RootPath,filebase,FileIndices,ext,SubDir]=read_file_boxes(handles);
+[P,F,str1,str2,str_a,str_b]=name2display(FileName);
+num1=stra2num(str1);
+num2=stra2num(str2);
+num_a=stra2num(str_a);
+num_b=stra2num(str_b);
+NomType=get(handles.FileIndex,'UserData');
+ind_opening=1; % default (images): will advice civ1 option by default in the civ interface
+if isequal(ext,'.nc') || isequal(ext,'.cdf')% netcdf files
+ ind_opening=2;% propose 'fix' as the default option
+% +read the current netcdf rootfile
+ Data=nc2struct(FileName,[]);
+ if isfield(Data,'fix') & isequal(Data.fix,1)
+ ind_opening=3;
+ end
+ if isfield(Data,'patch') & isequal(Data.patch,1)
+ ind_opening=4;
+ end
+ if isfield(Data,'civ2') & isequal(Data.civ2,1)
+ ind_opening=5;
+ end
+ if isfield(Data,'fix2') & isequal(Data.fix2,1)
+ ind_opening=6;
+ end
+end
+varargin{1}=filebase;
+varargin{2}=NomType;
+varargin{3}=num1;
+varargin{4}=num2;
+varargin{5}=num_a;
+varargin{6}=num_b;
+varargin{7}=SubDir;
+varargin{8}=ind_opening;% A REVOIR +TRANSMETTRE IMADOC INFO
+varargin{11}=ext;
+civ(varargin);% interface de civ(not in the uvmat file)
+
+% ------------------------------------------------------------------
+function MenuTools_Callback(hObject, eventdata, handles)
+
+% ------------------------------------------------------------------
+function MenuEdit_Callback(hObject, eventdata, handles)
+
+%--------------------------------------------------------------------------
+function enable_transform(handles,state)
+set(handles.menu_coord,'Visible',state)
+set(handles.TRANSFORM_txt,'Visible',state)
+set(handles.menu_coord,'Visible',state)
+set(handles.path_transform,'Visible',state)
+set(handles.pxcmx_txt,'Visible',state)
+set(handles.pxcmy_txt,'Visible',state)
+set(handles.pxcm,'Visible',state)
+set(handles.pycm,'Visible',state)
+
+% --------------------------------------------------------------------
+function MenuEditVectors_Callback(hObject, eventdata, handles)
+set(handles.edit_vect,'Visible','on')
+set(handles.edit_vect,'Value',1)
+edit_vect_Callback(hObject, eventdata, handles)
+
+
+
+
Index: /trunk/src/warndlg_uvmat.m
===================================================================
--- /trunk/src/warndlg_uvmat.m (revision 2)
+++ /trunk/src/warndlg_uvmat.m (revision 2)
@@ -0,0 +1,18 @@
+%'warndlg_uvmat': display warning message (error, warning, confirmation) in a given figure
+%---------------------------------------------------------------------
+% hwarn=warndlg_uvmat(warntext,title)
+%---------------------------------------------------------------------
+% OUTPUT:
+% hwarn: string representing the file name (including path)
+%
+% INPUT:
+% warntext: text to display
+% title: string indicating the type of message box:
+% title= 'ERROR', 'WARNING', 'CONFIRMATION' .
+
+function hwarn=warndlg_uvmat(warntext,title)
+hwarn=msgbox_uvmat(title,warntext);
+%if isequal(title,'ERROR')||isequal(title,'WARNING')
+ %delete(hwarn)
+%end
+
Index: /trunk/src/write_plot_param.m
===================================================================
--- /trunk/src/write_plot_param.m (revision 2)
+++ /trunk/src/write_plot_param.m (revision 2)
@@ -0,0 +1,109 @@
+%'write_plot_param': update the plotting parameters on the uvmat interface after a plotting operation
+function write_plot_param(handles,PlotParam)
+
+%scalar or image parameters
+if isfield(PlotParam,'Scalar')
+ set_scal_display(handles,'on')
+ if isfield(PlotParam.Scalar,'MaxA')
+ set(handles.MaxA,'String',num2str(PlotParam.Scalar.MaxA,3));
+ end
+ if isfield(PlotParam.Scalar,'MinA')
+ set(handles.MinA,'String',num2str(PlotParam.Scalar.MinA,3));
+ end
+
+ if isfield(PlotParam.Scalar,'IncrA')
+ set(handles.IncrA,'String',num2str(PlotParam.Scalar.IncrA,3))
+ end
+else
+ set_scal_display(handles,'off')
+end
+
+% parameter for vector field
+if isfield(PlotParam,'Vectors')
+ set_vect_display(handles,'on')
+ if isfield(PlotParam.Vectors,'VecScale')
+ set(handles.VecScale,'String',num2str(PlotParam.Vectors.VecScale,3))
+ end
+ if isfield(PlotParam.Vectors,'MinC')&& isfield(PlotParam.Vectors,'MaxC')
+ MinC=PlotParam.Vectors.MinC;
+ MaxC=PlotParam.Vectors.MaxC;
+ set(handles.min_vec,'String', num2str(MinC,3));
+ set(handles.max_vec,'String',num2str(MaxC,3));
+ list=get(handles.color_code,'String');
+ ichoice=get(handles.color_code,'Value');
+ color_option=list{ichoice};
+ test3color=strcmp(color_option,'rgb')||strcmp(color_option,'bgr');
+ if test3color% need to update color thresholds
+ set(handles.colcode1,'Visible','on')
+ set(handles.colcode2,'Visible','on')
+ set(handles.slider1,'Visible','on')
+ set(handles.slider2,'Visible','on')
+% slider1=get(handles.slider1,'Value');
+% slider2=get(handles.slider2,'Value');
+ colcode1=MinC+(MaxC-MinC)*PlotParam.Vectors.colcode1;
+ colcode2=MinC+(MaxC-MinC)*PlotParam.Vectors.colcode2;
+ set(handles.colcode1,'String',num2str(colcode1,3))
+ set(handles.colcode2,'String',num2str(colcode2,3))
+ set(handles.slider1,'Value',PlotParam.Vectors.colcode1)
+ set(handles.slider2,'Value',PlotParam.Vectors.colcode2)
+ else
+ set(handles.colcode1,'Visible','off')
+ set(handles.colcode2,'Visible','off')
+ set(handles.slider1,'Visible','off')
+ set(handles.slider2,'Visible','off')
+ end
+ end
+else
+ set_vect_display(handles,'off')
+ set(handles.edit_vect,'Visible','off')
+end
+
+%------------------------------------------------------------------
+%prepare interface for scalar display: state ='on' or 'off'
+function set_scal_display(handles,state)
+%------------------------------------------------------------------
+set(handles.SCALAR_title,'Visible',state)
+set(handles.MaxA,'Visible',state)
+set(handles.MinA,'Visible',state)
+%set(handles.IncrA,'Visible',state)
+set(handles.AutoScal,'Visible',state)
+set(handles.BW,'Visible',state)
+set(handles.Contours,'Visible',state)
+set(handles.SCALAR_title,'Visible',state)
+set(handles.min_title,'Visible',state)
+set(handles.max_title,'Visible',state)
+set(handles.frame_scal,'Visible',state)
+set(handles.npx,'Visible',state)
+set(handles.npy,'Visible',state)
+set(handles.npx_title,'Visible',state)
+set(handles.npy_title,'Visible',state)
+%set(handles.makemask,'Visible',state)
+
+%---------------------------------------------
+%prepare interface for vector display: state ='on' or 'off'
+function set_vect_display(handles,state)
+%------------------------------------------------------------------
+set(handles.frame_vect,'Visible',state)
+set(handles.VECT_title,'Visible',state)
+set(handles.VecScale,'Visible',state)
+set(handles.AutoVec,'Visible',state)
+set(handles.HideFalse,'Visible',state)
+set(handles.HideWarning,'Visible',state)
+set(handles.record,'Visible',state)
+set(handles.colcode1,'Visible',state)
+set(handles.colcode2,'Visible',state)
+set(handles.min_vec,'Visible',state)
+set(handles.max_vec,'Visible',state)
+set(handles.scale_title,'Visible',state)
+set(handles.slider1,'Visible',state)
+set(handles.slider2,'Visible',state)
+set(handles.col_vec,'Visible',state)
+set(handles.Color_title,'Visible',state)
+set(handles.color_code,'Visible',state)
+set(handles.vec_col_bar,'Visible',state)
+set(handles.record,'Visible',state)
+set(handles.AutoVecColor,'Visible',state)
+set(handles.decimate4,'Visible',state)
+set(handles.min_C_title,'Visible',state)
+set(handles.max_C_title,'Visible',state)
+set(handles.MenuEditVectors,'Enable',state)