program sia_saar

use constants_0
use convert_0
use sal_1
use sal_2
use gsw_library_5

implicit none
integer i, j, k, icalled_r
integer nx, ny, nz
parameter(nx=91,ny=45,nz=45)

real*8 sp, p, sp_si, t_si, p_si ,lat, long, sa ,sa_si
real*8 flag_saar_r, ndepth(ny,nx)
!real*8 longs_r(nx), lats_r(ny), p_r(nz), saar_ref_r(nz,ny,nx)
  
!100 continue

!write(*,*)" "
!write(*,*) "enter p, long, lat to calculate R"
!write(*,*)" "
!read(*,*)  p, long, lat

icalled_r = 0

if(icalled_r.eq.0) then
   icalled_r = 1
   open(10,file='/home/Paul/sia/SIA_library/gsw_data_v3_0.dat',status='old',err=1)
   flag_saar_r = 1
   !read(10,*) (longs_r(i), i=1,nx)
   !read(10,*) (lats_r(i), i=1,ny)
   !read(10,*) (p_r(i), i=1,nz)
   !read(10,*) ((ndepth_r(j,i), j=1,ny), i=1,nx)
   !read(10,*) (((saar_ref_r(k,j,i), k=1,nz), j=1,ny), i=1,nx)
   close(10)
   go to 2
1  flag_saar_r = 0
2  continue
end if

if (flag_saar_r.eq.0) then
write(*,*) " gsw_data_v3_0.dat is missing !!!  "
end if

if (flag_saar_r.eq.1) then
write(*,*) " gsw_data_v3_0.dat exists !!!  "
end if

!write(*,*) " sia_saar:           ", gsw_saar(long,lat,p), " R "
!write(*,*) " sia_SA_from_SP:           ", gsw_asal_from_psal(gsw_psal_from_asal(sa,long,lat,p),long,lat,p), "kg/kg"

!go to 100


end program

