NCAR / ncl

The NCAR Command Language (NCL) is a scripting language for the analysis and visualization of climate and weather data.

Home Page:http://www.ncl.ucar.edu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fortran runtime error by ncargf90 compiling a fortran file

yuanfu1 opened this issue · comments

I wrote a simple program xie.F90 calling NCARG cpcnrc routine for plotting. Hope you are still supporting the old style NCARG. I downloaded the ncl precompiled to my Mac. It went well until I ran a.out. It gave an error message:
(base) xiey % ncargf90 xie.F90
gfortran -fPIC -fno-range-check -m64 -Wall -fopenmp -O xie.F90 -L/usr/local/ncl-6.6.2/lib -L/opt/X11/lib -lncarg -lncarg_gks -lncarg_c -lXpm -lX11 -lXext -lcairo -lfontconfig -lpixman-1 -lfreetype -lexpat -lpng -lz -lXrender -lbz2
(base) xiey % ./a.out
At line 202 of file cpnumb.f
Fortran runtime error: Missing initial left parenthesis in format

^

Error termination. Backtrace:
#0 0x10924087e
#1 0x109241525
#2 0x10924210b
#3 0x109455872
#4 0x109455a23
#5 0x109466857
#6 0x108c0475f
#7 0x108c03687
#8 0x108bf76c6
#9 0x108bef40b
#10 0x108cafc28

The code is very simple:
program xie
INTEGER n
REAL a(8,8)

n = 8
a = 1.0

CALL opngks
CALL cpcnrc(a,8,8,8,0.0,0.0,0.0,0,0,-1)
CALL frame
CALL clsgks
end program xie

Computing environment

  • OS: [Linux, Mac, or Windows] Mac
  • OS version: [e.g. Ubuntu 16.04, MacOS 10.13.6, Windows 10] macOS Big Sur version 11.4
  • NCL Version: [e.g. 6.5.0] 6.6.2
  • Installation method: [binary from NCAR website, conda, other package manager (apt, brew, macports, yum), built from source] binary from NCAR website

Additional context
Add any other context about the problem here.

INCORRECT ANALYSIS. PLEASE SEE CORRECTION IN NEXT MESSAGE. >>> This error comes from cpnumb.f. This file appears to be part of your own source code, because I do not find it anywhere in NCARG source code. If you can locate this file somewhere else, please let us know where it is. <<<

This is a simple fortran error. Please correct the error in your own code, and try again.

Also when using NCARG, always add the -g option to your ncargf90 command, so that the backtrace will have better information about the location of your error.

My apologies, the previous message was wrong. I took another look at this. cpnumb.f is part of NCARG source code. It is a temporary file that is created and later removed during the NCARG build process. The actual source code is inside ncl_ncarg-6.6.2/ncarg2d/src/libncarg/conpack/CodeIftran, lines 9522 - 10024.

I was able to duplicate the error "Missing initial left parenthesis in format" by compiling your test program xie.F90 on Mac with gfortran version 10, and linking directly with NCARG libraries in the binary distribution ncl_ncarg-6.6.2-MacOS_10.13_64bit_gnu710.tar.gz. I had to provide a few other support libraries that are not included in the binary distribution.

I got xie.F90 to work without error by switching to gfortran version 7 and leaving everything else the same. The program also works fine with the most recent version of NCARG/NCL from macports.org.

This error "Missing initial left parenthesis in format" is probably caused by mixing compiler versions between a main program like xie.F90, and a binary distribution which in this case was compiled with gfortran 7. Gfortran documentation is specific that code compiled with gfortran 7 is not compatible with runtime libraries (libgfortran.*.dylib) in more recent gfortran versions. Gfortran 8.1 introduced an incompatible change in string passing between subroutines. The message "Missing initial left parenthesis in format" fits this hypothesis well. Refer to "Fortran language issues" in the "Porting to GCC 8" guide.

Here are several remedies. They all involve maintaining compatible compiler versions between user code, NCARG code, and the compiler runtime system.

  • Install NCARG/NCL from one of the modern package managers such as Macports or Conda. See NCL download documentation for Conda. This approach is my preferred solution.

  • Compile your own NCARG/NCL from source, with the same compiler version that is used with your own programs. Not recommended because with dependency libraries, this gets very complicated.

  • Compile your NCARG programs with gfortran 7, and link with the old Mac binary distributions that were built with gfortran 7. Not recommended because the old binary distributions may become incompatible with evolving support libraries.

Dave,

Thank you so much for the information. You were right. The compiler version is the source.

Yuanfu