% GLG 410 Fall 2011
% Japan Seismicity Script

% Created by:  Christy Baker
% Date created:  10/15/2011
% Date modified: 11/06/2011

% This script will plot seismicity data for Japan
%------------------------------------------------------
% % Load data from Japanese Eqrthquakes
    load ('japan.txt', 'ascii');
    
% Import variables into Matlab data from Japanese Earthquakes
    Latitude = japan(:,1);
    Longitude = japan(:,2);
    Depth = japan(:,3);
    Magnitude = japan(:,4);
    Time = japan(:,5);
    
% Plot of Magnitude vs. Time for seismicity since Jan. 1, 2011
    figure (1)
    plot (Time,Magnitude,'k.');
    title ('Magnitude vs. Time of 2011 Japan Earthquakes');
    ylabel ('Magnitude');
    xlabel ('Time (days)');
%---------------------------------------------------------    

% 3D plot of earthquake locations
    figure (2)
    plot3(Longitude, Latitude, -Depth, 'r.')
    grid on
    title('Japan Earthquake Hypocenters')
    xlabel('Longitude')
    ylabel('Latitude')
    zlabel('Depth (km)')
%----------------------------------------------------------

% Grid Plots
% Plot blue circles above each point in grid on top of earthquake locations.

figure(3)
plot(Longitude,Latitude,'r.')
grid on
title('Japan Earthquake Hypocenters')
xlabel('Longitude')
ylabel('Latitude')
zlabel('Depth (km)')
hold on

stepsize = 0.5;
long_range=min(Longitude):stepsize:max(Longitude);
lat_range=min(Latitude):stepsize:max(Latitude);
for long = long_range
       for lat = lat_range
           tf=Longitude <= long+stepsize./2 & Longitude >= long-stepsize./2 & Latitude <= lat+stepsize./2 & Latitude >= lat-stepsize./2;
       locations = find(tf);
       if length (locations) ~= 0
            plot(long,lat,'bo')
        end
    end
end


figure(4)
plot(Longitude,Latitude,'r.')
grid on
title('Japan Earthquake Hypocenters')
xlabel('Longitude')
ylabel('Latitude')
zlabel('Depth (km)')
hold on

stepsize = 1.0;
long_range=min(Longitude):stepsize:max(Longitude);
lat_range=min(Latitude):stepsize:max(Latitude);
for long = long_range
       for lat = lat_range
           tf=Longitude <= long+stepsize./2 & Longitude >= long-stepsize./2 & Latitude <= lat+stepsize./2 & Latitude >= lat-stepsize./2;
       locations = find(tf);
       if length (locations) ~= 0
            plot(long,lat,'bo')
        end
    end
end


figure(5)
plot(Longitude,Latitude,'r.')
grid on
title('Japan Earthquake Hypocenters')
xlabel('Longitude')
ylabel('Latitude')
zlabel('Depth (km)')
hold on

stepsize = 2.0;
long_range=min(Longitude):stepsize:max(Longitude);
lat_range=min(Latitude):stepsize:max(Latitude);
for long = long_range
       for lat = lat_range
           tf=Longitude <= long+stepsize./2 & Longitude >= long-stepsize./2 & Latitude <= lat+stepsize./2 & Latitude >= lat-stepsize./2;
       locations = find(tf);
       if length (locations) ~= 0
            plot(long,lat,'bo')
        end
    end
end

%--------------------------------------------------------------------------
% Text Label Plots

figure (6)
plot(Longitude,Latitude,'r.')
grid on
title('Japan Earthquake Hypocenters')
xlabel('Longitude')
ylabel('Latitude')
zlabel('Depth (km)')
hold on

stepsize = 0.5;
long_range=min(Longitude):stepsize:max(Longitude);
lat_range=min(Latitude):stepsize:max(Latitude);
for long = long_range
       for lat = lat_range
            tf=Longitude <= long+stepsize./2 & Longitude >= long-stepsize./2 & Latitude <= lat+stepsize./2 & Latitude >= lat-stepsize./2;
            locations = find(tf);
            mean_depth=mean(Depth(locations));
            if length(locations)~=0
                s=sprintf('%2.1f',mean_depth);
                text(long,lat,s);
            end
       end
end

figure (7)
plot(Longitude,Latitude,'r.')
grid on
title('Japan Earthquake Hypocenters')
xlabel('Longitude')
ylabel('Latitude')
zlabel('Depth (km)')
hold on

stepsize = 1.0;
long_range=min(Longitude):stepsize:max(Longitude);
lat_range=min(Latitude):stepsize:max(Latitude);
for long = long_range
       for lat = lat_range
            tf=Longitude <= long+stepsize./2 & Longitude >= long-stepsize./2 & Latitude <= lat+stepsize./2 & Latitude >= lat-stepsize./2;
            locations = find(tf);
            mean_depth=mean(Depth(locations));
            
            if length(locations)~=0
                s=sprintf('%2.1f',mean_depth);
                text(long,lat,s);
            end
       end
end


figure (8)
plot(Longitude,Latitude,'r.')
grid on
title('Japan Earthquake Hypocenters')
xlabel('Longitude')
ylabel('Latitude')
zlabel('Depth (km)')
hold on

stepsize = 2.0;
long_range=min(Longitude):stepsize:max(Longitude);
lat_range=min(Latitude):stepsize:max(Latitude);
for long = long_range
       for lat = lat_range
            tf=Longitude <= long+stepsize./2 & Longitude >= long-stepsize./2 & Latitude <= lat+stepsize./2 & Latitude >= lat-stepsize./2;
            locations = find(tf);
            mean_depth=mean(Depth(locations));
            if length(locations)~=0
                s=sprintf('%2.1f',mean_depth);
                text(long,lat,s);
            end
       end
end

%--------------------------------------------------------------------------
% Image Plots

figure(9)
Scaled_Image_Function(0.5,Longitude,Latitude,Depth,'Latitude','Longitude')
plot(Longitude, Latitude, 'k.')
hold on


figure(10)
Scaled_Image_Function(0.5,Longitude,Latitude,Depth,'Latitude','Longitude')
plot(Longitude, Latitude, 'k.')
hold on

figure(11)
Scaled_Image_Function(0.5,Longitude,Latitude,Depth,'Latitude','Longitude')
plot(Longitude, Latitude, 'k.')
hold on


           



               
           
    
    