Fortran Forum for Programming Help: Resources, Tips, and Support

In summary, this conversation is about a closed thread on Fortran programming and the suggestion to visit a different forum for help. A new user also asks for help with Fortran 77 and is given a definition of a common block and how to use it. An example of a code using a common block is provided, but the user encounters errors when compiling.
  • #141
please try to make your own thread, and upload your question there, anyway I think you need to compile by the following commaand
f95nag file_name
 
Technology news on Phys.org
  • #142
Hi, can I call a subroutine inside another subroutine in Fortran 77?, also can I call a function in a subroutine?

advance thank for help
 
  • #143
Hi everyone
I've got a problem when I build a function, I need my function to produce a matrix, then I called the function in the main program by its name to give the matrix to the main program, but it does not work at all, I mean the matrix is computed correctly in the function but I failed to call it to the main program, here what I have in my code

Code:
main_program
c
complex*16 A(m1,m2), Mat
EXTERNAL Mat
c
A = MainMat(n,m)
.
..
end
complex*16 function Mat(n,m)
c calculate the elemnts of Mat
Mat = A
.
end
I need to return the matrix Mat, which I computed by the function to the main program
I took off the external statement, and declare the function (Mat) in my main program as

Code:
complex*16 A, Mat
C then I call it as
A = MainMat(S1,S2)
But when I've done the following loop, it does not work

Code:
do i = 1,N
do j = 1,M
write(7,*) A(i,j)
end do
end do

so I changed in the declaration as A(N,M), BUT IT DOES NOT WORK AS WELL
 
  • #144
What does the code for your function MainMat look like? When you say that your nested loop in your last code example "doesn't work" what does that mean? Does it produce any results or no results? Did you set N and M? You don't show these variables being initialized.
 
  • #145
Opr

Please do not give me the answer but if you can direct me to site that will tell me what OPR represent in the statement dp_reduce(array, "opr"). I think opr represent operation but I need to find out what it does in this statement. Please don't give me the answer-just direct me to the right site to learn more about this.

thanks in advance.
 
  • #146
Mark44 said:
What does the code for your function MainMat look like? When you say that your nested loop in your last code example "doesn't work" what does that mean? Does it produce any results or no results? Did you set N and M? You don't show these variables being initialized.

thanks, the code in the main function call some subroutines to produce a complex matrix and let the function return this matrix to the main program, actually I've everything correct and the function produce the right matrix,...just I have a problem of return this matrix t the main program.

please don't worry about the initialization and so on as I delete them for not making my post too long...shall I declare the function name in the main program as
complex MainMat

or complex MainMat(N,N)
BECAUSE IN THE MAIN PROGRAM I have the nested loop to print the resulted matrix from the function

thanks
 
  • #147
i'm heading a problem in mathematical equation about the initial condition, what methode should we used if there is an addition force, such as damping force. This equation will be applied to performed oscillatory system in fortran language programme .
 
  • #148
I have been learning Fortran but I have a question
Is It possible to find a job as fortran programmer or Where is Fortran used I mean where in which divisions
 
  • #149
How Call C routines present in archive from Fortran on UNIX

Hello All,

I have created a library, an archive of C routines on UNIX, which we need to use with Fortran programs (call from Fortran program). I am linking the library at the time of compiling.
The command which I am using is as follows,
$ xlf add.o alenia.a - L /home/oracle/oracle/product/db_1/lib -lclnuts -q64

Here the alenia.a is C routines archive and add.o is fortran programm calling C function preasnt in alenia.a.

So plse tell me that any prototype I should add in Fortran program? if yes how to do that or now then how to link the C library to the Fortran program & call the C routines in Fortran program.

Thanx.
Harshal
 
  • #150
I have a problem, here's what the,
should be from ascii file to extract data that is the n-th row and n-th column
I do not know how. Could someone help me.
 
  • #151
Hi.
I have a problem with getting started. I am using Linux (however its my first day) and Eclipse. I have Phortan installed. I was going step by step with:
http://wiki.eclipse.org/PTP/photran/documentation/photran6#Starting_a_New_Project
i got to point 15. I save that file. Then I don't know what do next. Here is the screenshot with console view, and with my error which pops up when I press "run" button:
[PLAIN]http://img638.imageshack.us/img638/3829/screenshotaqb.png

I used only MVS C# before, and I don't really know how that compiler stuff work... In C# was enough to press "build and run" button.

