%   sends all files in C:\Documents and Settings\Lisa Taylor\My
%   Documents\Data\Apex\0015\data
%   to rd_apex.m
%
close all
clear all
[file_list_out,n_file_out]=list_file('C:\Documents and Settings\Lisa Taylor\My Documents\Data\0015\Apex\data') %calls list_file and returns the list and number of files in specified path
  for ii = 1:n_file_out-2 %for all files in specified folder (-2 because of two sets of dot files)
      filename=file_list_out(ii+2,:); %assigns all of row i (0015.001.edf) to array filename
      filename1=['C:\Documents and Settings\Lisa Taylor\My Documents\Data\0015\APEX\data\',filename]; %assigns contents of array filename (0005.001.edf) to filename1
      [A, B, C]=rd_apex(filename1); %calls rd_apex.m, passes it path\filename1, and expects array pos [A] and array dat [B] back
      %need to give A, B names that match file from which they were derived
      file_i=int2str(ii); %converts ii to a string and assigns it to file_i
       n=length(file_i); %checks length of string in file_i
        if n==1 %if 1, 2, 3....9
           assignin('base',['pos00',int2str(ii)],A); %concatenates pos00 and ii (to become pos001) and assigns this variable the value A
           assignin('base',['dat00',int2str(ii)],B); %concatenates dat00 and ii (to become dat001) and assigns this variable the value B
           assignin('base',['date00',int2str(ii)],C); %concatenates date00 and ii (to become date001) and assigns this variable the value C
        elseif n==2 %if 10, 11, 12....
           assignin('base',['pos0',int2str(ii)],A); %concatenates pos0 and ii (to become pos010) and assigns this variable the value A
           assignin('base',['dat0',int2str(ii)],B); %concatenates dat0 and ii (to become dat010) and assigns this variable the value B
           assignin('base',['date0',int2str(ii)],C); %concatenates date0 and ii (to become date010) and assigns this variable the value C
        else %if 100, 101, 102...999
           assignin('base',['pos',int2str(ii)],A); %concatenates pos and ii (to become pos100) and assigns this variable the value A
           assignin('base',['dat',int2str(ii)],B); %concatenates dat and ii (to become dat100) and assigns this variable the value B
           assignin('base',['date',int2str(ii)],C); %concatenates date and ii (to become date100) and assigns this variable the value C
        end           
  end
%should have N arrays beginning with pos and dat (check pos001 or dat001 so see data in these arrays)
N=(n_file_out-2); % need number of files for plot scripts
save  apex_data -v6