GetModificationDate.c 1.57 KB
 
/** @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);
}