clear all; close all; clc;
cd ~jeff;startup;cd ~/Research/RADCIG/

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

xi1=[5:175]/180*pi;
xi3=[0:0.05:1.5];
nx=length(xi1);
nz=length(xi3);
A=1000;

for ix=1:nx
    for iz=1:nz
      rays(iz,ix,1)= A*(xi1(ix))*cos(xi3(iz)); % X Coordinate
      rays(iz,ix,2)= A*(xi1(ix))*sin(xi3(iz)); % Z Coordinate
    end
end
ox=xi1(1);
dx=xi1(2)-xi1(1);

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=''Polar.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/Polar@'' ']);
  D1.data_format='xdr_float';
  D1.data=rays;
  eval(['sepwrite(D1,''Polar.HH'') '])
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
