Index: /trunk/src/find_field_cells.m
===================================================================
--- /trunk/src/find_field_cells.m	(revision 889)
+++ /trunk/src/find_field_cells.m	(revision 890)
@@ -210,9 +210,8 @@
 %            2)the coordinate variable contains only two elements, representing the coordinate bounds for the dimension with the same name as the cordinate
 ivar_remain=find(~check_select);% indices of remaining variables, not already taken into account
-ListVarName=Data.ListVarName(~check_select);%list of remaining variables
+ListVarName=Data.ListVarName(~check_select);%list of names of remaining variables
 VarDimName=Data.VarDimName(~check_select);%dimensions of remaining variables
 check_coord_select= cellfun(@numel,VarDimName)==1|cellfun(@ischar,VarDimName)==1;% find remaining variables with a single dimension
 check_coord_select=check_coord_select & ~strcmp('ancillary',Role(~check_select));% do not select ancillary variables as coordinates
-%check_coord(~check_select)=check_coord_select;
 ListCoordIndex=ivar_remain(check_coord_select);% indices of remaining variables with a single dimension
 ListCoordName=ListVarName(check_coord_select);% corresponding names of remaining variables with a single dimension
@@ -220,12 +219,12 @@
 
 %remove redondant variables -> keep only one variable per dimension
-check_keep=logical(ones(size(ListDimName)));
+check_keep=true(size(ListDimName));
 for idim=1:numel(ListDimName)
-    prev_ind=strcmp(ListDimName{idim},ListDimName(1:idim-1));% check whether the dimension is already taken into account
-    if ~isempty(prev_ind)
+    prev_ind=find(strcmp(ListDimName{idim},ListDimName(1:idim-1)));% check whether the dimension is already taken into account
+    if ~isempty(prev_ind)% in case of multiple coord variable
         if strcmp(ListCoordName{idim},ListDimName{idim}) %variable with the same name as the coordinate taken in priority
-            check_keep(prev_ind)=0;
+            check_keep(prev_ind)=0;% choose a variable with the same name as coordinate in priority
         else
-           check_keep(idim)=0; 
+           check_keep(idim)=0; %keep the first coordiante variable found
         end
     end
@@ -256,5 +255,5 @@
 NewCellDimIndex={};
 NewNbDim=[];
-for ivardim=1:numel(VarDimName) % loop at the list of remaining variables
+for ivardim=1:numel(VarDimName) % loop at the list of dimensions for the remaining variables
     DimCell=VarDimName{ivardim};% dimension names of the current variable 
     if ischar(DimCell), DimCell={DimCell}; end %transform char to cell if needed
Index: /trunk/src/get_field.m
===================================================================
--- /trunk/src/get_field.m	(revision 889)
+++ /trunk/src/get_field.m	(revision 890)
@@ -951,13 +951,19 @@
 % --- Executes on button press in CheckDimensionY.
 function CheckDimensionX_Callback(hObject, eventdata, handles)
-FieldList=get(handles.FieldOption,'String');
-FieldOption=FieldList{get(handles.FieldOption,'Value')};
-switch FieldOption
-    case '1D plot'
-        
-    case {'scalar'}
-       scalar_Callback(hObject, eventdata, handles)
-    case 'vectors'
-end
+CheckDimensionX=get(handles.CheckDimensionX,'value')
+if CheckDimensionX
+    set(handles.Coordinates,'visible','off')
+else
+    set(handles.Coordinates,'visible','on')
+end
+% FieldList=get(handles.FieldOption,'String');
+% FieldOption=FieldList{get(handles.FieldOption,'Value')};
+% switch FieldOption
+%     case '1D plot'
+%         
+%     case {'scalar'}
+%        scalar_Callback(hObject, eventdata, handles)
+%     case 'vectors'
+% end
 
 % % --- Executes on button press in CheckDimensionY.
Index: /trunk/src/proj_field.m
===================================================================
--- /trunk/src/proj_field.m	(revision 889)
+++ /trunk/src/proj_field.m	(revision 890)
@@ -123,39 +123,4 @@
 end
 
-% %% take the difference of projected input fields if relevant
-% [CellInfo,NbDim,errormsg]=find_field_cells(ProjData);
-% ind_remove=zeros(size(ProjData.ListVarName));
-% ivar=[];
-% ivar_1=[];
-% for icell=1:numel(CellInfo)
-%     if ~isempty(CellInfo{icell})
-%         % if two scalar are in the same cell
-%         if isfield(CellInfo{icell},'VarIndex_scalar') && numel(CellInfo{icell}.VarIndex_scalar)==2 && ProjData.VarAttribute{CellInfo{icell}.VarIndex_scalar(2)}.CheckSub;
-%             ivar=[ivar CellInfo{icell}.VarIndex_scalar(1)];
-%             ivar_1=[ivar_1 CellInfo{icell}.VarIndex_scalar(2)];
-%         end
-%         % if two vector u components are in the same cell
-%         if isfield(CellInfo{icell},'VarIndex_vector_x') && numel(CellInfo{icell}.VarIndex_vector_x)==2 && ProjData.VarAttribute{CellInfo{icell}.VarIndex_vector_x(2)}.CheckSub;
-%             ivar=[ivar CellInfo{icell}.VarIndex_vector_x(1)];
-%             ivar_1=[ivar_1 CellInfo{icell}.VarIndex_vector_x(2)];
-%         end
-%          % if two vector v components are in the same cell
-%         if isfield(CellInfo{icell},'VarIndex_vector_y') && numel(CellInfo{icell}.VarIndex_vector_y)==2 && ProjData.VarAttribute{CellInfo{icell}.VarIndex_vector_y(2)}.CheckSub;
-%             ivar=[ivar CellInfo{icell}.VarIndex_vector_y(1)];
-%             ivar_1=[ivar_1 CellInfo{icell}.VarIndex_vector_y(2)];
-%         end
-%     end
-% end
-% % subtract fields if relevant
-% for imod=1:numel(ivar)
-%         VarName=ProjData.ListVarName{ivar(imod)};
-%         VarName_1=ProjData.ListVarName{ivar_1(imod)};
-%         ProjData.(VarName)=double(ProjData.(VarName))-double(ProjData.(VarName_1));
-%         ind_remove(ivar_1(imod))=1;
-% end
-% ProjData.ListVarName(find(ind_remove))=[];
-% ProjData.VarDimName(find(ind_remove))=[];
-% ProjData.VarAttribute(find(ind_remove))=[];
-
 %-----------------------------------------------------------------
 %project on a set of points
@@ -1143,4 +1108,5 @@
         end
         [XI,YI]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
+        ProjData.VarDimName={AYName,AXName};
 %         XI=ObjectData.Coord(1,1)+(X)*cos(PlaneAngle(3))-YI*sin(PlaneAngle(3));%corresponding coordinates in the original system
 %         YI=ObjectData.Coord(1,2)+(X)*sin(PlaneAngle(3))+YI*cos(PlaneAngle(3));
@@ -1149,9 +1115,12 @@
         AYName=FieldData.ListVarName{CellInfo{icell_grid}.CoordIndex(NbDim-1)};%name of input x coordinate (name preserved on projection)
         AXName=FieldData.ListVarName{CellInfo{icell_grid}.CoordIndex(NbDim)};%name of input y coordinate (name preserved on projection)
+        AYDimName=FieldData.VarDimName{CellInfo{icell_grid}.CoordIndex(NbDim-1)};%
+        AXDimName=FieldData.VarDimName{CellInfo{icell_grid}.CoordIndex(NbDim)};%
+         ProjData.VarDimName={AYDimName,AXDimName};
         ProjData.(AYName)=FieldData.(AYName); % new (projected ) y coordinates
         ProjData.(AXName)=FieldData.(AXName); % new (projected ) y coordinates
     end
     ProjData.ListVarName={AYName,AXName};
-    ProjData.VarDimName={AYName,AXName};
+    
     ProjData.VarAttribute={[],[]};
 end
Index: /trunk/src/read_field.m
===================================================================
--- /trunk/src/read_field.m	(revision 889)
+++ /trunk/src/read_field.m	(revision 890)
@@ -80,9 +80,5 @@
     case 'civdata'% new format for civ results
         [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType);
-        if ~isempty(errormsg),errormsg=['read_civdata / ' errormsg];return,end
-%         if ~isempty(strcmp('C',ParamIn.FieldName))% if C image correlation is requested as field (not color visu)
-%             ScalarIndex=strcmp('C',Field.ListVarName);
-%             Field.VarAttribute{ScalarIndex}.Role='scalar';%put role as 'scalar' instead of ancillary
-%         end      
+        if ~isempty(errormsg),errormsg=['read_civdata / ' errormsg];return,end     
         ParamOut.CivStage=Field.CivStage;
     case 'civx'% old (obsolete) format for civ results
