#pragma rtGlobals=1 // Use modern global access method. ////////////// Conversion //////////////////// // //画像ファイル(.bmp, .png, .jpg)やグラフをEPS/EMFに変換する //EPS として保存したときはTeXに貼ることを想定し、TeX用のコマンドを履歴に表示する // // 使い方 // 1. 画像ファイルの場合は、ファイルのあるフォルダをCtrl+Shift+Alt+4 で出てきたプロンプトに入力 // 2. Ctrl+Shift+Alt+1 or メニューバーのConversion-> Convert Each // 3. 必要事項を選択&入力 // Name 変換するグラフ・画像ファイル // Width 幅 // Height 高さ // Unit 長さの単位 cm or inch or point (Igor での長さの単位) // Output 出力ファイルの名前 // Format 出力ファイル形式 EPS or EMF // Color 出力をカラーにするかどうか Yes or No // // List から一括で変換する // 1. List をつくっていない場合は、まずList をつくる // 1-1. Ctrl+Shift+Alt+3 or メニューバーのConversion-> Edit InfoList // 1-2. でてきた Table に Name, Path, Width, Height, Unit, Output, Format Color を記入 // 2. Ctrl+Shift+Alt+2 or or メニューバーのConversion-> Convert All // // その他 // グラフの場合、マーキーメニューからそのグラフを変換することも可能 // List 用のWave を保存するためのDataFolder としてroot:Conversion を使うので、 // 既にその名前のDataFolder がある場合には注意が必要 // //////////////////////////////////////////////////////////////////////////// Menu "Conversion" "Convert Each/SO1",ConversionPrompt() "Convert All/SO2",SaveGraphicsFromList() "Edit Info List/SO3",EditInfo() "Set Path of Pictures/SO4",NewPath/M="Where are Pictures from?"/O/Q/Z PICT "Edit Procedure",DisplayProcedure "InitializeConversion" InitializeConversion() End Menu "GraphMarquee" "Conversion",GraphConvertMarquee() End Function/S InitializeConversion() String folder Variable num folder=GetDataFolder(1) NewDataFolder/O/S root:Conversion Wave/T/Z Name if(WaveExists(Name)==0) Make/O/T/N=1 Name endif num=DimSize(Name,0) PathInfo PICT if(V_flag==0) NewPath/M="Where are Pictures from?"/O/Q/Z PICT PathInfo PICT endif if(WaveExists(Path)==0) Make/O/T/N=(num) Path Path[]=S_path endif if(WaveExists(Width)==0) Make/O/N=(num) Width endif if(WaveExists(Height)==0) Make/O/N=(num) Height endif if(WaveExists(Unit)==0) Make/O/T/N=(num) Unit endif if(WaveExists(Output)==0) Make/O/T/N=(num) Output endif if(WaveExists(Format)==0) Make/O/T/N=(num) Format endif if(WaveExists(Color)==0) Make/O/T/N=(num) Color endif SetDataFolder $folder return "" End Function ChangeLengthUnit(input,inUnit,outUnit) Variable input String inUnit,outUnit Variable inScale,outScale String list list="inch:1;cm:2.54;point:72;" inScale=NumberByKey(inUnit,list) outScale=NumberByKey(outUnit,list) return input/inScale*outScale End Function EditInfo() Wave/T Name=root:Conversion:Name Wave/T Path=root:Conversion:Path Wave Width=root:Conversion:Width Wave Height=root:Conversion:Height Wave/T Unit=root:Conversion:Unit Wave/T Output=root:Conversion:Output Wave/T Format=root:Conversion:Format Wave/T Color=root:Conversion:Color DoWindow/K ListTable Edit/W=(50,50,400,200) Name,Path,Width,Height,Unit,Output,Format,Color ModifyTable width[0]=0,width[3]=40,width[4]=40,width[5]=30,width[7]=40,Width[8]=40 DoWindow/C ListTable End Function SaveGraphicsFromList() Variable num,i Wave/T/Z Name=root:Conversion:Name Wave/T/Z Path=root:Conversion:Path Wave/Z Width=root:Conversion:Width Wave/Z Height=root:Conversion:Height Wave/T/Z Unit=root:Conversion:Unit Wave/T/Z Output=root:Conversion:Output Wave/T/Z Format=root:Conversion:Format Wave/T/Z Color=root:Conversion:Color if(WaveExists(Name)*WaveExists(Path)*WaveExists(Width)*WaveExists(Height)*WaveExists(Unit)*WaveExists(Output)*WaveExists(Format)*WaveExists(Color)==0) InitializeConversion() EditInfo() return 0 endif num=DimSize(Name,0) for(i=0;i Adjust to Height with same W/H ratio)" Prompt height,"Height ( 0 -> Adjust to Width with same W/H ratio)" Prompt unit,"Unit",popup,"cm;inch;point;" Prompt output,"Output" Prompt format,"Format",popup,"EPS;EMF;" Prompt color,"Color?",popup,"Yes;No;" DoPrompt "Convert",name,width,height,unit,output,format,color if(V_flag) return 0 endif SaveGraphics(name,width,height,unit,output,format,color) End Function GraphConvertMarquee() GetMarquee/Z if(V_flag==0) return 0 endif Variable width,height String unit,output,format,color Prompt width,"width" Prompt height,"height" Prompt unit "Length unit",popup,"cm;inch;point;" Prompt output,"Output" Prompt format,"Format",popup,"EPS;EMF;" Prompt color,"Color?",popup,"Yes;No;" DoPrompt "Graph",width,height,unit,output,format,color if(V_flag) return 0 endif SaveGraphics(S_marqueeWin,width,height,unit,output,format,color) End Function SaveGraphics(name,width,height,unit,output,format,color) String name,unit,output,format,color Variable width,height if(StringMatch(name[strlen(name)-4],".")) if(strlen(output)==0) output=name[0,strlen(name)-5] endif LoadPICT/O/P=PICT/Q name,$output if(V_flag==0) return 0 endif KillStrings/Z S_info if(width+height==0) width=NumberByKey("WIDTH",S_info) height=NumberByKey("HEIGHT",S_info) elseif(width==0) width=height*NumberByKey("WIDTH",S_info)/NumberByKey("HEIGHT",S_info) elseif(height==0) height=width*NumberByKey("HEIGHT",S_info)/NumberByKey("WIDTH",S_info) endif DisplayPicture(output,width,height,unit) SaveWindow(output,output,format,color) DoWindow/K $output KillPICTs/Z $output else if(strlen(output)==0) output=name endif MoveWindow/W=$name 1,1,1,1 GetWindow $name,wsize if(width+height==0) width=V_right-V_left height=V_bottom-V_top elseif(width==0) width=height*(V_right-V_left)/(V_bottom-V_top) width=ChangeLengthUnit(width,unit,"point") height=ChangeLengthUnit(height,unit,"point") elseif(height==0) height=width*(V_bottom-V_top)/(V_right-V_left) width=ChangeLengthUnit(width,unit,"point") height=ChangeLengthUnit(height,unit,"point") endif MoveWindow/W=$name 0,0,width,height SaveWindow(name,output,format,color) MoveWindow/W=$name 0,0,0,0 endif End Function DisplayPicture(name,width,height,unit) String name,unit Variable width,height Variable wratio,hratio,DPI String info info=PICTInfo(name) DPI=ScreenResolution width=ChangeLengthUnit(width,unit,"inch") height=ChangeLengthUnit(height,unit,"inch") wratio=width*DPI/NumberByKey("WIDTH",info) hratio=height*DPI/NumberByKey("HEIGHT",info) DoWindow/K $name Display/I/W=(0,0,width,height) DoWindow/C $name DrawPICT 0,0,wratio,hratio,$name End Function SaveWindow(name,output,format,color) String name,format,output,color String cmd DoWindow $name if(V_flag==0) return 0 endif cmd="SavePICT/C="+num2str(WhichListItem(color,"No;Yes;"))+"/O/P=HOME/WIN="+name strswitch(format) case "EPS": cmd=cmd+"/S/EF=2/E=-3 as \""+output+".eps\"" Execute cmd print cmd print "\includegraphics{"+output+".eps}" break case "EMF": cmd=cmd+"/E=-2 as \""+output+".emf\"" Execute cmd break endswitch End