/* Useful constants for programs dealing with EBS files and prototypes for ebs.c Copyright (C) 1993/94 Markus Kuhn, Institut fuer Physiologie und Biokybernetik (IPB), Universitaet Erlangen, Deutschland Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and related publications and that both that copyright notice and this permission notice appear in supporting documentation. The authors make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. Send your comments, suggestions or bug reports to ftpebs@uni-erlangen.de Or mail to Institut fuer Physiologie und Biokybernetik Markus Prosch Universitaetsstrasse 17 D-91054 Erlangen Germany $Id: ebs.h,v 1.23 1994/12/16 15:05:31 msprosch Exp $ */ #ifndef __EBS #define __EBS #ifndef MSDOS /* uncomment the following line, if you compile under MS-DOS */ /*#define MSDOS */ #endif #include #ifdef MSDOS #include "conf.h" #endif /* 8-byte Magic Code, used to identify EBS files */ #define EBS_MAGIC1 0x45425394L #define EBS_MAGIC2 0x0a131a0dL /* Encoding IDs */ #define EBS_TIB_16 0x00000000L #define EBS_CIB_16 0x00000001L #define EBS_TIL_16 0x00000002L #define EBS_CIL_16 0x00000003L #define EBS_TI_16D 0x00000010L #define EBS_CI_16D 0x00000011L /* Filter types */ #define EBS_LOW_PASS 0x00000001 #define EBS_HIGH_PASS 0x00000002 #define EBS_NOTCH_FILTER 0x00000003 #define EBS_NO_FILTER 0xffffffff /* Attribute Tags */ #define EBS_IGNORE 0x00000002L #define EBS_PATIENT_NAME 0x00000004L #define EBS_PATIENT_ID 0x00000006L #define EBS_PATIENT_BIRTHDAY 0x00000008L #define EBS_PATIENT_SEX 0x0000000aL #define EBS_SHORT_DESCRIPTION 0x0000000cL #define EBS_DESCRIPTION 0x0000000eL #define EBS_SAMPLE_RATE 0x00000010L #define EBS_INSTITUTION 0x00000012L #define EBS_PROCESSING_HISTORY 0x00000014L #define EBS_LOCATION_DIAGRAM 0x00000016L #define EBS_PREFERRED_INTEGER_RANGE 0x00000001L #define EBS_UNITS 0x00000003L #define EBS_CHANNEL_DESCRIPTION 0x00000005L #define EBS_CHANNEL_GROUPS 0x00000007L #define EBS_EVENTS 0x00000009L #define EBS_RECORDING_TIME 0x0000000bL #define EBS_CHANNEL_LOCATIONS 0x0000000dL #define EBS_FILTERS 0x0000000fL #define EBS_ASSUMED_NSAMPLES 0x00000011L #define EBS_FINAL_TAG 0x00000000L #define EBS_ILLEGAL_TAG 0xffffffffL /* Attribute Tag Ranges */ #define EBS_BEGIN_STANDARD_AREA 0x00000001L #define EBS_END_STANDARD_AREA 0x0000ffffL #define EBS_BEGIN_RESERVATION_AREA 0x00010000L #define EBS_END_RESERVATION_AREA 0x7fffffffL #define EBS_BEGIN_FREE_AREA 0x80000000L #define EBS_END_FREE_AREA 0x87ffffffL #define EBS_BEGIN_FREE_STRING_AREA 0x88000000L #define EBS_END_FREE_STRING_AREA 0xfffffffeL /* Character Sets for which conversion tables are available */ #define EBS_CS_ASCII 1 /* good old 7-bit US-ASCII */ #define EBS_CS_LATIN1 2 /* ISO 8859-1 */ #define EBS_CS_IBM437 3 /* the IBM PC character set */ #define EBS_CS_IBM850 4 /* the new OS/2 IBM character set */ #define EBS_CS_ATARI_ST 5 /* the Atari ST character set */ #define EBS_CS_MAC 6 /* Macintosh character set */ #define EBS_CS_UCS2 7 /* ISO 10646 UCS-2, Bigendian */ #define EBS_CS_UCS2L 8 /* ISO 10646 UCS-2, Littleendian */ #define EBS_CS_UTF2 9 /* the Plan 9 and POSIX UCS encoding */ #if defined(MSDOS) && !defined(EBS_CS_LOCAL) #define EBS_CS_LOCAL EBS_CS_IBM437 #endif #ifndef EBS_CS_LOCAL /* Select your local character set here! EBS uses internally a universal 16-bit character set (ISO 10646/Unicode) that contains the characters of all other character sets and the EBS tools convert these 16-bit characters automatically to/from your local character set. You only have to specify in the following #define which one you have. Use EBS_CS_LATIN1 for most UNIX X11 workstations, Amiga, Archimedes and MS Windows, use EBS_IBM_437 for programms running under MS-DOS, use EBS_CS_ASCII if your old terminal can only display 7-bit US-ASCII characters or use any other suitable character set from those listed above. */ #define EBS_CS_LOCAL EBS_CS_LATIN1 #endif #ifdef MSDOS typedef signed char int8; typedef unsigned char uint8; typedef signed short int16; typedef unsigned short uint16; typedef signed long int32; typedef unsigned long uint32; typedef signed long SampleT; typedef unsigned long USampleT; #ifdef EBS_64_BIT typedef signed long SampleT; typedef unsigned long USampleT; #endif #else typedef signed char int8; typedef unsigned char uint8; typedef signed short int16; typedef unsigned short uint16; typedef signed int int32; typedef unsigned int uint32; typedef signed long SampleT; typedef unsigned long USampleT; #ifdef EBS_64_BIT typedef signed long SampleT; typedef unsigned long USampleT; #endif #endif /* Prototypes for functions offered by ebs.c */ /* Determine, how many 32-bit words a 0-terminated string will need. s is encoded with the local character set. */ int s4len(char const *s); /* Determine, how many 32-bit words a 0-terminated string will need. s is encoded with the character set charset. */ int s4len_cs(char const *s, int charset); /* Determine, how many 32-bit words a 0-terminated ASCII floatingpoint number will need */ int f4len(double x); /**** Functions that operate on files/streams directly *****/ /* Read a Bigendian SampleT integer value from a file */ SampleT fgetst(FILE *f); #ifdef EBS_64_BIT /* Read a Bigendian 64-bit integer value from a file */ int64 fgeti64(FILE *f); #endif /* Read a Bigendian 32-bit integer value from a file */ int32 fgeti32(FILE *f); /* Read a Bigendian 16-bit integer value from a file */ short fgeti16(FILE *f); /* Write a Bigendian SampleT integer value to a file */ void fputst(SampleT n, FILE *f); #ifdef EBS_64_BIT /* Write a Bigendian 64-bit integer value to a file */ void fputi64(int64 n, FILE *f); #endif /* Write a Bigendian 32-bit integer value to a file */ void fputi32(int32 n, FILE *f); /* Write a Bigendian 16-bit integer value to a file */ void fputi16(short n, FILE *f); /* Read a Littleendian SampleT integer value from a file */ SampleT fgetstl(FILE *f); #ifdef EBS_64_BIT /* Read a Littleendian 64-bit integer value from a file */ int64 fgeti64l(FILE *f); #endif /* Read a Littleendian 32-bit integer value from a file */ int32 fgeti32l(FILE *f); /* Read a Littleendian 16-bit integer value from a file */ short fgeti16l(FILE *f); /* Write a Littleendian SampleT integer value to a file */ void fputstl(SampleT n, FILE *f); #ifdef EBS_64_BIT /* Write a Littleendian 64-bit integer value to a file */ void fputi64l(int64 n, FILE *f); #endif /* Write a Littleendian 32-bit integer value to a file */ void fputi32l(int32 n, FILE *f); /* Write a Littleendian 16-bit integer value to a file */ void fputi16l(short n, FILE *f); /* Write a 0-terminated string that is filled with 0-bytes to a multiple of four bytes length. The string s[] is encoded in the local character set but will be written in ISO 10646. */ void fputs4(char const *s, FILE *f); /* Write a 0-terminated string that is filled with 0-bytes to a multiple of four bytes length. The string s[] is encoded in the charset character set but will be written in ISO 10646. */ void fputs4_cs(char const *s, int charset, FILE *f); /* Read in a 0-terminated string that is filled with 0-bytes to a multiple of four length together with these 0-bytes. A maximum string length (including final 0-byte) maxlen may be specified, longer strings will be truncated. The return value is the number of characters (without 0-bytes) of the full untruncated string in the file. The string on the file is encoded in ISO 10646, but a string in the local character set will be returned. */ int fgets4(char *buf, int maxlen, FILE *f); /* Read in a 0-terminated string that is filled with 0-bytes to a multiple of four length together with these 0-bytes. A maximum string length (including final 0-byte) maxlen may be specified, longer strings will be truncated. The return value is the number of characters (without 0-bytes) of the full untruncated string in the file. The string on the file is encoded in ISO 10646, but a string in the character set charset will be returned. */ int fgets4_cs(char *buf, int maxlen, int charset, FILE *f); /* Write a 0-terminated ASCII floating point number that is filled with 0-bytes to a multiple of four bytes length. */ void fputf4(double x, FILE *f); /* Read in a 0-terminated floating point number that is filled with 0-bytes to a multiple of four length together with these 0-bytes. will be truncated. If the floating point number string is empty, *nan will be set to 1, if an error occured it will be set to a negative number and to 0 if everything is all right. The return value is the floating point number. */ double fgetf4(FILE *f, int *nan); /**** Functions that operate on EBS files loaded/mapped into memory *****/ /* Read a Bigendian SampleT integer value */ SampleT getst(void **p); #ifdef EBS_64_BIT /* Read a Bigendian 64-bit integer value */ int64 geti64(void **p); #endif /* Read a Bigendian 32-bit integer value */ int32 geti32(void **p); /* Read a Bigendian 16-bit integer value */ short geti16(void **p); /* Write a Bigendian SampleT integer value */ void putst(SampleT n, void **p); #ifdef EBS_64_BIT /* Write a Bigendian 64-bit integer value */ void puti64(int64 n, void **p); #endif /* Write a Bigendian 32-bit integer value */ void puti32(int32 n, void **p); /* Write a Bigendian 16-bit integer value to a file */ void puti16(short n, void **p); /* Read a Littleendian SampleT integer value */ SampleT getstl(void **p); #ifdef EBS_64_BIT /* Read a Littleendian 64-bit integer value */ int64 geti64l(void **p); #endif /* Read a Littleendian 32-bit integer value */ int32 geti32l(void **p); /* Read a Littleendian 16-bit integer value */ short geti16l(void **p); /* Write a Littleendian SampleT integer value */ void putstl(SampleT n, void **p); #ifdef EBS_64_BIT /* Write a Littleendian 64-bit integer value */ void puti64l(SampleT n, void **p); #endif /* Write a Littleendian 32-bit integer value */ void puti32l(int32 n, void **p); /* Write a Littleendian 16-bit integer value to a file */ void puti16l(short n, void **p); /* Write a 0-terminated string that is filled with 0-bytes to a multiple of four bytes length. The string s[] is encoded in the local character set but will be written in ISO 10646. */ void puts4(char const *s, void **p); /* Write a 0-terminated string that is filled with 0-bytes to a multiple of four bytes length. The string s[] is encoded in the character set charset but will be written in ISO 10646. */ void puts4_cs(char const *s, int charset, void **p); /* Read in a 0-terminated string that is filled with 0-bytes to a multiple of four length together with these 0-bytes. A maximum string length (including 1 0-byte) maxlen be specified, longer strings will be truncated. The return value is the number of characters (without 0-bytes) of the full untruncated string in the file. The string on the file is encoded in ISO 10646, but a string in the local character set will be returned. */ int gets4(char *buf, int maxlen, void **p); /* Read in a 0-terminated string that is filled with 0-bytes to a multiple of four length together with these 0-bytes. A maximum string length (including 1 0-byte) maxlen be specified, longer strings will be truncated. The return value is the number of characters (without 0-bytes) of the full untruncated string in the file. The string on the file is encoded in ISO 10646, but a string in the character set charset will be returned. */ int gets4_cs(char *buf, int maxlen, int charset, void **p); /* Write a 0-terminated ASCII floating point number that is filled with 0-bytes to a multiple of four bytes length. */ void putf4(double x, void **p); /* Read in a 0-terminated floating point number that is filled with 0-bytes to a multiple of four length together with these 0-bytes. will be truncated. If the floating point number string is empty, *nan will be set to 1, if an error occured it will be set to a negative number and to 0 if everything is all right. The return value is the floating point number. */ double getf4(void **p, int *nan); /* Reads in the data part from an input EBS file fin and writes the same data in any EBS data format to a different output file fout. The data file format for both files are specified in incode and outcode, instart and outstart are the positions of the first byte of the data part in both files and channels and samples determine the length of the whole data part. If modify is not NULL, (*modify)() is called for every data block in every channel before the blocks are written to fout. This allows you to modify data during format conversion (e.g. add an offset) and makes this function also useful for converting to/from non-EBS files. If outcode is 0xffffffff or fout is NULL, no data is written to the output file, but (*modify)() is still called for all blocks of the data part (e.g. for collecting statistical data only). The (*modify)() parameter start is a pointer to an array of length short values from channel channel+1 which might be modified. If *samples is 0xffffffff (only allowed for time-based ordered data), the function will determine the number of samples by looking for the end-of-file and will update *samples. return code: >= 0 length of output in bytes -1 error while reading fin -2 error while writing fout -3 not enough memory */ SampleT dataconv(FILE *fin, FILE *fout, uint32 incode, uint32 outcode, USampleT instart, USampleT outstart, uint32 channels, USampleT *samples, void (*modify)(short *start, USampleT length, uint32 channel, USampleT pos)); /* Convert an ASCII string with an EBS data encoding name ("CIB_16", etc.) to a numeric encoding ID (EBS_CIB_16, etc.). Return 0xffffffff if encoding name is unknown. */ int32 formatid(char const *name); /* Return a pointer to an ASCII string with the name of the EBS encoding format identified by id (e.g. "CIB_16") or return NULL for unknown or non-standard encoding IDs. */ char const *formatname(int32 id); #endif /* __EBS */