dataplot.pro 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517
  1. ;+----------------------------------------------------------------------------------------
  2. ; dataplot.pro
  3. ; IDL widget based plotting routine for plotting observation and background values
  4. ;
  5. ; Author: D. J. Lea - Feb 2008
  6. ;
  7. ;+----------------------------------------------------------------------------------------
  8. ;example calls:
  9. ;
  10. ;dataplot,filenamearray
  11. ;dataplot,filenamearray,/batch,/gif ; plots data directly to a gif
  12. ;dataplot,filenamearray,/batch,/ps ; plots data directly to a ps
  13. ;dataplot,filenamearray,/batch,area=area ; area 4 element array or descriptive string
  14. ;dataplot, longitude, latitude, deparr, dayarr, valarr, bkgarr
  15. ;dataplot, [longitude, latitude, deparr, dayarr, valarr, bkgarr], rmdi=rmdi, filename=filename
  16. ;
  17. ;optional keywords
  18. ;area descriptive string or array [minlon,minlat,maxlon,maxlat]
  19. ;typeplot=1-5 plot obs-bkg or obs bkg etc
  20. ;alldays=1 plot all days otherwise just plot first day
  21. ;depths [depmin,depmax] in metres
  22. ;showmdt plot mdt
  23. ;obstypeselect string array of selected obs types to plot
  24. ;printobstypes keyword to print unique obs types to the terminal
  25. ;
  26. ;+-----------------------------------------------------------------------------------------
  27. ; Note the upper two slider bars control the depth range
  28. ; the lower two slider bars control the day range
  29. ;------------------------------------------------------------------------------------------
  30. ; Event-handling procedure.
  31. PRO dataplot_event, ev
  32. ; Retrieve the anonymous structure contained in the user value of
  33. ; the top-level base widget.
  34. WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash
  35. WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
  36. ; print,uval
  37. ; print,'event'
  38. ; print,stash.depmin
  39. ; position = [!X.Window[0], !Y.Window[0], !X.Window[1], !Y.Window[1]]
  40. ; print,position
  41. ; xsize = (position(2) - position(0)) * !D.X_VSIZE
  42. ; ysize = (position(3) - position(1)) * !D.Y_VSIZE
  43. ; xstart = position(0) * !D.X_VSIZE
  44. ; ystart = position(1) * !D.Y_VSIZE
  45. ; print,xsize,ysize,xstart,ystart
  46. ; If the event is generated in the draw widget, update the
  47. ; label values with the current cursor position and the value
  48. ; of the data point under the cursor. Note that since we have
  49. ; passed a pointer to the image array rather than the array
  50. ; itself, we must dereference the pointer in the 'image' field
  51. ; of the stash structure before getting the subscripted value.
  52. IF (TAG_NAMES(ev, /STRUCTURE_NAME) eq 'WIDGET_DRAW') THEN BEGIN
  53. xdev= ev.X
  54. ydev= ev.Y
  55. ; print, 'xdev ',xdev, ' ydev ',ydev
  56. ; convert the pointer position to a data position
  57. arr=CONVERT_COORD( xdev, ydev, /device, /to_data)
  58. xdata=arr(0)
  59. ydata=arr(1)
  60. ; print, xdata , ydata
  61. ; print, 'xdev: ',xdev,' ydev: ',ydev,' xdata: ',xdata, ' ydata: ',ydata
  62. ; WIDGET_CONTROL, stash.label1, $
  63. ; SET_VALUE='X position: ' + STRING(xdata)
  64. ; WIDGET_CONTROL, stash.label2, $
  65. ; SET_VALUE='Y position: ' + STRING(ydata)
  66. ;; WIDGET_CONTROL, stash.label3, $
  67. ;; SET_VALUE='Value: ' + $
  68. ;; STRING((*stash.imagePtr)[ev.X, ev.Y], FORMAT='(Z12)')
  69. ; WIDGET_CONTROL, stash.label3, $
  70. ; What kind of event is this?
  71. ;eventTypes = ['DOWN', 'UP', 'MOTION']
  72. ;0 1 2
  73. ;thisEvent = ev.type
  74. ;print, 'ev.type ',ev.type
  75. CASE ev.type OF
  76. 0: BEGIN
  77. ; dragbox start
  78. print, 'down ',xdev,ydev, xdata, ydata
  79. ; Turn motion events on for the draw widget.
  80. Widget_Control, stash.draw, Draw_Motion_Events=1
  81. ; dragbox
  82. ; Create a pixmap. Store its ID. Copy window contents into it.
  83. Window, /Free, /Pixmap, XSize=stash.im_size(1), YSize=stash.im_size(2)
  84. stash.pixID = !D.Window
  85. Device, Copy=[0, 0, stash.im_size(1), stash.im_size(2), 0, 0, stash.drawID]
  86. ; WSet, stash.drawID
  87. print,stash.im_size(0), stash.im_size(1), stash.im_size(2), stash.pixID, stash.drawID
  88. stash.xcorn=xdev
  89. stash.ycorn=ydev
  90. stash.xdatacorn=xdata
  91. stash.ydatacorn=ydata
  92. ; RETURN
  93. ENDCASE
  94. 1: BEGIN
  95. ; dragbox close
  96. print, 'up ',xdev,ydev, xdata, ydata
  97. ; Turn draw motion events off. Clear any events queued for widget.
  98. Widget_Control, stash.draw, Draw_Motion_Events=0, Clear_Events=1
  99. WSet, stash.drawID
  100. Device, Copy=[0, 0, stash.im_size(1), stash.im_size(2), 0, 0, stash.pixID]
  101. WDelete, stash.pixID
  102. ; zoom in
  103. ; dragbox
  104. ; avoid zooming if no dragging has occurred
  105. pixdiffx = min([abs(stash.xcorn-xdev),abs(stash.ycorn-ydev)])
  106. print, '** Pixdiffx ',pixdiffx, stash.xcorn-xdev, stash.ycorn-ydev
  107. if (pixdiffx gt 1 and finite(xdata) and finite(ydata)) then begin
  108. minxdata = min([stash.xdatacorn, xdata], max=maxxdata)
  109. minydata = min([stash.ydatacorn, ydata], max=maxydata)
  110. if (minxdata ge -180 and maxxdata le 360 and minydata ge -90 and maxydata le 90) then begin
  111. stash.xrange=[minxdata,maxxdata]
  112. stash.yrange=[minydata,maxydata]
  113. plotpoints,stash
  114. endif
  115. endif
  116. ; RETURN
  117. ENDCASE
  118. 2: BEGIN
  119. ; drag box motion
  120. ; print, 'motion: ',ev.x, ev.y
  121. WSet, stash.drawID
  122. Device, Copy=[0, 0, stash.im_size(1), stash.im_size(2), 0, 0, stash.pixID]
  123. sx = stash.xcorn
  124. sy = stash.ycorn
  125. PlotS, [sx, sx, xdev, xdev, sx], [sy, ydev, ydev, sy, sy], /Device, $
  126. Color=!p.color
  127. ; Color=255
  128. ENDCASE
  129. ; RETURN
  130. 7: begin
  131. print,'mouse wheel event ',ev.clicks
  132. if (ev.clicks eq 1 or ev.clicks eq -1) then begin
  133. print,'zoom in/out'
  134. print,'stash.depmin ',stash.depmin
  135. print,'xdata ',xdata
  136. if (finite(xdata) and finite(ydata)) then begin
  137. ; make an adjustment if we're in the Pacific
  138. xrange=stash.xrange
  139. typeproj=stash.typeproj
  140. if (xrange(1) gt 180 and typeproj eq 1) then if (xdata lt 0) then xdata=xdata+360
  141. oxrange=stash.xrange
  142. oyrange=stash.yrange
  143. dataplot_zoom, stash, xdata, ydata, ev.clicks
  144. ; plot only if a change has been made
  145. if (stash.xrange(0) ne oxrange(0) or stash.yrange(0) ne oyrange(0) $
  146. or stash.xrange(1) ne oxrange(1) or stash.yrange(1) ne oyrange(1)) then $
  147. plotpoints, stash
  148. endif
  149. endif
  150. ENDCASE
  151. ENDCASE
  152. ; SET_VALUE='Value: ' + STRING(ev.release)
  153. ; if(ev.release eq 1) then begin
  154. ; print,'left click - search for nearest point'
  155. if(ev.release eq 1 or ev.release eq 4) then begin ; mouse click
  156. ; might want a generalised point selection routine
  157. ; for this routine and for plotpoints
  158. print,'xdata ',xdata, ' ydata ',ydata
  159. print,'xdev ',xdev, 'ydev ',ydev
  160. if (finite(xdata) and finite(ydata)) then begin
  161. print, 'finite'
  162. xarr1=stash.xarr
  163. yarr1=stash.yarr
  164. dep1=stash.dep
  165. dayarr=stash.dayarr
  166. daymin=stash.daymin
  167. daymax=stash.daymax
  168. obstypes1=stash.obstypes
  169. xrange=stash.xrange
  170. yrange=stash.yrange
  171. xs=xrange(1)-xrange(0)
  172. ys=yrange(1)-yrange(0)
  173. rmdi=stash.rmdi
  174. ; if (stash.salinity eq 0) then begin
  175. ; obs1=stash.obs
  176. ; bkg1=stash.bkg
  177. ; qcarr1=stash.qcarr
  178. ; endif else begin
  179. ; obs1=stash.obs2
  180. ; bkg1=stash.bkg2
  181. ; qcarr1=stash.qcarr2
  182. ; endelse
  183. typeproj=stash.typeproj
  184. ; make an adjustment if we're in the Pacific
  185. if (xrange(1) gt 180 and typeproj eq 1) then if (xdata lt 0) then xdata=xdata+360
  186. ; set reasonable dist criteria
  187. distmax=(xs/100.)^2+(ys/100.)^2
  188. ; print,'distmax ',distmax
  189. selpoints,stash,lonsel, latsel, innovsel, qcsel, daysel, obstypsel, obnumsel, numsel, typestr
  190. ; get max min daysel
  191. mindaysel=min(daysel, max=maxdaysel)
  192. ; print, 'selpoints ',obnumsel
  193. if (n_elements(lonsel) gt 0) then begin
  194. dist=((lonsel-xdata)^2+(latsel-ydata)^2)
  195. res=min(dist,whd) ; whd is the minumum dist point index
  196. ; print,lonsel
  197. xselstr=""
  198. yselstr=""
  199. valselstr=""
  200. qcselstr=""
  201. datestr=""
  202. obnumselstr=""
  203. mindatestr=""
  204. maxdatestr=""
  205. ; print,'whd(0) ',whd(0)
  206. ; print,'res ',res, ' distmax ',distmax
  207. obstypstr=""
  208. if (whd(0) gt -1 and res lt distmax) then begin
  209. xsel=lonsel(whd)
  210. ysel=latsel(whd)
  211. print,'xsel ',xsel,' ysel ',ysel
  212. ; make an adjustment if we're in the Pacific
  213. if (xrange(1) gt 180 and typeproj eq 1) then if (xsel gt 180) then xsel=xsel-360
  214. valsel=innovsel(whd)
  215. qcsel=qcsel(whd)
  216. datesel=daysel(whd)
  217. obstypsel=obstypsel(whd)
  218. obnumsel=obnumsel(whd)
  219. xselstr=string(xsel)
  220. yselstr=string(ysel)
  221. valselstr=string(valsel)
  222. qcselstr=string(qcsel)
  223. ; datestr=string(datesel)
  224. obstypstr=string(obstypsel(0))
  225. obnumselstr=string(obnumsel(0))
  226. print,'datesel(0) ',datesel(0)
  227. print,'obnumsel(0) ',obnumsel(0)
  228. jul_to_dtstr,datesel(0),datestr
  229. jul_to_dtstr,mindaysel,mindatestr
  230. jul_to_dtstr,maxdaysel,maxdatestr
  231. if (ev.release eq 4) then begin
  232. print,'ev.release ',ev.release
  233. ; window
  234. wh=where(xarr1 eq xsel and yarr1 eq ysel)
  235. print,'xsel ',xsel
  236. ; print,'xarr1 ',xarr1
  237. dep2=dep1(wh)
  238. if (wh(0) gt -1) then begin
  239. if (stash.density eq 0) then begin
  240. if (stash.salinity eq 0) then begin
  241. ; print,'salinity eq 0'
  242. obs2=stash.obs(wh)
  243. bkg2=stash.bkg(wh)
  244. qcarr2=stash.qcarr(wh)
  245. endif else begin
  246. ; print,'salinity eq 1'
  247. obs2=stash.obs2(wh)
  248. bkg2=stash.bkg2(wh)
  249. qcarr2=stash.qcarr2(wh)
  250. endelse
  251. endif else begin
  252. if (stash.filetype eq 'CRT') then begin
  253. bkgU=stash.bkg(wh)
  254. bkgV=stash.bkg2(wh)
  255. bkg2=sqrt(bkgU*bkgU + bkgV*bkgV)
  256. obsU=stash.obs(wh)
  257. obsV=stash.obs2(wh)
  258. obs2=sqrt(obsU*obsU + obsV*obsV)
  259. qcarr2=stash.qcarr(wh)
  260. endif else begin
  261. ; print,'density eq 1'
  262. bkgt=stash.bkg(wh)
  263. bkgs=stash.bkg2(wh)
  264. obst=stash.obs(wh)
  265. obss=stash.obs2(wh)
  266. ; obs2=obst+obss
  267. ; bkg2=bkgt+bkgs
  268. obs2=eos_nemo(obst,obss)
  269. bkg2=eos_nemo(bkgt,bkgs)
  270. wh2=where(bkgt eq rmdi or bkgs eq rmdi)
  271. if (wh2(0) gt -1) then begin
  272. obs2(wh2)=rmdi
  273. bkg2(wh2)=rmdi
  274. endif
  275. qcarr2=max([[stash.qcarr(wh)],[stash.qcarr2(wh)]],dim=2)
  276. endelse
  277. endelse
  278. ; val2=abs(obs1(wh)-bkg1(wh))
  279. val2=abs(obs2-bkg2)
  280. ; obs2=obs1(wh)
  281. ; bkg2=bkg1(wh)
  282. obstype2=obstypes1(wh)
  283. ; qcarr2=qcarr1(wh)
  284. dayarr2=dayarr(wh)
  285. ; val2=sqrt(val1(wh)^2)
  286. ; print,'val2 ',val2(wh2)
  287. ; print,'dep2 ',dep2(wh2)
  288. ; plot,val2(wh2),dep2(wh2),ystyle=1,xstyle=1
  289. profilewindow,dep2,val2,obs2,bkg2,obstype2,qcarr2,dayarr2,datestr,xselstr,yselstr,rmdi, salinity=stash.salinity, $
  290. plot_bad_obs=stash.plot_bad_obs, white_on_black=stash.white_on_black, coltable=stash.coltable, $
  291. depmax=stash.depmax, depmin=stash.depmin
  292. ; set graphics back to main window
  293. ; WSET, stash.drawID
  294. print,'ev release'
  295. plotpoints,stash
  296. endif ; wh(0)>-1
  297. endif ; ev.release 4 (right mouse)
  298. endif
  299. endif ; left or right mouse click
  300. WIDGET_CONTROL, stash.label1, $
  301. SET_VALUE=stash.labt1 + strtrim(xselstr,1)
  302. WIDGET_CONTROL, stash.label2, $
  303. SET_VALUE=stash.labt2 + strtrim(yselstr,1)
  304. WIDGET_CONTROL, stash.label3, $
  305. SET_VALUE=typestr+': ' + strtrim(valselstr,1)
  306. WIDGET_CONTROL, stash.label4, $
  307. SET_VALUE=stash.labt4 + strtrim(qcselstr,1)
  308. WIDGET_CONTROL, stash.label5, $
  309. SET_VALUE=stash.labt5 + strtrim(datestr,1)
  310. WIDGET_CONTROL, stash.label6, $
  311. SET_VALUE=stash.labt6 + strtrim(valselstr,1)
  312. ; WIDGET_CONTROL, stash.label7, $
  313. ; SET_VALUE=stash.labt7 + strtrim(string(innovsd),1)
  314. WIDGET_CONTROL, stash.label8, $
  315. SET_VALUE=stash.labt8 + strtrim(obstypstr,1)
  316. WIDGET_CONTROL, stash.label9, $
  317. SET_VALUE=stash.labt9 + strtrim(obnumselstr,1)
  318. WIDGET_CONTROL, stash.label10, $
  319. SET_VALUE=stash.labt10 + string(mindatestr) + ' ' + string(maxdatestr)
  320. endif else begin ; not finite
  321. print, 'not finite'
  322. ; check for colorbar click
  323. if (ydev lt 80) then begin
  324. toplevel=stash.base
  325. fmx=stash.fmx
  326. fmn=stash.fmn
  327. mx=stash.mx
  328. mn=stash.mn
  329. inputmxmnwindow, fmx, fmn, mx, mn, stash.rmdi, toplevel, success
  330. if (success eq 1) then begin
  331. stash.fmx=fmx
  332. stash.fmn=fmn
  333. plotpoints,stash
  334. endif
  335. endif
  336. endelse ; finite
  337. endif
  338. ; print,tag_names(ev)
  339. ; print,ev.id
  340. ; print,ev.top
  341. ; print,ev.handler
  342. ; print,ev.type
  343. ; print,ev.press
  344. ; print,ev.release
  345. ; print,ev.clicks
  346. ; print,ev.modifiers
  347. ; print,ev.ch
  348. ; print,ev.key
  349. ENDIF ; end of widget draw events
  350. ; If the event is generated in a button, destroy the widget
  351. ; hierarchy. We know we can use this simple test because there
  352. ; is only one button in the application.
  353. ; IF (TAG_NAMES(ev, /STRUCTURE_NAME) eq 'WIDGET_COMBOBOX') THEN BEGIN
  354. ; IF (uval eq 'LEVELLIST') THEN BEGIN
  355. IF (uval eq 'LEVELCHOICE') THEN BEGIN
  356. stash.depmin=ev.value
  357. print,'levelchoice'
  358. print, 'stash.depmin: ',stash.depmin
  359. print, 'stash.depmax: ',stash.depmax
  360. if (stash.depmin ge stash.depmax) then begin
  361. stash.depmax=stash.depmin
  362. if (stash.depmax gt stash.depmaxl) then stash.depmax=stash.depmaxl
  363. ;set sliderb position
  364. WIDGET_CONTROL, stash.sliderb, set_value=stash.depmax
  365. endif
  366. plotpoints, stash
  367. ; print,ev.index,widget_info(ev.id,/combobox_gettext)
  368. ENDIF
  369. IF (uval eq 'LEVELCHOICEB') THEN BEGIN
  370. stash.depmax=ev.value
  371. print,'levelchoiceb'
  372. print, 'stash.depmin: ',stash.depmin
  373. print, 'stash.depmax: ',stash.depmax
  374. if (stash.depmax le stash.depmin) then begin
  375. stash.depmin=stash.depmax
  376. if (stash.depmin lt stash.depminl) then stash.depmin=stash.depminl
  377. ;set sliderb position
  378. WIDGET_CONTROL, stash.slider, set_value=stash.depmin
  379. endif
  380. plotpoints, stash
  381. ; print,ev.index,widget_info(ev.id,/combobox_gettext)
  382. ENDIF
  383. IF (uval eq 'DATERANGE1') THEN BEGIN
  384. odaymin=stash.daymin
  385. odaymax=stash.daymax
  386. stash.daymin=ev.value
  387. ; print, 'ev.drag ',ev.drag
  388. ; set slider label
  389. jul_to_dtstr,stash.daymin,dayminstr, /notime
  390. WIDGET_CONTROL, stash.slider1label, $
  391. SET_VALUE='min date: '+dayminstr
  392. if (stash.daymin ge stash.daymax) then begin
  393. ; stash.daymax=stash.daymin+1
  394. stash.daymax=stash.daymin
  395. if (stash.daymax gt stash.daymaxl) then stash.daymax=stash.daymaxl
  396. ;set slider2 position
  397. WIDGET_CONTROL, stash.slider2, set_value=stash.daymax
  398. ; set slider 2 label
  399. jul_to_dtstr,stash.daymax,daymaxstr, /notime
  400. WIDGET_CONTROL, stash.slider2label, $
  401. SET_VALUE='max date: '+daymaxstr
  402. endif
  403. print,'daterange1'
  404. ; if (ev.drag eq 0) then
  405. if (stash.daymin ne odaymin or stash.daymax ne odaymax) then plotpoints,stash
  406. ENDIF
  407. IF (uval eq 'DATERANGE2') THEN BEGIN
  408. odaymin=stash.daymin
  409. odaymax=stash.daymax
  410. stash.daymax=ev.value
  411. ; set slider label
  412. jul_to_dtstr,stash.daymax,daymaxstr, /notime
  413. WIDGET_CONTROL, stash.slider2label, $
  414. SET_VALUE='max date: '+daymaxstr
  415. if (stash.daymax le stash.daymin) then begin
  416. ; stash.daymin=stash.daymax-1
  417. stash.daymin=stash.daymax
  418. if (stash.daymin lt stash.dayminl) then stash.daymin=stash.dayminl
  419. ;set slider1 position
  420. WIDGET_CONTROL, stash.slider1, set_value=stash.daymin
  421. ; set slider 2 label
  422. jul_to_dtstr,stash.daymin,dayminstr, /notime
  423. WIDGET_CONTROL, stash.slider1label, $
  424. SET_VALUE='min date: '+dayminstr
  425. endif
  426. print,'daterange2'
  427. ; if (ev.drag eq 0) then
  428. if (stash.daymin ne odaymin or stash.daymax ne odaymax) then plotpoints,stash
  429. ENDIF
  430. IF (uval eq "RADIO1") THEN BEGIN
  431. print,'uval eq RADIO1'
  432. stash.typeplot=1
  433. print, 'typeplot ',stash.typeplot
  434. plotpoints,stash
  435. ENDIF
  436. IF (uval eq "RADIO2") THEN BEGIN
  437. print,'uval eq RADIO2'
  438. stash.typeplot=2
  439. print, 'typeplot ',stash.typeplot
  440. plotpoints,stash
  441. ENDIF
  442. IF (uval eq "RADIO3") THEN BEGIN
  443. print,'uval eq RADIO3'
  444. stash.typeplot=3
  445. print, 'typeplot ',stash.typeplot
  446. plotpoints,stash
  447. ENDIF
  448. IF (uval eq "RADIO4") THEN BEGIN
  449. print,'uval eq RADIO4'
  450. stash.typeplot=4
  451. print, 'typeplot ',stash.typeplot
  452. plotpoints,stash
  453. ENDIF
  454. IF (uval eq "RADIO5") THEN BEGIN
  455. print,'uval eq RADIO5'
  456. stash.ombtypeplot=1
  457. print, 'ombtypeplot ',stash.ombtypeplot
  458. plotpoints,stash
  459. ENDIF
  460. IF (uval eq "RADIO6") THEN BEGIN
  461. print,'uval eq RADIO6'
  462. stash.ombtypeplot=2
  463. print, 'ombtypeplot ',stash.ombtypeplot
  464. plotpoints,stash
  465. ENDIF
  466. IF (uval eq "RADIO7") THEN BEGIN
  467. print,'uval eq RADIO7'
  468. stash.ombtypeplot=3
  469. print, 'ombtypeplot ',stash.ombtypeplot
  470. plotpoints,stash
  471. ENDIF
  472. IF (uval eq "RADIO01") THEN BEGIN
  473. print,'uval eq RADIO01'
  474. stash.typeproj=1
  475. stash.xrange=stash.xrangedef
  476. stash.yrange=stash.yrangedef
  477. plotpoints,stash
  478. ENDIF
  479. IF (uval eq "RADIO02") THEN BEGIN
  480. print,'uval eq RADIO02'
  481. stash.typeproj=2
  482. stash.xrange=stash.xrangedef
  483. stash.yrange=stash.yrangedef
  484. plotpoints,stash
  485. ENDIF
  486. IF (uval eq "RADIO03") THEN BEGIN
  487. print,'uval eq RADIO03'
  488. stash.typeproj=3
  489. stash.xrange=stash.xrangedef
  490. stash.yrange=stash.yrangedef
  491. plotpoints,stash
  492. ENDIF
  493. IF (uval eq "RADIO001") THEN BEGIN
  494. print,'uval eq RADIO001 ev.select: ',ev.select
  495. stash.plot_bad_obs=ev.select
  496. ; stash.xrange=stash.xrangedef
  497. ; stash.yrange=stash.yrangedef
  498. plotpoints,stash
  499. ENDIF
  500. IF (uval eq "RADIOSAL") THEN BEGIN
  501. print,'uval eq RADIOSAL ev.select: ',ev.select
  502. salinity=ev.select
  503. ; if (stash.filetype eq "Prof" or stash.filetype eq "feedback") then begin
  504. stash.salinity=salinity
  505. plotpoints,stash
  506. ; endif
  507. ENDIF
  508. IF (uval eq "RADIODENSITY") THEN BEGIN
  509. print,'uval eq RADIODENSITY ev.select: ',ev.select
  510. density=ev.select
  511. if (stash.filetype eq "CRT") then stash.salinity=0
  512. ; if (stash.filetype eq "Prof" or stash.filetype eq "CRT") then begin
  513. stash.density=density
  514. plotpoints,stash
  515. ; endif
  516. ENDIF
  517. IF (uval eq "PRINT") THEN BEGIN
  518. ps=1
  519. eps=0
  520. landscape=1
  521. pr2,file=stash.outfile+'.ps',landscape=landscape,ps=ps,eps=eps,color=1
  522. plotpoints,stash
  523. prend2,/view
  524. ENDIF
  525. IF (uval eq "SAVE") THEN BEGIN
  526. thisDevice = !D.Name
  527. psave=!p
  528. Set_Plot, 'Z' ; do graphics in the background
  529. ; Device, Set_Resolution=[800,512], decomposed=0
  530. Device, Set_Resolution=stash.picsize, decomposed=0
  531. Erase ; clear any existing stuff
  532. !p.charsize=0.75
  533. ; if (stash.white_on_black eq 0) then begin
  534. ;; flip background and foreground color
  535. ; pcolor=!p.color
  536. ; pbackground=!p.background
  537. ; !p.color=pbackground
  538. ; !p.background=pcolor
  539. ;
  540. ; endif
  541. ; print,'!p.color,!p.background ',!p.color,!p.background
  542. setupct, r, g, b, coltable=stash.coltable, $
  543. white_on_black=stash.white_on_black ; setup color table
  544. ; plot data
  545. plotpoints,stash
  546. snapshot = TVRD()
  547. WRITE_GIF,stash.outfile+'.gif',snapshot, r, g, b
  548. Device, Z_Buffer=1 ; reset graphics mode
  549. Set_Plot, thisDevice
  550. ; !p.charsize=0.0
  551. !p=psave
  552. spawn,'xv '+stash.outfile+'.gif'
  553. ENDIF
  554. ;Area selection
  555. xrange=stash.xrange
  556. yrange=stash.yrange
  557. areasel,uval,xrange,yrange,success, toplevel=stash.base
  558. if (success eq 1) then begin
  559. stash.xrange=xrange
  560. stash.yrange=yrange
  561. plotpoints,stash
  562. endif
  563. IF (uval eq "Timeseries") THEN BEGIN
  564. stash.numtimeseries=0
  565. timeserieswindow,stash
  566. ; set graphics back to main window
  567. ; WSET, stash.drawID
  568. ;; print,'ev release'
  569. ;; plotpoints,stash
  570. ENDIF
  571. IF (uval eq "Num timeseries") THEN BEGIN
  572. stash.numtimeseries=1
  573. timeserieswindow,stash
  574. ; set graphics back to main window
  575. ; WSET, stash.drawID
  576. print,'ev release'
  577. plotpoints,stash
  578. ENDIF
  579. IF (uval eq "TS diagram") THEN BEGIN
  580. tsdiagramwindow,stash
  581. ; set graphics back to main window
  582. ; WSET, stash.drawID
  583. print,'ev release'
  584. plotpoints,stash
  585. ENDIF
  586. IF (uval eq "Worst points") THEN BEGIN
  587. worstpointswindow,stash
  588. ENDIF
  589. IF (uval eq "Filter type") THEN BEGIN
  590. filterwindow, stash
  591. ENDIF
  592. IF (uval eq "Low res map") THEN BEGIN
  593. ; stash.map_file=""
  594. stash.hires_map=0
  595. Widget_Control, stash.loresmap, Set_Button=1
  596. Widget_Control, stash.hiresmap, Set_Button=0
  597. plotpoints,stash
  598. ENDIF
  599. IF (uval eq "Hi res map") THEN BEGIN
  600. ; stash.map_file="/opt/ukmo/wave/ukmo/data/map_europe.xdr"
  601. stash.hires_map=1
  602. Widget_Control, stash.loresmap, Set_Button=0
  603. Widget_Control, stash.hiresmap, Set_Button=1
  604. plotpoints,stash
  605. ENDIF
  606. IF (uval eq "Plot only bad obs") THEN BEGIN
  607. stash.plot_only_bad_obs = 1-stash.plot_only_bad_obs
  608. Widget_Control, stash.pltonbado, Set_Button=stash.plot_only_bad_obs
  609. if (stash.plot_bad_obs eq 1) then plotpoints,stash
  610. ENDIF
  611. IF (uval eq "White on black") THEN BEGIN
  612. print,uval,' !p.color,!p.background ',!p.color,!p.background
  613. stash.white_on_black = 1-stash.white_on_black
  614. Widget_Control, stash.whtonblack, Set_Button=stash.white_on_black
  615. ; IF (!d.name eq 'X') then begin
  616. ; WSET, stash.drawID
  617. ;; flip background and foreground color
  618. ; pcolor=!p.color
  619. ; pbackground=!p.background
  620. ; !p.color=pbackground
  621. ; !p.background=pcolor
  622. setupct, r, g, b, coltable=stash.coltable, $
  623. white_on_black=stash.white_on_black ; setup color table
  624. plotpoints,stash
  625. ; endif
  626. ENDIF
  627. IF (uval eq "Square psym") THEN BEGIN
  628. stash.sym=1
  629. plotpoints,stash
  630. ENDIF
  631. IF (uval eq "Round psym") THEN BEGIN
  632. stash.sym=2
  633. plotpoints,stash
  634. ENDIF
  635. IF (uval eq "incsym") THEN BEGIN
  636. stash.symscale=stash.symscale*1.41421
  637. plotpoints,stash
  638. ENDIF
  639. IF (uval eq "decsym") THEN BEGIN
  640. stash.symscale=stash.symscale/1.41421
  641. plotpoints,stash
  642. ENDIF
  643. IF (uval eq "resetsym") THEN BEGIN
  644. stash.symscale=1.0
  645. plotpoints,stash
  646. ENDIF
  647. IF (uval eq "vertgrad") THEN BEGIN
  648. stash.vertgrad=1-stash.vertgrad
  649. Widget_Control, stash.vertgradmenu, Set_Button=stash.vertgrad
  650. plotpoints,stash
  651. ENDIF
  652. IF (uval eq "Info") THEN BEGIN
  653. infowindow
  654. ENDIF
  655. IF (uval eq "input max/min") THEN BEGIN
  656. toplevel=stash.base
  657. fmx=stash.fmx
  658. fmn=stash.fmn
  659. mx=stash.mx
  660. mn=stash.mn
  661. inputmxmnwindow, fmx, fmn, mx, mn, stash.rmdi, toplevel, success
  662. if (success eq 1) then begin
  663. stash.fmx=fmx
  664. stash.fmn=fmn
  665. plotpoints,stash
  666. endif
  667. ; stash.mx=mx
  668. ; stash.mn=mn
  669. ; info,stash.fmx
  670. ; info,stash.fmn
  671. ; info,stash.mx
  672. ; info,stash.mn
  673. ENDIF
  674. ; store values
  675. WIDGET_CONTROL, ev.TOP, SET_UVALUE=stash
  676. ; IF (TAG_NAMES(ev, /STRUCTURE_NAME) eq 'WIDGET_BUTTON') THEN BEGIN
  677. IF (uval eq "DONE") THEN BEGIN
  678. ; WIDGET_CONTROL, ev.TOP, /DESTROY
  679. WIDGET_CONTROL, stash.base, /DESTROY
  680. ENDIF
  681. ; WIDGET_CONTROL, stash.label3, SET_VALUE=TAG_NAMES(ev, /STRUCTURE_NAME)
  682. ; print,TAG_NAMES(ev, /STRUCTURE_NAME), uval
  683. END
  684. ;-----------------
  685. ; proceedures
  686. ;-----------------
  687. ;setup area ranges
  688. PRO areasel, uval, xrange, yrange, success, toplevel=toplevel
  689. ;info, xrange
  690. ;info, yrange
  691. success=0
  692. IF (uval eq "Global") THEN BEGIN
  693. xrange=[-180.,180.]
  694. yrange=[-90.,90.]
  695. success=1
  696. ENDIF
  697. IF (uval eq "Arctic") THEN BEGIN
  698. xrange=[-180.,180.]
  699. yrange=[70.,90.]
  700. success=1
  701. ENDIF
  702. IF (uval eq "N Atl") THEN BEGIN
  703. xrange=[-100.,0.]
  704. yrange=[25.,70.]
  705. success=1
  706. ENDIF
  707. IF (uval eq "Trop Atl") THEN BEGIN
  708. xrange=[-80.,20.]
  709. yrange=[-25.,25.]
  710. success=1
  711. ENDIF
  712. IF (uval eq "S Atl") THEN BEGIN
  713. xrange=[-70.,20.]
  714. yrange=[-50.,-25.]
  715. success=1
  716. ENDIF
  717. IF (uval eq "N Pac") THEN BEGIN
  718. xrange=[120.,-100.+360.]
  719. yrange=[25.,70.]
  720. success=1
  721. ENDIF
  722. IF (uval eq "Trop Pac") THEN BEGIN
  723. xrange=[120.,-80.+360.]
  724. yrange=[-25.,25.]
  725. success=1
  726. ENDIF
  727. IF (uval eq "S Pac") THEN BEGIN
  728. xrange=[120.,-70.+360.]
  729. yrange=[-50.,-25.]
  730. success=1
  731. ENDIF
  732. IF (uval eq "Indian") THEN BEGIN
  733. xrange=[20.,120.]
  734. yrange=[-50.,30.]
  735. success=1
  736. ENDIF
  737. IF (uval eq "S Ocean") THEN BEGIN
  738. xrange=[-180.,180.]
  739. yrange=[-90.,-50.]
  740. success=1
  741. ENDIF
  742. IF (uval eq "Pacific") THEN BEGIN
  743. xrange=[120.,-80.+360.]
  744. yrange=[-50.,70.]
  745. success=1
  746. ENDIF
  747. IF (uval eq "Atlantic") THEN BEGIN
  748. xrange=[-100.,20.]
  749. yrange=[-50.,70.]
  750. success=1
  751. ENDIF
  752. IF (uval eq "Med") THEN BEGIN
  753. xrange=[-15.,38.]
  754. yrange=[30.,46.]
  755. success=1
  756. ENDIF
  757. IF (uval eq "NWS") THEN BEGIN
  758. xrange=[-20.,13.]
  759. yrange=[40.,65.]
  760. success=1
  761. ENDIF
  762. IF (uval eq "Input Area") THEN BEGIN
  763. IF (n_elements(toplevel) gt 0) THEN BEGIN
  764. print,'success b4',success
  765. inputareawindow, xrange, yrange, toplevel, success
  766. print,'success af',success
  767. ENDIF
  768. ENDIF
  769. END
  770. ;select points to plot
  771. PRO selpoints, stash, lonsel, latsel, innovsel, qcsel, daysel, obstypsel, obnumsel, numsel, typestr, $
  772. daymin=daymin, daymax=daymax, salinity=salinity, rmsmean=rmsmean, innovsel2=innovsel2
  773. ; print, 'calling selpoints ',stash.netcdf, stash.txt
  774. print, 'calling selpoints'
  775. xarr1=stash.xarr
  776. yarr1=stash.yarr
  777. dep1=stash.dep
  778. if (n_elements(salinity) eq 0) then salinity=stash.salinity
  779. density=stash.density
  780. mld=stash.mld
  781. filetype=stash.filetype
  782. obnum=stash.obnum
  783. ; obnum=lindgen(n_elements(xarr1)) ; generate an array of observation numbers
  784. ; ; starting with zero
  785. ; if (salinity eq 0) then begin
  786. ; obs1=stash.obs
  787. ; bkg1=stash.bkg
  788. ; qcarr=stash.qcarr
  789. ; endif else begin
  790. ; obs1=stash.obs2
  791. ; bkg1=stash.bkg2
  792. ; qcarr=stash.qcarr2
  793. ; endelse
  794. if (salinity eq 0) then qcarr=stash.qcarr
  795. if (salinity eq 1 or mld eq 1) then qcarr=stash.qcarr2
  796. if (density eq 1) then begin
  797. if (filetype eq 'CRT') then qcarr=stash.qcarr $
  798. else qcarr=max([[stash.qcarr],[stash.qcarr2]],dim=2)
  799. endif
  800. obstypes1=stash.obstypes
  801. depmin=stash.depmin
  802. depmax=stash.depmax
  803. xrange=stash.xrange
  804. yrange=stash.yrange
  805. dayarr=stash.dayarr
  806. fdayarr=long(dayarr+stash.dayshi) ; 0:00 hours should be plotted in prev day
  807. if (n_elements(daymin) eq 0) then daymin=stash.daymin
  808. if (n_elements(daymax) eq 0) then daymax=stash.daymax
  809. fdaymin=long(daymin)
  810. fdaymax=long(daymax)
  811. typeplot=stash.typeplot
  812. ombtypeplot=stash.ombtypeplot
  813. typeproj=stash.typeproj
  814. xrange=stash.xrange
  815. yrange=stash.yrange
  816. rmdi=stash.rmdi
  817. print,'dayarr ',max(dayarr)-2454710d, min(dayarr)-2454710d
  818. print,'dayarr a',max(dayarr+stash.dayshi)-2454710d,min(dayarr+stash.dayshi)-2454710d
  819. print,'stash.dayshi ',stash.dayshi
  820. print,'fdayarr mx/mn ',max(fdayarr),min(fdayarr)
  821. print,'fdaymin ',fdaymin,' fdaymax ',fdaymax
  822. plot_bad_obs=stash.plot_bad_obs
  823. typestr=''
  824. if (typeproj eq 2) then begin
  825. xrange=[-999., 999.]
  826. yrange=[0., 90.]
  827. endif
  828. if (typeproj eq 3) then begin
  829. xrange=[-999., 999.]
  830. yrange=[-90, 0.]
  831. endif
  832. ; add 360 if we're in the pacific
  833. if (xrange(1) gt 180 and typeproj eq 1) then begin
  834. print,'xrange(1) gt 180 ',xrange
  835. wh=where(xarr1 lt 0)
  836. xarr1(wh)=xarr1(wh)+360
  837. endif
  838. print,'dayarr(0): ',dayarr(0),fdayarr(0), daymin, daymax
  839. ; if (plot_bad_obs eq 1) then begin
  840. wh=where(dep1 ge depmin and dep1 le depmax and $
  841. fdayarr ge fdaymin and fdayarr le fdaymax and $
  842. xarr1 ge xrange(0) and xarr1 le xrange(1) and $
  843. yarr1 ge yrange(0) and yarr1 le yrange(1))
  844. ; endif else begin
  845. ; wh=where(dep1 ge depmin and dep1 le depmax and $
  846. ; fdayarr ge fdaymin and fdayarr le fdaymax and $
  847. ; xarr1 ge xrange(0) and xarr1 le xrange(1) and $
  848. ; yarr1 ge yrange(0) and yarr1 le yrange(1) and qcarr eq 0)
  849. ; endelse
  850. nelwh=n_elements(wh)
  851. print,'nelwh ',nelwh
  852. if (wh(0) gt -1) then begin
  853. ; obssel=obs1(wh)
  854. ; bkgsel=bkg1(wh)
  855. qcsel=qcarr(wh)
  856. lonsel=xarr1(wh)
  857. latsel=yarr1(wh)
  858. daysel=dayarr(wh)
  859. depsel=dep1(wh)
  860. obstypsel=obstypes1(wh)
  861. obnumsel=obnum(wh)
  862. numsel=lonarr(nelwh)
  863. nel=n_elements(obssel)
  864. ; select points here to avoid unnecessary density calculations
  865. obssel1=stash.obs(wh)
  866. bkgsel1=stash.bkg(wh)
  867. obssel2=stash.obs2(wh)
  868. bkgsel2=stash.bkg2(wh)
  869. if (density eq 0 and mld eq 0) then begin
  870. if (salinity eq 0) then begin
  871. obssel=obssel1
  872. bkgsel=bkgsel1
  873. endif else begin
  874. obssel=obssel2
  875. bkgsel=bkgsel2
  876. endelse
  877. endif else begin
  878. if (filetype eq 'CRT') then begin
  879. bkgsel=sqrt(bkgsel1*bkgsel1 + bkgsel2*bkgsel2)
  880. if (salinity eq 0) then begin
  881. obssel=sqrt(obssel1*obssel1 + obssel2*obssel2)
  882. endif else begin
  883. obssel=stash.obs3(wh)
  884. endelse
  885. endif else begin ; calculate density if mld flag set
  886. obssel=eos_nemo(obssel1,obssel2)
  887. bkgsel=eos_nemo(bkgsel1,bkgsel2)
  888. endelse
  889. endelse
  890. ; create an array to store the sum of the square differences for calculating profile rms
  891. ; omb2sel=(obssel - bkgsel)^2
  892. nel=n_elements(obssel)
  893. endif else begin ; if there are no obs then exit subroutine
  894. nel=0
  895. return
  896. endelse
  897. if ((stash.txt eq 1 or stash.netcdf eq 1) and stash.bindata eq 1) then begin
  898. innovseli=obssel^2
  899. innovseli2=bkgsel^2
  900. innovseli3=(obssel-bkgsel)^2
  901. innovseli4=obssel*bkgsel
  902. endif else begin
  903. if (ombtypeplot eq 1) then begin
  904. typestr='obs - bkg'
  905. innovseli=obssel-bkgsel
  906. endif
  907. if (ombtypeplot eq 2) then begin
  908. typestr='obs'
  909. innovseli=obssel
  910. endif
  911. if (ombtypeplot eq 3) then begin
  912. typestr='bkg'
  913. innovseli=bkgsel
  914. endif
  915. if (keyword_set(rmsmean)) then begin
  916. innovseli=innovseli
  917. innovseli2=innovseli^2
  918. endif else begin
  919. if (typeplot eq 1) then begin
  920. typestr='mean '+typestr
  921. endif
  922. if (typeplot eq 2) then begin
  923. typestr='rms '+typestr
  924. innovseli=innovseli^2
  925. endif
  926. if (typeplot eq 3) then begin
  927. typestr='sd '+typestr
  928. innovseli=innovseli^2 ; ?
  929. endif
  930. if (typeplot eq 4) then begin
  931. typestr='mean sq '+typestr
  932. innovseli=innovseli^2
  933. endif
  934. endelse
  935. endelse
  936. ; print,'bkgsel ',bkgsel
  937. ; print,'obssel ',obssel
  938. ; tolerance check
  939. if (wh(0) gt -1) then begin
  940. wh2=[-1]
  941. ; print,qcsel
  942. if (plot_bad_obs eq 0) then begin
  943. ; if (typeplot eq 1 or typeplot eq 2 $
  944. ; or typeplot eq 3) then $
  945. if (ombtypeplot eq 1) then $
  946. ; wh2=where(bkgsel ne rmdi and obssel ne rmdi)
  947. wh2=where(abs(bkgsel-rmdi) gt abs(rmdi)*0.01 and abs(obssel-rmdi) gt $
  948. abs(rmdi)*0.01 and qcsel eq 0) ; tolerance rmdi check
  949. if (ombtypeplot eq 2) then $
  950. ; if (typeplot eq 4) then $
  951. ; wh2=where(obssel ne rmdi)
  952. wh2=where(abs(obssel-rmdi) gt abs(rmdi)*0.01 and qcsel eq 0) ;tol rmdi check
  953. if (ombtypeplot eq 3) then $
  954. ; if (typeplot eq 5) then $
  955. ; wh2=where(bkgsel ne rmdi)
  956. wh2=where(abs(bkgsel-rmdi) gt abs(rmdi)*0.01 and qcsel eq 0) ;tol rmdi check
  957. ; check for bad observations
  958. ; if (plot_bad_obs eq 1) then begin
  959. endif else if (plot_bad_obs eq 1 and stash.plot_only_bad_obs eq 1) then begin
  960. ; wh2=where(qcsel ne 0 or obssel eq rmdi or bkgsel eq rmdi, count)
  961. ; wh2=where(qcsel ne 0 or abs(obssel-rmdi) lt abs(rmdi)*0.01,count)
  962. wh2=where(qcsel ne 0 and obssel ne rmdi)
  963. ; wh2=where(qcsel ne 0 or abs(obssel-rmdi) lt abs(rmdi)*0.01 or abs(bkgsel-rmdi) lt abs(rmdi)*0.01,count)
  964. ; print,'bad obs: ',count
  965. ; whtmp=where(qcsel eq 0, count)
  966. ; print,'qcsel eq 0: ',count
  967. ; whtmp=where(obssel eq 0, count)
  968. ; print,'obssel eq 0: ',count
  969. ; whtmp=where(bkgsel eq 0, count)
  970. ; print,'bkgsel eq 0: ',count
  971. endif else begin ; plot all observations
  972. ; wh2=where(obssel)
  973. wh2=where(obssel ne rmdi)
  974. endelse
  975. if (wh2(0) gt -1) then begin
  976. obssel=obssel(wh2)
  977. bkgsel=bkgsel(wh2)
  978. innovseli=innovseli(wh2)
  979. ; if ((stash.txt eq 1 or stash.netcdf eq 1) and stash.bindata eq 1) then begin
  980. if (n_elements(innovseli2) gt 0) then innovseli2=innovseli2(wh2)
  981. if (n_elements(innovseli3) gt 0) then innovseli3=innovseli3(wh2)
  982. if (n_elements(innovseli4) gt 0) then innovseli4=innovseli4(wh2)
  983. ; endif
  984. qcsel=qcsel(wh2)
  985. lonsel=lonsel(wh2)
  986. latsel=latsel(wh2)
  987. daysel=daysel(wh2)
  988. depsel=depsel(wh2)
  989. obstypsel=obstypsel(wh2)
  990. obnumsel=obnumsel(wh2)
  991. ; numsel=numsel(wh2)
  992. endif
  993. print,'nelwh2 ',n_elements(wh2), typeplot, ombtypeplot
  994. if (wh2(0) gt -1) then begin
  995. ; calculate vertical gradients if required
  996. if (stash.filetype eq "Prof" and stash.vertgrad eq 1) then $
  997. calcvertgrad, lonsel, latsel, daysel, obssel, bkgsel, qcsel, depsel, rmdi
  998. ; average profiles on the same latitude and longitude
  999. ; goes through each point and puts the average in the first instance and flags
  1000. ; the others for later removal
  1001. ; this routine can also be used to bin data
  1002. depmx=max(depsel,min=depmn)
  1003. print,'depmn/mx: ',depmn, depmx
  1004. if (depmx gt depmn or stash.duplicates gt 0 or stash.differences or stash.bindata) then begin
  1005. ; sort by lat and lon
  1006. ; presumably will average in time also...
  1007. if (stash.bindata) then begin ; if we are binning data (in 1 deg bins)
  1008. ; use +0.5 to get nearest round number
  1009. latbin=double(fix((latsel+stash.binsize(1)/2.)*(1/stash.binsize(1))))/(1/stash.binsize(1))
  1010. lonbin=double(fix((lonsel+stash.binsize(0)/2.)*(1/stash.binsize(0))))/(1/stash.binsize(0))
  1011. latlon=long(latbin*10000000d)+double(lonbin+180d)/360d
  1012. endif else begin
  1013. latlon=long(double(latsel)*10000000d)+double(lonsel+180d)/360d
  1014. endelse
  1015. elsort=sort(latlon)
  1016. latsel=latsel(elsort)
  1017. lonsel=lonsel(elsort)
  1018. obssel=obssel(elsort)
  1019. bkgsel=bkgsel(elsort)
  1020. innovseli=innovseli(elsort)
  1021. ; if ((stash.txt eq 1 or stash.netcdf eq 1) and stash.bindata eq 1) then begin
  1022. if (n_elements(innovseli2) gt 0) then innovseli2=innovseli2(elsort)
  1023. if (n_elements(innovseli3) gt 0) then innovseli3=innovseli3(elsort)
  1024. if (n_elements(innovseli4) gt 0) then innovseli4=innovseli4(elsort)
  1025. ; endif
  1026. qcsel=qcsel(elsort)
  1027. daysel=daysel(elsort)
  1028. depsel=depsel(elsort)
  1029. obstypsel=obstypsel(elsort)
  1030. obnumsel=obnumsel(elsort)
  1031. ; numsel=numsel(elsort)
  1032. latlon=latlon(elsort)
  1033. nel=n_elements(obssel)
  1034. accum=0
  1035. isave=0
  1036. lon1=-99999.0
  1037. lat1=-99999.0
  1038. latlon1=-99999.0
  1039. day1=-99999
  1040. num=0
  1041. ; if (nel gt 100) then begin
  1042. ; info,latsel
  1043. ; print,latsel(0:100)
  1044. ; info,lonsel
  1045. ; print,lonsel(0:100)
  1046. ; info,latlon
  1047. ; print,latlon(0:100)
  1048. ; latsel(0:100)=latsel(50)
  1049. ; lonsel(0:100)=lonsel(50)
  1050. ; latlon=long(double(latsel)*10000000d)+double(lonsel+180d)/360d
  1051. ; endif
  1052. print,'DJL ',max(daysel),min(daysel)
  1053. ; loop through the data averaging profiles at the same location
  1054. sign=1
  1055. if (stash.duplicates eq 2) then sign=-1 ; plot the difference rather than the average
  1056. numsel=lonarr(nel)
  1057. for i=0L,nel-1 do begin
  1058. if i mod 100000 eq 0 then print,i,nel
  1059. ; if (plot_bad_obs eq 0 and obssel(i) ne rmdi) or $
  1060. ; (plot_bad_obs eq 1 and lonsel(i) ne rmdi) then begin
  1061. ; if (lonsel(i) ne lon1 or latsel(i) ne lat1) then begin
  1062. ; check for new profile or reaching the end of the data
  1063. ; check for the end of a day added
  1064. if ((latlon(i) ne latlon1) or (i eq nel-1) or (long(daysel(i)) ne long(day1))) then begin
  1065. ; print,i, latlon(i), latlon1, daysel(i), day1
  1066. ; if i gt 0 then stop
  1067. ; average last profile
  1068. if (isave ge 0 and num gt 0) then begin
  1069. if (num gt 1) then begin
  1070. ; print,num
  1071. numsave=num
  1072. if (stash.duplicates eq 2) then num=1
  1073. if (stash.bindata) then begin
  1074. latsel(isave)=latsel(isave)/num
  1075. lonsel(isave)=lonsel(isave)/num
  1076. endif
  1077. obssel(isave)=obssel(isave)/num
  1078. bkgsel(isave)=bkgsel(isave)/num
  1079. daysel(isave)=daysel(isave)/num
  1080. depsel(isave)=depsel(isave)/num
  1081. innovseli(isave)=innovseli(isave)/num
  1082. ; if ((stash.txt eq 1 or stash.netcdf eq 1) and stash.bindata eq 1) then begin
  1083. if (n_elements(innovseli2) gt 0) then innovseli2(isave)=innovseli2(isave)/num
  1084. if (n_elements(innovseli3) gt 0) then innovseli3(isave)=innovseli3(isave)/num
  1085. if (n_elements(innovseli4) gt 0) then innovseli4(isave)=innovseli4(isave)/num
  1086. ; endif
  1087. num=numsave
  1088. ; save the num
  1089. numsel(isave)=num
  1090. ; if (fix(lonsel(isave)) eq -7297 and $
  1091. ; fix(latsel(isave)) eq -5935) then begin
  1092. ; print,'completed ',isave, num
  1093. ; print,'obssel ',obssel(isave)
  1094. ; print,'bkgsel ',bkgsel(isave)
  1095. ; endif
  1096. endif else begin
  1097. numsel(isave)=num
  1098. endelse
  1099. if ((stash.duplicates gt 0 and num eq 1) or (stash.differences and num gt 1)) then begin
  1100. obssel(isave)=rmdi
  1101. bkgsel(isave)=rmdi
  1102. lonsel(isave)=rmdi
  1103. latsel(isave)=rmdi
  1104. qcsel(isave)=rmdi
  1105. innovseli(isave)=rmdi
  1106. ; if ((stash.txt eq 1 or stash.netcdf eq 1) and stash.bindata eq 1) then begin
  1107. if (n_elements(innovseli2) gt 0) then innovseli2(isave)=rmdi
  1108. if (n_elements(innovseli3) gt 0) then innovseli3(isave)=rmdi
  1109. if (n_elements(innovseli4) gt 0) then innovseli4(isave)=rmdi
  1110. ; endif
  1111. endif
  1112. endif
  1113. if (plot_bad_obs eq 0 and obssel(i) ne rmdi) or $
  1114. (plot_bad_obs eq 1 and lonsel(i) ne rmdi) then begin
  1115. ; start a new profile
  1116. lon1=lonsel(i)
  1117. lat1=latsel(i)
  1118. latlon1=latlon(i)
  1119. day1=daysel(i)
  1120. isave=i
  1121. accum=1
  1122. num=1
  1123. endif ; plot_bad_obs ...
  1124. ; accumulating
  1125. endif else begin
  1126. if (plot_bad_obs eq 0 and obssel(i) ne rmdi) or $
  1127. (plot_bad_obs eq 1 and lonsel(i) ne rmdi) then begin
  1128. num=num+1
  1129. if (stash.bindata) then begin
  1130. latsel(isave)=latsel(isave)+double(fix((1./stash.binsize(1))*(latsel(i)+stash.binsize(1)/2.)))/(1./stash.binsize(1)) ;latsel(isave)+fix(latsel(i)+0.5)
  1131. lonsel(isave)=lonsel(isave)+double(fix((1./stash.binsize(0))*(lonsel(i)+stash.binsize(0)/2.)))/(1./stash.binsize(0)) ;lonsel(isave)+fix(lonsel(i)+0.5)
  1132. endif
  1133. obssel(isave)=obssel(isave)+obssel(i)*sign
  1134. bkgsel(isave)=bkgsel(isave)+bkgsel(i)*sign
  1135. innovseli(isave)=innovseli(isave)+innovseli(i)*sign
  1136. ; if ((stash.txt eq 1 or stash.netcdf eq 1) and stash.bindata eq 1) then begin
  1137. if (n_elements(innovseli2) gt 0) then innovseli2(isave)=innovseli2(isave)+innovseli2(i)*sign
  1138. if (n_elements(innovseli3) gt 0) then innovseli3(isave)=innovseli3(isave)+innovseli3(i)*sign
  1139. if (n_elements(innovseli4) gt 0) then innovseli4(isave)=innovseli4(isave)+innovseli4(i)*sign
  1140. ; endif
  1141. qcsel(isave)=min([qcsel(isave),qcsel(i)])
  1142. daysel(isave)=daysel(isave)+daysel(i)
  1143. depsel(isave)=depsel(isave)+depsel(i)
  1144. if (stash.bindata) then begin
  1145. latsel(i)=rmdi
  1146. lonsel(i)=rmdi
  1147. endif
  1148. obssel(i)=rmdi
  1149. bkgsel(i)=rmdi
  1150. innovseli(i)=rmdi
  1151. ; if ((stash.txt eq 1 or stash.netcdf eq 1) and stash.bindata eq 1) then begin
  1152. if (n_elements(innovseli2) gt 0) then innovseli2(i)=rmdi
  1153. if (n_elements(innovseli3) gt 0) then innovseli3(i)=rmdi
  1154. if (n_elements(innovseli4) gt 0) then innovseli4(i)=rmdi
  1155. ; endif
  1156. lonsel(i)=rmdi
  1157. latsel(i)=rmdi
  1158. qcsel(i)=rmdi
  1159. ; if (fix(lonsel(isave)*100) eq -7297 and $
  1160. ; fix(latsel(isave)*100) eq -5935) then begin
  1161. ; print,'isave ',isave, num
  1162. ; print,'obssel ',obssel(isave)
  1163. ; print,'bkgsel ',bkgsel(isave)
  1164. ; endif
  1165. endif ; plot_bad_obs ...
  1166. endelse
  1167. ; endif
  1168. endfor ; i nobs
  1169. print,'DJL2x ',max(daysel),min(daysel)
  1170. wh5=where(lonsel ne rmdi) ; clears out but the averaged profiles
  1171. if (wh5(0) gt -1) then begin
  1172. obssel=obssel(wh5)
  1173. bkgsel=bkgsel(wh5)
  1174. innovseli=innovseli(wh5)
  1175. ; if ((stash.txt eq 1 or stash.netcdf eq 1) and stash.bindata eq 1) then begin
  1176. if (n_elements(innovseli2) gt 0) then innovseli2=innovseli2(wh5)
  1177. if (n_elements(innovseli3) gt 0) then innovseli3=innovseli3(wh5)
  1178. if (n_elements(innovseli4) gt 0) then innovseli4=innovseli4(wh5)
  1179. ; endif
  1180. qcsel=qcsel(wh5)
  1181. lonsel=lonsel(wh5)
  1182. latsel=latsel(wh5)
  1183. daysel=daysel(wh5)
  1184. obstypsel=obstypsel(wh5)
  1185. obnumsel=obnumsel(wh5)
  1186. numsel=numsel(wh5)
  1187. nel=n_elements(obssel)
  1188. endif else begin ; if there are no obs then exit subroutine
  1189. nel=0
  1190. return
  1191. endelse
  1192. endif
  1193. print,'nel wh5 ',n_elements(wh5)
  1194. print,'DJL3 ',max(daysel),min(daysel)
  1195. typeselect=stash.obstypeselect
  1196. ; print, 'typeselect ',typeselect
  1197. if (typeselect(0) ne "") then begin
  1198. ; typeselecta=strsplit(typeselect,' ,',/extract) ; split string on commas or spaces
  1199. typeselecta=strsplit(typeselect,',',/extract) ; split string on commas only
  1200. nel=n_elements(typeselecta)
  1201. print,'n_elements(typeselecta) ',nel
  1202. for i=0L,nel-1 do begin
  1203. ; string matching (understands * ?)
  1204. st1=strtrim(string(obstypsel),2) ; strip tailing and leading spaces
  1205. st2=strtrim(typeselecta(i),2)
  1206. wh6t=where(strmatch(st1,st2,/FOLD_CASE) EQ 1)
  1207. ; print, 'wh6t ',typeselecta(i), wh6t
  1208. if i eq 0 then wh6=wh6t else wh6=[wh6,wh6t]
  1209. endfor
  1210. ; print,n_elements(wh6)
  1211. ; print,wh6
  1212. wh=where(wh6 gt -1)
  1213. ; print,wh
  1214. if (wh(0) gt -1) then begin
  1215. wh6=wh6(wh)
  1216. obssel=obssel(wh6)
  1217. bkgsel=bkgsel(wh6)
  1218. innovseli=innovseli(wh6)
  1219. ; if ((stash.txt eq 1 or stash.netcdf eq 1) and stash.bindata eq 1) then begin
  1220. if (n_elements(innovseli2) gt 0) then innovseli2=innovseli2(wh6)
  1221. if (n_elements(innovseli3) gt 0) then innovseli3=innovseli3(wh6)
  1222. if (n_elements(innovseli4) gt 0) then innovseli4=innovseli4(wh6)
  1223. ; endif
  1224. qcsel=qcsel(wh6)
  1225. lonsel=lonsel(wh6)
  1226. latsel=latsel(wh6)
  1227. daysel=daysel(wh6)
  1228. obstypsel=obstypsel(wh6)
  1229. obnumsel=obnumsel(wh6)
  1230. numsel=numsel(wh6)
  1231. nel=n_elements(obssel)
  1232. ; print, 'nel (in obstypeselect) ',nel
  1233. endif else begin ; if there are no obs then exit subroutine
  1234. print,'no matching obs'
  1235. nel=0
  1236. endelse
  1237. endif
  1238. if (stash.printobstypes eq 1) then begin
  1239. s=sort(obstypsel)
  1240. sobstypsel=obstypsel(s)
  1241. u=uniq(sobstypsel)
  1242. print,"unique obs types: ",sobstypsel(u)
  1243. endif
  1244. print,'nel ',nel
  1245. stash.symsize=1.0
  1246. if (nel gt 250) then stash.symsize=0.75
  1247. if (nel gt 1000) then stash.symsize=0.5
  1248. if (nel gt 2000) then stash.symsize=0.25
  1249. if (nel lt 20) then stash.symsize=2.0
  1250. if (!d.name eq 'Z') then stash.symsize=stash.symsize/2
  1251. print,'stash.symsize: ',stash.symsize
  1252. ; save data for mean and rms plots
  1253. ; for ombtypeplot=3 typeplot=2 innovsel = (obs - bkg)^2 mean value available from obssel(i) - bkgsel(i)
  1254. ; copy innovseli to innovsel (if we've got some valid data to plot / save)
  1255. if (nel gt 0) then innovsel=innovseli
  1256. if (stash.txt eq 1 and stash.bindata eq 1) then begin
  1257. ; The file contains: longitude, latitude, num of points, obs mean, bkg mean
  1258. ; mean sq obs, mean sq bkg, mean sq obs - bkg, mean obs * bkg
  1259. outfile=stash.outfile+'_selpoints.txt'
  1260. print, 'saving data to ',outfile
  1261. OPENW, unit, outfile, /get_lun
  1262. ; printf,unit,'Output selpoints data: '
  1263. printf,unit, 3 ; file version
  1264. printf,unit, typeplot
  1265. printf,unit, stash.bindata
  1266. printf,unit, xrange, yrange
  1267. printf,unit, min(daysel), max(daysel)
  1268. for i=0L,nel-1 do begin
  1269. printf,unit, lonsel(i), latsel(i), numsel(i), obssel(i), bkgsel(i), $
  1270. innovseli(i), innovseli2(i), innovseli3(i), innovseli4(i), $
  1271. format='(2d10.3, i8, 6d18.8)'
  1272. endfor
  1273. FREE_LUN, unit
  1274. endif
  1275. if (stash.netcdf eq 1 and stash.bindata eq 1) then begin
  1276. outfile=stash.outfile+'_selpoints.nc'
  1277. print, 'saving data to ',outfile
  1278. nid=NCDF_CREATE( outfile, /CLOBBER )
  1279. NCDF_ATTPUT, nid, 'version', 3, /SHORT, /GLOBAL
  1280. NCDF_ATTPUT, nid, 'bindata', stash.bindata, /FLOAT, /GLOBAL
  1281. NCDF_ATTPUT, nid, 'xrange0', xrange(0), /FLOAT, /GLOBAL
  1282. NCDF_ATTPUT, nid, 'xrange1', xrange(1), /FLOAT, /GLOBAL
  1283. NCDF_ATTPUT, nid, 'yrange0', yrange(0), /FLOAT, /GLOBAL
  1284. NCDF_ATTPUT, nid, 'yrange1', yrange(1), /FLOAT, /GLOBAL
  1285. NCDF_ATTPUT, nid, 'mindaysel', min(daysel), /FLOAT, /GLOBAL
  1286. NCDF_ATTPUT, nid, 'maxdaysel', max(daysel), /FLOAT, /GLOBAL
  1287. print, 'nel ',nel
  1288. nelid = NCDF_DIMDEF( nid, 'n', nel )
  1289. lonid = NCDF_VARDEF ( nid, 'longitudes', [nelid], /FLOAT )
  1290. latid = NCDF_VARDEF ( nid, 'latitudes', [nelid], /FLOAT )
  1291. numid = NCDF_VARDEF ( nid, 'num', [nelid], /LONG )
  1292. obsid = NCDF_VARDEF ( nid, 'obs_mean', [nelid], /FLOAT )
  1293. bkgid = NCDF_VARDEF ( nid, 'bkg_mean', [nelid], /FLOAT )
  1294. innovseli1id = NCDF_VARDEF ( nid, 'obs_mean_sq', [nelid], /FLOAT )
  1295. innovseli2id = NCDF_VARDEF ( nid, 'bkg_mean_sq', [nelid], /FLOAT )
  1296. innovseli3id = NCDF_VARDEF ( nid, 'omb_mean_sq', [nelid], /FLOAT )
  1297. innovseli4id = NCDF_VARDEF ( nid, 'otimesb_mean', [nelid], /FLOAT )
  1298. NCDF_CONTROL, nid, /ENDEF
  1299. if (nel gt 0) then begin
  1300. NCDF_VARPUT, nid, lonid, lonsel
  1301. NCDF_VARPUT, nid, latid, latsel
  1302. NCDF_VARPUT, nid, numid, numsel
  1303. NCDF_VARPUT, nid, obsid, obssel
  1304. NCDF_VARPUT, nid, bkgid, bkgsel
  1305. NCDF_VARPUT, nid, innovseli1id, innovseli
  1306. NCDF_VARPUT, nid, innovseli2id, innovseli2
  1307. NCDF_VARPUT, nid, innovseli3id, innovseli3
  1308. NCDF_VARPUT, nid, innovseli4id, innovseli4
  1309. endif
  1310. NCDF_CLOSE, nid
  1311. endif
  1312. if (stash.filterout ne '') then begin
  1313. ; write out filtered feedback file in new feedback format
  1314. ; with some filthy fudges to emulate NEMOVAR format
  1315. if (nel gt 0) then begin
  1316. print, 'writing filtered feedback file ',stash.filterout
  1317. ; split type string in two to be used as STATION_IDENTIFIER and STATION_TYPE
  1318. typesel=strarr(nel)
  1319. instsel=strarr(nel)
  1320. for iob = 0, nel-1 do begin
  1321. tempsel=strsplit(obstypsel[iob],/extract)
  1322. typesel[iob]=tempsel[0]
  1323. ; catch for data without space and instrument id in types (e.g. altimeter)
  1324. instsel[iob]=''
  1325. if (n_elements(tempsel) gt 1 ) then $
  1326. instsel[iob]=tempsel[1]
  1327. endfor
  1328. ; setup netcdf file
  1329. nid=NCDF_CREATE( stash.filterout, /CLOBBER )
  1330. ; global attribute to emulate NEMOVAR feedback files
  1331. NCDF_ATTPUT, nid, 'title', "NEMO observation operator output", /GLOBAL
  1332. if (stash.obstypeselect ne '' ) then $
  1333. NCDF_ATTPUT, nid, 'filter', stash.obstypeselect, /GLOBAL
  1334. NCDF_ATTPUT, nid, 'minday', min(daysel), /FLOAT, /GLOBAL
  1335. NCDF_ATTPUT, nid, 'maxday', max(daysel), /FLOAT, /GLOBAL
  1336. nobid = NCDF_DIMDEF( nid, 'N_OBS', nel )
  1337. ndepid = NCDF_DIMDEF( nid, 'N_LEVELS', 1 ) ; temporarily input 1d profile arrays
  1338. if (stash.filetype eq 'feedback') then begin
  1339. ncvars = stash.varname
  1340. nnvars = n_elements(ncvars)
  1341. endif else begin
  1342. nnvars = 1
  1343. ncvars = stash.filetype
  1344. if (stash.filetype eq 'Prof') then begin
  1345. ncvars = 'POTM'
  1346. if (salinity eq 1) then ncvars = 'PSAL'
  1347. nextid = NCDF_DIMDEF( nid, 'N_EXTRA', 1 )
  1348. endif
  1349. endelse
  1350. nvarid = NCDF_DIMDEF( nid, 'N_VARS', nnvars )
  1351. nentid = NCDF_DIMDEF( nid, 'N_ENTRIES', 1 )
  1352. nstrnamid = NCDF_DIMDEF( nid, 'STRINGNAM', 8 )
  1353. nstrwmoid = NCDF_DIMDEF( nid, 'STRINGWMO', 8 )
  1354. nstrtypid = NCDF_DIMDEF( nid, 'STRINGTYP', 4 )
  1355. nstrjulid = NCDF_DIMDEF( nid, 'STRINGJULD', 14 )
  1356. varid = NCDF_VARDEF ( nid, 'VARIABLES', [nstrnamid,nvarid], /CHAR )
  1357. entid = NCDF_VARDEF ( nid, 'ENTRIES', [nstrnamid,nentid], /CHAR )
  1358. signid = NCDF_VARDEF ( nid, 'STATION_IDENTIFIER', [nstrwmoid,nobid], /CHAR )
  1359. typeid = NCDF_VARDEF ( nid, 'STATION_TYPE', [nstrtypid,nobid], /CHAR )
  1360. lonid = NCDF_VARDEF ( nid, 'LONGITUDE', [nobid], /DOUBLE )
  1361. latid = NCDF_VARDEF ( nid, 'LATITUDE', [nobid], /DOUBLE )
  1362. depid = NCDF_VARDEF ( nid, 'DEPTH', [nobid], /DOUBLE )
  1363. ; depid = NCDF_VARDEF ( nid, 'DEPTH', [ndepid,nobid], /DOUBLE )
  1364. julid = NCDF_VARDEF ( nid, 'JULD', [nobid], /DOUBLE )
  1365. jrefid = NCDF_VARDEF ( nid, 'JULD_REFERENCE', [nstrjulid], /CHAR )
  1366. obsqcid = NCDF_VARDEF ( nid, 'OBSERVATION_QC', [nobid], /LONG )
  1367. FillVal=9999
  1368. NCDF_ATTPUT, nid, depid, '_Fillvalue', FillVal, /DOUBLE
  1369. NCDF_ATTPUT, nid, obsqcid, '_Fillvalue', FillVal, /LONG
  1370. obsids=intarr(nnvars)
  1371. bkgids=intarr(nnvars)
  1372. qcids=intarr(nnvars)
  1373. lqcids=intarr(nnvars)
  1374. for ivar = 0, nnvars-1 do begin
  1375. obsids[ivar] = NCDF_VARDEF ( nid, ncvars[ivar]+'_OBS', [nobid], /FLOAT )
  1376. NCDF_ATTPUT, nid, obsids[ivar], '_Fillvalue', FillVal, /FLOAT
  1377. bkgids[ivar] = NCDF_VARDEF ( nid, ncvars[ivar]+'_Hx', [nobid], /FLOAT )
  1378. NCDF_ATTPUT, nid, bkgids[ivar], '_Fillvalue', FillVal, /FLOAT
  1379. qcids[ivar] = NCDF_VARDEF ( nid, ncvars[ivar]+'_QC', [nobid], /LONG )
  1380. NCDF_ATTPUT, nid, qcids[ivar], '_Fillvalue', FillVal, /FLOAT
  1381. lqcids[ivar] = NCDF_VARDEF ( nid, ncvars[ivar]+'_LEVEL_QC', [nobid], /LONG )
  1382. NCDF_ATTPUT, nid, lqcids[ivar], '_Fillvalue', FillVal, /FLOAT
  1383. endfor
  1384. NCDF_CONTROL, nid, /ENDEF
  1385. JulDRef = '19500101000000'
  1386. NCDF_VARPUT, nid, jrefid, JulDRef
  1387. RefDate = JULDAY(fix(strmid(JulDRef,4,2)), fix(strmid(JulDRef,6,2)), fix(strmid(JulDRef,0,4)), $
  1388. fix(strmid(JulDRef,8,2)), fix(strmid(JulDRef,10,2)), fix(strmid(JulDRef,12,2)))
  1389. NCDF_VARPUT, nid, julid,daysel-RefDate
  1390. NCDF_VARPUT, nid, varid, ncvars
  1391. NCDF_VARPUT, nid, entid, 'Hx'
  1392. NCDF_VARPUT, nid, lonid, lonsel
  1393. NCDF_VARPUT, nid, latid, latsel
  1394. NCDF_VARPUT, nid, depid, fltarr(nel)
  1395. NCDF_VARPUT, nid, obsqcid, fltarr(nel)+1
  1396. for ivar = 0, nnvars-1 do begin
  1397. NCDF_VARPUT, nid, obsids[ivar], obssel
  1398. NCDF_VARPUT, nid, bkgids[ivar], bkgsel
  1399. NCDF_VARPUT, nid, qcids[ivar], qcsel+1
  1400. NCDF_VARPUT, nid, lqcids[ivar], fltarr(nel)+1
  1401. endfor
  1402. NCDF_VARPUT, nid, typeid, typesel
  1403. NCDF_VARPUT, nid, signid, instsel
  1404. endif
  1405. NCDF_CLOSE, nid
  1406. endif ; filterout
  1407. if (nel gt 0) then begin
  1408. if (typeplot eq 2) then begin
  1409. innovsel=sqrt(innovsel)
  1410. endif
  1411. if (typeplot eq 3) then begin
  1412. ; std dev = sqrt ( mean x2 - (mean x)^2)
  1413. x2=innovsel
  1414. print,'typeplot ',typeplot,' ombtypeplot ',ombtypeplot
  1415. if (ombtypeplot eq 1) then $
  1416. innovsel=sqrt(x2-(obssel-bkgsel)^2)
  1417. if (ombtypeplot eq 2) then $
  1418. innovsel=sqrt(x2-(obssel)^2)
  1419. if (ombtypeplot eq 3) then $
  1420. innovsel=sqrt(x2-(bkgsel)^2)
  1421. endif
  1422. if (keyword_set(rmsmean)) then begin
  1423. innovsel=innovseli ; mean
  1424. if (n_elements(innovseli2) gt 0) then innovsel2=innovseli2 ; rms
  1425. endif
  1426. innovmean=total(innovsel)/nel
  1427. innovmean2=total(innovsel^2)/nel
  1428. innovsd=sqrt(innovmean2-innovmean^2)
  1429. print,'mean innovsel ',innovmean
  1430. print,'sd innovsel ',innovsd
  1431. endif
  1432. endif
  1433. endif
  1434. wh=where(numsel eq 0)
  1435. if (wh(0) gt -1) then numsel(wh)=1
  1436. END
  1437. PRO setupct, r, g, b, coltable=coltable, white_on_black=white_on_black
  1438. if (coltable eq 0 or coltable lt -2) then begin
  1439. ; get color table and modify
  1440. loadct, 13
  1441. stretch, -40, 256
  1442. ; tvlct,r,g,b,/get
  1443. ; r(0)=0
  1444. ; g(0)=0
  1445. ; b(0)=0
  1446. ; r(255)=255
  1447. ; g(255)=255
  1448. ; b(255)=255
  1449. ; tvlct,r,g,b
  1450. endif else begin
  1451. if (coltable eq -1) then begin
  1452. restore_colors, 'spectrum.clr'
  1453. endif else if (coltable eq -2) then begin
  1454. restore_colors, '~frbe/spectrum_alt.xdr',/asis
  1455. endif else begin
  1456. loadct,coltable
  1457. endelse
  1458. endelse
  1459. tvlct,r,g,b,/get
  1460. i0=0
  1461. i1=255
  1462. if (n_elements(white_on_black) eq 1 and !d.name ne "PS") then begin
  1463. if (white_on_black eq 0) then begin
  1464. i0=255
  1465. i1=0
  1466. endif
  1467. endif
  1468. r(i0)=0
  1469. g(i0)=0
  1470. b(i0)=0
  1471. r(i1)=255
  1472. g(i1)=255
  1473. b(i1)=255
  1474. tvlct,r,g,b
  1475. END
  1476. PRO plotpoints, stash
  1477. nplots=1
  1478. if (stash.pmulti eq 2) then nplots=stash.pmulti
  1479. for nplot=0,nplots-1 do begin
  1480. if (stash.busy eq 1) then return
  1481. stash.busy = 1
  1482. num_cols=254
  1483. print,"!d.name ",!d.name
  1484. IF (stash.drawID gt -1) then begin
  1485. IF (!d.name eq 'X' or !d.name eq 'Z') then begin
  1486. device, decomposed=0
  1487. endif
  1488. IF (!d.name eq 'X') then WSET, stash.drawID
  1489. endif
  1490. IF (!d.name ne 'Z') then setupct, r, g, b, $
  1491. coltable=stash.coltable,white_on_black=stash.white_on_black ; setup color table
  1492. noerase=0
  1493. if (stash.pmulti eq 2) then begin
  1494. if (stash.pmultinum gt 0) then noerase=1
  1495. !p.multi=[stash.pmultinum,2,1]
  1496. stash.pmultinum=(stash.pmultinum+1) mod 2
  1497. endif else begin
  1498. !p.multi=0
  1499. endelse
  1500. ; xarr1=stash.xarr
  1501. ; yarr1=stash.yarr
  1502. ; dep1=stash.dep
  1503. ; obs1=stash.obs
  1504. ; bkg1=stash.bkg
  1505. ; depmin=stash.depmin
  1506. xrange=stash.xrange
  1507. yrange=stash.yrange
  1508. ; dayarr=stash.dayarr
  1509. daymin=stash.daymin
  1510. daymax=stash.daymax
  1511. ; typeplot=stash.typeplot
  1512. typeproj=stash.typeproj
  1513. ; print,"stash.map_file: ",stash.map_file
  1514. ; if (strlen(stash.map_file) gt 0) then map_file=stash.map_file
  1515. ; print,depmin,xrange,yrange
  1516. dummy=[0,0]
  1517. ; plot,dummy,/nodata,yrange=[-90,90],xrange=[-180,180]
  1518. ; plot,dummy,/nodata,yrange=[-50,80],xrange=[-110,40],$
  1519. ; xstyle=1,ystyle=1, xtitle='Longitude',ytitle='Latitude'
  1520. if (typeproj ne 1) then begin
  1521. origlon=0.
  1522. if (typeproj eq 2) then begin
  1523. origlat=90.
  1524. if (yrange(0) lt 0) then yrange(0)=45
  1525. if (yrange(1) lt 0) then yrange(1)=90
  1526. endif
  1527. if (typeproj eq 3) then begin
  1528. origlat=-90.
  1529. if (yrange(0) gt 0) then yrange(0)=-90
  1530. if (yrange(1) gt 0) then yrange(1)=-45
  1531. endif
  1532. ;scale=0.35
  1533. smap = map_proj_init('Polar Stereographic')
  1534. endif
  1535. ; select points to plot
  1536. typestr=""
  1537. spawn,'echo plotpoints 1 `date`'
  1538. selpoints, stash, lonsel, latsel, innovsel, qcsel, daysel, obstypsel, obnumsel, numsel, typestr
  1539. spawn,'echo plotpoints 2 `date`'
  1540. if (stash.txt eq 0 and stash.netcdf eq 0) then begin
  1541. nelsel=n_elements(innovsel)
  1542. nptsstr=strtrim(string(nelsel),2)
  1543. print,nptsstr, nelsel
  1544. ; if (nelsel gt 0) then begin
  1545. ;convert lats and lons to projection positions
  1546. ; if (nelsel gt 0) then begin
  1547. ; print,'min/max lonsel: ',min(lonsel),max(lonsel)
  1548. ; if (typeproj ne 1) then begin
  1549. ; coords = map_proj_forward(lonsel,latsel,MAP=smap)
  1550. ; lonsel=coords(0,*)
  1551. ; latsel=coords(1,*)
  1552. ; endif
  1553. ; endif
  1554. print,'nelsel: ',nelsel
  1555. nelinnov=n_elements(innovsel)
  1556. print,'nelinnov: ',nelinnov
  1557. jul_to_dtstr, daymin, dateminstr, /notime
  1558. jul_to_dtstr, daymax, datemaxstr, /notime
  1559. strtsal=''
  1560. ; print,'stash.filetype ',stash.filetype
  1561. if (stash.filetype eq "Prof" or stash.filetype eq "feedback") then begin
  1562. strtsal='T: '
  1563. if (stash.salinity eq 1) then strtsal='S: '
  1564. if (stash.density eq 1) then strtsal='Density: '
  1565. if (stash.mld eq 1) then strtsal='MLD: '
  1566. endif else begin
  1567. if (stash.filetype eq "CRT") then begin
  1568. strtsal='U: '
  1569. if (stash.salinity eq 1) then strtsal='V: '
  1570. if (stash.density eq 1) then strtsal='Speed: '
  1571. if (stash.salinity eq 1 and stash.density eq 1) then strtsal='Total Speed: '
  1572. endif else begin
  1573. strtsal=stash.filetype+': '
  1574. endelse
  1575. endelse
  1576. if (stash.vertgrad eq 1) then strtsal='Grad '+strtsal
  1577. nptsstr2='Points: '+nptsstr+' '
  1578. titlestr=strtsal+typestr+': '+dateminstr+' to '+datemaxstr
  1579. print,'titlestr ',titlestr
  1580. ; get max and min values
  1581. mx=0
  1582. mn=0
  1583. meaninnov=0
  1584. rmsinnov=0
  1585. if (nelinnov gt 0) then begin
  1586. ; NB these values are just the rms and mean of the points plotted...
  1587. ; and do not take account of the datapoints used in profiles plotted...
  1588. mx=max(innovsel)
  1589. mn=min(innovsel)
  1590. meaninnov=avg(innovsel)
  1591. rmsinnov=sqrt(avg(innovsel^2))
  1592. ; n=total(numsel)
  1593. ; wh=where(numsel gt 0)
  1594. ; print, 'innovsel: ',max(innovsel), min(innovsel)
  1595. ; print, 'numsel: ',max(numsel), min(numsel)
  1596. ; if (n gt 0) then begin
  1597. ; x=total(innovsel(wh)*numsel(wh))
  1598. ; x2=total(innovsel(wh)^2*numsel(wh))
  1599. ; meaninnov=x/n
  1600. ; rmsinnov=sqrt(x2/n)
  1601. ; endif
  1602. endif
  1603. subtitle=''
  1604. subtitle=nptsstr2+'depths: '+strtrim(string(long(stash.depmin)),2)+'-'+$
  1605. strtrim(string(long(stash.depmax)),2)
  1606. if (stash.obstypeselect ne "") then subtitle=subtitle+' filtered type: '+stash.obstypeselect
  1607. subtitle=subtitle+' extrema: '+$
  1608. strtrim(string(mn,format='(G0.4)'),2)+', '+strtrim(string(mx,format='(G0.4)'),2)
  1609. subtitle=subtitle+' mean: '+strtrim(string(meaninnov,format='(G0.4)'))+$
  1610. ' rms: '+strtrim(string(rmsinnov,format='(G0.4)'))
  1611. ; print,'noerase ',noerase
  1612. if (typeproj ne 1) then begin
  1613. map_set, /STEREOGRAPHIC, origlat, 0, /continents, title=titlestr+'!C'+subtitle, $
  1614. ymargin=[10.,5.], /label, latlab=xrange(0), lonlab=yrange(0), $
  1615. limit=[yrange(0),xrange(0),yrange(1),xrange(1)],/isotropic, hires=stash.hires_map, noerase=noerase
  1616. endif else begin
  1617. P0lon=0
  1618. P0lat=0
  1619. if (xrange(1) gt 180) then P0lon=180
  1620. print,'ranges: ',yrange(0),xrange(0),yrange(1),xrange(1)
  1621. map_set, P0lat, P0lon, /continents, title=titlestr+'!C'+subtitle, $
  1622. ymargin=[10.,5.], /label, latlab=xrange(0), lonlab=yrange(0), $
  1623. limit=[yrange(0),xrange(0),yrange(1),xrange(1)],/isotropic, hires=stash.hires_map, noerase=noerase
  1624. endelse
  1625. if (nelsel eq 0 or nelinnov eq 0) then begin
  1626. ; pp_contour,fld,title=titlestr,/nodata, /proportional, map_file=map_file
  1627. endif else begin
  1628. ; pp_contour,fld,title=titlestr,/nodata, /proportional, map_file=map_file
  1629. if (stash.fmx ne stash.rmdi) then mx=stash.fmx
  1630. if (stash.fmn ne stash.rmdi) then mn=stash.fmn
  1631. print,'setting stash mx/mn'
  1632. stash.mx=mx
  1633. stash.mn=mn
  1634. ; levs=contour_levels([mn,mx],nlevels=15)
  1635. ; levs=findgen(10+1)/10.*(mx-mn)+mn
  1636. print, 'mn mx ',mn,mx
  1637. ;; De-select points outside window?
  1638. ;
  1639. ; xnd= [ -!X.s(0), 1. ]/!X.s(1)
  1640. ; ynd= [ -!Y.s(0), 1. ]/!Y.s(1)
  1641. ; ov=0 ; overlap
  1642. ; clip_data= [ (!ppp.position(0)-ov)*xnd(1) + xnd(0) , $
  1643. ; (!ppp.position(1)-ov)*ynd(1) + ynd(0) , $
  1644. ; (!ppp.position(2)+ov)*xnd(1) + xnd(0) , $
  1645. ; (!ppp.position(3)+ov)*ynd(1) + ynd(0) ]
  1646. ;
  1647. ; wh=where(lonsel ge clip_data(0) and lonsel le clip_data(2) and $
  1648. ; latsel ge clip_data(1) and latsel le clip_data(3))
  1649. ; if (wh(0) gt -1) then begin
  1650. ; latsel=latsel(wh)
  1651. ; lonsel=lonsel(wh)
  1652. ; innovsel=innovsel(wh)
  1653. ; endif
  1654. print,'daymin=',daymin
  1655. print,'daymax=',daymax
  1656. ; print,dayarr(wh)
  1657. ; titlestr=typestr+': '+titlestr
  1658. mx=max(innovsel)
  1659. mn=min(innovsel)
  1660. if (stash.fmx ne stash.rmdi) then mx=stash.fmx
  1661. if (stash.fmn ne stash.rmdi) then mn=stash.fmn
  1662. ; stash.mx=mx
  1663. ; stash.mn=mn
  1664. ; levs=contour_levels([mn,mx],nlevels=30)
  1665. levs=findgen(15)/15.*(mx-mn)+mn
  1666. print, 'typeproj: ',typeproj
  1667. ; wh=sort(innovsel)
  1668. ; print,'innovsel ',innovsel(wh)
  1669. clr=fix((innovsel-mn)/(mx-mn)*(num_cols-1))+1
  1670. ; prevent colours going out of range
  1671. wh=where(clr lt 1)
  1672. if (wh(0) gt -1) then clr(wh)=1
  1673. wh=where(clr gt num_cols)
  1674. if (wh(0) gt -1) then clr(wh)=num_cols
  1675. ; print,'clr ',clr(wh)
  1676. case stash.sym of
  1677. 1: USERSYM, [-1,-1,1,1,-1],[1,-1,-1,1,1], /FILL
  1678. 2: usersym, cos(2.0*!pi*indgen(17)/16.0), sin(2.0*!pi*indgen(17)/16.0), thick=2.0, /fill
  1679. endcase
  1680. spawn,'echo plotpoints 3 `date`'
  1681. ;; rgb=transpose(reform(color24_to_rgb(clr),nelwh,3))
  1682. symsize=stash.symsize*stash.symscale
  1683. ; for i=0L,nelsel-1 do $
  1684. ; plots,lonsel(i),latsel(i),psym=8,color=clr,symsize=symsize
  1685. if (stash.bindata eq 0) then begin
  1686. plots,lonsel,latsel,psym=8,color=clr,symsize=symsize,noclip=0
  1687. ; plots,lonsel,latsel,psym=3,color=clr
  1688. ; print, 'lonsel latsel'
  1689. ; print,lonsel, format='(4g20.10)'
  1690. ; print,latsel, format='(4g20.10)'
  1691. endif
  1692. ; print, 'lonseld latseld'
  1693. ; print,lonsel - lonsel(0), format='(4g20.10)'
  1694. ; print,latsel - latsel(0), format='(4g20.10)'
  1695. ; wh=where(lonsel eq lonsel(0) and latsel eq latsel(0))
  1696. ; print,wh
  1697. endelse
  1698. spawn,'echo plotpoints 4 `date`'
  1699. print,"stash.symsize ",stash.symsize
  1700. print,'limit=',[yrange(0),xrange(0),yrange(1),xrange(1)]
  1701. ; endif ; nel lonsel > 0
  1702. if (stash.bindata) then begin
  1703. fillval=-32000
  1704. mxlat=max(latsel)
  1705. mnlat=min(latsel)
  1706. mxlon=max(lonsel)
  1707. mnlon=min(lonsel)
  1708. dlon=stash.binsize(0)
  1709. dlat=stash.binsize(1)
  1710. nlats=(mxlat-mnlat)/dlat+1
  1711. nlons=(mxlon-mnlon)/dlon+1
  1712. print,'nlons ',nlons,' nlats ',nlats
  1713. if (nlats ge 2 and nlons ge 2) then begin
  1714. innovsel2=fltarr(nlons,nlats)
  1715. ; latsel2=fltarr(nlons,nlats)
  1716. ; lonsel2=fltarr(nlons,nlats)
  1717. latsel2=findgen(nlats)*dlat+mnlat
  1718. lonsel2=findgen(nlons)*dlon+mnlon
  1719. innovsel2(*)=fillval ; missing data
  1720. ; latsel2(*)=fillval
  1721. ; lonsel2(*)=fillval
  1722. nelin=n_elements(innovsel)
  1723. print,mnlat,mnlon
  1724. iiarr=(lonsel-mnlon)/dlon
  1725. ijarr=(latsel-mnlat)/dlat
  1726. print,min(ijarr),max(ijarr),min(ijarr),max(ijarr)
  1727. info,latsel2
  1728. info,lonsel2
  1729. for i=0L,nelin-1 do begin
  1730. ii=iiarr(i)
  1731. iip=ii+1
  1732. if (iip ge nlons-1) then iip=ii
  1733. iim=ii-1
  1734. if (iim lt 0) then iim=0
  1735. ij=ijarr(i)
  1736. ijp=ij+1
  1737. if (ijp ge nlats-1) then ijp=ij
  1738. ijm=ij-1
  1739. if (ijm lt 0) then ijm=0
  1740. innovsel2(ii,ij)=innovsel(i)
  1741. ; fill in gaps
  1742. if (innovsel2(iip,ij) eq fillval) then innovsel2(iip,ij)=innovsel(i)
  1743. if (innovsel2(ii,ijp) eq fillval) then innovsel2(ii,ijp)=innovsel(i)
  1744. if (innovsel2(iim,ij) eq fillval) then innovsel2(iim,ij)=innovsel(i)
  1745. if (innovsel2(ii,ijm) eq fillval) then innovsel2(ii,ijm)=innovsel(i)
  1746. ; latsel2(ii,ij)=latsel(i)
  1747. ; lonsel2(ii,ij)=lonsel(i)
  1748. endfor
  1749. info,latsel2
  1750. print,latsel2
  1751. info,lonsel2
  1752. print,lonsel2
  1753. TVLCT, R, G, B, /get
  1754. TVLCT,R(1),G(1),B(1),0 ; bodge fix for wrong black contour
  1755. wh=where(innovsel2 gt mx-(mx-mn)*0.001 and innovsel2 ne fillval)
  1756. if (wh(0) gt -1) then innovsel2(wh)=mx-(mx-mn)*0.001
  1757. wh=where(innovsel2 lt mn and innovsel2 ne fillval)
  1758. if (wh(0) gt -1) then innovsel2(wh)=mn
  1759. levs2=nice_contourlevels([mn,mx],nlevels=50)
  1760. contour,innovsel2,lonsel2,latsel2,levels=levs2, /overplot, /cell_fill, min_value=-1000
  1761. TVLCT,R(0),G(0),B(0),0 ; restore original colour table
  1762. endif
  1763. endif
  1764. if (daymin eq daymax and daymin eq 0) then begin
  1765. print,'No data file'
  1766. xyouts, 0.15, 0.5, 'No data files', /normal, charsize=8
  1767. endif
  1768. ; plot colorbar
  1769. levs=nice_contourlevels([mn,mx],nlevels=10)
  1770. print, levs
  1771. barclr=findgen(num_cols)+1
  1772. colorbar_idl, [mn,mx], barclr, levs
  1773. endif ; stash.txt eq 0
  1774. stash.busy=0
  1775. if (stash.pmulti eq 2) then begin
  1776. typeproj=stash.typeproj
  1777. print, 'old stash.typeproj: ',stash.typeproj
  1778. if (typeproj eq 2) then stash.typeproj=3 ;plot north and south poles
  1779. if (typeproj eq 3) then stash.typeproj=2
  1780. print, 'new stash.typeproj: ',stash.typeproj
  1781. endif
  1782. endfor ; nplots
  1783. end
  1784. ;------------------------------------------
  1785. ;Profile plotting window and event handling
  1786. ;------------------------------------------
  1787. PRO profilewindow_event, ev
  1788. WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash2
  1789. WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
  1790. print,uval
  1791. if (uval eq "PRINTPW") then begin
  1792. ps=1
  1793. eps=0
  1794. landscape=1
  1795. pr2,file="~/plotprofile.ps",landscape=landscape,ps=ps,eps=eps,color=1
  1796. plotprofile,stash2
  1797. prend2,/view
  1798. endif
  1799. if (uval eq "SAVEPW") then begin
  1800. thisDevice = !D.Name
  1801. psave=!p
  1802. Set_Plot, 'Z' ; do graphics in the background
  1803. Device, Set_Resolution=[640,480] ; clear any existing stuff
  1804. !p.charsize=0.75
  1805. if (stash2.white_on_black eq 0) then begin
  1806. ; flip background and foreground color
  1807. pcolor=!p.color
  1808. pbackground=!p.background
  1809. !p.color=pbackground
  1810. !p.background=pcolor
  1811. endif
  1812. print,'!p.color,!p.background ',!p.color,!p.background
  1813. setupct, r, g, b, $
  1814. coltable=stash2.coltable,white_on_black=stash2.white_on_black ; setup color table
  1815. ; plot data
  1816. plotprofile,stash2
  1817. snapshot = TVRD()
  1818. WRITE_GIF,"~/plotprofile.gif",snapshot, r, g, b
  1819. Device, Z_Buffer=1 ; reset graphics mode
  1820. Set_Plot, thisDevice
  1821. !p=psave
  1822. spawn,'xv ~/plotprofile.gif'
  1823. endif
  1824. if (uval eq "TXTPW") then begin
  1825. plotprofile,stash2,/txt
  1826. endif
  1827. end
  1828. PRO plotprofile,stash2, txt=txt
  1829. if (n_elements(txt) eq 0) then txt=0
  1830. ;** need to deal with multiple times
  1831. dep2=stash2.dep2
  1832. val2=stash2.val2
  1833. obs2=stash2.obs2
  1834. bkg2=stash2.bkg2
  1835. obstype2=stash2.obstype2
  1836. qcarr2=stash2.qcarr2
  1837. dayarr2=stash2.dayarr2
  1838. datestr=stash2.datestr
  1839. xselstr=stash2.xselstr
  1840. yselstr=stash2.yselstr
  1841. rmdi=stash2.rmdi
  1842. multstr=""
  1843. mindayarr2=min(dayarr2,max=maxdayarr2)
  1844. whs=sort(dayarr2)
  1845. u=uniq(dayarr2)
  1846. nu=n_elements(u)
  1847. dayarr2u=dayarr2(u)
  1848. print,'dayarr2u: ',dayarr2u
  1849. if (maxdayarr2 ne mindayarr2) then multstr="mult times "+strtrim(string(nu),2)
  1850. ; print,'obstype2 ',obstype2
  1851. print,'profile plot_bad_obs: ',stash2.plot_bad_obs
  1852. print, obs2
  1853. print, bkg2
  1854. print, qcarr2
  1855. if (stash2.plot_bad_obs eq 0) then begin
  1856. wh=where(obs2 ne rmdi and qcarr2 eq 0)
  1857. endif else begin
  1858. ; wh=where(obs2 eq obs2)
  1859. wh=where(obs2 ne rmdi)
  1860. endelse
  1861. if (wh(0) gt -1) then begin
  1862. depo1=dep2(wh)
  1863. valo1=val2(wh)
  1864. obso1=obs2(wh)
  1865. bkgo1=bkg2(wh)
  1866. qcarro1=qcarr2(wh)
  1867. endif
  1868. if (stash2.plot_bad_obs eq 0) then begin
  1869. wh=where(bkg2 ne rmdi and qcarr2 eq 0)
  1870. endif else begin
  1871. ; wh=where(bkg2 eq bkg2)
  1872. wh=where(bkg2 ne rmdi)
  1873. endelse
  1874. if (wh(0) gt -1) then begin
  1875. depb1=dep2(wh)
  1876. valb1=val2(wh)
  1877. obsb1=obs2(wh)
  1878. bkgb1=bkg2(wh)
  1879. qcarrb1=qcarr2(wh)
  1880. endif
  1881. ;loop thru times
  1882. if (n_elements(bkgb1) gt 0) then begin
  1883. xmx=max([obso1,bkgb1],min=xmn)
  1884. ymx=max([depo1,depb1],min=ymn)
  1885. endif else begin
  1886. xmx=max(obso1,min=xmn)
  1887. ymx=max(depo1,min=ymn)
  1888. endelse
  1889. ; set max and min depth based on selection of depths from the main window
  1890. if (ymx gt stash2.depmax) then ymx=stash2.depmax
  1891. if (ymn lt stash2.depmin) then ymn=stash2.depmin
  1892. ; reset xrange based on new ymx and ymn
  1893. if (n_elements(bkgb1) gt 0) then begin
  1894. wh1=where(depo1 ge ymn and depo1 le ymx)
  1895. wh2=where(depb1 ge ymn and depb1 le ymx)
  1896. if (wh1(0) gt -1 and wh2(0) gt -1) then xmx=max([obso1(wh1),bkgb1(wh2)],min=xmn)
  1897. endif else begin
  1898. wh1=where(depo1 ge ymn and depo1 le ymx)
  1899. if (wh1(0) gt -1) then xmx=max(obso1(wh1),min=xmn)
  1900. endelse
  1901. ; add a little bit to xrange to make plots look better
  1902. if (xmn eq xmx) then begin
  1903. xmn=xmn-0.5
  1904. xmx=xmx+0.5
  1905. endif
  1906. dxrange=(xmx-xmn)*0.02
  1907. xmx=xmx+dxrange
  1908. xmn=xmn-dxrange
  1909. ; add a little bit to yrange to make plots look better
  1910. if (ymn eq ymx) then begin
  1911. ymn=ymn-0.5
  1912. ymx=ymx+0.5
  1913. endif
  1914. dyrange=(ymx-ymn)*0.01
  1915. ymx=ymx+dyrange
  1916. ymn=ymn-dyrange
  1917. print,'** yrange: ',ymn, ymx
  1918. if (txt eq 1) then begin
  1919. outfile='dataplot_profile.txt'
  1920. print, 'saving data to ',outfile
  1921. OPENW, unit, outfile, /get_lun
  1922. endif
  1923. for t=0,nu-1 do begin ; loop through times
  1924. wht=where(dayarr2 eq dayarr2u(t))
  1925. depo=depo1(wht)
  1926. valo=valo1(wht)
  1927. obso=obso1(wht)
  1928. bkgo=bkgo1(wht)
  1929. qcarro=qcarro1(wht)
  1930. dayarro=dayarr2(wht)
  1931. if (n_elements(depb1) gt 0) then depb=depb1(wht)
  1932. if (n_elements(valb1) gt 0) then valb=valb1(wht)
  1933. if (n_elements(obsb1) gt 0) then obsb=obsb1(wht)
  1934. if (n_elements(bkgb1) gt 0) then bkgb=bkgb1(wht)
  1935. if (n_elements(qcarrb1) gt 0) then qcarrb=qcarrb1(wht)
  1936. ;print data
  1937. ; if (txt eq 1) then begin
  1938. ; print,'rmdi: ',rmdi
  1939. ; print,'profile data'
  1940. ; for i=0,n_elements(depo)-1 do begin
  1941. ; print,depo(i),obso(i),bkgo(i),qcarro(i)
  1942. ; endfor
  1943. ; print,'profile data'
  1944. ; for i=0,n_elements(depb)-1 do begin
  1945. ; print,depb(i),obsb(i),bkgb(i),qcarrb(i)
  1946. ; endfor
  1947. ; endif
  1948. typestr="type: "+string(obstype2(0))
  1949. ;get variable type
  1950. vartype=size(obstype2,/type)
  1951. if (vartype ne 7) then begin
  1952. if (obstype2(0) eq rmdi) then typestr=""
  1953. endif
  1954. ; line thickness
  1955. thick1=2
  1956. thick2=2
  1957. ; color1='FFCC66'x
  1958. color1=102
  1959. color2=!p.color
  1960. color3=234
  1961. linestyle1=0
  1962. linestyle2=0
  1963. who=sort(depo)
  1964. whb=sort(depb)
  1965. obso_srto=obso(who)
  1966. depo_srto=depo(who)
  1967. qcarro_srto=qcarro(who)
  1968. whbad=where(qcarro ne 0)
  1969. if (txt eq 0) then begin
  1970. if (t eq 0) then $
  1971. plot,obso_srto,depo_srto,ystyle=1,xstyle=1,linestyle=linestyle1,$
  1972. xrange=[xmn,xmx],yrange=[ymx,ymn],thick=thick1, $
  1973. psym=-4,ytitle='Level',xtitle='Value', $
  1974. title=datestr+" "+multstr+" ("+xselstr+","+yselstr+") "+typestr, /nodata
  1975. oplot,obso_srto,depo_srto,linestyle=linestyle1,psym=-4, thick=thick1, color=color1
  1976. if (whbad(0) gt -1) then begin
  1977. oplot,obso_srto(whbad),depo_srto(whbad),psym=4, thick=thick1, color=color3
  1978. oplot,obso_srto(whbad),depo_srto(whbad),psym=1, thick=thick1, color=color3
  1979. endif
  1980. if (n_elements(bkgb) gt 0) then oplot,bkgb(whb),depb(whb),psym=-5,thick=thick2, color=color2,$
  1981. linestyle=linestyle2
  1982. xcoord=0.8
  1983. ycoord=0.2
  1984. ; if (stash2.salinity eq 1) then xcoord=0.15 ; left corner legend for salinity
  1985. nel=n_elements(who)
  1986. if (obso(who(0)) lt obso(who(nel-1))) then xcoord=0.15
  1987. if (t eq 0) then $
  1988. ycoord2=ycoord-0.05
  1989. xcoord2=xcoord+0.03
  1990. xcoord3=xcoord+0.05
  1991. plots, [xcoord,xcoord2],[ycoord,ycoord], psym=-4, linestyle=linestyle1, /normal, $
  1992. thick=thick1, color=color1
  1993. xyouts, xcoord+0.05, ycoord, 'obs', /normal
  1994. plots, [xcoord,xcoord2],[ycoord2,ycoord2], psym=-5, linestyle=linestyle2, /normal, $
  1995. thick=thick2, color=color2
  1996. xyouts, xcoord+0.05, ycoord2, 'bkg',/normal
  1997. endif else begin ; txt
  1998. printf, unit,'observations ',n_elements(who)
  1999. for i=0L,n_elements(who)-1 do begin
  2000. printf, unit, depo(i), obso(i), dayarro(i), format='(3f18.5)'
  2001. endfor
  2002. printf, unit, 'background ',n_elements(who)
  2003. for i=0L,n_elements(whb)-1 do begin
  2004. printf, unit, depb(i), bkgb(i), dayarro(i), format='(3f18.5)'
  2005. endfor
  2006. endelse
  2007. endfor ; t
  2008. if (txt eq 1) then FREE_LUN, unit
  2009. end
  2010. PRO profilewindow,dep2,val2,obs2,bkg2,obstype2,qcarr2,dayarr2,datestr,xselstr,yselstr,rmdi,salinity=salinity, $
  2011. plot_bad_obs=plot_bad_obs, density=density, white_on_black=white_on_black, coltable=coltable, $
  2012. depmax=depmax, depmin=depmin
  2013. basepw=WIDGET_BASE(/column)
  2014. drawpw = WIDGET_DRAW(basepw, XSIZE=640, YSIZE=480)
  2015. buttonBase = Widget_Base(basepw, Row=1)
  2016. buttonpw = WIDGET_BUTTON(buttonBase, VALUE='Print',uvalue="PRINTPW")
  2017. button2pw = WIDGET_BUTTON(buttonBase, VALUE='Save',uvalue="SAVEPW")
  2018. button3pw = WIDGET_BUTTON(buttonBase, VALUE='Text file',uvalue="TXTPW")
  2019. WIDGET_CONTROL, basepw, /REALIZE
  2020. if (n_elements(salinity) eq 0) then salinity=0
  2021. if (n_elements(density) eq 0) then density=0
  2022. if (n_elements(plot_bad_obs) eq 0) then plot_bad_obs=0
  2023. if (n_elements(white_on_black) eq 0) then white_on_black=1
  2024. stash2 = { dep2:dep2,val2:val2,obs2:obs2, bkg2:bkg2, $
  2025. obstype2:obstype2, qcarr2:qcarr2, dayarr2:dayarr2, $
  2026. datestr:datestr,xselstr:xselstr, yselstr:yselstr, $
  2027. rmdi:rmdi, salinity:salinity, plot_bad_obs:plot_bad_obs,$
  2028. density:density, white_on_black:white_on_black, $
  2029. coltable:coltable, depmax:depmax, depmin:depmin }
  2030. plotprofile,stash2
  2031. WIDGET_CONTROL, basepw, SET_UVALUE=stash2
  2032. XMANAGER, 'profilewindow', basepw, /NO_BLOCK
  2033. end
  2034. ;---------------------------------------
  2035. ;Worst points, window and event handling
  2036. ;---------------------------------------
  2037. PRO worstpoints,stash2
  2038. ;stash2 is a combination of main stash and worstpoints specific stuff
  2039. xrange=stash2.xrange
  2040. yrange=stash2.yrange
  2041. selpoints,stash2,lonsel, latsel, innovsel, qcsel, daysel, obstypsel, obnumsel, obnumsel, numsel, typestr
  2042. str1='Worst points in '+$
  2043. ' lons ('+strtrim(string(xrange(0)),2)+','+strtrim(string(xrange(1)),2)+$
  2044. ') lats ('+strtrim(string(yrange(0)),2)+','+strtrim(string(yrange(1)),2)+')'+$
  2045. ' depths '+strtrim(string(long(stash2.depmin)),2)+'-'+strtrim(string(long(stash2.depmax)),2)
  2046. print,str1
  2047. WIDGET_CONTROL, stash2.wwlabel1, set_value=str1
  2048. count=n_elements(innovsel)
  2049. wh=sort(abs(innovsel))
  2050. wh0=reverse(wh) ; reverse order starting with the largest
  2051. cmax=min([count,10])
  2052. stash2.lonselw(0:cmax-1)=lonsel(wh0(0:cmax-1))
  2053. stash2.latselw(0:cmax-1)=latsel(wh0(0:cmax-1))
  2054. stash2.dayselw(0:cmax-1)=daysel(wh0(0:cmax-1))
  2055. print,'lon lat '+typestr+' qc date '
  2056. for j1=1,cmax do begin
  2057. j=j1-1
  2058. jul_to_dtstr,daysel(wh0(j)),datestr
  2059. ; datedt=jul_to_dt(daysel(wh0(j)))
  2060. ; datestr=strtrim(fix(datedt.year),2)+'/'+ $
  2061. ; strtrim(string(fix(datedt.month),format='(i2.2)'),2)+'/'+ $
  2062. ; strtrim(string(fix(datedt.day),format='(i2.2)'),2)+' '+ $
  2063. ; strtrim(string(fix(datedt.hour),format='(i2.2)'),2)+':'+ $
  2064. ; strtrim(string(fix(datedt.minute),format='(i2.2)'),2)+':'+ $
  2065. ; strtrim(string(fix(datedt.second),format='(i2.2)'),2)
  2066. print,lonsel(wh0(j)),latsel(wh0(j)),innovsel(wh0(j)),$
  2067. qcsel(wh0(j)),' ',datestr
  2068. endfor
  2069. if (n_elements(stash2) gt 0) then begin
  2070. i=0
  2071. WIDGET_CONTROL, stash2.labels2(i,0), set_value="Lon" & i=i+1
  2072. WIDGET_CONTROL, stash2.labels2(i,0), set_value="Lat" & i=i+1
  2073. WIDGET_CONTROL, stash2.labels2(i,0), set_value=typestr & i=i+1
  2074. WIDGET_CONTROL, stash2.labels2(i,0), set_value="QC" & i=i+1
  2075. WIDGET_CONTROL, stash2.labels2(i,0), set_value="Date" & i=i+1
  2076. for j1=1,cmax do begin
  2077. j=j1-1
  2078. jul_to_dtstr,daysel(wh0(j)),datestr
  2079. ; datedt=jul_to_dt(daysel(wh0(j)))
  2080. ; datestr=strtrim(fix(datedt.year),2)+'/'+ $
  2081. ; strtrim(string(fix(datedt.month),format='(i2.2)'),2)+'/'+ $
  2082. ; strtrim(string(fix(datedt.day),format='(i2.2)'),2)+' '+ $
  2083. ; strtrim(string(fix(datedt.hour),format='(i2.2)'),2)+':'+ $
  2084. ; strtrim(string(fix(datedt.minute),format='(i2.2)'),2)+':'+ $
  2085. ; strtrim(string(fix(datedt.second),format='(i2.2)'),2)
  2086. i=0
  2087. WIDGET_CONTROL, stash2.labels2(i,j1), $
  2088. set_value=strtrim(string(lonsel(wh0(j)),format='(f9.3)'),2) & i=i+1
  2089. WIDGET_CONTROL, stash2.labels2(i,j1), $
  2090. set_value=strtrim(string(latsel(wh0(j)),format='(f9.3)'),2) & i=i+1
  2091. WIDGET_CONTROL, stash2.labels2(i,j1), set_value=strtrim(string(innovsel(wh0(j))),2) & i=i+1
  2092. WIDGET_CONTROL, stash2.labels2(i,j1), set_value=strtrim(string(qcsel(wh0(j))),2) & i=i+1
  2093. WIDGET_CONTROL, stash2.labels2(i,j1), set_value=strtrim(datestr,2) & i=i+1
  2094. ; print,lonsel(wh0(j)),latsel(wh0(j)),innovsel(wh0(j)),$
  2095. ; qcsel(wh0(j)),' ',datestr
  2096. endfor
  2097. endif
  2098. end
  2099. pro worstpointswindow,stash
  2100. basepw=WIDGET_BASE(/column)
  2101. ; drawpw = WIDGET_DRAW(basepw, XSIZE=640, YSIZE=480)
  2102. wwlabel1 = WIDGET_LABEL(basepw, XSIZE=480, VALUE="Worst points")
  2103. nj=11
  2104. ni=5
  2105. labels=intarr(nj)
  2106. for j=0,nj-1 do begin
  2107. labels(j)=Widget_Base(basepw,row=1)
  2108. endfor
  2109. labsiz=[50,50,50,50,125]
  2110. labels2=intarr(ni+2,nj)
  2111. for j=0,nj-1 do begin
  2112. for i=0,ni-1 do begin
  2113. labels2(i,j) = WIDGET_LABEL(labels(j), XSIZE=labsiz(i), $
  2114. VALUE="a")
  2115. endfor
  2116. if (j gt 0) then begin
  2117. labels2(i,j) = WIDGET_BUTTON(labels(j), VALUE='Zoom to', uvalue="Zoom to "+strtrim(string(j),2))
  2118. labels2(i+1,j) = WIDGET_BUTTON(labels(j), VALUE='Profile', uvalue="Profile "+strtrim(string(j),2))
  2119. endif
  2120. endfor
  2121. stashb={ wwlabel1:wwlabel1, labels2:labels2, ni:ni, nj:nj, lonselw:dblarr(10), latselw:dblarr(10), dayselw:dblarr(10)}
  2122. stash2=CREATE_STRUCT(stash,stashb)
  2123. buttonpw = WIDGET_BUTTON(basepw, VALUE='Print',uvalue="PRINTPW")
  2124. WIDGET_CONTROL, basepw, /REALIZE
  2125. worstpoints,stash2
  2126. WIDGET_CONTROL, basepw, SET_UVALUE=stash2
  2127. XMANAGER, 'worstpointswindow', basepw, /NO_BLOCK
  2128. end
  2129. PRO worstpointswindow_event, ev
  2130. WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash2
  2131. WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
  2132. print,uval
  2133. xarr1=stash2.xarr
  2134. yarr1=stash2.yarr
  2135. dep1=stash2.dep
  2136. dayarr=stash2.dayarr
  2137. daymin=stash2.daymin
  2138. daymax=stash2.daymax
  2139. obstypes1=stash2.obstypes
  2140. xrange=stash2.xrange
  2141. yrange=stash2.yrange
  2142. xs=xrange(1)-xrange(0)
  2143. ys=yrange(1)-yrange(0)
  2144. rmdi=stash2.rmdi
  2145. if (stash2.salinity eq 0) then begin
  2146. obs1=stash2.obs
  2147. bkg1=stash2.bkg
  2148. qcarr1=stash2.qcarr
  2149. endif else begin
  2150. obs1=stash2.obs2
  2151. bkg1=stash2.bkg2
  2152. qcarr1=stash2.qcarr2
  2153. endelse
  2154. if (uval eq "PRINTTSW") then begin
  2155. ps=1
  2156. eps=0
  2157. landscape=1
  2158. pr2,file="~/worstpoints.ps",landscape=landscape,ps=ps,eps=eps,color=1
  2159. worstpoints,stash2
  2160. prend2,/view
  2161. endif
  2162. print,strmid(uval,0,7)
  2163. if (strcmp(strmid(uval,0,7),"Zoom to")) then begin
  2164. num=fix(strmid(uval,7,3))
  2165. xsel=stash2.lonselw(num-1)
  2166. ysel=stash2.latselw(num-1)
  2167. print,num,xsel,ysel
  2168. dataplot_zoom,stash2, xsel, ysel, 1
  2169. plotpoints,stash2
  2170. endif
  2171. if (strcmp(strmid(uval,0,7),"Profile")) then begin
  2172. num=fix(strmid(uval,7,3))
  2173. xsel=stash2.lonselw(num-1)
  2174. ysel=stash2.latselw(num-1)
  2175. daysel=stash2.dayselw(num-1)
  2176. ; print,num,xsel,ysel,daysel,daysel-long(daysel),float(daysel)
  2177. ; info,dayarr
  2178. ; info,daysel
  2179. ; info,xarr1
  2180. ; info,ysel
  2181. ; info,yarr1
  2182. ; info,xsel
  2183. wh1=where(xarr1 eq xsel and yarr1 eq ysel)
  2184. ; print,'dayarr(wh1) ',dayarr(wh1), float(dayarr(wh1))
  2185. ; print,'dayarr(wh1)-long ',dayarr(wh1)-long(dayarr(wh1))
  2186. ; print,'dep1(wh1) ',dep1(wh1)
  2187. wh2=where(xarr1 eq xsel and yarr1 eq ysel and float(dayarr) eq float(daysel))
  2188. ; print,'wh2 ',wh2
  2189. ; if (wh2(0) gt -1) then print,'daysel(wh2) ',daysel(wh2)
  2190. wh=where(xarr1 eq xsel and yarr1 eq ysel and long(dayarr) eq long(daysel))
  2191. if (wh(0) gt -1) then begin
  2192. dep2=dep1(wh)
  2193. val2=abs(obs1(wh)-bkg1(wh))
  2194. obs2=obs1(wh)
  2195. bkg2=bkg1(wh)
  2196. obstype2=obstypes1(wh)
  2197. qcarr2=qcarr1(wh)
  2198. dayarr2=dayarr(wh)
  2199. jul_to_dtstr,stash2.dayselw(num-1),datestr
  2200. xselstr=string(xsel)
  2201. yselstr=string(ysel)
  2202. profilewindow,dep2,val2,obs2,bkg2,obstype2,qcarr2,dayarr2,datestr,xselstr,yselstr,rmdi, salinity=stash2.salinity, $
  2203. white_on_black=stash.white_on_black, coltable=stash.coltable, depmax=stash.depmax, depmin=stash.depmin
  2204. endif
  2205. endif
  2206. ; store values
  2207. WIDGET_CONTROL, ev.TOP, SET_UVALUE=stash2
  2208. end
  2209. PRO filterwindow, stash
  2210. val=stash.obstypeselect
  2211. obstypes=stash.obstypes
  2212. uniquetypes=strjoin(obstypes(uniq(obstypes, sort(obstypes))),string(10b))
  2213. base = WIDGET_BASE(GROUP_LEADER=stash.base ,/modal,/column)
  2214. intextid = CW_FIELD(base, TITLE = "Filter type", /FRAME, value=val, uvalue='intext', /RETURN_EVENTS)
  2215. outtextid = WIDGET_TEXT(base, value="Choose from:"+string(10b)+uniquetypes, $
  2216. scr_xsize=200, scr_ysize=200, /scroll)
  2217. buttonBase = Widget_Base(base, Row=1)
  2218. cancelID = Widget_Button(buttonBase, Value='Cancel', uvalue='cancel')
  2219. acceptID = Widget_Button(buttonBase, Value='Accept', uvalue='accept')
  2220. WIDGET_CONTROL, base, /REALIZE
  2221. ptr = Ptr_New({text:"", nocancel:0})
  2222. stash2={ ptr:ptr, intextid:intextid }
  2223. WIDGET_CONTROL, base, SET_UVALUE=stash2, /No_Copy
  2224. XMANAGER, 'filterwindow', base
  2225. theText = (*ptr).text
  2226. nocancel = (*ptr).nocancel
  2227. Ptr_Free, ptr
  2228. print, 'finished ',theText, nocancel
  2229. ; if obstypeselect has changed then replot the points
  2230. if (stash.obstypeselect ne theText and nocancel eq 1) then begin
  2231. stash.obstypeselect=theText
  2232. plotpoints,stash
  2233. endif
  2234. end
  2235. PRO filterwindow_event, ev
  2236. WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash2
  2237. WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
  2238. WIDGET_CONTROL, ev.ID, GET_VALUE=val
  2239. ; info,uval
  2240. ; info,val
  2241. print,uval
  2242. print,val
  2243. if (uval eq "accept" or uval eq "intext") then begin
  2244. ; stash2.val=val
  2245. Widget_Control, stash2.intextid, Get_Value=theText
  2246. print,'the text ',theText
  2247. (*stash2.ptr).text=theText
  2248. (*stash2.ptr).nocancel=1
  2249. endif
  2250. ; WIDGET_CONTROL, ev.TOP, SET_UVALUE=stash2
  2251. WIDGET_CONTROL, ev.top, /DESTROY
  2252. end
  2253. ;--------------------------------------
  2254. ; Input area
  2255. ;--------------------------------------
  2256. PRO inputareawindow, xrange, yrange, toplevel, success
  2257. val1=xrange(0)
  2258. val2=xrange(1)
  2259. val3=yrange(0)
  2260. val4=yrange(1)
  2261. base = WIDGET_BASE(GROUP_LEADER=toplevel,/modal,/column)
  2262. intextid1 = CW_FIELD(base, TITLE = "lon1", /FRAME, value=val1, uvalue='intext1', /RETURN_EVENTS)
  2263. intextid2 = CW_FIELD(base, TITLE = "lon2", /FRAME, value=val2, uvalue='intext2', /RETURN_EVENTS)
  2264. intextid3 = CW_FIELD(base, TITLE = "lat1", /FRAME, value=val3, uvalue='intext3', /RETURN_EVENTS)
  2265. intextid4 = CW_FIELD(base, TITLE = "lat2", /FRAME, value=val4, uvalue='intext4', /RETURN_EVENTS)
  2266. ; outtextid = WIDGET_TEXT(base, value="Choose from:"+string(10b)+uniquetypes, $
  2267. ; scr_xsize=200, scr_ysize=200, /scroll)
  2268. buttonBase = Widget_Base(base, Row=1)
  2269. acceptID = Widget_Button(buttonBase, Value='Accept', uvalue='accept')
  2270. cancelID = Widget_Button(buttonBase, Value='Cancel', uvalue='cancel')
  2271. WIDGET_CONTROL, base, /REALIZE
  2272. ptr = Ptr_New({text1:"", text2:"", text3:"", text4:"", nocancel:0})
  2273. stash2={ ptr:ptr, intextid1:intextid1, intextid2:intextid2, $
  2274. intextid3:intextid3, intextid4:intextid4}
  2275. WIDGET_CONTROL, base, SET_UVALUE=stash2, /No_Copy
  2276. XMANAGER, 'inputareawindow', base
  2277. lon1 = (*ptr).text1
  2278. lon2 = (*ptr).text2
  2279. lat1 = (*ptr).text3
  2280. lat2 = (*ptr).text4
  2281. nocancel = (*ptr).nocancel
  2282. Ptr_Free, ptr
  2283. print, 'finished ',lon1, lon2, lat1, lat2, nocancel
  2284. ; if obstypeselect has changed then replot the points
  2285. if (nocancel eq 1) then begin
  2286. xrange=[float(lon1),float(lon2)]
  2287. yrange=[float(lat1),float(lat2)]
  2288. xrange=xrange(sort(xrange))
  2289. yrange=yrange(sort(yrange))
  2290. wh=where(xrange gt 360)
  2291. if (wh(0) gt -1) then xrange(wh)=360
  2292. wh=where(xrange lt -180)
  2293. if (wh(0) gt -1) then xrange(wh)=-180
  2294. wh=where(yrange gt 90)
  2295. if (wh(0) gt -1) then yrange(wh)=90
  2296. wh=where(yrange lt -90)
  2297. if (wh(0) gt -1) then yrange(wh)=-90
  2298. if (xrange(0) eq xrange(1)) then xrange(1)=xrange(1)+0.1
  2299. if (yrange(0) eq yrange(1)) then yrange(1)=yrange(1)+0.1
  2300. success=1
  2301. endif
  2302. end
  2303. PRO inputareawindow_event, ev
  2304. WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash2
  2305. WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
  2306. WIDGET_CONTROL, ev.ID, GET_VALUE=val
  2307. ; info,uval
  2308. ; info,val
  2309. print,uval
  2310. print,val
  2311. if (uval eq 'accept') then begin
  2312. ; stash2.val=val
  2313. Widget_Control, stash2.intextid1, Get_Value=theText1
  2314. Widget_Control, stash2.intextid2, Get_Value=theText2
  2315. Widget_Control, stash2.intextid3, Get_Value=theText3
  2316. Widget_Control, stash2.intextid4, Get_Value=theText4
  2317. print,'the text ',theText1, theText2, theText3, theText4
  2318. (*stash2.ptr).text1=theText1
  2319. (*stash2.ptr).text2=theText2
  2320. (*stash2.ptr).text3=theText3
  2321. (*stash2.ptr).text4=theText4
  2322. (*stash2.ptr).nocancel=1
  2323. endif
  2324. ; WIDGET_CONTROL, ev.TOP, SET_UVALUE=stash2
  2325. WIDGET_CONTROL, ev.top, /DESTROY
  2326. end
  2327. ;--------------------------------------
  2328. ; Input max min
  2329. ;--------------------------------------
  2330. PRO inputmxmnwindow, fmx, fmn, mx, mn, rmdi, toplevel, success
  2331. print,'fmx/mn ',fmx,fmn
  2332. print,'mx/mn ',mx,mn
  2333. val1=mx
  2334. val2=mn
  2335. base = WIDGET_BASE(GROUP_LEADER=toplevel,/modal,/column)
  2336. intextid1 = CW_FIELD(base, TITLE = "mx", /FRAME, value=val1, uvalue='intext1', /RETURN_EVENTS)
  2337. intextid2 = CW_FIELD(base, TITLE = "mn", /FRAME, value=val2, uvalue='intext2', /RETURN_EVENTS)
  2338. text="Max and min not locked"
  2339. if (fmx ne rmdi) then text="Max locked"
  2340. if (fmn ne rmdi) then text="Min Locked"
  2341. if (fmx ne rmdi and fmn ne rmdi) then text="Max and min locked"
  2342. outtextid = WIDGET_TEXT(base, value=text, $
  2343. scr_xsize=200, scr_ysize=40)
  2344. buttonBase = Widget_Base(base, Row=1)
  2345. acceptID = Widget_Button(buttonBase, Value='Accept/lock', uvalue='accept')
  2346. resetID = Widget_Button(buttonBase, Value='Reset/free', uvalue='reset')
  2347. cancelID = Widget_Button(buttonBase, Value='Cancel', uvalue='cancel')
  2348. WIDGET_CONTROL, base, /REALIZE
  2349. ptr = Ptr_New({text1:"", text2:"", nocancel:0})
  2350. stash2={ ptr:ptr, intextid1:intextid1, intextid2:intextid2}
  2351. WIDGET_CONTROL, base, SET_UVALUE=stash2, /No_Copy
  2352. XMANAGER, 'inputmxmnwindow', base
  2353. fmx = float((*ptr).text1)
  2354. fmn = float((*ptr).text2)
  2355. info, fmx
  2356. info, fmn
  2357. nocancel = (*ptr).nocancel
  2358. Ptr_Free, ptr
  2359. print, 'finished ',fmx,fmn, mx, mn
  2360. ; if obstypeselect has changed then replot the points
  2361. if (nocancel eq 1) then begin
  2362. success=1
  2363. endif
  2364. if (nocancel eq 2) then begin
  2365. fmx=rmdi
  2366. fmn=rmdi
  2367. success=1
  2368. endif
  2369. end
  2370. PRO inputmxmnwindow_event, ev
  2371. WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash2
  2372. WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
  2373. WIDGET_CONTROL, ev.ID, GET_VALUE=val
  2374. ; info,uval
  2375. ; info,val
  2376. print,'uval ',uval,' val ',val
  2377. if (uval eq 'accept') then begin
  2378. ; stash2.val=val
  2379. Widget_Control, stash2.intextid1, Get_Value=theText1
  2380. Widget_Control, stash2.intextid2, Get_Value=theText2
  2381. print,'the text ',theText1, theText2
  2382. (*stash2.ptr).text1=theText1
  2383. (*stash2.ptr).text2=theText2
  2384. (*stash2.ptr).nocancel=1
  2385. endif
  2386. if (uval eq 'reset') then begin
  2387. (*stash2.ptr).nocancel=2
  2388. endif
  2389. ; WIDGET_CONTROL, ev.TOP, SET_UVALUE=stash2
  2390. WIDGET_CONTROL, ev.top, /DESTROY
  2391. end
  2392. pro infowindow
  2393. basepw=WIDGET_BASE(/column)
  2394. xsz=360
  2395. iwlabel0 = WIDGET_LABEL(basepw, XSIZE=xsz, VALUE="Dataplot")
  2396. iwlabela = WIDGET_LABEL(basepw, XSIZE=xsz, VALUE="--------")
  2397. iwlabelb = WIDGET_LABEL(basepw, XSIZE=xsz, VALUE="")
  2398. iwlabel1 = WIDGET_LABEL(basepw, XSIZE=xsz, VALUE="To report bugs or for help")
  2399. iwlabel2 = WIDGET_LABEL(basepw, XSIZE=xsz, VALUE="contact Dan Lea")
  2400. iwlabel3 = WIDGET_LABEL(basepw, XSIZE=xsz, VALUE="daniel.lea@metoffice.gov.uk")
  2401. WIDGET_CONTROL, basepw, /REALIZE
  2402. ; WIDGET_CONTROL, basepw, SET_UVALUE=stash2
  2403. ; XMANAGER, 'worstpointswindow', basepw, /NO_BLOCK
  2404. end
  2405. PRO dataplot_zoom, stash, xdata, ydata, zoominout
  2406. xrange=stash.xrange
  2407. yrange=stash.yrange
  2408. xrangedef=stash.xrangedef
  2409. yrangedef=stash.yrangedef
  2410. print,xrange,yrange
  2411. ; zx=xrange(0)
  2412. ; zy=yrange(0)
  2413. sx=xrange(1)-xrange(0)
  2414. sy=yrange(1)-yrange(0)
  2415. sxd=xrangedef(1)-xrangedef(0)
  2416. syd=yrangedef(1)-yrangedef(0)
  2417. print,sx,sy
  2418. if (zoominout eq 1) then begin
  2419. sx=sx/2.
  2420. sy=sy/2.
  2421. ; try to squarify for zoomed in version
  2422. sx2=(sx+sy)/2.
  2423. ; sx=max(sx,sx2)
  2424. ; sy=max(sy,sx2)
  2425. ; sx=(sx+sx2)/2.
  2426. ; sy=(sy+sx2)/2.
  2427. ; try to tend to initial proportions for zooming in
  2428. sx=(sx+1.0*(sxd*0.5/(sxd+syd)))/2.
  2429. sy=(sy+1.0*(syd*0.5/(sxd+syd)))/2.
  2430. endif
  2431. if (zoominout eq -1) then begin
  2432. sx=sx*2.
  2433. sy=sy*2.
  2434. ; try to make similar to initial proportions for zooming out
  2435. sx2=(sx+sy)*2.
  2436. sx=(sx+sx2*(sxd*0.5/(sxd+syd)))/2.
  2437. sy=(sy+sx2*(syd*0.5/(sxd+syd)))/2.
  2438. endif
  2439. print,'sx sy ',sx,sy, xdata, ydata
  2440. oxrange=xrange
  2441. xrange=[xdata-sx/2.,xdata+sx/2.]
  2442. yrange=[ydata-sy/2.,ydata+sy/2.]
  2443. if (oxrange(1) le 180) then begin ; 0 longitude centred
  2444. if (xrange(0) lt xrangedef(0)) then xrange(0)=xrangedef(0)
  2445. if (xrange(1) gt xrangedef(1)) then xrange(1)=xrangedef(1)
  2446. endif else begin ; 180 longitude centred
  2447. if (xrange(0) lt xrangedef(0)+180) then xrange(0)=xrangedef(0)+180
  2448. if (xrange(1) gt xrangedef(1)+180) then xrange(1)=xrangedef(1)+180
  2449. endelse
  2450. if (yrange(0) lt yrangedef(0)) then yrange(0)=yrangedef(0)
  2451. if (yrange(1) gt yrangedef(1)) then yrange(1)=yrangedef(1)
  2452. print,'xrange ',xrange,' yrange ',yrange
  2453. stash.xrange=xrange
  2454. stash.yrange=yrange
  2455. end
  2456. ;---------------------------------------
  2457. ;Time series plotting and event handling
  2458. ;---------------------------------------
  2459. PRO plottimeseries, stash
  2460. xrange=stash.xrange
  2461. yrange=stash.yrange
  2462. ; dayarr=stash.dayarr
  2463. daymin=stash.daymin
  2464. daymax=stash.daymax
  2465. dayminl=stash.dayminl
  2466. daymaxl=stash.daymaxl
  2467. numtimeseries=stash.numtimeseries ; if 1 then plot number of points
  2468. ; print,depmin,xrange,yrange
  2469. ; wh=where(dep1 eq ev.index)
  2470. ; wh=where(dep1 eq depmin and $
  2471. ; dayarr ge daymin and dayarr le daymax)
  2472. ;
  2473. ; nelwh=n_elements(wh)
  2474. ; select points to plot
  2475. typestr=''
  2476. if (stash.plottssel eq 1) then begin
  2477. dayminl=daymin
  2478. daymaxl=daymax
  2479. endif
  2480. print,'djl ',dayminl,daymaxl, min(stash.dayarr), max(stash.dayarr)
  2481. selpoints, stash, lonsel, latsel, innovsel, qcsel, daysel, obstypsel, obnumsel, numsel, typestr, $
  2482. daymin=dayminl, daymax=daymaxl, /rmsmean, innovsel2=innovsel2
  2483. print,'djl ',min(daysel), max(daysel)
  2484. if (stash.plottssel eq 1) then begin
  2485. daymaxl=daymaxl+1
  2486. endif
  2487. ; plot,daysel, ystyle=1
  2488. print,'n_elements(daysel) ',n_elements(daysel), min(daysel), max(daysel)
  2489. print, dayminl, daymaxl
  2490. ; group in 1/4 day bins
  2491. ; binspday=double(4.0) ; every 6 hours
  2492. ; binspday=double(8.0) ; every 3 hours
  2493. binspday=double(stash.binspday)
  2494. nbins=(daymaxl-dayminl)*binspday+1
  2495. print, daymaxl, dayminl, binspday
  2496. x2arr=dblarr(nbins)
  2497. xarr=dblarr(nbins)
  2498. narr=dblarr(nbins)
  2499. tarr=dblarr(nbins)
  2500. meants=dblarr(nbins)
  2501. rmsts=dblarr(nbins)
  2502. print, 'nbins: ',nbins
  2503. if n_elements(innovsel) gt 0 then begin
  2504. print,max(daysel),min(daysel)
  2505. for ibin=0L,nbins-1 do begin
  2506. timmn=double(dayminl)+ibin/binspday
  2507. timmx=timmn+1/binspday
  2508. ; print, ibin, timmn, timmx, timmx-timmn
  2509. wh=where(daysel ge timmn and daysel lt timmx, count)
  2510. print, 'ibin ',ibin, timmn, timmx, count
  2511. ; redo based on the number of observations
  2512. if (wh(0) ne -1) then begin
  2513. innovsels=innovsel(wh)
  2514. innovsel2s=innovsel2(wh)
  2515. numsels=numsel(wh)
  2516. x2arr(ibin)=total(innovsel2s*numsels)
  2517. xarr(ibin)=total(innovsels*numsels)
  2518. ; narr(ibin)=n_elements(innovsels)
  2519. narr(ibin)=total(numsels)
  2520. ; print,ibin, x2arr(ibin), xarr(ibin)
  2521. endif
  2522. tarr(ibin)=timmn
  2523. endfor
  2524. meants=xarr/narr
  2525. rmsts=sqrt(x2arr/narr)
  2526. ; print,'meants: ',meants
  2527. ; print,'rmsts: ',rmsts
  2528. endif ; n_elements(innovsel)
  2529. wh=where(finite(meants)) ; find finite values
  2530. ymx=max([meants(wh),rmsts(wh)],min=ymn)
  2531. ;put a bit of white space around ymx,ymn
  2532. dymxmn=(ymx-ymn)*0.02
  2533. ymx=ymx+dymxmn
  2534. ymn=ymn-dymxmn
  2535. print,'ymx/mn ',ymx,ymn
  2536. strtsal=''
  2537. ; print,'stash.filetype ',stash.filetype
  2538. if (stash.filetype eq 'Prof' or stash.filetype eq 'feedback') then begin
  2539. strtsal='T: '
  2540. if (stash.salinity eq 1) then strtsal='S: '
  2541. endif else begin
  2542. strtsal=stash.filetype+': '
  2543. endelse
  2544. title=strtsal+typestr+' lons ('+string(xrange(0))+','+string(xrange(1))+$
  2545. ') lats ('+string(yrange(0))+','+string(yrange(1))+')'
  2546. print,title
  2547. ; dtarr=jul_to_dt(tarr)
  2548. dtarr=tarr-0.5 ; convert back to julian day
  2549. xmx=max(dtarr,min=xmn)
  2550. ;put a bit of white space around xmx,xmn
  2551. dxmxmn=(xmx-xmn)*0.02
  2552. xmx=xmx+dxmxmn
  2553. xmn=xmn-dxmxmn
  2554. ;date_label = LABEL_DATE(DATE_FORMAT = $
  2555. ; ['%I:%S', '%H', '%D %M, %Y'])
  2556. ;date_label = LABEL_DATE(DATE_FORMAT = $
  2557. ; ['%D %M, %Y'])
  2558. date_label = LABEL_DATE(DATE_FORMAT=['%D-%M','%Y'])
  2559. if (stash.txt eq 0) then begin
  2560. if (numtimeseries ne 1) then begin
  2561. plot,dtarr, meants, xstyle=1, linestyle=1, yrange=[ymn,ymx], title=title, $
  2562. ytitle=typestr, xrange=[xmn,xmx], $
  2563. XTICKUNITS=['Time', 'Time'], XTICKFORMAT = ['LABEL_DATE'],YMARGIN=[6,4]
  2564. ; XTICKFORMAT = ['LABEL_DATE'], $
  2565. ; XTICKUNITS = ['Day'], $
  2566. ; XTICKINTERVAL = 4
  2567. plot, dtarr, rmsts, xstyle=1, yrange=[ymn,ymx], /noerase, $
  2568. ytitle=typestr, xrange=[xmn,xmx], $
  2569. XTICKUNITS=['Time', 'Time'], XTICKFORMAT = ['LABEL_DATE'],YMARGIN=[6,4]
  2570. ; XTICKFORMAT = ['LABEL_DATE'], $
  2571. ; XTICKUNITS = ['Day'], $
  2572. ; XTICKINTERVAL = 4
  2573. xcoord=0.8
  2574. ycoord=0.9
  2575. ycoord=0.35
  2576. ycoord=0.2
  2577. ; ukmo_legend,xcoord=xcoord,ycoord=ycoord,delta_y=0.05,$
  2578. ; ['RMS','mean'],linestyle=[0,1],/normal
  2579. ycoord2=ycoord-0.05
  2580. xcoord2=xcoord+0.03
  2581. xcoord3=xcoord+0.05
  2582. plots, [xcoord,xcoord2],[ycoord,ycoord], linestyle=0, /normal
  2583. xyouts, xcoord3, ycoord, 'RMS', /normal
  2584. plots, [xcoord,xcoord2],[ycoord2,ycoord2], linestyle=1, /normal
  2585. xyouts, xcoord3, ycoord2, 'mean',/normal
  2586. endif else begin
  2587. plot,dtarr, narr, xstyle=1, title=title, $
  2588. ytitle='number of obs', $
  2589. XTICKUNITS=['Time', 'Time'], XTICKFORMAT = ['LABEL_DATE'],YMARGIN=[6,4]
  2590. ; XTICKFORMAT = ['LABEL_DATE'], $
  2591. ; XTICKUNITS = ['Day'], $
  2592. ; XTICKINTERVAL = 4
  2593. endelse
  2594. endif else begin
  2595. outfile=stash.outfile+'_timeseries.txt'
  2596. print, 'saving data to ',outfile
  2597. OPENW, unit, outfile, /get_lun
  2598. ; printf,unit,'Output timeseries data: '
  2599. printf,unit, strtsal
  2600. printf,unit, typestr
  2601. printf,unit, xrange, yrange
  2602. printf,unit, binspday
  2603. nel=n_elements(dtarr)
  2604. for i=0L,nel-1 do begin
  2605. printf,unit, dtarr(i), narr(i), meants(i), rmsts(i),format='(d18.8,d18.2,d18.8,d18.8)'
  2606. endfor
  2607. FREE_LUN, unit
  2608. endelse
  2609. ; print,'min/max lonsel: ',min(lonsel),max(lonsel)
  2610. end
  2611. PRO timeserieswindow, stash
  2612. basepw=WIDGET_BASE(/column)
  2613. drawpw = WIDGET_DRAW(basepw, XSIZE=640, YSIZE=480)
  2614. buttons=Widget_Base(basepw,row=1)
  2615. tlb = Widget_Base(buttons,Title='Push-Buttons', row=1, Scr_XSize=400,$
  2616. /Exclusive)
  2617. ; no_release only sends select events (not release ones)
  2618. buttonp1 = Widget_Button(tlb, Value='1 bin per day',uvalue='RADIO1',/no_release)
  2619. buttonp2 = Widget_Button(tlb, Value='2 bins',uvalue='RADIO2',/no_release)
  2620. buttonp3= Widget_Button(tlb, Value='4 bins',uvalue='RADIO3',/no_release)
  2621. buttonp4 = Widget_Button(tlb, Value='8 bins',uvalue='RADIO4',/no_release)
  2622. if (stash.binspday eq 1) then Widget_Control, buttonp1, Set_Button=1
  2623. if (stash.binspday eq 2) then Widget_Control, buttonp2, Set_Button=1
  2624. if (stash.binspday eq 4) then Widget_Control, buttonp3, Set_Button=1
  2625. if (stash.binspday eq 8) then Widget_Control, buttonp4, Set_Button=1
  2626. tlb2 = Widget_Base(buttons,Title='Push-Buttons', row=1, Scr_XSize=100,$
  2627. /NonExclusive)
  2628. buttonpa1= Widget_Button(tlb2, Value='plot selected period',uvalue='PLOTSEL')
  2629. Widget_Control, buttonpa1, Set_Button=stash.plottssel
  2630. buttonpw = WIDGET_BUTTON(buttons, VALUE='Print',uvalue='PRINTTSW')
  2631. buttonpw2 = WIDGET_BUTTON(buttons, VALUE='Output',uvalue='OUTPUTTSW')
  2632. WIDGET_CONTROL, basepw, /REALIZE
  2633. xyouts,0.2,0.5,'working...',/normal,charsize=2.5
  2634. plottimeseries,stash
  2635. WIDGET_CONTROL, basepw, SET_UVALUE=stash
  2636. XMANAGER, 'timeserieswindow', basepw, /NO_BLOCK
  2637. end
  2638. PRO timeserieswindow_event, ev
  2639. WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash
  2640. WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
  2641. print,uval
  2642. if (uval eq 'PRINTTSW') then begin
  2643. ps=1
  2644. eps=0
  2645. landscape=1
  2646. pr2,file='~/timeseries.ps',landscape=landscape,ps=ps,eps=eps,color=1
  2647. plottimeseries,stash
  2648. prend2,/view
  2649. endif
  2650. if (uval eq 'OUTPUTTSW') then begin
  2651. savetxt=stash.txt
  2652. stash.txt=1
  2653. plottimeseries,stash
  2654. stash.txt=savetxt
  2655. endif
  2656. if (uval eq 'RADIO1') then begin
  2657. stash.binspday=1
  2658. plottimeseries,stash
  2659. endif
  2660. if (uval eq 'RADIO2') then begin
  2661. stash.binspday=2
  2662. plottimeseries,stash
  2663. endif
  2664. if (uval eq 'RADIO3') then begin
  2665. stash.binspday=4
  2666. plottimeseries,stash
  2667. endif
  2668. if (uval eq 'RADIO4') then begin
  2669. stash.binspday=8
  2670. plottimeseries,stash
  2671. endif
  2672. if (uval eq 'PLOTSEL') then begin
  2673. stash.plottssel=1-stash.plottssel
  2674. print,'stash.plottssel ',stash.plottssel
  2675. WIDGET_CONTROL, ev.TOP, SET_UVALUE=stash
  2676. plottimeseries,stash
  2677. endif
  2678. end
  2679. ;----------------------------------------
  2680. ; T-S diagram plotting and event handling
  2681. ;----------------------------------------
  2682. PRO plottsdiagram, stash
  2683. xrange=stash.xrange
  2684. yrange=stash.yrange
  2685. ; dayarr=stash.dayarr
  2686. daymin=stash.daymin
  2687. daymax=stash.daymax
  2688. dayminl=stash.dayminl
  2689. daymaxl=stash.daymaxl
  2690. xarr=stash.xarr
  2691. yarr=stash.yarr
  2692. rmdi=stash.rmdi
  2693. ; select T and S points to plot
  2694. typestr=''
  2695. selpoints, stash, lonsel, latsel, innovsel, qcsel, daysel, obstypsel, obnumsel, numsel, typestr, $
  2696. daymin=dayminl, daymax=daymaxl, salinity=1
  2697. ; select points with salinity
  2698. nel=n_elements(lonsel)
  2699. if (nel gt 0) then begin
  2700. bkg=stash.bkg
  2701. bkg2=stash.bkg2
  2702. obs=stash.obs
  2703. obs2=stash.obs2
  2704. dep=stash.dep
  2705. strtarr=0
  2706. depmin=stash.depmin
  2707. depmax=stash.depmax
  2708. for i=0L,nel-1 do begin
  2709. wh=where(lonsel(i) eq xarr and latsel(i) eq yarr and $
  2710. dep ge depmin and dep le depmax )
  2711. if (wh(0) gt -1) then begin
  2712. if (strtarr eq 0) then begin
  2713. strtarr=1
  2714. bkgsel=bkg(wh)
  2715. bkg2sel=bkg2(wh)
  2716. obssel=obs(wh)
  2717. obs2sel=obs2(wh)
  2718. endif else begin
  2719. bkgsel=[bkgsel,bkg(wh)]
  2720. bkg2sel=[bkg2sel,bkg2(wh)]
  2721. obssel=[obssel,obs(wh)]
  2722. obs2sel=[obs2sel,obs2(wh)]
  2723. endelse
  2724. endif
  2725. endfor
  2726. ;filter out points with missing data
  2727. wh=where(bkgsel ne rmdi and bkg2sel ne rmdi $
  2728. and obssel ne rmdi and obs2sel ne rmdi)
  2729. if (wh(0) gt -1) then begin
  2730. obssel=obssel(wh)
  2731. bkgsel=bkgsel(wh)
  2732. obs2sel=obs2sel(wh)
  2733. bkg2sel=bkg2sel(wh)
  2734. xmn=min([obssel,bkgsel],max=xmx)
  2735. ymn=min([obs2sel,bkg2sel],max=ymx)
  2736. title='T-S diagram: dep '+string(depmin)+'-'+string(depmax)
  2737. plot,obssel,obs2sel,psym=4, color='FFFFFF'x, xtitle='Temperature',ytitle='Salinity',$
  2738. xrange=[xmn,xmx], yrange=[ymn,ymx],xstyle=1,ystyle=1, title=title
  2739. oplot,bkgsel,bkg2sel,psym=5, color='FFCC66'x
  2740. xcoord=0.8
  2741. ycoord=0.9
  2742. ycoord=0.2
  2743. ; ukmo_legend,xcoord=xcoord,ycoord=ycoord,delta_y=0.05,$
  2744. ; ['obs','bkg'],psym=[4,5],color=['FFFFFF'x, 'FFCC66'x],/normal
  2745. ycoord2=ycoord-0.05
  2746. xcoord2=xcoord+0.03
  2747. xcoord3=xcoord+0.05
  2748. plots, [xcoord,xcoord2],[ycoord,ycoord], psym=4, color='FFFFFF'x, /normal
  2749. xyouts, xcoord+0.05, ycoord, 'obs', /normal
  2750. plots, [xcoord,xcoord2],[ycoord2,ycoord2], psym=5, color='FFCC66'x, /normal
  2751. xyouts, xcoord+0.05, ycoord2, 'bkg',/normal
  2752. endif
  2753. endif
  2754. end
  2755. PRO tsdiagramwindow, stash
  2756. basepw=WIDGET_BASE(/column)
  2757. drawpw = WIDGET_DRAW(basepw, XSIZE=640, YSIZE=480)
  2758. buttonpw = WIDGET_BUTTON(basepw, VALUE='Print',uvalue='PRINTTSW')
  2759. WIDGET_CONTROL, basepw, /REALIZE
  2760. plottsdiagram,stash
  2761. WIDGET_CONTROL, basepw, SET_UVALUE=stash
  2762. XMANAGER, 'tsdiagramwindow', basepw, /NO_BLOCK
  2763. end
  2764. PRO tsdiagramwindow_event, ev
  2765. WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash
  2766. WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
  2767. print,uval
  2768. if (uval eq 'PRINTTSW') then begin
  2769. ps=1
  2770. eps=0
  2771. landscape=1
  2772. pr2,file='~/tsdiagram.ps',landscape=landscape,ps=ps,eps=eps,color=1
  2773. plottsdiagram,stash
  2774. prend2,/view
  2775. endif
  2776. end
  2777. PRO jul_to_dtstr, daysel, datestr, notime=notime
  2778. ;print,'called jul_to_dtstr ',daysel
  2779. ; IDL Julian days start at 12 noon
  2780. CALDAT, daysel(0)-0.5, Month, Day, Year, Hour, Minute, Second
  2781. datestr=strtrim(fix(year),2)+'/'+ $
  2782. strtrim(string(fix(month),format='(i2.2)'),2)+'/'+ $
  2783. strtrim(string(fix(day),format='(i2.2)'),2)
  2784. if (n_elements(notime) eq 0) then $
  2785. datestr=datestr+' '+$
  2786. strtrim(string(fix(hour),format='(i2.2)'),2)+':'+ $
  2787. strtrim(string(fix(minute),format='(i2.2)'),2)+':'+ $
  2788. strtrim(string(fix(second),format='(i2.2)'),2)
  2789. ; datedt=jul_to_dt(daysel)
  2790. ; datedt=datedt(0)
  2791. ; datestr=strtrim(fix(datedt.year),2)+'/'+ $
  2792. ; strtrim(string(fix(datedt.month),format='(i2.2)'),2)+'/'+ $
  2793. ; strtrim(string(fix(datedt.day),format='(i2.2)'),2)+' '+ $
  2794. ; strtrim(string(fix(datedt.hour),format='(i2.2)'),2)+':'+ $
  2795. ; strtrim(string(fix(datedt.minute),format='(i2.2)'),2)+':'+ $
  2796. ; strtrim(string(fix(datedt.second),format='(i2.2)'),2)
  2797. ;print,datestr
  2798. END
  2799. ;-----------------------------------------------------------------------
  2800. ; MAIN routine
  2801. ; Widget creation routine.
  2802. ; dataplot, [longitude, latitude, deparr, dayarr, valarr, bkgarr]
  2803. ;+
  2804. PRO dataplot, indata, rmdi=rmdi, filename=filename, salinity=salinity, batch=batch, $
  2805. ps=ps, gif=gif, area=area, typeplot=typeplot, ombtypeplot=ombtypeplot, $
  2806. alldays=alldays, depths=depths, $
  2807. mx=mx, mn=mn, showmdt=showmdt, obstypeselect=obstypeselect, printobstypes=printobstypes, $
  2808. daterange=daterange, timeseries=timeseries, binspday=binspday, plot_bad_obs=plot_bad_obs, $
  2809. plot_only_bad_obs=plot_only_bad_obs, $
  2810. numtimeseries=numtimeseries, txt=txt, netcdf=netcdf, vertgrad=vertgrad, healthcheck=healthcheck, $
  2811. duplicates=duplicates, differences=differences, outfile=outfile, white_on_black=white_on_black, $
  2812. bindata=bindata, symscale=symscale, hiresmap=hiresmap, coltable=coltable, $
  2813. picsize=picsize, pmulti=pmulti, typeproj=typeproj, dayrange=dayrange, $
  2814. notfussy=notfussy, mld=mld, binsize=binsize, filterout=filterout
  2815. ;-
  2816. ; DJL switch off wave compatibility mode
  2817. res=execute('waveoff')
  2818. ; string array obstypeselect
  2819. if (n_elements(obstypeselect) eq 0) then obstypeselect=''
  2820. if (n_elements(printobstypes) eq 0) then printobstypes=''
  2821. if (n_elements(filterout) eq 0) then filterout=''
  2822. if (n_elements(binspday) eq 0) then binspday=4 ; plot timeseries every 6 hours
  2823. plottssel=0 ; plot selected period of timeseries
  2824. if (n_elements(plot_bad_obs) eq 0) then plot_bad_obs=0 ; don't plot bad obs
  2825. if (n_elements(plot_only_bad_obs) eq 0) then plot_only_bad_obs=1 ; plot only bad obs if selected
  2826. if (n_elements(white_on_black) eq 0) then white_on_black=1
  2827. if (n_elements(duplicates) eq 0) then duplicates=0 ; plot only duplicates if selected
  2828. if (n_elements(differences) eq 0) then differences=0 ; plot only differences if selected
  2829. if (n_elements(numtimeseries) eq 0) then numtimeseries=0 ; plot time series of O-B
  2830. if (n_elements(txt) eq 0) then txt=0
  2831. if (n_elements(netcdf) eq 0) then netcdf=0 ; if 1 the output netcdf data
  2832. print,obstypeselect
  2833. if (n_elements(salinity) eq 0) then salinity=0
  2834. density=0
  2835. if (n_elements(vertgrad) eq 0) then vertgrad=0
  2836. if (n_elements(mld) eq 0) then mld=0
  2837. if (n_elements(outfile) eq 0) then outfile="dataplot"
  2838. if (n_elements(bindata) eq 0) then bindata=0
  2839. if (n_elements(binsize) eq 0) then binsize=[1.0,1.0]
  2840. if (n_elements(symscale) eq 0) then symscale=1.0
  2841. if (n_elements(hiresmap) eq 0) then begin
  2842. hires_map=0
  2843. endif else begin
  2844. hires_map=hiresmap
  2845. endelse
  2846. if (n_elements(rmdi) eq 0) then rmdi=0
  2847. if (n_elements(coltable) eq 0) then begin
  2848. coltable=-1
  2849. endif
  2850. if (n_elements(picsize) ne 2) then picsize=[800,512] ; default gif resolution
  2851. if (n_elements(pmulti) eq 0) then pmulti=0 ; default pmulti
  2852. sz=size(indata)
  2853. nsz=n_elements(sz)
  2854. type=sz(nsz-2) ; get type 2 integer, 4 float, 7 string
  2855. if (type eq 7) then filename=indata
  2856. if (type ne 7) then begin
  2857. nel=n_elements(indata)
  2858. nel8=nel/8
  2859. numobs=nel8
  2860. ; get input values
  2861. if (nel gt 0) then begin
  2862. indata=reform(indata,numobs,8)
  2863. xarr=indata(*,0)
  2864. yarr=indata(*,1)
  2865. dep=indata(*,2)
  2866. dayarrin=indata(*,3)
  2867. obs=indata(*,4)
  2868. bkg=indata(*,5)
  2869. obs2=rmdi
  2870. obs3=rmdi
  2871. bkg2=rmdi
  2872. qcarr=long(indata(*,6))
  2873. qcarr2=rmdi
  2874. obnum=rmdi
  2875. obstypes=long(indata(*,7))
  2876. filetype="generic"
  2877. print, 'djl max/min dayarrin ',max(dayarrin), min(dayarrin)
  2878. print, 'djl max/min qcarr ',max(qcarr), min(qcarr)
  2879. endif
  2880. endif else begin
  2881. if (n_elements(filename) eq 0) then begin
  2882. print,'ERROR: No filename supplied'
  2883. print,'call: dataplot, filenamearr'
  2884. return
  2885. endif
  2886. endelse
  2887. ;read in data
  2888. if (n_elements(filename) gt 0) then begin
  2889. read_cdfobs, filename, numobs=numobs, Latitudes=yarr, Longitudes=xarr, $
  2890. obs=obs, modelvals=bkg, qcs=qcarr, $
  2891. ob2=obs2, modelval2=bkg2, qc2=qcarr2, $
  2892. ob3=obs3, $
  2893. Dates=dayarrin, rmdi=rmdi, $
  2894. depths=dep, nodates=0, types=obstypes, $
  2895. filetype=filetype, iobs=iobs, jobs=jobs, MDT=MDT, error=error, profilenum=obnum, $
  2896. notfussy=notfussy, VarName=varname
  2897. if (error eq 1) then begin
  2898. numobs=0
  2899. dayarrin=0
  2900. rmdi=-99999
  2901. xarr=rmdi
  2902. yarr=rmdi
  2903. obs=rmdi
  2904. bkg=rmdi
  2905. qcarr=1
  2906. dayarrin=rmdi
  2907. dayarr=rmdi
  2908. dep=rmdi
  2909. filetype=""
  2910. obstypes=rmdi
  2911. obnum=0
  2912. endif
  2913. print,'error ',error, numobs
  2914. if (numobs gt 0) then begin
  2915. print, 'numobs ',numobs
  2916. ;setup obnum if it is not produced by read_cdfobs
  2917. if (n_elements(obnum) ne numobs and numobs gt 0) then begin
  2918. obnum=lindgen(n_elements(numobs)) ; generate an array of observation numbers
  2919. ; starting with zero
  2920. endif
  2921. ;if gt 180 then make longitudes negative
  2922. wh=where(xarr ge 180 and xarr le 360)
  2923. if (wh(0) gt -1) then begin
  2924. xarr(wh)=xarr(wh)-360
  2925. endif
  2926. ;calculate vertical gradient
  2927. ;
  2928. ; if (filetype eq "Prof") then $
  2929. ; calcvertgrad, xarr, yarr, dayarrin, obs, bkg, qcarr, obs2,bkg2, qcarr2, dep, rmdi
  2930. ; adjust qc values for profile obs data (1 = good)
  2931. wh=where(bkg ne rmdi)
  2932. if (n_elements(bkg2) gt 0) then begin
  2933. wh2=where(bkg2 ne rmdi)
  2934. if (filetype eq "Prof" and wh(0) eq -1 and wh2(0) eq -1) then begin
  2935. qcarr=qcarr-1
  2936. qcarr2=qcarr2-1
  2937. endif
  2938. endif
  2939. if (keyword_set(showmdt) eq 1) then begin
  2940. bkg=MDT
  2941. endif
  2942. print,'rmdi ',rmdi
  2943. print,'file read in'
  2944. spawn,'echo part 1 `date`'
  2945. if (n_elements(rmdi) eq 0) then rmdi=-1.07374e+09
  2946. qcarr=fix(qcarr)
  2947. endif ; numobs
  2948. print,'endif numobs'
  2949. ; select area
  2950. sz=size(area)
  2951. nsz=n_elements(sz)
  2952. type=sz(nsz-2) ; get type 2 integer, 4 float, 7 string
  2953. if (type eq 7) then areasel, area, xrange, yrange, success
  2954. if (type eq 4 or type eq 2) then begin
  2955. if (nsz eq 4) then begin
  2956. xrange=[area(0),area(2)]
  2957. yrange=[area(1),area(3)]
  2958. endif
  2959. endif
  2960. ; set missing obs types to missing data
  2961. if (n_elements(obs2) eq 0) then begin
  2962. obs2=rmdi
  2963. bkg2=rmdi
  2964. qcarr2=rmdi
  2965. endif
  2966. if (n_elements(obs3) eq 0) then begin
  2967. obs3=rmdi
  2968. bkg3=rmdi
  2969. qcarr3=rmdi
  2970. endif
  2971. endif ; filename
  2972. if (n_elements(varname) eq 0) then varname=''
  2973. if (n_elements(dayarrin) ne numobs) then dayarrin=replicate(1,numobs)
  2974. ; dep=replicate(0,numobs)
  2975. if (size(dayarrin,/type) eq 8) then begin
  2976. dayarr=dayarrin.julian
  2977. endif else begin
  2978. dayarr=dayarrin
  2979. dayarr=dayarr+0.5 ; dataplot prefers each day to be a different integer
  2980. endelse
  2981. print,'xxx'
  2982. ;set contour range mn, mx
  2983. if (n_elements(mx) eq 0) then fmx=rmdi else fmx=mx
  2984. if (n_elements(mn) eq 0) then fmn=rmdi else fmn=mn
  2985. mx=fmx
  2986. mn=fmn
  2987. ; Define a monochrome image array for use in the application.
  2988. ; READ_PNG, FILEPATH('mineral.png', $
  2989. ; SUBDIR=['examples', 'data']), image
  2990. ; Place the image array in a pointer heap variable, so we can
  2991. ; pass the pointer to the event routine rather than passing the
  2992. ; entire image array.
  2993. ; imagePtr=PTR_NEW(image, /NO_COPY)
  2994. ; Retrieve the size information from the image array.
  2995. ; im_size=SIZE(*imagePtr)
  2996. ;---------------
  2997. ;Setup defaults
  2998. ;---------------
  2999. busy=0
  3000. wh=where(dep ge 0)
  3001. depminl=0.
  3002. depmaxl=1.
  3003. if( wh(0) gt -1) then depminl=min(dep(wh),max=depmaxl)
  3004. depscl=fix((depmaxl-depminl)/100.)
  3005. if (depscl lt 1) then depscl=1
  3006. depmin=depminl
  3007. ; depmax=depmin+depscl
  3008. depmax=depmaxl
  3009. pmultinum=0
  3010. if (n_elements(depths) eq 2) then begin
  3011. depmin=max([depminl,depths(0)])
  3012. depmax=min([depmaxl,depths(1)])
  3013. endif
  3014. print,'n_elements(typeplot) ',n_elements(typeplot)
  3015. if (n_elements(typeplot) eq 0) then typeplot=1
  3016. ; if (n_elements(where(bkg ne bkg(0))) gt 1) then begin
  3017. ; typeplot=3
  3018. ; endif else begin
  3019. ; typeplot=4
  3020. ; endelse
  3021. ; endif
  3022. if (typeplot gt 4) then typeplot=4
  3023. if (typeplot lt 1) then typeplot=1
  3024. if (n_elements(ombtypeplot) eq 0) then begin
  3025. if (n_elements(where(bkg ne bkg(0))) gt 1) then begin
  3026. ombtypeplot=1
  3027. endif else begin
  3028. ombtypeplot=2
  3029. endelse
  3030. endif
  3031. if (ombtypeplot gt 3) then ombtypeplot=3
  3032. if (ombtypeplot lt 1) then ombtypeplot=1
  3033. print,'typeplot ',typeplot, ' ombtypeplot ',ombtypeplot
  3034. if (n_elements(typeproj) eq 0) then typeproj=1
  3035. xrangedef=[-110.,40.]
  3036. yrangedef=[-50.,80.]
  3037. wh=where(xarr lt xrangedef(0) or xarr gt xrangedef(1) or $
  3038. yarr lt yrangedef(0) or yarr gt yrangedef(1),count)
  3039. if (count gt 0) then begin
  3040. xrangedef=[-180.,180.]
  3041. yrangedef=[-90.,90.]
  3042. endif
  3043. if (n_elements(xrange) eq 0) then begin
  3044. xrange=xrangedef
  3045. yrange=yrangedef
  3046. endif
  3047. symsize=1.0
  3048. ; map_file=""
  3049. ; plot_bad_obs=0
  3050. dayshi=-10.d/86400. ; small shift to group 0:00 hours with the previous day
  3051. ; dayshi=-0.1d
  3052. wh=where(dayarr gt 0 and dayarr lt 9000000)
  3053. ; print,dayarr
  3054. ; print,wh(0)
  3055. if (wh(0) gt -1) then begin
  3056. daymin=min(dayarr(wh)+dayshi,max=daymax)
  3057. endif else begin
  3058. daymax=0
  3059. daymin=0
  3060. endelse
  3061. ; daymax=maxday
  3062. ; daymin=minday
  3063. dayminl=daymin
  3064. daymaxl=daymax
  3065. print,'** dayminl daymaxl ', dayminl, daymaxl
  3066. ; ** Health check file
  3067. if (keyword_set(healthcheck)) then begin
  3068. OPENW, unit, outfile+'_health.txt', /get_lun
  3069. printf,unit,' Health check data '
  3070. printf,unit,'-------------------'
  3071. printf,unit,' Number of files ',n_elements(filename)
  3072. printf,unit,' List of files '
  3073. printf,unit,filename
  3074. printf,unit,' Filetype ',filetype
  3075. printf,unit,' Number of observations ',numobs
  3076. printf,unit,' Date range in julian days ',dayminl, daymaxl,format='(a,2f20.8)'
  3077. jul_to_dtstr,dayminl,datestr1
  3078. jul_to_dtstr,daymaxl,datestr2
  3079. printf,unit,' Date range ',datestr1,' - ',datestr2
  3080. mxo=0 & mno=0
  3081. mxb=0 & mnb=0
  3082. mxob=0 & mnob=0
  3083. rmsomb=0 & meanomb=0
  3084. ; info,obs
  3085. ; print,obs
  3086. ; info,bkg
  3087. ; print,bkg
  3088. ; print,'rmdi: ',rmdi
  3089. ; wh=where(obs ne rmdi and qcarr lt 1,counto)
  3090. ; check for missing data within a tolerance
  3091. wh=where(abs((obs-rmdi)/rmdi) gt 0.01 and qcarr lt 1, counto)
  3092. ; print,'min ',min(abs((bkg(wh)-rmdi)/rmdi))
  3093. ; print,'min ',min(bkg(wh)), min(obs(wh))
  3094. ; print,'min ',max(bkg(wh)), max(obs(wh))
  3095. if (counto gt 0) then mxo=max(obs(wh),min=mno)
  3096. ; wh=where(bkg ne rmdi and qcarr lt 1,countb)
  3097. wh=where(abs((bkg-rmdi)/rmdi) gt 0.01 and qcarr lt 1, countb)
  3098. if (countb gt 0) then mxb=max(bkg(wh),min=mnb)
  3099. ; wh=where(obs ne rmdi and bkg ne rmdi and qcarr lt 1,countob)
  3100. wh=where(abs((obs-rmdi)/rmdi) gt 0.01 and $
  3101. abs((bkg-rmdi)/rmdi) gt 0.01 and qcarr lt 1, countob)
  3102. if (countob gt 0) then mxob=max(obs(wh)-bkg(wh),min=mnob)
  3103. ; calculate rms / mean
  3104. if (countob gt 0) then begin
  3105. x=total(obs(wh)-bkg(wh))
  3106. x2=total((obs(wh)-bkg(wh))^2)
  3107. nel=n_elements(wh)
  3108. meanomb=x/nel
  3109. rmsomb=sqrt(x2/nel)
  3110. endif
  3111. printf,unit,' Max/min obs ',mxo,mno
  3112. printf,unit,' Max/min bkg ',mxb,mnb
  3113. printf,unit,' Max/min obs-bkg ',mxob,mnob
  3114. printf,unit,' RMS/mean obs-bkg ',rmsomb,meanomb
  3115. printf,unit,' Number of good observations ',counto
  3116. printf,unit,' Number of bad observations ', numobs-counto
  3117. mxo=0 & mno=0
  3118. mxb=0 & mnb=0
  3119. mxob=0 & mnob=0
  3120. rmsomb=0 & meanomb=0
  3121. wh=where(obs2 ne rmdi and qcarr2 lt 1,counto)
  3122. if (counto gt 0) then mxo=max(obs2(wh),min=mno)
  3123. wh=where(bkg2 ne rmdi and qcarr2 lt 1,countb)
  3124. if (countb gt 0) then mxb=max(bkg2(wh),min=mnb)
  3125. wh=where(obs2 ne rmdi and bkg2 ne rmdi and qcarr2 lt 1,countob)
  3126. if (countob gt 0) then mxob=max(obs2(wh)-bkg2(wh),min=mnob)
  3127. ; calculate rms / mean
  3128. if (countob gt 0) then begin
  3129. x=total(obs2(wh)-bkg2(wh))
  3130. x2=total((obs2(wh)-bkg2(wh))^2)
  3131. nel=n_elements(wh)
  3132. meanomb=x/nel
  3133. rmsomb=sqrt(x2/nel)
  3134. endif
  3135. printf,unit,' Max/min obs2 ',mxo,mno
  3136. printf,unit,' Max/min bkg2 ',mxb,mnb
  3137. printf,unit,' Max/min obs2-bkg2 ',mxob,mnob
  3138. printf,unit,' RMS/mean obs2-bkg2 ',rmsomb,meanomb
  3139. printf,unit,' Number of good observations2 ',counto
  3140. printf,unit,' Number of bad observations2 ', numobs-counto
  3141. FREE_LUN,unit
  3142. endif
  3143. daymax=daymaxl ; default to show everything
  3144. if (keyword_set(alldays)) then daymax=daymaxl ;print alldays
  3145. if (n_elements(daterange) eq 2) then begin
  3146. daymin=daterange(0)
  3147. if (daterange(0) lt dayminl) then daymin=dayminl
  3148. if (daterange(0) gt daymaxl) then daymin=daymaxl
  3149. if (daterange(1) gt dayminl and daterange(1) le daymaxl) then begin
  3150. daymax=daterange(1)
  3151. endif else begin
  3152. daymax=daymaxl
  3153. endelse
  3154. endif
  3155. if (n_elements(daterange) eq 1) then begin ; select number of days before end or after beginning
  3156. print,'daymin b4: ',daymin, daymax
  3157. daymax=daymaxl
  3158. daymin=dayminl
  3159. if (daterange(0) lt 0) then begin
  3160. if (daterange(0) eq -9999) then begin
  3161. daymin=daymax
  3162. endif else begin
  3163. daymin=daymax+daterange(0)
  3164. endelse
  3165. endif
  3166. if (daterange(0) gt 0) then daymax=daymin+daterange(0)
  3167. endif
  3168. ; select day from the start day
  3169. if (n_elements(dayrange) eq 1) then begin
  3170. daymin=dayminl+dayrange
  3171. daymax=daymin
  3172. endif
  3173. if (n_elements(dayrange) eq 2) then begin
  3174. daymin=dayminl+dayrange(0)
  3175. daymax=dayminl+dayrange(1)
  3176. endif
  3177. ; prevent error where only one day plotted
  3178. daymaxsl=daymaxl
  3179. dayminsl=dayminl
  3180. if (daymaxsl le dayminsl+1) then daymaxsl=dayminsl+1
  3181. ; stop day going out of range
  3182. if (daymax gt daymaxl) then daymax=daymaxl
  3183. if (daymax lt dayminl) then daymax=dayminl
  3184. if (daymin lt dayminl) then daymin=dayminl
  3185. if (daymin gt daymaxl) then daymin=daymaxl
  3186. print,'daymin af: ',daymin, daymax
  3187. sym=1
  3188. ;-------------
  3189. ;Setup window
  3190. ;-------------
  3191. if (not keyword_set(batch)) then begin
  3192. ; Create a base widget to hold the application.
  3193. ; base0=WIDGET_BASE()
  3194. base = WIDGET_BASE(/COLUMN,mbar=bar)
  3195. ; base = WIDGET_BASE(/row)
  3196. ; setup menu bar
  3197. menu1 = WIDGET_BUTTON(bar, VALUE='Areas', /MENU)
  3198. button1 = WIDGET_BUTTON(menu1, VALUE='Global', uvalue='Global')
  3199. button2 = WIDGET_BUTTON(menu1, VALUE='Arctic', uvalue='Arctic')
  3200. button2a = WIDGET_BUTTON(menu1, VALUE='Atlantic', uvalue='Atlantic')
  3201. button3 = WIDGET_BUTTON(menu1, VALUE='N Atl', uvalue='N Atl')
  3202. button4 = WIDGET_BUTTON(menu1, VALUE='Trop Atl', uvalue='Trop Atl')
  3203. button5 = WIDGET_BUTTON(menu1, VALUE='S Atl', uvalue='S Atl')
  3204. button5a = WIDGET_BUTTON(menu1, VALUE='Pacific', uvalue='Pacific')
  3205. button6 = WIDGET_BUTTON(menu1, VALUE='N Pac', uvalue='N Pac')
  3206. button7 = WIDGET_BUTTON(menu1, VALUE='Trop Pac', uvalue='Trop Pac')
  3207. button8 = WIDGET_BUTTON(menu1, VALUE='S Pac', uvalue='S Pac')
  3208. button9 = WIDGET_BUTTON(menu1, VALUE='Indian', uvalue='Indian')
  3209. button10 = WIDGET_BUTTON(menu1, VALUE='S Ocean', uvalue='S Ocean')
  3210. button11 = WIDGET_BUTTON(menu1, VALUE='Med', uvalue='Med')
  3211. button12 = WIDGET_BUTTON(menu1, VALUE='N West Shelf', uvalue='NWS')
  3212. button13 = WIDGET_BUTTON(menu1, VALUE='Input Area', uvalue='Input Area')
  3213. menu2 = WIDGET_BUTTON(bar, VALUE='Plot', /MENU)
  3214. button1 = WIDGET_BUTTON(menu2, VALUE='Timeseries', uvalue='Timeseries')
  3215. button1a = WIDGET_BUTTON(menu2, VALUE='Num timeseries', uvalue='Num timeseries')
  3216. button2 = WIDGET_BUTTON(menu2, VALUE='T-S diagram', uvalue='TS diagram')
  3217. menu1a = WIDGET_BUTTON(bar, VALUE='Find',/MENU)
  3218. button1a= WIDGET_BUTTON(menu1a, VALUE='Worst points', uvalue='Worst points')
  3219. button1a1 = WIDGET_BUTTON(menu1a, VALUE='Filter type', uvalue='Filter type')
  3220. menu3 = WIDGET_BUTTON(bar, VALUE='Config', /MENU)
  3221. loresmap = WIDGET_BUTTON(menu3, VALUE='Low res map', uvalue='Low res map', /checked_menu)
  3222. hiresmap = WIDGET_BUTTON(menu3, VALUE='Hi res map', uvalue='Hi res map', /checked_menu)
  3223. button3 = WIDGET_BUTTON(menu3, VALUE='Square psym', uvalue='Square psym')
  3224. button4 = WIDGET_BUTTON(menu3, VALUE='Round psym', uvalue='Round psym')
  3225. pltonbado = WIDGET_BUTTON(menu3, VALUE='Plot only bad obs', uvalue='Plot only bad obs', /checked_menu)
  3226. whtonblack = WIDGET_BUTTON(menu3, VALUE='White on black', uvalue='White on black', /checked_menu)
  3227. incsym = WIDGET_BUTTON(menu3, VALUE='Psym size+ ', uvalue='incsym')
  3228. decsym = WIDGET_BUTTON(menu3, VALUE='Psym size- ', uvalue='decsym')
  3229. resetsym = WIDGET_BUTTON(menu3, VALUE='Psym size reset ', uvalue='resetsym')
  3230. vertgradmenu = WIDGET_BUTTON(menu3, VALUE='Vert gradient', uvalue='vertgrad', /checked_menu)
  3231. button12 = WIDGET_BUTTON(menu3, VALUE='Input max/min', uvalue='input max/min')
  3232. menu4 = WIDGET_BUTTON(bar, VALUE='Help', /MENU)
  3233. help1 = WIDGET_BUTTON(menu4, VALUE='Info', uvalue='Info')
  3234. if (n_elements(filename) gt 0) then begin
  3235. menu5 = WIDGET_BUTTON(bar, VALUE=filename[0])
  3236. nel=n_elements(filename)
  3237. nel2=nel
  3238. nelmx=32
  3239. if (nel2 gt nelmx) then nel2=nelmx
  3240. for i=0L, nel2-1 do begin
  3241. id = WIDGET_BUTTON(menu5, VALUE=filename[i])
  3242. endfor
  3243. if (nel gt nelmx) then id=WIDGET_BUTTON(menu5, VALUE='... etc ...')
  3244. endif
  3245. Widget_Control, loresmap, Set_Button=1
  3246. Widget_Control, vertgradmenu, Set_Button=vertgrad
  3247. Widget_Control, pltonbado, Set_Button=plot_only_bad_obs
  3248. Widget_Control, whtonblack, Set_Button=white_on_black
  3249. ; Create a draw widget based on the size of the image, and
  3250. ; set the MOTION_EVENTS keyword so that events are generated
  3251. ; as the cursor moves across the image. Setting the BUTTON_EVENTS
  3252. ; keyword rather than MOTION_EVENTS would require the user to
  3253. ; click on the image before an event is generated.
  3254. ; im_size=[2,1024,800]
  3255. ; im_size=[2,800,800]
  3256. ; im_size=[2,800,720]
  3257. ; im_size=[2,1024,720]
  3258. im_size=[2,1024,680]
  3259. ; im_size=[2,800,640]
  3260. draw = WIDGET_DRAW(base, XSIZE=im_size[1], YSIZE=im_size[2], $
  3261. /BUTTON_EVENTS,/WHEEL_EVENTS, uvalue='MAPWINDOW')
  3262. ; base2=widget_base(GROUP_LEADER=base,/column)
  3263. ; droplist = WIDGET_COMBOBOX(base2,value=string([indgen(101)]),$
  3264. ; uvalue='LEVELLIST', FRAME=2)
  3265. ; button = WIDGET_BUTTON(base2, value='test',uvalue='test')
  3266. ; print,'depminl/maxl ',depminl, depmaxl
  3267. ; print,'value depmin ',depmin
  3268. ; print,'value depmax ',depmax
  3269. depmaxlsl=depmaxl
  3270. depminlsl=depminl
  3271. if (depmaxlsl eq depminlsl) then depmaxlsl=depmaxlsl+1
  3272. print, 'depminlsl, depmaxlsl ',depminlsl, depmaxlsl
  3273. slider = WIDGET_SLIDER(base,maximum=depmaxlsl,minimum=depminlsl,scroll=depscl,$
  3274. value=depmin,uvalue='LEVELCHOICE', ysize=32)
  3275. sliderb = WIDGET_SLIDER(base,maximum=depmaxlsl,minimum=depminlsl, scroll=depscl,$
  3276. value=depmax,uvalue='LEVELCHOICEB', ysize=32)
  3277. jul_to_dtstr,daymin,dayminstr,/notime
  3278. slider1label = WIDGET_LABEL(base, VALUE="min date: "+dayminstr, xsize=800,ysize=14)
  3279. slider1 = WIDGET_SLIDER(base,minimum=dayminsl,maximum=daymaxsl,scroll=1,$
  3280. value=daymin,uvalue='DATERANGE1',/suppress_value,/drag)
  3281. jul_to_dtstr,daymax,daymaxstr,/notime
  3282. slider2label = WIDGET_LABEL(base, VALUE="max date: "+daymaxstr, xsize=800,ysize=14)
  3283. slider2 = WIDGET_SLIDER(base,minimum=dayminsl,maximum=daymaxsl,scroll=1,$
  3284. value=daymax,uvalue='DATERANGE2',/suppress_value,/drag)
  3285. ; slider1 = WIDGET_SLIDER(base,minimum=dayminl,maximum=daymaxl,scroll=1,$
  3286. ; value=daymin,uvalue='DATERANGE1',PRO_SET_VALUE="datesliderset",/drag)
  3287. ;
  3288. ; slider2 = WIDGET_SLIDER(base,minimum=dayminl,maximum=daymaxl,scroll=1,$
  3289. ; value=daymax,uvalue='DATERANGE2',PRO_SET_VALUE="datesliderset",/drag)
  3290. ; Labels for stats
  3291. labt1='Lon: '
  3292. labt2='Lat: '
  3293. labt3='Value: '
  3294. labt4='QC: '
  3295. labt5='Date: '
  3296. labt6='Value: '
  3297. labt7=' '
  3298. labt8='Type: '
  3299. labt9='obnum: '
  3300. labt10='visible date range: '
  3301. ; Create label widgets to hold the cursor position and
  3302. ; Hexadecimal value of the pixel under the cursor.
  3303. labelb=Widget_Base(base,row=1)
  3304. labsiz=105
  3305. labsizl1=150
  3306. labsizlg=150
  3307. labsizl2=135
  3308. label7=0
  3309. lb_ysize=14
  3310. label1 = WIDGET_LABEL(labelb, XSIZE=labsiz, $
  3311. VALUE=labt1, ysize=lb_ysize)
  3312. label2 = WIDGET_LABEL(labelb, XSIZE=labsiz, $
  3313. VALUE=labt2, ysize=lb_ysize)
  3314. label3 = WIDGET_LABEL(labelb, XSIZE=labsizl1, $
  3315. VALUE=labt3, ysize=lb_ysize)
  3316. label4 = WIDGET_LABEL(labelb, XSIZE=labsiz, $
  3317. VALUE=labt4, ysize=lb_ysize)
  3318. label5 = WIDGET_LABEL(labelb, XSIZE=labsizlg, $
  3319. VALUE=labt5, ysize=lb_ysize)
  3320. label6 = WIDGET_LABEL(labelb, XSIZE=labsiz, $
  3321. VALUE=labt6, ysize=lb_ysize)
  3322. ; label7 = WIDGET_LABEL(labelb, XSIZE=labsiz, $
  3323. ; VALUE=labt7, ysize=lb_ysize)
  3324. label8 = WIDGET_LABEL(labelb, XSIZE=labsizl2, $
  3325. VALUE=labt8, ysize=lb_ysize)
  3326. label9 = WIDGET_LABEL(labelb, XSIZE=labsiz, $
  3327. VALUE=labt9, ysize=lb_ysize)
  3328. labelb2 = Widget_Base(base,row=1)
  3329. label10 = WIDGET_LABEL(labelb2, XSIZE=1024, $
  3330. VALUE=labt10, ysize=lb_ysize)
  3331. tlba = Widget_Base(base,row=1)
  3332. t1b = Widget_Base(tlba,Title='Push-Buttons', row=1, Scr_XSize=200,$
  3333. /Exclusive)
  3334. button1 = Widget_Button(t1b, Value='mean',uvalue='RADIO1',/no_release)
  3335. button2 = Widget_Button(t1b, Value='rms',uvalue='RADIO2',/no_release)
  3336. button3 = Widget_Button(t1b, Value='sd',uvalue='RADIO3',/no_release)
  3337. button4 = Widget_Button(t1b, Value='ms',uvalue='RADIO4',/no_release)
  3338. if (typeplot eq 1) then Widget_Control, button1, Set_Button=typeplot
  3339. if (typeplot eq 2) then Widget_Control, button2, Set_Button=typeplot
  3340. if (typeplot eq 3) then Widget_Control, button3, Set_Button=typeplot
  3341. if (typeplot eq 4) then Widget_Control, button4, Set_Button=typeplot
  3342. t1c = Widget_Base(tlba,Title='Push-Buttons', row=1, Scr_XSize=200,$
  3343. /Exclusive)
  3344. button5 = Widget_Button(t1c, Value='obs - bkg', uvalue='RADIO5',/no_release)
  3345. button6 = Widget_Button(t1c, Value='obs', uvalue='RADIO6',/no_release)
  3346. button7 = Widget_Button(t1c, Value='bkg', uvalue='RADIO7',/no_release)
  3347. if (ombtypeplot eq 1) then Widget_Control, button5, /Set_Button
  3348. if (ombtypeplot eq 2) then Widget_Control, button6, /Set_Button
  3349. if (ombtypeplot eq 3) then Widget_Control, button7, /Set_Button
  3350. ; tlb = Widget_Base(tlba,Title='Push-Buttons', row=1, Scr_XSize=400,$
  3351. ; /Exclusive)
  3352. ;; no_release only sends select events (not release ones)
  3353. ; button1 = Widget_Button(tlb, Value='rms Obs - Bkg',uvalue='RADIO1',/no_release)
  3354. ; button2 = Widget_Button(tlb, Value='sum(Obs - Bkg)^2',uvalue='RADIO2',/no_release)
  3355. ; button3= Widget_Button(tlb, Value='Obs - Bkg',uvalue='RADIO3',/no_release)
  3356. ; button4 = Widget_Button(tlb, Value='Obs',uvalue='RADIO4',/no_release)
  3357. ; button5 = Widget_Button(tlb, Value='Bkg',uvalue='RADIO5',/no_release)
  3358. ;
  3359. ; if (typeplot eq 1) then Widget_Control, button1, Set_Button=typeplot
  3360. ; if (typeplot eq 2) then Widget_Control, button2, Set_Button=typeplot
  3361. ; if (typeplot eq 3) then Widget_Control, button3, Set_Button=typeplot
  3362. ; if (typeplot eq 4) then Widget_Control, button4, Set_Button=typeplot
  3363. ; if (typeplot eq 5) then Widget_Control, button5, Set_Button=typeplot
  3364. tlb1 = Widget_Base(tlba,Title='Push-Buttons', row=1, Scr_XSize=220,$
  3365. /Exclusive)
  3366. button01 = Widget_Button(tlb1, Value='Lat/Lon',uvalue='RADIO01',/no_release)
  3367. button02 = Widget_Button(tlb1, Value='N Polar',uvalue='RADIO02',/no_release)
  3368. button03 = Widget_Button(tlb1, Value='S Polar',uvalue='RADIO03',/no_release)
  3369. Widget_Control, button01, Set_Button=typeproj
  3370. tlb1a = Widget_Base(tlba,Title='Push-Buttons', row=1, Scr_XSize=250,$
  3371. /NonExclusive)
  3372. button001 = Widget_Button(tlb1a, Value='Plot Bad Obs', uvalue='RADIO001')
  3373. Widget_Control, button001, Set_Button=plot_bad_obs
  3374. if filetype eq 'CRT' then begin
  3375. button002 = Widget_Button(tlb1a, Value='Meridional', uvalue='RADIOSAL')
  3376. Widget_Control, button002, Set_Button=salinity
  3377. button003 = Widget_Button(tlb1a, Value='Speed', uvalue='RADIODENSITY')
  3378. Widget_Control, button003, Set_Button=density
  3379. endif else begin
  3380. ; tlb1b = Widget_Base(tlba,Title='Push-Buttons', row=1, Scr_XSize=90,$
  3381. ; /NonExclusive)
  3382. button002 = Widget_Button(tlb1a, Value='Salinity', uvalue='RADIOSAL')
  3383. Widget_Control, button002, Set_Button=salinity
  3384. ; tlb1c = Widget_Base(tlba,Title='Push-Buttons', row=1, Scr_XSize=90,$
  3385. ; /NonExclusive)
  3386. button003 = Widget_Button(tlb1a, Value='Density', uvalue='RADIODENSITY')
  3387. Widget_Control, button003, Set_Button=density
  3388. endelse
  3389. tlb2= Widget_Base(tlba,row=1)
  3390. button = WIDGET_BUTTON(tlb2, VALUE='Print',uvalue="PRINT")
  3391. button = WIDGET_BUTTON(tlb2, VALUE='Save',uvalue="SAVE")
  3392. button = WIDGET_BUTTON(tlb2, VALUE='Done',uvalue="DONE")
  3393. ; Realize the widget hierarchy.
  3394. WIDGET_CONTROL, base, /REALIZE
  3395. ; WIDGET_CONTROL, base2, /REALIZE
  3396. ; WIDGET_CONTROL, tlb, /REALIZE
  3397. ; Retrieve the widget ID of the draw widget. Note that the widget
  3398. ; hierarchy must be realized before you can retrieve this value.
  3399. WIDGET_CONTROL, draw, GET_VALUE=drawID
  3400. ; Create an anonymous array to hold the image data and widget IDs
  3401. ; of the label widgets.
  3402. ; stash = { imagePtr:imagePtr, label1:label1, label2:label2, $
  3403. ; label3:label3, $
  3404. ; xarr:xarr, yarr:yarr, dep:dep, val:val }
  3405. spawn,'echo part 2 `date`'
  3406. stash = { label1:label1, label2:label2, $
  3407. label3:label3, label4:label4, $
  3408. label5:label5, label6:label6, $
  3409. label7:label7, label8:label8, $
  3410. label9:label9, label10:label10, $
  3411. labt1:labt1, labt2:labt2, $
  3412. labt3:labt3, labt4:labt4, $
  3413. labt5:labt5, labt6:labt6, $
  3414. labt7:labt7, labt8:labt8, $
  3415. labt9:labt9, labt10:labt10, $
  3416. slider1label:slider1label, $
  3417. slider2label:slider2label, $
  3418. drawID:drawID, draw:draw, base:base, $
  3419. im_size:im_size, pixID:0, $
  3420. xcorn:0, ycorn:0, xdatacorn:0.0, ydatacorn:0.0, $
  3421. slider1:slider1, slider2:slider2, $
  3422. slider:slider, sliderb:sliderb, $
  3423. hiresmap:hiresmap, loresmap:loresmap, vertgradmenu:vertgradmenu, $
  3424. pltonbado:pltonbado, plot_only_bad_obs:plot_only_bad_obs, $
  3425. whtonblack:whtonblack, white_on_black:white_on_black, $
  3426. duplicates:duplicates, differences:differences, $
  3427. bindata:bindata, binsize:binsize, $
  3428. filetype:filetype, $
  3429. xarr:xarr, yarr:yarr, dep:dep, dayarr:dayarr, $
  3430. obs:obs, bkg:bkg, qcarr:qcarr, obstypes: obstypes, $
  3431. obs2:obs2, obs3:obs3, bkg2:bkg2, qcarr2:qcarr2, $
  3432. obnum:obnum, $
  3433. depmin:depmin, typeplot:typeplot, ombtypeplot:ombtypeplot, $
  3434. typeproj:typeproj, $
  3435. hires_map:hires_map, $
  3436. plot_bad_obs:plot_bad_obs, salinity: salinity, $
  3437. density:density, vertgrad:vertgrad, mld:mld, $
  3438. daymin:daymin, daymax:daymax, dayminl:dayminl, daymaxl:daymaxl, $
  3439. dayshi:dayshi, $
  3440. depminl:depminl, depmaxl:depmaxl, depmax:depmax, depscl:depscl, $
  3441. xrange:xrange, yrange:yrange, $
  3442. fmx:fmx, fmn:fmn, mx:mx, mn:mn, $
  3443. symsize:symsize, sym:sym, picsize:picsize, $
  3444. pmulti:pmulti, pmultinum:pmultinum, $
  3445. outfile:outfile, $
  3446. xrangedef:xrangedef, yrangedef:yrangedef, rmdi:rmdi, $
  3447. obstypeselect:obstypeselect, printobstypes:printobstypes, $
  3448. plottssel:plottssel, $
  3449. binspday:binspday, numtimeseries:numtimeseries, txt:txt, netcdf:netcdf, $
  3450. busy:busy, symscale:symscale, coltable:coltable, $
  3451. filterout:filterout, varname:varname }
  3452. ; Set the user value of the top-level base widget equal to the
  3453. ; 'stash' array.
  3454. WIDGET_CONTROL, base, SET_UVALUE=stash
  3455. ; Make the draw widget the current IDL drawable area.
  3456. WSET, drawID
  3457. spawn,'echo part 3 `date`'
  3458. ; Draw the image into the draw widget.
  3459. plotpoints, stash
  3460. ; plotpoints updates mx/mn values make sure these are included
  3461. WIDGET_CONTROL, base, SET_UVALUE=stash
  3462. spawn,'echo part 4 `date`'
  3463. ; Call XMANAGER to manage the widgets.
  3464. XMANAGER, 'dataplot', base, /NO_BLOCK
  3465. ; XMANAGER, 'dataplot', base
  3466. endif else begin
  3467. ;do batch
  3468. print,"batch"
  3469. drawID=-1
  3470. print, 'filetype: ',filetype
  3471. stash = { drawID:drawID,$
  3472. filetype:filetype, $
  3473. xarr:xarr, yarr:yarr, dep:dep, dayarr:dayarr, $
  3474. obs:obs, bkg:bkg, qcarr:qcarr, obstypes: obstypes, $
  3475. obs2:obs2, bkg2:bkg2, qcarr2:qcarr2, $
  3476. obnum:obnum, $
  3477. depmin:depmin, typeplot:typeplot, ombtypeplot:ombtypeplot, $
  3478. typeproj:typeproj, $
  3479. hires_map:hires_map, $
  3480. plot_only_bad_obs:plot_only_bad_obs, $
  3481. white_on_black:white_on_black, $
  3482. duplicates:duplicates, differences:differences, $
  3483. bindata: bindata, binsize:binsize, $
  3484. plot_bad_obs:plot_bad_obs, salinity: salinity, $
  3485. density:density, vertgrad:vertgrad, mld:mld, $
  3486. daymin:daymin, daymax:daymax, dayminl:dayminl, daymaxl:daymaxl, $
  3487. dayshi:dayshi, $
  3488. depminl:depminl, depmaxl:depmaxl, depmax:depmax, depscl:depscl, $
  3489. xrange:xrange, yrange:yrange, $
  3490. fmx:fmx, fmn:fmn, mx:mx, mn:mn, $
  3491. symsize:symsize, sym:sym, picsize:picsize, $
  3492. pmulti:pmulti, pmultinum:pmultinum, $
  3493. outfile:outfile, $
  3494. xrangedef:xrangedef, yrangedef:yrangedef, rmdi:rmdi, $
  3495. obstypeselect:obstypeselect, printobstypes:printobstypes, $
  3496. plottssel:plottssel, $
  3497. binspday:binspday, numtimeseries:numtimeseries, txt:txt, netcdf:netcdf, $
  3498. busy:busy, symscale:symscale, coltable:coltable, $
  3499. filterout:filterout, varname:varname }
  3500. if (keyword_set(ps)) then begin
  3501. ps=1
  3502. eps=0
  3503. landscape=1
  3504. pr2,file=stash.outfile+'.ps',landscape=landscape,ps=ps,eps=eps,color=1
  3505. ; plot data
  3506. if keyword_set(timeseries) then begin ; plot timeseries if keyword is set
  3507. plottimeseries,stash
  3508. endif else begin ; otherwise plot points on a map
  3509. plotpoints,stash
  3510. endelse
  3511. prend2,view=0
  3512. endif
  3513. if (keyword_set(gif)) then begin
  3514. thisDevice = !D.Name
  3515. Set_Plot, 'Z' ; do graphics in the background
  3516. ; Device, Set_Resolution=[640,512], decomposed=0
  3517. ; Device, Set_Resolution=[800,512], decomposed=0
  3518. Device, Set_Resolution=picsize, decomposed=0
  3519. Erase ; clear any existing stuff
  3520. !p.charsize=0.75
  3521. setupct, r, g, b, coltable=stash.coltable, $
  3522. white_on_black=stash.white_on_black ; setup color table
  3523. ; plot data
  3524. if keyword_set(timeseries) then begin ; plot timeseries if keyword is set
  3525. plottimeseries,stash
  3526. endif else begin ; otherwise plot points on a map
  3527. plotpoints,stash
  3528. endelse
  3529. ; if (keyword_set(gif)) then begin
  3530. ; IMAGE_GRAB, /gif, filename=stash.outfile+'.gif',/overwrite
  3531. snapshot = TVRD()
  3532. WRITE_GIF,stash.outfile+'.gif',snapshot, r, g, b
  3533. ; endif
  3534. Device, Z_Buffer=1 ; reset graphics mode
  3535. Set_Plot, thisDevice
  3536. !p.charsize=0.0
  3537. endif
  3538. if (keyword_set(txt)) then begin
  3539. if keyword_set(timeseries) then begin ; plot timeseries if keyword is set
  3540. plottimeseries,stash
  3541. endif else begin ; otherwise plot points on a map
  3542. plotpoints,stash
  3543. ; print,'no txt version of plotpoints!'
  3544. endelse
  3545. endif
  3546. if (keyword_set(netcdf)) then begin
  3547. if keyword_set(timeseries) then begin
  3548. print,'no netcdf version of timeseries!'
  3549. endif else begin
  3550. plotpoints,stash
  3551. endelse
  3552. endif
  3553. if (stash.filterout ne '') then begin
  3554. selpoints, stash, lonsel, latsel, innovsel, qcsel, daysel, obstypsel, obnumsel, numsel, typestr
  3555. endif
  3556. endelse ; batch
  3557. END