Index: trunk/src/find_file_series.m
===================================================================
--- trunk/src/find_file_series.m	(revision 960)
+++ trunk/src/find_file_series.m	(revision 961)
@@ -77,189 +77,231 @@
 end
 if checkfileindexing
-NomTypePref='';
-if isempty(NomType)||strcmp(NomType,'*')
-    if exist(fullfileinput,'file')
-        [tild,RootFile]=fileparts(fileinput);% case of constant name (no indexing), get the filename without its extension
+    NomTypePref='';
+    if isempty(NomType)||strcmp(NomType,'*')
+        if exist(fullfileinput,'file')
+            [tild,RootFile]=fileparts(fileinput);% case of constant name (no indexing), get the filename without its extension
+        else
+            RootFile='';
+        end
     else
-        RootFile='';
-    end
-else
-    %% if checkxml=1, possibly include the first index in the root name, if there exists a corresponding xml file 
-    if ~exist('checkxml','var')||checkxml
-        r=regexp(NomType,'^(?<tiretnum>_|\d+)','names');%look for a number or _1 at the beginning of NomType
-        if ~isempty(r) %if NomType begins by a number or _1
-            fileinput_end=regexprep(fileinput,['^' RootFile],'');%remove RootFile at the beginning of fileinput
-            if isempty(regexp(r.tiretnum,'^_','once'))% if a separator '_' is not  detected
-                rr=regexp(fileinput_end,'^(?<i1>\d+)','names');
-            else% if a separator '_' is  detected
-                rr=regexp(fileinput_end,'^(?<i1>_\d+)','names');
-            end
-            if ~isempty(rr)
-                RootFile_i=[RootFile rr.i1];% new root file
-                %look for an xml file correspoonding to the new root name
-                if exist(fullfile(RootPath,SubDir,[RootFile_i '.xml']),'file') || (strcmp(FileExt,'.nc') && exist(fullfile(RootPath,[RootFile_i '.xml']),'file'))
-                    RootFile=RootFile_i;
-                    NomTypePref=r.tiretnum;
-                    NomType=regexprep(NomType,['^'  NomTypePref],'');
-                    i1_input=j1_input;
-                    i2_input=j2_input;
-                    j1_input=[];
-                    j2_input=[];
-                end
-            end
-        end
-    end
-    %% analyse the list of existing files when relevant
-    sep1='';
-    sep2='';
-    i1_str='(?<i1>)';%will set i1=[];
-    i1_star='';
-    i2_str='(?<i2>)';%will set i2=[];
-    i2_star='';
-    j1_str='(?<j1>)';%will set j1=[];
-    j1_star='';
-    j2_str='(?<j2>)';%will set j2=[];
-    j2_star='';
-    %Look for cases with letter indexing for the second index
-    r=regexp(NomType,'^(?<sep1>_?)(?<i1>\d+)(?<sep2>_?)(?<j1>[a|A])(?<j2>[b|B]?)$','names');
-    if ~isempty(r)
-        sep1=r.sep1;
-        sep2=r.sep2;
-        i1_str='(?<i1>\d+)';
-        i1_star='*';
-        if strcmp(lower(r.j1),r.j1)% lower case index
-            j1_str='(?<j1>[a-z])';
-        else
-           j1_str='(?<j1>[A-Z])'; % upper case index
-        end
-        j1_star='*';
-        if ~isempty(r.j2)
-           if strcmp(lower(r.j1),r.j1)
-            j2_str='(?<j2>[a-z])';
-            else
-           j2_str='(?<j2>[A-Z])'; 
-           end
-            j2_star='*';
-        end
-    else %numerical indexing
-        r=regexp(NomType,'^(?<sep1>_?)(?<i1>\d+)(?<i2>(-\d+)?)(?<j1>(_\d+)?)(?<j2>(-\d+)?)$','names');
+        %% if checkxml=1, possibly include the first index in the root name, if there exists a corresponding xml file
+        if ~exist('checkxml','var')||checkxml
+            r=regexp(NomType,'^(?<tiretnum>_|\d+)','names');%look for a number or _1 at the beginning of NomType
+            if ~isempty(r) %if NomType begins by a number or _1
+                fileinput_end=regexprep(fileinput,['^' RootFile],'');%remove RootFile at the beginning of fileinput
+                if isempty(regexp(r.tiretnum,'^_','once'))% if a separator '_' is not  detected
+                    rr=regexp(fileinput_end,'^(?<i1>\d+)','names');
+                else% if a separator '_' is  detected
+                    rr=regexp(fileinput_end,'^(?<i1>_\d+)','names');
+                end
+                if ~isempty(rr)
+                    RootFile_i=[RootFile rr.i1];% new root file
+                    %look for an xml file correspoonding to the new root name
+                    if exist(fullfile(RootPath,SubDir,[RootFile_i '.xml']),'file') || (strcmp(FileExt,'.nc') && exist(fullfile(RootPath,[RootFile_i '.xml']),'file'))
+                        RootFile=RootFile_i;
+                        NomTypePref=r.tiretnum;
+                        NomType=regexprep(NomType,['^'  NomTypePref],'');
+                        i1_input=j1_input;
+                        i2_input=j2_input;
+                        j1_input=[];
+                        j2_input=[];
+                    elseif exist([RootPath '.xml'],'file')% new convention with j indices in sub-folders level0, 1...
+                        rj=regexp(SubDir,'^level(?<j1>\d+)$','names');
+                        if ~isempty(rj)
+                            j1_input=rj.j1;
+                            NomType='level';
+                            [RootPath,SubDir]=fileparts(RootPath);
+                        end
+                    end
+                end
+            end
+        end
+        
+        %% analyse the list of existing files when relevant
+        sep1='';
+        sep2='';
+        i1_str='(?<i1>)';%will set i1=[];
+        i1_star='';
+        i2_str='(?<i2>)';%will set i2=[];
+        i2_star='';
+        j1_str='(?<j1>)';%will set j1=[];
+        j1_star='';
+        j2_str='(?<j2>)';%will set j2=[];
+        j2_star='';
+        %Look for cases with letter indexing for the second index
+        r=regexp(NomType,'^(?<sep1>_?)(?<i1>\d+)(?<sep2>_?)(?<j1>[a|A])(?<j2>[b|B]?)$','names');
         if ~isempty(r)
             sep1=r.sep1;
