Changeset 457 for trunk


Ignore:
Timestamp:
Jun 17, 2012, 10:52:04 PM (12 years ago)
Author:
sommeria
Message:

merg_i_j transformed to the new standards.
Various improvements

Location:
trunk/src/series
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series/aver_stat.m

    r454 r457  
    11%'aver_stat': calculate field average, used with series.fig
     2% this function can be used as a template for applying a global operation (here averaging) on a series of input fields
    23%------------------------------------------------------------------------
    3 % function GUI_input=aver_stat(Param)
     4% function ParamOut=aver_stat(Param)
    45%
    56%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
     7%
     8% This function is used in four modes by the GUI series:
     9%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     10%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     11%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     12%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     13%
     14% This function is used in four modes by the GUI series:
     15%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     16%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     17%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     18%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     19%
    620%OUTPUT
    721% GUI_input=list of options in the GUI series.fig needed for the function
     
    3246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3347
    34 function GUI_input=aver_stat(Param)
     48function ParamOut=aver_stat(Param)
    3549
    3650%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    3751if ~exist('Param','var') % case with no input parameter
    38     GUI_input={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
     52    ParamOut={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
    3953        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     54        'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    4055        'NbSlice';'on'; ...%nbre of slices ('off' by default)
    4156        'VelType';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     
    5065
    5166%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
    52 %% get input parameters, file names and indices
     67%% select different modes,  RUN, parameter input, BATCH
    5368% BATCH  case: read the xml file for batch case
    54 if ischar(Param) && ~isempty(find(regexp(Param,'.xml$')))
    55     Param=xml2struct(Param);
    56     checkrun=0;
    57 % RUN case: parameters introduced as the input structure Param 
    58 else
     69ParamOut=Param; %default output
     70if ischar(Param)
     71    if strcmp(Param,'input?')
     72        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
     73    else
     74        Param=xml2struct(Param);
     75        checkrun=0;
     76    end
     77% RUN case: parameters introduced as the input structure Param
     78else
    5979    hseries=guidata(Param.hseries);%handles of the GUI series
    6080    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
    61     checkrun=1; % indicate the RUN option is used
    62 end
     81    checkrun=2; % indicate the RUN option is used
     82end
     83
     84%% root input file(s) and type
     85RootPath=Param.InputTable(:,1);
     86RootFile=Param.InputTable(:,3);
     87SubDir=Param.InputTable(:,2);
     88NomType=Param.InputTable(:,4);
     89FileExt=Param.InputTable(:,5);
     90
    6391% get the set of input file names (cell array filecell), and the lists of
    6492% input file or frame indices i1_series,i2_series,j1_series,j2_series
    65 
    6693[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    67 
    6894% filecell{iview,fileindex}: cell array representing the list of file names
    6995%        iview: line in the table corresponding to a given file series
     
    7298% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    7399% set of frame indices used for movie or multimage input
    74 
    75 
    76 %% root input file(s) and type
    77 RootPath=Param.InputTable(:,1);
    78 RootFile=Param.InputTable(:,3);
    79 SubDir=Param.InputTable(:,2);
    80 NomType=Param.InputTable(:,4);
    81 FileExt=Param.InputTable(:,5);
    82 
    83100% numbers of slices and file indices
     101
    84102NbSlice=1;%default
    85 if isfield(Param.IndexRange,'NbSlice')
     103if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
    86104    NbSlice=Param.IndexRange.NbSlice;
    87105end
    88106nbview=numel(i1_series);%number of input file series (lines in InputTable)
    89 nbfield_j=size(i1_series{1},1); %nb of consecutive fields for the j index (bursts or volume slices)
    90 nbfield_i=size(i1_series{1},2); %nb of consecutive fields for the i index
    91 nbfield=nbfield_j*nbfield_i; %total number of files or frames
     107nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     108nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     109nbfield=nbfield_j*nbfield_i; %total number of fields
    92110nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
    93111nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
     
    96114ImageTypeOptions={'image','multimage','mmreader','video'};
    97115NcTypeOptions={'netcdf','civx','civdata'};
    98    
    99116for iview=1:nbview
    100117    if ~exist(filecell{iview,1}','file')
     
    117134itime=0;
    118135NbSlice_calib={};
     136XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
    119137for iview=1:nbview%Loop on views
    120     XmlData{iview}=[];%default
    121     filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
    122     if exist([filebase{iview} '.xml'],'file')
    123         [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
    124         if isfield(XmlData{iview},'Time')
    125             itime=itime+1;
    126             timecell{itime}=XmlData{iview}.Time;
    127         end
    128         if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
    129             NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
    130             if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
    131                 msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    132             end
    133         end
    134     elseif exist([filebase{iview} '.civ'],'file')
    135         [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
     138    SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
     139    filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
     140    if ~exist(filexml,'file')
     141        filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
     142        if ~exist(filexml,'file')
     143            filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
     144            if ~exist(filexml,'file')
     145                filexml='';
     146            end
     147        end
     148    end
     149    if ~isempty(filexml)
     150        [XmlData{iview},error]=imadoc2struct(filexml);
     151    end
     152    if isfield(XmlData{iview},'Time')
    136153        itime=itime+1;
    137         timecell{itime}=time;
    138         XmlData{iview}.Time=time;
    139         GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
    140         GeometryCalib.Tx=0;
    141         GeometryCalib.Ty=0;
    142         GeometryCalib.Tz=1;
    143         GeometryCalib.dpx=1;
    144         GeometryCalib.dpy=1;
    145         GeometryCalib.sx=1;
    146         GeometryCalib.Cx=0;
    147         GeometryCalib.Cy=0;
    148         GeometryCalib.f=1;
    149         GeometryCalib.kappa1=0;
    150         GeometryCalib.CoordUnit='cm';
    151         XmlData{iview}.GeometryCalib=GeometryCalib;
    152         if error==1
    153             msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
     154        timecell{itime}=XmlData{iview}.Time;
     155    end
     156    if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
     157        NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
     158        if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
     159            msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    154160        end
    155161    end
     
    182188    end   
    183189end
    184 if size(time,2) < i2_series{1}(end) || size(time,3) < j2_series{1}(end)% time array absent or too short in ImaDoc xml file'
     190if size(time,2) < i2_series{1}(end) ||( ~isempty(j2_series{1}) && size(time,3) < j2_series{1}(end))% time array absent or too short in ImaDoc xml file'
    185191    time=[];
    186192end
     
    283289       
    284290        %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
    285         index
    286291        for iview=1:nbview
    287292            % reading input file(s)
     
    369374        msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted'])
    370375    end
    371     if isempty(time) % time read from files  prevails
     376    if isempty(time) % time is read from files 
    372377        if isfield(Field,'Time')
    373378            time_end=Field.Time(1);%last time read
     
    377382            end
    378383        end
    379     else  % time from ImaDoc prevails
    380         DataOut.Time=time(1,i1_series{1}(1),j1_series{1}(1));
     384    else  % time from ImaDoc prevails if it exists
     385        j1=1;%default
     386        if ~isempty(j1_series{1})
     387            j1=j1_series{1};
     388        end
     389        DataOut.Time=time(1,i1_series{1}(1),j1filexml);
    381390        DataOut.Time_end=time(end,i1_series{end}(end),j1_series{end}(end));
    382391    end
  • trunk/src/series/check_data_files.m

    r455 r457  
    3232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3333
    34 function GUI_input=check_data_files(Param)
     34function ParamOut=check_data_files(Param)
    3535
    3636%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    3737if ~exist('Param','var') % case with no input parameter
    38     GUI_input={'NbViewMax';'';...% max nbre of input file series (default='' , no limitation)
     38    ParamOut={'NbViewMax';'';...% max nbre of input file series (default='' , no limitation)
    3939        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
    4040        'NbSlice';'on'; ...%nbre of slices ('off' by default)
     
    5151%% get input parameters, file names and indices
    5252% BATCH  case: read the xml file for batch case
     53ParamOut=Param; %default output
    5354if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
    5455    Param=xml2struct(Param);
  • trunk/src/series/ima_levels.m

    r454 r457  
    11%'ima_levels': rescale the image intensity to reduce strong luminosity peaks (their blinking effects often perturbs PIV))
    2 % this function can be used as a template for applying a transform (here 'levels.m') on each image of a series
     2% this function can be used as a template for applying a transform (here 'levels.m') to each image of a series
    33%------------------------------------------------------------------------
    44% function GUI_input=ima_levels(Param)
    55%
    66%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
     7%
     8% This function is used in four modes by the GUI series:
     9%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     10%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     11%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     12%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     13%
    714%OUTPUT
    815% GUI_input=list of options in the GUI series.fig needed for the function
     
    5057end
    5158
    52 %% get input parameters, file names and indices
     59%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     60%% select different modes,  RUN, parameter input, BATCH
    5361% BATCH  case: read the xml file for batch case
    54 if ischar(Param) && ~isempty(find(regexp(Param,'.xml$')))
    55     Param=xml2struct(Param);
    56     checkrun=0;
    57 % RUN case: parameters introduced as the input structure Param 
    58 else
     62if ischar(Param)
     63    if strcmp(Param,'input?')
     64        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
     65    else
     66        Param=xml2struct(Param);
     67        checkrun=0;
     68    end
     69% RUN case: parameters introduced as the input structure Param
     70else
    5971    hseries=guidata(Param.hseries);%handles of the GUI series
    6072    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
    61     checkrun=1; % indicate the RUN option is used
    62 end
    63 
    64 % get the set of input file names (cell array filecell), and the lists of
    65 [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     73    checkrun=2; % indicate the RUN option is used
     74end
    6675
    6776%% root input file(s) and type
     
    7281FileExt=Param.InputTable(:,5);
    7382
     83% get the set of input file names (cell array filecell), and the lists of
     84% input file or frame indices i1_series,i2_series,j1_series,j2_series
     85[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     86% filecell{iview,fileindex}: cell array representing the list of file names
     87%        iview: line in the table corresponding to a given file series
     88%        fileindex: file index within  the file series,
     89% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
     90% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
     91% set of frame indices used for movie or multimage input
    7492% numbers of slices and file indices
     93
    7594NbSlice=1;%default
    7695if isfield(Param.IndexRange,'NbSlice')
     
    7897end
    7998nbview=numel(i1_series);%number of input file series (lines in InputTable)
    80 nbfield_j=size(i1_series{1},1); %nb of consecutive fields for the j index (bursts or volume slices)
    81 nbfield_i=size(i1_series{1},2); %nb of consecutive fields for the i index
    82 nbfield=nbfield_j*nbfield_i; %total number of files or frames
     99nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     100nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     101nbfield=nbfield_j*nbfield_i; %total number of fields
    83102nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
    84103nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
     
    86105%determine the file type on each line from the first input file
    87106ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
     107
    88108[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
    89109CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
  • trunk/src/series/merge_proj.m

    r447 r457  
    1 
    2 
    3 
    4 
    5 
    6 %'merge_proj': project and concatene fields, used with series.fig
     1%'merge_proj': project and concatene fieldsmerge_proj
     2% can be used as a template for applying an operation (here projection and concateantion) on each field of an input series
    73%------------------------------------------------------------------------
    8 % function GUI_input=merge_proj(Param)
     4% function GUI_config=merge_proj(Param)
     5%------------------------------------------------------------------------
     6
     7%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
    98%
     9% This function is used in four modes by the GUI series:
     10%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     11%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     12%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     13%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     14%
     15% This function is used in four modes by the GUI series:
     16%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     17%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     18%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     19%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     20%
     21%OUTPUT
     22% GUI_input=list of options in the GUI series.fig needed for the function
     23%
     24%INPUT:
     25% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
     26% In batch mode, Param is the name of the corresponding xml file containing the same information
     27% In the absence of input (as activated when the current Action is selected
     28% in series), the function ouput GUI_input set the activation of the needed GUI elements
     29%
     30% Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     31%    .InputTable: cell of input file names, (several lines for multiple input)
     32%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
     33%    .OutputSubDir: name of the subdirectory for data outputs
     34%    .OutputDir: directory for data outputs, including path
     35%    .Action: .ActionName: name of the current activated function
     36%             .ActionPath:   path of the current activated function
     37%    .IndexRange: set the file or frame indices on which the action must be performed
     38%    .FieldTransform: .TransformName: name of the selected transform function
     39%                     .TransformPath:   path  of the selected transform function
     40%                     .TransformHandle: corresponding function handle
     41%    .InputFields: sub structure describing the input fields withfields
     42%              .FieldName: name of the field
     43%              .VelType: velocity type
     44%              .FieldName_1: name of the second field in case of two input series
     45%              .VelType_1: velocity type of the second field in case of two input series
     46%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
     47%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     48
     49function GUI_input=merge_proj(Param)
     50
     51%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
     52if ~exist('Param','var') % case with no input parameter
     53    GUI_input={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
     54        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     55        'NbSlice';'on'; ...%nbre of slices ('off' by default)
     56        'VelType';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     57        'FieldName';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     58        'FieldTransform'; 'on';...%can use a transform function
     59        'ProjObject';'on';...%can use projection object(option 'off'/'on',
     60        'Mask';'on';...%can use mask option   (option 'off'/'on', 'off' by default)
     61        'OutputDirExt';'.proj';...%set the output dir extension
     62               ''};
     63        return
     64end
     65
     66%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     67%% select different modes,  RUN, parameter input, BATCH
     68% BATCH  case: read the xml file for batch case
     69if ischar(Param)
     70    if strcmp(Param,'input?')
     71        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
     72    else
     73        Param=xml2struct(Param);
     74        checkrun=0;
     75    end
     76% RUN case: parameters introduced as the input structure Param
     77else
     78    hseries=guidata(Param.hseries);%handles of the GUI series
     79    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
     80    checkrun=2; % indicate the RUN option is used
     81end
     82
     83%% root input file(s) and type
     84RootPath=Param.InputTable(:,1);
     85RootFile=Param.InputTable(:,3);
     86SubDir=Param.InputTable(:,2);
     87NomType=Param.InputTable(:,4);
     88FileExt=Param.InputTable(:,5);
     89
     90% get the set of input file names (cell array filecell), and the lists of
     91% input file or frame indices i1_series,i2_series,j1_series,j2_series
     92[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     93% filecell{iview,fileindex}: cell array representing the list of file names
     94%        iview: line in the table corresponding to a given file series
     95%        fileindex: file index within  the file series,
     96% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
     97% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
     98% set of frame indices used for movie or multimage input
     99% numbers of slices and file indices
     100
     101NbSlice=1;%default
     102if isfield(Param.IndexRange,'NbSlice')
     103    NbSlice=Param.IndexRange.NbSlice;
     104end
     105nbview=numel(i1_series);%number of input file series (lines in InputTable)
     106nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     107nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     108nbfield=nbfield_j*nbfield_i; %total number of fields
     109nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     110nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
     111
     112%determine the file type on each line from the first input file
     113ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
     114
     115[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
     116CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
     117if ~isempty(j1_series{1})
     118    frame_index{1}=j1_series{1};
     119else
     120    frame_index{1}=i1_series{1};
     121end
     122
     123%% calibration data and timing: read the ImaDoc files
     124mode=''; %default
     125timecell={};
     126itime=0;
     127NbSlice_calib={};
     128for iview=1:nbview%Loop on views
     129    XmlData{iview}=[];%default
     130    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
     131    if exist([filebase{iview} '.xml'],'file')
     132        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
     133        if isfield(XmlData{iview},'Time')
     134            itime=itime+1;
     135            timecell{itime}=XmlData{iview}.Time;
     136        end
     137        if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
     138            NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
     139            if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
     140                msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
     141            end
     142        end
     143    elseif exist([filebase{iview} '.civ'],'file')
     144        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
     145        itime=itime+1;
     146        timecell{itime}=time;
     147        XmlData{iview}.Time=time;
     148        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
     149        GeometryCalib.Tx=0;
     150        GeometryCalib.Ty=0;
     151        GeometryCalib.Tz=1;
     152        GeometryCalib.dpx=1;
     153        GeometryCalib.dpy=1;
     154        GeometryCalib.sx=1;
     155        GeometryCalib.Cx=0;
     156        GeometryCalib.Cy=0;
     157        GeometryCalib.f=1;
     158        GeometryCalib.kappa1=0;
     159        GeometryCalib.CoordUnit='cm';
     160        XmlData{iview}.GeometryCalib=GeometryCalib;
     161        if error==1
     162            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
     163        end
     164    end
     165end
     166
     167%% check coincidence in time for several input file series
     168multitime=0;
     169if isempty(timecell)
     170    time=[];
     171elseif length(timecell)==1
     172    time=timecell{1};
     173elseif length(timecell)>1
     174    multitime=1;
     175    for icell=1:length(timecell)
     176        if ~isequal(size(timecell{icell}),size(timecell{1}))
     177            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
     178            time=timecell{1};
     179            multitime=0;
     180            break
     181        end
     182    end
     183end
     184if multitime
     185    for icell=1:length(timecell)
     186        time(icell,:,:)=timecell{icell};
     187    end
     188    diff_time=max(max(diff(time)));
     189    if diff_time>0
     190        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
     191    end   
     192end
     193if size(time,2) < i2_series{1}(end) || size(time,3) < j2_series{1}(end)% time array absent or too short in ImaDoc xml file'
     194    time=[];
     195end
     196
     197%% coordinate transform or other user defined transform
     198transform_fct='';%default
     199if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle')
     200    transform_fct=Param.FieldTransform.TransformHandle;
     201end
     202%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
     203 % EDIT FROM HERE
     204
     205%% check the validity of  input file types
     206if CheckImage{1}
     207    FileExtOut='.png'; % write result as .png images for image inputs
     208elseif CheckNc{1}
     209    FileExtOut='.nc';% write result as .nc files for netcdf inputs
     210else
     211    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
     212    return
     213end
     214if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
     215        msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
     216    return
     217end
     218NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
     219if NbSlice~=nbfield_j
     220    answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
     221    if ~strcmp(answer,'Yes')
     222        return
     223    end
     224end
     225
     226%% Set field names and velocity types
     227InputFields{1}=[];%default (case of images)
     228if isfield(Param,'InputFields')
     229    InputFields{1}=Param.InputFields;
     230end
     231if nbview==2
     232    InputFields{2}=[];%default (case of images)
     233    if isfield(Param,'InputFields')
     234        InputFields{2}=Param.InputFields{1};%default
     235        if isfield(Param.InputFields,'FieldName_1')
     236            InputFields{2}.FieldName=Param.InputFields.FieldName_1;
     237            if isfield(Param.InputFields,'VelType_1')
     238                InputFields{2}.VelType=Param.InputFields.VelType_1;
     239            end
     240        end
     241    end
     242end
     243
     244%% Initiate output fields
     245%initiate the output structure as a copy of the first input one (reproduce fields)
     246[DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
     247if ~isempty(errormsg)
     248    msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
     249    return
     250end
     251time_1=[];
     252if isfield(DataOut,'Time')
     253    time_1=DataOut.Time(1);
     254end
     255if CheckNc{iview}
     256    if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
     257        DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
     258    end
     259    DataOut.Conventions='uvmat';
     260    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
     261    ActionKey='Action';
     262    while isfield(DataOut,ActionKey)
     263        ActionKey=[ActionKey '_1'];
     264    end
     265    DataOut.(ActionKey)=Param.Action;
     266    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
     267    if isfield(DataOut,'Time')
     268        DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
     269    end
     270end
     271
     272%% MAIN LOOP ON SLICES
     273%%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     274for i_slice=1:NbSlice
     275    index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice
     276    nbfiles=0;
     277    nbmissing=0;
     278   
     279   %initiate result fields
     280   for ivar=1:length(DataOut.ListVarName)
     281       DataOut.(DataOut.ListVarName{ivar})=0; % initialise all fields to zero
     282   end
     283
     284    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
     285    for index=index_slice
     286        if checkrun
     287            update_waitbar(hseries.waitbar_frame,WaitbarPos,index/(nbfield))
     288            stopstate=get(hseries.RUN,'BusyAction');
     289        else
     290            stopstate='queue';
     291        end
    10292%OUTPUT
    11293% GUI_input=list of options in the GUI series.fig needed for the function
     
    15297%  or name of the xml file containing these parameters (BATCH case)
    16298%
    17 function GUI_input=merge_proj(Param)
    18 
    19 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
    20 if ~exist('Param','var')
    21     GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
    22         'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
    23         'RootFile';'on';... %root input file name ('on' by default)
    24         'FileExt';'on';... %input file extension ('on' by default)
    25         'NomType';'on';...%type of file indexing ('on' by default)
    26         'NbSlice';'on'; ...%nbre of slices ('off' by default)
    27         'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
    28         'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
    29         'CoordType';'on';...%can use a transform function 'off' by default
    30         'GetObject';'on';...%can use projection object ,'off' by default
    31         'OutputDirExt';'.proj';...
    32         %'GetMask';'on'...%can use mask option   ,'off' by default
    33         %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
    34                ''};
    35     return %exit the function
    36 end
    37 
    38 %% input parameters:
    39 % read the xml file for batch case
    40 if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
    41     Param=xml2struct(Param);
    42 else % RUN case : parameters introduced as the input structure Param
    43     hseries=guidata(Param.hseries);%handles of the GUI series
    44     WaitbarPos=get(hseries.waitbar_frame,'Position');% info for the waitbar
    45 end
    46 [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    47 
    48 %% coordinate transform or other user defined transform
    49 transform_fct='';%default
    50 if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'fct_handle')
    51     transform_fct=Param.FieldTransform.fct_handle;
    52 end
     299
    53300
    54301%% projection object
  • trunk/src/series/relabel_i_j.m

    r249 r457  
    11%'relabel_i_j': relabel an image series with two indices, and correct errors from the RDvision transfer program
    2 %----------------------------------------------------------------------
    3 function GUI_input=relabel_i_j(num_i1,num_i2,num_j1,num_j2,Series)
    4 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
    5 
    6 GUI_input={};
    7 
    8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
    9 hGUI=findobj(allchild(0),'name','series');
    10 hseries=guidata(hGUI);%handles of the GUI series
    11 WaitbarPos=get(hseries.waitbar_frame,'Position');
    12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    13 
    14 %% PARAMETERS (for RDvision system)
     2%------------------------------------------------------------------------
     3% function GUI_config=relabel_i_j(Param)
     4%------------------------------------------------------------------------
     5
     6%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
     7%
     8% This function is used in four modes by the GUI series:
     9%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     10%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     11%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     12%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     13%
     14% This function is used in four modes by the GUI series:
     15%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     16%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     17%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     18%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     19%
     20%OUTPUT
     21% GUI_input=list of options in the GUI series.fig needed for the function
     22%
     23%INPUT:
     24% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
     25% In batch mode, Param is the name of the corresponding xml file containing the same information
     26% In the absence of input (as activated when the current Action is selected
     27% in series), the function ouput GUI_input set the activation of the needed GUI elements
     28%
     29% Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     30%    .InputTable: cell of input file names, (several lines for multiple input)
     31%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
     32%    .OutputSubDir: name of the subdirectory for data outputs
     33%    .OutputDir: directory for data outputs, including path
     34%    .Action: .ActionName: name of the current activated function
     35%             .ActionPath:   path of the current activated function
     36%    .IndexRange: set the file or frame indices on which the action must be performed
     37%    .FieldTransform: .TransformName: name of the selected transform function
     38%                     .TransformPath:   path  of the selected transform function
     39%                     .TransformHandle: corresponding function handle
     40%    .InputFields: sub structure describing the input fields withfields
     41%              .FieldName: name of the field
     42%              .VelType: velocity type
     43%              .FieldName_1: name of the second field in case of two input series
     44%              .VelType_1: velocity type of the second field in case of two input series
     45%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
     46%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     47
     48function GUI_config=relabel_i_j(Param)
     49
     50%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
     51if ~exist('Param','var') % case with no input parameter
     52    GUI_config={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
     53        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     54        'WholeIndexRange';'on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
     55        'NbSlice';'off'; ...%nbre of slices ('off' by default)
     56        'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     57        'FieldName';'off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     58        'FieldTransform'; 'off';...%can use a transform function
     59        'ProjObject';'off';...%can use projection object(option 'off'/'on',
     60        'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
     61        'OutputDirExt';'';...%set the output dir extension
     62               ''};
     63        return
     64end
     65
     66%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     67%% select different modes,  RUN, parameter input, BATCH
     68% BATCH  case: read the xml file for batch case
     69GUI_config=Param;%reproduce the input parameters, no interactive input
     70if ischar(Param)
     71    if strcmp(Param,'input?')
     72        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
     73    else
     74        Param=xml2struct(Param);
     75        checkrun=0;
     76    end
     77% RUN case: parameters introduced as the input structure Param
     78else
     79    hseries=guidata(Param.hseries);%handles of the GUI series
     80    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
     81    checkrun=2; % indicate the RUN option is used
     82end
     83
     84%% root input file(s) and type
     85RootPath=Param.InputTable(:,1);
     86RootFile=Param.InputTable(:,3);
     87SubDir=Param.InputTable(:,2);
     88NomType=Param.InputTable(:,4);
     89FileExt=Param.InputTable(:,5);
     90
     91% get the set of input file names (cell array filecell), and the lists of
     92% input file or frame indices i1_series,i2_series,j1_series,j2_series
     93[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     94% filecell{iview,fileindex}: cell array representing the list of file names
     95%        iview: line in the table corresponding to a given file series
     96%        fileindex: file index within  the file series,
     97% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
     98% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
     99% set of frame indices used for movie or multimage input
     100% numbers of slices and file indices
     101
     102NbSlice=1;%default
     103if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
     104    NbSlice=Param.IndexRange.NbSlice;
     105end
     106nbview=numel(i1_series);%number of input file series (lines in InputTable)
     107nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     108nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     109nbfield=nbfield_j*nbfield_i; %total number of fields
     110nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     111nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
     112
     113%determine the file type on each line from the first input file
     114ImageTypeOptions={'image','multimage','mmreader','video'};
     115NcTypeOptions={'netcdf','civx','civdata'};
     116for iview=1:nbview
     117    if ~exist(filecell{iview,1}','file')
     118        msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
     119        return
     120    end
     121    [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
     122    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
     123    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
     124    if ~isempty(j1_series{iview})
     125        frame_index{iview}=j1_series{iview};
     126    else
     127        frame_index{iview}=i1_series{iview};
     128    end
     129end
     130
     131%% calibration data and timing: read the ImaDoc files
     132mode=''; %default
     133timecell={};
     134itime=0;
     135NbSlice_calib={};
     136XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
     137for iview=1:nbview%Loop on views
     138    SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
     139    filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
     140    if ~exist(filexml,'file')
     141        filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
     142        if ~exist(filexml,'file')
     143            filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
     144            if ~exist(filexml,'file')
     145                filexml='';
     146            end
     147        end
     148    end
     149    if ~isempty(filexml)
     150        [XmlData{iview},error]=imadoc2struct_special(filexml);
     151    end
     152    if isfield(XmlData{iview},'Time')
     153        itime=itime+1;
     154        timecell{itime}=XmlData{iview}.Time;
     155    end
     156    if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
     157        NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
     158        if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
     159            msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
     160        end
     161    end
     162end
     163
     164%% check coincidence in time for several input file series
     165% not relevant
     166
     167%% coordinate transform or other user defined transform
     168%not relevant
     169%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
     170 % EDIT FROM HERE
     171
     172%% check the validity of  input file types
     173if CheckImage{1}
     174    FileExtOut='.png'; % write result as .png images for image inputs
     175elseif CheckNc{1}
     176    FileExtOut='.nc';% write result as .nc files for netcdf inputs
     177else
     178    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
     179    return
     180end
     181if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
     182        msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
     183    return
     184end
     185NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
     186if NbSlice~=nbfield_j
     187    answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
     188    if ~strcmp(answer,'Yes')
     189        return
     190    end
     191end
     192
     193%% Set field names and velocity types
     194% not relevant here
     195
     196%% Initiate output fields
     197% not relevant here
     198
     199%% interactive input of specific parameters (for RDvision system)
    15200display('RDvision system')
    16201first_label=0; %image numbers start from 0
    17 %errorfactor=1 %correct a factor of 2 in NbDk+1
    18 
    19 %% read imadoc
    20 RootPath=get(hseries.RootPath,'String');
    21 RootFile=get(hseries.RootFile,'String');
    22 if ~iscell(RootFile)
    23     msgbox_uvmat('ERROR','please enter an input image series from RDVision system')%error message for xml file reading
    24     return
    25 end
    26 basename=fullfile(RootPath{1},RootFile{1});
    27 [XmlData,warntext]=imadoc2struct([basename '.xml']);% read the xml file appended to the present function (containing bug corrections)
    28 if ~isempty(warntext)
    29     msgbox_uvmat('ERROR',warntext)%error message for xml file reading
    30 end
    31 nbfield1=size(XmlData.Time,1);
    32 nbfield2=size(XmlData.Time,2);
    33 set(hseries.first_i,'String',num2str(first_label))% display the first image in the process
    34 set(hseries.last_i,'String',num2str(nbfield1*nbfield2-1+first_label))% display the last image in the process
    35 set(hseries.nb_field,'String',{num2str(nbfield1*nbfield2-1+first_label)})% display the total nbre of images
    36 SeriesData=get(hGUI,'UserData');
    37 if ~strcmp(SeriesData.NomType,'_000001')
     202if ~strcmp(NomType{1},'_000001')
    38203    msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation
    39204    return
    40205else
    41     answer=msgbox_uvmat('','this function will relabel the file series from RDvision and correct the xml file');%error message for directory creation
     206    answer=msgbox_uvmat('','this function will relabel the file series from RDvision from  and correct the xml file');%error message for directory creation
    42207    if ~strcmp(answer,'Yes')
    43208        return
     
    45210end
    46211
    47 %% stop program ther when it is selected in the menu (no run action)
    48 if ~exist('num_i1','var')
    49     return
    50 end
    51 if nbfield2>=2
    52 answer=msgbox_uvmat('',[num2str(nbfield1) ' bursts containing ' num2str(nbfield2) ' images each']);%error message for directory creation
    53 nomtype='_i_j';
    54 else
    55     answer=msgbox_uvmat('',['image series with ' num2str(nbfield1) ' images']);%error message for directory creation
    56     nomtype='_i';
    57 end
    58 if ~strcmp(answer,'Yes')
    59     return
    60 end
     212%% read imadoc
     213% RootPath=get(hseries.RootPath,'String');
     214% RootFile=get(hseries.RootFile,'String');
     215% if ~iscell(RootFile)
     216%     msgbox_uvmat('ERROR','please enter an input image series from RDVision system')%error message for xml file reading
     217%     return
     218% end
     219% basename=fullfile(RootPath{1},RootFile{1});
     220% [XmlData,warntext]=imadoc2struct_special([basename '.xml']);% read the xml file appended to the present function (containing bug corrections)
     221% if ~isempty(warntext)
     222%     msgbox_uvmat('ERROR',warntext)%error message for xml file reading
     223% end
     224% nbfield1=size(XmlData.Time,1);
     225% nbfield2=size(XmlData.Time,2);
     226% set(hseries.first_i,'String',num2str(first_label))% display the first image in the process
     227% set(hseries.last_i,'String',num2str(nbfield1*nbfield2-1+first_label))% display the last image in the process
     228% set(hseries.nb_field,'String',{num2str(nbfield1*nbfield2-1+first_label)})% display the total nbre of images
     229% SeriesData=get(hGUI,'UserData');
     230
     231
     232%% stop program there when it is selected in the menu (no run action)
     233% if ~exist('num_i1','var')
     234%     return
     235% end
     236% if nbfield2>=2
     237% answer=msgbox_uvmat('',[num2str(nbfield1) ' bursts containing ' num2str(nbfield2) ' images each']);%error message for directory creation
     238% nomtype='_i_j';
     239% else
     240%     answer=msgbox_uvmat('',['image series with ' num2str(nbfield1) ' images']);%error message for directory creation
     241%     nomtype='_i';
     242% end
     243% if ~strcmp(answer,'Yes')
     244%     return
     245% end
    61246
    62247%% copy and adapt the xml file
    63 if exist([basename '.xml'],'file')
    64     try
    65         copyfile([basename '.xml'],[basename '.xml~']);% backup the xml file
    66     catch ME
    67         msgbox_uvmat('ERROR',ME.message);
    68         return
    69     end
    70     t=xmltree([basename '.xml']);
    71    
    72     %update information on the first image name in the series
    73     uid_Heading=find(t,'ImaDoc/Heading');
    74     if isempty(uid_Heading)
    75         [t,uid_Heading]=add(t,1,'element','Heading');
    76     end
    77     uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
    78     ImageName=name_generator(basename,1,1,'.png','_i_j');
    79     [pth,ImageName]=fileparts(ImageName);
    80     ImageName=[ImageName '.png'];
    81     if isempty(uid_ImageName)
    82         [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
    83     end
    84     uid_value=children(t,uid_ImageName);
    85     if isempty(uid_value)
    86         t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
     248if ~isempty(XmlData{1})
     249
     250%     if exist([basename '.xml'],'file')
     251%         try
     252%             copyfile([basename '.xml'],[basename '.xml~']);% backup the xml file
     253%         catch ME
     254%             msgbox_uvmat('ERROR',ME.message);
     255%             return
     256%         end
     257%         filexml=[filebase{1} '.xml']
     258        t=xmltree(filexml);
     259       
     260        %update information on the first image name in the series
     261        uid_Heading=find(t,'ImaDoc/Heading');
     262        if isempty(uid_Heading)
     263            [t,uid_Heading]=add(t,1,'element','Heading');
     264        end
     265        uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
     266        j1=[];
     267        if ~isempty(j1_series{1})
     268            j1=j1_series{1};
     269        end
     270        ImageName=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'_1_1',i1_series{1}(1),[],j);
     271%         ImageName=name_generator(basename,1,1,'.png','_i_j');
     272        [pth,ImageName]=fileparts(ImageName);
     273        ImageName=[ImageName '.png'];
     274        if isempty(uid_ImageName)
     275            [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
     276        end
     277        uid_value=children(t,uid_ImageName);
     278        if isempty(uid_value)
     279            t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
     280        else
     281            t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
     282        end
     283       
     284        %%%% correction RDvision %%%%
     285        if isfield(XmlData,'NbDtj')
     286            uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
     287            uid_value=children(t,uid_NbDtj);
     288            if ~isempty(uid_value)
     289                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
     290            end
     291        end
     292        if isfield(XmlData,'NbDtk')
     293            uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
     294            uid_value=children(t,uid_NbDtk);
     295            if ~isempty(uid_value)
     296                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
     297            end
     298        end
     299        if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
     300            uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
     301            t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
     302            uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
     303            t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
     304            uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
     305            uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
     306            t=delete(t,uid_NbDtj);
     307            t=delete(t,uid_NbDtk);
     308            uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
     309            uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
     310            t=delete(t,uid_Dtj);
     311            t=delete(t,uid_Dtk);
     312        end
     313            SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
     314    filexml_new=[fullfile(RootPath{1},SubDirBase) '.xml'];
     315        save(t,filexml_new)
     316%     end
     317end
     318
     319%% main loop on images
     320%j1=[];%default
     321nbfield2=size(XmlData{1}.Time,2);
     322for ifile=1:nbfield
     323    if checkrun
     324        update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield)
     325        stopstate=get(hseries.RUN,'BusyAction');
    87326    else
    88         t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
    89     end
    90    
    91     %%%% correction RDvision %%%%
    92     if isfield(XmlData,'NbDtj')
    93         uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
    94         uid_value=children(t,uid_NbDtj);
    95         if ~isempty(uid_value)
    96             t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
    97         end
    98     end
    99     if isfield(XmlData,'NbDtk')
    100         uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
    101         uid_value=children(t,uid_NbDtk);
    102         if ~isempty(uid_value)
    103             t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
    104         end
    105     end
    106     if strcmp(nomtype,'_i') && isfield(XmlData,'NbDti')
    107         uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
    108         t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
    109         uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
    110         t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
    111 %         uid_value=children(t,uid_NbDti);
    112 %         if ~isempty(uid_value)
    113 %             t=set(t,uid_value(1),'value',num2str(XmlData.NbDti));
    114 %         end
    115         uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
    116         uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
    117         t=delete(t,uid_NbDtj);
    118         t=delete(t,uid_NbDtk);
    119         uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
    120         uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
    121         t=delete(t,uid_Dtj);
    122         t=delete(t,uid_Dtk);
    123     end
    124     %%%
    125    
    126     save(t,[basename '.xml'])
    127 end
    128 
    129 %% main loop
    130 
    131 for ifile=1:nbfield1*nbfield2
    132     update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield1*nbfield2))
    133     filename=name_generator(basename,ifile-1,1,Series.FileExt,Series.NomType);
    134     num_j=mod(ifile-1+first_label,nbfield2)+1;
    135     num_i=floor((ifile-1+first_label)/nbfield2)+1;
    136     filename_new=name_generator(basename,num_i,num_j,'.png',nomtype);
    137     try
    138         movefile(filename,filename_new);
    139         [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a')
    140         if ~s
    141             msgbox_uvmat('ERROR',errormsg);
     327        stopstate='queue';
     328    end
     329    if isequal(stopstate,'queue') % enable STOP command
     330        filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile));
     331        j1=mod(ifile-1+first_label,nbfield2)+1;
     332        i1=floor((ifile-1+first_label)/nbfield2)+1;
     333        %         filename_new=name_generator(basename,num_i,num_j,'.png',nomtype);
     334        filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'_1_1',i1,[],j1);
     335        try
     336            movefile(filename,filename_new);
     337            [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a')
     338            if ~s
     339                msgbox_uvmat('ERROR',errormsg);
     340                return
     341            end
     342        catch ME
     343            msgbox_uvmat('ERROR',ME.message);
    142344            return
    143345        end
    144     catch ME
    145         msgbox_uvmat('ERROR',ME.message);
    146         return
    147     end
    148 end
    149 
    150 
    151 %'imadoc2struct': reads the xml file for image documentation
     346    end
     347end
     348
     349%'imadoc2struct_special': reads the xml file for image documentation
    152350%------------------------------------------------------------------------
    153 % function [s,errormsg]=imadoc2struct(ImaDoc,option)
     351% function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
    154352%
    155353% OUTPUT:
     
    165363% option: ='GeometryCalib': read  the data of GeometryCalib, including source point coordinates
    166364
    167 function [s,errormsg]=imadoc2struct(ImaDoc,option)
     365function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
    168366
    169367%% default input and output
     
    247445                     s.Dti=Dti;
    248446                else
    249                     NbDtj=NbDtj/numel(Dtj);%bursts
     447                    % NbDtj=NbDtj/numel(Dtj);%bursts
    250448                    s.NbDtj=NbDtj;
    251449                end
  • trunk/src/series/sub_background.m

    r455 r457  
    1 %'sub_background': substract background to an image series, used with series.fig
     1%'sub_background': substract a sliding background to an image series
     2% This is an example of action on a series of input images
    23%------------------------------------------------------------------------
    34% Method:
     
    1415    % Else nbfield2=nbfield_j =nbre of images in a burst (j index)
    1516   
    16 % function GUI_series_config=sub_background(Param)
     17% function GUI_config=sub_background(Param)
    1718%
    1819%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
     20%
     21% This function is used in four modes by the GUI series:
     22%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     23%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     24%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     25%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     26%
    1927%OUTPUT
    2028% GUI_series_config=list of options in the GUI series.fig needed for the function
     
    5260    GUI_config={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
    5361        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     62        'WholeIndexRange';'on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    5463        'NbSlice';'on'; ...%nbre of slices ('off' by default)
    5564        'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     
    6473
    6574%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
    66 %% get input parameters, file names and indices
     75%% select different modes,  RUN, parameter input, BATCH
    6776% BATCH  case: read the xml file for batch case
    68 if ischar(Param) && ~isempty(find(regexp(Param,'.xml$'))) %batch mode
     77if ischar(Param)
     78    if strcmp(Param,'input?')
     79        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
     80    else
    6981        Param=xml2struct(Param);
    7082        checkrun=0;
    71     % RUN case: parameters introduced as the input structure Param
     83    end
     84% RUN case: parameters introduced as the input structure Param
    7285else
    7386    hseries=guidata(Param.hseries);%handles of the GUI series
    7487    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
    75     checkrun=1; % indicate the RUN option is used
    76 end
     88    checkrun=2; % indicate the RUN option is used
     89end
     90
     91%% root input file(s) and type
     92RootPath=Param.InputTable(:,1);
     93RootFile=Param.InputTable(:,3);
     94SubDir=Param.InputTable(:,2);
     95NomType=Param.InputTable(:,4);
     96FileExt=Param.InputTable(:,5);
     97
    7798% get the set of input file names (cell array filecell), and the lists of
    7899% input file or frame indices i1_series,i2_series,j1_series,j2_series
     
    84105% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    85106% set of frame indices used for movie or multimage input
    86 
    87 
    88 %% root input file(s) and type
    89 RootPath=Param.InputTable(:,1);
    90 RootFile=Param.InputTable(:,3);
    91 SubDir=Param.InputTable(:,2);
    92 NomType=Param.InputTable(:,4);
    93 FileExt=Param.InputTable(:,5);
    94 
    95107% numbers of slices and file indices
     108
    96109NbSlice=1;%default
    97 if isfield(Param.IndexRange,'NbSlice')
     110if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
    98111    NbSlice=Param.IndexRange.NbSlice;
    99112end
     
    162175end
    163176
    164 %% set processing parameters
    165 if ~isfield(Param,'Specific')
     177%% input of specific parameters
     178if checkrun %get specific parameters interactively
    166179    prompt = {'volume scan mode (Yes/No)';'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';...
    167180        'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
     
    200213    answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
    201214    GUI_config.CheckLevelTransform=strcmp(answer,'Yes');
    202    
    203 %     % return to BATCH mode
    204 %     if checkrun==-1
    205         return %transfer to BATCH mode
    206 %     end
     215    if checkrun==2
     216         return
     217    end
     218    %%%%%%%%%%%%%%%%%%%%%%  STOP HERE FOR PAMETER INPUT MODE  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    207219else
    208220    GUI_config=Param.Specific;
  • trunk/src/series/time_series.m

    r447 r457  
    11%'time_series': extract a time series, used with series.fig
     2% this function can be used as a template for applying a global operation on a series of input fields
    23%------------------------------------------------------------------------
    34% function GUI_input=time_series(Param)
     5%
     6%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
     7%
     8% This function is used in four modes by the GUI series:
     9%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     10%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     11%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     12%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     13%
     14% This function is used in four modes by the GUI series:
     15%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     16%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     17%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     18%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
    419%
    520%OUTPUT
     
    722%
    823%INPUT:
    9 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
    10 %i2_series: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
    11 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
    12 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
    13 %Series: Matlab structure containing information set by the series interface
     24% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
     25% In batch mode, Param is the name of the corresponding xml file containing the same information
     26% In the absence of input (as activated when the current Action is selected
     27% in series), the function ouput GUI_input set the activation of the needed GUI elements
    1428%
    15 function GUI_input=time_series(Param)
     29% Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     30%    .InputTable: cell of input file names, (several lines for multiple input)
     31%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
     32%    .OutputSubDir: name of the subdirectory for data outputs
     33%    .OutputDir: directory for data outputs, including path
     34%    .Action: .ActionName: name of the current activated function
     35%             .ActionPath:   path of the current activated function
     36%    .IndexRange: set the file or frame indices on which the action must be performed
     37%    .FieldTransform: .TransformName: name of the selected transform function
     38%                     .TransformPath:   path  of the selected transform function
     39%                     .TransformHandle: corresponding function handle
     40%    .InputFields: sub structure describing the input fields withfields
     41%              .FieldName: name of the field
     42%              .VelType: velocity type
     43%              .FieldName_1: name of the second field in case of two input series
     44%              .VelType_1: velocity type of the second field in case of two input series
     45%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
     46%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     47%
     48function ParamOut=time_series(Param)
    1649
    1750%% requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
    1851if ~exist('Param','var')
    19     GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
     52    ParamOut={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
    2053        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
    2154        'RootFile';'on';... %root input file name ('on' by default)
     
    3467end
    3568
    36 %% input parameters
    37 % read the xml file for batch case
    38 if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
    39     Param=xml2struct(Param);
    40     checkrun=0;
    41 else %  RUN case: parameters introduced as the input structure Param
     69%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     70%% select different modes,  RUN, parameter input, BATCH
     71% BATCH  case: read the xml file for batch case
     72ParamOut=Param; %default output
     73if ischar(Param)
     74    if strcmp(Param,'input?')
     75        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
     76    else
     77        Param=xml2struct(Param);
     78        checkrun=0;
     79    end
     80% RUN case: parameters introduced as the input structure Param
     81else
    4282    hseries=guidata(Param.hseries);%handles of the GUI series
    43     WaitbarPos=get(hseries.waitbar_frame,'Position');
    44     checkrun=1;
    45 end
     83    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
     84    checkrun=2; % indicate the RUN option is used
     85end
     86
     87%% root input file(s) and type
     88RootPath=Param.InputTable(:,1);
     89RootFile=Param.InputTable(:,3);
     90SubDir=Param.InputTable(:,2);
     91NomType=Param.InputTable(:,4);
     92FileExt=Param.InputTable(:,5);
     93
     94% get the set of input file names (cell array filecell), and the lists of
     95% input file or frame indices i1_series,i2_series,j1_series,j2_series
    4696[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     97% filecell{iview,fileindex}: cell array representing the list of file names
     98%        iview: line in the table corresponding to a given file series
     99%        fileindex: file index within  the file series,
     100% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
     101% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
     102% set of frame indices used for movie or multimage input
     103% numbers of slices and file indices
     104
     105NbSlice=1;%default
     106if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
     107    NbSlice=Param.IndexRange.NbSlice;
     108end
     109nbview=numel(i1_series);%number of input file series (lines in InputTable)
     110nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     111nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     112nbfield=nbfield_j*nbfield_i; %total number of fields
     113nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     114nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
     115
     116%determine the file type on each line from the first input file
     117ImageTypeOptions={'image','multimage','mmreader','video'};
     118NcTypeOptions={'netcdf','civx','civdata'};
     119for iview=1:nbview
     120    if ~exist(filecell{iview,1}','file')
     121        msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
     122        return
     123    end
     124    [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
     125    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
     126    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
     127    if ~isempty(j1_series{iview})
     128        frame_index{iview}=j1_series{iview};
     129    else
     130        frame_index{iview}=i1_series{iview};
     131    end
     132end
     133
     134%% calibration data and timing: read the ImaDoc files
     135mode=''; %default
     136timecell={};
     137itime=0;
     138NbSlice_calib={};
     139XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
     140for iview=1:nbview%Loop on views
     141    SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
     142    filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
     143    if ~exist(filexml,'file')
     144        filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
     145        if ~exist(filexml,'file')
     146            filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
     147            if ~exist(filexml,'file')
     148                filexml='';
     149            end
     150        end
     151    end
     152    if ~isempty(filexml)
     153        [XmlData{iview},error]=imadoc2struct(filexml);
     154    end
     155    if isfield(XmlData{iview},'Time')
     156        itime=itime+1;
     157        timecell{itime}=XmlData{iview}.Time;
     158    end
     159    if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
     160        NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
     161        if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
     162            msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
     163        end
     164    end
     165end
     166
     167%% check coincidence in time for several input file series
     168multitime=0;
     169if isempty(timecell)
     170    time=[];
     171elseif length(timecell)==1
     172    time=timecell{1};
     173elseif length(timecell)>1
     174    multitime=1;
     175    for icell=1:length(timecell)
     176        if ~isequal(size(timecell{icell}),size(timecell{1}))
     177            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
     178            time=timecell{1};
     179            multitime=0;
     180            break
     181        end
     182    end
     183end
     184if multitime
     185    for icell=1:length(timecell)
     186        time(icell,:,:)=timecell{icell};
     187    end
     188    diff_time=max(max(diff(time)));
     189    if diff_time>0
     190        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
     191    end   
     192end
     193if size(time,2) < i2_series{1}(end) ||( ~isempty(j2_series{1}) && size(time,3) < j2_series{1}(end))% time array absent or too short in ImaDoc xml file'
     194    time=[];
     195end
    47196
    48197%% coordinate transform or other user defined transform
    49198transform_fct='';%default
    50 if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'fct_handle')
    51     transform_fct=Param.FieldTransform.fct_handle;
    52 end
    53 
    54 %% projection object
    55 test_object=get(hseries.GetObject,'Value');
    56 if test_object
    57     hset_object=findobj(allchild(0),'tag','set_object');
    58     ProjObject=read_GUI(hset_object);
    59     answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Type]);
    60     if ~isequal(answeryes,'Yes')
     199if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle')
     200    transform_fct=Param.FieldTransform.TransformHandle;
     201end
     202%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
     203 % EDIT FROM HERE
     204
     205%% check the validity of  input file types
     206if CheckImage{1}
     207    FileExtOut='.png'; % write result as .png images for image inputs
     208elseif CheckNc{1}
     209    FileExtOut='.nc';% write result as .nc files for netcdf inputs
     210else
     211    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
     212    return
     213end
     214if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
     215        msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
     216    return
     217end
     218NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
     219if NbSlice~=nbfield_j
     220    answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
     221    if ~strcmp(answer,'Yes')
    61222        return
    62223    end
    63 else
    64     msgbox_uvmat('ERROR','a projection object is needed');
    65     return
    66 end
    67 
    68 %% features of the input fields
    69 RootPath=Param.InputTable(:,1);
    70 RootFile=Param.InputTable(:,3);
    71 % SubDir=Param.InputTable(:,2);
    72 NomType=Param.InputTable(:,4);
    73 FileExt=Param.InputTable(:,5);
    74 % ext=FileExt{1};
    75 % form=imformats(ext(2:end));%test valid Matlab image formats
    76 nbfield=size(i1_series{1},1)*size(i1_series{1},2); %number of fields in the time series
    77 
    78 %% determine image type
    79 hhh=which('mmreader');
    80 testnetcdf=0;
    81 nbview=length(RootPath);%Number of input series: this function  accepts only one or two input file series (sub_field is used in the latter case)
    82 for iview=1:nbview
    83     if isequal(FileExt{iview},'.nc')||isequal(FileExt{iview},'.cdf')
    84         FileType{iview}='netcdf';
    85         testnetcdf=1;
    86     elseif isequal(lower(FileExt{iview}),'.avi')
    87         if ~isequal(hhh,'')%&& mmreader.isPlatformSupported()
    88             MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
    89             FileType{iview}='movie';
    90         else
    91             FileType{iview}='avi';
    92         end
    93     elseif isequal(lower(FileExt{iview}),'.vol')
    94         FileType{iview}='vol';
    95     else
    96        form=imformats(FileExt{iview}(2:end));
    97        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
    98            if isequal(NomType{iview},'*');
    99                FileType{iview}='multimage';
    100            else
    101                FileType{iview}='image';
    102            end
    103        end
    104     end
    105 end
    106 filebase{1}=fullfile(RootPath{1},RootFile{1});
    107 
    108 %% number of slices
    109 NbSlice=Param.NbSlice;
    110 
    111 %% Field and velocity type (the same for the two views)
    112 FieldName={''};
    113 
    114 if isfield(Param,'InputFields')&&isfield(Param.InputFields,'FieldMenu') 
    115     FieldName=Param.InputFields.FieldMenu;%the same set of fields for all views
    116     VelType{1}=Param.InputFields.VelTypeMenu;
    117 end
    118 if isempty(FieldName) && testnetcdf
    119     msgbox_uvmat('ERROR','A field must be defined as input')
    120     return
    121 end
     224end
     225
     226%% Set field names and velocity types
     227InputFields{1}=[];%default (case of images)
     228if isfield(Param,'InputFields')
     229    InputFields{1}=Param.InputFields;
     230end
     231if nbview==2
     232    InputFields{2}=[];%default (case of images)
     233    if isfield(Param,'InputFields')
     234        InputFields{2}=Param.InputFields{1};%default
     235        if isfield(Param.InputFields,'FieldName_1')
     236            InputFields{2}.FieldName=Param.InputFields.FieldName_1;
     237            if isfield(Param.InputFields,'VelType_1')
     238                InputFields{2}.VelType=Param.InputFields.VelType_1;
     239            end
     240        end
     241    end
     242end
     243%%% TO UPDATE
    122244if isequal(FieldName,'get_field...')
    123245    hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
     
    140262    end
    141263end
     264%%%%%%%
     265
     266%% Initiate output fields
     267%initiate the output structure as a copy of the first input one (reproduce fields)
     268[DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
     269if ~isempty(errormsg)
     270    msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
     271    return
     272end
     273time_1=[];
     274if isfield(DataOut,'Time')
     275    time_1=DataOut.Time(1);
     276end
     277if CheckNc{iview}
     278    if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
     279        DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
     280    end
     281    DataOut.Conventions='uvmat';
     282    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
     283    ActionKey='Action';
     284    while isfield(DataOut,ActionKey)
     285        ActionKey=[ActionKey '_1'];
     286    end
     287    DataOut.(ActionKey)=Param.Action;
     288    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
     289    if isfield(DataOut,'Time')
     290        DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
     291    end
     292end
     293
     294
     295
    142296
    143297%% detect whether the two files are 'images' or 'netcdf'
     
    155309%     VelType{2}=VelType_str{VelType_val};
    156310% end
    157 
    158 %% Calibration data and timing: read the ImaDoc files
    159 % mode=''; %default
    160 timecell={};
    161 XmlData={};
    162 itime=0;
    163 NbSlice_calib={};
    164 for iview=1:nbview%Loop on views
    165     XmlData{iview}=[];%default
    166     filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
    167     if exist([filebase{iview} '.xml'],'file')
    168         [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
    169         if isfield(XmlData{iview},'Time')
    170             itime=itime+1;
    171             timecell{itime}=XmlData{iview}.Time;
    172         end
    173         if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
    174             NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
    175             if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
    176                 msgbox_uvmat('WARNING','inconsistent number of Z indices for the field series');
    177             end
    178         end
    179     elseif exist([filebase{iview} '.civ'],'file')%old convention .civ text file
    180         [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
    181         itime=itime+1;
    182         timecell{itime}=time;
    183         XmlData{iview}.Time=time;
    184         GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
    185         GeometryCalib.Tx=0;
    186         GeometryCalib.Ty=0;
    187         GeometryCalib.Tz=1;
    188         GeometryCalib.dpx=1;
    189         GeometryCalib.dpy=1;
    190         GeometryCalib.sx=1;
    191         GeometryCalib.Cx=0;
    192         GeometryCalib.Cy=0;
    193         GeometryCalib.f=1;
    194         GeometryCalib.kappa1=0;
    195         GeometryCalib.CoordUnit='cm';
    196         XmlData{iview}.GeometryCalib=GeometryCalib;
    197         if error==1
    198             msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
    199         end
    200     end
    201 end
    202 time=[];%default
    203 if ~isempty(timecell)
    204     if numel(timecell{1})<nbfield
    205        msgbox_uvmat('WARNING','time array from ImaDoc to short')
    206     else
    207         time=timecell{1}; %time defined from ImaDoc file (image series)
    208     end
    209 end
    210 
    211 %% check coincidence in time
    212 if length(timecell)>1
    213     for icell=2:length(timecell)
    214         if isequal(size(timecell{icell}),size(time))
    215             diff_time=max(abs(timecell{icell}-time));
    216             if diff_time>0
    217                 msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
    218                 break
    219             end
    220         else
    221             msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
    222             break
    223         end
    224     end
    225 end
    226 if ~isempty(time)
    227     display(['time is read from ' filebase{iview} '.xml'])
    228 end
    229 
    230 %%  Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
    231 subdir_result='time_series';
    232 pathdir=fullfile(RootPath{1},subdir_result);
    233 while exist(pathdir,'dir')
    234     subdir_result=[subdir_result '.0'];
    235     pathdir=fullfile(RootPath{1},subdir_result);
    236 end
    237 [m1,m2,m3]=mkdir(pathdir);
    238 if ~isequal(m2,'')
    239      msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation
    240 end
    241 [xx,msg2] = fileattrib(pathdir,'+w','g'); %yield writing access (+w) to user group (g)
    242 if ~strcmp(msg2,'')
    243     msgbox_uvmat('ERROR',['pb of permission for ' pathdir ': ' msg2])%error message for directory creation
    244     return
    245 end
    246 filebase_out=filebase{1};
    247  i21=i1_series{end}(end);
    248  if ~isempty(i2_series{end})
    249      i21=i2_series{end}(end)-i1_series{1}(1);
    250  end
    251  j21=1;
    252  if ~isempty(j1_series{1})
    253      j21=j1_series{end}(end);
    254       if ~isempty(j2_series{end})
    255           j21=j2_series{end}(end)-j21;
    256       end
    257  end
    258 NomTypeOut=nomtype2pair(NomType{1},i21,j21);
    259 
    260 
    261 %% velocity type
    262 VelType_str=get(hseries.VelTypeMenu,'String');
    263 VelType_val=get(hseries.VelTypeMenu,'Value');
    264 VelType{1}=VelType_str{VelType_val};
    265 if nbview==2
    266     VelType_str=get(hseries.VelTypeMenu_1,'String');
    267     VelType_val=get(hseries.VelTypeMenu_1,'Value');
    268     VelType{2}=VelType_str{VelType_val};
    269 end
    270311
    271312%% LOOP ON SLICES
Note: See TracChangeset for help on using the changeset viewer.