CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Main CFD Forum (
-   -   CGNS Fortran Writing Error (

AeroMike August 21, 2012 06:35

CGNS Fortran Writing Error
Hi all,

I have written a Fortran code which writes a structured grid, I used the NASA website which is a great help, and my code is heavily based on that.

Anyway, it works locally and I have tested the grids extensively. When I try to run it on the two HPC's I have access to it behaves very oddly - compiles okay, but crashes out with an error that:

VertexSize[0]=71 and CellSize[0]=0

If I print the isize(1,2) immediately before the cgns call it is 70 as expected but seems to go wrong in the call.

Placing print statements in the code seems to cause it to misbehave a bit (sometimes my cgns error becomes "no cgns error"!).

I am using 64 bit cgns and compiling with all my integers as 8 bit. Has anyone experienced a similar problem and/or can hazard a guess at what could be going wrong?!

Thanks for any help,

bensciens April 10, 2013 08:26

I have recently been getting this error myself using Fortran and the CGNS libraries.

Did you solve the problem?

AeroMike April 10, 2013 08:34

Hi Ben,

Yes, but it was a while back and I can't be sure what I'm about to tell you is correct, but it is something which I know fixed some of my mistakes.

You have to be very careful writing integers to any of the cgns routines. There is a cgns type variable you should use for all integers, "cgsize_t".

The place where it catches me out is in the bc's where you always write a fixed "2". But you must declare a cgsize_t:: fixed_bc_length and set the variable to 2 or it sometimes will fail.

I'm not sure if that is the actual solution though. If that doesn't work let me know and I'll hunt through git and find my change log for August last year!

bensciens April 10, 2013 08:52

Thanks for the quick reply Mike.
I'm not entirely sure how to use cgsize_t for integers.

Are you saying that my problem comes from using isize declared as:

INTEGER:: isize(3,3)

This is then used to store the VERTEXSIZE, CELLSIZE and bc:

isize(1,1) = in(nb)
isize(2,1) = jn(nb)
isize(3,1) = kn(nb)
isize(1,2) = isize(1,1)-1
isize(2,2) = isize(2,1)-1
isize(3,2) = isize(3,1)-1
isize(1,3) = 0
isize(2,3) = 0
isize(3,3) = 0

where nb is the block number.
Directly below is the call function:

CALL cg_zone_write_f(index_file, index_base, zonename(nb), isize, Structured, index_zone(nb), ier)
IF (ier .NE. 0) CALL cg_error_exit_f

This is for a structured grid.

Any further help you can give me is much appreciated.


AeroMike April 10, 2013 08:55

I think so yes, in my code I have them all declared like that:

!> CGNS identifiers
cgsize_t :: IER
cgsize_t, DIMENSION(3,3) :: ISIZE

AeroMike April 10, 2013 08:56

PS: You will have to have included the lines:

include 'cgnslib_f.h'

#include "cgnstypes_f.h"

In your header too (I'm not sure what the # is for but it seems to be required!).

bensciens April 10, 2013 09:01

Thank you,

Just found another way around it, from the information I have read it seems to be something to do with compiling in 32/64-bit.

Your way is probably the better way but changing the declaration for isize to:

for 64-bit
INTEGER*8 :: isize(3,3)

for 32-bit
INTEGER*4 :: isize(3,3)

This also seems to work.

Thank you for your help Mike.

AeroMike April 10, 2013 09:04


Yes, you can change it manually and it should work. But this means that you will need to make sure that you always check it when you switch to a new machine. This will inevetibly cause trouble when you switch to a different HPC, or more likely, when the code gets passed on to someone else and they have the same problem again.

All cgsize_t does is check which cgns library is installed and choose the appropriate integer size, which allows you to compile it hassle free on any machine.

Glad it's working though!


bensciens April 10, 2013 09:37

I'm trying to compile with

#INCLUDE "cgnstypes_f.h"

but I'm getting a 'Bad # preprocessor line'.

Were you using ifort?

AeroMike April 10, 2013 09:42

You must use both lines:

include 'cgnslib_f.h'

#include "cgnstypes_f.h"

I'm not sure why you get an error then though, I can compile with ifort or gfortran and both work.

bensciens April 10, 2013 09:45

I have both if I don't include the '#' the error applies to the hashes lines inside

Do you know what compiler options you used?

AeroMike April 10, 2013 09:50

You must make sure that the first of the two lines is indenteded and the second isn't at all. The first must not be #'d and the second must. I'm not sure why, but I think that this exactly the formatting it must be. I can't say why though!

E.G exact formatting below.

include 'cgnslib_f.h'

#include "cgnstypes_f.h"

Now, as for compiler options it shouldn't matter, I have debug flags and that works or just compiling with -O3 -r8 -i4 -fpp should work too.

bensciens April 10, 2013 09:58

Got it!

I had everything but the -fpp flag. It works for now just a fault because I made a vector the wrong size somewhere.

Thanks for the help.

AeroMike April 10, 2013 10:00

Yeah, I can't be held responsible for other bugs in your code ;-)

Glad it's working now though.

All times are GMT -4. The time now is 21:48.