104 lines
2.5 KiB
Go
104 lines
2.5 KiB
Go
package extract
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
type Params struct {
|
|
InputData string
|
|
OutputPath string
|
|
Satellite string
|
|
DataId string
|
|
LogFile string
|
|
TempPath string
|
|
Report string
|
|
Result string
|
|
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>
|
|
<outputPath>{{.OutputPath}}</outputPath>
|
|
<TempPath>{{.TempPath}}</TempPath>
|
|
<reportFile>{{.ReportFile}}</reportFile>
|
|
<resultFile>{{.ResultFile}}</resultFile>
|
|
</outputfilelist>
|
|
<params>
|
|
<stationId>QH</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
|
|
}
|