text:
RpcApi.SimpleOrganism(0x0000000000032473,:(function (o::Creature.Organism,)
        function func_143(var_141::Int8=28,var_142::Bool=false)
            local var_156::Int8 = -124
            for i::Int8 = 1:div(var_156,_LOOP_STEPS_DIVIDER)
            end
            Creature.eatRight(o,Int(var_141))
            Creature.eatLeft(o,Int(var_141))
            return var_141
        end
        function func_137(var_136::Int16=-19242)
            Creature.stepRight(o)
            return var_136
        end
        local var_125::Bool = true
        function func_96(var_95::String="CMsQ6J5t")
            return var_95
        end
        local var_82::Int16 = -28253
        function func_63(var_62::Int64=-5487471262987408691)
            if var_62 <= var_62
                Creature.stepRight(o)
                Creature.stepLeft(o)
            end
            Creature.stepDown(o)
            Creature.stepUp(o)
            Creature.stepRight(o)
            return var_62
        end
        local var_55::Int64 = 8062249648076403993
        function func_45(var_43::String="D42FzkNp",var_44::String="QVktoUuw")
            return var_43
        end
        local var_34::Int64 = -6982312523886405890
        function func_25(var_24::Int64=5926471544133193903)
            Creature.stepDown(o)
            Creature.stepLeft(o)
            return var_24
        end
        function func_9(var_8::Int8=-18)
            local var_123::Int64 = 2850089338817388517
            local var_85::Int16 = -29091
            local var_76::Int64 = -8364194871863581978
            local var_57::Bool = true
            local var_28::Int64 = -5547387289894786475
            local var_26::String = "zSGt1MST"
            local var_16::Bool = true
            local var_14::Int8 = 115
            local var_13::Int16 = 31438
            Creature.eatDown(o,Int(var_14))
            Creature.stepLeft(o)
            Creature.stepUp(o)
            var_16 = var_57 | var_16
            Creature.eatLeft(o,Int(var_14))
            Creature.eatDown(o,Int(var_8))
            Creature.stepUp(o)
            o.mem[var_85] = var_13
            if var_28 > var_76
            end
            o.mem[var_13] = var_13
            Creature.stepUp(o)
            Creature.eatUp(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            var_26 = var_26 * var_26
            Creature.eatLeft(o,Int(var_14))
            Creature.stepRight(o)
            o.mem[var_13] = var_85
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_8))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_8))
            Creature.stepDown(o)
            if var_26 !== var_26
                Creature.stepDown(o)
                Creature.stepLeft(o)
                Creature.stepRight(o)
            end
            o.mem[var_13] = var_85
            Creature.eatDown(o,Int(var_8))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_8))
            var_13 = var_13 - var_13
            Creature.eatDown(o,Int(var_14))
            if var_28 !== var_28
                Creature.stepUp(o)
            end
            Creature.stepUp(o)
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepLeft(o)
            var_76 = var_76 * var_76
            Creature.eatUp(o,Int(var_8))
            o.mem[var_13] = var_13
            Creature.stepDown(o)
            if var_8 !== var_14
                local var_144::Int16 = 1587
                Creature.stepUp(o)
            end
            Creature.eatRight(o,Int(var_8))
            if var_26 === var_26
                Creature.stepDown(o)
            end
            Creature.eatRight(o,Int(var_14))
            var_85 = var_85 * var_13
            Creature.stepDown(o)
            var_26 = var_26[1:if length(var_26) > length(var_26) > 0
                            0
                        else
                            div(length(var_26),length(var_26))
                        end]
            Creature.eatUp(o,Int(var_8))
            if var_14 !== var_14
                Creature.stepUp(o)
                Creature.stepLeft(o)
            end
            if var_16 === var_16
                Creature.stepUp(o)
                Creature.stepRight(o)
                Creature.stepUp(o)
                Creature.stepRight(o)
            end
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepUp(o)
            Creature.eatLeft(o,Int(var_8))
            return var_8
        end
        local var_1::Int8 = 59
        var_82 = var_82 * var_82
        var_12 = func_9(var_1)
        var_12 = func_9(var_12)
        var_82 = var_82 / var_82
        var_1 = func_9(var_1)
        var_1 = var_1 + var_12
        var_125 = var_125 | var_125
        Creature.stepDown(o)
        var_12 = var_12 * var_1
        var_12 = func_9(var_12)
        Creature.stepUp(o)
        Creature.eatDown(o,Int(var_1))
        o.mem[var_82] = var_82
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        Creature.eatDown(o,Int(var_1))
        o.mem[var_82] = var_82
        Creature.stepRight(o)
        Creature.stepUp(o)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepUp(o)
        var_82 = var_82 / var_82
        Creature.stepUp(o)
        o.mem[var_82] = var_82
        Creature.stepRight(o)
        var_82 = var_82 - var_82
        Creature.eatLeft(o,Int(var_1))
        Creature.eatDown(o,Int(var_12))
        Creature.stepUp(o)
        if var_12 <= var_12
            local var_150::Bool = true
            Creature.stepLeft(o)
            var_150 = var_150 * var_150
            Creature.stepUp(o)
        end
        for i::Int8 = 1:div(var_1,_LOOP_STEPS_DIVIDER)
            Creature.stepLeft(o)
        end
        Creature.eatUp(o,Int(var_12))
        return true
    end),[100,300,95,0,1,1,1],8,9191,16,1493407,0x00000312,Dict(0=>0,31438=>-29091,-28253=>-28253,-29091=>31438,-2660=>-29091,1670=>1670,-5320=>-5320,-572=>-572,1=>1),[399,280],148),RpcApi.SimpleOrganism(0x0000000000032771,:(function (o::Creature.Organism,)
        local var_156::Int8 = 83
        local var_131::Int16 = 20703
        local var_125::Bool = true
        function func_96(var_95::String="CMsQ6J5t")
            return var_95
        end
        local var_82::Int16 = -28253
        function func_63(var_62::Int64=-5487471262987408691)
            var_62 = var_62 - var_62
            Creature.stepDown(o)
            return var_62
        end
        local var_55::Int64 = 8062249648076403993
        function func_45(var_43::String="D42FzkNp",var_44::String="QVktoUuw")
            Creature.stepUp(o)
            return var_43
        end
        local var_34::Int64 = -6982312523886405890
        function func_25(var_24::Int64=5926471544133193903)
            Creature.stepUp(o)
            Creature.stepDown(o)
            var_24 = var_24 / var_24
            return var_24
        end
        function func_9(var_8::Int8=-18)
            local var_123::Int64 = 2850089338817388517
            local var_85::Int16 = -29091
            local var_76::Int64 = -8364194871863581978
            local var_57::Bool = true
            local var_28::Int64 = -5547387289894786475
            local var_26::String = "zSGt1MST"
            local var_16::Bool = true
            local var_14::Int8 = 115
            local var_13::Int16 = 31438
            Creature.eatDown(o,Int(var_14))
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            o.mem[var_85] = var_13
            if var_28 > var_76
                Creature.stepUp(o)
            end
            o.mem[var_13] = var_13
            Creature.eatUp(o,Int(var_8))
            var_26 = var_26 * var_26
            Creature.eatLeft(o,Int(var_14))
            Creature.stepLeft(o)
            var_26 = var_26[1:if length(var_26) > length(var_26)
                            0
                        else
                            length(var_26) - length(var_26)
                        end]
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_8))
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_8))
            o.mem[var_13] = var_85
            Creature.eatDown(o,Int(var_8))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_8))
            var_13 = var_13 - var_13
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepLeft(o)
            var_76 = var_76 * var_76
            Creature.eatDown(o,Int(var_14))
            o.mem[var_85] = var_85
            Creature.stepDown(o)
            if var_8 !== var_14
                Creature.stepUp(o)
            end
            Creature.eatRight(o,Int(var_8))
            if var_26 === var_26
                Creature.stepDown(o)
                Creature.stepDown(o)
            end
            Creature.eatRight(o,Int(var_14))
            if var_123 === var_123
                Creature.stepDown(o)
            end
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_8))
            Creature.eatDown(o,Int(var_14))
            var_123 = var_123 + var_76
            Creature.eatUp(o,Int(var_8))
            if var_14 !== var_14
                Creature.stepUp(o)
            end
            if var_16 === var_16
                Creature.stepUp(o)
                Creature.stepRight(o)
                Creature.stepRight(o)
            end
            var_26 = var_26 * var_26
            Creature.eatDown(o,Int(var_14))
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.eatLeft(o,Int(var_8))
            return var_8
        end
        local var_1::Int8 = 59
        function func_135(var_134::Int64=6349986163145892178)
            var_134 = var_134 - var_134
            return var_134
        end
        var_12 = func_9(var_1)
        var_12 = func_9(var_12)
        var_15 = func_9(var_12)
        Creature.eatDown(o,Int(var_12))
        var_1 = func_9(var_1)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepDown(o)
        var_131 = if haskey(o.mem,var_131)
                o.mem[var_131]
            else
                var_131
            end
        Creature.stepRight(o)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        if var_55 == var_34
            Creature.stepLeft(o)
        end
        var_12 = func_9(var_12)
        Creature.stepUp(o)
        Creature.eatRight(o,Int(var_12))
        o.mem[var_82] = var_82
        Creature.eatUp(o,Int(var_1))
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        Creature.eatUp(o,Int(var_15))
        Creature.eatDown(o,Int(var_12))
        Creature.stepUp(o)
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.eatUp(o,Int(var_1))
        Creature.stepUp(o)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        Creature.stepUp(o)
        if var_1 != var_1
            Creature.stepUp(o)
        end
        Creature.stepUp(o)
        Creature.stepLeft(o)
        Creature.stepUp(o)
        Creature.eatLeft(o,Int(var_12))
        o.mem[var_82] = var_131
        if var_12 <= var_12
            Creature.stepUp(o)
        end
        Creature.stepUp(o)
        for i::Int8 = 1:div(var_1,_LOOP_STEPS_DIVIDER)
            Creature.stepDown(o)
        end
        Creature.stepRight(o)
        var_55 = Int(Creature.getEnergy(o,Int(var_82),Int(var_82)))
        return true
    end),[100,300,95,0,1,1,1],12,7670,35,1028867,0x000002cf,Dict(0=>0,31438=>-29091,-28253=>20703,-29091=>-29091,-2660=>-29091,20703=>20703,-5320=>-5320,-572=>-572,1=>1),[37,290],143),RpcApi.SimpleOrganism(0x0000000000032702,:(function (o::Creature.Organism,)
        local var_161::Int8 = 81
        local var_131::Int16 = 20703
        local var_125::Bool = true
        function func_96(var_95::String="CMsQ6J5t")
            return var_95
        end
        local var_82::Int16 = -28253
        function func_63(var_62::Int64=-5487471262987408691)
            var_62 = var_62 / var_62
            return var_62
        end
        local var_55::Int64 = 8062249648076403993
        function func_45(var_43::String="D42FzkNp",var_44::String="QVktoUuw")
            local var_158::Int64 = 8569834185104060114
            if var_44 <= var_44
            end
            var_44 = var_44 * var_43
            return var_43
        end
        local var_34::Int64 = -6982312523886405890
        function func_25(var_24::Int64=5926471544133193903)
            return var_24
        end
        function func_9(var_8::Int8=-18)
            local var_123::Int64 = 2850089338817388517
            local var_85::Int16 = -29091
            local var_76::Int64 = -8364194871863581978
            local var_57::Bool = true
            local var_28::Int64 = -5547387289894786475
            local var_26::String = "zSGt1MST"
            local var_16::Bool = true
            local var_14::Int8 = 115
            local var_13::Int16 = 31438
            Creature.eatDown(o,Int(var_14))
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            o.mem[var_85] = var_13
            if var_28 > var_76
                Creature.stepUp(o)
            end
            o.mem[var_13] = var_13
            Creature.eatUp(o,Int(var_8))
            var_26 = var_26 * var_26
            Creature.eatLeft(o,Int(var_14))
            Creature.stepLeft(o)
            var_26 = var_26[1:if length(var_26) > length(var_26)
                            0
                        else
                            length(var_26) - length(var_26)
                        end]
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_8))
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_8))
            o.mem[var_13] = var_85
            Creature.eatDown(o,Int(var_8))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_8))
            var_13 = var_13 - var_13
            Creature.eatDown(o,Int(var_14))
            if var_28 !== var_28
                var_140 = var_140 / var_140
                Creature.stepUp(o)
            end
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepLeft(o)
            var_76 = var_76 * var_76
            Creature.eatDown(o,Int(var_14))
            o.mem[var_85] = var_85
            Creature.stepDown(o)
            if var_8 !== var_14
                Creature.stepUp(o)
            end
            Creature.eatRight(o,Int(var_8))
            if var_26 === var_26
                Creature.stepDown(o)
                Creature.stepDown(o)
            end
            Creature.eatRight(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            if var_123 === var_123
                Creature.stepDown(o)
            end
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_8))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            var_123 = var_123 + var_76
            Creature.eatUp(o,Int(var_8))
            if var_14 !== var_14
                Creature.stepUp(o)
            end
            if var_16 === var_16
                Creature.stepUp(o)
                Creature.stepRight(o)
                Creature.stepRight(o)
            end
            var_26 = var_26 * var_26
            Creature.eatDown(o,Int(var_14))
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.eatLeft(o,Int(var_8))
            return var_8
        end
        local var_1::Int8 = 59
        function func_135(var_134::Int64=6349986163145892178)
            return var_134
        end
        var_12 = func_9(var_1)
        var_12 = func_9(var_12)
        var_15 = func_9(var_12)
        var_1 = func_9(var_1)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepDown(o)
        var_131 = if haskey(o.mem,var_131)
                o.mem[var_131]
            else
                var_131
            end
        Creature.eatUp(o,Int(var_1))
        Creature.stepRight(o)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        if var_55 == var_34
            local var_150::Int64 = 2167039937830895435
            Creature.stepLeft(o)
        end
        var_12 = func_9(var_12)
        Creature.stepUp(o)
        Creature.eatRight(o,Int(var_12))
        o.mem[var_82] = var_82
        Creature.eatUp(o,Int(var_1))
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        Creature.eatUp(o,Int(var_15))
        Creature.eatDown(o,Int(var_12))
        Creature.stepUp(o)
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepUp(o)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        Creature.stepUp(o)
        if var_1 != var_1
            local var_160::Int64 = 6104843260668152792
            Creature.stepRight(o)
            Creature.stepDown(o)
            Creature.stepLeft(o)
        end
        Creature.stepUp(o)
        Creature.stepLeft(o)
        Creature.stepUp(o)
        Creature.eatLeft(o,Int(var_12))
        o.mem[var_82] = var_131
        if var_12 <= var_12
            Creature.stepUp(o)
        end
        Creature.stepUp(o)
        for i::Int8 = 1:div(var_1,_LOOP_STEPS_DIVIDER)
            Creature.stepDown(o)
            Creature.stepLeft(o)
        end
        Creature.stepRight(o)
        var_55 = Int(Creature.getEnergy(o,Int(var_82),Int(var_82)))
        return true
    end),[100,300,95,0,1,1,1],27,8590,35,949279,0x000002d9,Dict(0=>0,31438=>-29091,-28253=>20703,-29091=>-29091,-2660=>-29091,20703=>20703,-5320=>-5320,-572=>-572,1=>1),[6,289],148),RpcApi.SimpleOrganism(0x00000000000324da,:(function (o::Creature.Organism,)
        local var_162::Bool = false
        local var_161::Int8 = 81
        local var_131::Int16 = 20703
        local var_125::Bool = true
        function func_96(var_95::String="CMsQ6J5t")
            return var_95
        end
        local var_82::Int16 = -28253
        function func_63(var_62::Int64=-5487471262987408691)
            return var_62
        end
        local var_55::Int64 = 8062249648076403993
        function func_45(var_43::String="D42FzkNp",var_44::String="QVktoUuw")
            local var_158::Int64 = 8569834185104060114
            var_44 = var_44 * var_43
            Creature.stepUp(o)
            return var_43
        end
        local var_34::Int64 = -6982312523886405890
        function func_25(var_24::Int64=5926471544133193903)
            Creature.stepUp(o)
            return var_24
        end
        function func_9(var_8::Int8=-18)
            local var_123::Int64 = 2850089338817388517
            local var_85::Int16 = -29091
            local var_76::Int64 = -8364194871863581978
            local var_57::Bool = true
            local var_28::Int64 = -5547387289894786475
            local var_26::String = "zSGt1MST"
            local var_16::Bool = true
            local var_14::Int8 = 115
            local var_13::Int16 = 31438
            Creature.eatDown(o,Int(var_14))
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            o.mem[var_85] = var_13
            if var_28 > var_76
                Creature.stepUp(o)
            end
            o.mem[var_13] = var_13
            Creature.eatUp(o,Int(var_8))
            var_26 = var_26 * var_26
            Creature.eatLeft(o,Int(var_14))
            Creature.stepLeft(o)
            var_26 = var_26[1:if length(var_26) > length(var_26)
                            0
                        else
                            length(var_26) - length(var_26)
                        end]
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_8))
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_8))
            o.mem[var_13] = var_85
            Creature.eatDown(o,Int(var_8))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_8))
            var_13 = var_13 - var_13
            Creature.eatDown(o,Int(var_14))
            if var_28 !== var_28
                var_140 = var_140 / var_140
                Creature.stepUp(o)
            end
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepLeft(o)
            var_76 = var_76 * var_76
            Creature.eatDown(o,Int(var_14))
            o.mem[var_85] = var_85
            Creature.stepDown(o)
            if var_8 !== var_14
                Creature.stepUp(o)
            end
            Creature.eatRight(o,Int(var_8))
            if var_26 === var_26
                Creature.stepDown(o)
                Creature.stepDown(o)
            end
            Creature.eatRight(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            if var_123 === var_123
                Creature.stepDown(o)
            end
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_8))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            var_123 = var_123 + var_76
            Creature.eatUp(o,Int(var_8))
            if var_14 !== var_14
                Creature.stepUp(o)
            end
            if var_16 === var_16
                Creature.stepUp(o)
                Creature.stepRight(o)
                Creature.stepRight(o)
            end
            var_26 = var_26 * var_26
            Creature.eatDown(o,Int(var_14))
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.eatLeft(o,Int(var_8))
            return var_8
        end
        local var_1::Int8 = 59
        function func_135(var_134::Int64=6349986163145892178)
            return var_134
        end
        var_12 = func_9(var_1)
        var_12 = func_9(var_12)
        var_15 = func_9(var_12)
        var_1 = func_9(var_1)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepDown(o)
        var_131 = if haskey(o.mem,var_131)
                o.mem[var_131]
            else
                var_131
            end
        Creature.stepRight(o)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        if var_55 == var_34
            local var_150::Int64 = 2167039937830895435
            Creature.stepLeft(o)
        end
        var_12 = func_9(var_12)
        Creature.stepUp(o)
        Creature.eatRight(o,Int(var_12))
        o.mem[var_82] = var_82
        Creature.eatUp(o,Int(var_1))
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        Creature.eatUp(o,Int(var_15))
        Creature.eatDown(o,Int(var_12))
        Creature.stepUp(o)
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepUp(o)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        Creature.stepUp(o)
        if var_1 != var_1
            local var_160::Int64 = 6104843260668152792
            Creature.stepRight(o)
            Creature.stepDown(o)
        end
        Creature.stepUp(o)
        Creature.stepLeft(o)
        Creature.stepUp(o)
        Creature.eatLeft(o,Int(var_12))
        o.mem[var_82] = var_131
        if var_12 <= var_12
            Creature.stepUp(o)
        end
        Creature.stepUp(o)
        for i::Int8 = 1:div(var_1,_LOOP_STEPS_DIVIDER)
            Creature.stepDown(o)
        end
        Creature.stepRight(o)
        var_55 = Int(Creature.getEnergy(o,Int(var_82),Int(var_82)))
        return true
    end),[100,300,95,0,1,1,1],27,8590,35,941529,0x000002d5,Dict(0=>0,31438=>-29091,-28253=>20703,-29091=>-29091,-2660=>-29091,20703=>20703,-5320=>-5320,-572=>-572,1=>1),[25,273],146),RpcApi.SimpleOrganism(0x00000000000324e6,:(function (o::Creature.Organism,)
        local var_131::Int16 = 20703
        local var_125::Bool = true
        function func_96(var_95::String="CMsQ6J5t")
            return var_95
        end
        local var_82::Int16 = -28253
        function func_63(var_62::Int64=-5487471262987408691)
            local var_156::Int16 = -9347
            return var_62
        end
        local var_55::Int64 = 8062249648076403993
        function func_45(var_43::String="D42FzkNp",var_44::String="QVktoUuw")
            return var_43
        end
        local var_34::Int64 = -6982312523886405890
        function func_25(var_24::Int64=5926471544133193903)
            Creature.stepRight(o)
            var_24 = var_24 / var_24
            Creature.stepDown(o)
            return var_24
        end
        function func_9(var_8::Int8=-18)
            local var_123::Int64 = 2850089338817388517
            local var_85::Int16 = -29091
            local var_76::Int64 = -8364194871863581978
            local var_57::Bool = true
            local var_28::Int64 = -5547387289894786475
            local var_26::String = "zSGt1MST"
            local var_16::Bool = true
            local var_14::Int8 = 115
            local var_13::Int16 = 31438
            Creature.eatDown(o,Int(var_14))
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            o.mem[var_85] = var_13
            if var_28 > var_76
                Creature.stepUp(o)
            end
            o.mem[var_13] = var_13
            Creature.eatUp(o,Int(var_8))
            var_26 = var_26 * var_26
            Creature.eatLeft(o,Int(var_14))
            Creature.stepLeft(o)
            var_26 = var_26[1:if length(var_26) > length(var_26)
                            0
                        else
                            length(var_26) - length(var_26)
                        end]
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_8))
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_8))
            o.mem[var_13] = var_85
            Creature.eatDown(o,Int(var_8))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_8))
            var_13 = var_13 - var_13
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepDown(o)
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.eatDown(o,Int(var_14))
            Creature.stepLeft(o)
            var_76 = var_76 * var_76
            Creature.eatDown(o,Int(var_14))
            o.mem[var_85] = var_85
            Creature.stepDown(o)
            if var_8 !== var_14
                Creature.stepUp(o)
            end
            Creature.eatRight(o,Int(var_8))
            var_28 = Int(Creature.getEnergy(o,Int(var_13),Int(var_85)))
            if var_26 === var_26
                Creature.stepDown(o)
                Creature.stepDown(o)
            end
            Creature.eatRight(o,Int(var_14))
            if var_123 === var_123
                Creature.stepDown(o)
            end
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_8))
            Creature.eatDown(o,Int(var_14))
            var_123 = var_123 + var_76
            Creature.eatUp(o,Int(var_8))
            if var_14 !== var_14
                Creature.stepUp(o)
            end
            if var_16 === var_16
                Creature.stepUp(o)
                Creature.stepRight(o)
                Creature.stepRight(o)
            end
            var_26 = var_26 * var_26
            Creature.eatDown(o,Int(var_14))
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.eatLeft(o,Int(var_8))
            return var_8
        end
        local var_1::Int8 = 59
        function func_135(var_134::Int64=6349986163145892178)
            Creature.stepLeft(o)
            return var_134
        end
        var_12 = func_9(var_1)
        var_12 = func_9(var_12)
        var_15 = func_9(var_12)
        var_1 = func_9(var_1)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepDown(o)
        var_131 = if haskey(o.mem,var_131)
                o.mem[var_131]
            else
                var_131
            end
        Creature.stepRight(o)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        if var_55 == var_34
            Creature.stepLeft(o)
        end
        var_12 = func_9(var_12)
        Creature.stepUp(o)
        Creature.eatRight(o,Int(var_12))
        Creature.eatUp(o,Int(var_1))
        Creature.eatUp(o,Int(var_1))
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        Creature.eatUp(o,Int(var_15))
        Creature.eatDown(o,Int(var_12))
        Creature.stepUp(o)
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.eatUp(o,Int(var_1))
        Creature.stepUp(o)
        var_82 = if haskey(o.mem,var_82)
                o.mem[var_82]
            else
                var_82
            end
        Creature.stepRight(o)
        Creature.stepUp(o)
        if var_1 != var_1
            Creature.stepUp(o)
        end
        Creature.stepUp(o)
        Creature.stepLeft(o)
        Creature.stepUp(o)
        Creature.eatLeft(o,Int(var_12))
        o.mem[var_82] = var_131
        if var_12 <= var_12
            Creature.stepUp(o)
        end
        Creature.stepUp(o)
        for i::Int8 = 1:div(var_1,_LOOP_STEPS_DIVIDER)
            Creature.stepDown(o)
        end
        Creature.stepRight(o)
        var_55 = Int(Creature.getEnergy(o,Int(var_82),Int(var_82)))
        return true
    end),[100,300,95,0,1,1,1],12,7670,35,861018,0x000002db,Dict(0=>0,31438=>-29091,-28253=>20703,-29091=>-29091,-2660=>-29091,20703=>20703,-5320=>-5320,-572=>-572,1=>1),[35,289],140)]

max_stars_repo_name: tmptrash/jevo

max_issues_repo_name: tmptrash/jevo

max_forks_repo_name: tmptrash/jevo


text:
using BHAtp, Statistics

ProjDir = @__DIR__
!isdir(joinpath(ProjDir, "plots")) && mkdir(joinpath(ProjDir, "plots"))

ProjName = split(ProjDir, "/")[end]
bhaj = BHAtp.BHAJ(ProjName, ProjDir)
bhaj.ratio = 2.3

segs = [
	# Element type,  Material,    Length,     ID,   OD,    fc
	(:bit,           :steel,        0.00,   2.000, 17.500,  0.0),
  (:collar,        :steel,        1.44,   2.000,  9.500,  0.0),
  (:collar,        :steel,        3.00,   3.000,  9.500,  0.0),
  (:collar,        :steel,        1.24,   2.938,  9.500,  0.0),
	(:stabilizer,    :steel,        0.00,   2.938, 17.500,  0.0),
  (:collar,        :steel,        4.04,   2.938,  9.500,  0.0),
	(:collar,        :monel,       37.45,   2.875,  9.500,  0.0),
  (:collar,        :monel,       27.09,   3.000,  9.625,  0.0),
  (:collar,        :monel,       30.01,   2.875,  9.500,  0.0),
  (:collar,        :steel,        1.87,   3.000,  9.500,  0.0),
  (:stabilizer,    :steel,        0.00,   3.000, 17.500,  0.0),
  (:collar,        :steel,        3.73,   3.000,  9.500,  0.0),
	(:collar,        :steel,       28.73,   2.875,  9.500,  0.0),
  (:collar,        :steel,        4.22,   3.000,  9.125,  0.0),
  (:collar,        :steel,       27.98,   2.750,  7.875,  0.0),
  (:collar,        :steel,       29.45,   2.875,  7.563,  0.0),
  (:collar,        :steel,       30.87,   2.875,  7.625,  0.0),
  (:collar,        :steel,       31.10,   2.750,  8.000,  0.0),
  (:collar,        :steel,       32.18,   3.000,  8.000,  0.0),
  (:collar,        :steel,       30.88,   2.750,  7.938,  0.0),
  (:collar,        :steel,        3.50,   2.750,  8.000,  0.0)
]

