Skip to content

Commit

Permalink
Organize headers in C-Extension
Browse files Browse the repository at this point in the history
Header files should only contain includes that are necessary for the
compiler to understand the header. Includes needed by the implementation
should be included by the corresponding source.

With this philosophy in mind the includes in all c files were
reorganized.
As part of this reorganization the header `cmontecarlo1.h` was removed
and it's declaration moved to `cmontecarlo.h`

Resolves: #489
  • Loading branch information
yeganer committed Mar 30, 2016
1 parent 55c19d3 commit ca82a9f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 38 deletions.
18 changes: 15 additions & 3 deletions tardis/montecarlo/src/cmontecarlo.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#define _POSIX_C_SOURCE 1

#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#ifdef WITHOPENMP
#include <omp.h>
#endif
#include "io.h"
#include "abbrev.h"
#include "status.h"
#include "rpacket.h"
#include "cmontecarlo.h"
#include "io.h"


/** Look for a place to insert a value in an inversely sorted float array.
Expand All @@ -18,7 +22,7 @@
*
* @return index of the next boundary to the left
*/
static tardis_error_t
tardis_error_t
reverse_binary_search (const double *x, double x_insert,
int64_t imin, int64_t imax, int64_t * result)
{
Expand Down Expand Up @@ -59,6 +63,14 @@ reverse_binary_search (const double *x, double x_insert,
return ret_val;
}

/** Insert a value in to an array of line frequencies
*
* @param nu array of line frequencies
* @param nu_insert value of nu key
* @param number_of_lines number of lines in the line list
*
* @return index of the next line ot the red. If the key value is redder than the reddest line returns number_of_lines.
*/
tardis_error_t
line_search (const double *nu, double nu_insert, int64_t number_of_lines,
int64_t * result)
Expand Down
20 changes: 11 additions & 9 deletions tardis/montecarlo/src/cmontecarlo.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
#ifndef TARDIS_CMONTECARLO_H
#define TARDIS_CMONTECARLO_H

#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "randomkit/randomkit.h"
#include "rpacket.h"
#include "status.h"
#include "cmontecarlo1.h"
#include "storage.h"

#ifdef WITH_VPACKET_LOGGING
#define LOG_VPACKETS 1
#else
#define LOG_VPACKETS 0
#endif

typedef void (*montecarlo_event_handler_t) (rpacket_t * packet,
storage_model_t * storage,
typedef void (*montecarlo_event_handler_t) (rpacket_t *packet,
storage_model_t *storage,
double distance, rk_state *mt_state);

void initialize_random_kit (unsigned long seed);

tardis_error_t line_search (const double *nu, double nu_insert,
int64_t number_of_lines, int64_t * result);

tardis_error_t
reverse_binary_search (const double *x, double x_insert,
int64_t imin, int64_t imax, int64_t * result);

double rpacket_doppler_factor(const rpacket_t *packet, const storage_model_t *storage);

/** Calculate the distance to shell boundary.
Expand Down Expand Up @@ -55,7 +57,7 @@ tardis_error_t compute_distance2line (const rpacket_t * packet,
*
* sets distance to the next continuum event (in centimeters) in packet rpacket structure
*/
void compute_distance2continuum (rpacket_t * packet, storage_model_t * storage);
void compute_distance2continuum (rpacket_t *packet, storage_model_t *storage);

int64_t macro_atom (const rpacket_t * packet, const storage_model_t * storage, rk_state *mt_state);

Expand Down
15 changes: 0 additions & 15 deletions tardis/montecarlo/src/cmontecarlo1.h

This file was deleted.

4 changes: 3 additions & 1 deletion tardis/montecarlo/src/io.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#define _POSIX_C_SOURCE 1

#include <unistd.h>
#include <inttypes.h>
#include <stdio.h>
#include <unistd.h>

#define STATUS_FORMAT "\r\033[2K\t[%" PRId64 "%%] Packets(finished/total): %" PRId64 "/%" PRId64

Expand Down
5 changes: 5 additions & 0 deletions tardis/montecarlo/src/rpacket.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include <stdbool.h>
#include <stdint.h>
#include "rpacket.h"
#include "storage.h"

extern tardis_error_t line_search (const double *nu, double nu_insert,
int64_t number_of_lines, int64_t * result);

tardis_error_t
rpacket_init (rpacket_t * packet, storage_model_t * storage, int packet_index,
int virtual_packet_flag)
Expand Down
6 changes: 1 addition & 5 deletions tardis/montecarlo/src/rpacket.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#ifndef TARDIS_RPACKET_H
#define TARDIS_RPACKET_H

#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "randomkit/randomkit.h"
#include "status.h"
#include "storage.h"
#include "cmontecarlo1.h"

#define MISS_DISTANCE 1e99
#define C 29979245800.0
Expand Down
7 changes: 2 additions & 5 deletions tardis/montecarlo/src/storage.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#ifndef TARDIS_STORAGE_H
#define TARDIS_STORAGE_H

#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#include "status.h"

typedef struct StorageModel
{
Expand Down

0 comments on commit ca82a9f

Please sign in to comment.