R/GetEVRawPaths.R

Defines functions GetEVRawPaths

Documented in GetEVRawPaths

#' Get the names of raw data files used in the EV file from
#' which sphere target data were exported.
#'
#' @param file.list
#'   This is essentially one EV file selected by the user.
#' @return
#' Returns the full filename for the raw data files in the EV file
#' represented by "file.list".
#'
#' #' @details
#' This function is a helper function for Sphere2BeamPattern and is not called
#' on its own.



GetEVRawPaths <- function(file.list)
{
  # now a for loop to get raw data file list for each EV file in all_EV_files nested in a loop to
  # open each of the EV files in all_EV_files and then close each EV file

  # create an empty list in which to store the k data frames
  klist <- list()

  for (k in 1:length(file.list)) {
    try(
      EVFile <- EVAppObj$OpenFile(file.list[k]) #Selects the kth EV file in the list and opens it.
    )
    Sys.sleep(1)   #This slows R down to wait for Echoview.  Generally also fails without this.

    filesetName <- EVFile[["Filesets"]]$Item(0)$Name()
    try(
      fileset.loc <- EVFindFilesetByName(EVFile, filesetName)$filesetObj #select the fileset COM obj for the named fileset
    )
    nbr.of.raw.in.fileset <- fileset.loc[["DataFiles"]]$Count() # identify # of raw data files in the kth EV file/fileset
    raw.file.names <- 0 #create file.names object, will be overwritten with character vector of all the data file paths
    # loop gets file.path for each DT4 file associated with the kth EV file.
    for (j in 0:(nbr.of.raw.in.fileset - 1)) {
      raw.file.names[j + 1] <- file.path(fileset.loc[["DataFiles"]]$Item(j)$FileName())   #Loop through the j raw data files
    } # close inner loop
    # grabbing their full names and creating a character vector of the full names
    files <- data.frame(raw.file.names) # convert the character vector of file names for the kth EV file
    klist[[k]] <- files
    try(
    EVCloseFile(EVFile = EVFile) #close the EV file so you don't have a ton of EV files open.
    )
    Sys.sleep(1)
  } #Close outer loop
  EVAppObj$Quit()

  # combine all of the k data frames into one big data frame
  onebigdf <<- dplyr::bind_rows(klist)
  #return(onebigdf)
  write.csv(onebigdf, 'DT4_files_used_for_calibration.csv', row.names=FALSE)  #Save a csv file that includes the
  # the full path of the raw data files for each EV file, the full name of that EV file, and the name of the ECS file used
  # by each EV file.
}
dmwarn/Sphere2BeamPattern documentation built on Dec. 7, 2019, 12:26 a.m.