## D_ECMWF2ROMS Matlab scripts

### D_ECMWF2ROMS Matlab scripts

Dear all,

I am using D_ECMWF2ROMS to prepare the forcing ECMWF data for ROMS, but I still need to understand it clearly. I am a new ROMS user, so would you mind to help with the questions below:

1/ Why do we use F( 3).scale=? for each variable? Is it compulsory for ROMS?

2/ How do I select the mybasedate? should I select = datenum(1858,11,17,0,0,0) if I use HYCOM for initial/boundary conditions?

3/ How about LonMin LonMax LatMin LatMax ? Could I select these numbers to be larger than my grid domain? or these need to be same as the domain?

4/ Do I need to use the same time interval (e.g. every 3-hours) for all variables? or Could I use both 6 hours and 12 hours-interval? Does ROMS accepts it?

5. Last, what is the rule to arrange the forcing files in ocean*.in? if I use this script to prepare the forcing data.

Many thanks in advance!

Regards

Barack

I am using D_ECMWF2ROMS to prepare the forcing ECMWF data for ROMS, but I still need to understand it clearly. I am a new ROMS user, so would you mind to help with the questions below:

1/ Why do we use F( 3).scale=? for each variable? Is it compulsory for ROMS?

2/ How do I select the mybasedate? should I select = datenum(1858,11,17,0,0,0) if I use HYCOM for initial/boundary conditions?

3/ How about LonMin LonMax LatMin LatMax ? Could I select these numbers to be larger than my grid domain? or these need to be same as the domain?

4/ Do I need to use the same time interval (e.g. every 3-hours) for all variables? or Could I use both 6 hours and 12 hours-interval? Does ROMS accepts it?

5. Last, what is the rule to arrange the forcing files in ocean*.in? if I use this script to prepare the forcing data.

Many thanks in advance!

Regards

Barack

**Barack**

### Re: D_ECMWF2ROMS Matlab scripts

I don't use that tool, but I can answer some of these:

Just be consistent across everything from initial to boundary to forcing files. We chose 1900,1,1 some time ago and are sticking with it.2/ How do I select the mybasedate? should I select = datenum(1858,11,17,0,0,0) if I use HYCOM for initial/boundary conditions?

At least as big as your domain. We fetch the global grid to use for multiple domains.3/ How about LonMin LonMax LatMin LatMax ? Could I select these numbers to be larger than my grid domain? or these need to be same as the domain?

ROMS will read the time variable for each forcing variable independently. Note that to resolve diurnal variations in shortwave, for instance, three hours does better than 12 hours. We average three of the hourly MERRA records into one for 3-hourly fields.4/ Do I need to use the same time interval (e.g. every 3-hours) for all variables? or Could I use both 6 hours and 12 hours-interval? Does ROMS accepts it?

The order doesn't matter, though if you have both 2011 and 2012 in separate files, they have to be listed in chronological order.5. Last, what is the rule to arrange the forcing files in ocean*.in? if I use this script to prepare the forcing data.

### Re: D_ECMWF2ROMS Matlab scripts

Thanks Kate, actually I use this tool because I read this: viewtopic.php?f=30&t=3003

My first question is important because it relates to the scale, and time interval.. Any further help would always be appreciated!

Regards

Barack

My first question is important because it relates to the scale, and time interval.. Any further help would always be appreciated!

Regards

Barack

**Barack**

### Re: D_ECMWF2ROMS Matlab scripts

I wrote this code a long time ago so my memory of the details is a biz fuzzy, but it required some awkward programming to get the ECMWF results into the form ROMS expects.

The challenging thing is that several of the values in the ECMWF raw data files are reported as a cumulative sum over the forecast interval. This is noted in comments in the Matlab routine ...

ROMS wants forcing data in some units per time, e.g. Joules per second (i.e. Watts) but ECMWF have integrated this over time. You can't just divide by 3 hours because the value at hour 6 is the integral from hours 0 through 6, not from hour 3 to 6.

