Exemplo n.º 1
0
void comment_add(char **comments, int* length, char *tag, char *val)
{
    char* p=*comments;
    int vendor_length=readint(p, 8);
    int user_comment_list_length=readint(p, 8+4+vendor_length);
    int tag_len=(tag?strlen(tag)+1:0);
    int val_len=strlen(val);
    int len=(*length)+4+tag_len+val_len;

    p=(char*)realloc(p, len);
    if(p==NULL){
        fprintf(stderr, "realloc failed in comment_add()\n");
        exit(1);
    }

    writeint(p, *length, tag_len+val_len);      /* length of comment */
    if(tag){
        memcpy(p+*length+4, tag, tag_len);        /* comment tag */
        (p+*length+4)[tag_len-1] = '=';           /* separator */
    }
    memcpy(p+*length+4+tag_len, val, val_len);  /* comment */
    writeint(p, 8+4+vendor_length, user_comment_list_length+1);
    *comments=p;
    *length=len;
}
Exemplo n.º 2
0
static int listone ( TREE *t, va_list ap )
{
	int x;

	x = writestring (t->Tname);
	if (x == SCMOK)  x = writeint ((int)t->Tmode);
	if (x == SCMOK)  x = writeint ((int)t->Tflags);
	if (x == SCMOK)  x = writeint (t->Tmtime);
	return (x);
}
Exemplo n.º 3
0
void comment_init(char **comments, int* length, char *vendor_string)
{
  int vendor_length = strlen(vendor_string);
  int user_comment_list_length = 0;
  int len= 4 + vendor_length + 4;
  char *p = (char*)safe_malloc(len);

  writeint(p, 0, vendor_length);
  memcpy(p + 4, vendor_string, vendor_length);
  writeint(p, 4 + vendor_length, user_comment_list_length);
  *length = len;
  *comments = p;
}
Exemplo n.º 4
0
static void comment_init(char **comments, int *length, const char *vendor_string) {
    // The 'vendor' field should be the actual encoding library used
    int vendor_length = strlen(vendor_string);
    int user_comment_list_length = 0;
    int len = 8 + 4 + vendor_length + 4;
    char *p = (char *)malloc(len);
    memcpy(p, "OpusTags", 8);
    writeint(p, 8, vendor_length);
    memcpy(p + 12, vendor_string, vendor_length);
    writeint(p, 12 + vendor_length, user_comment_list_length);
    *length = len;
    *comments = p;
}
Exemplo n.º 5
0
i64 write_header(CSA *csa, FILE *f2, int isize)
{
  i64 i,m,k,c;
  int k2;

  m = csa->m;

  k = (blog(max(csa->n+1,csa->sigma-1))+1+8-1)/8;
  printf("k = %d\n", k);
  writeint(1,k,f2); /* #bytes of integer */
  writeint(k,csa->n,f2);   /* length of the text */
  writeint(k,csa->D,f2); /* interval between two SA values stored explicitly */
  writeint(k,csa->D2,f2); /* interval between two inverse SA values stored explicitly */
//  writeint(k,SIGMA,f2);   /* alphabet size */
//  writeint(k,csa->sigma-1,f2);   /* alphabet size */
  writeint(k,csa->sigma,f2);   /* alphabet size */
  writeint(k,csa->m,f2);   /* the number of distinct characters in the text  */
  isize += 1+5*k;

  k2 = blog(csa->sigma-1)+1; // アルファベットを表現するのに必要なビット数
  k2 = (k2+8-1)/8; // アルファベットを表現するのに必要なバイト数

  for (i = 0; i < m; i++) {
    c = csa->AtoC[i];
//    writeint(1,c,f2); /* characters appeared in the text */
    writeint(k2,c,f2); /* characters appeared in the text */
    writeint(k,csa->C[c],f2); /* frequency of characters */
  }
  isize += m*(k+1);

  return isize;
}
Exemplo n.º 6
0
i64 write_header(CSA *csa, FILE *f2, int isize)
{
	i64 i,m,k,c;

	m = csa->m;

	k = (blog(csa->n+1)+1+8-1)/8;
	writeint(1,k,f2); /* #bytes of integer */
	writeint(k,csa->n,f2);   /* length of the text */
	//  writeint(k,csa->L,f2); /* interval between two psi values stored explicitly */
	writeint(k,csa->D,f2); /* interval between two SA values stored explicitly */
	writeint(k,csa->D2,f2); /* interval between two inverse SA values stored explicitly */
	writeint(k,SIGMA,f2);   /* alphabet size */
	writeint(k,csa->m,f2);   /* the number of distinct characters in the text  */
	isize += 1+5*k;

	for (i = 0; i < m; i++) {
		c = csa->AtoC[i];
		writeint(1,c,f2); /* characters appeared in the text */
		writeint(k,csa->C[c],f2); /* frequency of characters */
	}
	isize += m*(k+1);

	return isize;
}
Exemplo n.º 7
0
i64 write_isa(CSA *csa, FILE *f2, int isize)
{
	i64 i,n,D2,k;
	n = csa->n;  D2 = csa->D2;  k = csa->k;
	writeint(1,k,f2); /* #bytes of integer */
	writeint(k,D2,f2); /* interval between two SA values stored explicitly */
	isize += 1+k;
	for (i = 0; i <= (n-1)/D2; i++) {
		display_progressbar("writing isa ",i,(n-1)/D2);
		writeint(k,getuint(csa->ISA,i,k),f2);
		isize += k;
	}
	return isize;
}
Exemplo n.º 8
0
int msgxpatch (void)
{
	int x;
	int i;

	if (server) {
		x = readmsg (MSGXPATCH);
		if (x != SCMOK)  return (x);
		x = readint (&xargc);
		if (x != SCMOK)  return (x);
		xargc += 2;
		xargv = (char **)calloc (sizeof (char *),(unsigned)xargc+1);
		if (xargv == NULL)
			return (SCMERR);
		for (i = 2; i < xargc; i++) {
			x = readstring (&xargv[i]);
			if (x != SCMOK)  return (x);
		}
		x = readmend ();
	} else {
		x = writemsg (MSGXPATCH);
		if (x != SCMOK)  return (x);
		x = writeint (xargc);
		if (x != SCMOK)  return (x);
		for (i = 0; i < xargc; i++) {
			x = writestring (xargv[i]);
			if (x != SCMOK)  return (x);
		}
		x = writemend ();
	}
	return (x);
}
Exemplo n.º 9
0
Arquivo: error.c Projeto: kstephens/Rt
static
void	_print_line( int fd, const char* file, int line ) {
	int	filefd;

	writestring(fd, "in file ");
	writestring(fd, file);
	writestring(fd, " at line ");
	writeint(fd, line);
	writechar(fd, ':');

#ifndef O_TEXT
#define O_TEXT 0
#endif
	if ( (filefd = open(file, O_RDONLY | O_TEXT )) != -1 ) {
		char	c;

		for ( ; line > 1; line -- ) {
			while ( readchar(filefd) != '\n' )
				;
		}

		do {
			writechar(fd, c = readchar(filefd));
		} while ( c != '\n' );
	} else {
		writestring(2, "Couldn't open ");
		writestring(2, file);
		writechar(2, '\n');
	}
}
Exemplo n.º 10
0
i64 write_sa(CSA *csa, FILE *f2, int isize)
{
	i64 i,n,D,k;
	n = csa->n;  D = csa->D;  k = csa->k;
	printf("write_sa n=%ld D=%ld k=%ld\n",n,D,k);
	writeint(1,k,f2); /* #bytes of integer */
	writeint(k,D,f2); /* interval between two SA values stored explicitly */
	isize += 1+k;
	for (i = 0; i <= n/D; i++) {
		display_progressbar("writing sa ",i,n/D);
		//    printf("sa[%ld] = %ld\n",i,getuint(sa->SA,i,k));
		writeint(k,getuint(csa->SA,i,k),f2);
		isize += k;
	}
	return isize;
}
Exemplo n.º 11
0
void comment_init(char **comments, int* length, char *vendor_string)
{
  int vendor_length=strlen(vendor_string);
  int user_comment_list_length=0;
  int len=4+vendor_length+4;
  char *p=(char*)malloc(len);
  if(p==NULL){
     fprintf (stderr, "malloc failed in comment_init()\n");
     exit(1);
  }
  writeint(p, 0, vendor_length);
  memcpy(p+4, vendor_string, vendor_length);
  writeint(p, 4+vendor_length, user_comment_list_length);
  *length=len;
  *comments=p;
}
Exemplo n.º 12
0
int msglist (void)
{
	int x;
	if (server) {
		x = writemsg (MSGLIST);
		if (x == SCMOK)  x = Tprocess (listT,listone);
		if (x == SCMOK)  x = writestring ((char *)NULL);
		if (x == SCMOK)  x = writeint ((int)scantime);
		if (x == SCMOK)  x = writemend ();
	} else {
		char *name;
		int mode,flags,mtime;
		TREE *t;
		x = readmsg (MSGLIST);
		if (x == SCMOK)  x = readstring (&name);
		while (x == SCMOK) {
			if (name == NULL)  break;
			x = readint (&mode);
			if (x == SCMOK)  x = readint (&flags);
			if (x == SCMOK)  x = readint (&mtime);
			if (x != SCMOK)  break;
			t = Tinsert (&listT,name,TRUE);
			free (name);
			t->Tmode = mode;
			t->Tflags = flags;
			t->Tmtime = mtime;
			x = readstring (&name);
		}
		if (x == SCMOK)  x = readint ((int *)&scantime);
		if (x == SCMOK)  x = readmend ();
	}
	return (x);
}
Exemplo n.º 13
0
static int needone ( TREE *t, va_list ap )
{
	int x;
	x = writestring (t->Tname);
	if (x == SCMOK)  x = writeint ((t->Tflags&FUPDATE) != 0);
	return (x);
}
Exemplo n.º 14
0
void loop(int c)
{
  int d;
  for (d=0; d<c; d++)
  {
    writeint(d);
    writechar('\n');
  }
}
Exemplo n.º 15
0
static void comment_init(char **comments, int* length, const char *vendor_string)
{
    /*The 'vendor' field should be the actual encoding library used.*/
    int vendor_length=strlen(vendor_string);
    int user_comment_list_length=0;
    int len=8+4+vendor_length+4;
    char *p=(char*)malloc(len);
    if(p==NULL){
        fprintf(stderr, "malloc failed in comment_init()\n");
        exit(1);
    }
    memcpy(p, "OpusTags", 8);
    writeint(p, 8, vendor_length);
    memcpy(p+12, vendor_string, vendor_length);
    writeint(p, 12+vendor_length, user_comment_list_length);
    *length=len;
    *comments=p;
}
Exemplo n.º 16
0
void writetwodig (SLOT *sp, int i)
{
  if (i >= 100)
    writeint (sp, i);
  else {
    writech (sp, i / 10 + '0');
    writech (sp, i % 10 + '0');
  }
}
Exemplo n.º 17
0
int main(int argc, char* argv[])
{
  char* x = "Hello world\n";
  writestring(x);
  writeint(12345);
  writechar('\n');
  loop(1000);
  return 0;
}
Exemplo n.º 18
0
int msgsignon (void)
{
	int x;

	if (server) {
		x = readmsg (MSGSIGNON);
		if (x == SCMOK)  x = readint (&protver);
		if (x == SCMOK)  x = readint (&pgmver);
		if (x == SCMOK)  x = readstring (&scmver);
		if (x == SCMOK)  x = readmend ();
	} else {
		x = writemsg (MSGSIGNON);
		if (x == SCMOK)  x = writeint (PROTOVERSION);
		if (x == SCMOK)  x = writeint (pgmversion);
		if (x == SCMOK)  x = writestring (scmversion);
		if (x == SCMOK)  x = writemend ();
	}
	return (x);
}
Exemplo n.º 19
0
int msgsignonack ()
{
	register int x;

	if (server) {
		x = writemsg (MSGSIGNONACK);
		if (x == SCMOK)  x = writeint (PROTOVERSION);
		if (x == SCMOK)  x = writeint (pgmversion);
		if (x == SCMOK)  x = writestring (scmversion);
		if (x == SCMOK)  x = writeint (fspid);
		if (x == SCMOK)  x = writemend ();
	} else {
		x = readmsg (MSGSIGNONACK);
		if (x == SCMOK)  x = readint (&protver);
		if (x == SCMOK)  x = readint (&pgmver);
		if (x == SCMOK)  x = readstring (&scmver);
		if (x == SCMOK)  x = readint (&fspid);
		if (x == SCMOK)  x = readmend ();
	}
	return (x);
}
Exemplo n.º 20
0
void L298N::set(int in1, int in2, int in3, int in4, int ena, int enb) {
	if (!_valid) {
		return;
	}
	
	#ifdef DEBUG
		std::cout << "Set(" << in1 << ", " << in2 << ", " << in3 << ", " << in4 << ", " << ena << ", " << enb << ")" << std::endl;
	#endif
	
	/*writeint(_fd1, in1);
	writeint(_fd2, in2);
	writeint(_fd3, in3);
	writeint(_fd4, in4);*/
	_in1->set(in1);
	_in2->set(in2);
	_in3->set(in3);
	_in4->set(in4);
	
	writeint(_fda, ena);
	writeint(_fdb, enb);
}
Exemplo n.º 21
0
void comment_add(char **comments, int* length, char *tag, char *val)
{
  char* p=*comments;
  int vendor_length=readint(p, 0);
  int user_comment_list_length=readint(p, 4+vendor_length);
  int tag_len=(tag?strlen(tag):0);
  int val_len=strlen(val);
  int len=(*length)+4+tag_len+val_len;

  p=(char*)realloc(p, len);
  if(p==NULL){
  }

  writeint(p, *length, tag_len+val_len);      /* length of comment */
  if(tag) memcpy(p+*length+4, tag, tag_len);  /* comment */
  memcpy(p+*length+4+tag_len, val, val_len);  /* comment */
  writeint(p, 4+vendor_length, user_comment_list_length+1);

  *comments=p;
  *length=len;
}
Exemplo n.º 22
0
void dump_userinfoshort (ACCOUNT *acct, int logged_in)
{
  ACCOUNT *cur_acct;
  long idle, hours, mins, secs;

  cur_acct = &cur_slot->acct;

  writestr (cur_slot, "Login/Handle: ");
  begin_color (cur_slot, acct->msgcolor);
  writestr (cur_slot, acct->id);
  writech (cur_slot, '/');
  writestr (cur_slot, acct->handle);
  reset_attr (cur_slot);

  writestr (cur_slot, "\nChannel: ");
  if (cur_acct->level == TOPLEVEL  ||
      channels[acct->chan].name    ||
      acct->chan == cur_acct->chan ||
      !strcmp(acct->id, cur_acct->id)) {
    writeint (cur_slot, acct->chan);
    writestr (cur_slot, "\n");
  } else
    writestr (cur_slot, "**\n");

  if (cur_acct->level >= 2 ||
      acct->email_public   ||
      !strcmp(acct->id, cur_acct->id)) {
    writestr (cur_slot, "Email address is ");
    writestr (cur_slot, acct->email_address);
    writestr (cur_slot, acct->email_public ? " [public]\n" : " [private]\n");
  } else
    writestr (cur_slot, "Email address is *PRIVATE*\n");

  writestr (cur_slot, "Last logout: ");
  writestr (cur_slot, ctime(&acct->last_logout));

  if (logged_in) {
    /* calculate idle time if the user is logged in */
    idle = time (NULL) - acct->last_typed;
    hours = idle / 3600;
    idle -= hours * 3600;
    mins = idle / 60;
    secs = idle - (mins * 60);
    sprintf (msg_buf, "Last typed: %.24s (idle: %dh %02dm %02ds)\n",
             ctime(&acct->last_typed), hours, mins, secs);
    writestr (cur_slot, msg_buf);
  } else {
    writestr (cur_slot, "Last typed: ");
    writestr (cur_slot, ctime(&acct->last_typed));
  }
}
Exemplo n.º 23
0
void SpeexEncoder::comment_add(char **comments, int* length, char *tag, char *val)
{
	char* p = *comments;
	int vendor_length = readint(p, 0);
	int user_comment_list_length = readint(p, 4 + vendor_length);
	int tag_len = (tag ? strlen(tag) : 0);
	int val_len = strlen(val);
	int len = (*length) + 4 + tag_len + val_len;

	p = (char*)realloc(p, len);
	if (p == NULL){
		fprintf(stderr, "realloc failed in comment_add()\n");
		exit(1);
	}

	writeint(p, *length, tag_len + val_len);      /* length of comment */
	if (tag) memcpy(p + *length + 4, tag, tag_len);  /* comment */
	memcpy(p + *length + 4 + tag_len, val, val_len);  /* comment */
	writeint(p, 4 + vendor_length, user_comment_list_length + 1);

	*comments = p;
	*length = len;
}
Exemplo n.º 24
0
int main()
{

    int i;
    
    quicksort(nums, NUM_ELEM(nums));
    
    #ifdef IO
    for (i = 0; i < NUM_ELEM(nums); ++i) {
        writeint(nums[i]);
    }
    #endif
    
    asm("swi 0x11");
}
Exemplo n.º 25
0
int msglogack (void)
{
	int x;
	if (server) {
		x = writemsg (MSGLOGACK);
		if (x == SCMOK)  x = writeint (logack);
		if (x == SCMOK)  x = writestring (logerror);
		if (x == SCMOK)  x = writemend ();
	} else {
		x = readmsg (MSGLOGACK);
		if (x == SCMOK)  x = readint (&logack);
		if (x == SCMOK)  x = readstring (&logerror);
		if (x == SCMOK)  x = readmend ();
	}
	return (x);
}
Exemplo n.º 26
0
int msgsetup (void)
{
	int x;

	if (server) {
		x = readmsg (MSGSETUP);
		if (x != SCMOK)  return (x);
		if (protver >= 7) {
			x = readint (&xpatch);
			if (x != SCMOK)  return (x);
		} else
			xpatch = FALSE;
		if (xpatch) {
			x = readstring (&xuser);
			if (x != SCMOK)  return (x);
			return (readmend ());
		}
		x = readstring (&collname_g);
		if (x == SCMOK)  x = readint ((int *)&lasttime);
		if (x == SCMOK)  x = readstring (&basedir_g);
		if (x == SCMOK)  x = readint (&basedev);
		if (x == SCMOK)  x = readint (&baseino);
		if (x == SCMOK)  x = readint (&listonly);
		if (x == SCMOK)  x = readint (&newonly);
		if (x == SCMOK)
			if (protver < 6)
				release = (char *)NULL;
			else
				x = readstring (&release);
		if (x == SCMOK)  x = readmend ();
	} else {
		x = writemsg (MSGSETUP);
		if (x != SCMOK)  return (x);
		if (protver >= 7) {
			x = writeint (xpatch);
			if (x != SCMOK)  return (x);
		}
		if (xpatch) {
			x = writestring (xuser);
			if (x != SCMOK)  return (x);
			return (writemend ());
		}
		if (x == SCMOK)  x = writestring (collname_g);
		if (x == SCMOK)  x = writeint ((int)lasttime);
		if (x == SCMOK)  x = writestring (basedir_g);
		if (x == SCMOK)  x = writeint (basedev);
		if (x == SCMOK)  x = writeint (baseino);
		if (x == SCMOK)  x = writeint (listonly);
		if (x == SCMOK)  x = writeint (newonly);
		if (x == SCMOK && protver >= 6)  x = writestring (release);
		if (x == SCMOK)  x = writemend ();
	}
	return (x);
}
Exemplo n.º 27
0
void paabout (SLOT *sl, char *msg)
{
  SLOT *sp;
  SLOT_LIST *slist;

  write_log_paabout (sl, msg);

  slist = channels[MAINLIST].members;
  while (slist) {
    sp = slist->slot;

    if (sp && (sp->acct.pa_notify || 
               (sl->acct.chan == sp->acct.chan))) {
      select_stop (sp);
      select_wrap (sp);
      begin_color (sp, sl->acct.msgcolor);
      if (slots_f) {
        writestr (sp, "-- #");
        writeint (sp, sl->nslot);
      } else {
        writestr (sp, "--");
      }
      writech (sp, ' ');
      writestr (sp, msg);
      writestr (sp, " channel ");
      if (sl->acct.chan == sp->acct.chan || 
          sl->flags.listed || sl->acct.chan == 1 ||
          sp->acct.level > 2)
        writetwodig (sp, sl->acct.chan);
      else
        writestr (sp, "**");
      writestr (sp, ": ");
      writestr (sp, sl->acct.id);
      writech (sp, '/');
      writestr (sp, sl->acct.handle);
      reset_attr (sp);
      writech (sp, '\n');
      clear_stop (sp);
      clear_wrap (sp);
    }
    slist = slist->next;
  }
}
Exemplo n.º 28
0
int msgdone (void)
{
	int x;

	if (protver < 6) {
		printf ("Error, msgdone should not have been called.");
		return (SCMERR);
	}
	if (server) {
		x = readmsg (MSGDONE);
		if (x == SCMOK)  x = readint (&doneack);
		if (x == SCMOK)  x = readstring (&donereason);
		if (x == SCMOK)  x = readmend ();
	} else {
		x = writemsg (MSGDONE);
		if (x == SCMOK)  x = writeint (doneack);
		if (x == SCMOK)  x = writestring (donereason);
		if (x == SCMOK)  x = writemend ();
	}
	return (x);
}
void saveFaceGraph(char *filename, FaceGraph fg){
    int i, j;
    FILE* file = fopen(filename,"wb");
    assert(file);
    /* Write out the size */
    writeint(file, fg->geosize);
    writeint(file, fg->totalsize);
    writeint(file, fg->params != NULL);
    if(fg->params) {
        writeint (file, fg->params->length);
        for(i = 0; i < fg->params->length; i++){
            writereal(file, fg->params->wavelength[i]);
            writereal(file, fg->params->angle[i]);
            writereal(file, fg->params->phase[i]);
            writereal(file, fg->params->aspect[i]);
            writereal(file, fg->params->radius[i]);
            writeint (file, fg->params->size[i]);
            writereal(file, fg->params->kx[i]);
            writereal(file, fg->params->ky[i]);
        }
    }

    for(i = 0; i < fg->totalsize; i++){
        /* write out jet i */
        writeint(file, fg->jets[i]->length);
        writereal(file, fg->jets[i]->x);
        writereal(file, fg->jets[i]->y);
        for(j = 0; j < fg->jets[i]->length; j++){
            writereal(file, fg->jets[i]->realPart[j]);
            writereal(file, fg->jets[i]->imagPart[j]);
            writereal(file, fg->jets[i]->mag[j]);
            writereal(file, fg->jets[i]->ang[j]);
        }
    }
    
    fclose(file);
}
Exemplo n.º 30
0
static int encode(char *outfile, long *nlength, int a[], int nx, int ny, int scale)
{

/* FILE *outfile;  - change outfile to a char array */  
/*
  long * nlength    returned length (in bytes) of the encoded array)
  int a[];								 input H-transform array (nx,ny)
  int nx,ny;								 size of H-transform array	
  int scale;								 scale factor for digitization
*/
int nel, nx2, ny2, i, j, k, q, vmax[3], nsign, bits_to_go;
unsigned char nbitplanes[3];
unsigned char *signbits;
int stat;

        noutchar = 0;  /* initialize the number of compressed bytes that have been written */
	nel = nx*ny;
	/*
	 * write magic value
	 */
	qwrite(outfile, code_magic, sizeof(code_magic));
	writeint(outfile, nx);			/* size of image */
	writeint(outfile, ny);
	writeint(outfile, scale);		/* scale factor for digitization */
	/*
	 * write first value of A (sum of all pixels -- the only value
	 * which does not compress well)
	 */
	writelonglong(outfile, (LONGLONG) a[0]);

	a[0] = 0;
	/*
	 * allocate array for sign bits and save values, 8 per byte
	 */
	signbits = (unsigned char *) malloc((nel+7)/8);
	if (signbits == (unsigned char *) NULL) {
		ffpmsg("encode: insufficient memory");
		return(DATA_COMPRESSION_ERR);
	}
	nsign = 0;
	bits_to_go = 8;
	signbits[0] = 0;
	for (i=0; i<nel; i++) {
		if (a[i] > 0) {
			/*
			 * positive element, put zero at end of buffer
			 */
			signbits[nsign] <<= 1;
			bits_to_go -= 1;
		} else if (a[i] < 0) {
			/*
			 * negative element, shift in a one
			 */
			signbits[nsign] <<= 1;
			signbits[nsign] |= 1;
			bits_to_go -= 1;
			/*
			 * replace a by absolute value
			 */
			a[i] = -a[i];
		}
		if (bits_to_go == 0) {
			/*
			 * filled up this byte, go to the next one
			 */
			bits_to_go = 8;
			nsign += 1;
			signbits[nsign] = 0;
		}
	}
	if (bits_to_go != 8) {
		/*
		 * some bits in last element
		 * move bits in last byte to bottom and increment nsign
		 */
		signbits[nsign] <<= bits_to_go;
		nsign += 1;
	}
	/*
	 * calculate number of bit planes for 3 quadrants
	 *
	 * quadrant 0=bottom left, 1=bottom right or top left, 2=top right, 
	 */
	for (q=0; q<3; q++) {
		vmax[q] = 0;
	}
	/*
	 * get maximum absolute value in each quadrant
	 */
	nx2 = (nx+1)/2;
	ny2 = (ny+1)/2;
	j=0;	/* column counter	*/
	k=0;	/* row counter		*/
	for (i=0; i<nel; i++) {
		q = (j>=ny2) + (k>=nx2);
		if (vmax[q] < a[i]) vmax[q] = a[i];
		if (++j >= ny) {
			j = 0;
			k += 1;
		}
	}
	/*
	 * now calculate number of bits for each quadrant
	 */

        /* this is a more efficient way to do this, */
 
 
        for (q = 0; q < 3; q++) {
            for (nbitplanes[q] = 0; vmax[q]>0; vmax[q] = vmax[q]>>1, nbitplanes[q]++) ; 
        }


/*
	for (q = 0; q < 3; q++) {
		nbitplanes[q] = (int) (log((float) (vmax[q]+1))/log(2.0)+0.5);
		if ( (vmax[q]+1) > (1<<nbitplanes[q]) ) {
			nbitplanes[q] += 1;
		}
	}
*/

	/*
	 * write nbitplanes
	 */
	if (0 == qwrite(outfile, (char *) nbitplanes, sizeof(nbitplanes))) {
	        *nlength = noutchar;
		ffpmsg("encode: output buffer too small");
		return(DATA_COMPRESSION_ERR);
        }
	 
	/*
	 * write coded array
	 */
	stat = doencode(outfile, a, nx, ny, nbitplanes);
	/*
	 * write sign bits
	 */

	if (nsign > 0) {

	   if ( 0 == qwrite(outfile, (char *) signbits, nsign)) {
	        free(signbits);
	        *nlength = noutchar;
		ffpmsg("encode: output buffer too small");
		return(DATA_COMPRESSION_ERR);
          }
	} 
	
	free(signbits);
	*nlength = noutchar;

        if (noutchar >= noutmax) {
		ffpmsg("encode: output buffer too small");
		return(DATA_COMPRESSION_ERR);
        }  
	
	return(stat); 
}