Sponsored Content
Top Forums Shell Programming and Scripting Using IF statements with maths where the input is not an integer Post 302546900 by yazu on Friday 12th of August 2011 11:42:30 AM
Old 08-12-2011
You really over complicated things. Smilie Awk can work with floating numbers (even "old" awk, afaik).

You just need this:
Code:
awk  '{ for (i=1; i<=NF; i++)  s+= $i  } END { print s }'

In your first attempt you just add zero with the first field and this field was zero.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with Maths

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)
Discussion started by: Quesa
3 Replies

2. Shell Programming and Scripting

isql input file with multiple sql statements

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)
Discussion started by: Cailet
0 Replies

3. Shell Programming and Scripting

Perl - maths equation - need help

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)
Discussion started by: Anuj8584
7 Replies

4. Programming

How i can read a long integer from standar input and a string with as many characters as specified..

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)
Discussion started by: aintour
6 Replies

5. Shell Programming and Scripting

Maths with variables

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)
Discussion started by: DFr0st
1 Replies

6. UNIX for Dummies Questions & Answers

Check if input is an integer or a floating point?

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)
Discussion started by: krishnampkkm
2 Replies

7. Programming

I don't know how to replace input char with appropriate integer

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)
Discussion started by: solaris_user
6 Replies

8. Shell Programming and Scripting

Simple maths calculator loop.

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)
Discussion started by: johnthebaptist
4 Replies

9. Shell Programming and Scripting

Maths in shell scripts

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)
Discussion started by: vchee
4 Replies

10. Shell Programming and Scripting

Calculate the constant e to 14+ decimal places using integer maths.

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
gdaldem(1)						      General Commands Manual							gdaldem(1)

