Promotion of data is an easily added feature of SDDAS software and this library is the way to do it. It is by no means a necessary part of any SDDAS software.
Promotion of data refers to an application retrieving the data from a remote archive server so one may analyze your data without having to retrieve the data manually.
The advantages of doing it this way is that you only retrieve the data you need. If, for instance, one wishes to analyze a bit of UARS data from 1993, you do not need to request the entire dataset of UARS, only the hour in which you are interested.
First, decide whether you wish to use the C or C++ interface. The C++ interface is more powerful (i.e. more things can be controlled) or the simpler C interface. Regardless of which interface you choose, you must link with libstdc++ if you are using gcc.
Furthermore, this library makes use of our typedefs so you will need to include SDDAS_types.h if you do not already. It will be automatically included when you include either libPromote.h or Promote.h.
Another thing to remember is you may only promote a single time range per Promote stucture whether you use the C or C++ interface. If you want to promote multiple time ranges, you must create multiple Promote * for C++ and multiple void * structures for the C interface.
Each particular interface is geared toward a different type of user. If you are familiar with C++, the C++ interface should not be anymore complex than the C one. The C one; however, is a very simple interface meant to be used with a variety of programs/programmer levels. It involves only four routines which are easily utilized in any program. The C++ makes the programmer do a little more work, but allows one to have better control over what happens. For instance, with the C++ interface the automatic meta data promote may be turned on or off, as well as multiple interfaces to similar routines.
The C interface to libPromote is very simple and is based on a data key and
a time. To use the C interface, add an "#include "libPromote.h"" in your
source file. The routines are as follows:
The first six fields are the beginning and ending times. The sequence is as
follows:
Finally, the last parameter enables an X status window to appear. Send
a sTrue to enable this window, or sFalse to disable it.
The value returned is a pointer to a opaque structure. You may not do anything
with this pointer except send it to one of the five following routines.
This structure must be freed with pro_FreePromote after being called.
.
This routine will determine whether or not you need to promote data based on
the data source sent in and the time specified in the pro_InitPromote. It
will return sTrue if you need to promote and sFalse if you do not.
This routine requires the pointer returned by pro_InitPromote as input and
will simply promote all off-line data that you requested in the
pro_InitPromote. It returns sTrue for success and sFalse for failure.
This routine requires the void pointer returned by pro_InitPromote as input and
will simply demote (delete!) all on-line data that you requested in the
pro_InitPromote. It returns sTrue for success and sFalse for failure.
For this routine to work, pro_PromoteAll had to be called previously. You
may not call pro_DemoteAll without calling pro_PromoteAll first.
To use the C++ interface, add "#include "Promote.h"." This will initialize
the Promote object. The more complex C++ interface is as follows:
There are multiple ways to set the time depending on your needs and the data
that you have available to you. The SetBTime is for the beginning time and the
SetETime is for the ending time.
This first way requires the year, the day, and the millisecond of the day for
data access.
Note: You need call only one set of routines (or you may mix/match them although
this is not recommended).
There are two ways of specifying a source(s) using AddSource. Either send in the data key,
or send in the string names (i.e. "UARS", "UARS-1", "PEM", "HEPS", "HPSA").
Also, this routine is "adding" sources to a list so you may add as many sources to
this list as you like by calling this routine multiple times with different data keys
or string names.
BuildDBList is the routine needed to build a list of items to promote. You must
call this routine after setting the time and the sources. The first parameter
is one of the following flags or a combination of the following created by OR'ing
their values together:
The second parameter is one of the following flags and refers to what "state" of data
to build a list :
The third parameter is optional and specifies the maximum number of entries to promote.
The default is 1000 which is a pretty sizable number. Anything more than that and you
might find a better way to get the data; however, this parameter can be changed.
Return Values:
PromoteList will promote the list generated by BuildDBList; thus, it must be
called after all the previous routines have been called. It will promote all the
off-line data that was generated by the BuildDBList call. PromoteList will
return a sTrue on success and an sFalse on failure.
After the data has been promoted and you have finished using it, you may demote
(delete!) all the data which has been promoted. PromoteList will return a
sTrue on success and a sFalse on failure.
The parameter on the DemoteAllData signifies whether the data that is to be demoted
is to be deleted regardless of whether or not the data was promoted. The default is
sFalse which means the data will only be deleted if it was previously promoted.
Sending an sTrue means delete the data regardless. This can be dangerous so be
careful!
The following routines are all completely optional and need to be called only if
necessary.
SetXStatus can turn on or off the X promotion status window. The default is OFF.
Send SetXStatus either ON or OFF as input.
SetAutoPromoteMeta will make the promote automatically promote some meta data
if it does not exist. The default is to promote the meta data. Send
SetAutoPromoteMeta either sTrue to promote the meta data or sFalse to not promote
it.
This code demonstrates promoting some data for UARS HPSA data from 1991.
void *pro_InitPromote (SDDAS_INT, SDDAS_INT, SDDAS_LONG,
SDDAS_INT, SDDAS_INT, SDDAS_LONG,
SDDAS_BOOL);
void pro_AddSource (void *, SDDAS_ULONG);
The first parameter is the opaque data structure created by pro_InitPromote.
The next parameter is the data key representing the source. This can be had in
a number of ways. You can use either get_data_key (see
IDFS Programmers Manual) or if you use either of our Source GUIs, they
both return the data_key to you.
SDDAS_BOOL pro_NeedToPromote (void *);
SDDAS_BOOL pro_PromoteAll (void *);
SDDAS_BOOL pro_DemoteAll (void *);
void pro_FreePromote (void *);
This simply frees the structure that was generated by pro_InitPromote.
You may call this routine anytime after pro_InitPromote provided
pro_InitPromote did not return a NULL. Once you call this routine,
you may no longer call pro_PromoteAll or pro_DemoteAll.
C++ Interface
Promote ();
virtual ~Promote ();
The usual constructor/destructor. These will initialize/free the data structure
so the compiler will call these automatically.
void SetBTime (SDDAS_INT, SDDAS_INT, SDDAS_LONG);
void SetETime (SDDAS_INT, SDDAS_INT, SDDAS_LONG);
void SetBTime (SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_LONG = 0);
void SetETime (SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_LONG = 0);
The second way requires the year, day, hour, minute, second, and millisecond
of the day for the data you wish to access. You are encouraged to make use
of this routine rather than making the computation yourself. The last parameter
is for millisecond and is an optional parameter. If you do not specify a
millisecond to use, zero will be used.
void AddSource (SDDAS_ULONG);
void AddSource (char *, char *, char *, char *, char *);
SDDAS_INT BuildDBList (int, StatusType, int = 1000);
SDDAS_BOOL PromoteList ();
SDDAS_BOOL DemoteAllData (SDDAS_BOOL);
void SetXStatus (XStatusType);
void SetAutoPromoteMeta (SDDAS_BOOL);
Sample Code
C Code
#include
C++ Code
#include "Promote.h"
int main ()
{
Promote *P;
CfgInit (); // Initialize CFG files
P = new Promote ();
P->SetXStatus (ON); // default is off
P->AddSource ("UARS", "UARS-1", "PEM", "HEPS", "HPSA");
P->SetBTime (1993, 191, 8, 0, 0);
P->SetETime (1993, 191, 14, 0, 0);
if (P->BuildDBList (_I_FILE_ | _HD_FILE_ | _P_FILE_, OFFLINE) > 0) {
P->PromoteList ();
// do something with data
P->DemoteAllData ();
delete P;
}
CfgTerm ();
exit (0);
}