Initializing help system before first use

Defining and retrieving annotations


Type: Programming
Rating: 2
Description:
  • annottest.mos: Defining and accessing annotations
  • annotdisplay.c: Retrieving annotations into a C program (requires annottest.mos)
  • annotdisplay.java: Retrieving annotations into a Java program (requires annottest.mos)
File(s): annottest.mos, annotdisplay.c, annotdisplay.java


annottest.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file annottest.mos 
   ``````````````````
   Defining and accessing annotations.
 
   (c) 2015 Fair Isaac Corporation
       author: . Colombani, S. Heipcke, Mar. 2015
*******************************************************!)
model "Using annotations"
 uses "mmjobs", "mmsystem"
 
 public declarations
(!@.
  @value.first 5
  @value.second 0
  @descr A scalar value
 !)
   myint: integer   
   AnnNames: set of string          !@descr Set of annotation names  
   Ann: array(string) of string     !@descr Annotation values  
   mytxt: text                      !@descr Default input data file 
 end-declarations
 
 !@descr Annotations test
 !@furtherinfo Simply displays all defined global or specific annotations
 
 ! Get all global annotations defined in this model:
 getannotations("", "", AnnNames, Ann)
 writeln("Global annotations:")
 forall(a in AnnNames) writeln("  ", a, " = ", Ann(a))

 ! Get all annotations for "myint":
 getannotations("myint", "", AnnNames, Ann)
 writeln("Annotations defined for 'myint':")
 forall(a in AnnNames) writeln("  ", a, " = ", Ann(a))

 ! Retrieve all annotations starting with 'value.' and that are
 ! associated to 'myint'
 getannotations("myint", "value.", AnnNames, Ann)
 writeln("'value' annotations for 'myint':")
 forall(a in AnnNames) writeln("  ", a, " = ", Ann(a))

end-model

annotdisplay.c
/*******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file annotdisplay.c
   ```````````````````
   Compiling and loading a model to retrieve some
   annotations from it for display.
   
   (c) 2015 Fair Isaac Corporation
       author: S. Heipcke, Mar. 2015
********************************************************/

#include 
#include 
#include "xprm_mc.h"

/* Maximum number of annotations */
#define MAXANN 100

int main()
{
 XPRMmodel mod;
 void *ref;
 const char *symb;                    /* A model object name */
 const char *ann[MAXANN*2];           /* List of annotations */
 int i,n;

 if(XPRMinit())                       /* Initialize Mosel */
  return 1;

 if(XPRMcompmod(NULL, "annottest.mos", NULL, "Annotation example"))
  return 2;                           /* Compile the model into a BIM */

 if((mod=XPRMloadmod("annottest.bim",NULL))==NULL)  /* Load the BIM file */
  return 3;

/* Retrieve and display global annotations */
 n=XPRMgetannotations(mod,NULL,NULL,ann,MAXANN*2);
 printf("Global annotations (total: %d):\n", n/2);
 for(i=0;i\n",symb);
  for(i=0;i

annotdisplay.java
/*******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file annotdisplay.java
   ``````````````````````
   Compiling and loading a model to retrieve some
   annotations from it for display.
   
   (c) 2015 Fair Isaac Corporation
       author: S. Heipcke, Mar. 2015
********************************************************/

import com.dashoptimization.*;

public class annotdisplay
{
 public static void main(String[] args) throws Exception
 {
  XPRM mosel;
  XPRMModel mod;
  XPRMAnnotation ann[];                         // List of annotations

  mosel = new XPRM();                           // Initialize Mosel

  mosel.compile("annottest.mos");           // Compile the model into a BIM 
  mod = mosel.loadModel("annottest.bim");   // Load the BIM file

// Retrieve and display global annotations
  ann=mod.getAnnotations("");
  System.out.println("Global annotations (total: "+ ann.length +"):");
  for(int i=0;i");
   for(int i=0;i