+            sep2=r.sep2;
             i1_str='(?<i1>\d+)';
             i1_star='*';
-            if ~isempty(r.i2)
-                i2_str='(?<i2>-\d+)';
-                i2_star='-*';
-            end
-            if ~isempty(r.j1)
-                j1_str='(?<j1>_\d+)';
-                j1_star='_*';
-            end
+            if strcmp(lower(r.j1),r.j1)% lower case index
+                j1_str='(?<j1>[a-z])';
+            else
+                j1_str='(?<j1>[A-Z])'; % upper case index
+            end
+            j1_star='*';
             if ~isempty(r.j2)
-                j2_str='(?<j2>-\d+)';
-                j2_star='-*';
-            end
-        end
-    end
-    detect_string=['^' RootFile sep1 i1_str i2_str sep2 j1_str j2_str FileExt '$'];%string used in regexp to detect file indices
-    %find the string used to extract the relevant files with the command dir
-    star_string=[RootFile sep1 i1_star i2_star sep2 j1_star j2_star FileExt];
-    wd=pwd;%current working directory
-    cd (FilePath)% move to the local dir to save time in the operation dir.
-    dirpair=dir(star_string);% look for relevant files in the file directory
-    cd(wd)
-    nbpair=numel(dirpair);
-    ref_i_list=zeros(1,nbpair);
-    ref_j_list=zeros(1,nbpair);
-    if nbpair==0% no detected file
-        RootFile='';
-    end
-    % scan the list of relevant files, extract the indices
-    for ifile=1:nbpair
-        rr=regexp(dirpair(ifile).name,detect_string,'names');
-        if ~isempty(rr)
-            i1=str2num(rr.i1);
-            i2=str2num(regexprep(rr.i2,'^-',''));
-            j1=stra2num(regexprep(rr.j1,'^_',''));
-            j2=stra2num(regexprep(rr.j2,'^-',''));
-            ref_i=i1;
-            if isempty(i2_input)
-                if ~isempty(i2)% invalid file name if i2 does not exist in the input file
-                    break
-                end
+                if strcmp(lower(r.j1),r.j1)
+                    j2_str='(?<j2>[a-z])';
+                else
+                    j2_str='(?<j2>[A-Z])';
+                end
+                j2_star='*';
+            end
+        else %numerical indexing
+            r=regexp(NomType,'^(?<sep1>_?)(?<i1>\d+)(?<i2>(-\d+)?)(?<j1>(_\d+)?)(?<j2>(-\d+)?)$','names');
+            if ~isempty(r)
+                sep1=r.sep1;
+                i1_str='(?<i1>\d+)';
+                i1_star='*';
+                if ~isempty(r.i2)
+                    i2_str='(?<i2>-\d+)';
+                    i2_star='-*';
+                end
+                if ~isempty(r.j1)
+                    j1_str='(?<j1>_\d+)';
+                    j1_star='_*';
+                end
+                if ~isempty(r.j2)
+                    j2_str='(?<j2>-\d+)';
+                    j2_star='-*';
+                end
+            end
+        end
+        if strcmp(NomType,'level')
+            star_string=[RootFile '*' FileExt];
+            detect_string=['^' RootFile '(?<i1>\d+)' FileExt '$'];%string used in regexp to detect file indices
+             wd=pwd;%current working directory
+            cd (FilePath)% move to the local dir to save time in the operation dir.
+            dirpair=dir(star_string);% look for relevant files in the file directory
+            cd(wd)
+            nbpair=numel(dirpair);
+            i1_series=zeros(1,nbpair);
+            if nbpair==0% no detected file
+                RootFile='';
+            end
+            % scan the list of relevant files, extract the indices
+            for ifile=1:nbpair
+                rr=regexp(dirpair(ifile).name,detect_string,'names');
+                if ~isempty(rr)
+                    i1_series(ifile)=str2num(rr.i1);                 
+                end
+            end
+            % look for the list of subfolders level#
+            cd (fullfile(RootPath,SubDir))% move to the local dir to save time in the operation dir.
+            dirpair=dir('level*');% look for relevant files in the file directory
+            cd(wd)
+            nbpair=numel(dirpair);
+            jfile=0;
+            for ifile=1:nbpair
+                rr=regexp(dirpair(ifile).name,'^level(?<i1>\d+)$','names');
+                if ~isempty(rr)
+                    jfile=jfile+1;
+                    j1_series(jfile)=str2num(rr.i1);              
+                end
+            end
+            [i1_series,j1_series]=meshgrid(i1_series,j1_series);
+            i1_series=reshape(i1_series,1,[]);
+            j1_series=reshape(j1_series,1,[]);
+        else
+            detect_string=['^' RootFile sep1 i1_str i2_str sep2 j1_str j2_str FileExt '$'];%string used in regexp to detect file indices
+            %find the string used to extract the relevant files with the command dir
+            star_string=[RootFile sep1 i1_star i2_star sep2 j1_star j2_star FileExt];
+            wd=pwd;%current working directory
+            cd (FilePath)% move to the local dir to save time in the operation dir.
+            dirpair=dir(star_string);% look for relevant files in the file directory
+            cd(wd)
+            nbpair=numel(dirpair);
+            ref_i_list=zeros(1,nbpair);
+            ref_j_list=zeros(1,nbpair);
+            if nbpair==0% no detected file
+                RootFile='';
+            end
+            % scan the list of relevant files, extract the indices
+            for ifile=1:nbpair
+                rr=regexp(dirpair(ifile).name,detect_string,'names');
+                if ~isempty(rr)
+                    i1=str2num(rr.i1);
+                    i2=str2num(regexprep(rr.i2,'^-',''));
+                    j1=stra2num(regexprep(rr.j1,'^_',''));
+                    j2=stra2num(regexprep(rr.j2,'^-',''));
+                    ref_i=i1;
+                    if isempty(i2_input)
+                        if ~isempty(i2)% invalid file name if i2 does not exist in the input file
+                            break
+                        end
+                    else
+                        ref_i=floor((i1+i2)/2);
+                    end
+                    ref_j=1;
+                    if isempty(j1_input)
+                        if  ~isempty(j1)% invalid file name if j1 does not exist in the input file
+                            break
+                        end
+                    else %j1_input is not empty
+                        if isempty(j1)% the detected name does not fit with the input
+                            break
+                        else
+                            ref_j=j1;
+                            if isempty(j2_input)
+                                if  ~isempty(j2)% invalid file name if j2 does not exist in the input file
+                                    break
+                                end
+                            else
+                                ref_j=floor((j1+j2)/2);
+                            end
+                        end
+                    end
+                    % update the detected index series
+                    if ~isempty(ref_i)&&~isempty(ref_j)
+                        ref_i_list(ifile)=ref_i;
+                        ref_j_list(ifile)=ref_j;
+                        nb_pairs=0;
+                        if ~isempty(i2_input)|| ~isempty(j2_input) %deals with  pairs
+                            if size(i1_series,1)>=ref_i+1 && size(i1_series,2)>=ref_j+1
+                                nb_pairs=numel(find(i1_series(ref_i+1,ref_j+1,:)~=0));
+                            end
+                        end
+                        if i1==0
+                            i1=-1;% set index 0 to -1 to distinguish from the absent index (set to 0)
+                        end
+                        if j1==0
+                            j1=-1;% set index 0 to -1 to distinguish from the absent index (set to 0)
+                        end
+                        i1_series(ref_i+1,ref_j+1,nb_pairs+1)=i1;
+                        if ~isempty(i2_input)
+                            i2_series(ref_i+1,ref_j+1,nb_pairs+1)=i2;
+                        end
+                        if ~isempty(j1_input)
+                            j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1;
+                        end
+                        if ~isempty(j2_input)
+                            j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1;
+                            j2_series(ref_i+1,ref_j+1,nb_pairs+1)=j2;
+                        end
+                    end
+                end
+            end
+            % look for the numerical string of the first files to update the NomType (take into account the 0 before the number)
+            max_j=max(ref_j_list);
+            if isempty(max_j)
+                ref_ij=ref_i_list;
             else
