import os import re table = { "u": "u", "i" : "i", "b" : "i8", "B" : "u8", "S" : "&'a str", "f" : "f", } _S_INFO = [ ("time", "u4"), ("day", "u2"), ("unambiguous_distance", "u2"), ("azimuth", "u2"), ("radial_num", "u2"), ("radial_state", "u2"), ("elevation", "u2"), ("el_num", "u2"), ("first_gate_r", "u2"), ("first_gate_v", "u2"), ("gate_length_r", "u2"), ("gate_length_v", "u2"), ("gate_num_r", "u2"), ("gate_num_v", "u2"), ("sector_num", "u2"), ("system_coff", "u4"), ("r_pointer", "u2"), ("v_pointer", "u2"), ("w_pointer", "u2"), ("v_reso", "u2"), ("vcp_mode", "u2"), ("res2", "u2", 4), ("r_pointer_2", "u2"), ("v_pointer_2", "u2"), ("w_pointer_2", "u2"), ("nyquist_vel", "u2"), ] _S_INFO = [("r", "u1", 460), ("v", "u1", 920), ("w", "u1", 920), ("res4", "u2", 2)] _S_INFO = [("r", "u1", 800), ("v", "u1", 1600), ("w", "u1", 1600), ("res4", "u2", 2)] _S_INFO = [("r", "u1", 1000), ("v", "u1", 1000), ("w", "u1", 1000)] _S_INFO = [ ("sFileID", "S4"), ("fVersionNo", "f4"), ("lFileHeaderLength", "i4"), ("sCountry", "S30"), ("sProvince", "S20"), ("sStation", "S40"), ("sStationNumber", "S10"), ("sRadarType", "S20"), ("sLongitude", "S16"), ("sLatitude", "S16"), ("lLongitudeValue", "i4"), ("lLatitudeValue", "i4"), ("lHeight", "i4"), ("shMaxAngle", "i2"), ("shOptiAngle", "i2"), ("lAntennaG", "i4"), ("usBeamH", "u2"), ("usBeamL", "u2"), ("ucPolarization", "B"), ("usSidelobe", "u2"), ("lPower", "i4"), ("lWavelength", "i4"), ("usLogA", "u2"), ("usLineA", "u2"), ("usAGCP", "u2"), ("usLogMinPower", "u2"), ("usLineMinPower", "u2"), ("ucClutterT", "B"), ("ucVelocityP", "B"), ("ucFilterP", "B"), ("ucNoiseT", "B"), ("ucSQIT", "B"), ("ucIntensityC", "B"), ("ucIntensityR", "B"), ] def transform(k): f = k[0] tf = f[0] flag = table.get(tf) if len(k) == 1: if tf in ['S','b','B']: return flag return f"{flag}{int(f[1:])*8}" else: l = int(k[1]) if tf in ['S','b','B']: return f"[{flag};{l}]" else: return f"[{flag}{int(f[1:])*8}; {l}]" def camel_to_snake(name): name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower() for i in _S_INFO: print(f"f{camel_to_snake(i[0])}: {transform(i[1:])},")