function S = ParseDataFileLine(L)

% S = ParseDataFileLine(L)
%
% Determine fields of structure S from '\n' terminated line
% L from DataFile.
% Fields of S are:
%	idnum (int)
%	sample_id (string)
% 	specfile (string) - complete path + filename
% 	imagefile (string)
%  segimagefile (string)
% 	basic_class (string) - basic classification
%	classification (string)
%  sample_area (interior, crust, etc)	
%  distance (double) /[meters]
%  x_scale (double) /[mm/pixel]
%  y_scale (double) /[mm/pixel]
%  x_origin /[pixel number - cartesian axes]
%  y_origin /[pixel number - cartesian axes]
%  position [X Y Z] /[m] - position (usually DGPS coords) of sample, if applicable.  
%                          If position n/a, then values are Inf.
%  metalfile (string) - path + filename of metal detector readings

% Liam Pedersen, NASA ARC, August 1998
% version 1.0

%extract idnum
[st, L] = strtok(L);
if (st(1) == '*') S.idnum = -1;
else S.idnum = str2num(st);
   if (isempty(S.idnum)) S.idnum = -1;
   end
end

% extract sample_id
[S.sample_id,L] = strtok(L);

% extract spectrum path + file
[spath, L] = strtok(L);
[sfile, L] = strtok(L);

if (~isempty(spath) & ~isempty(sfile) & spath(1) ~= '*' & sfile(1) ~= '*')
   S.specfile = [spath sfile];
else
   S.specfile = '*';
end

% extract image and segmented image path + file
[ipath, L] = strtok(L);
[ifile, L] = strtok(L);
%[sifile, L] = strtok(L);

if (~isempty(ipath) & ~isempty(ifile) & ipath(1) ~= '*' & ifile(1) ~= '*')
   S.imagefile = [ipath ifile];
else
   S.imagefile = '*';
end

% extract basic classification
[S.basic_class, L] = strtok(L);

% extract classification {gabbro, granite, basalt, diorite, slate, limestone, etc...}
[S.classification, L] = strtok(L);

% extract formation (Sedimentary, Igneous, Metamorphic, Extraterrestrial)
[S.formation, L] = strtok(L);

% extract sampling area
[S.sample_area, L] = strtok(L);

% extract distance from camera to sample
[st, L] = strtok(L);
if (~isempty(st) & st(1) ~= '*')
   S.distance = str2num(st);
else
   S.distance = -1;
end

% extract x scale of image (mm/pixel)
[st, L] = strtok(L);
if (~isempty(st) & st(1) ~= '*')
   S.x_scale = str2num(st);
else
   S.x_scale = -1;
end

% extract y scale of image (mm/pixel)
[st, L] = strtok(L);
if (~isempty(st) & st(1) ~= '*')
   S.y_scale = str2num(st);
else
   S.y_scale = -1;
end

% extract x origin of image (pixel)
[st, L] = strtok(L);
if (~isempty(st) & st(1) ~= '*')
   S.x_origin = str2num(st);
else
   S.x_origin = -1;
end

% extract y origin of image (pixel)
[st, L] = strtok(L);
if (~isempty(st) & st(1) ~= '*')
   S.y_origin = str2num(st);
else
   S.y_origin = -1;
end

%extract position of sample
[stx, L] = strtok(L);
[sty, L] = strtok(L);
[stz, L] = strtok(L);
if (~isempty(stx) & stx(1) ~= '*') X = str2num(stx); else X = inf; end
if (~isempty(sty) & sty(1) ~= '*') Y = str2num(sty); else Y = inf; end
if (~isempty(stz) & stz(1) ~= '*') Z = str2num(stz); else Z = inf; end
S.position = [X Y Z];

% extract metal detector path + file
[mpath, L] = strtok(L);
[mfile, L] = strtok(L);

if (~isempty(mpath) & mpath(1) ~= '*' & mfile(1) ~= '*')
   S.metalfile = [mpath mfile];
else
   S.metalfile = '*';
end


