Error: Unclassifiable statement at (1) fortran - fortran

How could I fix the Unclassifiable statement error in the if () to go? The error is in
DO J=1,N
IF ( I .EQ. J )GO TO 3
Y=Y-A( I , J )*X( J )
3 END DO
program gausssiedel
INTEGER, PARAMETER :: M=100
INTEGER :: NMI, IJK , ITER, I , J
real , dimension (M,M) :: A
REAL,DIMENSION(M) :: B,X
WRITE(6 , * ) 'ECUACIONES DE ENTRADA. '
OPEN(2 ,FILE= 'datos . dat ' ,STATUS='OLD' )
READ(2 , * )N,NMI,NAPROX ! LEE DATOS DEL ARCHIVO DE ENTRADA
APROX=10.0**(-NAPROX)
DO I =1,N
READ( 2 , * ) (A( I , J ) , J=1,N) ,B( I )
WRITE( 6 , * ) (A( I , J ) , J=1,N) ,B( I )
END DO
CLOSE (2)
DO I =1,N
X( I ) = 0.0 ! PRIMERA APROXIMACION DE LA SOLUCION
END DO
WRITE(6 , * ) 'RESULTADOS'
WRITE( * , * ) ! IMPRIME RESULTADOS
DO ITER=1,NMI
WRITE( * , * )ITER , (X( J ) , J=1,N)
IJK = 0
DO I =1,N
Y=B( I )
DO J=1,N
IF ( I .EQ. J )GO TO 3
Y=Y-A( I , J )*X( J )
3 END DO
Y=Y/A( I , I )
IF (ABS( (X( I)-Y)/Y ) .GT.APROX) IJK=1
X( I ) = Y
END DO
IF ( IJK .EQ.0 )GO TO 6
END DO
WRITE( * , * ) 'NUMERO DE ITERACIONES: ' ,NMI
6 CONTINUE
pause
end program

What do you expect the do-loop to do? Are you just trying to skip the i == j value or exit the do-loop. You can achieve both without labeling the end do statement.
Skip the i == j case:
DO J=1,N
IF ( I .EQ. J ) cycle
Y=Y-A( I , J )*X( J )
END DO
Exit the loop case:
DO J=1,N
IF ( I .EQ. J ) exit
Y=Y-A( I , J )*X( J )
END DO

Related

BLAS tensor contractions for two indexes together

I want to calculate D[a,d] = A[a,b,c] * B[b,c,d].
Method I: reshape A[a,b,c] => C1[a,e], B[b,c,d] => C2[e,d], e = b*c
Method II: directly call dgemm. This is a run-time error.
" na, nb, nc, nd ?
2 3 5 7
Time for reshaping method 2.447600000000000E-002
Intel MKL ERROR: Parameter 10 was incorrect on entry to DGEMM .
Time for straight method 1.838800000000000E-002
Difference between result matrices 5.46978468774136 "
Question: Can we contract two indexes together by BLAS?
The following only works for one index.
How to speed up reshape in higher rank tensor contraction by BLAS in Fortran?
Program reshape_for_blas
Use, Intrinsic :: iso_fortran_env, Only : wp => real64, li => int64
Implicit None
Real( wp ), Dimension( :, :, : ), Allocatable :: a
Real( wp ), Dimension( :, :, : ), Allocatable :: b
Real( wp ), Dimension( :, : ), Allocatable :: c1, c2
Real( wp ), Dimension( :, : ), Allocatable :: d
Real( wp ), Dimension( :, : ), Allocatable :: e
Integer :: na, nb, nc, nd, ne
Integer( li ) :: start, finish, rate
Write( *, * ) 'na, nb, nc, nd ?'
Read( *, * ) na, nb, nc, nd
ne = nb * nc
Allocate( a ( 1:na, 1:nb, 1:nc ) )
Allocate( b ( 1:nb, 1:nc, 1:nd ) )
Allocate( c1( 1:na, 1:ne ) )
Allocate( c2( 1:ne, 1:nd ) )
Allocate( d ( 1:na, 1:nd ) )
Allocate( e ( 1:na, 1:nd ) )
! Set up some data
Call Random_number( a )
Call Random_number( b )
! With reshapes
Call System_clock( start, rate )
c1 = Reshape( a, Shape( c1 ) )
c2 = Reshape( b, Shape( c2 ) )
Call dgemm( 'N', 'N', na, nd, ne, 1.0_wp, c1, Size( c1, Dim = 1 ), &
c2, Size( c2, Dim = 1 ), &
0.0_wp, e, Size( e, Dim = 1 ) )
Call System_clock( finish, rate )
Write( *, * ) 'Time for reshaping method ', Real( finish - start, wp ) / rate
! Direct
Call System_clock( start, rate )
Call dgemm( 'N', 'N', na, nd, ne, 1.0_wp, a , Size( a , Dim = 1 ), &
b , Size( b , Dim = 1 ), &
0.0_wp, d, Size( d, Dim = 1 ) )
Call System_clock( finish, rate )
Write( *, * ) 'Time for straight method ', Real( finish - start, wp ) / rate
Write( *, * ) 'Difference between result matrices ', Maxval( Abs( d - e ) )
End Program reshape_for_blas

How to separate a string with a sign in the middle

I am working on a code that needs to get the two variables of a binomial expression. I want to know if there's a way to separate a string with a sign in the middle into two substrings.
e.g. (x+y)^3 to var1=x and var2=y or (qwerty-asdf)^12 to var1=qwerty and var2=asdf
I have tried doing this:
character(100) :: str, var
var=' '
do i=1,len(str)
if (((str(i:i) == "+") .or. (str(i:i) == "-")) .or. &
((str(i:i) >= "a") .and. (str(i:i) <= "z"))) &
var=trim(var)//trim(str(i:i))
end do
But the only characters that get removed are the parenthesis and the power.
Another way that I'm looking at my problem is that if I know what the string length where the signs are then I can do this:
character(100) :: str, var
var=' '
do i=1,len(the_unknown_string_length)
if ((str(i:i) >= "a") .and. (str(i:i) <= "z")) &
var=trim(var)//trim(str(i:i))
end do
Although, I also don't know how I could get the specific string length where the signs appear.
I wouldn't mess about with loops - I'd use the available intrinsic functions. Something like
ijb#ijb-Latitude-5410:~/work/stack$ cat binom.f90
Program binom
Implicit None
Character( Len = 100 ) :: expression
Character( Len = : ), Allocatable :: var1, var2
Write( *, '( a )' ) 'Expression?'
Read ( *, '( a )' ) expression
Call split_it( expression, var1, var2 )
If( Len( var1 ) /= 0 .And. Len( var2 ) /= 0 ) Then
Write( *, '( a, a, t20, i0 )' ) 'Var1 = ', var1, Len( var1 )
Write( *, '( a, a, t20, i0 )' ) 'Var2 = ', var2, Len( var2 )
Else
Write( *, * ) 'No + or - in the string'
End If
Contains
Subroutine split_it( expression, var1, var2 )
Implicit None
Character( Len = * ), Intent( In ) :: expression
Character( Len = : ), Allocatable, Intent( Out ) :: var1
Character( Len = : ), Allocatable, Intent( Out ) :: var2
Integer :: split_pos
Integer :: paren_pos
split_pos = Scan( expression, '+-' )
If( split_pos /= 0 ) Then
var1 = Trim( Adjustl( expression( :split_pos - 1 ) ) )
paren_pos = Scan( var1, '(' )
var1 = Trim( Adjustl( var1( paren_pos + 1: ) ) )
var2 = Trim( Adjustl( expression( split_pos + 1: ) ) )
paren_pos = Scan( var2, ')' )
var2 = Trim( Adjustl( var2( :paren_pos - 1 ) ) )
Else
Allocate( Character( Len = 0 ) :: var1 )
Allocate( Character( Len = 0 ) :: var2 )
End If
End Subroutine split_it
End Program binom
ijb#ijb-Latitude-5410:~/work/stack$ gfortran --version
GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
ijb#ijb-Latitude-5410:~/work/stack$ gfortran -Wall -Wextra -fcheck=all -std=f2008 -g binom.f90
ijb#ijb-Latitude-5410:~/work/stack$ ./a.out
Expression?
(x+y)^3
Var1 = x 1
Var2 = y 1
ijb#ijb-Latitude-5410:~/work/stack$ ./a.out
Expression?
(qwerty-asdf)^12
Var1 = qwerty 6
Var2 = asdf 4
ijb#ijb-Latitude-5410:~/work/stack$ ./a.out
Expression?
( aag + fg ) ^98
Var1 = aag 3
Var2 = fg 2
ijb#ijb-Latitude-5410:~/work/stack$ ./a.out
Expression?
wibble
No + or - in the string

Problem with memory allocation for allocatable array( real type )

I am new in Fortran programming so I need a help about allocatable arrays.
This is my simple code:
PROGRAM MY_SIMPLE_CODE
IMPLICIT NONE
INTEGER :: N_TMP, ALLOC_ERR, DEALLOC_ERR
REAL, ALLOCATABLE, DIMENSION(:) :: P_POT
WRITE( *,* ) "ENTER THE VALUE FOR N_TMP:"
READ( *,* ) N_TMP
IF ( .NOT. ALLOCATED( P_POT) ) ALLOCATE( P_POT( N_TMP), STATUS = ALLOC_ERR )
IF ( ALLOC_ERR .NE. 0 ) STOP( "ERROR - ALLOCATION P_POT !!!")
IF ( ALLOCATED( P_POT) ) DEALLOCATE( P_POT, STATUS = DEALLOC_ERR )
IF ( DEALLOC_ERR .NE. 0 ) STOP( "ERROR - DEALLOCATION P_POT !!!")
END PROGRAM MY_SIMPLE_CODE
When I cobuild this code I got this error message:
Allocate-object is neither a data pointer nor an allocatable variable
What is wrong with this code?
What kind of tricky stuff can be masked in this simple code?
IDE: Code::Blocks TDM_GCC_5 1 0
OS: Win 10 X64
Just like #Steve said in the comment, the keyword for the status of allocation/deallocation is STAT, not STATUS. The error comes because the compiler doesn't recognize the name and thinks it is a variable.
Moreover, there is a syntax error because there must be at least a space between the STOP statement and the opening brace (or no braces at all).
IF ( .NOT. ALLOCATED( P_POT) ) ALLOCATE( P_POT( N_TMP), STAT = ALLOC_ERR )
IF ( ALLOC_ERR .NE. 0 ) STOP "ERROR - ALLOCATION P_POT !!!"
!(...)
IF ( ALLOCATED( P_POT) ) DEALLOCATE( P_POT, STAT = DEALLOC_ERR )
IF ( DEALLOC_ERR .NE. 0 ) STOP "ERROR - DEALLOCATION P_POT !!!"

opencv and c++ visual studio 2012

