func secondPassTHERMO(nc *lib.Nc, m *config.Map, cfg toml.Configtoml, files []string, optDebug *bool) {

	regdata := regexp.MustCompile(cfg.Thecsas.Data)

	fmt.Fprintf(lib.Echo, "Second pass ...\n")

	// initialize profile
	var nbProfile int = 0

	// loop over each files passed throw command line
	for _, file := range files {
		var line int = 0

		fid, err := os.Open(file)
		if err != nil {
			log.Fatal(err)
		}
		defer fid.Close()
		// fmt.Printf("Read %s\n", file)
		// increment slice index
		Profile := GetProfileNumber(nc, nbProfile)
		nc.Variables_1D["PROFILE"] = append(nc.Variables_1D["PROFILE"].([]float64), Profile)
		scanner := bufio.NewScanner(fid)
		for scanner.Scan() {
			str := scanner.Text()
			match := regdata.MatchString(str)
			if match {
				// fill map data with information contain in read line str
				DecodeData(nc, m, str, Profile, file, line)
				// fill 2D slice
				for _, key := range m.Hdr {
					if key != "PRFL" {
						//fmt.Println("Line: ", line, "key: ", key, " data: ", m.Data[key])
						lib.SetData(nc.Variables_2D[key], nbProfile, line, config.GetData(m.Data[key]))
					}
				}

				line++
			}

		}

		if err := scanner.Err(); err != nil {
			log.Fatal(err)
		}
		nbProfile += 1

		var t = lib.NewTimeFromString("Jan 02 2006 15:04:05", nc.Extras_s[fmt.Sprintf("Starttime:%d", int(Profile))])
		v := t.Time2JulianDec()
		nc.Variables_1D["TIME"] = append(nc.Variables_1D["TIME"].([]float64), v)

		if v, err := lib.Position2Decimal(nc.Extras_s[fmt.Sprintf("Startlongpos:%d", int(Profile))]); err == nil {
			nc.Variables_1D["LONGITUDE"] = append(nc.Variables_1D["LONGITUDE"].([]float64), v)
		}
		if v, err := lib.Position2Decimal(nc.Extras_s[fmt.Sprintf("Startlatpos:%d", int(Profile))]); err == nil {
			nc.Variables_1D["LATITUDE"] = append(nc.Variables_1D["LATITUDE"].([]float64), v)
		}
	}

}
예제 #2
0
// read .cnv files and extract data
func secondPassBTL(nc *lib.Nc, m *config.Map, cfg toml.Configtoml, files []string, optDebug *bool) {

	regheader := regexp.MustCompile(cfg.Seabird.Header)
	regheaderBTL := regexp.MustCompile(cfg.Seabird.HeaderBTL)
	regheaderBTL2 := regexp.MustCompile(cfg.Seabird.HeaderBTL2)

	// initialize profile
	var nbProfile int = 0

	fmt.Fprintf(lib.Echo, "Second pass ...\n")
	// loop over each files passed throw command line
	for _, file := range files {
		var line int = 0

		fid, err := os.Open(file)
		if err != nil {
			log.Fatal(err)
		}
		defer fid.Close()
		// fmt.Printf("Read %s\n", file)

		profile := GetProfileNumber(nc, cfg, file)
		fmt.Println("start file : ", profile)
		scanner := bufio.NewScanner(fid)
		for scanner.Scan() {
			str := scanner.Text()
			match := regheader.MatchString(str)
			if match {
				DecodeHeader(nc, cfg, str, profile, optDebug)
			} else {
				match := regheaderBTL.MatchString(str)
				match1 := regheaderBTL2.MatchString(str)
				if !match || !match1 {
					fmt.Println("decodedata  :", line)
					DecodeData(nc, m, str, profile, file, line)
					// fill 2D slice
					for _, key := range m.Hdr {
						if key != "PRFL" {
							//fmt.Println("Line: ", line, "key: ", key, " data: ", m.Data[key])
							lib.SetData(nc.Variables_2D[key], nbProfile, line, config.GetData(m.Data[key]))
						}

					}
					line = line + 1
				}
			}
		}
		if err := scanner.Err(); err != nil {
			log.Fatal(err)
		}

	}
}
예제 #3
0
func secondPassCTD(nc *lib.Nc, m *config.Map, cfg toml.Configtoml, files []string, optDebug *bool) {

	regIsHeader := regexp.MustCompile(cfg.Seabird.Header)

	fmt.Fprintf(lib.Echo, "Second pass ...\n")

	// initialize profile and pressure max
	var nbProfile int = 0

	// loop over each files passed throw command line
	for _, file := range files {
		var line int = 0

		fid, err := os.Open(file)
		if err != nil {
			log.Fatal(err)
		}
		defer fid.Close()
		// fmt.Printf("Read %s\n", file)

		profile := GetProfileNumber(nc, cfg, file)
		scanner := bufio.NewScanner(fid)
		downcast := true
		for scanner.Scan() {
			str := scanner.Text()
			match := regIsHeader.MatchString(str)
			if match {
				DecodeHeader(nc, cfg, str, profile, optDebug)
			} else {
				// fill map data with information contain in read line str
				DecodeData(nc, m, str, profile, file, line)

				if downcast {
					// fill 2D slice
					for _, key := range m.Hdr {
						if key != "PRFL" {
							//fmt.Println("Line: ", line, "key: ", key, " data: ", data[key])
							lib.SetData(nc.Variables_2D[key], nbProfile, line, config.GetData(m.Data[key]))
						}
					}
					// exit loop if reach maximum pressure for the profile
					if m.Data["PRES"] == nc.Extras_f[fmt.Sprintf("PRES:%d", int(profile))] {
						downcast = false
					}
				} else {
					// store last julian day for end profile
					nc.Extras_f[fmt.Sprintf("ETDD:%d", int(profile))] = m.Data["ETDD"].(float64)
					//fmt.Println(presMax)
				}
				line++
			}
		}
		if err := scanner.Err(); err != nil {
			log.Fatal(err)
		}

		// increment sclice index
		nbProfile += 1

		// store last julian day for end profile
		nc.Extras_f[fmt.Sprintf("ETDD:%d", int(profile))] = m.Data["ETDD"].(float64)
		//fmt.Println(presMax)
	}
	fmt.Fprintln(lib.Debug, nc.Variables_1D["PROFILE"])
}
예제 #4
0
func secondPassXBT(nc *lib.Nc, m *config.Map, cfg toml.Configtoml, files []string, optDebug *bool) {

	regIsHeader := regexp.MustCompile(cfg.Mk21.Header)

	fmt.Fprintf(lib.Echo, "Second pass ...\n")

	// initialize profile
	var nbProfile int = 0

	// loop over each files passed throw command line
	for _, file := range files {
		var Etat bool = true
		var line int = 0

		fid, err := os.Open(file)
		if err != nil {
			log.Fatal(err)
		}
		defer fid.Close()
		// fmt.Printf("Read %s\n", file)

		profile := GetProfileNumber(nc, cfg, file)
		nc.Variables_1D["PROFILE"] = append(nc.Variables_1D["PROFILE"].([]float64), profile)
		scanner := bufio.NewScanner(fid)
		downcast := true
		for scanner.Scan() {
			str := scanner.Text()
			match := regIsHeader.MatchString(str)
			if Etat {
				DecodeHeader(nc, cfg, str, profile, optDebug)
			} else {
				// fill map data with information contain in read line str
				DecodeData(nc, m, str, profile, file, line)

				if downcast {
					// fill 2D slice
					for _, key := range m.Hdr {
						if key != "PRFL" {
							lib.SetData(nc.Variables_2D[key], nbProfile, line, config.GetData(m.Data[key]))
							//fmt.Println("Line: ", line, "key: ", key, " data: ", m.Data[key])
						}

					}
					// exit loop if reach maximum pressure for the profile
					if m.Data["DEPTH"] == nc.Extras_f[fmt.Sprintf("DEPTH:%d", int(profile))] {
						downcast = false
					}

				} else {
					// store last julian day for end profile
					//nc.Extras_f[fmt.Sprintf("ETDD:%d", int(profile))] = m.Data["ETDD"].(float64)
					//fmt.Println(presMax)
				}
				line++
			}
			if match {
				Etat = false
			}
		}
		if err := scanner.Err(); err != nil {
			log.Fatal(err)
		}

		// increment sclice index
		nbProfile += 1

		// store last julian day for end profile
		//nc.Extras_f[fmt.Sprintf("ETDD:%d", int(profile))] = m.Data["ETDD"].(float64)
		//fmt.Println(presMax)
		value := nc.Extras_s["DATE"] + " " + nc.Extras_s["HEURE"]
		value = lib.ConvertDate(value)
		var t = lib.NewTimeFromString("Jan 02 2006 15:04:05", value)
		v := t.Time2JulianDec()
		nc.Variables_1D["TIME"] = append(nc.Variables_1D["TIME"].([]float64), v)
	}

	fmt.Fprintln(lib.Debug, nc.Variables_1D["PROFILE"])
}