gsheetsCode.js
/**
* Adds a species to the decompoosition.
*
* @customfunction
*/
Adds a species to the decompoosition.
Adds a species to the decompoosition .
function addSpeciesToDecomp(Species, decompHeader){
  try{
    var outputArray = []  ;
    var numOfPredictiveGroups = 31;
    var sum = 0;
    var group1Index = decompHeader[0][1];
    var pDataArray = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("PData_Properties").getValues();
    for(var i = group1Index; i < numOfPredictiveGroups + group1Index; i++){
      if(typeof(Species[0][0].valueOf()) === "number"){
        if(pDataArray[Species[0][0]][i].toString === "" || typeof(pDataArray[Species[0][0]][i]) === null){        
          outputArray.push(0)
        }else{
          if(Number(pDataArray[Species[0][0]][i]) === NaN){
            myErrorMsg = "Some decomposition values are not numeric.";
            throw new Error("Function name: " + fcnName + ", " + myErrorMsg);
          }else{ 
            outputArray.push(Number(pDataArray[Species[0][0]][i]));
            sum = sum + Number(pDataArray[Species[0][0]][i])
          }
        }
      }else{
        outputArray.push(0)
      }
    }
    if(sum !== 0){
      for(var i = 0; i < numOfPredictiveGroups; i++){            
        outputArray[i] = outputArray[i]/sum;
      }
    };
    return outputArray;
  }catch(myErrorHandler){
    return myErrorHandler.message;
  }
}
function addSpeciesToDecomp ( Species , decompHeader ) { try { var outputArray = [ ] ; var numOfPredictiveGroups = 31 ; var sum = 0 ; var group1Index = decompHeader [ 0 ] [ 1 ] ; var pDataArray = SpreadsheetApp . getActiveSpreadsheet ( ) . getRangeByName ( "PData_Properties" ) . getValues ( ) ; for ( var i = group1Index ; i < numOfPredictiveGroups + group1Index ; i ++ ) { if ( typeof ( Species [ 0 ] [ 0 ] . valueOf ( ) ) === "number" ) { if ( pDataArray [ Species [ 0 ] [ 0 ] ] [ i ] . toString === "" || typeof ( pDataArray [ Species [ 0 ] [ 0 ] ] [ i ] ) === null ) { outputArray . push ( 0 ) } else { if ( Number ( pDataArray [ Species [ 0 ] [ 0 ] ] [ i ] ) === NaN ) { myErrorMsg = "Some decomposition values are not numeric." ; throw new Error ( "Function name: " + fcnName + ", " + myErrorMsg ) ; } else { outputArray . push ( Number ( pDataArray [ Species [ 0 ] [ 0 ] ] [ i ] ) ) ; sum = sum + Number ( pDataArray [ Species [ 0 ] [ 0 ] ] [ i ] ) } } } else { outputArray . push ( 0 ) } } if ( sum !== 0 ) { for ( var i = 0 ; i < numOfPredictiveGroups ; i ++ ) { outputArray [ i ] = outputArray [ i ] / sum ; } } ; return outputArray ; } catch ( myErrorHandler ) { return myErrorHandler . message ; } }
Adds a species to the decompoosition.
Adds a species to the decompoosition .