delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/11/24/04:35:21

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:in-reply-to:references:date
:message-id:subject:from:to:content-type; q=dns; s=default; b=uj
l7yrb6IwlFpcgETXy415vGVNS8/uxG4YLOzUoQM9Cjkxt/qR73N5j/lpaeX+sdcu
HO1+nFEvW+TPqBa0M6EbX1a3VPAcVqePERYpRxCMQibRM4I889r4ehVRyXrjuOC4
Wf8ofHdS90g6iOMsmZQBRx44wdFTLQv/fCI6ni8gQ=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:in-reply-to:references:date
:message-id:subject:from:to:content-type; s=default; bh=uG6OQs+f
R8PJ2h/seJoOn2qdF9g=; b=AouVkTcvhNP2Z0QexrrH6OA/Gq88Ki0hC92RaSgu
Z9YJKSCDijpcBsgEFRdXn515+ge7ULaVznFAlgSwaXO2FIfoxKCu0UWzRrDqN1zv
sQ45nw8iazxsf3jcGv4ua6tyQda0HqfQZOMtQEsk4LvcNNsW9yecDMyeaL8icjjn
Ar0=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=1.4 required=5.0 tests=AWL,BAYES_50,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2
X-HELO: mail-lf0-f48.google.com
MIME-Version: 1.0
X-Received: by 10.112.150.225 with SMTP id ul1mr12791349lbb.47.1448357699120; Tue, 24 Nov 2015 01:34:59 -0800 (PST)
In-Reply-To: <CAD8GWsvXCC0GB8mxozLrT4aWpfoRhe7mEu9whSi2o6kp59q61w@mail.gmail.com>
References: <CAE3taFC=tjki1FTfbjyt+KnEGsWmrj63FMeBjgRswRwRSKdAWQ AT mail DOT gmail DOT com> <CAD8GWsvXCC0GB8mxozLrT4aWpfoRhe7mEu9whSi2o6kp59q61w AT mail DOT gmail DOT com>
Date: Tue, 24 Nov 2015 09:34:59 +0000
Message-ID: <CAE3taFAQQPx23C59e0+6qPGiJqcPLqWqa7GPd-UkGp6Kok-kLA@mail.gmail.com>
Subject: Re: Awk not ouputting results via echo
From: Lester Anderson <arctica1963 AT gmail DOT com>
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes

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 AT gmail DOT com> wrote:
> On 11/23/15, Lester Anderson <arctica1963 AT gmail DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019