BiasCorrectQ.Program.WriteFile C# (CSharp) Method

WriteFile() private static method

private static WriteFile ( List sim_new, string filename, TextFormat fmt ) : void
sim_new List
filename string
fmt TextFormat
return void
        private static void WriteFile(List<Point> sim_new, string filename,
            TextFormat fmt)
        {
            //make sure directory to filename exists
            string outdir = Path.GetDirectoryName(Path.GetFullPath(filename));
            if (!Directory.Exists(outdir))
            {
            Directory.CreateDirectory(outdir);
            }

            //fill lines with sim new data
            string[] lines = new string[sim_new.Count];
            for (int i = 0; i < sim_new.Count; i++)
            {
            Point pt = sim_new[i];

            if (fmt == TextFormat.vic)
            {
                lines[i] = string.Format("{0} {1} {2:0.000}", pt.Date.Year, pt.Date.Month,
                                         pt.Value);
                if (Utils.IsDataDaily(sim_new))
                {
                    lines[i] = string.Format("{0} {1} {2} {3:0.000}", pt.Date.Year, pt.Date.Month,
                                             pt.Date.Day, pt.Value);
                }

            }
            if (fmt == TextFormat.csv)
            {
                lines[i] = string.Format("{0:M/d/yyyy},{1:0.000}", pt.Date, pt.Value);
            }
            }

            //write file
            File.WriteAllLines(filename, lines);
        }