prov_Indices <- function(recipe, graph) {
  #Indices metadata definitions
  index_name <- names(recipe$Analysis$Workflow$Indices)
  parentnodename_fcst <- graph$parentnodename$parentnodename_fcst
  parentnodename_hcst <- graph$parentnodename$parentnodename_hcst
  parentnodename_obs <- graph$parentnodename$parentnodename_obs
  i <- 0
  graph <- graph$graph

  nodenames <- list()
  indexnodenames <- list()

  for (index in index_name){
    i <- i + 1
    #Match METACLIP class with Index
    class <- switch(index,
                    "NAO" = "ds:NAO",
                    "Nino1+2" = "ds:Nino1plus2",
                    "Nino3" = "ds:Nino3",
                    "Nino3.4" = "ds:Nino3_4",
                    "Nino4" = "ds:Nino4")
    
    #Climate Index type node
    if (index != "NAO"){
      index.nodename <- class
    }else {
      index.nodename <- paste0("ClimateIndex_", i)
    }

    graph <- add_vertices(graph,
                          nv = 1,
                          name = index.nodename,
                          label = index,
                          className = class)

    indexnodenames <- append(indexnodenames, index.nodename)

    for (parentnodename in c(parentnodename_hcst, parentnodename_obs)) {
      type <- strsplit(parentnodename, "_")[[1]][[2]]
      climin.nodename <- paste0("ClimateIndex_", type, "_", i)
      graph <- add_vertices(graph,
                            nv = 1,
                            name = climin.nodename,
                            label = "Climate Index Calculation",
                            className = "ds:ClimateIndexCalculation")

      graph <- add_edges(graph,
                         c(getNodeIndexbyName(graph, parentnodename),
                           getNodeIndexbyName(graph, climin.nodename)),
                         label = "ds:hadClimateIndexCalculation")

      graph <- add_edges(graph,
                         c(getNodeIndexbyName(graph, climin.nodename),
                           getNodeIndexbyName(graph, index.nodename)),
                         label = "ds:withClimateIndex")
                         
      nodenames <- append(nodenames, climin.nodename)
      
    }
  }
  #Command Call and output definition
  if (!is.null(data$fcst)) {
    graph <- prov_Command(graph, package = "Indices",
                                version = "2.0.0",
                                fun = "modules/Indices/Indices.R",
                                arg.list =
                                  list(
                                       "Recipe",
                                       "Data"),
                                origin.node.name =
                                  nodenames)

    graph <- list("graph" = graph,
                  "parentnodename" =
                    list(
                         "parentnodename_fcst" = parentnodename_fcst,
                         "parentnodename_hcst" = parentnodename_hcst,
                         "parentnodename_obs" = parentnodename_obs,
                         "indicesnodenames" = nodenames))

  } else {
    graph <- prov_Command(graph, package = "Indices",
                                version = "2.0.0",
                                fun = "modules/Indices/Indices.R",
                                arg.list =
                                  list(
                                       "Recipe",
                                       "Data"),
                                origin.node.name =
                                  nodenames)
    graph <- list("graph" = graph,
                  "parentnodename" =
                    list(
                         "parentnodename_hcst" = parentnodename_hcst,
                         "parentnodename_obs" = parentnodename_obs,
                         "indicesnodenames" = nodenames))
  }

  message("INFO  ", "[", Sys.time(), "]",
          "Provenance correctly generated for the Indices module")

  #Name of the generated JSON according to recipe values
  main_dir <- paste0(recipe$Run$output_dir, "/outputs", "/provenance/")
  recipe_model <- paste0("sys-",
                         gsub('\\.', '', recipe$Analysis$Datasets$System$name))
  recipe_split <- paste0("_ref-", recipe$Analysis$Datasets$Reference$name,
                         "_var-", recipe$Analysis$Variables$name,
                         "_reg-", recipe$Analysis$Region$name,
                         "_sdate-", recipe$Analysis$Time$sdate)

  json_name <- paste0("main_provenance", "_", recipe_model, recipe_split)

  #Convert from igraph to JSON format and store in the output directory
  graph2json(graph$graph, output.file = paste0(main_dir,
                                               json_name,  ".json"))

  return(graph)
}
