Main Page   Compound List   File List   Compound Members   File Members  

rr_libs/rr_fread.c

Go to the documentation of this file.
00001 /* rr_fread() */
00002 /*=====================================================================
00003                 =======   COPYRIGHT NOTICE   =======
00004 Copyright (C) 1994, Carnegie Mellon University and Ronald Rosenfeld.
00005 All rights reserved.
00006 
00007 This software is made available for research purposes only.  It may be
00008 redistributed freely for this purpose, in full or in part, provided
00009 that this entire copyright notice is included on any copies of this
00010 software and applications and derivations thereof.
00011 
00012 This software is provided on an "as is" basis, without warranty of any
00013 kind, either expressed or implied, as to any matter including, but not
00014 limited to warranty of fitness of purpose, or merchantability, or
00015 results obtained from use of this software.
00016 ======================================================================*/
00017 
00018 /* call fread and quit if it fails 
00019    Also SWAP the data if read on a MIPS machine 
00020    Roni Rosenfeld, 9/92  */
00021 
00027 /* Edited by Philip Clarkson, March 1997 to prevent compilation warnings */
00028 
00029 
00030 #include <stdio.h>
00031 #include "mips_swap.h"
00032 #include "general.h"
00033 
00034 void *rr_fread(char *ptr, int elsize, int n_elem, FILE *fp,
00035                char *header, int not_more)
00036 {
00037   int n_read, i;
00038   char dummychar;
00039 
00040   if (n_elem > 0) {
00041      n_read = fread(ptr,elsize,n_elem,fp);
00042      if (n_read != n_elem) quit(-1,
00043         "rr_fread: problems reading %s.  Only %d of %d elements were read\n",
00044          header, n_read, n_elem);
00045 
00046      if (elsize == sizeof(int)) {
00047         for (i=0; i<n_elem; i++) {
00048            SWAPWORD(ptr+(elsize*i));
00049         }
00050      }
00051      else if (elsize == sizeof(short)) {
00052         for (i=0; i<n_elem; i++) {
00053            SWAPHALF(ptr+(elsize*i));
00054         }
00055      }
00056      else if (elsize == sizeof(double)) {
00057         for (i=0; i<n_elem; i++) {
00058            SWAPDOUBLE(ptr+(elsize*i));
00059         }
00060      }
00061   }
00062 
00063   if (not_more) {
00064      if (fread(&dummychar,1,1,fp) != 0)
00065        quit(-1,"rr_fread: more data after %s - should not be there\n",header);
00066   }
00067 
00068   return(0); /* Not relevant, but stops compilation warnings. */
00069 
00070 }

Generated on Tue Dec 21 13:54:46 2004 by doxygen1.2.18