# Error creating GRIDMASK

**URL:** <https://forum.cmascenter.org/t/error-creating-gridmask/1254>\
**Category:** SMOKE\
**Created:** [January 23, 2020, 2:35pm UTC](https://forum.cmascenter.org/t/error-creating-gridmask/1254 "2020-01-23T14:35:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaofen](https://avatars.discourse-cdn.com/v4/letter/x/e79b87/32.png) [@xiaofen](https://forum.cmascenter.org/u/xiaofen)\
**Post date:** [January 23, 2020, 2:35pm UTC](https://forum.cmascenter.org/t/error-creating-gridmask/1254/1 "2020-01-23T14:35:04Z")

</div>

Hi all~

I am trying to generate my own GRIDMASK since I use other emission inventory instead of EDGAR. I wrote a f90 file to generate a GRIDMASK file. But when SMOKE was reading the GRIDMASK, the error shows up:

Value for PROMPTFLAG: N returning FALSE  
Error reading IDs for variable TZONES  
netCDF error number -49 processing file “GRIDMASK”  
NetCDF: Variable not found  
Could not open file “GRIDMASK”.

I guess the error is caused by the global attribute I wrote into GRIDMASK, which is

```
VAR-LIST = 'GEOCODE TZONES'

```

The attribute in EDGAR GRIDMASK is

```
VAR-LIST = 'GEOCODE TZONES '

```

There are some space behind ‘TZONES’. However I did put space behind ‘TZONES’ in the f90 file

```
character (len=34), parameter :: VAR_name = 'GEOCODE TZONES '

```

But it doesn’t work with the netcdf libraries. It seems that netcdf function will subtract the tail space. How can I solve it? Thank you in advance!

Best,  
Feng

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [January 23, 2020, 11:35pm UTC](https://forum.cmascenter.org/t/error-creating-gridmask/1254/2 "2020-01-23T23:35:52Z")

</div>

GRIDMASK is a I/O API file. I/O API is an acronym for Input/Output Applications **Programming** Interface. As the documentation says, **it is not a data format** (and so far, _every_ attempt that I have seen to treat it as a data format has failed in at least some way). [And, by the way, netCDF’s Fortran-C interface is a bit of a hack, especially insofar as character strings are concerned; you really don’t want to have to worry about all the troubles involved with that!]

If you want to create a `GRIDMASK` file from scratch, you need to treat it as a programming problem that uses the I/O API. A good place to start would be to modify one of the I/O API’s M3Tools programs to do the job you want. _ **m3mask** _ might be a good place to start.

Carlie J. Coats, Jr., Ph.D.  
I/O API Author/Maintainer

---

<div class="post-metadata">

**Author:** ![eyth.alison](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@eyth.alison](https://forum.cmascenter.org/u/eyth.alison)\
**Post date:** [January 24, 2020, 3:09pm UTC](https://forum.cmascenter.org/t/error-creating-gridmask/1254/3 "2020-01-24T15:09:58Z")

</div>

Hi, to expand on what Carlie is saying, you cannot create an  
I/O API file using only netCDF functions – you need to use the I/O API libraries as an interface. The approach you are taking is causing string formatting issues in the I/O API variable list that prevents the GRIDMASK netCDF variables  
from being read by SMOKE. Instead, try generating the GRIDMASK using the FORTRAN I/O API library.

---

<div class="post-metadata">

**Author:** ![xiaofen](https://avatars.discourse-cdn.com/v4/letter/x/e79b87/32.png) [@xiaofen](https://forum.cmascenter.org/u/xiaofen)\
**Post date:** [February 3, 2020, 2:04pm UTC](https://forum.cmascenter.org/t/error-creating-gridmask/1254/4 "2020-02-03T14:04:16Z")

</div>

Thank you @cjcoats @eyth.alison! The problem is solved.

---

<div class="post-metadata">

**Author:** ![xiaofen](https://avatars.discourse-cdn.com/v4/letter/x/e79b87/32.png) [@xiaofen](https://forum.cmascenter.org/u/xiaofen)\
**Post date:** [May 15, 2021, 12:28pm UTC](https://forum.cmascenter.org/t/error-creating-gridmask/1254/5 "2021-05-15T12:28:40Z")

</div>

hi all,

Since I received several messages asking how I generated GRIDMASK, I would like to answer it here. I used m3fake. The method is similar with generating dummy ocean file.
