static inline void wbExportRaw_setFile(wbExportRaw_t raw, const char *path) { if (raw != NULL) { if (wbExportRaw_getFile(raw) != NULL) { wbFile_delete(wbExportRaw_getFile(raw)); } if (path != NULL) { wbExportRaw_getFile(raw) = wbFile_open(path, "w+"); } else { wbExportRaw_getFile(raw) = NULL; } } return; }
static inline void wbExportRaw_write(wbExportRaw_t raw, void *data, int rows, int columns, wbType_t type) { int ii, jj; FILE *handle; wbFile_t file; if (raw == nullptr || wbExportRaw_getFile(raw) == nullptr) { return; } file = wbExportRaw_getFile(raw); handle = wbFile_getFileHandle(file); if (handle == nullptr) { return; } if (columns == 1) { fprintf(handle, "%d\n", rows); } else { fprintf(handle, "%d %d\n", rows, columns); } for (ii = 0; ii < rows; ii++) { for (jj = 0; jj < columns; jj++) { if (type == wbType_integer) { int elem = ((int *)data)[ii * columns + jj]; fprintf(handle, "%d", elem); } else if (type == wbType_ubit8) { int elem = ((unsigned char *)data)[ii * columns + jj]; fprintf(handle, "%d", elem); } else { wbReal_t elem = ((wbReal_t *)data)[ii * columns + jj]; fprintf(handle, "%f", elem); } if (jj == columns - 1) { fprintf(handle, "\n"); } else { fprintf(handle, " "); } } } return; }
static inline wbExportRaw_t wbExportRaw_new(void) { wbExportRaw_t raw; raw = wbNew(struct st_wbExportRaw_t); wbExportRaw_getFile(raw) = NULL; wbExportRaw_setRowCount(raw, -1); wbExportRaw_setColumnCount(raw, -1); return raw; }