Skip to content

Instantly share code, notes, and snippets.



Last active May 28, 2018
What would you like to do?
Fortran / C interoperability for logical

Compile using either of:


and you should get the result:

           3 T F
true -> false
           3 F T
false -> true

Now compile using Intel:


and you get the result:

           3 T F
true -> true
           3 F T
false -> true

Which is incorrect. Enable -fpscomp logical in compile_intel, recompile, then you get:

           3 T F
true -> false
           3 F T
false -> true
module a
use iso_c_binding, only: c_int, c_bool
implicit none
public foo
subroutine foo(n, relat, relat_out) bind(c, name="foo")
integer(c_int), intent(in), value :: n
logical(c_bool), intent(in), value :: relat
logical(c_bool), intent(out) :: relat_out
relat_out = .not. relat
print *, n, relat, relat_out
end subroutine
end module
gcc -o m.o -c m.c
gfortran -o a.o -c a.f90
gcc m.o a.o -lgfortran
icc -o m.o -c m.c
#ifort -fpscomp nologicals -o a.o -c a.f90
ifort -o a.o -c a.f90
icc m.o a.o -lifcore
pgcc -o m.o -c m.c
pgf90 -o a.o -c a.f90
pgcc m.o a.o -pgf90libs
#include <stdio.h>
#include <stdbool.h>
void foo(int n, bool relat, bool *relat_out);
int main()
bool relat_out;
foo(3, true, &relat_out);
printf("true -> %s\n", relat_out ? "true" : "false");
foo(3, false, &relat_out);
printf("false -> %s\n", relat_out ? "true" : "false");
return 0;

This comment has been minimized.

Copy link

@kunalbali kunalbali commented Mar 27, 2014

I need some help in fortran programming. As i am new in fortran so i am not getting how to merge two file or all i can say how to compile 2 file. As i am student of atmospheric science stream so i need to merge some satellite data. I have 10 files (Lat Lon Vales in each files). I want to make it one and also want to do average of each lat , lon values.

Hope you got my problem

Thank You

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.