public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Awk not ouputting results via echo
@ 2015-11-23 13:17 Lester Anderson
  2015-11-23 14:00 ` Lester Anderson
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Lester Anderson @ 2015-11-23 13:17 UTC (permalink / raw)
  To: cygwin

Hello,

Having sorted how to access a separate drive location, I have expanded
the script to include an awk section which processes new coordinate
limits which should pass to img2grd to extract the data grids.
However, the awk scripting does not seem to generate any data - is
there something I am missing? Modified from a published script

#!/bin/bash
ruta_elev="Q:/geophys/Potential-field datasets/Topography/topo_17.1.img"
ruta_grav="Q:/geophys/Potential-field datasets/Gravity/grav.img.23.1"
lon_min=-12
lon_max=0
lat_min=28
lat_max=39
R_d=167
R_i=20

echo $lon_min $lon_max $lat_min $lat_max $R_d $R_i |
awk "{R_t=6370;
      pi=3.14159;
      lat_av=(($lat_max+$lat_min)/2)*(pi/180.);
      lon_av=(($lon_min+$lon_max)/2);
      d_lat_e=($R_d/R_t)*180./pi;
      d_lon_e=($R_d/(R_t*cos(lat_av)))*180./pi;
      d_lat_i=($R_i/R_t)*180./pi;
      d_lon_i=($R_i/(R_t*cos(lat_av)))*180./pi;
      lon_e_min=$lon_min-d_lon_e;
      lon_e_max=$lon_max+d_lon_e;
      lat_e_min=$lat_min-d_lat_e;
      lat_e_max=$lat_max+d_lat_e;
      lon_i_min=$lon_min-d_lon_i;
      lon_i_max=$lon_max+d_lon_i;
      lat_i_min=$lat_min-d_lat_i;
      lat_i_max=$lat_max+d_lat_i;
      print lon_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av;
}" | read lon_e_min lon_e_max lat_e_min lat_e_max lon_i_min lon_i_max
lat_i_min lat_i_max lat_av lon_av
proj='m'$lon_av'/'$lat_av'/16'
echo $lon_e_min $lon_e_max $lat_e_min $lat_e_max $lon_i_min $lon_i_max
$lat_i_min $lat_i_max $lat_av $lon_av
#
img2grd "$ruta_elev"  -V -T1
-R$lon_e_min/$lon_e_max/$lat_e_min/$lat_e_max -S1 -Gelev.grd -I1m -D
img2grd "$ruta_grav" -T1 -V
-R$lon_e_min/$lon_e_max/$lat_e_min/$lat_e_max -S0.1 -GFA.grd -I1m -D
#

Any pointers on this, thanks

Lester

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Awk not ouputting results via echo
  2015-11-23 13:17 Awk not ouputting results via echo Lester Anderson
@ 2015-11-23 14:00 ` Lester Anderson
       [not found]   ` <5653288B.5040004@cs.umass.edu>
  2015-11-23 14:42 ` cyg Simple
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Lester Anderson @ 2015-11-23 14:00 UTC (permalink / raw)
  To: cygwin

The error when run is:

ERROR 4: `///' does not exist in the file system,
and is not recognised as a supported dataset name.

img2grd (GMTAPI_Import_Grid): Not a supported grid format [///]
Error returned from GMT API: GMT_GRID_READ_ERROR (18)
img2grd: Syntax error -R option.  Correct syntax:
        -R<xmin>/<xmax>/<ymin>/<ymax>[/<zmin>/<zmax>]
          Append r if giving lower left and upper right coordinates
        -Rg or -Rd for global domain
        -R<grdfile> to take the domain from a grid file
Error returned from GMT API: GMT_PARSE_ERROR (61)
ERROR 4: `///' does not exist in the file system,
and is not recognised as a supported dataset name.