-                ref_i=floor((i1+i2)/2);
-            end
-            ref_j=1;
-            if isempty(j1_input)
-                if  ~isempty(j1)% invalid file name if j1 does not exist in the input file
-                    break
-                end
-            else %j1_input is not empty
-                if isempty(j1)% the detected name does not fit with the input
-                    break
-                else
-                    ref_j=j1;
-                    if isempty(j2_input)
-                        if  ~isempty(j2)% invalid file name if j2 does not exist in the input file
-                            break
-                        end
-                    else
-                        ref_j=floor((j1+j2)/2);
-                    end
-                end
-            end
-            % update the detected index series
-            if ~isempty(ref_i)&&~isempty(ref_j)
-                ref_i_list(ifile)=ref_i;
-                ref_j_list(ifile)=ref_j;
-                nb_pairs=0;
-                if ~isempty(i2_input)|| ~isempty(j2_input) %deals with  pairs
-                    if size(i1_series,1)>=ref_i+1 && size(i1_series,2)>=ref_j+1
-                        nb_pairs=numel(find(i1_series(ref_i+1,ref_j+1,:)~=0));
-                    end
-                end
-                if i1==0
-                    i1=-1;% set index 0 to -1 to distinguish from the absent index (set to 0)
-                end
-                if j1==0
-                    j1=-1;% set index 0 to -1 to distinguish from the absent index (set to 0)
-                end
-                i1_series(ref_i+1,ref_j+1,nb_pairs+1)=i1;
-                if ~isempty(i2_input)
-                    i2_series(ref_i+1,ref_j+1,nb_pairs+1)=i2;
-                end
-                if ~isempty(j1_input)
-                    j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1;
-                end
-                if ~isempty(j2_input)
-                    j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1;
-                    j2_series(ref_i+1,ref_j+1,nb_pairs+1)=j2;
-                end
-            end
-        end
-    end
-    % look for the numerical string of the first files to update the NomType (take into account the 0 before the number)
-    max_j=max(ref_j_list);
-    if isempty(max_j)
-        ref_ij=ref_i_list;
-    else
-        ref_ij=ref_i_list*max_j+ref_j_list; % ordered by index i, then by j for a given i.
-    end
-    ind_select=find(ref_ij>0);
-    
-    if isempty(ind_select)
-%         RootFile='';
-%         NomType='';
-    else
-        [tild,ifile_min]=min(ref_ij(ind_select));
-        [tild,tild,tild,tild,tild,tild,tild,tild,NomType]=fileparts_uvmat(dirpair(ind_select(ifile_min)).name);% update the representation of indices (number of 0 before the number)
-        NomType=regexprep(NomType,['^' NomTypePref],'');
-        %% update the file type if the input file does not exist (pb of 0001)
-        if isempty(FileInfo.FileType)
-            [FileInfo,MovieObject]=get_file_info(fullfile(FilePath,dirpair(ifile_min).name));
-        end
-    end
-end
+                ref_ij=ref_i_list*max_j+ref_j_list; % ordered by index i, then by j for a given i.
+            end
+            ind_select=find(ref_ij>0);
+            
+            if ~isempty(ind_select)
+                [tild,ifile_min]=min(ref_ij(ind_select));
+                [tild,tild,tild,tild,tild,tild,tild,tild,NomType]=fileparts_uvmat(dirpair(ind_select(ifile_min)).name);% update the representation of indices (number of 0 before the number)
+                NomType=regexprep(NomType,['^' NomTypePref],'');
+                %% update the file type if the input file does not exist (pb of 0001)
+                if isempty(FileInfo.FileType)
+                    [FileInfo,MovieObject]=get_file_info(fullfile(FilePath,dirpair(ifile_min).name));
+                end
+            end
+        end
+    end
 
 %% set to empty array the irrelevant index series
