Previous Next        Current Page: NeXtMidas Training / Primitives / Primitive Restarts / Preserving State
back
Start Here   
Background   
Common Midas Concepts   
Getting Started - Part 1   
Getting Started - Part 2   
Working with Files   
Option Trees   
Macros - Part 1 (Basics)   
Macros - Part 2 (Graphics)   
NetBeans - Part 1 (Setup)   
NetBeans - Part 2 (GUIs)   
NetBeans - Part 3 (Profiler)   
Eclipse - Part 1 (Setup)   
Eclipse - Part 2 (GUIs)   
Primitives   
   + Overview   
   + Open, Process, Close   
   + Building   
   + The NeXtMidas API   
   + Lab 1   
   + Special Variables   
   + Lab 2   
   + Lab 3*   
   + Files in a Primitive   
   + Lab 4   
   + Lab 5*   
   + Test Macros   
   + Lab 6   
   + Real Time Controls   
   + Lab 7   
   + Working with Messages   
   + Lab 8   
   - Primitive Restarts   
      - Using Restarts   
      - Control Flow (Restart)   
      - Control Flow (Restart)   
      - Restart-Safe Primitives   
      - Preserving State   
      - Restarting a Primitive   
   + Introduction to DSP   
   + Lab 9   
   - Commands executing commands   
WebStart   
Maps & Imagery   
X-Midas Interoperability   
RMIF & Remoting   
Installing NeXtMidas   
Support & Maintenance   
File Handlers   


  • Preserving State:
    • On occasion it may be necessary to preserve some state across a restart. The standard way to do this is as follows:
      • All variables where state is NOT preserved should be initialized in open().
      • All variables where state is preserved should be initialized in open() if they are null (or NaN, etc.), and be left unaltered otherwise.
      • Example:
        public class myprim extends Primitive {
          private double frameRate; // Default value set in open()
          private double frequency = 1024.0;
          private double amplitude = -1.0;
          
          public int open() {
            frameRate = MA.getD("RATE", 16.0);       // Always reset frameRate
            frequency = MA.getD("FREQ", frequency);  // Reset frequency if given on command line
            if (amplitude <= 0) {
              amplitude = MA.getD("AMP", 1.0);       // Always preserve amplitude
            }
            ...
          }
          
          public int process() { ... }
          public int close() { ... }
        }
        
        In the above example, following a restart...
        • frameRate is always reset back to its initial value (as given on the command line or 16.0).
        • frequency is reset back to its initial value ONLY if FREQ= was specified on the command line.
        • amplitude is always preserved.

back