img2grd (GMTAPI_Import_Grid): Not a supported grid format [///]
Error returned from GMT API: GMT_GRID_READ_ERROR (18)
img2grd: Syntax error -R option.  Correct syntax:
        -R<xmin>/<xmax>/<ymin>/<ymax>[/<zmin>/<zmax>]
          Append r if giving lower left and upper right coordinates
        -Rg or -Rd for global domain
        -R<grdfile> to take the domain from a grid file
Error returned from GMT API: GMT_PARSE_ERROR (61)

Basically the variables lon_e_min, lon_e_max, lat_e_min and lat_e_max
are not transferred as inputs to -R.

I don't get any errors from the awk part.

Lester

On 23 November 2015 at 13:17, Lester Anderson <arctica1963@gmail.com> wrote:
> Hello,
>
> Having sorted how to access a separate drive location, I have expanded
> the script to include an awk section which processes new coordinate
> limits which should pass to img2grd to extract the data grids.
> However, the awk scripting does not seem to generate any data - is
> there something I am missing? Modified from a published script
>
> #!/bin/bash
> ruta_elev="Q:/geophys/Potential-field datasets/Topography/topo_17.1.img"
> ruta_grav="Q:/geophys/Potential-field datasets/Gravity/grav.img.23.1"
> lon_min=-12
> lon_max=0
> lat_min=28
> lat_max=39
> R_d=167
> R_i=20
>
> echo $lon_min $lon_max $lat_min $lat_max $R_d $R_i |
> awk "{R_t=6370;
>       pi=3.14159;
>       lat_av=(($lat_max+$lat_min)/2)*(pi/180.);
>       lon_av=(($lon_min+$lon_max)/2);
>       d_lat_e=($R_d/R_t)*180./pi;
>       d_lon_e=($R_d/(R_t*cos(lat_av)))*180./pi;
>       d_lat_i=($R_i/R_t)*180./pi;
>       d_lon_i=($R_i/(R_t*cos(lat_av)))*180./pi;
>       lon_e_min=$lon_min-d_lon_e;
>       lon_e_max=$lon_max+d_lon_e;
>       lat_e_min=$lat_min-d_lat_e;
>       lat_e_max=$lat_max+d_lat_e;
>       lon_i_min=$lon_min-d_lon_i;
>       lon_i_max=$lon_max+d_lon_i;
>       lat_i_min=$lat_min-d_lat_i;
>       lat_i_max=$lat_max+d_lat_i;
>       print lon_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av;
> }" | read lon_e_min lon_e_max lat_e_min lat_e_max lon_i_min lon_i_max
> lat_i_min lat_i_max lat_av lon_av
> proj='m'$lon_av'/'$lat_av'/16'
> echo $lon_e_min $lon_e_max $lat_e_min $lat_e_max $lon_i_min $lon_i_max
> $lat_i_min $lat_i_max $lat_av $lon_av
> #
> img2grd "$ruta_elev"  -V -T1
> -R$lon_e_min/$lon_e_max/$lat_e_min/$lat_e_max -S1 -Gelev.grd -I1m -D
> img2grd "$ruta_grav" -T1 -V
> -R$lon_e_min/$lon_e_max/$lat_e_min/$lat_e_max -S0.1 -GFA.grd -I1m -D
> #
>
> Any pointers on this, thanks
>
> Lester

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Awk not ouputting results via echo
  2015-11-23 13:17 Awk not ouputting results via echo Lester Anderson
  2015-11-23 14:00 ` Lester Anderson
@ 2015-11-23 14:42 ` cyg Simple
  2015-11-23 15:23 ` Eliot Moss
  2015-11-23 20:41 ` Lee
  3 siblings, 0 replies; 11+ messages in thread
From: cyg Simple @ 2015-11-23 14:42 UTC (permalink / raw)
  To: cygwin

On 11/23/2015 8:17 AM, Lester Anderson wrote:
> 
> #!/bin/bash
> ruta_elev="Q:/geophys/Potential-field datasets/Topography/topo_17.1.img"
> ruta_grav="Q:/geophys/Potential-field datasets/Gravity/grav.img.23.1"

This response is based on your subsequent email but what if you change
Q: to be /cygdrive/q instead?

-- 
cyg Simple

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Awk not ouputting results via echo
       [not found]   ` <5653288B.5040004@cs.umass.edu>
@ 2015-11-23 15:11     ` Lester Anderson
  2015-11-24 18:32       ` cyg Simple
  0 siblings, 1 reply; 11+ messages in thread
From: Lester Anderson @ 2015-11-23 15:11 UTC (permalink / raw)
  To: cygwin

Hello,

The img2grd program is a Windows code. The script is using the GMT
software that is freely available, and accessed via Cygwin; can also
work via standard windows batch files to a more restricted degree.

The Windows path definition worked fine, thanks for that

The issue seems to be getting the variables calculated via awk into
the region definition (R). The awk version under Cygwin is Gawk, and
it appears to run without issue, although I cannot get the values out
to check the calculation. The echo command does not give any output.
Awk has to be used as bash does not work with floating point numbers
as far as I can see.

I am slowly working my way through a published script to get it running.

Lester

On 23 November 2015 at 14:54, Eliot Moss <moss@cs.umass.edu> wrote:
> If img2grd is a Windows program, then you probably want to
> use cygpath to convert to a suitable Windows path name.  I
> think the forward slashes *may* work, but Windows generally
> does backslashes.
>
> If img2grd is a cygwin program, you may have greater success
> doing /cygdrive/q than using Q: ...
>
> In short, Windows style pathnames for Windows programs,
> cygwin style pathnames for cygwin program :-) ...
>
> Regards -- Eliot Moss

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Awk not ouputting results via echo
  2015-11-23 13:17 Awk not ouputting results via echo Lester Anderson
  2015-11-23 14:00 ` Lester Anderson
  2015-11-23 14:42 ` cyg Simple
@ 2015-11-23 15:23 ` Eliot Moss
  2015-11-23 16:24   ` Lester Anderson
  2015-11-23 20:41 ` Lee
  3 siblings, 1 reply; 11+ messages in thread
From: Eliot Moss @ 2015-11-23 15:23 UTC (permalink / raw)
  To: cygwin

Ok, I think I have a sense of an underlying problem here.

When you do:  ... | read v1 v2 ...

The read executes in an inferior process, setting variables there.
The process then exits and you have no bindings in the parent shell,
which is where you want them.

Maybe something like this would suit you better:

myfunction() {
   ... stuff using positional arguments $1, $2, etc.
}

myfunction $(awk blah ...)

This take the output of the invocation of awk and puts it
where $(awk ...) was, which will invoke myfunction with
the line, parsing it into separate arguments (I believe).

You could also capture the line using something like this:

line="$(awk ...)"

and then you can fiddle the result however you want, but I think that
calling a function (or another script) is probably simpler here.

Regards -- Eliot Moss

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Awk not ouputting results via echo
  2015-11-23 15:23 ` Eliot Moss
@ 2015-11-23 16:24   ` Lester Anderson
  2015-11-23 16:44     ` Lester Anderson
  2015-11-23 16:53     ` Eliot Moss
  0 siblings, 2 replies; 11+ messages in thread
From: Lester Anderson @ 2015-11-23 16:24 UTC (permalink / raw)
  To: moss, cygwin

Hi Eliot,

I can see the logic of the function, but not sure how it is
implemented from the section I have:

lon_min=-12
lon_max=0
lat_min=28
lat_max=39
R_d=167
R_i=20

echo $lon_min $lon_max $lat_min $lat_max $R_d $R_i |
awk "{R_t=6370;
      pi=3.14159;
      lat_av=(($lat_max+$lat_min)/2)*(pi/180.);
      lon_av=(($lon_min+$lon_max)/2);
      d_lat_e=($R_d/R_t)*180./pi;
      d_lon_e=($R_d/(R_t*cos(lat_av)))*180./pi;
      d_lat_i=($R_i/R_t)*180./pi;
      d_lon_i=($R_i/(R_t*cos(lat_av)))*180./pi;
      lon_e_min=$lon_min-d_lon_e;
      lon_e_max=$lon_max+d_lon_e;
      lat_e_min=$lat_min-d_lat_e;
      lat_e_max=$lat_max+d_lat_e;
      lon_i_min=$lon_min-d_lon_i;
      lon_i_max=$lon_max+d_lon_i;
      lat_i_min=$lat_min-d_lat_i;
      lat_i_max=$lat_max+d_lat_i;
      print lon_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av;
}" | read lon_e_min lon_e_max lat_e_min lat_e_max lon_i_min lon_i_max
echo $lon_e_min $lon_e_max $lat_e_min $lat_e_max $lon_i_min $lon_i_max
$lat_i_min $lat_i_max $lat_av $lon_av