Index: trunk/src/fullfile_uvmat.m
===================================================================
--- trunk/src/fullfile_uvmat.m	(revision 960)
+++ trunk/src/fullfile_uvmat.m	(revision 961)
@@ -76,5 +76,5 @@
 end
 if isequal(i1,i2)
-    i2=[];% suppress the secodn index if equal to the first
+    i2=[];% suppress the second index if equal to the first
 end
 if ~exist('i1','var') 
@@ -93,48 +93,51 @@
 
 %% look for NomType with pairs (separator '-' or terminasion ab or AB
-if ~isempty(regexp(NomType,'^_\d'))
-    sep1='_';
-    NomType(1)=[];%remove '_' from the beginning of NomType
-end
-r=regexp(NomType,'^(?<num1>\d+)','names');%look for a number at the beginning of NomType
-if ~isempty(r)
-    i1_str=num2str(i1,['%0' num2str(length(r.num1)) 'd']);
-    NomType=regexprep(NomType,['^' r.num1],'');   
-    r=regexp(NomType,'^-(?<num2>\d+)','names');%look for a pair i1-i2
-    if ~isempty(r)
-         if ~isempty(i2)
-        sep2='-';
-         i2_str=num2str(i2,['%0' num2str(length(r.num2)) 'd']);
-         end
-         NomType=regexprep(NomType,['^-' r.num2],'');
-    end
-    if ~isempty(regexp(NomType,'^_'));
-        sep3='_';
+if strcmp(NomType,'level')% organisation with a sub-folder for the files of each index i
+    filename=fullfile(RootPath,SubDir,['level' num2str(j1)],[RootFile num2str(i1) FileExt]);
+else
+    if ~isempty(regexp(NomType,'^_\d'))
+        sep1='_';
         NomType(1)=[];%remove '_' from the beginning of NomType
     end
-    if ~isempty(regexp(NomType,'^[a|A]'));
-        j1_str=num2stra(j1,NomType);
-        if ~isempty(regexp(NomType,'[b|B]$'))&& ~isempty(j2);
-            j2_str=num2stra(j2,NomType);
+    r=regexp(NomType,'^(?<num1>\d+)','names');%look for a number at the beginning of NomType
+    if ~isempty(r)
+        i1_str=num2str(i1,['%0' num2str(length(r.num1)) 'd']);
+        NomType=regexprep(NomType,['^' r.num1],'');
+        r=regexp(NomType,'^-(?<num2>\d+)','names');%look for a pair i1-i2
+        if ~isempty(r)
+            if ~isempty(i2)
+                sep2='-';
+                i2_str=num2str(i2,['%0' num2str(length(r.num2)) 'd']);
+            end
+            NomType=regexprep(NomType,['^-' r.num2],'');
         end
-    else
-        r=regexp(NomType,'^(?<num3>\d+)','names');
-        if ~isempty(r)
-            j1_str=num2str(j1,['%0' num2str(length(r.num3)) 'd']);
-            NomType=regexprep(NomType,['^' r.num3],'');
+        if ~isempty(regexp(NomType,'^_'));
+            sep3='_';
+            NomType(1)=[];%remove '_' from the beginning of NomType
         end
-        if ~isempty(j2) 
-        r=regexp(NomType,'-(?<num4>\d+)','names');
-        if ~isempty(r)
-            sep4='-';
-            j2_str=num2str(j2,['%0' num2str(length(r.num4)) 'd']);
-        end
+        if ~isempty(regexp(NomType,'^[a|A]'));
+            j1_str=num2stra(j1,NomType);
+            if ~isempty(regexp(NomType,'[b|B]$'))&& ~isempty(j2);
+                j2_str=num2stra(j2,NomType);
+            end
+        else
+            r=regexp(NomType,'^(?<num3>\d+)','names');
+            if ~isempty(r)
+                j1_str=num2str(j1,['%0' num2str(length(r.num3)) 'd']);
+                NomType=regexprep(NomType,['^' r.num3],'');
+            end
+            if ~isempty(j2)
+                r=regexp(NomType,'-(?<num4>\d+)','names');
+                if ~isempty(r)
+                    sep4='-';
+                    j2_str=num2str(j2,['%0' num2str(length(r.num4)) 'd']);
+                end
+            end
         end
     end
+    filename=fullfile(RootPath,SubDir,RootFile);
+    filename=[filename sep1 i1_str sep2 i2_str sep3 j1_str sep4 j2_str];
+    filename=[regexprep(filename,'_$','') FileExt];%suppress possible '_' at the end of the string and add the extension
 end
-filename=fullfile(RootPath,SubDir,RootFile);
-filename=[filename sep1 i1_str sep2 i2_str sep3 j1_str sep4 j2_str];
-filename=[regexprep(filename,'_$','') FileExt];%suppress possible '_' at the end of the string and add the extension
-
 
 function test
Index: trunk/src/proj_field.m
===================================================================
--- trunk/src/proj_field.m	(revision 960)
+++ trunk/src/proj_field.m	(revision 961)
@@ -1642,4 +1642,5 @@
                     % determine the boundaries of the projected field,
                     % first find the 8 summits of the initial volume in the
+                    Angle=ObjectData.Angle*pi/180;
                     % new coordinates
                     Coord{1}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});%initial z coordinates