@@ -128,5 +124,4 @@
                     ProjModeRequest=[ProjModeRequest {ProjModeRequestVar}];
                     ListInputField=[ListInputField InputField(ilist)];
-                    %ListOperator=[ListOperator {[r.Operator '_U']}];
                 else
                     checkU=1;
@@ -137,5 +132,5 @@
                     ProjModeRequest=[ProjModeRequest {ProjModeRequestVar}];
                     ListInputField=[ListInputField InputField(ilist)];
-                    %ListInputField=[ListInputField {''}];
+                    
                 else
                     checkV=1;
@@ -211,4 +206,14 @@
             end
         end
+        % insert coordinates as indices in case of plots vs matrix index
+        if isfield(ParamIn,'CheckCoordIndex') && ParamIn.CheckCoordIndex
+            Field.ListVarName=[Field.ListDimName Field.ListVarName];
+            Field.VarDimName=[Field.ListDimName Field.VarDimName];
+            for idim=1:numel(Field.ListDimName)
+                CoordName=Field.ListDimName{idim};
+                Field.(CoordName)=1:Field.DimValue(idim);
+            end
+            Field.VarAttribute=[cell(1,numel(Field.ListDimName)) Field.VarAttribute]
+        end
     case 'video'
         if strcmp(class(ParamIn),'VideoReader')
Index: /trunk/src/script_mat2nc.m
===================================================================
--- /trunk/src/script_mat2nc.m	(revision 890)
+++ /trunk/src/script_mat2nc.m	(revision 890)
@@ -0,0 +1,27 @@
+% script to transform .mat files into netcdf
+DataFolder=pwd; %=current working directory: to replace by path to data
+fileinput=uigetfile_uvmat('pick an input .mat file',DataFolder,'.mat');% pick a .mat file by the browser
+ncfile=regexprep(fileinput,'.mat$','.nc');% replace extension .mat by .nc
+Data=load(fileinput)% load data from .mat file contains all variables
+ListFields=fieldnames(Data);% list of  all variable names
+
+% Example of variable selection: look for the variable with higher dimensions
+Npy=zeros(1,numel(ListFields));
+Npx=zeros(1,numel(ListFields));
+for ilist =1:numel(ListFields)
+    [Npy(ilist),Npx(ilist)]=size(Data.(ListFields{ilist}));
+end
+[tild,ilist]=max(Npy.*Npx);
+Data.coord_x=1:Npx(ilist);% coordinate variable
+Data.coord_y=1:Npy(ilist);
+Data.ListVarName={'coord_x','coord_y',ListFields{ilist}};
+Data.VarDimName={'coord_x','coord_y',{'coord_y','coord_x'}};
+
+errormsg=struct2nc(ncfile,Data); % write the netcdf file
+if isempty(errormsg)
+    disp([ncfile ' written'])
+else
+    disp(errormsg)
+end
+Dataread=nc2struct(ncfile)% check the netcdf file
+
Index: /trunk/src/script_readnc.m
===================================================================
--- /trunk/src/script_readnc.m	(revision 890)
+++ /trunk/src/script_readnc.m	(revision 890)
@@ -0,0 +1,18 @@
+DataFolder=''; %TODO: put the actual path to start browser
+DataFolder='C:\Users\sommeria\Documents\MATLAB_WORK\UVMAT_DEMO_SOURCES\UVMAT_DEMO03_PIVchallenge_2005C';
+fileinput=uigetfile_uvmat('pick an input file',DataFolder);
+Data=nc2struct(fileinput);
+figure
+npy=numel(Data.coord_y);
+npx=numel(Data.coord_x);
+X=ones(npy,1)*Data.coord_x';
+Sum=sum(Data.VMean,2);
+XMean=sum(X.*Data.VMean,2)./Sum;
+XMean=XMean*ones(1,npx);
+Xrms=sum(((X-XMean).*(X-XMean).*Data.VMean),2)./Sum;
+Xrm=sqrt(Xrms);
+plot(Data.coord_y(3:end-1),Xrms(3:end-1))
+%0.024 y+0.14
+% spread= sqrt(2*log(2))*0.024=0.028
+%y0=-5.8; 
+
Index: unk/src/tutorial_jet.m
===================================================================
--- /trunk/src/tutorial_jet.m	(revision 889)
+++ 	(revision )
@@ -1,18 +1,0 @@
-DataFolder=''; %TODO: put the actual path to start browser
-DataFolder='C:\Users\sommeria\Documents\MATLAB_WORK\UVMAT_DEMO_SOURCES\UVMAT_DEMO03_PIVchallenge_2005C';
-fileinput=uigetfile_uvmat('pick an input file',DataFolder);
-Data=nc2struct(fileinput);
-figure
-npy=numel(Data.coord_y);
-npx=numel(Data.coord_x);
-X=ones(npy,1)*Data.coord_x';
-Sum=sum(Data.VMean,2);
-XMean=sum(X.*Data.VMean,2)./Sum;
-XMean=XMean*ones(1,npx);
-Xrms=sum(((X-XMean).*(X-XMean).*Data.VMean),2)./Sum;
-Xrm=sqrt(Xrms);
-plot(Data.coord_y(3:end-1),Xrms(3:end-1))
-%0.024 y+0.14
-% spread= sqrt(2*log(2))*0.024=0.028
-%y0=-5.8; 
-
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 889)
+++ /trunk/src/uvmat.m	(revision 890)
@@ -3249,4 +3249,5 @@
     ParamIn.Coord_y=get(handles.Coord_y,'String');
     ParamIn.Coord_z=get(handles.Coord_z,'String');
