Пример #1
0
int attack_unit_count(army_type_t type, int max) {
  printf("%s (max %d)\n", unit_string(type), max);
  int count = atoi(get_command_string());
  while (count > max || count < 0) {
    printf("Wrong number passed\n");
    count = atoi(get_command_string());
  }

  return count;
}
Пример #2
0
void AbstractHdf5Access::SetUnlimitedDatasetId()
{
    // Now deal with the unlimited dimension

    // In terms of an Unlimited dimension dataset:
    // * Files pre - r16738 (inc. Release 3.1 and earlier) use simply "Time" for "Data"'s unlimited variable.
    // * Files generated by r16738 - r18257 used "<DatasetName>_Time" for "<DatasetName>"'s unlimited variable,
    //   - These are not to be used and there is no backwards compatibility for them, since they weren't in a release.
    // * Files post r18257 (inc. Release 3.2 onwards) use "<DatasetName>_Unlimited" for "<DatasetName>"'s
    //   unlimited variable,
    //   - a new attribute "Name" has been added to the Unlimited Dataset to allow it to assign
    //     any name to the unlimited variable. Which can then be easily read by Hdf5DataReader.
    //   - if this dataset is missing we look for simply "Time" to remain backwards compatible with Releases <= 3.1

    if (DoesDatasetExist(mDatasetName + "_Unlimited"))
    {
        mUnlimitedDatasetId = H5Dopen(mFileId, (mDatasetName + "_Unlimited").c_str());
        hid_t name_attribute_id = H5Aopen_name(mUnlimitedDatasetId, "Name");
        hid_t unit_attribute_id = H5Aopen_name(mUnlimitedDatasetId, "Unit");

        hid_t attribute_type  = H5Aget_type(name_attribute_id);

        // Read into it.
        char* string_array = (char *)malloc(sizeof(char)*MAX_STRING_SIZE);
        H5Aread( name_attribute_id, attribute_type, string_array);
        std::string name_string(&string_array[0]);
        mUnlimitedDimensionName = name_string;

        H5Aread( unit_attribute_id, attribute_type, string_array);
        std::string unit_string(&string_array[0]);
        mUnlimitedDimensionUnit = unit_string;

        free(string_array);
        H5Tclose(attribute_type);
        H5Aclose(name_attribute_id);
        H5Aclose(unit_attribute_id);
    }
    else if (DoesDatasetExist("Time"))
    {
        mUnlimitedDimensionName = "Time";
        mUnlimitedDimensionUnit = "msec";
        mUnlimitedDatasetId = H5Dopen(mFileId, mUnlimitedDimensionName.c_str());
    }
    else
    {
        NEVER_REACHED;
    }
    mIsUnlimitedDimensionSet = true;
}