ROMS UNSW2008: Difference between revisions
No edit summary (change visibility) |
No edit summary (change visibility) |
||
(52 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<div class="title">Installing and Running ROMS for First Time Users | <div class="title">Installing and Running ROMS for First Time Users</div> | ||
''' | '''A tutorial for new ROMS users will be held at the UNSW Computer Labs on Monday 30 March 2009, immediately prior to the ROMS Sydney 2009 User Workshop at the Sydney Institute of Marine Sciences, 31 March to 2 April 2009.''' | ||
{{note}}''<span class="blue">This tutorial is intended for complete newcomers to ROMS. It assumes basic knowledge of working in a UNIX environment, and that the essential components required to compile and execute ROMS are already installed on the host computer network. This wiki page borrows heavily from David Robertson's excellent [[ROMS_Cygwin|Installing ROMS under Cygwin]] tutorial where you will find more information about setting up the required computing environment (compilers, libraries etc.) for ROMS.</span>'' | |||
In this tutorial, we cover how to download the code, configure it for an application, and run the model. Error messages that arise during the configuration process will be explained so that these can better be debugged when users return to their home institutions and try to work through this process again. | |||
'''A follow-on [[CSTMS_UNSW2008|tutorial discussing sediment in ROMS]] will be presented on Friday 03 April.''' | |||
{{note}}An important resource you should use as you get started is the [[Frequently_Asked_Questions | Frequently Asked Questions]] entry in [https://www.myroms.org/wiki WikiROMS]. | |||
{{note}}'''Note:''' In SVN revision 933 (January 26, 2019) all <span class="red">ocean_*.in</span> files were renamed to <span class="red">roms_*.in</span> and all <span class="red">ocean*</span> ROMS executables were renamed to <span class="red">roms*</span> in order to facilitate and clarify model coupling efforts. More information can be found in the ROMS repository [https://www.myroms.org/projects/src/ticket/794 Trac ticket #794]. If you are working with a ROMS release prior to revision 933 you will need to replace <span class="red">roms_upwelling.in</span> with <span class="red">ocean_upwelling.in</span> and <span class="red">romsS</span>, <span class="red">romsM</span>, or <span class="red">romsO</span> with <span class="red">oceanS</span>, <span class="red">oceanM</span>, or <span class="red">oceanO</span> in all commands below. | |||
{{note}} | {{note}}'''Note:''' The build scripts have also changed names so '''<span class="red">build.bash</span>''' becomes '''<span class="red">build.sh</span>''' and '''<span class="red">build.sh</span>''' becomes '''<span class="red">build.csh</span>'''. | ||
__TOC__ | __TOC__ | ||
==Download ROMS== | ==Download ROMS== | ||
The disk space available on the UNSW Computer Lab machines is quite limited, so for the purposes of this tutorial we have downloaded the ROMS source code to '''<span class="red">/srv/ckpt/roms/shared/src</span>''' on host '''<span class="blue">matht001</span>'''. Instructions below will explain how to point the '''<span class="red">build.bash</span>''' script that compiles ROMS to this directory. | |||
'''To download the code to your own machine, these are the steps you would follow:''' | |||
== | :*You must have already registered on the ROMS portal and obtained your ROMS username/password as indicated in the [[ROMS_Cygwin#Register|Register]]. | ||
:*Create a <span class="red">src</span> folder where you will keep the ROMS source code. You can place this wherever you wish in your directory tree (here we assume under your home directory "<span class="forestGreen">~</span>") and name it whatever you like. | |||
::<div class="box"><span class="forestGreen">cd ~<br />mkdir src</span></div> | |||
:*Check out the ROMS source code replacing <span class="forestGreen">''bruce''</span> with the ROMS user name you registered with. | |||
::<div class="box"><span class="forestGreen">svn checkout --username bruce <nowiki>https://www.myroms.org/svn/src/trunk src</nowiki></span></div> Note the target directory <span class="forestGreen">src</span> at the end of the command. If your code ends up in the wrong place, you may have omitted this. | |||
You will see many lines stream by indicating the files that are being added to your src directory. When it finishes, you can type <span class="forestGreen">ls src</span> to see the contents of the directory. | |||
To see the contents of the directory where the code is downloaded for this tutorial, type this: | |||
::<div class="box"><span class="forestGreen">cd /srv/ckpt/roms/shared<br />ls src</span></div> | |||
==Customize the [[build Script|Build Script]]== | |||
The ROMS source code comes with a [[build Script|build script]] in the <span class="red">ROMS/Bin</span> directory. Examples written with <span class="forestGreen">bash</span> (<span class="red">build.bash</span>) and <span class="forestGreen">csh</span> (<span class="red">build.sh</span>) are provided. The UNSW Computer Lab machines are configured to use <span class="forestGreen">bash</span> as the default login shell, so we will work with <span class="red">build.bash</span>. A full description of the build script can be found [[build Script|here]]. | The ROMS source code comes with a [[build Script|build script]] in the <span class="red">ROMS/Bin</span> directory. Examples written with <span class="forestGreen">bash</span> (<span class="red">build.bash</span>) and <span class="forestGreen">csh</span> (<span class="red">build.sh</span>) are provided. The UNSW Computer Lab machines are configured to use <span class="forestGreen">bash</span> as the default login shell, so we will work with <span class="red">build.bash</span>. A full description of the build script can be found [[build Script|here]]. | ||
:*In your home directory | :*In your home directory (you can use some other directory to organize your ROMS projects if you wish) create a new folder named <span class="red">Projects</span> and change into it. | ||
::<div class="box"><span class="forestGreen">mkdir Projects<br />cd Projects</span></div> | ::<div class="box"><span class="forestGreen">cd ~<br />mkdir Projects<br />cd Projects</span></div> | ||
:*Create a folder named <span class="red">Upwelling</span> and change | :*Create a folder named <span class="red">upwelling</span> and change into it. ROMS is distributed with several [[Test Cases|Test Cases]] and the [[UPWELLING_CASE|Upwelling example]] is the default which we will compile and run here. | ||
::<div class="box"><span class="forestGreen"> | ::<div class="box"><span class="forestGreen">mkdir upwelling<br />cd upwelling</span></div> | ||
:*Copy the <span class="red">build.bash</span> file distributed with ROMS to your <span class="red">Projects/upwelling</span> directory. | |||
::<div class="box"><span class="forestGreen">cp /srv/ckpt/roms/shared/src/ROMS/Bin/build.bash .</span></div> | |||
Next we need to configure a few options inside <span class="red">build.bash</span> so that it finds the directories where the source code and your Project are located. | |||
:*Open the <span class="red">build.bash</span> script you just copied into your <span class="red">upwelling</span> directory using your preferred text editor, e.g. vi. | |||
::<div class="box"><span class="forestGreen">vi build.bash</span></div> | |||
:*Scroll down until you find <span class="orange">ROMS_APPLICATION</span>. You will notice it is set as follows: | |||
::<div class="box"> <span class="blue">export</span> <span class="red">ROMS_APPLICATION</span>=UPWELLING</div> We do not need to change this. But this is the first thing you will alter when starting your own project. This tells ROMS the name of an include file that will contain all the directives to the C-PreProcessor to configure your application at compile time. ROMS' rule is change this string to lowercase and append a ".h", so this will search for a file called <span class="red">upwelling.h</span>. It must be in the directory specified by <span class="orange">MY_PROJECT_DIR</span>: | |||
:*Scroll down until you find <span class="orange">MY_PROJECT_DIR</span> and set it as follows: | |||
::<div class="box"> <span class="blue">export</span> <span class="red">MY_PROJECT_DIR</span>=${<span class="red">HOME</span>}/Projects/upwelling</div> This obviously assumes you put <span class="red">Projects/upwelling</span> under your home directory. | |||
If you frequently move your ROMS project between hosts where you have a different directory structure, e.g. a temporary scratch space, you can use the <span class="orange">MY_ROOT_DIR</span> variable to minimize the changes you make to <span class="red">build.bash</span>. | |||
:*For example: | |||
::<div class="box"><span class="blue">export</span> <span class="red">MY_ROOT_DIR</span>=/usr/scratch/bruce<br /><span class="blue">export</span> <span class="red">MY_PROJECT_DIR</span>=${<span class="red">MY_ROOT_DIR</span>}/Projects/upwelling</div> | |||
Next we tell <span class="red">build.bash</span> where to find the ROMS source code downloaded from the svn repository (which you can keep up to date the <span class="forestGreen">svn update</span> command - see more on this at LINK ). Note that most of the source code changes you make to customize ROMS will be made in your Projects space, and need not be made to the downloaded code directly. We will discuss exceptions to this during the tutorial, and how source code modifications interact with svn. | |||
:*Set <span class="orange">MY_ROMS_SRC</span> to the location of the source code: | |||
::<div class="box"><span class="blue">export</span> <span class="red">MY_ROMS_SRC</span>=/srv/ckpt/roms/shared/src</div> In practise, you will probably do something more like this: | |||
::<div class="box"><span class="blue">export</span> <span class="red">MY_ROMS_SRC</span>=${<span class="red">MY_ROOT_DIR</span>}/src</div> assuming this is the relative path in which you keep your source code on the various machines you work on. | |||
Make sure that <span class="orange">MY_CPP_FLAGS</span> is '''not''' set. Sometimes this is set in the distributed build.bash exmaple. Comment out options with the # symbol like so: | |||
::<div class="box"><span class="blue">#export MY_CPP_FLAGS="-DAVERAGES"</span> </div> | |||
The UNSW Computer Lab machines are single core, so we need to tell <span class="red">build.bash</span> not to assume MPI parallel compilation. | |||
:*Comment out the options for <span class="orange">USE_MPI</span> and <span class="orange">USE_MPIF90</span> | |||
::<div class="box"><span class="blue">#export USE_MPI=on <br>#export USE_MPIF90=on</span> </div> | |||
:*If you were compiling in parallel you would leave the default entries in <span class="red">build.bash</span>. | |||
::<div class="box"><span class="blue">export</span> <span class="red">USE_MPI</span>=on<br /><span class="blue">export</span> <span class="red">USE_MPIF90</span>=on</div> | |||
:*We leave the compiler option as the default because this says use the <span class="forestGreen">ifort</span> (Intel FORTRAN) compiler which is what we want on the UNSW machines. | |||
::<div class="box"><span class="blue">export</span> <span class="red">FORT</span>=ifort</div> | |||
:*In the interests of speed for this tutorial, we turn off compiler optimization by activating the debug option: | |||
::<div class="box"><span class="blue">export</span> <span class="red">USE_DEBUG</span>=on</div>On the UNSW Lab machines compiling with optimization on will take over 15 minutes, but with optimization off (USE_DEBUG=on) it will be less than 60 seconds. | |||
Save and close the <span class="red">build.bash</span> file. | |||
==Copy the input and CPPDEFS options files== | |||
We need three more files in <span class="red">Projects/upwelling</span> to configure and run ROMS. We copy the versions downloaded with svn because these are files you will work with locally when you experiment with changes to the test case example configuration. | |||
:*Copy files <span class="red">ocean_upwelling.in, varinfo.dat</span> and <span class="red">upwelling.h</span> into the <span class="red">Projects/upwelling</span> directory you just created. | |||
::<div class="box"><span class="forestGreen">cd ~/Projects/upwelling<br />cp /srv/ckpt/roms/shared/src/ROMS/External/ocean_upwelling.in . <br>cp /srv/ckpt/roms/shared/src/ROMS/External/varinfo.dat . <br>cp /srv/ckpt/roms/shared/src/ROMS/Include/upwelling.h .</span></div> | |||
View the file <span class="red">upwelling.h</span>. It contains all the [[C_Preprocessor|C-Pre-Processor (CPP)]] options that the compiler interprets to activate certain source code options within ROMS. | |||
View the file <span class="red">ocean_upwelling.in</span>. It contains the inputs options that ROMS [[roms.in|reads from standard input]] at run time to set options that need not be fixed at compile time. | |||
View <span class="red">varinfo.dat</span>. The file [[varinfo.dat]] contains descriptions of the names and attributes of input and output variables that ROMS reads and writes from netcdf files. For most applications you will not need to change the entries in this file. If you need to know the default units assumed for different variables, those are noted in this file. (Before we run ROMS, we will need to tell it where to find this file). | |||
Now we are ready to compile ROMS by executing the <span class="red">build.bash</span> script. | |||
==Compile ROMS== | |||
Before you run ROMS, you need to compile it to create an executable <span class="red">oceanS</span> file ('''S''' for serial or single processor computer), or <span class="red">oceanM</span> file (if using '''MPI''' on a parallel computer). | |||
:*Go to your upwelling project directory: | |||
::<div class="box"><span class="forestGreen">cd ~/Projects/upwelling</span></div> | |||
:*Then type: | |||
::<div class="box"><span class="forestGreen">./build.bash</span></div> | |||
:*If lots of stuff comes on the screen then compilation is proceeding, and make take some time. | |||
:*If the build process ends quickly with an error, then it is likely that <span class="red">build.bash</span> does not point to the correct location for the <span class="red">upwelling.h</span> file, the FORTRAN compiler, or some libraries. We describe common ''getting started'' errors and solutions in the next section. | |||
:*You may give the option <span class="forestGreen">-j</span> to the build command to distribute the compilation to multiple processors if your host supports this, e.g.: | |||
::<div class="box"><span class="forestGreen">./build.bash -j 8</span></div> to compile on 8 processor at once. | |||
If your build was successful it will not have reported any errors, and there will be an executable file in your <span class="red">Projects/upwelling</span> directory called <span class="forestGreen">oceanG</span>. The <span class="forestGreen">"G"</span> in the file name indicates <span class="red">build.bash</span> activated the <span class="blue">USE_DEBUG</span> option. | |||
If <span class="blue">USE_DEBUG</span> were not selected, the executable would be <span class="forestGreen">oceanS</span>, where the <span class="forestGreen">"S"</span> indicates "serial" or "single-processor" because we deactivated MPI. | |||
If you had activated MPI with the <span class="blue">USE_MPI</span> option the executable would be named <span class="forestGreen">oceanM</span>. | |||
(See also [[Frequently_Asked_Questions#My_build_finished_with_no_errors._Where_is_the_ROMS_executable.3F|FAQ: My build finished with no errors, where is the ROMS executable?]]). | |||
===Common ''getting started'' compile error messages=== | |||
Getting past the first few errors with compilation is often tricky. Carefully read any error messages you get for clues on what might be wrong with your configuration. Here are some common difficulties new users encounter getting started when first executing the <span class="red">build.bash</span> command. | |||
:*<div class="box">Compilers/../ROMS/Include/cppdefs.h:709:22: <br>error: /student/0/a0000020/Projects/upwelling/upwelling.h: No such file or directory</div> This says the file <span class="red">upwelling.h</span> is not where Build expects it to be, which is in <span class="orange">MY_PROJECT_DIR</span>. You set this to <span class="red">~/Projects/upwelling</span>. | |||
:*<div class="box">cp: cannot stat `/opt/intelsoft/netcdf/include/netcdf.mod': No such file or directory</div> This says that netcdf is not where build.bash expects to find it. Locate where the netcdf include and lib directories with steps something like:<div class="box"><span class="forestGreen">cd /usr <br>find . -name netcdf.mod -print<br></span> ./local/netcdf-3.6.2/include/netcdf.mod <br> ./local/netcdf/intel/3.6.3/include/netcdf.mod</div>This tells us the most recent (3.6.3) netcdf is in <span class="red">/usr/local/netcdf/intel/3.6.3</span>. Direct ROMS to this location by making two changes to <span class="red">build.bash</span>. First, advise ROMS to read your changes to the default library path by uncommenting the option for <span class="orange">USE_MY_LIBS</span>. | |||
::<div class="box"><span class="blue">export</span> <span class="red">USE_MY_LIBS</span>=on</div> Then specifiy the correct location for netcdf: | |||
::<div class="box"><span class="blue">export</span> <span class="red">NETCDF_INCDIR</span>=/usr/local/netcdf/intel/3.6.3/include<br /><span class="blue">export</span> <span class="red">NETCDF_LIBDIR</span>=/usr/local/netcdf/intel/3.6.3/lib</div> {{warning}} Be careful where you make this change. You need to make it for the <span class="forestGreen">ifort</span> compiler option, and NOT for the <span class="orange">USE_NETCDF4</span> option (we are using netcdf-3). If you've done this correctly, your compilation with <span class="red">build.bash</span> should now succeed. | |||
:*<div class="box">error <br>error: </div> Note here further errors we encounter during the tutorial. | |||
==Run ROMS== | |||
You run ROMS by executing the <span class="forestGreen">oceanG</span> (or <span class="forestGreen">oceanS</span>) binary, giving it the <span class="red">ocean_upwelling.in</span> file as UNIX standard input. | |||
::<div class="box"><span class="forestGreen">./oceanS < ocean_upwelling.in</span></div> ROMS standard output will be typed to the screen. To save it a file instead, enter, e.g.: | |||
::<div class="box"><span class="forestGreen">./oceanS < ocean_upwelling.in > my_upwelling.log </span></div> | |||
If you have compiled a parallel (MPI) executable, the syntax for running the mode is slightly '''but critically''' different. The <span class="red">ocean_upwelling.in</span> file is no longer read from UNIX standard input (it has handled by all the MPI threads) so the <span class="forestGreen">"<"</span> disappears from the command, and you need the correct syntax on your UNIX host for running an MPI process. It is probably something like: | |||
::<div class="box"><span class="forestGreen">mpirun -np 8 ./oceanM ocean_upwelling.in > my_upwelling.log</span></div> where the <span class="forestGreen">"-np 8"</span> indicates use 8 processors and this number of tiles must have been set by | |||
(See also [[Frequently_Asked_Questions#What_do_I_have_to_do_to_run_an_application.3F | FAQ: What do I have to do to runs ROMS?]]). | |||
===Common ''getting started'' run error messages=== | |||
::<div class="box">bash: oceanG: command not found</div>The working directory is not in your UNIX path. That's why we type "dot-slash" in front of the commands above. | |||
==Successful execution== | |||
===Standard Output=== | |||
When ROMS runs it will type a lot of information to UNIX standard output. This is the "logfile" you named following the ">", or your terminal if you did not redirect stdout. | |||
STDOUT shows the following: | |||
:*UNIX process info, run time, run TITLE | |||
::<div class="box"> Process Information: <br> Thread # 0 (pid= 4449) is active. <br> Model Input Parameters: ROMS/TOMS version 3.2 <br> Monday - March 23, 2009 - 10:02:39 AM <br>----------------------------------------------------------- <br> Wind-Driven Upwelling/Downwelling over a Periodic Channel</div> | |||
:*OS, compiler information, SVN version, and your MY_ROMS_SRC, MY_HEADER_DIR and ROMS_APPLICATION settings | |||
::<div class="box">Operating system : Linux<br>CPU/hardware : i686<br>Compiler system : ifort <br>Compiler command : /usr/local/intel/fc/10.1.021/bin/ifort <br>Compiler flags : -heap-arrays -ip -O3 -pc80 -xW -free<br><br>SVN Root URL : <nowiki>https://www.myroms.org/svn/src/trunk</nowiki><br>SVN Revision : 333<br>Local Root : /srv/ckpt/roms/shared/src<br>Header Dir : /student/0/a0000020/srv/Projects/upwelling<br>Header file : upwelling.h<br>Analytical Dir: /student/0/a0000020/srv/Projects/upwelling<br><br>Resolution, Grid 01: 0041x0080x016, Parallel Threads: 1, Tiling: 001x001</div>Check that these are what you intended. In last line above | |||
::*"Grid 01" pertains to future ROMS developments with multiple nested/connected grids, | |||
::* 0041x0080x016 shows the grid size is 41 x 80 x 16 grid points in the K,J,I directions | |||
::* The Parallel/Tiling message shows you are using a single process and a single domain tile. When using MPI, this message will describe how many tiles you are using and the MPI processes assigned. | |||
:*Input parameters set in <span class="red">ocean_upwelling.in</span> | |||
::<div class="box">Physical Parameters, Grid: 01<br>=============================<br><br> 288 ntimes Number of timesteps for 3-D equations.<br> 300.000 dt Timestep size (s) for 3-D equations.<br> 30 ndtfast Number of timesteps for 2-D equations between<br> each 3D timestep.<br> ...<br> Output Averages File: ocean_avg.nc<br> Output Diagnostics File: ocean_dia.nc</div> | |||
:*Then some more about the tiling when running in parallel | |||
:*The C-PreProcessor (CPP) flags set in <span class="red">upwelling.h</span> but '''AS MODIFIED''' by ROMS when interpreting and checking the selected CPP options. | |||
::<div class="box"> Activated C-preprocessing Options:<br><br> UPWELLING Wind-Driven Upwelling/Downwelling over a Periodic Channel<br> ANA_BSFLUX Analytical kinematic bottom salinity flux.<br> ANA_BTFLUX Analytical kinematic bottom temperature flux.<br> ANA_GRID Analytical grid set-up.<br> ANA_INITIAL Analytical initial conditions.<br> ...</div>You should check that the CPP options displayed here agree with what you intended. For example, if you inadvertently specify more than one horizontal advection scheme option, ROMS will have chosen only one and reported that option here. | |||
:*The preamble in STDOUT continues with information about the space and time discretization: grid spacing, grid volume, Courant number (time step stability) and stiffness (related to s-coordinate accuracy). | |||
:*Then the model starts time stepping: | |||
::<div class="box">NL ROMS/TOMS: started time-stepping: (Grid: 01 TimeSteps: 00000001 - 00000288)<br><br> STEP Day HH:MM:SS KINETIC_ENRG POTEN_ENRG TOTAL_ENRG NET_VOLUME<br><br> 0 0 00:00:00 0.000000E+00 6.579497E+02 6.579497E+02 3.884376E+11<br> DEF_HIS - creating history file: ocean_his.nc<br> WRT_HIS - wrote history fields (Index=1,1) into time record = 000000<br> DEF_AVG - creating average file: ocean_avg.nc<br> DEF_DIAGS - creating diagnostics file: ocean_dia.nc<br> 1 0 00:05:00 3.268255E-13 6.579497E+02 6.579497E+02 3.884376E+11<br> 2 0 00:10:00 6.503587E-12 6.579497E+02 6.579497E+02 3.884376E+11<br> 3 0 00:15:00 4.592307E-11 6.579497E+02 6.579497E+02 3.884376E+11<br><br> ...</div>This output indicates several things: | |||
::*the run is programmed to run from time step 1 to 288 | |||
::*the run starts at time 00:00:0 | |||
::*netcdf output HISTORY, AVERAGES and DIAGNOSTICS files are created. Every time ROMS creates a new netcdf file, and writes to an existing file, it reports this to STDOUT | |||
::*output is written to the HISTORY file | |||
::*then global quantities related to the model KE, PE and domain volume are reported on each time step | |||
{{note}} In 99% of situations, ''getting started'' problems with model set-up and configuration can be diagnosed by carefully reading the STDOUT above. Things to look for are: | |||
:*misconfigured CPP options (what you got is not what you thought you asked for) | |||
:*parameter errors (e.g. you activated horizontal mixing but left the coefficient as zero) | |||
:*misnamed output files (that's why the files from your last run got overwritten) | |||
:*irrational choices of grid spacing or time step | |||
:*initial/boundary/forcing data being read from the wrong file, or not read at all (because you selected analytical conditions) | |||
At the conclusion of the run, ROMS reports information about run time: | |||
::<div class="box"> Elapsed CPU time (seconds):<br><br> Thread # 0 CPU: 108.079<br> Total: 108.079<br><br>Nonlinear model elapsed time profile:<br><br> Initialization ................................... 0.016 ( 0.0148 %)<br> Processing of input data ......................... 0.028 ( 0.0259 %)<br> Processing of output time averaged data .......... 4.312 ( 3.9899 %)<br> ... </div> | |||
:*about the number of output records written to each file | |||
::<div class="box"> ROMS/TOMS - Output NetCDF summary for Grid 01: <br> number of time records written in HISTORY file = 00000005 <br> ...</div> | |||
:*and the analytical files included | |||
::<div class="box"> Analytical header files used:<br><br> ROMS/Functionals/ana_btflux.h<br> ROMS/Functionals/ana_grid.h<br> ...</div>If you used a modified analytical file in your <span class="orange">MY_HEADER_DIR</span> it will be reported here and is another thing you should check for consistency with your intentions. | |||
===Netcdf file output=== | |||
As reported above, ROMS created 4 output netcdf files when it ran. There are ocean_his.nc, ocean_avg.nc, ocean_dia.nc, and coean_rst.nc. These are, respectively: | |||
:*history records or 'snapshots' of the model state a selected time intervals | |||
:*averages of the model state over selected intervals (not necessarily the same intervals as the history) | |||
:*diagnostics of the model state, the precise contents of which are controlled by CPP options | |||
:*a restart file with everything ROMS needs to restart a application. This is useful if your job crashes at some point and you want to recommence from a previous state without starting over. Typically the restart file is set to keep just 2 time records by continually over-writing the oldest as the run proceeds. This behaviour is controlled in ocean_upwelling.in. Also, when ROMS "blows up" it dumps the ocean state to a 3rd record in the restart file. | |||
You can browse the contents of netcdf files at the UNIX command line with the command ncdump, e.g. | |||
::<div class="box"><span class="forestGreen">ncdump -h ocean_his.nc | more</span> </div> | |||
Note the use of the <span class="forestGreen">"-h"</span> option. This restricts the output from ncdump to be just the header information, or metadata, in the netcdf file. Without the "-h" option you will get the entire contents of the file converted to ascii. | |||
Things to notice when you ncdump the ocean_his.nc file are that it contains all the input parameters (time step, mixing coefficients, s-coordinate parameters, etc.) from roms.in, the model grid coordinates (x, y, lon, lat, depth, Coriolis parameter, etc.) which may have been computed by the ANA_GRID option or read from an input grid netcdf file, in addition to the actual model output (ocean_time, zeta, u, v, temp, salt). | |||
There are netcdf '''global attributes''' that echo much of the information typed to STDOUT. This includes compiler, svn version, and project directory information, and all the CPP options. This is a valuable source of information when returning to a project and trying to figure out what you did! The global attributes metadata show precisely which options were activated when creating the output in this netcdf file. | |||
==Changing the UPWELLING test case configuration== | |||
===Compile time changes: <span class="red">upwelling.h</span>=== | |||
Changes to options that must be set at compilation time are made to the upwelling.h file. These settings are interpreted during the C-PreProcessing step. | |||
To see what the present options are, edit the upwelling.h file: | |||
::<div class="box"><span class="forestGreen">vi upwelling.h</span></div> | |||
Recall that the actual options active after this file in interpreted will be typed to STDOUT (the "logfile") and also written to the output netcdf file in the global attributes. | |||
To see the all the options that might be set using C-PreProcessor directives, you can browse the <span class="forestGreen">cppdefs.h</span> file in the <span class="red">ROMS/Include</span> directory underneath the <span class="orange">MY_ROMS_SRC</span> location set in your build.bash. In this case: | |||
::<div class="box"><span class="forestGreen">cd /srv/ckpt/roms/shared/src<br>more ROMS/Include/cppdefs.h</span></div> | |||
The contents of this file are almost entirely comments and are provided to document the options available. For more information consult WikiROMS or the User Forum. | |||
At the very bottom of <span class="red">cppdefs.h</span> you will see a short code segment that loads the actual application options from ROMS_HEADER. This variable is set by the <span class="orange">ROMS_APPLICATION</span> value in build.bash. | |||
===Run time changes: <span class="red">ocean_upwelling.in</span>=== | |||
Changes to options that are set at run time are made to the ocean_upwelling.in file. | |||
To see what the present options are, edit the ocean_upwelling.in file: | |||
::<div class="box"><span class="forestGreen">vi ocean_upwelling.in</span></div> | |||
Comments at the beginning of this file document the <span class="blue">KEYWORD <nowiki>==</nowiki> value</span> syntax. | |||
Comments at the end of file provide brief summaries of what each parameter does. | |||
For more information consult WikiROMS or the Use Forum. | |||
Recall that the actual parameter values ROMS uses after reading this file will be typed to STDOUT (the "logfile") and also written to the output netcdf files. | |||
==A ''Realistic'' model example: LaTTE== | |||
<span class="red">THIS TEST CASE IS WAY OUT OF DATE AND ALMOST CERTAINLY WON'T WORK WITH A RECENT VERSION OF ROMS. IT NEEDS UPDATING. UNTIL I GET TO THAT, TREAT THIS SECTION AS A GUIDELINE ON THE BASIC STEPS TO CREATING A REALISTIC APPLICATION, BUT DON'T PERSEVERE TRYING TO RUN IT.</span> | |||
This section of the tutorial assumes you have successfully compiled and run the UPWELLING example above. Key concepts you should be comfortable with before you proceed are: | |||
:*you need a new directory where you will keep the files specific to the new application | |||
:*customize <span class="red">build.bash</span> for the new application (copy the build.bash from <span class="red">upwelling</span> because it has all the correct compiler and library settings) | |||
:*set <span class="blue">MY_PROJECT_DIR</span> in <span class="red">build.bash</span> to point to the directory for the new application | |||
:*set <span class="blue">ROMS_APPLICATION</span> in <span class="red">build.bash</span> to the correct name for the new application | |||
:*if you wish to customize any of the <span class="forestGreen">ana_*.h</span> files, copy just the ones you need into the new project directory | |||
:*you '''don't''' need to make a copy the source code a new application | |||
With these concepts in mind, we proceed by configuring ROMS to run a realistic coastal ocean application that includes open boundaries on 3 sides, open boundary tides and climatological open boundary velocity and tracer (temperature and salinity) conditions, surface meteorological forcing, and initial conditions, all provided by input netcdf files. | |||
The example is called LaTTE_C because it simulates ocean conditions during the '''Lagrangian Transport and Transformation Experiment''' conducted on the New Jersey inner shelf in the Spring of 2006. The '_C' denotes a coarse resolution configuration suitable for this training exercise. | |||
===Create a latte_c project directory=== | |||
We have placed the CPP options file <span class="red">latte_c.h</span>, standand input <span class="red">ocean_lattec.in</span>, and a modified <span class="red">varinfo.dat</span> in <span class="red">/srv/ckpt/roms/shared/latte_c/Forward</span>. Make a new Project directory for this new application and copy these 3 files. '''DO NOT''' copy all the netcdf files from <span class="red">/srv/ckpt/roms/shared/latte_c/in | |||
</span>. | |||
===Edit build.bash=== | |||
Set the correct entries for environment variables that define the user application. | |||
<span class="blue">ROMS_APPLICATION=LATTE_C</span> causes <span class="red">build.bash</span> to look for the file <span class="red">latte_c.h</span> in order to set the CPP options | |||
<span class="blue">MY_PROJECT_DIR=${HOME}/Projects/latte_c</span> will instruct build.bash where to look for the latte_c.h file. | |||
Setting <span class="blue">MY_HEADER_DIR</span> would instruct ROMS where to look for the user functional files <span class="red">ana_*.h</span> that over-ride default options. In this example, however, we don’t actually need to modify any of those functionals. This is typical of “realistic” applications where input grid, initial and boundary conditions are provided from data in input netcdf files. | |||
{{note}}The format of ROMS output files (history, averages and restart) is the same as ROMS input initial conditions and climatology. This means the output of previous runs can become the initial conditions, or 3-D climatology (for nudging) for new runs. | |||
===Edit ocean_lattec.in=== | |||
Open the ocean_lattec.in file in an editor. There are KEYWORDS that define the names of the input netcdf files for applications of this type: | |||
:*GRDNAME is the grid file with coordinates, grid metrics (spacing), bathymetry, land/sea mask and Coriolis | |||
:*ININAME is the initial conditions | |||
:*BRYNAME are the open boundary sea leve, velocity and tracer conditions | |||
:*FRCNAME are the tides, river source, and surface meteorological forcing files. Notice there are multiple files and the number of files ROMS is to read is set by the NFFILES parameter. On initialization, ROMS scans this list for each forcing variable it needs, using the first file to contain the necessary and ''shadowing'' any entry in subsequent files. Therefore if you want to re-run your model with a new set of wind data but happen to have other wind data in a files with all your other meteorology inputs, just put the new file at the beginning of the list. | |||
There are KEYWORDS that determine the output file names. These are: | |||
:*RSTNAME, HISNAME, AVGNAME, DIANAME, STANAME, FLTNAME .... etc | |||
There are keywords that set how many time steps ROMS takes between writing output. These are: | |||
:*NRST,NHIS,NAVG,NDIA,NSTA ...etc | |||
You can have ROMS write multiple records to each output file at these intervals, but periodically create a new file (to keep file sizes manageable) by setting the keywords: | |||
:*NDEFHIS,NDEFAVG,NDEFDIA | |||
===Compile with build.bash=== | |||
If you have set the entries in build.bash correctly, you compile exactly as before by executing the script. | |||
Watch the output of the build process. You should see that instead of "Project/upwelling/Build" the compilation is now writing temporary files to "Project/latte_c/Build". This Build subdirectory is kept separate so you can be working on two projects at once and not confuse things. | |||
cd to the Build subdirectory and look at some of the files there, e.g. | |||
::<div class="box"><span class="forestGreen">cd ~/Projects/latte_c/Build<br>more u3dbc_im.f90</span></div> | |||
This is the file that sets open boundary conditions on 3-d velocity. This is the Fortran90 file that is generated after the C-PreProcessor has done its job. If you find your model is doing things you don't expect, it can be instructive to view the <span class="forestGreen">".f90"</span> file and corresponding <span class="forestGreen">".F"</span> (in MY_ROMS_SRC) to see whether the CPP options being processed are what you intended. If not, review your header file (in this case latte_c.h), and the list of CPP options typed to STDOUT. Don't edit the "f90" file directly because it gets over-written when you recompile. | |||
==Before we run latte_c== | |||
===Browse the latte_c.h options=== | |||
Use <span class="forestGreen">vi</span> or <span class="forestGreen">more</span> to browse the CPP options used in this "realistic" application. Things to notice that are different from <span class="red">upwelling.h</span> are: | |||
:*There are no <span class="blue">ANA_INITIAL</span> or <span class="blue">ANA_WINDS</span> options. If analytical initial and forcing options are not set with a <span class="blue">#define</span> then ROMS defaults to reading this information from input netcdf files. | |||
:*<span class="blue">WEST_, EAST_, SOUTH_</span> and <span class="blue">NORTHERN_WALL</span>. These options define the open boundary schemes. (The nomenclature of the compass points assume a grid oriented with west along ''i=1'' and south along ''j=1''). The upwelling case had closed boundaries to the north and south, and periodic conditions east-west. The open boundary conditions here are set with the following options: | |||
:*<span class="blue">WEST_FSCHAPMAN,WEST_M2FLATHER</span> etc. indicate “west” side free surface (FS) and depth-averaged velocity/momentum (M2) | |||
:*<span class="blue">WEST_M3GRADIENT,WEST_TGRADIENT</span> “west side” 3-d velocity/momentum (M3) and all tracers. | |||
:*<span class="blue">SSH_TIDES, UV_TIDES</span> cause ROMS to add tidal variability in sea level and depth-average velocity using the harmonics read from the tides forcing file. See the wikiROMS entry on tides for more information. | |||
:*<span class="blue"><nowiki>#</nowiki>ifdef SSH_TIDES<br> #define ADD_FSOBC</span><br>This construct is a conditional test that causes prescribed mean or slowly varying sea surface height to be added to the tidal variability. <br> The further option <span class="blue">ANA_FSOBC</span> means the prescribed value is set by one of the analytical functional include files. If <span class="blue">ANA_FSOBC</span> is not defined, ROMS will look for the boundary sea level in a boundary conditions file. | |||
:*<span class="blue">BULK_FLUXES</span> In this application the surface meteorology forcing files give net shortwave and longwave radiation and the temperature, pressure and humidity conditions in the marine atmospheric boundary layer. These values are converted to air-sea fluxes of heat and momentum according to the Fairall et al. bulk formulae. | |||
:*<span class="blue">GLS_MIXING</span> This activates the Generalized Length Scale vertical turbulence closure parameterization of Umlauf and Buchard. Parameters in ocean_lattec.in determine details such as whether the closure method is actually k-epsilon, k-kl, etc. | |||
:*<span class="blue">UV_PSOURCE, TS_PSOURCE</span> These options activate point sources; in this case the inflow of the Hudson River. | |||
===The input netcdf files=== | |||
Use ncdump to browse the contents of some of the input files, e.g.: | |||
::<div class="box"><span class="forestGreen">ncdump -h frc_lattec_wrf_Pair.nc | more</span></div> | |||
We see that in this case the dimensions of the data match the dimensions of the ROMS grid: | |||
::<div class="box">dimensions:<br> time = UNLIMITED ; // (1560 currently)<br> eta_rho = 82 ;<br> xi_rho = 146 ;</div>For '''time varying 2D surface forcing data only''' (e.g. meteorological data) ROMS will regrid during execution 2D data defined on simple 1D coordinates (vectors of lon and lat). In all other cases, the forcing data must have already been interpolated to the ROMS grid. | |||
ROMS associates the variable name of the forcing data with the appropriate internal variable by consulting the entries in varinfo.dat. Edit varinfo.dat and search for the string "Pair" | |||
::<div class="box"><span class="forestGreen">vi varinfo.dat</span></div> | |||
::<div class="box">'Pair' ! Input<br> 'surface air pressure'<br> 'millibar' ! [millibar]<br> 'Pair, scalar, series'<br> 'pair_time'<br> 'idPair'<br> 'r2dvar'<br> 1.0d0</div>This tells us 3 important things: | |||
::*The name of the surface air pressure variable in the forcing netcdf is "Pair". If your netcdf file was made with some other name you can change it here, e.g. "press_sfc" and you DO NOT need to change the netcdf file. This is acceptable because the variable is strictly an ''Input'' variable as noted by the comment <nowiki>(! Input)</nowiki> at the end of the first line. | |||
::*The units are assumed to be millibars. If your data are not in millibars you must either modify the data in the forcing netcdf file, or you may apply a scalar factor by editing the last line in the block above (presently set to 1.0d0). | |||
::*The Pair data are defined at the times recorded by the variable named "pair_time" in the same forcing netcdf file. '''However''', in the netcdf file itself this default can be reset by adding a "time" attribute to Pair. Return to viewing the netcdf file with ncdump to see this: | |||
::<div class="box">variables:<br> double Pair(time, eta_rho, xi_rho) ;<br> Pair:long_name = "Surface air pressure" ;<br>...<br> Pair:time = "ncep_time" ;<br> double ncep_time(time) ;<br> ncep_time:long_name = "forcing observations time" ;<br> ncep_time:units = "days since 01-Jan-2006" ;</div>The "time" attribute "Pair:time" indicates that variable "ncep_time" in this file contains the times at which the air pressure is reported. This overrides the value in varinfo.dat. The units attribute to ncep_time shows the CF convention of "days since 2006-01-01 00:00:0". This time base must match in ALL your forcing netcdf files AND the initial conditions file. ROMS '''will not enforce consistency between different time conventions''' - that would be nice but for now it's on you. (Nor will the ''TIME_REF'' keyword in roms.in adjust this time - it only sets the units attribute string for ''ocean_time'' in output netcdf files so you need to take care to set all these times be be consistent.) Nor will ROMS convert data units if they do not match what is assumed in varinfo.dat. The units attributes in this file are therefore purely metadata that document the file contents. | |||
Let's also examine the format of the open boundary conditions file: | |||
::<div class="box"><span class="forestGreen">ncdump -h lattec_bndy_uv2d_half.nc | more</span></div> | |||
The file has the same dimensions as the forcing files and output netcdf files. It contains parameters and variables that define the vertical s-coordinate and then the actual open boundary data such as: | |||
::<div class="box"> float temp_east(time, s_rho, eta_rho) ;<br> temp_east:long_name = "potential temperature east boundary condition" ;<br> temp_east:units = "Celcius" ;<br> temp_east:field = "temp_east, scalar, series" ;<br> temp_east:time = "ocean_time" ;</div>Notice that this variable has dimensions "''(time, s_rho, eta_rho)''" which describe a time varying 2D spatial structure in depth (s_rho) and horizontal coordinate (eta_rho). This "east" boundary is at constant "i" index (i=L) and therefore has no "xi" coordinate dimension. The data along the southern boundary on the other hand,'' temp_south'', has dimensions "''(time, s_rho, xi_rho)''". | |||
==Run the latte_c example== | |||
Run the model exactly as you did in the UPWELLING example, but giving the new ocean_lattec.in as the input file. | |||
:*UNIX process info, run time, run TITLE | |||
::<div class="box"><span class="forestGreen">./oceanG < ocean_lattec.in</span> </div> | |||
=== Stdout for Latte_C=== | |||
The preamble to STDOUT (which you might redirect to a logfile with ">") will resemble what you saw for UPWELLING. UNIX process information, compiler and svn version information, model input parameters read from the roms.in file, and the list of active CPP options. | |||
The differences from UPWELLING come shortly before the model begins time stepping. ROMS reports the following information to help you check that you have configured the model correctly. | |||
:*Initial conditions | |||
::<div class="box">NLM: GET_STATE - Read state initial conditions, t = 94 00:00:00<br> (File: lattec_ini_94.nc, Rec=0001, Index=1)<br> - free-surface<br> (Min = -7.02081803E-01 Max = 0.00000000E+00)</div>This shows initial time is 94 days, that initial conditions were read from record 1 of file lattec_ini_94.nc, and that the free surface data read ranged from -0.702 meters to 0 meters. Check: are data being read from the correct file for the correct record/time? If you see unrealistic values in the Min/Max range you may have special values (999?) in your input netcdf file, or a units error. | |||
:*Forcing data - static non time varying | |||
::<div class="box"> GET_NGFLD - tidal period<br> (Min = 4.30820452E+04 Max = 9.67260840E+04)<br> GET_2DFLD - tidal elevation amplitude<br> (Min = 0.00000000E+00 Max = 1.13473975E+00) </div>The vector of tidal priods (in hours) are read and then 2D fields of tidal elevation and velocity. Again: check the file source and Min/Max range. | |||
:*Forcing data - time varying | |||
::<div class="box"> GET_NGFLD - river runoff mass transport, t = 94 00:00:00<br> (Rec=0465, Index=2, File: roms_lattec_river.nc)<br> (Tmin= -370.0000 Tmax= 267.0000)<br> (Min = -9.25473328E+02 Max = -1.69902756E+02)<br>...<br> GET_2DFLD - surface u-wind component, t = 94 00:00:00<br> (Rec=0001, Index=1, File: frc_latte_wrf_Uwind.nc)<br> (Tmin= 94.0000 Tmax= 158.9583)<br> (Min = -8.73357999E-02 Max = 4.12751995E+00)<br>...<br> GET_NGFLD - river runoff mass transport, t = 95 00:00:00<br> (Rec=0466, Index=1, File: roms_lattec_river.nc)<br> (Tmin= -370.0000 Tmax= 267.0000)<br> (Min = -9.88811890E+02 Max = -1.86609863E+02)<br>...<br> GET_2DFLD - surface u-wind component, t = 94 00:59:59<br> (Rec=0002, Index=2, File: frc_latte_wrf_Uwind.nc)<br> (Tmin= 94.0000 Tmax= 158.9583)<br> (Min = -1.26112560E-01 Max = 2.46840043E+00)<br></div>Time varying forcing data will be read for times that bracket the current ROMS time. ROMS finds the correct times from the time variable in the files (which can be different for each variable - see the "time" attribute of the data). ROMS linearly interpolates the forcing data for these two records to the ROMS ocean_time on every model time step. The forcing data do not need to be regularly spaced in time, but the data do need to bracket ROMS initial time for the model to start. Again: check file names, data ranges and the times. Recall that if forcing data of the same name occurs in two forcing files in the list set by FRCNAME in roms.in then ROMS takes the first data it finds. This will be the filename in the message above. | |||
:*The model then begins execution, reporting global energy diagnostics and any netcdf files it creates and writes to. | |||
::<div class="box"> STEP Day HH:MM:SS KINETIC_ENRG POTEN_ENRG TOTAL_ENRG NET_VOLUME<br><br> 0 94 00:00:00 9.698352E-03 2.011729E+02 2.011826E+02 1.421876E+12<br> DEF_HIS - creating history file: ./out/his_lattec.nc<br> WRT_HIS - wrote history fields (Index=1,1) into time record = 0000001<br> DEF_STATION - creating stations file: ./out/sta_ocean.nc<br> 1 94 00:06:00 8.873902E-03 2.011284E+02 2.011372E+02 1.422005E+12<br> 2 94 00:12:00 8.377911E-03 2.011090E+02 ...</div> | |||
If in this initialization phase you do not see a report of values you expected ROMS to read, then ROMS '''did not''' read those data. This could be because you have an ANA option set that causes ROMS to get the information internally, or you may have set other CPP options such that there is no need to read the data. '''ROMS does not read data from netcdf files that it does not need to run.''' This information will help you diagnose misconfiguration or misunderstanding of the interaction of various CPP options. | |||
:*New forcing data when required | |||
::<div class="box"> 9 94 00:54:00 6.518542E-03 2.012623E+02 2.012688E+02 1.424463E+12<br> GET_2DFLD - surface u-wind component, t = 94 02:00:00<br> (Rec=0003, Index=1, File: frc_latte_wrf_Uwind.nc)<br> (Tmin= 94.0000 Tmax= 158.9583)<br> (Min = -4.55454426E-01 Max = 4.03826709E+00)</div>When ROMS ocean_time reaches the end of the interval bracketed by any forcing data it holds in memory it will read the next set of values from the netcdf file and report this to STDOUT. If ROMS runs for a while and crashes shortly after reading some new forcing data check that you don't have corrupt data (from the Min/Max range). | |||
Eventually ROMS concludes and provides the same report it did in the UPWELLING example: elapsed time profile, the number of output records written, and the analytical functional used at compilation. | |||
==Plotting netcdf output with Matlab== | |||
===Basics of Matlab-Netcdf=== | |||
Matlab version 2008b, which is installed on the UNSW Computer Lab machines, has support for reading netcdf files. It uses the built-in java tools to do this and the necessity to install a machine-dependent set of mexnc routines that was required in earlier versions of Matlab is no longer necessary. | |||
To ease the process of reading netcdf files into the Matlab workspace we have however installed a set of Matlab m-files called SNCTOOLS, written by John Evans at Mathworks. These tools should be in your Matlab path. You can verify this in Matlab by entering the command <span class="forestGreen">which nc_varget</span>. | |||
nc_varget is the workhorse utility that reads subsets of data from a netcdf file. Many of the Matlab tools that people distribute for working with ROMS output use SNCTOOLS functions, like nc_varget, to provide the interface to reading netcd files. You won't get much further in this part of the tutorial if you can't work nc_varget. | |||
Enter <span class="forestGreen">help nc_varget</span> to see the syntax. | |||
Note that nc_varget also supports reading from OPeNDAP/THREDDS data servers in addition to reading from local netcdf files. | |||
===Using the roms_wilkin Matlab routines=== | |||
ROMS output files are CF-Compliant netcdf files and therefore there are many software tools that allow you to browse, extract and plot output easily. There are also a number of collections of code written for Matlab that offer tools for plotting ROMS output. What you choose to use is a matter of personal preference and the functionality offered. | |||
For this tutorial I show just a few tools out of the set of <span class="purple">roms_wilkin</span> Matlab tools described in more detail at the tiddlywiki http://romsmatlab.tiddlyspot.com and also at [https://www.myroms.org/forum/viewtopic.php?f=23&t=916&start=0&hilit=roms_wilkin this thread] on the ROMS forum. | |||
: | |||
On the UNSW Computer Lab machines you can add the directory of roms_wilkin Matlab routines to your Matlab path using the command: | |||
::<div class="box"> | ::<div class="box"> <span class="purple">>> addpath('/student/0/a0000020/matlab/roms_wilkin','-end')</span></div> | ||
The <span class="purple">{z,s,i,j}view</span> routines in roms_wilkin make simple plots directly from a ROMS file or OPeNDAP URL by slicing along coordinate directions. Enter <span class="purple">help roms_zview</span> to see the syntax. The functions all make use of the model coordinates loaded into a structure by function <span class="purple">roms_get_grid</span>. | |||
: | In matlab, load this grid structure from any file containing the grid coordinates, such as an output file: | ||
::<div class="box"><span class=" | ::<div class="box"><span class="purple"> >> file = 'his_lattec.h';<br> >> g = roms_get_grid(file,file); </span></div> | ||
: | Then to make a plot at constant z = -3 metres of salinity from time record 2 of the file, overlaying green coloured velocity vectors at every 2nd grid point (scaled by a factor of 0.2 deg lon/at per m/s), enter: | ||
::<div class="box"><span class="purple"> >> roms_zview(file,'salt',2,-3,g,3,0.2,'g');</span></div> Not much has happened because we are only a few hours into the simulation so make it easier to the extent of the low salinity Hudson River water by changing the colorbar range and zooming in: | |||
::<div class="box"><span class="purple"> >> caxis([20 34]); colorbar <br> >> axis([-74.4 -73.2 39.9 41]) </span></div> | |||
If you specify time as a string instead of an index, <span class="purple">roms_zview</span> will endeavour to parse the time/date information in the file and select the record nearest in time to plot. You can also give an optional output argument to roms_zview in which case it returns a structure with the data that went in to the plot. | |||
::<div class="box"><span class="purple"> >> thedata = roms_zview(file,'salt','2006-04-05 02:00',-3,g,3,0.2,'g');</span></div> | |||
The output structure <span class="purple">thedata</span> contains: | |||
::<div class="box"><span class="purple">thedata = <br><br> x: [82x146 double]<br> y: [82x146 double]<br> data: [82x146 double]<br> t: 7.3277e+05<br> tstr: '05-Apr-2006 03:00:00'<br> u: [82x145 double]<br> v: [81x146 double]<br> ue: [726x1 double]<br> vn: [726x1 double]<br> xq: [726x1 double]<br> yq: [726x1 double]</span></div> | |||
"File" could equally well have been an OPeNDAP URL to ROMS output such as the example in the [https://www.myroms.org/forum/viewtopic.php?f=23&t=916&start=0&hilit=roms_wilkin ROMS Forum]. | |||
::<div class="box"><span class=" | ::<div class="box"><span class="purple"> >> file = <nowiki>'http://tashtego.marine.rutgers.edu:8080/thredds/dodsC/roms/cblast/2002-050/averages'</nowiki><br> >> g = roms_get_grid(file,file); % the grid structure<br> >> % temperature slice for time step nearest to 20JUN2002, at 2-m <br> >> % depth, with every 3rd velocity vector over-plotted<br> >> roms_zview(file,'temp','20-Jun-2002',-2,g,3,.1,'k')</span></div> |
Latest revision as of 15:11, 28 January 2021
A tutorial for new ROMS users will be held at the UNSW Computer Labs on Monday 30 March 2009, immediately prior to the ROMS Sydney 2009 User Workshop at the Sydney Institute of Marine Sciences, 31 March to 2 April 2009.
This tutorial is intended for complete newcomers to ROMS. It assumes basic knowledge of working in a UNIX environment, and that the essential components required to compile and execute ROMS are already installed on the host computer network. This wiki page borrows heavily from David Robertson's excellent Installing ROMS under Cygwin tutorial where you will find more information about setting up the required computing environment (compilers, libraries etc.) for ROMS.
In this tutorial, we cover how to download the code, configure it for an application, and run the model. Error messages that arise during the configuration process will be explained so that these can better be debugged when users return to their home institutions and try to work through this process again.
A follow-on tutorial discussing sediment in ROMS will be presented on Friday 03 April.
An important resource you should use as you get started is the Frequently Asked Questions entry in WikiROMS.
Note: In SVN revision 933 (January 26, 2019) all ocean_*.in files were renamed to roms_*.in and all ocean* ROMS executables were renamed to roms* in order to facilitate and clarify model coupling efforts. More information can be found in the ROMS repository Trac ticket #794. If you are working with a ROMS release prior to revision 933 you will need to replace roms_upwelling.in with ocean_upwelling.in and romsS, romsM, or romsO with oceanS, oceanM, or oceanO in all commands below.
Note: The build scripts have also changed names so build.bash becomes build.sh and build.sh becomes build.csh.
Download ROMS
The disk space available on the UNSW Computer Lab machines is quite limited, so for the purposes of this tutorial we have downloaded the ROMS source code to /srv/ckpt/roms/shared/src on host matht001. Instructions below will explain how to point the build.bash script that compiles ROMS to this directory.
To download the code to your own machine, these are the steps you would follow:
- You must have already registered on the ROMS portal and obtained your ROMS username/password as indicated in the Register.
- Create a src folder where you will keep the ROMS source code. You can place this wherever you wish in your directory tree (here we assume under your home directory "~") and name it whatever you like.
- cd ~
mkdir src
- Check out the ROMS source code replacing bruce with the ROMS user name you registered with.
- svn checkout --username bruce https://www.myroms.org/svn/src/trunk srcNote the target directory src at the end of the command. If your code ends up in the wrong place, you may have omitted this.
You will see many lines stream by indicating the files that are being added to your src directory. When it finishes, you can type ls src to see the contents of the directory.
To see the contents of the directory where the code is downloaded for this tutorial, type this:
- cd /srv/ckpt/roms/shared
ls src
Customize the Build Script
The ROMS source code comes with a build script in the ROMS/Bin directory. Examples written with bash (build.bash) and csh (build.sh) are provided. The UNSW Computer Lab machines are configured to use bash as the default login shell, so we will work with build.bash. A full description of the build script can be found here.
- In your home directory (you can use some other directory to organize your ROMS projects if you wish) create a new folder named Projects and change into it.
- cd ~
mkdir Projects
cd Projects
- Create a folder named upwelling and change into it. ROMS is distributed with several Test Cases and the Upwelling example is the default which we will compile and run here.
- mkdir upwelling
cd upwelling
- Copy the build.bash file distributed with ROMS to your Projects/upwelling directory.
- cp /srv/ckpt/roms/shared/src/ROMS/Bin/build.bash .
Next we need to configure a few options inside build.bash so that it finds the directories where the source code and your Project are located.
- Open the build.bash script you just copied into your upwelling directory using your preferred text editor, e.g. vi.
- vi build.bash
- Scroll down until you find ROMS_APPLICATION. You will notice it is set as follows:
- export ROMS_APPLICATION=UPWELLINGWe do not need to change this. But this is the first thing you will alter when starting your own project. This tells ROMS the name of an include file that will contain all the directives to the C-PreProcessor to configure your application at compile time. ROMS' rule is change this string to lowercase and append a ".h", so this will search for a file called upwelling.h. It must be in the directory specified by MY_PROJECT_DIR:
- Scroll down until you find MY_PROJECT_DIR and set it as follows:
- export MY_PROJECT_DIR=${HOME}/Projects/upwellingThis obviously assumes you put Projects/upwelling under your home directory.
If you frequently move your ROMS project between hosts where you have a different directory structure, e.g. a temporary scratch space, you can use the MY_ROOT_DIR variable to minimize the changes you make to build.bash.
- For example:
- export MY_ROOT_DIR=/usr/scratch/bruce
export MY_PROJECT_DIR=${MY_ROOT_DIR}/Projects/upwelling
Next we tell build.bash where to find the ROMS source code downloaded from the svn repository (which you can keep up to date the svn update command - see more on this at LINK ). Note that most of the source code changes you make to customize ROMS will be made in your Projects space, and need not be made to the downloaded code directly. We will discuss exceptions to this during the tutorial, and how source code modifications interact with svn.
- Set MY_ROMS_SRC to the location of the source code:
- export MY_ROMS_SRC=/srv/ckpt/roms/shared/srcIn practise, you will probably do something more like this:
- export MY_ROMS_SRC=${MY_ROOT_DIR}/srcassuming this is the relative path in which you keep your source code on the various machines you work on.
Make sure that MY_CPP_FLAGS is not set. Sometimes this is set in the distributed build.bash exmaple. Comment out options with the # symbol like so:
- #export MY_CPP_FLAGS="-DAVERAGES"
The UNSW Computer Lab machines are single core, so we need to tell build.bash not to assume MPI parallel compilation.
- Comment out the options for USE_MPI and USE_MPIF90
- #export USE_MPI=on
#export USE_MPIF90=on
- If you were compiling in parallel you would leave the default entries in build.bash.
- export USE_MPI=on
export USE_MPIF90=on
- We leave the compiler option as the default because this says use the ifort (Intel FORTRAN) compiler which is what we want on the UNSW machines.
- export FORT=ifort
- In the interests of speed for this tutorial, we turn off compiler optimization by activating the debug option:
- export USE_DEBUG=onOn the UNSW Lab machines compiling with optimization on will take over 15 minutes, but with optimization off (USE_DEBUG=on) it will be less than 60 seconds.
Save and close the build.bash file.
Copy the input and CPPDEFS options files
We need three more files in Projects/upwelling to configure and run ROMS. We copy the versions downloaded with svn because these are files you will work with locally when you experiment with changes to the test case example configuration.
- Copy files ocean_upwelling.in, varinfo.dat and upwelling.h into the Projects/upwelling directory you just created.
- cd ~/Projects/upwelling
cp /srv/ckpt/roms/shared/src/ROMS/External/ocean_upwelling.in .
cp /srv/ckpt/roms/shared/src/ROMS/External/varinfo.dat .
cp /srv/ckpt/roms/shared/src/ROMS/Include/upwelling.h .
View the file upwelling.h. It contains all the C-Pre-Processor (CPP) options that the compiler interprets to activate certain source code options within ROMS.
View the file ocean_upwelling.in. It contains the inputs options that ROMS reads from standard input at run time to set options that need not be fixed at compile time.
View varinfo.dat. The file varinfo.dat contains descriptions of the names and attributes of input and output variables that ROMS reads and writes from netcdf files. For most applications you will not need to change the entries in this file. If you need to know the default units assumed for different variables, those are noted in this file. (Before we run ROMS, we will need to tell it where to find this file).
Now we are ready to compile ROMS by executing the build.bash script.
Compile ROMS
Before you run ROMS, you need to compile it to create an executable oceanS file (S for serial or single processor computer), or oceanM file (if using MPI on a parallel computer).
- Go to your upwelling project directory:
- cd ~/Projects/upwelling
- Then type:
- ./build.bash
- If lots of stuff comes on the screen then compilation is proceeding, and make take some time.
- If the build process ends quickly with an error, then it is likely that build.bash does not point to the correct location for the upwelling.h file, the FORTRAN compiler, or some libraries. We describe common getting started errors and solutions in the next section.
- You may give the option -j to the build command to distribute the compilation to multiple processors if your host supports this, e.g.:
- ./build.bash -j 8to compile on 8 processor at once.
If your build was successful it will not have reported any errors, and there will be an executable file in your Projects/upwelling directory called oceanG. The "G" in the file name indicates build.bash activated the USE_DEBUG option.
If USE_DEBUG were not selected, the executable would be oceanS, where the "S" indicates "serial" or "single-processor" because we deactivated MPI.
If you had activated MPI with the USE_MPI option the executable would be named oceanM.
(See also FAQ: My build finished with no errors, where is the ROMS executable?).
Common getting started compile error messages
Getting past the first few errors with compilation is often tricky. Carefully read any error messages you get for clues on what might be wrong with your configuration. Here are some common difficulties new users encounter getting started when first executing the build.bash command.
- Compilers/../ROMS/Include/cppdefs.h:709:22:This says the file upwelling.h is not where Build expects it to be, which is in MY_PROJECT_DIR. You set this to ~/Projects/upwelling.
error: /student/0/a0000020/Projects/upwelling/upwelling.h: No such file or directory
- cp: cannot stat `/opt/intelsoft/netcdf/include/netcdf.mod': No such file or directoryThis says that netcdf is not where build.bash expects to find it. Locate where the netcdf include and lib directories with steps something like:cd /usrThis tells us the most recent (3.6.3) netcdf is in /usr/local/netcdf/intel/3.6.3. Direct ROMS to this location by making two changes to build.bash. First, advise ROMS to read your changes to the default library path by uncommenting the option for USE_MY_LIBS.
find . -name netcdf.mod -print
./local/netcdf-3.6.2/include/netcdf.mod
./local/netcdf/intel/3.6.3/include/netcdf.mod
- export USE_MY_LIBS=onThen specifiy the correct location for netcdf:
- export NETCDF_INCDIR=/usr/local/netcdf/intel/3.6.3/includeBe careful where you make this change. You need to make it for the ifort compiler option, and NOT for the USE_NETCDF4 option (we are using netcdf-3). If you've done this correctly, your compilation with build.bash should now succeed.
export NETCDF_LIBDIR=/usr/local/netcdf/intel/3.6.3/lib
- errorNote here further errors we encounter during the tutorial.
error:
Run ROMS
You run ROMS by executing the oceanG (or oceanS) binary, giving it the ocean_upwelling.in file as UNIX standard input.
- ./oceanS < ocean_upwelling.inROMS standard output will be typed to the screen. To save it a file instead, enter, e.g.:
- ./oceanS < ocean_upwelling.in > my_upwelling.log
If you have compiled a parallel (MPI) executable, the syntax for running the mode is slightly but critically different. The ocean_upwelling.in file is no longer read from UNIX standard input (it has handled by all the MPI threads) so the "<" disappears from the command, and you need the correct syntax on your UNIX host for running an MPI process. It is probably something like:
- mpirun -np 8 ./oceanM ocean_upwelling.in > my_upwelling.logwhere the "-np 8" indicates use 8 processors and this number of tiles must have been set by
(See also FAQ: What do I have to do to runs ROMS?).
Common getting started run error messages
- bash: oceanG: command not foundThe working directory is not in your UNIX path. That's why we type "dot-slash" in front of the commands above.
Successful execution
Standard Output
When ROMS runs it will type a lot of information to UNIX standard output. This is the "logfile" you named following the ">", or your terminal if you did not redirect stdout.
STDOUT shows the following:
- UNIX process info, run time, run TITLE
- Process Information:
Thread # 0 (pid= 4449) is active.
Model Input Parameters: ROMS/TOMS version 3.2
Monday - March 23, 2009 - 10:02:39 AM
-----------------------------------------------------------
Wind-Driven Upwelling/Downwelling over a Periodic Channel
- OS, compiler information, SVN version, and your MY_ROMS_SRC, MY_HEADER_DIR and ROMS_APPLICATION settings
- Operating system : LinuxCheck that these are what you intended. In last line above
CPU/hardware : i686
Compiler system : ifort
Compiler command : /usr/local/intel/fc/10.1.021/bin/ifort
Compiler flags : -heap-arrays -ip -O3 -pc80 -xW -free
SVN Root URL : https://www.myroms.org/svn/src/trunk
SVN Revision : 333
Local Root : /srv/ckpt/roms/shared/src
Header Dir : /student/0/a0000020/srv/Projects/upwelling
Header file : upwelling.h
Analytical Dir: /student/0/a0000020/srv/Projects/upwelling
Resolution, Grid 01: 0041x0080x016, Parallel Threads: 1, Tiling: 001x001- "Grid 01" pertains to future ROMS developments with multiple nested/connected grids,
- 0041x0080x016 shows the grid size is 41 x 80 x 16 grid points in the K,J,I directions
- The Parallel/Tiling message shows you are using a single process and a single domain tile. When using MPI, this message will describe how many tiles you are using and the MPI processes assigned.
- Input parameters set in ocean_upwelling.in
- Physical Parameters, Grid: 01
=============================
288 ntimes Number of timesteps for 3-D equations.
300.000 dt Timestep size (s) for 3-D equations.
30 ndtfast Number of timesteps for 2-D equations between
each 3D timestep.
...
Output Averages File: ocean_avg.nc
Output Diagnostics File: ocean_dia.nc
- Then some more about the tiling when running in parallel
- The C-PreProcessor (CPP) flags set in upwelling.h but AS MODIFIED by ROMS when interpreting and checking the selected CPP options.
- Activated C-preprocessing Options:You should check that the CPP options displayed here agree with what you intended. For example, if you inadvertently specify more than one horizontal advection scheme option, ROMS will have chosen only one and reported that option here.
UPWELLING Wind-Driven Upwelling/Downwelling over a Periodic Channel
ANA_BSFLUX Analytical kinematic bottom salinity flux.
ANA_BTFLUX Analytical kinematic bottom temperature flux.
ANA_GRID Analytical grid set-up.
ANA_INITIAL Analytical initial conditions.
...
- The preamble in STDOUT continues with information about the space and time discretization: grid spacing, grid volume, Courant number (time step stability) and stiffness (related to s-coordinate accuracy).
- Then the model starts time stepping:
- NL ROMS/TOMS: started time-stepping: (Grid: 01 TimeSteps: 00000001 - 00000288)This output indicates several things:
STEP Day HH:MM:SS KINETIC_ENRG POTEN_ENRG TOTAL_ENRG NET_VOLUME
0 0 00:00:00 0.000000E+00 6.579497E+02 6.579497E+02 3.884376E+11
DEF_HIS - creating history file: ocean_his.nc
WRT_HIS - wrote history fields (Index=1,1) into time record = 000000
DEF_AVG - creating average file: ocean_avg.nc
DEF_DIAGS - creating diagnostics file: ocean_dia.nc
1 0 00:05:00 3.268255E-13 6.579497E+02 6.579497E+02 3.884376E+11
2 0 00:10:00 6.503587E-12 6.579497E+02 6.579497E+02 3.884376E+11
3 0 00:15:00 4.592307E-11 6.579497E+02 6.579497E+02 3.884376E+11
...- the run is programmed to run from time step 1 to 288
- the run starts at time 00:00:0
- netcdf output HISTORY, AVERAGES and DIAGNOSTICS files are created. Every time ROMS creates a new netcdf file, and writes to an existing file, it reports this to STDOUT
- output is written to the HISTORY file
- then global quantities related to the model KE, PE and domain volume are reported on each time step
In 99% of situations, getting started problems with model set-up and configuration can be diagnosed by carefully reading the STDOUT above. Things to look for are:
- misconfigured CPP options (what you got is not what you thought you asked for)
- parameter errors (e.g. you activated horizontal mixing but left the coefficient as zero)
- misnamed output files (that's why the files from your last run got overwritten)
- irrational choices of grid spacing or time step
- initial/boundary/forcing data being read from the wrong file, or not read at all (because you selected analytical conditions)
At the conclusion of the run, ROMS reports information about run time:
- Elapsed CPU time (seconds):
Thread # 0 CPU: 108.079
Total: 108.079
Nonlinear model elapsed time profile:
Initialization ................................... 0.016 ( 0.0148 %)
Processing of input data ......................... 0.028 ( 0.0259 %)
Processing of output time averaged data .......... 4.312 ( 3.9899 %)
...
- about the number of output records written to each file
- ROMS/TOMS - Output NetCDF summary for Grid 01:
number of time records written in HISTORY file = 00000005
...
- and the analytical files included
- Analytical header files used:If you used a modified analytical file in your MY_HEADER_DIR it will be reported here and is another thing you should check for consistency with your intentions.
ROMS/Functionals/ana_btflux.h
ROMS/Functionals/ana_grid.h
...
Netcdf file output
As reported above, ROMS created 4 output netcdf files when it ran. There are ocean_his.nc, ocean_avg.nc, ocean_dia.nc, and coean_rst.nc. These are, respectively:
- history records or 'snapshots' of the model state a selected time intervals
- averages of the model state over selected intervals (not necessarily the same intervals as the history)
- diagnostics of the model state, the precise contents of which are controlled by CPP options
- a restart file with everything ROMS needs to restart a application. This is useful if your job crashes at some point and you want to recommence from a previous state without starting over. Typically the restart file is set to keep just 2 time records by continually over-writing the oldest as the run proceeds. This behaviour is controlled in ocean_upwelling.in. Also, when ROMS "blows up" it dumps the ocean state to a 3rd record in the restart file.
You can browse the contents of netcdf files at the UNIX command line with the command ncdump, e.g.
- ncdump -h ocean_his.nc | more
Note the use of the "-h" option. This restricts the output from ncdump to be just the header information, or metadata, in the netcdf file. Without the "-h" option you will get the entire contents of the file converted to ascii.
Things to notice when you ncdump the ocean_his.nc file are that it contains all the input parameters (time step, mixing coefficients, s-coordinate parameters, etc.) from roms.in, the model grid coordinates (x, y, lon, lat, depth, Coriolis parameter, etc.) which may have been computed by the ANA_GRID option or read from an input grid netcdf file, in addition to the actual model output (ocean_time, zeta, u, v, temp, salt).
There are netcdf global attributes that echo much of the information typed to STDOUT. This includes compiler, svn version, and project directory information, and all the CPP options. This is a valuable source of information when returning to a project and trying to figure out what you did! The global attributes metadata show precisely which options were activated when creating the output in this netcdf file.
Changing the UPWELLING test case configuration
Compile time changes: upwelling.h
Changes to options that must be set at compilation time are made to the upwelling.h file. These settings are interpreted during the C-PreProcessing step.
To see what the present options are, edit the upwelling.h file:
- vi upwelling.h
Recall that the actual options active after this file in interpreted will be typed to STDOUT (the "logfile") and also written to the output netcdf file in the global attributes.
To see the all the options that might be set using C-PreProcessor directives, you can browse the cppdefs.h file in the ROMS/Include directory underneath the MY_ROMS_SRC location set in your build.bash. In this case:
- cd /srv/ckpt/roms/shared/src
more ROMS/Include/cppdefs.h
The contents of this file are almost entirely comments and are provided to document the options available. For more information consult WikiROMS or the User Forum.
At the very bottom of cppdefs.h you will see a short code segment that loads the actual application options from ROMS_HEADER. This variable is set by the ROMS_APPLICATION value in build.bash.
Run time changes: ocean_upwelling.in
Changes to options that are set at run time are made to the ocean_upwelling.in file.
To see what the present options are, edit the ocean_upwelling.in file:
- vi ocean_upwelling.in
Comments at the beginning of this file document the KEYWORD == value syntax.
Comments at the end of file provide brief summaries of what each parameter does.
For more information consult WikiROMS or the Use Forum.
Recall that the actual parameter values ROMS uses after reading this file will be typed to STDOUT (the "logfile") and also written to the output netcdf files.
A Realistic model example: LaTTE
THIS TEST CASE IS WAY OUT OF DATE AND ALMOST CERTAINLY WON'T WORK WITH A RECENT VERSION OF ROMS. IT NEEDS UPDATING. UNTIL I GET TO THAT, TREAT THIS SECTION AS A GUIDELINE ON THE BASIC STEPS TO CREATING A REALISTIC APPLICATION, BUT DON'T PERSEVERE TRYING TO RUN IT.
This section of the tutorial assumes you have successfully compiled and run the UPWELLING example above. Key concepts you should be comfortable with before you proceed are:
- you need a new directory where you will keep the files specific to the new application
- customize build.bash for the new application (copy the build.bash from upwelling because it has all the correct compiler and library settings)
- set MY_PROJECT_DIR in build.bash to point to the directory for the new application
- set ROMS_APPLICATION in build.bash to the correct name for the new application
- if you wish to customize any of the ana_*.h files, copy just the ones you need into the new project directory
- you don't need to make a copy the source code a new application
With these concepts in mind, we proceed by configuring ROMS to run a realistic coastal ocean application that includes open boundaries on 3 sides, open boundary tides and climatological open boundary velocity and tracer (temperature and salinity) conditions, surface meteorological forcing, and initial conditions, all provided by input netcdf files.
The example is called LaTTE_C because it simulates ocean conditions during the Lagrangian Transport and Transformation Experiment conducted on the New Jersey inner shelf in the Spring of 2006. The '_C' denotes a coarse resolution configuration suitable for this training exercise.
Create a latte_c project directory
We have placed the CPP options file latte_c.h, standand input ocean_lattec.in, and a modified varinfo.dat in /srv/ckpt/roms/shared/latte_c/Forward. Make a new Project directory for this new application and copy these 3 files. DO NOT copy all the netcdf files from /srv/ckpt/roms/shared/latte_c/in .
Edit build.bash
Set the correct entries for environment variables that define the user application.
ROMS_APPLICATION=LATTE_C causes build.bash to look for the file latte_c.h in order to set the CPP options
MY_PROJECT_DIR=${HOME}/Projects/latte_c will instruct build.bash where to look for the latte_c.h file.
Setting MY_HEADER_DIR would instruct ROMS where to look for the user functional files ana_*.h that over-ride default options. In this example, however, we don’t actually need to modify any of those functionals. This is typical of “realistic” applications where input grid, initial and boundary conditions are provided from data in input netcdf files.
The format of ROMS output files (history, averages and restart) is the same as ROMS input initial conditions and climatology. This means the output of previous runs can become the initial conditions, or 3-D climatology (for nudging) for new runs.
Edit ocean_lattec.in
Open the ocean_lattec.in file in an editor. There are KEYWORDS that define the names of the input netcdf files for applications of this type:
- GRDNAME is the grid file with coordinates, grid metrics (spacing), bathymetry, land/sea mask and Coriolis
- ININAME is the initial conditions
- BRYNAME are the open boundary sea leve, velocity and tracer conditions
- FRCNAME are the tides, river source, and surface meteorological forcing files. Notice there are multiple files and the number of files ROMS is to read is set by the NFFILES parameter. On initialization, ROMS scans this list for each forcing variable it needs, using the first file to contain the necessary and shadowing any entry in subsequent files. Therefore if you want to re-run your model with a new set of wind data but happen to have other wind data in a files with all your other meteorology inputs, just put the new file at the beginning of the list.
There are KEYWORDS that determine the output file names. These are:
- RSTNAME, HISNAME, AVGNAME, DIANAME, STANAME, FLTNAME .... etc
There are keywords that set how many time steps ROMS takes between writing output. These are:
- NRST,NHIS,NAVG,NDIA,NSTA ...etc
You can have ROMS write multiple records to each output file at these intervals, but periodically create a new file (to keep file sizes manageable) by setting the keywords:
- NDEFHIS,NDEFAVG,NDEFDIA
Compile with build.bash
If you have set the entries in build.bash correctly, you compile exactly as before by executing the script.
Watch the output of the build process. You should see that instead of "Project/upwelling/Build" the compilation is now writing temporary files to "Project/latte_c/Build". This Build subdirectory is kept separate so you can be working on two projects at once and not confuse things.
cd to the Build subdirectory and look at some of the files there, e.g.
- cd ~/Projects/latte_c/Build
more u3dbc_im.f90
This is the file that sets open boundary conditions on 3-d velocity. This is the Fortran90 file that is generated after the C-PreProcessor has done its job. If you find your model is doing things you don't expect, it can be instructive to view the ".f90" file and corresponding ".F" (in MY_ROMS_SRC) to see whether the CPP options being processed are what you intended. If not, review your header file (in this case latte_c.h), and the list of CPP options typed to STDOUT. Don't edit the "f90" file directly because it gets over-written when you recompile.
Before we run latte_c
Browse the latte_c.h options
Use vi or more to browse the CPP options used in this "realistic" application. Things to notice that are different from upwelling.h are:
- There are no ANA_INITIAL or ANA_WINDS options. If analytical initial and forcing options are not set with a #define then ROMS defaults to reading this information from input netcdf files.
- WEST_, EAST_, SOUTH_ and NORTHERN_WALL. These options define the open boundary schemes. (The nomenclature of the compass points assume a grid oriented with west along i=1 and south along j=1). The upwelling case had closed boundaries to the north and south, and periodic conditions east-west. The open boundary conditions here are set with the following options:
- WEST_FSCHAPMAN,WEST_M2FLATHER etc. indicate “west” side free surface (FS) and depth-averaged velocity/momentum (M2)
- WEST_M3GRADIENT,WEST_TGRADIENT “west side” 3-d velocity/momentum (M3) and all tracers.
- SSH_TIDES, UV_TIDES cause ROMS to add tidal variability in sea level and depth-average velocity using the harmonics read from the tides forcing file. See the wikiROMS entry on tides for more information.
- #ifdef SSH_TIDES
#define ADD_FSOBC
This construct is a conditional test that causes prescribed mean or slowly varying sea surface height to be added to the tidal variability.
The further option ANA_FSOBC means the prescribed value is set by one of the analytical functional include files. If ANA_FSOBC is not defined, ROMS will look for the boundary sea level in a boundary conditions file.
- #ifdef SSH_TIDES
- BULK_FLUXES In this application the surface meteorology forcing files give net shortwave and longwave radiation and the temperature, pressure and humidity conditions in the marine atmospheric boundary layer. These values are converted to air-sea fluxes of heat and momentum according to the Fairall et al. bulk formulae.
- GLS_MIXING This activates the Generalized Length Scale vertical turbulence closure parameterization of Umlauf and Buchard. Parameters in ocean_lattec.in determine details such as whether the closure method is actually k-epsilon, k-kl, etc.
- UV_PSOURCE, TS_PSOURCE These options activate point sources; in this case the inflow of the Hudson River.
The input netcdf files
Use ncdump to browse the contents of some of the input files, e.g.:
- ncdump -h frc_lattec_wrf_Pair.nc | more
We see that in this case the dimensions of the data match the dimensions of the ROMS grid:
- dimensions:For time varying 2D surface forcing data only (e.g. meteorological data) ROMS will regrid during execution 2D data defined on simple 1D coordinates (vectors of lon and lat). In all other cases, the forcing data must have already been interpolated to the ROMS grid.
time = UNLIMITED ; // (1560 currently)
eta_rho = 82 ;
xi_rho = 146 ;
ROMS associates the variable name of the forcing data with the appropriate internal variable by consulting the entries in varinfo.dat. Edit varinfo.dat and search for the string "Pair"
- vi varinfo.dat
- 'Pair' ! InputThis tells us 3 important things:
'surface air pressure'
'millibar' ! [millibar]
'Pair, scalar, series'
'pair_time'
'idPair'
'r2dvar'
1.0d0- The name of the surface air pressure variable in the forcing netcdf is "Pair". If your netcdf file was made with some other name you can change it here, e.g. "press_sfc" and you DO NOT need to change the netcdf file. This is acceptable because the variable is strictly an Input variable as noted by the comment (! Input) at the end of the first line.
- The units are assumed to be millibars. If your data are not in millibars you must either modify the data in the forcing netcdf file, or you may apply a scalar factor by editing the last line in the block above (presently set to 1.0d0).
- The Pair data are defined at the times recorded by the variable named "pair_time" in the same forcing netcdf file. However, in the netcdf file itself this default can be reset by adding a "time" attribute to Pair. Return to viewing the netcdf file with ncdump to see this:
- variables:The "time" attribute "Pair:time" indicates that variable "ncep_time" in this file contains the times at which the air pressure is reported. This overrides the value in varinfo.dat. The units attribute to ncep_time shows the CF convention of "days since 2006-01-01 00:00:0". This time base must match in ALL your forcing netcdf files AND the initial conditions file. ROMS will not enforce consistency between different time conventions - that would be nice but for now it's on you. (Nor will the TIME_REF keyword in roms.in adjust this time - it only sets the units attribute string for ocean_time in output netcdf files so you need to take care to set all these times be be consistent.) Nor will ROMS convert data units if they do not match what is assumed in varinfo.dat. The units attributes in this file are therefore purely metadata that document the file contents.
double Pair(time, eta_rho, xi_rho) ;
Pair:long_name = "Surface air pressure" ;
...
Pair:time = "ncep_time" ;
double ncep_time(time) ;
ncep_time:long_name = "forcing observations time" ;
ncep_time:units = "days since 01-Jan-2006" ;
Let's also examine the format of the open boundary conditions file:
- ncdump -h lattec_bndy_uv2d_half.nc | more
The file has the same dimensions as the forcing files and output netcdf files. It contains parameters and variables that define the vertical s-coordinate and then the actual open boundary data such as:
- float temp_east(time, s_rho, eta_rho) ;Notice that this variable has dimensions "(time, s_rho, eta_rho)" which describe a time varying 2D spatial structure in depth (s_rho) and horizontal coordinate (eta_rho). This "east" boundary is at constant "i" index (i=L) and therefore has no "xi" coordinate dimension. The data along the southern boundary on the other hand, temp_south, has dimensions "(time, s_rho, xi_rho)".
temp_east:long_name = "potential temperature east boundary condition" ;
temp_east:units = "Celcius" ;
temp_east:field = "temp_east, scalar, series" ;
temp_east:time = "ocean_time" ;
Run the latte_c example
Run the model exactly as you did in the UPWELLING example, but giving the new ocean_lattec.in as the input file.
- UNIX process info, run time, run TITLE
- ./oceanG < ocean_lattec.in
Stdout for Latte_C
The preamble to STDOUT (which you might redirect to a logfile with ">") will resemble what you saw for UPWELLING. UNIX process information, compiler and svn version information, model input parameters read from the roms.in file, and the list of active CPP options.
The differences from UPWELLING come shortly before the model begins time stepping. ROMS reports the following information to help you check that you have configured the model correctly.
- Initial conditions
- NLM: GET_STATE - Read state initial conditions, t = 94 00:00:00This shows initial time is 94 days, that initial conditions were read from record 1 of file lattec_ini_94.nc, and that the free surface data read ranged from -0.702 meters to 0 meters. Check: are data being read from the correct file for the correct record/time? If you see unrealistic values in the Min/Max range you may have special values (999?) in your input netcdf file, or a units error.
(File: lattec_ini_94.nc, Rec=0001, Index=1)
- free-surface
(Min = -7.02081803E-01 Max = 0.00000000E+00)
- Forcing data - static non time varying
- GET_NGFLD - tidal periodThe vector of tidal priods (in hours) are read and then 2D fields of tidal elevation and velocity. Again: check the file source and Min/Max range.
(Min = 4.30820452E+04 Max = 9.67260840E+04)
GET_2DFLD - tidal elevation amplitude
(Min = 0.00000000E+00 Max = 1.13473975E+00)
- Forcing data - time varying
- GET_NGFLD - river runoff mass transport, t = 94 00:00:00Time varying forcing data will be read for times that bracket the current ROMS time. ROMS finds the correct times from the time variable in the files (which can be different for each variable - see the "time" attribute of the data). ROMS linearly interpolates the forcing data for these two records to the ROMS ocean_time on every model time step. The forcing data do not need to be regularly spaced in time, but the data do need to bracket ROMS initial time for the model to start. Again: check file names, data ranges and the times. Recall that if forcing data of the same name occurs in two forcing files in the list set by FRCNAME in roms.in then ROMS takes the first data it finds. This will be the filename in the message above.
(Rec=0465, Index=2, File: roms_lattec_river.nc)
(Tmin= -370.0000 Tmax= 267.0000)
(Min = -9.25473328E+02 Max = -1.69902756E+02)
...
GET_2DFLD - surface u-wind component, t = 94 00:00:00
(Rec=0001, Index=1, File: frc_latte_wrf_Uwind.nc)
(Tmin= 94.0000 Tmax= 158.9583)
(Min = -8.73357999E-02 Max = 4.12751995E+00)
...
GET_NGFLD - river runoff mass transport, t = 95 00:00:00
(Rec=0466, Index=1, File: roms_lattec_river.nc)
(Tmin= -370.0000 Tmax= 267.0000)
(Min = -9.88811890E+02 Max = -1.86609863E+02)
...
GET_2DFLD - surface u-wind component, t = 94 00:59:59
(Rec=0002, Index=2, File: frc_latte_wrf_Uwind.nc)
(Tmin= 94.0000 Tmax= 158.9583)
(Min = -1.26112560E-01 Max = 2.46840043E+00)
- The model then begins execution, reporting global energy diagnostics and any netcdf files it creates and writes to.
- STEP Day HH:MM:SS KINETIC_ENRG POTEN_ENRG TOTAL_ENRG NET_VOLUME
0 94 00:00:00 9.698352E-03 2.011729E+02 2.011826E+02 1.421876E+12
DEF_HIS - creating history file: ./out/his_lattec.nc
WRT_HIS - wrote history fields (Index=1,1) into time record = 0000001
DEF_STATION - creating stations file: ./out/sta_ocean.nc
1 94 00:06:00 8.873902E-03 2.011284E+02 2.011372E+02 1.422005E+12
2 94 00:12:00 8.377911E-03 2.011090E+02 ...
If in this initialization phase you do not see a report of values you expected ROMS to read, then ROMS did not read those data. This could be because you have an ANA option set that causes ROMS to get the information internally, or you may have set other CPP options such that there is no need to read the data. ROMS does not read data from netcdf files that it does not need to run. This information will help you diagnose misconfiguration or misunderstanding of the interaction of various CPP options.
- New forcing data when required
- 9 94 00:54:00 6.518542E-03 2.012623E+02 2.012688E+02 1.424463E+12When ROMS ocean_time reaches the end of the interval bracketed by any forcing data it holds in memory it will read the next set of values from the netcdf file and report this to STDOUT. If ROMS runs for a while and crashes shortly after reading some new forcing data check that you don't have corrupt data (from the Min/Max range).
GET_2DFLD - surface u-wind component, t = 94 02:00:00
(Rec=0003, Index=1, File: frc_latte_wrf_Uwind.nc)
(Tmin= 94.0000 Tmax= 158.9583)
(Min = -4.55454426E-01 Max = 4.03826709E+00)
Eventually ROMS concludes and provides the same report it did in the UPWELLING example: elapsed time profile, the number of output records written, and the analytical functional used at compilation.
Plotting netcdf output with Matlab
Basics of Matlab-Netcdf
Matlab version 2008b, which is installed on the UNSW Computer Lab machines, has support for reading netcdf files. It uses the built-in java tools to do this and the necessity to install a machine-dependent set of mexnc routines that was required in earlier versions of Matlab is no longer necessary.
To ease the process of reading netcdf files into the Matlab workspace we have however installed a set of Matlab m-files called SNCTOOLS, written by John Evans at Mathworks. These tools should be in your Matlab path. You can verify this in Matlab by entering the command which nc_varget.
nc_varget is the workhorse utility that reads subsets of data from a netcdf file. Many of the Matlab tools that people distribute for working with ROMS output use SNCTOOLS functions, like nc_varget, to provide the interface to reading netcd files. You won't get much further in this part of the tutorial if you can't work nc_varget.
Enter help nc_varget to see the syntax.
Note that nc_varget also supports reading from OPeNDAP/THREDDS data servers in addition to reading from local netcdf files.
Using the roms_wilkin Matlab routines
ROMS output files are CF-Compliant netcdf files and therefore there are many software tools that allow you to browse, extract and plot output easily. There are also a number of collections of code written for Matlab that offer tools for plotting ROMS output. What you choose to use is a matter of personal preference and the functionality offered.
For this tutorial I show just a few tools out of the set of roms_wilkin Matlab tools described in more detail at the tiddlywiki http://romsmatlab.tiddlyspot.com and also at this thread on the ROMS forum.
On the UNSW Computer Lab machines you can add the directory of roms_wilkin Matlab routines to your Matlab path using the command:
- >> addpath('/student/0/a0000020/matlab/roms_wilkin','-end')
The {z,s,i,j}view routines in roms_wilkin make simple plots directly from a ROMS file or OPeNDAP URL by slicing along coordinate directions. Enter help roms_zview to see the syntax. The functions all make use of the model coordinates loaded into a structure by function roms_get_grid.
In matlab, load this grid structure from any file containing the grid coordinates, such as an output file:
- >> file = 'his_lattec.h';
>> g = roms_get_grid(file,file);
Then to make a plot at constant z = -3 metres of salinity from time record 2 of the file, overlaying green coloured velocity vectors at every 2nd grid point (scaled by a factor of 0.2 deg lon/at per m/s), enter:
- >> roms_zview(file,'salt',2,-3,g,3,0.2,'g');Not much has happened because we are only a few hours into the simulation so make it easier to the extent of the low salinity Hudson River water by changing the colorbar range and zooming in:
- >> caxis([20 34]); colorbar
>> axis([-74.4 -73.2 39.9 41])
If you specify time as a string instead of an index, roms_zview will endeavour to parse the time/date information in the file and select the record nearest in time to plot. You can also give an optional output argument to roms_zview in which case it returns a structure with the data that went in to the plot.
- >> thedata = roms_zview(file,'salt','2006-04-05 02:00',-3,g,3,0.2,'g');
The output structure thedata contains:
- thedata =
x: [82x146 double]
y: [82x146 double]
data: [82x146 double]
t: 7.3277e+05
tstr: '05-Apr-2006 03:00:00'
u: [82x145 double]
v: [81x146 double]
ue: [726x1 double]
vn: [726x1 double]
xq: [726x1 double]
yq: [726x1 double]
"File" could equally well have been an OPeNDAP URL to ROMS output such as the example in the ROMS Forum.
- >> file = 'http://tashtego.marine.rutgers.edu:8080/thredds/dodsC/roms/cblast/2002-050/averages'
>> g = roms_get_grid(file,file); % the grid structure
>> % temperature slice for time step nearest to 20JUN2002, at 2-m
>> % depth, with every 3rd velocity vector over-plotted
>> roms_zview(file,'temp','20-Jun-2002',-2,g,3,.1,'k')