HDFPT.C
Upload User: jihankui
Upload Date: 2013-03-01
Package Size: 5664k
Code Size: 5k
Development Platform:

Matlab

  1. /* Copyright (c) 1984-98 by The MathWorks, Inc. */
  2. /*
  3.  * hdfpt.c --- support file for HDF.MEX
  4.  *
  5.  * This module supports the HDF-EOS PT interface.  The only public
  6.  * function is hdfPT(), which is called by mexFunction().
  7.  * hdfPT looks at the second input argument to determine which
  8.  * private function should get control.
  9.  *
  10.  * Syntaxes
  11.  * ========
  12.  */
  13. /* $Revision: 1.3 $  $Date: 1997/11/21 23:36:48 $ */
  14. #ifdef USE_EOS
  15. static char rcsid[] = "$Id: hdfpt.c,v 1.3 1997/11/21 23:36:48 moler Exp $";
  16. #include <string.h>
  17. #include <math.h>
  18. /* Main HDF library header file */
  19. #include "hdf.h"
  20. /* MATLAB API header file */
  21. #include "mex.h"
  22. /* HDFMEX utility functions */
  23. #include "hdfutils.h"
  24. /*
  25.  * hdfPTattach
  26.  *
  27.  * Purpose: gateway to PTannlen()
  28.  *          attaches to an existing point within the file.
  29.  *
  30.  * MATLAB usage:
  31.  * point_id = hdf('PT', 'attach', ptfile_id, pointname)
  32.  *            returns -1 on failure.
  33.  */
  34. static void hdfPTattach(int nlhs,
  35.                         mxArray *plhs[],
  36.                         int nrhs,
  37.                         const mxArray *prhs[])
  38. {
  39.     int32 pointfile_id;
  40.     char *pointName = NULL;
  41.     int32 point_id;
  42.     
  43.     haNarginChk(4, 4, nrhs);
  44.     haNargoutChk(0, 1, nlhs);
  45.     
  46.     pointfile_id = (int32) haGetDoubleScalar(prhs[2], "Point file ID");
  47.     pointname = haGetString(pointname, "Point name");
  48.     point_id = PTattach(pointfile_id, pointname);
  49.     if (point_id != FAIL)
  50.     {
  51.         haAddIDToList(point_id, PT_ID_List);
  52.     }
  53.     plhs[0] = haCreateDoubleScalar(point_id);
  54.     mxFree(pointname);
  55. }
  56. /*
  57.  * hdfPTattrinfo
  58.  *
  59.  * Purpose: gateway to PTattrinfo()
  60.  *          returns information about a point attribute
  61.  *
  62.  * MATLAB usage:
  63.  * [numbertype, count, status] = hdf('PT','attrinfo',point_id,attr_name)
  64.  */
  65. static void hdfPTattrinfo(int nlhs,
  66.                           mxArray *plhs[],
  67.                           int nrhs,
  68.                           const mxArray *prhs[])
  69. {
  70.     char *attr_name = NULL;
  71.     int32 point_id;
  72.     int32 number_type;
  73.     int32 count;
  74.     intn status;
  75.     
  76.     haNarginChk(4, 4, nrhs);
  77.     haNargoutChk(0, 1, nlhs);
  78.     point_id = (int32) haGetDoubleScalar(prhs[2], "Point ID");
  79.     attr_name = haGetString(prhs[3], "Attribute name");
  80.     
  81.     status = PTattrinfo(point_id, attr_name, &number_type, &count);
  82.     mxFree(attr_name);
  83.     
  84.     if (status == SUCCEED)
  85.     {
  86.         plhs[0] = haCreateDoubleScalar((double) number_type);
  87.         
  88.         if (nlhs > 1)
  89.         {
  90.             plhs[1] = haCreateDoubleScalar((double) count);
  91.         }
  92.         
  93.         if (nlhs > 2)
  94.         {
  95.             plhs[2] = haCreateDoubleScalar((double) status);
  96.         }
  97.     }
  98.     else
  99.     {
  100.         plhs[0] = EMPTY;
  101.         
  102.         if (nlhs > 1)
  103.         {
  104.             plhs[1] = EMPTY;
  105.         }
  106.         
  107.         if (nlhs > 2)
  108.         {
  109.             plhs[2] = status;
  110.         }
  111.     }
  112. }
  113. /*
  114.  * hdfPTopen
  115.  *
  116.  * Purpose: gateway to PTopen()
  117.  *          opens or creates HDF file
  118.  *
  119.  * MATLAB usage:
  120.  * point_file_id = hdf('PT', 'open', filename, access)
  121.  *          access can be 'read', 'readwrite', or 'create'
  122.  *
  123.  */
  124. static void hdfPTopen(int nlhs,
  125.                       mxArray *plhs[],
  126.                       int nrhs,
  127.                       const mxArray *prhs[])
  128. {
  129.     intn access;
  130.     char *filename;
  131.     int32 point_file_id;
  132.     haNarginChk(4, 4, nrhs);
  133.     haNargoutChk(0, 1, nlhs);
  134.     
  135.     filename = haGetString(prhs[2], "Filename");
  136.     access = haGetAccessMode(prhs[3]);
  137.     
  138.     point_file_id = PTopen(filename, access);
  139.     if (point_file_id != FAIL)
  140.     {
  141.         status = haAddIDToList(point_file_id, Pointfile_ID_List);
  142.         if (status == FAIL)
  143.         {
  144.             /* 
  145.              * Couldn't add the file_id to the list.  This might
  146.              * cause data loss later, so we don't allow it.
  147.              */
  148.             PTclose(point_file_id);
  149.             point_file_id = FAIL;
  150.         }
  151.     }
  152.     
  153.     plhs[0] = haCreateDoubleScalar((double) point_file_id);
  154.     
  155.     mxFree(filename);
  156. }
  157. /*
  158.  * hdfPT
  159.  *
  160.  * Purpose: Function switchyard for the PT part of the HDF-EOS gateway.
  161.  *
  162.  * Inputs:  nlhs --- number of left-side arguments
  163.  *          plhs --- left-side arguments
  164.  *          nrhs --- number of right-side arguments
  165.  *          prhs --- right-side arguments
  166.  *          functionStr --- string specifying which AN function to call
  167.  * Outputs: none
  168.  * Return:  none
  169.  */
  170. void hdfPT(int nlhs,
  171.            mxArray *plhs[],
  172.            int nrhs,
  173.            const mxArray *prhs[],
  174.            char *functionStr)
  175. {
  176.     void (*func)(int nlhs, mxArray *plhs[], 
  177.                  int nrhs, const mxArray *prhs[]);
  178.     if (strcmp(functionStr, "attach") == 0)
  179.     {
  180.         func = hdfPTattach;
  181.     }
  182.     else if (strcmp(functionStr, "attrinfo") == 0)
  183.     {
  184.         func = hdfPTattrinfo;
  185.     }
  186.     else if (strcmp(functionStr, "open") == 0)
  187.     {
  188.         func = hdfPTopen;
  189.     }
  190.     else
  191.     {
  192.         mexErrMsgTxt("Unknown PT interface function.");
  193.     }
  194.     (*func)(nlhs, plhs, nrhs, prhs);
  195. }
  196. #endif /* USE_EOS */