/* * LIBML library - read, write and manipulate MATLAB MAT-files * Copyright (C) 1994 Michael J. Maurer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Michael Maurer * Durand Bldg - Room 232 * Stanford, CA 94305-4055 * (415) 723-1024 */ /****************************************************************************** miscdefs.h This file is part of the STARLab Magellan Altimeter Data Processing Software. Michael Maurer, August 1993. ******************************************************************************/ /* $Log: miscdefs.h,v $ * Revision 1.0 1993/08/02 00:55:51 maurer * Initial revision * */ #ifndef MISCDEFS_H #define MISCDEFS_H #include #include #define calloct_err(Ptr,N,Typ) do {\ if (((Ptr)=(Typ *) calloc((size_t)(N),sizeof(Typ))) == NULL) {\ fprintf(stderr, "%s %d: calloc failed for %u elements of type \"Typ\".\n", __FILE__, __LINE__, (unsigned int)(N));\ exit(-51);\ }} while (0) #define malloct_err(Ptr,N,Typ) do {\ if (((Ptr)=(Typ *) malloc((size_t)(N)*sizeof(Typ))) == NULL) {\ fprintf(stderr, "%s %d: malloc failed for %u elements of type \"Typ\".\n", __FILE__, __LINE__, (unsigned int)(N));\ exit(-52);\ }} while (0) #define realloct_err(Ptr,N,Typ) do {\ if ((Ptr)==NULL)\ malloct_err((Ptr),N,Typ);\ else\ if (((Ptr)=(Typ *) realloc((char *)(Ptr),(size_t)(N)*sizeof(Typ))) == NULL) {\ fprintf(stderr, "%s %d: realloc failed for %u elements of type \"Typ\".\n", __FILE__, __LINE__, (unsigned int)(N));\ exit(-53);\ }\ } while (0) #define myrealloct_err(Ptr,No,Nn,Typ) do {\ if (((Ptr)=(Typ *) myrealloc((char *)(Ptr),(size_t)(No)*sizeof(Typ),(size_t)(Nn)*sizeof(Typ))) == NULL) {\ fprintf(stderr, "%s %d: myrealloc failed for %u elements of type \"Typ\".\n", __FILE__, __LINE__, (Nn));\ exit(-54);\ }} while (0) #define malloc_err(Ptr,N) malloct_err(Ptr,N,char) #define malloc2t_err(Ptr,M,N,Typ) do {\ int _i;\ malloct_err(Ptr,N,Typ *);\ malloct_err((Ptr)[0],M*N,Typ);\ for (_i=1; _i #define tmemcpy(dst,src,n,typ) do {\ if ((char *)(src)!=(char *)(dst))\ memcpy((dst),(src),(n)*sizeof(typ));\ } while (0) #define UCP(x) ((unsigned char *)(x)) #define l_vax2ieee(in,out,n) swapb_4(UCP(in),UCP(out),n) #define s_vax2ieee(in,out,n) swapb_2(UCP(in),UCP(out),n) #define l_ieee2vax(in,out,n) swapb_4(UCP(in),UCP(out),n) #define s_ieee2vax(in,out,n) swapb_2(UCP(in),UCP(out),n) /****************************************************************************** Conversions between "ieee" and "mipsel" ieee Big-endian, IEEE-954 floating point mipsel Little-endian, IEEE-954 floating point ******************************************************************************/ #define d_mipsel2ieee(in,out,n) swapb_8(UCP(in),UCP(out),n) #define f_mipsel2ieee(in,out,n) swapb_4(UCP(in),UCP(out),n) #define l_mipsel2ieee(in,out,n) swapb_4(UCP(in),UCP(out),n) #define s_mipsel2ieee(in,out,n) swapb_2(UCP(in),UCP(out),n) #define d_ieee2mipsel(in,out,n) swapb_8(UCP(in),UCP(out),n) #define f_ieee2mipsel(in,out,n) swapb_4(UCP(in),UCP(out),n) #define l_ieee2mipsel(in,out,n) swapb_4(UCP(in),UCP(out),n) #define s_ieee2mipsel(in,out,n) swapb_2(UCP(in),UCP(out),n) /****************************************************************************** Conversions between "mipsel" and "vax" mipsel Little-endian, IEEE-954 floating point vax Little-endian, VAX-F or VAX-D floating point ******************************************************************************/ #define d_vax2mipsel(in,out,n) do {\ d_vax2ieee(UCP(in),UCP(out),n);\ d_ieee2mipsel(UCP(out),UCP(out),n);\ } while (0) #define f_vax2mipsel(in,out,n) do {\ f_vax2ieee(UCP(in),UCP(out),n);\ f_ieee2mipsel(UCP(out),UCP(out),n);\ } while (0) #define l_vax2mipsel(in,out,n) tmemcpy(UCP(out),UCP(in),n,long) #define s_vax2mipsel(in,out,n) tmemcpy(UCP(out),UCP(in),n,short) #define d_mipsel2vax(in,out,n) do {\ d_mipsel2ieee(UCP(in),UCP(out),n);\ d_ieee2vax(UCP(out),UCP(out),n);\ } while (0) #define f_mipsel2vax(in,out,n) do {\ f_mipsel2ieee(UCP(in),UCP(out),n);\ f_ieee2vax(UCP(out),UCP(out),n);\ } while (0) #define l_mipsel2vax(in,out,n) tmemcpy(UCP(out),UCP(in),n,long) #define s_mipsel2vax(in,out,n) tmemcpy(UCP(out),UCP(in),n,short) /****************************************************************************** Conversions between "ieee", "mipsel" and "vax" and the "local" format ieee Big-endian, IEEE-954 floating point vax Little-endian, VAX-F or VAX-D floating point mipsel Little-endian, IEEE-954 floating point ******************************************************************************/ /****************************************************************************** local = big-endian, IEEE-954 floating-point ("ieee") ******************************************************************************/ #ifdef order_big_endian #ifdef float_ieee #define d_ieee2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,double) #define f_ieee2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,float) #define l_ieee2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,long) #define s_ieee2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,short) #define d_local2ieee(in,out,n) tmemcpy(UCP(out),UCP(in),n,double) #define f_local2ieee(in,out,n) tmemcpy(UCP(out),UCP(in),n,float) #define l_local2ieee(in,out,n) tmemcpy(UCP(out),UCP(in),n,long) #define s_local2ieee(in,out,n) tmemcpy(UCP(out),UCP(in),n,short) #define d_mipsel2local(in,out,n) d_mipsel2ieee(UCP(in),UCP(out),n) #define f_mipsel2local(in,out,n) f_mipsel2ieee(UCP(in),UCP(out),n) #define l_mipsel2local(in,out,n) l_mipsel2ieee(UCP(in),UCP(out),n) #define s_mipsel2local(in,out,n) s_mipsel2ieee(UCP(in),UCP(out),n) #define d_local2mipsel(in,out,n) d_ieee2mipsel(UCP(in),UCP(out),n) #define f_local2mipsel(in,out,n) f_ieee2mipsel(UCP(in),UCP(out),n) #define l_local2mipsel(in,out,n) l_ieee2mipsel(UCP(in),UCP(out),n) #define s_local2mipsel(in,out,n) s_ieee2mipsel(UCP(in),UCP(out),n) #define d_vax2local(in,out,n) d_vax2ieee(UCP(in),UCP(out),n) #define f_vax2local(in,out,n) f_vax2ieee(UCP(in),UCP(out),n) #define l_vax2local(in,out,n) l_vax2ieee(UCP(in),UCP(out),n) #define s_vax2local(in,out,n) s_vax2ieee(UCP(in),UCP(out),n) #define d_local2vax(in,out,n) d_ieee2vax(UCP(in),UCP(out),n) #define f_local2vax(in,out,n) f_ieee2vax(UCP(in),UCP(out),n) #define l_local2vax(in,out,n) l_ieee2vax(UCP(in),UCP(out),n) #define s_local2vax(in,out,n) s_ieee2vax(UCP(in),UCP(out),n) #endif /* float_ieee */ #endif /* order_big-endian */ /****************************************************************************** local = little-endian, IEEE-954 floating-point ("mipsel") ******************************************************************************/ #ifdef order_little_endian #ifdef float_ieee #define d_ieee2local(in,out,n) d_ieee2mipsel(UCP(in),UCP(out),n) #define f_ieee2local(in,out,n) f_ieee2mipsel(UCP(in),UCP(out),n) #define l_ieee2local(in,out,n) l_ieee2mipsel(UCP(in),UCP(out),n) #define s_ieee2local(in,out,n) s_ieee2mipsel(UCP(in),UCP(out),n) #define d_local2ieee(in,out,n) d_mipsel2ieee(UCP(in),UCP(out),n) #define f_local2ieee(in,out,n) f_mipsel2ieee(UCP(in),UCP(out),n) #define l_local2ieee(in,out,n) l_mipsel2ieee(UCP(in),UCP(out),n) #define s_local2ieee(in,out,n) s_mipsel2ieee(UCP(in),UCP(out),n) #define d_mipsel2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,double); #define f_mipsel2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,float); #define l_mipsel2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,long) #define s_mipsel2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,short) #define d_local2mipsel(in,out,n) tmemcpy(UCP(out),UCP(in),n,double); #define f_local2mipsel(in,out,n) tmemcpy(UCP(out),UCP(in),n,float); #define l_local2mipsel(in,out,n) tmemcpy(UCP(out),UCP(in),n,long) #define s_local2mipsel(in,out,n) tmemcpy(UCP(out),UCP(in),n,short) #define d_vax2local(in,out,n) d_vax2mipsel(UCP(in),UCP(out),n) #define f_vax2local(in,out,n) f_vax2mipsel(UCP(in),UCP(out),n) #define l_vax2local(in,out,n) l_vax2mipsel(UCP(in),UCP(out),n) #define s_vax2local(in,out,n) s_vax2mipsel(UCP(in),UCP(out),n) #define d_local2vax(in,out,n) d_mipsel2vax(UCP(in),UCP(out),n) #define f_local2vax(in,out,n) f_mipsel2vax(UCP(in),UCP(out),n) #define l_local2vax(in,out,n) l_mipsel2vax(UCP(in),UCP(out),n) #define s_local2vax(in,out,n) s_mipsel2vax(UCP(in),UCP(out),n) #endif /* float_ieee */ #endif /* order_little_endian */ /****************************************************************************** local = little-endian, VAX floating-point ("vax") ******************************************************************************/ #ifdef order_little_endian #ifdef float_vax #define d_ieee2local(in,out,n) d_ieee2vax(UCP(in),UCP(out),n) #define f_ieee2local(in,out,n) f_ieee2vax(UCP(in),UCP(out),n) #define l_ieee2local(in,out,n) l_ieee2vax(UCP(in),UCP(out),n) #define s_ieee2local(in,out,n) s_ieee2vax(UCP(in),UCP(out),n) #define d_local2ieee(in,out,n) d_vax2ieee(UCP(in),UCP(out),n) #define f_local2ieee(in,out,n) f_vax2ieee(UCP(in),UCP(out),n) #define l_local2ieee(in,out,n) l_vax2ieee(UCP(in),UCP(out),n) #define s_local2ieee(in,out,n) s_vax2ieee(UCP(in),UCP(out),n) #define d_mipsel2local(in,out,n) d_mipsel2vax(in,out,n) #define f_mipsel2local(in,out,n) f_mipsel2vax(in,out,n) #define l_mipsel2local(in,out,n) l_mipsel2vax(in,out,n) #define s_mipsel2local(in,out,n) s_mipsel2vax(in,out,n) #define d_local2mipsel(in,out,n) d_vax2mipsel(in,out,n) #define f_local2mipsel(in,out,n) f_vax2mipsel(in,out,n) #define l_local2mipsel(in,out,n) l_vax2mipsel(in,out,n) #define s_local2mipsel(in,out,n) s_vax2mipsel(in,out,n) #define d_vax2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,double); #define f_vax2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,float); #define l_vax2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,long) #define s_vax2local(in,out,n) tmemcpy(UCP(out),UCP(in),n,short) #define d_local2vax(in,out,n) tmemcpy(UCP(out),UCP(in),n,double); #define f_local2vax(in,out,n) tmemcpy(UCP(out),UCP(in),n,float); #define l_local2vax(in,out,n) tmemcpy(UCP(out),UCP(in),n,long) #define s_local2vax(in,out,n) tmemcpy(UCP(out),UCP(in),n,short) #endif /* float_vax */ #endif /* order_little_endian */ #endif /* IVCONVERT_H */ /****************************************************************************** sundefs.h This file is part of the STARLab Magellan Altimeter Data Processing Software. Michael Maurer, Aug 1993. ******************************************************************************/ /* $Log: sundefs.h,v $ * Revision 1.0 1993/08/04 05:26:05 maurer * Initial revision * */ #ifndef SUNDEFS_H #define SUNDEFS_H #ifdef sun typedef unsigned long fpos_t; #ifndef SEEK_SET #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 #endif /* SEEK_SET */ #define fgetpos(f,p) (*(p)=ftell(f),0) #define fsetpos(f,p) fseek((f),(*p),SEEK_SET) #endif /* sun */ #endif /* SUNDEFS_H */