Do you have an example function that shows the workflow? Sorry not an
awk/cygwin expert!

Thanks
Lester

On 23 November 2015 at 15:23, Eliot Moss <moss@cs.umass.edu> wrote:
> Ok, I think I have a sense of an underlying problem here.
>
> When you do:  ... | read v1 v2 ...
>
> The read executes in an inferior process, setting variables there.
> The process then exits and you have no bindings in the parent shell,
> which is where you want them.
>
> Maybe something like this would suit you better:
>
> myfunction() {
>   ... stuff using positional arguments $1, $2, etc.
> }
>
> myfunction $(awk blah ...)
>
> This take the output of the invocation of awk and puts it
> where $(awk ...) was, which will invoke myfunction with
> the line, parsing it into separate arguments (I believe).
>
> You could also capture the line using something like this:
>
> line="$(awk ...)"
>
> and then you can fiddle the result however you want, but I think that
> calling a function (or another script) is probably simpler here.
>
> Regards -- Eliot Moss
>
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Awk not ouputting results via echo
  2015-11-23 16:24   ` Lester Anderson
@ 2015-11-23 16:44     ` Lester Anderson
  2015-11-23 16:53     ` Eliot Moss
  1 sibling, 0 replies; 11+ messages in thread
From: Lester Anderson @ 2015-11-23 16:44 UTC (permalink / raw)
  To: moss, cygwin

As  a test I did a simple function to read the inputs:

#!/bin/sh
lon_min=-12
lon_max=0
lat_min=28
lat_max=39
R_d=167
R_i=20
function Test() {
    echo Test function: $lon_min $lon_max $lat_min $lat_max $R_d $R_i
    }
#
Test > test.txt
# test.txt -> -12 0 28 39 167 20

Still needs awk to do those fiddly bits!

Lester

On 23 November 2015 at 16:24, Lester Anderson <arctica1963@gmail.com> wrote:
> Hi Eliot,
>
> I can see the logic of the function, but not sure how it is
> implemented from the section I have:
>
> lon_min=-12
> lon_max=0
> lat_min=28
> lat_max=39
> R_d=167
> R_i=20
>
> echo $lon_min $lon_max $lat_min $lat_max $R_d $R_i |
> awk "{R_t=6370;
>       pi=3.14159;
>       lat_av=(($lat_max+$lat_min)/2)*(pi/180.);
>       lon_av=(($lon_min+$lon_max)/2);
>       d_lat_e=($R_d/R_t)*180./pi;
>       d_lon_e=($R_d/(R_t*cos(lat_av)))*180./pi;
>       d_lat_i=($R_i/R_t)*180./pi;
>       d_lon_i=($R_i/(R_t*cos(lat_av)))*180./pi;
>       lon_e_min=$lon_min-d_lon_e;
>       lon_e_max=$lon_max+d_lon_e;
>       lat_e_min=$lat_min-d_lat_e;
>       lat_e_max=$lat_max+d_lat_e;
>       lon_i_min=$lon_min-d_lon_i;
>       lon_i_max=$lon_max+d_lon_i;
>       lat_i_min=$lat_min-d_lat_i;
>       lat_i_max=$lat_max+d_lat_i;
>       print lon_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av;
> }" | read lon_e_min lon_e_max lat_e_min lat_e_max lon_i_min lon_i_max
> echo $lon_e_min $lon_e_max $lat_e_min $lat_e_max $lon_i_min $lon_i_max
> $lat_i_min $lat_i_max $lat_av $lon_av
>
> Do you have an example function that shows the workflow? Sorry not an
> awk/cygwin expert!
>
> Thanks
> Lester
>
> On 23 November 2015 at 15:23, Eliot Moss <moss@cs.umass.edu> wrote:
>> Ok, I think I have a sense of an underlying problem here.
>>
>> When you do:  ... | read v1 v2 ...
>>
>> The read executes in an inferior process, setting variables there.
>> The process then exits and you have no bindings in the parent shell,
>> which is where you want them.
>>
>> Maybe something like this would suit you better:
>>
>> myfunction() {
>>   ... stuff using positional arguments $1, $2, etc.
>> }
>>
>> myfunction $(awk blah ...)
>>
>> This take the output of the invocation of awk and puts it
>> where $(awk ...) was, which will invoke myfunction with
>> the line, parsing it into separate arguments (I believe).
>>
>> You could also capture the line using something like this:
>>
>> line="$(awk ...)"
>>
>> and then you can fiddle the result however you want, but I think that
>> calling a function (or another script) is probably simpler here.
>>
>> Regards -- Eliot Moss
>>
>>
>> --
>> Problem reports:       http://cygwin.com/problems.html
>> FAQ:                   http://cygwin.com/faq/
>> Documentation:         http://cygwin.com/docs.html
>> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Awk not ouputting results via echo
  2015-11-23 16:24   ` Lester Anderson
  2015-11-23 16:44     ` Lester Anderson
@ 2015-11-23 16:53     ` Eliot Moss
  1 sibling, 0 replies; 11+ messages in thread
From: Eliot Moss @ 2015-11-23 16:53 UTC (permalink / raw)
  To: Lester Anderson, cygwin

On 11/23/2015 11:24 AM, Lester Anderson wrote:
> Hi Eliot,
>
> I can see the logic of the function, but not sure how it is
> implemented from the section I have:

This has to do with bash and shells in general, and is not
specific to awk or to the cygwin Unix-like environment.

But what I meant was something like the code below.  When I
run it under bash in cygwin, I get this output:

-13.8013 1.80133 26.4979 40.5021 -12.2157 0.215728

Here's the code.  The use of the first echo is just to send one
line to awk, so it will run its code for that line.  You can drop
the echo and | if you put BEGIN just after the open quote of the
argument to awk, and add exit(0) in the awk code after awk's print
statement.

lon_min=-12
lon_max=0
lat_min=28
lat_max=39
R_d=167
R_i=20

bindvars () {
   lon_e_min=$1
   lon_e_max=$2
   lat_e_min=$3
   lat_e_max=$4
   lon_i_min=$5
   lon_i_max=$6
}

bindvars $(echo | awk "{R_t=6370;
        pi=3.14159;
        lat_av=(($lat_max+$lat_min)/2)*(pi/180.);
        lon_av=(($lon_min+$lon_max)/2);
        d_lat_e=($R_d/R_t)*180./pi;
        d_lon_e=($R_d/(R_t*cos(lat_av)))*180./pi;
        d_lat_i=($R_i/R_t)*180./pi;
        d_lon_i=($R_i/(R_t*cos(lat_av)))*180./pi;
        lon_e_min=$lon_min-d_lon_e;
        lon_e_max=$lon_max+d_lon_e;
        lat_e_min=$lat_min-d_lat_e;
        lat_e_max=$lat_max+d_lat_e;
        lon_i_min=$lon_min-d_lon_i;
        lon_i_max=$lon_max+d_lon_i;
        lat_i_min=$lat_min-d_lat_i;
        lat_i_max=$lat_max+d_lat_i;
        print 
lon_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av;
}")
echo $lon_e_min $lon_e_max $lat_e_min $lat_e_max $lon_i_min $lon_i_max $lat_i_min $lat_i_max $lat_av 
$lon_av

Regards -- Eliot Moss

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Awk not ouputting results via echo
  2015-11-23 13:17 Awk not ouputting results via echo Lester Anderson
                   ` (2 preceding siblings ...)
  2015-11-23 15:23 ` Eliot Moss
