function [x,y,var,Lat_long]=loaddatfile(filename,index)
%% load date file using format based on the index
%%  index = 1   ->  [Long Lat   Var] where Long & Lat in degrees
%%  index = 2   ->  [Lat  Long  Var] where Long & Lat in degrees
%%  index = 3   ->  [ X     Y   Var] where X & Y in km
%%  index = 4   ->  [ Y     X   Var] where X & Y in km
%%  Lat_long = long/lat flag: 
%%      if using long/lat or Lat_long = 1, otherwise = 0 


%%  Kriging Software Package  version 1.0 beta,   October 29, 1998
%%  Copyright (c) 1998, property of Dezhang Chu and Woods Hole Oceanographic
%%  Institution.  All Rights Reserved.


variablename=filenametruncation(filename);
eval(['load ' '''' filename ''''])
eval(['dat=' variablename ';'])

%dat=load(filename);
switch index
  case 1 
   x=dat(:,1);y=dat(:,2);
   Lat_long = 1;
  case 2
   x=dat(:,2);y=dat(:,1);
   Lat_long = 1;
  case 3
   x=dat(:,1);y=dat(:,2);
   Lat_long=0;
  case 4
   x=dat(:,2);y=dat(:,1);
   Lat_long=0;
end
var=dat(:,3); 
