# The field route_togrid is with indices on the local grid. That needs to be converted to the global grid.
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"routetogrid","Grid into which the basin flows","-",grgrid,vtyp,"int")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"routetogrid","Grid into which the basin flows","-",grgrid,vtyp,orig_type="int")
# route to basin
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"routetobasin","Basin in to which the water goes","-",self.route_tobasin[:,:],vtyp,"int")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"routetobasin","Basin in to which the water goes","-",self.route_tobasin[:,:],vtyp,orig_type="int")
# basin id
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"basinid","ID of basin","-",self.global_basinid[:,:],vtyp,"int")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"basinid","ID of basin","-",self.global_basinid[:,:],vtyp,orig_type="int")
#
# basin area
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"basin_area","area of basin","m^2",self.routing_area[:,:],vtyp,"float")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"basin_area","area of basin","m^2",self.routing_area[:,:],vtyp)
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"basin_floodp","Fraction of floodplains","-",self.routing_floodp[:,:],vtyp,"float")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"basin_floodp","Fraction of floodplains","-",self.routing_floodp[:,:],vtyp)
# route number into basin
self.add_variable(outnf,procgrid,NCFillValue,part,('y','x'),"routenbintobas","Number of basin into current one","-",self.route_nbintobas[:],vtyp,"int")
self.add_variable(outnf,procgrid,NCFillValue,part,('y','x'),"routenbintobas","Number of basin into current one","-",self.route_nbintobas[:],vtyp,orig_type="int")
#
# original number into basin
self.add_variable(outnf,procgrid,NCFillValue,part,('y','x'),"originnbintobas","Number of sub-grid basin into current one before truncation","-",self.origin_nbintobas[:],vtyp,"int")
self.add_variable(outnf,procgrid,NCFillValue,part,('y','x'),"originnbintobas","Number of sub-grid basin into current one before truncation","-", \
self.origin_nbintobas[:],vtyp,orig_type="int")
#
# latitude of outlet
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"outletlat","Latitude of Outlet","degrees north",self.route_outlet[:,:,0],vtyp,"float")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"outletlat","Latitude of Outlet","degrees north",self.route_outlet[:,:,0],vtyp)
# longitude of outlet
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"outletlon","Longitude of Outlet","degrees east",self.route_outlet[:,:,1],vtyp,"float")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"outletlon","Longitude of Outlet","degrees east",self.route_outlet[:,:,1],vtyp)
# type of outlet
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"outlettype","Type of outlet","code",self.route_type[:,:],vtyp,"float")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"outlettype","Type of outlet","code",self.route_type[:,:],vtyp)
#
# topographic index
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"topoindex","Topographic index of the retention time","m",self.topo_resid[:,:],vtyp,"float")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"topoindex","Topographic index of the retention time","m",self.topo_resid[:,:],vtyp)
#
# Inflow number
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"route_innum","Number of inflow","-",self.route_innum[:,:],vtyp,"int")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"route_innum","Number of inflow","-",self.route_innum[:,:],vtyp,orig_type="int")
self.add_variable(outnf,procgrid,NCFillValue,part,('inflow','z','y','x'),"route_ingrid","Grid from which the water flows","-",self.route_ingrid[:,:,:],vtyp,"int")
self.add_variable(outnf,procgrid,NCFillValue,part,('inflow','z','y','x'),"route_ingrid","Grid from which the water flows","-", \
self.route_ingrid[:,:,:],vtyp,orig_type="int")
#
# Inflow basin
self.add_variable(outnf,procgrid,NCFillValue,part,('inflow','z','y','x'),"route_inbasin","Basin from which the water flows","-",self.route_inbasin[:,:,:],vtyp,"int")
self.add_variable(outnf,procgrid,NCFillValue,part,('inflow','z','y','x'),"route_inbasin","Basin from which the water flows","-", \
self.route_inbasin[:,:,:],vtyp,orig_type="int")
#
# Save centre of gravity of HTU
#
# Check if it works
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"CG_lon","Longitude of centre of gravity of HTU","degrees east",self.routing_cg[:,:,1],vtyp,"float")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"CG_lon","Longitude of centre of gravity of HTU","degrees east",self.routing_cg[:,:,1],vtyp)
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"CG_lat","Latitude of centre of gravity of HTU","degrees north",self.routing_cg[:,:,0],vtyp,"float")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"CG_lat","Latitude of centre of gravity of HTU","degrees north",self.routing_cg[:,:,0],vtyp)
#
# Save the fetch of each basin
#
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"fetch","Fetch contributing to each HTU","m^2",self.routing_fetch[:,:],vtyp,"float")
self.add_variable(outnf,procgrid,NCFillValue,part,('z','y','x'),"fetch","Fetch contributing to each HTU","m^2",self.routing_fetch[:,:],vtyp)
#
# Build and save a map of all the structures located on the graph