traj = [
	#Heading,  Diameter
	( 60.0,      17.5)
]

wobs = 30:5:40
incls = 30:5:60  # Or e.g. incls = [5 10 20 30 40 45 50]

@time bhaj(segs, traj, wobs, incls)

display("Fetch tp=false, wob=35, incl@bit=30 solution:")
df,df_tp = show_solution(ProjDir, 35, 30, show=false, tp=false)
df[:,[2; 5:6; 9:12]] |> display
println()

println("Fetch tp=true, wob=35, incl@bit=30 solution:")
df,df_tp = show_solution(ProjDir, 35, 30, show=false);
df[:,[2; 5:6; 9:12]] |> display
println()

tpf = create_final_tp_df(ProjDir, wobs, incls; ofu=false)
tpf |> display
println()

# Collect computed side forces on NBS @ 45ft

sfs = []
for wob in wobs
  for incl in incls
    df, df_tp = show_solution(ProjDir, wob, incl, show=false);
    sf = @linq df |> where(:dtb .== 5.68)
    append!(sfs, sf.fx)
  end
end

# Actual tps

actual = DataFrame(
  incls = [40.0, 42.3, 44.0, 44.65, 45.7, 47.25, 49.5],
  atp = [2.55, 2.65, 0.4, 1.15, 1.18, 2.15, 2.35],
)

