# Editing global attributes or making 2d file into 3d

**URL:** <https://forum.cmascenter.org/t/editing-global-attributes-or-making-2d-file-into-3d/1598>\
**Category:** I/O API\
**Created:** [June 27, 2020, 6:12pm UTC](https://forum.cmascenter.org/t/editing-global-attributes-or-making-2d-file-into-3d/1598 "2020-06-27T18:12:51Z")\
**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:** [June 27, 2020, 6:12pm UTC](https://forum.cmascenter.org/t/editing-global-attributes-or-making-2d-file-into-3d/1598/1 "2020-06-27T18:12:51Z")

</div>

Hi,  
I want to add n layers to an ioapi file with 1 layer by repeating the data of the first layer to get another ioapi file with more layers.

Can anybody give hints? I do not know how to write another file from scratch :), and so was looking for some simpler tricks.

Also, isn’t it possible to edit global attribute NLAYS ? If it was possible, I think I could solve my problem.

Thanks

---

<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:** [June 27, 2020, 7:02pm UTC](https://forum.cmascenter.org/t/editing-global-attributes-or-making-2d-file-into-3d/1598/2 "2020-06-27T19:02:15Z")

</div>

This doesn’t really make sense. What you need to do is to write a program to read the data from the first file into 2-D arrays, copy/expand those 2-D arrays into 3-D arrays, and then write out the result to a new file.

In order to write such a program, you might want to look at one or more of the M3Tools programs (for which the source code is available) and adapt something from that – perhaps _m3cple.f90_ might be a good place to start.

---

<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:** [June 27, 2020, 9:29pm UTC](https://forum.cmascenter.org/t/editing-global-attributes-or-making-2d-file-into-3d/1598/3 "2020-06-27T21:29:11Z")

</div>

I appreciate your prompt reply and the hint. Finally, I am going to learn something useful. I will work on that.

Thanks.

---

<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:** [June 27, 2020, 11:45pm UTC](https://forum.cmascenter.org/t/editing-global-attributes-or-making-2d-file-into-3d/1598/4 "2020-06-27T23:45:41Z")

</div>

just in case if I can explain what I meant by changing NLAYS.

I have created a 3D layered file (somehow) and that file is recognized by IOAPI tools. A simple program m3xtract, for instance, recognizes the file, however, it sees only the 1st layer in the data although the file has 3 layers (when viewed with ncdump, or ncview). I am not sure what is the basis for the m3tools to read the vertical dimensionality but I suspect it is by reading NLAYS in the global attributes?  
ncdump to my input 3D file (created from 2D file) looks like  
netcdf emis\_mole\_all\_1KM {  
dimensions:  
TSTEP = UNLIMITED ; // (25 currently)  
VAR = 62 ;  
DATE-TIME = 2 ;  
LAY = 3 ; [### here!]  
ROW = 280 ;  
COL = 280 ;  
variables:  
int TFLAG(TSTEP, VAR, DATE-TIME) ;  
TFLAG:units = “\<YYYYDDD,HHMMSS\>” ;  
TFLAG:long\_name = "TFLAG " ;  
TFLAG:var\_desc = "Timestep-valid flags: (1) YYYYDDD or (2) HHMMSS " ;  
float ACET(TSTEP, LAY, ROW, COL) ;  
ACET:\_FillValue = NaNf ;  
ACET:long\_name = "ACET " ;  
ACET:units = "mole/s " ;  
ACET:var\_desc = "ACET[1]  
…  
:NTHIK = 1 ;  
:NCOLS = 280 ;  
:NROWS = 280 ;  
:NLAYS = 1 ; [### here!]  
:NVARS = 62 ;  
:GDTYP = 2 ;

Thanks

---

<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:** [June 28, 2020, 10:49am UTC](https://forum.cmascenter.org/t/editing-global-attributes-or-making-2d-file-into-3d/1598/5 "2020-06-28T10:49:28Z")

</div>

But this is **not** a correctly formed I/O API file.

I/O API stands for Input/Output Applications Programming Interface. See [https://en.wikipedia.org/wiki/Application\_programming\_interface](https://en.wikipedia.org/wiki/Application_programming_interface)

**This is not a data format !!** …and **treating it as one is _not_ supported;** there are internal data structures that you will not get right (no one trying to do it that way has!). By analogy, if _.docx_ files were treated as just another data format, you can and would use a binary hex editor to edit them, instead of using the _MSWord_ program or a library such as _python-docx_ – it’s not something you do “by hand”.

---

<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:** [June 28, 2020, 11:49am UTC](https://forum.cmascenter.org/t/editing-global-attributes-or-making-2d-file-into-3d/1598/6 "2020-06-28T11:49:42Z")

</div>

That is an useful information, and so I have started learning IOAPI tools in details.  
BTW I have been able to use other languages to modify ioapi files’ data though ( i.e. without modifying the data structures but just the data values).

Thanks

---

<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:** [June 29, 2020, 1:17am UTC](https://forum.cmascenter.org/t/editing-global-attributes-or-making-2d-file-into-3d/1598/7 "2020-06-29T01:17:31Z")

</div>

Thanks. Finally, got successful in implementing the method (CJC) suggested above.
