Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

javamaxmmem(megabytes)
function output = javamaxmmem(megabytes)
% JAVAMAXMEM changes or says the maximum memory allocated to java

% if no arguments, returns the current value
if ~nargin
    % returns it
    output = java.lang.Runtime.getRuntime.maxMemory;

else
    % defines the filename
    javaOpts = [matlabroot, filesep, 'bin', filesep, computer('arch'), filesep, 'java.opts'];
    createFile = ~exist(javaOpts, 'file');
    
    % if the java.opts file already exists, then get the user to change it
    % themselves
    if ~createFile
        % ask the user what they want to do
        selection = questdlg(   {   'The maximum memory allocated to the Java heap space is less than 100 MB, and more is required for stable operation over more than 2 days.';...
                                    'To change this a line must be added to java.opts, which already exists.';...
                                    'Overwrite Java settings automatically or edit the existing file manually?'},...
                                'Overwrite Confirmation',...
                                'Overwrite', 'Edit',...
                                'Overwrite');
                            
        % decides
        switch selection
            case 'Overwrite'
                % deletes the file
                delete(javaOpts)

                % changes create file to true
                createFile = true;

            case 'Edit'
                % opens it in the editor for changing
                open(javaOpts)

                % brings up a dialog to tell the user what to do
                msgdlg('To increase the memory, the line "-Xmx256m" (without quotes) must be added to the file.')
        end
    end
    
    % if the file is to be created...
    if createFile
        % creates it
        javaOptsFid = fopen(javaOpts, 'w');
        
        % writes the line to it
        fprintf(javaOptsFid, '-Xmx', num2str(round(megabytes)), 'm');
        
        % closes it
        fclose(javaOptsFid);
        
        % closes matlab - a bit too abrupt for the user for my tastes
        %quit
    end
end

Contact us