rpm = DataFrame(
  incls = [35, 43.5,43.6,44.2,44.3,44.9, 45, 48,48.1, 55],
  rpm = [ 100,  100,  60,  60,  70,  70, 80, 80, 120,120]
)

name = "figure_03"

figure_03 = @pgf TikzPicture(
  Axis({
      height = "6cm", width = " 8cm",
      xmin = 30, xmax = 90,
      ymin = 0, ymax = 6.5,
      axis_y_line = "left",
      xlabel = "Inclination [°]",
      ylabel = "TP [°/100ft]",
      title = "Figure 3: Actual vs. Isotropic TP",
      legend_pos = "south east",
    },
    Plot({ color="blue", mark = "." },
      Table(tpf.incl[1:7], tpf.tp[1:7])),
    LegendEntry("TP wob=30"),
    Plot({ color="gray", mark = "." },
      Table(tpf.incl[8:14], tpf.tp[8:14])),
    LegendEntry("TP wob=35"),
    Plot({ color="green", mark = "." },
      Table(tpf.incl[15:21], tpf.tp[15:21])),
    LegendEntry("TP wob=40"),
    Plot({ thick, color="black", mark = "+" },
      Table(actual.incls, actual.atp)),
    LegendEntry("TP, actual")),
  Axis({
      height = "6cm", width = " 8cm",
      ymin = 0, ymax = 160,
      xmin = 30, xmax = 90,
      hide_x_axis,
      axis_y_line = "right",
      ylabel = "RPM [revs/min]",
      legend_pos = "north east",
    },
    Plot({ color="red", mark = "." },
      Table(rpm.incls, rpm.rpm)),
    LegendEntry("RPM")),
)

