Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple smaller Issues at the conversion #1

Open
alexanderwendt opened this issue Sep 3, 2018 · 0 comments
Open

Multiple smaller Issues at the conversion #1

alexanderwendt opened this issue Sep 3, 2018 · 0 comments

Comments

@alexanderwendt
Copy link

Multiple smaller issues were found at the conversion of *.dfq-files:

  1. Sometimes there are double empty lines in the dfq files.
  2. At the end of file, there has to be two empty lines to cover the measurement data
  3. In all my dfq-files, there were no separation between the K10*-addresses and the K20*-addresses. The separation of line blocks has to be made by comparing the previous value with a string match.

I fixed the issues in the code below. You might integrate this solution if you want to.

public void Convert(string dfqFilePath)
{
if (string.IsNullOrEmpty(dfqFilePath))
throw new ArgumentException("dfqFilePath");

		Parts = new List<Part>();
		Characteristics = new List<Characteristic>();
		_currentPart = null;

		var dfqFile = File.ReadAllLines(dfqFilePath);
        var sectionBlock = new List<List<string>>();
		var lineBlock = new List<string>();
        

        Boolean addToLineblock = false;
        int counter = 1;

        //Create Blocks from file, then process the blocks
        for (int i=0; i<dfqFile.Length; i++)
        {
            String previousLine = "";
            String currentLine = dfqFile[i];
            String nextLine = "";

            if (i>0)
            {
                previousLine = dfqFile[i - 1];
            } 

            if (i<dfqFile.Length-1)
            {
                nextLine = dfqFile[i + 1];
            }


            //Set the separator
            //1. Empty lines
            //2. K10* to K20 if there is no line break

            //Create lineblock
            //Console.WriteLine("Create text blocks.");
            //=== Special text splitter ===//
            //Check if there is a special splitter
            Boolean textSplitActiveStart = false;
            if (previousLine.StartsWith("K10") && currentLine.StartsWith("K20"))
            {
                textSplitActiveStart = true;
                Console.WriteLine("Special text split start K10*->K20*");
            }

            //====================================//

            //Stop line block
            if (string.IsNullOrEmpty(currentLine) || textSplitActiveStart == true || string.IsNullOrEmpty(nextLine))
            {
                sectionBlock.Add(new List<String>(lineBlock));
                lineBlock.Clear();
                addToLineblock = false;
                Console.WriteLine("End line block at line: " + counter + ">" + currentLine);
            }


            //Start line block
            //Startpart is at start/run, previousline was empty or split K1*/K2 was active
            if (string.IsNullOrEmpty(currentLine)==false && (counter==1 || string.IsNullOrEmpty(previousLine)==true || textSplitActiveStart==true))
            {
                addToLineblock = true;
                Console.WriteLine("Start new lineblock at line: " + counter + ">" + currentLine);
            }

            //Add line if block is open
            if (addToLineblock==true)
            {
                lineBlock.Add(currentLine);
                Console.WriteLine("Added line to block. Line: " + counter + ">" + currentLine);
            }

            counter++;
        }

        Console.WriteLine("Created " + sectionBlock.Count() + " section blocks.");
        Console.WriteLine("Process each section block.");

        foreach (var block in sectionBlock)
        {
            if (block.Count()>0)
            {
                ProcessBlock(block);
            }
            
        }

        Console.WriteLine("Conversion finished");
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant