0

I am trying to use FileHelper to read a csv file, in which data are arranged like this: 0,0,0,0,0,0,0,1,1,1,0,0,0,0,...... 1kX1k of them. Here is my FileHelper code:

[DelimitedRecord(",")] 
    public class ROIMaskCSV 
    { 
        public int value;

        //[TransformToRecord(typeof(ROIMaskCSV[]))]
        public static ROIMaskCSV[] loadMask(string fileName)
        {

            DelimitedFileEngine engine = new DelimitedFileEngine(typeof(ROIMaskCSV));

            ROIMaskCSV[] mask = (ROIMaskCSV[])engine.ReadFile(fileName); 

           // mask[0].value = this.value;

            return mask;
        }
    }

And here is where FileHelper loadMask() function gets called:

public class TIFFIImageIO
{
    public static int LoadTIFF(string fileName, int x, int y)
    {

        ROIMaskCSV[] mask = ROIMaskCSV.loadMask("d:\\myMask.csv");
        ......

I stepped in, so when program gets:

 ROIMaskCSV[] mask = (ROIMaskCSV[])engine.ReadFile(fileName); 

the program is just freezed. I am not sure what happened. Something I did wrong? Anyone can give some pointers? Any suggestion is appreciated.

Nick Tsui
  • 524
  • 2
  • 9
  • 29
  • How much time did you give it? Is it possible it's just slow? – Jonathan Wood Feb 20 '13 at 16:04
  • I would say on mins. It does not look right to me..... – Nick Tsui Feb 20 '13 at 16:05
  • Is the program still using CPU? – Ann L. Feb 20 '13 at 16:12
  • have you tried writing code that reads and Splits the code without using FileHelper..? – MethodMan Feb 20 '13 at 16:19
  • @AnnL. I actually think it is not using CPU. I open task manager, and the program is not on top that consumes much CPU resources. – Nick Tsui Feb 20 '13 at 16:20
  • @DJKRAZE: Because I have seen good review of FileHelper, so I think it is worth trying to see how it performs. – Nick Tsui Feb 20 '13 at 16:20
  • Well based on what you are stating doesn't seem like it's `performing` quite so well.. perhaps you are implementing it incorrectly as well – MethodMan Feb 20 '13 at 16:23
  • @DJKRAZE: Yeah, so I need to know which one, poor performance or my bad (probably my bad). That is why I posted my code here hoping someone gives some hint. This is the first time I am using FileHelper. – Nick Tsui Feb 20 '13 at 16:27
  • have you looked at any of their links or support links [FileHelpers library](http://filehelpers.sourceforge.net/) [FileHelpers Example of how to use](http://filehelpers.sourceforge.net/) – MethodMan Feb 20 '13 at 16:30
  • Yes, I went to their website, and basically followed their tutorail of delimited data reading. My code is based on their example. However, I now have a problem. – Nick Tsui Feb 20 '13 at 16:31
  • perhaps there is an issue in your data.. like multiple commas in a string can you show what the file looks like..? if not try to create a sample file that has 2 to 3 lines test that and see if you are experiencing the same Performance Issue..? – MethodMan Feb 20 '13 at 16:36
  • @DJKRAZE: Does that mean my code looks fine? – Nick Tsui Feb 20 '13 at 16:47
  • Only you would know that.. since you are working from an example I would guess and say yes.. but that's something that you would only know.. – MethodMan Feb 20 '13 at 16:52
  • OK. I give up. I will just stream read the file, then parse it. – Nick Tsui Feb 20 '13 at 17:25

1 Answers1

2

OK. I give up. I will just stream read the file, then parse it. This is the code I read my csv file:

byte[] array = System.IO.File.ReadAllBytes(fileName);

Then convert array[i] to char/int, or whatever type you want.

To char, for example to convert ASC II 65 to 'A':

char.ConvertFromUtf32(65);

To int, for example to convert ASC II 48 to 0:

Convert.ToInt32(char.ConvertFromUtf32(48));
Nick Tsui
  • 524
  • 2
  • 9
  • 29