Blame DAS.h

Packit a4aae4
Packit a4aae4
// -*- mode: c++; c-basic-offset:4 -*-
Packit a4aae4
Packit a4aae4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
Packit a4aae4
// Access Protocol.
Packit a4aae4
Packit a4aae4
// Copyright (c) 2002,2003 OPeNDAP, Inc.
Packit a4aae4
// Author: James Gallagher <jgallagher@opendap.org>
Packit a4aae4
//
Packit a4aae4
// This library is free software; you can redistribute it and/or
Packit a4aae4
// modify it under the terms of the GNU Lesser General Public
Packit a4aae4
// License as published by the Free Software Foundation; either
Packit a4aae4
// version 2.1 of the License, or (at your option) any later version.
Packit a4aae4
//
Packit a4aae4
// This library is distributed in the hope that it will be useful,
Packit a4aae4
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4aae4
// Lesser General Public License for more details.
Packit a4aae4
//
Packit a4aae4
// You should have received a copy of the GNU Lesser General Public
Packit a4aae4
// License along with this library; if not, write to the Free Software
Packit a4aae4
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit a4aae4
//
Packit a4aae4
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
Packit a4aae4
Packit a4aae4
// (c) COPYRIGHT URI/MIT 1994-1999
Packit a4aae4
// Please read the full copyright statement in the file COPYRIGHT_URI.
Packit a4aae4
//
Packit a4aae4
// Authors:
Packit a4aae4
//      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
Packit a4aae4
Packit a4aae4
// Using the DASVHMap class, build a parser for the DAS and add functions
Packit a4aae4
// that provide access to the variables, their attributes and values.
Packit a4aae4
//
Packit a4aae4
// jhrg 7/25/94
Packit a4aae4
Packit a4aae4
#ifndef _das_h
Packit a4aae4
#define _das_h 1
Packit a4aae4
Packit a4aae4
Packit a4aae4
#include <cstdio>
Packit a4aae4
#include <string>
Packit a4aae4
#include <iostream>
Packit a4aae4
Packit a4aae4
#ifndef _attrtable_h
Packit a4aae4
#include "AttrTable.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
using std::cout;
Packit a4aae4
Packit a4aae4
namespace libdap
Packit a4aae4
{
Packit a4aae4
Packit a4aae4
/** @brief Hold attribute data for a DAP2 dataset.
Packit a4aae4
Packit a4aae4
    The Data Attribute Structure is a set of name-value pairs used to
Packit a4aae4
    describe the data in a particular dataset. The name-value pairs are
Packit a4aae4
    called the ``attributes''. The values may be of any of the DAP2 simple
Packit a4aae4
    data types (Byte, Int16, UInt16, Int32, UInt32, Float32, Float64, String
Packit a4aae4
    and URL), and may be scalar or vector. Note that all values are actually
Packit a4aae4
    stored as String data, making the easy to read/check using a web browser.
Packit a4aae4
Packit a4aae4
    A value may also consist of a set of other name-value pairs.  This
Packit a4aae4
    makes it possible to nest collections of attributes, giving rise
Packit a4aae4
    to a hierarchy of attributes.  DAP2 uses this structure to provide
Packit a4aae4
    information about variables in a dataset.  For example, consider
Packit a4aae4
    the dataset used in the DDS example earlier.
Packit a4aae4
Packit a4aae4
    In the following example of a DAS, several of the attribute
Packit a4aae4
    collections have names corresponding to the names of variables in
Packit a4aae4
    the DDS example.  The attributes in that collection are said to
Packit a4aae4
    belong to that variable.  For example, the <tt>lat</tt> variable has an
Packit a4aae4
    attribute ``units'' of ``degrees_north''.
Packit a4aae4
Packit a4aae4
    
Packit a4aae4
    Attributes {
Packit a4aae4
        GLOBAL {
Packit a4aae4
            String title "Reynolds Optimum Interpolation (OI) SST";
Packit a4aae4
        }
Packit a4aae4
        lat {
Packit a4aae4
            String units "degrees_north";
Packit a4aae4
            String long_name "Latitude";
Packit a4aae4
            Float64 actual_range 89.5, -89.5;
Packit a4aae4
        }
Packit a4aae4
        lon {
Packit a4aae4
            String units "degrees_east";
Packit a4aae4
            String long_name "Longitude";
Packit a4aae4
            Float64 actual_range 0.5, 359.5;
Packit a4aae4
        }
Packit a4aae4
        time {
Packit a4aae4
            String units "days since 1-1-1 00:00:00";
Packit a4aae4
            String long_name "Time";
Packit a4aae4
            Float64 actual_range 726468., 729289.;
Packit a4aae4
            String delta_t "0000-00-07 00:00:00";
Packit a4aae4
        }
Packit a4aae4
        sst {
Packit a4aae4
            String long_name "Weekly Means of Sea Surface Temperature";
Packit a4aae4
            Float64 actual_range -1.8, 35.09;
Packit a4aae4
            String units "degC";
Packit a4aae4
            Float64 add_offset 0.;
Packit a4aae4
            Float64 scale_factor 0.0099999998;
Packit a4aae4
            Int32 missing_value 32767;
Packit a4aae4
        }
Packit a4aae4
    }
Packit a4aae4
    
Packit a4aae4
Packit a4aae4
    Attributes may have arbitrary names, although in most datasets it
Packit a4aae4
    is important to choose these names so a reader will know what they
Packit a4aae4
    describe.  In the above example, the ``GLOBAL'' attribute provides
Packit a4aae4
    information about the entire dataset.
Packit a4aae4
Packit a4aae4
    Data attribute information is an important part of the the data
Packit a4aae4
    provided to a DAP2 client by a server, and the DAS is how this
Packit a4aae4
    data is packaged for sending (and how it is received).
Packit a4aae4
Packit a4aae4
    The DAS class is simply a sequence of attribute tables and names.
Packit a4aae4
    It may be thought of as the top level of the attribute hierarchy.
Packit a4aae4
Packit a4aae4
    @see DDS
Packit a4aae4
    @see AttrTable */
Packit a4aae4
class DAS : public DapObj
Packit a4aae4
{
Packit a4aae4
private:
Packit a4aae4
    // The DAS support the notion of a current attribute table for a given
Packit a4aae4
    // container. Containers are used by the BES to support datasets that
Packit a4aae4
    // are built using several files (but not exactly the same way as
Packit a4aae4
    // NCML builds them.
Packit a4aae4
    AttrTable *d_container ;
Packit a4aae4
    string d_container_name ;
Packit a4aae4
Packit a4aae4
    // A DAS is a shell around an attribute table. Since tables can be nested,
Packit a4aae4
    // there is one top-level table and the attribute tables for individual
Packit a4aae4
    // variables are its children.
Packit a4aae4
    AttrTable d_attrs ;
Packit a4aae4
Packit a4aae4
    void duplicate(const DAS &src;;
Packit a4aae4
Packit a4aae4
public:
Packit a4aae4
    DAS() : DapObj(), d_container( 0 ) { }
Packit a4aae4
    DAS(const DAS &das) { duplicate(das); }
Packit a4aae4
Packit a4aae4
    virtual ~DAS() { }
Packit a4aae4
Packit a4aae4
    DAS & operator=(const DAS &rhs;;
Packit a4aae4
Packit a4aae4
    /** @brief Returns the name of the current attribute container when multiple
Packit a4aae4
     * files used to build this DAS
Packit a4aae4
     */
Packit a4aae4
    virtual string container_name() const {return d_container_name; }
Packit a4aae4
Packit a4aae4
    virtual void container_name( const string &cn ) ;
Packit a4aae4
Packit a4aae4
    /** @brief Returns the current attribute container when multiple files
Packit a4aae4
     * used to build this DAS.
Packit a4aae4
     *
Packit a4aae4
     * @return current attribute table for current container
Packit a4aae4
     */
Packit a4aae4
    virtual AttrTable *container() { return d_container; }
Packit a4aae4
Packit a4aae4
    /** @brief Returns the top most set of attributes
Packit a4aae4
     *
Packit a4aae4
     * This could be the top most variable attribute tables, or it could be
Packit a4aae4
     * the top most dataset container attribute tables, if we have multiple
Packit a4aae4
     * datasets being used to construct this DAS
Packit a4aae4
     */
Packit a4aae4
    virtual AttrTable *get_top_level_attributes() {
Packit a4aae4
		if (d_container)
Packit a4aae4
			return d_container;
Packit a4aae4
		return &d_attrs;
Packit a4aae4
	}
Packit a4aae4
Packit a4aae4
    virtual void erase() ;
Packit a4aae4
Packit a4aae4
    virtual unsigned int get_size() const ;
Packit a4aae4
Packit a4aae4
    AttrTable::Attr_iter var_begin() ;
Packit a4aae4
    AttrTable::Attr_iter var_end() ;
Packit a4aae4
Packit a4aae4
    string get_name(AttrTable::Attr_iter &i);
Packit a4aae4
    AttrTable *get_table(AttrTable::Attr_iter &i);
Packit a4aae4
Packit a4aae4
    virtual AttrTable *get_table(const string &name);
Packit a4aae4
Packit a4aae4
    virtual AttrTable *add_table(const string &name, AttrTable *at);
Packit a4aae4
Packit a4aae4
    /** Read a DAS by parsing the specified file*/
Packit a4aae4
    virtual void parse(string fname);
Packit a4aae4
    virtual void parse(int fd);
Packit a4aae4
    virtual void parse(FILE *in = stdin);
Packit a4aae4
Packit a4aae4
    /** Print the DAS */
Packit a4aae4
    virtual void print(FILE *out, bool dereference = false);
Packit a4aae4
    virtual void print(ostream &out, bool dereference = false);
Packit a4aae4
Packit a4aae4
    virtual void dump(ostream &strm) const ;
Packit a4aae4
};
Packit a4aae4
Packit a4aae4
} // namespace libdap
Packit a4aae4
Packit a4aae4
#endif // _das_h