Example #1
0
        public static string RedSeaFilenames(int step, int?substep, int?member, RedSea.Variable var)
        {
            string dir = locDataFolder + (step + 1);

            // Look for raw file.
            //if (substep != null || var == RedSea.Variable.VELOCITY_Z)
            //{
            substep = substep ?? 0;
            dir     = locDataFolderSubstep + (step + 1);

            // Not the W case: go into the inner folder.
            if (substep != null)
            {
                dir += locFolderName + member + '/';
            }

            //string filename = RedSea.GetShortName(var) + ".0*" + (substep + 1) + ".data_scaled_end";
            Console.WriteLine("Step {0}, Substep {1}", step, substep);
            int    numZeros = 10 - (substep == 0 ? 1 : (int)(Math.Log10((int)substep * 9) + 1));
            string filename = RedSea.GetShortName(var) + "." + new string('0', numZeros) + (substep * 9) + ".data";

            Console.WriteLine(filename);
            string[] rawDirs = Directory.GetFiles(dir, filename, SearchOption.TopDirectoryOnly);
            Debug.Assert(rawDirs.Length == 1, "Exactly one matching file expected!");

            return(rawDirs[0]);
            //}
            //else
            //{
            //    dir += locFileName;
            //    return dir;
            //}
        }
Example #2
0
        /// <summary>
        /// Create a Loader object and open a NetCDF file.
        /// </summary>
        /// <param name="file">Path of the file.</param>
        //public LoaderRaw(string file)
        //{
        //    Debug.Assert(_numOpenFiles == 0, "Another file is still open!");
        //    _fileName = file;
        //    // nDims = [3];
        //    // dimList = [
        //    //   500, 1, 500,
        //    //   500, 1, 500,
        //    //    50, 1, 50
        //    // ];
        //    // dataprec = ['float32'];
        //    // nrecords = [1];
        //    // timeStepNumber = [108];
        //    //string metadata = System.IO.File.ReadAllText(@file+".meta");
        //    //int index = metadata.IndexOf("nDims = [   ") + ("nDims = [   ").Length;
        //    //if (index != -1)
        //    //{
        //    //    int index2 = this.Message.IndexOf(",", index);
        //    //    if (index2 == -1)
        //    //    {
        //    //        index2 = this.Message.Length;
        //    //    }
        //    //}
        //    _dimIDs = new int[] { (int)RedSea.Variable.GRID_X, (int)RedSea.Variable.GRID_Y, (int)RedSea.Variable.GRID_Z };
        //    _dimLengths = new int[] { 500, 500, 50 };
        //}
        //protected int _step;
        //protected int _substep;
        public LoaderRaw(RedSea.Variable var = RedSea.Variable.VELOCITY_X)
        {
            Debug.Assert(_numOpenFiles == 0, "Another file is still open!");

            _dimIDs = (int[])_dimensionIDs.Clone(); // new int[] { (int)RedSea.Dimension.GRID_X, (int)RedSea.Dimension.GRID_Y, (int)RedSea.Dimension.GRID_Z, (int)RedSea.Dimension.MEMBER, (int)RedSea.Dimension.TIME, (int)RedSea.Dimension.SUBTIME };

            _dimLengths = new int[] { 500, 500, 50, 50, RedSea.Singleton.NumSteps, RedSea.Singleton.NumSubsteps };

            Range = new SliceRangeRaw();
            Range.CorrectEndian = false;
        }
Example #3
0
            public SliceRange(LoaderNCF file, RedSea.Variable var)
                : base()
            {
                // Query number of dimensions of variable.
                int numDims;
                NetCDF.ResultCode ncState = NetCDF.nc_inq_varndims(file.GetID(), (int)var, out numDims);
                Debug.Assert(ncState == NetCDF.ResultCode.NC_NOERR);
                int[] dimIDs = new int[numDims];

                // Query relevant dimensions.
                ncState = NetCDF.nc_inq_vardimid(file.GetID(), (int)var, dimIDs);
                Debug.Assert(ncState == NetCDF.ResultCode.NC_NOERR);

                Initialize(dimIDs, var);
            }
Example #4
0
 public SliceRange(int[] dims, RedSea.Variable var)
 {
     Initialize(dims, var);
 }
