clear all; close all; clc;
cd ~jeff;startup;cd ~/Thesis/geono/

% Cartesian Test
nx=1024;
dx=15;
ox=15.;

nz=800;
dz=pi/((nz-1));
oz=0.;

xi1=[0:nx-1]*dx+ox;
xi3=[0:nz-1]*dz+oz;

%A =1.*ones(size(xi3)) + 0.*xi3 -.0*xi3.^2;
A=1.*ones(size(xi3)) +.2*xi3 -.05*xi3.^2;
%A=1.*ones(size(xi3))+( .4*sin(xi3)  )+ ;

% Say v=v(z)  = 1500 + z
for ix=1:nx
    for iz=1:nz
      rays(iz,ix,1)= A(iz)*xi1(ix)*cos(xi3(iz)); % X Coordinate
      rays(iz,ix,2)= A(iz)*xi1(ix)*sin(xi3(iz)); % Z Coordinate
%      Vel (iz,ix)  = 1500 + 0.5*rays(iz,ix,2);
    end
end



dz=mean(mean(sqrt( ...
       ( rays(2:nz,:,1)-rays(1:nz-1,:,1) ).^2+...
       ( rays(2:nz,:,2)-rays(1:nz-1,:,2) ).^2)));


  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % . . Coordinate system
  eval(['D1.history_file=''Test1.rays.HH'' '])
  D1.n=[nz nx 2];   D1.o=[oz ox 0];
  D1.d=[dz dx 1];   D1.esize=4;
  eval(['D1.in=''/net/koko/jeff/Test1.rays@'' ']);
  D1.data_format='xdr_float';
  D1.data=rays;
  eval(['sepwrite(D1,''Test1.rays.HH'') '])
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  
  clear D1
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % . . Velocit%y
  eval(['D1.history_file=''Test1.Vel.HH'' '])
  D1.n=[nz nx];   D1.o=[oz ox];
  D1.d=[dz dx];   D1.esize=4;
  eval(['D1.in=''/net/koko/jeff/Test1.Vel@'' ']);
  D1.data_format='xdr_float';
  D1.data=Vel;
  eval(['sepwrite(D1,''Test1.Vel.HH'') '])
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

