Calc CRC16 for massage
163715
def crc16(msg)
      crc_lo = 0xff
      crc_hi = 0xff

      msg.unpack('c*').each do |byte|
        i = crc_hi ^ byte
        crc_hi = crc_lo ^ CrcHiTable[i]
        crc_lo = CrcLoTable[i]
      end

      return ((crc_hi << 8) + crc_lo)
    end
1286122
function phi1z(eccent, qs) {
        var sinphi, cosphi, con, com, dphi;
        var phi = asinz(0.5 * qs);
        if (eccent < EPSLN) {
            return phi;
        }

        var eccnts = eccent * eccent;
        for (var i = 1; i <= 25; i++) {
            sinphi = Math.sin(phi);
            cosphi = Math.cos(phi);
            con = eccent * sinphi;
            com = 1 - con * con;
            dphi = 0.5 * com * com / cosphi * (qs / (1 - eccnts) - sinphi / com + 0.5 / eccent * Math.log((1 - con) / (1 + con)));
            phi = phi + dphi;
            if (Math.abs(dphi) <= 1e-7) {
                return phi;
            }
        }
        return null;
    }
809722
def calc_AF(M,major=0,minor=2):
    """"""
    if minor==2:
        Nhet   = (M==0).sum(axis=0)
        Nmajor = 2*(M==0).sum(axis=0)
        Nminor = 2*(M==2).sum(axis=0)
        af  = Nminor/sp.double(2*M.shape[0])
    else:
        Nmajor = (M==0).sum(axis=0)
        Nminor = (M==1).sum(axis=0)
        af  = Nminor/sp.double(1*M.shape[0])
    RV = {}
    RV['af'] = af
    RV['Nmajor'] = Nmajor
    RV['Nminor'] = Nminor
    return RV
616614
def _calculate_crc_ccitt(data):
    
    global CRC_CCITT_TABLE
    if not CRC_CCITT_TABLE:
        crc_ccitt_table = []
        for i in range(0, 256):
            crc = 0
            c = i << 8

            for j in range(0, 8):
                if (crc ^ c) & 0x8000:
                    crc = c_ushort(crc << 1).value ^ 0x1021
                else:
                    crc = c_ushort(crc << 1).value

                c = c_ushort(c << 1).value

            crc_ccitt_table.append(crc)
            CRC_CCITT_TABLE = crc_ccitt_table

    is_string = _is_string(data)
    crc_value = 0x0000  # XModem version

    for c in data:
        d = ord(c) if is_string else c
        tmp = ((crc_value >> 8) & 0xff) ^ d
        crc_value = ((crc_value << 8) & 0xff00) ^ CRC_CCITT_TABLE[tmp]

    return crc_value
1016779
function crc32(str: string): number {
  /* jslint bitwise: true */
  var crc = -1;
  for (var i = 0, len = str.length; i < len; i++) {
    crc = (crc >>> 8) ^ table[(crc ^ str.charCodeAt(i)) & 0xFF];
  }
  return ~crc;
}
1160673
public static int generateInt16(int crc, int value)
  {
    crc = next(crc, (value >> 8));
    crc = next(crc, (value >> 0));

    return crc;
  }
679011
private void calcERT(int deviation) {
        final int[][][] ERTs = this.ERTs;
        final int currentLength = ERTs.length;

        // we have to extend the ERT table

        int[][] lastERT = ERTs[ERTs.length - 1];
        int[][] nextERT = new int[lastERT.length][weights.size()];
        if (currentLength == 1) {
            //first line compares biggest residue and 0
            for (int j = 0; j < weights.size(); j++) {
                nextERT[0][j] = Math.min(lastERT[nextERT.length - 1][j], lastERT[0][j]);
            }
            for (int i = 1; i < nextERT.length; i++) {
                for (int j = 0; j < weights.size(); j++) {
                    nextERT[i][j] = Math.min(lastERT[i][j], lastERT[i - 1][j]);
                }
            }
        } else {
            int step = (1 << (currentLength - 2));
            for (int i = step; i < nextERT.length; i++) {
                for (int j = 0; j < weights.size(); j++) {
                    nextERT[i][j] = Math.min(lastERT[i][j], lastERT[i - step][j]);
                }
            }
            //first lines compared with last lines (greatest residues) because of modulo's cyclic characteristic
            for (int i = 0; i < step; i++) {
                for (int j = 0; j < weights.size(); j++) {
                    nextERT[i][j] = Math.min(lastERT[i][j], lastERT[i + nextERT.length - step][j]);
                }
            }
        }

        // now store newly calculated ERT
        synchronized (this) {
            final int[][][] tables = this.ERTs;
            if (tables.length == currentLength) {
                this.ERTs = Arrays.copyOf(this.ERTs, this.ERTs.length + 1);
                this.ERTs[this.ERTs.length - 1] = nextERT;
            } else {
                // another background thread did already compute the ERT. So we don't have to do this again
            }
        }
        // recursively calculate ERTs for higher deviations
        // current ERT is already sufficient
        if ((1 << (currentLength - 1)) <= deviation) calcERT(deviation);
    }
