Editing global attributes or making 2d file into 3d

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.


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.

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


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 {
TSTEP = UNLIMITED ; // (25 currently)
VAR = 62 ;
LAY = 3 ; [### here!]
ROW = 280 ;
COL = 280 ;
TFLAG:long_name = "TFLAG " ;
TFLAG:var_desc = "Timestep-valid flags: (1) YYYYDDD or (2) HHMMSS " ;
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 ;


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

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”.

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. Finally, got successful in implementing the method (CJC) suggested above.