parsing - Parse formatted string in Golang -


I am trying to parse a GNSS Rinx file using Golland.

For example, here is the RINEX specification for line VERSION:

  + ------------------- - + ------------------------------------------ + ----- - ------ + | RINEX version / type | - Format version (2.11) | F 9.2, 11x, | | | - File type (for 'o' overview data). A1, 19, X, | | | - Satellite system: blank or 'g': GPS | A1, 19 x. | | 'R': GLONASS | | | | 'S': Geostationary | | | | Signal payload | | | | 'E': Galileo | | | | 'M': Mixed | | + -------------------- + ---------------------------- -------------- + ------------ +  

Each row has a fixed width in a RINEX file 80 ASCII character + "\ n". In this example, the first 9 letter version number (float) indicates.

In Python I can use it:

  struct.unpack ("9s11s1s19s1s19s20s", line)  

7 string

I am new to going and trying to use fmt.Sscanf to read the formatted text:

  func main () {str: = "2.11 Inspection Data G (GPS) Rinx version / type \ n "var value float 32a, gael: = fmt. Sqnf (str, "% 9.2f", and value) fmt.println (a) fmt.println (err) fmt .Println (value)}  

Returns:

< Pre> 0 bad action% for Float32 0

Is there a package that allows to parse fixed width data?

And if not, what could be a good way to write something like this, for example,

  package main import ("" "  / P>   errors "" FMT "" strunk "" strings ") // http://gage14.upc.es/gLAB/HTML/LaunchHTML.html // http: // gage14. Upc.es/gLAB/HTML/Observation_Rinex_v2.11 .html file to Parsvasian Type (line string) (version float64, fileType, satellite, label string, error error) {label = line [60:80] If the label! = "RINEX VERSION / TYPE" {err = errors.New ("unknown error = = zero {return} fileType = line [20:21] satellite = line [40: header label"] return} version, err = strconv.ParseFloat (Line [0: 9]), 64) 41] Return} Fenc Main () {Line: = "2.11 Inspection Data G (GPS) Rinx Works ION / TYPE \ n" version, fileType, satellite, label , Err: = parseVersionType (line) fmt.printf ("% g% q% q% q% v \ n", version, file type, satellite, label, error)}  

Output:

  2.11 "Hey" "G" "RINX version / type" & gt; & gt;  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -