/// <summary> /// Adds a one-dimensional variable to the specified SDS object with floating point dimension data /// </summary> /// <param name="SDSObject">A reference to an SDS object</param> /// <param name="variableName">The name of the variable to create</param> /// <param name="units">Units of the data</param> /// <param name="numDimensions">The number of dimensions for the new variable</param> /// <param name="namesDimensions">A vector of names of the dimensions for the variable</param> /// <param name="missingValue">The missing value to apply to the new variable</param> /// <param name="dimension1Data">A vector of values of the first dimension</param> public void AddVariable(DataSet SDSObject, string variableName, string units, int numDimensions, string[] namesDimensions, double missingValue, float[] dimension1Data) { //If the wrong number of dimension names have been provided, then return error if (namesDimensions.Length != numDimensions) Debug.Fail("Error: you have provided the wrong number of dimension names"); //Since this overload method deals with one-dimensional variables, return an error if this is not the case if (numDimensions != 1) Debug.Fail("Error: you have provided data for the wrong number of dimensions"); //If the variable already exists in the SDS, then take no action, otherwise create new variable if (SDSObject.Variables.Contains(variableName)) { Console.WriteLine("SDS object already contains a variable with that name. Skipping..."); } else { //For each dimension, if it already exists in the SDS then take no action, otherwise create a new variable and populate it with the provided data if (SDSObject.Variables.Contains(namesDimensions[0])) { } else { SDSObject.AddVariable<float>(namesDimensions[0], dimension1Data, namesDimensions[0]); } //If the variable is the same as one of the entered dimensions, then take no action, otherwise create the new variable and populate it with missing values if (SDSObject.Variables.Contains(variableName)) { } else { //Create array of missing values of the correct dimensions double[] tempOutData = new double[dimension1Data.Length]; for (int ii = 0; ii < dimension1Data.Length; ii++) { tempOutData[ii] = missingValue; } //Add variable to SDS var testOut = SDSObject.Add<double[]>(variableName, units, missingValue, tempOutData, namesDimensions); //Metadata required by SDS testOut.Metadata["DisplayName"] = variableName; testOut.Metadata["MissingValue"] = missingValue; //Commit changes SDSObject.Commit(); } } }