[R-gregmisc-users] SF.net SVN: r-gregmisc:[1848] trunk/SASxport/src
Brought to you by:
warnes
From: <wa...@us...> - 2014-07-20 02:05:41
|
Revision: 1848 http://sourceforge.net/p/r-gregmisc/code/1848 Author: warnes Date: 2014-07-20 02:05:33 +0000 (Sun, 20 Jul 2014) Log Message: ----------- Rename 'host_to_be' to 'to_bigend' to be more transparent about purpose Modified Paths: -------------- trunk/SASxport/src/SASxport.c trunk/SASxport/src/SASxport.h trunk/SASxport/src/ibm2ieee.c trunk/SASxport/src/ieee2ibm.c Added Paths: ----------- trunk/SASxport/src/ibm2ieee.h Modified: trunk/SASxport/src/SASxport.c =================================================================== --- trunk/SASxport/src/SASxport.c 2014-07-20 02:01:34 UTC (rev 1847) +++ trunk/SASxport/src/SASxport.c 2014-07-20 02:05:33 UTC (rev 1848) @@ -48,7 +48,7 @@ #define BLANK24 " " #define GET_RECORD(rec, fp, len) \ - fread((rec), sizeof(char), (size_t) (len), (fp)) + (int) fread((rec), sizeof(char), (size_t) (len), (fp)) #define IS_SASNA_CHAR(c) ((c) == 0x5f || (c) == 0x2e || \ (0x41 <= (c) && (c) <= 0x5a)) @@ -80,9 +80,11 @@ /* exponent is expressed here as excess 70 (=64+6) to accomodate integer conversion of c[1] to c[4] */ - char negative = c[0] & 0x80, exponent = (c[0] & 0x7f) - 70, buf[4]; + char negative = c[0] & 0x80; + // needs to be signed: char is not on Raspbian + signed char exponent = (c[0] & 0x7f) - 70; double value; - char ibuf[8]; + char buf[4], ibuf[8]; if (len < 2 || len > 8) error(_("invalid field length in numeric variable")); @@ -258,9 +260,8 @@ record[58] = '\0'; sscanf(record+54, "%d", &length); - /* Extract data set name */ tmp = strchr(mem_head->sas_dsname, ' '); - n = tmp - mem_head->sas_dsname; + n = (int)(tmp - mem_head->sas_dsname); if(n > 0) { if (n > 8) n = 8; @@ -290,7 +291,9 @@ } static int -next_xport_info(FILE *fp, int namestr_length, int nvars, +next_xport_info(FILE *fp, + int namestr_length, + int nvars, int *headpad, int *tailpad, int *length, @@ -586,7 +589,7 @@ ansLength = 0; PROTECT(ans = allocVector(VECSXP, 0)); - PROTECT(ansNames = allocVector(STRSXP, 0)); + PROTECT(ansNames = allocVector(STRSXP, 0)); while(!feof(fp)) { @@ -689,6 +692,7 @@ char *record, *tmpchar, *c; FILE *fp; SEXP ans, names, data, dataInfo, dataName; + double dbl; ansLength = LENGTH(xportInfo); PROTECT(ans = allocVector(VECSXP, ansLength)); @@ -736,8 +740,19 @@ for(k = nvar-1; k >= 0; k--) { tmpchar = record + dataPosition[k]; if(dataType[k] == REALSXP) { - REAL(VECTOR_ELT(data, k))[j] = - get_IBM_double(tmpchar, dataWidth[k]); + + /* REAL(VECTOR_ELT(data, k))[j] = */ + /* get_IBM_double(tmpchar, dataWidth[k]); */ + + ibm2ieee( (unsigned char*) &dbl, + (unsigned char*) tmpchar, + 1 ); + + /* convert from big-endian layout */ + to_bigend( (unsigned char*) &dbl, sizeof(double) ); + + REAL(VECTOR_ELT(data, k))[j] = dbl; + } else { tmpchar[dataWidth[k]] = '\0'; /* strip trailing blanks */ Modified: trunk/SASxport/src/SASxport.h =================================================================== --- trunk/SASxport/src/SASxport.h 2014-07-20 02:01:34 UTC (rev 1847) +++ trunk/SASxport/src/SASxport.h 2014-07-20 02:05:33 UTC (rev 1848) @@ -28,6 +28,8 @@ #include "foreign.h" #include "swap_bytes.h" #include <errno.h> +#include "to_bigend.h" +#include "ibm2ieee.h" /* double cnxptiee(double from, int fromtype, int totype); */ Modified: trunk/SASxport/src/ibm2ieee.c =================================================================== --- trunk/SASxport/src/ibm2ieee.c 2014-07-20 02:01:34 UTC (rev 1847) +++ trunk/SASxport/src/ibm2ieee.c 2014-07-20 02:05:33 UTC (rev 1848) @@ -22,8 +22,8 @@ * information. */ -#include "writeSAS.h" #include <stdio.h> +#include "ibm2ieee.h" /**************************** * ibm2ieee @@ -40,29 +40,6 @@ * ***************************/ -#define OUT_IEEE_ZERO { \ - *out++ = 0; \ - *out++ = 0; \ - *out++ = 0; \ - *out++ = 0; \ - *out++ = 0; \ - *out++ = 0; \ - *out++ = 0; \ - *out++ = 0; \ - continue; } \ - -#define OUT_IEEE_NAN { /* Signaling NAN */ \ - *out++ = 0xFF; \ - *out++ = 0xF0; \ - *out++ = 0x0B; \ - *out++ = 0xAD; \ - *out++ = 0x0B; \ - *out++ = 0xAD; \ - *out++ = 0x0B; \ - *out++ = 0xAD; \ - continue; } \ - - void ibm2ieee(register unsigned char *out, register const unsigned char *in, int count) Added: trunk/SASxport/src/ibm2ieee.h =================================================================== --- trunk/SASxport/src/ibm2ieee.h (rev 0) +++ trunk/SASxport/src/ibm2ieee.h 2014-07-20 02:05:33 UTC (rev 1848) @@ -0,0 +1,62 @@ +/* + * File: SASxport/src/ibm2ieee.h + * + * Originally from BRL-CAD file /brlcad/src/libbu/htond.c + * + * Copyright (c) 2004-2007 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * * Minor changes (c) 2007 by Gregory R. Warnes <gr...@wa...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +#ifndef IBM2IEEE_H +#define IBM2IEEE_H + +#include <R.h> +#include <Rinternals.h> + +#define OUT_IEEE_ZERO { \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + continue; } \ + +#define OUT_IEEE_NAN { /* Signaling NAN */ \ + *out++ = 0xFF; \ + *out++ = 0xF0; \ + *out++ = 0x0B; \ + *out++ = 0xAD; \ + *out++ = 0x0B; \ + *out++ = 0xAD; \ + *out++ = 0x0B; \ + *out++ = 0xAD; \ + continue; } \ + + +void ieee2ibm(register unsigned char *out, + register const unsigned char *in, + int count); + +void ibm2ieee(register unsigned char *out, + register const unsigned char *in, + int count); + + +#endif /* IBM2IEEE_H */ Modified: trunk/SASxport/src/ieee2ibm.c =================================================================== --- trunk/SASxport/src/ieee2ibm.c 2014-07-20 02:01:34 UTC (rev 1847) +++ trunk/SASxport/src/ieee2ibm.c 2014-07-20 02:05:33 UTC (rev 1848) @@ -22,8 +22,8 @@ * information. */ -#include "writeSAS.h" #include <stdio.h> +#include "ibm2ieee.h" /**************************** * ieee2ibm This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |