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 <arctica1...@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 <m...@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