%function porkchop(JD_dep,JD_arr,spanx,spany,step)
%
% This function produces a porkchop plot given the 
% following inputs:
%    JD_dep = Center Julian Date of Departure
%    JD_arr = Center Julian Data of Arrival
%    spanx = Span of days before and after inputted JD_dep
%    spany = Span of days before and after inputted JD_arr
%    step = Number of days between each point
%
%    Example: If JD_dep=25, JD_arr=75 spanx=10, spany=20 and step=2 
%      the x-axis will cover from a JD of 15 to 35, and the y-axis
%      will cover from a JD of 55 to 95.  In order to create the
%      plot, Lambert's problem will be solved at 2-day intervals

row=0;
col=0;

for i=[JD_dep-spanx:step:JD_dep+spanx]
   row=row+1;
   JDi=i;
   col=0;
   for j=[JD_arr-spany:step:JD_arr+spany]
      col=col+1;
      JDf=j;
      con_x(row,col)=JDi-JD_dep;
      con_y(row,col)=JDf-JD_arr;
      [ri,vi,vearth,rf,vf,vmars]=lambert(JDi,JDf);
      C3_dep(row,col)=(norm(vi-vearth)^2);
      vinf_arr(row,col)=norm(vf-vmars);
   end
end

[C2,h2] = contour(con_x,con_y,C3_dep,[15,16:2:30,35,40,45,50],'r');
clabel(C2,h2);
hold on
[C3,h3] = contour(con_x,con_y,vinf_arr,[2.3,2.5,3:7],'b--');
clabel(C3,h3);
hold off
xlabel(['Days from Nominal Earth Departure Date, JD = ',num2str(JD_dep)])
ylabel(['Days from Nominal Mars Arrival Date, JD = ',num2str(JD_arr)])
legend([h2(1),h3(1)],'C3L (km^2/s^2)','Arrival V_\infty (km/s)',2)



