Main Page   Compound List   File List   Compound Members   File Members  

rr_libs/rr_fwrite.c

Go to the documentation of this file.
00001 /* rr_fwrite(): call fwrite and quit if it fails */
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 /* If on a MIPS machine, write the data SWAP'ed. 
00019    Roni Rosenfeld, 9/92  */
00020 
00024 /* Edited by Philip Clarkson, March 1997 to prevent compilation warnings */
00025 
00026 #include <stdio.h>
00027 #include "mips_swap.h"
00028 #include "general.h"
00029 
00030 void *rr_fwrite(char *ptr, int elsize, int n_elem, FILE *fp, char *header)
00031 {
00032   int n_written, i;
00033 
00034   if (n_elem > 0) {
00035 
00036      if (elsize == sizeof(int)) {
00037         for (i=0; i<n_elem; i++) {
00038            SWAPWORD(ptr+(elsize*i));
00039         }
00040      }
00041      else if (elsize == sizeof(short)) {
00042         for (i=0; i<n_elem; i++) {
00043            SWAPHALF(ptr+(elsize*i));
00044         }
00045      }
00046      else if (elsize == sizeof(double)) {
00047         for (i=0; i<n_elem; i++) {
00048            SWAPDOUBLE(ptr+(elsize*i));
00049         }
00050      }
00051 
00052      n_written = fwrite(ptr,elsize,n_elem,fp);
00053 
00054      if (elsize == sizeof(int)) {
00055         for (i=0; i<n_elem; i++) {
00056            SWAPWORD(ptr+(elsize*i));
00057         }
00058      }
00059      else if (elsize == sizeof(short)) {
00060         for (i=0; i<n_elem; i++) {
00061            SWAPHALF(ptr+(elsize*i));
00062         }
00063      }
00064      else if (elsize == sizeof(double)) {
00065         for (i=0; i<n_elem; i++) {
00066            SWAPDOUBLE(ptr+(elsize*i));
00067         }
00068      }
00069 
00070      if (n_written != n_elem) quit(-1,
00071        "rr_fwrite: problems writing %s. Only %d of %d elements were written\n",
00072         header, n_written, n_elem);
00073   }
00074 
00075   return(0); /* Not relevant, but stops compilation warnings. */
00076 
00077 }

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