示例#1
0
    /**
    * \fn msiNcOpenGroup (msParam_t *rootNcidParam, msParam_t *fullGrpNameParam,
    msParam_t *outParam, ruleExecInfo_t *rei)
    * \brief Open a fully qualified group name and get the group id.  nc_inq_grp_full_ncid is called to get the grpncid
    * \module core
    *
    * \since 3.2
    *
    * \author  Mike Wan
    * \date    2012
    *
    * \usage See clients/icommands/test/rules3.0/netcdfTest1.r, netcdfTest2.r and netcdfTest3.r.
    * \param[in] rootNcidParam - An INT_MS_T containing the rootNcid.
    * \param[in] fullGrpNameParam - A STR_MS_T containing the full group name
    * \param[out] outParam - An INT_MS_T containing the group ncid
    *
    **/
    int
    msiNcOpenGroup (msParam_t *rootNcidParam, msParam_t *fullGrpNameParam,
    msParam_t *outParam, ruleExecInfo_t *rei)
    {
        rsComm_t *rsComm;
        ncOpenInp_t ncOpenInp;
        int *grpNcid = NULL;

        RE_TEST_MACRO ("    Calling msiNcOpenGroup")

        if (rei == NULL || rei->rsComm == NULL) {
          rodsLog (LOG_ERROR,
            "msiNcOpenGroup: input rei or rsComm is NULL");
          return (SYS_INTERNAL_NULL_INPUT_ERR);
        }
        rsComm = rei->rsComm;

        bzero (&ncOpenInp, sizeof (ncOpenInp));
        if (rootNcidParam == NULL) {
            rodsLog (LOG_ERROR,
              "msiNcOpenGroup: input rootNcidParam is NULL");
            return (SYS_INTERNAL_NULL_INPUT_ERR);
        }
        ncOpenInp.rootNcid = parseMspForPosInt (rootNcidParam);
        if (strcmp (fullGrpNameParam->type, STR_MS_T) == 0) {
            rstrcpy (ncOpenInp.objPath, (char*)fullGrpNameParam->inOutStruct,
              MAX_NAME_LEN);
        } else {
            rodsLog (LOG_ERROR,
              "msiNcOpenGroup: Unsupported input fullGrpNameParam type %s",
              fullGrpNameParam->type);
            return (USER_PARAM_TYPE_ERR);
        }
        rei->status = irods::server_api_call ( NC_OPEN_GROUP_AN, rsComm, &ncOpenInp, &grpNcid);

        clearKeyVal (&ncOpenInp.condInput);
        if (rei->status >= 0) {
            fillIntInMsParam (outParam, *grpNcid);
            free (grpNcid);
        } else {
          rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
            "msiNcOpenGroup: api call to ncOpenGroup failed for rootNcid %d, status = %d",
            ncOpenInp.rootNcid, rei->status);
        }
        return (rei->status);
    }
示例#2
0
/**
 * \fn writePosInt(msParam_t* where, msParam_t* inInt, ruleExecInfo_t *rei)
 *
 * \brief  This microservice writes a positive integer into a buffer.
 *
 * \module core
 *
 * \since pre-2.1
 *
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] where - a msParam of type STR_MS_T which is the buffer name in ruleExecOut.
 * \param[in] inInt - the integer to write
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
 **/
int writePosInt( msParam_t* where, msParam_t* inInt, ruleExecInfo_t *rei ) {
    char *writeId;
    char writeStr[LONG_NAME_LEN];
    int status;

    if ( where->inOutStruct != NULL ) {
        writeId = ( char* )where->inOutStruct;
    }
    else {
        writeId = where->label;
    }

    if ( inInt->inOutStruct != NULL ) {
        sprintf( writeStr, "%d", parseMspForPosInt( inInt ) );
    }
    else {
        snprintf( writeStr, LONG_NAME_LEN, "%s", inInt->label );
    }

    status = _writeString( writeId, writeStr, rei );

    return status;
}
    /**
    * \fn msiNcGetElementInArray (msParam_t *arrayStructParam, msParam_t *indexParam, msParam_t *outParam, ruleExecInfo_t *rei)
    * \brief Get the value of an element in an array. The position of the element in the array is given in the indexParam input.
    * \module core
    *
    * \since 3.2
    *
    * \author  Mike Wan
    * \date    2012
    *
    * \usage See clients/icommands/test/rules3.0/netcdfTest1.r, netcdfTest2.r and netcdfTest3.r.
    * \param[in] indexParam - An INT_MS_T containing the index of an element in the array
    * \param[out] outParam - An INT_MS_T, CHAR_MS_T, STR_MS_T, or DOUBLE_MS_T, etc (depending on the dataType of the array) containing the value of the element).
    *
    * \DolVarDependence none
    * \DolVarModified none
    * \iCatAttrDependence none
    * \iCatAttrModified none
    * \sideeffect none
    *
    * \return integer
    * \retval 0 upon success
    * \pre N/A
    * \post N/A
    * \sa N/A
    *
    **/
    int
    msiNcGetElementInArray (msParam_t *arrayStructParam, msParam_t *indexParam,
    msParam_t *outParam, ruleExecInfo_t *rei)
    {
        int myindex;
        void *myarray;
        int dataType;
        int arrayLen;
        char *charArray;
        int *intArray;
        float *floatArray;
        rodsLong_t *longArray;
        char **strArray;

        RE_TEST_MACRO ("    Calling msiNcGetElementInArray")

        if (arrayStructParam == NULL || indexParam == NULL ||
          outParam == NULL) return USER__NULL_INPUT_ERR;

        if (strcmp (arrayStructParam->type, NcInqWithIdOut_MS_T) == 0) {
            /* intArray for the id array */
            ncInqWithIdOut_t *ncInqWithIdOut;
            ncInqWithIdOut = (ncInqWithIdOut_t *) arrayStructParam->inOutStruct;
            dataType = NC_INT;
            myarray = (void *) ncInqWithIdOut->intArray;
            arrayLen = ncInqWithIdOut->ndim;
        } else if (strcmp (arrayStructParam->type, NcGetVarOut_MS_T) == 0) {
            ncGetVarOut_t *ncGetVarOut;
            ncGetVarOut = (ncGetVarOut_t *) arrayStructParam->inOutStruct;
            if (ncGetVarOut == NULL || ncGetVarOut->dataArray == NULL)
                return USER__NULL_INPUT_ERR;
            dataType = ncGetVarOut->dataArray->type;
            myarray = ncGetVarOut->dataArray->buf;
            arrayLen = ncGetVarOut->dataArray->len;
        } else {
            rodsLog (LOG_ERROR,
              "msiNcGetNumDim: Unsupported input Param type %s",
              arrayStructParam->type);
            return (USER_PARAM_TYPE_ERR);
        }
        myindex = parseMspForPosInt (indexParam);
        if (myindex < 0 || myindex >= arrayLen) {
            rodsLog (LOG_ERROR,
              "msiNcGetElementInArray: input index %d out of range. arrayLen = %d",
              myindex, arrayLen);
            return (NETCDF_DIM_MISMATCH_ERR);
        }

        switch (dataType) {
          case NC_CHAR:
          case NC_BYTE:
          case NC_UBYTE:
            charArray = (char *) myarray;
            fillCharInMsParam (outParam, charArray[myindex]);
            break;
          case NC_STRING:
            strArray = (char **) myarray;
            fillStrInMsParam (outParam, strArray[myindex]);
            break;
          case NC_INT:
          case NC_UINT:
            intArray = (int *) myarray;
            fillIntInMsParam (outParam, intArray[myindex]);
            break;
          case NC_FLOAT:
            floatArray = (float *) myarray;
            fillFloatInMsParam (outParam, floatArray[myindex]);
            break;
          case NC_INT64:
          case NC_UINT64:
          case NC_DOUBLE:
            longArray = (rodsLong_t *) myarray;
            fillDoubleInMsParam (outParam, longArray[myindex]);
            break;
          default:
            rodsLog (LOG_ERROR,
              "msiNcGetElementInArray: Unknow dataType %d", dataType);
            return (NETCDF_INVALID_DATA_TYPE);
        }
        return 0;
    }
    /**
    * \fn msiNcGetDimNameInInqOut (msParam_t *ncInqOutParam, msParam_t *inxParam,
    msParam_t *varNameParam, msParam_t *outParam, ruleExecInfo_t *rei)
    * \brief Get the name of a dimension in a NcInqOut_MS_T
    * \module core
    *
    * \since 3.2
    *
    * \author  Mike Wan
    * \date    2012
    *
    * \usage See clients/icommands/test/rules3.0/netcdfTest1.r, netcdfTest2.r and netcdfTest3.r.
    * \param[in] ncInqOutParam - A NcInqOut_MS_T which is the output of msiNcInq.
    * \param[in] inxParam - An INT_MS_T containing the index of an element in the variable's dimension array
    * \param[in] varNameParam - A STR_MS_T containing the name of a variable
    * \param[out] outParam - A STR_MS_T containing the name of the dimension
    *
    * \DolVarDependence none
    * \DolVarModified none
    * \iCatAttrDependence none
    * \iCatAttrModified none
    * \sideeffect none
    *
    * \return integer
    * \retval 0 upon success
    * \pre N/A
    * \post N/A
    * \sa N/A
    *
    **/
    int
    msiNcGetDimNameInInqOut (msParam_t *ncInqOutParam, msParam_t *inxParam,
    msParam_t *varNameParam, msParam_t *outParam, ruleExecInfo_t *rei)
    {
        ncInqOut_t *ncInqOut;
        int inx, i;
        char *name = NULL;

        RE_TEST_MACRO ("    Calling msiNcGetDimNameInInqOut")

        if (ncInqOutParam == NULL || inxParam == NULL || outParam == NULL)
            return USER__NULL_INPUT_ERR;

        if (strcmp (ncInqOutParam->type, NcInqOut_MS_T) != 0) {
            rodsLog (LOG_ERROR,
              "msiNcGetDimNameInInqOut: ncInqOutParam must be NcInqOut_MS_T. %s",
              ncInqOutParam->type);
            return (USER_PARAM_TYPE_ERR);
        } else {
            ncInqOut = (ncInqOut_t *) ncInqOutParam->inOutStruct;
        }
        inx = parseMspForPosInt (inxParam);
        if (inx < UNLIMITED_DIM_INX || inx >= ncInqOut->ndims) {
            rodsLog (LOG_ERROR,
              "msiNcGetDimNameInInqOut: input inx %d is out of range. ndims  = %d",
              inx, ncInqOut->ndims);
            return NETCDF_VAR_COUNT_OUT_OF_RANGE;
        }

        if (inx == UNLIMITED_DIM_INX) {
            /* get the name of unlimdim */
            if (ncInqOut->unlimdimid < 0) return NETCDF_NO_UNLIMITED_DIM;
            for (i = 0; i < ncInqOut->ndims; i++) {
                if (ncInqOut->unlimdimid == ncInqOut->dim[i].id) {
                    name = ncInqOut->dim[i].name;
                    break;
                }
            }
            if (name == NULL) {
                rodsLog (LOG_ERROR,
                  "msiNcGetDimNameInInqOut: no match for unlimdimid %d",
                  ncInqOut->unlimdimid);
                return NETCDF_NO_UNLIMITED_DIM;
            }
        } else {
            char *varName;
            if (varNameParam == NULL) return USER__NULL_INPUT_ERR;
            if (strcmp (varNameParam->type, STR_MS_T) != 0) {
                rodsLog (LOG_ERROR,
                  "msiNcGetDimNameInInqOut: nameParam must be STR_MS_T. %s",
                  varNameParam->type);
                return (USER_PARAM_TYPE_ERR);
            } else {
                varName = (char*) varNameParam->inOutStruct;
            }
            if (strcmp (varName, "null") == 0) {
                /* use the global for inx */
                name = ncInqOut->dim[inx].name;
            } else {
                /* match the varName first */
                for (i = 0; i < ncInqOut->nvars; i++) {
                    int dimId, j;
                    if (strcmp (varName, ncInqOut->var[i].name) == 0) {
                        /* a match in var name */
                        dimId = ncInqOut->var[i].dimId[inx];
                        /* try to match dimId */
                        for (j = 0; j <  ncInqOut->ndims; j++) {
                            if (ncInqOut->dim[j].id == dimId) {
                                name = ncInqOut->dim[j].name;
                                break;
                            }
                        }
                    }
                }
                if (name == NULL) {
                    rodsLog (LOG_ERROR,
                      "msiNcGetDimNameInInqOut: unmatched varName %s and ix %d",
                      varName, inx);
                    return NETCDF_UNMATCHED_NAME_ERR;
                }
            }
        }
        fillStrInMsParam (outParam, name);

        return 0;
    }