Ignore:
Timestamp:
Apr 3, 2013, 10:21:53 AM (11 years ago)
Author:
sommeria
Message:

various bug corrections. Steps further for civ_series (still development needed)

File:
1 edited

Legend:

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

    r563 r599  
    33% function ParamOut=relabel_i_j(Param)
    44%------------------------------------------------------------------------
    5 
     5%
    66%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
    77%
    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 %
    208%OUTPUT
    21 % GUI_input=list of options in the GUI series.fig needed for the function
     9% ParamOut: sets options in the GUI series.fig needed for the function
    2210%
    2311%INPUT:
    2412% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
    2513% 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
     14% when Param.Action.RUN=0 (as activated when the current Action is selected
     15% in series), the function ouput paramOut set the activation of the needed GUI elements
    2816%
    29 % Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     17% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
     18% see the current structure Param)
    3019%    .InputTable: cell of input file names, (several lines for multiple input)
    3120%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
    3221%    .OutputSubDir: name of the subdirectory for data outputs
    33 %    .OutputDir: directory for data outputs, including path
     22%    .OutputDirExt: directory extension for data outputs
    3423%    .Action: .ActionName: name of the current activated function
    3524%             .ActionPath:   path of the current activated function
     25%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
     26%             .RUN =0 for GUI input, =1 for function activation
     27%             .RunMode='local','background', 'cluster': type of function  use
     28%             
    3629%    .IndexRange: set the file or frame indices on which the action must be performed
    3730%    .FieldTransform: .TransformName: name of the selected transform function
    3831%                     .TransformPath:   path  of the selected transform function
    39 %                     .TransformHandle: corresponding function handle
    4032%    .InputFields: sub structure describing the input fields withfields
    41 %              .FieldName: name of the field
     33%              .FieldName: name(s) of the field
    4234%              .VelType: velocity type
    4335%              .FieldName_1: name of the second field in case of two input series
    4436%              .VelType_1: velocity type of the second field in case of two input series
     37%              .Coord_y: name of y coordinate variable
     38%              .Coord_x: name of x coordinate variable
    4539%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
    4640%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    4943
    5044%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    51 if ~exist('Param','var') % case with no input parameter
    52     ParamOut={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
    53         'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
    54         'WholeIndexRange';'on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    55         'NbSlice';'off'; ...%nbre of slices ('off' by default)
    56         'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
    57         'FieldName';'off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
    58         'FieldTransform'; 'off';...%can use a transform function
    59         'ProjObject';'off';...%can use projection object(option 'off'/'on',
    60         'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
    61         'OutputDirExt';'';...%set the output dir extension
    62                ''};
    63         return
    64 end
    65 
    66 %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
    67 %% select different modes,  RUN, parameter input, BATCH
    68 % BATCH  case: read the xml file for batch case
     45if isstruct(Param) && isequal(Param.Action.RUN,0)
     46    ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
     47    ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
     48    ParamOut.NbSlice='one'; ...%nbre of slices, 'one' prevents splitting in several processes, ('off' by default)
     49    ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     50    ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     51    ParamOut.FieldTransform = 'off';...%can use a transform function
     52    ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
     53    ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
     54    ParamOut.OutputDirExt='';%set the output dir extension
     55    if size(Param.InputTable,1)>1
     56        msgbox_uvmat('WARNING', 'this function acts only on the first input file line')
     57    end
     58return
     59end
     60
     61ParamOut=[];
     62%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
     63%% read input parameters from an xml file if input is a file name (batch mode)
     64checkrun=1;
    6965if ischar(Param)
    70         Param=xml2struct(Param);
    71         checkrun=0;
    72 % RUN case: parameters introduced as the input structure Param
    73 else
    74     hseries=guidata(Param.hseries);%handles of the GUI series
    75     if isfield(Param,'Specific')&& strcmp(Param.Specific,'?')
    76         checkrun=1;% will only search interactive input parameters (preparation of BATCH mode)
    77     else
    78         checkrun=2; % indicate the RUN option is used
    79     end
    80 end
    81 ParamOut=Param; %default output
     66    Param=xml2struct(Param);% read Param as input file (batch case)
     67    checkrun=0;
     68end
    8269
    8370%% root input file(s) and type
     
    9481% numbers of slices and file indices
    9582
    96 NbSlice=1;%default
    97 if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
    98     NbSlice=Param.IndexRange.NbSlice;
    99 end
    100 nbview=numel(i1_series);%number of input file series (lines in InputTable)
    10183nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
    10284nbfield_i=size(i1_series{1},2); %nb of fields for the i index
    10385nbfield=nbfield_j*nbfield_i; %total number of fields
    104 nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
    105 nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
    10686
    10787%determine the file type on each line from the first input file
    10888ImageTypeOptions={'image','multimage','mmreader','video'};
    109 NcTypeOptions={'netcdf','civx','civdata'};
    110 for iview=1:nbview
    111     if ~exist(filecell{iview,1}','file')
    112         msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
    113         return
    114     end
    115     [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
    116     CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
    117     CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
    118     if ~isempty(j1_series{iview})
    119         frame_index{iview}=j1_series{iview};
    120     else
    121         frame_index{iview}=i1_series{iview};
    122     end
    123 end
     89
     90if ~exist(filecell{1,1}','file')
     91    msgbox_uvmat('ERROR',['the first input file ' filecell{1,1} ' does not exist'])
     92    return
     93end
     94[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
     95CheckImage=~isempty(find(strcmp(FileType{1},ImageTypeOptions)));% =1 for images
     96
    12497
    12598%% calibration data and timing: read the ImaDoc files
     
    128101itime=0;
    129102NbSlice_calib={};
    130 XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
    131 for iview=1:nbview%Loop on views
    132     SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
    133     filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
     103
     104SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
     105filexml=[fullfile(RootPath{1},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
     106if ~exist(filexml,'file')
     107    filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.xml']; % old convention: xml inside the image folder
    134108    if ~exist(filexml,'file')
    135         filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
     109        filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.civ']; % very old convention: .civ file
    136110        if ~exist(filexml,'file')
    137             filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
    138             if ~exist(filexml,'file')
    139                 filexml='';
    140             end
    141         end
    142     end
    143     if ~isempty(filexml)
    144         [XmlData{iview},error]=imadoc2struct_special(filexml);
    145     end
    146     if isfield(XmlData{iview},'Time')
    147         itime=itime+1;
    148         timecell{itime}=XmlData{iview}.Time;
    149     end
    150     if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
    151         NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
    152         if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
    153             msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    154         end
     111            filexml='';
     112        end
     113    end
     114end
     115if ~isempty(filexml)
     116    [XmlData,error]=imadoc2struct_special(filexml);
     117end
     118if isfield(XmlData,'Time')
     119    itime=itime+1;
     120    timecell{itime}=XmlData.Time;
     121end
     122if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
     123    NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
     124    if ~isequal(NbSlice_calib{1},NbSlice_calib{1})
     125        msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    155126    end
    156127end
     
    164135 % EDIT FROM HERE
    165136
    166 %% check the validity of  input file types
    167 if CheckImage{1}
    168     FileExtOut='.png'; % write result as .png images for image inputs
    169 elseif CheckNc{1}
    170     FileExtOut='.nc';% write result as .nc files for netcdf inputs
    171 else
    172     msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
    173     return
    174 end
    175 if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
    176         msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
    177     return
    178 end
    179 % NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
    180 % if NbSlice~=nbfield_j
    181 %     answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
    182 %     if ~strcmp(answer,'Yes')
    183 %         return
    184 %     end
    185 % end
    186137
    187138%% Set field names and velocity types
     
    194145display('RDvision system')
    195146first_label=0; %image numbers start from 0
    196 if ~strcmp(NomType{1},'_000001')
     147if ~CheckImage || ~strcmp(NomType{1},'_000001')
    197148    msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation
    198149    return
     
    206157%% copy and adapt the xml file
    207158NomTypeNew='_1_1';
    208 if ~isempty(XmlData{1})
     159if ~isempty(XmlData)
    209160        t=xmltree(filexml);
    210161       
     
    233184       
    234185        %%%% correction RDvision %%%%
    235         if isfield(XmlData{1},'NbDtj')
     186        if isfield(XmlData,'NbDtj')
    236187            uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
    237188            uid_value=children(t,uid_NbDtj);
    238189            if ~isempty(uid_value)
    239                 t=set(t,uid_value(1),'value',num2str(XmlData{1}.NbDtj));
    240             end
    241         end
    242         if isfield(XmlData{1},'NbDtk')
     190                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
     191            end
     192        end
     193        if isfield(XmlData,'NbDtk')
    243194            uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
    244195            uid_value=children(t,uid_NbDtk);
    245196            if ~isempty(uid_value)
    246                 t=set(t,uid_value(1),'value',num2str(XmlData{1}.NbDtk));
    247             end
    248         end
    249         if isempty(j1_series{1}) && isfield(XmlData{1},'NbDti')
     197                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
     198            end
     199        end
     200        if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
    250201            uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
    251             t=add(t,uid_Dti,'chardata',num2str(XmlData{1}.Dti));
     202            t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
    252203            uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
    253             t=add(t,uid_NbDti,'chardata',num2str(XmlData{1}.NbDti));
     204            t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
    254205            uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
    255206            uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
     
    264215            SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
    265216    filexml_new=[fullfile(RootPath{1},SubDirBase) '.xml'];
    266         save(t,filexml_new)
     217       % save(t,filexml_new)
    267218end
    268219
    269220%% main loop on images
    270221%j1=[];%default
    271 nbfield2=size(XmlData{1}.Time,2);
     222nbfield2=size(XmlData.Time,2)
    272223for ifile=1:nbfield
    273224    if checkrun
    274         update_waitbar(hseries.Waitbar,ifile/nbfield)
    275         drawnow
    276         stopstate=get(hseries.RUN,'BusyAction');
     225        stopstate=get(Param.RUNHandle,'BusyAction');
     226        update_waitbar(Param.WaitbarHandle,ifile/nbfield)
    277227    else
    278228        stopstate='queue';
    279229    end
    280     if isequal(stopstate,'queue') % enable STOP command
    281         filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile));
    282         j1=mod(ifile-1+first_label,nbfield2)+1;
    283         i1=floor((ifile-1+first_label)/nbfield2)+1;
    284         filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1);
    285         try
    286             movefile(filename,filename_new);
    287             [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a')
    288             if ~s
    289                 msgbox_uvmat('ERROR',errormsg);
    290                 return
    291             end
    292         catch ME
    293             msgbox_uvmat('ERROR',ME.message);
     230    if ~isequal(stopstate,'queue')% enable STOP command
     231        break
     232    end
     233    filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile));
     234    j1=mod(ifile-1+first_label,nbfield2)+1;
     235    i1=floor((ifile-1+first_label)/nbfield2)+1;
     236    filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1);
     237    try
     238        movefile(filename,filename_new);
     239        [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a')
     240        if ~s
     241            msgbox_uvmat('ERROR',errormsg);
    294242            return
    295243        end
    296     end
     244    catch ME
     245        msgbox_uvmat('ERROR',ME.message);
     246        return
     247    end
     248   
    297249end
    298250
Note: See TracChangeset for help on using the changeset viewer.