美文网首页
Compass-Walcs-Basic软件单体质量模型文件.dm

Compass-Walcs-Basic软件单体质量模型文件.dm

作者: zoziha | 来源:发表于2020-08-17 08:44 被阅读0次

    1 源码

    package main
    
    /*
    User: zozha
    Date: 2020-06-23
    Function: dmfMaker.go 是采取简单的方式将各站的质量转化为 compass-walcs-baisc 的单体分段质量模型文件 .dmf 。
    */
    
    import (
        "bufio"
        "fmt"
        "io"
        "log"
        "os"
        "strconv"
        "strings"
    )
    
    func readLine(filePth string) [2][]float64 {
        var ReadDate [2][]float64
        file, err := os.Open(filePth)
        if err != nil {
            log.Fatal(err)
        }
        defer file.Close()
        bfRD := bufio.NewReader(file)
        for i := 0; ; i++ {
            line, errRead := bfRD.ReadBytes('\n') // 该语句 读取文件数据行,行的标志是 '\n' 回车。
            if len(line) == 1 {
                continue // 该语句 表明程序读到一条空行。
            }
            j := 0
            for ; ; j++ {
                if line[j] == '\t' {
                    break
                }
            }
            // 下段语句 将数据分为两列,并且去除多余的字符,将读取的字符转化为纯浮点数,最后将其存放在一个二维数组切片内,为后续处理做准备。
            e1, err := strconv.ParseFloat(strCleaner(string(line[:j])), 64)
            if err != nil {
                log.Fatal(err)
            }
            e2, err := strconv.ParseFloat(strCleaner(string(line[j:])), 64)
            if err != nil {
                log.Fatal(err)
            }
            ReadDate[0] = append(ReadDate[0], e1)
            ReadDate[1] = append(ReadDate[1], e2)
            if errRead != nil {
                if errRead == io.EOF {
                    return ReadDate
                }
                log.Fatal(errRead)
            }
        }
    }
    
    // func writeLine 将数据 按 .dmf 文件格式输出
    func writeLine(date [2][]float64) {
        tol := len(date[0])
        var (
            pmass []ms
        )
        pmass = make([]ms, tol, tol)
        yr, zg := readFromConsole()
        file, err := os.OpenFile("./date.done", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
        file_1,err := os.OpenFile("./date_1.done", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
        if err != nil {
            log.Fatal(err)
        }
        defer file.Close()
    
        for i := 0; i < tol; i++ {
            // 下段语句 处理数据
            if i == 0 {
                pmass[i].mi = date[1][i]
                pmass[i].x1 = date[0][i] - 0.5*(date[0][i+1]-date[0][i])
                pmass[i].x2 = date[0][i] + 0.5*(date[0][i+1]-date[0][i])
                pmass[i].xg = 0.5 * (pmass[i].x1 + pmass[i].x2)
                pmass[i].yr = yr
                pmass[i].zg = zg
            } else if i == tol-1 {
                pmass[i].mi = date[1][i]
                pmass[i].x1 = date[0][i] - 0.5*(date[0][i]-date[0][i-1])
                pmass[i].x2 = date[0][i] + 0.5*(date[0][i]-date[0][i-1])
                pmass[i].xg = 0.5 * (pmass[i].x1 + pmass[i].x2)
                pmass[i].yr = yr
                pmass[i].zg = zg
            } else {
                pmass[i].mi = date[1][i]
                pmass[i].x1 = date[0][i] - 0.5*(date[0][i]-date[0][i-1])
                pmass[i].x2 = date[0][i] + 0.5*(date[0][i+1]-date[0][i])
                pmass[i].xg = 0.5 * (pmass[i].x1 + pmass[i].x2)
                pmass[i].yr = yr
                pmass[i].zg = zg
            }
            // 下段语句 将处理后的数据输出到 ./date.done 文件
            file.WriteString(strconv.Itoa(i+1))
            file.Write([]byte("  "))
            file.WriteString(strconv.FormatFloat(pmass[i].mi, 'f', -1, 64))
            file.Write([]byte("  "))
            file.WriteString(strconv.FormatFloat(pmass[i].x1, 'f', -1, 64))
            file.Write([]byte("  "))
            file.WriteString(strconv.FormatFloat(pmass[i].x2, 'f', -1, 64))
            file.Write([]byte("  "))
            file.WriteString(strconv.FormatFloat(pmass[i].xg, 'f', -1, 64))
            file.Write([]byte("  "))
            file.WriteString(strconv.FormatFloat(pmass[i].yr, 'f', -1, 64))
            file.Write([]byte("  "))
            file.WriteString(strconv.FormatFloat(pmass[i].zg, 'f', -1, 64))
            file.Write([]byte("  \n"))
            
            file_1.WriteString(strconv.Itoa(i+1))
            file_1.Write([]byte("  "))
            file_1.WriteString(strconv.FormatFloat(pmass[i].xg, 'f', -1, 64))
            file_1.Write([]byte("  0.0  0.0  "))
            file_1.WriteString(strconv.FormatFloat(pmass[i].zg, 'f', -1, 64))
            file_1.Write([]byte("  \n"))
        }
    
    }
    
    func readFromConsole() (float64, float64) {
        var (
            yr, zg float64
        )
        f := bufio.NewReader(os.Stdin) //读取输入的内容
        for {
            fmt.Print("请输入 yr zg >")
            Input, _ := f.ReadString('\n') //定义一行输入的内容分隔符。
            if len(Input) == 1 {
                continue //如果用户输入的是一个空行就让用户继续输入。
            } else {
                fmt.Sscan(Input, &yr, &zg) //将Input
                fmt.Printf("您输入的第一个参数是:·\033[31;1m%v\033[0m·,输入的第二个参数是··\033[31;1m%v\033[0m·.\n", yr, zg)
                break
            }
    
        }
        return yr, zg
    }
    
    // func strCleaner 去除字符内的 空格、回车、Tab。
    func strCleaner(str string) string {
        str = strings.Replace(str, " ", "", -1)
        str = strings.Replace(str, "\n", "", -1)
        str = strings.Replace(str, "\t", "", -1)
        str = strings.Replace(str, "\r", "", -1)
        return str
    }
    
    // ms 构建船体质量段结构体
    type ms struct {
        mi, x1, x2, xg, yr, zg float64
    }
    
    func main() {
        // 下语句 告诉使用者 该程序的功能是什么。
        fmt.Println("程序功能:dmfMaker.go 是采取简单的方式将各站的质量转化为 compass-walcs-baisc 的单体分段质量模型文件 .dmf 。")
        ReadDate := readLine("./date.test")
        writeLine(ReadDate)
    }
    

    2 实例

    -6.2330 2
    -5.2330 2.305779328
    -4.2330 4.559927617
    -3.2330 4.107797392
    -2.2330 7.555018298
    -1.2330 8.544404575
    -0.2330 9.535647601
    0.7670  9.785724562
    1.7670  9.444907699
    2.7670  9.502077063
    3.7670  11.0050099
    4.7670  12.14715244
    5.7670  10.37115277
    6.7670  10.22936785
    7.7670  12.44091873
    8.7670  13.21113765
    9.7670  14.30198198
    10.7670 14.320104
    11.7670 13.66899266
    12.7670 12.87946151
    13.7670 11.52838389
    14.7670 6.145090715
    15.7670 12.70998965
    16.7670 13.99368408
    17.7670 19.81839815
    18.7670 21.19400422
    19.7670 22.01260445
    20.7670 20.38012513
    21.7670 16.96894532
    22.7670 15.13635421
    23.7670 13.7297027
    24.7670 13.37502768
    25.7670 16.00161312
    26.7670 7.110507213
    27.7670 11.15537134
    28.7670 13.32965835
    29.7670 12.90185057
    30.7670 13.81531035
    31.7670 13.45322222
    32.7670 12.23344337
    33.7670 12.01158223
    34.7670 11.60780953
    35.7670 11.00887448
    36.7670 5.243121192
    37.7670 5.33357333
    38.7670 4.544966446
    39.7670 4.446304967
    40.7670 4.010739151
    41.7670 3.739183101
    42.7670 3.87074772
    43.7670 5.177992512
    44.7670 5.631332947
    45.7670 5.924107108
    46.7670 5.042622014
    47.7670 4.007332034
    48.7670 2.791144298
    49.7670 1.919486923
    50.7670 2.155028224
    51.7670 1.429755033
    52.7670 0.749606668
    53.7670 0.104959719
    
    1  4.385  -6.87  -5.87  -6.37  6.4  3.2  
    2  7.075779328  -5.87  -4.87  -5.37  6.4  3.2  
    3  9.329927617  -4.87  -3.87  -4.37  6.4  3.2  
    4  8.877797392  -3.87  -2.87  -3.37  6.4  3.2  
    5  12.3250183  -2.87  -1.87  -2.37  6.4  3.2  
    6  13.31440457  -1.87  -0.8700000000000001  -1.37  6.4  3.2  
    7  14.3056476  -0.87  0.13  -0.37  6.4  3.2  
    8  14.55572456  0.13  1.13  0.6299999999999999  6.4  3.2  
    9  14.2149077  1.13  2.13  1.63  6.4  3.2  
    10  14.27207706  2.13  3.13  2.63  6.4  3.2  
    11  13.3900099  3.13  4.13  3.63  6.4  3.2  
    12  12.14715244  4.13  5.13  4.63  6.4  3.2  
    13  10.37115277  5.13  6.13  5.63  6.4  3.2  
    14  10.22936785  6.13  7.13  6.63  6.4  3.2  
    15  12.44091873  7.13  8.13  7.630000000000001  6.4  3.2  
    16  13.21113765  8.13  9.13  8.63  6.4  3.2  
    17  14.30198198  9.13  10.13  9.63  6.4  3.2  
    18  14.320104  10.13  11.13  10.63  6.4  3.2  
    19  13.66899266  11.13  12.13  11.63  6.4  3.2  
    20  12.87946151  12.13  13.13  12.63  6.4  3.2  
    21  11.52838389  13.13  14.13  13.63  6.4  3.2  
    22  6.145090715  14.13  15.13  14.63  6.4  3.2  
    23  12.70998965  15.13  16.13  15.629999999999999  6.4  3.2  
    24  18.12368408  16.13  17.13  16.63  6.4  3.2  
    25  28.07839815  17.13  18.13  17.63  6.4  3.2  
    26  29.45400422  18.13  19.13  18.63  6.4  3.2  
    27  30.27260445  19.13  20.13  19.63  6.4  3.2  
    28  28.64012513  20.13  21.13  20.63  6.4  3.2  
    29  21.09894532  21.13  22.13  21.63  6.4  3.2  
    30  15.13635421  22.13  23.13  22.63  6.4  3.2  
    31  13.7297027  23.13  24.13  23.63  6.4  3.2  
    32  13.37502768  24.13  25.13  24.63  6.4  3.2  
    33  16.00161312  25.13  26.13  25.63  6.4  3.2  
    34  7.110507213  26.13  27.13  26.63  6.4  3.2  
    35  11.15537134  27.13  28.13  27.63  6.4  3.2  
    36  13.32965835  28.13  29.13  28.63  6.4  3.2  
    37  12.90185057  29.13  30.13  29.63  6.4  3.2  
    38  13.81531035  30.13  31.13  30.63  6.4  3.2  
    39  13.45322222  31.13  32.13  31.630000000000003  6.4  3.2  
    40  12.23344337  32.13  33.13  32.63  6.4  3.2  
    41  12.01158223  33.13  34.13  33.63  6.4  3.2  
    42  11.60780953  34.13  35.13  34.63  6.4  3.2  
    43  11.00887448  35.13  36.13  35.63  6.4  3.2  
    44  5.243121192  36.13  37.13  36.63  6.4  3.2  
    45  5.33357333  37.13  38.13  37.63  6.4  3.2  
    46  4.544966446  38.13  39.13  38.63  6.4  3.2  
    47  4.446304967  39.13  40.13  39.63  6.4  3.2  
    48  4.010739151  40.13  41.13  40.63  6.4  3.2  
    49  3.739183101  41.13  42.13  41.63  6.4  3.2  
    50  3.87074772  42.13  43.13  42.63  6.4  3.2  
    51  5.177992512  43.13  44.13  43.63  6.4  3.2  
    52  5.631332947  44.13  45.13  44.63  6.4  3.2  
    53  5.924107108  45.13  46.13  45.63  6.4  3.2  
    54  5.042622014  46.13  47.13  46.63  6.4  3.2  
    55  4.007332034  47.13  48.13  47.63  6.4  3.2  
    56  2.791144298  48.13  49.13  48.63  6.4  3.2  
    57  1.919486923  49.13  50.13  49.63  6.4  3.2  
    58  2.155028224  50.13  51.13  50.63  6.4  3.2  
    59  1.429755033  51.13  52.13  51.63  6.4  3.2  
    60  0.749606668  52.13  53.13  52.63  6.4  3.2  
    61  0.104959719  53.13  54.13  53.63  6.4  3.2  
    

    3 美图

    知乎-雾山五行.png

    相关文章

      网友评论

          本文标题:Compass-Walcs-Basic软件单体质量模型文件.dm

          本文链接:https://www.haomeiwen.com/subject/ifyfjktx.html