prov_calibration <- function(recipe, data, graph, type){

  #Define Calibration parameters
  cal <- tolower(recipe$Analysis$Workflow$Calibration$method)
  archive <- read_yaml("conf/variable-dictionary.yml")

  if (cal %in% names(archive$calibration)) {
    cal.method <- archive$calibration[[cal]]$long_name
    cal.class <- paste0("cal:", archive$calibration[[cal]]$representation)
    cal.description <- archive$calibration[[cal]]$definition
  }else {
    stop("Calibration method not registered or not correctlyy defined")
  }

  if (!(cal == "qmap")) {
    comment <- "For more details, see the  CSTools documentation 
               for CST_Calibration()"
  }else{
    comment <- "For more details, see the  CSTools documentation 
                for CST_QuantileMapping()"
  }
  referenceURL <- "https://cran.r-project.org/web/packages/CSTools/CSTools.pdf"
  reference.nodename <- graph$parentnodename$parentnodename_obs

  #Define last node to which Calibration is applied
  if (type == "fcst" || type == "hcst") {
    i <- switch(type,
                "fcst" = "parentnodename_fcst",
                "hcst" = "parentnodename_hcst")
    parentnodename <- graph$parentnodename[[i]]
    graph <- graph$graph

    #Add Calibration node and vertex
    cal.nodename <- paste0("Calibration_", type)
    graph <- add_vertices(graph,
                          nv = 1,
                          name = cal.nodename,
                          label = "Calibration",
                          className = "cal:Calibration")

    graph <- add_edges(graph,
                       c(getNodeIndexbyName(graph, parentnodename),
                         getNodeIndexbyName(graph, cal.nodename)),
                       label = "cal:hadCalibration")

    #Add Calibration Method
    calmethod.nodename <- paste0("CalibrationMethod_", "all")
    graph <- add_vertices(graph,
                             nv = 1,
                             name = calmethod.nodename,
                             label = cal.method,
                             className = cal.class,
                             attr = list("dc:description" = cal.description,
                                         "dc:comment" = comment,
                                         "ds:referenceURL" = referenceURL))
    graph <- add_edges(graph,
                       c(getNodeIndexbyName(graph, cal.nodename),
                         getNodeIndexbyName(graph, calmethod.nodename)),
                       label = "cal:withCalibrationMethod")
                       
    #Add Reference node
    graph <- add_edges(graph,
                       c(getNodeIndexbyName(graph, cal.nodename),
                         getNodeIndexbyName(graph, reference.nodename)),
                       label = "cal:withReferenceData")

    return(list("graph" = graph, "parentnodename" = cal.nodename))
  }else {
    return(list("graph" = graph$graph,
                "parentnodename" = graph$parentnodename$parentnodename_obs))
  }
}