xml params
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package extract
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Params struct {
|
||||
InputData string
|
||||
OutputPath string
|
||||
@@ -12,5 +18,86 @@ type Params struct {
|
||||
Station string
|
||||
}
|
||||
|
||||
// 定义 InputFileList 结构体
|
||||
type InputFileList struct {
|
||||
InputData string `xml:"inputdata"`
|
||||
}
|
||||
|
||||
// 定义 OutputFileList 结构体
|
||||
type OutputFileList struct {
|
||||
Num int `xml:"num,attr"`
|
||||
OutputPath string `xml:"outputPath"`
|
||||
TempPath string `xml:"tempPath"`
|
||||
ReportFile string `xml:"reportFile"`
|
||||
ResultFile string `xml:"resultFile"`
|
||||
}
|
||||
|
||||
// 定义 Params 结构体
|
||||
type XMLParams struct {
|
||||
StationId string `xml:"stationId"`
|
||||
Sensor string `xml:"sensor"`
|
||||
DataId string `xml:"dataId"`
|
||||
SatelliteId string `xml:"satelliteId"`
|
||||
}
|
||||
|
||||
// 定义 Task 结构体
|
||||
type L0Task struct {
|
||||
XMLName xml.Name `xml:"task"`
|
||||
InputFileList InputFileList `xml:"inputFileList"`
|
||||
OutputFileList OutputFileList `xml:"outputfilelist"`
|
||||
Params XMLParams `xml:"params"`
|
||||
}
|
||||
|
||||
// L0 ID
|
||||
const L0_ID = `{{.Satellite}}_{{.Sensor}}_{{.YYMMDD}}_{{.HHMMSS}}_{{.DataId}}_{{.Index}}`
|
||||
|
||||
const L0TPLFile = "resource/template/satellite/sjy01.l0.xml.tpl"
|
||||
const L0TPL = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<task>
|
||||
<inputFileList>
|
||||
<inputdata>{{.InputData}}</inputdata>
|
||||
</inputFileList>
|
||||
<outputfilelist num="3">
|
||||
<outputPath>{{.OutputPath}}</outputPath>
|
||||
<TempPath>{{.TempPath}}</TempPath>
|
||||
<reportFile>{{.ReportFile}}</reportFile>
|
||||
<resultFile>{{.ResultFile}}</resultFile>
|
||||
</outputfilelist>
|
||||
<params>
|
||||
<stationId>WN</stationId>
|
||||
<sensor>PMS</sensor>
|
||||
<dataId>{{.DataId}}</dataId>
|
||||
<satelliteId>SJY01</satelliteId>
|
||||
</params>
|
||||
</task>
|
||||
`
|
||||
|
||||
func LoadL0Params(fname string) (*Params, error) {
|
||||
data, err := os.ReadFile(fname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var task L0Task
|
||||
err = xml.Unmarshal(data, &task)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var params Params
|
||||
params.InputData = task.InputFileList.InputData
|
||||
params.OutputPath = task.OutputFileList.OutputPath
|
||||
params.Satellite = task.Params.SatelliteId
|
||||
params.DataId = task.Params.DataId
|
||||
params.Report = task.OutputFileList.ReportFile
|
||||
params.Result = task.OutputFileList.ResultFile
|
||||
params.Station = task.Params.StationId
|
||||
|
||||
params.LogFile = fmt.Sprintf("/tmp/SJY01/log/%s_l0.log", params.DataId)
|
||||
params.TempPath = task.OutputFileList.TempPath
|
||||
if params.TempPath == "" {
|
||||
params.TempPath = "/tmp/SJY01/data"
|
||||
}
|
||||
|
||||
return ¶ms, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user