!
!  put_mem.f90
!
    subroutine put_mem(cmem,cname,ctype,location,length,ierr)
    use main_memory
    use memory_pointers
    character (len=*) :: cmem,cname
    character (len=*) :: ctype
    integer :: length,ierr
! Pointer
    integer :: location
!
!-----------   
    if ( cmem(1:7)=='physics' ) then
      nphys = nphys + 1
      if (nphys > nphys_max) then
        write(*,*) 'Physics pointer table exceeded...'
        stop
      endif  
      phys_ptrs(nphys)%name=cname
      phys_ptrs(nphys)%type=ctype
      phys_ptrs(nphys)%ptr=location
      phys_ptrs(nphys)%length=length
!
      if (ctype(1:4)=='real') then
        pphys_real = pphys_real+length  
        if (pphys_real > irzp) then
          write(*,*) 'Physics real memory exceeded...'
          stop        
        endif
      elseif (ctype(1:3)=='int') then
        pphys_int = pphys_int+length 
        if (pphys_int > iizp) then
          write(*,*) 'Physics integer memory exceeded...'
          stop        
        endif
      elseif (ctype(1:4)=='char') then
        pphys_char = pphys_char+length
        if (pphys_char > iczp) then
          write(*,*) 'Physics character memory exceeded...'
          stop        
        endif                 
      endif
!
!-----------
    else if ( cmem(1:4)=='cell' ) then 
      ncell = ncell + 1
      if (ncell > ncell_max) then
        write(*,*) 'Cell pointer table exceeded...'
        stop
      endif 
      cell_ptrs(ncell)%name=cname
      cell_ptrs(ncell)%type=ctype
      cell_ptrs(ncell)%ptr=location
      cell_ptrs(ncell)%length=length
!
      if (ctype(1:4)=='real') then
        p_real = p_real+length               
        if (p_real > irz) then
          write(*,*) 'Real memory exceeded...'
          stop        
        endif
      elseif (ctype(1:3)=='int') then
        p_int = p_int+length 
        if (p_int > iiz) then
          write(*,*) 'Integer memory exceeded...'
          stop        
        endif
      elseif (ctype(1:4)=='char') then
        p_char = p_char+length 
        if (p_char > icz) then
          write(*,*) 'Character memory exceeded...'
          stop        
        endif
      elseif (ctype(1:4)=='dble') then
        p_dble = p_dble+length
        if (p_dble > idz) then
          write(*,*) 'Double precision memory exceeded...'
          stop        
        endif
      endif
!
!-----------                         
    else if  ( cmem(1:4)=='coef' ) then
      ncoef = ncoef + 1
      if (ncoef > ncoef_max) then
        write(*,*) 'Coef pointer table exceeded...'
        stop
      endif 
      coef_ptrs(ncoef)%name=cname
      coef_ptrs(ncoef)%type=ctype
      coef_ptrs(ncoef)%ptr=location
      coef_ptrs(ncoef)%length=length
!
      if (ctype(1:4)=='real') then
        p_real = p_real+length               
        if (p_real > irz) then
          write(*,*) 'Real memory exceeded...'
          stop        
        endif
      elseif (ctype(1:3)=='int') then
        p_int = p_int+length 
        if (p_int > iiz) then
          write(*,*) 'Integer memory exceeded...'
          stop        
        endif
      elseif (ctype(1:4)=='char') then
        p_char = p_char+length 
        if (p_char > icz) then
          write(*,*) 'Character memory exceeded...'
          stop        
        endif
      elseif (ctype(1:4)=='dble') then
        p_dble = p_dble+length
        if (p_dble > idz) then
          write(*,*) 'Double precision memory exceeded...'
          stop        
        endif
      endif
!
!-----------      
    else if  ( cmem(1:9)=='interface' ) then
      nint = nint + 1
      if (nint > nint_max) then
        write(*,*) 'Interface pointer table exceeded...'
        stop
      endif 
      int_ptrs(nint)%name=cname
      int_ptrs(nint)%type=ctype
      int_ptrs(nint)%ptr=location
      int_ptrs(nint)%length=length
!
      if (ctype(1:4)=='real') then
        p_real = p_real+length               
        if (p_real > irz) then
          write(*,*) 'Real memory exceeded...'
          stop        
        endif
      elseif (ctype(1:3)=='int') then
        p_int = p_int+length 
        if (p_int > iiz) then
          write(*,*) 'Integer memory exceeded...'
          stop        
        endif
      elseif (ctype(1:4)=='char') then
        p_char = p_char+length 
        if (p_char > icz) then
          write(*,*) 'Character memory exceeded...'
          stop        
        endif
      elseif (ctype(1:4)=='dble') then
        p_dble = p_dble+length
        if (p_dble > idz) then
          write(*,*) 'Double precision memory exceeded...'
          stop        
        endif
      endif    
    endif
!
    end subroutine put_mem  