/* * =========== FILE: get_first_vidf.c =========== * * Description -- This routine returns the name of the first vidf in the * database. * * Synopsis -- int get_first_vidf_times (data_key, *btime_yr, *btime_day, *btime_msec) * * SDDAS_LONG data_key * * data_key the data_key for project/mission/experiment/instrument/virtual * * Return Values -- * * Fatal errors: * DBF_OPEN_ERROR - can't open the databases * DBF_READ_ERROR - can't read the databases * CONFIG_FILE_ERROR - can't read the config file or * find what I am looking for in then * * Nonfatal error: * NO_DATA - can't find the requested data in the database * * Ok return value: * ALL_OK - the data was found in the database * * Routines Used -- * * int OpenDbf() open a database file and initialize structure * int OpenIndex() open an index file * * Externals -- * * LinkList Projects pointer to projects tree * * Internals -- * * StrHier src pointers to the virtual instrument data within the project tree * char *path path value from configuration file */ #include /* for memset */ #include "SDDAS_types.h" #include "dbf.h" #include "DbDefs.h" #include "libCfg.h" #include "libserver.h" #include "local.h" #define FG(a,b,c) if (FieldGetN(a, b, c) != SUCCESS) return DBF_READ_ERROR int SwRI_get_first_vidf_times (SDDAS_ULONG data_key, SDDAS_SHORT *btime_yr, SDDAS_SHORT *btime_day, SDDAS_ULONG *btime_msec) { char *path, DbfName [FILE_NAME_LEN], NdxName [FILE_NAME_LEN], *tmp; SDDAS_INT Dbf, Ndx; StrHier src; char vinst [25]; SDDAS_SHORT params[5]; SDDAS_LONG temp; SDDAS_BOOL foundVINST = sFalse; int ret_val; key_to_fields (data_key, params); src = SourceByNum (Projects, params[0], params[1], params[2], params[3], params[4], NULL); /* * the request is for post-time data, need to open the database to search * for the correct file that contains the request time and decoded key */ /* * get the database directory path and generate the database and index * filenames */ if ((path = DbfFile (src)) == NULL) return CONFIG_FILE_ERROR; memset (DbfName, 0, sizeof (DbfName)); memset (NdxName, 0, sizeof (NdxName)); memset (vinst, 0, sizeof (vinst)); sprintf (DbfName, "%s.I.DBF", path); sprintf (NdxName, "%s.I.NDX", path); /* open up the database and index files */ if (OpenDbf (&Dbf, DbfName, O_RDONLY) != SUCCESS) { return DBF_OPEN_ERROR; } if (OpenNdx (Dbf, NdxName, &Ndx) != SUCCESS) { CloseDbf (Dbf); return DBF_OPEN_ERROR; } /* Go through the data base looking for our virtual name */ while (foundVINST == sFalse) { FG (Dbf, "V_INST", &vinst); tmp = strchr (vinst, ' '); if (tmp != NULL) tmp [0] = '\0'; if (strcmp (StrHierName (src), vinst) != 0) { if (Skip (Dbf, Ndx, 1) != SUCCESS) break; } else foundVINST = sTrue; } if (foundVINST == sTrue) { /* We found the data we are looking for in the database, so lets build a filename and change the beginning time to be based on what is found in the database */ /* pull the beginning time from the current database record */ FG (Dbf, "B_YR", &temp); *btime_yr = (SDDAS_SHORT) temp; FG (Dbf, "B_DAY", &temp); *btime_day = (SDDAS_SHORT) temp; FG (Dbf, "B_MSEC", btime_msec); ret_val = ALL_OK; } else { ret_val = NO_DATA; } /* Close out databases and then return the ret_val */ CloseNdx (Dbf, Ndx); CloseDbf (Dbf); return ret_val; }