      subroutine annet

!!    ~ ~ ~ PURPOSE ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!!    this subroutine controls the call of the annet function
!!    Author: Arthur Hrast Essenfelder
!!    E-mail: arthur.essenfelder@unive.it
!!
!!    Version: 1.0
!!    Last update on: 07/11/2016
!!
!!    ~ ~ ~ INCOMING VARIABLES  ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!!    name           |units         |definition
!!    ----------------------------------------------------------
!!
!!    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!!
!!    ~ ~ ~ OUTGOING VARIABLES  ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!!    name           |units         |definition
!!    ----------------------------------------------------------
!!
!!    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!!
!!    ~ ~ ~ LOCAL DEFINITIONS ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!!    name           |units         |definition
!!    ----------------------------------------------------------
!!
!!    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!!
!!    ~ ~ ~ SUBROUTINES/FUNCTIONS CALLED  ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!!    name            |type          |definition
!!    ----------------------------------------------------------
!!    annet_predata   |subroutine    |prepares the input data for the annet function
!!    annet_posdata   |subroutine    |reads the output data from the annet function
!!
!!    ~ ~ ~ ~ ~ ~ END SPECIFICATIONS  ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

      !! Initial declarations
      use parm
      implicit none

      !! Declaring Variables
      character(32) :: filename, filename1, filename2
      character(4) :: subcode
      character(2024) :: command
      logical :: filecheck

      !! Preparing the input data for the ANnet model
      call annet_predata

!      !! Preparing the name of the files
!      filename = "ANnet_Simulate_Run"
!      write(subcode, '(i4)') inum1
!      write(filename1, '(a32)') trim(filename) // ".R"
!      write(filename2, '(a32)') trim("Xsim") // ".csv"
!      filename1 = trim(adjustl(filename1))
!      filename2 = trim(adjustl(filename2))

!      !! Checking if ANnet model exists
!      inquire(file=filename1, exist=filecheck)
!      if (filecheck) then
!      
!        !! If yes, calling the ANnet model
!        command = "Rscript --vanilla --default-packages='methods,&
!                   stats,utils' " // trim(adjustl(filename1))
!        command = trim(adjustl(command))
!        call EXECUTE_COMMAND_LINE(command, wait=.TRUE.)
!        
!        !! Reading the output of the ANnet model and importing to SWAT
!        call annet_posdata

!      end if

      return
      end
