#! /bin/csh -f
#******************* Allocate Shapefiles Run Script **************************
# Allocates a polygon shapefile's data to an I/O API gridded file
# July 2005, CAS 
#  Dec. 2007, LR -- projection specification changes
#*****************************************************************************

setenv SOURCE_TYPE $1

setenv DEBUG_OUTPUT Y

setenv SA_HOME /aqm1/models/utils/Spatial-Allocator-master

# Set executable
setenv EXE "$SA_HOME/bin/32bits/allocator.exe"

# Set Input Directory
setenv DATADIR /aqm3/projects/sites/spatial/data
setenv OUTPUT /aqm3/projects/sites/spatial/output


# Select method of spatial analysis

setenv MIMS_PROCESSING ALLOCATE

setenv TIME time

#set "data" shapefile parameters
setenv GRIDDESC $DATADIR/GRIDDESC

#set parameters for file being allocated
setenv INPUT_FILE_NAME $DATADIR/shapefiles/BAAQMD_4km_CEPAM_2026_factors_${SOURCE_TYPE}
setenv INPUT_FILE_TYPE ShapeFile
setenv INPUT_FILE_MAP_PRJN "+proj=utm,+zone=10"
setenv INPUT_FILE_ELLIPSOID "+datum=NAD83"
setenv ALLOCATE_ATTRS IFIPS,TOG,ROG,CO,NOX,SOX,PM,PM10,PM25,NH3
setenv ALLOC_MODE_FILE ALL_DISCRETEOVERLAP

# Set name and path of resulting shapefile
setenv OUTPUT_FILE_NAME $OUTPUT/BAAQMD_4km_CEPAM_2026_factors_${SOURCE_TYPE}_overlap.ncf
setenv OUTPUT_FILE_TYPE IoapiFile
setenv OUTPUT_GRID_NAME BAAQMD_4km
setenv OUTPUT_FILE_MAP_PRJN BAAQMD_4km
setenv OUTPUT_FILE_ELLIPSOID "+a=6370000.0,+b=6370000.0"

if( -e ${OUTPUT_FILE_NAME} ) rm ${OUTPUT_FILE_NAME}

#echo "Allocating tracts to county for population and housing"
$TIME $EXE
