Skip to content

Commit

Permalink
Separate SW_netCDF.c into General, Input and Output
Browse files Browse the repository at this point in the history
- Motivation: With nc inputs coming with the branch, it is good to modularize the different functionalities

- Rename current `SW_netCDF.c` to `SW_netCDF_General.c`
- Create two new files including their own header file
	* SW_netCDF_Input.c
	* SW_netCDF_Output.c

- SW_netCDF_General.c
	* Provides general functionality between itself and the two other files
	* This file includes
		- The writing/getting of attribute/values from netCDF variables/dimensions
		- The full creation of templates and variables
		- Getting dimension sizes
		- Reading input/output information
	* Most functions that were previously static in SW_netCDF.c have been converted to functions with global-level visibility or were moved to the other two files

- SW_netCDF_Output.c
	* Contains functionality that pertains to netCDF outputs
	* Main functionalities that are contained within this are
		- Reading the output variable information into the program
		- Conversion from SOILWAT2 units to output units
		- Creation of and writing to output files

- SW_netCDF_Input.c
	* Contains functionality that pertains to netCDF inputs
	* Main functionalities that are contained within this are
		- Creating/modifying domain/progress files
		- Reading user inputted values

- Modified function `SW_NC_init_ptrs()` to call helper functions within Output and Input files
	* `SW_NCOUT_init_ptrs()` and `SW_NCIN_init_ptrs()` do mostly the same of what `SW_NC_init_ptrs()` did minus the point below
- Removed commented chunk of code from `SW_OUTDOM_init_ptrs()` and placed it in `SW_NCIN_init_ptrs()`
- Moved static local variables and defines to their respective file
  • Loading branch information
N1ckP3rsl3y committed Aug 13, 2024
1 parent 07afd21 commit fbea26e
Show file tree
Hide file tree
Showing 13 changed files with 6,261 additions and 6,075 deletions.
178 changes: 0 additions & 178 deletions include/SW_netCDF.h

This file was deleted.

181 changes: 181 additions & 0 deletions include/SW_netCDF_General.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#ifndef SWNETCDF_GEN_H
#define SWNETCDF_GEN_H

#include "include/generic.h" // for Bool, IntUS
#include "include/SW_datastructs.h" // for SW_DOMAIN, SW_NETCDF_OUT, S...
#include "include/SW_Defines.h" // for OutPeriod, SW_OUTNPERIODS, SW_OUTN...
#include <stdio.h> // for size_t

#ifdef __cplusplus
extern "C" {
#endif

/* =================================================== */
/* Local Definitions */
/* --------------------------------------------------- */

/** Domain netCDF index within `InFilesNC` and `varNC` (SW_NETCDF_OUT) */
#define vNCdom 0

/** Progress netCDF index within `InFilesNC` and `varNC` (SW_NETCDF_OUT) */
#define vNCprog 1

#define MAX_NUM_DIMS 5

/** Number of possible keys within `attributes_nc.in` */
#define NUM_ATT_IN_KEYS 28

/* =================================================== */
/* Global Function Declarations */
/* --------------------------------------------------- */

void SW_NC_get_dimlen_from_dimid(
int ncFileID, int dimID, size_t *dimVal, LOG_INFO *LogInfo
);

void SW_NC_get_dim_identifier(
int ncFileID, const char *dimName, int *dimID, LOG_INFO *LogInfo
);

void SW_NC_check(
SW_DOMAIN *SW_Domain, int ncFileID, const char *fileName, LOG_INFO *LogInfo
);

void SW_NC_get_single_val(
int ncFileID,
int *varID,
const char *varName,
size_t index[],
void *value,
const char *type,
LOG_INFO *LogInfo
);

void SW_NC_write_att(
const char *attName,
void *attVal,
int varID,
int ncFileID,
size_t numVals,
int ncType,
LOG_INFO *LogInfo
);

void SW_NC_write_string_att(
const char *attName,
const char *attStr,
int varID,
int ncFileID,
LOG_INFO *LogInfo
);

void SW_NC_write_string_vals(
int ncFileID, int varID, const char *const varVals[], LOG_INFO *LogInfo
);

Bool SW_NC_dimExists(const char *targetDim, int ncFileID);

Bool SW_NC_varExists(int ncFileID, const char *varName);

void SW_NC_write_vals(
int *varID,
int ncFileID,
const char *varName,
void *values,
size_t start[],
size_t count[],
const char *type,
LOG_INFO *LogInfo
);

void SW_NC_get_str_att_val(
int ncFileID,
const char *varName,
const char *attName,
char *strVal,
LOG_INFO *LogInfo
);

void SW_NC_create_netCDF_dim(
const char *dimName,
unsigned long size,
const int *ncFileID,
int *dimID,
LOG_INFO *LogInfo
);

void SW_NC_get_var_identifier(
int ncFileID, const char *varName, int *varID, LOG_INFO *LogInfo
);

void SW_NC_get_dimlen_from_dimname(
int ncFileID, const char *dimName, size_t *dimVal, LOG_INFO *LogInfo
);

void SW_NC_create_full_var(
int *ncFileID,
const char *domType,
int newVarType,
size_t timeSize,
size_t vertSize,
size_t pftSize,
const char *varName,
const char *attNames[],
const char *attVals[],
unsigned int numAtts,
Bool hasConsistentSoilLayerDepths,
double lyrDepths[],
double *startTime,
unsigned int baseCalendarYear,
unsigned int startYr,
OutPeriod pd,
int deflateLevel,
LOG_INFO *LogInfo
);

void SW_NC_dealloc_outputkey_var_info(SW_OUT_DOM *OutDom, IntUS k);

void SW_NC_create_netCDF_var(
int *varID,
const char *varName,
int *dimIDs,
const int *ncFileID,
int varType,
int numDims,
size_t chunkSizes[],
int deflateLevel,
LOG_INFO *LogInfo
);

void SW_NC_create_template(
const char *domType,
const char *domFile,
const char *fileName,
int *newFileID,
Bool isInput,
const char *freq,
LOG_INFO *LogInfo
);

void SW_NC_deconstruct(SW_NETCDF_OUT *SW_netCDFOut, SW_NETCDF_IN *SW_netCDFIn);

void SW_NC_deepCopy(
SW_NETCDF_OUT *source_output,
SW_NETCDF_IN *source_input,
SW_NETCDF_OUT *dest_output,
SW_NETCDF_IN *dest_input,
LOG_INFO *LogInfo
);

void SW_NC_read(
SW_NETCDF_IN *SW_netCDFIn,
SW_NETCDF_OUT *SW_netCDFOut,
SW_PATH_INPUTS *SW_PathInputs,
LOG_INFO *LogInfo
);

#ifdef __cplusplus
}
#endif

#endif // SWNETCDF_GEN_H
Loading

0 comments on commit fbea26e

Please sign in to comment.