| Example 5 | UDF PROGRAMMERS MANUAL | Example 5 |
|---|
This program is similar to that given in Example2 with the exception that a full set of images is retrieved.
The program prints out the beginning and ending time of the image, some miscellaneous information on the images read, and then the image data itself.
#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;
struct MatrixData Md;
void *UDF;
ReaL_4 *f1, *fEnD;
u_ByTe_4 Key;
ByTe_1 *P = "IMAGE", *M = "IMAGE1", *E = "HENA";
ByTe_1 *I = "HENASCI", *SI = "IMHIMCPL";
ByTe_1 *Ext = "";
ByTe_1 S = 0;
u_ByTe_2 V;
ByTe_4 Bs, Bns = 0, Es, Ens, NumI, J, L;
ByTe_2 By = 2000, Bd = 187, Ey = 2000, Ed = 187;
ByTe_2 Hr = 00, Mn = 00, Ss = 0, Ms;
ByTe_2 rV, Ops[2];
ByTe_1 NAS = 2, Tbls[2], Stor = 0;
/********************************************************************
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 10 minutes beyond the beginning time.
********************************************************************/
Bs = 3600 * Hr + 60 * Mn + Ss;
Es = 3600 * Hr + 60 * (Mn + 10) + Ss;
/********************************************************************
Set up the table and operation used in conversion to cnts/sec
********************************************************************/
Tbls[0] = 0;
Tbls[1] = 1;
Ops[0] = 150;
Ops[1] = 3;
/********************************************************************
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;
/********************************************************************
Create one instance of a UDF Matrix Data structure. If there is
an error then give error code and exit.
********************************************************************/
rV = CreateMatStruc(&Md, NAS, Tbls, Ops);
if (rV != ALL_OKAY)
{
printf ("Encountered error %d in CreateMatStruct\n", rV);
exit (-1);
}
/********************************************************************
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 to the closed UDF data record to the
starting time. If there is an error then give error code and exit.
********************************************************************/
rV = FilePosRec(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);
}
/********************************************************************
Read in an image and report any errors if encountered.
********************************************************************/
rV = BuildImage(Key, Ext, V, UDF, &Md, Stor);
if (rV != ALL_OKAY)
{
printf ("Encountered condition %d in BuildImage\n", rV);
exit (-1);
}
/********************************************************************
Compute and print beginning time of image
********************************************************************/
By = Md.BYr;
Bd = Md.BDy;
Hr = Md.BMs / 3600000;
Mn = (Md.BMs % 3600000) / 60000;
Ss = ((Md.BMs % 3600000) % 60000) / 1000;
Ms = Md.BMs % 1000;
printf ("Image Begin: %d %03d %02d:%02d:%02d.%03d\n",
By, Bd, Hr, Mn, Ss, Ms);
/********************************************************************
Compute and print ending time of image
********************************************************************/
By = Md.EYr;
Bd = Md.EDy;
Hr = Md.EMs / 3600000;
Mn = (Md.EMs % 3600000) / 60000;
Ss = ((Md.EMs % 3600000) % 60000) / 1000;
Ms = Md.EMs % 1000;
printf ("Image End: %d %03d %02d:%02d:%02d.%03d\n",
By, Bd, Hr, Mn, Ss, Ms);
/********************************************************************
Print out miscellaneous image information
********************************************************************/
printf("Image Size: %d rows X %d cols\n", Md.TRows, Md.TCols);
NumI = Md.Sz / (Md.TRows * Md.TCols * sizeof(ReaL_4));
printf("Images: %d \n", NumI);
/********************************************************************
Print out images
********************************************************************/
for (J = 0; J < NumI; ++J)
{
printf("\nImage: %2d \n\n", J);
fEnD = (ReaL_4 *)Md.Data + (J+ 1) * Md.TRows * Md.TCols;
for (L = 0; L < Md.TRows; ++L)
{
f1 = (ReaL_4 *)Md.Data + J * Md.TRows * Md.TCols + L;
for (; f1 < fEnD; f1 += Md.TRows)
printf ("%11.3e", *f1);
printf ("\n");
}
}
exit(0);
}
| UDF V2.2 | July 31, 1999 | UDF V2.2 |
|---|