Index: trunk/src/proj_field.m
===================================================================
--- trunk/src/proj_field.m	(revision 672)
+++ trunk/src/proj_field.m	(revision 675)
@@ -562,7 +562,7 @@
             NbPoint=ceil(LineLength/DX);
             DX=LineLength/NbPoint;%adjust DX to get an integer nbre of intervals in a closed line
-            DX_end=DX/2;
+            DX_edge=DX/2;
         else
-            DX_end=(LineLength-DX*floor(LineLength/DX))/2;%margin from the first point and first interpolation point
+            DX_edge=(LineLength-DX*floor(LineLength/DX))/2;%margin from the first point and first interpolation point, the same for the end point
         end
         XI=[];
@@ -571,5 +571,5 @@
         dlengthI=[];
         if strcmp(ObjectData.Type,'ellipse')
-            phi=(DX_end:DX:LineLength)*2*pi/LineLength;
+            phi=(DX_edge:DX:LineLength)*2*pi/LineLength;
             XI=ObjectData.RangeX*cos(phi);
             YI=ObjectData.RangeY*sin(phi);
@@ -580,16 +580,21 @@
                 costheta=cos(theta(isegment));
                 sintheta=sin(theta(isegment));
-                XIsegment=(LineCoord(isegment,1)+DX_end*costheta:DX*costheta:LineCoord(isegment+1,1));
-                YIsegment=(LineCoord(isegment,2)+DX_end*sintheta:DX*sintheta:LineCoord(isegment+1,2));
+%                 XIsegment=LineCoord(isegment,1)+DX_edge*costheta:DX*costheta:LineCoord(isegment+1,1));
+%                 YIsegment=(LineCoord(isegment,2)+DX_edge*sintheta:DX*sintheta:LineCoord(isegment+1,2));
+                NbInterval=floor((dlength(isegment)-DX_edge)/DX);
+                LastX=DX_edge+DX*NbInterval;
+                NbPoint=NbInterval+1;
+                XIsegment=linspace(LineCoord(isegment,1)+DX_edge*costheta,LineCoord(isegment,1)+LastX*costheta,NbPoint);
+                YIsegment=linspace(LineCoord(isegment,2)+DX_edge*sintheta,LineCoord(isegment,2)+LastX*sintheta,NbPoint);
                 XI=[XI XIsegment];
                 YI=[YI YIsegment];
                 ThetaI=[ThetaI theta(isegment)*ones(1,numel(XIsegment))];
                 dlengthI=[dlengthI DX*ones(1,numel(XIsegment))];
-                DX_end=DX_end+DX-(dlength(isegment)-DX*(numel(XIsegment)-1));
+                DX_edge=DX-(dlength(isegment)-LastX);%edge for the next segment set to keep DX=DX_end+DX_edge between two segments
             end
         end
         Xproj=cumsum(dlengthI);
     else
-        errormsg='mesh DX needed for interpolation';
+        errormsg='abscissa mesh along line DX needed for interpolation';
         return
     end
@@ -713,6 +718,4 @@
                 [DataOut,VarAttribute,errormsg]=calc_field_tps(Coord,NbCentres,SubRange,FieldVar,CellInfo{icell}.FieldName,cat(3,XI,YI));
                 ProjData.X=Xproj;
-%                 ProjData.ListVarName=[ProjData.ListVarName {XName}];
-%                 ProjData.VarDimName=[ProjData.VarDimName {XName}];
                 nbvar=numel(ProjData.ListVarName);
                 ProjData.VarAttribute{nbvar}.long_name='abscissa along line';
@@ -923,7 +926,4 @@
     testXMin=XMax>XMin;
     testXMax=1;% range restriction along X
-    % else
-    %     XMin=FieldData.XMin;%default
-    %     XMax=FieldData.XMax;%default
 end
 if isfield(ObjectData,'RangeY')
@@ -932,7 +932,4 @@
     testYMin=YMax>YMin;
     testYMax=1;
-    % else
-    %     YMin=FieldData.YMin;%default
-    %     YMax=FieldData.YMax;%default
 end
 width=0;%default width of the projection band
@@ -1036,107 +1033,4 @@
             if ~isfield(FieldData,'XMax')
                 FieldData=find_field_bounds(FieldData);
