| Example 2 | UDF PROGRAMMERS MANUAL | Example 2 |
|---|
This program is similar to that given in Example1 with the exception that the retrieved data has a vector source. With a vector source both scan index and the measurement array are generally dealt with. The program uses the vector length to establish a block of memory where the converted data will be stored. Note that even though all of the data in this example are being returned in their raw state (NAS is 0), a call to convert_to_units is still made. This call does nothing more than return the requested UDF data in a floating point representation.
The program prints out the beginning and ending time of the data array followed by the scan index, value, and beginning phase of each element in the array.
#include < stdio.h >
#include < stdlib.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;
void *RetData = 0;
ReaL_4 *rD1, *rD2;
u_ByTe_4 Key;
ByTe_4 L, Len = 0, Fill = 0, bytes;
ByTe_1 *P = "IMAGE", *M = "IMAGE-1", *E = "EUV";
ByTe_1 *I = "EUVSCI", *SI = "IMES0IMG";
ByTe_1 *Ext = "", CFill = 0;
ByTe_1 S = 0, FwD = 1, FullCol = 0;
u_ByTe_2 V;
ByTe_4 Bs, Bns = 0, Es, Ens, Ms;
ByTe_2 By = 1999, Bd = 169, Ey = 1999, Ed = 169;
ByTe_2 Hr = 19, Mn = 22, Ss = 0;
ByTe_2 rV, SeN = 0, MCol = 0, Ops[1];
ByTe_1 NAS = 0, 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;
/********************************************************************
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 source. 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 condition %d in read_drec\n", rV);
exit (-1);
}
/********************************************************************
Check if data was acquired.
If no data could be found then report that.
********************************************************************/
if (ExDa->filled_data)
{
/********************************************************************
Make sure that the data return array is large enough to hold all
of the data, both sensor data and the scan indices.
********************************************************************/
if (Len < 2 * ExDa->num_sample)
{
bytes = 2 * ExDa->num_sample * sizeof (ReaL_4);
RetData = realloc (RetData, bytes);
Len = 2 * ExDa->num_sample;
}
/********************************************************************
Set pointer to memory where sensor data will be returned and
get the data.
********************************************************************/
rD1 = (ReaL_4 * )RetData;
rV = convert_to_units(Key, Ext, V, UDF, SENSOR, 0, NAS, Tbls,
Ops, rD1, CFill, Fill);
if (rV != ALL_OKAY)
{
printf ("Encountered error %d in convert_to_units\n", rV);
exit (-1);
}
/********************************************************************
Set pointer to memory where scan index data will be returned and
get the scan index data.
********************************************************************/
rD2 = (ReaL_4 * )RetData + ExDa->num_sample;
rV = convert_to_units(Key, Ext, V, UDF, SCNA_INDEX, 0, NAS, Tbls,
Ops, rD2, CFill, Fill);
if (rV != ALL_OKAY)
{
printf ("Encountered error %d in convert_to_units\n", rV);
exit (-1);
}
/********************************************************************
Print out the beginning and ending time associated with the
this data array.
********************************************************************/
By = ExDa->byear;
Bd = ExDa->bday;
Hr = ExDa->bmilli / 3600000;
Mn = (ExDa->bmilli % 3600000) / 60000;
Ss = ((ExDa->bmilli % 3600000) % 60000) / 1000;
Ms = ExDa->bmilli % 1000;
printf ("Array Begin: %d %03d %02d:%02d:%02d.%03d\n",
By, Bd, Hr, Mn, Ss, Ms);
By = ExDa->eyear;
Bd = ExDa->eday;
Hr = ExDa->emilli / 3600000;
Mn = (ExDa->emilli % 3600000) / 60000;
Ss = ((ExDa->emilli % 3600000) % 60000) / 1000;
Ms = ExDa->emilli % 1000;
printf ("Array End: %d %03d %02d:%02d:%02d.%03d\n",
By, Bd, Hr, Mn, Ss, Ms);
/********************************************************************
Print out the scan index value, the data, and the spin angle for
each position in the returned data array.
********************************************************************/
for (L = 0; L < ExDa->num_sample; ++L)
printf ("Array Index %.0f Value %.0f Phase = %.2f\n",
rD2[L], rD1[L], ExDa->start_az[L]);
}
else
printf ("No Data available\n");
exit(0);
}
| UDF V2.2 | July 31, 1999 | UDF V2.2 |
|---|