There is a table in the comments in the preamble to the routine noting the translations between ECMWF variables and ROMS forcing variables.

Unless ECMWF have changed how these data are stored, the code works provided you download all 3-hour interval data. That's why the instructions say:

The challenging thing is that several of the values in the ECMWF raw data files are reported as a cumulative sum over the forecast interval. This is noted in comments in the Matlab routine ...

Code: Select all

```
% If the scale F(n).scale is set to negative, the input ECMWF data is a
% cumulative integral in forecast cycle from hour zero.
% For steps at 6, 9 and 12 hours we must separate last 3 hours of
% integration from previous accumulation.
% At 3 hour step don't change anything
```

There is a table in the comments in the preamble to the routine noting the translations between ECMWF variables and ROMS forcing variables.

Code: Select all

```
% This dataset is written in compact way (short numbers). We need to
% convert to floating-point data and scale to ROMS units:
%
% Uwind (m s-1) v10u
% Vwind (m s-1) v10v
% sustr (N m-2) ewss / (3*3600); 3-hour step
% svstr (N m-2) nsss / (3*3600); 3-hour step
% shflux (W m-2) (ssr+str+sshf+slhf) / (3*3600)
% swrad (W m-2) ssr / (3*3600); 3-hour step
% lwrad_down (W m-2) strd / (3*3600); 3-hour step
% latent (W m-2) slhf / (3*3600); 3-hour step
% sensible (W m-2) sshf / (3*3600): 3-hour step
% rain (kg m-2 s-1) tp * Rho_w / (3*3600)
% evaporation (kg m-2 s-1) e * Rho_w / (3*3600)
% swflux (cm day-1) (-e - tp) * 100 / (3/24); 0.125 day step
% cloud (nondimesional) tcc
% Pair (mb) msl / 100; (1 mb = 100 Pa)
% Tair (Celsius) t2m - 273.15; (1 C = 273.15 K)
% Qair (percentage) 100 * (E/Es)
```

Unless ECMWF have changed how these data are stored, the code works provided you download all 3-hour interval data. That's why the instructions say:

Code: Select all

```
% The following parameters are used to extract ERA-Interim fields:
% Select time: 00:00:00 12:00:00
% Select step: 0 3 6 9 12
```

**If you skip some data in your download from ECMWF, say only downloading 0, 6, 12 time-steps, you almost certainly break the logic for unraveling the cumulative summations and will have incorrect heat fluxes.**John Wilkin: DMCS Rutgers University

71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

### Re: D_ECMWF2ROMS Matlab scripts

Thanks John for your clarification.

Is there any updated/easier scripts to prepare the forcing data I could look at?

Best,

Is there any updated/easier scripts to prepare the forcing data I could look at?

Best,

**Barack**

### Re: D_ECMWF2ROMS Matlab scripts

Hi All,

I am trying to use d_ecmwf2roms (I check out the file at revision 914) to generate a forcing file and I encountered the problem below. Am I missing some files/toolboxes? Any suggestion would be helpful. Thank you

I am trying to use d_ecmwf2roms (I check out the file at revision 914) to generate a forcing file and I encountered the problem below. Am I missing some files/toolboxes? Any suggestion would be helpful. Thank you

Code: Select all

```
** Creating ROMS NetCDF forcing file: gom_Tair_era.nc **
Wrote lon into record: , Min=-1.79250e+02 Max= 1.80000e+02
Wrote lat into record: , Min=-9.00000e+01 Max= 9.00000e+01
** Creating ROMS NetCDF forcing file: gom_Qair_era.nc **
Wrote lon into record: , Min=-1.79250e+02 Max= 1.80000e+02
Wrote lat into record: , Min=-9.00000e+01 Max= 9.00000e+01
** Processing: sustr for 01-Oct-2012 03:00:00 **
Undefined function or variable 'nc_int'.
Error in nc_read>nc_read_matlab (line 430)
case {nc_int, nc_short, nc_byte}
Error in nc_read (line 95)
f =
nc_read_matlab(ncfile,Vname,Tindex,ReplaceValue,PreserveType,Info);
Error in d_ecmwf2roms_na (line 476)
field = nc_read(InpFile, Vecmwf, Rec);
```

### Re: D_ECMWF2ROMS Matlab scripts

I think it is a little bug in the function of "nc_read", line 430.bkresning wrote: Undefined function or variable 'nc_int'.

Error in nc_read>nc_read_matlab (line 430)

case {nc_int, nc_short, nc_byte}

Error in nc_read (line 95)

f = nc_read_matlab(ncfile,Vname,Tindex,ReplaceValue,PreserveType,Info);

Error in d_ecmwf2roms_na (line 476)

field = nc_read(InpFile, Vecmwf, Rec);

It should be similar to the next "switch" block, means,

Code: Select all

```
case {netcdf.getConstant('nc_int'), ...
netcdf.getConstant('nc_short'), ...
netcdf.getConstant('nc_byte')}
f = double(f).*scale+offset;
```

Code: Select all

```
case {nc_int, nc_short, nc_byte}
f = double(f).*scale+offset;
```

### Re: D_ECMWF2ROMS Matlab scripts

Thank you, the suggested action solved the error.

- neelbasak08
**Posts:**99**Joined:**Wed Dec 09, 2020 3:58 pm**Location:**Thapar Institute of Engineering and Technology, Patiala, PN, India

### Re: D_ECMWF2ROMS Matlab scripts

Hello everyone,

I wanted to use d_ecmwf2roms.m matlab script to create forcing file for a grid which I created myself. But I am unable to understand how to use and run the script and what values I need to change in order to run that. Here are my grid file and other mexcdf and other snctools all added to matlab path and their location:

My location for files are as follows-

matlab_dir: C:\Users\aBc\Documents\MATLAB

mexcdf: C:\Users\aBc\Documents\MATLAB

netcdf_toolbox: C:\Users\aBc\Documents\MATLAB

'mygrid.nc' grid file: C:\Users\aBc\Documents\MATLAB

I just kept my grid file on which I want forcing in ran the code with changing anything. It gave the following error:

Thanks a lot and extreme regards

I wanted to use d_ecmwf2roms.m matlab script to create forcing file for a grid which I created myself. But I am unable to understand how to use and run the script and what values I need to change in order to run that. Here are my grid file and other mexcdf and other snctools all added to matlab path and their location:

My location for files are as follows-

matlab_dir: C:\Users\aBc\Documents\MATLAB

mexcdf: C:\Users\aBc\Documents\MATLAB

netcdf_toolbox: C:\Users\aBc\Documents\MATLAB

'mygrid.nc' grid file: C:\Users\aBc\Documents\MATLAB

I just kept my grid file on which I want forcing in ran the code with changing anything. It gave the following error:

I am quite new to ROMS (just ran the upwelling test case and created a grid on my own for myself using easygrid and just applied TPXO9 extraction to it ) and MATLAB, any help is extremely appreciated by me.>> d_ecmwf2roms

** Creating ROMS NetCDF forcing file: gom_sms_era.nc **

Error using internal.matlab.imagesci.nc/openToRead (line 1272)

Could not open ocean\repository\Projects\gom\Data\Forcing2\ecmwf_era_flux_2000.nc for reading.

Error in internal.matlab.imagesci.nc (line 121)

this.openToRead();

Error in ncinfo (line 88)

ncObj = internal.matlab.imagesci.nc(ncFile);

Error in nc_getatt>nc_getatt_matlab (line 117)

Info = ncinfo(ncfile);

Error in nc_getatt (line 65)

A = nc_getatt_matlab(ncfile, Aname, Vname); % Matlab native interface

Error in nc_inq (line 69)

A = nc_getatt(ncfile); % NetCDF file global attributes

Error in nc_read (line 77)

Info = nc_inq(ncfile);

Error in d_ecmwf2roms (line 296)

lon = nc_read(InpFile, 'longitude', ...

Thanks a lot and extreme regards

- neelbasak08
**Posts:**99**Joined:**Wed Dec 09, 2020 3:58 pm**Location:**Thapar Institute of Engineering and Technology, Patiala, PN, India

### Re: D_ECMWF2ROMS Matlab scripts

Hello everyone,

I wanted to use d_ecmwf2roms.m matlab script to create forcing file for a grid which I created myself. But I am unable to understand how to use and run the script and what values I need to change in order to run that. Here are my grid file and other mexcdf and other snctools all added to matlab path and their location:

My location for files are as follows-

matlab_dir: C:\Users\aBc\Documents\MATLAB

mexcdf: C:\Users\aBc\Documents\MATLAB

netcdf_toolbox: C:\Users\aBc\Documents\MATLAB

'mygrid.nc' grid file: C:\Users\aBc\Documents\MATLAB

I just kept my grid file on which I want forcing in ran the code with changing anything. It gave the following error:

Thanks a lot and extreme regards

I wanted to use d_ecmwf2roms.m matlab script to create forcing file for a grid which I created myself. But I am unable to understand how to use and run the script and what values I need to change in order to run that. Here are my grid file and other mexcdf and other snctools all added to matlab path and their location:

My location for files are as follows-

matlab_dir: C:\Users\aBc\Documents\MATLAB

mexcdf: C:\Users\aBc\Documents\MATLAB

netcdf_toolbox: C:\Users\aBc\Documents\MATLAB

'mygrid.nc' grid file: C:\Users\aBc\Documents\MATLAB

I just kept my grid file on which I want forcing in ran the code with changing anything. It gave the following error:

I am quite new to ROMS (just ran the upwelling test case and created a grid on my own for myself using easygrid and just applied TPXO9 extraction to it ) and MATLAB, any help is extremely appreciated by me.>> d_ecmwf2roms

** Creating ROMS NetCDF forcing file: gom_sms_era.nc **

Error using internal.matlab.imagesci.nc/openToRead (line 1272)

Could not open ocean\repository\Projects\gom\Data\Forcing2\ecmwf_era_flux_2000.nc for reading.

Error in internal.matlab.imagesci.nc (line 121)

this.openToRead();

Error in ncinfo (line 88)

ncObj = internal.matlab.imagesci.nc(ncFile);

Error in nc_getatt>nc_getatt_matlab (line 117)

Info = ncinfo(ncfile);

Error in nc_getatt (line 65)

A = nc_getatt_matlab(ncfile, Aname, Vname); % Matlab native interface

Error in nc_inq (line 69)

A = nc_getatt(ncfile); % NetCDF file global attributes

Error in nc_read (line 77)

Info = nc_inq(ncfile);

Error in d_ecmwf2roms (line 296)

lon = nc_read(InpFile, 'longitude', ...

Thanks a lot and extreme regards

### Re: D_ECMWF2ROMS Matlab scripts

This is a user modifiable script demonstrating how to create ROMS forcing NetCDF files, but you need to customize it for your own environment and application. The very first executable line in the script is:

which points to files the example user has downloaded from ECMWF. So clearly you need to modify this to point to files on your own computer.

The script is old and refers to ECMWF's ERA-Interim Dataset

at http://apps.ecmwf.int/datasets/data/interim_full_daily/ which has been superceded by ERA-5.

Maybe someone out there in the User Forum has already updated for ERA-5.

Code: Select all

```
% Path to downloaded ERA data files.
Dir = fullfile(getenv('HOME'), ...
'ocean/repository/Projects/gom/Data/Forcing2');
```

The script is old and refers to ECMWF's ERA-Interim Dataset

at http://apps.ecmwf.int/datasets/data/interim_full_daily/ which has been superceded by ERA-5.

Maybe someone out there in the User Forum has already updated for ERA-5.

John Wilkin: DMCS Rutgers University

71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu