function RETURN=rowop(matrix,user)
global undo; %this allows for undoing of previous command if global undo is declared in calling environment.

global noprint
global err

noprint=0;
err=0;

if(exist('matrix')==0) %check if passed matrix is defined
  noprint=1;
  sprintf('%s\n','The matrix you have passed as an argument to ROWOP has not been defined.')

 error(' ')
end

undo=matrix;
sizecheck=size(matrix);




check_for_c=findstr(user,'c'); 
if (isempty(check_for_c)==0)
sprintf('%s','When using ROWOP you must use [r] in the command line instead of [c] (which you use with the function COLOP)')
err=1;
error('  ')
end

a = sscanf(user,' r%d = r%d %[+-] r%d'); %note: this also used for sign_coeff

if (size(a)==[4,1]) %no multiplier or brackets
     q = sscanf(user,' r%d = r%d %[+-] r%d');
     operand=q(1,1);
     multiplier=1;
     multiplee=q(4,1);
     check=q(2,1);

else  %there exists multiplier and possibly brackets, division operator
   brackets=findstr(user, '(' ); %check for bracket
   m=findstr(user,'/');      %check for fractional multiplier
 
     if (isempty(m)==1)    % case there is no division operator in string
        if (isempty(brackets)==1) %case no brackets no division operator
                nobracknodiv=sscanf(user,' r%d = r%d %[+-]%f r%d'); 
                operand=nobracknodiv(1,1);
                multiplier=nobracknodiv(4,1);
            	multiplee=nobracknodiv(5,1);
		check=nobracknodiv(2,1);

         else     %case have brackets but no division operator
		bracknodiv=sscanf(user,' r%d = r%d %[+-] ( %f ) r%d');
		operand=bracknodiv(1,1);
		multiplier=bracknodiv(4,1);
		multiplee=bracknodiv(5,1);
		check=bracknodiv(2,1);
	end

    else  % case there is a division operator: scan string accordingly
        if (isempty(brackets)==1) %case no brackets and have division operator
                b=sscanf(user,' r%d = r%d %[+-]%f / %f r%d');
       	        operand=b(1,1);
          	multiplier=b(4,1)/b(5,1);
          	multiplee=b(6,1);
		check=b(2,1);

      	else  %case have brackets and have division operator
		brackplusdiv=sscanf(user,' r%d = r%d %[+-] ( %f / %f ) r%d');
		operand=brackplusdiv(1,1);
          	multiplier=brackplusdiv(4,1)/brackplusdiv(5,1);
          	multiplee=brackplusdiv(6,1);
		check=brackplusdiv(2,1);
        end
  end
end

% consistency and size checks
mistake_true=0;

if(operand>sizecheck(1,1))
sprintf('%s\n%s','Error: The index number of the row you attempted to operate on','exceeds the number of rows in the matrix (on the left hand side of your expression).')
mistake_true=mistake_true+1;
err=1;
end

if(check>sizecheck(1,1))
sprintf('%s\n%s','Error: The index number of the row you attempted to operate on','exceeds the number of rows in the matrix (on the right hand side of your expression).')
mistake_true=mistake_true+1;
err=1;
end


if(multiplee>sizecheck(1,1))
sprintf('%s\n%s','Error: The index number of the row you attempted to add or subtract ','exceeds the number of rows in the matrix.')
mistake_true=mistake_true+1;
err=1;
end

if (check ~= operand)
sprintf('%s \n\n%s \n\n%s \n\n%s','Inconsistency: You have entered an expression of the form: ','                rA = rB + JrK','The correct form is: ','                rA = rA + JrK')  %no semi-colon to print to screen
mistake_true=mistake_true+1;
err=1;
end

if(mistake_true>0)
RETURN=matrix; 

return
end



%sprintf('%s %d','leaving rowop err=',err)



% scan for +,- sign using ASCII codes
if (a(3,1)==43)
sign_coeff=1;
elseif (a(3,1)==45)
sign_coeff= -1;
end

% execute rowop
matrix(operand,:)=matrix(operand,:) +sign_coeff*multiplier*matrix(multiplee,:);

RETURN=matrix;