I have this code it work good.
When video length less than 1 minute and video size its 165 KB
When I change the video with other length 2 minute and size 15 MB OR another one same length with size 5 MB its show to me
project has stop working
this my code
# include "windows.h"
# ifdef _CH_
# pragma package < opencv >
# endif
# include "windows.h"
# ifndef _EiC
# include "cv.h"
# include "cvAux.h"
# include "highgui.h"
# include "cxcore.h"
# include < stdio.h >
# include < ctype.h >
# endif
// x?y?
int getpixel ( IplImage * image , int x , int y , int * h , int * s , int * v ) {
* h = ( uchar ) image -> imageData [ y * image -> widthStep + x * image -> nChannels ] ;
* s = ( uchar ) image -> imageData [ y * image -> widthStep + x * image -> nChannels + 1 ] ;
* v = ( uchar ) image -> imageData [ y * image -> widthStep + x * image -> nChannels + 2 ] ;
return 0 ;
}
//--------------------------------------------------------------------------------
int main ( int argc , char * * argv ) {
CvCapture * capture = cvCaptureFromAVI("a.avi") ;
IplImage * image = 0;
IplImage * HSV = 0 ;
/*
IplImage* img = cvLoadImage("greatwave.png", 1);
Mat mtx(img); // convert IplImage* -> Mat
*/
if ( argc == 1 || ( argc == 2 && strlen ( argv [ 1 ] ) == 1 && isdigit ( argv [ 1 ] [ 0 ] ) ) ) {
//capture = cvCaptureFromCAM ( argc == 2 ? argv [ 1 ] [ 0 ] - '0' : 0 ) ;
}
else if ( argc == 2 ) {
//capture = cvCaptureFromAVI ( argv [ 1 ] ) ;
}
if ( !capture ) {
fprintf ( stderr , "Could not initialize capturing.../n" ) ;
return - 1 ;
}
printf ( "Hot keys: /n" "/tESC - quit the program/n" ) ;
//Normal
cvNamedWindow ( "Normal" , CV_WINDOW_AUTOSIZE ) ;
//Condensation-------------------------------------------------
int DP = 2 ; //
int MP = 2 ; //
int SamplesNum = 300 ; //
CvConDensation * ConDens = cvCreateConDensation ( DP , MP , SamplesNum ) ;
//-----------------------------------------------------------------------
//Condensation-----------------------------------
CvMat * lowerBound ; //
CvMat * upperBound ; //
lowerBound = cvCreateMat ( 2 , 1 , CV_32F ) ;
upperBound = cvCreateMat ( 2 , 1 , CV_32F ) ;
//640*480
cvmSet ( lowerBound , 0 , 0 , 0.0 ) ;
cvmSet ( upperBound , 0 , 0 , 640.0 );
cvmSet ( lowerBound , 1 , 0 , 0.0 ) ;
cvmSet ( upperBound , 1 , 0 , 480.0 ) ;
cvConDensInitSampleSet ( ConDens , lowerBound , upperBound ) ;
//-----------------------------------------------------------------------
//------------------------------
for ( int i = 0 ; i < SamplesNum ; i++ ) {
ConDens -> flSamples [ i ] [ 0 ] += 320.0 ;
ConDens -> flSamples [ i ] [ 1 ] += 240.0 ;
}
//-----------------------------------------------------------------------
//----------------------------
ConDens -> DynamMatr [ 0 ] = 1.0 ;
ConDens->DynamMatr [ 1 ] = 0.0 ;
ConDens -> DynamMatr [ 2 ] = 0.0 ;
ConDens->DynamMatr [ 3 ] = 1.0 ;
//-----------------------------------------------------------------------
for ( ;; ) {
IplImage* frame = 0 ;
int c ;
int X , Y , XX , YY ;
int H , S , V ;
frame = cvQueryFrame ( capture ) ;
if ( !frame ) {
break ;
}
if ( !image ) {
image = cvCreateImage ( cvGetSize ( frame ) , 8 , 3 ) ;
image -> origin = frame -> origin ;
HSV = cvCreateImage ( cvGetSize ( frame ) , 8 , 3 ) ;
HSV -> origin = frame -> origin ;
}
cvCopy ( frame , image , 0 ) ;
cvCvtColor ( image , HSV , CV_BGR2HSV ) ;
//?---------------------------------------------------
for ( int i = 0 ; i < SamplesNum ; i++ ) {
X = ( int ) ConDens -> flSamples [ i ] [ 0 ] ;
Y = ( int ) ConDens -> flSamples [ i ] [ 1 ] ;
if ( X >= 0 && X <= 640 && Y >= 0 && Y <= 480 ) { //
getpixel ( HSV , X , Y , &H , &S , & V ) ;
if ( H <= 19 && S >= 48 ) { // //H<=19 S>=48
cvCircle ( image , cvPoint ( X , Y ) , 4 , CV_RGB ( 255 , 0 , 0 ) , 1 ) ;
ConDens -> flConfidence [ i ] = 1.0 ;
}
else {
ConDens -> flConfidence [ i ] = 0.0 ;
}
}
else {
ConDens -> flConfidence [ i ] = 0.0 ;
}
}
//--------------------------------------------------------------------------
//
cvConDensUpdateByTime ( ConDens ) ;
cvShowImage ( "Normal" , image ) ;
c = cvWaitKey ( 20 ) ;
if ( c == 27 ) {
break ;
}
}
//------------------------------------
cvReleaseImage ( &image ) ;
cvReleaseImage ( &HSV ) ;
cvReleaseConDensation ( &ConDens ) ;
cvReleaseMat ( &lowerBound ) ;
cvReleaseMat ( &upperBound ) ;
cvReleaseCapture ( &capture ) ;
cvDestroyWindow ( "Normal" ) ;
//---------------------------------------------
return 0 ;
}
# ifdef _EiC
main ( 1 , "condensation.cpp" ) ;
# endif
also when o comment this
for ( int i = 0 ; i < SamplesNum ; i++ ) {
X = ( int ) ConDens -> flSamples [ i ] [ 0 ] ;
Y = ( int ) ConDens -> flSamples [ i ] [ 1 ] ;
if ( X >= 0 && X <= 640 && Y >= 0 && Y <= 480 ) { //
getpixel ( HSV , X , Y , &H , &S , & V ) ;
if ( H <= 19 && S >= 48 ) { // //H<=19 S>=48
cvCircle ( image , cvPoint ( X , Y ) , 4 , CV_RGB ( 255 , 0 , 0 ) , 1 ) ;
ConDens -> flConfidence [ i ] = 1.0 ;
}
else {
ConDens -> flConfidence [ i ] = 0.0 ;
}
}
else {
ConDens -> flConfidence [ i ] = 0.0 ;
}
}
program work without do my idea of track object
i have windows 8
please comment if u dont understand some thing
I think that the problem is related to the declaration of IplImage *frame inside the for loop. When the size of your video length increases then, your memory gets full. Because you are continuously creating new frames inside the for loop without freeing the memory allocated to them.
You should declare IplImage *frame outside the for loop and then release the memory allocated to it outside the for loop.
ADVICE: Do not use old C-standards of OpenCV. Use the new C++ standards where you have to declare an image as Mat image. Then, you don't need to think about freeing memory because it does all the stuff itself.

