IGMPlot: src/include/ADF_KFc.h Source File

IGMPlot 3.16 Optimized IGMplot version able to use wfn/wfx/xyz files

Loading...
Searching...
No Matches
ADF_KFc.h
1 /***************************************************************************
2 KFc.h - header file for KFReader: library for handling ADF binary file
3 format, the so-called KF-files. The current version supports only
4 reading KF files.
5 Even though the binary files are system-dependent, they are
6 converted on the fly and the caller routine gets the data in the
7 native format.
8
9 Copyright (C) 2006-2023 by Software for Chemistry & Materials B.V.
10 For support, contact support at scm . com
11
12 This file is part of the ADF software
13 For more information, see <http://www.scm.com>
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU Lesser General Public License as published by
17 the Free Software Foundation version 3 of the License.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 SCM owns the intellectual property right for this file and reserves the
25 right to distrbute it under a license other than LGPL
26 ****************************************************************************/
27#ifndef _KF_H_
28#define _KF_H_
29
30
31#include <ADF_ArrayList.h>
32
33
34
35/* variable types */
36
37#define KF_T_INTEGER 1
38#define KF_T_DOUBLE 2
39#define KF_T_STRING 3
40#define KF_T_LOGICAL 4
41
42/* block types */
43#define KF_BT_EMPTY 0
44#define KF_BT_FREE 1
45#define KF_BT_SUPERINDEX 2
46#define KF_BT_INDEX 3
47#define KF_BT_DATA 4
48
49/* byte order */
50#define KF_BIG_ENDIAN 1
51#define KF_LITTLE_ENDIAN 2
52
53/* KF file signature */
54#define KF_SIG "SUPERINDEX "
55#define KF_EMPTY_SIG "EMPTY "
56#define KF_SIG_LENGTH 32
57
58/* KF block length */
59#define KF_BLOCKLENGTH 4096
60#define KF_N_DATATYPES 4
61
62
63#define KF_SECTION_NAME_LENGTH 32
64
65#define KF_NUM_SUPERINDEX_BLOCK_ENTRIES32 ((KF_BLOCKLENGTH-sizeof(KFSuperIndexBlockHeader32))/sizeof(KFSuperIndexBlockEntry32))
66#define KF_NUM_INDEX_BLOCK_ENTRIES32 ((KF_BLOCKLENGTH-sizeof(KFIndexBlockHeader32))/sizeof(KFIndexBlockEntry32))
67#define KF_NUM_SUPERINDEX_BLOCK_ENTRIES64 ((KF_BLOCKLENGTH-sizeof(KFSuperIndexBlockHeader64))/sizeof(KFSuperIndexBlockEntry64))
68#define KF_NUM_INDEX_BLOCK_ENTRIES64 ((KF_BLOCKLENGTH-sizeof(KFIndexBlockHeader64))/sizeof(KFIndexBlockEntry64))
69
70#ifdef _MSC_VER
71 typedef int INT32;
72 typedef _int64 INT64;
73#else
74 typedef int INT32;
75 typedef long long INT64;
76#endif
77
81 typedef struct _KFSuperIndexBlockHeader32 {
82 char name[KF_SIG_LENGTH];
83 INT32 mxbl; /* The total number of blocks in the file */
84 INT32 mxsbl; /* The total number of superblocks in the file */
85 INT32 mxsec; /* The number of sections in the file */
86 INT32 nextPhys; /* Physical block number of the next superindex block in the chain */
87} KFSuperIndexBlockHeader32;
88 typedef struct _KFSuperIndexBlockHeader64 {
89 char name[KF_SIG_LENGTH];
90 INT64 mxbl; /* The total number of blocks in the file */
91 INT64 mxsbl; /* The total number of superblocks in the file */
92 INT64 mxsec; /* The number of sections in the file */
93 INT64 nextPhys; /* Physical block number of the next superindex block in the chain */
94} KFSuperIndexBlockHeader64;
95
99 typedef struct _KFSuperIndexBlockEntry32 {
100 char name[KF_SECTION_NAME_LENGTH];
101 INT32 physBlk; /* Physical block number */
102 INT32 logicBlk; /* Logical block number within the section, starts from one. */
103 INT32 numBlks; /* Number of blocks in this block run */
104 INT32 type; /* Type of this entry, one of the BT_* macros */
105} KFSuperIndexBlockEntry32;
106 typedef struct _KFSuperIndexBlockEntry64 {
107 char name[KF_SECTION_NAME_LENGTH];
108 INT64 physBlk; /* Physical block number */
109 INT64 logicBlk; /* Logical block number within the section, starts from one. */
110 INT64 numBlks; /* Number of blocks in this block run */
111 INT64 type; /* Type of this entry, one of the BT_* macros */
112} KFSuperIndexBlockEntry64;
113
117 typedef struct _KFIndexBlockHeader32 {
118 char name[KF_SECTION_NAME_LENGTH];
119 INT32 mxibl; /* The number of index blocks in this section */
120 INT32 mxdbl; /* The number of data blocks in this section */
121 INT32 mxbyte; /* The number of used bytes in the last data block of this section */
122 INT32 mxtype[KF_N_DATATYPES];/* The number of used enttries of each type in the last data block of this section */
123 /* One per data type in the order: int, double, char, logical */
124} KFIndexBlockHeader32;
125 typedef struct _KFIndexBlockHeader64 {
126 char name[KF_SECTION_NAME_LENGTH];
127 INT64 mxibl; /* The number of index blocks in this section */
128 INT64 mxdbl; /* The number of data blocks in this section */
129 INT64 mxbyte; /* The number of used bytes in the last data block of this section */
130 INT64 mxtype[KF_N_DATATYPES];/* The number of used enttries of each type in the last data block of this section */
131 /* One per data type in the order: int, double, char, logical */
132} KFIndexBlockHeader64;
133
137 typedef struct _KFIndexBlockEntry32 {
138 char name[KF_SECTION_NAME_LENGTH];
139 INT32 firstLBlk; /* The logical block number of the data block where the varialbe starts */
140 INT32 firstBlkIndx; /* The index into the data block where the variable starts.
141 Each index refers to the part of the data block containing data of its own type. */
142 INT32 length; /* Length of the variable in elements (1 for scalars) */
143 INT32 firstBlkLen; /* The number of elements of the variable contained in its 1st data block */
144 INT32 usedLen; /* The number of elements of the variable that has actually been written in the file */
145 INT32 type; /* The type of the variable */
146} KFIndexBlockEntry32;
147 typedef struct _KFIndexBlockEntry64 {
148 char name[KF_SECTION_NAME_LENGTH];
149 INT64 firstLBlk; /* The logical block number of the data block where the varialbe starts */
150 INT64 firstBlkIndx; /* The index into the data block where the variable starts.
151 Each index refers to the part of the data block containing data of its own type. */
152 INT64 length; /* Length of the variable in elements (1 for scalars) */
153 INT64 firstBlkLen; /* The number of elements of the variable contained in its 1st data block */
154 INT64 usedLen; /* The number of elements of the variable that has actually been written in the file */
155 INT64 type; /* The type of the variable */
156} KFIndexBlockEntry64;
157
161 typedef struct _KFSuperIndexBlock32 {
162 KFSuperIndexBlockHeader32 header;
163 KFSuperIndexBlockEntry32 entries[KF_NUM_SUPERINDEX_BLOCK_ENTRIES32];
164} KFSuperIndexBlock32;
165 typedef struct _KFSuperIndexBlock64 {
166 KFSuperIndexBlockHeader64 header;
167 KFSuperIndexBlockEntry64 entries[KF_NUM_SUPERINDEX_BLOCK_ENTRIES64];
168} KFSuperIndexBlock64;
169
173 typedef struct _KFDataBlockHeader32 {
174 INT32 index[KF_N_DATATYPES]; /* Number of elements in this block, one per data type in the order: int, double, char, logical */
175} KFDataBlockHeader32;
176 typedef struct _KFDataBlockHeader64 {
177 INT64 index[KF_N_DATATYPES]; /* Number of elements in this block, one per data type in the order: int, double, char, logical */
178} KFDataBlockHeader64;
179
180 typedef struct _KFBlockRun {
181 int physBlock;
182 int logBlock;
183 int count;
184} KFBlockRun;
185
186 typedef struct _KFFile {
187 char *name;
188 ArrayList sections; /* ArrayList containing KFSection elements */
189 int fd; /* File descriptor if the file is open */
190 int byteOrder; /* BIG_ENDIAN or LITTLE_ENDIAN */
191 int integerSize; /* 4 or 8 */
192 int isOpen; /* 1 if open, otherwise closed */
193 int indexHeaderLength;
194 int indexEntryLength;
195 int superIndexHeaderLength;
196 int superIndexEntryLength;
197 int typeSize[5];
198} KFFile;
199
200 typedef struct _KFSection {
201 KFFile *file;
202 ArrayList indexBlockRuns; /* Array of KFBlockRun objects containing index */
203 ArrayList dataBlockRuns; /* Array of KFBlockRun objects containing data */
204 ArrayList variables; /* Array of KFVariable objects for this section */
205 int totalDataBlocks;
206 int totalIndexBlocks;
207 char name[KF_SECTION_NAME_LENGTH+1];
208} KFSection;
209
210 typedef struct _KFVariable {
211 KFSection *section;
212 int firstLogBlk; /* The logical block number of the data block where the varialbe starts */
213 int firstBlkIndex; /* The index into the data block where the variable starts.
214 Each index refers to the part of the data block containing data of its own type. */
215 int length; /* Length of the variable in elements (1 for scalars) */
216 int firstBlkLen; /* The number of elements of the variable contained in its 1st data block */
217 int usedLen; /* The number of elements of the variable that has actually been written in the file */
218 int type; /* The type of the variable */
219 int multiBlock; /* 0 if this variable occupies more than one block */
220 char name[KF_SECTION_NAME_LENGTH+1];
221} KFVariable;
222
223#ifdef __cplusplus
224extern "C" {
225#endif
226
227extern char *KFTypeNames[];
228
229/* Support functions */
230int getHostByteOrder();
231
232/* Primary methods for accessing KF file data */
233
234int openKFFile(KFFile *kf, const char *name); /* Return file descriptor or -1 if there was an error opening file */
235void closeKFFile (KFFile *kf); /* Free memory taken by the file structures and close the file */
236
237int getKFVariableLength(KFFile *kf, const char *name); /* returns variable length in units
238 of the corresponding type */
239int getKFVariableUsedLength(KFFile *kf, const char *name); /* returns the number of used elements in the variable */
240
241int getKFVariableType(KFFile *kf, const char *name); /* returns variable type (one of the
242 T_* macros) or 0 (zero) */
243
244/* Fills in the memory pointed to by buf with data from the KF file.
245 The memory space pointed to by buf must be large enough to hold all data.
246 IMPORTANT: the data is converted to a native for this platform type
247
248 kf - pointer to an open KF file
249 name - variable name in the form section%variable
250 buf - pointer to the receiving buffer that must be large enough to hold all data
251
252 returns the number of elements read or -1 if an error has occured
253*/
254int getKFData(KFFile *kf, const char *name, void *buf);
255
256
257#ifdef __cplusplus
258}
259#endif
260
261
262
263#endif
_KFBlockRun
Definition ADF_KFc.h:180
_KFDataBlockHeader32
Definition ADF_KFc.h:173
_KFDataBlockHeader64
Definition ADF_KFc.h:176
_KFFile
Definition ADF_KFc.h:186
_KFIndexBlockEntry32
Definition ADF_KFc.h:137
_KFIndexBlockEntry64
Definition ADF_KFc.h:147
_KFIndexBlockHeader32
Definition ADF_KFc.h:117
_KFIndexBlockHeader64
Definition ADF_KFc.h:125
_KFSection
Definition ADF_KFc.h:200
_KFSuperIndexBlock32
Definition ADF_KFc.h:161
_KFSuperIndexBlock64
Definition ADF_KFc.h:165
_KFSuperIndexBlockEntry32
Definition ADF_KFc.h:99
_KFSuperIndexBlockEntry64
Definition ADF_KFc.h:106
_KFSuperIndexBlockHeader32
Definition ADF_KFc.h:81
_KFSuperIndexBlockHeader64
Definition ADF_KFc.h:88
_KFVariable
Definition ADF_KFc.h:210