Blame view

src/DDSERVICES/TOOLS/StartStop.c 3.57 KB
c8f4ea1d   Elena.Budnik   new cdf2nc, updat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
/** @file  StartStop.c
*   @brief Stand-alone executable <br> Returns real Start-Stop for VI in DDBase <br>
*          Is used in DD Server WebServices <br>
*    @details StartStop(string *, string *)  <br>
*        @arg \c argv[1] Full name of DDBase reference file  <br>
*        @arg \c argv[2] Virtual Instrument ID (DD notation) <br>
*     Output: YYYYDDdayHHMMSSMLS-YYYYDDdayHHMMSSMLS       
*                 
*   @date 10.10.2007
*   @version $Id: StartStop.c,v 1.3 2011/09/05 11:27:34 budnik Exp $
*/


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <netcdf.h>
#include <DD.h>


int DataID, RecID, VarID, StartID, StopID;
size_t RecNum;
char StartT[TIMELENGTH], StopT[TIMELENGTH], Var[128];
size_t count[2] = {1L,TIMELENGTH};
size_t start[2] = {0L,0L};
size_t countVar[2] = {1L,128L};

/*---------------- NC ERROR --------------------------------------*/
void nc_handle_error(int status)
{
  fprintf(stderr, "%s\n", nc_strerror(status));
  exit(1);
}

/* ----------------------- MAIN ------------------------------------*/
  int main(int argc, char *argv[])
{
    
    int status, len;
 
ea9068c7   Benjamin Renard   Fix all warning w...
44
    char Project[50],Instrument[50],Mode[50], RInstrName[200];
c8f4ea1d   Elena.Budnik   new cdf2nc, updat...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59


    if (argc < 3)
    {
       fprintf(stderr,"Usage: StartStop reference_file_name DD_VI_ID\n");
       exit(0);
    }

     
    if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR)
                                            nc_handle_error(status);
    
     sscanf(argv[2], "%[^:]%*c%[^:]%*c%[^:]%*c",Project,
                                                  Instrument,
                                                   Mode);
ea9068c7   Benjamin Renard   Fix all warning w...
60
61
     memset(RInstrName, 0, 200*sizeof(char));
     sprintf(RInstrName,"%s_%s_%s",Project,Instrument,Mode);
c8f4ea1d   Elena.Budnik   new cdf2nc, updat...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

      if ((status = nc_inq_varid(DataID,RInstrName,&VarID)) != NC_NOERR)
                                            nc_handle_error(status);
    
      start[0] = 1;
      if((status = nc_get_vara_text(DataID, VarID, start, countVar, Var)) != NC_NOERR)
                                          nc_handle_error(status);
       
       len = strcspn(Var," "); Var[len] = '\0';

       if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status);

// Open VI_times.nc
      
       if ((status = nc_open(Var, NC_NOWRITE, &DataID)) != NC_NOERR)
                                                nc_handle_error(status);

       if ((status = nc_inq_dimid(DataID, "record", &RecID)) != NC_NOERR)
                                          nc_handle_error(status);
     
//   Get Number of Records
   
      if ((status = nc_inq_dimlen(DataID, RecID, &RecNum)) != NC_NOERR)
                                          nc_handle_error(status);

      if ((status = nc_inq_varid(DataID, "StartTime", &StartID)) != NC_NOERR)
                                          nc_handle_error(status);
      if ((status = nc_inq_varid(DataID, "StopTime", &StopID)) != NC_NOERR)
                                          nc_handle_error(status);

// Get The First Start and The Last Stop Times      
      start[0] = 0;     

     if((status = nc_get_vara_text(DataID, StartID, start, count, StartT)) != NC_NOERR)
                                          nc_handle_error(status);

      start[0] = RecNum-1; 
      if((status = nc_get_vara_text(DataID, StopID, start, count, StopT)) != NC_NOERR)
                                          nc_handle_error(status);
 
      printf("%s-%s\n",  StartT, StopT);
      if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status);
    
}