function datapath = readdatapath
% returns path for binary read from the .datapath file, if it exists.
% if it does not, the result is './'
%
% currently does not work for DOS/Windows environments
%
% .datapath should be either in current dir, or in home dir
% The function uses the $HOSTNM environment variable; i.e., if the computer
% running Matlab is named ashland.stanford.edu, then $HOSTNM=ashland. 
% If it is not set: 'SETENV HOSTNM ashland' at system command prompt to set it.
% .datapath syntax example: it should have a line like:
% ashland datapath=/net/ashland/scr1/nick/
%
% input argument: logical value, 0 if not on Windows, 1 otherwise

iswindows=checkwindows;

if ~iswindows
      [status0,hostname]=unix('echo $HOSTNM');
      if status0~=0
	 error('Environment variable HOSTNM not defined. See help.')
      end

      % Find datapath
      [status1,rawline]=unix('grep $HOSTNM .datapath');
      % if we receive a particular error message:
      if findstr('.aliases: No such file or directory.',rawline)==1
         rawline=rawline(38:end);
      end
      if status1~=0
	 [status2,rawline]=unix('grep $HOSTNM ~/.datapath');
         if findstr('.aliases: No such file or directory.',rawline)==1
            rawline=rawline(38:end);
         end
	 if status2~=0
	    rawline = './'
	 end
      end

      if strcmp(rawline,'./')
	 datapath = rawline;
      else
      % This lines assume the .datapath syntax is as described in help:
	 [h,datapath]=strtok(rawline);
         datapath = strtok(datapath);
	 datapath = datapath(10:end);
      end
else
      error('The current version does not run under DOS/Windows')
end
