github.com/archlabjp/eeslism-go@v0.0.0-20231109122333-4bb7bfcdf292/eeslism/eefiles.go (about) 1 package eeslism 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "path/filepath" 8 "strings" 9 ) 10 11 /* ----------------------------------------------------- */ 12 13 // ファイルのオープン 14 func (Simc *SIMCONTL) eeflopen(Flout []*FLOUT, efl_path string) { 15 // 気象データファイルを開く 16 if Simc.Wdtype == 'H' { 17 var fullpath string 18 if filepath.IsAbs(Simc.Wfname) { 19 fullpath = Simc.Wfname 20 } else { 21 fullpath = filepath.Join(efl_path, Simc.Wfname) 22 } 23 24 var err error 25 Simc.Fwdata, err = os.Open(fullpath) 26 if err != nil { 27 Eprint("<eeflopen>", fullpath) 28 os.Exit(EXIT_WFILE) 29 } 30 Simc.Fwdata2, err = os.Open(fullpath) 31 if err != nil { 32 Eprint("<eeflopen>", fullpath) 33 os.Exit(EXIT_WFILE) 34 } 35 36 Simc.Ftsupw, err = ioutil.ReadFile(filepath.Join(efl_path, "supw.efl")) 37 if err != nil { 38 Eprint("<eeflopen>", "supw.efl") 39 os.Exit(EXIT_SUPW) 40 } 41 } 42 43 // Fname = Simc.ofname + ".log" 44 // ferr, err := os.Create(Fname) 45 // if err != nil { 46 // fmt.Println(err) 47 // os.Exit(1) 48 // } 49 50 // 出力ファイルを開く 51 for _, fl := range Flout { 52 fl.Fname = Simc.Ofname + string(fl.Idn) + ".es" 53 fl.F = new(strings.Builder) 54 } 55 } 56 57 /* ----------------------------------------------------- */ 58 59 func Eeflclose(Flout []*FLOUT) { 60 var fl *FLOUT 61 62 if Ferr != nil { 63 Ferr.Close() 64 } 65 66 for _, fl = range Flout { 67 fo, err := os.Create(fl.Fname) 68 if err != nil { 69 Eprint("<eeflopen>", fl.Fname) 70 os.Exit(EXIT_WFILE) 71 } 72 73 fmt.Fprint(fo, fl.F) 74 fmt.Fprintln(fo, "-999") 75 fo.Close() 76 } 77 }