awk issue (return an array from user defined function)

I have this function (converting coordinate of an WGS84 geoid to cartesian coordinates...doesn't matter):

  function convert_geo_to_enu(coord_geo) { \
    xi=sqrt(1 - e*e*sin(coord_geo[1])*sin(coord_geo[2])); \
        \
        coord_enu[1]=(a/xi + coord_geo[3])*cos(coord_geo[1])*cos(coord_geo[2]); \
        print coord_enu[1] " hhh " ; \
        coord_enu[2]=(a/xi + coord_geo[3])*cos(coord_geo[1])*sin(coord_geo[2]); \
        coord_enu[3]=(a*(1-e*e)/xi0 + coord_geo[3])*sin(coord_geo[1]); \
    \
    return coord_enu \   # <-- here comes the problem
  } \


problem --> mawk: line 64: illegal reference to array coord_enu

What is the problem to return as an array? Is there any different syntax?

I could use:

  function convert_geo_to_enu(coord_geo, coord_enu) { \
       ...
       coord_enu[1]=...
       ...
  } \

or even:

  function convert_geo_to_enu(coord_geo) { \
       ...
       coord_enu[1]=...
       ...
  } \

and then just use the variable coord_enu as a global?

But it looks better with usage of return statement (esp. for me)

Answers


A little late, but here's a solution I used:

I sent a variable I wanted filled as a parameter to the function:

function myfunct(result, array_size) {
    for(i = 1; i <= array_size; i++) {
        result[i] = ##whatever you want
    }
}

then, you can treat the result variable as an array outside of the function

hope this helps someone looking for an answer


Need Your Help

Oracle SQL Injection, select user from dual is not working

sql oracle sql-injection

I am learning about SQL injection. There is a regular statement that reads:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.