Home > mml > setpathmml.m

setpathmml

PURPOSE ^

SETPATHMML - Initialize the Matlab MiddleLayer (MML) path

SYNOPSIS ^

function [MachineName, SubMachineName, LinkFlag, MMLROOT] = setpathmml(varargin)

DESCRIPTION ^

SETPATHMML -  Initialize the Matlab MiddleLayer (MML) path
  [MachineName, SubMachineName, OnlineLinkMethod, MMLROOT]  = setpathmml(MachineName, SubMachineName, MachineType, OnlineLinkMethod, MMLROOT)

  INPUTS
  1. MachineName -
  2. SubMachineName -
  3. MachineType - 'StorageRing' {Default}, 'Booster', 'Linac', or 'Transport'
  4. OnlineLinkMethod - 'MCA', 'LabCA', 'SCA', 'Tango', 'SLC', 'UCODE', ... {Default: 'LabCA'}
  5. MMLROOT - Directory path to the MML root directory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [MachineName, SubMachineName, LinkFlag, MMLROOT] = setpathmml(varargin)
0002 %SETPATHMML -  Initialize the Matlab MiddleLayer (MML) path
0003 %  [MachineName, SubMachineName, OnlineLinkMethod, MMLROOT]  = setpathmml(MachineName, SubMachineName, MachineType, OnlineLinkMethod, MMLROOT)
0004 %
0005 %  INPUTS
0006 %  1. MachineName -
0007 %  2. SubMachineName -
0008 %  3. MachineType - 'StorageRing' {Default}, 'Booster', 'Linac', or 'Transport'
0009 %  4. OnlineLinkMethod - 'MCA', 'LabCA', 'SCA', 'Tango', 'SLC', 'UCODE', ... {Default: 'LabCA'}
0010 %  5. MMLROOT - Directory path to the MML root directory
0011 
0012 %  Written by Greg Portmann
0013 %  Updated by Igor Pinayev
0014 
0015 
0016 % Inputs:  MachineName, SubMachineName, MachineType, LinkFlag, MMLROOT
0017 
0018 
0019 % First strip-out the link method
0020 LinkFlag = '';
0021 for i = length(varargin):-1:1
0022     if ~ischar(varargin{i})
0023         % Ignor input
0024     elseif strcmpi(varargin{i},'LabCA')
0025         LinkFlag = 'LabCA';
0026         varargin(i) = [];
0027     elseif strcmpi(varargin{i},'MCA')
0028         LinkFlag = 'MCA';
0029         varargin(i) = [];
0030     elseif strcmpi(varargin{i},'SCA')
0031         LinkFlag = 'SCA';
0032         varargin(i) = [];
0033     elseif strcmpi(varargin{i},'OPC')
0034         LinkFlag = 'OPC';
0035         varargin(i) = [];
0036     elseif strcmpi(varargin{i},'SLC')
0037         LinkFlag = 'SLC';
0038         varargin(i) = [];
0039     elseif strcmpi(varargin{i},'Tango')
0040         LinkFlag = 'Tango';
0041         varargin(i) = [];
0042     elseif strcmpi(varargin{i},'UCODE')
0043         LinkFlag = 'UCODE';
0044         varargin(i) = [];
0045     end
0046 end
0047 
0048 
0049 % Get the machine name
0050 if length(varargin) >= 1
0051     MachineName = varargin{1};
0052 else
0053     MachineName = '';
0054 end
0055 
0056 if isempty(MachineName)
0057     [MachineListCell, SubMachineListCell] = getmachinelist;
0058     [i, iok] = listdlg('Name','SETPATHMML', 'ListString',MachineListCell, 'Name','MML Init', 'PromptString',{'Select a facility:'}, 'SelectionMode','Single');
0059     %[MachineNameCell, i] = editlist(MachineListCell,'',zeros(size(MachineListCell,1),1));
0060     drawnow;
0061     if iok
0062         MachineName = MachineListCell{i};
0063     else
0064         fprintf('   No path change.\n');
0065         MachineName=''; SubMachineName=''; LinkFlag=''; MMLROOT='';
0066         return;
0067     end
0068 else
0069     SubMachineListCell = {};
0070 end
0071 
0072 
0073 % Get the submachine name
0074 if length(varargin) >= 2
0075     SubMachineName = varargin{2};
0076 else
0077     SubMachineName = '';
0078 end
0079 if isempty(SubMachineName)
0080     if isempty(SubMachineListCell)
0081         [MachineListCell, SubMachineListCell] = getmachinelist;
0082     end
0083     i = strmatch(MachineName, MachineListCell, 'exact');
0084     SubMachineListCell = SubMachineListCell{i}(:);
0085     
0086     if length(SubMachineListCell) == 1
0087         SubMachineName = SubMachineListCell{1};
0088     else
0089         [i, iok] = listdlg('Name','SETPATHMML', 'ListString',SubMachineListCell, 'Name','MML Init', 'PromptString',{'Select an accelerator:'}, 'SelectionMode','Single');
0090         drawnow;
0091         if iok
0092             SubMachineName = SubMachineListCell{i};
0093         else
0094             fprintf('   No path change.\n');
0095             MachineName=''; SubMachineName=''; LinkFlag=''; MMLROOT='';
0096             return;
0097         end
0098     end
0099 end
0100 
0101 
0102 % Find the machine type
0103 if length(varargin) >= 3
0104     MachineType = varargin{3};
0105 else
0106     MachineType = '';
0107 end
0108 if isempty(MachineType)
0109     switch upper(SubMachineName)
0110         case {'LTB', 'LB', 'BTS', 'BS', 'LT1', 'LT2', 'INJECTOR', 'LINAC', 'GUN'}
0111             MachineType = 'Transport';
0112         case {'BOOSTER', 'BOOSTER RING', 'BR'}
0113             MachineType = 'Booster';
0114         case {'SR', 'STORAGERING', 'STORAGE RING', 'HER', 'LER', '800MEV'}
0115             MachineType = 'StorageRing';
0116         otherwise
0117             MachineType = 'StorageRing';
0118     end
0119 end
0120 
0121 
0122 %if all(strcmpi(MachineType, {'StorageRing','Booster','Linac','Transport'}) == 0)
0123 %    error('MachineType must be storagering, booster, linac, or transport.');
0124 %end
0125 
0126 MatlabVersion = ver('Matlab');
0127 MatlabVersion = str2num(MatlabVersion.Version);
0128 
0129 % LinkFlag if empty
0130 if isempty(LinkFlag)
0131     switch upper(MachineName)
0132         case 'ALS'
0133             if strncmp(computer,'PC',2)
0134                 LinkFlag = 'LABCA';
0135                 %LinkFlag = 'MCA';
0136             elseif isunix
0137                 if strncmp(computer,'GLNX',4) || MatlabVersion >= 7.4
0138                     LinkFlag = 'LABCA';
0139                     %LinkFlag = 'SCA';
0140                 else
0141                     %LinkFlag = 'LABCA';
0142                     LinkFlag = 'SCA';
0143                 end
0144             else
0145                 LinkFlag = 'LABCA';
0146             end
0147         case {'ASP'}
0148             LinkFlag = 'LABCA';
0149         case {'NSRRC','PLS','SPEAR','SPEAR3','SSRF'}
0150             LinkFlag = 'MCA';
0151         case 'BFACTORY'
0152             LinkFlag = 'SLC';
0153         case 'LCLS'
0154             LinkFlag = 'LABCA';
0155         case {'NSRC','SPS'}
0156             LinkFlag = 'OPC';
0157         case {'VUV','XRAY'}
0158             LinkFlag = 'UCODE';
0159         case {'ALBA','SOLEIL'}
0160             LinkFlag = 'Tango';
0161         otherwise
0162             % Other
0163             if strncmp(computer,'PC',2)
0164                 LinkFlag = 'LABCA';
0165                 %LinkFlag = 'MCA';
0166             elseif isunix
0167                 LinkFlag = 'LABCA';
0168             else
0169                 LinkFlag = 'LABCA';
0170                 %LinkFlag = 'MCA';
0171             end
0172     end
0173 end
0174 
0175 
0176 % Find the MML root directory
0177 if length(varargin) >= 4
0178     MMLROOT = varargin{4};
0179 else
0180     MMLROOT = '';
0181 end
0182 if isempty(MMLROOT)
0183     MMLROOT = getmmlroot;
0184 end
0185 
0186 
0187 % The path does not needs to be set in Standalone mode
0188 if ~isdeployed_local
0189     
0190     % Jeff's orbit GUI
0191     if any(strcmpi(MachineName,{'Spear3','cls','diamond','asp','alba','camd'}))
0192         %addpath(fullfile(MMLROOT, 'applications', 'orbit'), '-begin');
0193         addpath(fullfile(MMLROOT, 'applications', 'orbit', 'lib'), '-begin');
0194         addpath(fullfile(MMLROOT, 'applications', 'orbit', lower(MachineName)), '-begin');
0195     end
0196     
0197     % N A F F (files not distributed with MML)
0198     Directory = fullfile(MMLROOT, 'applications', 'naff');
0199     if exist(Directory, 'dir')
0200         addpath(fullfile(MMLROOT, 'applications', 'naff'), '-begin');
0201     end
0202     
0203     % m2html generation program
0204     addpath(fullfile(MMLROOT, 'applications', 'm2html'), '-begin');
0205 
0206     % MySQL
0207     %addpath(fullfile(MMLROOT, 'applications', 'database', 'mysql'), '-begin');
0208     addpath(fullfile(MMLROOT, 'applications', 'database', 'mym'), '-begin');
0209 
0210     % XML
0211     addpath(fullfile(MMLROOT, 'applications', 'xml', 'geodise'), '-begin');
0212     %addpath(fullfile(MMLROOT, 'applications', 'xml', 'xmltree'), '-begin');
0213 
0214     % AT root
0215     setpathat(fullfile(MMLROOT,'at'));
0216 
0217     % Connection MML to simulator
0218     addpath(fullfile(MMLROOT, 'mml', 'at'),'-begin');
0219 
0220     % LOCO
0221     addpath(fullfile(MMLROOT, 'applications', 'loco'),'-begin');
0222 
0223     % Link method
0224     switch upper(LinkFlag)
0225         case 'MCA'
0226             % R3.14.4 and Andrei's MCA
0227             %fprintf('   Appending MATLAB path control using MCA and EPICS R3.13.4\n');
0228             %addpath(fullfile(MMLROOT, 'links', 'mca', 'win32', 'R3.14.4'),'-begin');
0229             %addpath(fullfile(MMLROOT, 'mml', 'links', 'mca'),'-begin');
0230 
0231             % R3.14.4 and Australian MCA
0232             fprintf('   Appending MATLAB path control using MCA (Australian)\n');
0233             addpath(fullfile(MMLROOT, 'links', 'mca_asp'),'-begin');
0234             addpath(fullfile(MMLROOT, 'mml', 'links', 'mca_asp'),'-begin');
0235             
0236         case 'LABCA'
0237             fprintf('   Appending MATLAB path control using LabCA \n');
0238             switch computer
0239                 case 'PCWIN'
0240                     addpath(fullfile(MMLROOT,'links','labca', 'bin','win32-x86','labca'),'-begin');
0241                     %addpath(fullfile(MMLROOT,'links','labca', 'bin','win32-x86_3_0','labca'),'-begin');
0242                 case 'SOL2'
0243                     addpath(fullfile(MMLROOT,'links','labca', 'bin','solaris-sparc','labca'),'-begin');
0244                 case 'SOL64'
0245                     addpath(fullfile(MMLROOT,'links','labca', 'bin','solaris-sparc64','labca'),'-begin');
0246                 case 'GLNX86'
0247                     addpath(fullfile(MMLROOT,'links','labca', 'bin','linux-x86','labca'),'-begin');
0248                 case 'GLNXA64'
0249                     addpath(fullfile(MMLROOT,'links','labca', 'bin','linux-x86_64','labca'),'-begin');
0250                 otherwise
0251                     fprintf('Computer not recognized for LabCA path.\n');
0252             end
0253 
0254             addpath(fullfile(MMLROOT,'mml', 'links', 'labca'),'-begin');
0255 
0256         case 'SCA'
0257             fprintf('   Appending MATLAB path control using Simple-CA Version 3\n');
0258             switch computer
0259                 case 'PCWIN'
0260                     fprintf('\n   WARNING:  SCAIII is not working with PC''s yet\n\n');
0261                     addpath(fullfile(MMLROOT,'links','sca', 'bin','win32-x86','sca'),'-begin');
0262                 case 'SOL2'
0263                     addpath(fullfile(MMLROOT,'links','sca', 'bin','solaris-sparc','sca'),'-begin');
0264                 case 'SOL64'
0265                     addpath(fullfile(MMLROOT,'links','sca', 'bin','solaris-sparc64','sca'),'-begin');
0266                 case 'GLNX86'
0267                     addpath(fullfile(MMLROOT,'links','sca', 'bin','linux-x86','sca'),'-begin');
0268                 case 'GLNXA64'
0269                     addpath(fullfile(MMLROOT,'links','sca', 'bin','linux-x86_64','sca'),'-begin');
0270                 otherwise
0271                     fprintf('Computer not recognized for SCA path.\n');
0272             end
0273             addpath(fullfile(MMLROOT, 'mml', 'links', 'sca'),'-begin');
0274 
0275         case 'TANGO'
0276 
0277             fprintf('   Appending MATLAB path control using Tango\n');
0278             addpath(fullfile(MMLROOT,'links','tango'),'-begin');
0279             addpath(fullfile(MMLROOT, 'mml', 'links', 'tango'),'-begin');
0280 
0281         case 'UCODE'
0282             fprintf('   Appending MATLAB path control using UCODE \n');
0283             %addpath(fullfile(MMLROOT,'links','ucode'),'-begin');
0284             addpath(fullfile(MMLROOT,'mml','links','ucode'),'-begin');
0285 
0286         case 'SLC'
0287             fprintf('   Appending MATLAB path for SLC control \n');
0288             addpath(fullfile(MMLROOT,'links','slc'),'-begin');
0289             addpath(fullfile(MMLROOT,'mml', 'links', 'slc'),'-begin');
0290 
0291         case 'OPC'
0292             fprintf('   Appending MATLAB path for OPC control \n');
0293             addpath(fullfile(MMLROOT,'links','opc'),'-begin');
0294             addpath(fullfile(MMLROOT,'mml', 'links', 'opc'),'-begin');
0295 
0296         otherwise
0297             fprintf('   Unknown type for the Online connection method.  Only simulator mode will work.\n');
0298     end
0299 
0300 
0301     % Common files
0302     addpath(fullfile(MMLROOT, 'applications', 'common'),'-begin');
0303 
0304     % MML path
0305     addpath(fullfile(MMLROOT, 'mml'),'-begin');
0306 
0307     % Machine directory
0308     if ~isempty(MachineName) && ~isempty(SubMachineName)
0309         % Sometimes there is a common directory that all submachines share
0310         Directory = fullfile(MMLROOT, 'machine', MachineName, 'common');
0311         if exist(Directory, 'dir')
0312             addpath(Directory,'-begin');
0313         end
0314         Directory = fullfile(MMLROOT, 'machine', MachineName, 'Common');
0315         if exist(Directory, 'dir')
0316             addpath(Directory,'-begin');
0317         end
0318         
0319         % New MML path
0320         addpath(fullfile(MMLROOT, 'machine', MachineName, SubMachineName),'-begin');
0321     end
0322 end
0323 
0324 
0325 % Start the AD with machine and submachine
0326 setad([]);
0327 AD.Machine = MachineName;
0328 AD.SubMachine = SubMachineName;
0329 AD.MachineType = MachineType;
0330 AD.OperationalMode = '';    % Gets filled in later
0331 setad(AD);
0332 
0333 
0334 % Initialize the AO & AD
0335 aoinit(SubMachineName);
0336 
0337 
0338 function RunTimeFlag = isdeployed_local
0339 % isdeployed is not in matlab 6.5
0340 V = version;
0341 if str2num(V(1,1)) < 7
0342     RunTimeFlag = 0;
0343 else
0344     RunTimeFlag = isdeployed;
0345 end

Generated on Fri 01-Aug-2008 10:57:33 by m2html © 2003