clear all;
load Velmodels.mat
dx=0.6; dy=0.6;
Pvel=Pvel';Svel=Svel';
[xo,yo]=meshgrid(0:dx:size(Pvel,2)*dx-dx,0:dy:size(Pvel,1)*dy-dy);
[xi,yi]=meshgrid(0:330,1:120);
Pnew=interp2(xo,yo,Pvel,xi,yi);
Snew=interp2(xo,yo,Svel,xi,yi);
clear Pvel Svel;
% . . Construct P model
Pvel(1:120,1:384)=6.2;
Pvel(40:120,1:128)=8.0;
Pvel(42:120,238:384)=8.0;
Pvel(1:110,129:238)=Pnew(1:110,1:3:330);
Pvel(110:120,1:384)=8.0;

Svel(1:120,1:384)=3.6;
Svel(40:120,1:128)=4.5;
Svel(42:120,238:384)=4.5;
Svel(1:110,129:238)=Snew(1:110,1:3:330);
Svel(110:120,1:384)=4.5;

Pslow=1./Pvel;
Sslow=1./Svel;

% . . Construct 1D models
P1D( 1:120,1:384)=6.2;
P1D(40:120,1:384)=8.0;

S1D( 1:120,1:384)=3.6;
S1D(40:120,1:384)=4.5;

P1DS=1./P1D;
S1DS=1./S1D;

save Models Pvel Svel Pslow Sslow
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% . . Take .mat files to SEPLib 

% . . P velocity
% . . Create D1 Data file
   eval(['D1.history_file=''Pvel.HH'' '])
   D1.n=[120 384 1];   D1.o=[0.0 0.0 0];
   D1.d=[1. 3. 1];     D1.esize=4;
   eval(['D1.in=''/net/koko/jeff/Pvel@'' ']);   
   D1.data_format='xdr_float';
   D1.data=Pvel;

% . . Call sepwrite program ;
   eval(['sepwrite(D1,''Pvel.HH'') '])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% . . S velocity
% . . Create D1 Data file
   eval(['D1.history_file=''Svel.HH'' '])
   D1.n=[120 384 1];   D1.o=[0.0 0.0 0];
   D1.d=[1. 3. 1];     D1.esize=4;
   eval(['D1.in=''/net/koko/jeff/Svel@'' ']);   
   D1.data_format='xdr_float';
   D1.data=Svel;

% . . Call sepwrite program ;
   eval(['sepwrite(D1,''Svel.HH'') '])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% . . P slowness
% . . Create D1 Data file
   eval(['D1.history_file=''Pslow.HH'' '])
   D1.n=[120 384 1];   D1.o=[0.0 0.0 0];
   D1.d=[1. 3. 1];     D1.esize=4;
   eval(['D1.in=''/net/koko/jeff/Pslow@'' ']);   
   D1.data_format='xdr_float';
   D1.data=Pslow;

% . . Call sepwrite program ;
   eval(['sepwrite(D1,''Pslow.HH'') '])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% . . S slowness
% . . Create D1 Data file
   eval(['D1.history_file=''Sslow.HH'' '])
   D1.n=[120 384 1];   D1.o=[0.0 0.0 0];
   D1.d=[1. 3. 1];     D1.esize=4;
   eval(['D1.in=''/net/koko/jeff/Sslow@'' ']);   
   D1.data_format='xdr_float';
   D1.data=Sslow;

% . . Call sepwrite program ;
   eval(['sepwrite(D1,''Sslow.HH'') '])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% . . Take .mat files to SEPLib 

% . . P velocity
% . . Create D1 Data file
   eval(['D1.history_file=''P1D.HH'' '])
   D1.n=[120 384 1];   D1.o=[0.0 0.0 0];
   D1.d=[1. 3. 1];     D1.esize=4;
   eval(['D1.in=''/net/koko/jeff/P1D@'' ']);   
   D1.data_format='xdr_float';
   D1.data=P1D;

% . . Call sepwrite program ;
   eval(['sepwrite(D1,''P1D.HH'') '])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% . . S velocity
% . . Create D1 Data file
   eval(['D1.history_file=''S1D.HH'' '])
   D1.n=[120 384 1];   D1.o=[0.0 0.0 0];
   D1.d=[1. 3. 1];     D1.esize=4;
   eval(['D1.in=''/net/koko/jeff/S1D@'' ']);   
   D1.data_format='xdr_float';
   D1.data=S1D;

% . . Call sepwrite program ;
   eval(['sepwrite(D1,''S1D.HH'') '])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% . . P slowness
% . . Create D1 Data file
   eval(['D1.history_file=''P1DS.HH'' '])
   D1.n=[120 384 1];   D1.o=[0.0 0.0 0];
   D1.d=[1. 3. 1];     D1.esize=4;
   eval(['D1.in=''/net/koko/jeff/P1DS@'' ']);   
   D1.data_format='xdr_float';
   D1.data=P1DS;

% . . Call sepwrite program ;
   eval(['sepwrite(D1,''P1DS.HH'') '])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% . . S slowness
% . . Create D1 Data file
   eval(['D1.history_file=''S1DS.HH'' '])
   D1.n=[120 384 1];   D1.o=[0.0 0.0 0];
   D1.d=[1. 3. 1];     D1.esize=4;
   eval(['D1.in=''/net/koko/jeff/S1DS@'' ']);   
   D1.data_format='xdr_float';
   D1.data=S1DS;

% . . Call sepwrite program ;
   eval(['sepwrite(D1,''S1DS.HH'') '])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
