# How to add new variable to existing ioapi file?

**URL:** <https://forum.cmascenter.org/t/how-to-add-new-variable-to-existing-ioapi-file/1427>\
**Category:** I/O API\
**Created:** [April 10, 2020, 9:39pm UTC](https://forum.cmascenter.org/t/how-to-add-new-variable-to-existing-ioapi-file/1427 "2020-04-10T21:39:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![CMAQ\_user](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@CMAQ\_user](https://forum.cmascenter.org/u/CMAQ_user)\
**Post date:** [April 10, 2020, 9:39pm UTC](https://forum.cmascenter.org/t/how-to-add-new-variable-to-existing-ioapi-file/1427/1 "2020-04-10T21:39:40Z")

</div>

Hi (@cjcoats),

I tried to add new variable to an IOAPI file using python, but the IOAPI tools couldn’t recognize the new variable (meaning didn’t show the new varialbes when using other tools such as m3xtract to see if the modified file is ioapi compliant). Could you hint how to include new variable in the existing m3file? (The new variable will have a similar dimensionality as the rest of the variables that are already there)

Thank you.

---

<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:** [April 10, 2020, 9:46pm UTC](https://forum.cmascenter.org/t/how-to-add-new-variable-to-existing-ioapi-file/1427/2 "2020-04-10T21:46:08Z")

</div>

Use M3Tools program _m3merge_: see [https://cjcoats.github.io/ioapi/M3MERGE.html](https://cjcoats.github.io/ioapi/M3MERGE.html)

---

<div class="post-metadata">

**Author:** ![CMAQ\_user](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@CMAQ\_user](https://forum.cmascenter.org/u/CMAQ_user)\
**Post date:** [April 10, 2020, 9:49pm UTC](https://forum.cmascenter.org/t/how-to-add-new-variable-to-existing-ioapi-file/1427/3 "2020-04-10T21:49:36Z")

</div>

wow, you are so quick! Thanks.

By the way, both files are not already ioapi - meaning, I would do some manipulations of the variables that are already in one of the ioapi file, and create more variables out of it, for example by adding some 17 variables together. What is the netcdf format the data must be saved for it to be compatible with IOAPI tools, if I create/modify the files in other programming languages such as python (e.g. netcdf3\_classic)?

---

<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:** [April 10, 2020, 10:16pm UTC](https://forum.cmascenter.org/t/how-to-add-new-variable-to-existing-ioapi-file/1427/4 "2020-04-10T22:16:01Z")

</div>

For the non-I/O API data, you need to convert it into I/O API data.  
The easiest way is to turn the data into CSV, then use the M3Tools  
program “m3fake” to read that and write out I/O API.

– Carlie

---

<div class="post-metadata">

**Author:** ![CMAQ\_user](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@CMAQ\_user](https://forum.cmascenter.org/u/CMAQ_user)\
**Post date:** [April 21, 2020, 12:45am UTC](https://forum.cmascenter.org/t/how-to-add-new-variable-to-existing-ioapi-file/1427/7 "2020-04-21T00:45:45Z")

</div>

sorry to bother, but I have a question: (the problem is not having found a simple and ‘complete’) example which would show how to read, and write ioapi file)

I was trying to read an ioapi file using the following arrangement.  
setenv GRID\_CRO\_2D /home/GRIDCRO2D\_20130108.nc  
echo $GRIDCRO2D  
./open.exe

It says file not available, can you hint a bit?

the program (shwon below) compliles but execution throws error.

…  
USE M3UTILIO  
IMPLICIT NONE  
CHARACTER_16 PNAME  
CHARACTER_16 GRID\_CRO\_2D  
INTEGER LOGDEV  
DATA PNAME / ‘myProg’ /

```
  LOGDEV = INIT3() ! initialization returns unit # for log
  CALL GETENV('GRID_CRO_2D', GRID_CRO_2D)
  PRINT*,GRID_CRO_2D
  IF ( .NOT. OPEN3( GRID_CRO_2D, FSREAD3, PNAME ) ) THEN
  PRINT*,'No'
  END IF

```

…

Thank you.

---

<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:** [April 21, 2020, 2:16pm UTC](https://forum.cmascenter.org/t/how-to-add-new-variable-to-existing-ioapi-file/1427/8 "2020-04-21T14:16:07Z")

</div>

There’s some confusion about names and values here: the `OPEN3` argument should be the name, not the value (returned from `GETENV`). And by the way, that environment value is a file system path, which (according to the POSIX standard, may use at least 512 characters (maybe more on some systems).  
By using program-variable `GRID_CRO_2D`, you’re passing (the first 16 characters _“/home/GRIDCRO2D\_”_ of) the file’s path-name into `OPEN3`.  
So, instead:  
PROGRAM MYPROG  
USE M3UTILIO  
IMPLICIT NONE  
CHARACTER_16, PARAMETER :: PNAME = ‘MyProg’  
CHARACTER_512 GC2 !! change the name, to avoid any confusion in reading this code here  
INTEGER LOGDEV  
LOGDEV = INIT3() ! initialization returns unit # for log  
CALL GETENV(‘GRID\_CRO\_2D’, GC2)  
PRINT\*, GC2  
!! Note the quoted name ‘GRID\_CRO\_2D’ in what follows:  
IF ( .NOT. OPEN3( ‘GRID\_CRO\_2D’, FSREAD3, PNAME ) ) THEN…

Or equivalently:

```
    PROGRAM MYPROG
USE M3UTILIO
IMPLICIT NONE
CHARACTER*16, PARAMETER :: PNAME = 'MyProg'
CHARACTER*16, PARAMETER :: GNAME = 'GRID_CRO_2D'
CHARACTER*512 GC2 !! change the name, to avoid any confusion in reading this code here
INTEGER LOGDEV
LOGDEV = INIT3() ! initialization returns unit # for log
CALL GETENV('GRID_CRO_2D', GC2)
PRINT*, GC2
IF ( .NOT. OPEN3( GNAME, FSREAD3, PNAME ) ) THEN...
```

---

<div class="post-metadata">

**Author:** ![CMAQ\_user](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@CMAQ\_user](https://forum.cmascenter.org/u/CMAQ_user)\
**Post date:** [April 21, 2020, 4:57pm UTC](https://forum.cmascenter.org/t/how-to-add-new-variable-to-existing-ioapi-file/1427/9 "2020-04-21T16:57:50Z")

</div>

Many thanks, it worked!
