Commit 05630fbd authored by Purves, Murray's avatar Purves, Murray
Browse files

WIP radixsnd2arl: Writing full index header;

parent eb0630bb
Pipeline #16759 failed with stages
in 9 minutes and 11 seconds
......@@ -190,17 +190,45 @@ bool ARLDataStream::write_index_header(const ARLRecordHeader& rheader,
radix_line(" nz = " << iheader.nz);
radix_line(" Size of each record = " << p->recordSize);
char indexHeader[108];
sprintf(indexHeader,
size_t MAX_HEADER_LENGTH = 10000;
char indexHeaderMain[108], indexHeaderVars[MAX_HEADER_LENGTH];
int pos = 0;
// Write the variable description part of the header
for (size_t level = 0; level < iheader.nz; ++level)
{
pos += sprintf(indexHeaderVars + pos, "%6.2f", iheader.levels[level]);
pos += sprintf(indexHeaderVars + pos, "%2d", iheader.nVarsAtLevels[level]);
for (size_t var = 0; var < iheader.nVarsAtLevels[level]; ++var)
{
if (level == 0)
{
pos += sprintf(indexHeaderVars + pos, "%4s",
iheader.surfaceVarNames[var].c_str());
}
else
{
pos += sprintf(indexHeaderVars + pos, "%4s",
iheader.varNames[var].c_str());
}
pos += sprintf(indexHeaderVars + pos, "%3d ", iheader.checkSums[var]);
}
}
// Construct the main part of the header (inc. size calculation)
int headerLength = 108 + pos;
sprintf(indexHeaderMain,
"%4s%3d%2d%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f%7."
"2f%3d%3d%3d%2d%4d",
iheader.model_id.c_str(), iheader.icx, iheader.mn, iheader.pole_lat,
iheader.pole_lon, iheader.ref_lat, iheader.ref_lon, iheader.size,
iheader.orient, iheader.tang_lat, iheader.sync_xp, iheader.sync_yp,
iheader.sync_lat, iheader.sync_lon, iheader.dummy, iheader.nx,
iheader.ny, iheader.nz, iheader.z_flag, iheader.lenh);
iheader.ny, iheader.nz, iheader.z_flag, headerLength);
p->stream->writeString(std::string(indexHeader), 108);
// Write the two elements of the header
p->stream->writeString(std::string(indexHeaderMain), 108);
p->stream->writeString(std::string(indexHeaderVars), pos);
// Skip enough bytes to get to the next index header
int bytesToSkip = roundUpInt(p->stream->bytesWritten(), p->recordSize) -
......@@ -210,7 +238,7 @@ bool ARLDataStream::write_index_header(const ARLRecordHeader& rheader,
p->stream->writeString("", bytesToSkip);
radix_line(" header as string:\n " << indexHeader);
radix_line(" header as string:\n " << indexHeaderVars);
result = true;
return result;
......
......@@ -109,6 +109,12 @@ struct RADIX_PUBLIC ARLIndexHeader
int nz;
int z_flag;
int lenh;
std::vector<float> levels;
std::vector<int> nVarsAtLevels;
std::vector<std::string> surfaceVarNames;
std::vector<std::string> varNames;
std::vector<int> checkSums;
bool prime;
bool latlon;
bool gbldat;
......
......@@ -165,8 +165,8 @@ int main(int argc, char **argv)
std::string inputCsvPath = commandLine.get<std::string>("i");
std::string outputArlPath =
commandLine.get<std::string>("o", inputCsvPath + ".bin");
float extent = commandLine.get<int>("e");
float resolution = commandLine.get<int>("r");
float extent = commandLine.get<float>("e");
float resolution = commandLine.get<float>("r");
float centreLat = commandLine.get<float>("clat");
float centreLon = commandLine.get<float>("clon");
int numberTimesteps = commandLine.get<int>("n", 1);
......@@ -404,27 +404,32 @@ int main(int argc, char **argv)
thisRecordHeader.prec = 0.f;
thisRecordHeader.var1 = 0.f;
ARLIndexHeader thisIndexHeader;
thisIndexHeader.model_id = "NFDB";
thisIndexHeader.icx = 0;
thisIndexHeader.mn = 0;
thisIndexHeader.pole_lat = centreLat;
thisIndexHeader.pole_lon = centreLon;
thisIndexHeader.ref_lat = centreLat;
thisIndexHeader.ref_lon = centreLon;
thisIndexHeader.size = 000.f;
thisIndexHeader.orient = 0.f;
thisIndexHeader.tang_lat = centreLat;
thisIndexHeader.sync_xp = (numberGridCells + 1) / 2;
thisIndexHeader.sync_yp = (numberGridCells + 1) / 2;
thisIndexHeader.sync_lat = centreLat;
thisIndexHeader.sync_lon = centreLon;
thisIndexHeader.dummy = 0.f;
thisIndexHeader.nx = numberGridCells;
thisIndexHeader.ny = numberGridCells;
thisIndexHeader.nz = inputPressures.size();
thisIndexHeader.z_flag = 2;
thisIndexHeader.lenh =
inputPressures.size() * numberGridCells * numberGridCells;
thisIndexHeader.model_id = "NFDB";
thisIndexHeader.icx = 0;
thisIndexHeader.mn = 0;
thisIndexHeader.pole_lat = centreLat;
thisIndexHeader.pole_lon = centreLon;
thisIndexHeader.ref_lat = centreLat;
thisIndexHeader.ref_lon = centreLon;
thisIndexHeader.size = 000.f;
thisIndexHeader.orient = 0.f;
thisIndexHeader.tang_lat = centreLat;
thisIndexHeader.sync_xp = (numberGridCells + 1) / 2;
thisIndexHeader.sync_yp = (numberGridCells + 1) / 2;
thisIndexHeader.sync_lat = centreLat;
thisIndexHeader.sync_lon = centreLon;
thisIndexHeader.dummy = 0.f;
thisIndexHeader.nx = numberGridCells;
thisIndexHeader.ny = numberGridCells;
thisIndexHeader.nz = inputPressures.size();
thisIndexHeader.z_flag = 2;
thisIndexHeader.lenh = numberGridCells * numberGridCells;
thisIndexHeader.levels = inputPressures;
thisIndexHeader.nVarsAtLevels = std::vector<int>(inputPressures.size(), 5);
thisIndexHeader.surfaceVarNames = {"PRSS", "TEMP", "RELH", "UWND", "VWND"};
thisIndexHeader.varNames = {"PRES", "TEMP", "RELH", "UWND", "VWND"};
thisIndexHeader.checkSums = std::vector<int>(5, 0);
// Write the headers
outputStream.write_record_header(thisRecordHeader);
outputStream.write_index_header(thisRecordHeader, thisIndexHeader);
......@@ -438,7 +443,14 @@ int main(int argc, char **argv)
// Write pressure variables
{
thisRecordHeader.kvar = "PRSS";
if (level == 0)
{
thisRecordHeader.kvar = "PRSS";
}
else
{
thisRecordHeader.kvar = "PRES";
}
thisRecordHeader.var1 = inputPressures[level];
std::vector<std::vector<float>> thisData(
numberGridCells,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment