;+ ; NAME: ; ml_importcmm ; ; PURPOSE: ; Reads information from UWash CMM files in plaintext format and convert to a Yanny-style ; format for where the holes in a plate were actually drilled. ; ; The CMM plaintext files are stored on the ?? svn at ??. ; This routine looks through this directory for the file for a given ; plateid, converts it into a Yanny file, and sticks it into the ; appropriate directory in mangacore. ; ; Nomx, nomy values are in xflat,yflat coordinates. ; ; CALLING SEQUENCE: ; ml_importcmm,plateidstr ; ; INPUTS: ; plateidstr: Long-integer or string format plate ID ; ; OPTIONAL INPUTS: ; ; OPTIONAL KEYWORDS: ; ; OUTPUT: ; ; COMMENTS: ; ; EXAMPLES: ; ; BUGS: ; Currently hard-coded to take input from a local folder ; on DRL desktop computer. Will be changed once a permanent ; import solution in place. ; ; PROCEDURES CALLED: ; concat_dir() ; ml_getenv() ; ml_plategroup() ; fileandpath() ; readcol ; ml_checkcmm ; splog ; ; INTERNAL SUPPORT ROUTINES: ; ; REVISION HISTORY: ; 07-Dec-2012 Written by David Law (Dunlap Institute; drlaw@di.utoronto.ca) ; 03-Dec-2013 Adapted for production run (D. Law) ;- ;------------------------------------------------------------------------------ pro ml_importcmm,plateidstr,inputdir=inputdir,outputdir=outputdir ; Convert plateid to long integer if a string was provided plateid=long(plateidstr) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Set up I/O paths ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Default input directory (STILL UNCERTAIN) if (keyword_set(inputdir)) then inputdir=inputdir $ else inputdir='/Users/drlaw/Desktop/cmmtemp/' ; Default output directory if (keyword_set(outputdir))then outputdir=outputdir $ else begin outputdir=concat_dir(ml_getenv('MANGACORE_DIR'),'drill/'+ml_plategroup(plateid)+'/') ; Create the directory if it didn't exist already spawn, 'mkdir -p ' + outputdir endelse ; Look for files in the input directory with the cmm format names ; (fit_6653_1_2012-12-06.txt for example, where 6653 is the plateid) files=file_search(inputdir,'fit_*.txt',count=nfiles) filename=fileandpath(files) fileid=intarr(nfiles) ; Break up filename at the _ and pick second piece for plateid for i=0,nfiles-1 do fileid[i]=(strsplit(filename[i],'_',/extract))[1] ; Match the plateid index=where(fileid eq plateid,nindex) ; Bomb out if no match if (nindex eq 0) then begin splog,'ERROR: No matching plateid found' return endif if (nindex eq 1) then begin splog,'Using '+filename[index] endif if (nindex gt 1) then begin splog,'WARNING: More than one plateid match found.' splog,'Using '+filename[index[nindex-1]] endif inpfile=files[index[nindex-1]] outfile=concat_dir(outputdir,strcompress('plate-'+string(plateid)+'-CMM.par',/remove_all)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Copy from input to output files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Read header parameters first and determine header length openr,drillun,inpfile,/get_lun openw,lun,outfile,/get_lun ; Header goes up to the line saying 'DataTable' temp='' string1='' nlines=0 while (string1 ne 'DataTable') do begin readf,drillun,temp string1=(strsplit(temp,' ',/extract))[0] ; Split up the FitOffset line into x and y components if (string1 eq 'FitOffset') then begin printf,lun,'FitOffsetX '+(strsplit(temp,' ',/extract))[1] printf,lun,'FitOffsetY '+(strsplit(temp,' ',/extract))[2] endif if ((string1 ne '#') and (string1 ne 'DataTable') and (string1 ne 'FitOffset')) then begin printf,lun,temp endif ; One more line in the header nlines++ endwhile ; Read data vectors readcol,inpfile,nomx,nomy,measx,measy,residx,residy,residr,nomdia,diaerr,qpresidx,qpresidy,qpresidr,skipline=nlines+1 ; Setup Yanny file printf,lun,'' printf,lun,'typedef struct {' printf,lun,'double nomx;' printf,lun,'double nomy;' printf,lun,'double measx;' printf,lun,'double measy;' printf,lun,'double residx;' printf,lun,'double residy;' printf,lun,'double residr;' printf,lun,'double nomdia;' printf,lun,'double diaerr;' printf,lun,'double qpresidx;' printf,lun,'double qpresidy;' printf,lun,'double qpresidr;' printf,lun,'} CMMPOS;' printf,lun,'' print,size(nomx) for i=0,(size(nomx))[1]-1 do begin printf,lun,strcompress('CMMPOS '+string(nomx[i])+string(nomy[i])+string(measx[i])+string(measy[i])+string(residx[i])+string(residy[i])+string(residr[i])+string(nomdia[i])+string(diaerr[i])+string(qpresidx[i])+string(qpresidy[i])+string(qpresidr[i])) endfor close,lun close,drillun free_lun,lun free_lun,drillun ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Now run the file through QA checks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ml_checkcmm,outfile,/verbose return end