Fixed write block

Do you have objects, models, libraries, path decorators, textures, symbols, custom API code, documentation, or anything else others might find useful? Please attach it here with a brief description.
Post Reply
jdoran
Posts: 700
Joined: Tue Dec 06, 2011 6:47 am
Location: Brisbane, QLD

Fixed write block

Post by jdoran » Sun Jan 05, 2014 7:25 pm

This fixed the outstanding bug where writing in an experiment would dump all csv files in the simulation root directory, ignoring the relative directories you specify in the file path in the file element. The fix was trivial, and I am sure I have raised it several times both on this forum. I made the fix a few months ago, and have kept meaning to post it here (if indeed I have not already). The problem with unofficial fixes is that it is another moving part to update, keep track of, and adds to installation complexity. I have lost previous fixes twice (due to fresh re-installs).

Essentially "fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileName);" was the culprit.

I changed the "_writerFileName" directive from using the above variable to:

_writerFileName = "fileName + "_" + simioScenarioName + "_Rep" + simioReplicationNumber + fileExtension;"

I could do something neater (as the current output will have a ".csv" in the middle of the name), but did not spend any time on this. It would be appreciated if this was fixed and applied to the official write block (even if as a toggleable option), as due to the over-zealous licensing terms, the DLL will not load on an unlicensed client... meaning I have to choose between having the bug fixed and not dumping hundreds of thousands of CSV files in my simulation root... or causing clients considerable inconvenience by writing hundreds of thousands of CSV files into their simulation root.

Here is the relevant code extract in the file element:

Code: Select all

            if (String.IsNullOrEmpty(fileName) == false)
            {
                string fileRoot = null;
                string fileDirectoryName = null;
                string fileNameWithoutExtension = null;
                string fileExtension = null;

                try
                {
                    fileRoot = System.IO.Path.GetPathRoot(fileName);
                    fileDirectoryName = System.IO.Path.GetDirectoryName(fileName);
                    fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileName);
                    fileExtension = System.IO.Path.GetExtension(fileName);
                }
                catch (ArgumentException e)
                {
                    data.ExecutionContext.ExecutionInformation.ReportError(String.Format("Failed to create runtime file element. Message: {0}", e.Message));
                }

                string simioProjectFolder = _data.ExecutionContext.ExecutionInformation.ProjectFolder;
                string simioExperimentName = _data.ExecutionContext.ExecutionInformation.ExperimentName;
                string simioScenarioName = _data.ExecutionContext.ExecutionInformation.ScenarioName;
                string simioReplicationNumber = _data.ExecutionContext.ExecutionInformation.ReplicationNumber.ToString();

                if (String.IsNullOrEmpty(fileDirectoryName) || String.IsNullOrEmpty(fileRoot))
                {
                    fileDirectoryName = simioProjectFolder;
                    fileName = fileDirectoryName + "\\" + fileName;
                }

                _readerFileName = fileName;

                if (String.IsNullOrEmpty(simioExperimentName))
                    _writerFileName = fileName;
                else
                    _writerFileName = fileName + "_" + simioScenarioName + "_Rep" + simioReplicationNumber + fileExtension;
            }
Using relative file paths worked at one stage, and was later broken. Below are two threads with work around un-offical dlls that probably implement the fix nicer.

10/07/2012 - http://www.simio.com/forums/viewtopic.php?f=19&t=829
07/12/2012 - http://www.simio.com/forums/viewtopic.php?f=20&t=987
Attachments
TextFileReadWrite_source.zip
(59.39 KiB) Downloaded 492 times
TextFileReadWrite_compiled.zip
(6.11 KiB) Downloaded 465 times
James Doran
Resident Problem Synthesiser

gtwirth
Simio Team Member
Posts: 156
Joined: Mon Jun 09, 2008 4:42 pm

Re: Fixed write block

Post by gtwirth » Thu Jan 09, 2014 2:25 pm

Thanks for the feedback. The relative paths on experiments will be fixed the next sprint release (Sprint 98). The ExcelConnectElement.cs for the Excel Write step had the same issue. It will be fixed as well.
Glen Wirth
Simio LLC

jdoran
Posts: 700
Joined: Tue Dec 06, 2011 6:47 am
Location: Brisbane, QLD

Re: Fixed write block

Post by jdoran » Thu Jan 09, 2014 4:29 pm

Great!
James Doran
Resident Problem Synthesiser

jzhou
Simio Insider
Posts: 291
Joined: Mon Aug 03, 2009 12:01 am
Location: China
Contact:

Re: Fixed write block

Post by jzhou » Thu Jan 09, 2014 10:14 pm

It's great. it save us a lot of time to assign long path name
Xunhe----www.simio-china.com

rgingalls
Posts: 8
Joined: Wed Dec 10, 2008 10:38 pm
Contact:

Re: Fixed write block

Post by rgingalls » Mon Jun 13, 2016 3:36 pm

What if I wanted each run to overwrite the output file? What it is doing now is writing output.csv file to:
output_Scenario1_Rep1.csv

What if I actually wanted to write to the output.csv file?

Thanks - Ricki.
Ricki Ingalls
Diamond Head Associates

Post Reply