/* hdf_utils.cpp */ /* remap Copyright (C) 2006 Fabrice Ducos, fabrice.ducos@icare.univ-lille1.fr This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "common.h" #include "hdf_utils.h" int hdf_create_empty_file(const char *file) { // const intn fill_mode = SD_NOFILL; // SD_FILL or SD_NOFILL int32 sd_id; intn status; sd_id = SDstart(file, DFACC_CREATE); if (sd_id == FAIL) { std::cerr << APPNAME << ": failed to create " << file << std::endl; return -1; } status = SDend(sd_id); assert(status != FAIL); return 0; } int hdf_add_empty_sds(const char *file, const char *sds_name, int32 sds_type, int32 rank, int32 *dimensions, const VOIDP fill_value, const float64 cal, const float64 offset, const float64 cal_err, const float64 off_err) { int32 sd_id; int32 sds_id; int32 sds_index; intn status; sd_id = SDstart(file, DFACC_WRITE); if (sd_id == FAIL) { std::cerr << APPNAME << ": failed to write into " << file << std::endl; return -1; } sds_index = SDnametoindex(sd_id, sds_name); if (sds_index != FAIL) { /* the dataset already exists */ status = SDend(sd_id); assert(status != FAIL); return -1; } sds_id = SDcreate(sd_id, sds_name, sds_type, rank, dimensions); status = SDsetcal(sds_id, cal, cal_err, offset, off_err, sds_type); assert(status != FAIL); if (fill_value) { status = SDsetfillvalue(sds_id, fill_value); assert(status != FAIL); } status = SDendaccess(sds_id); assert(status != FAIL); status = SDend(sd_id); assert(status != FAIL); return 0; }