Template:CMI Example go Fortran

From CSDMS
  type(edu_csdms_tools_TemplateFiles_t) :: template
  type(edu_csdms_models_LTRANS_wrap) :: dp
  character (len=2048) :: input_dir
  character (len=2048) :: isStandalone
  integer :: ng, seconds, stepT

  double precision :: days_dbl, time_interval

  ! As the execution is in the go method this component is the Driver
  dp%d_private_data%isDriver = .TRUE.
  print *, "LTRANS_CMI> LTRANS status: Driver"
  call flush()
  call edu_csdms_models_LTRANS__get_data_m(self, dp)

  call getString (dp%d_private_data%userinput, "/LTRANS/Input/Dir", ".", input_dir, exception)
  call getInt (dp%d_private_data%userinput, "/LTRANS/Input/Var/dt", 1, dt, exception)
  call getString (dp%d_private_data%userinput, "/LTRANS/Input/Var/isStandalone", "", isStandalone, exception)

  !TODO: For some reason getDouble not working, changing to getInteger (For testing)
  call getDouble (dp%d_private_data%userinput, "/LTRANS/Input/Var/days", 1.0D0, days_dbl, exception)
  !call getInt (dp%d_private_data%userinput, "/LTRANS/Input/Var/days", 1, days, exception)
  days = days_dbl
  print *, "LTRANS_CMI> dt: ", dt, " days: ", days
  call flush()

  if (input_dir=="GUI") then
    print *, "LTRANS_CMI> Input from User Input"
    call new (template, exception)
    print *, "LTRANS_CMI> Creating output file"
    ! If ltrans is coupled use a different input file template
    if(isStandalone == 'FALSE') then
        print *, 'Is project runing in standalone mode: ', isStandalone
        call add_file (template, "LTRANS_coupled.data.in", "LTRANS.data", exception)
        !call add_file (template, "LTRANS_grid.data.in", "GRID.data", exception)
        call substitute (template, dp%d_private_data%userinput, "/LTRANS/Input/Var/", ".", exception);
    else
        call add_file (template, "LTRANS.data.in", "LTRANS.data", exception)
        !call add_file (template, "LTRANS_grid.data.in", "GRID.data", exception)
        call substitute (template, dp%d_private_data%userinput, "/LTRANS/Input/Var/", ".", exception);
    end if
  else
    print *, "LTRANS_CMI> Input from File"
    print *, 'LTRANS_CMI> Copying input file to working directory: ', input_dir
    call system("cp " // input_dir // " .")
  end if

  if(trim(isStandalone) == 'FALSE') then
    print *, 'LTRANS_CMI> Getting the component ready, running as a coupled component'
    call LTR_CMI_initializev31n7eesph_mi(self, "NULL", retval, exception)

    !days*24*60*60 = total number of seconds to run the model
    !divide that by dt to get the number of external time steps
    seconds = days*DBLE(24)*DBLE(60)*DBLE(60) !Total seconds to run model
    stepT   = int(seconds/dt)                 !number of external time steps
    print *, 'LTRANS_CMI> Total seconds to run model: ', seconds
    print *, 'LTRANS_CMI> Number of external time step: ', stepT
    print *, 'Time step: '
    print *, real(p)
    do p=1,stepT
        time_interval=real(p)
        call LTRANS_CMI_run4nqryolxalh_xn_mi(self, time_interval, retval, exception)
    enddo
    call flush()
    print *, "LTRANS_cmi> Run finished. Finalizing model..."
    call LTRAN_CMI_finalizehz7pezx1ae_mi(self, retval, exception)
  else
    print *, 'ltrans cmi> Running as a standalone component'
    call run_LTRANS()
  end if
  print *, 'LTRANS_CMI> Done.'