Does anybody know how to use Doxygen to document Fortran code in which a character array is assigned a string that terminates in a backslash. I tried it with the following code with Doxygen version 1.6.1 :
program test
character(80) :: test_char
test_char = '\\test\test\'
stop
end program test
and got the error: "Error in file test.f90 line: 9, state: 20"
This is likely a doxygen 1.6.1 bug (doxygen commands could start with backslash and \' is probably wrongly parsed).
The latest version of doxygen is 1.8.7, so first step is to update and try with that.
In case it does not help, you can use custom FILTER to remove backslash characters from strings in your code.
Thanks everyone. I ended up using the following solution:
program test
character(80) :: test_char
character(2) :: bckslsh = '\\'
test_char = '\\test\test'//bckslsh(1:1)
stop
end program test
Related
As shown in the following code that I use to practice fixed-form Fortran (because the code I am trying to learn is fixed form Fortran), the 4th format statement and the reading from file 1 are newly added. The code worked as expected prior to adding these statements, but now the intel ifort compiler with no additional flags will not compile the 4th format statement and returns the following error:
fortPractice.for(18): error #5082: Syntax error, found FORMAT_ELEMENT 'format' when expecting one of: <END-OF-STATEMENT> ;
4 format(i6,2x)
--------------^
fortPractice.for(26): error #6052: This label has not been defined as a FORMAT label.
write(2,3)
----------------------------------^
The code is:
c This is a script for practicing Fortran codes
program fortPractice
implicit none
integer :: x(0:5),y(2:7)
integer :: nph(1:6)
real :: z(4:9)
integer :: i
OPEN(unit=1,file='test.txt',status='old')
read(1,*) nph
close(unit=1)
open(unit = 2, file = 'output.txt')
2 format(i3,2x,i3,2x,2e11.2)
3 format(1x,78('*'))
4 format(i6,2x)
do i = 0,5
x(i) = i;
y(i+2) = i+2;
z(i+4) = x(i)**2 + y(i+2)**2
z(i+4) = sqrt(z(i+4)) + 10000
write(2,2) x(i),y(i+2),z(i+4)
write(2,3)
enddo
write(2,*) nph
close(unit = 2)
endprogram fortPractice
Output is a file created by the program. test.txt contains just a row of numbers: 1 2 3 4 5 6
When I comment or remove the 4th format statement then the code compiles and runs as expected. As I am just learning how fixed form Fortran works, I am just interested in why the 4th format statement won't compile.
Edit:
I have replaced all the tabs with spaces, and the program with some more modification shown below can now compile, but the program does not produce the output file, likely encountered some run-time error:
Edit 2:
Nevermind, I forgot to change the file identifiers.
Thanks everyone!
Now we have enough information to solve the problem. In the troublesome source line, the label 4 is preceded by a tab. Tabs in Fortran source are not standard, but Intel Fortran (and many other compilers) support something called "tab source form". The way it works in ifort is as follows:
If the line starts with a tab and then a nonzero digit, the digit is treated as if it were in column 6
If the line starts with a tab and then some other character, then the character is treated as if it were in column 7
If the line starts with a numeric statement label and then a tab, the next character is treated as if it were in column 7
Otherwise, a tab is treated as a blank (this last varies among compilers)
In your case, a tab preceded the 4 so it was taken to be a continuation of the previous line, resulting in an error. Either don't use tabs, or understand how the compiler treats them. Editors that automatically insert tabs will just give you trouble.
I'm trying to write a string filename in fortran using:
WRITE(FILENAME,'(A27,I3.3,A1,I3.3,A3)') NAME,MYPR,'_',IBL,'.nc'
where NAME is a string of variable lengths, and MYPR and IBL are integers.
I'm searching for a solution where I can dynamically write the format:
'(A27,I3.3,A1,I3.3,A3)',
where A27 will change depending on the length of NAME. I've tried 'A' alone but this caused an error. I'm not sure of what is possible here as many texts do not even cover something similar issues.
Would appreciate some ideas.
The obvious solution would be to use the format string '(A,I3.3,A1,I3.3,A3)', i.e. using just A for the name and letting the compiler choose the correct length. This is working perfectly for me.
As #agentp suggested, you might see issues due to whitespaces in the string. This might be resolved by using trim(name) to get rid of trailing whitespace, or even trim(adjustl(name)) which removes both leading and trailing whitespace. This solution is given below in subroutine print1().
The other option would be to generate the format string dynamically - after all, that is just a string as well. This is quite cumbersome, and an overkill in your situation - see print2().
module test_mod
implicit none
contains
subroutine print1(NAME,MYPR,IBL)
character(len=*),intent(in) :: NAME
integer,intent(in) :: MYPR,IBL
WRITE(*,'(A,I3.3,A1,I3.3,A3)') trim(adjustl(NAME)),MYPR,'_',IBL,'.nc'
end subroutine
subroutine print2(NAME,MYPR,IBL)
character(len=*),intent(in) :: NAME
integer,intent(in) :: MYPR,IBL
character(len=128) :: fmt
write(fmt,*) len_trim(adjustl(NAME))
fmt = '(A'//trim(adjustl(fmt))//',I3.3,A1,I3.3,A3)'
WRITE(*,fmt) trim(adjustl(NAME)),MYPR,'_',IBL,'.nc'
end subroutine
end module
program test
use test_mod
call print1(' Testfile ', 1, 2)
call print2(' Testfile ', 1, 2)
end program
Output:
./a.out
Testfile001_002.nc
Testfile001_002.nc
I got this error while building:
dist/package.conf.inplace:
inappropriate type
FAILED DURING THE BUILDING PHASE. The **exception** was: ExitFailure 1
How do I use subRegex in package Text.Regex?
I have written:
import Text.Regex.Posix
But I got this error:
_.hs:13:5: Not in scope: ‘subRegex’
_.hs:13:15:
Not in scope: ‘mkRegex’
Perhaps you meant ‘makeRegex’ (imported from Text.Regex.Posix)
So, I went to Text.Regex's [page][1], and there it said:
Uses the POSIX regular expression interface in Text.Regex.Posix.
So why not aren't these functions in-scope?
Here are some steps you can perform to make it working.
Download from http://hackage.haskell.org/package/regex-compat-0.92, unzip to <Haskell Platform INSTALL FOLDER>\2014.2.0.0\lib\
Run Haskell.
Type :mod +Text.Regex to load the package.
Type, e.g. subRegex (mkRegex "[0-9]+") "foobar567" "123"
Result is "foobar123" (after all packages are loaded).
Here is the subRegex description:
:: Regex Search pattern
-> String Input string
-> String Replacement text
-> String Output string
Replaces every occurance of the given regexp with the replacement
string.
In the replacement string, "\1" refers to the first substring; "\2" to
the second, etc; and "\0" to the entire match. "\\" will insert a
literal backslash.
This does not advance if the regex matches an empty string. This
misfeature is here to match the behavior of the the original
Text.Regex API.
Some cool links that can help you delve deeper:
http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutorial/, and
https://wiki.haskell.org/Cookbook/Pattern_matching.
I am using it in Windows, here is my screen:
You shouldn't import Text.Regex.Posix, but rather just Text.Regex, because the two functions you want are there.
Have a look at the Hackage page - you were almost there, but the functions where actually in that file.
I have a Fortran program in which I use a format staement for writing like
WRITE (12,'(A72,1X,A,1X,I6.6)') ALINE,SFFIX(1:NUM),LINENO
which works fine. However when I write a character string `fmtt' like
WRITE (fmtt,'(a)') trim(adjustl(sttr(2)))
where string 'sttr (2)is '(A72,1X,A,1X,I6.6) ' ` , which I confirm by printing fmtt like
WRITE(*,'(a)')fmtt
When I use string fmtt as format in a write statement like
WRITE (12, fmtt) ALINE,SFFIX(1:NUM),LINENO
I get error message
forrtl : info(58) format syntax error at or near '(A72,1X,A,1X,I6.6) '
Though I am not an expert I expected it to work as format is supposed to be a character string. Where am I wrong? I wanted to do this to make format dependent on user input. Thanking you.
Probably the single quotation marks ' ' are making problem. Following code is working fine.
implicit none
character(len=30) :: fmtt
fmtt = '(A72,1X,A,1X,I6.6)'
write(*,fmtt)"first_character","second_character",230
stop
end
Note that print*,fmtt give the output without single quotes. I follow the method given in http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html . Hopefully this will help you.
I have a problem when using string.
This is my C++ code:
string s;
s = "..\inputs\Meknes_ext1\REF_WV02_12SEP15_ext1";
The compilation was successfully done, but when debugging, the string s takes random values like "hûJ" at the first line and then the affectation don't change his content.
How can I resolve this error?
You need to escape the escape character \, change this to \\:
s = "..\\inputs\\Meknes_ext1\\REF_WV02_12SEP15_ext1";
you need to escape the \ special character. Your string must be like that:
s = "..\\inputs\\Meknes_ext1\\REF_WV02_12SEP15_ext1";
I find out that this problem occur only when debugging, in the execution, the string takes the right value, note that I'm using the RelWithDebInfo mode. the explanation of this was find in: Visual Studio: Garbled debug watch of std::string's?