Exemplo n.º 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;
}
Exemplo n.º 2
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
              vr_name - 2 character string giving value representation.
                 It is an error to pass in two NULs if explicit VR is used
                 (ACR_NO_VR_SPECIFIED is returned).
              data_length - length of data to follow. If set to 
                 ACR_VARIABLE_LENGTH, then the data portion is not written out.
              data_pointer - pointer to data. If NULL, then no data is
                 written.
@OUTPUT     : (nothing)
@RETURNS    : VIO_Status.
@DESCRIPTION: Routine to write out one ACR-NEMA element.
@METHOD     : 
@GLOBALS    : 
@CALLS      : 
@CREATED    : November 10, 1993 (Peter Neelin)
@MODIFIED   : January 29, 1997 (P.N.)
---------------------------------------------------------------------------- */
Acr_Status acr_write_one_element(Acr_File *afp,
                                 int group_id, int element_id,
                                 char vr_name[],
                                 long data_length, char *data_pointer)
{
   long buflen;
   unsigned char buffer[2*ACR_SIZEOF_SHORT+2*ACR_SIZEOF_LONG];
   Acr_Short grpid, elid, sval;
   Acr_Long datalen;
   int offset;
   Acr_byte_order byte_order;
   Acr_Status status;

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

   /* Get byte ordering */
   byte_order = acr_get_byte_order(afp);

   /* Get the group id and element id */
   offset = 0;
   grpid = (Acr_Short) group_id;
   acr_put_short(byte_order, 1, &grpid, &buffer[offset]);
   offset += ACR_SIZEOF_SHORT;
   elid = (Acr_Short) element_id;
   acr_put_short(byte_order, 1, &elid, &buffer[offset]);
   offset += ACR_SIZEOF_SHORT;

   /* Check data length */
   if ((Acr_Long)data_length == ACR_VARIABLE_LENGTH)
      datalen = ACR_UNDEFINED_ELEMENT_LENGTH;
   else
      datalen = (Acr_Long)data_length;

   /* Check whether we need VR */
   if (acr_get_vr_encoding(afp) == ACR_IMPLICIT_VR) {
      acr_put_long(byte_order, 1, &datalen, &buffer[offset]);
      offset += ACR_SIZEOF_LONG;
   }
   else {
      if (vr_name[0] == '\0') return ACR_NO_VR_SPECIFIED;
      buffer[offset++] = vr_name[0];
      buffer[offset++] = vr_name[1];
      if (!is_special_vr(vr_name)) {
         sval = (Acr_Short) datalen;
         acr_put_short(byte_order, 1, &sval, &buffer[offset]);
         offset += ACR_SIZEOF_SHORT;
      }
      else {
         sval = 0;
         acr_put_short(byte_order, 1, &sval, &buffer[offset]);
         offset += ACR_SIZEOF_SHORT;
         acr_put_long(byte_order, 1, &datalen, &buffer[offset]);
         offset += ACR_SIZEOF_LONG;
         buflen += ACR_SIZEOF_LONG;
      }
   }

   /* Write it out */
   status = acr_write_buffer(afp, buffer, buflen, NULL);
   if (status != ACR_OK) return status;

   if ((data_length == ACR_VARIABLE_LENGTH) || (data_pointer == NULL)) {
      return ACR_OK;
   }

   /* Write out the data */
   status = acr_write_buffer(afp, (unsigned char *) data_pointer, 
                             data_length, NULL);
   if (status != ACR_OK) return status;

   return ACR_OK;
}