| Example 1 | UDF PROGRAMMERS MANUAL | Example 1 |
|---|
The program below will retrieve one instance of the IMAGE satellite Spin Rate converted to Rev/Min. The value returned will be that taken closest to the time: Year 1999, Day 169, Hr 00, Min 10, Sec 00. Normally the PIDF is read to determine the VIDF sensor number, and to obtain the Algorithm Steps. Doing this manually we find that the Spin Rate is defined as sensor 95 and that the algorithm to convert the raw telemetry into units consists of a single step, the application of VIDF table 13 with and operation of = (value 0).
#include < stdio.h >
#include "util_var.h"
#include "ret_codes.h"
#include "user_defs.h"
#include "libbase_udf.h"
int main ()
{
struct idf_data *ExDa;
void *UDF;
ReaL_4 RetData[5];
u_ByTe_4 Key;
ByTe_4 Fill = 0;
ByTe_1 *P = "IMAGE", *M = "IMAGE-1", *E = "CIDP";
ByTe_1 *I = "CIDP", *SI = "IMCLORHK";
ByTe_1 *Ext = "", CFill = 0;
ByTe_1 S = 0, FwD = 1, FullCol = 0;
u_ByTe_2 V;
ByTe_4 Bs, Bns = 0, Es, Ens;
ByTe_2 By = 1999, Bd = 169, Ey = 1999, Ed = 169;
ByTe_2 Hr = 00, Mn = 10, Ss = 0;
ByTe_2 rV, SeN = 95, MCol = 0, Ops[1];
ByTe_1 NAS = 1, Tbls[1];
/********************************************************************
Put beginning time and ending time into seconds of day. Since
only one sample is being retrieved the ending time can be
anything greater than the beginning. Since we really don't know
the closest time to what is requested, I just set the ending
time to 1 hour beyond the beginning time.
********************************************************************/
Bs = 3600 * Hr + 60 * Mn + Ss;
Es = 3600 * (Hr + 1) + 60 * Mn + Ss;
/********************************************************************
Set up the table and operation used in conversion to rev/min
********************************************************************/
Tbls[0] = 13;
Ops[0] = 0;
/********************************************************************
Initialize the UDF structures and get a version number
********************************************************************/
init_udf();
get_version_number(&V);
/********************************************************************
Create one instance of a UDF data block. If there is an error
then give error code and exit. If no error then set up a
structure pointer into the data block.
********************************************************************/
rV = create_idf_data_structure(&UDF);
if (rV != ALL_OKAY)
{
printf ("Encountered error %d in create_idf_data_structure\n", rV);
exit (-1);
}
ExDa = (struct idf_data *) UDF;
/********************************************************************
Get the data key for the UDF containing the spin rate. If there
is an error then give error code and exit.
********************************************************************/
rV = get_data_key(P, M, E, I, SI, &Key);
if (rV != ALL_OKAY)
{
printf ("Encountered error %d in get_data_key\n", rV);
exit (-1);
}
/********************************************************************
Open the UDF data file containing the beginning time. If there
is an error then give error code and exit.
********************************************************************/
rV = file_open(Key, Ext, V, By, Bd, Bs, Bns, Ey, Ed, Es, Ens, S);
if (rV != ALL_OKAY)
{
printf ("Encountered error %d in file_open\n", rV);
exit (-1);
}
/********************************************************************
Position the file pointer at the starting time in the UDF data
file. If there is an error then give error code and exit.
********************************************************************/
rV = file_pos(Key, Ext, V, UDF, By, Bd, Bs, Bns, Ey, Ed, Es, Ens);
if (rV != ALL_OKAY)
{
printf ("Encountered error %d in file_pos\n", rV);
exit (-1);
}
/********************************************************************
Loop over read_routine ending only when either we get return code
which is not a NO SENSOR DATA FOUND. On exit report the any
non ALL_OKAY exit status only if no data was found.
********************************************************************/
while ((rV = read_drec(Key, Ext, V, UDF, SeN, MCol, FwD,
FullCol)) == DREC_NO_SENSOR);
if (rV != ALL_OKAY && !ExDa->filled_data)
{
printf ("Encountered error %d in read_drec\n", rV);
exit (-1);
}
/********************************************************************
Check if data was acquired. If so then set up the algorithm table
and operation arrays and convert the raw UDF data to rev/min. If
any errors occur in the conversion process report these and exit
program. If no data could be found then report that.
********************************************************************/
if (ExDa->filled_data)
{
rV = convert_to_units(Key, Ext, V, UDF, SENSOR, 0, NAS, Tbls,
Ops, RetData, CFill, Fill);
if (rV != ALL_OKAY)
{
printf ("Encountered error %d in convert_to_units\n", rV);
exit (-1);
}
printf ("Satellite Spin Rate is %.3f Rev/Minute\n",RetData[0]);
}
else
printf ("No Satellite Spin Rate available\n");
exit(0);
}
| UDF V2.2 | July 31, 1999 | UDF V2.2 |
|---|