#include #include #include #include #include "SDDAS_types.h" #include "libdb.h" #include "local.h" int dbIDFSGetRealTimeFile (SDDAS_ULONG data_key, RequestedDataType dataType, const char *exten, char *name1, char *name2) { char *path; char vinst [MAX_IDFS_VIRT_NAME]; int err = dbVirtualName_r (data_key, vinst, sizeof (vinst)); if (err != 1) { SetErrorString ("ERROR - dbIDFSGetRealTimeFile - Bad virtual instrument..."); return CONFIG_FILE_ERROR; } if ((path = dbCfgPath (data_key, "RealTimePath")) == NULL) { return CONFIG_FILE_ERROR; } switch (dataType) { case _H_AND_D_ : case _HEADER_ : sprintf (name1, "%s/%sH%s", path, vinst, exten); break; case _DATA_ : sprintf (name1, "%s/%sD%s", path, vinst, exten); break; case _VIDF_ : sprintf (name1, "%s/%sI%s", path, vinst, exten); break; } /* switch */ /* if the user requested both files */ if (dataType == _H_AND_D_) { strcpy (name2, name1); name2 [strlen (name2) - 1] = 'D'; /* replace the last letter with a D */ } return ALL_OKAY; } #ifdef ALL_DB int SQL_dbIDFSGetFile (SDDAS_ULONG data_key, SDDAS_SHORT btime_yr, SDDAS_SHORT btime_day, SDDAS_LONG btime_msec, SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_msec, RequestedDataType dataType, const char *exten, char *name1, char *name2) { SDDAS_SHORT btime_yr_r = btime_yr; // these will be over written SDDAS_SHORT btime_day_r = btime_day; SDDAS_LONG btime_msec_r = btime_msec; return SQL_dbIDFSGetFileAndTimes (data_key, &btime_yr_r, &btime_day_r, &btime_msec_r, etime_yr, etime_day, etime_msec, dataType, exten, name1, name2); } int SQL_dbIDFSGetFileAndTimes (SDDAS_ULONG data_key, SDDAS_SHORT *btime_yr, SDDAS_SHORT *btime_day, SDDAS_LONG *btime_msec, SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_msec, RequestedDataType dataType, const char *exten, char *name1, char *name2) #else int dbIDFSGetFile (SDDAS_ULONG data_key, SDDAS_SHORT btime_yr, SDDAS_SHORT btime_day, SDDAS_LONG btime_msec, SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_msec, RequestedDataType dataType, const char *exten, char *name1, char *name2) { SDDAS_SHORT btime_yr_r = btime_yr; // these will be overwritten SDDAS_SHORT btime_day_r = btime_day; SDDAS_LONG btime_msec_r = btime_msec; return dbIDFSGetFileAndTimes (data_key, &btime_yr_r, &btime_day_r, &btime_msec_r, etime_yr, etime_day, etime_msec, dataType, exten, name1, name2); } int dbIDFSGetFileAndTimes (SDDAS_ULONG data_key, SDDAS_SHORT *btime_yr, SDDAS_SHORT *btime_day, SDDAS_LONG *btime_msec, SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_msec, RequestedDataType dataType, const char *exten, char *name1, char *name2) #endif { char query_str [1024]; DB_RESULT *result; DB_ROW row; char whichDB [20]; char file [100]; char vinst [MAX_IDFS_VIRT_NAME]; int err = dbVirtualName_r (data_key, vinst, sizeof (vinst)); if (err != 1) { SetErrorString ("ERROR - dbIDFSGetFile - Bad virtual instrument..."); return CONFIG_FILE_ERROR; } switch (dataType) { case _H_AND_D_ : case _HEADER_ : case _DATA_ : strcpy (whichDB, "hd_entries"); break; case _VIDF_ : strcpy (whichDB, "v_entries"); break; } /* switch */ /* this is where we do our query to the data base */ sprintf (query_str, "SELECT b_yr, b_day, b_msec FROM %s WHERE data_key=%ld "\ "AND BETWEEN_TIMES(b_yr, b_day, b_msec, e_yr, e_day, e_msec, "\ "%d, %d, %ld, %d, %d, %ld) > 0 "\ "LIMIT 1;", whichDB, (long) data_key, (int) *btime_yr, (int) *btime_day, (long) *btime_msec, (int) etime_yr, (int) etime_day, (long) etime_msec); if ((result = (DB_RESULT *) dbQueryStore (query_str)) != NULL) { while ((row = (DB_ROW) dbFetchRow (result))) { *btime_yr = (SDDAS_SHORT) atoi (row [0]); *btime_day = (SDDAS_SHORT) atoi (row [1]); *btime_msec = (SDDAS_LONG) atoi (row [2]); } if (dbNumberRows (result) == 0) { SetErrorString ("ERROR - dbIDFSGetFile - No data for requested time! Must promote..."); dbFreeResult (result); return (NO_DATA); } dbFreeResult (result); } else { SetErrorString ("ERROR - dbIDFSGetFile - Query failed!"); return (DBF_ERROR); } /* we found an entry */ switch (dataType) { case _H_AND_D_ : case _HEADER_ : MakeFileName (vinst, *btime_yr, *btime_day, *btime_msec, 'H', file, sizeof (file)); break; case _DATA_ : MakeFileName (vinst, *btime_yr, *btime_day, *btime_msec, 'D', file, sizeof (file)); break; case _VIDF_ : MakeFileName (vinst, *btime_yr, *btime_day, *btime_msec, 'I', file, sizeof (file)); break; } /* switch */ /* * if the exten variable has something in it, use the user data * path for data instead of the default one */ if (strlen (exten) != 0) { if (getenv ("USER_DATA") == NULL) { sprintf (name1, "%s/%s%s", getenv ("HOME"), file, exten); } else { sprintf (name1, "%s/%s%s", getenv ("USER_DATA"), file, exten); } } else { sprintf (name1, "%s/%s", dbCfgPath (data_key, "PostTimePath"), file); } /* if the user requested both files */ if (dataType == _H_AND_D_) { strcpy (name2, name1); name2 [strlen (name2) - 1] = 'D'; /* replace the last letter with a D */ } return (ALL_OKAY); }