-%             CellIndex=find(check_grid);
-%             for igrid=1:numel(CellIndex)
-%                 icell=CellIndex(igrid);% TODO: recalculate coordinates here to get the bounds in the rotated coordinates
-%                 NbDim=NbDimArray(icell);
-%                 for idim=1:NbDim %loop on space dimensions
-%                     ivar=CellInfo{icell}.CoordIndex(idim);% index of the variable corresponding to the current dimension
-%                     Coord{idim}=FieldData.(FieldData.ListVarName{ivar});% coord values for the input field
-%                     if ~isequal(ivar,0)%  a variable corresponds to the dimension #idim
-%                         
-%                         
-%                         
-%                     else
-%                                                     Coord_i_str=['Coord_' num2str(idim)];
-%                             DCoord_min(idim)=1;%default
-%                             Coord{idim}=[0.5 DimValue(idim)-0.5];
-%                             test_direct(idim)=1;
-%                     end
-%                 % default bounds, case of gridded data
-%                 if strcmp(CellInfo{icell}.CoordType,'grid')
-%                     % find default mesh
-%                     for idim=1:NbDim %loop on space dimensions
-%                         test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
-%                         ivar=CellInfo{icell}.CoordIndex(idim);% index of the variable corresponding to the current dimension
-%                         DimValue=size(FieldData.(FieldData.ListVarName{ivar}));
-%                         if ~isequal(ivar,0)%  a variable corresponds to the dimension #idim
-%                             Coord{idim}=FieldData.(FieldData.ListVarName{ivar});% coord values for the input field
-%                             if numel(Coord{idim})==2 %input array defined on a regular grid
-%                                 DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim);
-%                                 Coord{idim}=linspace(Coord{idim}(1),Coord{idim}(2),DimValue(idim));
-%                             else
-%                                 DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field
-%                                 DCoord_min(idim)=min(DCoord);
-%                                 DCoord_max=max(DCoord);
-%                                 if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000)
-%                                     msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim)  ' in proj_field.m'])
-%                                     return
-%                                 end
-%                                 test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
-%                             end
-%                             test_direct(idim)=(DCoord_min(idim)>0);
-%                         else  % no variable associated with the  dimension #idim, the coordinate value is set equal to the matrix index by default
-% %                             Coord_i_str=['Coord_' num2str(idim)];
-% %                             DCoord_min(idim)=1;%default
-% %                             Coord{idim}=[0.5 DimValue(idim)-0.5];
-% %                             test_direct(idim)=1;
-%                         end
-%                     end
-%                     if isempty(DY)
-%                         DY=abs(DCoord_min(NbDim-1));
-%                     end
-%                     npY=1+round(abs(Coord{NbDim-1}(end)-Coord{NbDim-1}(1))/DY);%nbre of points after interpol
-%                     if isempty(DX)
-%                         DX=abs(DCoord_min(NbDim));
-%                     end
-%                     npX=1+round(abs(Coord{NbDim}(end)-Coord{NbDim}(1))/DX);%nbre of points after interpol
-%                     for idim=1:NbDim
-%                         if test_interp(idim)
-%                             DimValue(idim)=1+round(abs(Coord{idim}(end)-Coord{idim}(1))/abs(DCoord_min(idim)));%nbre of points after possible interpolation on a regular gri
-%                         end
-%                     end
-%                     Coord_y=linspace(Coord{NbDim-1}(1),Coord{NbDim-1}(end),npY);
-%                     test_direct_y=test_direct(NbDim-1);
-%                     Coord_x=linspace(Coord{NbDim}(1),Coord{NbDim}(end),npX);
-%                     test_direct_x=test_direct(NbDim);
-%                     DAX=DCoord_min(NbDim);
-%                     DAY=DCoord_min(NbDim-1);
-%                     minAX=min(Coord_x);
-%                     maxAX=max(Coord_x);
-%                     minAY=min(Coord_y);
-%                     maxAY=max(Coord_y);
-%                     xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);% image corners in the new coordiantes
-%                     ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
-%                     xcor_new=xcorner*cos_om+ycorner*sin_om;%coord new frame
-%                     ycor_new=-xcorner*sin_om+ycorner*cos_om;
-%                     if ~testXMax
-%                         XMax(igrid)=max(xcor_new);
-%                     end
-%                     if ~testXMin
-%                         XMin(igrid)=min(xcor_new);
-%                     end
-%                     if ~testYMax
-%                         YMax(igrid)=max(ycor_new);
-%                     end
-%                     if ~testYMin
-%                         YMin(igrid)=min(ycor_new);
-%                     end
-%                     DX(igrid)=(maxAX-minAX)/(DimValue(NbDim)-1);
-%                     DY(igrid)=(maxAY-minAY)/(DimValue(NbDim-1)-1);
-%                     if NbDim==3
-%                         DZ(igrid)=(Coord{1}(end)-Coord{1}(1))/(DimValue(1)-1);
-%                         if ~test_direct(1)
-%                             DZ=-DZ;
-%                         end
-%                         Coord_z=linspace(Coord{1}(1),Coord{1}(end),DimValue(1));
-%                         test_direct_z=test_direct(1);
-%                     end
-%                 else
-%                     
-%                 end
-%                 YMax=max(YMax);
-%                 YMin=min(YMin);
-%                 XMax=max(XMax);
-%                 XMin=min(XMin);
             end
         end