@@ -1651,5 +1652,5 @@
                     summit(1:2,5:8)=summit(1:2,1:4);
                     summit(3,:)=[Coord{1}(1)*ones(1,4) Coord{1}(end)*ones(1,4)];
-                    Mrot=rodrigues(PlaneAngle);
+                    %Mrot_inv=rodrigues(-PlaneAngle);
                     newsummit=zeros(3,8);% initialize the rotated summit coordinates
                     ObjectData.Coord=ObjectData.Coord';
@@ -1657,18 +1658,34 @@
                     ObjectData.Coord=[ObjectData.Coord; 0];%add z origin at z=0 by default
                     end
+                    M2=[cos(Angle(2)) sin(Angle(2)) 0;-sin(Angle(2)) cos(Angle(2)) 0;0 0 1];
+                    M1=[1 0 0;0 cos(Angle(1)) sin(Angle(1));0 -sin(Angle(1)) cos(Angle(1))];
+                    M=M1*M2;
+                    M_inv=inv(M);
+                    
                     for isummit=1:8% TODO: introduce a function for rotation of n points (to use also for scattered data)
-                        newsummit(:,isummit)=Mrot*(summit(:,isummit)-(ObjectData.Coord));
+                        newsummit(:,isummit)=M*(summit(:,isummit)-(ObjectData.Coord));
                     end
                     coord_x_proj=min(newsummit(1,:)):InterpMesh: max(newsummit(1,:));% set of coordinqtes in the projection plane
                     coord_y_proj=min(newsummit(2,:)):InterpMesh: max(newsummit(2,:));
                     coord_z_proj=-width:width;
-                    Mrot_inverse=rodrigues(-PlaneAngle);% inverse rotation matrix
-                    Origin=Mrot_inverse*[coord_x_proj(1);coord_y_proj(1);coord_z_proj(1)]+ObjectData.Coord;
+                    %Mrot=rodrigues(PlaneAngle);% inverse rotation matrix
+                    Origin=M_inv*[coord_x_proj(1);coord_y_proj(1);coord_z_proj(1)]+ObjectData.Coord;
                     npx=numel(coord_x_proj);
                     npy=numel(coord_y_proj);
                     npz=numel(coord_z_proj);
-                    ix=Mrot_inverse*[coord_x_proj(end)-coord_x_proj(1);0;0]/(npx-1);% unit vector along the new x coordinates
-                    iy=Mrot_inverse*[0;coord_y_proj(end)-coord_y_proj(1);0]/(npy-1);% unit vector y coordinates
-                    iz=Mrot_inverse*[0;0;coord_z_proj(end)-coord_z_proj(1)]/(npz-1);% x unit vector z coordinates
+                    
+                    %modangle=sqrt(PlaneAngle(1)*PlaneAngle(1)+PlaneAngle(2)*PlaneAngle(2));
+%                     cosphi=PlaneAngle(1)/modangle;
+%                     sinphi=PlaneAngle(2)/modangle;
+                    iX=[coord_x_proj(end)-coord_x_proj(1);0;0]/(npx-1);
+                    iY=[0;coord_y_proj(end)-coord_y_proj(1);0]/(npy-1);
+                    iZ=[0;0;coord_z_proj(end)-coord_z_proj(1)]/(npz-1);
+%                     iX(1:2)=[cosphi -sinphi;sinphi cosphi]*iX(1:2);
+%                     iY(1:2)=[-cosphi -sinphi;sinphi cosphi]*iY(1:2);
+                    
+                    ix=M_inv*iX;%  vector along the new x coordinates transformed into old coordinates
+                    iy=M_inv*iY;% vector along y coordinates
+                    iz=M_inv*iZ;% vector along z coordinates
+
                     [Grid_x,Grid_y,Grid_z]=meshgrid(0:npx-1,0:npy-1,0:npz-1);
                     if ismatrix(Grid_x)% add a singleton in case of a single z value
