Line endings using fprintf

Hello Everyone:

First, I am using IGOR Pro 8.04 on an Intel Mac running 11.5.2.

In a procedure, I read and modify a text file and then write it line by line to a new file using:

do
   FReadLine tmpFile, line
   ...
   fprintf inFile, "%s", line
while (1)

 

When a unix program reads this text file, it complains there are Windows(DOS) line endings in it.

So, I have tried things like:

        last = strlen(line)
        line[last] = "\n"

but with no success.

This is probably very elementary, but I haven't been able to figure it out.  

Thanks for the help,

  Joe


 

Most likely the <CR><LF> windows-style line endings were read from the file and are present in your string variable "line".

You might be able to use

line = RemoveLineEnding(line, "\r\n")
line += "\n"

Note that I have not tested this!

Or perhaps

line = ReplaceString("\r\n", line, "\n")

 

Thanks John:

I've tried both your suggestions but with no success.  First, I checked the original text file and it has the proper unix style endings and can be used as an input file to the program I am trying to run.

When I used ReplaceString, it apparently did nothing.  If I just use that, it writes all the lines as one very long line when I open it with the Atom editor. 

If I use line += "\n", the lines display properly but it still shows that the line endings are CRLF.

I was unable to find RemoveLineEnding.  Is it in one of the procedure folders?

 

To make this easier, I've attached both my procedure file and the input file that gets processed.  The command I use for testing is:

RunTests("PH", "TAMU", 0.3)

Note that I had to change the extension of the input file from"tmp" to "txt" in order to upload it here.

Thanks again for the help,

  Joe Kelly

The Details section for FReadLine says that, if you omit /T, it returns CR as terminator. So you need to do this:

line = ReplaceString("\r", line, "\n")

 

Hi Joe,

First, John probably meant

line = RemoveEnding(line, "\r\n")
line += "\n"

but I am not sure this will help you. Looking at your test file I see that all lines are terminated with just a linefeed ("\n"). But somehow your code seems to sneak in a carriage return ("\r") in somewhere. Looking at your script I don't see where this happens. To make sure you do not accidentally write a CR, you could do this:

line = ReplaceString("\r", line, "")

This will just delete all carriage returns before writing the line.

EDIT: OK, Howard got the right answer here!

In reply to by hrodstein

Thanks Howard!  The problem was not setting  /T=(num2char(10)).  Using that worked great.

Ironically, the 

line = ReplaceString("\r", line, "\n")

 

was one of the first things I tried, and for some reason it didn't work.

Thanks again for the great support,

   Joe