0

I am compiling a Fortran code using F77 (I tried with gfortran as well); however, I got some compiling errors as below:

Code:

c  ** write 'ass.ini' file **

    open(17,file=inifile,status='unknown')

    write(17,1001) ext1

    write(17,1002) ext2

    close(17)

1001    format('\'.',a1,'\'             ext1')

1002    format('\'.',a1,'\'             ext2')

Compiling errors:

 1001 format('\'.',a1,'\'             ext1')
                 1

Error: Unexpected element ‘.’ in format string at (1)

 1002 format('\'.',a1,'\'             ext2')
                 1

Error: Unexpected element ‘.’ in format string at (1)

  write(17,1001) ext1
                   1

Error: FORMAT label 1001 at (1) not defined

  write(17,1002) ext2
                   1

Error: FORMAT label 1002 at (1) not defined

I tried with advance="no" but could not fix. I am new to Fortran, I would like to get some suggestions to fix this error please. Many thanks!

Vladimir F
  • 50,383
  • 4
  • 60
  • 96
Han
  • 1
  • 1
  • Looks like you're trying to use an extension where the backslash character is intended to escape the apostrophe character. Read the gfortran documentation. There an option named `-fbackslash` that gives what you likely want. – steve Jan 29 '21 at 21:55
  • And if you want a literal (single) quote you have [other options](https://stackoverflow.com/q/30997887/3157076) beyond escaping. – francescalus Jan 29 '21 at 22:27
  • @francescalus Thanks for the suggestion. I have tried to do that and it seems I can compile the code but the output file is: line 1: \..\ ext1; line 2: \..\ ext2 and what I want is: line 1: '.e' ext1 and line 2: '.n' ext2 . Could you please check if I have done the right thing as you suggested: 1001 format('\.',a1,'\ ext1') 1002 format('\.',a1,'\ ext2') – Han Jan 29 '21 at 22:41
  • @steve Thank you Steve. I am looking into that. – Han Jan 29 '21 at 22:42
  • You want `format("'.",a1,"'....")`. – francescalus Jan 29 '21 at 22:47
  • @francescalus Thank you soooo much! – Han Jan 29 '21 at 22:53
  • Please do not add any `[Solved]` to question titles. We have other options here (see the [tour]). – Vladimir F Jan 30 '21 at 09:10

0 Answers0