|
[Sponsors] |
Fortran issue (write statement modifying variables??) |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 18, 2014, 21:11 |
Fortran issue (write statement modifying variables??)
|
#1 |
Senior Member
Joachim
Join Date: Mar 2012
Location: Paris, France
Posts: 145
Rep Power: 15 |
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 |
|
January 19, 2014, 03:56 |
|
#2 | |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,764
Rep Power: 71 |
Quote:
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.. |
||
January 19, 2014, 05:29 |
|
#3 |
Senior Member
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20 |
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? |
|
January 19, 2014, 10:44 |
|
#4 |
Senior Member
Joachim
Join Date: Mar 2012
Location: Paris, France
Posts: 145
Rep Power: 15 |
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 |
|
January 19, 2014, 11:16 |
|
#5 | |
New Member
Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 14 |
Quote:
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 |
||
January 19, 2014, 11:29 |
|
#6 | |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,764
Rep Power: 71 |
Quote:
but what about FCFLAGS? |
||
January 19, 2014, 12:58 |
|
#7 |
Senior Member
Joachim
Join Date: Mar 2012
Location: Paris, France
Posts: 145
Rep Power: 15 |
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! |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
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 |