Silverfrost Forums

Welcome to our forums

formatted output file

12 May 2014 1:44 #14071

I have created a formatted output file using FTN95, and can read the file perfectly in Plato, Excel, and WordPad, but it looks completely garbled in NotePad. If I create the same file using a different compiler the problem does not occur.

I am perfectly happy to make the output file available if somebody could let me know how to do so. Unfortunately, providing some complete sample code for the output to reproduce the problem would be difficult, but it works something like the following:

  WRITE (UNIT=iout,FMT='(A)',ADVANCE='no') TRIM(c)
  DO j=1,m
     WRITE (cout,FMT=*) r(j)
     WRITE (UNIT=iout,FMT='(2A)',ADVANCE='no') c,TRIM(ADJUSTL(cout))
  END DO
  WRITE (UNIT=iout,FMT='(A)',ADVANCE='yes')
  ij=0
  DO i=1,n
     WRITE (cout,FMT=*) s(i)
     WRITE (UNIT=iout,FMT='(A)',ADVANCE='no') TRIM(ADJUSTL(cout))
     DO j=1,m
           ij=ij+1
        WRITE (cout,FMT=*) v(ij)
        WRITE (UNIT=iout,FMT='(2A)',ADVANCE='no') cdelim,TRIM(ADJUSTL(cout))
     END DO
     WRITE (UNIT=iout,FMT='(A)',ADVANCE='yes')
  END DO

The code above is part of a subroutine, and c is is passed as a CHARACTER(LEN=*) argument, m and n as INTEGER, and r,s and v as REAL arrays. The subroutine and is called more than once when generating the output file. The problem occurs only sometimes, apparently depending on the value of c. If I abort the program part way through printing the file the partial file looks ok until the second call to the routine when line 6 above is invoked.

12 May 2014 5:21 #14072

Notepad needs a CR+LF at the end of each line, whereas Wordpad and the editor in Plato can get by with LF.

One thing I note in your code, is that the WRITE you are doing to turn ADVANCE back on isn't correct as there isn't any data to match the A format descriptor.

I would have used:

WRITE(UNIT=iout, FMT='()', ADVANCE='yes')

An empty format descriptor is valid Fortran.

12 May 2014 6:15 #14073

Thanks David, Usually if Notepad does not have the correct end-of-line character it just wraps everything into a single line. The file then becomes difficult to read, but not what I see now - Chinese and other special characters. It almost looks as if the file is binary, but there are no complaints from NotePad when the file is opened.

13 May 2014 6:10 #14076

Plato can also read UNICODE/UTF8 files and maybe Notepad cannot do this.

This key in the end will be to look at the binary. You can do this from Plato provided that you use the Open on the File menu and not the toolbar button. Then you get a check box to select in order to display the binary.

13 May 2014 6:32 #14077

Thanks for the suggestion, Paul. I see how to open the file in binary as you indicated. The first few lines look as follows:

      0:  31393731  2D30362F  30390932  38362E30  1971-06/09¸286.0
     10:  30303030  30303030  09323838  2E303030  00000000¸288.000
     20:  30303030  30300932  39302E30  30303030  000000¸290.00000
     30:  30303030  09323932  2E303030  30303030  0000¸292.0000000
     40:  30300932  39342E30  30303030  30303030  00¸294.000000000
     50:  200D0A32  342E3030  30303030  30303030   ¸¸24.0000000000

Some of this is recognisable: the '1971-06/09', for example, is the first character string I printed in line 1, and the numbers 286, 288 ... do follow.

In Plato, Excel etc, the data look like this:

1971-06/09	286.000000000	288.000000000	290.000000000	292.000000000	294.000000000 
24.0000000000	28.3700000000	28.2825000000	28.2625000000	28.2200000000	28.1400000000 
22.0000000000	28.4475000000	28.2850000000	28.1950000000	28.1450000000	28.0750000000 
20.0000000000	28.4925000000	28.2775000000	28.1375000000	28.1100000000	28.0725000000 
18.0000000000	28.3275000000	28.1950000000	28.0875000000	28.0950000000	28.1025000000 
16.0000000000	27.9625000000	27.9375000000	27.9525000000	28.0350000000	28.0925000000 