savefig(joinpath(ProjDir, "plots", name), figure_03, ProjDir)

ext: jl


text:
# OPMInstallDeps - Load / Install depencies for rest of the files to operate

if (install)
    Pkg.add(["FWF","DataFrames","CategoricalArrays", "Query", "ShiftedArraysShiftedArrays"])
    #install.packages("dplyr", repos = "http://mran.revolutionanalytics.com")
    #install.packages("tidyverse", repos = "http://mran.revolutionanalytics.com")
    #install.packages("reshape2", repos = "http://mran.revolutionanalytics.com")
end
using FWF
using DataFrames
using CategoricalArrays
using Query
using ShiftedArrays

include("OPMFileParsing.jl")
include("OPMFileTransform.jl")
include("OPMOperations.jl")
# Keep this last
include("OPMExternalData.jl")


text:
function parsim(m::SearchDomain, vsu::Vector{SimUnit}, n_sims::Int)
    np = nprocs()       # number of processes available
    i = 1
    nextidx() = (idx=i; i+=1; idx)
    costs = zeros(n_sims, length(vsu))
    @sync begin
        for p=1:np
            if p != myid() || np == 1
                @async begin
                    while true
                        idx = nextidx()
                        idx > n_sims && break
                        costs[idx,:]=remotecall_fetch(psim, p, idx, m, vsu)
                    end
                end
            end
        end
    end
    return costs
end
function parsim(m::SearchDomain, su::SimUnit, n_sims::Int)
    return vec( parsim(m, [su], n_sims) )
end

# like simulation, but special for parallel simulations
# main change is deep-copying of arguments so as to not disturb them
function psim(idx::Int, m::SearchDomain, vsu::Vector{SimUnit})

    # copy these so they don't get messed up by other cores
    m = deepcopy(m)
    vsu = deepcopy(vsu)

    # change the target location
    theta!(m)

    costs = zeros(length(vsu))

    print("Simulation ", idx, ": ")
    for (su_ind, su) in enumerate(vsu)
        print(su_ind, ",")

        # reset the filter, vehicle, and policy
        reset!(m, su)

        costs[su_ind] = simulate(m, su)
    end
    println("complete.")
    return costs
end


text:
using CUSPARSE
using CUDArt
using Base.Test

m = 25
n = 35
k = 10
blockdim = 5

@testset "gtsv" begin
    @testset for elty in [Float32,Float64,Complex64,Complex128]
        @testset "gtsv!" begin
            dl = rand(elty,m-1)
            du = rand(elty,m-1)
            d = rand(elty,m)
            B = rand(elty,m,n)
            d_dl = CudaArray(vcat([0],dl))
            d_du = CudaArray(vcat(du,[0]))
            d_d = CudaArray(d)
            d_B = CudaArray(B)
            d_B = CUSPARSE.gtsv!(d_dl,d_d,d_du,d_B)
            C = diagm(d,0) + diagm(du,1) + diagm(dl,-1)
            h_B = to_host(d_B)
            @test h_B ≈ C\B
        end

        @testset "gtsv" begin
            dl = rand(elty,m-1)
            du = rand(elty,m-1)
            d = rand(elty,m)
            B = rand(elty,m,n)
            d_dl = CudaArray(vcat([0],dl))
            d_du = CudaArray(vcat(du,[0]))
            d_d = CudaArray(d)
            d_B = CudaArray(B)
            d_C = CUSPARSE.gtsv(d_dl,d_d,d_du,d_B)
            C = diagm(d,0) + diagm(du,1) + diagm(dl,-1)
            h_C = to_host(d_C)
            @test h_C ≈ C\B
        end

        @testset "gtsv_nopivot!" begin
            dl = rand(elty,m-1)
            du = rand(elty,m-1)
            d = rand(elty,m)
            B = rand(elty,m,n)
            d_dl = CudaArray(vcat([0],dl))
            d_du = CudaArray(vcat(du,[0]))
            d_d = CudaArray(d)
            d_B = CudaArray(B)
            d_B = CUSPARSE.gtsv_nopivot!(d_dl,d_d,d_du,d_B)
            C = diagm(d,0) + diagm(du,1) + diagm(dl,-1)
            h_B = to_host(d_B)
            @test h_B ≈ C\B
        end

        @testset "gtsv_nopivot" begin
            dl = rand(elty,m-1)
            du = rand(elty,m-1)
            d = rand(elty,m)
            B = rand(elty,m,n)
            d_dl = CudaArray(vcat([0],dl))
            d_du = CudaArray(vcat(du,[0]))
            d_d = CudaArray(d)
            d_B = CudaArray(B)
            d_C = CUSPARSE.gtsv_nopivot(d_dl,d_d,d_du,d_B)
            C = diagm(d,0) + diagm(du,1) + diagm(dl,-1)
            h_C = to_host(d_C)
            @test h_C ≈ C\B
        end

        @testset "gtsvStridedBatch!" begin
            dla = rand(elty,m-1)
            dua = rand(elty,m-1)
            da = rand(elty,m)
            dlb = rand(elty,m-1)
            dub = rand(elty,m-1)
            db = rand(elty,m)
            xa = rand(elty,m)
            xb = rand(elty,m)
            d_dl = CudaArray(vcat([0],dla,[0],dlb))
            d_du = CudaArray(vcat(dua,[0],dub,[0]))
            d_d = CudaArray(vcat(da,db))
            d_x = CudaArray(vcat(xa,xb))
            d_x = CUSPARSE.gtsvStridedBatch!(d_dl,d_d,d_du,d_x,2,m)
            Ca = diagm(da,0) + diagm(dua,1) + diagm(dla,-1)
            Cb = diagm(db,0) + diagm(dub,1) + diagm(dlb,-1)
            h_x = to_host(d_x)
            @test h_x[1:m] ≈ Ca\xa
            @test h_x[m+1:2*m] ≈ Cb\xb
        end

        @testset "gtsvStridedBatch" begin
            dla = rand(elty,m-1)
            dua = rand(elty,m-1)
            da = rand(elty,m)
            dlb = rand(elty,m-1)
            dub = rand(elty,m-1)
            db = rand(elty,m)
            xa = rand(elty,m)
            xb = rand(elty,m)
            d_dl = CudaArray(vcat([0],dla,[0],dlb))
            d_du = CudaArray(vcat(dua,[0],dub,[0]))
            d_d = CudaArray(vcat(da,db))
            d_x = CudaArray(vcat(xa,xb))
            d_y = CUSPARSE.gtsvStridedBatch(d_dl,d_d,d_du,d_x,2,m)
            Ca = diagm(da,0) + diagm(dua,1) + diagm(dla,-1)
            Cb = diagm(db,0) + diagm(dub,1) + diagm(dlb,-1)
            h_y = to_host(d_y)
            @test h_y[1:m] ≈ Ca\xa
            @test h_y[m+1:2*m] ≈ Cb\xb
        end
    end
end


