Пример #1
0
/* ----------------------------- MNI Header -----------------------------------
@NAME       : acr_write_one_element
@INPUT      : afp - Acr_File pointer from which to read
              group_id - ACR-NEMA group id
              element_id - ACR-NEMA element id
              data_length - length of data to follow
              data_pointer - pointer to data.
@OUTPUT     : (nothing)
@RETURNS    : Status.
@DESCRIPTION: Routine to write out one ACR-NEMA element.
@METHOD     : 
@GLOBALS    : 
@CALLS      : 
@CREATED    : November 10, 1993 (Peter Neelin)
@MODIFIED   : 
---------------------------------------------------------------------------- */
Acr_Status acr_write_one_element(Acr_File *afp,
                                        int group_id, int element_id,
                                        long data_length, char *data_pointer)
{
   int ch, i, buflen;
   unsigned char buffer[2*ACR_SIZEOF_SHORT+ACR_SIZEOF_LONG];
   unsigned short grpid, elid;

   buflen = sizeof(buffer)/sizeof(buffer[0]);

   /* Write out group id, element id and length of data */
   grpid = group_id;
   acr_put_short(1, &grpid, &buffer[0]);
   elid = element_id;
   acr_put_short(1, &elid, &buffer[2]);
   acr_put_long(1, &data_length, &buffer[4]);
   for (i=0; i < buflen; i++) {
      ch = acr_putc(buffer[i], afp);
      if (ch == EOF) {
         return ACR_OTHER_ERROR;
      }
   }

   /* Write out the data */
   for (i=0; i < data_length; i++) {
      ch = acr_putc(data_pointer[i], afp);
      if (ch == EOF) {
         return ACR_OTHER_ERROR;
      }
   }

   return ACR_OK;
}
Пример #2
0
/* ----------------------------- MNI Header -----------------------------------
@NAME       : acr_write_buffer
@INPUT      : afp
              nbytes_to_write
              buffer
@OUTPUT     : nbytes_written
@RETURNS    : Output status.
@DESCRIPTION: Writes out a buffer of data and optionally returns the number 
              of bytes written
@METHOD     : 
@GLOBALS    : 
@CALLS      : 
@CREATED    : February 12, 1997 (Peter Neelin)
@MODIFIED   : 
---------------------------------------------------------------------------- */
Acr_Status acr_write_buffer(Acr_File *afp, unsigned char buffer[],
                            long nbytes_to_write, long *nbytes_written)
{
   long i;

   for (i=0; i < nbytes_to_write; i++) {
      if (acr_putc(buffer[i], afp) == EOF) {
         break;
      }
   }

   /* Save the number of bytes written */
   if (nbytes_written != NULL) {
      *nbytes_written = i;
   }

   /* Return the status */
   if (i < nbytes_to_write) {
      return ACR_ABNORMAL_END_OF_OUTPUT;
   }
   else {
      return ACR_OK;
   }
}