summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>1997-09-15 19:07:03 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>1997-09-15 19:07:03 (GMT)
commitfec4cf898953d2a95401c9fabb6b730c22b2a1b6 (patch)
tree9171d889e8980fdb1ccae7c6d9fa4cc151068e9f
parentdcdc0d7dfff8359ef5bdb65551b23a166a75a116 (diff)
downloadhdf5-fec4cf898953d2a95401c9fabb6b730c22b2a1b6.zip
hdf5-fec4cf898953d2a95401c9fabb6b730c22b2a1b6.tar.gz
hdf5-fec4cf898953d2a95401c9fabb6b730c22b2a1b6.tar.bz2
[svn-r81] Finished basic data-type conversions, files are now portably written on most
"normal" architectures.
-rw-r--r--src/H5D.c41
-rw-r--r--src/H5Dprivate.h2
-rw-r--r--src/H5Tpublic.h17
-rw-r--r--src/Makefile.in2
4 files changed, 55 insertions, 7 deletions
diff --git a/src/H5D.c b/src/H5D.c
index 995d741..8316a9d 100644
--- a/src/H5D.c
+++ b/src/H5D.c
@@ -387,6 +387,8 @@ done:
herr_t H5Dread(hatom_t oid, hatom_t did, VOIDP buf)
{
H5D_dataset_t *dataset; /* dataset object to do I/O on */
+ void *readbuf; /* pointer to buffer to write out */
+ uintn free_buf=0; /* if temporary conversion buffer needs to be free'd */
uintn toread; /* number of bytes to read in */
herr_t ret_value = SUCCEED;
@@ -415,12 +417,24 @@ herr_t H5Dread(hatom_t oid, hatom_t did, VOIDP buf)
else
HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
-/* Check memory to disk datatype conversions, etc. */
-/* DO THIS! -QAK */
+ /* Check memory to disk datatype conversions, etc. */
+/* This is totally hacked up code, but I'm in a hurry. ;-/ -QAK */
+ if(dataset->type->dt.arch!=H5T_ARCH_TYPE)
+ {
+ if((readbuf=HDmalloc(toread))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
+ free_buf=1;
+ } /* end if */
+ else
+ readbuf=buf;
+
/* Write the data out to disk */
- if(H5F_block_read(dataset->file,dataset->data,toread,buf)==FAIL)
+ if(H5F_block_read(dataset->file,dataset->data,toread,readbuf)==FAIL)
HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL);
+
+ if(free_buf!=0)
+ H5D_convert_buf(buf,readbuf,toread,dataset->type->dt.len);
done:
if(ret_value == FAIL)
@@ -429,6 +443,8 @@ done:
} /* end if */
/* Normal function cleanup */
+ if(free_buf!=0) /* check if we need to release the conversion buffer */
+ HDfree(readbuf);
FUNC_LEAVE(ret_value);
} /* end H5Dread() */
@@ -456,6 +472,8 @@ herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf)
{
H5D_dataset_t *dataset; /* dataset object to do I/O on */
uintn towrite; /* number of bytes to write out */
+ void *writebuf; /* pointer to buffer to write out */
+ uintn free_buf=0; /* if temporary conversion buffer needs to be free'd */
herr_t ret_value = SUCCEED;
FUNC_ENTER(H5Dwrite, H5D_init_interface, FAIL);
@@ -488,11 +506,20 @@ herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf)
if((dataset->data=H5MF_alloc(dataset->file,towrite))==FAIL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
-/* Check memory to disk datatype conversions, etc. */
-/* DO THIS! -QAK */
+ /* Check memory to disk datatype conversions, etc. */
+/* This is totally hacked up code, but I'm in a hurry. ;-/ -QAK */
+ if(dataset->type->dt.arch!=H5T_ARCH_TYPE)
+ {
+ if((writebuf=HDmalloc(towrite))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
+ H5D_convert_buf(writebuf,buf,towrite,dataset->type->dt.len);
+ free_buf=1;
+ } /* end if */
+ else
+ writebuf=buf;
/* Write the data out to disk */
- if(H5F_block_write(dataset->file,dataset->data,towrite,buf)==FAIL)
+ if(H5F_block_write(dataset->file,dataset->data,towrite,writebuf)==FAIL)
HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL);
done:
@@ -502,6 +529,8 @@ done:
} /* end if */
/* Normal function cleanup */
+ if(free_buf!=0) /* check if we need to release the conversion buffer */
+ HDfree(writebuf);
FUNC_LEAVE(ret_value);
} /* end H5Dwrite() */
diff --git a/src/H5Dprivate.h b/src/H5Dprivate.h
index 83a090f..beb982e 100644
--- a/src/H5Dprivate.h
+++ b/src/H5Dprivate.h
@@ -57,5 +57,7 @@ hatom_t H5D_access(hatom_t oid);
hatom_t H5D_find_name(hatom_t owner_id, hobjtype_t type, const char *name);
herr_t H5D_flush(hatom_t oid);
herr_t H5D_release(hatom_t oid);
+/* in H5Dconv.c */
+herr_t H5D_convert_buf(void *dst,const void *src,uintn len,uintn size);
#endif
diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h
index 60686fa..daca824 100644
--- a/src/H5Tpublic.h
+++ b/src/H5Tpublic.h
@@ -37,6 +37,23 @@
#define H5T_BIGENDIAN 0
#define H5T_LITTLEENDIAN 1
+/* Define the machine's architecture */
+/*
+WARNING!
+ This is _extremly_ crude is is only valid for very generic architectures,
+ anything with a wierd size of integer or wacky floating-point format will
+ _not_ work with this hack. It needs to be replaced with Robb's much more
+ comprehensive code from H5detect.c. -QAK
+WARNING!
+*/
+#define H5T_ARCH_BIGENDIAN 0
+#define H5T_ARCH_LITTLEENDIAN 1
+#ifdef WORDS_BIGENDIAN
+#define H5T_ARCH_TYPE H5T_ARCH_BIGENDIAN
+#else /* WORDS_BIGENDIAN */
+#define H5T_ARCH_TYPE H5T_ARCH_LITTLEENDIAN
+#endif /* WORDS_BIGENDIAN */
+
typedef struct {
hatom_t base; /* Basic datatype */
uint8 len; /* Length of base-type, in bytes */
diff --git a/src/Makefile.in b/src/Makefile.in
index 33aef36..4136a0c 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -16,7 +16,7 @@ PROGS=debug
# Source and object files for the library (lexicographically)...
LIB_SRC=H5.c H5A.c H5AC.c H5B.c H5C.c H5D.c H5E.c H5F.c H5G.c H5Gnode.c \
H5H.c H5M.c H5MF.c H5MM.c H5O.c H5Ocont.c H5Oname.c H5Onull.c \
- H5Ostab.c H5Osdtyp.c H5Osdim.c H5P.c H5T.c H5Ostdst.c
+ H5Ostab.c H5Osdtyp.c H5Osdim.c H5P.c H5T.c H5Ostdst.c H5Dconv.c
LIB_OBJ=$(LIB_SRC:.c=.o)
# Source and object files for programs...