// read cnv files in two pass, the first to get dimensions // second to get data func ReadSeabird(nc *lib.Nc, m *config.Map, files []string, optCfgfile string) { switch { case filestruct.Instrument == cfg.Instrument.Type[0]: config.GetConfigCTD(nc, m, cfg, optCfgfile, filestruct.TypeInstrument, optAll) // first pass, return dimensions fron cnv files nc.Dimensions["TIME"], nc.Dimensions["DEPTH"] = firstPassCTD(nc, files) // initialize 2D data nc.Variables_2D = make(lib.AllData_2D) for i, _ := range m.Map_var { nc.Variables_2D.NewData_2D(i, nc.Dimensions["TIME"], nc.Dimensions["DEPTH"]) } // second pass, read files again, extract data and fill slices secondPassCTD(nc, files) // write ASCII file WriteAsciiCTD(nc, m.Map_format, m.Hdr, filestruct.Instrument) // write netcdf file //if err := nc.WriteNetcdf(); err != nil { //log.Fatal(err) //} WriteNetcdf(nc, m, filestruct.Instrument) case filestruct.Instrument == cfg.Instrument.Type[1]: config.GetConfigBTL(nc, m, cfg, optCfgfile, filestruct.TypeInstrument) // first pass, return dimensions fron btl files nc.Dimensions["TIME"], nc.Dimensions["DEPTH"] = firstPassBTL(nc, m, files) // // initialize 2D data // nc.Variables_2D = make(AllData_2D) // for i, _ := range map_var { // nc.Variables_2D.NewData_2D(i, nc.Dimensions["TIME"], nc.Dimensions["DEPTH"]) // } // second pass, read files again, extract data and fill slices secondPassBTL(nc, m, files) // write ASCII file WriteAsciiBTL2(nc, m.Map_format, m.Hdr, filestruct.Instrument) // write netcdf file //if err := nc.WriteNetcdf(); err != nil { //log.Fatal(err) //} WriteNetcdf(nc, m, filestruct.Instrument) } }
func GetConfigCTD(nc *lib.Nc, m *Map, cfg toml.Configtoml, configFile string, Type string, optAll *bool) { // var split, header, format string var split, splitAll []string // define map from netcdf structure nc.Dimensions = make(map[string]int) nc.Attributes = make(map[string]string) nc.Extras_f = make(map[string]float64) nc.Extras_s = make(map[string]string) nc.Variables_1D = make(map[string]interface{}) // initialize map entry from nil interface to empty slice of float64 nc.Variables_1D["PROFILE"] = []float64{} nc.Variables_1D["TIME"] = []float64{} nc.Variables_1D["LATITUDE"] = []float64{} nc.Variables_1D["LONGITUDE"] = []float64{} nc.Variables_1D["BATH"] = []float64{} nc.Variables_1D["TYPECAST"] = []float64{} nc.Variables_1D["TYPECAST"] = append(nc.Variables_1D["TYPECAST"].([]float64), -1) nc.Roscop = roscop.CodeRoscopFromCsv(cfg.Roscopfile) // add some global attributes for profile, change in future nc.Attributes["data_type"] = Type split = cfg.Ctd.Split splitAll = cfg.Ctd.SplitAll // stationPrefixLength = cfg.Ctd.StationPrefixLength // TODOS: complete nc.Attributes["cycle_mesure"] = cfg.Cruise.CycleMesure nc.Attributes["plateforme"] = cfg.Cruise.Plateforme nc.Attributes["institute"] = cfg.Cruise.Institute nc.Attributes["pi"] = cfg.Cruise.Pi nc.Attributes["timezone"] = cfg.Cruise.Timezone nc.Attributes["begin_date"] = cfg.Cruise.BeginDate nc.Attributes["end_date"] = cfg.Cruise.EndDate nc.Attributes["creator"] = cfg.Cruise.Creator nc.Attributes["type_instrument"] = cfg.Ctd.TypeInstrument nc.Attributes["instrument_number"] = cfg.Ctd.InstrumentNumber // add specific column(s) to the first header line in ascii file // First column should be PRFL m.Hdr = append(m.Hdr, "PRFL") // fill map_var from split (read in .ini configuration file) // store the position (column) of each physical parameter var fields []string if *optAll { fields = splitAll } else { fields = split } fmt.Fprintln(debug, "getConfig: ", fields) // construct header slice from split for i := 0; i < len(fields); i += 2 { if v, err := strconv.Atoi(fields[i+1]); err == nil { m.Map_var[fields[i]] = v - 1 m.Hdr = append(m.Hdr, fields[i]) } } fmt.Fprintln(debug, "getConfig: ", m.Hdr) // fill map_format from code_roscop for _, key := range m.Hdr { m.Map_format[key] = roscop.GetRoscopformat(nc.Roscop[key]) } //return nc }