Equivalent of the C++ \n with fortran

Equivalent of the C++ \n with fortran

I'm trying to read an ASCII file with MPI_FILE_READ. I found out that I need first of all to read the entire file and put it on a character string.

The problem is that I didn't found how to split this string on a lines because I don't know how to detect a new line in a character string with fortran.

In some way I'm searching the equivalent of this C++ code in Fortran :

nlines = 0;
for (int i=0; i<file_size;i++)
     if (data[i] == '\n') (*nlines)++;




4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You can use the char function char(10) is linefeed LF and char(13) is carriage return CR

Thanks a lot for the answer. It works with CHAR(10).  

If you are a little paranoid, ACHAR(10) is better - this is a little more robust to the default character kind not being ascii.  The NEW_LINE standard intrinsic is even more robust.

There's also the C_NEW_LINE and C_CARRIAGE_RETURN constants from the ISO_C_BINDING module for kind C_CHAR characters.

Leave a Comment

Please sign in to add a comment. Not a member? Join today