mpi_gather of two variables

I am new to MPI programming with Fortran. I want to plot a 2D graph. I am trying to let each processor calculate one point of graph and send it to root to write it on file. Can somebody tell me how to send two variables viz: x and f(x) with mpi_gather. Thanks for any help.
Just as an example of both what Hristo said and " Is there anything wrong with passing an unallocated array to a routine without an explicit interface? " here's how you might do it
Program gather
Use mpi
Implicit None
Integer, Dimension( :, : ), Allocatable :: result
Integer, Dimension( 1:2 ) :: buffer
Integer :: me, nprocs, error
Integer :: x, fx
Call mpi_init( error )
Call mpi_comm_rank( mpi_comm_world, me , error )
Call mpi_comm_size( mpi_comm_world, nprocs, error )
If( me == 0 ) Then
Allocate( result( 1:2, 1:nprocs ) ) !Naughty - should check stat
Else
Allocate( result( 1:0, 1:0 ) ) !Naughty - should check stat
End If
x = me
fx = x * x
buffer( 1 ) = x
buffer( 2 ) = fx
Call mpi_gather( buffer, 2, mpi_integer, &
result, 2, mpi_integer, &
0, mpi_comm_world, error )
If( me == 0 ) Then
Write( *, '( 99999( i3, 1x ) )' ) result( 1, : )
Write( *, '( 99999( i3, 1x ) )' ) result( 2, : )
End If
Call mpi_finalize( error )
End Program gather
Wot now? mpif90 gather.f90
Wot now? mpirun -np 7 ./a.out
0 1 2 3 4 5 6
0 1 4 9 16 25 36