Index: prextra/@ftp/active.m
===================================================================
--- prextra/@ftp/active.m	(revision 113)
+++ prextra/@ftp/active.m	(revision 113)
@@ -0,0 +1,18 @@
+function active(h)
+% ACTIVE Change to active mode
+%   ACTIVE(FTP) changes the communication mode of FTP to active mode.
+
+% Idin Motedayen-Aval
+
+% Make sure we're still connected.
+connect(h)
+
+if (nargin ~= 1)
+    error('Incorrect number of arguments.')
+end
+
+h.jobject.enterLocalActiveMode;
+
+% There isn't an easier way to set the value of a StringBuffer.
+h.passiveMode.setLength(0);
+h.passiveMode.append('a');
Index: prextra/@ftp/ascii.m
===================================================================
--- prextra/@ftp/ascii.m	(revision 113)
+++ prextra/@ftp/ascii.m	(revision 113)
@@ -0,0 +1,13 @@
+function ascii(f)
+%ASCII  Sets ASCII transfer type.
+%   ASCII(F) sets ASCII transfer type for the FTP object F.
+
+% Matthew J. Simoneau, 31-Jan-2002
+% Copyright 1984-2005 The MathWorks, Inc.
+
+% Make sure we're still connected.
+connect(f)
+
+% There isn't an easier way to set the value of a StringBuffer.
+f.type.setLength(0);
+f.type.append('ascii');
Index: prextra/@ftp/binary.m
===================================================================
--- prextra/@ftp/binary.m	(revision 113)
+++ prextra/@ftp/binary.m	(revision 113)
@@ -0,0 +1,13 @@
+function binary(f)
+%BINARY  Sets binary transfer type.
+%   BINARY(F) sets binary transfer type for the FTP object F.
+
+% Matthew J. Simoneau, 31-Jan-2002
+% Copyright 1984-2004 The MathWorks, Inc.
+
+% Make sure we're still connected.
+connect(f)
+
+% There isn't an easier way to set the value of a StringBuffer.
+f.type.setLength(0);
+f.type.append('binary');
Index: prextra/@ftp/cd.m
===================================================================
--- prextra/@ftp/cd.m	(revision 113)
+++ prextra/@ftp/cd.m	(revision 113)
@@ -0,0 +1,21 @@
+function newDir = cd(h,str)
+%CD Change current working directory.
+%   CD(FTP,'DIRECTORY') sets the current directory to the one specified.
+%   CD(FTP,'..') moves to the directory above the current one.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2004 The MathWorks, Inc.
+
+% Make sure we're still connected.
+connect(h)
+
+if (nargin > 1)
+    isSuccess = h.jobject.changeWorkingDirectory(str);
+    if ~isSuccess
+        error(message('MATLAB:ftp:NoSuchDirectory', str))
+    end
+end
+newDir = char(h.jobject.printWorkingDirectory);
+% There isn't an easier way to set the value of a StringBuffer.
+h.remotePwd.setLength(0);
+h.remotePwd.append(newDir);
Index: prextra/@ftp/close.m
===================================================================
--- prextra/@ftp/close.m	(revision 113)
+++ prextra/@ftp/close.m	(revision 113)
@@ -0,0 +1,12 @@
+function close(h)
+%CLOSE Close the connection with the server.
+%    CLOSE(FTP) closes the connection with the server.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2004 The MathWorks, Inc.
+
+try
+    h.jobject.disconnect;
+catch
+    % Do nothing.  The error was probably that we were already disconnected.
+end
Index: prextra/@ftp/dataMode.m
===================================================================
--- prextra/@ftp/dataMode.m	(revision 113)
+++ prextra/@ftp/dataMode.m	(revision 113)
@@ -0,0 +1,33 @@
+function dataConnectionMode = dataMode(h)
+% dataMode Change to active mode
+%   dataMode(FTP) returns the current connection status.
+%   Possible return strings are:
+%       'ACTIVE_LOCAL_DATA_CONNECTION_MODE'
+%       'ACTIVE_REMOTE_DATA_CONNECTION_MODE'
+%       'PASSIVE_LOCAL_DATA_CONNECTION_MODE'
+%       'PASSIVE_REMOTE_DATA_CONNECTION_MODE'
+
+% Idin Motedayen-Aval
+% December 2004
+
+% Make sure we're still connected.
+connect(h)
+
+if (nargin ~= 1)
+    error('Incorrect number of arguments.')
+end
+
+modeNumber = h.jobject.getDataConnectionMode;
+
+switch modeNumber
+    case 0
+        dataConnectionMode = 'ACTIVE_LOCAL_DATA_CONNECTION_MODE';
+    case 1
+        dataConnectionMode = 'ACTIVE_REMOTE_DATA_CONNECTION_MODE';
+    case 2
+        dataConnectionMode = 'PASSIVE_LOCAL_DATA_CONNECTION_MODE';
+    case 3
+        dataConnectionMode = 'PASSIVE_REMOTE_DATA_CONNECTION_MODE';
+    otherwise
+        error ('Invalid data connection mode returned.');
+end
Index: prextra/@ftp/delete.m
===================================================================
--- prextra/@ftp/delete.m	(revision 113)
+++ prextra/@ftp/delete.m	(revision 113)
@@ -0,0 +1,26 @@
+function delete(h,filename)
+%DELETE Delete a file on an FTP server.
+%    DELETE(FTP,FILENAME) deletes a file on the server.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2012 The MathWorks, Inc.
+
+% Make sure we're still connected.
+connect(h)
+
+if any(filename=='*')
+    listing = h.jobject.listNames(filename);
+    names = cell(size(listing));
+    for i = 1:length(listing)
+        names{i} = listing(i);
+    end
+else
+    names = {filename};
+end
+
+for i = 1:length(names)
+    status = h.jobject.deleteFile(names{i});
+    if (status == 0)
+        error(message('MATLAB:ftp:DeleteFailed',char(names{i})));
+    end
+end
Index: prextra/@ftp/dir.m
===================================================================
--- prextra/@ftp/dir.m	(revision 113)
+++ prextra/@ftp/dir.m	(revision 113)
@@ -0,0 +1,107 @@
+function varargout = dir(h,str)
+%DIR List directory on an FTP server.
+%   DIR(FTP,DIRECTORY_NAME) lists the files in a directory. Pathnames and
+%   wildcards may be used.  
+%
+%   D = DIR(...) returns the results in an M-by-1
+%   structure with the fields: 
+%       name    -- filename
+%       date    -- modification date
+%       bytes   -- number of bytes allocated to the file
+%       isdir   -- 1 if name is a directory and 0 if not
+%       datenum -- MATLAB serial date number
+%
+%   Because FTP servers do not return directory information in a standard way,
+%   the last four fields in the structure may be empty or some items may
+%   be missing.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2011 The MathWorks, Inc.
+
+% Make sure we're still connected.
+connect(h)
+
+narginchk(0,2)
+if (nargin < 2)
+    str = '.';
+end
+
+ftp=h.jobject;
+ftp.setDataTimeout(15000); % in milliseconds 
+listing=[];
+try
+    remoteFileList=ftp.listFiles(str);
+catch
+    remoteFileList = [];
+end
+form = java.text.SimpleDateFormat('dd-MMM-yyyy HH:mm:ss');
+%form = java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG,java.util.Locale.US);
+for i=1:length(remoteFileList);
+    file=remoteFileList(i);
+    listing(i,1).name=char(file.getName);
+    if nargout == 1
+        listing(i,1).bytes=file.getSize;
+        listing(i,1).isdir=~logical(file.isFile);
+        cal=file.getTimestamp;
+        if isempty(cal) % A user reported this coming back empty, see g575311.
+            listing(i,1).date = '';
+            listing(i,1).datenum = [];
+        else
+            listing(i,1).date=char(form.format(cal.getTime));
+            yr=cal.get(cal.YEAR);
+            mon=cal.get(cal.MONTH) + 1;
+            day=cal.get(cal.DATE);
+            hr=cal.get(cal.HOUR_OF_DAY);
+            min=cal.get(cal.MINUTE);
+            sec=cal.get(cal.SECOND);
+            listing(i,1).datenum=datenum(yr,mon,day,hr,min,sec);
+        end
+    end
+end
+
+% For Window's FTP server, listFiles is empty.  Just get the names.
+if isempty(listing)
+    names=ftp.listNames(str);
+    for i=1:length(names)
+        listing(i,1).name=char(names(i));
+        listing(i,1).date='';
+        listing(i,1).bytes=[];
+        listing(i,1).isdir=[];
+        listing(i,1).datenum=[];
+    end
+end
+
+switch nargout
+case 0
+    disp(' ');
+    if ~isempty(listing)
+        disp(convertListToColumns(char(listing.name)));
+    end
+    disp(' ');
+case 1
+    varargout={listing};
+end
+
+%================================================================================
+function list=convertListToColumns(list)
+
+% Pad the list out with two extra spaces to separate the columns
+list=[list ' '*ones(size(list,1),2)];
+
+% Calculate the number of columns that fit on the screen
+windowWidth=get(0,'CommandWindowSize')*[1;0];
+numberOfColumns=floor(windowWidth/size(list,2));
+if (numberOfColumns==0)
+    numberOfColumns=1;
+end
+
+% Calculate the number of rows and pad out the remaining column
+rows=ceil(size(list,1)/numberOfColumns);
+pad=rows*numberOfColumns-size(list,1);
+list=[list;' '*ones(pad,size(list,2))];
+
+% Reshape the list into the columns (trick from Zhiping)
+[r,c]=size(list);
+[I,J]=find(ones(rows,r*c/rows));
+ind=sub2ind(size(list), floor((J-1)/c)*rows+I, rem(J-1,c)+1);
+list=reshape(list(ind),rows,r*c/rows);
Index: prextra/@ftp/disp.m
===================================================================
--- prextra/@ftp/disp.m	(revision 113)
+++ prextra/@ftp/disp.m	(revision 113)
@@ -0,0 +1,17 @@
+function disp(h)
+% DISP Display method for the FTP object.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2012 The MathWorks, Inc.
+
+if length(h) ~= 1
+    % FTP array; Should work for empty case as well.
+    s = size(h);
+    str = sprintf('%dx',s);
+    str(end) = [];
+    disp(getString(message('MATLAB:ftp:ArrayOfFtp',str)));
+else
+    disp(sprintf( ...
+        '  FTP Object\n     host: %s\n     user: %s\n      dir: %s\n     mode: %s', ...
+        h.host,h.username,char(h.remotePwd.toString),char(h.type.toString)));
+end
Index: prextra/@ftp/display.m
===================================================================
--- prextra/@ftp/display.m	(revision 113)
+++ prextra/@ftp/display.m	(revision 113)
@@ -0,0 +1,9 @@
+function display(h)
+% DISPLAY Display method for the FTP object.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2004 The MathWorks, Inc.
+
+fprintf('\n%s = \n\n',inputname(1));
+disp(h)
+fprintf('\n');
Index: prextra/@ftp/ftp.m
===================================================================
--- prextra/@ftp/ftp.m	(revision 113)
+++ prextra/@ftp/ftp.m	(revision 113)
@@ -0,0 +1,77 @@
+function h = ftp(host,username,password)
+% FTP Create an FTP object.
+%    FTP(host,username,password) returns an FTP object.  If only a host is 
+%    specified, it defaults to "anonymous" login.
+%
+%    An alternate port can be specified by separating it from the host name
+%    with a colon.  For example: ftp('ftp.mathworks.com:34')
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2008 The MathWorks, Inc.
+% $Revision: 1.1.4.3 $  $Date: 2008/11/04 21:20:59 $
+
+% Our FTP implementation uses code from the Apache Jakarta Project.
+% Copyright (c) 2001 The Apache Software Foundation.  All rights reserved.
+
+error(javachk('jvm','The FTP object'))
+
+% Short-circuit cases.
+if (nargin == 0)
+   % All MATLAB objects need a default constructor.  It is useless, though.
+   % Immutable fields.
+   h.jobject = org.apache.commons.net.ftp.FTPClient;
+   h.host = '';
+   h.port = 21;
+   h.username = '';
+   h.password = '';
+   % Mutable fields.  Use StringBuffers so these will act as references.
+   h.remotePwd = java.lang.StringBuffer('');
+   h.type = java.lang.StringBuffer('binary');
+   % Make the cast.
+   h = class(h,'ftp');
+   return
+elseif isa(host,'ftp')
+   % If given an FTP object, give it back.
+   h = host;
+   return
+end
+
+% Agrument parsing
+error(nargchk(1,3,nargin))
+switch nargin
+case 3
+    % Everything passed in.
+case 1
+    % Default to anonymous login
+    username = 'anonymous';
+    password = 'anonymous@example.com';
+otherwise
+    error('MATLAB:ftp:IncorrectArgumentCount','Incorrect number of arguments.')
+end
+
+% Immutable fields.
+h.jobject = org.apache.commons.net.ftp.FTPClient;
+colon = find(host==':');
+if isempty(colon)
+    h.host = host;
+    h.port = 21;
+else
+    h.host = host(1:colon-1);
+    h.port = str2double(host(colon+1:end));
+end
+h.username = username;
+h.password = password;
+
+% Mutable fields.  Use StringBuffers so these will act as references.
+h.remotePwd = java.lang.StringBuffer('');
+h.type = java.lang.StringBuffer('binary');
+
+% Keep track of passive/active mode
+% Added by Idin Motedayen-Aval
+h.passiveMode = java.lang.StringBuffer('p');
+
+% Make the cast.
+h = class(h,'ftp');
+
+% Connect.
+connect(h)
Index: prextra/@ftp/ja/cd.m
===================================================================
--- prextra/@ftp/ja/cd.m	(revision 113)
+++ prextra/@ftp/ja/cd.m	(revision 113)
@@ -0,0 +1,8 @@
+%CD  »ÝÌìÆfBNgÌÏX
+%
+%   CD(FTP,'DIRECTORY') ÍAJgfBNgðwèµœfBNgÉ
+%   ÝèµÜ·B
+%   CD(FTP,'..') ÍA1 ÂãÊÌfBNgÉÚ®µÜ·B
+
+
+% Copyright 1984-2008 The MathWorks, Inc.
Index: prextra/@ftp/ja/close.m
===================================================================
--- prextra/@ftp/ja/close.m	(revision 113)
+++ prextra/@ftp/ja/close.m	(revision 113)
@@ -0,0 +1,6 @@
+%CLOSE  T[oÆÌÚ±ðÂ¶é
+%
+%    CLOSE(FTP) ÍAT[oÆÌÚ±ðÂ¶Ü·B
+
+
+% Copyright 1984-2008 The MathWorks, Inc.
Index: prextra/@ftp/ja/delete.m
===================================================================
--- prextra/@ftp/ja/delete.m	(revision 113)
+++ prextra/@ftp/ja/delete.m	(revision 113)
@@ -0,0 +1,7 @@
+% DELETE   FTPT[oãÌt@Cðí
+%
+% DELETE(FTP,FILENAME) ÍAT[oãÌt@CðíµÜ·B
+
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2004 The MathWorks, Inc.
Index: prextra/@ftp/ja/dir.m
===================================================================
--- prextra/@ftp/ja/dir.m	(revision 113)
+++ prextra/@ftp/ja/dir.m	(revision 113)
@@ -0,0 +1,18 @@
+%DIR  FTP T[oãÌfBNgê
+%
+%   DIR(FTP,DIRECTORY_NAME) ÍAfBNgàÌt@Cðê\ŠµÜ·B
+%   pXŒÆChJ[hðg€±ÆªÅ«Ü·B 
+%
+%   D = DIR(...) ÍAÈºÌtB[hðÂ M s 1 ñÌ\¢ÌÆµÄÊð
+%   ÔµÜ·B
+%       name  -- t@CŒ
+%       date  -- t@CXVú
+%       bytes - t@CÖÌèÄoCg
+%       isdir - name ªfBNgÌê 1A»€ÅÈ¢ê 0
+%       datenum -- MATLAB VAÔút
+%
+%   FTP T[oÍWÌû@ÅÍfBNgîñðÔ³È¢œßA\¢ÌÌÅãÌ 
+%   4 ÂÌtB[hÍóÉÈéÂ\«ª èÜ·B
+
+
+% Copyright 1984-2008 The MathWorks, Inc.
Index: prextra/@ftp/ja/disp.m
===================================================================
--- prextra/@ftp/ja/disp.m	(revision 113)
+++ prextra/@ftp/ja/disp.m	(revision 113)
@@ -0,0 +1,5 @@
+% DISP   FTPIuWFNgÌ\bhÌ\Š
+
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2004 The MathWorks, Inc.
Index: prextra/@ftp/ja/display.m
===================================================================
--- prextra/@ftp/ja/display.m	(revision 113)
+++ prextra/@ftp/ja/display.m	(revision 113)
@@ -0,0 +1,4 @@
+% DISPLAY  FTP IuWFNgÉÎ·é\bhÌ\Š
+
+
+% Copyright 1984-2008 The MathWorks, Inc.
Index: prextra/@ftp/ja/ftp.m
===================================================================
--- prextra/@ftp/ja/ftp.m	(revision 113)
+++ prextra/@ftp/ja/ftp.m	(revision 113)
@@ -0,0 +1,11 @@
+% FTP  FTPIuWFNgÌì¬
+%
+% FTP(host,username,password) ÍAFTPIuWFNgðoÍµÜ·BzXgÌÝ
+% wè³êœêAftHgÍ "anonymous"OCÉÈèÜ·B
+%
+% ãíèÌ|[gÆµÄARðgÁœzXgŒ©ç»êðª£µÄwè·é
+% ±ÆªÂ\Å·BáŠÎ: ftp('ftp.mathworks.com:34')B
+
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2004 The MathWorks, Inc.
Index: prextra/@ftp/ja/loadobj.m
===================================================================
--- prextra/@ftp/ja/loadobj.m	(revision 113)
+++ prextra/@ftp/ja/loadobj.m	(revision 113)
@@ -0,0 +1,4 @@
+% LOADOBJ  FTP IuWFNgÉÎ·étB^ÌÇÝÝ
+
+
+% Copyright 1984-2008 The MathWorks, Inc.
Index: prextra/@ftp/ja/mkdir.m
===================================================================
--- prextra/@ftp/ja/mkdir.m	(revision 113)
+++ prextra/@ftp/ja/mkdir.m	(revision 113)
@@ -0,0 +1,6 @@
+%MKDIR  FTP TCgÉVKfBNgðì¬
+%
+%    MKDIR(FTP,DIRECTORY) ÍAFTP TCgÉfBNgðì¬µÜ·B
+
+
+% Copyright 1984-2008 The MathWorks, Inc.
Index: prextra/@ftp/ja/rmdir.m
===================================================================
--- prextra/@ftp/ja/rmdir.m	(revision 113)
+++ prextra/@ftp/ja/rmdir.m	(revision 113)
@@ -0,0 +1,6 @@
+%RMDIR  FTP TCgÌfBNgðí
+%
+%    RMDIR(FTP,DIRECTORY) ÍAFTP TCgÌfBNgðíµÜ·B
+
+
+% Copyright 1984-2008 The MathWorks, Inc.
Index: prextra/@ftp/ja/saveobj.m
===================================================================
--- prextra/@ftp/ja/saveobj.m	(revision 113)
+++ prextra/@ftp/ja/saveobj.m	(revision 113)
@@ -0,0 +1,4 @@
+% SAVEOBJ  FTP IuWFNgÌtB^ðÛ¶
+
+
+% Copyright 1984-2008 The MathWorks, Inc.
Index: prextra/@ftp/loadobj.m
===================================================================
--- prextra/@ftp/loadobj.m	(revision 113)
+++ prextra/@ftp/loadobj.m	(revision 113)
@@ -0,0 +1,7 @@
+function f = loadobj(f)
+% LOADOBJ Load filter for FTP objects.
+
+% Matthew J. Simoneau, 11-Mar-2004
+% Copyright 1984-2004 The MathWorks, Inc.
+
+f.jobject = org.apache.commons.net.ftp.FTPClient;
Index: prextra/@ftp/mget.m
===================================================================
--- prextra/@ftp/mget.m	(revision 113)
+++ prextra/@ftp/mget.m	(revision 113)
@@ -0,0 +1,112 @@
+function location = mget(h,str,targetDirectory)
+%MGET Download from an FTP site.
+%    MGET(FTP,FILENAME) downloads a file.
+%
+%    MGET(FTP,DIRECTORY) downloads a directory and its contents.
+%
+%    MGET(FTP,WILDCARD) downloads a set of files or directories specified
+%    by a wildcard.
+%
+%    MGET(...,TARGETDIRECTORY) specifies the local target directory, rather
+%    than the current directory.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2012 The MathWorks, Inc.
+
+% Make sure we're still connected.
+connect(h)
+
+if (nargin < 3)
+    targetDirectory = pwd;
+end
+
+% Set ascii/binary
+switch char(h.type.toString)
+    case 'binary'
+        h.jobject.setFileType(h.jobject.BINARY_FILE_TYPE);
+    otherwise
+        h.jobject.setFileType(h.jobject.ASCII_FILE_TYPE);
+end
+
+if any(str == '*')
+    list = h.jobject.listNames(str);
+    listing = cell(size(list));
+    for i = 1:length(list)
+        listing{i} = char(list(i));
+    end
+else
+    listing = {str};
+end
+
+iListing = 0;
+location = {};
+while iListing < length(listing)
+    iListing = iListing+1;
+    name = char(listing(iListing));
+    localName = strrep(fullfile(targetDirectory,name),'/',filesep);
+
+    % Where should we save this file?
+    fileObject = java.io.File(localName);
+
+    % Are we trying to overwrite a local file we can't change?
+    if fileObject.exists && ~fileObject.delete
+        error(message('MATLAB:ftp:CannotOverwrite', localName))
+    end
+
+    % Are we trying to write a local file where we don't have permission?
+    try
+        d = java.io.File(fileparts(localName));
+        d.mkdirs;
+        canOpen = fileObject.createNewFile;
+    catch
+        canOpen = false;
+    end
+    if ~canOpen
+        error(message('MATLAB:ftp:CannotCreate', localName));
+    end
+
+    % Download the file.
+    fos = java.io.FileOutputStream(fileObject);
+    h.jobject.retrieveFile(name,fos);
+    fos.close;
+    fschange(fileparts(localName))
+    
+    % Did it work?
+    replyCode = h.jobject.getReplyCode;
+    switch replyCode
+        case 226
+            % "Closing data connection. Requested file action successful."
+            % Build the list of files uploaded.
+            location{end+1,1} = localName;
+        case 550
+            % "Requested action not taken.  File unavailable."
+            fileObject.delete;
+
+            % Couldn't find a file with that name.  Try a directory.
+            currentDir = cd(h);
+            try
+                cd(h,name);
+                isDir = true;
+            catch
+                isDir = false;
+            end
+            cd(h,currentDir);                
+            if isDir
+                mkdir(localName);
+                d = dir(h,name);
+                for i = 1:length(d)
+                    next = d(i).name;
+                    if isequal(next,'.') || isequal(next,'..')
+                        % skip
+                    else
+                        listing{end+1} = [name '/' next];
+                    end
+                end
+            else
+                error(message('MATLAB:ftp:FileUnavailable', name));
+            end
+        otherwise
+            error(message('MATLAB:ftp:FTPError',replyCode))
+    end
+
+end
Index: prextra/@ftp/mkdir.m
===================================================================
--- prextra/@ftp/mkdir.m	(revision 113)
+++ prextra/@ftp/mkdir.m	(revision 113)
@@ -0,0 +1,11 @@
+function mkdir(h,dirname)
+%MKDIR Creates a new directory on an FTP site.
+%    MKDIR(FTP,DIRECTORY) creates a directory on the FTP site.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2004 The MathWorks, Inc.
+
+% Make sure we're still connected.
+connect(h)
+
+h.jobject.makeDirectory(dirname);
Index: prextra/@ftp/mput.m
===================================================================
--- prextra/@ftp/mput.m	(revision 113)
+++ prextra/@ftp/mput.m	(revision 113)
@@ -0,0 +1,88 @@
+function location = mput(h,str)
+%MPUT Upload to an FTP site.
+%    MPUT(FTP,FILENAME) uploads a file.
+%
+%    MPUT(FTP,DIRECTORY) uploads a directory and its contents.
+%
+%    MPUT(FTP,WILDCARD) uploads a set of files or directories specified
+%    by a wildcard.
+%
+%    All of these calling forms return a cell array listing the full path to the
+%    uploaded files on the server.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2012 The MathWorks, Inc.
+
+% Make sure we're still connected.
+connect(h)
+
+% Figure out where the files live.
+[localDir,file,ext] = fileparts(str);
+filename = [file ext];
+if isempty(localDir)
+    localDir = pwd;
+end
+remoteDir = char(h.jobject.printWorkingDirectory);
+
+% Set ascii/binary
+switch char(h.type.toString)
+    case 'binary'
+        h.jobject.setFileType(h.jobject.BINARY_FILE_TYPE);
+    otherwise
+        h.jobject.setFileType(h.jobject.ASCII_FILE_TYPE);
+end
+
+if strfind(filename,'*')
+    % Upload any files and directories that match the wildcard.
+    d=dir(fullfile(localDir,filename));
+    listing = {d.name};
+else
+    listing = {filename};
+end
+
+location = {};
+iListing = 0;
+while (iListing < length(listing))
+    iListing = iListing+1;
+    name = listing{iListing};
+    localName = strrep(fullfile(localDir,name),'/',filesep);
+    if isdir(localName)
+        mkdir(h,name);
+        d = dir(localName);
+        for i = 1:length(d)
+            next = d(i).name;
+            if isequal(next,'.') || isequal(next,'..')
+                % skip
+            else
+                listing{end+1} = [name '/' next];
+            end
+        end
+    else
+        % Check for the file.
+        fileObject = java.io.File(localName);
+        if ~fileObject.exists
+            error(message('MATLAB:ftp:NotFound', localName))
+        end
+
+        % Upload this file.
+        fis = java.io.FileInputStream(fileObject);
+        status = h.jobject.storeFile(name,fis);
+        fis.close;
+
+        % Error if the upload failed.
+        if (status == 0)
+            code = h.jobject.getReplyCode;
+            switch code
+                case 550
+                    error(message('MATLAB:ftp:UploadFailed', name));
+                case 553
+                    error(message('MATLAB:ftp:BadFilename', name));
+                otherwise
+                    error(message('MATLAB:ftp:FTPError',code));
+            end
+        end
+
+        % Build the list of files uploaded.
+        location{end+1,1} = [remoteDir '/' name];
+    end
+end
Index: prextra/@ftp/pasv.m
===================================================================
--- prextra/@ftp/pasv.m	(revision 113)
+++ prextra/@ftp/pasv.m	(revision 113)
@@ -0,0 +1,18 @@
+function pasv(h)
+% PASV Change to passive mode
+%   PASV(FTP) changes the communication mode of FTP to passive mode.
+
+% Idin Motedayen-Aval
+
+% Make sure we're still connected.
+connect(h)
+
+if (nargin ~= 1)
+    error('Incorrect number of arguments.')
+end
+
+h.jobject.enterLocalPassiveMode;
+
+% There isn't an easier way to set the value of a StringBuffer.
+h.passiveMode.setLength(0);
+h.passiveMode.append('p');
Index: prextra/@ftp/private/connect.m
===================================================================
--- prextra/@ftp/private/connect.m	(revision 113)
+++ prextra/@ftp/private/connect.m	(revision 113)
@@ -0,0 +1,47 @@
+function connect(h)
+%CONNECT Open a connection to the server.
+%    CONNECT(FTP) opens a connection to the server.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2004 The MathWorks, Inc.
+% $Revision: 1.1.4.1 $  $Date: 2004/03/18 17:59:41 $
+
+% If we're already connected, exit.
+try
+    h.jobject.getStatus;
+    return
+end
+
+% Try to open.
+try
+    h.jobject.connect(h.host,h.port);
+catch
+    error('MATLAB:ftp:NoConnection', ...
+        'Could not open a connection to "%s", port "%.0f".',h.host,h.port)
+end
+
+% Try to login.
+try
+    isSuccess = h.jobject.login(h.username,h.password);
+catch
+    isSuccess = false;
+end
+if ~isSuccess
+    error('MATLAB:ftp:BadLogin','Connection refused for "%s".',h.username)
+end
+
+% Try to return to the directory we were in before, if any.
+if (h.remotePwd.length == 0)
+    h.remotePwd.append(h.jobject.printWorkingDirectory);
+else
+    cd(h,char(h.remotePwd.toString));
+end
+
+% Try to restore passive data connection mode if that was the case before
+% Added by Idin Motedayen-Aval to allow passive-mode functionality.
+pMode = char(h.passiveMode);
+if pMode == 'p'
+    pasv(h);
+else
+    active(h);
+end
Index: prextra/@ftp/rename.m
===================================================================
--- prextra/@ftp/rename.m	(revision 113)
+++ prextra/@ftp/rename.m	(revision 113)
@@ -0,0 +1,11 @@
+function rename(h,oldname,newname)
+%RENAME Rename a file on an FTP site.
+%    RENAME(FTP,OLDNAME,NEWNAME) renames a file on an FTP site.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2004 The MathWorks, Inc.
+
+% Make sure we're still connected.
+connect(h)
+
+h.jobject.rename(oldname,newname);
Index: prextra/@ftp/rmdir.m
===================================================================
--- prextra/@ftp/rmdir.m	(revision 113)
+++ prextra/@ftp/rmdir.m	(revision 113)
@@ -0,0 +1,20 @@
+function rmdir(h,dirname)
+%rmdir Remove a directory on an FTP site.
+%    RMDIR(FTP,DIRECTORY) removes a directory on an FTP site.
+
+% Matthew J. Simoneau, 14-Nov-2001
+% Copyright 1984-2012 The MathWorks, Inc.
+
+% Make sure we're still connected.
+connect(h)
+
+status = h.jobject.removeDirectory(dirname);
+if (status == 0)
+    code = h.jobject.getReplyCode;
+    switch code
+        case 550
+            error(message('MATLAB:ftp:DeleteFailed',dirname));
+        otherwise
+            error(message('MATLAB:ftp:FTPError',code))
+    end
+end
Index: prextra/@ftp/saveobj.m
===================================================================
--- prextra/@ftp/saveobj.m	(revision 113)
+++ prextra/@ftp/saveobj.m	(revision 113)
@@ -0,0 +1,7 @@
+function f = saveobj(f)
+% SAVEOBJ Save filter for FTP objects.
+
+% Matthew J. Simoneau, 11-Mar-2004
+% Copyright 1984-2004 The MathWorks, Inc.
+
+f.jobject = [];
Index: prextra/emc.m
===================================================================
--- prextra/emc.m	(revision 110)
+++ prextra/emc.m	(revision 113)
@@ -45,6 +45,7 @@
 	if size(a,2) ~= size(b,2)
 		error('Datasets should have same number of features')
-	end
+  end
 	
+  borg = setlabels(b,getnlab(b));
 	c = getsize(a,3);
 	epsilon = 1e-6;
@@ -65,5 +66,13 @@
 	w = a*classf;
 	
+  starttime = clock;
+  runtime = 0;
+  iter = 0;
 	while change > epsilon
+    disp(borg*w*testd)
+    if runtime > prtime
+      prwarning(2,['EM algorithme stopped by PRTIME after ' num2str(iter) ' iterations']);
+      break
+    end
 		d = b*w;
 		switch labtype
@@ -81,4 +90,6 @@
 		c = [setlabtype(a,labtype); b];
 		w = c*classf;
+    runtime = etime(clock,starttime);
+    iter = iter+1;
 	end
 	
Index: prextra/prtools_export.m
===================================================================
--- prextra/prtools_export.m	(revision 113)
+++ prextra/prtools_export.m	(revision 113)
@@ -0,0 +1,324 @@
+%PRTOOLS_EXPORT creates and stores PRTools export
+%
+% PRTOOLS_EXPORT(FLAG,EXPORTDIR)
+%
+% Creates, if FLAG is true an export version of PRTools in
+% http://prtools.tudelft.org/files/prtools.zip.
+%
+% If FLAG is false (default) just zip-files in EXPORTDIR are created for
+% inspection and the website is not attached.
+%
+% EXPORTDIR should be the Matlab/prtools_export dir in the PRLab group
+% directory. Default is K:\insy\PRLab\Matlab\prtools_export
+%
+% The intention is that this routine works on the PC as well as on the Unix
+% platform. The latter, however, has not yet been tested.
+%
+% Save trials are prtools_export, prtools_export(0), prtools_export(0,dir)
+% and inspect the prtools_export directory.
+%
+% This m-file should be located in PREXTRA, which should be in the path, 
+% as it needs the overruled FTP commands located in PREXTRA
+%
+% Bob Duin 31 Aug 2016
+
+function prtools_export(doit,exportdir)
+
+if nargin < 2, exportdir = 'K:\insy\PRLab\Matlab\prtools_export'; end
+if nargin < 1, doit = false; end
+
+prdir = fileparts(which(mfilename));
+%exportdir = fullfile(prdir,'prtools_export'); % maybe to be located elsewwhere
+curdir = pwd;
+[~,prdirdir] = fileparts(prdir);
+if ~strcmp(prdirdir,'prextra')
+  error('prtools_export should be located in the prextra directory')
+end
+
+% create temp dir
+prtmp = fullfile(prdir,'tmp');
+if exist(prtmp,'dir') ~= 7
+  mkdir(prtmp);
+end
+
+% get rid of prtools in the path
+r = which('fisherc');
+if ~isempty(r)
+  rmpath(r);
+end
+
+cd(prtmp);
+dd = dir;
+n=strmatch('prtools',{dd.name},'exact');
+if ~isempty(n)
+  rmdir('prtools','s');
+end
+    
+% checkout present PRTools version
+if isunix
+  s = unix('svn co https://svn-mede.ewi.tudelft.nl/MM-ICT/PRTOOLS prtools');
+elseif ispc
+  fprintf(1,'    Tortoise will pop up, find it and click OK 2x');
+  s = dos('TortoiseProc.exe /command:checkout /url:"https://svn-mede.ewi.tudelft.nl/MM-ICT/PRTOOLS" /path:prtools');
+  fprintf(1,'\n');
+  input('    Ready to continue?');
+else 
+  error('svn checkout not implemented for Mac')
+end
+if (s~=0)
+  error('Error in running svn: could not checkout prtools')
+end
+
+% adjust version number
+addpath(fullfile(pwd,'prtools'))
+pver  = prtver;
+fprintf(1,'    Present PRTools version is %s\n',pver{1}.Version);
+pver_new = input(['    Give new version number: [' pver{1}.Version '] '],'s');
+if isempty(pver_new)
+  pver_new = pver{1}.Version;
+end
+set_version_in_Contents(pver_new);
+% Commit version change
+if isunix
+  s = unix(['svn ci ' fullfile('prtools','Contents.m')]);
+elseif ispc
+  fprintf(1,'    Tortoise will pop up to commit change version number in Contents, find it and click OK 2x')
+  s = dos(['TortoiseProc.exe /command:commit /path:' fullfile('prtools','Contents.m')]);
+  fprintf(1,'\n');
+  input('    Ready to continue?');
+else 
+  error(['svn commit not implemented for Mac'])
+end
+  
+% Delete all svn files
+fprintf(1,'    Removing all svn files ... \n');
+if isunix
+  unix('chmod -R +w prtools');
+  unix('\rm -rf prtools/.svn prtools/*/.svn');
+elseif ispc
+  dos('rmdir /S /Q prtools\.svn');
+  dos('rmdir /S /Q prtools\@prdataset\.svn');
+  dos('rmdir /S /Q prtools\@prdatafile\.svn');
+  dos('rmdir /S /Q prtools\@prmapping\.svn');
+  dos('rmdir /S /Q prtools\private\.svn');
+end
+
+% Create export version in dir2
+today = datestr(date,'ddmmmyy');
+exporttemp = fullfile(prtmp,['prtex' pver_new '.' today]);
+mkdir(exporttemp);
+dir1 = fileparts(which('fisherc'));
+dir2 = fullfile(exporttemp,'prtools');
+mkdir(dir2);
+copydirm(dir1,dir2); % copy main dir
+copydirm(fullfile(dir1,'private'),fullfile(dir2,'private'),'all'); % copy private as it is
+copydirm(fullfile(dir1,'@prdataset'),fullfile(dir2,'@prdataset'),'%'); % copy headers only
+copydirm(fullfile(dir1,'@prdatafile'),fullfile(dir2,'@prdatafile'),'%'); % copy headers only
+copydirm(fullfile(dir1,'@prmapping'),fullfile(dir2,'@prmapping'),'%'); % copy headers only
+
+% Generate pcodes
+fprintf(1,'    Generating pcodes ... \n');
+cd(fullfile(dir2,'@prdataset')); pcode(fullfile(dir1,'@prdataset'));  % generate pcode in dir2/@dataset
+cd(fullfile(dir2,'@prdatafile')); pcode(fullfile(dir1,'@prdatafile')); % generate pcode in dir2/@datafile
+cd(fullfile(dir2,'@prmapping')); pcode(fullfile(dir1,'@prmapping'));  % generate pcode in dir2/@mapping
+
+% Create zip-files
+fprintf(1,'    Creating zip files ... \n');
+cd(exportdir);
+copyfile('License.txt',exporttemp,'f');
+copyfile('Install_notes.txt',exporttemp,'f');
+copyfile('Release_notes.txt',exporttemp,'f');
+pfiles = ['prtex' pver_new '.' today '.zip'];
+mfiles = ['prtools' pver_new '.' today '.zip'];
+zip(pfiles,{'prtools','License.txt','Install_notes.txt','Release_notes.txt'},exporttemp);
+zip(mfiles,[fullfile(prtmp,'prtools') '/*']);
+rmdir(prtmp,'s');
+  
+if doit
+  fprintf(1,'    FTP PRTools zip-file to website ... \n');
+  % store p-files on website
+  ftpsite = ftp('prtools.tudelft.nl','prtools','pvG4z1!1');
+  cd(ftpsite,'httpdocs/files');
+  mput(ftpsite,pfiles);
+  rename(ftpsite,pfiles,'prtools.zip');
+  disp('p-files have been stored on the website.')
+  disp('Please check and adjust release notes and known problems on website')
+  close(ftpsite)
+  
+  % backup p-files and m-files
+  fprintf(1,'    Storing backups of mfiles and p-files ... \n');
+  [s,mess] = copyfile(pfiles,fullfile(exportdir,'prtools_old_p'));
+  if s
+    delete(pfiles);
+    disp(['p-files have been backed-up in ' exportdir])
+  else
+    disp(mess); 
+  end
+  [s,mess] = copyfile(mfiles,fullfile(exportdir,'prtools_old_m'));
+  if s
+    delete(mfiles);
+    disp(['m-files have been backed-up in ' exportdir])
+  else
+    disp(mess); 
+  end
+end
+    
+cd(curdir)
+
+	
+%COPYDIRM Copy mfiles from dir to dir
+function copydirm(dir1,dir2,type)
+if nargin < 3
+	type = 'm';
+end
+if exist(dir2) ~= 7
+	[parentdir,subdir] = fileparts(dir2);
+	mkdir(parentdir,subdir);
+end
+[f1,f2] = fileparts(dir2);
+%disp(['Copying ' f2]);
+switch type
+case {'m','%'}
+	if isunix
+		unix(['cp ' dir1 '/*.m ' dir2]);
+	else
+		list = dir([dir1 '/*.m']);
+	end
+case {'p'}
+	if isunix
+		unix(['cp ' dir1 '/*.p ' dir2]);
+	else
+		list = dir([dir1 '/*.p']);
+	end
+case {'qld'}
+	if isunix
+		unix(['cp ' dir1 '/qld.dl* ' dir2]);
+		unix(['cp ' dir1 '/qld.mex* ' dir2]);
+	else
+		list = dir([dir1 '/qld.dl*']);
+		list = [list; dir([dir1 '/qld.mex*'])];
+  end
+otherwise
+	if isunix
+		unix(['cp ' dir1 '/* ' dir2]);
+	else
+		list = dir([dir1 '/*']);
+	end
+
+end
+if ~isunix
+	k = length(list);
+	for i = 1:k
+		%disp(['File copy ' list(i).name]);
+		if ~list(i).isdir
+			copyfile(fullfile(dir1,list(i).name),fullfile(dir2,list(i).name));
+		end
+	end
+end
+
+if strcmp(type,'%')
+	list = dir(dir2);
+	k = length(list);
+	for i=1:k
+		%disp(['File reduce ' list(i).name]); 
+		if ~list(i).isdir
+			r = gethf(fullfile(dir2,list(i).name));
+			writf(fullfile(dir2,list(i).name),r);			
+		end
+	end
+end
+
+%LISTN List lines specified by their line number
+%
+% t = listn(r,n)
+% Get the lines in r given by the line numbers in n.
+function t = listn(r,n)
+nlchar = setstr(10); % use Windows / Unix newline char
+k = [0,find(r==nlchar)];
+t = [];
+for j = n
+    t = [t,r(k(j)+1:k(j+1))];
+end
+return
+
+%GETHFT Create heading file from m-file
+%
+%	s = gethf(file)
+%
+% The heading of the given m-file consisting of all starting % lines
+% is isolated and returned in s.
+
+function s = gethf(file)
+[s,ns] = readf(file);
+p=grep(s,'%');
+if isempty(p), p = 0; end
+I = find(p - [0,p(1:length(p)-1)] ~= 1);
+if p(1) == 1 & isempty(I), I = length(p) + 1; end
+if length(I) > 0 & I(1) > 1
+	n = I(1) - 1;
+	s = listn(s,1:n);
+else
+	s = '';
+end
+
+%GREP Get line specific lines
+%
+% n = grep(r,s)
+% Get the numbers of all lines in the set of lines r 
+% that contain s.
+
+function k = grep(r,s)
+n = [0,find(r==newline)];
+m = findstr(r,s);
+[i,j] = sort([n,m]);;
+q = [0,j(1:length(j)-1)]-j;
+k = j(find(q>0))-1;
+return
+
+function [s,n] = readf(file)
+fid = fopen(file);
+if fid < 0
+	error(['File ' file ' not found, probably wrong directory'])
+end
+[s,n] = fread(fid);
+if isempty(s)
+  error(['File ' file ' could not be read'])
+end
+s = s(:)';
+fclose(fid);
+
+function writf(file,s)
+filedir = fileparts(which(file));
+fid = fopen(fullfile(filedir,file),'w');
+if fid < 0
+	error(['File ' file ' could not be opened for writing'])
+end
+fwrite(fid,s);
+fclose(fid);
+
+function set_version_in_Contents(prtv)
+if ~isstr(prtv)
+	error('Version should be given as string, e.g. ''3.2.7''')
+end
+s = readf('Contents.m');
+n = findstr(s,newline);
+r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
+writf('Contents.m',r);
+disp('    Contents.m rewritten with new version number')
+
+function myedit(file)
+
+try 
+  edit(file);
+catch
+  if isunix
+    s = input('    Could not find editor, OK to open vi? [yes]/no: ','s');
+    if isempty(s) | strcmp(s,'yes')
+      unix(['vi ' file]);
+    else
+      disp(['    Could not open ' file ' for editing']);
+    end
+  else
+    disp(['    Could not open ' file ' for editing']);
+  end
+end
