public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Lee <ler762@gmail.com>
To: cygwin@cygwin.com
Subject: Re: Awk not ouputting results via echo
Date: Mon, 23 Nov 2015 20:41:00 -0000	[thread overview]
Message-ID: <CAD8GWsvXCC0GB8mxozLrT4aWpfoRhe7mEu9whSi2o6kp59q61w@mail.gmail.com> (raw)
In-Reply-To: <CAE3taFC=tjki1FTfbjyt+KnEGsWmrj63FMeBjgRswRwRSKdAWQ@mail.gmail.com>

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

  parent reply	other threads:[~2015-11-23 20:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-23 13:17 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 [this message]
2015-11-24 10:54   ` Lester Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAD8GWsvXCC0GB8mxozLrT4aWpfoRhe7mEu9whSi2o6kp59q61w@mail.gmail.com \
    --to=ler762@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).