home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / imdisp79.zip / DFI.H < prev    next >
C/C++ Source or Header  |  1992-06-16  |  15KB  |  400 lines

  1. /*-----------------------------------------------------------------------------
  2.  * File:    dfi.h
  3.  * Purpose: HDF internal header file
  4.  * Invokes: stdio.h, sys/file.h
  5.  * Contents: 
  6.  *  Compilation parameters
  7.  *  Machine-dependent definitions
  8.  *  Flexibility definitions: i/o buffering, dynamic memory, structure i/o
  9.  *  Size parameters
  10.  * Remarks: To port to a new system, only dfi.h and Makefile need be modified.
  11.  *          This file is included with user programs, but users do not see it.
  12.  *---------------------------------------------------------------------------*/
  13.  
  14.  
  15. #ifndef DF_MAGICK        /* avoid re-inclusion */
  16.  
  17. #define    DF_MAGICK    "\016\003\023\001" /* ^N^C^S^A */
  18.  
  19. #ifndef FILE
  20. #include <stdio.h>
  21. #endif /*FILE*/
  22.  
  23. /*--------------------------------------------------------------------------*/
  24. /*          Compilation Parameters for Flexibility and Portability          */
  25.  
  26. /* modify this line to allow for machine dependencies */
  27. #define    PC
  28. /**IMPORTANT** this is now in the in the makefile */
  29.  
  30. /* modify this line for buffered/unbuffered i/o */
  31. #define    DF_BUFFIO
  32.  
  33. /* modify this line for dynamic/static memory allocation */
  34. #define    DF_DYNAMIC
  35.  
  36. /* modify this line if structures cannot be read/written as is */
  37. #undef    DF_STRUCTOK        /* leave it this way - hdfsh expects it */
  38.  
  39. /* Current version number */
  40. #define    DFVERSION   3.00
  41.  
  42. /*--------------------------------------------------------------------------*/
  43. /*                              MT/NT constants                             */
  44. /*      four MT nibbles represent int, float, double, uchar                 */
  45. #define    DFMT_SUN        0x1111
  46. #define    DFMT_ALLIANT    0x1111
  47. #define    DFMT_IRIS4      0x1111
  48. #define    DFMT_UNICOS     0x3331
  49. #define    DFMT_CTSS       0x3331
  50. #define    DFMT_VAX        0x2221
  51. #define    DFMT_PC         0x4144    /* note byte swapping ??? */
  52.                 /* check this... */
  53. #define    DFMT_MAC        0x1111
  54. #define DFMT_SUN386    0x1444
  55.  
  56. #define    DFNT_VERSION    1    /* current version of NT info */
  57.  
  58. /* type info codes */
  59. #define    DFNT_UINT       1
  60. #define    DFNT_INT        2
  61. #define    DFNT_UCHAR      3
  62. #define    DFNT_CHAR       4
  63. #define    DFNT_FLOAT      5
  64. #define    DFNT_DOUBLE     6
  65.  
  66. /* class info codes for int */
  67. #define    DFNTI_MBO       1    /* Motorola byte order 2's compl */
  68. #define    DFNTI_VBO       2    /* Vax byte order 2's compl */
  69. #define    DFNTI_IBO       4    /* Intel byte order 2's compl */
  70.  
  71. /* class info codes for float */
  72. #define    DFNTF_IEEE      1    /* IEEE format */
  73. #define    DFNTF_VAX       2    /* Vax format */
  74. #define    DFNTF_CRAY      3    /* Cray format */
  75. #define    DFNTF_PC        4    /* PC floats - flipped IEEE */
  76.  
  77. /* class info codes for char */
  78. #define    DFNTC_BYTE      0    /* bitwise/numeric field */
  79. #define    DFNTC_ASCII     1    /* ASCII */
  80. #define    DFNTC_EBCDIC    5    /* EBCDIC */
  81.  
  82. /* array order */
  83. #define    DFO_FORTRAN     1    /* column major order */
  84. #define    DFO_C           2    /* row major order */
  85.  
  86. /*--------------------------------------------------------------------------*/
  87. /*                      Machine dependencies                                */
  88. #ifdef PC
  89.  
  90. /* Compiler Definitions for the various IBM PC compilers */
  91. /* define for Microsoft C 5.1 */
  92. #define MICROSOFT
  93. /* define for Lattice C 3.2 */
  94. /*#define LATTICE*/
  95.  
  96. #ifndef O_RDONLY
  97. #include <fcntl.h>
  98. #include <sys\types.h>        /* for unbuffered file I/O */
  99. #include <sys\stat.h>
  100. #include <io.h>
  101. #include <stdlib.h>            /* for malloc() */
  102. #include <malloc.h>
  103. #include <conio.h>            /* for debugging getch() calls */
  104. #include <string.h>            /* for vaious string functions */
  105. #define    L_INCR  1
  106. #endif /*O_RDONLY*/
  107. typedef char int8;
  108. typedef unsigned char uint8;
  109. typedef int int16;
  110. typedef unsigned int uint16;
  111. typedef long int int32;
  112. typedef unsigned long int uint32;
  113. typedef float float32;
  114. #define    DFmovmem(from, to, len) memmove(to, from, len)
  115. #undef DF_STRUCTOK                  /* structure writing will not work on PC */
  116. #undef DF_BUFFIO                    /* unbuffered i/o is faster */
  117.  
  118.     /* in the next 3 lines, p is recast so right number of bytes passed */
  119.     /* ### Note that all calls modify p.  Need to use temporary ptr */
  120. #define    UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  121. #define    INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  122. #define    INT32READ(p, x) { x = ((int32)(*p++))<<24; x|=((int32)((*p++) & 255))<<16;    \
  123.             x|=((int32)((*p++) & 255))<<8; x|=(int32)(*p++) & 255; }
  124.  
  125. #define    UINT16WRITE(p, x) { *p++ = (uint8)((x>>8) & 255); *p++ = (uint8)(x & 255); }
  126. #define    INT16WRITE(p, x) { *p++ = (uint8)((x>>8) & 255); *p++ = (uint8)(x & 255); }
  127. #define    INT32WRITE(p, x) { *p++ = (uint8)((x>>24) & 255); *p++ = (uint8)((x>>16) & 255);  \
  128.             *p++ = (uint8)((x>>8) & 255); *p++ = (uint8)(x & 255); }
  129.  
  130. #define    DF_CREAT(name, prot) open(name, O_CREAT|O_TRUNC,(prot==666 ? S_IREAD|S_IWRITE : prot))
  131. #define    DF_MT   DFMT_PC
  132. #endif /*PC*/
  133.  
  134.  
  135. #ifdef UNICOS
  136. #ifndef O_RDONLY
  137. #include <sys/fcntl.h>              /* for unbuffered i/o stuff */
  138. #define    L_INCR  1
  139. #endif /*O_RDONLY*/
  140. #define    int16 int
  141. #define    uint16 int
  142. #define    int32 int
  143. #define    float32 float
  144. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  145. #undef DF_STRUCTOK          /* cannot directly read/write structures */
  146. #define    DF_CAPFNAMES            /* fortran names are in all caps */
  147. #define    UINT16READ(p, x)    { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  148. #define    INT16READ(p, x)     { x = (*p++)<<8; x |= (*p++) & 255; }
  149. #define    INT32READ(p, x)     { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  150.                                 x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  151. #define    UINT16WRITE(p, x)   { *p++ = (x>>8) & 255; *p++ = x & 255; }
  152. #define    INT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  153. #define    INT32WRITE(p, x)    { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;   \
  154.                                 *p++ = (x>>8) & 255; *p++ = x & 255; }
  155. #define    DF_CREAT(name, prot) creat(name, prot)
  156. #define    DF_MT   DFMT_UNICOS
  157. #endif /*UNICOS*/
  158.  
  159.  
  160. #ifdef SUN
  161. #if ! defined mc68010 && ! defined mc68020 && ! defined mc68030
  162. #undef DF_STRUCTOK
  163. #endif
  164. #include <sys/file.h>               /* for unbuffered i/o stuff */
  165. #define    int16 short
  166. #define    uint16 unsigned short
  167. #define    int32 long
  168. #define    float32 float
  169. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  170. #ifndef DF_STRUCTOK
  171. #define    UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  172. #define    INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  173. #define    INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  174.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  175. #define    UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  176. #define    INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  177. #define    INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  178.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  179. #endif /*DF_STRUCTOK*/
  180. #define    DF_CREAT(name, prot) creat(name, prot)
  181. #define    DF_MT   DFMT_SUN
  182. #endif /*SUN*/
  183.  
  184. #ifdef SUN386
  185. #undef DF_STRUCTOK
  186. #include <sys/file.h>               /* for unbuffered i/o stuff */
  187. #define    int16 short
  188. #define    uint16 unsigned short
  189. #define    int32 long
  190. #define    float32 float
  191. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  192. #ifndef DF_STRUCTOK
  193. #define    UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  194. #define    INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  195. #define    INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  196.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  197. #define    UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  198. #define    INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  199. #define    INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  200.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  201. #endif /*DF_STRUCTOK*/
  202. #define    DF_CREAT(name, prot) creat(name, prot)
  203. #define    DF_MT   DFMT_SUN386
  204. #endif /* SUN386 */
  205.  
  206. #ifdef ALLIANT
  207. #include <sys/file.h>               /* for unbuffered i/o stuff */
  208. #define    int16 short
  209. #define    uint16 unsigned short
  210. #define    int32 long
  211. #define    float32 float
  212. #define    DFmovmem(from, to, len) bcopy(from, to, len)
  213. #ifndef DF_STRUCTOK
  214. #define    UINT16READ(p, x)    { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  215. #define    INT16READ(p, x)     { x = (*p++)<<8; x |= (*p++) & 255; }
  216. #define    INT32READ(p, x)     { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  217.                                 x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  218. #define    UINT16WRITE(p, x)   { *p++ = (x>>8) & 255; *p++ = x & 255; }
  219. #define    INT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  220. #define    INT32WRITE(p, x)    { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;   \
  221.                                 *p++ = (x>>8) & 255; *p++ = x & 255; }
  222. #endif /*DF_STRUCTOK*/
  223. #define    DF_CREAT(name, prot) creat(name, prot)
  224. #define    DF_MT   DFMT_ALLIANT
  225. #endif /*ALLIANT*/
  226.  
  227.  
  228. #ifdef IRIS4
  229. #undef DF_STRUCTOK
  230. #include <sys/types.h>
  231. #include <sys/file.h>               /* for unbuffered i/o stuff */
  232. #define    int16 short
  233. #define    uint16 unsigned short
  234. #define    int32 long
  235. #define    float32 float
  236. #define    DFmovmem(from, to, len) bcopy(from, to, len)
  237. #ifndef DF_STRUCTOK
  238. #define    UINT16READ(p, x)    { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  239. #define INT16READ(p, x)     { x = (*p++)<<8; x |= (*p++) & 255; }
  240. #define INT32READ(p, x)     { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  241.                                 x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  242. #define UINT16WRITE(p, x)   { *p++ = (x>>8) & 255; *p++ = x & 255; }
  243. #define INT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  244. #define INT32WRITE(p, x)    { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;   \
  245.                                 *p++ = (x>>8) & 255; *p++ = x & 255; }
  246. #endif /*DF_STRUCTOK*/
  247. #define DF_CREAT(name, prot) creat(name, prot)
  248. #define DF_MT   DFMT_IRIS4
  249. #endif /*IRIS4*/
  250.  
  251.  
  252. #ifdef MAC
  253. #undef DF_BUFFIO        /* use unbuffered i/o */
  254. #include <memory.h>             /* malloc stuff for MPW 3.0 */
  255. #include <fcntl.h>              /* unbuffered IO stuff for MPW 3.0 */
  256. #ifdef THINK_C                  /* for LightSpeed C */
  257. #include <unix.h>
  258. #else /*THINK_C                   MPW, possibly others */
  259. #include <Files.h>              /* for unbuffered i/o stuff */
  260. #endif /*THINK_C*/
  261. #define    DF_CAPFNAMES            /* fortran names are in all caps */
  262. #define DF_DYNAMIC        /* use dynamic allocation */
  263. #define int16 short
  264. #define uint16 unsigned short
  265. #define int32 long
  266. #define float32 float
  267. #ifdef THINK_C                   /* LightSpeed C does not have memcpy */
  268. #define DFmovmem(from, to, len) DFImemcopy(from, to, len)
  269. #else /*THINK_C*/
  270. #define DFmovmem(from, to, len) memcpy(to, from, len)
  271. #endif /*THINK_C*/
  272. #define malloc(x)   NewPtr((Size)   (x))    /* don't use malloc on the Mac */
  273. #define free(x)     DisposPtr((Ptr) (x))    /* don't use free on the Nac   */ 
  274. #undef DF_STRUCTOK
  275. #define UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  276. #define INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  277. #define INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  278.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  279. #define UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  280. #define INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  281. #define INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  282.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  283. #define DF_CREAT(name, prot) open(name, O_WRONLY|O_TRUNC|O_CREAT)
  284. #define DF_MT   DFMT_MAC
  285. #endif /*MAC*/
  286.  
  287. #ifdef VMS
  288. /*#undef DF_BUFFIO should be buff !!!!*/
  289.    /* use only unbuff i/o - buff doesn't work! */
  290. #ifndef DFopen                  /* avoid double includes */
  291. #include "dfivms.h"
  292. #endif /*DFopen*/
  293. #undef DF_STRUCTOK
  294. #define DF_CAPFNAMES            /* fortran names are in all caps */
  295. #include <file.h>               /* for unbuffered i/o stuff */
  296. #define int16 short
  297. #define uint16 unsigned short
  298. #define int32 long
  299. #define float32 float
  300. #define DFmovmem(from, to, len) memcpy(to, from, len)
  301. #ifndef DF_STRUCTOK
  302. #define UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  303. #define INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  304. #define INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  305.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  306. #define UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  307. #define INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  308. #define INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  309.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  310. #endif /*DF_STRUCTOK*/
  311. #define DF_CREAT(name, prot) open(name, prot)
  312. #define DF_MT   DFMT_VAX
  313. #endif /*VMS*/
  314.  
  315.  
  316.  
  317. /*--------------------------------------------------------------------------*/
  318. /*                      Flexibility parameters                              */
  319.  
  320. #ifdef DF_BUFFIO            /* set all calls to do buffered I/O */
  321. #define DF_OPEN(x,y) fopen(x,y)
  322. #define DF_CLOSE(x) fclose(x)
  323. #define DF_SEEK(x,y,z) fseek(x,y,z)
  324. #define DF_SKEND(x,y,z) fseek(x,y,z)
  325. #define DF_TELL(x) ftell(x)
  326. #define DF_READ(a,b,c,d) fread(a,b,c,d)
  327. #define DF_WRITE(a,b,c,d) fwrite(a,b,c,d)
  328. #define DF_FLUSH(a) fflush(a)
  329. #ifdef PC
  330. #define DF_RDACCESS "rb"
  331. #define DF_WRACCESS "rb+"
  332. #else /*PC*/
  333. #define DF_RDACCESS "r"
  334. #define DF_WRACCESS "r+"
  335. #endif /*PC*/
  336.  
  337. #else /*DF_BUFFIO         unbuffered i/o */
  338. #ifdef PC
  339. #define DF_OPEN(x,y) open(x,y,S_IWRITE|S_IREAD)
  340. #else
  341. #define DF_OPEN(x,y) open(x,y)
  342. #endif
  343. #define DF_CLOSE(x) close(x)
  344. #define DF_SEEK(x,y,z) lseek(x,y,z)
  345. #define DF_SKEND(x,y,z) lseek(x,-1*y,z)
  346. #define DF_TELL(x) lseek(x,0L,1)
  347. #define DF_READ(a,b,c,d) read(d,a,b*c)
  348. #define DF_WRITE(a,b,c,d) write(d,a,b*c)
  349. #define DF_FLUSH(a)                             /* no need to flush */
  350. #ifdef PC
  351. #if defined MICROSOFT
  352. #define DF_RDACCESS O_RDONLY | O_BINARY
  353. #define DF_WRACCESS O_RDWR | O_BINARY
  354. #elif defined LATTICE
  355. #define DF_RDACCESS O_RDONLY | O_RAW
  356. #define DF_WRACCESS O_RDWR | O_RAW
  357. #endif
  358. #else /*PC*/
  359. #define DF_RDACCESS O_RDONLY
  360. #define DF_WRACCESS O_RDWR
  361. #endif /*PC*/
  362. #endif /*DF_BUFFIO*/
  363.  
  364.  
  365.     /* if not allocating memory dynamically, need buffer for compression */
  366. #ifndef DF_DYNAMIC
  367. #define DF_TBUF
  368. #define DF_TBUFSZ    10000    /* buffer size */
  369. #endif /*DF_DYNAMIC*/
  370.  
  371.     /* if reading/writing structures not ok, need buffer for conversion */
  372. #ifndef DF_TBUF
  373. #ifndef DF_STRUCTOK
  374. #define DF_TBUF
  375. #define DF_TBUFSZ    256    /* buffer size can be smaller */
  376. #endif /*DF_STRUCTOK*/
  377. #endif /*DF_TBUF*/
  378.  
  379.     /* set buffer size */
  380. #ifdef DF_TBUF
  381. #ifndef DFMASTER
  382. extern
  383. #endif /*DFMASTER*/
  384.     char DFtbuf[DF_TBUFSZ];
  385. #endif /*DF_TBUF*/
  386.  
  387. /*--------------------------------------------------------------------------*/
  388. /*                          Size parameters                                 */
  389. #define DF_MAXDFS           32  /* How many DF's can be open at once */
  390. #define DF_DEFAULTDDS       16  /* How many DD's a file has by default */
  391. #define DF_MAXFNLEN         256 /* maximum length of filename parameters */
  392.  
  393. #ifndef PC
  394. char *strncpy();        /* these function definitions are handled in the include files */
  395. char *strcpy();
  396. char *malloc();
  397. char *memcpy();
  398. #endif    /* PC */
  399. #endif /*DF_MAGICK*/
  400.