507296
def calc_cR(Q2, sigma):
    """"""
    return Q2 * np.exp(np.sum(np.log(sigma**2))/sigma.shape[0])
1341739
function (r, a, sqrtassist) {
  var r1 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var r2 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var r3 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var r4 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var r5 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var i=0;
  curve25519_sqrmodp(r2, a);					//  2 === 2 * 1
  curve25519_sqrmodp(r3, r2);					//  4 === 2 * 2
  curve25519_sqrmodp(r1, r3);					//  8 === 2 * 4
  curve25519_mulmodp(r3, r1, a);				//  9 === 8 + 1
  curve25519_mulmodp(r1, r3, r2);				// 11 === 9 + 2
  curve25519_sqrmodp(r2, r1);					// 22 === 2 * 11
  curve25519_mulmodp(r4, r2, r3);				// 31 === 22 + 9
 												//	=== 2^5   - 2^0
  curve25519_sqrmodp(r2, r4);					// 2^6   - 2^1
  curve25519_sqrmodp(r3, r2);					// 2^7   - 2^2
  curve25519_sqrmodp(r2, r3);					// 2^8   - 2^3
  curve25519_sqrmodp(r3, r2);					// 2^9   - 2^4
  curve25519_sqrmodp(r2, r3);					// 2^10  - 2^5
  curve25519_mulmodp(r3, r2, r4);				// 2^10  - 2^0
  curve25519_sqrmodp(r2, r3);					// 2^11  - 2^1
  curve25519_sqrmodp(r4, r2);					// 2^12  - 2^2
  for (i = 1; i < 5; i++) {
	curve25519_sqrmodp(r2, r4);
	curve25519_sqrmodp(r4, r2);
  } 											// 2^20  - 2^10
  curve25519_mulmodp(r2, r4, r3);				// 2^20  - 2^0
  curve25519_sqrmodp(r4, r2);					// 2^21  - 2^1
  curve25519_sqrmodp(r5, r4);					// 2^22  - 2^2
  for (i = 1; i < 10; i++) {
	curve25519_sqrmodp(r4, r5);
	curve25519_sqrmodp(r5, r4);
  } 											// 2^40  - 2^20
  curve25519_mulmodp(r4, r5, r2);				// 2^40  - 2^0
  for (i = 0; i < 5; i++) {
	curve25519_sqrmodp(r2, r4);
	curve25519_sqrmodp(r4, r2);
  } 											// 2^50  - 2^10
  curve25519_mulmodp(r2, r4, r3);				// 2^50  - 2^0
  curve25519_sqrmodp(r3, r2);					// 2^51  - 2^1
  curve25519_sqrmodp(r4, r3);					// 2^52  - 2^2
  for (i = 1; i < 25; i++) {
	curve25519_sqrmodp(r3, r4);
	curve25519_sqrmodp(r4, r3);
  } 											// 2^100 - 2^50
  curve25519_mulmodp(r3, r4, r2);				// 2^100 - 2^0
  curve25519_sqrmodp(r4, r3);					// 2^101 - 2^1
  curve25519_sqrmodp(r5, r4);					// 2^102 - 2^2
  for (i = 1; i < 50; i++) {
	curve25519_sqrmodp(r4, r5);
	curve25519_sqrmodp(r5, r4);
  } 											// 2^200 - 2^100
  curve25519_mulmodp(r4, r5, r3);				// 2^200 - 2^0
  for (i = 0; i < 25; i++) {
	curve25519_sqrmodp(r5, r4);
	curve25519_sqrmodp(r4, r5);
  } 											// 2^250 - 2^50
  curve25519_mulmodp(r3, r4, r2);				// 2^250 - 2^0
  curve25519_sqrmodp(r2, r3);					// 2^251 - 2^1
  curve25519_sqrmodp(r3, r2);					// 2^252 - 2^2
  if (sqrtassist === 1) {
	curve25519_mulmodp(r, a, r3);				// 2^252 - 3
  } else {
	curve25519_sqrmodp(r2, r3);					// 2^253 - 2^3
	curve25519_sqrmodp(r3, r2);					// 2^254 - 2^4
	curve25519_sqrmodp(r2, r3);					// 2^255 - 2^5
	curve25519_mulmodp(r, r2, r1);				// 2^255 - 21
  }
}
390733
static int calculateChecksum(ByteBuf data, int offset, int length) {
        Crc32c crc32 = new Crc32c();
        try {
            crc32.update(data, offset, length);
            return maskChecksum((int) crc32.getValue());
        } finally {
            crc32.reset();
        }
    }
