Example #1
0
 /// <summary>Associate the FITS object with a given URL</summary>
 /// <param name="myURL">The URL to be associated with the FITS file.</param>
 /// <param name="compressed">Is the data compressed?</param>
 /// <exception cref="FitsException">Thrown if unable to find or open
 /// a file or URL from the string given.</exception>
 public Fits(Uri myURL, bool compressed)
 {
     InitBlock();
     try
     {
         Stream s = FitsUtil.GetURLStream(myURL.OriginalString, 0);
         StreamInit(s, compressed, false);
     }
     catch (IOException)
     {
         throw new FitsException("Unable to open input from URL:" + myURL);
     }
 }
Example #2
0
        // change suggested in .99.4 version: Added bool compressed field.
        /// <summary>Associate the FITS object with a file or URL.
        ///
        /// The string is assumed to be a URL if it begins one of the
        /// protocol strings.
        /// If the string ends in .gz it is assumed that
        /// the data is in a compressed format.
        /// All string comparisons are case insensitive.
        ///
        /// <param name="filename"> The name of the file or URL to be processed.</summary>
        /// <exception cref="FitsException"> Thrown if unable to find or open
        /// a file or URL from the string given.
        public Fits(String filename, bool compressed, FileAccess access)
        {
            InitBlock();

            //Stream inp;

            if (filename == null)
            {
                throw new FitsException("Null FITS Identifier String");
            }


            int    len = filename.Length;
            String lc  = filename.ToLower();

            // for (String protocol: urlProtocols)
            for (int i = 0; i < UrlProtocols.Length; i++)
            {
                if (lc.StartsWith(UrlProtocols[i]))
                {
                    // This seems to be a URL.
                    try
                    {
                        // change suggested in .99.5 version: Added to retrieve GZIP stream.
                        Stream s = FitsUtil.GetURLStream(filename, 0);
                        StreamInit(s, compressed, false);
                    }
                    catch (IOException e)
                    {
                        throw new FitsException("Unable to open stream from URL:" + filename + " Exception=" + e);
                    }
                    return;
                }
            }
            if (compressed)
            {
                FileInit(new FileInfo(filename), true);
            }
            else
            {
                RandomInit(new FileInfo(filename), access);
            }
        }