CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Fortran issue (write statement modifying variables??)

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By cfdnewbie

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 18, 2014, 21:11
Default Fortran issue (write statement modifying variables??)
  #1
Senior Member
 
Joachim
Join Date: Mar 2012
Location: Paris, France
Posts: 145
Rep Power: 15
Joachim is on a distinguished road
Hi everyone!

I have been having an issue with my fortran code, which really does not make sense to me. If somebody could give me his opinion, I would greatly appreciate!

At one point, my code generates a mistake (a variable = NaN). I used write statements to spot the source of the error.

if I use

print *, Mbar -> answer: 2.802

if I use

print *, Mbar, Cavg -> answer: NaN, 0,354

I did not change anything in the code, but the value of the variable Mbar changed to NaN!!!
Why would such a thing happen??

Thank you very much for your help!

Joachim
Joachim is offline   Reply With Quote

Old   January 19, 2014, 03:56
Default
  #2
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,764
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by Joachim View Post
Hi everyone!

I have been having an issue with my fortran code, which really does not make sense to me. If somebody could give me his opinion, I would greatly appreciate!

At one point, my code generates a mistake (a variable = NaN). I used write statements to spot the source of the error.

if I use

print *, Mbar -> answer: 2.802

if I use

print *, Mbar, Cavg -> answer: NaN, 0,354

I did not change anything in the code, but the value of the variable Mbar changed to NaN!!!
Why would such a thing happen??

Thank you very much for your help!

Joachim

what option you added in compiling your code? Mbar should be an integer? Often this kind of error is just an indication that your source code has some error like mismatch of type or some error in the bound of array.
Use the debug settings..
FMDenaro is offline   Reply With Quote

Old   January 19, 2014, 05:29
Default
  #3
Senior Member
 
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20
cfdnewbie is on a distinguished road
I would agree, Debug flags are your best option. I would assume some memory allocation / out of bounds array things, because when an error seems to "jump" when you add a line, that usually means that a different part of the memory becomes corrupted.

Just out of curiosity: what type of code is it? f77 still around?
FMDenaro likes this.
cfdnewbie is offline   Reply With Quote

Old   January 19, 2014, 10:44
Default
  #4
Senior Member
 
Joachim
Join Date: Mar 2012
Location: Paris, France
Posts: 145
Rep Power: 15
Joachim is on a distinguished road
Hey! thanks to both of you.
I am not very familiar with makefiles however. What kind of line should I had to spot the mistake?

So far, that is what I have in my Makefile

-------------------------------------------------------------------------------------
FC = gfortran

# List of executables to be built within the package
PROGRAMS = main_euler_v1

-fcheck=all -fbacktrace -ffpe-trap=invalid,zero,overflow

# "make" builds all
all: $(PROGRAMS)

# Dependency rules
main_euler_v1.o: data_package_v1.o
main_euler_v1: data_package_v1.o
main_euler_v1.o: grid_jacobian_v1.o
main_euler_v1: grid_jacobian_v1.o
main_euler_v1.o: euler_solver_v1.o
main_euler_v1: euler_solver_v1.o
main_euler_v1.o: fluxes_v1.o
main_euler_v1: fluxes_v1.o

grid_jacobian_v1.o: data_package_v1.o
euler_solver_v1.o: data_package_v1.o
fluxes_v1.o: data_package_v1.o

# General rules for building the program
%: %.o
$(FC) $(FCFLAGS) -o $@ $^ $(LDFLAGS)

%.o: %.f90
$(FC) $(FCFLAGS) -c $<

%.o: %.F90
$(FC) $(FCFLAGS) -c $<

# Utility targets
.PHONY: clean veryclean

clean:
rm -f *.o *.mod *.MOD

veryclean: clean
-----------------------------------------------------------------------------------

Thank you once again!

Joachim

ps: I am using f90
Joachim is offline   Reply With Quote

Old   January 19, 2014, 11:16
Default
  #5
New Member
 
Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 14
Patrick1 is on a distinguished road
Quote:
Originally Posted by Joachim View Post
Hi everyone!

I have been having an issue with my fortran code, which really does not make sense to me. If somebody could give me his opinion, I would greatly appreciate!

At one point, my code generates a mistake (a variable = NaN). I used write statements to spot the source of the error.

if I use

