GDXEncoding

Table of Contents

Note
This tool is part of the GAMS Tools Library. Please inspect the general information about GAMS Tools.

This converts the unique elements in the GDX file from one [encoding] (https://docs.python.org/3/library/codecs.html#standard-encodings) to another one. The GDX string (a sequence of bytes) is decoded using encodingIn (default latin_1) into a proper unicode string and afterwards encoded again into a GDX string (byte array) using encodingOut (default utf_8). If verbose is set to 1 (default is 0) the converted unique elements are printed with new and old GDX strings (byte arrays) to the GAMS log. If the number of conversions is necessary in GAMS, a name of a scalar can be passed via numConv (default empty) which will hold the number of unique elements converted.

Usage

Command line:

gamstool [gdxservice.]GDXEncoding gdxFile [encodingIn=codeIn] [encodingOut=codeOut] [numConv=id gdxOut=fileOut.gdx]

Compile time:

$callTool [gdxservice.]GDXEncoding gdxFile [encodingIn=codeIn] [encodingOut=codeOut] [numConv=id]

Execution time:

executeTool '[gdxservice.]GDXEncoding gdxFile [encodingIn=codeIn] [encodingOut=codeOut] [numConv=id]';

Where:

| gdxFile | Name of GDX file. |

The following named parameters are available:

Argument Description
encodingIn=codeIn Input encoding of GDX string. Default is latin_1
encodingOut=codeOut Output encoding of GDX string. Default is utf_8.
numConv=id GAMS scalar symbol to store the number of actual conversions.
gdxOut=fileOut.gdx Name of GDX file that contains symbol numConv after execution. Mandatory if called from the command line with argument numConv set, otherwise optional.

Example

* UTF-8 encoding
Set c / "côte d'ivoire-3" , "cote d'ivoire-3" /;
Scalar numConv /0/;
$gdxUnload c.gdx c
* Changes the label encoding from UTF-8 to Latin-1:
$callTool gdxservice.gdxEncoding c.gdx encodingIn=utf_8 encodingOut=latin_1 numConv=numConv trace=1

The complete example is also part of the GAMS Test Library, see model [gdxencoding1] for reference.