Example #5
0
            protected void Initialize(int[] dims, RedSea.Variable var)
            {
                _var = var;

                int numDims = dims.Length;

                _presentDims = new RedSea.Dimension[numDims];
                for (int i = 0; i < numDims; ++i)
                    _presentDims[i] = (RedSea.Dimension)dims[i];
                _dimOffsets = new int[numDims];
                _dimLengths = new int[numDims];

                // Fill arrays.
                for (int dim = 0; dim < numDims; ++dim)
                {
                    // Dimensions in correct order.
                    _presentDims[dim] = (RedSea.Dimension)dims[dim];

                    // "Activate" all dimensions.
                    _dimOffsets[dim] = -1;
                    _dimLengths[dim] = -1;
                }
            }
Example #6
0
 public void SetVariable(RedSea.Variable value)
 {
     _var = value;
 }
Example #7
0
            public void SetToComplete(RedSea.Dimension dim)
            {
                // Search for position of dimension in present dimensions.
                int dimPos = -1;
                for (int pos = 0; pos < _presentDims.Length; ++pos)
                {
                    if (_presentDims[pos] == dim)
                    {
                        dimPos = pos;
                        break;
                    }
                }

                // Dimension found?
                Debug.Assert(dimPos != -1, "Dimension not present, cannot be set!");

                _dimOffsets[dimPos] = -1;
            }
Example #8
0
            /// <summary>
            /// Only include this slice of the data in this dimension.
            /// </summary>
            /// <param name="dim"></param>
            /// <param name="slice"></param>
            public void SetMember(RedSea.Dimension dim, int slice)
            {
                // Search for position of dimension in present dimensions.
                int dimPos = -1;
                for (int pos = 0; pos < _presentDims.Length; ++pos)
                {
                    if (_presentDims[pos] == dim)
                    {
                        dimPos = pos;
                        break;
                    }
                }

                // Dimension found?
                Debug.Assert(dimPos != -1, "Dimension not present, cannot be set!");

                _dimOffsets[dimPos] = slice;
                // We only chose one element.
                _dimLengths[dimPos] = 1;
            }
Example #9
0
        //        string locWFileName = ".0000000108.data";
        /// <summary>
        /// Loads the field using either 
        /// </summary>
        /// <param name="step"></param>
        /// <param name="substep"></param>
        /// <param name="var"></param>
        /// <returns>Should the NetCDF loader be used?</returns>
        public static Loader RedSeaLoader(int step, int? substep, int? member, RedSea.Variable var)
        {
            string dir = RedSea.Singleton.GetFilename(step, substep, member, var);

            // Look for raw file.
            if (substep != null || var == RedSea.Variable.VELOCITY_Z)
            {
                var loader = new LoaderRaw(var);
                loader.Range.SetMember(RedSea.Dimension.TIME, step);
                loader.Range.SetMember(RedSea.Dimension.SUBTIME, substep??0);
                loader.Range.SetMember(RedSea.Dimension.MEMBER, member??0);
                return loader;
            }
            else
            {
                return new LoaderNCF(dir);
            }
        }
Example #10
0
        public static string RedSeaFilenames(int step, int? substep, int? member, RedSea.Variable var)
        {
            string dir = locDataFolder + (step + 1);

            // Look for raw file.
            //if (substep != null || var == RedSea.Variable.VELOCITY_Z)
            //{
            substep = substep ?? 0;
            dir = locDataFolderSubstep + (step + 1);

            // Not the W case: go into the inner folder.
            if (substep != null)
                dir += locFolderName + member + '/';

            //string filename = RedSea.GetShortName(var) + ".0*" + (substep + 1) + ".data_scaled_end";
            Console.WriteLine("Step {0}, Substep {1}", step, substep);
            int numZeros = 10 - (substep == 0 ? 1 : (int)(Math.Log10((int)substep * 9) + 1));
            string filename = RedSea.GetShortName(var) + "." + new string('0', numZeros) + (substep * 9) + ".data";
            Console.WriteLine(filename);
            string[] rawDirs = Directory.GetFiles(dir, filename, SearchOption.TopDirectoryOnly);
            Debug.Assert(rawDirs.Length == 1, "Exactly one matching file expected!");

            return rawDirs[0];
            //}
            //else
            //{
            //    dir += locFileName;
            //    return dir;
            //}
        }
Example #11
0
 public SliceRangeRaw(RedSea.Variable var = RedSea.Variable.VELOCITY_X)
     : base(_dimensionIDs, var)
 {
     CorrectEndian = false;
     SetMember(RedSea.Dimension.MEMBER, 0);
     SetMember(RedSea.Dimension.GRID_Z, 0);
 }
Example #12
0
 public ScalarField LoadFieldSlice(RedSea.Variable var)
 {
     Range.SetVariable(var);
     return LoadFieldSlice(Range);
 }