function niris_inv_niris1, date ; NIRIS_inv ; This routine enhances Stokes inversion for the NIRIS data at the NST. ; Inputs: IMG , header ; Output: Inversion map consisting of ; ; B = par[0] ; magnetic field strength in Gauss ; theta = par[1] ; inclination in radian ; chi = par[2] ; azimuth in radian ; eta0 = par[3] ; ratio of line center opacity to the continuum one ; dlambdaD= par[4] ; Doppler width in angstrom ; a = par[5] ; damping parameter ; lambda0 = par[6] ; line center in A ; B0 = par[7] ; zeroth order of the source function ; B1 = par[8] ; first order of the source function ; ; This routine performs parallel computing. If you don't need it, then you can ; bypass this routine simply to call 'main_test'. ; The original routine 'main_test' was coded by J. Chae in Mar. 2016 ; This routine was coded by K. Ahn in Apr. 2016 ; For any question regarding the code please contact the author. ; email: ksahn@bbso.njit.edu ;pathi='F:\NIRIS_data\' yr=strmid(date, 0,4) mo=strmid(date, 4,2) da=strmid(date, 6,2) pathi='W:\'+yr+'\'+mo+'\'+da+'\' ;temp ;lpathi='X:\2021\07\11\' index=file_search(pathi+date+'\final\cals_*.fts') help, index nCPUs = !CPU.HW_NCPU-2 oBridge = objarr(nCPUs-1) rangearr=intarr(nCPUs,2) window, xs=720, ys=720 loadct, 13 for ind=0, nm1(index) do begin ftime=strmid(index[ind],strlen(index[ind])-17,17) print, ftime timest=strmid(systime(), 11, 2) ; if timest eq '08' or timest eq '12' or timest eq '16' then begin ; oUrl = obj_new('IDLnetUrl') ; ok = oUrl->Get(URL='http://www.bbso.njit.edu/~ksahn/idlsendmail.php?info='+ftime+'_inv', /STRING_ARRAY) ; obj_destroy, oUrl ; endif if file_test(pathi+date+'\inv\nirisinv_'+ftime) then begin print, ftime, ' already exists' goto, jump7 endif else img=readfits(index[ind],header) sze=size(img) nx=sze[1] & ny=sze[2] parmap=fltarr(nx,ny,10) parmap(*)=0. parmap[*,*,9]=img[*,*,0,0] rangearr(*)=0 t1=systime(/s) for i=0, nCPUs-2 do oBridge[i] = obj_new('IDL_IDLBridge') for i=0, nCPUs-1 do begin range = [ny/nCPUs*i,ny/nCPUs*(i+1)-1] if i EQ n_elements(oBridge) then range[1] = ny-1 rangearr[i,*]=range ; print, range if i EQ nCPUs-1 then $ parmap[*,range[0]:range[1],0:8] = main_test(img[*,range[0]:range[1],*,*], header) $ else begin ; oBridge[i] = obj_new('IDL_IDLBridge') oBridge[i]->SetVar, 'a', img[*,range[0]:range[1],*,*] oBridge[i]->SetVar, 'h', header oBridge[i]->Execute, ".r main_test.pro" oBridge[i]->Execute, "results = main_test(a,h)", /nowait endelse endfor ;print, rangearr notdone = 1 while notdone do begin done=0 for i=0, n_elements(oBridge)-1 do $ done = done+oBridge[i]->Status() if done EQ 0 then notdone=done endwhile for i=0, n_elements(oBridge)-1 do begin parmap[*,rangearr[i,0]:rangearr[i,1],0:8] =[oBridge[i]->GetVar('results')] endfor t3=systime(/s) print, 'Total time=', t3-t1 tv, bytscl(parmap[*,*,0], 0, 3000) writefits, pathi+date+'\inv\nirisinv_'+ftime, parmap for i=0, nm1(oBridge) do oBridge[i]->Cleanup jump7: endfor print, 'done!', date return, 1 end