
  program built_hessian

  use sep

  implicit none
  
  integer                         		:: i1,i2,i3,i4
  integer					:: n1,n2,n3,n4,n5,n6,n7,n8,n9,n10
  real                            		:: o1,o2,o3,o4,o5,o6,o7,o8,o9,o10
  real                            		:: d1,d2,d3,d4,d5,d6,d7,d8,d9,d10
  real,dimension(:),allocatable 		:: in,out

  call sep_init()
  call sep_begin_prog()

  !! get info from history file
!  call from_history("n1",n1);  call from_history("d1",d1);  call from_history("o1",o1);
!  call from_history("n2",n2);  call from_history("d2",d2);  call from_history("o2",o2);
!  call from_history("n3",n3);  call from_history("d3",d3);  call from_history("o3",o3);

  !! get info from parameter
  call from_param("n1",n1);  call from_param("n2",n2);!  call from_param("n3",n3)
  call from_param("d1",d1);  call from_param("d2",d2);!  call from_param("d3",d3)
  call from_param("o1",o1);  call from_param("o2",o2);!  call from_param("o3",o3)
  call from_param("n4",n4);  call from_param("d4",d4);  call from_param("o4",o4)

  
  !! write info out to history file
  call to_history("n1",1);   call to_history("d1",1);  call to_history("o1",1);		call putch('label1', 's', 'ax')
  call to_history("n2",1);   call to_history("d2",1);  call to_history("o2",1);		call putch('label2', 's', 'ay')
  call to_history("n3",1);   call to_history("d3",1);  call to_history("o3",1);		call putch('label3', 's', 'az')
  call to_history("n4",18);  call to_history("d4",1);  call to_history("o4",1);		call putch('label4', 's', 'ang_x_')
  call to_history("n5",1);   call to_history("d5",1);  call to_history("o5",1);		call putch('label5', 's', 'ang_y_')
  call to_history("n6",n2);  call to_history("d6",1);  call to_history("o6",-60);	call putch('label6', 's', 'ang_x')
  call to_history("n7",1);   call to_history("d7",1);  call to_history("o7",1);		call putch('label7', 's', 'ang_y')
  call to_history("n8",n1);  call to_history("d8",d1); call to_history("o8",o1);	call putch('label8', 's', 'zt')
  call to_history("n9",50);  call to_history("d9",75); call to_history("o9",32000);	call putch('label9', 's', 'xt')
  call to_history("n10",1);  call to_history("d10",1); call to_history("o10",1);   	call putch('label10', 's', 'yt')


!! allocate working space
  allocate(in(n1*n2*n3),out(n1*n2*n3))
!!

 in=0.;out=0.
 call sreed("in",in,n1*n2*n3*4)
n3=n3/n4
do i4=1,n4
   do i3=1,n3 
      do i2=1,n2
         do i1=1,n1
 	    out((i3-1)*n1*n2*n4+(i1-1)*n2*n4+(i2-1)*n4+i4)=in((i4-1)*n1*n2*n3+(i3-1)*n2*n1+(i2-1)*n1+i1)
         end do
      end do
   end do
end do

call sep_write(out,"out")
!! clean up
deallocate(in,out)
call sep_end_prog()

end program built_hessian
