Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
b474d592
Commit
b474d592
authored
Mar 23, 2019
by
Loic Hausammann
Browse files
Logger: Start implementing the logger_index
parent
3ff86beb
Changes
2
Hide whitespace changes
Inline
Side-by-side
logger/logger_index.c
0 → 100644
View file @
b474d592
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
/* Config parameters. */
#include
"../config.h"
/* Some standard headers. */
#include
<stdio.h>
/* This object's header. */
#include
"logger_index.h"
#include
"logger_tools.h"
/**
* @brief Initialize the #logger_index.
*
* @param index The #logger_index.
* @param reader The #logger_reader.
* @param basename The basename of the index files.
*/
void
logger_index_init
(
struct
logger_index
*
index
,
struct
logger_reader
*
reader
,
char
*
basename
)
{
/* Set pointers to 0 */
index
->
offsets
=
NULL
;
index
->
ids
=
NULL
;
}
/**
* @brief Read a single index file.
*
* @param index The #logger_index.
* @param i The index of the file.
*/
void
logger_index_read_file
(
struct
logger_index
*
index
,
int
i
)
{
/* Cleanup the memory of previous file */
logger_index_free_current_file
(
index
);
/* Open file */
FILE
*
f
=
NULL
;
f
=
fopen
(
index
->
filenames
[
i
],
"wb"
);
/* Read the double time */
double
time
;
fread
(
&
time
,
sizeof
(
double
),
1
,
f
);
/* Read integer time */
double
int_time
;
fread
(
&
int_time
,
sizeof
(
integertime_t
),
1
,
f
);
/* Read the number of particles */
long
long
N_total
[
swift_type_count
];
fread
(
N_total
,
sizeof
(
long
long
),
swift_type_count
,
f
);
/* Count total number of particles */
long
long
N
=
0
;
for
(
int
i
=
0
;
i
<
swift_type_count
;
i
++
)
{
N
+=
N_total
[
i
];
}
/* Read Ids */
if
(
posix_memalign
((
void
**
)
&
index
->
ids
,
IO_BUFFER_ALIGNMENT
,
N
*
sizeof
(
long
long
))
!=
0
)
error
(
"Unable to allocate the offset buffer"
);
fread
(
index
->
ids
,
sizeof
(
size_t
),
N
,
f
);
/* Read offsets */
if
(
posix_memalign
((
void
**
)
&
index
->
offsets
,
IO_BUFFER_ALIGNMENT
,
N
*
sizeof
(
size_t
))
!=
0
)
error
(
"Unable to allocate the offset buffer"
);
fread
(
index
->
offset
,
sizeof
(
size_t
),
N
,
f
);
/* Close file */
fclose
(
f
);
}
/**
* @brief Free the memory allocated for current file.
*
* @param index The #logger_index.
*/
void
logger_index_free_current_file
(
struct
logger_index
*
index
)
{
/* Free offsets */
if
(
index
->
offsets
)
free
(
index
->
offsets
);
index
->
offsets
=
NULL
;
/* Free ids */
if
(
index
->
ids
)
free
(
index
->
ids
);
index
->
ids
=
NULL
;
}
/**
* @brief Free the memory.
*
* @param index The #logger_index.
*/
void
logger_index_free
(
struct
logger_index
*
index
)
{
/* Free the memory allocated for current file */
logger_index_free_file_data
(
index
);
/* Free the filenames */
for
(
int
i
=
0
;
i
<
index
->
number_files
;
i
++
)
{
if
(
index
->
filenames
[
i
])
free
(
index
->
filenames
[
i
]);
index
->
filenames
[
i
]
=
NULL
;
}
/* Free the array of filenames */
free
(
index
->
filenames
);
index
->
filenames
=
NULL
;
}
logger/logger_index.h
View file @
b474d592
...
...
@@ -23,10 +23,38 @@
#ifndef __LOGGER_LOGGER_INDEX_H__
#define __LOGGER_LOGGER_INDEX_H__
struct
logger_reader
;
/**
* @brief This structure will contain the data related to
* the index file.
*/
struct
logger_index
{};
struct
logger_index
{
/* The reader */
struct
logger_reader
*
reader
;
/* List of the time for each file */
double
*
times
;
/* Number of files */
int
number_files
;
/* List of all the index files */
char
**
filenames
;
/* Offsets */
size_t
*
offsets
;
/* ids */
long
long
ids
;
};
void
logger_index_init
(
struct
logger_index
*
index
,
struct
logger_reader
*
reader
,
char
*
basename
);
void
logger_index_read_file
(
struct
logger_index
*
index
,
int
i
);
void
logger_index_free
(
struct
logger_index
*
index
);
void
logger_index_free_current_file
(
struct
logger_index
*
index
);
#endif // __LOGGER_LOGGER_INDEX_H__
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment