Beispiel #1
0
/*!
 * Set the extended header data for unit [iunit] to be [numBytes] bytes with the contents 
 * of array [extra].  Returns negative values for internal errors or 2 for a write error.
 * Fortran wrappers iiuAltExtendedData and ialsym (a void).
 */
int iiuAltExtendedData(int iunit, int numBytes, int *extra)
{
  int doExit = iiuGetExitOnError();
  MrcHeader *hdr = iiuMrcHeader(iunit, "iiAltExtendedData", doExit, 2);
  if (!hdr)
    return -1;
  if (iiuFileType(iunit) != IIFILE_MRC)
    return 0;
  if (hdr->swapped) {
    fprintf(stdout, "\nERROR: iiuAltExtendedData - Cannot write extra header data to a"
            " byte-swapped file (unit %d).\n", iunit);
    if (doExit)
      exit(1);
    return -2;
  }
  hdr->next = numBytes;
  hdr->headerSize = 1024 + numBytes;
  b3dFseek(hdr->fp, 1024, SEEK_SET);
  if (b3dFwrite(extra, 1, numBytes, hdr->fp) != numBytes) {
    fprintf(stdout, "\nERROR: iiAltExtendedData - Writing %d bytes of extended header "
            "data for unit %d.\n", numBytes, iunit);
    if (doExit)
      exit(1);
    return 2;
  }
  return 0;
}
Beispiel #2
0
void qwrite(int *iunit, char *array, int *nitems)
{
  int unit = *iunit - 1;
  
  Unit *u = check_unit(unit, "qwrite", 1);
  int bc = *nitems;
  if (u->read_only) {
    fprintf(stdout, "\nERROR: qwrite - '%s' is read only.\n", u->tailName);
    exit(3);
  }

  errno = 0;
  if (b3dFwrite(array, 1, bc, u->fp) != bc) {
    unit = errno;
    fprintf(stdout, "\nERROR: qwrite - writing '%s'\n", u->tailName);
    if (unit)
      fprintf(stdout, "ERROR: from system - %s\n", strerror(unit));
    exit(3);
  }
  u->pos += bc;
}
Beispiel #3
0
/*!
 * Writes the data from [slice] into a new MRC file whose name is given in 
 * [filename].  Returns -1 for error opening the file, -2 for error writing
 * header, or an error from ferror if there is an error writing the data.
 * Unused as of 2/3/07, but seems usable.
 */
int sliceWriteMRCfile(char *filename, Islice *slice)
{
  MrcHeader hout;
  FILE *fp = fopen(filename, "wb");
  int error;

  if (!fp) return -1;
  mrc_head_new(&hout, slice->xsize, slice->ysize, 1, slice->mode);
  sliceMMM(slice);
  hout.amin  = slice->min;
  hout.amax  = slice->max;
  hout.amean = slice->mean;
  if (mrc_head_write(fp, &hout)) {
    fclose(fp);
    return -2;
  }
  b3dFwrite(slice->data.b, slice->dsize, 
            slice->csize * slice->xsize * slice->ysize, fp);
  error = ferror(fp);
  fclose(fp);
  return(error);
}