Exemplo n.º 1
0
static void write_double(FILE *fp, int swap_flag, double x)
{
    if (swap_flag)
	swap_8(&x);

    if (fwrite(&x, 8, 1, fp) != 1)
	G_fatal_error(_("Error writing data"));
}
Exemplo n.º 2
0
static int swap_element(int nbr, int tokensize)
{
  if(*little_endian)
    {
      if(tokensize == FOUR_BYTES)
        swap_4(nbr);
      
      if(tokensize == EIGHT_BYTES)
        swap_8(nbr);
      
    }
  
  return nbr;
}
Exemplo n.º 3
0
static void convert_cell(
    unsigned char *out_cell, const DCELL in_cell,
    int is_fp, int bytes, int swap_flag)
{
    if (is_fp) {
	switch (bytes) {
	case 4:
	    *(float *) out_cell = (float) in_cell;
	    break;
	case 8:
	    *(double *) out_cell = (double) in_cell;
	    break;
	}
    }
    else {
	switch (bytes) {
	case 1:
	    *(unsigned char *) out_cell = (unsigned char) in_cell;
	    break;
	case 2:
	    *(short *) out_cell = (short) in_cell;
	    break;
	case 4:
	    *(int *) out_cell = (int) in_cell;
	    break;
#ifdef HAVE_LONG_LONG_INT
	case 8:
	    *(long long *) out_cell = (long long) in_cell;
	    break;
#endif
	}
    }

    if (swap_flag) {
	switch (bytes) {
	case 1:				break;
	case 2:	swap_2(out_cell);	break;
	case 4:	swap_4(out_cell);	break;
	case 8:	swap_8(out_cell);	break;
	}
    }
}
Exemplo n.º 4
0
static void read_cell(DCELL *out_cell, int is_integer, int is_signed, int bytes,
		int byte_swap) {

	if (fread(in_cell, bytes, 1, fp) != 1)
		G_fatal_error(_("Error reading binary data"));

	if (byte_swap) {
		switch (bytes) {
		case 1:
			break;
		case 2:
			swap_2(in_cell);
			break;
		case 4:
			swap_4(in_cell);
			break;
		case 8:
			swap_8(in_cell);
			break;
		}
	}

	if (!is_integer) {
		switch (bytes) {
		case 4:
			*out_cell = (DCELL) *(float *) in_cell;
			break;
		case 8:
			*out_cell = (DCELL) *(double *) in_cell;
			break;
		}
	} else if (is_signed) {
		switch (bytes) {
		case 1:
			*out_cell = (DCELL) *(signed char *) in_cell;
			break;
		case 2:
			*out_cell = (DCELL) *(short *) in_cell;
			break;
		case 4:
			*out_cell = (DCELL) *(int *) in_cell;
			break;
#ifdef HAVE_LONG_LONG_INT
		case 8:
			*out_cell = (DCELL) *(long long *) in_cell;
			break;
#endif
		}
	} else {
		switch (bytes) {
		case 1:
			*out_cell = (DCELL) *(unsigned char *) in_cell;
			break;
		case 2:
			*out_cell = (DCELL) *(unsigned short *) in_cell;
			break;
		case 4:
			*out_cell = (DCELL) *(unsigned int *) in_cell;
			break;
#ifdef HAVE_LONG_LONG_INT
		case 8:
			*out_cell = (DCELL) *(unsigned long long *) in_cell;
			break;
#endif
		}
	}
}