function [vnames, vdat, rowdat]=unpack(fstring)
% unpack takes the string of data and forms three arrays out of it.
% function [vnames, vdat, rowdat]=unpack(fstring)
% First the number of comounds is put into nc as a global variable
% Array  Holds
% vnames names of all data variables, both numeric and character
% vdat gives the number of row, columns and type of each variable.
%   the type is designated by: 0=character, 1=numeric
% rowdat is the row data to be inserted into the arrays
% cr will be the carriage return string variable: It is character 10 in Sun OS 4.1
%     and 13 on a Mac. 770xx.  
vnames = '';
vrmax = [];
vcols = [];
vrows = [];
vtypes = [];
rowdat = '';
cr=setstr(10);
cr=setstr(10);
ncrs=find(cr==fstring); % shows where CRs are in fstring
% set nc from data in the first line of the file that made fstring
global nc
v1=fstring(1:(ncrs(1)-1));
lv1=length(v1);
eval([v1(1:8),'=',v1(9:lv1),';']); % setting the number of compounds: nc
nl=2;  % next line to be decoded
while nl<length(ncrs)  % there are the same number of lines as carriage returns
   stln=ncrs(nl-1)+1; % the start of a line
   mdln=stln+7; % The first 8 characters have the variable name in it
   endln=ncrs(nl)-1; % the end of the line
   vnames=[vnames;fstring(stln:mdln)]; % extracting the variable name
   eval(['cdat=[',fstring(mdln+1:endln),'];']); %extracting the size and type
   if length(cdat)~=4
      disp('There are not four numbers on line:')
      disp(nl)
      return
   end
   vrmax=[vrmax, cdat(1)]; % max number of rows
   vcols=[vcols, cdat(2)]; % the number of columns
   vrows=[vrows, cdat(3)]; % the number of rows
   vtypes=[vtypes, cdat(4)]; % the type: 0=character, 1=numeric
   for k=1:cdat(3)
      nl=nl+1;
      stln=ncrs(nl-1)+1;
      endln=ncrs(nl)-1;
      rowdat=cgrp(rowdat,fstring(stln:endln)); % putting each row of data into rowdat
   end
   nl=nl+1;
end
vdat=[vrmax;vcols;vrows;vtypes]; % making a single array
