00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027
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);
00069
00070 }