Skip to content

Commit e9ed8b0

Browse files
committed
Code cleanup 1 for PR
1 parent a10988b commit e9ed8b0

File tree

8 files changed

+34
-28
lines changed

8 files changed

+34
-28
lines changed

events.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ EventNode** readEventData(char *eventFile, int numLocs) {
142142
currYear = year;
143143
currDay = day;
144144

145-
//printf("Found events:\n");
146-
//printEvent(next);
147-
148145
while (fgets(line, EVENT_LINE_SIZE, in) != NULL) {
149146
// We have another event
150147
curr = next;
@@ -171,7 +168,6 @@ EventNode** readEventData(char *eventFile, int numLocs) {
171168
}
172169

173170
next = createEventNode(loc, year, day, eventType, eventParamsStr);
174-
//printEvent(next);
175171
if (currLoc == loc) {
176172
// Same location, add the new event to this location's list
177173
curr->nextEvent = next;

events.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ struct EventNode {
5555
EventNode *nextEvent;
5656
};
5757

58-
/* Read event data from <FILENAME>.event
58+
/* Read event data from input filename (canonically events.in)
5959
*
6060
* Format: returned data is structured as an array of EventNode pointers, indexed by
6161
* location. Each element of the array is the first event for that location (or null
62-
* if there are no events). It is assumed that the events are in chrono order.
62+
* if there are no events). It is assumed that the events are ordered first by location
63+
* and then by year and day.
6364
*/
6465
EventNode** readEventData(char *eventFile, int numLocs);
6566

frontend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int main(int argc, char *argv[]) {
8282
double **standarddevs;
8383
int dataTypeIndices[MAX_DATA_TYPES];
8484

85-
#ifdef EVENT_HANDLER
85+
#if EVENT_HANDLER
8686
// Extra filename if we are handing events
8787
char eventFile[FILE_MAXNAME+24];
8888
#endif

modelStructures.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
// See also sipnet.c for other options (that should be moved here if/when testing is added)
1212

1313
#define EVENT_HANDLER 0
14-
// Read in and process agronomic events. Expects a file named <FILENAME>.event to exist.
14+
// Read in and process agronomic events. SIPNET expects a file named events.in to exist, though
15+
// unit tests may use other names.
1516

1617

1718
#endif //MODEL_STRUCTURES_H

sipnet.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,8 @@ static ClimateNode *climate; // current climate
489489
static Fluxes fluxes;
490490
static double *outputPtrs[MAX_DATA_TYPES]; // pointers to different possible outputs
491491

492-
#ifdef EVENT_HANDLER
493-
static EventNode **events; // MJL: event structs
492+
#if EVENT_HANDLER
493+
static EventNode **events;
494494
#endif
495495

496496
/* Read climate file into linked lists,
@@ -1936,8 +1936,8 @@ void calculateFluxes() {
19361936
double potGrossPsn; // potential photosynthesis, without water stress
19371937
double dWater;
19381938
double lai; // m^2 leaf/m^2 ground (calculated from plantLeafC)
1939-
//double litterBreakdown; /* total litter breakdown (i.e. litterToSoil + rLitter)
1940-
// (g C/m^2 ground/day) */
1939+
//double litterBreakdown; /* total litter breakdown (i.e. litterToSoil + rLitter)
1940+
//(g C/m^2 ground/day) */
19411941
double folResp, woodResp; // maintenance respiration terms, g C * m^-2 ground area * day^-1
19421942
double litterWater, soilWater; /* amount of water in litter and soil (cm)
19431943
taken from either environment or climate drivers, depending on value of MODEL_WATER */
@@ -2485,7 +2485,7 @@ void setupModel(SpatialParams *spatialParams, int loc) {
24852485

24862486
// Setup events at given location
24872487
void setupEvents(int currLoc) {
2488-
2488+
// Implementation TBD
24892489
}
24902490

24912491

@@ -2514,8 +2514,8 @@ void runModelOutput(FILE *out, OutputItems *outputItems, int printHeader, Spatia
25142514

25152515
for (currLoc = firstLoc; currLoc <= lastLoc; currLoc++) {
25162516
setupModel(spatialParams, currLoc);
2517-
#ifdef EVENT_HANDLER
2518-
setupEvents(currLoc);
2517+
#if EVENT_HANDLER
2518+
setupEvents(currLoc);
25192519
#endif
25202520
if ((loc == -1) && (outputItems != NULL)) { // print the current location at the start of the line
25212521
sprintf(label, "%d", currLoc);
@@ -2525,15 +2525,16 @@ void runModelOutput(FILE *out, OutputItems *outputItems, int printHeader, Spatia
25252525
while (climate != NULL) {
25262526
updateState();
25272527
if (out != NULL) {
2528-
outputState(out, currLoc, climate->year, climate->day, climate->time);
2528+
outputState(out, currLoc, climate->year, climate->day, climate->time);
25292529
}
25302530
if (outputItems != NULL) {
2531-
writeOutputItemValues(outputItems);
2531+
writeOutputItemValues(outputItems);
25322532
}
25332533
climate = climate->nextClim;
25342534
}
2535-
if (outputItems != NULL)
2535+
if (outputItems != NULL) {
25362536
terminateOutputItemLines(outputItems);
2537+
}
25372538
}
25382539
}
25392540

@@ -2794,7 +2795,7 @@ int initModel(SpatialParams **spatialParams, int **steps, char *paramFile, char
27942795
* Populates static event structs
27952796
*/
27962797
void initEvents(char *eventFile, int numLocs) {
2797-
#ifdef EVENT_HANDLER
2798+
#if EVENT_HANDLER
27982799
events = readEventData(eventFile, numLocs);
27992800
#endif
28002801
}

sipnet.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ char **getDataTypeNames();
5252
int initModel(SpatialParams **spatialParams, int **steps, char *paramFile, char *climFile);
5353

5454
/*
55-
* TBD
55+
* Read in event data for all the model runs
56+
*
57+
* Read in event data from a file with the following specification:
58+
* - one line per event
59+
* - all events are ordered first by location (ascending) and then by year/day (ascending)
60+
*
61+
* @param eventFile Name of file containing event data
62+
* @param numLocs Number of locations in the event file.
5663
*/
5764
void initEvents(char *eventFile, int numLocs);
5865

tests/sipnet/exitHandler.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <setjmp.h>
22
#include <unistd.h>
33

4+
//
5+
46
static int expected_code = 1; // the expected value a tested function passes to exit
5-
static int should_exit = 1; // 1 if exit should have been called
6-
static int really_exit = 0; // set to 1 to prevent stubbing behavior and actually exit
7+
static int should_exit = 1; // set in test code; 1 if exit should have been called
8+
static int really_exit = 0; // set to 1 to prevent stubbing behavior and actually exit
79

810
static jmp_buf jump_env;
911

@@ -19,7 +21,7 @@ static int exit_result = 1;
1921
// }
2022
// test_assert(jmp_rval==0);
2123
//
22-
// set should_exit=1 when exit(0 is expected:
24+
// set should_exit=1 when exit is expected:
2325
//
2426
// should_exit = 1;
2527
// expected_code = 1; // or whatever the exit code should be
@@ -40,8 +42,6 @@ void exit(int code)
4042
test_assert(expected_code==code);
4143
longjmp(jump_env, 1);
4244
}
43-
else
44-
{
45-
_exit(code);
46-
}
45+
46+
_exit(code);
4747
}

tests/test.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ int main() {
3434
}
3535

3636
cleanup();
37-
}
37+
}

0 commit comments

Comments
 (0)