GetModificationDate.c
1.57 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/** @file GetModificationDate.c
* @brief Stand-alone executable <br> Returns modification date for given VI in DDBase <br>
*
* @details GetModificationDate(string *) <br>
* @arg \c argv[1] Path to VI directory
* @arg \c argv[2] Times file name
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>
#include <math.h>
#include <netcdf.h>
#include <DD.h>
/*---------------- 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;
if (argc < 3){
fprintf(stderr,"Usage: GetModificationDate path_to_vi times_file_name\n");
exit(1);
}
char timesPath[512];
memset(timesPath, 0, 512*sizeof(char));
strcat(timesPath, argv[1]);
strcat(timesPath, "/");
strcat(timesPath, argv[2]);
// Open VI_times.nc
int DataID;
if ((status = nc_open(timesPath, NC_NOWRITE, &DataID)) != NC_NOERR)
nc_handle_error(status);
char modificationDate[21];
memset(modificationDate, 0, 21*sizeof(char));
if ((status = nc_get_att_text(DataID, NC_GLOBAL, "ModificationDate", modificationDate)) != NC_NOERR) {
struct stat b;
if (!stat(timesPath, &b)) {
strftime(modificationDate, 21, "%Y-%m-%dT%H:%M:%SZ", localtime( &b.st_mtime));
}
}
nc_close(DataID);
if (strcmp(modificationDate, "") == 0) {
exit(1);
}
printf("%s\n", modificationDate);
exit(0);
}