Skip to content

Commit

Permalink
remove debug/info output
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsp-spirit committed Sep 2, 2019
1 parent be905c8 commit 1daddfc
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions R/read_fs_mgh.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ read.fs.mgh <- function(filepath, is_gzipped = "AUTO") {
}

if (is_gz) {
cat(sprintf("*Parsing header of file '%s', assuming it is gz-compressed.\n", filepath));
fh = gzfile(filepath, "rb");
}
else {
cat(sprintf("*Parsing header of file '%s', assuming it is NOT gz-compressed.\n", filepath));
fh = file(filepath, "rb");
}

Expand All @@ -60,32 +58,22 @@ read.fs.mgh <- function(filepath, is_gzipped = "AUTO") {
dtype = readBin(fh, integer(), n = 1, endian = "big");
dof = readBin(fh, integer(), n = 1, endian = "big");


cat(sprintf(" v=%d, ndim1=%d, ndim2=%d, ndim3=%d, nframes=%d, type=%d, dof=%d.\n", v, ndim1, ndim2, ndim3, nframes, dtype, dof));


unused_header_space_size_left = 256;

ras_good_flag = readBin(fh, numeric(), n = 1, endian = "big");
if(ras_good_flag == 1) {
cat(sprintf(" 'RAS good' flag is set, reading RAS information.\n"));
delta = readBin(fh, numeric(), n = 3, endian = "big");
Mdc = readBin(fh, numeric(), n = 9, endian = "big");
Pxyz_c = readBin(fh, numeric(), n = 3, endian = "big");
RAS_space_size = (3*4 + 4*3*4);
cat(sprintf(" Read %d bytes of RAS information.\n", RAS_space_size));
unused_header_space_size_left = unused_header_space_size_left - RAS_space_size;
} else {
cat(sprintf(" 'RAS good' flag is NOT set, no RAS information to read.\n"));
}
cat(sprintf(" There are %d unused header bytes left that will be skipped (data starts at fixed index).\n", unused_header_space_size_left));

# Skip to end of header/beginning of data
seek(fh, where = unused_header_space_size_left, origin = "current");

nv = ndim1 * ndim2 * ndim3 * nframes; # number of voxels
volsz = c(ndim1, ndim2, ndim3, nframes);
cat(sprintf(" Expecting %d voxels total.\n", nv));

# Determine size of voxel data, depending on dtype from header above
MRI_UCHAR = 0;
Expand All @@ -111,19 +99,14 @@ read.fs.mgh <- function(filepath, is_gzipped = "AUTO") {
} else {
stop(sprintf(" ERROR: Unexpected data type found in header. Expected one of {0, 1, 3, 4} (%s) but got %d.\n", dt_explanation, dtype));
}
cat(sprintf(" Data type found in header is %d (%s), with %d bytes per voxel.\n", dtype, dt_explanation, nbytespervox));

num_read = prod(length(data));
if (num_read == nv) {
cat(sprintf(" OK, read %d voxel values as expected.\n", num_read));
} else {
cat(sprintf(" ERROR: read %d voxel values but expected to read %d.\n", num_read, nv));
quit(status=1);
if (num_read != nv) {
stop(sprintf(" ERROR: read %d voxel values but expected to read %d.\n", num_read, nv));
}

# Reshape to expected dimensions
data = array(data, dim = c(ndim1, ndim2, ndim3, nframes));
cat(sprintf(" Reshaped array to expected dimensions: %s\n", paste(dim(data), collapse = ' ')));
close(fh);
return(data);
}

0 comments on commit 1daddfc

Please sign in to comment.