a47a23a9
dmayerich
added ENVI functions
|
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#ifndef ENVIOPEN_H
#define ENVIOPEN_H
#include <string>
#include <iostream>
#include <fstream>
#include <ctime>
#include <sstream>
#include <stdio.h>
#include "EnviHeader.h"
#include "EnviFid.h"
using namespace std;
//return value is incorrect
static EnviFidClass EnviOpen(string filename, char* mask = NULL, string mode = "r", int nBands = 0, int sX = 0)
{
//create a file ID object
EnviFidClass fid;
//set the file read/write mode
fid.mode = mode;
//set the mask (if specified)
fid.mask = mask;
// load the header file only while reading
if(mode=="r")
{
//load the header file
int error = fid.header.LoadHeader(filename);
//if the LoadHeader function is not zero, the header is invalid
if (error != 0)
{
fid.isValid = 0;
return fid;
}
}
//default header to be used in case of writing a file
else
{
fid.header.datatype= 4;
fid.header.nF= nBands;
fid.header.sX=0;
fid.header.sY=1;
fid.header.headersize=0;
}
//load the binary file associated with this header
//get the binary file name
//find the binary file name
//locate the position of the extension
int pos = filename.find(".hdr");
string binaryname = filename.substr(0, pos);
//load the binary file using fopen()
//store the resulting FILE pointer in the EnviFidClass variable
mode += "b";
fid.file = fopen (binaryname.c_str(), mode.c_str());
if(fid.file == NULL)
{
cout<<"Error opening binary file."<<endl;
fid.isValid = 0;
return fid;
}
//set the file name
fid.fileName = binaryname;
fid.isValid = 1;
return fid;
}
static EnviFidClass EnviOpen(EnviFidClass fid, char* mask = NULL, string mode = "r")
{
string filename = fid.fileName;
filename += ".hdr";
return EnviOpen(filename, mask, mode);
}
#endif
|