[gradsusr] Maxloc Function

Mark Sponsler msponsler at comcast.net
Wed Apr 29 20:17:23 EDT 2015


Thanks Tom,
Very helpful. I like the new function better than the old.

I also figured out how to get the old maxloc to work. Like you said, I had to figure out how many lines of output to scan to get the result. I wasn't scanning deep enough into the pile. 

Appreciate your help!

On April 29, 2015 4:33:41 PM PDT, Thomas Robinson <ter at hawaii.edu> wrote:
>Aloha Mark,
>
>I've had much better luck using amaxlocx and amaxlocy over maxloc.
>http://www.iges.org/grads/gadoc/gradfuncamaxlocx.html
>
>It's two lines of code instead of one, but then you don't have to deal
>with
>the nightmare of output from the maxloc function.  When you use maxloc,
>it
>produces a lot of output, so your script is just grabbing the wrong
>line.
> amaxlocx and amaxlocy produce only 1 line of output.
>
>That's what I used as a work around for this same problem.  Here is the
>code to replace what you are doing.  I hope it works for you.
>
>**Find the x-coordinate of the maximum htsgw (xc)
>'d amaxlocx(htsgw,lon='lon1',lon='lon2',lat='lat1',lat='lat2')'
>xc=subwrd(result,4)
>**Find the y-coordinate of the maximum htsgw (yc)
>'d amaxlocy(htsgw,lon='lon1',lon='lon2',lat='lat1',lat='lat2')'
>yc=subwrd(result,4)
>
>-Tom
>
>
>
>On Sun, Apr 26, 2015 at 8:39 AM, Mark Sponsler <msponsler at comcast.net>
>wrote:
>
>> Hello everyone,
>> I'm struggling with maxloc. For whatever reason - I cannot get valid
>> results out of it
>>  I'm using a simple 0.5 X 0.5 deg grid.
>>  I can find the max value just fine.  It's the location of that value
>> that is the issue.
>> Specifically selecting the correct record to read to obtain the x
>value
>> (nxp3 in this example):
>>  'd maxloc(max(htsgw,lat='lat1',lat='lat2'),lon='lon1',lon='lon2')'
>>    rec=sublin(result,nxp3)
>>  The last valid line of data from maxloc looks like this (the next
>line
>> is undefined values):
>>         rec = MAXing.  dim = 1, start = 146, end = 286
>>
>> Where is the actual grib point or longitude where the max value is
>located?
>> The results I'm getting are the same for every time step in the grib
>> file....  dim = 1
>>  Or should I be looking somewhere else?
>>  Thanks for your help.
>>  Here's the whole script:
>>  ********************************
>> * Define number of grid points to scan
>> ********************************
>> lon1 = 120
>> lon2 = 255
>> lat1 = -5
>> lat2 = 65
>>  nxp = (lon2-lon1)
>> *       say '  nxp = 'nxp
>> nyp = (lat2-lat1)
>> *      say '  nyp = 'nyp
>> *  Grid dimensions are 0.5 x 0.5
>> nxp1 = nxp/0.5
>> *    say 'nxp1 = 'nxp1
>> nyp1 = nyp/0.5
>> *    say 'nyp1 = 'nyp1
>> nxp2 = math_int(nxp1)
>> nyp2 = math_int(nyp1)
>> *   say 'nxp2 nyp2 = 'nxp2' 'nyp2
>>
>> ********************************
>> * Find Max Longitude (x dim)
>> ********************************
>> * There are 'nxp1' number of data points over the longitude range
>plus 1
>> for MAXLOCing
>> * and 1 for the result value line. So add 2.
>> ********************************
>>  nxp3 = (nxp2 + 2)
>>      say 'nxp3 = 'nxp3
>>
>> 'set gxout print'
>> 'd maxloc(max(htsgw,lat='lat1',lat='lat2'),lon='lon1',lon='lon2')'
>>    rec=sublin(result,nxp3)
>>        say 'rec = 'rec
>>    xc=subwrd(rec,4)
>>         say 'Max height lon = 'xc
>>
>> ********************************
>> * Find max Latitude (y dim)
>> ********************************
>> * There are 'nyp1' number of data points over the long range plus 1
>for
>> MAXLOCing
>> * and 1 for the result value line. So add 2.
>> ********************************
>>  nyp3 = (nyp2 + 2)
>>      say 'nyp3 = 'nyp3
>> 'd maxloc(max(htsgw,lon='lon1',lon='lon2'),lat='lat1',lat='lat2')'
>>    rec=sublin(result,nyp3)
>>       say 'rec = 'rec
>>    yc=subwrd(rec,4)
>>      say 'Max height lat = 'yc
>>
>>        say 'location of max seas = 'xc' 'yc
>>
>> **************
>> *  Draw Max Location
>> **************
>> 'q gr2xy 'xc' 'yc
>>     rec2=sublin(result,1)
>>       say 'rec2 = 'rec2
>>     xc2 = subwrd(result,3)
>>     yc2 = subwrd(result,6)
>>       say 'Max Height coords = 'xc2' 'yc2
>>  Thanks,
>> Mark
>>
>> _______________________________________________
>> gradsusr mailing list
>> gradsusr at gradsusr.org
>> http://gradsusr.org/mailman/listinfo/gradsusr
>>
>>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>gradsusr mailing list
>gradsusr at gradsusr.org
>http://gradsusr.org/mailman/listinfo/gradsusr

Thanks,
Mark Sponsler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20150429/cb337fb0/attachment-0001.html 


More information about the gradsusr mailing list