NAME
gdaldem - gdaldem Tools to analyze and visualize DEMs. (since GDAL 1.7.0) SYNOPSIS
- To generate a shaded relief map from any GDAL-supported elevation raster : gdaldem hillshade input_dem output_hillshade [-z ZFactor (default=1)] [-s scale* (default=1)]" [-az Azimuth (default=315)] [-alt Altitude (default=45)] [-alg ZevenbergenThorne] [-compute_edges] [-b Band (default=1)] [-of format] [-co "NAME=VALUE"]* [-q] - To generate a slope map from any GDAL-supported elevation raster : gdaldem slope input_dem output_slope_map" [-p use percent slope (default=degrees)] [-s scale* (default=1)] [-alg ZevenbergenThorne] [-compute_edges] [-b Band (default=1)] [-of format] [-co "NAME=VALUE"]* [-q] - To generate an aspect map from any GDAL-supported elevation raster Outputs a 32-bit float raster with pixel values from 0-360 indicating azimuth : gdaldem aspect input_dem output_aspect_map" [-trigonometric] [-zero_for_flat] [-alg ZevenbergenThorne] [-compute_edges] [-b Band (default=1)] [-of format] [-co "NAME=VALUE"]* [-q] - To generate a color relief map from any GDAL-supported elevation raster gdaldem color-relief input_dem color_text_file output_color_relief_map [-alpha] [-exact_color_entry | -nearest_color_entry] [-b Band (default=1)] [-of format] [-co "NAME=VALUE"]* [-q] where color_text_file contains lines of the format "elevation_value red green blue" - To generate a Terrain Ruggedness Index (TRI) map from any GDAL-supported elevation raster: gdaldem TRI input_dem output_TRI_map [-compute_edges] [-b Band (default=1)] [-of format] [-q] - To generate a Topographic Position Index (TPI) map from any GDAL-supported elevation raster: gdaldem TPI input_dem output_TPI_map [-compute_edges] [-b Band (default=1)] [-of format] [-q] - To generate a roughness map from any GDAL-supported elevation raster: gdaldem roughness input_dem output_roughness_map [-compute_edges] [-b Band (default=1)] [-of format] [-q] Notes : Scale is the ratio of vertical units to horizontal for Feet:Latlong use scale=370400, for Meters:LatLong use scale=111120).fi DESCRIPTION
This utility has 7 different modes : hillshade to generate a shaded relief map from any GDAL-supported elevation raster slope to generate a slope map from any GDAL-supported elevation raster aspect to generate an aspect map from any GDAL-supported elevation raster color-relief to generate a color relief map from any GDAL-supported elevation raster TRI to generate a map of Terrain Ruggedness Index from any GDAL-supported elevation raster TPI to generate a map of Topographic Position Index from any GDAL-supported elevation raster roughness to generate a map of roughness from any GDAL-supported elevation raster The following general options are available : input_dem: The input DEM raster to be processed output_xxx_map: The output raster produced -of format: Select the output format. The default is GeoTIFF (GTiff). Use the short format name. -compute_edges: (GDAL >= 1.8.0) Do the computation at raster edges and near nodata values -alg ZevenbergenThorne: (GDAL >= 1.8.0) Use Zevenbergen & Thorne formula, instead of Horn's formula, to compute slope & aspect. The litterature suggests Zevenbergen & Thorne to be more suited to smooth landscapes, whereas Horn's formula to perform better on rougher terrain. -b band: Select an input band to be processed. Bands are numbered from 1. -co 'NAME=VALUE': Passes a creation option to the output format driver. Multiple -co options may be listed. See format specific documentation for legal creation options for each format. -q: Suppress progress monitor and other non-error output. For all algorithms, except color-relief, a nodata value in the target dataset will be emitted if at least one pixel set to the nodata value is found in the 3x3 window centered around each source pixel. The consequence is that there will be a 1-pixel border around each image set with nodata value. From GDAL 1.8.0, if -compute_edges is specified, gdaldem will compute values at image edges or if a nodata value is found in the 3x3 window, by interpolating missing values. Modes hillshade This command outputs an 8-bit raster with a nice shaded relief effect. It's very useful for visualizing the terrain. You can optionally specify the azimuth and altitude of the light source, a vertical exaggeration factor and a scaling factor to account for differences between vertical and horizontal units. The value 0 is used as the output nodata value. The following specific options are available : -z zFactor: vertical exaggeration used to pre-multiply the elevations -s scale: ratio of vertical units to horizontal. If the horizontal unit of the source DEM is degrees (e.g Lat/Long WGS84 projection), you can use scale=111120 if the vertical units are meters (or scale=370400 if they are in feet) -az azimuth: azimuth of the light, in degrees. 0 if it comes from the top of the raster, 90 from the east, ... The default value, 315, should rarely be changed as it is the value generally used to generate shaded maps. -alt altitude: altitude of the light, in degrees. 90 if the light comes from above the DEM, 0 if it is raking light. slope This command will take a DEM raster and output a 32-bit float raster with slope values. You have the option of specifying the type of slope value you want: degrees or percent slope. In cases where the horizontal units differ from the vertical units, you can also supply a scaling factor. The value -9999 is used as the output nodata value. The following specific options are available : -p : if specified, the slope will be expressed as percent slope. Otherwise, it is expressed as degrees -s scale: ratio of vertical units to horizontal. If the horizontal unit of the source DEM is degrees (e.g Lat/Long WGS84 projection), you can use scale=111120 if the vertical units are meters (or scale=370400 if they are in feet) aspect This command outputs a 32-bit float raster with values between 0o and 360o representing the azimuth that slopes are facing. The definition of the azimuth is such that : 0o means that the slope is facing the North, 90o it's facing the East, 180o it's facing the South and 270o it's facing the West (provided that the top of your input raster is north oriented). The aspect value -9999 is used as the nodata value to indicate undefined aspect in flat areas with slope=0. The following specifics options are available : -trigonometric: return trigonometric angle instead of azimuth. Thus 0o means East, 90o North, 180o West, 270o South -zero_for_flat: return 0 for flat areas with slope=0, instead of -9999 By using those 2 options, the aspect returned by gdaldem aspect should be identical to the one of GRASS r.slope.aspect. Otherwise, it's identical to the one of Matthew Perry's aspect.cpp utility. color-relief This command outputs a 3-band (RGB) or 4-band (RGBA) raster with values are computed from the elevation and a text-based color configuration file, containing the association between various elevation values and the corresponding wished color. By default, the colors between the given elevation values are blended smoothly and the result is a nice colorized DEM. The -exact_color_entry or -nearest_color_entry options can be used to avoid that linear interpolation for values that don't match an index of the color configuration file. The following specifics options are available : color_text_file: text-based color configuration file -alpha : add an alpha channel to the output raster -exact_color_entry : use strict matching when searching in the color configuration file. If none matching color entry is found, the '0,0,0,0' RGBA quadruplet will be used -nearest_color_entry : use the RGBA quadruplet corresponding to the closest entry in the color configuration file. The color-relief mode is the only mode that supports VRT as output format. In that case, it will translate the color configuration file into appropriate LUT elements. Note that elevations specified as percentage will be translated as absolute values, which must be taken into account when the statistics of the source raster differ from the one that was used when building the VRT. The text-based color configuration file generally contains 4 columns per line : the elevation value and the corresponding Red, Green, Blue component (between 0 and 255). The elevation value can be any floating point value, or the nv keyword for the nodata value.. The elevation can also be expressed as a percentage : 0% being the minimum value found in the raster, 100% the maximum value. An extra column can be optionnaly added for the alpha component. If it is not specified, full opacity (255) is assumed. Various field separators are accepted : comma, tabulation, spaces, ':'. Common colors used by GRASS can also be specified by using their name, instead of the RGB triplet. The supported list is : white, black, red, green, blue, yellow, magenta, cyan, aqua, grey/gray, orange, brown, purple/violet and indigo. Since GDAL 1.8.0, GMT .cpt palette files are also supported (COLOR_MODEL = RGB only). Note: the syntax of the color configuration file is derived from the one supported by GRASS r.colors utility. ESRI HDR color table files (.clr) also match that syntax. The alpha component and the support of tablulations and commma as separators are GDAL specific extensions. For example : 3500 white 2500 235:220:175 50% 190 185 135 700 240 250 150 0 50 180 50 nv 0 0 0 0 TRI This command outputs a single-band raster with values computed from the elevation. TRI stands for Terrain Ruggedness Index, which is defined as the mean difference between a central pixel and its surrounding cells (see Wilson et al 2007, Marine Geodesy 30:3-35). The value -9999 is used as the output nodata value. There are no specific options. TPI This command outputs a single-band raster with values computed from the elevation. TPI stands for Topographic Position Index, which is defined as the difference between a central pixel and the mean of its surrounding cells (see Wilson et al 2007, Marine Geodesy 30:3-35). The value -9999 is used as the output nodata value. There are no specific options. roughness This command outputs a single-band raster with values computed from the elevation. Roughness is the the largest inter-cell difference of a central pixel and its surrounding cell, as defined in Wilson et al (2007, Marine Geodesy 30:3-35). The value -9999 is used as the output nodata value. There are no specific options. AUTHORS
Matthew Perry perrygeo@gmail.com, Even Rouault even.rouault@mines-paris.org, Howard Butler hobu.inc@gmail.com, Chris Yesson chris.yesson@ioz.ac.uk Derived from code by Michael Shapiro, Olga Waupotitsch, Marjorie Larson, Jim Westervelt : U.S. Army CERL, 1993. GRASS 4.1 Reference Manual. U.S. Army Corps of Engineers, Construction Engineering Research Laboratories, Champaign, Illinois, 1-425. See also Documentation of related GRASS utilities : http://grass.osgeo.org/grass64/manuals/html64_user/r.slope.aspect.html http://grass.osgeo.org/grass64/manuals/html64_user/r.shaded.relief.html http://grass.osgeo.org/grass64/manuals/html64_user/r.colors.html GDAL
Tue Sep 18 2012 gdaldem(1)
All times are GMT -4. The time now is 01:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy