Skip to content
Snippets Groups Projects
formatCheckParameterCd.r 1.22 KiB
Newer Older
  • Learn to ignore specific revisions
  • Laura A DeCicco's avatar
    Laura A DeCicco committed
    formatCheckParameterCd <- function(ParameterCd, interactive=TRUE){     #checks for a 5 digit number
    
      if (nchar(ParameterCd) < 5){
        
        padVariable <- function(x,padTo){
          numDigits <- nchar(x)
          if (padTo != numDigits){
            leadingZeros <- paste(rep("0",(padTo-numDigits)),collapse="",sep="")
            x <- paste(leadingZeros,x,sep="")
          }
          return(x)
        }
        
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
        if (interactive){
          cat("Most USGS parameter codes are 5 digits long, you entered a ", nchar(ParameterCd), "digit number = ", ParameterCd , ".\n")
    
          
          ParameterCd <- padVariable(ParameterCd,5)
          cat("The following parameter code will be used instead:",ParameterCd,"\n")
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          cat("If you would like to change the parameter code, enter it here (no quotes), otherwise hit return:\n")
          tempParameterCd <- readline()
          if (nzchar(tempParameterCd)) ParameterCd <- tempParameterCd
        } else {
    
          tempText <- padVariable(ParameterCd,5)
          warningMessage <- paste("Most USGS parameter codes are 5 digits long, you entered ", 
                                  ParameterCd , ".\n",tempText," will be used instead", sep="")
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          warning(warningMessage)
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
        }
      }
      return(ParameterCd)
    }