/** @file GetReleaseDate.c * @brief Stand-alone executable
Returns release date for given VI in DDBase
* * @details GetReleaseDate(string *)
* @arg \c argv[1] Full name of *_times.nc * */ #include #include #include #include #include #include #include #include /*---------------- 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: GetReleaseDate 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); int FileID; if ((status = nc_inq_varid(DataID, "FileName", &FileID)) != NC_NOERR) nc_handle_error(status); int Filedims[2]; if ((status = nc_inq_var(DataID, FileID, NULL, NULL, NULL, Filedims, NULL)) != NC_NOERR) nc_handle_error(status); size_t nb_records; if ((nc_inq_dimlen(DataID, Filedims[0], &nb_records)) != NC_NOERR) nc_handle_error(status); int i; char FileName[32]; char filePath[512]; size_t count[2] = {1L,32L}; size_t start[2] = {0L,0L}; struct stat attrib; time_t releaseDate = 0; for (i = 0; i < nb_records; ++i) { count[1] = 32; if ((status = nc_get_vara_text(DataID, FileID, start, count, FileName)) != NC_NOERR) nc_handle_error(status); memset(filePath, 0, 512*sizeof(char)); strcat(filePath, argv[1]); strcat(filePath, "/"); strcat(filePath, FileName); strcat(filePath, ".gz"); stat(filePath, &attrib); if (releaseDate < attrib.st_mtime) releaseDate = attrib.st_mtime; } nc_close(DataID); if (releaseDate == 0) exit(1); char releaseDateISO[21]; memset(releaseDateISO, 0, 21*sizeof(char)); strftime(releaseDateISO, 21, "%Y-%m-%dT%H:%M:%SZ", localtime( &releaseDate)); printf("%s\n", releaseDateISO); exit(0); }