How to add new variable to existing ioapi file?

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.

Use M3Tools program m3merge: see https://cjcoats.github.io/ioapi/M3MERGE.html

1 Like

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)?

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

1 Like

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

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
CHARACTER16, 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...
1 Like

Many thanks, it worked!