text:
"""
    TGARCH{o, p, q, T<:AbstractFloat} <: UnivariateVolatilitySpec{T}
"""
struct TGARCH{o, p, q, T<:AbstractFloat} <: UnivariateVolatilitySpec{T}
    coefs::Vector{T}
    function TGARCH{o, p, q, T}(coefs::Vector{T}) where {o, p, q, T}
        length(coefs) == nparams(TGARCH{o, p, q})  || throw(NumParamError(nparams(TGARCH{o, p, q}), length(coefs)))
        new{o, p, q, T}(coefs)
    end
end

"""
    TGARCH{o, p, q}(coefs) -> UnivariateVolatilitySpec
Construct a TGARCH specification with the given parameters.

# Example:
```jldoctest
julia> TGARCH{1, 1, 1}([1., .04, .9, .01])
TGARCH{1,1,1} specification.

─────────────────────────────────
               ω    γ₁   β₁    α₁
─────────────────────────────────
Parameters:  1.0  0.04  0.9  0.01
─────────────────────────────────
```
"""
TGARCH{o, p, q}(coefs::Vector{T}) where {o, p, q, T}  = TGARCH{o, p, q, T}(coefs)

"""
    GARCH{p, q, T<:AbstractFloat} <: UnivariateVolatilitySpec{T}
---
    GARCH{p, q}(coefs) -> UnivariateVolatilitySpec

Construct a GARCH specification with the given parameters.

# Example:
```jldoctest
julia> GARCH{2, 1}([1., .3, .4, .05 ])
TGARCH{0,2,1} specification.

────────────────────────────────
               ω   β₁   β₂    α₁
────────────────────────────────
Parameters:  1.0  0.3  0.4  0.05
────────────────────────────────
```

"""
const GARCH = TGARCH{0}

"""
    ARCH{q, T<:AbstractFloat} <: UnivariateVolatilitySpec{T}
---
    ARCH{q}(coefs) -> UnivariateVolatilitySpec

Construct an ARCH specification with the given parameters.

# Example:
```jldoctest
julia> ARCH{2}([1., .3, .4])
TGARCH{0,0,2} specification.

──────────────────────────
               ω   α₁   α₂
──────────────────────────
Parameters:  1.0  0.3  0.4
──────────────────────────
```
"""
const ARCH = GARCH{0}

@inline nparams(::Type{<:TGARCH{o, p, q}}) where {o, p, q} = o+p+q+1

@inline presample(::Type{<:TGARCH{o, p, q}}) where {o, p, q} = max(o, p, q)

Base.@propagate_inbounds @inline function update!(
        ht, lht, zt, at, ::Type{<:TGARCH{o, p, q}}, garchcoefs
        ) where {o, p, q}
    mht = garchcoefs[1]
    for i = 1:o
        mht += garchcoefs[i+1]*min(at[end-i+1], 0)^2
    end
    for i = 1:p
        mht += garchcoefs[i+1+o]*ht[end-i+1]
    end
    for i = 1:q
        mht += garchcoefs[i+1+o+p]*(at[end-i+1])^2
    end
    push!(ht, mht)
    push!(lht, (mht > 0) ? log(mht) : -mht)
    return nothing
end

@inline function uncond(::Type{<:TGARCH{o, p, q}}, coefs::Vector{T}) where {o, p, q, T}
    den=one(T)
    for i = 1:o
        den -= coefs[i+1]/2
    end
    for i = o+1:o+p+q
        den -= coefs[i+1]
    end
    h0 = coefs[1]/den
end

function startingvals(::Type{<:TGARCH{o,p,q}}, data::Array{T}) where {o, p, q, T}
    x0 = zeros(T, o+p+q+1)
    x0[2:o+1] .= 0.04/o
    x0[o+2:o+p+1] .= 0.9/p
    x0[o+p+2:end] .= o>0 ? 0.01/q : 0.05/q
    x0[1] = var(data)*(one(T)-sum(x0[2:o+1])/2-sum(x0[o+2:end]))
    return x0
end

function constraints(::Type{<:TGARCH{o,p,q}}, ::Type{T}) where {o,p, q, T}
    lower = zeros(T, o+p+q+1)
    upper = ones(T, o+p+q+1)
    upper[2:o+1] .= ones(T, o)/2
    upper[1] = T(Inf)
    return lower, upper
end

function coefnames(::Type{<:TGARCH{o,p,q}}) where {o,p, q}
    names = Array{String, 1}(undef, o+p+q+1)
    names[1] = "ω"
    names[2:o+1] .= (i -> "γ"*subscript(i)).([1:o...])
    names[2+o:o+p+1] .= (i -> "β"*subscript(i)).([1:p...])
    names[o+p+2:o+p+q+1] .= (i -> "α"*subscript(i)).([1:q...])
    return names
end


text:
# extend methods to dense Hermitian

import .GenericLinearAlgebra
using .GenericLinearAlgebra: symtri!

using LinearAlgebra: RealHermSymComplexHerm

function geigen!(A::RealHermSymComplexHerm{T,<:StridedMatrix};
                 sortby::Union{Function,Nothing}=eigsortby
                 ) where T <: AbstractFloat
    S = symtri!(A)
    λ, V = _st_schur!(S.diagonals.dv, S.diagonals.ev, wantV = true)
    if eltype(A) <: Complex
        V = V .+ 0im
    end
    lmul!(S.Q, V)
    LinearAlgebra.Eigen(sorteig!(λ, V, sortby)...)
end

function geigen!(A::RealHermSymComplexHerm{T,<:StridedMatrix}, irange::UnitRange
                 ) where T <: AbstractFloat
    S = symtri!(A)
    λ, V = _st_schur!(S.diagonals.dv, S.diagonals.ev, wantV = true,
                     select=IndexedEigvalSelector(first(irange),last(irange)))
    if eltype(A) <: Complex
        V = V .+ 0im
    end
    lmul!(S.Q, V)
    LinearAlgebra.Eigen(sorteig!(λ, V, eigsortby)...)
end

function geigen!(A::RealHermSymComplexHerm{T,<:StridedMatrix}, vl::Real, vu::Real
                 ) where T <: AbstractFloat
    S = symtri!(A)
    λ, V = _st_schur!(S.diagonals.dv, S.diagonals.ev, wantV = true,
                     select=IntervalEigvalSelector(vl,vu))
    if eltype(A) <: Complex
        V = V .+ 0im
    end
    lmul!(S.Q, V)
    LinearAlgebra.Eigen(sorteig!(λ, V, eigsortby)...)
end

function geigvals!(A::RealHermSymComplexHerm{T,<:StridedMatrix};
                sortby::Union{Function,Nothing}=eigsortby) where T <: AbstractFloat
    S = symtri!(A)
    λ, _ = _st_schur!(S.diagonals.dv, S.diagonals.ev, wantV = false)
    sorteig!(λ, sortby)
    return λ
end

function geigvals!(A::RealHermSymComplexHerm{T,<:StridedMatrix}, irange::UnitRange
                   ) where T  <: AbstractFloat
    S = symtri!(A)
    λ, _ = _st_schur!(S.diagonals.dv, S.diagonals.ev, wantV = false,
                     select=IndexedEigvalSelector(first(irange),last(irange)))
    sorteig!(λ, sortby)
    return λ
end

function geigvals!(A::RealHermSymComplexHerm{T,<:StridedMatrix}, vl::Real, vu::Real
                   ) where T  <: AbstractFloat
    S = symtri!(A)
    λ, _ = _st_schur!(S.diagonals.dv, S.diagonals.ev, wantV = false,
                     select=IntervalEigvalSelector(vl,vu))
    sorteig!(λ, sortby)
    return λ
end


text:
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()

using Documenter, MolecularGraph

