// // tvstudy.h // TV Study // // Copyright (c) 2012-2013 Hammett & Edison, Inc. All rights reserved. // Modify include to link to bsd libraries for Arch Linux // #include #include // #include #include // #include #include // #include #include #include #include // #include // Modify include for Linux #include //--------------------------------------------------------------------------------------------------------------------- // The version string changes whenever there are code changes. The cache version number is stored in cache files, when // it does not match the files are discarded. The cache version changes only when an update potentially makes cached // information invalid. The database version is stored in study records in the root database, if it does not match // the study cannot be opened. It changes when the database structure changes. The UI application has code to update // existing study databases in place when possible. When either version number changes it is derived from the then- // current version string "x.y.z" as "xyyzzz". #define TVSTUDY_VERSION "1.1.1" #define TVSTUDY_CACHE_VERSION 101001 #define TVSTUDY_DATABASE_VERSION 101000 // Database keys and enumeration values for study parameters. These must be kept in sync with database contents, see // the root database setup script for details. #define PARAM_GRID_TYPE 2 #define PARAM_CELL_SIZE 4 #define PARAM_ERROR_HNDLNG 10 #define PARAM_DEPANGLE_METH 12 #define PARAM_VPAT_MTILT 14 #define PARAM_VPAT_GEN_TILT 16 #define PARAM_TRUST_DA_FLAG 18 #define PARAM_AVG_TERR_DB 20 #define PARAM_AVG_TERR_RES 22 #define PARAM_PATH_TERR_DB 30 #define PARAM_PATH_TERR_RES 32 #define PARAM_US_CENSUS 40 #define PARAM_CA_CENSUS 42 #define PARAM_MX_CENSUS 44 #define PARAM_RND_POP_CRDS 46 #define PARAM_REPL_METH 50 #define PARAM_MIN_ERP_VLO 52 #define PARAM_MIN_ERP_VHI 54 #define PARAM_MIN_ERP_UHF 56 #define PARAM_MAX_ERP_VLO1 58 #define PARAM_MAX_ERP_VLO23 60 #define PARAM_MAX_ERP_VHI1 62 #define PARAM_MAX_ERP_VHI23 64 #define PARAM_MAX_ERP_UHF 66 #define PARAM_MAX_ERP_VHF_LP 68 #define PARAM_MAX_ERP_UHF_LP 70 #define PARAM_CL_VLO_DTV 80 #define PARAM_CL_VHI_DTV 82 #define PARAM_CL_UHF_DTV 84 #define PARAM_CL_VLO_DTV_LP 86 #define PARAM_CL_VHI_DTV_LP 88 #define PARAM_CL_UHF_DTV_LP 90 #define PARAM_CL_VLO_NTSC 92 #define PARAM_CL_VHI_NTSC 94 #define PARAM_CL_UHF_NTSC 96 #define PARAM_CL_VLO_NTSC_LP 98 #define PARAM_CL_VHI_NTSC_LP 100 #define PARAM_CL_UHF_NTSC_LP 102 #define PARAM_USE_DIPOLE 104 #define PARAM_DIPOLE_CENTER 106 #define PARAM_HAAT_RADIALS 120 #define PARAM_MIN_HAAT 121 #define PARAM_CONTOUR_RADIALS 122 #define PARAM_CONT_LIMIT_VLO 124 #define PARAM_CONT_LIMIT_VHI 126 #define PARAM_CONT_LIMIT_UHF 128 #define PARAM_RECEIVE_HEIGHT 130 #define PARAM_MIN_XMTR_HEIGHT 132 #define PARAM_RPAT_VLO_DTV 140 #define PARAM_RPAT_VHI_DTV 142 #define PARAM_RPAT_UHF_DTV 144 #define PARAM_RPAT_VLO_NTSC 146 #define PARAM_RPAT_VHI_NTSC 148 #define PARAM_RPAT_UHF_NTSC 150 #define PARAM_LOC_DTV_DES 160 #define PARAM_TME_DTV_DES 162 #define PARAM_CNF_DTV_DES 164 #define PARAM_LOC_DTV_UND 166 #define PARAM_CNF_DTV_UND 168 #define PARAM_LOC_NTSC_DES 170 #define PARAM_TME_NTSC_DES 172 #define PARAM_CNF_NTSC_DES 174 #define PARAM_LOC_NTSC_UND 176 #define PARAM_CNF_NTSC_UND 178 #define PARAM_SIG_POL 180 #define PARAM_ATM_REFRAC 182 #define PARAM_GND_PERMIT 184 #define PARAM_GND_CONDUC 186 #define PARAM_LR_SERV_MODE 190 #define PARAM_LR_CLIM_TYPE 192 #define PARAM_EARTH_SPH_DIST 200 #define PARAM_RULE_EXTRA_DIST 210 #define PARAM_CO_CHAN_MX_DIST 212 #define PARAM_APPLY_CLUTTER 249 #define PARAM_CLUTTER 250 // Start of a sequential range of parameter keys, see parameter.c. #define PARAM_N_CLUTTER 40 #define PARAM_N_LANDCOVER 16 #define PARAM_KEY_SIZE 306 // Size for parameter storage arrays, see parameter.c. // Constants for various parameters that are enumerated options, must match database contents. #define GRID_TYPE_LOCAL 1 // Values for PARAM_GRID_TYPE. #define GRID_TYPE_GLOBAL 2 #define ERRORS_IGNORE 1 // Values for PARAM_ERROR_HNDLNG. #define ERRORS_SERVICE 2 #define ERRORS_NOSERVICE 3 #define DEPANGLE_METH_EFF_HEIGHT 1 // Values for PARAM_DEPANGLE_METH. #define DEPANGLE_METH_TRUE 2 #define VPAT_GEN_TILT_NONE 0 // Values for PARAM_VPAT_GEN_TILT. #define VPAT_GEN_TILT_FULL 1 #define VPAT_GEN_TILT_OFFSET 2 #define TERR_DB1 1 // Values for PARAM_*_TERR_DB, used as argument to terrain_*() functions. #define TERR_DB3 2 #define TERR_DB30 3 #define REPL_METH_DERIVE 1 // Values for PARAM_REPL_METH. #define REPL_METH_AREA 2 // Database keys from root index tables for country, service, etc., also must match database. #define CNTRY_USA 1 // Country keys in source records - USA. #define CNTRY_CAN 2 // Canada. #define CNTRY_MEX 3 // Mexico. #define MAX_COUNTRY 3 // Number of possible countries. WARNING! The code uses country keys as index values in // arrays, after subtracting 1. The key range must be 1 through MAX_COUNTRY without gaps. #define SERV_DTV_FULL 1 // Service type keys for source records. Full service digital. #define SERV_NTSC_FULL 2 // Full service analog. #define SERV_DTV_CLASS_A 3 // Class A digital. #define SERV_NTSC_CLASS_A 4 // Class A analog. #define SERV_DTV_LPTV 5 // LPTV/translator/booster digital. #define SERV_NTSC_LPTV 6 // LPTV/translator/booster analog. #define ZONE_I 1 // Zone keys in source records. Zone 1. #define ZONE_II 2 // Zone 2. #define ZONE_III 3 // Zone 3. #define ZONE_NONE 0 // Undefined zone. #define FREQ_OFFSET_ZERO 1 // Frequency offest keys. Zero offset. #define FREQ_OFFSET_PLUS 2 // + offset. #define FREQ_OFFSET_MINUS 3 // - offset. #define FREQ_OFFSET_NONE 0 // No offset or N/A. #define LPTV_MASK_SIMPLE 1 // Emission mask keys for LPTV/Class A. Simple mask. #define LPTV_MASK_STRINGENT 2 // Stringent mask. #define LPTV_MASK_FULL_SERVICE 3 // Full-service mask. #define LPTV_MASK_NONE 0 // Unknown or N/A. // These must match like-named code constants in the front end app, used in interference rule data, see source.c. #define FREQUENCY_OFFSET_WITHOUT 1 #define FREQUENCY_OFFSET_WITH 2 // Other codes and values used only in this application, first values used in source.c. #define SERV_FULL 1 // Service type database key is broken out into a digital flag and this. #define SERV_CLASS_A 2 #define SERV_LPTV 3 #define BAND_VLO1 1 // Channel band keys. Channel 2-4. #define BAND_VLO2 2 // Channel 5-6. #define BAND_VHI 3 // Channel 7-13. #define BAND_UHF 4 // Channel 14-51. // Used in cell.c, these are from 73.626(c), the "Table of Distances" for DTS. #define DTS_MAX_DIST_VLOZ1 108. #define DTS_MAX_DIST_VLOZ23 128. #define DTS_MAX_DIST_VHIZ1 101. #define DTS_MAX_DIST_VHIZ23 123. #define DTS_MAX_DIST_UHF 103. // Flags and codes used in fcc_curve.c. #define FCC_DST 1 // Mode key. Compute distance from field/power. #define FCC_FLD 2 // Compute field from distance/power. #define FCC_PWR 3 // Compute power from distance/field. #define FCC_F50 1 // Curve set key. F(50,50). #define FCC_F10 2 // F(50,10). #define FCC_F90 3 // F(50,90). #define FCC_HGTLO 1 // Return status code. Height <30.5, used 30.5. #define FCC_HGTHI 2 // Height >1600, used 1600. #define FCC_DSTFS 3 // Distance too small, used free-space. #define FCC_FLDFS 4 // Field too large, used free-space. #define FCC_DST50 5 // Distance too small for F(50,10/90), used F(50,50). #define FCC_FLD50 6 // Field too large for F(50,10/90), used F(50,50). #define FCC_DSTHI 7 // Distance to large, used max distance. #define FCC_FLDLO 8 // Field too small, returned max distance. // Clutter bands and types, values are used to compute an index into the ClutterValues[] parameter array. #define CLUTTER_BAND_VLO 0 #define CLUTTER_BAND_VHI 1 #define CLUTTER_BAND_ULO 2 #define CLUTTER_BAND_UHI 3 #define N_CLUTTER_BANDS 4 #define CLUTTER_UNKNOWN 0 #define CLUTTER_OPEN_LAND 1 #define CLUTTER_AGRICULTURAL 2 #define CLUTTER_RANGELAND 3 #define CLUTTER_WATER 4 #define CLUTTER_FOREST_LAND 5 #define CLUTTER_WETLAND 6 #define CLUTTER_RESIDENTIAL 7 #define CLUTTER_MIXED_URBAN_BUILDINGS 8 #define CLUTTER_COMMERCIAL_INDUSTRIAL 9 #define CLUTTER_SNOW_AND_ICE 10 // Land cover types, see landcover.c. The values are used to index the LandCoverClutter[] parameter array. #define LANDCOVER_OPEN_WATER 0 #define LANDCOVER_PERENNIAL_ICE_SNOW 1 #define LANDCOVER_DEVELOPED_OPEN_SPACE 2 #define LANDCOVER_DEVELOPED_LOW_INTENSITY 3 #define LANDCOVER_DEVELOPED_MEDIUM_INTENSITY 4 #define LANDCOVER_DEVELOPED_HIGH_INTENSITY 5 #define LANDCOVER_BARREN_LAND_ROCK_SAND_CLAY 6 #define LANDCOVER_DECIDUOUS_FOREST 7 #define LANDCOVER_EVERGREEN_FOREST 8 #define LANDCOVER_MIXED_FOREST 9 #define LANDCOVER_SHRUB_SCRUB 10 #define LANDCOVER_GRASSLAND_HERBACEOUS 11 #define LANDCOVER_PASTURE_HAY 12 #define LANDCOVER_CULTIVATED_CROPS 13 #define LANDCOVER_WOODY_WETLANDS 14 #define LANDCOVER_EMERGENT_HERBACEOUS_WETLANDS 15 // Constants for shapefile code, see map.c. #define SHP_TYPE_NULL 0 // Supported shape types. #define SHP_TYPE_POINT 1 #define SHP_TYPE_POLYLINE 3 #define SHP_TYPE_POLYGON 5 #define SHP_ATTR_CHAR 'C' // Supported attribute types. #define SHP_ATTR_NUM 'N' #define SHP_ATTR_BOOL 'L' // Argument flags and error codes used in coordinates.c. #define CNV_N27N83 1 // Convert NAD27 to NAD83/WGS84 #define CNV_N83N27 2 // Convert NAD83/WGS84 to NAD27 #define CNV_W72N83 3 // Convert WGS72 to WGS84 #define CNV_N83W72 4 // Convert WGS84 to WGS72 #define CNV_EAREA 1 // Errors. Coordinates outside conversion area. #define CNV_EFILE 2 // File I/O error for NADCON algorithm. #define CNV_ECONV 3 // Failure to converge during iteration. // Codes for selection of cache type, see cache.c. #define CACHE_DES 1 #define CACHE_UND 2 // Misc. useful numbers. #define PI 3.14159265358979323 // Pi #define TWO_PI 6.2831853071795862 // 2 * Pi #define HALF_PI 1.5707963267948966 // Pi / 2 #define RADIANS_TO_DEGREES 57.295779513082323 // Radians to degrees. #define DEGREES_TO_RADIANS 0.017453292519943295 // Degrees to radians. #define TINY 1.e-20 // A small number. #define BIG 1.e20 // A large number. #define MAX_STRING 256 // Max length of misc. strings, i.e. file names. #define MAX_QUERY 10240 // Max length of a database query string. // Limit value on grid size causing a global-mode study grid to be broken up into smaller grids, see study.c. #define MAX_GRID_COUNT 5000000 //--------------------------------------------------------------------------------------------------------------------- // Structure definitions. typedef struct { // A bounding box structure using integer coordinates of varying units. See coordinates.c. int southLatIndex; int eastLonIndex; int northLatIndex; int westLonIndex; } INDEX_BOUNDS; typedef struct fld { // One calculated field strength in a study cell, desired or undesired. struct fld *next; // For list of fields in cell. float bearing; // Bearing from source to cell, degrees true. float reverseBearing; // Bearing from cell to source, degrees true. float distance; // Distance from source to cell, kilometers. float field; // Field strength, dBu. unsigned short sourceKey; // Source key. short percentTime; // Percent time variability for undesired, 0 for desired. short status; // Status, 0 = calculated no error, >0 calculated with error, <0 needs calculation. short cached; // True if data has been written to cache. } FIELD; typedef struct cel { // Data for one study cell. struct cel *next; // For list of cells at the same grid index, in case of multiple countries in grid. FIELD *fields; // Fields in cell, desired and undesired. double latitude; // Coordinates of study point, north latitude and west longitude, NAD83. double longitude; int latIndex; // Cell identifiers. Units of one arc-second but these are not the latitude and longitude in int lonIndex; // arc-seconds, these are the south-east corner of the cell in the study grid. int population; // Population in cell, may be 0. float area; // Cell area. float elevation; // Ground elevation at study coordinates. short clutterType; // Receiver clutter type, CLUTTER_*. short countryKey; // Country key, may be 0 for undetermined. } CELL; typedef struct { // Accumulator for interference. double ixArea; // Areas in square kilometers - total interference, double uniqueIxArea; // unique interference (from this source only), double errorArea; // path-loss model errors. int ixPop; // Population totals, as above. int uniqueIxPop; int errorPop; } UND_TOTAL; typedef struct { // Information for an undesired source with respect to a specific desired source. UND_TOTAL totals[MAX_COUNTRY]; // Interference totals by country. FIELD *field; // Used during local setup and analysis loops to collect fields in a cell. double ixDistance; // Maximum interference distance ("culling" distance). double requiredDU; // Required (minimum) D/U for no interference. unsigned short sourceKey; // Source key. short percentTime; // Percent time variability for field strength prediction. short adjustDU; // Set for co-channel to DTV desired, D/U is not fixed, see dtv_codu_adjust(). } UNDESIRED; typedef struct { // Accumulator for desired coverage. double contourArea; // Areas in square kilometers - inside contour, double serviceArea; // above service level, double ixFreeArea; // no interference, double errorArea; // path-loss model errors. int contourPop; // Population totals, as above. int servicePop; int ixFreePop; int errorPop; } DES_TOTAL; typedef struct { // Data for a vertical pattern. int np; // Number of points in pattern. double *dep; // Depression angles in degrees. double *pat; // Pattern values in relative dB. double mxdep; // Depression angle of max value, for "mirroring". size_t siz; // Size of allocated memory, see pattern.c. } VPAT; typedef struct { // Data for a matrix (a.k.a. per-azimuth) vertical pattern. int ns; // Number of slices. double *az; // Azimuths. int *np; // Number of points in each slice. double **dep; // Slice patterns. double **pat; size_t siz; // Size of allocated memory, see pattern.c. } MPAT; #define CALL_SIGN_L 13 // Lengths of source descriptive strings. #define CITY_L 21 #define STATE_L 3 #define STATUS_L 7 #define FILE_NUMBER_L 23 typedef struct src { // Data for a signal source (not always a station; DTS station has many sources). DES_TOTAL totals[MAX_COUNTRY]; // Coverage totals by country. INDEX_BOUNDS cellBounds; // Bounds of protected coverage area study cell grid, arc-second units. INDEX_BOUNDS gridIndex; // Bounds of desired cells in the study grid, units of grid index. INDEX_BOUNDS undGridIndex; // Bounds of undesired cells (only new calculations), units of grid index. double *hpat; // Horizontal pattern tabulation every 1 degree, relative dB. NULL for omni. VPAT *vpat; // Vertical pattern data, NULL for generic or matrix. MPAT *mpat; // Matrix pattern data, or NULL for generic or vpat. struct src *dtsSrcs; // Actual sources for DTS; parent only defines the service area contour. struct src *parentSrc; // Parent for a DTS source, NULL on parent or non-DTS. double *haat; // HAAT values computed for HAATCount radials, NULL if contour came from cache. double *cont; // Distance to contour for ContourCount radials. UNDESIRED *unds; // Undesired sources for this source as a desired, may be NULL. struct src *next; // For secondary and working lists; the full source list is in a flat array. double frequency; // Transmitter frequency in MHz, computed from channel. double latitude; // Coordinates of transmitter, north latitude and west longitude, NAD83. double longitude; double dtsLatitude; // Distance check reference point coordinates for a DTS parent, else not used. double dtsLongitude; double heightAMSL; // Transmitter height AMSL, meters. May be derived from HAAT for Canada. double overallHAAT; // Overall height above average terrain, meters. double heightAGL; // Transmitter height AGL, meters, determined from path-loss terrain database. double peakERP; // Maximum ERP, dBk. double hpatOrientation; // Horizontal pattern orientation value, degrees true. double vpatElectricalTilt; // Electrical beam tilt, degrees of depression. double vpatMechanicalTilt; // Mechanical beam tilt, degrees of depression. double vpatTiltOrientation; // Orientation azimuth for mechanical tilt, degrees true. double serviceLevel; // Service contour level, dBu. double cellArea; // Area of a cell in square kilometers for local mode, not used in global mode. double contourERP; // ERP to project the contour, may be != peakERP for a replication source. int facility_id; // CDBS facility ID. int cellLonSize; // Longitude size of cells, all cells in local mode, minimum in global mode. unsigned short sourceKey; // Database primary key, always unique in a given study. short needsUpdate; // True if source needs re-calculation and cache update. short inScenario; // True for sources in the current scenario being studied. short doStudy; // True if source will be studied, otherwise it only contributes interference. short serviceTypeKey; // Service type key, SERV_*. short service; // Service class, mapped from service type key. short dtv; // True for DTV, false for NTSC, mapped from service type key. short dts; // True for DTS (will always be DTV, may be any service). short channel; // Channel number. short band; // Channel band, BAND_*, mapped from channel. short clutterBand; // Channel band for clutter adjustments, CLUTTER_BAND_*, mapped from channel. short countryKey; // Country key, CNTRY_*. short zoneKey; // Zone key, ZONE_*. short frequencyOffsetKey; // Frequency offset key, FREQ_OFFSET_*. short emissionMaskKey; // LPTV/Class A digital emission mask key, LPTV_MASK_*. short hasHpat; // True if source has a directional horizontal pattern, else omni. short hasVpat; // True if source has vertical pattern, else generic or matrix is used. short hasMpat; // True if source has matrix pattern, else generic or vpat is used. unsigned short origSourceKey; // When replicating this is the original-channel source; else 0. short heightChanged; // True if AMSL height was modified during source pre-processing. short undCount; // Count of undesired sources. short cached; // True if source data has been written to cache. short hasDesiredCache; // True if source has a desired cell cache file. short dcache; // Utility flags used during setup and study, may indicate cell data needs to be short ucache; // loaded from cache, or new cell data needs to be written to cache. char callSign[CALL_SIGN_L]; // Information for reporting, not relevant to calculations. char city[CITY_L]; char state[STATE_L]; char status[STATUS_L]; char fileNumber[FILE_NUMBER_L]; } SOURCE; typedef struct { // General-purpose geographic data structure, a list of coordinates. See map.c. int nPts; // Current number of points stored, never greater than maxPts. int maxPts; // Allocated size of the arrays, this may be 0 in which case ptLat and ptLon are NULL. double *ptLat; // Arrays of point coordinates, positive north and west, NAD83. double *ptLon; } GEOPOINTS; typedef struct { // Define one attribute for a shapefile. See map.c. char *name; // Attribute name. char type; // Attribute type, SHP_TYPE_*. int length; // Attribute length. } SHAPEATTR; typedef struct { // Structure to manage a shapefile, see functions in map.c. FILE *shapeFile; // Shape file. FILE *indexFile; // Index file. FILE *dbFile; // DBF file. int shapeType; // Shape type in file, SHP_TYPE_*. int numAttr; // Number of attributes (DBF fields). int *attrLen; // Length of attributes. int recordNum; // Current record number in output. int totalSize; // Current total size of shape output. double xmin; // Accumulated bounding box. double ymin; double xmax; double ymax; } SHAPEFILE; //--------------------------------------------------------------------------------------------------------------------- // Function prototypes. // study.c int open_study(char *host, char *user, char *pass, int studyKey, char *studyName); void close_study(); int find_scenario_name(char *scenarioName); int run_scenario(int scenarioKey, FILE *reportFile, FILE *csvFile, FILE *cellFile, int analyzeByCell, char *shpName); // parameter.c int load_parameters(); // source.c int load_sources(); int load_scenario(int scenarioKey, char *shpName); double interp(double lookup, double *table, int count, double step); // report.c void report_header(FILE *reportFile, FILE *csvFile); void report_source(SOURCE *src, FILE *reportFile, FILE *csvFile); char *erpkw_string(double erpDbk); // cell.c int global_lon_size(int latIndex); double cell_area(int latIndex, int lonSize); int grid_setup(INDEX_BOUNDS cellBounds, int cellLonSize); int load_grid_population(SOURCE *src); int cell_setup(SOURCE *src); // cache.c int cache_setup(); int read_source_cache(SOURCE *src); int write_source_cache(SOURCE *src); int read_cell_cache(SOURCE *src, int cacheType, unsigned short desiredSourceKey); int write_cell_cache(SOURCE *src, int cacheType, unsigned short desiredSourceKey); // pattern.c int load_patterns(SOURCE *src); double erp_lookup(SOURCE *src, double azm); double vpat_lookup(SOURCE *src, double hgt, double dist, int eflg, double azm, double rhgt); double recv_az_lookup(SOURCE *src, double rot, double ang); // fcc_curve.c int fcc_curve(double *power, double *field, double *dist, double height, int iband, int mode1, int mode2, SOURCE *src); // longley_rice.c int longley_rice(SOURCE *src, short percentTime, float *profile, int ntp, double *field); // terrain.c int terrain_profile(double latStartDegrees, double lonStartDegrees, double bearingDegrees, double distanceKilometers, double pointsPerKilometer, int database, int maximumProfilePointCount, float *profileElevations, int *profilePointCount); int terrain_point(double latDegrees, double lonDegrees, int database, float *elevation); // landcover.c int land_cover(double lat, double lon); // map.c int find_country(double lat, double lon); SHAPEFILE *open_shapefile(char *baseName, int shapeType, int nAttr, SHAPEATTR *attrs); int write_shape(SHAPEFILE *shp, double ptLat, double ptLon, GEOPOINTS *pts, int nParts, int *iParts, char **attrData); void close_shapefile(SHAPEFILE *shp); GEOPOINTS *render_contour(SOURCE *src, double mapScale, GEOPOINTS *pts); GEOPOINTS *points_alloc(int np); void points_addpoint(GEOPOINTS *pts, double lat, double lon); void points_free(GEOPOINTS *pts); // coordinates.c int convert_coords(double xlat, double xlon, int jflg, double *ylat, double *ylon); void bear_distance(double lat1, double lon1, double lat2, double lon2, double *bear, double *rbear, double *dist); void coordinates(double lat1, double lon1, double bear, double dist, double *lat2, double *lon2); void initialize_bounds(INDEX_BOUNDS *bounds); void extend_bounds_index(INDEX_BOUNDS *bounds, int latIndex, int lonIndex); void extend_bounds_latlon(INDEX_BOUNDS *bounds, double lat, double lon); void extend_bounds_bounds(INDEX_BOUNDS *bounds, INDEX_BOUNDS *box); void extend_bounds_radius(INDEX_BOUNDS *bounds, double lat, double lon, double radius); int inside_bounds_index(INDEX_BOUNDS *bounds, int latIndex, int lonIndex); int inside_bounds_latlon(INDEX_BOUNDS *bounds, double lat, double lon); int inside_bounds_bounds(INDEX_BOUNDS *bounds, INDEX_BOUNDS *box); int overlaps_bounds(INDEX_BOUNDS *bounds, INDEX_BOUNDS *box); // memory.c void init_cell_pools(); CELL *get_cell(int gridRowIndex); void init_field_pools(); FIELD *get_field(int gridRowIndex); void *mem_alloc(size_t size); void *mem_zalloc(size_t size); void *mem_calloc(size_t count, size_t size); void *mem_realloc(void *ptr, size_t size); void mem_free(void *ptr); void memswabcpy(void *to, void *from, size_t count, size_t align); // log.c void log_open(FILE *messageLog, FILE *errorLog); void log_message(const char *fmt, ...); void log_error(const char *fmt, ...); void log_db_error(const char *fmt, ...); //--------------------------------------------------------------------------------------------------------------------- // Global parameters, see parameter.c. extern int GridType; extern double CellSize; extern int ErrorHandling; extern int DepressionAngleMethod; extern int VpatMechTilt; extern int GenericVpatTilt; extern int TrustPatternFlag; extern int TerrAvgDb; extern double TerrAvgPpk; extern int TerrPathDb; extern double TerrPathPpk; extern int CenYear[MAX_COUNTRY]; extern int RoundPopCoords; extern int ReplicationMethod; extern double MinimumVloERP; extern double MinimumVhiERP; extern double MinimumUhfERP; extern double MaximumVloZ1ERP; extern double MaximumVloZ23ERP; extern double MaximumVhiZ1ERP; extern double MaximumVhiZ23ERP; extern double MaximumUhfERP; extern double MaximumVhfErpLPTV; extern double MaximumUhfErpLPTV; extern double ContourVloDigital; extern double ContourVhiDigital; extern double ContourUhfDigital; extern double ContourVloDigitalLPTV; extern double ContourVhiDigitalLPTV; extern double ContourUhfDigitalLPTV; extern double ContourVloAnalog; extern double ContourVhiAnalog; extern double ContourUhfAnalog; extern double ContourVloAnalogLPTV; extern double ContourVhiAnalogLPTV; extern double ContourUhfAnalogLPTV; extern int UseDipole; extern double DipoleCenterFreq; extern int HAATCount; extern double HAATStep; extern double MinimumHAAT; extern int ContourCount; extern double ContourStep; extern double ContourLimitVlo; extern double ContourLimitVhi; extern double ContourLimitUhf; extern double ReceiveHeight; extern double MinimumHeightAGL; extern double ReceivePatVloDigital; extern double ReceivePatVhiDigital; extern double ReceivePatUhfDigital; extern double ReceivePatVloAnalog; extern double ReceivePatVhiAnalog; extern double ReceivePatUhfAnalog; extern int DigitalDesiredLocation; extern int DigitalDesiredTime; extern int DigitalDesiredConfidence; extern int DigitalUndesiredLocation; extern int DigitalUndesiredConfidence; extern int AnalogDesiredLocation; extern int AnalogDesiredTime; extern int AnalogDesiredConfidence; extern int AnalogUndesiredLocation; extern int AnalogUndesiredConfidence; extern int SignalPolarization; extern double AtmosphericRefractivity; extern double GroundPermittivity; extern double GroundConductivity; extern int LRServiceMode; extern int LRClimateType; extern double KilometersPerDegree; extern double RuleExtraDistance; extern double CoChannelMxDistance; extern int ApplyClutter; extern double ClutterValues[PARAM_N_CLUTTER]; extern int LandCoverClutter[PARAM_N_LANDCOVER]; //--------------------------------------------------------------------------------------------------------------------- // Study globals, see study.c. extern MYSQL *MyConnection; extern int StudyKey; extern char StudyName[MAX_STRING]; extern char ParameterSummary[MAX_QUERY]; //--------------------------------------------------------------------------------------------------------------------- // Globals for source data, see source.c. extern SOURCE *Sources; extern int SourceCount; extern SOURCE **SourceKeyIndex; extern int SourceIndexSize; extern int SourceIndexMaxSize; extern int ScenarioKey; extern char ScenarioName[MAX_STRING]; //--------------------------------------------------------------------------------------------------------------------- // Globals for cell grid, see cell.c. extern INDEX_BOUNDS CellBounds; extern INDEX_BOUNDS GridIndex; extern int GridCount; extern CELL **GridCells; extern int GridMaxCount; extern int CellLatSize; extern int GridLatCount; extern int CellLonSize; extern int GridLonCount; extern int *CellLonSizes; extern double *CellAreas; extern int *GridLonCounts; extern int *CellEastLonIndex; extern int GridMaxLatCount;