%ADASS_PAPAER_SUBMSSION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%FITSONDOTNET.TEX -- ADASS XIII (2003) 
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
\documentclass[11pt,twoside]{article}  % Leave intact
\usepackage{adassconf}

\begin{document}

%-----------------------------------------------------------------------
%			    Paper ID Code
%-----------------------------------------------------------------------
%
\paperID{P4-16}
%%%% ID=P4-16

%-----------------------------------------------------------------------
%		            Paper Title 
%-----------------------------------------------------------------------
%
\title{Making FITS available on Dot Net and its applications}

%-----------------------------------------------------------------------
%		          Authors of Paper
%-----------------------------------------------------------------------
%
\author{Vivek \ Haridas, Tam\'as Budav\'ari, William \ O'Mullane,
	Alex \ Szalay and Ani \ Thakar}
\affil{Department of Physics and Astronomy, Johns Hopkins University, Email: haridas@pha.jhu.edu }

\author{Alberto \ Conti and Antonio \ Volpicelli}
\affil{Space Telescope Science Institute}

\author{Bill \ Pence}
\affil{NASA/GSFC}

%-----------------------------------------------------------------------
%			 Contact Information
%-----------------------------------------------------------------------
%
\contact{Vivek Haridas}
\email{haridas@pha.jhu.edu }

