% function [imgpth resfol dataset mpd]=ListDataset2(mpd);
%Make list of entire data set for programs to run through
% global mpd
if ~exist('mpd')
    mpd=uigetdir(pwd,['Select the main project directory (that contains the Images folder and where all other results will be saved)']);
end
% d_img=uigetdir(pwd,['Select the main image folder']);
% d_res=uigetdir(pwd,['Select/create the folder where you want to save the mat-file data']);

d_img=[mpd '\Images'];
d_res=[mpd '\Mat-files'];

imgpth=[];
resfol=[];
dataset=[];

cd(d_img);
pltf=dir;
for i1=3:size(pltf)
    pltimd=[d_img '\' pltf(i1).name];
    cd(pltimd)
    imgs=dir('*.jpg'); %go through images
    for i3=1:size(imgs,1)
        
        %% Get pic info
        groupID=imgs(i3).name(1:3);
        pltID=imgs(i3).name(5:7);
        age=imgs(i3).name(9:10);
        plane=imgs(i3).name(12:13);
        
        %% Make list of data and results folders
        dataset=cat(1,dataset,imgs(i3).name(1:13));
        imgpth=cat(1,imgpth,[pltimd '\' imgs(i3).name]);
        resfol=cat(1,resfol,[d_res '\PLT' pltID '\' plane]);
        
        %% Make results folder for this line/plant/plane
        if ~exist(resfol(end,:));
            mkdir(resfol(end,:));
        end
        
        pltID=str2num(pltID);
        age=str2num(age);
        plane=str2num(plane(end));
        c_imgpth=imgpth(end,:);
        save([resfol(end,:) '/picinfo.mat'],'groupID','pltID','age','plane','c_imgpth');
    end
end


%% Save to the main folder
save([mpd '\dataset.mat'],'dataset','imgpth','resfol')


