comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: SPAWN with AWK
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: SPAWN with AWK [message #83550] Mon, 11 March 2013 01:36
hannah_ue is currently offline  hannah_ue
Messages: 14
Registered: November 2012
Junior Member
Thanks Mat and Chip for your responses!
Mats suggestions is working exactly as I want it to.

Cheers, Hannah
Re: SPAWN with AWK [message #83561 is a reply to message #83550] Sat, 09 March 2013 07:54 Go to previous message
Chip Helms is currently offline  Chip Helms
Messages: 24
Registered: November 2012
Junior Member
I think IDL is interpreting the "" as a single " (since " ends the string in this case "" is used to place a single double-quote...if you started your string with a ' instead, you'd have to use '' to have IDL print a single ' ). If you change it to (min="""") I think it should work. Also, as to reading data with spawn and awk, my experience has been that it is considerably less efficient than IDL's built-in routines, but the difference is not usually noticeable unless you are calling spawn/awk a large number of time (such as in a for loop).

Cheers,
Chip

On Saturday, March 9, 2013 9:38:58 AM UTC, Hannah wrote:
> Hi there,
>
>
>
>
>
> I have to read in a lot of data files in my IDL script and thought about using SPAWN with AWK for this. So far, I did it with READCOL and WHERE functions but I find it kind of convenient to do it with just one line in AWK (but I have no idea of the efficiencies, if someone could say anything to this..).
>
>
>
> No I have some problems with my command, as there are to many ". The line looks like this:
>
>
>
> spawn, "awk '{if (min=="") {min=max=$17}; if ($17>max) {(max=$17) && (maxid=$1)}; if (($17<min) && ($17!=0.)) {(min=$17) && (minid=$1)}} END {print min, minid, max, maxid}' dat file" val_vec
>
>
>
> Not surprisingly, I get an "unterminated string" error bec of the "s at (min==""). So my question is, if anyone has an idea to fix this either in the awk command or anyhow in IDL.
>
>
>
>
>
> Thanks for your help!
>
> Hannah
Re: SPAWN with AWK [message #83562 is a reply to message #83561] Sat, 09 March 2013 02:28 Go to previous message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den lördagen den 9:e mars 2013 kl. 10:38:58 UTC+1 skrev Hannah:
> Hi there,
>
> I have to read in a lot of data files in my IDL script and thought about using SPAWN with AWK for this. So far, I did it with READCOL and WHERE functions but I find it kind of convenient to do it with just one line in AWK (but I have no idea of the efficiencies, if someone could say anything to this..).
>
> No I have some problems with my command, as there are to many ". The line looks like this:
>
> spawn, "awk '{if (min=="") {min=max=$17}; if ($17>max) {(max=$17) && (maxid=$1)}; if (($17<min) && ($17!=0.)) {(min=$17) && (minid=$1)}} END {print min, minid, max, maxid}' dat file" val_vec
>
> Not surprisingly, I get an "unterminated string" error bec of the "s at (min==""). So my question is, if anyone has an idea to fix this either in the awk command or anyhow in IDL.

You could try building the string by concatenating substrings using, like this:

IDL> print,"awk '" + '{if (min==""){min=max=$17}; if ($17>max) {(max=$17) && (maxid=$1)}; if (($17<min) && ($17!=0.)) {(min=$17) && (minid=$1)}} END {print min, minid, max,maxid}' + "'" + ' dat file" val_vec'
awk '{if (min==""){min=max=$17}; if ($17>max) {(max=$17) && (maxid=$1)}; if (($17<min) && ($17!=0.)) {(min=$17) && (minid=$1)}} END {print min, minid, max,maxid}' dat file" val_vec
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: SPAWN with AWK
Next Topic: problems accessing Ken Bowman's IDL page?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Nov 29 02:03:46 PST 2020

Total time taken to generate the page: 0.00788 seconds