Changeset 346


Ignore:
Timestamp:
04/30/21 19:25:36 (3 years ago)
Author:
dumas
Message:

nzoc, number of vertical levels in T/S files is read in netcdf file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SOURCES/bmelt-beckmann-gcm_mod.f90

    r339 r346  
    2929  implicit none 
    3030 
    31   integer, parameter :: nzoc = 40 !< number of vertical levels in the ocean 
    32   integer, parameter :: nbassins = 10 !< number of vertical levels in the ocean 
     31  integer, parameter :: nbassins = 10 !< number of sectors in the ocean 
     32  integer :: nzoc !< number of vertical levels in the ocean (read in netcdf T/S file) 
    3333  real*8 :: coef_OM !combined coefficient by DeConto et Pollard (m/yr/C2) 
    3434  real*8 :: K_t 
    3535  real*8 :: n_tour 
    36   real*8, dimension (nx,ny,nzoc) :: temp_ocean , mask_oce2, temp_ocean_2 !< thermal forcing            , input 
    37   real*8, dimension (nx,ny,nzoc) :: salinity_ocean !< thermal forcing            , input 
     36  real*8, dimension (:,:,:), allocatable :: temp_ocean , mask_oce2, temp_ocean_2 !< thermal forcing            , input 
     37  real*8, dimension (:,:,:), allocatable :: salinity_ocean !< thermal forcing            , input 
     38   
    3839  real :: bmelt_empty ! bmelt value for bassins without any GCM data 
    3940       
    4041!  integer, dimension (nx,ny) :: profondeur 
    4142  integer, dimension(nx,ny) :: bassin 
    42   real*8, dimension (nzoc)      :: zoc             !< depth of oceanic levels    , input 
     43  real*8, dimension (:), allocatable :: zoc             !< depth of oceanic levels    , input 
    4344  real*8, dimension (nx,ny)      :: mesh_area       !< grid cell area 
    4445  real*8, dimension (nx,ny)      :: ice_draft       !< ice draft (S-H) 
    4546  character(len=200) :: TO_file, SO_file, Bassin_file   ! fichiers de forcage 
    46   logical, dimension(nzoc) :: mask_bassin_vide  ! mask true if bassin without any GCM data 
     47  logical, dimension(nbassins) :: mask_bassin_vide  ! mask true if bassin without any GCM data 
    4748   
    4849contains 
     
    6768    integer :: depth_max_grid ! max depth level were T S are defined (all grid) 
    6869    integer, dimension(nx,ny) :: depth_max ! max depth were T S are defined for every point 
    69     integer, dimension(nx,ny,nzoc) :: mask_gcm  ! mask were T S are defined 
    70     integer, dimension(nx,ny,nzoc) :: mask_gcm_init ! mask were T S are defined in GCM before interpolation 
     70    integer, dimension(:,:,:), allocatable :: mask_gcm  ! mask were T S are defined 
     71    integer, dimension(:,:,:), allocatable :: mask_gcm_init ! mask were T S are defined in GCM before interpolation 
    7172    integer, dimension(nbassins) :: max_depth_bassin ! max level were T S are defined for every bassins 
    7273    integer :: nmax ! to avoid inifite loop  
     74    integer :: err 
    7375    namelist/bmelt_beckmann_gcm_mod/TO_file,SO_file,Bassin_file,bmelt_empty 
    7476     
     
    8284 
    8385    file_inputs=TRIM(DIRNAMEINP)//'Snapshots-GCM/'//TRIM(TO_file) 
     86     
     87    ! read the number of levels in T/S files : 
     88    nzoc = read_nzoc(file_inputs) 
     89    ! print*, 'nzoc = ',nzoc 
     90     
     91    ! allocate tabs : 
     92    if (.not.allocated(zoc)) then 
     93      allocate(zoc(nzoc),stat=err) 
     94      if (err/=0) then 
     95          print *,"erreur a l'allocation du tableau zoc",err 
     96          stop 4 
     97       end if 
     98    end if 
     99    if (.not.allocated(temp_ocean)) then 
     100      allocate(temp_ocean(nx,ny,nzoc),stat=err) 
     101      if (err/=0) then 
     102          print *,"erreur a l'allocation du tableau temp_ocean",err 
     103          stop 4 
     104       end if 
     105    end if 
     106    if (.not.allocated(mask_oce2)) then 
     107      allocate(mask_oce2(nx,ny,nzoc),stat=err) 
     108      if (err/=0) then 
     109          print *,"erreur a l'allocation du tableau mask_oce2",err 
     110          stop 4 
     111       end if 
     112    end if 
     113    if (.not.allocated(temp_ocean_2)) then 
     114      allocate(temp_ocean_2(nx,ny,nzoc),stat=err) 
     115      if (err/=0) then 
     116          print *,"erreur a l'allocation du tableau temp_ocean_2",err 
     117          stop 4 
     118       end if 
     119    end if 
     120    if (.not.allocated(salinity_ocean)) then 
     121      allocate(salinity_ocean(nx,ny,nzoc),stat=err) 
     122      if (err/=0) then 
     123          print *,"erreur a l'allocation du tableau salinity_ocean",err 
     124          stop 4 
     125       end if 
     126    end if 
     127    if (.not.allocated(mask_gcm)) then 
     128      allocate(mask_gcm(nx,ny,nzoc),stat=err) 
     129      if (err/=0) then 
     130          print *,"erreur a l'allocation du tableau mask_gcm",err 
     131          stop 4 
     132       end if 
     133    end if 
     134    if (.not.allocated(mask_gcm_init)) then 
     135      allocate(mask_gcm_init(nx,ny,nzoc),stat=err) 
     136      if (err/=0) then 
     137          print *,"erreur a l'allocation du tableau mask_gcm_init",err 
     138          stop 4 
     139       end if 
     140    end if 
     141      
    84142    call Read_Ncdf_var('lev',file_inputs,tab1d) 
    85143    zoc(:)  = -tab1d(:) 
     
    378436 
    379437  end subroutine bmeltshelf 
     438 
     439  function read_nzoc(filename) 
     440    ! Reads number of vertical levels in ocean forcing NetCDF File. 
     441    ! Returns the levels number  
     442 
     443    ! Reads 
     444    use netcdf 
     445 
     446    implicit none 
     447    ! input 
     448    character (len = *), intent(in) :: filename 
     449    integer :: read_nzoc 
     450 
     451    ! This will be the netCDF ID for the file and data variable. 
     452    integer :: ncid, varid, status 
     453    integer, dimension(3) :: count 
     454    integer, dimension(3) :: start 
     455 
     456    ! Open the file.  
     457    status = nf90_open(filename, nf90_nowrite, ncid) 
     458    if (status/=nf90_noerr) then 
     459       write(*,*)"unable to open netcdf file : ",filename 
     460       stop 
     461    endif 
     462 
     463    ! Get the varids of the netCDF variable. 
     464    status = nf90_inq_dimid(ncid, "lev", varid) 
     465    status = nf90_inquire_dimension(ncid, varid, len = read_nzoc) 
     466 
     467    ! Close the file. This frees up any internal netCDF resources 
     468    ! associated with the file. 
     469    status = nf90_close(ncid) 
     470 
     471  end function read_nzoc 
     472 
    380473end module bmelt_beckmann_gcm_mod 
Note: See TracChangeset for help on using the changeset viewer.