Subject: a data format swiss army knife program in C++?

From: [email-masked] (Edward Hartnett)
Date: 21 Dec 1994 15:27:28 GMT

(I'm posting this to the c++ group and the scientific data format
group). 

I've been working with a lot of data formats recently, including HDF,
and I recently had an interesting thought.

It would be possible to treat a gridded data set of N dimensions as a
C++ object, which could have different methods to write out different
format files (i.e. HDF, grib, etc.).

I arrived at this conslusion by thinking about how I write format
conversion programs. When I needed to convert between a local format
(called pheonix) and HDF, first I put together C data structures for
each file, then I wrote a library of functions for each format which
would read and write the data. After al that it wasn't too hard to
make first a reader from both formats, then a program that read in one
and wrote out the other.

I recently realized that if I had used the same data structures for
both formats (indeed, for all my gridded data format), my job would
simplify to writing read function to get an new file into that data
stucture, and functions to write from that data structure to a
specific format.

Before I go any further I thought I'd post these thoughts and see if
anyone out there has done this sort of thing.
--
Edward Hartnett - [email-masked] - (301) 286-2396
Code 910.3, NASA/GSFC, Greenbelt MD, 20771 - fax: 286-1754

IAGO: How poor are they that have not patience!  What wound did ever
heal but by degrees?  Thou know'st we work by wit, and not by
witchcraft; And wit depends on dilatory time.

---

From: [email-masked] (Daniel Stephens)
Date: 21 Dec 1994 18:45:25 GMT

>   format files (i.e. HDF, grib, etc.).

  I've used a similar method several times when converting between varying
data formats.. However I tend to find that my 'data representation' class gets
way too cluttered when it's loaded with file format conversion routines.

  My preferred method of doing things is to have a central class which holds
the concept (ie.. a gridded data set) and then have a set of classes which
provide the various conversions I require (ie. HDF_Convertor, grib_Convertor)

  If you're really lucky then the conversion routines will share some similar
properties which you can use to generate a fairly solid interface between the
data representation and the conversion routines, and then make an abstract
base class (ie. Base_Convertor) which the other conversion classes derive from.

  That way you can create things like::

  	class Gridded_Data {
	   	public:

    		Gridded_Data(Base_Convertor &in_conv);

		int Output(Base_Convertor &out_conv);
	};

  Of course, you may prefer to have two base convertor classes such as
Base_Input_Convertor and Base_Output_Convertor, I guess that all depends on
personal preference, and whether the two actually share any common operations
or not... (I'm not at all familiar with any of the formats mentioned above so
I don't know if they do or not)..

Just my $0.02

Daniel.
--
/-           Daniel Stephens            ---------------------#----------------\
| email [email-masked]'                    #   # # #         |
| .signature still under development 8-)                    ### ##  # # 'LIFE'|
\-----------------------------------------------                 #  ##       -/