makedocs(
    sitename="MolecularGraph.jl",
    pages = [
        "Home" => "index.md",
        "MolecularGraph" => [
            "Molecule" => "moleculargraph/molecule.md",
            "I/O" => "moleculargraph/io.md",
            "Structure drawing" => "moleculargraph/draw.md",
            "Chemical properties" => "moleculargraph/properties.md",
            "Preprocessing" => "moleculargraph/preprocess.md",
            "Molecular mass/weight" => "moleculargraph/mass.md",
            "Substructure match" => "moleculargraph/substructure.md",
            "MCS" => "moleculargraph/mcs.md",
            "Functional group detection" => "moleculargraph/funcgroup.md"
        ],
        "MolecularGraph.Graph" => [
            "Interface" => "graph/interface.md",
            "Graph models" => "graph/model.md",
            "Generator" => "graph/generator.md",
            "Traversal" => "graph/traversal.md",
            "Topology" => "graph/topology.md",
            "Operations" => "graph/operation.md",
            "Clique" => "graph/clique.md",
            "Isomorphism" => "graph/isomorphism.md"
        ],
        "MolecularGraph.Geometry" => [
            "Cartesian" => "geometry/cartesian.md"
        ]
    ],
    format = Documenter.HTML(
        prettyurls = get(ENV, "CI", nothing) == "true"
    )
)

deploydocs(
    repo="github.com/mojaie/MolecularGraph.jl.git",
    push_preview=true
)


text:
################################################################################
"""
    prepare_maps()
---
# Job descriptions
This is to prepare various maps:
1. [x] Illumina cow 50k v1
2. [x] Illumina cow 50k v2
3. [x] Illumina cow 50k v3
4. [x] Illumina cow 777k
5. [x] Three dutch map
   - 10690
   - 10993
   - 11483

This is suppose to run once for all. It also garantee the maps created meet the
requirements of downstream analysis, e.g., to merge with plink.ped.

# Note
The Illumina platfomr 50k v1-3 has more SNP than those in the final reports.
A subset should be made for that.

# Plink map file
1. chromosome (1-29, X, Y or 0 if unplaced)
2. rs# or snp identifier
3. Genetic distance (morgans)
4. Base-pair position (bp units)
"""
function prepare_maps()
    cd(work_dir)
    tdir = "data/maps/origin"
    isdir(tdir) || mkdir(tdir)

    title("Prepare 7 maps for downstream analsis")
    item("Extract Name, Chr, Mapinfo columns from the Illumina 777k mnft")
    open("$tdir/v7.map", "w") do v7
        open("data/maps/illumina/hd-mnft.csv", "r") do io
            nsnp = 0
            for line in eachline(io) # read total number of SNP
                if occursin("Loci Count", line)
                    nsnp = parse(Int, split(line, ',')[2])
                    break
                end
            end
            for line in eachline(io) # skip header
                occursin("IlmnID", line) && break
            end
            for _ in 1:nsnp
                line = readline(io)
                name, chr, bp = [split(line, ',')[k] for k in [2, 10, 11]]
                write(v7, join([name, chr, bp], '\t'), '\n')
            end
        end
    end
    done()

    item("Extract Name, Chr, Mapinfo columns from the Illumina 54k v1")
    open("$tdir/v1.map", "w") do v1
        open("data/maps/illumina/cow.50k.v1.tsv", "r") do io
            _ = readline(io)
            for line in eachline(io)
                name, chr, bp = [split(line, '\t')[k] for k in [14, 12, 13]]
                write(v1, join([name, chr, bp], '\t'), '\n')
            end
        end
    end
    done()

    item("Extract Name, Chr, Mapinfo columns from the Illumina 50k v2")
    open("$tdir/v2.map", "w") do v2
        open("data/maps/illumina/cow.50k.v2.tsv", "r") do io
            _ = readline(io)
            for line in eachline(io)
                name, chr, bp = [split(line, '\t')[k] for k in [14, 12, 13]]
                write(v2, join([name, chr, bp], '\t'), '\n')
            end
        end
    end
    done()

    item("Extract Name, Chr, Mapinfo columns from the Illumina 50k v3")
    open("$tdir/v3.map", "w") do v3
        open("data/maps/illumina/BovineSNP50_v3_A2.csv", "r") do io
            nsnp = 0
            for line in eachline(io) # read total number of SNP
                if occursin("Loci Count", line)
                    nsnp = parse(Int, split(line, ',')[2])
                    break
                end
            end
            for line in eachline(io) # skip header
                occursin("IlmnID", line) && break
            end
            for _ in 1:nsnp
                line = readline(io)
                name, chr, bp = [split(line, ',')[k] for k in [2, 10, 11]]
                write(v3, join([name, chr, bp], '\t'), '\n')
            end
        end
    end
    done()

    item("Make soft links of 3 Dutch maps")
    dir = pwd()
    cd(tdir)
    for file in ["d1", "d2", "d3"]
        isfile("$file.map") && rm("$file.map")
    end
    symlink("../dutch-ld/10690.map", "d1.map")
    symlink("../dutch-ld/10993.map", "d2.map")
    symlink("../dutch-ld/11483.map", "d3.map")
    cd(work_dir)
end

"""
    update_maps()
---
This function read `v3.map` in `data/maps/origin` as dictionary. Then update the rest with this dictionary.
"""
function update_maps()
    cd(work_dir)
    sdir = "data/maps/origin"
    tdir = "data/maps/updated"
    isdir(tdir) || mkdir(tdir)

    title("Update d1-3, v1, v2, and v7 with v3.map")
    item("v3.map")
    dic = Dict()
    for line in eachline("$sdir/v3.map")
        snp, chr, bp = split(line)
        dic[snp] = [chr, bp]
    end
    cp("$sdir/v3.map", "$tdir/v3.map", force=true)

    for ver in ["d1", "d2", "d3", "v1", "v2", "v7"]
        item("$ver.map")
        target = open("$tdir/$ver.map", "w")
        for line in eachline("$sdir/$ver.map")
            snp, chr, bp = split(line)
            if haskey(dic, snp)
                write(target, snp, ' ', dic[snp][1], ' ', dic[snp][2], '\n')
            else
                write(target, line, '\n')
            end
        end
        done()
    end
end


text:
using Printf
using Formatting
using DifferentialEquations
using ProgressMeter
include("Yfind.jl")
using PyCall
pygui(:qt)
using PyPlot
pygui(true)
# barrier=100

function condition2(u,t,integrator) # Event when event_f(u,t) == 0
 u[1]
end
function affect!(integrator)
end
 function affect_neg!(integrator)
 end
function g(resid,u,p,t)
  resid[1] = ( (u[3]-u[1])^2+(u[2]-u[4])^2 )*( (u[3]+u[1])^2+(u[2]+u[4])^2 )/ ((u[2]^4+2*u[2]^2*(u[1]^2-1)+(1+u[1]^2)^2 )*(u[3]^4+2*u[3]^2*(u[4]^2+1)+(u[4]^2-1)^2 ))-H
  resid[2] = 0
  resid[3] = 0
  resid[4] = 0
end

condition3(u,t,integrator)=abs(u[1])>barrier || abs(u[2])>barrier || abs(u[3])>barrier||abs(u[4])>barrier
affect3!(integrator) = terminate!(integrator)
# Restrict to energy surface
cb1 = ManifoldProjection(g,save=false)
# only keep plane X=0
cb2 = ContinuousCallback(condition2,affect!,nothing)
# stop when vortices escape to infinity
cb3 = DiscreteCallback(condition3,affect3!)

cb=CallbackSet(cb2)
Energy=.45
Energy=0.125789
Energy=BigFloat("0.125789")

H=(2*Energy)^2
n_iter=50
t_end=200

# H1(p,q,t)= ( (q[2]-q[1])^2+(p[2]-p[1])^2 )*( (q[2]+q[1])^2+(p[2]+a[1])^2 )
# H2(p,q,t)= (p[2]^4+2*p[2]^2*(q[1]^2-1)+(1+q[1]^2)^2 )*(q[2]^4+2*q[2]^2*(p[1]^2+1)+(p[1]^2-1)^2 )
# HAM(p,q,t)=H1(p,q,t)/H2(p,q,t)
H_test(u)=( (u[3]-u[1])^2+(u[2]-u[4])^2 )*( (u[3]+u[1])^2+(u[2]+u[4])^2 )/ ((u[2]^4+2*u[2]^2*(u[1]^2-1)+(1+u[1]^2)^2 )*(u[3]^4+2*u[3]^2*(u[4]^2+1)+(u[4]^2-1)^2 ))

ODE1(z,w)=conj(  im * w.*( BigFloat("1") ./(z.^2-w.^2)+BigFloat("1") ./(1+w.^2) ))
ODE2(z,w)=conj(  im * z.*( BigFloat("1") ./(w.^2-z.^2)+BigFloat("1") ./(1+z.^2) ))
function Eq_of_M(du,u,p,t)
    du[1]=real(ODE1(u[1]+im*u[2],u[3]+im*u[4]))
    du[2]=imag(ODE1(u[1]+im*u[2],u[3]+im*u[4]))
    du[3]=real(ODE2(u[1]+im*u[2],u[3]+im*u[4]))
    du[4]=imag(ODE2(u[1]+im*u[2],u[3]+im*u[4]))
    return
end
# refernce
# z=X+iP W=Q+iY . Plane Q=0, P=0
# z=u[1]+i u[2] ; w=u[3]+i u[4]

#Q=0, have P find Y

ArrQ=range(BigFloat("1e-5"),stop=BigFloat("1"),length=n_iter)
ArrP=range(BigFloat("1e-5"),stop=BigFloat("1"),length=n_iter)
#initialize stuff

Last_Q=zeros(BigFloat ,0)
Last_P=zeros(BigFloat ,0)
Last_X=zeros(BigFloat ,0)
Last_Y=zeros(BigFloat ,0)
Last_T=zeros(BigFloat ,0)
MAX=zeros(BigFloat ,0)

#all colors but red, reserve for exit points
COLOR=["b", "g", "c", "m", "y", "k", "w"]
figure(dpi=600)

# axis([ -.3,.3,-.03, .03]);# Efigure(dpi=3600)
axis([ -.025, .025,-.25, .25]) #around E=0.1257895
# axis([ -5, 5, -2, 2])
 for j=1:n_iter
            Q=ArrQ[j]
            for k=1:n_iter

                    P=ArrP[k]
                    Y=Yfind(Q,P,H)
                    if ~isempty(Y) && Y>0
                        u0=zeros(BigFloat,4)
                        u0[1]=0 #X
                        u0[2]=P #P
                        u0[3]=Q #Q
                        u0[4]=Y #Y
                        #are the initial conditions right?
                        u0=convert(Array{Float64},u0)
                        prob = ODEProblem(Eq_of_M,u0,(0., t_end))
                        sol=solve(prob, Vern9(),maxiters=1e10, reltol=1e-13,abstol=1e-15,callback=cb,save_start=true,save_end=true,save_everystep=false)
                        # plot(A[3,:],-A[2,:],color=current_color,",")
                        #testing if energy is conserved at end?
                        A=sol[:,:]
                        #values at end to check if energy is coservered
                        dH=zeros(BigFloat ,length(A[1,:]))
                        umax=zeros(BigFloat ,length(A[1,:]))
                        for i=1:length(A[1,:])
                            uf=zeros(BigFloat ,4)
                            uf[1]=A[1,i] #X
                            uf[2]=A[2,i] #P
                            uf[3]=A[3,i]#Q
                            uf[4]=A[4,i] #Y
                            dH[i]=abs(H_test(uf)-H)
                            umax[i]=maximum(uf)
                        end
                        dH_max=maximum(dH)
                        #filter if energy is not conservered-toss
                        if dH_max<1e-8# t,A=solve(prob, RK4(),maxiters=1e20, reltol=1e-6,abstol=1e-8,callback=cb,save_start=true,save_end=true,save_everystep=false)
                            current_color=COLOR[mod(k,length(COLOR))+1]

                            #convert to float64 before plotting
                            A=convert(Array{Float64},A)
                            # plot(A[2,2:end-1],A[3,2:end-1],color=current_color,",")
                            # plot(-A[2,2:end-1],A[3,2:end-1],color=current_color,",")
                            # plot(A[2,2:end-1],-A[3,2:end-1],color=current_color,",")
                            # plot(-A[2,2:end-1],-A[3,2:end-1],color=current_color,",")
                            # plot(A[3,:],-A[2,:],color=current_color,",")
                            #testing if energy is conserved at end?

                                how_far=maximum(umax)
                                push!(MAX,how_far)
                                # add final values to list- I had to let the callback save the final value so
                                # I need to check if the final value is actually on the section X=0
                                # println(abs(A[1,end]))
                                # println(abs(A[1,end-1]))
                                if abs(A[1,end])<1e-7 && how_far>10
                                    push!(Last_Q,A[3,end])
                                    push!(Last_P,A[2,end])
                                    push!(Last_X,A[1,end])
                                    push!(Last_Y,A[4,end])
                                    push!(Last_T,sol.t[end])
                                elseif abs(A[1,end-1])<1e-7 && how_far>10
                                    push!(Last_Q,A[3,end-1])
                                    push!(Last_P,A[2,end-1])
                                    push!(Last_X,A[1,end-1])
                                    push!(Last_Y,A[4,end-1])
                                    push!(Last_T,sol.t[end-1])
                                end

                            end
                        end
                    end
                end

H_vec=zeros(BigFloat,length(Last_P))
u_max=zeros(BigFloat,length(Last_P))
for j=1:length(Last_P)
    uf=zeros(BigFloat ,4)
    uf[1]=Last_X[j]
    uf[2]=Last_P[j]
    uf[3]=Last_Q[j]
    uf[4]=Last_Y[j]
    u_max[j]=maximum(abs.([uf[1],uf[2],uf[3],uf[4]]))
    H_vec[j]=H_test(uf)/H
end

H_vec=convert(Array{Float64},H_vec)
Last_P=convert(Array{Float64},Last_P)
Last_Q=convert(Array{Float64},Last_Q)
plot(Last_P,Last_Q,color="r",".",markersize=.5, markeredgewidth=.1)
plot(Last_P,-Last_Q,color="r",".",markersize=.5,  markeredgewidth=.1)
plot(-Last_P,Last_Q,color="r",".",markersize=.5,  markeredgewidth=.1)
plot(-Last_P,-Last_Q,color="r",".",markersize=.5, markeredgewidth=.1)
xlabel("P")
ylabel("Q")

# figure()
# title("Is energy conserved?")
# plot(1:length(Last_P)-1,log.(H_vec[1:end-1]))

# figure()
# plot(1:length(Last_P),sort(Last_T) )
# figure()
# # plot(sort(MAX))
# titleS="P-Q Plane PSS where X=0 at Energy "*string(Energy)*" with "*string(n_iter^2)*" iterations."
# filenameS="PSS_Red_ExitE_"*string(Energy)*"_n_iter_"*string(n_iter)*"_t_"*string(t_end)*"withprojection.png"