spm_platform.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. function varargout=spm_platform(varargin)
  2. % Platform specific configuration parameters for SPM
  3. %
  4. % FORMAT ans = spm_platform(arg)
  5. % arg - optional string argument, can be
  6. % - 'bigend' - return whether this architecture is bigendian
  7. % - 0 - is little endian
  8. % - 1 - is big endian
  9. % - 'filesys' - type of filesystem
  10. % - 'unx' - UNIX
  11. % - 'win' - DOS
  12. % - 'sepchar' - returns directory separator
  13. % - 'user' - returns username
  14. % - 'host' - returns system's host name
  15. % - 'tempdir' - returns name of temp directory
  16. % - 'desktop' - returns whether or not the Desktop is in use
  17. %
  18. % FORMAT PlatFontNames = spm_platform('fonts')
  19. % Returns structure with fields named after the generic (UNIX) fonts, the
  20. % field containing the name of the platform specific font.
  21. %
  22. % FORMAT PlatFontName = spm_platform('font',GenFontName)
  23. % Maps generic (UNIX) FontNames to platform specific FontNames
  24. %
  25. % FORMAT PLATFORM = spm_platform('init',comp)
  26. % Initialises platform specific parameters in persistent PLATFORM
  27. % (External gateway to init_platform(comp) subfunction)
  28. % comp - computer to use [defaults to MATLAB's `computer`]
  29. % PLATFORM - copy of persistent PLATFORM
  30. %
  31. % FORMAT spm_platform
  32. % Initialises platform specific parameters in persistent PLATFORM
  33. % (External gateway to init_platform(computer) subfunction)
  34. %
  35. % ----------------
  36. % SUBFUNCTIONS:
  37. %
  38. % FORMAT init_platform(comp)
  39. % Initialise platform specific parameters in persistent PLATFORM
  40. % comp - computer to use [defaults to MATLAB's `computer`]
  41. %
  42. %--------------------------------------------------------------------------
  43. %
  44. % Since calls to spm_platform will be made frequently, most platform
  45. % specific parameters are stored as a structure in the persistent variable
  46. % PLATFORM. Subsequent calls use the information from this persistent
  47. % variable, if it exists.
  48. %
  49. % Platform specific definitions are contained in the data structures at
  50. % the beginning of the init_platform subfunction at the end of this file.
  51. %__________________________________________________________________________
  52. % Copyright (C) 1999-2017 Wellcome Trust Centre for Neuroimaging
  53. % Matthew Brett
  54. % $Id: spm_platform.m 7205 2017-11-09 11:29:59Z guillaume $
  55. %-Initialise
  56. %--------------------------------------------------------------------------
  57. persistent PLATFORM
  58. if isempty(PLATFORM), PLATFORM = init_platform; end
  59. if nargin==0, return, end
  60. switch lower(varargin{1}), case 'init' %-(re)initialise
  61. %==========================================================================
  62. init_platform(varargin{2:end});
  63. varargout = {PLATFORM};
  64. case 'bigend' %-Return endian for this architecture
  65. %==========================================================================
  66. varargout = {PLATFORM.bigend};
  67. case 'filesys' %-Return file system
  68. %==========================================================================
  69. varargout = {PLATFORM.filesys};
  70. case 'sepchar' %-Return file separator character
  71. %==========================================================================
  72. warning('Use FILESEP instead.')
  73. varargout = {PLATFORM.sepchar};
  74. case 'user' %-Return user string
  75. %==========================================================================
  76. varargout = {PLATFORM.user};
  77. case 'host' %-Return hostname
  78. %==========================================================================
  79. varargout = {PLATFORM.host};
  80. case 'drives' %-Return drives
  81. %==========================================================================
  82. error('Use spm_select(''ListDrives'') instead.');
  83. case 'tempdir' %-Return temporary directory
  84. %==========================================================================
  85. twd = getenv('SPMTMP');
  86. if isempty(twd)
  87. twd = tempdir;
  88. end
  89. varargout = {twd};
  90. case {'font','fonts'} %-Map default font names to platform font names
  91. %==========================================================================
  92. if nargin<2, varargout={PLATFORM.font}; return, end
  93. switch lower(varargin{2})
  94. case 'times'
  95. varargout = {PLATFORM.font.times};
  96. case 'courier'
  97. varargout = {PLATFORM.font.courier};
  98. case 'helvetica'
  99. varargout = {PLATFORM.font.helvetica};
  100. case 'symbol'
  101. varargout = {PLATFORM.font.symbol};
  102. otherwise
  103. warning(['Unknown font ',varargin{2},', using default'])
  104. varargout = {PLATFORM.font.helvetica};
  105. end
  106. case 'desktop' %-Return desktop usage
  107. %==========================================================================
  108. varargout = {PLATFORM.desktop};
  109. otherwise %-Unknown Action string
  110. %==========================================================================
  111. error('Unknown Action string')
  112. %==========================================================================
  113. end
  114. %==========================================================================
  115. %- S U B - F U N C T I O N S
  116. %==========================================================================
  117. function PLATFORM = init_platform(comp) %-Initialise platform variables
  118. %==========================================================================
  119. if nargin<1
  120. if ~strcmpi(spm_check_version,'octave')
  121. comp = computer;
  122. else
  123. if isunix
  124. switch uname.machine
  125. case {'x86_64'}
  126. comp = 'GLNXA64';
  127. case {'i586','i686'}
  128. comp = 'GLNX86';
  129. case {'armv6l','armv7l','armv8l'}
  130. comp = 'ARM';
  131. otherwise
  132. error('%s is not supported.',comp);
  133. end
  134. elseif ispc
  135. comp = 'PCWIN64';
  136. elseif ismac
  137. comp = 'MACI64';
  138. end
  139. end
  140. end
  141. %-Platform definitions
  142. %--------------------------------------------------------------------------
  143. PDefs = {'PCWIN', 'win', 0;...
  144. 'PCWIN64', 'win', 0;...
  145. 'MAC', 'unx', 1;...
  146. 'MACI', 'unx', 0;...
  147. 'MACI64', 'unx', 0;...
  148. 'GLNX86', 'unx', 0;...
  149. 'GLNXA64', 'unx', 0;...
  150. 'ARM', 'unx', 0};
  151. PDefs = cell2struct(PDefs,{'computer','filesys','endian'},2);
  152. %-Which computer?
  153. %--------------------------------------------------------------------------
  154. [issup, ci] = ismember(comp,{PDefs.computer});
  155. if ~issup
  156. error([comp ' not supported architecture for ' spm('Ver')]);
  157. end
  158. %-Set byte ordering
  159. %--------------------------------------------------------------------------
  160. PLATFORM.bigend = PDefs(ci).endian;
  161. %-Set filesystem type
  162. %--------------------------------------------------------------------------
  163. PLATFORM.filesys = PDefs(ci).filesys;
  164. %-File separator character
  165. %--------------------------------------------------------------------------
  166. PLATFORM.sepchar = filesep;
  167. %-Username
  168. %--------------------------------------------------------------------------
  169. switch PLATFORM.filesys
  170. case 'unx'
  171. PLATFORM.user = getenv('USER');
  172. case 'win'
  173. PLATFORM.user = getenv('USERNAME');
  174. end
  175. if isempty(PLATFORM.user), PLATFORM.user = 'anonymous'; end
  176. %-Hostname
  177. %--------------------------------------------------------------------------
  178. switch PLATFORM.filesys
  179. case 'unx'
  180. [sts, PLATFORM.host] = system('hostname');
  181. if sts
  182. PLATFORM.host = getenv('HOSTNAME');
  183. else
  184. PLATFORM.host = PLATFORM.host(1:end-1);
  185. end
  186. case 'win'
  187. PLATFORM.host = getenv('COMPUTERNAME');
  188. end
  189. PLATFORM.host = strtok(PLATFORM.host,'.');
  190. %-Fonts
  191. %--------------------------------------------------------------------------
  192. switch comp
  193. case {'MAC','MACI','MACI64'}
  194. PLATFORM.font.helvetica = 'TrebuchetMS';
  195. PLATFORM.font.times = 'Times';
  196. PLATFORM.font.courier = 'Courier';
  197. PLATFORM.font.symbol = 'Symbol';
  198. case {'GLNX86','GLNXA64'}
  199. PLATFORM.font.helvetica = 'Helvetica';
  200. PLATFORM.font.times = 'Times';
  201. PLATFORM.font.courier = 'Courier';
  202. PLATFORM.font.symbol = 'Symbol';
  203. case {'PCWIN','PCWIN64'}
  204. PLATFORM.font.helvetica = 'Arial Narrow';
  205. PLATFORM.font.times = 'Times New Roman';
  206. PLATFORM.font.courier = 'Courier New';
  207. PLATFORM.font.symbol = 'Symbol';
  208. end
  209. %-Desktop
  210. %--------------------------------------------------------------------------
  211. try
  212. PLATFORM.desktop = usejava('desktop');
  213. catch
  214. PLATFORM.desktop = false;
  215. end