Index: /issm/trunk/src/m/utils/Array/allempty.m
===================================================================
--- /issm/trunk/src/m/utils/Array/allempty.m	(revision 33)
+++ /issm/trunk/src/m/utils/Array/allempty.m	(revision 33)
@@ -0,0 +1,22 @@
+%
+%  function to return an empty cell array if all array elements are empty
+%
+%  function [cout]=allempty(cin)
+%
+function [cout]=allempty(cin)
+
+if ~nargin
+    help allempty
+    return
+end
+
+for j=1:numel(cin)
+    if ~isempty(cin{j})
+        cout=cin;
+        return
+    end
+end
+cout={};
+
+end
+
Index: /issm/trunk/src/m/utils/Array/allequal.m
===================================================================
--- /issm/trunk/src/m/utils/Array/allequal.m	(revision 33)
+++ /issm/trunk/src/m/utils/Array/allequal.m	(revision 33)
@@ -0,0 +1,67 @@
+%
+%  function to return an empty array if all array elements are
+%  equal to the given value.
+%
+%  function [aout]=allequal(ain,aval)
+%
+function [aout]=allequal(ain,aval)
+
+if ~nargin
+    help allequal
+    return
+end
+
+aout=ain;
+
+if     islogical(ain) && islogical(aval)
+    for i=1:numel(ain)
+        if ain(i) ~= aval
+            return
+        end
+    end
+    aout=logical([]);
+
+elseif isnumeric(ain) && isnumeric(aval)
+    for i=1:numel(ain)
+        if ain(i) ~= aval
+            return
+        end
+    end
+    aout=[];
+
+elseif ischar(ain) && ischar(aval)
+    for i=1:size(ain,1)
+        if ~strcmp(ain(i,:),aval)
+            return
+        end
+    end
+    aout='';
+
+elseif iscell(ain)
+    if     islogical(aval)
+        for i=1:numel(ain)
+            if ~islogical(ain{i}) || ain{i} ~= aval
+                return
+            end
+        end
+        aout={};
+
+    elseif isnumeric(aval)
+        for i=1:numel(ain)
+            if ~isnumeric(ain{i}) || ain{i} ~= aval
+                return
+            end
+        end
+        aout={};
+
+    elseif ischar(aval)
+        for i=1:size(ain,1)
+            if ~ischar(ain{i}) || ~strcmp(ain{i},aval)
+                return
+            end
+        end
+        aout={};
+    end
+end
+
+end
Index: /issm/trunk/src/m/utils/Array/allnan.m
===================================================================
--- /issm/trunk/src/m/utils/Array/allnan.m	(revision 33)
+++ /issm/trunk/src/m/utils/Array/allnan.m	(revision 33)
@@ -0,0 +1,22 @@
+%
+%  function to return an empty double array if all array elements are NaN
+%
+%  function [dout]=allnan(din)
+%
+function [dout]=allnan(din)
+
+if ~nargin
+    help allnan
+    return
+end
+
+for i=1:numel(din)
+    if ~isnan(din(i))
+        dout=din;
+        return
+    end
+end
+dout=[];
+
+end
+
Index: /issm/trunk/src/m/utils/Array/any2str.m
===================================================================
--- /issm/trunk/src/m/utils/Array/any2str.m	(revision 33)
+++ /issm/trunk/src/m/utils/Array/any2str.m	(revision 33)
@@ -0,0 +1,18 @@
+%
+%  function to convert anything to a string
+%
+%  function [svec]=any2str(a)
+%
+function [svec]=any2str(a)
+
+if iscell(a)
+    svec=string_cell(a);
+else
+    if (numel(a) > 1) && ~ischar(a)
+        svec=string_vec(a);
+    else
+        svec=item2str(a);
+    end
+end
+
+end
Index: /issm/trunk/src/m/utils/Array/find_string.m
===================================================================
--- /issm/trunk/src/m/utils/Array/find_string.m	(revision 33)
+++ /issm/trunk/src/m/utils/Array/find_string.m	(revision 33)
@@ -0,0 +1,17 @@
+%
+%  function to find a string in a cell array
+%  
+%  [ifound]=find_string(cells,str)
+%
+function [ifound]=find_string(cells,str)
+
+ifound=false;
+
+for i=1:numel(cells)
+    if ischar(cells{i}) && strcmp(cells{i},str)
+        ifound=i;
+        return
+    end
+end
+
+end
Index: /issm/trunk/src/m/utils/Array/item2str.m
===================================================================
--- /issm/trunk/src/m/utils/Array/item2str.m	(revision 33)
+++ /issm/trunk/src/m/utils/Array/item2str.m	(revision 33)
@@ -0,0 +1,25 @@
+%
+%  function to convert an item to a string
+%
+%  function [svec]=item2str(a)
+%
+function [svec]=item2str(a)
+
+if     islogical(a)
+    if a
+        svec='true';
+    else
+        svec='false';
+    end
+elseif ischar(a)
+    svec=['''' a ''''];
+elseif isnumeric(a)
+    svec=num2str(a);
+else
+    warning('item2str:item_unrecog',...
+        'Item ''%s'' is of unrecognized type ''%s''.',...
+        inputname(1),class(a));
+    return
+end
+
+end
Index: /issm/trunk/src/m/utils/Array/string_cell.m
===================================================================
--- /issm/trunk/src/m/utils/Array/string_cell.m	(revision 33)
+++ /issm/trunk/src/m/utils/Array/string_cell.m	(revision 33)
@@ -0,0 +1,26 @@
+%
+%  function to return the string of a cell array
+%
+%  function [svec]=string_cell(a)
+%
+function [svec]=string_cell(a)
+
+if ~nargin
+    help string_vec
+    return
+end
+
+if (numel(a) == 0)
+    svec='{}';
+    return
+end
+
+%  assemble string for output
+
+svec ='{';
+for i=1:numel(a)-1;
+    svec=[svec item2str(a{i}) ' '];
+end
+svec=[svec item2str(a{end}) '}'];
+
+end
Index: /issm/trunk/src/m/utils/Array/string_dim.m
===================================================================
--- /issm/trunk/src/m/utils/Array/string_dim.m	(revision 33)
+++ /issm/trunk/src/m/utils/Array/string_dim.m	(revision 33)
@@ -0,0 +1,45 @@
+%
+%  function to return the string dimension of an array element
+%
+%  function [sdim]=string_dim(a,idim)
+%
+function [sdim]=string_dim(a,idim)
+
+if ~nargin
+    help string_dim
+    return
+end
+
+if (numel(a) == 1) && (idim == 1)
+    sdim='';
+    return
+end
+if (idim > numel(a))
+    error('Index %d exceeds number of elements in ''%s''.',...
+        idim,inputname(1));
+end
+
+asize=size(a);
+index=zeros(size(asize));
+aprod=prod(asize);
+idim =idim-1;
+
+%  calculate indices base 0 and convert to base 1
+
+for i=length(asize):-1:1
+    aprod=aprod/asize(i);
+    index(i)=floor(idim/aprod);
+    idim=idim-index(i)*aprod;
+end
+index=index+1;
+
+%  assemble string for output
+
+sdim ='(';
+for i=1:length(asize)-1;
+    sdim =[sdim num2str(index(i)) ','];
+end
+sdim =[sdim num2str(index(end)) ')'];
+
+end
+
Index: /issm/trunk/src/m/utils/Array/string_vec.m
===================================================================
--- /issm/trunk/src/m/utils/Array/string_vec.m	(revision 33)
+++ /issm/trunk/src/m/utils/Array/string_vec.m	(revision 33)
@@ -0,0 +1,26 @@
+%
+%  function to return the string of an vector
+%
+%  function [svec]=string_vec(a)
+%
+function [svec]=string_vec(a)
+
+if ~nargin
+    help string_vec
+    return
+end
+
+if (numel(a) == 0)
+    svec='[]';
+    return
+end
+
+%  assemble string for output
+
+svec ='[';
+for i=1:numel(a)-1;
+    svec=[svec item2str(a(i)) ' '];
+end
+svec=[svec item2str(a(end)) ']'];
+
+end
Index: /issm/trunk/src/m/utils/BC/SetIceSheetBC.m
===================================================================
--- /issm/trunk/src/m/utils/BC/SetIceSheetBC.m	(revision 33)
+++ /issm/trunk/src/m/utils/BC/SetIceSheetBC.m	(revision 33)
@@ -0,0 +1,52 @@
+function md=SetIceSheetBC(md)
+%SETICESHEETBC - Create the boundary conditions for diagnostic and thermal models for an IceSheet with no Ice Front
+%
+%   Usage:
+%      md=SetIceSheetBC(md)
+%
+%   See also: SETICESHELFBC, SETMARINEICESHEETBC
+
+%grid on Dirichlet
+pos=find(md.gridonboundary);
+md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+md.gridondirichlet_diag(pos)=1;
+
+%Dirichlet Values
+md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+if (length(md.vx_obs)==md.numberofgrids & length(md.vy_obs)==md.numberofgrids)
+	disp('      boundary conditions for diagnostic model: spc set as observed velocities');
+	md.dirichletvalues_diag(pos,:)=[md.vx_obs(pos) md.vy_obs(pos)];
+else
+	disp('      boundary conditions for diagnostic model: spc set as zero');
+end
+
+%segment on neumann (Ice Front) -> none
+md.segmentonneumann_diag=zeros(0,3);
+md.neumannvalues_diag=[];
+
+%Create zeros melting and accumulation if not specified
+if isnan(md.accumulation),
+	md.accumulation=zeros(md.numberofgrids,1);
+	disp('      no accumulation specified: values set as zero');
+end
+if isnan(md.melting),
+	md.melting=zeros(md.numberofgrids,1);
+	disp('      no melting specified: values set as zero');
+end
+
+disp('      boundary conditions for prognostic model initialization ');
+md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+md.segmentonneumann_prog=[];
+md.neumannvalues_prog=[];
+
+if (length(md.observed_temperature)==md.numberofgrids),
+	disp('      boundary conditions for thermal model');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	if (length(md.geothermalflux)~=md.numberofgrids),
+		md.geothermalflux=50*10^-3*ones(md.numberofgrids,1); %50 mW/m^2
+	end
+else
+	disp('      no thermal boundary conditions created: no observed temperature found');
+end
Index: /issm/trunk/src/m/utils/BC/SetIceShelfBC.m
===================================================================
--- /issm/trunk/src/m/utils/BC/SetIceShelfBC.m	(revision 33)
+++ /issm/trunk/src/m/utils/BC/SetIceShelfBC.m	(revision 33)
@@ -0,0 +1,65 @@
+function md=SetIceShelfBC(md,icefrontfile)
+%SETICESHELFBC - Create the boundary conditions for diagnostic and thermal models for a  Ice Shelf with Ice Front
+%
+%   Neumann BC are used on the ice front (an ANRGUS contour around the ice front
+%   must be given in input)
+%   Dirichlet BC are used elsewhere for diagnostic
+%
+%   Usage:
+%      md=SetIceShelfBC(md,icefrontfile)
+%
+%   Example:
+%      md=SetIceShelfBC(md,'Front.exp');
+%
+%   See also: SETICESHEETBC, SETMARINEICESHEETBC
+
+%grid on Dirichlet (boundary and ~icefront)
+if ~exist(icefrontfile)
+	error(['SetIceShelfBC error message: ice front file ' icefrontfile ' not found']);
+end
+gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread(icefrontfile,1),'node',2);
+gridonicefront=double(md.gridonboundary & gridinsideicefront);
+pos=find(md.gridonboundary & ~gridonicefront);
+md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+md.gridondirichlet_diag(pos)=1;
+
+%Dirichlet Values
+md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+if (length(md.vx_obs)==md.numberofgrids & length(md.vy_obs)==md.numberofgrids)
+	disp('      boundary conditions for diagnostic model: spc set as observed velocities');
+	md.dirichletvalues_diag(pos,:)=[md.vx_obs(pos) md.vy_obs(pos)];
+else
+	disp('      boundary conditions for diagnostic model: spc set as zero');
+end
+
+%segment on Neumann (Ice Front)
+pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+md.segmentonneumann_diag=md.segments(pos,:);
+md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+%Create zeros melting and accumulation if not specified
+if isnan(md.accumulation),
+	md.accumulation=zeros(md.numberofgrids,1);
+	disp('      no accumulation specified: values set as zero');
+end
+if isnan(md.melting),
+	md.melting=zeros(md.numberofgrids,1);
+	disp('      no melting specified: values set as zero');
+end
+
+disp('      boundary conditions for prognostic model initialization ');
+md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+md.segmentonneumann_prog=[];
+md.neumannvalues_prog=[];
+
+if (length(md.observed_temperature)==md.numberofgrids),
+	disp('      boundary conditions for thermal model');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	if (length(md.geothermalflux)~=md.numberofgrids),
+		md.geothermalflux=zeros(md.numberofgrids,1);
+	end
+else
+	disp('      no thermal boundary conditions created: no observed temperature found');
+end
Index: /issm/trunk/src/m/utils/BC/SetMarineIceSheetBC.m
===================================================================
--- /issm/trunk/src/m/utils/BC/SetMarineIceSheetBC.m	(revision 33)
+++ /issm/trunk/src/m/utils/BC/SetMarineIceSheetBC.m	(revision 33)
@@ -0,0 +1,66 @@
+function md=SetMarineIceSheetBC(md,icefrontfile)
+%SETICEMARINESHEETBC - Create the boundary conditions for diagnostic and thermal models for a  Marine Ice Sheet with Ice Front
+%
+%   Neumann BC are used on the ice front (an ANRGUS contour around the ice front
+%   must be given in input)
+%   Dirichlet BC are used elsewhere for diagnostic
+%
+%   Usage:
+%      md=SetMarineIceSheetBC(md,icefrontfile)
+%
+%   Example:
+%      md=SetMarineIceSheetBC(md,'Front.exp')
+%
+%   See also: SETICESHELFBC, SETMARINEICESHEETBC
+
+%grid on Dirichlet (boundary and ~icefront)
+if ~exist(icefrontfile)
+	error(['SetMarineIceSheetBC error message: ice front file ' icefrontfile ' not found']);
+end
+gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread(icefrontfile,1),'node',2);
+gridonicefront=double(md.gridonboundary & gridinsideicefront);
+pos=find(md.gridonboundary & ~gridonicefront);
+md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+md.gridondirichlet_diag(pos)=1;
+
+%Dirichlet Values
+md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+if (length(md.vx_obs)==md.numberofgrids & length(md.vy_obs)==md.numberofgrids)
+	disp('      boundary conditions for diagnostic model: spc set as observed velocities');
+	md.dirichletvalues_diag(pos,:)=[md.vx_obs(pos) md.vy_obs(pos)];
+else
+	disp('      boundary conditions for diagnostic model: spc set as zero');
+end
+
+%segment on Neumann (Ice Front)
+pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+md.segmentonneumann_diag=md.segments(pos,:);
+md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+%Create zeros melting and accumulation if not specified
+if isnan(md.accumulation),
+	md.accumulation=zeros(md.numberofgrids,1);
+	disp('      no accumulation specified: values set as zero');
+end
+if isnan(md.melting),
+	md.melting=zeros(md.numberofgrids,1);
+	disp('      no melting specified: values set as zero');
+end
+
+disp('      boundary conditions for prognostic model initialization ');
+md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+md.segmentonneumann_prog=[];
+md.neumannvalues_prog=[];
+
+if (length(md.observed_temperature)==md.numberofgrids),
+	disp('      boundary conditions for thermal model');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	if (length(md.geothermalflux)~=md.numberofgrids),
+		md.geothermalflux=zeros(md.numberofgrids,1);
+		md.geothermalflux(find(md.gridonicesheet))=50*10^-3; %50mW/m2
+	end
+else
+	disp('      no thermal boundary conditions created: no observed temperature found');
+end
Index: /issm/trunk/src/m/utils/DataProcessing/addtrack.m
===================================================================
--- /issm/trunk/src/m/utils/DataProcessing/addtrack.m	(revision 33)
+++ /issm/trunk/src/m/utils/DataProcessing/addtrack.m	(revision 33)
@@ -0,0 +1,148 @@
+function [x_m2 y_m2 values2]=addtrack(x_m1,y_m1,values1,track_coord,track_values,distance,exponent),
+%ADDTRACK - modify a map to take values of a track
+%
+%   This routine modify a map to improve it with values of tracks.
+%   This output map has more values than the input one so that the values
+%   of the tracks are relevant.
+%   x_m1 and y_m1 are two vector containing the coordinates of the matrix
+%   the distance between two points must be the same everywhere
+%   values1 is a matrix of size (y_m1-1)*(x_m1-1)
+%   trac_coord is an exp file containing the coordinates of the tracks (x and y)
+%   trav_values is a vector with the values along the track coordinates
+%   distance indicates the distance from the tracks where points have to be modified
+%   exposant allows to chance the influence of the track and the map
+%   it must be positive and usually is superior to 1.
+%
+%   Usage:
+%      [x_m2 y_m2 values1 values2]=addtrack(x_m1,y_m1,values1,track_coord,track_values,distance,exposant)
+%
+%   Example:
+%      [xnew ynew valuesnew]=addtrack(x_m,y_m,thickness,'trackcoord.exp',thickness_track,1000,2)
+
+%Create a new picture precise enough to be modified by the tracks
+%Read the points of the tracks
+stru=expread(track_coord,1);
+nods=stru.nods;
+xtracks=stru.x';
+ytracks=stru.y';
+
+%First check that the parameters are ok:
+if (size(track_values,1)~=nods)  || (size(xtracks,2)~=nods) || (size(ytracks,2)~=nods),
+	error('addtrack error message : track coordinates and track values must have the same size');
+elseif distance<0,
+	error('addtrack error message : the distance must be a positive value');
+elseif exponent<0,
+	error('addtrack error message : the exponent must be a positive value');
+elseif (size(x_m1,1)~=(size(values1,2)+1)) || (size(y_m1,1)~=(size(values1,1)+1)),
+	error('addtrack error message : problem in the map, check the size of x_m1, y_m1 and values1');
+end
+
+%stru.nods=4;
+%xtracks=[50 50 55 62]; % 2 3 4 5 6 7 8 9 1 ]';
+%ytracks=[40 40.5 41 41]; % 5 5 5 5 5 5 5 5 8 ]';
+%x_m1=[1:10:101]';
+%y_m1=[1:10:101]';
+%track_values=2*ones(4,1);
+%values1=ones(10,10);
+
+%Find the average distance between two points of the tracks
+av_x=sum(abs(diff(xtracks)))/(stru.nods-1);
+av_y=sum(abs(diff(ytracks)))/(stru.nods-1);
+dist_av=sqrt(av_x^2+av_y^2);
+
+%Calculate the multiplicate factor for the new values:
+mult=round((x_m1(2)-x_m1(1))/(1*dist_av));
+
+%Plug the values in the new multiplied matrix
+values=zeros(mult*size(values1,1),mult*size(values1,2));
+
+for i=1:mult,
+	for j=1:mult,
+		values(i:mult:end,j:mult:end)=values1;
+	end
+end
+
+%Create the new x and y addapted to the matrix
+x_m2=linspace(x_m1(1),x_m1(end),mult*(size(x_m1,1)-1)+1)';
+y_m2=linspace(y_m1(1),y_m1(end),mult*(size(y_m1,1)-1)+1)';
+
+%Create a new set of x and y correponding to the medium value on the matrix
+x_med=(x_m2(1:end-1)+x_m2(2:end))/2;
+y_med=(y_m2(1:end-1)+y_m2(2:end))/2;
+
+numrow=size(y_med,1);
+numcol=size(x_med,1);
+
+%Create new x and y to have the hole matrix
+x_mat=repmat(x_med',numrow,1);
+y_mat=repmat(y_med,1,numcol);
+
+%Remove useless points of the track
+points=find(track_values==0);
+track_values(points)=[];
+xtracks(points)=[];
+ytracks(points)=[];
+points=find(isnan(track_values));
+track_values(points)=[];
+xtracks(points)=[];
+ytracks(points)=[];
+
+%Remove points outside of the map
+points=find(xtracks<x_med(1) | xtracks>x_med(end) | ytracks<y_med(1) | ytracks>y_med(end));
+track_values(points)=[];
+xtracks(points)=[];
+ytracks(points)=[];
+
+%initialize some matrices
+numoverlap=zeros(numrow,numcol);
+weights=zeros(numrow,numcol);
+weightsvalues=zeros(numrow,numcol);
+
+%Loop over the points of the track
+nel=size(track_values,1);
+for i=1:nel;
+	if mod(i,1000)==0,
+		disp(sprintf('\r%s%.2f%s','      track processing progress  ',i/nel*100,' %'));
+	end
+
+	x=xtracks(i);
+	y=ytracks(i);
+
+	%get indices that are modified
+	indexx1=max(find(x_med<x-distance));
+	if isempty( indexx1), indexx1=1; end
+	indexx2=min(find(x_med>x+distance));
+	if isempty( indexx2), indexx2=numrow; end
+	indexy1=max(find(y_med<y-distance));
+	if isempty( indexy1), indexy1=1; end
+	indexy2=min(find(y_med>y+distance));
+	if isempty( indexy2), indexy2=numcol; end
+
+
+	%get weighing coefficient
+	val=track_values(i);
+	distances=sqrt((x-x_mat(indexy1:indexy2,indexx1:indexx2)).^2+(y-y_mat(indexy1:indexy2,indexx1:indexx2)).^2);
+	coeff=min(1,(distances/distance)).^(1/exponent);
+
+	%update numoverlap and weights
+	numoverlap(indexy1:indexy2,indexx1:indexx2)=numoverlap(indexy1:indexy2,indexx1:indexx2)+1;
+	weights(indexy1:indexy2,indexx1:indexx2)=weights(indexy1:indexy2,indexx1:indexx2)+coeff;
+	weightsvalues(indexy1:indexy2,indexx1:indexx2)=weightsvalues(indexy1:indexy2,indexx1:indexx2)+(1-coeff)*val;
+
+end
+if nel>1000,
+	disp(sprintf('\r%s%.2f%s','      track processing progress:  ',100,' %'));
+end
+
+
+%Change the values of numoverlap to 1 if 0 since we are going to devide by this matrix
+numoverlap(find(~numoverlap))=1;
+
+%Same thing for weights since values far from the tracks don't change
+weights(find(~weights))=1;
+
+%Create the final matrix depending on the previous matrix
+values=(values.*weights+weightsvalues)./numoverlap;
+
+%Plug the values of the track in the new matrix
+values2=values;
Index: /issm/trunk/src/m/utils/DataProcessing/data_processing_tool.m
===================================================================
--- /issm/trunk/src/m/utils/DataProcessing/data_processing_tool.m	(revision 33)
+++ /issm/trunk/src/m/utils/DataProcessing/data_processing_tool.m	(revision 33)
@@ -0,0 +1,467 @@
+function varargout = data_processing_tool(varargin)
+%DATA_PROCESSING_TOOL - GUI to process binary data
+%
+%   this routine is a GUI that helps the user to open
+%   a binary file (Little Endian, Big Endian, Float 32,
+%   double,...) and save a Matlab file (.mat) with the
+%   processed data and the coordinates
+%
+%   Usage:
+%      data_processing_tool
+
+	gui_Singleton = 1;
+	gui_State = struct('gui_Name',       mfilename, ...
+		'gui_Singleton',  gui_Singleton, ...
+		'gui_OpeningFcn', @data_processing_tool_OpeningFcn, ...
+		'gui_OutputFcn',  @data_processing_tool_OutputFcn, ...
+		'gui_LayoutFcn',  [] , ...
+		'gui_Callback',   []);
+	if nargin && ischar(varargin{1})
+		gui_State.gui_Callback = str2func(varargin{1});
+	end
+
+	if nargout
+		[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+	else
+		gui_mainfcn(gui_State, varargin{:});
+	end
+end
+
+function data_processing_tool_OpeningFcn(hObject, eventdata, handles, varargin)
+	handles.output = hObject;
+
+	%enable toolbar (useful for caxis...)
+	set(hObject,'toolbar','figure');
+
+	% Update handles structure
+	guidata(hObject, handles);
+
+	%this variable used to prevent users from breaking the GUI
+	%the variable is set to 1 once the data has been processed
+	handles.processDataCompleted=0;
+
+	%initialize other variables
+	handles.Msize=NaN;
+	handles.Nsize=NaN;
+	handles.numvectors=NaN;
+	handles.endian=NaN;
+	handles.datatype=NaN;
+	handles.dx=NaN;
+	handles.dy=NaN;
+	handles.xEast=NaN;
+	handles.yNorth=NaN;
+
+	%two files permitted
+	set(handles.inputFile,'Max',1);
+	set(handles.inputFile,'Min',0);
+
+	% Update handles structure
+	guidata(hObject, handles);
+end
+
+% --- Outputs from this function are returned to the command line.
+function varargout = data_processing_tool_OutputFcn(hObject, eventdata, handles) 
+
+	% Get default command line output from handles structure
+	varargout{1} = handles.output;
+end
+
+
+function inputFile_Callback(hObject, eventdata, handles)
+%no code needed for this callback, the listbox is only used as a visual
+end
+
+function addFiles_pushbutton_Callback(hObject, eventdata, handles)
+	%gets input file(s) from user. the sample data files have extension .s2p
+	[input_file,pathname] = uigetfile( ...
+		{'*.*', 'All Files (*.*)'}, ...
+		'Select files', ... 
+		'MultiSelect', 'on');
+
+	%if file selection is cancelled, pathname should be zero
+	%and nothing should happen
+	if pathname==0
+		return
+	end
+
+	handles.processDataCompleted=1;
+
+	%gets the current data file names inside the listbox
+	inputFileName=get(handles.inputFile,'String');
+
+	%if they only select one file, then the data will not be a cell
+	inputFileName= fullfile(pathname,input_file);
+
+	%updates the gui to display all filenames in the listbox
+	set(handles.inputFile,'String',inputFileName);
+
+	%make sure first file is always selected so it doesn't go out of range
+	%the GUI will break if this value is out of range
+	set(handles.inputFile,'Value',1);
+
+	% Update handles structure
+	guidata(hObject, handles);
+end
+
+function reset_pushbutton_Callback(hObject, eventdata, handles)
+	%resets the GUI by clearing all relevant fields
+
+	handles.processDataCompleted = 0;
+
+	%clears the axes
+	cla(handles.axes1,'reset');
+
+	%set the popupmenu to default value
+%	set(handles.plot_popupmenu,'Value',1);
+
+	%clears the contents of the listbox
+	set(handles.inputFile,'String','');
+	set(handles.inputFile,'Value',0);
+
+	%updates the handles structure
+	guidata(hObject, handles);
+end
+
+function plotdata_pushbutton_Callback(hObject, eventdata, handles)
+
+	%get the list of input file names from the listbox
+	inputFileName=get(handles.inputFile,'String');
+
+	%checks to see if the user selected any input files
+	%if not, nothing happens
+	if isempty(inputFileName)
+		errordlg('Select a file first!')
+		return
+	end
+
+	%disables the button while data is processing
+	disableButtons(handles);
+	refresh(data_processing_tool); 
+
+	%parse options
+	if ~isnan(handles.Msize)
+		M=handles.Msize;
+	else
+		errordlg('Number of lines (M) not valid')
+		return
+	end
+	if ~isnan(handles.Nsize)
+		N=handles.Nsize;
+	else
+		errordlg('Number of rows (N) not valid')
+		return
+	end
+	if ~isnan(handles.numvectors)
+		numvectors=handles.numvectors;
+		%change M
+		M=numvectors*M;
+	else
+		numvectors=1;
+	end
+	if ~isnan(handles.endian)
+		endian=handles.endian;
+	else
+		endian=1;
+	end
+	if ~isnan(handles.datatype)
+		datatype=handles.datatype;
+	else
+		datatype='float32';
+	end
+
+	%open file
+	if endian==1
+		fid=fopen(inputFileName,'r','ieee-be');
+	else
+		fid=fopen(inputFileName,'r','ieee-le');
+	end
+
+	%read file
+	[u, numpoints]=fread(fid, [M,N],datatype);
+
+	%close file
+	fclose(fid);
+
+	%Pair of vectors?
+	if numvectors==2,
+	   vx=u(1:2:M,:);vx=flipud(vx');
+	   vy=u(2:2:M,:);vx=flipud(vx');
+
+		%keep track
+		handles.vx=vx;
+		handles.vy=vy;
+
+		u=sqrt(vx.^2+vy.^2);
+	end
+
+	cla(handles.axes1); %clear the axes
+	axes(handles.axes1); %set the axes to plot
+	grid on
+	imagesc(u)
+	colorbar
+
+	%keep track
+	handles.u=u;
+
+	%to see whether the data has been processed or not
+	handles.processDataCompleted=2;
+
+	%data is done processing, so re-enable the buttons
+	enableButtons(handles);
+	guidata(hObject, handles);
+end
+
+function plotcoord_Callback(hObject, eventdata, handles)
+
+	%check
+	if handles.processDataCompleted<2
+		errordlg('Process data first !')
+		return
+	end
+
+	%parse options
+	if ~isnan(handles.dx)
+		dx=handles.dx;
+	else
+		errordlg('value of x-spacing not supported')
+		return
+	end
+	if ~isnan(handles.dy)
+		dy=handles.dy;
+	else
+		errordlg('value of y-spacing not supported')
+		return
+	end
+	if ~isnan(handles.xEast)
+		xEast=handles.xEast;
+	else
+		errordlg('value of xEast not supported')
+		return
+	end
+	if ~isnan(handles.yNorth)
+		yNorth=handles.yNorth;
+	else
+		errordlg('value of yNorth not supported')
+		return
+	end
+
+	disableButtons(handles);
+
+	%process coordinates
+	u=handles.u;
+	s=size(u);
+	M=s(1)+1;
+	N=s(2)+1;
+
+	%correction North and East -> real
+	yNorth=yNorth-M*dy; % corner north
+	x_m=xEast+dx*(0:N-1)';
+	y_m=yNorth+dy*(0:M-1)';
+
+	%plot new axes
+	cla(handles.axes1); %clear the axes
+	axes(handles.axes1); %set the axes to plot
+	grid on
+	imagesc(x_m,y_m,handles.u)
+	set(handles.axes1,'Ydir','Normal');
+	colorbar
+
+	%Keep track of x_m and y_m
+	handles.x_m=x_m;
+	handles.y_m=y_m;
+
+	%to see whether the data has been processed or not
+	handles.processDataCompleted=3;
+
+	%data is done processing, so re-enable the buttons
+	enableButtons(handles);
+	guidata(hObject, handles);
+
+end
+
+
+function save_pushbutton_Callback(hObject, eventdata, handles)
+	%if the data hasn't been processed yet, 
+	%nothing happens when this button is pressed
+	if (handles.processDataCompleted ~= 3)
+		return
+	end
+
+	disableButtons(handles);
+
+	if handles.numvectors==2,
+
+		prompt={'Enter the name of the variable 1:','Enter the name of the variable 2:','Enter the name of the file:'};
+		name='Save Matlab File';
+		numlines=1;
+		defaultanswer={'vx','vy','ProcessedFile'};
+		answer=inputdlg(prompt,name,numlines,defaultanswer);
+		variablename1=answer{1};
+		variablename2=answer{2};
+		filename=answer{3};
+
+		if ~isempty(variablename1) & ~isempty(variablename2) & ~isempty(filename)
+			%get the variables
+			x_m=handles.x_m;
+			y_m=handles.y_m;
+			eval([variablename1 ' = handles.vx;']);
+			eval([variablename2 ' = handles.vy;']);
+			x_m=handles.x_m;
+			eval(['save ' filename ' x_m y_m ' variablename1 ' ' variablename2 ]);
+			disp(['in the file ' filename ' have been saved the following variables: x_m, y_m, ' variablename1 ' and ' variablename2])
+		end
+	else
+		prompt={'Enter the name of the variable:','Enter the name of the file:'};
+		name='Save Matlab File';
+		numlines=1;
+		defaultanswer={'thickness','ProcessedFile'};
+		answer=inputdlg(prompt,name,numlines,defaultanswer);
+		variablename=answer{1};
+		filename=answer{2};
+
+		if ~isempty(variablename) & ~isempty(filename)
+			%get the variables
+			x_m=handles.x_m;
+			y_m=handles.y_m;
+			eval([variablename ' = handles.u;']);
+			eval(['save ' filename ' x_m y_m ' variablename]);
+			disp(['in the file ' filename ' have been saved the following variables: x_m, y_m, and ' variablename])
+		end
+	end
+	enableButtons(handles);
+	guidata(hObject, handles);
+end
+
+function inputFile_CreateFcn(hObject, eventdata, handles)
+	if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+		set(hObject,'BackgroundColor','white');
+	end
+end
+
+function disableButtons(handles)
+	set(handles.figure1,'Pointer','watch');
+	set(handles.plotdata_pushbutton,'Enable','off');
+	set(handles.plotcoord,'Enable','off');
+	set(handles.save_pushbutton,'Enable','off');
+	set(handles.addFiles_pushbutton,'Enable','off');
+	set(handles.reset_pushbutton,'Enable','off');
+end
+
+function enableButtons(handles)
+	set(handles.figure1,'Pointer','arrow');
+	set(handles.plotdata_pushbutton,'Enable','on');
+	set(handles.plotcoord,'Enable','on');
+	set(handles.save_pushbutton,'Enable','on');
+	set(handles.addFiles_pushbutton,'Enable','on');
+	set(handles.reset_pushbutton,'Enable','on');
+end
+
+function EndianType_Callback(hObject, eventdata, handles)
+	handles.endian=get(handles.EndianType,'Value');
+	guidata(hObject, handles);
+end
+
+function EndianType_CreateFcn(hObject, eventdata, handles)
+	if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+		set(hObject,'BackgroundColor','white');
+	end
+end
+
+function DataType_Callback(hObject, eventdata, handles)
+
+	datatype= get(handles.DataType,'Value');
+	switch datatype
+		case 1
+			string='float32';
+
+		case 2
+			string='single';
+
+		case 3
+			string='float64';
+
+		case 4
+			string='double';
+		end
+	handles.datatype=string;
+	guidata(hObject, handles);
+end
+
+function DataType_CreateFcn(hObject, eventdata, handles)
+	if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+		set(hObject,'BackgroundColor','white');
+	end
+end
+
+function PairOfVectors_Callback(hObject, eventdata, handles)
+	handles.numvectors = get(handles.PairOfVectors,'Value');
+	guidata(hObject, handles);
+end
+
+function PairOfVectors_CreateFcn(hObject, eventdata, handles)
+	if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+		set(hObject,'BackgroundColor','white');
+	end
+end
+
+function Msize_Callback(hObject, eventdata, handles)
+	handles.Msize=eval(get(hObject,'String'));
+	guidata(hObject, handles);
+end
+
+function Msize_CreateFcn(hObject, eventdata, handles)
+	if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+		set(hObject,'BackgroundColor','white');
+	end
+end
+
+function Nsize_Callback(hObject, eventdata, handles)
+	handles.Nsize=eval(get(hObject,'String'));
+	guidata(hObject, handles);
+end
+
+function Nsize_CreateFcn(hObject, eventdata, handles)
+	if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+		set(hObject,'BackgroundColor','white');
+	end
+end
+
+function dx_Callback(hObject, eventdata, handles)
+	handles.dx=eval(get(hObject,'String'));
+	guidata(hObject, handles);
+end
+function dx_CreateFcn(hObject, eventdata, handles)
+	if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+		set(hObject,'BackgroundColor','white');
+	end
+end
+
+function dy_Callback(hObject, eventdata, handles)
+	handles.dy=eval(get(hObject,'String'));
+	guidata(hObject, handles);
+end
+function dy_CreateFcn(hObject, eventdata, handles)
+	if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+		set(hObject,'BackgroundColor','white');
+	end
+end
+
+function xEast_Callback(hObject, eventdata, handles)
+	handles.xEast=eval(get(hObject,'String'));
+	guidata(hObject, handles);
+end
+function xEast_CreateFcn(hObject, eventdata, handles)
+	if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+		set(hObject,'BackgroundColor','white');
+	end
+end
+
+function yNorth_Callback(hObject, eventdata, handles)
+	handles.yNorth=eval(get(hObject,'String'));
+	guidata(hObject, handles);
+end
+function yNorth_CreateFcn(hObject, eventdata, handles)
+	if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+		set(hObject,'BackgroundColor','white');
+	end
+end
Index: /issm/trunk/src/m/utils/Exp/expmaster.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/expmaster.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/expmaster.m	(revision 33)
@@ -33,35 +33,30 @@
 numpoints=0;
 closed=[];
-if nargin>1,
-	isexist=1;
-	for i=1:nargin-1
-		filename=varargin{i};
-		if ~exist(filename),
-			error(['expmaster error message:, ' filename ' does not exist. Exiting...']);
-		else
-			%read file
-			B=expread(filename,1);
-			%go through all profiles of B
-			for i=1:size(B,2)
-				%plug profile in A
-				if numprofiles
-					A(numprofiles+1)=B(i);
-				else
-					A=B(i);
-				end
-				%update numprofiles and numpoints
-				numpoints=numpoints+length(B(i).x);
-				numprofiles=numprofiles+1;
-				%figure out if the profile is closed or not
-				if (B(i).x(1)==B(i).x(end) & B(i).y(1)==B(i).y(end))
-					closed(numprofiles)=1;
-				else
-					closed(numprofiles)=0;
-				end
+for i=1:nargin-1
+	filename=varargin{i};
+	if ~exist(filename),
+		error(['expmaster error message:, ' filename ' does not exist. Exiting...']);
+	else
+		%read file
+		B=expread(filename,1);
+		%go through all profiles of B
+		for i=1:size(B,2)
+			%plug profile in A
+			if numprofiles
+				A(numprofiles+1)=B(i);
+			else
+				A=B(i);
 			end
-		end
-	end
-else
-	isexist=0;
+			%update numprofiles and numpoints
+			numpoints=numpoints+length(B(i).x);
+			numprofiles=numprofiles+1;
+			%figure out if the profile is closed or not
+			if (B(i).x(1)==B(i).x(end) & B(i).y(1)==B(i).y(end))
+				closed(numprofiles)=1;
+			else
+				closed(numprofiles)=0;
+			end
+		end
+	end
 end
 
@@ -69,10 +64,21 @@
 [path root ext ver]=fileparts(newfile);
 
-%Figure out how nany plots have been done so far 
-g=get(gca,'children'); 
-prevplot=length(g);
-prevplot2=prevplot;
+%get current figure
+set(gcf,'Renderer','zbuffer'); %fixes a bug on Mac OS X (not needed in future Matlab version
+F=getframe(gca);
+F=F.cdata;
+%get current axis
+xlim=get(gca,'Xlim');
+ylim=get(gca,'Ylim');
+%recreate x_m and y_m
+x_m=linspace(xlim(1),xlim(2),size(F,2));
+y_m=linspace(ylim(2),ylim(1),size(F,1)); %getframe reverse axis...
+%plot the data in another figure
+figure
+imagesc(x_m,y_m,F); set(gca,'Ydir','normal');
 
 %plot existing profile if any
+prevplot=1;
+prevplot2=1;
 hold on
 if numprofiles
@@ -94,63 +100,61 @@
 while loop
 
-	%is there a profile in A?
-	if isexist
-
-		%Go through A and rule out the empty profiles
-		list=[];
-		for i=1:size(A,2);
-			if length(A(i).x)==0
-				list(end+1)=i;
-				numprofiles=numprofiles-1;
-			end
-		end
-		A(list)=[];
-		closed(list)=[];
-
-		%display menu
-		title('Main Menu','FontSize',14);
-		button=menu('Menu','add a profile',...  %1
-		'remove a profile',...                  %2
-		'modify the position of a point',...    %3
-		'add points inside a profile',...       %4
-		'add points at the end of a profile',...%5
-		'remove points',...                     %6
-		'remove several points',...             %7
-		'cut a segment',...                     %8
-		'cut a large area',...                  %9
-		'merge profiles',...                    %10
-		'close profile',...                     %11
-		'undo',...                              %12
-		'redo',...                              %13
-		'quit');                                %14
-
-
-		%UNDO??
-		if button==12;
-			if counter==1
-				disp('Already at oldest change');
-			else
-				counter=counter-1;
-				A=backup{counter,1};
-				numprofiles=backup{counter,2};
-				numpoints=backup{counter,3};
-				closed=backup{counter,4};
-			end
-		end
-
-		%REDO??
-		if button==13
-			if counter==size(backup,1)
-				disp('Already at newest change');
-			else
-				counter=counter+1;
-				A=backup{counter,1};
-				numprofiles=backup{counter,2};
-				numpoints=backup{counter,3};
-				closed=backup{counter,4};
-			end
-		end
-
-		switch button
+	%Go through A and rule out the empty profiles
+	list=[];
+	for i=1:size(A,2);
+		if length(A(i).x)==0
+			list(end+1)=i;
+			numprofiles=numprofiles-1;
+		end
+	end
+	A(list)=[];
+	closed(list)=[];
+
+	%display menu
+	title('Main Menu','FontSize',14);
+	button=menu('Menu','add a profile (open)',...%1
+		'add a contour (closed)',...              %2
+		'remove a profile',...                    %3
+		'modify the position of a point',...      %4
+		'add points inside a profile',...         %5
+		'add points at the end of a profile',...  %6
+		'remove points',...                       %7
+		'remove several points',...               %8
+		'cut a segment',...                       %9
+		'cut a large area',...                    %10
+		'merge profiles',...                      %11
+		'close profile',...                       %12
+		'undo',...                                %13
+		'redo',...                                %14
+		'quit');                                  %15
+
+
+	%UNDO??
+	if button==13;
+		if counter==1
+			disp('Already at oldest change');
+		else
+			counter=counter-1;
+			A=backup{counter,1};
+			numprofiles=backup{counter,2};
+			numpoints=backup{counter,3};
+			closed=backup{counter,4};
+		end
+	end
+
+	%REDO??
+	if button==14
+		if counter==size(backup,1)
+			disp('Already at newest change');
+		else
+			counter=counter+1;
+			A=backup{counter,1};
+			numprofiles=backup{counter,2};
+			numpoints=backup{counter,3};
+			closed=backup{counter,4};
+		end
+	end
+
+	switch button
 
 		case 1
@@ -165,4 +169,13 @@
 		case 2
 
+			[A,numprofiles,numpoints,closed]=addcontour(A,numprofiles,numpoints,closed,prevplot2,root);
+			counter=counter+1;
+			backup{counter,1}=A;
+			backup{counter,2}=numprofiles;
+			backup{counter,3}=numpoints;
+			backup{counter,4}=closed;
+
+		case 3
+
 			[A,numprofiles,numpoints,closed]=removeprofile(A,numprofiles,numpoints,closed,prevplot2,root);
 			counter=counter+1;
@@ -172,5 +185,5 @@
 			backup{counter,4}=closed;
 
-		case 3
+		case 4
 
 			[A,numprofiles,numpoints,closed]=modifyposition(A,numprofiles,numpoints,closed,prevplot,root);
@@ -181,5 +194,5 @@
 			backup{counter,4}=closed;
 
-		case 4
+		case 5
 
 			[A,numprofiles,numpoints,closed]=addinsideprofile(A,numprofiles,numpoints,closed,prevplot,root);
@@ -190,5 +203,5 @@
 			backup{counter,4}=closed;
 
-		case 5
+		case 6
 
 			[A,numprofiles,numpoints,closed]=addendprofile(A,numprofiles,numpoints,closed,prevplot2,root);
@@ -199,5 +212,5 @@
 			backup{counter,4}=closed;
 
-		case 6
+		case 7
 
 			[A,numprofiles,numpoints,closed]=removepoints(A,numprofiles,numpoints,closed,prevplot,root);
@@ -208,5 +221,5 @@
 			backup{counter,4}=closed;
 
-		case 7
+		case 8
 
 			[A,numprofiles,numpoints,closed]=removeseveralpoints(A,numprofiles,numpoints,closed,prevplot,root);
@@ -217,5 +230,5 @@
 			backup{counter,4}=closed;
 
-		case 8
+		case 9
 
 			[A,numprofiles,numpoints,closed]=cutprofile(A,numprofiles,numpoints,closed,prevplot,root);
@@ -226,5 +239,5 @@
 			backup{counter,4}=closed;
 
-		case 9
+		case 10
 
 			[A,numprofiles,numpoints,closed]=cutarea(A,numprofiles,numpoints,closed,prevplot,root);
@@ -235,5 +248,5 @@
 			backup{counter,4}=closed;
 
-		case 10
+		case 11
 
 			[A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root);
@@ -245,5 +258,5 @@
 
 
-		case 11
+		case 12
 
 			[A,numprofiles,numpoints,closed]=closeprofile(A,numprofiles,numpoints,closed,prevplot,root);
@@ -254,6 +267,6 @@
 			backup{counter,4}=closed;
 
-		%QUIT
-		case 14
+			%QUIT
+		case 15
 
 			loop=0;
@@ -263,20 +276,10 @@
 			%do nothing
 
-		end
-
-    %no argus file has been given in input, go to addcontour directly
-	else
-		[A,numprofiles,numpoints,closed]=addprofile(A,numprofiles,numpoints,closed,prevplot2,root);
-		counter=counter+1;
-		backup{counter,1}=A;
-		backup{counter,2}=numprofiles;
-		backup{counter,3}=numpoints;
-		backup{counter,4}=closed;
-		isexist=1;
-	 end
-
-	 %Now erase all that have been done and plot the new structure A as it is
-	 undoplots(prevplot);
+	end
+
+	%Now erase all that have been done and plot the new structure A as it is
+	undoplots(prevplot);
 	if numprofiles
+		prevplot2=1;
 		for i=1:numprofiles
 			plot(A(i).x,A(i).y,'-r','MarkerSize',10);
@@ -289,5 +292,5 @@
 
 %write contour using expwrite
-title('New file written, exiting','FontSize',14);
+title('New file written, exiting...','FontSize',14);
 if isempty(A)
 	disp('Profile empty, no file written')
@@ -295,2 +298,5 @@
 	expwrite(A,newfile);
 end
+
+%close window
+close;
Index: /issm/trunk/src/m/utils/Exp/ginputquick.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/ginputquick.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/ginputquick.m	(revision 33)
@@ -21,5 +21,5 @@
 
 %   Copyright 1984-2005 The MathWorks, Inc.
-%   $Revision: 1.2 $  $Date: 2009/03/27 00:44:53 $
+%   $Revision: 1.1 $  $Date: 2009/04/03 22:56:26 $
 
 out1 = []; out2 = []; out3 = []; y = [];
Index: /issm/trunk/src/m/utils/Exp/manipulation/addcontour.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/addcontour.m	(revision 33)
+++ /issm/trunk/src/m/utils/Exp/manipulation/addcontour.m	(revision 33)
@@ -0,0 +1,52 @@
+function [A,numprofiles,numpoints,closed]=addcontour(A,numprofiles,numpoints,closed,prevplot,root);
+%ADDCONTOUR - add a closed contour
+%
+%   this script is used by expmaster as an elementary operation
+%   on an ARGUS profile
+%
+%   Usage:
+%      [A,numprofiles,numpoints,closed]=addcontour(A,numprofiles,numpoints,closed,prevplot,root)
+		   
+	title('click to add a point to the new profile, RETURN to exit','FontSize',14)
+	hold on
+
+	loop=1;
+	x=[];
+	y=[];
+
+	while loop
+
+		[xi,yi] = ginput(1);
+					  
+		if ~isempty(xi)
+			x(end+1,1)=xi;
+			y(end+1,1)=yi;
+
+			%plot everything
+			undoplots(prevplot);
+			if length(x)
+				plot(x,y,'-rs','MarkerSize',10);
+			end
+			plot(x,y,'rs','MarkerSize',10);
+			plot(x(end),y(end),'rs','MarkerSize',14);
+
+		else
+
+			%check that the profile is not empty
+			if ~isempty(x)
+				x(end+1)=x(1);
+				y(end+1)=y(1);
+				A(end+1).x=x; 
+				A(end).y=y; 
+				A(end).name=root; 
+				A(end).density=1; 
+				numprofiles=numprofiles+1;
+				numpoints=numpoints+length(x);
+				closed(end+1)=1;
+			end
+
+			%get out
+			loop=0;
+		end
+	end
+end
Index: /issm/trunk/src/m/utils/Exp/manipulation/addendprofile.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/addendprofile.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/manipulation/addendprofile.m	(revision 33)
@@ -10,5 +10,5 @@
 	%some checks
 	if numprofiles==0
-		disp('no profile present')
+		disp('no profile present, exiting...')
 		return
 	end	   
Index: /issm/trunk/src/m/utils/Exp/manipulation/addinsideprofile.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/addinsideprofile.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/manipulation/addinsideprofile.m	(revision 33)
@@ -10,9 +10,9 @@
 	%some checks
 	if numprofiles==0
-		disp('no profile present')
+		disp('no profile present, exiting...')
 		return
 	end	   
 	if numpoints<2
-		disp('at least two points are required')
+		disp('at least two points are required, exiting...')
 		return
 	end	   
@@ -39,5 +39,5 @@
 			%check that at least one segment exists
 			if indsel==0
-				disp('at least two points in one profile are required')
+				disp('at least two points in one profile are required, exiting...')
 				return
 			end
Index: /issm/trunk/src/m/utils/Exp/manipulation/closeprofile.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/closeprofile.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/manipulation/closeprofile.m	(revision 33)
@@ -22,4 +22,14 @@
 	while loop
 
+		%some checks,
+		if numprofiles==0    
+			disp('no profile present, exiting...')
+			return            
+		end  
+		if ~any(~closed),
+			disp('All the profiles are closed, exiting...')
+			return
+		end
+
 		[xi,yi] = ginput(1);
 					  
@@ -30,8 +40,11 @@
 
 			if ismember(profsel,selection)
-				%profile was in selection, close it
+				%profile was in selection, remove it from the selection
 				selection(find(selection==profsel))=[];
 				%back to red
 				plot(A(profsel).x,A(profsel).y,'-r','MarkerSize',10);
+			elseif closed(profsel),
+				%profile already closed, do nothing
+				disp('selected profile aready closed, make another selection'),
 			else
 				%add the profile to the list to be closed
@@ -43,12 +56,8 @@
 			%close the profiles
 			for i=1:length(selection),
-				if (A(selection(i)).x(end)~=A(selection(i)).x(1) | A(selection(i)).y(end)~=A(selection(i)).y(1))
-					A(selection(i)).x(end+1)=A(selection(i)).x(1);
-					A(selection(i)).y(end+1)=A(selection(i)).y(1);
-					numpoints=numpoints+1;
-					closed(selection(i))=1;
-				else
-					disp('one profile is already closed')
-				end
+				A(selection(i)).x(end+1)=A(selection(i)).x(1);
+				A(selection(i)).y(end+1)=A(selection(i)).y(1);
+				numpoints=numpoints+1;
+				closed(selection(i))=1;
 			end
 			loop=0;
Index: /issm/trunk/src/m/utils/Exp/manipulation/cutarea.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/cutarea.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/manipulation/cutarea.m	(revision 33)
@@ -26,9 +26,9 @@
 		%some checks
 		if numprofiles==0
-			disp('no profile present')
+			disp('no profile present, exiting...')
 			return
 		end	   
 		if numpoints<3
-			disp('at least two points are needed')
+			disp('at least two points are needed, exiting...')
 			return
 		end	   
@@ -131,4 +131,5 @@
 							end
 						end
+
 						%plot new profile
 						undoplots(prevplot);
@@ -137,4 +138,5 @@
 						end
 						points=[];
+
 					end
 				end
Index: /issm/trunk/src/m/utils/Exp/manipulation/cutprofile.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/cutprofile.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/manipulation/cutprofile.m	(revision 33)
@@ -10,5 +10,5 @@
 	%some checks
 	if numprofiles==0
-		disp('no profile present')
+		disp('no profile present, exiting...')
 		return
 	end	   
Index: /issm/trunk/src/m/utils/Exp/manipulation/mergeprofiles.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/mergeprofiles.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/manipulation/mergeprofiles.m	(revision 33)
@@ -1,4 +1,4 @@
 function [A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root);
-%MERGEPROFILES - morge profiles
+%MERGEPROFILES - merge profiles
 %
 %   this script is used by expmaster as an elementary operation
@@ -9,17 +9,36 @@
 %      [A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root)
 
-	hold on
-	loop=1;
+hold on
+loop=1;
 
-	%Take all the tips coordinates
-	tips=zeros(2*numprofiles,4);
-	for i=1:numprofiles
+%Take all the tips coordinates of open profiles
+counter=1; tips=[];
+for i=1:numprofiles
+	if ~closed(i),
 		%x and y coord, profile number, 1 if beginning, 2 and if end
-		tips(2*i-1,:)=[A(i).x(1)   A(i).y(1)   i  1];
-		tips(2*i,:) = [A(i).x(end) A(i).y(end) i  2];
+		if length(A(i).x)==1,
+			tips(counter,:)=[A(i).x(1)   A(i).y(1)   i  1];
+			counter=counter+1;
+		else
+			tips(counter,:)=[A(i).x(1)   A(i).y(1)   i  1];
+			tips(counter+1,:) = [A(i).x(end) A(i).y(end) i  2];
+			counter=counter+2;
+		end
 	end
-	%remove the closed profiles fron the list
-	tips([2*find(closed)-1;2*find(closed)],:)=[];
+end
 
+if size(tips,1)<2
+	disp('at least one unclosed profile is required')
+	return
+end
+
+%plot the tips
+plot(tips(:,1),tips(:,2),'rs','Markersize',10);
+firsttip=1;
+
+%loop (at least 2 clicks needed)
+while loop
+
+	%some checks
 	if size(tips,1)<2
 		disp('at least one unclosed profiles are required')
@@ -27,115 +46,103 @@
 	end
 
-	%plot the tips
-	plot(tips(:,1),tips(:,2),'rs','Markersize',10);
-	firsttip=1;
+	%select a point
+	if firsttip
+		title('click on the first tip, RETURN to exit','FontSize',14)
+	else
+		title('click on the second tip, RETURN to exit','FontSize',14)
+	end
 
-	%loop (at least 2 clicks needed)
-	while loop
-	
-		%some checks
-		if size(tips,1)<2
-			disp('at least one unclosed profiles are required')
-			return
-		end
+	[xi,yi] = ginput(1);
 
-		%select a point
+	if ~isempty(xi)
+
 		if firsttip
-			title('click on the first tip, RETURN to exit','FontSize',14)
+			%find the selected tip
+			distance=(xi-tips(:,1)).^2+(yi-tips(:,2)).^2;
+			[dmin tip1]=min(distance);
+			numprofile1=tips(tip1,3);
+			firsttip=0;
+
+			%remove tip1 from tips list
+			newtips=tips;
+			newtips(tip1,:)=[];
+
+			%plot selected tip
+			plot(tips(tip1,1),tips(tip1,2),'bs','MarkerSize',10);
+			plot(A(numprofile1).x,A(numprofile1).y,'-g');
+
+		%second selection
 		else
-			title('click on the second tip, RETURN to exit','FontSize',14)
-		end
+			distance=(xi-newtips(:,1)).^2+(yi-newtips(:,2)).^2;
+			[dmin tip2]=min(distance);
+			numprofile2=newtips(tip2,3);
 
-		[xi,yi] = ginput(1);
+			if numprofile1==numprofile2
+				%close the profile
+				A(numprofile1).x(end+1)=A(numprofile1).x(1);
+				A(numprofile1).y(end+1)=A(numprofile1).y(1);
+				numpoints=numpoints+1;
+				closed(numprofile1)=1;
 
-		if ~isempty(xi)
+			else
 
-			if firsttip
-				%find the selected tip
-				distance=(xi-tips(:,1)).^2+(yi-tips(:,2)).^2;
-				[dmin tip1]=min(distance);
-				numprofile1=tips(tip1,3);
-				firsttip=0;
+				if tips(tip1,4)==1 & newtips(tip2,4)==1,
+					A(numprofile1).x=[flipud(A(numprofile2).x); A(numprofile1).x];
+					A(numprofile1).y=[flipud(A(numprofile2).y); A(numprofile1).y];
+					numprofiles=numprofiles-1;
 
-				%remove tip1 grom tips list
-				newtips=tips;
-				newtips(tip1,:)=[];
+				elseif tips(tip1,4)==1 & newtips(tip2,4)==2,
+					A(numprofile1).x=[A(numprofile2).x; A(numprofile1).x];
+					A(numprofile1).y=[A(numprofile2).y; A(numprofile1).y];
+					numprofiles=numprofiles-1;
 
-				%plot selected tip
-				plot(tips(tip1,1),tips(tip1,2),'bs','MarkerSize',10);
-				plot(A(numprofile1).x,A(numprofile1).y,'-g');
+				elseif tips(tip1,4)==2 & newtips(tip2,4)==1,
+					A(numprofile1).x=[A(numprofile1).x; A(numprofile2).x];
+					A(numprofile1).y=[A(numprofile1).y; A(numprofile2).y];
+					numprofiles=numprofiles-1;
 
-			%second selection
-			else
-				distance=(xi-newtips(:,1)).^2+(yi-newtips(:,2)).^2;
-				[dmin tip2]=min(distance);
-				numprofile2=newtips(tip2,3);
-
-				%reverse if necessary
-				if numprofile2<numprofile1
-					fakeprofile=numprofile2;
-					numprofile2=numprofile1;
-					numprofile1=fakeprofile;
+				elseif tips(tip1,4)==2 & newtips(tip2,4)==2,
+					A(numprofile1).x=[A(numprofile1).x; flipud(A(numprofile2).x)];
+					A(numprofile1).y=[A(numprofile1).y; flipud(A(numprofile2).y)];
+					numprofiles=numprofiles-1;
 				end
 
-				if numprofile1==numprofile2
-					%close the profile
-					A(numprofile1).x(end+1)=A(numprofile1).x(1);
-					A(numprofile1).y(end+1)=A(numprofile1).y(1);
-					numpoints=numpoints+1;
-					closed(numprofile1)=1;
+				%delete profile2
+				A(numprofile2)=[];
+				closed(numprofile2)=[];
 
-				else
+			end
 
-					if tips(tip1,4)==1 & newtips(tip2,4)==1,
-						A(numprofile1).x=[flipud(A(numprofile2).x); A(numprofile1).x];
-						A(numprofile1).y=[flipud(A(numprofile2).y); A(numprofile1).y];
-						numprofiles=numprofiles-1;
-						closed(numprofile1)=1;
+			%update tips
+			counter=1; tips=[];
+			for i=1:numprofiles
+				if ~closed(i),
+					%x and y coord, profile number, 1 if beginning, 2 and if end
+					if length(A(i).x)==1,
+						tips(counter,:)=[A(i).x(1)   A(i).y(1)   i  1];
+						counter=counter+1;
+					else
+						tips(counter,:)=[A(i).x(1)   A(i).y(1)   i  1];
+						tips(counter+1,:) = [A(i).x(end) A(i).y(end) i  2];
+						counter=counter+2;
+					end
+				end
+			end
 
-					elseif tips(tip1,4)==1 & newtips(tip2,4)==2,
-						A(numprofile1).x=[A(numprofile2).x; A(numprofile1).x];
-						A(numprofile1).y=[A(numprofile2).y; A(numprofile1).y];
-						numprofiles=numprofiles-1;
-						closed(numprofile1)=1;
+			%plot new profile
+			undoplots(prevplot);
+			for i=1:numprofiles
+				plot(A(i).x,A(i).y,'-r','MarkerSize',10);
+			end
+			if ~isempty(tips)
+				plot(tips(:,1),tips(:,2),'rs','Markersize',10);
+			end
 
-					elseif tips(tip1,4)==2 & newtips(tip2,4)==1,
-						A(numprofile1).x=[A(numprofile1).x; A(numprofile2).x];
-						A(numprofile1).y=[A(numprofile1).y; A(numprofile2).y];
-						numprofiles=numprofiles-1;
-						closed(numprofile1)=1;
-
-					elseif tips(tip1,4)==2 & newtips(tip2,4)==2,
-						A(numprofile1).x=[A(numprofile1).x; flipud(A(numprofile2).x)];
-						A(numprofile1).y=[A(numprofile1).y; flipud(A(numprofile2).y)];
-						numprofiles=numprofiles-1;
-						closed(numprofile1)=1;
-					end
-
-					%delete profile2
-					A(numprofile2)=[];
-					closed(numprofile2)=[];
-
-				end
-
-				%update tips
-				tips=newtips;
-				tips(tip2,:)=[];
-				tips(find(tips(:,3)==numprofile2),3)=numprofile1;
-
-				%plot new profile
-				undoplots(prevplot);
-				for i=1:numprofiles
-					plot(A(i).x,A(i).y,'-r','MarkerSize',10);
-				end
-				plot(tips(:,1),tips(:,2),'rs','Markersize',10);
-
-				%back to beginning
-				firsttip=1;
-			end
-		else
-			%RETRUN-> quit
-			loop=0;
+			%back to beginning
+			firsttip=1;
 		end
+	else
+		%RETRUN-> quit
+		loop=0;
 	end
 end
Index: /issm/trunk/src/m/utils/Exp/manipulation/modifyposition.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/modifyposition.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/manipulation/modifyposition.m	(revision 33)
@@ -10,5 +10,5 @@
 	%some checks
 	if numprofiles==0
-		disp('no profile present')
+		disp('no profile present, exiting..')
 		return
 	end
Index: /issm/trunk/src/m/utils/Exp/manipulation/removepoints.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/removepoints.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/manipulation/removepoints.m	(revision 33)
@@ -10,5 +10,5 @@
 	%some checks
 	if numprofiles==0
-		disp('no profile present')
+		disp('no profile present, exiting...')
 		return
 	end
Index: /issm/trunk/src/m/utils/Exp/manipulation/removeprofile.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/removeprofile.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/manipulation/removeprofile.m	(revision 33)
@@ -18,5 +18,5 @@
 		%some checks
 		if numprofiles==0
-			disp('no profile to be removed')
+			disp('no profile to be removed, exiting...')
 			return
 		end
Index: /issm/trunk/src/m/utils/Exp/manipulation/removeseveralpoints.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/manipulation/removeseveralpoints.m	(revision 32)
+++ /issm/trunk/src/m/utils/Exp/manipulation/removeseveralpoints.m	(revision 33)
@@ -10,9 +10,9 @@
 	%some checks
 	if numprofiles==0
-		disp('no profile present')
+		disp('no profile present, exiting...')
 		return
 	end	   
 	if numpoints<3
-		disp('at least two points are needed')
+		disp('at least 3 points are required, exiting...')
 		return
 	end	   
@@ -29,4 +29,10 @@
 	%loop (at least 3 clicks needed)
 	while loop
+
+		%some checks
+		if numpoints<3
+			disp('at least 3 points are required, exiting...')
+			return
+		end
 
 		%select a point
@@ -54,4 +60,5 @@
 					text(A(selection).x(indsel),A(selection).y(indsel),num2str(1),'FontSize',14,'background',[0.7 0.7 0.9]);
 				end
+				%disp(['p1= ' num2str(indsel)]),
 			else
 				%get the 2d or 3d point for the given contou
@@ -64,7 +71,9 @@
 						points(end+1)=indsel;
 						text(A(selection).x(indsel),A(selection).y(indsel),num2str(2),'FontSize',14,'background',[0.7 0.7 0.9]);
+						%disp(['p2= ' num2str(indsel)]),
 					%third click?
 					else
 						p1=points(1); p2=points(2); p3=indsel;
+						%disp(['p3= ' num2str(indsel)]),
 						if p1<p2
 							if p3>p1 & p3<p2
@@ -72,5 +81,4 @@
 								A(selection).y(p1+1:p2-1)=[];
 								numpoints=numpoints-(p2-p1-1);
-								loop=0;
 							else
 								A(selection).x=A(selection).x(p1:p2);
@@ -83,5 +91,4 @@
 									numpoints=numpoints+1;
 								end
-								loop=0;
 							end
 						else
@@ -90,6 +97,4 @@
 								A(selection).y(p2+1:p1-1)=[];
 								numpoints=numpoints-(p1-p2-1);
-								loop=0;
-
 							else
 								A(selection).x=A(selection).x(p2:p1);
@@ -102,7 +107,14 @@
 									numpoints=numpoints+1;
 								end
-								loop=0;
 							end
 						end
+
+						%plot new profiles
+						undoplots(prevplot);
+						for i=1:numprofiles
+							plot(A(i).x,A(i).y,'-rs','MarkerSize',10);
+						end
+						points=[];
+
 					end
 				end
Index: /issm/trunk/src/m/utils/Mesh/squaremesh.m
===================================================================
--- /issm/trunk/src/m/utils/Mesh/squaremesh.m	(revision 33)
+++ /issm/trunk/src/m/utils/Mesh/squaremesh.m	(revision 33)
@@ -0,0 +1,78 @@
+function md=squaremesh(md,Lx,Ly,nx,ny)
+%SQUAREMESH - create a structured square mesh 
+%
+%   This script will generate a structured square mesh
+%   Lx and Ly are the dimension of the domain (in meters)
+%   nx anx ny are the number of nodes in the x and y direction
+%   The coordinates x and y returned are in meters.
+%
+%   Usage:
+%      [x y index]=squaremesh(Lx,Ly,nx,ny)
+
+%get number og elements and number of nodes
+nel=(nx-1)*(ny-1)*2;
+nods=nx*ny;
+
+%initialization
+segments=zeros(0,3);
+index=zeros(nel,3);
+x=zeros(nx*ny,1);
+y=zeros(nx*ny,1);
+counter=1;
+
+%create coordinates
+for n=1:nx,
+	for m=1:ny,
+		x((n-1)*ny+m)=(n-1);
+		y((n-1)*ny+m)=(m-1);
+	end
+end
+
+%create index
+for n=1:(nx-1)
+	for m=1:(ny-1),
+		A=(n-1)*ny+m;
+		B=A+1;
+		C=n*ny+m;
+		D=C+1;
+		index((n-1)*(ny-1)*2+2*(m-1)+1,:)=[A C B];
+		index((n-1)*(ny-1)*2+2*m,:)=[B C D];
+	end
+end
+
+%Scale  x and y
+x=x/max(x)*Lx;
+y=y/max(y)*Ly;
+
+%create segments
+segments=zeros(2*(nx-1)+2*(ny-1),3);
+%left edge:
+segments(1:ny-1,:)=[[2:ny]' [1:ny-1]' 2*[1:ny-1]'-1];
+%right edge:
+segments(ny:2*(ny-1),:)=[[ny*(nx-1)+1:nx*ny-1]' [ny*(nx-1)+2:nx*ny]' 2*[(ny-1)*(nx-2)+1:(nx-1)*(ny-1)]'];
+%front edge:
+segments(2*(ny-1)+1:2*(ny-1)+(nx-1),:)=[[2*ny:ny:ny*nx]' [ny:ny:ny*(nx-1)]' [2*(ny-1):2*(ny-1):2*(nx-1)*(ny-1)]'];
+%back edge
+segments(2*(ny-1)+(nx-1)+1:2*(nx-1)+2*(ny-1),:)=[[1:ny:(nx-2)*ny+1]' [ny+1:ny:ny*(nx-1)+1]' [1:2*(ny-1):2*(nx-2)*(ny-1)+1]'];
+
+%plug coordinates and grids
+md.x=x;
+md.y=y;
+md.z=zeros(nods,1);
+md.numberofgrids=nods;
+md.gridonboundary=zeros(nods,1);md.gridonboundary(segments(:,1:2))=1;
+md.gridonbed=ones(nods,1);
+md.gridonsurface=ones(nods,1);
+
+%plug elements
+md.elements=index;
+md.segments=segments;
+md.numberofelements=nel;
+md.elementonbed=ones(nel,1);
+md.elementonsurface=ones(nel,1);
+
+%plug other field
+md.type='2d';
+md.counter=1;
+md.riftoutline='';
+md.domainoutline='Square';
Index: /issm/trunk/src/m/utils/Nightly/nightlyrun.m
===================================================================
--- /issm/trunk/src/m/utils/Nightly/nightlyrun.m	(revision 32)
+++ /issm/trunk/src/m/utils/Nightly/nightlyrun.m	(revision 33)
@@ -5,5 +5,5 @@
 
 %Go to Test directory
-eval(['cd ' ISSM_DIR '/tests/']);
+eval(['cd ' ISSM_DIR '/test/']);
 
 %Run all verification tests
Index: /issm/trunk/src/m/utils/UpdateArchive/updatearchive.m
===================================================================
--- /issm/trunk/src/m/utils/UpdateArchive/updatearchive.m	(revision 32)
+++ /issm/trunk/src/m/utils/UpdateArchive/updatearchive.m	(revision 33)
@@ -6,5 +6,5 @@
 
 %Go to Test directory
-eval(['cd ' ISSM_DIR '/Tests/']);
+eval(['cd ' ISSM_DIR '/test/']);
 
 %Run all verification tests
