/*
 * include needed system headers
 */
#include <stdio.h>       /* include standard i/o library */
#include <stdlib.h>      /* include standard library */
#include <string.h>      /* include string library */
#include <unistd.h>      /* include unix standard library */
#include <sys/types.h>   /* */
#include <sys/stat.h>    /* */
#include <fcntl.h>       /* */
#include <errno.h>       /* error simbol definitions */
#include <time.h>        /* system time definitions */
#include <math.h>        /* math library */


/**
 * Read nbytes at position p of buffer, and fill value
 */

void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value)

{
    char bytes[4];
    int i;

    for(i=0; i<*nbytes; i++) {
	bytes[i] = *(buffer+(*p)-1+i);
    }
    if(*nbytes == 1)
	*value = 0x000000ff & bytes[0];
    if(*nbytes == 2)
	*value = ((bytes[0]<<8)&0x0000ff00) |
	    (bytes[1]&0x000000ff);
    if(*nbytes == 4)
	*value = ((bytes[0]<<24)&0xff000000) |
	    ((bytes[1]<<16)&0x00ff0000) |
	    ((bytes[2]<<8)&0x0000ff00) |
	    (bytes[3]&0x000000ff);

    *p += *nbytes;

    return;
}