+    ParamIn.CheckCoordIndex=strcmp(get(handles.SwitchCoordIndex,'String'),'dim');
     TimeName=get(handles.TimeName,'String');
     r=regexp(TimeName,'^(?<type>(dim:)|(var:))','names');%look for 'var:' or 'dim:' at the beginning of time name
@@ -3260,8 +3261,5 @@
     end 
 end
-% check_tps = 0;         
-% if strcmp(UvData.FileType{1},'civdata')&&~strcmp(ParamIn.FieldName,'velocity')&&~strcmp(ParamIn.FieldName,'get_field...') 
-%        check_tps=1;%tps needed to get the requested field
-% end
+
 [Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
 if ~isempty(errormsg)
@@ -4270,4 +4268,6 @@
         FieldList={};
         VecColorList={''};
+        XName='';
+        YName='';
         ZName='';
         switch GetFieldData.FieldOption
@@ -4275,8 +4275,10 @@
                 UName=GetFieldData.PanelVectors.vector_x;
                 VName=GetFieldData.PanelVectors.vector_y;
-                YName=GetFieldData.Coordinates.Coord_y;
-                if isfield(GetFieldData.Coordinates,'Coord_z')
-                ZName=GetFieldData.Coordinates.Coord_z;
-                end
+                if isfield(GetFieldData,'Coordinates')
+                    YName=GetFieldData.Coordinates.Coord_y;
+                    if isfield(GetFieldData.Coordinates,'Coord_z')
+                        ZName=GetFieldData.Coordinates.Coord_z;
+                    end
+                end              
                 CName=GetFieldData.PanelVectors.vec_color;
                 FieldList={['vec(' UName ',' VName ')'];...
@@ -4290,7 +4292,9 @@
             case 'scalar'
                 AName=GetFieldData.PanelScalar.scalar;
-                YName=GetFieldData.Coordinates.Coord_y;
-                if isfield(GetFieldData.Coordinates,'Coord_z')
-                ZName=GetFieldData.Coordinates.Coord_z;
+                if isfield(GetFieldData,'Coordinates')
+                    YName=GetFieldData.Coordinates.Coord_y;
+                    if isfield(GetFieldData.Coordinates,'Coord_z')
+                        ZName=GetFieldData.Coordinates.Coord_z;
+                    end
                 end
                 FieldList={AName};
@@ -4302,5 +4306,10 @@
         % get time as file index, attribute, variable or matrix index
         if ~strcmp(GetFieldData.FieldOption,'civdata...')
-            XName=GetFieldData.Coordinates.Coord_x;
+            if isfield(GetFieldData,'Coordinates')
+                XName=GetFieldData.Coordinates.Coord_x;
+                set(handles.SwitchCoordIndex,'String','var'); % variable used as coordinate
+            else
+                set(handles.SwitchCoordIndex,'String','dim'); % matrix index used a coordinate
+            end
             TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
             switch TimeNameStr
