year = ["1993","1994","1996","1997","1998","1999","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015","2016","2017"];
yearprinter = 'I just finished';
depthprinter = 'I just finished';
dew = 8.88889;
for m = 1:9
    tic
    for j = 1:length(year) %Run the code for each year.
        tic
        day = xlsread('Weather Data 1993-2018.xlsx',year(j),'A2:A215');
        RHmax= xlsread('Weather Data 1993-2018.xlsx',year(j),'D2:D215');
        RHmin= xlsread('Weather Data 1993-2018.xlsx',year(j),'E2:E215');
        p = xlsread('Weather Data 1993-2018.xlsx',year(j),'F2:F215');
        Wind = xlsread('Weather Data 1993-2018.xlsx',year(j),'G2:G215');
        Tmin = xlsread('Weather Data 1993-2018.xlsx',year(j),'C2:C215');
        Tmax = xlsread('Weather Data 1993-2018.xlsx',year(j),'B2:B215');
        Tmean = (Tmax + Tmin)/2;
        Input = table(day,RHmax,RHmin,p,Wind,Tmin,Tmax);
        Ri = [9.6, 10.6, 10.9, 9.9, 9.2, 8.3, 7.0];
        Rmda = [];
        for i = 1:length(day)
            if 1 <= day(i) && day(i) <= 30
                Rnettemp = 3.6 * Ri(1);
                Rmda = [Rmda, Rnettemp];
            end
            if 31 <= day(i) && day(i) <= 61
                Rnettemp = 3.6 * Ri(2);
                Rmda = [Rmda, Rnettemp];
            end
            if 62 <= day(i) && day(i) <= 91
                Rnettemp = 3.6 * Ri(3);
                Rmda = [Rmda, Rnettemp];
            end
            if 92 <= day(i) && day(i) <= 122
                Rnettemp = 3.6 * Ri(4);
                Rmda = [Rmda, Rnettemp];
            end
            if 123 <= day(i) && day(i) <= 153
                Rnettemp = 3.6 * Ri(5);
                Rmda = [Rmda, Rnettemp];
            end
            if 154 <= day(i) && day(i) <= 183
                Rnettemp = 3.6 * Ri(6);
                Rmda = [Rmda, Rnettemp];
            end
            if 184 <= day(i) && day(i) <= 214
                Rnettemp = 3.6 * Ri(7);
                Rmda = [Rmda, Rnettemp];
            end
            if 215 <= day(i) && day(i) <= 365
                Rnettemp = 3.6 *Ri(7);
                Rmda = [Rmda, Rnettemp];
            end
        end
        Rmd = Rmda';
        windms = Wind*0.44704;
        windconverter = (4.87/(log(67.8*8.3536-5.42)));
        Wind2 = windms*windconverter;
        slope_vapor_pressure_curve = (4098*(.6108*exp((17.27*Tmean)./(Tmean+237.3))))./((Tmean + 237.3).^2);
        Pressure = p*3.38639;
        Psychrometric_constant = .000665*Pressure;
        Delta_term = slope_vapor_pressure_curve./(slope_vapor_pressure_curve + Psychrometric_constant.*(1+.34*Wind2));
        PT = Psychrometric_constant./(slope_vapor_pressure_curve + Psychrometric_constant.*(1+0.34*Wind2));
        TT = (900./(Tmean + 273)).*Wind2;
        Emin = .6108*exp((17.27*Tmin)./(Tmin+237.3));
        Emax = .6108*exp((17.27*Tmax)./(Tmax+237.3));
        Es = (Emax+Emin)/2;
        AVP = Emin.*((RHmax/100)+Emax.*(RHmin/100))/2;
        Dr = 1+.033*cos(((2*pi)/365)*day);
        declination = 0.409*sin(((2*pi)/365)*day-1.39);
        lat_dec_deg = 36.75;
        lat_rad = pi/180*lat_dec_deg;
        sunset_hr_angle = acos(-tan(lat_rad)*tan(declination));
        Rextra = 1440/pi*.082*Dr.*(sunset_hr_angle*sin(lat_rad).*sin(declination))+(cos(lat_rad)*cos(declination).*sin(sunset_hr_angle));
        Rclearsky = (.75+(2*(10^(-5)))*2163)*Rextra;
        Bare = xlsread('imagedata.xlsx','Sheet1','B2:B14');
        Straw = xlsread('imagedata.xlsx','Sheet1','C2:C14');
        if Bare(m) == 0
            Albedo = .28;
        end
        if Straw(m)==0
            Albedo = .15;
        end
        if Bare(m)~= 0 && Straw(m)~= 0
            Albedo = .15*Bare(m) + .28*Straw(m);
        end
        Rnetshort = (1-Albedo)*Rmd;
        if Rclearsky > Rmd
            Rnetlong = (4.903*10^-9)*(((Tmax+273.16).^4+(Tmin+273.16).^4)/2).*(.34-.14*sqrt(AVP)).*((1.35*Rmd./Rclearsky)-.35);
        else
            Rnetlong = (4.903*10^-9)*(((Tmax+273.16).^4+(Tmin+273.16).^4)/2).*(.34-.14*sqrt(AVP)).*(1.35-.35);
        end
        Rnet = .408*(Rnetshort-Rnetlong);
        ETrad = Delta_term.*Rnet;
        ETwind = PT.*TT.*(Es-AVP);
        ET=ETrad+ETwind;
        Finale = table(day,ETrad,ETwind,ET);
        if m == 1
            xlswrite('output2data0.xlsx',day,j);
            xlswrite('output2data0.xlsx',ET,j,'B1:B214');
            xlswrite('output2data0.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data0.xlsx',ETwind,j,'D1:D214');
        end
        if m == 2
            xlswrite('output2data1.xlsx',day,j);
            xlswrite('output2data1.xlsx',ET,j,'B1:B214');
            xlswrite('output2data1.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data1.xlsx',ETwind,j,'D1:D214');
        end
        if m == 3
            xlswrite('output2data2.xlsx',day,j);
            xlswrite('output2data2.xlsx',ET,j,'B1:B214');
            xlswrite('output2data2.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data2.xlsx',ETwind,j,'D1:D214');
        end
        if m == 4
            xlswrite('output2data3.xlsx',day,j);
            xlswrite('output2data3.xlsx',ET,j,'B1:B214');
            xlswrite('output2data3.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data3.xlsx',ETwind,j,'D1:D214');
        end
        if m == 5
            xlswrite('output2data4.xlsx',day,j);
            xlswrite('output2data4.xlsx',ET,j,'B1:B214');
            xlswrite('output2data4.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data4.xlsx',ETwind,j,'D1:D214');
        end
        if m == 6
            xlswrite('output2data5.xlsx',day,j);
            xlswrite('output2data5.xlsx',ET,j,'B1:B214');
            xlswrite('output2data5.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data5.xlsx',ETwind,j,'D1:D214');
        end
        if m == 7
            xlswrite('output2data6.xlsx',day,j);
            xlswrite('output2data6.xlsx',ET,j,'B1:B214');
            xlswrite('output2data6.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data6.xlsx',ETwind,j,'D1:D214');
        end
        if m == 8
            xlswrite('output2data7.xlsx',day,j);
            xlswrite('output2data7.xlsx',ET,j,'B1:B214');
            xlswrite('output2data7.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data7.xlsx',ETwind,j,'D1:D214');
        end
        if m == 9
            xlswrite('output2data8.xlsx',day,j);
            xlswrite('output2data8.xlsx',ET,j,'B1:B214');
            xlswrite('output2data8.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data8.xlsx',ETwind,j,'D1:D214');
        end
        if m == 10
            xlswrite('output2data9.xlsx',day,j);
            xlswrite('output2data9.xlsx',ET,j,'B1:B214');
            xlswrite('output2data9.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data9.xlsx',ETwind,j,'D1:D214');
        end
        if m == 11
            xlswrite('output2data10.xlsx',day,j);
            xlswrite('output2data10.xlsx',ET,j,'B1:B214');
            xlswrite('output2data10.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data10.xlsx',ETwind,j,'D1:D214');
        end
        if m == 12
            xlswrite('output2data11.xlsx',day,j);
            xlswrite('output2data11.xlsx',ET,j,'B1:B214');
            xlswrite('output2data11.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data11.xlsx',ETwind,j,'D1:D214');
        end
        if m == 13
            xlswrite('output2data12.xlsx',day,j);
            xlswrite('output2data12.xlsx',ET,j,'B1:B214');
            xlswrite('output2data12.xlsx',ETrad,j,'C1:C214');
            xlswrite('output2data12.xlsx',ETwind,j,'D1:D214');
        end
        disp(yearprinter)
        disp(year(j))
        disp(j)
        toc
    end
disp(depthprinter)
disp(m)
toc
end