UDF PROGRAMMERS MANUAL

Example 3 UDF PROGRAMMERS MANUAL Example 3

The program below is an example of how to retrieve VIDF fields. The parameter plot_package allows only the VIDF to be opened. Neither the Data nor the Header files for the source for the time requested need be online.

#include 
#include "util_var.h"
#include "ret_codes.h"
#include "local_defs.h"
#include "idf_defs.h"
#include "user_defs.h"
#include "libbase_udf.h"

int main ()
{
     u_ByTe_4 Key;
     ByTe_1 *P = "IMAGE", *M = "IMAGE-1", *E = "OA";
     ByTe_1 *I = "ORBIT", *SI = "IMOORBIT";
     ByTe_1 *Ext = "";
     u_ByTe_2 V;
     ByTe_4  Bs, Bns = 0, Es, Ens, L = 0, N;
     ByTe_2  By = 1999, Bd = 154, Ey = 1999, Ed = 169;
     ByTe_2  Hr = 00, Mn = 10, Ss = 0;
     ByTe_2 rV, NseN;
     ByTe_1 S = 0, NamE[90];
     
     /********************************************************************
        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.  Setting plot_package to 0 will
        allow just the VIDF to be opened - otherwise all three UDF files
        will have to be online and we don't care about the DATA and
        HEADER file.  Also get a version number.
      ********************************************************************/
      
     init_udf();
     get_version_number(&V);
     plot_package = 0;

     /******************************************************************** 
        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.  Ignore
        all errors since there may not be data on line but VIDF will be
        there.
      ********************************************************************/

     rV = file_open(Key, Ext, V, By, Bd, Bs, Bns, Ey, Ed, Es, Ens, S);

     /******************************************************************** 
        Get the number of defined sensors from the VIDF
      ********************************************************************/

     rV = read_idf(Key, Ext, V, (ByTe_1 *)&NseN, _SeN, 0, 0, -1);
     if (rV != ALL_OKAY)
     {
        printf ("Encountered error %d in read_idf\n", rV);
        exit (-1);
     }

     printf ("Number of Sensors: %d\n",NseN);

     /******************************************************************** 
        If there are sensors - get their VIDF descriptions.  Trim off
        leading and trailing spaces.
      ********************************************************************/

     if (NseN > 0)
     {
        for (L = 0; L < NseN; ++L)
        {
           rV = read_idf(Key, Ext, V, NamE , _SenNamE, 0, L, 1);
           if (rV != ALL_OKAY)
           {
              printf ("Encountered error %d in read_idf\n", rV);
              exit (-1);
           }
           
           N = 79;
           while ((NamE[N] == ' ' || NamE[N] == 0) && N >= 0)
              --N;
           NamE[++N] = 0;
           N = 0;
           while (NamE[N] == ' ')
              ++N;

           printf ("Sensor %03d : %s\n", L, &NamE[N]);
        }
     }

     exit(0);
}
UDF V2.2 July 31, 1999 UDF V2.2

TOC HOME