<commit_before>/*global document, window, setInterval, Cesium, Image, navigator, twoline2rv, sgp4, tle, gstime*/
(function () {
    'use strict';
    var canvas                  = document.getElementById('glCanvas');
    var ellipsoid               = Cesium.Ellipsoid.WGS84;
    var scene                   = new Cesium.Scene(canvas);
    var satBillboards           = new Cesium.BillboardCollection();
    var cb                      = new Cesium.CentralBody(ellipsoid);
    var orbitTraces             = new Cesium.PolylineCollection(); // currently only one at a time
    var satrecs                 = [];   // populated from onclick file load
    var satPositions            = [];   // calculated by updateSatrecsPosVel()
    var satData                 = [];   // list of satellite data and metadata
    var selectedSatelliteIdx    = null;
    var transitioner            = new Cesium.SceneTransitioner(scene, ellipsoid);

    // Constants
    var CESIUM_TEXTURES_BASE    = 'media/sot/cesium/Assets/Textures';
    var SKYBOX_BASE             = CESIUM_TEXTURES_BASE + '/SkyBox';
    var CALC_INTERVAL_MS        = 1000;

    // HACK: force globals for SGP4
    var WHICHCONST              = 72;   //
    var TYPERUN                 = 'm';  // 'm'anual, 'c'atalog, 'v'erification
    var TYPEINPUT               = 'n';  // HACK: 'now'
    var PLAY                    = true;

    // Global Variables for URL
    var ORIGINAL_GROUP = 'SMD';
    var ORIGINAL_SATELLITE = 'null';

    // Dictionary of Map tile providers for Cesium
    var TILE_PROVIDERS = {
        'bing': new Cesium.BingMapsImageryProvider({
            url: 'http://dev.virtualearth.net',
            mapStyle: Cesium.BingMapsStyle.AERIAL_WITH_LABELS
        }),
        'osm': new Cesium.OpenStreetMapImageryProvider({
            url: 'http://otile1.mqcdn.com/tiles/1.0.0/osm'
        }),
        'static': new Cesium.SingleTileImageryProvider({
            url: CESIUM_TEXTURES_BASE + '/NE2_LR_LC_SR_W_DR_2048.jpg'
        }),
        // Lots of ArcGIS products avaiable including .../World_Street_Map/MapServer
        // TODO: for now use AGI's proxy but we need to run our own to avoid:
        // "Cross-origin image load denied by Cross-Origin Resource Sharing policy."
        'arcgis': new Cesium.ArcGisMapServerImageryProvider({
            url: 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
            proxy: new Cesium.DefaultProxy('http://cesiumjs.org/proxy/')
        })
    };

    // Function to get all basic views set on load.
    function bootstrap() {
        checkURLVariables();

        // How do we tell if we can't get Bing, and substitute flat map with 'single'?
        cb.imageryLayers.addImageryProvider(TILE_PROVIDERS.bing); // TODO: get from HTML selector

        scene.primitives.centralBody = cb;
        scene.skyAtmosphere = new Cesium.SkyAtmosphere(); // make globe stand out from skybox
        scene.skyBox = new Cesium.SkyBox({
            sources : {
                positiveX: SKYBOX_BASE + '/tycho2t3_80_px.jpg',
                negativeX: SKYBOX_BASE + '/tycho2t3_80_mx.jpg',
                positiveY: SKYBOX_BASE + '/tycho2t3_80_py.jpg',
                negativeY: SKYBOX_BASE + '/tycho2t3_80_my.jpg',
                positiveZ: SKYBOX_BASE + '/tycho2t3_80_pz.jpg',
                negativeZ: SKYBOX_BASE + '/tycho2t3_80_mz.jpg'
            }
        });
        scene.primitives.add(orbitTraces);

        ////////////////////////
        // This should first see if there's a satellite in url, if not, check for geolocation, else default.
        //

        if(ORIGINAL_SATELLITE === 'null'){
            showGeolocation(scene);
        }

        document.getElementById('select_satellite_group').value = ORIGINAL_GROUP;
        // document.getElementById('select_satellite').value = ORIGINAL_SATELLITE;
        getSatrecsFromTLEFile(document.getElementById('select_satellite_group').value);
        populateSatelliteSelector();
        populateSatelliteBillboard();
        satelliteHoverDisplay(scene); // should be self-invoked
        satelliteClickDetails(scene); // should be self-invoked
    }

    bootstrap();

    function checkURLVariables() {

        // Function to find the current variables in the URL for permalinks.
        function loadURIVariables(qs){
            // This function is anonymous, is executed immediately and
            // the return value is assigned to QueryString!
            var query_string = {};
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                    // If first entry with this name
                if (typeof query_string[pair[0]] === "undefined") {
                    query_string[pair[0]] = pair[1];
                    // If second entry with this name
                } else if (typeof query_string[pair[0]] === "string") {
                    var arr = [ query_string[pair[0]], pair[1] ];
                    query_string[pair[0]] = arr;
                    // If third or later entry with this name
                } else {
                    query_string[pair[0]].push(pair[1]);
                }
            }
            return query_string;
        }

        var query = window.location.search.substring(1);
        var variables = loadURIVariables(query);

        if (variables.group !== undefined) {
            ORIGINAL_GROUP = variables.group;
        }

        if (variables.satellite !== undefined) {
            ORIGINAL_SATELLITE = variables.satellite;
        }
    }

    ///////////////////////////////////////////////////////////////////////////<commit_msg>Making the bootstrap function an IIFE.<commit_after>/*global document, window, setInterval, Cesium, Image, navigator, twoline2rv, sgp4, tle, gstime*/
(function () {
    'use strict';
    var canvas                  = document.getElementById('glCanvas');
    var ellipsoid               = Cesium.Ellipsoid.WGS84;
    var scene                   = new Cesium.Scene(canvas);
    var satBillboards           = new Cesium.BillboardCollection();
    var cb                      = new Cesium.CentralBody(ellipsoid);
    var orbitTraces             = new Cesium.PolylineCollection(); // currently only one at a time
    var satrecs                 = [];   // populated from onclick file load
    var satPositions            = [];   // calculated by updateSatrecsPosVel()
    var satData                 = [];   // list of satellite data and metadata
    var selectedSatelliteIdx    = null;
    var transitioner            = new Cesium.SceneTransitioner(scene, ellipsoid);

    // Constants
    var CESIUM_TEXTURES_BASE    = 'media/sot/cesium/Assets/Textures';
    var SKYBOX_BASE             = CESIUM_TEXTURES_BASE + '/SkyBox';
    var CALC_INTERVAL_MS        = 1000;

    // HACK: force globals for SGP4
    var WHICHCONST              = 72;   //
    var TYPERUN                 = 'm';  // 'm'anual, 'c'atalog, 'v'erification
    var TYPEINPUT               = 'n';  // HACK: 'now'
    var PLAY                    = true;

    // Global Variables for URL
    var ORIGINAL_GROUP = 'SMD';
    var ORIGINAL_SATELLITE = 'null';

    // Dictionary of Map tile providers for Cesium
    var TILE_PROVIDERS = {
        'bing': new Cesium.BingMapsImageryProvider({
            url: 'http://dev.virtualearth.net',
            mapStyle: Cesium.BingMapsStyle.AERIAL_WITH_LABELS
        }),
        'osm': new Cesium.OpenStreetMapImageryProvider({
            url: 'http://otile1.mqcdn.com/tiles/1.0.0/osm'
        }),
        'static': new Cesium.SingleTileImageryProvider({
            url: CESIUM_TEXTURES_BASE + '/NE2_LR_LC_SR_W_DR_2048.jpg'
        }),
        // Lots of ArcGIS products avaiable including .../World_Street_Map/MapServer
        // TODO: for now use AGI's proxy but we need to run our own to avoid:
        // "Cross-origin image load denied by Cross-Origin Resource Sharing policy."
        'arcgis': new Cesium.ArcGisMapServerImageryProvider({
            url: 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
            proxy: new Cesium.DefaultProxy('http://cesiumjs.org/proxy/')
        })
    };

    function checkURLVariables() {

        // Function to find the current variables in the URL for permalinks.
        function loadURIVariables(qs){
            // This function is anonymous, is executed immediately and
            // the return value is assigned to QueryString!
            var query_string = {};
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                    // If first entry with this name
                if (typeof query_string[pair[0]] === "undefined") {
                    query_string[pair[0]] = pair[1];
                    // If second entry with this name
                } else if (typeof query_string[pair[0]] === "string") {
                    var arr = [ query_string[pair[0]], pair[1] ];
                    query_string[pair[0]] = arr;
                    // If third or later entry with this name
                } else {
                    query_string[pair[0]].push(pair[1]);
                }
            }
            return query_string;
        }

        var query = window.location.search.substring(1);
        var variables = loadURIVariables(query);

        if (variables.group !== undefined) {
            ORIGINAL_GROUP = variables.group;
        }

        if (variables.satellite !== undefined) {
            ORIGINAL_SATELLITE = variables.satellite;
        }
    }

    // Function to get all basic views set on load.
    (function () {
        checkURLVariables();

        // How do we tell if we can't get Bing, and substitute flat map with 'single'?
        cb.imageryLayers.addImageryProvider(TILE_PROVIDERS.bing); // TODO: get from HTML selector

        scene.primitives.centralBody = cb;
        scene.skyAtmosphere = new Cesium.SkyAtmosphere(); // make globe stand out from skybox
        scene.skyBox = new Cesium.SkyBox({
            sources : {
                positiveX: SKYBOX_BASE + '/tycho2t3_80_px.jpg',
                negativeX: SKYBOX_BASE + '/tycho2t3_80_mx.jpg',
                positiveY: SKYBOX_BASE + '/tycho2t3_80_py.jpg',
                negativeY: SKYBOX_BASE + '/tycho2t3_80_my.jpg',
                positiveZ: SKYBOX_BASE + '/tycho2t3_80_pz.jpg',
                negativeZ: SKYBOX_BASE + '/tycho2t3_80_mz.jpg'
            }
        });
        scene.primitives.add(orbitTraces);

        ////////////////////////
        // This should first see if there's a satellite in url, if not, check for geolocation, else default.
        //

        if(ORIGINAL_SATELLITE === 'null'){
            showGeolocation(scene);
        }

        document.getElementById('select_satellite_group').value = ORIGINAL_GROUP;
        // document.getElementById('select_satellite').value = ORIGINAL_SATELLITE;
        getSatrecsFromTLEFile(document.getElementById('select_satellite_group').value);
        populateSatelliteSelector();
        populateSatelliteBillboard();
        satelliteHoverDisplay(scene); // should be self-invoked
        satelliteClickDetails(scene); // should be self-invoked
    }());

    ///////////////////////////////////////////////////////////////////////////
{'fraction_non_alphanumeric': 0.11933153451127165, 'fraction_numerical': 0.009748455043955087, 'mean_word_length': 1.8391401037805781, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3938475', 'n_tokens_mistral': 3427, 'n_tokens_neox': 3221, 'n_words': 769}