I hope someone can help me.

Tom :)
 
Last edited by a moderator:
  • #152
Hi there,
I have a source code which I want to compile it on Windows.
I've tried the Intel Visual Compiler 11 but I got many errors.
here is code:
http://www.shahabfar.com/dragon.rar"
I wonder if somebody compile it on Windows and let me know my problem.
Thank you in advance
 
Last edited by a moderator:
  • #153
Hello. I am running a Fortran 90 code. It runs, but I get the following error messages. Does anyone know how to help me figure out where my mistake is? I think I am replying when what I want to do is post a new thread. Sorry about that. Thanks in advance for any help!


forrtl: severe (64): input conversion error, unit 10, file C:\Fem605\Wrk\ft10.d
Image PC Routine Line Source
FEM6.exe 004CCEB9 Unknown Unknown Unknown
FEM6.exe 004CCCEB Unknown Unknown Unknown
FEM6.exe 004CBEF4 Unknown Unknown Unknown
FEM6.exe 004CC329 Unknown Unknown Unknown
FEM6.exe 004BF5D1 Unknown Unknown Unknown
FEM6.exe 004BE91F Unknown Unknown Unknown
FEM6.exe 00433102 Unknown Unknown Unknown
FEM6.exe 004305F6 Unknown Unknown Unknown
FEM6.exe 0042E664 Unknown Unknown Unknown
FEM6.exe 00413CED Unknown Unknown Unknown
FEM6.exe 00443755 Unknown Unknown Unknown
FEM6.exe 004F1769 Unknown Unknown Unknown
FEM6.exe 004E5964 Unknown Unknown Unknown
kernel32.dll 7D4E7D42 Unknown Unknown Unknown

C:\Fem605\Wrk>del fname.d

C:\Fem605\Wrk>del mpower2.d

C:\Fem605\Wrk>del FT90.d

C:\Fem605\Wrk>del ft10.d

C:\Fem605\Wrk>del ft11.d

C:\Fem605\Wrk>del ft16.d

C:\Fem605\Wrk>del ft17.d

C:\Fem605\Wrk>del ft18.d

C:\Fem605\Wrk>del fort.19
Could Not Find C:\Fem605\Wrk\fort.19

C:\Fem605\Wrk>del C:\FEM605\Wrk\outp\mpower2.ft20
Could Not Find C:\FEM605\Wrk\outp\mpower2.ft20

C:\Fem605\Wrk>rem ////// FEMAXI-6 Calc. completed ! ///////

C:\Fem605\Wrk>
 
  • #154
Fortran 77 variables values can not be recognized

Hi,

I am writing a program that uses an external file 'parameter.f' to specify my inputs.

Example of parameter.f
PARAMETER (LA=6D-2)
PARAMETER (LB=6D-2)
PARAMETER (LC=6D-2) ...

In my main program:

DOUBLE PRECISION LA, LB, LC
INCLUDE 'parameter.f'
**** main program continues
CALL subroutineA(...)
***
END of main program

For my subroutineA, it will call another subroutineC that will take inputs LA, LB, LC
Example of subroutineA:
subroutineA()
INCLUDE 'parameter.f'
...
call subroutineC(LA, LB, LC)
...
END of subroutineA

I realize that the LA, LB, LC values specified as 0.06, will be recognized as zero value
in the subroutine. Hence, zero values will be past to the subroutineC when it is called by
subroutineA.

I have been trying to figure out the bug of this program... but
eventually how I solve the problem is change the variable names.

I have changed LA, LB, LC for my program to AL, BL, CL instead and it works!
There is no change in the calling of subroutine, main structure of program.

It is strange to me as the beginner of Fortran that I can ignore this and continue for my simulation. But I hardly accept the fact that I can simply solve this problem by just changing the name of variables...

I appreciate if anyone has the similar experience and please share with me. Thank you.
 
  • #155
hendraarkan said:
i'm heading a problem in mathematical equation about the initial condition, what methode should we used if there is an addition force, such as damping force. This equation will be applied to performed oscillatory system in fortran language programme .

What is your main concern about solving the differential equation? I thought with the differential equation, you can apply ODE methods like Euler, Runge-Kutta and etc. that can solve the initial value problem even though it has damping force.

Perhaps you concern is over the convergence of solution and its stability. you may refer to numerical recipe textbook for reference on solving this type of problem.
 
  • #156
How to solve this in fortran?

a=∏_(k=1)^(n-1)*((2x+10)/(k-3)) ^(2/k)
 
  • #157
Hi guys,
I'm working in some code for my PhD and I would like continue the calculi once it stoped. The point is that I am saving some information and I would like the continuation code would be able to find automatically the last file written. The structure of the backup file is "rra_00000.dat" where follow the format '(A,I5.5,A)' and I don't know how to say to the compiler that took the last file written
 
  • #158
Hi,
I have written a code, which is divided into 5 different files:
Element_data.f90, Check_criteria.f90, Read_in.f90, Service_subs.f90 and main.f90.

All files contain one module each, exept main.f90, which is the program and where
all the modules are referenced to via an include command.

I am trying to create a makefile for this. It seems to work, the program is compiled,
but when I change the order of the include commands in main.f90, suddenly Check_criteria cannot acces shared variables from element_data any more. This can't be right. Anybody can help?
Oh, I am using the f90 compiler for hp unix. This is my makefile so far, this is the first time I am trying to create one. I left the lines from previous tries in it. Thanks!:

Debugopts = -g

Main: Main.o
f90 Main.o -o $@

Main.o: Element_data.f90 Check_criteria.f90 Service_subs.f90\
Read_in.f90 Main.f90
f90 $(Debugopts) Main.f90


#Element_data.o: Element_data.f90
# f90 $(Debugopts) Element_data.f90

#Check_criteria.o: Element_data.f90 Check_criteria.f90
# f90 $(Debugopts) Check_criteria.f90
#
#Service_subs.o: Element_data.f90 Service_subs.f90
# f90 $(Debugopts) Service_subs.f90

#Read_in.o: Element_data.f90 Service_subs.f90 Read_in.f90
# f90 $(Debugopts) Read_in.f90

#Main.o: Element_data.f90 Check_criteria.f90 Service_subs.f90\
# Read_in.f90

#Element_data.o: Element_data.f90


#Check_criteria.o: Element_data.f90

#Service_subs.o: Element_data.f90


#Read_in.o: Element_data.o Service_subs.f90

clean:
rm *.o
cleanall:
rm *.o Main
 
  • #159


GohJQ said:
Hi,

I am writing a program that uses an external file 'parameter.f' to specify my inputs.

Example of parameter.f
PARAMETER (LA=6D-2)
PARAMETER (LB=6D-2)
PARAMETER (LC=6D-2) ...

In my main program:

DOUBLE PRECISION LA, LB, LC
INCLUDE 'parameter.f'
**** main program continues
CALL subroutineA(...)
***
END of main program

For my subroutineA, it will call another subroutineC that will take inputs LA, LB, LC
Example of subroutineA:
subroutineA()
INCLUDE 'parameter.f'
...
call subroutineC(LA, LB, LC)
...
END of subroutineA

I realize that the LA, LB, LC values specified as 0.06, will be recognized as zero value
in the subroutine. Hence, zero values will be past to the subroutineC when it is called by
subroutineA.

I have been trying to figure out the bug of this program... but
eventually how I solve the problem is change the variable names.

I have changed LA, LB, LC for my program to AL, BL, CL instead and it works!
There is no change in the calling of subroutine, main structure of program.

It is strange to me as the beginner of Fortran that I can ignore this and continue for my simulation. But I hardly accept the fact that I can simply solve this problem by just changing the name of variables...

I appreciate if anyone has the similar experience and please share with me. Thank you.

Statement PARAMETER in fortran is used just to assign a name to a number, but not to assign a value to identifier

So in your code you should not define LA, LB, LC as doubles, you should not define them at all.
At the beginning the following strings are complitely enough
PARAMETER (LA=6D-2)
PARAMETER (LB=6D-2)
PARAMETER (LC=6D-2)
You cannot use LA,LB,LC as formal arguments, as common block elements or as variables.
If you write in the any place of your code

RL=LA

it would be the same as if you have written

RL=6D-2

The substitution will be made by COMPILER during compilation. No other use for LA,LB,LC is allowed. Understand?

More tips: Parameter statement preseeds all other declarations, therefore if RR is declared then it CANNOT be used in parameter statement.

In you case you should remove parameter statements and use value assignment statements
LA=6D-2
LB=6D-2
LC=6D-2
instead (place it after all declarations)
 
  • #160
rfmergarejo said:
Hi guys,
I'm working in some code for my PhD and I would like continue the calculi once it stoped. The point is that I am saving some information and I would like the continuation code would be able to find automatically the last file written. The structure of the backup file is "rra_00000.dat" where follow the format '(A,I5.5,A)' and I don't know how to say to the compiler that took the last file written
During execution let your program open an additional ASCII file "My-states" and each time when you save the state of your data into file "rra_00000...dat" write down this name
into "My-states" file. Then the next time you run your code you can get info about the
last file written from the "My-states".
 
  • #161
Ma_He said:
Hi,
I have written a code, which is divided into 5 different files:
Element_data.f90, Check_criteria.f90, Read_in.f90, Service_subs.f90 and main.f90.

All files contain one module each, exept main.f90, which is the program and where
all the modules are referenced to via an include command.

I am trying to create a makefile for this. It seems to work, the program is compiled,
but when I change the order of the include commands in main.f90, suddenly Check_criteria cannot acces shared variables from element_data any more. This can't be right. Anybody can help?
Oh, I am using the f90 compiler for hp unix. This is my makefile so far, this is the first time I am trying to create one. I left the lines from previous tries in it. Thanks!:

Debugopts = -g

Main: Main.o
f90 Main.o -o $@

Main.o: Element_data.f90 Check_criteria.f90 Service_subs.f90\
Read_in.f90 Main.f90
f90 $(Debugopts) Main.f90


#Element_data.o: Element_data.f90
# f90 $(Debugopts) Element_data.f90

#Check_criteria.o: Element_data.f90 Check_criteria.f90
# f90 $(Debugopts) Check_criteria.f90
#
#Service_subs.o: Element_data.f90 Service_subs.f90
# f90 $(Debugopts) Service_subs.f90

#Read_in.o: Element_data.f90 Service_subs.f90 Read_in.f90
# f90 $(Debugopts) Read_in.f90

#Main.o: Element_data.f90 Check_criteria.f90 Service_subs.f90\
# Read_in.f90

#Element_data.o: Element_data.f90


#Check_criteria.o: Element_data.f90

#Service_subs.o: Element_data.f90


#Read_in.o: Element_data.o Service_subs.f90

clean:
rm *.o
cleanall:
rm *.o Main

If you have referenced (included) the source code of your subroutines into the end of your main program text then the command f90 Main.f90 -o name_for_my_prog
should create executable.
 
  • #162
hello friends,
i am new in Fortran programming. Actually i would like to read multiple data files. For reading a single file i have written a small pro-gramme as mentioned below

! PROGRAM FOR RANGE_RESIDUAL


! DEFINING COLUMNS
! // Number SampleTime Delay Code AmbF SpCF SpTF CorF KD-1 RecF ToneLevel CodeLevel PhaseError ToneLoopSN CDownModIndex
! C1 C2,C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C16


!1110 ROWS AFTER HEADER AND 16 COLUMS AS DEFINED ABOVE

DOUBLE PRECISION :: C2,C3,C12,C13,C14,C15,C16,C10,C4
INTEGER :: C1,C5
CHARACTER :: C6*4,C7*6,C8*6,C9*6,C11*5,files
OPEN(1,file = 'M32ICL1L1A_RGX_041920603_00.RAW')
DO IROW=1,190
READ(1,*)
ENDDO


OPEN(2,FILE='FROW')
READ(2,*)FR
DO I=192,FR

READ(1,777)C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14, &
C15,C16
777 FORMAT(5x,I4,2x,F9.0,F10.3,E22.13,I6,A4,3(A6),E24.13,A5, &
F23.1,F22.3,F22.3,F22.12,F22.3)
write(*,778)C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14, &
C15,C16
778 FORMAT(I4,1x,F9.0,F10.3,E22.13,1X,I6,A4,3(A6),E24.13,A5, &
F23.1,F22.3,F22.3,F22.12,F22.3)


ENDDO


STOP
END

This is the file ( M32ICL1L1A_RGX_041920603_00.RAW) containing header information, like wise i have , multipal files. So is there anybody who can help me, by telling how to read number of files ?

Thanks in advance !

Ashok Verma
ashokverma.iitkgp@gmail.com
 
  • #163
Do somebody knows about fortran IV?
 
  • #164
Hello evryone, can you help me with this question in Fortran code... Thank you so much...

Is it possible if we use the same number for 2 different file as below (file 10 used for both "2d.in" and "gr.001"?
open(10,file='2din')

read(10,*) dx,dz
read(10,*) nx,nz
read(10,*) tmax,hifreq
close(10)

open(10,file='gr.001',form='unformatted',
* access='direct',recl=4*nz)
 
  • #165
Yes, this should work, because you close the first file before opening the second one.

It's been many years since I last programmed seriously in Fortran, but I'm pretty sure I did the same thing myself, sometimes.
 
  • #166
thank you so much...
Well, you had a great experience in programming... I'm just a baby in this field... I feel very confused... Why did they use the same name for 2 different file? I think there are some relations... Do you think so?
 
  • #167
Hello,

I would like to know if in sequential access mode to a file, it is possible to overwrite a given record in the middle of the file, while keeping all the subsequent records.

When I write a record in the middle of an existing file, it makes the file to terminate imediatly after the record I've just written.

Thanks in advance
 
  • #168
salparadise said:
Hello,

I would like to know if in sequential access mode to a file, it is possible to overwrite a given record in the middle of the file, while keeping all the subsequent records.

When I write a record in the middle of an existing file, it makes the file to terminate imediatly after the record I've just written.

Thanks in advance
Show us your code that does this.
 
  • #169
Nphung78 said:
Why did they use the same name for 2 different file? I think there are some relations... Do you think so?

I can't read minds, so I can only guess. It might be that the two files are simply parts of the same data set, so that they could have just as well been in one file to begin with. Or maybe the programmer simply preferred to use as few input unit numbers as possible.
 
  • #170
Mark44 said:
Show us your code that does this.

Hope this is comprehensible, I'm posting only the relevant part of the code. This code is intended to change parameters value in a file with following structure:

--------------------------------------------------------------------------------
...
Block Minpar

# comment:
# parameter_id parameter_value
3 23.45 # This parameter is...
...
---------------------------------------------------------------------------------




OPEN(file_id,FILE=file,STATUS='unknown',IOSTAT=ios,)

DO
READ(file_id,'(A100)',IOSTAT=ios),line

If((line(1:1)=='#').OR.(line(1:1)=='')) Cycle

IF (line(1:12)=='BLOCK MINPAR') THEN
DO
Read(file_id,'(a100)'),line
IF (line(1:5)=='BLOCK') EXIT
If ((line(1:1)=='#').OR.(line(1:1)=='')) Cycle
BACKSPACE(file_id)

READ(file_id,*) param_id,param_value
rest_line=line(INDEX(line,'#'):)

IF ((parameter_name=='m0').AND.(param_id==1)) THEN
BACKSPACE(file_id)
WRITE(file_id,'(A,I5,A)') achar(9),param_id,achar(9), new_parameter_value, achar(9)//TRIM(rest_line)

[...]
 
  • #171
jtbell said:
I can't read minds, so I can only guess. It might be that the two files are simply parts of the same data set, so that they could have just as well been in one file to begin with. Or maybe the programmer simply preferred to use as few input unit numbers as possible.

Yes, you are right, jtbell. After several days working on this, I also guess that programmer used "10" as a number for input file...
Thank you so much...:smile:

Now, I have problem with open "unformatted file". I can not open it by normal text editor as notepad... The output file is also in "unformatted"... What can I deal with them, pls give me some directions...

Thanks in advance!
 
  • #172
Hi
could u please help me out with following simple fortran programme
i am getting small error in calculating cosine of 270 deg, Ideally answer should be zero but i am getting -3.65E-08. how to get exact cosine of 270deg

I am using compaq visual fortran



Subroutine CONSTANTS()
REAL PI,RtoD,DtoR
PI=4.0*ATAN(1.0)
RtoD=180.0/PI
DtoR=PI/180.0

Print*,Cos(270.0*DtoR)
End

Answer = -3.65E-08
 
  • #173
Your variables are single-precision (4-byte) reals, so your answer isn't too far off from zero. For more precision, try using 8-byte reals, like this:
Code:
REAL*8 PI, RtD, DtR
You still might not get zero, but you should get something that is closer to zero than what you got.
 
  • #174
sine(270) give correct amnswer Why not cosine
 
  • #175
Is there any setting in compiler for example Math files needs to be included.
 

Similar threads

  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
7
Views
6K
  • Programming and Computer Science
Replies
13
Views
4K
  • Programming and Computer Science
Replies
16
Views
4K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
14
Views
3K
  • Sticky
  • DIY Projects
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
11
Views
5K
Back
Top