@@ -1680,8 +1697,5 @@
                     YI=Origin(2)+ix(2)*Grid_x+iy(2)*Grid_y+iz(2)*Grid_z;
                     ZI=Origin(3)+ix(3)*Grid_x+iy(3)*Grid_y+iz(3)*Grid_z;
-                   [X,Y,Z]=meshgrid(Coord{3},Coord{2},Coord{1});
-%                     X=permute(X,[3 1 2]);
-%                     Y=permute(Y,[3 1 2]);
-%                     Z=permute(Z,[3 1 2]);
+                   [X,Y,Z]=meshgrid(Coord{3},Coord{2},Coord{1});% mesh in the initial coordinates
                     for ivar=VarIndex
                             VarName=FieldData.ListVarName{ivar};
Index: trunk/src/rodrigues.m
===================================================================
--- trunk/src/rodrigues.m	(revision 961)
+++ trunk/src/rodrigues.m	(revision 961)
@@ -0,0 +1,273 @@
+function	[out,dout]=rodrigues(in)
+
+% RODRIGUES	Transform rotation matrix into rotation vector and viceversa.
+%		
+%		Sintax:  [OUT]=RODRIGUES(IN)
+% 		If IN is a 3x3 rotation matrix then OUT is the
+%		corresponding 3x1 rotation vector
+% 		if IN is a rotation 3-vector then OUT is the 
+%		corresponding 3x3 rotation matrix
+%
+
+%%
+%%		Copyright (c) March 1993 -- Pietro Perona
+%%		California Institute of Technology
+%%
+
+%% ALL CHECKED BY JEAN-YVES BOUGUET, October 1995.
+%% FOR ALL JACOBIAN MATRICES !!! LOOK AT THE TEST AT THE END !!
+
+%% BUG when norm(om)=pi fixed -- April 6th, 1997;
+%% Jean-Yves Bouguet
+
+%% Add projection of the 3x3 matrix onto the set of special ortogonal matrices SO(3) by SVD -- February 7th, 2003;
+%% Jean-Yves Bouguet
+
+% BUG FOR THE CASE norm(om)=pi fixed by Mike Burl on Feb 27, 2007
+
+
+[m,n] = size(in);
+%bigeps = 10e+4*eps;
+bigeps = 10e+20*eps;
+
+if ((m==1) & (n==3)) | ((m==3) & (n==1)) %% it is a rotation vector
+    theta = norm(in);
+    if theta < eps
+        R = eye(3);
+
+        %if nargout > 1,
+
+        dRdin = [0 0 0;
+            0 0 1;
+            0 -1 0;
+            0 0 -1;
+            0 0 0;
+            1 0 0;
+            0 1 0;
+            -1 0 0;
+            0 0 0];
+
+        %end;
+
+    else
+        if n==length(in)  in=in'; end; 	%% make it a column vec. if necess.
+
+        %m3 = [in,theta]
+
+        dm3din = [eye(3);in'/theta];
+
+        omega = in/theta;
+
+        %m2 = [omega;theta]
+
+        dm2dm3 = [eye(3)/theta -in/theta^2; zeros(1,3) 1];
+
+        alpha = cos(theta);
+        beta = sin(theta);
+        gamma = 1-cos(theta);
+        omegav=[[0 -omega(3) omega(2)];[omega(3) 0 -omega(1)];[-omega(2) omega(1) 0 ]];
+        A = omega*omega';
+
+        %m1 = [alpha;beta;gamma;omegav;A];
+
+        dm1dm2 = zeros(21,4);
+        dm1dm2(1,4) = -sin(theta);
+        dm1dm2(2,4) = cos(theta);
+        dm1dm2(3,4) = sin(theta);
+        dm1dm2(4:12,1:3) = [0 0 0 0 0 1 0 -1 0;
+            0 0 -1 0 0 0 1 0 0;
+            0 1 0 -1 0 0 0 0 0]';
+
+        w1 = omega(1);
+        w2 = omega(2);
+        w3 = omega(3);
+
+        dm1dm2(13:21,1) = [2*w1;w2;w3;w2;0;0;w3;0;0];
+        dm1dm2(13: 21,2) = [0;w1;0;w1;2*w2;w3;0;w3;0];
+        dm1dm2(13:21,3) = [0;0;w1;0;0;w2;w1;w2;2*w3];
+
+        R = eye(3)*alpha + omegav*beta + A*gamma;
+
+        dRdm1 = zeros(9,21);
+
+        dRdm1([1 5 9],1) = ones(3,1);
+        dRdm1(:,2) = omegav(:);
+        dRdm1(:,4:12) = beta*eye(9);
+        dRdm1(:,3) = A(:);
+        dRdm1(:,13:21) = gamma*eye(9);
+
+        dRdin = dRdm1 * dm1dm2 * dm2dm3 * dm3din;
+
+
+    end;
+    out = R;
+    dout = dRdin;
+
+    %% it is prob. a rot matr.
+elseif ((m==n) & (m==3) & (norm(in' * in - eye(3)) < bigeps)...
+        & (abs(det(in)-1) < bigeps))
+    R = in;
+
+    % project the rotation matrix to SO(3);
+    [U,S,V] = svd(R);
+    R = U*V';
+
+    tr = (trace(R)-1)/2;
+    dtrdR = [1 0 0 0 1 0 0 0 1]/2;
+    theta = real(acos(tr));
+
+
+    if sin(theta) >= 1e-4,
+
+        dthetadtr = -1/sqrt(1-tr^2);
+
+        dthetadR = dthetadtr * dtrdR;
+        % var1 = [vth;theta];
+        vth = 1/(2*sin(theta));
+        dvthdtheta = -vth*cos(theta)/sin(theta);
+        dvar1dtheta = [dvthdtheta;1];
+
+        dvar1dR =  dvar1dtheta * dthetadR;
+
+
+        om1 = [R(3,2)-R(2,3), R(1,3)-R(3,1), R(2,1)-R(1,2)]';
+
+        dom1dR = [0 0 0 0 0 1 0 -1 0;
+            0 0 -1 0 0 0 1 0 0;
+            0 1 0 -1 0 0 0 0 0];
+
+        % var = [om1;vth;theta];
+        dvardR = [dom1dR;dvar1dR];
+
+        % var2 = [om;theta];
+        om = vth*om1;
+        domdvar = [vth*eye(3) om1 zeros(3,1)];
+        dthetadvar = [0 0 0 0 1];
+        dvar2dvar = [domdvar;dthetadvar];
+
+
+        out = om*theta;
+        domegadvar2 = [theta*eye(3) om];
+
+        dout = domegadvar2 * dvar2dvar * dvardR;
+
+
+    else
+        if tr > 0; 			% case norm(om)=0;
+
+            out = [0 0 0]';
+
+            dout = [0 0 0 0 0 1/2 0 -1/2 0;
+                0 0 -1/2 0 0 0 1/2 0 0;
+                0 1/2 0 -1/2 0 0 0 0 0];
+        else
+
+            % case norm(om)=pi;
+            if(0)
+
+                %% fixed April 6th by Bouguet -- not working in all cases!
+                out = theta * (sqrt((diag(R)+1)/2).*[1;2*(R(1,2:3)>=0)'-1]);
+                %keyboard;
+
+            else
+
+                % Solution by Mike Burl on Feb 27, 2007
+                % This is a better way to determine the signs of the
+                % entries of the rotation vector using a hash table on all
+                % the combinations of signs of a pairs of products (in the
+                % rotation matrix)
+
+                % Define hashvec and Smat
+                hashvec = [0; -1; -3; -9; 9; 3; 1; 13; 5; -7; -11];
+                Smat = [1,1,1; 1,0,-1; 0,1,-1; 1,-1,0; 1,1,0; 0,1,1; 1,0,1; 1,1,1; 1,1,-1;
+                    1,-1,-1; 1,-1,1];
+
+                M = (R+eye(3,3))/2;
+                uabs = sqrt(M(1,1));
+                vabs = sqrt(M(2,2));
+                wabs = sqrt(M(3,3));
+
+                mvec = ([M(1,2), M(2,3), M(1,3)] + [M(2,1), M(3,2), M(3,1)])/2;
+                syn  = ((mvec > eps) - (mvec < -eps)); % robust sign() function
+                hash = syn * [9; 3; 1];
+                idx = find(hash == hashvec);
+                svec = Smat(idx,:)';
+
+                out = theta * [uabs; vabs; wabs] .* svec;
+
+            end;
+
+            if nargout > 1,
+                fprintf(1,'WARNING!!!! Jacobian domdR undefined!!!\n');
+                dout = NaN*ones(3,9);
+            end;
+        end;
+    end;
+
+else
+    error('Neither a rotation matrix nor a rotation vector were provided');
+end;
+
+return;
+
+%% test of the Jacobians:
+
+%% TEST OF dRdom:
+om = randn(3,1);
+dom = randn(3,1)/1000000;
+[R1,dR1] = rodrigues(om);
+R2 = rodrigues(om+dom);
+R2a = R1 + reshape(dR1 * dom,3,3);
+gain = norm(R2 - R1)/norm(R2 - R2a)
+
+%% TEST OF dOmdR:
+om = randn(3,1);
+R = rodrigues(om);
+dom = randn(3,1)/10000;
+dR = rodrigues(om+dom) - R;
+
+[omc,domdR] = rodrigues(R);
+[om2] = rodrigues(R+dR);
+om_app = omc + domdR*dR(:);
+gain = norm(om2 - omc)/norm(om2 - om_app)
+
+
+%% OTHER BUG: (FIXED NOW!!!)
+omu = randn(3,1);   
+omu = omu/norm(omu)
+om = pi*omu;        
+[R,dR]= rodrigues(om);
+[om2] = rodrigues(R);
+[om om2]
+
+%% NORMAL OPERATION
+om = randn(3,1);         
+[R,dR]= rodrigues(om);
+[om2] = rodrigues(R);
+[om om2]
+
+%% Test: norm(om) = pi
+u = randn(3,1);
+u = u / sqrt(sum(u.^2));
+om = pi*u;
+R = rodrigues(om);
+R2 = rodrigues(rodrigues(R));
+norm(R - R2)
+
+%% Another test case where norm(om)=pi from Chen Feng (June 27th, 2014)
+R = [-0.950146567583153 -6.41765854280073e-05 0.311803617668748; ...
+     -6.41765854277654e-05 -0.999999917385145 -0.000401386434914383; ...
+      0.311803617668748 -0.000401386434914345 0.950146484968298];
+om = rodrigues(R)
+norm(om) - pi
+
+%% Another test case where norm(om)=pi from äœæä¹ (July 1st, 2014)
+R = [-0.999920129411407	-6.68593208347372e-05	-0.0126384464118876; ...
+     9.53007036072085e-05	-0.999997464662094	-0.00224979713751896; ...
+    -0.0126382639492467	-0.00225082189773293	0.999917600647740];
+om = rodrigues(R)
+norm(om) - pi
+
+
+
+
Index: trunk/src/set_object.m
===================================================================
--- trunk/src/set_object.m	(revision 960)
+++ trunk/src/set_object.m	(revision 961)
@@ -163,5 +163,5 @@
          set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
          set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
-         set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
+%         set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
 %     end
 end
@@ -288,5 +288,5 @@
 set(handles.num_Angle_1,'Visible','off')
 set(handles.num_Angle_2,'Visible','off')
-set(handles.num_Angle_3,'Visible','off')
+%set(handles.num_Angle_3,'Visible','off')
 set(handles.num_RangeX_1,'Visible','off')
 set(handles.num_RangeX_2,'Visible','off')
@@ -329,5 +329,5 @@
         set(handles.num_RangeY_2,'TooltipString',['num_RangeY_2: half width of the ' ObjectStyle])
     case {'plane','plane_z'}  
-        set(handles.num_Angle_3,'Visible','on')
+%        set(handles.num_Angle_3,'Visible','on')
         set(handles.num_RangeX_1,'Visible','on')
         set(handles.num_RangeX_2,'Visible','on')
@@ -338,4 +338,6 @@
             set(handles.num_Angle_2,'Visible','on')
             set(handles.num_Angle_1,'Visible','on')
+            set(handles.num_Angle_1,'String','90')
+            set(handles.Coord,'Data',[0 0 0])
             set(handles.num_RangeZ_2,'Visible','on')
         end
Index: trunk/src/uvmat.m
===================================================================
--- trunk/src/uvmat.m	(revision 960)
+++ trunk/src/uvmat.m	(revision 961)
@@ -991,7 +991,7 @@
                 data.RangeY=UvData.Field.CoordMesh;
             case 'plane_z'
-                data.Angle=[0 0 0];
-                data.DX=10*UvData.Field.CoordMesh;
-                data.DY=10*UvData.Field.CoordMesh;
+                data.Angle=[90 0];
+                data.DX=UvData.Field.CoordMesh;
+                data.DY=UvData.Field.CoordMesh;
                 data.RangeZ=UvData.Field.CoordMesh;
             otherwise
@@ -2355,21 +2355,21 @@
 NomType=get(handles.NomType,'String');
 indices=get(handles.FileIndex,'String');
-[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(indices);% the indices for the second series taken from FileIndex
-switch index_rank
-    case 1
-        indices=fullfile_uvmat('','','','',NomType,stra2num(get(handles.i1,'String')),i2,j1,j2);
-%        set(handles.i1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
-    case 2
-        indices=fullfile_uvmat('','','','',NomType,i1,stra2num(get(handles.i2,'String')),j1,j2);
-%        set(handles.i2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
-    case 3
-        indices=fullfile_uvmat('','','','',NomType,i1,i2,stra2num(get(handles.j1,'String')),j2);
-%        set(handles.j1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
-    case 4
-        indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,stra2num(get(handles.j2,'String')));
-%        set(handles.j2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
+if strcmp(NomType,'level')
+    indices=get(handles.i1,'String');
+else
+    [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(indices);% the indices for the second series taken from FileIndex
+    switch index_rank
+        case 1
+            indices=fullfile_uvmat('','','','',NomType,stra2num(get(handles.i1,'String')),i2,j1,j2);
+        case 2
+            indices=fullfile_uvmat('','','','',NomType,i1,stra2num(get(handles.i2,'String')),j1,j2);
+        case 3
+            indices=fullfile_uvmat('','','','',NomType,i1,i2,stra2num(get(handles.j1,'String')),j2);
+        case 4
+            indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,stra2num(get(handles.j2,'String')));
+    end
 end
 set(handles.FileIndex,'String',indices)
-%set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
+
 % update the second index if relevant
 if strcmp(get(handles.FileIndex_1,'Visible'),'on')
@@ -2944,5 +2944,9 @@
         set(handles.j2,'String',num2stra(j2,NomType,2));
     end
+    if strcmp(NomType,'level')
+       indices=num2str(i1); 
+    else
     indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2);
+    end
     set(handles.FileIndex,'String',indices);
     if ~isempty(filename_1)
@@ -3151,5 +3155,10 @@
 if isempty(i2), set(handles.i2,'String',''); end % suppress the second i index display if not used
 if isempty(j2), set(handles.j2,'String',''); end % suppress the second j index display if not used
+if strcmp(get(handles.NomType,'String'),'level')
+    jindex=str2num(get(handles.j1,'String'));
+    filename=[fullfile(RootPath,SubDir,['level' num2str(jindex)],RootFile) FileIndex FileExt];% build the input file name (first line)
+else
 filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
+end
 filename_1='';%default second file name
 FileIndex_1='';
