Back to Philip's IMMA page.

IMMA.js

IMMA.js is a core JavaScript class allowing IMMA records to be used by JavaScript programs. It provides methods for packing, unpacking and manipulating IMMA records.

IMMA records are objects with the usual JavaScript properties. Data values (parameters) are accessible through the object. I.e. if the object is record (record = new IMMA(string_representation);) the observation year is stored as record.YR, the sea-surface temperature is record.SST, and the wet-bulb temperature indicator is record.WBTI. The parameters available are those listed in the IMMA documentation, but note that they are not all guaranteed to be available: if the record has no SST given, record.SST will be null. (One extra parameter is available: record.string is the string representation of the record).

Methods

  1. new: Create a new IMMA object
    Usage: record = new IMMA(string_representation);
    Creats a new record - unpacks the string and creates all the parameters in the object (calls unpackString().


  2. unpackString(): unpacks all the parameters from the string representation. (I.e. record.unpackString() gets record.YR, record.SST etc. from record.string).


  3. packString(): creates the string representation from the parameters. (I.e. record.packString() creates record.string from record.YR, record.SST etc.).


  4. checkParameter(parameter_name): checks that the named parameter has a value in the ranges specified by the IMMA definition. (I.e. record.checkParamater("YR") checks that record.YR is between 1600 and 2024).


Examples

The class enables IMMA records to be displayed and manipulated by web scripts. If an IMMA file is retrieved with xmlHttpRequest() the contents can be decode and displayed on the web using client JavaScript. See the IMMA online editor for an example application.

Extensions

IMMA is designed to be extensible. Each IMMA record contains a core component and a number of optional extensions (described in the documentation). The details of data for the core and each extension is defined in the IMMA.attachments, IMMA.parameters and IMMA.definitions arrays - these are defined as class variables in the source file.

Users will only need to be aware of attachments when explicitly adding or deleting an attachment from an IMMA record. To do this, manipulate the attachments parameter of the IMMA record: this is a list of the attachments possessed by the record. So, for example record.attachments.push(3) will add a model quality control attachment (with all data undefined) to record, 3 is the attachment ID of model quality control attachments.