diff --git a/src/SERVER/DD_GetData.c b/src/SERVER/DD_GetData.c index 4210327..36cab54 100755 --- a/src/SERVER/DD_GetData.c +++ b/src/SERVER/DD_GetData.c @@ -508,20 +508,16 @@ int GetAttribute(int ID, char *VarName) */ { static int *VarID = NULL; /* IDs of requested Parameters of this VI */ - static char TimeStr[TIMELENGTH]; - static char TimeName[] = "Time"; static int TimeID; + static int TimeIsDouble = 0; //static size_t DimArray[NC_MAX_DIMS]; static size_t **DimArrayS = NULL; /* Several Dimensions arrays */ size_t *DimArray; /* Local Dimension Array (for the specific parameter */ static int DimIDArray[NC_MAX_DIMS]; static nc_type type; static size_t start[NC_MAX_DIMS]; - static size_t TimeCount[2] = {1,TIMELENGTH}; - static size_t TimeStart[2] = {0,0}; static int Scalar = 0; /* indicator of scalar value */ static int String = 0; /* indicator of single (not timed) string March 9 1997 */ - static int TimeTypeValue = 0; /* indicator of time type value */ static size_t RecordSize; /* Size of one record in terms of variables of specified type */ static size_t *PacketSize=NULL; /* Packets sizes of one record (of specified variable) */ static size_t RecordNumber; /* Variable maximal number of records in one packet */ @@ -691,16 +687,24 @@ int GetAttribute(int ID, char *VarName) /*--------------------------------------------- * Define time ID *--------------------------------------------*/ - status = nc_inq_varid(CurrncID,TimeName,&TimeID); + TimeID = Time_GetVarID(CurrncID); + if (TimeID < 0) + { + if(Verbose) fprintf(stderr,"GetMultiData(%d): Error in time var detection\n",ID); + return(DATAFILEERR); + } + + TimeIsDouble = Time_IsDoubleVar(CurrncID, TimeID); + + if(Verbose) fprintf(stderr,"GetMultiData(%d): TimeID = %d - TimeIsDouble = %d\n",ID,TimeID,TimeIsDouble); + /*------------------------------------------------------------------------------------------ * Reseting VarNumber and create a new local data structure * Also we need to set Time limit constants *------------------------------------------------------------------------------------------*/ if(DD_Var[ID]->LastPacketFlag == OK) /* Very new request, after SetTime() */ { - TimeStart[0] = DD_Var[ID]->nc_rec; - status = nc_get_vara_text(DD_Var[ID]->ncID,TimeID,TimeStart,TimeCount,TimeStr); - DD_Var[ID]->CDTime = DD_Time2Double(TimeStr); /* Current time of record */ + DD_Var[ID]->CDTime = Time_GetValueFromVar(DD_Var[ID]->ncID,TimeID,TimeIsDouble,DD_Var[ID]->nc_rec); /* Current time of record */ DD_Var[ID]->SDTime = DD_Var[ID]->CDTime; /* Start time of record */ DD_Var[ID]->FDTime = DD_Var[ID]->SDTime + DD_Time2Double(TimeInt); } @@ -860,9 +864,7 @@ int GetAttribute(int ID, char *VarName) /*---------- Define START from LOCAL struct and read current Time ----------*/ start[0] = Local.nc_rec; - TimeStart[0] = Local.nc_rec; - status = nc_get_vara_text(Local.ncID,TimeID,TimeStart,TimeCount,TimeStr); - Local.CDTime = DD_Time2Double(TimeStr); /* Current time of record */ + Local.CDTime = Time_GetValueFromVar(Local.ncID, TimeID, TimeIsDouble, Local.nc_rec); //fprintf(stderr,"GetData(%d): Start %f Current %f Stop %f\n",ID,Local.SDTime,Local.CDTime,Local.FDTime); //-------------- Check if we have to return by time -------------- diff --git a/src/SERVER/DD_TimeVar.c b/src/SERVER/DD_TimeVar.c new file mode 100644 index 0000000..5c4bed5 --- /dev/null +++ b/src/SERVER/DD_TimeVar.c @@ -0,0 +1,65 @@ +/*===================================================================== + * DD SYSTEM base package + * DD_Server library + * DD_TimeVar.c + * V.1.0 + * Last revision: + * June 03 2019: Version 1.0. Common methods used for time variable + */ + +#include <netcdf.h> +#include "DD.h" +#include "DD_comm.h" + +int Time_GetVarID(int ncID) { + static char TimeName[] = "Time"; + int status = NC_NOERR; + int TimeID = -1; + status = nc_inq_varid(ncID, TimeName, &TimeID); + if (status != NC_NOERR) { + return -1; + } + return TimeID; +} + +int Time_IsDoubleVar(int ncID, int timeVarID) { + nc_type TimeType; + int status = NC_NOERR; + status = nc_inq_var (ncID, timeVarID, NULL, &TimeType, NULL, NULL, NULL); + if (status != NC_NOERR) { + return 0; + } + return (TimeType == NC_DOUBLE) ? 1 : 0; +} + +double Time_GetValueFromTextVar(int ncID, int timeVarID, int recNum) { + static char TimeStr[TIMELENGTH]; + static size_t TimeCountText[2] = {1,TIMELENGTH}; + size_t TimeStartText[2] = {recNum,0}; + int status = NC_NOERR; + status = nc_get_vara_text(ncID,timeVarID,TimeStartText,TimeCountText,TimeStr); + if (status != NC_NOERR) { + return 0.; + } + return DD_Time2Double(TimeStr); +} + +double Time_GetValueFromDoubleVar(int ncID, int timeVarID, int recNum) { + static size_t TimeCountDouble[1] = {1}; + size_t TimeStartDouble[1] = {recNum}; + double val; + int status = NC_NOERR; + status = nc_get_vara_double (ncID,timeVarID,TimeStartDouble,TimeCountDouble,&val); + if (status != NC_NOERR) { + return 0.; + } + return val; +} + +double Time_GetValueFromVar(int ncID, int timeVarID, int isDoubleTime, int recNum) { + if (isDoubleTime) { + return Time_GetValueFromDoubleVar(ncID, timeVarID, recNum); + } + return Time_GetValueFromTextVar(ncID, timeVarID, recNum); +} + -- libgit2 0.21.2