16 #define GLOBAL_DECLARATION
17 #include "../inc/config.h"
23 #include "lmrcImageProjection.h"
26 typedef struct lmrc2hdfInfo {
37 typedef enum lmrc2hdfMode {
42 extern int lmrc2hdfimaris(hid_t* out, mrcImage* in, lmrc2hdfInfo* linfo, int mode);
43 extern int lmrc2hdf(hid_t* out, mrcImage* in, lmrc2hdfInfo* linfo, int mode);
46 main(int argc, char* argv[])
57 argCheck(&info, argc, argv);
60 DEBUGPRINT("Program Start\n");
63 linfo.in = (mrcImage*)memoryAllocate(sizeof(mrcImage), "in main");
64 mrcFileRead(linfo.in, info.In, "in main", 0);
67 } else if(info.flagInList) {
68 linfo.numFile = info.flagInList;
69 linfo.flagIn = info.flagInList;
70 linfo.in = (mrcImage*)memoryAllocate(sizeof(mrcImage)*linfo.numFile, "in main");
71 for(i=0; i<linfo.numFile; i++) {
72 mrcFileRead(&(linfo.in[i]), info.InList[i], "in main", 0);
74 linfo.inColor[0] = info.IR;
75 linfo.inColor[1] = info.IG;
76 linfo.inColor[2] = info.IB;
77 linfo.inColor[3] = info.IA;
78 if(info.flagInList2) {
79 if(linfo.numFile != info.flagInList2) {
80 fprintf(stderr, "Different Number between -I and -I2: %ld %ld\n", info.flagInList, info.flagInList2);
83 linfo.flagIn2 = info.flagInList2;
84 linfo.in2 = (mrcImage*)memoryAllocate(sizeof(mrcImage)*linfo.numFile, "in main");
85 for(i=0; i<linfo.numFile; i++) {
86 mrcFileRead(&(linfo.in2[i]), info.InList2[i], "in main", 0);
88 linfo.in2Color[0] = info.I2R;
89 linfo.in2Color[1] = info.I2G;
90 linfo.in2Color[2] = info.I2B;
91 linfo.in2Color[3] = info.I2A;
96 fprintf(stderr, "-i or -I is necessary\n");
99 linfo.nResolution = info.nResolution;
100 //out = H5Fopen(info.Out, H5F_ACC_TRUNC, H5P_DEFAULT);
101 out = H5Fcreate(info.Out, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
103 fprintf(stderr, "Not openend:%s\n", info.Out);
107 switch(info.hdf5mode) {
109 lmrc2hdf(&out, linfo.in, &linfo, info.mode);
113 lmrc2hdfimaris(&out, linfo.in, &linfo, info.mode);
117 fprintf(stderr, "not supported hdf5mode: %ld\n", info.hdf5mode);
122 status = H5Fclose(out);
130 fprintf(stderr, "----- Additional Usage -----\n");
135 lhdfAttributeString(hid_t gIDChannel, char tag[], char* stmp)
138 hid_t attrspaceID, attrID;
143 attrspaceID = H5Screate_simple(1, &sdim, NULL);
144 stringType = H5Tcopy(H5T_C_S1);
145 status = H5Tset_size(stringType, 1);
146 status = H5Tset_strpad(stringType, H5T_STR_NULLTERM);
147 DEBUGPRINT3("space: %lld type: %lld status: %d \n", attrspaceID, stringType, status);
148 attrID = H5Acreate(gIDChannel, tag, stringType, attrspaceID, H5P_DEFAULT, H5P_DEFAULT);
149 DEBUGPRINT1("attrID: %lld\n", attrID);
150 status = H5Awrite(attrID, stringType, stmp);
151 status = H5Aclose(attrID);
152 status = H5Sclose(attrspaceID);
158 lhdfAttributeUInt32(hid_t gIDChannel, char tag[], uint32_t* i, hsize_t num)
160 hid_t attrspaceID, attrID;
163 attrspaceID = H5Screate_simple(1, &num, NULL);
164 attrID = H5Acreate(gIDChannel, tag, H5T_STD_U32LE, attrspaceID, H5P_DEFAULT, H5P_DEFAULT);
165 status = H5Awrite(attrID, H5T_STD_U32LE, i);
166 status = H5Aclose(attrID);
167 status = H5Sclose(attrspaceID);
173 lhdfAttributeInt2String(hid_t gIDChannel, char tag[], hsize_t i)
177 hid_t attrspaceID, attrID;
181 sprintf(stmp, "%lld", i);
183 attrspaceID = H5Screate_simple(1, &sdim, NULL);
184 stringType = H5Tcopy(H5T_C_S1);
185 status = H5Tset_size(stringType, 1);
186 status = H5Tset_strpad(stringType, H5T_STR_NULLTERM);
187 DEBUGPRINT3("space: %lld type: %lld status: %d \n", attrspaceID, stringType, status);
188 attrID = H5Acreate(gIDChannel, tag, stringType, attrspaceID, H5P_DEFAULT, H5P_DEFAULT);
189 DEBUGPRINT1("attrID: %lld\n", attrID);
190 status = H5Awrite(attrID, stringType, stmp);
191 status = H5Aclose(attrID);
192 status = H5Sclose(attrspaceID);
198 lhdfAttributeReal2String(hid_t gIDChannel, char tag[], double f)
202 hid_t attrspaceID, attrID;
206 sprintf(stmp, "%lf", f);
208 attrspaceID = H5Screate_simple(1, &sdim, NULL);
209 stringType = H5Tcopy(H5T_C_S1);
210 status = H5Tset_size(stringType, 1);
211 status = H5Tset_strpad(stringType, H5T_STR_NULLTERM);
212 DEBUGPRINT3("space: %lld type: %lld status: %d \n", attrspaceID, stringType, status);
213 attrID = H5Acreate(gIDChannel, tag, stringType, attrspaceID, H5P_DEFAULT, H5P_DEFAULT);
214 DEBUGPRINT1("attrID: %lld\n", attrID);
215 status = H5Awrite(attrID, stringType, stmp);
216 status = H5Aclose(attrID);
217 status = H5Sclose(attrspaceID);
223 lmrc2hdfimaris(hid_t* out, mrcImage* in, lmrc2hdfInfo* linfo, int mode)
226 static hsize_t sdim=1024;
230 static hsize_t nHist1024=1024;
231 static hsize_t nHist=256;
233 uint64_t hist1024[nHist1024];
234 uint64_t hist[nHist];
249 hid_t datasetPropertyID;
251 static uint32_t numOfDataSets = 1;
255 char* groupName[] = {"/DataSet", "/DataSetInfo", "/DataSetTimes", "/Thumbnail"};
257 int i, ires, itime, ichannel;
259 int nres, ntime, nchannel;
260 hid_t dsetID, dspaceID, gIDRes, gIDTime, gIDChannel, attrID, attrspaceID, stringType;
261 mrcImageParaTypeReal x, y, z;
262 mrcImageParaTypeReal xorg, yorg, zorg;
263 int irange, numrange;
264 unsigned char* thumbImage;
265 double sum, min, max, mean;
268 lmrcImageProjectionInfo lpro;
270 DEBUGPRINT("Start lmrc2hdfimaris\n");
271 // Top Level Attribute
272 lhdfAttributeString(*out, "DataSetDirectoryName", "DataSet");
273 lhdfAttributeString(*out, "DataSetInfoDirectoryName", "DataSetInfo");
274 lhdfAttributeString(*out, "ImarisDataSet", "ImarisDataSet");
275 lhdfAttributeString(*out, "ImarisVersion", "5.5.0");
276 lhdfAttributeUInt32(*out, "NumberOfDataSets", &numOfDataSets, 1);
277 lhdfAttributeString(*out, "ThumbnailDirectoryName", "Thumbnail");
280 for(i=0; i<nGroup; i++) {
281 DEBUGPRINT2("Group: %s %d\n", groupName[i], i);
282 groupID[i] = H5Gcreate2(*out, groupName[i], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
284 fprintf(stderr, "Not create Group: %s\n", groupName[i]);
287 DEBUGPRINT1("Success: %d\n", i);
292 dims[0] = in[0].HeaderN.z;
293 dims[1] = in[0].HeaderN.y;
294 dims[2] = in[0].HeaderN.x;
305 datasetPropertyID = H5Pcreate(H5P_DATASET_CREATE);
306 status = H5Pset_chunk(datasetPropertyID, 3, chunk);
309 status = H5Pset_fill_value(datasetPropertyID, H5T_NATIVE_INT, &val);
310 status = H5Pset_alloc_time(datasetPropertyID, H5D_ALLOC_TIME_EARLY);
311 status = H5Pclose(datasetPropertyID);
314 nres = linfo->nResolution;
315 ntime = linfo->numFile;
316 if(0<linfo->flagIn) {
319 if(0<linfo->flagIn2) {
321 if(in[0].HeaderN.x != linfo->in2[0].HeaderN.x
322 ||in[0].HeaderN.y != linfo->in2[0].HeaderN.y
323 ||in[0].HeaderN.z != linfo->in2[0].HeaderN.z) {
324 fprintf(stderr, "Different Size : In (%d %d %d) and I2 (%d, %d, %d)\n",
325 linfo->in[0].HeaderN.x, linfo->in[0].HeaderN.y, linfo->in[0].HeaderN.z,
326 linfo->in2[0].HeaderN.x, linfo->in2[0].HeaderN.y, linfo->in2[0].HeaderN.z);
332 for(ires=0; ires<nres; ires++) {
333 sprintf(tmp, "%s/%s %d", groupName[0], "ResolutionLevel", ires);
334 gIDRes = H5Gcreate2(groupID[0], tmp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
335 DEBUGPRINT1("%s\n", tmp);
336 for(itime=0; itime<ntime; itime++) {
337 sprintf(tmp, "%s/%s %d/%s %d", groupName[0], "ResolutionLevel", ires, "TimePoint", itime);
338 gIDTime = H5Gcreate2(gIDRes, tmp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
339 DEBUGPRINT1("%s\n", tmp);
340 for(ichannel=0; ichannel<nchannel; ichannel++) {
349 fprintf(stderr, "Not supported ichannel: %d\n", ichannel);
353 sprintf(tmp, "%s/%s %d/%s %d/%s %d", groupName[0], "ResolutionLevel", ires, "TimePoint", itime, "Channel", ichannel);
354 gIDChannel = H5Gcreate2(gIDTime, tmp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
355 DEBUGPRINT1("%s\n", tmp);
357 lhdfAttributeInt2String(gIDChannel, "ImageSizeX", dims[2]);
358 lhdfAttributeInt2String(gIDChannel, "ImageSizeY", dims[1]);
359 lhdfAttributeInt2String(gIDChannel, "ImageSizeZ", dims[0]);
362 dspaceID = H5Screate_simple(3, dims, NULL);
363 sprintf(tmp, "%s/%s %d/%s %d/%s %d/%s", groupName[0], "ResolutionLevel", ires, "TimePoint", itime, "Channel", ichannel, "Data");
364 DEBUGPRINT1("%s\n", tmp);
365 DEBUGPRINT1("mode: %d\n", tmpIn[0].HeaderMode);
366 image = (float*)memoryAllocate(sizeof(float)*dims[0]*dims[1]*dims[2], "in lmrc2hdfimars");
368 for(i=0; i<256; i++) hist[i] = 0;
369 for(i=0; i<1024; i++) hist1024[i] = 0;
371 DEBUGPRINT("image\n");
372 if(tmpIn[itime].HeaderAMax<=tmpIn[itime].HeaderAMin) {
373 fprintf(stderr, "Image data is flat\n");
374 for(i=0; i<dims[0]*dims[1]*dims[2]; i++) {
375 image[i] = tmpIn[itime].HeaderAMin;
381 DEBUGPRINT2("res: %d irange %d\n", ires, irange);
382 for(z=0; z<dims[0]; z++) {
383 if(0==(((int)(z/(double)(dims[0]-1)*100))%10)) {
384 DEBUGPRINT2("%d/%llu\n", (int)z, dims[0]);
386 for(y=0; y<dims[1]; y++) {
387 for(x=0; x<dims[2]; x++) {
388 i64 = (double)x + (double)y*(double)dims[2] + (double)z*(double)dims[2]*(double)dims[1];
389 if(dims[0]*dims[1]*dims[2]<=i64) {
390 DEBUGPRINT1("%f \n", x + (double)y*(double)dims[2] + (double)z*(double)dims[2]*(double)dims[1]);
391 DEBUGPRINT4("%lld %f %f %f\n", i64, x, y, z);
392 DEBUGPRINT4("%lld %lld %lld %lld\n", dims[0]*dims[1]*dims[2], dims[2], dims[1], dims[0]);
395 for(zorg=z*irange;zorg<(z+1)*irange; zorg++) {
396 for(yorg=y*irange;yorg<(y+1)*irange; yorg++) {
397 for(xorg=x*irange;xorg<(x+1)*irange; xorg++) {
399 mrcPixelDataGet(&(tmpIn[itime]), xorg, yorg, zorg, &data, mrcPixelRePart, mrcPixelHowNearest);
409 DEBUGPRINT4("%llu %f = %f / %d\n", i64, data, sum, numrange);
414 //DEBUGPRINT("numrange is zero: Something wrong\n");
417 image[i64] = (float)data;
422 DEBUGPRINT("MIN/MAX\n");
424 for(i64=1; i64<dims[2]*dims[1]*dims[0]; i64++) {
425 if(image[i64]<min) min = image[i64];
426 if(max<image[i64]) max = image[i64];
428 DEBUGPRINT2("%f/%f\n", min, max);
429 DEBUGPRINT("HISTGRAM\n");
430 for(i64=1; i64<dims[2]*dims[1]*dims[0]; i64++) {
432 iLevel = MAX(0,MIN(1023,(int)((data-min)/(max-min)*1023+0.5)));
434 iLevel = MAX(0,MIN( 255,(int)((data-min)/(max-min)* 255+0.5)));
439 DEBUGPRINT("H5Dcreate");
440 dsetID = H5Dcreate(gIDChannel, tmp, H5T_IEEE_F32LE, dspaceID, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
441 status = H5Dwrite(dsetID, H5T_IEEE_F32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, image);
442 DEBUGPRINT3("%s End: dataset %lld status %d\n", tmp, dsetID, status);
444 status = H5Dclose(dsetID);
445 status = H5Sclose(dspaceID);
447 lhdfAttributeInt2String(gIDChannel, "HistogramMax", max);
448 lhdfAttributeInt2String(gIDChannel, "HistogramMin", min);
449 lhdfAttributeInt2String(gIDChannel, "HistogramMax1024", max);
450 lhdfAttributeInt2String(gIDChannel, "HistogramMin1024", min);
453 dspaceID = H5Screate_simple(1, &nHist, NULL);
454 sprintf(tmp, "%s/%s %d/%s %d/%s %d/%s", groupName[0], "ResolutionLevel", ires, "TimePoint", itime, "Channel", ichannel, "Histogram");
455 dsetID = H5Dcreate(gIDChannel, tmp, H5T_STD_U64LE, dspaceID, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
456 status = H5Dwrite(dsetID, H5T_STD_U64LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, hist);
457 status = H5Dclose(dsetID);
458 status = H5Sclose(dspaceID);
461 dspaceID = H5Screate_simple(1, &nHist1024, NULL);
462 sprintf(tmp, "%s/%s %d/%s %d/%s %d/%s", groupName[0], "ResolutionLevel", ires, "TimePoint", itime, "Channel", ichannel, "Histogram1024");
463 dsetID = H5Dcreate(gIDChannel, tmp, H5T_STD_U64LE, dspaceID, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
464 status = H5Dwrite(dsetID, H5T_STD_U64LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, hist1024);
465 status = H5Dclose(dsetID);
466 status = H5Sclose(dspaceID);
469 status = H5Gclose(gIDChannel);
471 status = H5Gclose(gIDTime);
476 status = H5Gclose(gIDRes);
479 DEBUGPRINT("DataSetInfo\n");
481 char* dsiGroupName[] = {"Channel 0", "Image", "Imaris", "ImarisDataSet", "Log", "TImeInfo"};
483 hid_t dsiGroupID[dsiNGroup];
485 for(i=0; i<dsiNGroup; i++) {
486 sprintf(stmp, "%s/%s", groupName[1], dsiGroupName[i]);
487 dsiGroupID[i] = H5Gcreate2(*out, stmp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
490 lhdfAttributeString(dsiGroupID[0], "Name", "No");
491 lhdfAttributeString(dsiGroupID[0], "Color", "1.000 0.000 0.000");
492 lhdfAttributeString(dsiGroupID[0], "ColorMode", "BaseColor");
493 lhdfAttributeReal2String(dsiGroupID[0], "ColorOpacity", 1.000);
494 lhdfAttributeReal2String(dsiGroupID[0], "Min", in[0].HeaderAMax);
495 lhdfAttributeReal2String(dsiGroupID[0], "Max", in[0].HeaderAMin);
497 lhdfAttributeString(dsiGroupID[1], "Description", "No");
498 lhdfAttributeString(dsiGroupID[1], "Name", "No");
499 lhdfAttributeInt2String(dsiGroupID[1], "Noc", 1);
500 lhdfAttributeReal2String(dsiGroupID[1], "ExtMin0", in[0].HeaderStartN.x*in[0].HeaderLength.x);
501 lhdfAttributeReal2String(dsiGroupID[1], "ExtMin1", in[0].HeaderStartN.y*in[0].HeaderLength.y);
502 lhdfAttributeReal2String(dsiGroupID[1], "ExtMin2", in[0].HeaderStartN.z*in[0].HeaderLength.z);
503 lhdfAttributeReal2String(dsiGroupID[1], "ExtMax0", (in[0].HeaderStartN.x+dims[2]-1)*in[0].HeaderLength.x);
504 lhdfAttributeReal2String(dsiGroupID[1], "ExtMax1", (in[0].HeaderStartN.y+dims[1]-1)*in[0].HeaderLength.y);
505 lhdfAttributeReal2String(dsiGroupID[1], "ExtMax2", (in[0].HeaderStartN.z+dims[0]-1)*in[0].HeaderLength.z);
507 lhdfAttributeString(dsiGroupID[1], "ResampleDimensionX", "true");
508 lhdfAttributeString(dsiGroupID[1], "ResampleDimensionY", "true");
509 lhdfAttributeString(dsiGroupID[1], "ResampleDimensionZ", "true");
511 lhdfAttributeString(dsiGroupID[1], "Unit", "um");
512 lhdfAttributeInt2String(dsiGroupID[1], "X", dims[2]);
513 lhdfAttributeInt2String(dsiGroupID[1], "Y", dims[1]);
514 lhdfAttributeInt2String(dsiGroupID[1], "Z", dims[0]);
516 lhdfAttributeString(dsiGroupID[2], "Version", "5,5");
518 lhdfAttributeString(dsiGroupID[3], "Creator", "lmrc2hdf5imaris");
519 lhdfAttributeString(dsiGroupID[3], "NumberOfImages", "1");
520 lhdfAttributeString(dsiGroupID[3], "Version", "1.0");
522 for(i=dsiNGroup-1; i>=0; i--) {
523 status = H5Gclose(dsiGroupID[i]);
527 DEBUGPRINT("DataSetTimes\n");
528 DEBUGPRINT("Thumbnail\n");
533 hsize_t dimsX, dimsY;
534 float orgx, orgy, orgz;
536 if(in[0].HeaderN.x<in[0].HeaderN.y) {
537 zoomx *= in[0].HeaderN.x/(double)in[0].HeaderN.y;
539 zoomy *= in[0].HeaderN.y/(double)in[0].HeaderN.x;
541 dimsT[0] = dimsX = ((int)(256*zoomx));
542 dimsT[1] = ((int)(256*zoomy))*4; // RGBA
545 DEBUGPRINT2("zoom: %f %f\n", zoomx, zoomy);
546 DEBUGPRINT4("dimsT: %llu %llu - %llu %llu\n", dimsT[0], dimsT[1], dimsX, dimsY);
547 sprintf(tmp, "%s/%s", groupName[3], "Data");
548 thumbImage = (unsigned char*) memoryAllocate(sizeof(unsigned char)*dimsT[0]*dimsT[1], "in imaris");
550 lmrcImageProjectionMIP(&tmpImage, &in[0], &lpro);
553 mrcFileWrite(&tmpImage, "/tmp/tmpImage.mrc", "in tet", 0);
560 for(x=0; x<in[0].HeaderN.x; x++) {
561 for(y=0; y<in[0].HeaderN.y; y++) {
562 mrcPixelDataGet(&tmpImage, x, y, 0, &data, mrcPixelRePart, mrcPixelHowNearest);
564 if(data<min) min = data;
565 if(max<data) max = data;
568 mean = sum/in[0].HeaderN.x/in[0].HeaderN.y;
570 DEBUGPRINT1("min: %f\n", min);
571 DEBUGPRINT1("max: %f\n", max);
572 DEBUGPRINT1("mean: %f\n", mean);
573 for(x=0; x<dimsX; x++) {
574 for(y=0; y<dimsY; y++) {
575 orgx = x/(dimsX - 1)*(in[0].HeaderN.x-1);
576 orgy = y/(dimsY - 1)*(in[0].HeaderN.y-1);
577 mrcPixelDataGet(&tmpImage, orgx, orgy, 0, &data, mrcPixelRePart, mrcPixelHowNearest);
579 thumbImage[(int)(y*4+x*dimsT[1])] = 0;
581 data = (int)(255.0*(data-(mean - (mean - min)/3))/((mean + (max-mean)/3) - (mean - (mean-min)/3))+0.5);
583 if(255<data) data = 255;
584 thumbImage[(int)(y*4+x*dimsT[1])] = data;
586 thumbImage[(int)(y*4+1+x*dimsT[1])] = 0;
587 thumbImage[(int)(y*4+2+x*dimsT[1])] = 0;
588 thumbImage[(int)(y*4+3+x*dimsT[1])] = 255;
592 dspaceID = H5Screate_simple(2, &(dimsT[0]), NULL); // H5S dimension
593 sprintf(tmp, "%s/%s", groupName[3], "Data"); // Group Name
594 dsetID = H5Dcreate2(groupID[3], tmp, H5T_STD_U8LE, dspaceID, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
595 status = H5Dwrite(dsetID, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, thumbImage); // Write
596 mrcImageFree(&tmpImage, "in lmrc2hdfimaris");
598 status = H5Dclose(dsetID);
599 status = H5Sclose(dspaceID);
601 for(i=nGroup-1; i>=0; i--) {
602 status = H5Gclose(groupID[i]);
608 lmrc2hdf(hid_t* out, mrcImage* in, lmrc2hdfInfo* linfo, int mode)
618 hid_t datasetPropertyID;
622 char* groupName[] = {"/DataSet", "/DataSet/ResolutionLevel 0", "/DataSet/ResolutionLevel 0/TimePoint 0", "/DataSet/ResolutionLevel 0/TimePoint 0/Channel 0"};
623 //char* groupName[] = {"/DataSet"};
628 for(i=0; i<nGroup; i++) {
629 DEBUGPRINT1("Group: %s\n", groupName[i]);
630 groupID[i] = H5Gcreate2(*out, groupName[i], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
632 fprintf(stderr, "Not create Group: %s\n", groupName[i]);
635 DEBUGPRINT("Success\n");
639 dims[0] = in->HeaderN.x;
640 dims[1] = in->HeaderN.y;
641 dims[2] = in->HeaderN.z;
642 dims[3] = linfo->numFile;
649 datasetPropertyID = H5Pcreate(H5P_DATASET_CREATE);
650 status = H5Pset_chunk(datasetPropertyID, 4, chunk);
653 status = H5Pset_fill_value(datasetPropertyID, H5T_NATIVE_INT, &val);
654 status = H5Pset_alloc_time(datasetPropertyID, H5D_ALLOC_TIME_EARLY);
656 dataspaceID2 = H5Screate_simple(4, dims, NULL);
657 //datasetID2 = H5Dcreate(*out, "/prop", H5T_STD_I32LE, dataspaceID2, H5P_DEFAULT, datasetPropertyID, H5P_DEFAULT);
659 sprintf(tmp, "%s/%s", groupName[i], "Data");
660 datasetID2 = H5Dcreate2(groupID[i], tmp, H5T_STD_I32LE, dataspaceID2, H5P_DEFAULT, datasetPropertyID, H5P_DEFAULT);
661 status = H5Pclose(datasetPropertyID);
662 status = H5Dclose(datasetID2);
663 status = H5Sclose(dataspaceID2);
666 dataspaceID = H5Screate_simple(4, dims, NULL);
667 switch(in->HeaderMode) {
669 datasetID = H5Dcreate(*out, "/mrc", H5T_STD_U8LE, dataspaceID, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
670 status = H5Dwrite(datasetID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, in->Image);
673 datasetID = H5Dcreate(*out, "/mrc", H5T_STD_I16LE, dataspaceID, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
674 status = H5Dwrite(datasetID, H5T_NATIVE_SHORT, H5S_ALL, H5S_ALL, H5P_DEFAULT, in->Image);
677 datasetID = H5Dcreate(*out, "/mrc", H5T_STD_U16LE, dataspaceID, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
678 status = H5Dwrite(datasetID, H5T_NATIVE_USHORT, H5S_ALL, H5S_ALL, H5P_DEFAULT, in->Image);
681 datasetID = H5Dcreate(*out, "/mrc", H5T_IEEE_F32LE, dataspaceID, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
682 status = H5Dwrite(datasetID, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, in->Image);
685 fprintf(stderr, "Not supported: %d\n", in->HeaderMode);
690 status = H5Dclose(datasetID);
691 status = H5Sclose(dataspaceID);
693 for(i=nGroup-1; i>=0; i--) {
694 status = H5Gclose(groupID[i]);