clear all; close all;

cd 'C:\Borland\BCC55\Bin\fdtd'


LIMX = 60
LIMY = 100

fps = 12;
outfilename = 'movie.avi';
outfile = sprintf('%s', outfilename);
mov = avifile(outfile, 'fps', fps, 'quality', 100);

delX = 0.389e-3;
delY = 0.4e-3;
delT = 0.441e-12;

x = (1:LIMX)*delX;
y = (1:LIMY)*delY;


% show patch position
B = zeros(60, 100);
heightP = 0.2;

%microstrip
for i=20:26
    for j=1:50
        B(i, j) = heightP;
    end
end

%patch antenna
for i=15:47
    for j=51:90
        B(i, j) = heightP;
    end
end
surf(y, x, B);
axis([0 LIMY*delY 0 LIMX*delX -1 1])
title('Here is the patch and microstrip line.  In a second a pulse will be launched')
pause(1)
for nn=1:25
    F = getframe( figure(1) );
    mov=addframe(mov, F);
end

A = dlmread('junk.0');
    counter = 1;
    for a=1:LIMX
        B(a, :) = A(counter:counter+LIMY-1);
        counter = counter + LIMY;
    end
    surf(y, x, B)
    axis([0 LIMY*delY 0 LIMX*delX -1 1])
        winsize = get(figure,'Position');
    winsize(1:2) = [0 0];
    close;
    fig1 = figure;
set(fig1,'NextPlot','replacechildren');
for iter=0:599
    basename = 'junk.';
    suffix = int2str(iter);

    filename = [basename suffix];

    A = dlmread(filename);

    counter = 1;
    for a=1:LIMX
        B(a, :) = A(counter:counter+LIMY-1);
        counter = counter + LIMY;
    end
    figure(1)
    surf(y, x, B)
    axis([0 LIMY*delY 0 LIMX*delX -1 1])
    xlabel('y-axis (m)');
    ylabel('x-axis (m)');
    zlabel('E_z (V/m)');
    title(['Time = ' num2str(iter*delT) ' sec     Plot of z-component of E-field under Patch Antenna and Microstrip'])
   
    pause(.1)
    F = getframe( figure(1) );
    mov=addframe(mov, F);
   
end
mov = close(mov);