print *, Mbar -> answer: 2.802

if I use

print *, Mbar, Cavg -> answer: NaN, 0,354

I did not change anything in the code, but the value of the variable Mbar changed to NaN!!!
Why would such a thing happen??

Thank you very much for your help!

Joachim
Try using a format specifier:

http://www.fortran.com/F77_std/rjcnf0001-sh-13.html

here is an old piece of code of mine. First I define the format with ID 91:

91 format (3X,I4,4X,3(6x,f6.1),2(6x,F10.6))

Then I write onto the screen (6) using the 91 format:

write (6,91) turbno,x_mat(dum_turbno),y_mat(dum_turbno),height, (U(dum_turbno,j)),(TI(j))

turbno etc are just the names of my variables.

The format specifiers can be found on the web but the basic ones are:

Integers of field width w: Iw
Real numbers of field width w and n decimal places: Fw.n
n blank spaces: nX

So in my format 91 I write 3 blank spaces, and integer of field width 4, 3 times 6 blank spaces then a real number of field width 6 and one decimal place..etc
Patrick1 is offline   Reply With Quote

Old   January 19, 2014, 11:29
Default
  #6
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,764
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by Joachim View Post
Hey! thanks to both of you.
I am not very familiar with makefiles however. What kind of line should I had to spot the mistake?

So far, that is what I have in my Makefile

-------------------------------------------------------------------------------------
FC = gfortran

# List of executables to be built within the package
PROGRAMS = main_euler_v1

-fcheck=all -fbacktrace -ffpe-trap=invalid,zero,overflow

# "make" builds all
all: $(PROGRAMS)

# Dependency rules
main_euler_v1.o: data_package_v1.o
main_euler_v1: data_package_v1.o
main_euler_v1.o: grid_jacobian_v1.o
main_euler_v1: grid_jacobian_v1.o
main_euler_v1.o: euler_solver_v1.o
main_euler_v1: euler_solver_v1.o
main_euler_v1.o: fluxes_v1.o
main_euler_v1: fluxes_v1.o

grid_jacobian_v1.o: data_package_v1.o
euler_solver_v1.o: data_package_v1.o
fluxes_v1.o: data_package_v1.o

# General rules for building the program
%: %.o
$(FC) $(FCFLAGS) -o $@ $^ $(LDFLAGS)

%.o: %.f90
$(FC) $(FCFLAGS) -c $<

%.o: %.F90
$(FC) $(FCFLAGS) -c $<

# Utility targets
.PHONY: clean veryclean

clean:
rm -f *.o *.mod *.MOD

veryclean: clean
-----------------------------------------------------------------------------------

Thank you once again!

Joachim

ps: I am using f90

but what about FCFLAGS?
FMDenaro is offline   Reply With Quote

Old   January 19, 2014, 12:58
Default
  #7
Senior Member
 
Joachim
Join Date: Mar 2012
Location: Paris, France
Posts: 145
Rep Power: 15
Joachim is on a distinguished road
thanks everyone! Actually, I cheated for that makefile. I just took a template and adapted it for my purpose...

I think I found something interesting, but I still don't fully understand it.

In my code, I use a special type called flow, in which I store most of the variables (--> flow(i,j)%u, etc).

1.At one point in the code, I checked and flow(i,j)%u is properly defined.

2. It is then called by a subroutine to compute the fluxes. The flow pointer is a global variable (use simulation_data at the beginning of the subroutine), but for some reason, if I do print *, flow(i,j)%u, I obtain NaN.

3. Pretty weird, if I add a print statement at the very beginning of the subroutine, then everything works just fine!! (if I don't, the flux calculation fails because u = NaN).

I think there is a problem when communicating the flow pointer, but I really don't understand why!! Would anyone have an idea??
Thanks very much for your help!
Joachim is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting environment variables: bash issue travonz OpenFOAM Installation 2 July 31, 2012 03:17
Issue with write interval haze_1986 OpenFOAM 0 July 30, 2012 02:24
Comparison between C/C++ and Fortran? rick Main CFD Forum 45 September 6, 2011 00:52
CFX11 + Fortran compiler ? Mohan CFX 20 March 30, 2011 18:56
about USER FORTRAN compiling issue CXL CFX 1 October 9, 2003 21:00


All times are GMT -4. The time now is 08:32.