@@ -1188,15 +1082,4 @@
     end
     VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
-    %     ivar_U=[];ivar_V=[];ivar_W=[];
-    %     if isfield(CellInfo{icell},'VarIndex_vector_x_tps')&&isfield(CellInfo{icell},'VarIndex_vector_y_tps')
-    %         ivar_U=CellInfo{icell}.VarIndex_vector_x_tps;
-    %         ivar_V=CellInfo{icell}.VarIndex_vector_y_tps;
-    %     elseif isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y')
-    %         ivar_U=CellInfo{icell}.VarIndex_vector_x;
-    %         ivar_V=CellInfo{icell}.VarIndex_vector_y;
-    %     end
-    %     if isfield(CellInfo{icell},'VarIndex_vector_z')
-    %         ivar_W=CellInfo{icell}.VarIndex_vector_z;
-    %     end
     %dimensions
     DimCell=FieldData.VarDimName{VarIndex(1)};
@@ -1390,65 +1273,8 @@
             Coord_x=[];
             
-            
-            
-            %             % default bounds
-            %             minAX=min(Coord_x);
-            %             maxAX=max(Coord_x);
-            %             minAY=min(Coord_y);
-            %             maxAY=max(Coord_y);
-            %             xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);% image corners in the new coordiantes
-            %             ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
-            %             xcor_new=xcorner*cos_om+ycorner*sin_om;%coord new frame
-            %             ycor_new=-xcorner*sin_om+ycorner*cos_om;
-            %             if ~testXMax
-            %                 XMax=max(xcor_new);
-            %             end
-            %             if ~testXMin
-            %                 XMin=min(xcor_new);
-            %             end
-            %             if ~testYMax
-            %                 YMax=max(ycor_new);
-            %             end
-            %             if ~testYMin
-            %                 YMin=min(ycor_new);
-            %             end
-            %             DXinit=(maxAX-minAX)/(DimValue(NbDim)-1);
-            %             DYinit=(maxAY-minAY)/(DimValue(NbDim-1)-1);
-            %             if DX==0
-            %                 DX=DXinit;
-            %             end
-            %             if DY==0
-            %                 DY=DYinit;
-            %             end
-            %             if NbDim==3
-            %                 DZ=(Coord{1}(end)-Coord{1}(1))/(DimValue(1)-1);
-            %                 if ~test_direct(1)
-            %                     DZ=-DZ;
-            %                 end
-            %                 Coord_z=linspace(Coord{1}(1),Coord{1}(end),DimValue(1));
-            %                 test_direct_z=test_direct(1);
-            %             end
-            %define new coordiantes if not already done by the definition of a projection grid
-            if ~check_grid
-                
-                
-            end
-            
             if testangle
                 ProjMode{icell}='interp_lin'; %request linear interpolation for projection on a tilted plane
             end
-            
-            %             npX=floor((XMax-XMin)/DX+1);
-            %             npY=floor((YMax-YMin)/DY+1);
-            %             if test_direct_y
-            %                 coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
-            %             else
-            %                 coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
-            %             end
-            %             if test_direct_x
-            %                 coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
-            %             else
-            %                 coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
-            %             end
+
             if isequal(ProjMode{icell},'projection')% && (~testangle || test90y || test90x)
                 if  NbDim==2 && ~testXMin && ~testXMax && ~testYMin && ~testYMax% no range restriction