@ 2015-11-23 20:41 ` Lee
  2015-11-24 10:54   ` Lester Anderson
  3 siblings, 1 reply; 11+ messages in thread
From: Lee @ 2015-11-23 20:41 UTC (permalink / raw)
  To: cygwin

On 11/23/15, Lester Anderson <arctica1963@gmail.com> wrote:
> Hello,
>
> Having sorted how to access a separate drive location, I have expanded
> the script to include an awk section which processes new coordinate
> limits which should pass to img2grd to extract the data grids.
> However, the awk scripting does not seem to generate any data - is
> there something I am missing? Modified from a published script

As has already been pointed out, the read isn't going to get envars
set the way you want, so call another script with the proper
variables.  And AWK is going to want to read input, so you need to put
everything inside BEGIN{ "your stuff here" ; exit }
And I use -v and single quotes with awk ,so how about something like

awk  -v lon_min="$lon_min" -v lon_max="$lon_max" -v lat_min="$lat_min" \
     -v lat_max="$lat_max" -v R_d="$R_d" -v R_i="$R_i" \
'BEGIN{R_t=6370;
  ... etc ...
      cmd=sprintf("%s %f %f %f %f %f %f %f %f %f %f\n",
                  "echo ", on_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,
                           lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av)
      system(cmd)
  exit
}'


.. you need to write your own secondary script & not use "echo"

Regards,
Lee


>
> #!/bin/bash
> ruta_elev="Q:/geophys/Potential-field datasets/Topography/topo_17.1.img"
> ruta_grav="Q:/geophys/Potential-field datasets/Gravity/grav.img.23.1"
> lon_min=-12
> lon_max=0
> lat_min=28
> lat_max=39
> R_d=167
> R_i=20
>
> echo $lon_min $lon_max $lat_min $lat_max $R_d $R_i |
> awk "{R_t=6370;
>       pi=3.14159;
>       lat_av=(($lat_max+$lat_min)/2)*(pi/180.);
>       lon_av=(($lon_min+$lon_max)/2);
>       d_lat_e=($R_d/R_t)*180./pi;
>       d_lon_e=($R_d/(R_t*cos(lat_av)))*180./pi;
>       d_lat_i=($R_i/R_t)*180./pi;
>       d_lon_i=($R_i/(R_t*cos(lat_av)))*180./pi;
>       lon_e_min=$lon_min-d_lon_e;
>       lon_e_max=$lon_max+d_lon_e;
>       lat_e_min=$lat_min-d_lat_e;
>       lat_e_max=$lat_max+d_lat_e;
>       lon_i_min=$lon_min-d_lon_i;
>       lon_i_max=$lon_max+d_lon_i;
>       lat_i_min=$lat_min-d_lat_i;
>       lat_i_max=$lat_max+d_lat_i;
>       print
> lon_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av;
> }" | read lon_e_min lon_e_max lat_e_min lat_e_max lon_i_min lon_i_max
> lat_i_min lat_i_max lat_av lon_av
> proj='m'$lon_av'/'$lat_av'/16'
> echo $lon_e_min $lon_e_max $lat_e_min $lat_e_max $lon_i_min $lon_i_max
> $lat_i_min $lat_i_max $lat_av $lon_av
> #
> img2grd "$ruta_elev"  -V -T1
> -R$lon_e_min/$lon_e_max/$lat_e_min/$lat_e_max -S1 -Gelev.grd -I1m -D
> img2grd "$ruta_grav" -T1 -V
> -R$lon_e_min/$lon_e_max/$lat_e_min/$lat_e_max -S0.1 -GFA.grd -I1m -D
> #
>
> Any pointers on this, thanks
>
> Lester

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Awk not ouputting results via echo
  2015-11-23 20:41 ` Lee
@ 2015-11-24 10:54   ` Lester Anderson
  0 siblings, 0 replies; 11+ messages in thread
From: Lester Anderson @ 2015-11-24 10:54 UTC (permalink / raw)
  To: cygwin

Thanks for all the pointers on this query. I applied the method of
Eliot and managed to get the output and grids generated with the
spatial adjustment:

#!/bin/bash
ruta_elev="Q:\geophys\Potential-field datasets\Topography\topo_17.1.img"
ruta_grav="Q:\geophys\Potential-field datasets\Gravity\grav.img.23.1"
lon_min=-12
lon_max=0
lat_min=28
lat_max=39
R_d=167
R_i=20

echo $ruta_elev
echo $ruta_grav

bindvars () {
  lon_e_min=$1
  lon_e_max=$2
  lat_e_min=$3
  lat_e_max=$4
  lon_i_min=$5
  lon_i_max=$6
  lat_i_min=$7
  lat_i_max=$8
  lat_av=$9
  lon_av=$10
}
bindvars $(echo | awk "{R_t=6370;
      pi=3.14159;
      lat_av=(($lat_max+$lat_min)/2)*(pi/180.);
      lon_av=(($lon_min+$lon_max)/2);
      d_lat_e=($R_d/R_t)*180./pi;
      d_lon_e=($R_d/(R_t*cos(lat_av)))*180./pi;
      d_lat_i=($R_i/R_t)*180./pi;
      d_lon_i=($R_i/(R_t*cos(lat_av)))*180./pi;
      lon_e_min=$lon_min-d_lon_e;
      lon_e_max=$lon_max+d_lon_e;
      lat_e_min=$lat_min-d_lat_e;
      lat_e_max=$lat_max+d_lat_e;
      lon_i_min=$lon_min-d_lon_i;
      lon_i_max=$lon_max+d_lon_i;
      lat_i_min=$lat_min-d_lat_i;
      lat_i_max=$lat_max+d_lat_i;
      print lon_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av;
}")
echo $lon_e_min $lon_e_max $lat_e_min $lat_e_max $lon_i_min $lon_i_max
$lat_i_min $lat_i_max $lat_av $lon_av
img2grd "$ruta_elev"  -V -T1
-R$lon_e_min/$lon_e_max/$lat_e_min/$lat_e_max -S1 -GTopo_adj.grd -I1m
-D
img2grd "$ruta_grav" -T1 -V
-R$lon_e_min/$lon_e_max/$lat_e_min/$lat_e_max -S0.1 -GFAA_adj.grd -I1m
-D

So it automatically got the adjusted long/lat values (lon_e_min,
lon_e_max etc) to pass to img2grd.

I will also experiment with the alternate route proposed by Lee, these
are all useful for someone who is just getting started with this
scripting and Cygwin.

Lester

