Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation



06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

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;

    % 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',...
        % decides
        switch selection
            case 'Overwrite'
                % deletes the file

                % changes create file to true
                createFile = true;

            case 'Edit'
                % opens it in the editor for changing

                % 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.')
    % 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
        % closes matlab - a bit too abrupt for the user for my tastes

Contact us