Commit c1f7435fd89751372e12eea2de0ffbcee0dd4c4f
1 parent
f115086f
Exists in
master
and in
9 other branches
Give the possibility to define time as a timestamp (double)
Showing
2 changed files
with
79 additions
and
12 deletions
Show diff stats
src/SERVER/DD_GetData.c
... | ... | @@ -508,20 +508,16 @@ int GetAttribute(int ID, char *VarName) |
508 | 508 | */ |
509 | 509 | { |
510 | 510 | static int *VarID = NULL; /* IDs of requested Parameters of this VI */ |
511 | - static char TimeStr[TIMELENGTH]; | |
512 | - static char TimeName[] = "Time"; | |
513 | 511 | static int TimeID; |
512 | + static int TimeIsDouble = 0; | |
514 | 513 | //static size_t DimArray[NC_MAX_DIMS]; |
515 | 514 | static size_t **DimArrayS = NULL; /* Several Dimensions arrays */ |
516 | 515 | size_t *DimArray; /* Local Dimension Array (for the specific parameter */ |
517 | 516 | static int DimIDArray[NC_MAX_DIMS]; |
518 | 517 | static nc_type type; |
519 | 518 | static size_t start[NC_MAX_DIMS]; |
520 | - static size_t TimeCount[2] = {1,TIMELENGTH}; | |
521 | - static size_t TimeStart[2] = {0,0}; | |
522 | 519 | static int Scalar = 0; /* indicator of scalar value */ |
523 | 520 | static int String = 0; /* indicator of single (not timed) string March 9 1997 */ |
524 | - static int TimeTypeValue = 0; /* indicator of time type value */ | |
525 | 521 | static size_t RecordSize; /* Size of one record in terms of variables of specified type */ |
526 | 522 | static size_t *PacketSize=NULL; /* Packets sizes of one record (of specified variable) */ |
527 | 523 | static size_t RecordNumber; /* Variable maximal number of records in one packet */ |
... | ... | @@ -691,16 +687,24 @@ int GetAttribute(int ID, char *VarName) |
691 | 687 | /*--------------------------------------------- |
692 | 688 | * Define time ID |
693 | 689 | *--------------------------------------------*/ |
694 | - status = nc_inq_varid(CurrncID,TimeName,&TimeID); | |
690 | + TimeID = Time_GetVarID(CurrncID); | |
691 | + if (TimeID < 0) | |
692 | + { | |
693 | + if(Verbose) fprintf(stderr,"GetMultiData(%d): Error in time var detection\n",ID); | |
694 | + return(DATAFILEERR); | |
695 | + } | |
696 | + | |
697 | + TimeIsDouble = Time_IsDoubleVar(CurrncID, TimeID); | |
698 | + | |
699 | + if(Verbose) fprintf(stderr,"GetMultiData(%d): TimeID = %d - TimeIsDouble = %d\n",ID,TimeID,TimeIsDouble); | |
700 | + | |
695 | 701 | /*------------------------------------------------------------------------------------------ |
696 | 702 | * Reseting VarNumber and create a new local data structure |
697 | 703 | * Also we need to set Time limit constants |
698 | 704 | *------------------------------------------------------------------------------------------*/ |
699 | 705 | if(DD_Var[ID]->LastPacketFlag == OK) /* Very new request, after SetTime() */ |
700 | 706 | { |
701 | - TimeStart[0] = DD_Var[ID]->nc_rec; | |
702 | - status = nc_get_vara_text(DD_Var[ID]->ncID,TimeID,TimeStart,TimeCount,TimeStr); | |
703 | - DD_Var[ID]->CDTime = DD_Time2Double(TimeStr); /* Current time of record */ | |
707 | + DD_Var[ID]->CDTime = Time_GetValueFromVar(DD_Var[ID]->ncID,TimeID,TimeIsDouble,DD_Var[ID]->nc_rec); /* Current time of record */ | |
704 | 708 | DD_Var[ID]->SDTime = DD_Var[ID]->CDTime; /* Start time of record */ |
705 | 709 | DD_Var[ID]->FDTime = DD_Var[ID]->SDTime + DD_Time2Double(TimeInt); |
706 | 710 | } |
... | ... | @@ -860,9 +864,7 @@ int GetAttribute(int ID, char *VarName) |
860 | 864 | |
861 | 865 | /*---------- Define START from LOCAL struct and read current Time ----------*/ |
862 | 866 | start[0] = Local.nc_rec; |
863 | - TimeStart[0] = Local.nc_rec; | |
864 | - status = nc_get_vara_text(Local.ncID,TimeID,TimeStart,TimeCount,TimeStr); | |
865 | - Local.CDTime = DD_Time2Double(TimeStr); /* Current time of record */ | |
867 | + Local.CDTime = Time_GetValueFromVar(Local.ncID, TimeID, TimeIsDouble, Local.nc_rec); | |
866 | 868 | //fprintf(stderr,"GetData(%d): Start %f Current %f Stop %f\n",ID,Local.SDTime,Local.CDTime,Local.FDTime); |
867 | 869 | |
868 | 870 | //-------------- Check if we have to return by time -------------- |
... | ... |
... | ... | @@ -0,0 +1,65 @@ |
1 | +/*===================================================================== | |
2 | + * DD SYSTEM base package | |
3 | + * DD_Server library | |
4 | + * DD_TimeVar.c | |
5 | + * V.1.0 | |
6 | + * Last revision: | |
7 | + * June 03 2019: Version 1.0. Common methods used for time variable | |
8 | + */ | |
9 | + | |
10 | +#include <netcdf.h> | |
11 | +#include "DD.h" | |
12 | +#include "DD_comm.h" | |
13 | + | |
14 | +int Time_GetVarID(int ncID) { | |
15 | + static char TimeName[] = "Time"; | |
16 | + int status = NC_NOERR; | |
17 | + int TimeID = -1; | |
18 | + status = nc_inq_varid(ncID, TimeName, &TimeID); | |
19 | + if (status != NC_NOERR) { | |
20 | + return -1; | |
21 | + } | |
22 | + return TimeID; | |
23 | +} | |
24 | + | |
25 | +int Time_IsDoubleVar(int ncID, int timeVarID) { | |
26 | + nc_type TimeType; | |
27 | + int status = NC_NOERR; | |
28 | + status = nc_inq_var (ncID, timeVarID, NULL, &TimeType, NULL, NULL, NULL); | |
29 | + if (status != NC_NOERR) { | |
30 | + return 0; | |
31 | + } | |
32 | + return (TimeType == NC_DOUBLE) ? 1 : 0; | |
33 | +} | |
34 | + | |
35 | +double Time_GetValueFromTextVar(int ncID, int timeVarID, int recNum) { | |
36 | + static char TimeStr[TIMELENGTH]; | |
37 | + static size_t TimeCountText[2] = {1,TIMELENGTH}; | |
38 | + size_t TimeStartText[2] = {recNum,0}; | |
39 | + int status = NC_NOERR; | |
40 | + status = nc_get_vara_text(ncID,timeVarID,TimeStartText,TimeCountText,TimeStr); | |
41 | + if (status != NC_NOERR) { | |
42 | + return 0.; | |
43 | + } | |
44 | + return DD_Time2Double(TimeStr); | |
45 | +} | |
46 | + | |
47 | +double Time_GetValueFromDoubleVar(int ncID, int timeVarID, int recNum) { | |
48 | + static size_t TimeCountDouble[1] = {1}; | |
49 | + size_t TimeStartDouble[1] = {recNum}; | |
50 | + double val; | |
51 | + int status = NC_NOERR; | |
52 | + status = nc_get_vara_double (ncID,timeVarID,TimeStartDouble,TimeCountDouble,&val); | |
53 | + if (status != NC_NOERR) { | |
54 | + return 0.; | |
55 | + } | |
56 | + return val; | |
57 | +} | |
58 | + | |
59 | +double Time_GetValueFromVar(int ncID, int timeVarID, int isDoubleTime, int recNum) { | |
60 | + if (isDoubleTime) { | |
61 | + return Time_GetValueFromDoubleVar(ncID, timeVarID, recNum); | |
62 | + } | |
63 | + return Time_GetValueFromTextVar(ncID, timeVarID, recNum); | |
64 | +} | |
65 | + | |
... | ... |