I'm using the Eccodes API to convert GRIB2 files. When I use the C++ API to extract all paramId and shortName, V component of wind (paramId is 132 and shortName is v) is not present in the query results, as follows:
ids=73
0 31 43 54 59 130 131 133 134 135 156 157 165 167 168 172 173 3020 3024 3041 3045 3046 3054 3063 3066 3086 228001 228002 228139 228164 228228 260002 260003 260029 260030 260031 260032 260038 260056 260065 260072 260073 260074 260083 260087 260088 260097 260098 260125 260127 260128 260155 260180 260185 260187 260189 260190 260205 260206 260207 260208 260209 260238 260242 260256 260317 260389 260390 260391
260439 260442 260509 7001353
names=73
10u 2d 2r 2t 4lftx VRATE absv acpcp al bmixl cape cd cfrzr ci cicep cin cnwat crain csnow dlwrf dswrf fricv gh gust hindex hlcy hpbl lftx lhtfl lsm ltng mslet mstav orog pli poros pres prmsl pwat q r refc refd rlyrs sde sdwe shtfl slt smdry smref snowc soill soilw sp sr ssw st t tcc tke tp u ulwrf unknown uswrf veg vgtyp vis vucsh vvcsh w wilt wz
The program code is as follows:
/*
* Copyright 2005-2017 ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/*
* C Implementation: grib_index
*
* Description: How to create and use an index to access GRIB messages from a file
*
*/
#include "eccodes.h"
int main(int argc,char* argv[])
{
codes_index* index = NULL;
codes_handle* h = NULL;
int ret;
size_t size, i;
char** names;
long* ids;
index = codes_index_new_from_file(0, argv[argc - 1], "paramId,shortName", &ret);
CODES_CHECK(ret, 0);
CODES_CHECK(codes_index_get_size(index, "shortName", &size),0);
ids=(long*)malloc(sizeof(long)*size);
CODES_CHECK(codes_index_get_long(index,"paramId",ids,&size),0);
printf("ids=%ld\n",(long)size);
for (i=0;i<size;i++) printf("%ld ",ids[i]);
printf("\n");
CODES_CHECK(codes_index_get_size(index, "shortName", &size),0);
names=(char**)malloc(sizeof(char*)*size);
CODES_CHECK(codes_index_get_string(index,"shortName",names,&size),0);
printf("names=%ld\n",(long)size);
for (i=0;i<size;i++) printf("%s ",names[i]);
printf("\n");
return 0;
}
However, if I query the parameter using grib_ls, it shows up:
wuh20#sapphire:~/github/test$ grib_ls -w paramId=132 -p paramId,level,shortName,name ~/Desktop/test/nam_218_20180701_0000_000.grb2
/home/graduate/wuh20/Desktop/test/nam_218_20180701_0000_000.grb2
paramId level shortName name
132 0 v V component of wind
132 50 v V component of wind
132 75 v V component of wind
132 100 v V component of wind
132 125 v V component of wind
132 150 v V component of wind
132 175 v V component of wind
132 200 v V component of wind
132 225 v V component of wind
132 250 v V component of wind
132 275 v V component of wind
132 300 v V component of wind
132 325 v V component of wind
132 350 v V component of wind
132 375 v V component of wind
132 400 v V component of wind
132 425 v V component of wind
132 450 v V component of wind
132 475 v V component of wind
132 500 v V component of wind
132 525 v V component of wind
132 550 v V component of wind
132 575 v V component of wind
132 600 v V component of wind
132 625 v V component of wind
132 650 v V component of wind
132 675 v V component of wind
132 700 v V component of wind
132 725 v V component of wind
132 750 v V component of wind
132 775 v V component of wind
132 800 v V component of wind
132 825 v V component of wind
132 850 v V component of wind
132 875 v V component of wind
132 900 v V component of wind
132 925 v V component of wind
132 950 v V component of wind
132 975 v V component of wind
132 1000 v V component of wind
132 0 v V component of wind
132 0 v V component of wind
132 80 v V component of wind
132 3000 v V component of wind
132 6000 v V component of wind
132 9000 v V component of wind
132 12000 v V component of wind
132 15000 v V component of wind
132 18000 v V component of wind
49 of 446 messages in /home/graduate/wuh20/Desktop/test/nam_218_20180701_0000_000.grb2
Could somebody help me figure this out?
I can provide my data if it is needed or helpful. Thank you.
This is rather a hidden but easy one. I have to turn on multi support which is ON by default in all tools.
For all the tools default is multi support ON.
reference
Related
I have a two tables are data and report.
In data table the following columns are Size A, Size B and Size C, Type and Rank.
In data table I created rank for each type based on the sizes. The purpose of the rank column were multiple matches for same size in this case the rank column will help to decide exact type were match more than one.
In report table the following columns are Size A, Size B and Size C.
In both table the Size A, Size B and Size C columns are common/relationship.
I am trying find out the appropriate type according to the Size A, Size B and Size C from data table into report table.
Data:
TYPE
SIZEA
SIZEB
SIZEC
RANK
A6
420
600
440
11.00
A4
640
600
480
9.00
A5
890
1100
1330
2.00
A6
1335
1100
2350
1.00
A7
890
1100
390
5.00
A8
890
1100
530
3.00
A9
670
1100
540
4.00
A10
670
1100
440
6.00
A11
320
1100
440
10.00
A12
600
400
400
12.00
A13
800
600
400
8.00
A14
1000
600
500
7.00
Report:
SIZEA
SIZEB
SIZEC
DESIRED RESULT-TYPE
400
300
140
A12
A12
250
250
160
A12
600
400
285
A12
400
300
150
A12
280
230
170
A12
320
320
320
A12
320
320
320
A12
600
400
140
A12
400
300
140
A12
400
300
140
A12
370
320
340
A12
320
240
250
A12
300
200
90
A12
400
290
140
A12
I am applying following formula in report table in order to get the appropriate type according to the Size A, Size B and Size C
=INDEX(DATA!$D$2:$D$16,AGGREGATE(15,6,(ROW(DATA!$H$2:$H$16)-1)/(DATA!$H$2:$H$16=1/(1/MAX(((DATA!$E$2:$E$16>=$B3)*(DATA!$F$2:$F$16>=$A3)+(DATA!$E$2:$E$16>=$A3)*(DATA!$F$2:$F$16>=$B3)>0)*(DATA!$G$2:$G$16>=$C3)*DATA!$H$2:$H$16))),1))
How can I apply the same logic in Power BI? Any advise please.
I am looking for new calculate column options. Herewith share the Excel file for your reference
https://www.dropbox.com/scl/fi/iq0gteeyazrg79q7a4tb1/AUTO-MODIFY-REQ.xlsx?dl=0&rlkey=nyyerjsg7if2dz30z9iqo6kdc
Here is another formula that will return the same result as per your current formula, although it is still a long formula, but more easily to understand:
=INDEX($D$2:$D$13,MATCH(MAX(IF($G$2:$G$13<$L3,0,
IF((IF($E$2:$E$13<$K3,0,1)*IF($F$2:$F$13<$J3,0,1))+(IF($E$2:$E$13<$J3,0,1)*IF($F$2:$F$13<$K3,0,1))>0,1,0))
*$H$2:$H$13),$H$2:$H$13,0),1)
So I will break it down to explain how do it working:
Part 1: This if formula is checking comparison of Size C, if your data is lower than than table, the value for the Type will be zero therefore will not be considered at all because zero times any amount will be zero
(IF($G$2:$G$13<$L3,0
Part 2: This part is will first checking comparison of Size A vs Size B, if lower than table than return 0 and apply for other comparison, at then end using If at the beginning to reset the value so than the final value will be 0 or 1
IF((IF($E$2:$E$13<$K3,0,1)*IF($F$2:$F$13<$J3,0,1))+(IF($E$2:$E$13<$J3,0,1)*IF($F$2:$F$13<$K3,0,1))>0,1,0)
Part 3: From the value you calculate, if 0 times any ranking will be zero, so from none zero ranking such as 12 or 9, it will get the max value from the list, most of them are 12
Max((.....)*$H$2:$H$13)
Part 4: Index Match - Finally it is same as your formula first part, but you are using Index row which make it difficult to understand
INDEX($D$2:$D$13,MATCH(Max(...))
A shorter version of your formula by removing unnecessary portion:
=INDEX($D$2:$D$13,MATCH(MAX(IF($G$2:$G$13<$L4,0,
IF(($E$2:$E$13>=$K4)*($F$2:$F$13>=$J4)+($E$2:$E$13>=$J4)*($F$2:$F$13>=$K4)>0,1,0))*$H$2:$H$13),
$H$2:$H$13,0),1)
You can add a colum to your report table like:
Desired = LOOKUPVALUE(DataR[TYPE],DataR[RANK], MAXX(FILTER(DataR, DataR[SIZEA] >= ReportR[SIZEA] && DataR[SIZEB] >= ReportR[SIZEB] && DataR[SIZEC] >= ReportR[SIZEC]), DataR[RANK]))
It first filters the table to find the row where the sizes are more or equal to the report row, selects the rank and then does a lookup to the type.
Result:
I am using WKHTMLTOPDF in ColdFusion 18 and am trying to have the page size be "Envelope DL". I found the global setting size.PageSize so in the code below I added pagesize = "Envelope DL" but this did not change it. Does anyone have any other ideas or could tell me what I am missing?
Any help would be greatly appreciated!
<CF_WKHTMLTOPDF
PageURL = "http://www.com/temppdf/test.htm"
filename = "D://temppdf/test.pdf"
orientation = "portrait"
DisableSmartShrinking="yes"
margintop = "0.25"
marginleft = "0.25"
marginright = "0.25"
marginbottom = "0.25"
TimeOut = "180"
AddFooterPageNum="yes">
<cfheader name="content-disposition" value="inline; filename=""CS_#Dateformat(NOW(),'MMDDYYYY')#.pdf""">
<cfcontent type="application/pdf" file="D://temppdf/test.pdf" deletefile="Yes">
I wrote the ColdFusion WKHTMLTOPDF custom tag. If you look at the source code, the notes indicate where to look for the "pagesize" parameter.
Here are the allowable paper sizes. (I've used "Comm10E" for my envelopes):
http://doc.qt.io/qt-4.8/qprinter.html#PaperSize-enum
QPrinter::A0 5 841 x 1189 mm
QPrinter::A1 6 594 x 841 mm
QPrinter::A2 7 420 x 594 mm
QPrinter::A3 8 297 x 420 mm
QPrinter::A4 0 210 x 297 mm, 8.26 x 11.69 inches
QPrinter::A5 9 148 x 210 mm
QPrinter::A6 10 105 x 148 mm
QPrinter::A7 11 74 x 105 mm
QPrinter::A8 12 52 x 74 mm
QPrinter::A9 13 37 x 52 mm
QPrinter::B0 14 1000 x 1414 mm
QPrinter::B1 15 707 x 1000 mm
QPrinter::B2 17 500 x 707 mm
QPrinter::B3 18 353 x 500 mm
QPrinter::B4 19 250 x 353 mm
QPrinter::B5 1 176 x 250 mm, 6.93 x 9.84 inches
QPrinter::B6 20 125 x 176 mm
QPrinter::B7 21 88 x 125 mm
QPrinter::B8 22 62 x 88 mm
QPrinter::B9 23 33 x 62 mm
QPrinter::B10 16 31 x 44 mm
QPrinter::C5E 24 163 x 229 mm
QPrinter::Comm10E 25 105 x 241 mm, U.S. Common 10 Envelope
QPrinter::DLE 26 110 x 220 mm
QPrinter::Executive 4 7.5 x 10 inches, 190.5 x 254 mm
QPrinter::Folio 27 210 x 330 mm
QPrinter::Ledger 28 431.8 x 279.4 mm
QPrinter::Legal 3 8.5 x 14 inches, 215.9 x 355.6 mm
QPrinter::Letter 2 8.5 x 11 inches, 215.9 x 279.4 mm
QPrinter::Tabloid 29 279.4 x 431.8 mm
QPrinter::Custom 30 Unknown, or a user defined size.
According to the wkhtmltopdf manual located here it then refers you to list of usable --page-size options which can be found here.
The page size of "DL Envelope" is 110mm x 220mm. So the page size option you need to supply to wkhtmltopdf is --page-size DLE.
I'm writing an application in Python that applies a watermark to a font file. The glyphs are non-convex polygons with holes and consist of bezier splines defined in PostScript. The watermark needs to merge with the glyphs, not overlap. I was unable to find a library to do this in Python so I'm using CGAL & C++. I have it working nicely on most glyphs, but it's mysteriously failing on others.
Initially, I was very impressed with CGAL. It looked very comprehensive and sophisticated and seemed to provide all the functionality I needed, but it suffers one fatal flaw - and I almost can't believe it - the library contains no error handling. No error codes, no exceptions, just assertions - but only in the debug build. In the release build you get a nice segmentation fault instead. Furthermore, the assertions reveal nothing about the nature of the problem.
The program fails only on certain glyphs. The letter 'e' works fine, but it crashes on 'a'. The crash occurs when I attempt to compute the union of the glyph with the watermark. There is nothing visibly wrong with the 'a' glyph. My application parses the PostScript correctly and renders it fine on a QGraphicsView.
This program needs to run on a server and its output sent directly to the customer so it must be reliable. I can't recover from an assertion failure or a segfault, so what can I do?
Even if I get it working reliably, how can I trust that it will never fail? If there was some kind of error handling in place, I could just skip the few glyphs that it fails on, leaving them unwatermarked - not ideal, but acceptable. I just don't understand what the authors of this library were thinking; they went to such tremendous effort to make the most comprehensive geometry library available only to ensure that it's completely unfit for purpose.
Currently, it's looking like I'm going to have to modify the code myself to handle the error in a sensible way, but this just seems so ridiculous.
I'm sorry if I come off as impatient, but I'm way past my deadline and my client isn't going to care about or understand these excuses.
The assertion failure is occurring on line 2141 of multiset.h:
CGAL_multiset_precondition (comp_f(object, nodeP->object) != LARGER);
It happens when I call join() on a BezierPolygonSet. My types are as follows:
typedef CGAL::CORE_algebraic_number_traits NtTraits;
typedef NtTraits::Rational Rational;
typedef NtTraits::Algebraic Algebraic;
typedef CGAL::Cartesian<Rational> RatKernel;
typedef CGAL::Cartesian<Algebraic> AlgKernel;
typedef RatKernel::Point_2 BezierRatPoint;
typedef CGAL::Arr_Bezier_curve_traits_2<RatKernel, AlgKernel, NtTraits> Traits;
typedef Traits::Point_2 BezierPoint;
typedef Traits::Curve_2 BezierCurve;
typedef CGAL::Gps_traits_2<Traits> BezierTraits;
typedef BezierTraits::X_monotone_curve_2 BezierXMonotoneCurve;
typedef BezierTraits::General_polygon_2 BezierPolygon;
typedef BezierTraits::General_polygon_with_holes_2 BezierPolygonWithHoles;
typedef CGAL::Gps_default_dcel<BezierTraits> BezierDcelTraits;
typedef CGAL::General_polygon_set_2<BezierTraits, BezierDcelTraits> BezierPolygonSet;
Any help would be much appreciated. Thanks.
EDIT:
I have a module called Geometry which wraps the CGAL code and exposes a bunch of geometric primitives (Point, Curve, LineSegment, CubicBezier, Path) and the functions:
PathList toPathList(const PolyList& polyList);
PolyList toPolyList(const PathList& paths);
The Path class has a method called computeUnion, which looks like this:
PathList Path::computeUnion(const PathList& paths1, const PathList& paths2) {
PolyList polyList1 = toPolyList(paths1);
PolyList polyList2 = toPolyList(paths2);
cgal_wrap::BezierPolygonSet polySet;
for (auto i : polyList1) {
polySet.join(i);
}
for (auto i : polyList2) {
polySet.join(i);
}
PolyList polyList;
polySet.polygons_with_holes(std::back_inserter(polyList));
return toPathList(polyList);
}
The error occurs when I call join(). The polygons are created from paths like so:
PolyList toPolyList(const PathList& paths) {
cgal_wrap::Traits traits;
cgal_wrap::Traits::Make_x_monotone_2 fnMakeXMonotone = traits.make_x_monotone_2_object();
cgal_wrap::RatKernel ratKernel;
cgal_wrap::RatKernel::Equal_2 fnEqual = ratKernel.equal_2_object();
PolyList polyList; // The final polygons with holes
cgal_wrap::BezierPolygon outerPoly;
std::list<cgal_wrap::BezierPolygon> holes;
std::list<cgal_wrap::BezierXMonotoneCurve> monoCurves;
bool first = true;
cgal_wrap::BezierRatPoint firstPoint;
// For each path in the list
for (auto i = paths.begin(); i != paths.end(); ++i) {
const Path& path = *i;
cgal_wrap::BezierRatPoint prevEndPoint;
// For each curve in the path
for (auto j = path.begin(); j != path.end(); ++j) {
const Curve& curve = **j;
std::list<cgal_wrap::BezierRatPoint> points;
if (curve.type() == LineSegment::type) {
const LineSegment& lseg = dynamic_cast<const LineSegment&>(curve);
cgal_wrap::BezierRatPoint A = lseg.A();
if (j != path.begin()) {
if (A != prevEndPoint) {
// TODO
assert(false);
}
A = prevEndPoint;
}
points.push_back(cgal_wrap::BezierRatPoint(A));
points.push_back(cgal_wrap::BezierRatPoint(lseg.B()));
}
else if (curve.type() == CubicBezier::type) {
const CubicBezier& bezier = dynamic_cast<const CubicBezier&>(curve);
cgal_wrap::BezierRatPoint A = bezier.A();
if (j != path.begin()) {
if (A != prevEndPoint) {
// TODO
assert(false);
}
A = prevEndPoint;
}
points.push_back(cgal_wrap::BezierRatPoint(A));
points.push_back(cgal_wrap::BezierRatPoint(bezier.B()));
points.push_back(cgal_wrap::BezierRatPoint(bezier.C()));
points.push_back(cgal_wrap::BezierRatPoint(bezier.D()));
}
bool bClosesCurve = false;
if (!first && Point(points.back()) == Point(firstPoint)) {
points.pop_back();
points.push_back(firstPoint);
bClosesCurve = true;
}
prevEndPoint = points.back();
cgal_wrap::BezierCurve cgalCurve(points.begin(), points.end());
std::list<CGAL::Object> monoObjs;
fnMakeXMonotone(cgalCurve, std::back_inserter(monoObjs));
// Append the x-monotone curves to the list
cgal_wrap::BezierXMonotoneCurve monoCurve;
for (auto o = monoObjs.begin(); o != monoObjs.end(); ++o) {
if (CGAL::assign(monoCurve, *o)) {
monoCurves.push_back(monoCurve);
}
}
if (!first) {
// If this curve closes the current chain, thereby creating a new polygon
if (bClosesCurve) {
// Add the new polygon to the list
cgal_wrap::BezierPolygon subPoly(monoCurves.begin(), monoCurves.end());
if (subPoly.orientation() == CGAL::COUNTERCLOCKWISE) {
if (!outerPoly.is_empty()) {
polyList.push_back(cgal_wrap::BezierPolygonWithHoles(outerPoly, holes.begin(), holes.end()));
holes.clear();
}
outerPoly = subPoly;
}
else {
holes.push_back(subPoly);
}
monoCurves.clear();
first = true;
}
}
else {
// This is the first curve in the chain - store its source point
firstPoint = cgalCurve.control_point(0);
first = false;
}
}
}
polyList.push_back(cgal_wrap::BezierPolygonWithHoles(outerPoly, holes.begin(), holes.end()));
return polyList;
}
Notice that I'm careful to ensure that the polygon boundaries have no gaps by setting the first point of curve n+1 to the last point of curve n in case they were slightly different. I was hoping this would solve the problem, but it didn't. I can't think of any other things that might make the shapes invalid.
Here is the successful merging of the 'e' glyph with the watermark (an X).
Here is what the 'a' glyph looks like. The merging fails on this glyph.
EDIT 2:
Here are the curves that make up the 'a' glyph after parsing it from PostScript. There doesn't appear to be anything wrong with it. As I said, it looks okay when rendered. The error probably occurs during the translation from this data into the CGAL types. The line segments get translated into BezierCurves with 2 control points. I will investigate further.
LineSegment[(344, 0), (409, 0)]
CubicBezier[(409, 0), (403, 24), (400, 68), (400, 161)]
LineSegment[(400, 161), (400, 324)]
CubicBezier[(400, 324), (400, 437), (330, 485), (232, 485)]
CubicBezier[(232, 485), (180, 485), (121, 472), (66, 437)]
LineSegment[(66, 437), (94, 385)]
CubicBezier[(94, 385), (127, 405), (167, 424), (224, 424)]
CubicBezier[(224, 424), (283, 424), (326, 392), (326, 320)]
LineSegment[(326, 320), (326, 290)]
LineSegment[(326, 290), (236, 287)]
CubicBezier[(236, 287), (188, 285), (150, 280), (118, 264)]
CubicBezier[(118, 264), (70, 242), (38, 199), (38, 136)]
CubicBezier[(38, 136), (38, 45), (102, -10), (188, -10)]
CubicBezier[(188, -10), (247, -10), (293, 18), (330, 53)]
LineSegment[(330, 53), (344, 0)]
LineSegment[(326, 234), (326, 114)]
CubicBezier[(326, 114), (304, 91), (260, 52), (201, 52)]
CubicBezier[(201, 52), (147, 52), (113, 88), (113, 140)]
CubicBezier[(113, 140), (113, 171), (127, 198), (154, 213)]
CubicBezier[(154, 213), (175, 224), (202, 230), (243, 231)]
LineSegment[(243, 231), (326, 234)]
EDIT 3:
Here are the 'a' glyph curves after translation into CGAL curves. Notice that they exactly match the curves before translation implying that none of them had to be split into X-monotone subcurves; they must have all been X-monotone already.
Outer boundary:
2 344 0 409 0 [1] | 344 0 --> 409 0
4 409 0 403 24 400 68 400 161 [1] | 409 0 --> 400 161
2 400 161 400 324 [1] | 400 161 --> 400 324
4 400 324 400 437 330 485 232 485 [1] | 400 324 --> 232 485
4 232 485 180 485 121 472 66 437 [1] | 232 485 --> 66 437
2 66 437 94 385 [1] | 66 437 --> 94 385
4 94 385 127 405 167 424 224 424 [1] | 94 385 --> 224 424
4 224 424 283 424 326 392 326 320 [1] | 224 424 --> 326 320
2 326 320 326 290 [1] | 326 320 --> 326 290
2 326 290 236 287 [1] | 326 290 --> 236 287
4 236 287 188 285 150 280 118 264 [1] | 236 287 --> 118 264
4 118 264 70 242 38 199 38 136 [1] | 118 264 --> 38 136
4 38 136 38 45 102 -10 188 -10 [1] | 38 136 --> 188 -10
4 188 -10 247 -10 293 18 330 53 [1] | 188 -10 --> 330 53
2 330 53 344 0 [1] | 330 53 --> 344 0
Holes:
Hole:
2 326 234 326 114 [1] | 326 234 --> 326 114
4 326 114 304 91 260 52 201 52 [1] | 326 114 --> 201 52
4 201 52 147 52 113 88 113 140 [1] | 201 52 --> 113 140
4 113 140 113 171 127 198 154 213 [1] | 113 140 --> 154 213
4 154 213 175 224 202 230 243 231 [1] | 154 213 --> 243 231
2 243 231 326 234 [1] | 243 231 --> 326 234
This polygon causes the assertion failure when added to a BezierPolygonSet. Any ideas?
You can customize error handling; see the manual.
Please attach a complete standalone program. Nothing looks wrong to me with statements you listed.
You can approximate the Bezier curves with polylines and process the whole things using polylines. If the problem is with the handling of Bezier curves, then this would solve it. If this is acceptable, it will also be more efficient.
We have fixed a bug in the CGAL component that handles Bezier curves, namely, Arr_Bezier_curve_traits_2.h.
I'm trying to create a graph and I need to know the size of the window the user is running the code in. I'm trying to scale the data so the data shows only on the size of the window, without wrapping or scrolling. I'm on windows but I want to use something similar to Linux equivalent
int lines = atoi(getenv("LINES") ;
int cols = atoi(getenv("COLUMNS") ;
So I can scale numbers and show a graph like this
320 a ============================================================
160 b ==============================
80 c ===============
40 d =======
20 e ===
10 f =
5 g
2 h
1 i
2 j
17 k ===
41 l =======
67 m ============
97 n ==================
127 o ========================
157 p =============================
191 q ====================================
227 r ===========================================
257 s ================================================
283 t =====================================================
331 u ==============================================================
367 v =====================================================================
373 w ======================================================================
379 x ========================================================================
383 y ========================================================================
389 z ==========================================================================
Is there something that will work on Windows and Linux? I'm using Visual Studio 2012.
Use GetWindowRect
RECT rect;
if(GetWindowRect(hwnd, &rect))
{
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
}
Use GetConsoleScreenBufferInfo or one of its siblings.
You are interrested in the dzSize field of the "returned" struct.
Read documentation here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx
You already have a solution for Linux.
On Windows the API call you need is GetConsoleScreenBufferInfo.
This returns a CONSOLE_SCREEN_BUFFER_INFO struct, from which you read out the dwSize member:
A COORD structure that contains the size of the console screen buffer, in character columns and rows.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am currently trying to understand how the following code (http://pastebin.com/zTHUrmyx) works, my approach is currently compiling the software in debug and using gdb to step through the code.
However, I'm running into the problem that 'step' does not always tell me what is going on. Particularly unclear to me is the EXECUTE {...} which I cannot step into.
How do I go about learning what the code is doing?
1 /*
2 Copyright 2008 Brain Research Institute, Melbourne, Australia
3
4 Written by J-Donald Tournier, 27/06/08.
5
6 This file is part of MRtrix.
7
8 MRtrix is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 MRtrix is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with MRtrix. If not, see <http://www.gnu.org/licenses/>.
20
21
22 15-10-2008 J-Donald Tournier <d.tournier#brain.org.au>
23 * fix -prs option handling
24 * remove MR::DICOM_DW_gradients_PRS flag
25
26 15-10-2008 J-Donald Tournier <d.tournier#brain.org.au>
27 * add -layout option to manipulate data ordering within the image file
28
29 14-02-2010 J-Donald Tournier <d.tournier#brain.org.au>
30 * fix -coord option so that the "end" keyword can be used
31
32
33 */
34
35 #include "app.h"
36 #include "image/position.h"
37 #include "image/axis.h"
38 #include "math/linalg.h"
39
40 using namespace std;
41 using namespace MR;
42
43 SET_VERSION_DEFAULT;
44
45 DESCRIPTION = {
46 "perform conversion between different file types and optionally extract a subset of the input image.",
47 "If used correctly, this program can be a very useful workhorse. In addition to converting images between different formats, it can be used to extract specific studies from a data set, extract a specific region of interest, flip the images, or to scale the intensity of the images.",
48 NULL
49 };
50
51 ARGUMENTS = {
52 Argument ("input", "input image", "the input image.").type_image_in (),
53 Argument ("ouput", "output image", "the output image.").type_image_out (),
54 Argument::End
55 };
56
57
58 const gchar* type_choices[] = { "REAL", "IMAG", "MAG", "PHASE", "COMPLEX", NULL };
59 const gchar* data_type_choices[] = { "FLOAT32", "FLOAT32LE", "FLOAT32BE", "FLOAT64", "FLOAT64LE", "FLOAT64BE",
60 "INT32", "UINT32", "INT32LE", "UINT32LE", "INT32BE", "UINT32BE",
61 "INT16", "UINT16", "INT16LE", "UINT16LE", "INT16BE", "UINT16BE",
62 "CFLOAT32", "CFLOAT32LE", "CFLOAT32BE", "CFLOAT64", "CFLOAT64LE", "CFLOAT64BE",
63 "INT8", "UINT8", "BIT", NULL };
64
65 OPTIONS = {
66 Option ("coord", "select coordinates", "extract data only at the coordinates specified.", false, true)
67 .append (Argument ("axis", "axis", "the axis of interest").type_integer (0, INT_MAX, 0))
68 .append (Argument ("coord", "coordinates", "the coordinates of interest").type_sequence_int()),
69
70 Option ("vox", "voxel size", "change the voxel dimensions.")
71 .append (Argument ("sizes", "new dimensions", "A comma-separated list of values. Only those values specified will be changed. For example: 1,,3.5 will change the voxel size along the x & z axes, and leave the y-axis voxel size unchanged.")
72 .type_sequence_float ()),
73
74 Option ("datatype", "data type", "specify output image data type.")
75 .append (Argument ("spec", "specifier", "the data type specifier.").type_choice (data_type_choices)),
76
77 Option ("scale", "scaling factor", "apply scaling to the intensity values.")
78 .append (Argument ("factor", "factor", "the factor by which to multiply the intensities.").type_float (NAN, NAN, 1.0)),
79
80 Option ("offset", "offset", "apply offset to the intensity values.")
81 .append (Argument ("bias", "bias", "the value of the offset.").type_float (NAN, NAN, 0.0)),
82
83 Option ("zero", "replace NaN by zero", "replace all NaN values with zero."),
84
85 Option ("output", "output type", "specify type of output")
86 .append (Argument ("type", "type", "type of output.")
87 .type_choice (type_choices)),
88
89 Option ("layout", "data layout", "specify the layout of the data in memory. The actual layout produced will depend on whether the output image format can support it.")
90 .append (Argument ("spec", "specifier", "the data layout specifier.").type_string ()),
91
92 Option ("prs", "DW gradient specified as PRS", "assume that the DW gradients are specified in the PRS frame (Siemens DICOM only)."),
93
94 Option::End
95 };
96
97
98
99 inline bool next (Image::Position& ref, Image::Position& other, const std::vector<int>* pos)
100 {
101 int axis = 0;
102 do {
103 ref.inc (axis);
104 if (ref[axis] < ref.dim(axis)) {
105 other.set (axis, pos[axis][ref[axis]]);
106 return (true);
107 }
108 ref.set (axis, 0);
109 other.set (axis, pos[axis][0]);
110 axis++;
111 } while (axis < ref.ndim());
112 return (false);
113 }
114
115
116
117
118
119 EXECUTE {
120 std::vector<OptBase> opt = get_options (1); // vox
121 std::vector<float> vox;
122 if (opt.size())
123 vox = parse_floats (opt[0][0].get_string());
124
125
126 opt = get_options (3); // scale
127 float scale = 1.0;
128 if (opt.size()) scale = opt[0][0].get_float();
129
130 opt = get_options (4); // offset
131 float offset = 0.0;
132 if (opt.size()) offset = opt[0][0].get_float();
133
134 opt = get_options (5); // zero
135 bool replace_NaN = opt.size();
136
137 opt = get_options (6); // output
138 Image::OutputType output_type = Image::Default;
139 if (opt.size()) {
140 switch (opt[0][0].get_int()) {
141 case 0: output_type = Image::Real; break;
142 case 1: output_type = Image::Imaginary; break;
143 case 2: output_type = Image::Magnitude; break;
144 case 3: output_type = Image::Phase; break;
145 case 4: output_type = Image::RealImag; break;
146 }
147 }
148
149
150
151
152 Image::Object &in_obj (*argument[0].get_image());
153
154 Image::Header header (in_obj);
155
156 if (output_type == 0) {
157 if (in_obj.is_complex()) output_type = Image::RealImag;
158 else output_type = Image::Default;
159 }
160
161 if (output_type == Image::RealImag) header.data_type = DataType::CFloat32;
162 else if (output_type == Image::Phase) header.data_type = DataType::Float32;
163 else header.data_type.unset_flag (DataType::ComplexNumber);
164
165
166 opt = get_options (2); // datatype
167 if (opt.size()) header.data_type.parse (data_type_choices[opt[0][0].get_int()]);
168
169 for (guint n = 0; n < vox.size(); n++)
170 if (isfinite (vox[n])) header.axes.vox[n] = vox[n];
171
172 opt = get_options (7); // layout
173 if (opt.size()) {
174 std::vector<Image::Axis> ax = parse_axes_specifier (header.axes, opt[0][0].get_string());
175 if (ax.size() != (guint) header.axes.ndim())
176 throw Exception (String("specified layout \"") + opt[0][0].get_string() + "\" does not match image dimensions");
177
178 for (guint i = 0; i < ax.size(); i++) {
179 header.axes.axis[i] = ax[i].axis;
180 header.axes.forward[i] = ax[i].forward;
181 }
182 }
183
184
185 opt = get_options (8); // prs
186 if (opt.size() && header.DW_scheme.rows() && header.DW_scheme.columns()) {
187 for (guint row = 0; row < header.DW_scheme.rows(); row++) {
188 double tmp = header.DW_scheme(row, 0);
189 header.DW_scheme(row, 0) = header.DW_scheme(row, 1);
190 header.DW_scheme(row, 1) = tmp;
191 header.DW_scheme(row, 2) = -header.DW_scheme(row, 2);
192 }
193 }
194
195 std::vector<int> pos[in_obj.ndim()];
196
197 opt = get_options (0); // coord
198 for (guint n = 0; n < opt.size(); n++) {
199 int axis = opt[n][0].get_int();
200 if (pos[axis].size()) throw Exception ("\"coord\" option specified twice for axis " + str (axis));
201 pos[axis] = parse_ints (opt[n][1].get_string(), header.dim(axis)-1);
202 header.axes.dim[axis] = pos[axis].size();
203 }
204
205 for (int n = 0; n < in_obj.ndim(); n++) {
206 if (pos[n].empty()) {
207 pos[n].resize (in_obj.dim(n));
208 for (guint i = 0; i < pos[n].size(); i++) pos[n][i] = i;
209 }
210 }
211
212
213 in_obj.apply_scaling (scale, offset);
214
215
216
217
218
219
220 Image::Position in (in_obj);
221 Image::Position out (*argument[1].get_image (header));
222
223 for (int n = 0; n < in.ndim(); n++) in.set (n, pos[n][0]);
224
225 ProgressBar::init (out.voxel_count(), "copying data...");
226
227 do {
228
229 float re, im = 0.0;
230 in.get (output_type, re, im);
231 if (replace_NaN) if (gsl_isnan (re)) re = 0.0;
232 out.re (re);
233
234 if (output_type == Image::RealImag) {
235 if (replace_NaN) if (gsl_isnan (im)) im = 0.0;
236 out.im (im);
237 }
238
239 ProgressBar::inc();
240 } while (next (out, in, pos));
241
242 ProgressBar::done();
243 }
As was noted in the comments, EXECUTE seems to be a macro, apparent from the context a function header (and maybe a bit more, e.g. some global variables and functions), so the part in curly braces is the function body.
To get to the definition of EXECUTE, you will have to examine the headers.
However, if you can reach some part of the code during debugging, you could insert a string or char[] at that point, giving it the stringified version of EXECUTE, so you get whatever the preprocessor will emit for EXECUTE at that position in the code.
#define STR(x) #x
#define STRINGIFY(x) STR(x)
char c[] = STRINGIFY(EXECUTE);
the two macros are a known little macro trick to get the content of any macro as a string literal. Try it out and inspect the char array in your debugger to get the content of execute.
My wild guess here: EXECUTE is the main function or a replacement for it, the OPTIONS and ARGUMENTS describe what arguments the program expects and what command line options you can pass to it. Those macros and some of the used functions and variables (get_options, argument) are part of a little framework that should facilitate the usage, evaluation and user information about command line options.