302871
def rs(self):
        
        rs = np.linalg.norm(self.coords_for_computations, axis=1)
        return ComputedColumn(self, rs)
874350
def crc16(data):
    
    m_crc = 0xffff
    for this in data:
        m_crc ^= ord(this)
        for _ in range(8):
            j = m_crc & 1
            m_crc >>= 1
            if j:
                m_crc ^= 0x8408
    return m_crc
1020289
def calcEL(self,**kwargs):
                                   
        E,L= calcELStaeckel(self._R,self._vR,self._vT,self._z,self._vz,
                            self._pot)
        return (E,L)
1053664
def calc_complex(mag, pha):
    ''' 
    '''
    complx = [10 ** m * math.e ** (1j * p / 1e3) for m, p in zip(mag, pha)]
    real = [math.log10((1 / c).real) for c in complx]
    imag = []
    for c in complx:
        if ((1 / c).imag) == 0:
            imag.append(math.nan)
        else:
            i = math.log10(abs((1 / c).imag))
            imag.append(i)
    return real, imag
1304305
def calculo(self):
        """"""
        T = self.kwargs["T"]
        P = self.kwargs["P"]
        S = self.kwargs["S"]

        self.m = S/(1-S)/Ms
        if self.kwargs["fast"] and T <= 313.15:
            pw = self._waterSupp(T, P)
        elif self.kwargs["IF97"]:
            pw = self._waterIF97(T, P)
        else:
            pw = self._water(T, P)
        ps = self._saline(T, P, S)

        prop = {}
        for key in ps:
            prop[key] = pw[key]+ps[key]
            self.__setattr__(key, prop[key])

        self.T = T
        self.P = P
        self.rho = 1./prop["gp"]
        self.v = prop["gp"]
        self.s = -prop["gt"]
        self.cp = -T*prop["gtt"]
        self.cv = T*(prop["gtp"]**2/prop["gpp"]-prop["gtt"])
        self.h = prop["g"]-T*prop["gt"]
        self.u = prop["g"]-T*prop["gt"]-P*1000*prop["gp"]
        self.a = prop["g"]-P*1000*prop["gp"]
        self.alfav = prop["gtp"]/prop["gp"]
        self.betas = -prop["gtp"]/prop["gtt"]
        self.xkappa = -prop["gpp"]/prop["gp"]
        self.ks = (prop["gtp"]**2-prop["gtt"]*prop["gpp"])/prop["gp"] / \
            prop["gtt"]
        self.w = prop["gp"]*(prop["gtt"]*1000/(prop["gtp"]**2 -
                             prop["gtt"]*1000*prop["gpp"]*1e-6))**0.5

        if "thcond" in pw:
            kw = pw["thcond"]
        else:
            kw = _ThCond(1/pw["gp"], T)
        try:
            self.k = _ThCond_SeaWater(T, P, S)+kw
        except NotImplementedError:
            self.k = None

        if S:
            self.mu = prop["gs"]
            self.muw = prop["g"]-S*prop["gs"]
            self.mus = prop["g"]+(1-S)*prop["gs"]
            self.osm = -(ps["g"]-S*prop["gs"])/self.m/Rm/T
            self.haline = -prop["gsp"]/prop["gp"]
        else:
            self.mu = None
            self.muw = None
            self.mus = None
            self.osm = None
            self.haline = None
159934
def _crc16(data, crc, table):
    
    bytes_to_int = lambda x: ord(x) if sys.version_info.major == 2 else x
    for byte in data:
        crc = ((crc << 8) & 0xff00) ^ table[((crc >> 8) & 0xff) ^ bytes_to_int(byte)]
    return crc & 0xffff
747658
def check_crc(f, inf, desc):
    
    exp = inf._md_expect
    if exp is None:
        return
    ucrc = f._md_context.digest()
    if ucrc != exp:
        print('crc error - %s - exp=%r got=%r' % (desc, exp, ucrc))