function TEMP_WOD01 = extract_bin(datetime_wod01, dep_wod01, bindepths, temp_wod01)
%
% finds all temp data from WOD01 data for a given month and depth and calculates median
% depths (bindepths) provided in plot_osd.m - can adjust
%
[yy,month,dd] = datevec(datetime_wod01); %converts date string to date vector
uyear = unique(yy); %finds each year (once) in dataset and stores in array uyear
TEMP_WOD01 = []; %initializes array TEMP_WOD01
for ky = 1:length(uyear) %for each year in dataset
    umonth = unique(month(yy==uyear(ky))); %finds each month (once) in each year
    for km = 1:length(umonth) %for each month in each year in each dataset
        midx = yy==uyear(ky) & month==umonth(km); %where year AND month exist (create logical array)
        temp_wod01_midx = temp_wod01(midx); %create array temp_wod01_midx of temp data at midx = true
        dep_midx = dep_wod01(midx); %create array dep_midx of depth data at midx = true
        %disp([uyear(ky) umonth(km)]);
        thisrow = [uyear(ky) umonth(km) nan(1,2*(length(bindepths)-1))]; %make array thisrow of yr, mo, NaNs for each bindepth to fill w/chl and st dev
        for kb = 1:(length(bindepths)-1) %for all bindepths
            found = dep_midx>=bindepths(kb) & dep_midx<bindepths(kb+1); %where dep falls within bindepth range (logical array created)
            thisrow(2+kb) = nanmedian(temp_wod01_midx(found)); %skip yr, mo cols of array thisrow and add median chl for bindepth range to next cols of row kb
            thisrow(2+length(bindepths)-1+kb) = nanstd(temp_wod01_midx(found)); %skip yr, mo, chl cols and add std to next cols of row kb
        end
        TEMP_WOD01 = [TEMP_WOD01; thisrow]; %append new row to big array TEMP_WOD01 (see plot.osd.m for TEMP_WOD01 contents)
    end
end
return