On 23 November 2015 at 20:39, Lee <ler762@gmail.com> wrote:
> On 11/23/15, Lester Anderson <arctica1963@gmail.com> wrote:
>> Hello,
>>
>> Having sorted how to access a separate drive location, I have expanded
>> the script to include an awk section which processes new coordinate
>> limits which should pass to img2grd to extract the data grids.
>> However, the awk scripting does not seem to generate any data - is
>> there something I am missing? Modified from a published script
>
> As has already been pointed out, the read isn't going to get envars
> set the way you want, so call another script with the proper
> variables.  And AWK is going to want to read input, so you need to put
> everything inside BEGIN{ "your stuff here" ; exit }
> And I use -v and single quotes with awk ,so how about something like
>
> awk  -v lon_min="$lon_min" -v lon_max="$lon_max" -v lat_min="$lat_min" \
>      -v lat_max="$lat_max" -v R_d="$R_d" -v R_i="$R_i" \
> 'BEGIN{R_t=6370;
>   ... etc ...
>       cmd=sprintf("%s %f %f %f %f %f %f %f %f %f %f\n",
>                   "echo ", on_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,
>                            lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av)
>       system(cmd)
>   exit
> }'
>
>
> .. you need to write your own secondary script & not use "echo"
>
> Regards,
> Lee
>
>
>>
>> #!/bin/bash
>> ruta_elev="Q:/geophys/Potential-field datasets/Topography/topo_17.1.img"
>> ruta_grav="Q:/geophys/Potential-field datasets/Gravity/grav.img.23.1"
>> lon_min=-12
>> lon_max=0
>> lat_min=28
>> lat_max=39
>> R_d=167
>> R_i=20
>>
>> echo $lon_min $lon_max $lat_min $lat_max $R_d $R_i |
>> awk "{R_t=6370;
>>       pi=3.14159;
>>       lat_av=(($lat_max+$lat_min)/2)*(pi/180.);
>>       lon_av=(($lon_min+$lon_max)/2);
>>       d_lat_e=($R_d/R_t)*180./pi;
>>       d_lon_e=($R_d/(R_t*cos(lat_av)))*180./pi;
>>       d_lat_i=($R_i/R_t)*180./pi;
>>       d_lon_i=($R_i/(R_t*cos(lat_av)))*180./pi;
>>       lon_e_min=$lon_min-d_lon_e;
>>       lon_e_max=$lon_max+d_lon_e;
>>       lat_e_min=$lat_min-d_lat_e;
>>       lat_e_max=$lat_max+d_lat_e;
>>       lon_i_min=$lon_min-d_lon_i;
>>       lon_i_max=$lon_max+d_lon_i;
>>       lat_i_min=$lat_min-d_lat_i;
>>       lat_i_max=$lat_max+d_lat_i;
>>       print
>> lon_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av;
>> }" | read lon_e_min lon_e_max lat_e_min lat_e_max lon_i_min lon_i_max
>> lat_i_min lat_i_max lat_av lon_av
>> proj='m'$lon_av'/'$lat_av'/16'
>> echo $lon_e_min $lon_e_max $lat_e_min $lat_e_max $lon_i_min $lon_i_max
>> $lat_i_min $lat_i_max $lat_av $lon_av
>> #
>> img2grd "$ruta_elev"  -V -T1
>> -R$lon_e_min/$lon_e_max/$lat_e_min/$lat_e_max -S1 -Gelev.grd -I1m -D
>> img2grd "$ruta_grav" -T1 -V
>> -R$lon_e_min/$lon_e_max/$lat_e_min/$lat_e_max -S0.1 -GFA.grd -I1m -D
>> #
>>
>> Any pointers on this, thanks
>>
>> Lester
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Awk not ouputting results via echo
  2015-11-23 15:11     ` Lester Anderson
@ 2015-11-24 18:32       ` cyg Simple
  0 siblings, 0 replies; 11+ messages in thread
From: cyg Simple @ 2015-11-24 18:32 UTC (permalink / raw)
  To: cygwin

On 11/23/2015 10:11 AM, Lester Anderson wrote:
> Hello,
> 
> The img2grd program is a Windows code. The script is using the GMT

Which is the cause of any PTY issue.

> software that is freely available, and accessed via Cygwin; can also
> work via standard windows batch files to a more restricted degree.
> 
> The Windows path definition worked fine, thanks for that
> 
> The issue seems to be getting the variables calculated via awk into
> the region definition (R). The awk version under Cygwin is Gawk, and
> it appears to run without issue, although I cannot get the values out
> to check the calculation. The echo command does not give any output.
> Awk has to be used as bash does not work with floating point numbers
> as far as I can see.
> 

When in a shell that has an embedded echo such as bash you're actually
using the shell internals.  What if you use /bin/echo instead?  Or even
/bin/cat.  This may or may not alleviate any PTY issue.

> I am slowly working my way through a published script to get it running.
> 

Please stop top posting.  It is most annoying.

-- 
cyg Simple

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-11-24 18:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-23 13:17 Awk not ouputting results via echo Lester Anderson
2015-11-23 14:00 ` Lester Anderson
     [not found]   ` <5653288B.5040004@cs.umass.edu>
2015-11-23 15:11     ` Lester Anderson
2015-11-24 18:32       ` cyg Simple
2015-11-23 14:42 ` cyg Simple
2015-11-23 15:23 ` Eliot Moss
2015-11-23 16:24   ` Lester Anderson
2015-11-23 16:44     ` Lester Anderson
2015-11-23 16:53     ` Eliot Moss
2015-11-23 20:41 ` Lee
2015-11-24 10:54   ` Lester Anderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).