Previous Next        Current Page: NeXtMidas Training / Primitives / Files in a Primitive / A Note About Files
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   
      - File Categories   
      - Getting Files   
      - Reading Frame-Based Data   
      - Writing Frame-Based Data   
      - Reading Record-Based Data   
      - Writing Record-Based Data   
      - A Note About Files   
   + Lab 4   
   + Lab 5*   
   + Test Macros   
   + Lab 6   
   + Real Time Controls   
   + Lab 7   
   + Working with Messages   
   + Lab 8   
   + Primitive Restarts   
   + Introduction to DSP   
   + Lab 9   
Applets & WebStart   
Maps & Imagery   
X-Midas Interoperability   
RMIF & Remoting   
Installing NeXtMidas   
Support & Maintenance   
File Handlers   


  • Important Note:
    • The past few slides have shown the most common ways of accessing frame-based and record-based data.
      • NeXtMidas provides alternative methods that may be more appropriate to a given situation.
        • FILE COPY treats all files as simple binary ones and uses byte-based read and write methods.
      • It is possible to treat most frame-based data as record-based and record-based as frame-based.
        • LIST2 treats all data as record-based (listing is an inherently record-based activity).
        • NOOP treats all data as frame-based (simplifies this primitive and improves copy speed).
Don't Make This Mistake:
  • Do not forget to close your input/output files in your primitive's close method, otherwise not all data may be written or your primitive may be holding on to resources that it no longer needs, causing a "resource/memory leak".
  • Additionally, you should check if your file is null otherwise you may get a NullPointerException.
public int close() {
  if (outfile!=null) {
    outfile.close();
  }
}
Java Experts Take Note:
File offsets and sizes are of type double. There are two reasons for this:
  • It allows bit indexing (fractional part indicates bit in byte) for frame-based data.
  • It is consistent with the definition of Midas Blue files. (The definition of a Blue file pre-dates widespread support for 64-bit integers, and the only way to support file size larger than 2GB was to use a double.)
Many new applications/primitives (like LIST2) that work with record-based data internally store row numbers as a long and cast it to double when reading/writing (this prevents the user from entering a fractional record number).