41 std::string
node =
"hiakasat";
43 std::string
source =
"incoming";
55 printf(
"Usage: archive node [agent] [\"incoming\"|\"outgoing\"]\n");
61 printf(
"Couldn't establish client for node %s\n", node.c_str());
66 std::vector<filestruc> srcfiles;
71 if (srcfile.type !=
"directory")
74 if ((fin =
data_open(srcfile.path, (
char *)
"r")) != NULL)
77 uint32_t year, jday, isecond;
78 sscanf(srcfile.name.c_str(),
"%*[A-Z,a-z,0-9]_%4u%3u%5u", &year, &jday, &isecond);
79 double utc =
cal2mjd(year, 1, isecond/86400.) + jday;
82 uint16_t namelen = srcfile.name.size();
83 if (namelen >= 3 && srcfile.name.substr(namelen-3, 3) ==
".gz")
85 srcfile.name = srcfile.name.substr(0, namelen-3);
88 std::string newpath =
data_name_path(node,
"data", agentname, utc, srcfile.name);
92 if ((fout =
data_open(newpath, (
char *)
"w")) != NULL)
98 nbytes =
gzread(gzin, buffer, 8192);
102 fwrite(buffer, 1, nbytes, fout);
104 }
while (nbytes > 0 && !
gzeof(gzin));
110 printf(
"Success: %s: %" PRIu64
"\n", newpath.c_str(), tbytes);
114 remove(newpath.c_str());
115 printf(
"Failure: %s\n", newpath.c_str());
int ZEXPORT gzeof(gzFile file)
Definition: gzlib.c:511
FILE * data_open(string path, const char *mode)
Open file from path.
Definition: datalib.cpp:1019
string data_name_path(string node, string location, string agent, double mjd, string name)
Create data file path.
Definition: datalib.cpp:954
vector< filestruc > data_list_files(string directory)
Get list of files in a directory, directly.
Definition: datalib.cpp:461
nodestruc node
Structure for summary information in node.
Definition: jsondef.h:4220
Definition: datalib.h:113
static char buffer[255]
Definition: propagator_simple.cpp:60
string agentname
Definition: agent_add_soh.cpp:53
char name[40+1]
Node Name.
Definition: jsondef.h:3556
Definition: agentclass.h:139
int ZEXPORT gzclose_r(gzFile file)
Definition: gzread.c:567
double cal2mjd(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second, int32_t nsecond)
Calendar representation to Modified Julian Day - full.
Definition: timelib.cpp:294
gzFile ZEXPORT gzdopen(int fd, const char *mode)
Definition: gzlib.c:284
static string source
Definition: ax25_recv.cpp:42
cosmosstruc * cinfo
Definition: agentclass.h:346
Agent * agent
Definition: archive.cpp:37
static string node
Definition: agent_monitor.cpp:126
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
Definition: gzread.c:288
bool data_exists(string &path)
Check existence of path.
Definition: datalib.cpp:1003