%-----------------------------------------------------------------------
%		      Author Index Specification
%-----------------------------------------------------------------------
%
\paindex{Haridas, V.}
\aindex{Budav\'ari, T.}     
\aindex{OMullane@O'Mullane, W.}
\aindex{Szalay, A. S.}     
\aindex{Thakar, A.}
\aindex{Conti, A.}     
\aindex{Volpicelli, A.}
\aindex{Pence, B.}

%-----------------------------------------------------------------------
%                     Author list for page header
%-----------------------------------------------------------------------
%
\authormark{Haridas et al.}

%-----------------------------------------------------------------------
%			Subject Index keywords
%-----------------------------------------------------------------------
%
\keywords{FITS, Microsoft, DotNet, library, C-Sharp, object oriented}

%-----------------------------------------------------------------------
%			       Abstract
%-----------------------------------------------------------------------
%

\begin{abstract}          % Leave intact

The Flexible Image Transport System (FITS) is a powerful and widely
adopted means of exchanging Astronomical Data. There are also a great
number of tools and libraries available on many platforms to facilitate
working with FITS.

We present the 
\htmladdnormallinkfoot{FitsLib}{http://skyservice.pha.jhu.edu/develop/FitsLib/}
, A library written to facilitate development of
astronomical data analysis tools on the Microsoft.Net Platform.  This has
been developed as a wrapper over one of the very popular and time tested
FITS libraries, CFITSIO.
Fits.Net library merges the advantages of speed and ruggedness of CFITSIO
with the language independence of the Microsoft.Net technology and a
simple Document Object Model (DOM). We believe this library will be
intuitive for .NET programmers.

We present the design and usage patterns of the library in C-Sharp. We also
discuss performance issues of the library. Finally we present a number of
applications and web services, which are currently running on this
library.

\end{abstract}

%-----------------------------------------------------------------------
%			      Main Body
%-----------------------------------------------------------------------
%

\section{Introduction}

We wished to use the CFITSIO package in developing image 
cutout services on the Microsoft's .Net Platform in the C-Sharp language.
This is a comprehensive library
and we did not feel translation was viable, C-Sharp does allow use of managed
C++.
We set out to wrap a minimal set of routines in the managed C++ programming 
environment. 

This minimal set, however, grew larger as more functionality was {\em required} in C-Sharp.
It became apparent that developing code with so many pointers and unmanaged data objects in 
 C-Sharp would prove to be prohibitive, both for development and for maintenance. This led to the 
design of an object-oriented wrapper that eased the memory and safety issues involved 
with pointers. 

Initially a minimal  package was developed which could perform reading operations 
on FITS files. Slowly more features were added until most of the popular FITS operations 
are now possible

An undercurrent of a Document Object Model like structure can be seen throughout the package. 
We felt that it would match closely with the structure of a FITS file and would be easy to 
associate with for a programmer in an Object Oriented Language such as C-Sharp.

\section{Design Overview}

One of the design decisions was to make the library Common Language Runtime compatible (CLR).
This would enable the wrapper to be used across different .Net languages such as C-Sharp, 
Visual Basic and Managed C++. 

This resulted in the whole design being done in two stages. In the first stage a CLR 
compliant interface was designed. In the second stage this interface was implemented 
by instantiating and operating on the appropriate CFITSIO data structures.

\subsection{The Interface}
\label{P4-16:sec:interface}

The interface intends to provide an intuitive Document Object Model (DOM) like layout for a 
FITS file. Features 
such as indexing, properties and polymorphism are utilized here to give a DOM 
layout for the classes involved.

The FitsFactory provides methods for creation of new interfaces to FITS files.
The Fits interface 
opens FITS files for read or write operations. There are also specific interfaces for Fits Table 
and Image units. The FitsHeader interface provides access to header information in every unit.  
FitsData is the data structure representing a cell of a Table and also the image buffers.

\subsection{The Implementation}

The implementation focuses on issues such as memory management, invoking the underlying CFITSIO routines, 
error management, implementing object-oriented data structures and maintaining CFITSIO data structures. 
Specific classes implement each of the interface classes managing the tasks mentioned above (\ref{P4-16:sec:interface}). 

CFitsTable and CFitsImage are the two major implementation classes. The CFitsTable class implements a 
major portion of the different interfaces to the Fits Table. The CFitsData class implements the FitsData 
interface by wrapping the fits table vectors and image buffers inside it.

\section{Performance Observations}

The object oriented and memory managed .Net interface is easy to use but, 
introduces a small overhead compared with direct CFITSIO usage. 

Performance testing of such interfaces is non trivial. It was observed that 
for some very large FITS files the .NET package appears to outperform the CFITSIO, 
which seems anomalous. This could be due to host of independent variants such as memory paging, 
code optimization or garbage collection  on the .Net platform. 

However, when tested over a range of different operational requirements and 
loads, some overhead can be observed.

The performance comparisons shown above 
were done between similar pieces of CFITSIO and FitsLib program code. Additionally, 
some mathematical operations were done on the data being used in the tables and images. 
This was done to minimize the effects of code optimization.
\begin{figure}
\plotone{P4-16_1.eps}
\label{P4-16:fiq.stats}
\caption{Performance Statistics}
\end{figure}

\section{Applications}
Thanks to active usage and support from a small number of developers from the 
initial stage, the tool is already employed successfully in a few applications and 
WebServices, some of which are listed below.

\subsection{Galex Summary}
The 
\htmladdnormallinkfoot{GALEX Summary page}{http://galex.stsci.edu/Tools/Explore/explore.aspx}
allows users to browse images in depth and obtain details of individual GALEX objects.

Among the information provided are the object unique identifier, 
its coordinates in the GALEX combined object catalog and 
in the individual band passes (Far UV and Near UV). 

\subsection{Catalog Archive Server - JOBS}
This is a 
\htmladdnormallinkfoot{system}{http://skyservice.pha.jhu.edu/devel/casjobs/} 
used to process queries against large astronomical databases.
It uses a system of queues and personal databases to accommodate a variety of 
different queries in a timely and efficient manner.

\subsection{CAS - Service}
This is an XML Web Services 
\htmladdnormallinkfoot{interface}{http://skyservice.pha.jhu.edu/devel/casservices/casservice.asmx} 
to the SDSS Catalog Archive Server (CAS).
It provides access to catalog data and returns the result in different formats.

\section{Summary}
FitsLib is a library meant for for astronomers and developers working on Microsoft's .Net Platform. It 
offers a DOM like layout and the convenience of a .Net language along with the speed of CFITSIO.

The latest documentation, samples, source and binary downloads are available 
from \htmladdURL{http://skyservice.pha.jhu.edu/develop/FitsLib/} .

%-----------------------------------------------------------------------
%			      References
%------Design patterns, CFITSIO, MSDN, FITS-----------------------------------------------------------------
%

\begin{references}

\reference HEASARC, CFITSIO User's Reference Guide, \\
{\small
\htmladdURL{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/cfitsio.html}
}

\reference NASA/GSFC, A User's Guide for the Flexible Image Transport System, \\
\htmladdURL{http://archive.stsci.edu/fits/users_guide/}

\reference Erich Gamma et al., Addison-Wesley Pub Co, Design Patterns, \\
\htmladdURL{http://www.awprofessional.com/titles/0-201-63361-2/}

\reference Microsoft Corporation, Microsoft Developer Network, \\
\htmladdURL{http://msdn.microsoft.com/netframework/}, \\
\htmladdURL{http://msdn.microsoft.com/vcsharp/}, \\
\htmladdURL{http://msdn.microsoft.com/visualc/}

\end{references}

\end{document}  % Leave intact

