This question already has answers here:
Double Negation in C++
(14 answers)
Closed 2 years ago.
Came across using !! in C++ during condition check
if ( !! (flag != 0 )){..
}
This could be directly used like
if( flag != 0 ){..
}
Is there any specific corner use case in C/C++ or is it just a form of coding style ?
In this case, it's superfluous, but in general this style is used to convert the actual expression value to
an integer type in C.
a boolean type in C++.
This question already has answers here:
Format string for output dependent on a variable
(4 answers)
Closed 2 years ago.
I am trying to understand "variable dependent formatting", specifically where the repeat count in FORTRAN format statement is a variable instead of a fixed number. I have gone through one of the similar questions here, where this is addressed by defining a format variable. I have tried to implement a similar type of test code but I get a run-time error saying "Fortran runtime error: Missing initial left parenthesis in format". I am attaching the code that I have. Could you please let me know where I am going wrong.
Thank you
program main
implicit none
integer num,i
real,dimension(:),allocatable :: logar
character(len = 100) fmt
print*, "enter any number"
read*,num
allocate(logar(num))
do i = 1,num
logar(i) = log(i/3.14)
end do
open(unit=200,file="num.txt",status="unknown")
write(fmt,'( I4,"(f10.5)" )') num
print*,fmt
write(200,fmt) (logar(i),i=1,num)
end program
Change
write(fmt,'( I4,"(f10.5)" )') num
to
write(fmt,'(a, I4,"(f10.5)",a )') '(', num, ')'
Else, you are missing the parenthesis in fmt. Formats strings are delimited by parentheses.
This question already has answers here:
What is * in FORTRAN 77
(1 answer)
How can a scalar be passed to a vector (1D array) to a Fortran subroutine?
(2 answers)
Closed 3 years ago.
I have some problem with scipy.interpolate.splrep, so I have no choice by to dig into some very old Fortran77 code.
And one thing I can not understand is here:
https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack/curfit.f#L257
it calls a subroutine fpcurf
call fpcurf(iopt,x,y,w,m,xb,xe,k,s,nest,tol,maxit,k1,k2,n,t,c,fp,
* wrk(ifp),wrk(iz),wrk(ia),wrk(ib),wrk(ig),wrk(iq),iwrk,ier)
where the wrk is one dimension array
and the signature of fpcurf is
subroutine fpcurf(iopt,x,y,w,m,xb,xe,k,s,nest,tol,maxit,k1,k2,
* n,t,c,fp,fpint,z,a,b,g,q,nrdata,ier)
c ..
c ..scalar arguments..
real*8 xb,xe,s,tol,fp
integer iopt,m,k,nest,maxit,k1,k2,n,ier
c ..array arguments..
real*8 x(m),y(m),w(m),t(nest),c(nest),fpint(nest),
* z(nest),a(nest,k1),b(nest,k2),g(nest,k2),q(m,k1)
integer nrdata(nest)
you can find it at https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack/fpcurf.f
And obviously the signature doesn't match (since wrk is array, and wrk[xxx] is a scalar). Can anyone explain why? I noticed that there is a asterisk (*) here, does it mean anything special?
Maybe anyone familiar with Fortran could please take a look at this function and figure out why the call doesn't match the subroutine signature?
This question already has answers here:
Strange label usage for an IF condition in a DO loop [duplicate]
(2 answers)
Closed 9 years ago.
I have a question about some code I'm looking at written in Fortran. The section of the code I'm confused about is written below.
DO 40 LL=1,N
DO 40 I=1,N-1,2
IF((LL-I)*(LL-I-1)*(LL-I*2)*(LL-I+N-2)) 22,21,22
NODO=LL-I+1
IF((LL.EQ.1) .AND. (I.EQ.N-1)) NODO=NODO+N
I don't understand the condition for the first IF statement. It just looks like numbers are being multiplied together but that number isn't checked against anything. Then 3 line numbers are written after the IF statement. Do anyone know what this IF statement is doing? The last IF statement makes sense as a condition is actually being checked. Thanks.
The line
IF((LL-I)*(LL-I-1)*(LL-I*2)*(LL-I+N-2)) 22,21,22
is an arithmetic if statement, which is certainly obsolescent (the Fortran standard term for deprecated) and may even have been removed in the latest language standard(s). If the condition evaluates to a negative number program control branches to the line with the first label (ie 22), if it evaluates to 0 to the second label (21), if to a positive value to the third label (22). As you see the three labels need not all be different.
This question already has an answer here:
what does DATA TKX/2HKX/ mean in fortran?
(1 answer)
Closed 1 year ago.
Does anyone know the meaning of 4HEND in the following line which comes from an old Fortran code?
DATA XHEND / 4HEND /
4HEND is a Hollerith code to represent the character string "END ". In very old FORTRAN, the variable XHEND might even be a 4-byte integer or real used to hold character data. If implicit typing was in effect in this program, XHEND would have been a real. Another recent question with Hollerith codes: Writing both characters and digits in an array
It replaces assignment
XHEND='END '