In NotePad, the data look like this:

㤱ㄷ〭⼶㤰㈉㘸〮〰〰〰〰㈉㠸〮〰〰〰〰㈉〹〮〰〰〰〰㈉㈹〮〰〰〰〰㈉㐹〮〰

I did open the output file as a formatted file, and an INQUIRE on the file confirms that.

13 May 2014 11:43 #14080

The first line of the binary looks fine so there must be something else going on. Are you sure that you are opening the same file in Notepad?

14 May 2014 5:30 #14082

Quoted from simon

In NotePad, the data look like this:

㤱ㄷ〭⼶㤰㈉㘸〮〰〰〰〰㈉㠸〮〰〰〰〰㈉〹〮〰〰〰〰㈉㈹〮〰〰〰〰㈉㐹〮〰

To me, it looks like the Notepad assumes your text file as Unicode text. Notepad uses IsTextUnicode() winapi function to determine if buffer is likely to contain a form of Unicode text.

I wrote you a small program to test, if this is the case.

Paul,

Would it be better to separate bytes in binary view with one blank and groups of four bytes with two blanks? I think it would make it easier to visualize data.

I currently use this output style with my hexdump utility:

00000000: 6D 6F 64 75  6C 65 20 65  69 6E 67 61  62 65 6E 5F | module eingaben_
00000010: 6D 6F 64 75  6C 20 0D 0A  20 69 6E 74  65 67 65 72 | modul .. integer
00000020: 2A 34 20 73  65 6C 31 2C  69 63 6F 6C  20 0D 0A 20 | *4 sel1,icol .. 
00000030: 63 68 61 72  61 63 74 65  72 20 63 62  65 7A 31 28 | character cbez1(
00000040: 33 29 2C 63  69 6E 70 75  74 31 2A 31  30 2C 63 69 | 3),cinput1*10,ci
00000050: 6E 70 75 74  32 2A 31 30  20 0D 0A 20  69 6E 74 65 | nput2*10 .. inte
14 May 2014 6:06 #14083

Thanks for the suggestion.

14 May 2014 7:13 #14084

Thank you all for the assistance.

I have double-checked and am 100% certain that I am looking at the same file. But I did only copy a small portion of what is viewed in NotePad because everything is on a single line. Here is a bit more, if that helps:

㤱ㄷ〭⼶㤰㈉㘸〮〰〰〰〰㈉㠸〮〰〰〰〰㈉〹〮〰〰〰〰㈉㈹〮〰〰〰〰㈉㐹〮〰〰〰〰ഠ㈊⸴〰〰〰〰〰㈉⸸㜳〰〰〰〰㈉⸸㠲㔲〰〰〰㈉⸸㘲㔲〰〰〰㈉⸸㈲〰〰〰〰㈉⸸㐱〰〰〰〰ഠ㈊⸲〰〰〰〰〰㈉⸸㐴㔷〰〰〰㈉⸸㠲〵〰〰〰㈉⸸㤱〵〰〰〰㈉⸸㐱〵〰〰〰㈉⸸㜰〵〰〰〰ഠ㈊⸰〰〰〰〰〰㈉⸸㤴㔲〰〰〰㈉⸸㜲㔷〰〰〰㈉⸸㌱㔷〰〰〰㈉⸸ㄱ〰〰〰〰㈉⸸㜰㔲〰〰〰ഠㄊ⸸〰〰〰〰〰㈉⸸㈳㔷〰〰〰㈉⸸㤱〵

When I run Jalih's program it says:

'Text file is probably Unicode.'

14 May 2014 8:01 #14085

See http://blogs.msdn.com/b/oldnewthing/archive/2007/04/17/2158334.aspx

14 May 2014 9:32 #14086

Thanks Paul.

If I read the file into WordPad, it reads ok. If I then save it as:

Text Document - Notepad does NOT display the data properly MS-DOS Format - Notepad does NOT display the data properly Unicode Text Document - Notepad does display the data properly

I think I can justifiably treat this as a Notepad problem then.

Please login to reply.