Global Warming - GCM Model-E
Modifications to run on Windows XP
GCM Model-E was written to run on Unix systems.
This page records what was needed to make the program compile and run under
Windows XP.
Downloads
| Preprocessing Directives
| File Order
| SYSTEM.f
| Compile Errors
| Running the Model
| Output File
| Debug Notes
Downloads
The
model source code
(modelE1.tar.gz)
was downloaded and uncompressed (via 7-Zip).
Because the model source is written in Fortran,
I downloaded and installed
gfortran,
the free GNU Fortran compiler.
Using commands similar to the following (with the appropriate source file names added),
I run the compiler in a DOS window (at a command prompt) so that I can see the errors.
"C:\Program Files\gfortran\bin\gfortran.exe" -o C:\GW_Model\modelE1\modelE1_pub\decks\test.exe -cpp
-DMACHINE_XP -DCONVERT_BIGENDIAN -O2 "a very long list of files goes here, the order is important"
|
For this command, it is important that the current directory is the one with the Fortran source files.
cd C:\GW_Model\modelE1\modelE1_pub\model
|
Preprocessing Directives
Many of the source files contain
preprocessor directives of the form
#include "rundeck_opts.h"
#if (defined TRACERS_ON) || (defined TRACERS_OCEAN)
call alloc_tracer_com(grid)
#ifdef TRACERS_SPECIAL_Lerner
call alloc_tracer_special_lerner_com(grid)
call alloc_linoz_chem_com(grid)
#endif
#endif
|
By default, gfortran processes these based on the filename extension.
With capital-F, they are processed, with lower case-f, they are not
and they produce errors.
The solution was to activate the preprocessor for all files regardless
of the extension by using the -cpp command line flag.
gfortran.exe -cpp filename1.f filename2.f ...
|
That worked except that rundeck_opts.h
was not found.
Since *.h files are typically c header files,
I simply deleted those lines.
I later found out that rundeck_opts.h was
created by the scripts before calling the compiler -
it is used to force a recompile
when tracers are enabled and disabled (I think).
At any rate, I should have simply created an empty file
and not modified the code.
File Order
The order that the files are compiled in is important.
This is a typical error ... fixed by controlling the compile order.
MODEL_COM.f:216.72:
USE DOMAIN_DECOMP, ONLY : DYN_GRID
1
Fatal Error: Can't open module file 'domain_decomp.mod' for reading
at (1): No such file or directory
|
Precompiled source files are included via statements similar
to the following.
USE FILEMANAGER, only : openunit,closeunit,openalias
USE PARAM
|
The first explicitly specifies what is used,
the second allows the use of everything that is available.
I spent time looking, but
never found a way to supply a file with the filenames in it.
Therefore, I had to place the file names on the command line.
The provided scripts did this automatically
(based on the contents of the rundeck),
but since they would not run on Windows, I had to do this manually.
The procedure was to
add one file at a time and see what modules were not found.
Then add the missing modules in the correct order (also, one at a time)
and repeat.
I started with a few files that do not rely on others.
- Add a new filename to the compile string
- Compile
- Use AgentRansack to search for the missing module
- Repeat
In many languages, the module name and filename have to be the same ...
with one module per file.
However, Fortran does not follow that convention.
Therefore it is
necessary to use a program like AgentRansack to search all the source files.
For instance
Both CLOUDS.f and CLOUDS2.f contain
MODULE CLOUDS
... code here
END MODULE CLOUDS
|
Therefore, only one of these files can be used.
DIAG_PRT.f contains 3 separate modules.
This order works
PARAM.f SYSTEM.f UTILDBL.f DOMAIN_DECOMP.f GEOM_B.f FFT72.f CONST.f
SNOW.f SNOW_DRV.f ATMDYN_COM.f QUSDEF.f QUS_DRV.f QUS_COM.f FLUXES.f
LAKES_COM.f LAKES.f SEAICE.f SEAICE_DRV.f PBL.f PBL_COM.f PBL_DRV.f
VEGETATION.f VEG_COM.f VEG_DRV.f GHY_COM.f GHY.f GHY_DRV.f
CLOUDS2.f CLOUDS_COM.f CLOUDS2_DRV.f LANDICE.f LANDICE_DRV.f RES_M12.f
MODEL_COM.f RAD_COM.f DIAG_COM.f RAD_DRV.f RADIATION.f DIAG.f PARSER.f
MODELE.f DEFACC.f IORSF.f OCEAN.f OCNML.f DIAG_PRT.f ATURB.f
ICEDYN.f ICEDYN_DRV.f POUT.f TQUS_DRV.f ATMDYN.f MOMEN2ND.f SURFACE.f ALLOC_DRV.f
|
SYSTEM.f
SYSTEM.f contains code that is system or compiler dependent
- Compute random numbers
- Get the system time
- Stop the program
- And the like
It is configured via preprocessor commands similar to
#if defined(MACHINE_SGI) || defined(MACHINE_Linux) || defined(MACHINE_DEC)
|| defined(MACHINE_MAC) || defined(MACHINE_XP)
|
I added several MACHINE_XP entries.
Since I didn't know what would work, I just guessed.
To make this work,
was added to the command line.
Note: I originally tried to use just -DXP, but the compile failed
because every place the variable XP appeared in the code
was replaced with the number 1.
was compiled as
Compile Errors
Several additional files would not compile without source code modification.
These are most likely do to differences in how compilers
handle certain syntax.
It is possible that these problems could have been fixed by setting
some command line parameter, but I modified the code as follows.
PBL.f and PBL_DRV.f
Apparently, some compilers allow line numbers to appear on any valid statement.
However, gfortran would not compile until I changed the code to the following
in both files.
go to 100
...
100 continue
end do
|
DIAG.f
Apparently, some compilers support some type of variable substitution.
USE MODEL_COM, only :
& im,imh,fim,byim,jm,jeq,lm,ls1,idacc,ptop,psfmpt,jdate,
& mdyn,mdiag, ndaa,sig,sige,dsig,Jhour,u,v,t,p,q,wm,km=>lm
|
To fix this, I had to explicitly declare and initialize km and to add lm
to the list.
USE MODEL_COM, only :
& im,imh,fim,byim,jm,jeq,lm,ls1,idacc,ptop,psfmpt,jdate,
C & mdyn,mdiag, ndaa,sig,sige,dsig,Jhour,u,v,t,p,q,wm,km=>lm removed 11-04-08
& mdyn,mdiag, ndaa,sig,sige,dsig,Jhour,u,v,t,p,q,wm,lm
INTEGER :: km
c added 11-04-08 rlc
km = lm
|
What's weird is that the *a=>b* syntax is used in lots of files,
but only this one has a problem.
MODEL.f
iargc is used to read the command line parameters.
Apparently, some versions of Fortran require (or allow) iargc
to be defined as an external value -
gfortran does not allow that syntax.
I had to comment out the following
integer, external :: iargc
|
like this
c integer, external :: iargc 11-04-08 rlc - no external reference
|
Summary
In all, 5 files had to be modified for the model to compile.
SYSTEM.f
| | Needed the computer system added to the #IF statements
|
PBL.f, PBL_DRV.f
| | Fixed bad branches
|
DIAG.f, MODEL.f
| | Had compiler dependent code
|
Running the Model
The output of the compiler is an *.exe file
- the precise name is specified using the -o filename
command line option.
To run this file, you must supply the name of the rundeck
(initial parameter file) on the command line.
C:\GW_Model\modelE1\modelE1_pub\decks\test2.exe -i my_run.R
|
At this point, the program compiled and ran ...
but terminated with a "file not found" error ...
without any indication of what file was not found.
FILEMANAGER: FILE OPENING ERROR
|
Output File
Unix programs write to standard output ...
which can be redirected to a file
via the command line redirection operator.
From runpmE (perl script)
./$runID.exe < Ix > $runID.PRT.dt$dt.$date; rc=\$?
|
From pdE (shell script)
$RUNDIR/${runID}.exe -i Ipd $* < Ipd > pd.PRT
|
Windows also supports the redirection operator when running a program from the
command prompt, but not when running via a shortcut link.
Therefore, I added the following to MODELE.f.
open(6, file="Startup_Info.txt")
|
Note: The first time I ran the model, it immediately quit without any indication as to why.
I knew that a lot of error messages were written via
code similar to
write(6,*) 'some error message',variable1,variable2
|
which is why I made the code modification.
I later discovered that 6 referred to the standard output.
Debug Notes
Once the program compiled, and the output file was fixed,
the program quit again without indicating why in the output file.
Running directly from a command prompt
(instead of by clicking the link)
produced the following error.
At line 1839 of file SEAICE.f (unit = 51, file = 'GIC.E046D3M20A.1DEC1955')
Fortran runtime error: End of file
|
So, in debug mode,
I find it convenient to keep 2 command windows (DOS prompts) open
- One to compile the program
- One to run the program
Basic Source Code Modifications
describes
additional software and command line modifications
necessary get the model to run longer than a couple of seconds.
Author:
Robert Clemenzi