EnviClose.h
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef ENVICLOSE_H
#define ENVICLOSE_H
#include <fstream>
#include <stdio.h>
#include "EnviHeader.h"
#include "EnviFid.h"
#include "EnviOpen.h"
// this is to close all the opened files and to create a header file for the written files
static void EnviClose(EnviFidClass &fid, int dimX=0)
{
float* zeroPtr = (float*) malloc(sizeof(float) * fid.header.nF);
memset(zeroPtr, 0, sizeof(float) * fid.header.nF);
if(fid.mode=="r")
{
fclose(fid.file);
}
else
{
int totalPixels = fid.header.sX;
int dimY = totalPixels/dimX;
if(totalPixels % dimX > 0)
{
dimY++;
int padding = dimY*dimX-totalPixels;
for(int p=0; p < padding; p++)
fwrite(zeroPtr, sizeof(float), fid.header.nF, fid.file);
}
//write the calculated values to the header object
fid.header.sX = dimX;
fid.header.sY = dimY;
//write the header file to disk
//TODO
//close the binary file
fclose(fid.file);
}
}
#endif