Using IF statements with maths where the input is not an integer
Hi All
I've made a few scripts which using GDAL extract the value of a pixel within a given raster. The purpose is to work out the combine value of every pixel. I thought there may have been an easier way to do this but alas!
The code below extracts the pixel value at position X Y. The value is a floating point rather than an integer and thats where my problem lies. The if statement simply exports the value to a txt file. Other scripts take care of the rest ie change values of X Y and summing the resultant txt files.
However, I get the following message back when ever my statement is true because my value isn't an integer;
extract2.sh: line 4: [: 2.15787172317505: integer expression expected
Please note the raster file mostly contains zero values, and its only the values greater than zero I'm interested in, which is why I added the expression.
Any ideas how I can alter this code so the IF statement excepts integers? Alternatively if anyone knows of a faster method of quickly summing the values of a raster file, that would be equally useful.
Many thanks in advance for any assistance you can offer.
Andy
Last edited by vbe; 08-12-2011 at 09:50 AM..
Reason: please use code tags!
Heres a script i wrote as a bit of practise. What it does is insert a line in the middle of a file. The line being $1 and the file being $2
#!/bin/bash
rm tempfile
touch tempfile
count=1
linenum= `wc -l < $2`
if
then
echo $1 >> $2
else
even=`expr "$linenum" % 2`
if
then... (3 Replies)
I've got:
isql -U $USERID -S $SERVER -D $DATABASE -i inputfile.sql -o outputfile.txt
in inputfile I have:
go
sql#1
go
sql#2
go
sql#3
go
I also tried without "go" and with";" instead which did not work
SQL statements will work if I paste them directly into the script and use EOF
... (0 Replies)
if input to the perl program is ' ( p * ((a+b) * (c+d))) + q ' it shuld give the output as ' pac + pad + pbc + pbd + q ' .can anyone suggest a way to do this ? (7 Replies)
how i can read a long integer from standar input and a string with as many characters as specified in the number?
i thing that i must use the read command ofcourse.... (6 Replies)
Hello,
I'm trying to write a while loop for a decimal value in tcsh which I know can't be done. Instead I want my increments to be one order of magnitude too large and then divide it by 10 when I use the variable. However, I don't know how to divide my variable and set it as another.
set... (1 Reply)
Hiii
I actually intent to check the integer or floating point number input by user i.e. 23, 100, 55.25, 12.50 ..etc. However, when someone input strings or alpha character, my program has to show invalid input.!! Is there any Unix shell script syntax can help me to check ?
Thanking you (2 Replies)
Hi guys, I asked for help on programming forums and no one didn't helped me so I ask for help here. I am playing with some tasks from my book and I can't figure where did I get wrong.
From the first program I get a blank screen, program won't generate 10*10 matrix.
And second problem is I... (6 Replies)
Hi, I am trying to make a maths calculator that:
1. Prompts the user for a number.
2. Prompts the user for an operation (add, subtract, divide or multiply)
3. Prompts the user for a number.
4. Prompts the user for another operation (same as above) OR the option to get the result for the... (4 Replies)
Hi,
Need help on this. I need to increment a variable by 1 but retain as 2 characters.
I am using expr to do additions:
NEWSERIAL=`expr $SERIAL + 1`
$SERIAL can range from 01-99. After adding "1", I need the result to be 2 characters, eg: 02+1 = 03. By default expr will truncate the... (4 Replies)
Hi guys...
I am loving this integer maths thing.
64 bit systems are certainly easier than 32 bit, but hey, I don't intend to leave out my fav' platform.
Using one of the 'Brothers' methods, URL inside the code.
#!/bin/sh
#
# #!/usr/local/bin/dash
# e_constant.sh
# Brother's formula .
#... (2 Replies)
Discussion started by: wisecracker
2 Replies
LEARN ABOUT OSX
glbitmap
GLBITMAP(3G)GLBITMAP(3G)NAME
glBitmap - draw a bitmap
C SPECIFICATION
void glBitmap( GLsizei width,
GLsizei height,
GLfloat xorig,
GLfloat yorig,
GLfloat xmove,
GLfloat ymove,
const GLubyte *bitmap )
PARAMETERS
width, height Specify the pixel width and height of the bitmap image.
xorig, yorig Specify the location of the origin in the bitmap image. The origin is measured from the lower left corner of the bitmap,
with right and up being the positive axes.
xmove, ymove Specify the x and y offsets to be added to the current raster position after the bitmap is drawn.
bitmap Specifies the address of the bitmap image.
DESCRIPTION
A bitmap is a binary image. When drawn, the bitmap is positioned relative to the current raster position, and frame buffer pixels corre-
sponding to 1's in the bitmap are written using the current raster color or index. Frame buffer pixels corresponding to 0's in the bitmap
are not modified.
glBitmap takes seven arguments. The first pair specifies the width and height of the bitmap image. The second pair specifies the location
of the bitmap origin relative to the lower left corner of the bitmap image. The third pair of arguments specifies x and y offsets to be
added to the current raster position after the bitmap has been drawn. The final argument is a pointer to the bitmap image itself.
The bitmap image is interpreted like image data for the glDrawPixels command, with width and height corresponding to the width and height
arguments of that command, and with type set to GL_BITMAP and format set to GL_COLOR_INDEX. Modes specified using glPixelStore affect the
interpretation of bitmap image data; modes specified using glPixelTransfer do not.
If the current raster position is invalid, glBitmap is ignored. Otherwise, the lower left corner of the bitmap image is positioned at the
window coordinates
xw = xr - xo
yw = yr - yo
where ( xr , yr ) is the raster position and ( xo , yo ) is the bitmap origin. Fragments are then generated for each pixel corresponding
to a 1 (one) in the bitmap image. These fragments are generated using the current raster z coordinate, color or color index, and current
raster texture coordinates. They are then treated just as if they had been generated by a point, line, or polygon, including texture map-
ping,
fogging, and all per-fragment operations such as alpha and depth testing.
After the bitmap has been drawn, the x and y coordinates of the current raster position are offset by xmove and ymove. No change is made
to the z coordinate of the current raster position, or to the current raster color, texture coordinates, or index.
NOTES
To set a valid raster position outside the viewport, first set a valid raster position inside the viewport, then call glBitmap with NULL as
the bitmap parameter and with xmove and ymove set to the offsets of the new raster position. This technique is useful when panning an image
around the viewport.
ERRORS
GL_INVALID_VALUE is generated if width or height is negative.
GL_INVALID_OPERATION is generated if glBitmap is executed between the execution of glBegin and the corresponding execution of glEnd.
ASSOCIATED GETS
glGet with argument GL_CURRENT_RASTER_POSITION
glGet with argument GL_CURRENT_RASTER_COLOR
glGet with argument GL_CURRENT_RASTER_DISTANCE
glGet with argument GL_CURRENT_RASTER_INDEX
glGet with argument GL_CURRENT_RASTER_TEXTURE_COORDS
glGet with argument GL_CURRENT_RASTER_POSITION_VALID
SEE ALSO
glDrawPixels, glPixelStore, glPixelTransfer, glRasterPos
GLBITMAP(3G)