summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf')
-rw-r--r--Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf205
1 files changed, 173 insertions, 32 deletions
diff --git a/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf b/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf
index b01dff4de55..ff1cb14b3d0 100644
--- a/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf
+++ b/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf
@@ -1,5 +1,5 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% mcf2graph ver 4.70 Copyright (c) 2013-2021 Akira Yamaji
+% mcf2graph ver 4.71 Copyright (c) 2013-2021 Akira Yamaji
%
% Permission is hereby granted, free of charge, to any person obtaining a copy of this software
% and associated documentation files (the "Software"), to deal in the Software without restriction,
@@ -37,7 +37,7 @@
% Set to use plain.mp (label,arrow,atom) : mpost -s labeloffset=2 FILENAME
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tracingstats:=1;
-message "* This is mcf2graph ver 4.70 2021.08.01";
+message "* This is mcf2graph ver 4.71 2021.09.05";
%-------------------------------------------------------------------------------------------------
newinternal cntA,cntB,cntM,minX,minY,maxX,maxY,sftX,sftY,com,par,envT,envB,lenT,lineT,angT,rotT,
crR,nA,nB,nC,nD,nE,nF,nS,nL,nR,nU,nP,xpos,ypos,markA,markB,saveA,saveB,bondL;
@@ -46,7 +46,7 @@ numeric save_num[],comD[][],parD[][],adrD[][],cntD[],tbl_atom[],tbl_group[][],f_
com_group[][],par_group[][],cnt_group[],colorA[],colorB[],sumA[],bondC[],hideH[],lineB[],
sB[],eB[],angB[],angA[],lenB[],angX[],numS[],wdM[],htM[],wdA[],dxA[],cmm_adr[],mc_indent[];
string save_str[],tbl_atom_str[],strD[],tag[],file_name_output,blank_str,aux_delimiter,atomfont,
- mpfont,s_tag,s_var,cal_FM,cal_MW,cal_MI,
+ default_data_file,default_temp_file,mpfont,s_tag,s_var,cal_FM,cal_MW,cal_MI,
inf_NO,inf_EN,inf_JN,inf_FM,inf_CAS,inf_USE,inf_EXA,inf_EXB,inf_MW;
pair save_pair[],posA[],posM[][],msize,mposition,fsize,fmargin,save_mposition,posBs,posBe,dum;
picture mol_stru[],atom_picture,save_picture,temp_picture;
@@ -94,6 +94,8 @@ if (known green)and(known ahlength):
color color_list[];
for i=1 upto 100: colorA[i]:=colorB[i]:=0; endfor
prologues:=3;
+ default_data_file:="mcf_data_base.mcf";
+ default_temp_file:="temp.mcf";
mpfont:="uhvr8r";
atomfont:=defaultfont:="";
%--default ahangle=45---------------------------------------------------------------------
@@ -253,16 +255,16 @@ enddef;
def beginfont(text s)=
begingroup
save ',f_beginchar,f_ext,blen,ext,add,ang_br,n_fw,n_bw,at_colon,at_semicol,temps,t_tag,
- mc,info,file_name_input,bond_cnt,warning_cnt,hideH_cnt,bondC;
+ mc,info,file_name_input,bond_cnt,warning_cnt,hideH_cnt,bondC,filter_s;
numeric at_semicol[];
- string info[],mc[],mc,temps,file_name_input,t_tag;
+ string info[],mc[],mc,temps,file_name_input,t_tag,filter_s;
%------------------------------------------------------------------------------------------------
def ext=ext_to_font enddef;
def add=add_to_molecule enddef;
def '=read_ud enddef;
%------------------------------------------------------------------------------------------------
inf_NO:=inf_EN:=inf_JN:=inf_MW:=inf_FM:=inf_CAS:=inf_USE:=inf_EXA:=inf_EXB:="-";
- mc:=t_tag:=file_name_input:=cal_MW:=cal_MI:=cal_FM:="";
+ mc:=t_tag:=file_name_input:=cal_MW:=cal_MI:=cal_FM:=filter_s:="";
%------------------------------------------------------------------------------------------------
parts_cnt:=parts_usr_start;
parts_int:=parts_int_start;
@@ -376,8 +378,8 @@ enddef;
%-------------------------------------------------------------------------------------------------
def pickup_data_unit(expr t,v)=
begingroup
- save data_unit_cnt,f_end,semicol_cnt,cond,n_var;
- f_end:=data_unit_cnt:=semicol_cnt:=cond:=at_semicol[0]:=inf_num:=0;
+ save unit_cnt,f_end,semicol_cnt,cond,n_var;
+ f_end:=unit_cnt:=semicol_cnt:=cond:=at_semicol[0]:=inf_num:=0;
if t="n": n_var:=scantokens(v); fi
forever:
temps:=readfrom file_name_input;
@@ -385,9 +387,9 @@ def pickup_data_unit(expr t,v)=
exitif temps=EOF;
if subc(1,temps)="%":
ef (subc(1,temps)="+")and(subc(2,temps)<>"-"):
- data_unit_cnt:=data_unit_cnt+1;
+ unit_cnt:=unit_cnt+1;
if v="*": cond:=1;
- ef t="n": if data_unit_cnt=n_var: cond:=1; fi
+ ef t="n": if unit_cnt=n_var: cond:=1; fi
else: if v=scantokens("inf_"&t): cond:=1; fi
fi
if cond=1:
@@ -414,10 +416,7 @@ def pickup_data_unit(expr t,v)=
endfor
fi
else:
- semicol_cnt:=0;
- for i=1 upto length(temps):
- if subc(i,temps)=";": semicol_cnt:=semicol_cnt+1; at_semicol[semicol_cnt]:=i; fi
- endfor
+ semicol_cnt:=count_char(";",temps);
inf_num:=semicol_cnt+1;
for i=1 upto inf_num:
if i<=semicol_cnt: info[i]:=substring (at_semicol[i-1],at_semicol[i]-1) of temps;
@@ -446,6 +445,13 @@ vardef scan_char(expr c,s,d,n)=
fi
n_s
enddef;
+%--------------------------------------------------------------------------------------------------
+vardef count_char(expr c,s)=
+ save nS;
+ nS:=0;
+ for i=1 upto length(s): if subc(i,s)=c: nS:=nS+1; at_semicol[nS]:=i; fi endfor
+ nS
+enddef;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def set_def_MC=
save /,//,/*,*/,**,*/*,~,^,',`,<,>,:,=,\,\\,*\,\*,*\*,@,@$,$,&,&$,#,##,{,},|,||,_,inside_def_MC;
@@ -454,9 +460,7 @@ def set_def_MC=
| :=(_com,_mark); || := (_com,_moff); ##:=(_com,_len_e);
_:=Me; \:=0; \\:=zero_dm; *\:=zero_wf; \*:=zero_zf; *\*:=zero_wv;
let = ==op_equ; let : ==op_col; let ^ ==op_hat; let ~ ==op_til; let > ==op_lt; let ` ==op_bq;
-%%%%%%%%% def @$ == @.$ enddef;
- def @$ == jump_atom_abs enddef;
- def { == read_number( enddef; let } == ); def '==read_id enddef;
+ def @$ == jump_atom_abs enddef; def { == read_number( enddef; let } == ); def '==read_id enddef;
def < == rot_angle enddef; def @ == jump_atom enddef; def & == cyc_atom enddef;
def # == chg_length enddef; def $ == abs_adress enddef; def &$ == &.$ enddef;
def / == group_si enddef; def // == group_dm enddef; def */ == group_wf enddef;
@@ -2074,24 +2078,161 @@ def proc_err(expr ERR_CODE,ADR)=
fi
enddef;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-vardef count_data_unit(expr f)=
- save temps,file_name,f_mcf,f_error,line_cnt,unit_cnt;
- string temps,file_name;
- line_cnt:=unit_cnt:=f_mcf:=f_error:=0;
- file_name:=f&".mcf";
- forever:
- temps:=readfrom file_name;
- exitif temps=EOF;
- line_cnt:=line_cnt+1;
- if subc(1,temps)="%":
+def query(text s)=
+ begingroup
+ save temps,file_name,f_mcf,f_line,unit_row,unit_cnt,line_s,unit_row_cnt,mc_row,line_cnt,
+ semicol_cnt,inf_num,info_s,filter_n,tag_s,var_s,order,min_s,min_n,par_cnt,key_cnt,var_n,
+ sign_at,sign_n,filter_tag,filter_var,filter_sign,filter_cnt,temp_s,
+ at_semicol,at_colon,at_equal,at_less,at_greater,at_n;
+ string line_s[][],sort_s[],par_list[],sort_all[],key_s[],filter_s[],filter_tag[],filter_var[],
+ temps,file_name_input,info_s,tag_s,var_s,temp_s,min_s;
+ numeric unit_row_cnt[],at_semicol[],order[],order_tbl[],filter_sign[];
+ unit_row:=f_mcf:=mc_row:=line_cnt:=inf_num:=par_cnt:=key_cnt:=filter_cnt:=at_semicol[0]:=0;
+ unit_cnt:=1;
+ for list=s: par_cnt:=par_cnt+1; par_list[par_cnt]:=list; endfor
+ %------------------------------------------------------------------------------------------------
+ file_name_input:=default_data_file;
+ file_name_output:=default_temp_file;
+ %------------------------------------------------------------------------------------------------
+ for j=1 upto par_cnt:
+ at_colon:=scan_char(":",par_list[j],0,1);
+ at_equal:=scan_char("=",par_list[j],0,1);
+ at_less:=scan_char("<",par_list[j],0,1);
+ at_greater:=scan_char(">",par_list[j],0,1);
+ %---------------------------------------------------------------------------------------------
+ if at_colon>=2: sign_at:=at_colon; sign_n:=0; at_n:=1;
+ ef at_equal>=2: if (at_equal-1)=at_less: sign_at:=at_equal; sign_n:=5; at_n:=2;
+ ef (at_equal-1)=at_greater: sign_at:=at_equal; sign_n:=6; at_n:=2;
+ else: sign_at:=at_equal; sign_n:=1; at_n:=1; fi
+ ef at_greater>=2: if (at_greater-1)=at_less: sign_at:=at_greater; sign_n:=2; at_n:=2;
+ else: sign_at:=at_greater; sign_n:=4; at_n:=1; fi
+ ef at_less>=2: sign_at:=at_less; sign_n:=3; at_n:=1;
+ fi
+ tag_s:=substring (0,sign_at-at_n) of par_list[j];
+ var_s:=substring (sign_at,length(par_list[j])) of par_list[j];
+ %---------------------------------------------------------------------------------------------
+ if sign_n=0:
+ if tag_s="i": file_name_input:=var_s;
+ ef tag_s="o": file_name_output:=var_s;
+ ef tag_s="s": key_cnt:=key_cnt+1; key_s[key_cnt]:=var_s;
+ fi
+ %---------------------------------------------------------------------------------------------
else:
- if (subc(1,temps)="+")and(subc(2,temps)<>"-"): if f_mcf=1: f_error:=1; fi f_mcf:=1; fi
- if (subc(1,temps)="+")and(subc(2,temps)="-"):
- if f_mcf=0: f_error:=1; else: f_mcf:=0; unit_cnt:=unit_cnt+1; fi
+ filter_cnt:=filter_cnt+1;
+ filter_tag[filter_cnt]:=tag_s;
+ filter_sign[filter_cnt]:=sign_n;
+ if (sign_n>=3)and(is_num(var_s)=1): filter_var[filter_cnt]:=fix_n(var_s);
+ else: filter_var[filter_cnt]:=var_s;
+ fi
+ fi
+ endfor
+ %------------------------------------------------------------------------------------------------
+ forever:
+ temps:=readfrom file_name_input; exitif temps=EOF;
+ if subc(1,temps)<>"%":
+ line_cnt:=line_cnt+1; unit_row:=unit_row+1;
+ line_s[unit_cnt][unit_row]:=temps;
+ if (subc(1,temps)="+")and(subc(2,temps)<>"-"): f_mcf:=1; mc_row:=1;
+ ef (subc(1,temps)="+")and(subc(2,temps)="-"):
+ unit_row_cnt[unit_cnt]:=unit_row;
+ f_mcf:=unit_row:=0;
+ if filter_n=1: unit_cnt:=unit_cnt+1; fi
+ ef (subc(1,temps)<>"+")and(subc(1,temps)<>"%"):
+ if f_mcf=1: mc_row:=mc_row+1;
+ else:
+ semicol_cnt:=count_char(";",temps);
+ inf_num:=semicol_cnt+1;
+ filter_n:=1;
+ %---------------------------------------------------------------------------------------
+ for i=1 upto inf_num:
+ if i<=semicol_cnt: info_s:=substring (at_semicol[i-1],at_semicol[i]-1) of temps;
+ else: info_s:=substring (at_semicol[semicol_cnt],length(temps)) of temps;
+ fi
+ at_colon:=scan_char(":",info_s,0,1);
+ tag_s:=substring (0,at_colon-1) of info_s;
+ var_s:=substring (at_colon,length(info_s)) of info_s;
+ %-------------------------------------------------------------------------------------
+ for j=1 upto key_cnt:
+ if key_s[j]=tag_s:
+ if is_num(var_s)=1: sort_s[j]:=fix_n(var_s); else: sort_s[j]:=var_s; fi
+ fi
+ endfor
+ %-------------------------------------------------------------------------------------
+ for j=1 upto filter_cnt:
+ if filter_tag[j]=tag_s:
+ if (filter_sign[j]>=3)and(is_num(var_s)=1): temp_s:=fix_n(var_s);
+ else: temp_s:=var_s;
+ fi
+ if filter_sign[j]=1: if not(temp_s= filter_var[j]): filter_n:=0; fi
+ ef filter_sign[j]=2: if not(temp_s<>filter_var[j]): filter_n:=0; fi
+ ef filter_sign[j]=3: if not(temp_s< filter_var[j]): filter_n:=0; fi
+ ef filter_sign[j]=4: if not(temp_s> filter_var[j]): filter_n:=0; fi
+ ef filter_sign[j]=5: if not(temp_s<=filter_var[j]): filter_n:=0; fi
+ ef filter_sign[j]=6: if not(temp_s>=filter_var[j]): filter_n:=0; fi
+ fi
+ fi
+ endfor
+ endfor
+ %-------------------------------------------------------------------------------------
+ sort_all[unit_cnt]:="";
+ for j=1 upto key_cnt:
+ if j=key_cnt: sort_all[unit_cnt]:=sort_all[unit_cnt]&sort_s[j];
+ else: sort_all[unit_cnt]:=fix_s(15,sort_s[1]);
+ fi
+ endfor
+ %-------------------------------------------------------------------------------------
+ fi
fi
- exitif f_error=1;
fi
endfor
- if f_error=1: -line_cnt else: unit_cnt fi
+ %=============================================================================================
+ unit_cnt:=unit_cnt-1;
+ %---------------------------------------------------------------------------------------------
+ if key_cnt>=1:
+ for i=1 upto unit_cnt: order[i]:=0; endfor
+ for i=1 upto unit_cnt: min_s:="~";
+ for j=1 upto unit_cnt:
+ if order[j]=0: if sort_all[j]<min_s: min_s:=sort_all[j]; min_n:=j; fi fi
+ endfor
+ order[min_n]:=i; order_tbl[i]:=min_n;
+ endfor
+ for i=1 upto unit_cnt:
+ for j=1 upto unit_row_cnt[order_tbl[i]]: printf line_s[order_tbl[i]][j]; endfor
+ endfor
+ else:
+ for i=1 upto unit_cnt: for j=1 upto unit_row_cnt[i]: printf line_s[i][j]; endfor endfor
+ fi
+ closefrom file_name_input; closefrom file_name_output;
+ endgroup;
+enddef;
+%=============================================================================================
+vardef fix_s(expr n,s)=
+ save temp_s;
+ string temp_s;
+ if length(s)<n: temp_s:=s&substring(0,n-length(s)) of blank_str;
+ ef length(s)>n: temp_s:=substring(0,n) of s;
+ fi
+ temp_s
+enddef;
+%---------------------------------------------------------------------------------------------
+vardef fix_n(expr s)=
+ save temp_s,at_dot;
+ string temp_s;
+ temp_s:=s;
+ at_dot:=scan_char(".",temp_s,0,1);
+ if at_dot=0: temp_s:=fsr(4)(temp_s); ef at_dot=1: temp_s:=" 0"&temp_s;
+ ef at_dot=2: temp_s:=" "&temp_s; ef at_dot=3: temp_s:=" "&temp_s;
+ ef at_dot=4: temp_s:=" "&temp_s;
+ fi
+ temp_s
+enddef;
+%---------------------------------------------------------------------------------------------
+vardef is_num(expr s)=
+ save numeric_n;
+ numeric_n:=1;
+ for i=1 upto length(s):
+ if ((subc(i,s)>="0")and(subc(i,s)<="9"))or(subc(i,s)="."): else: numeric_n:=0; fi
+ endfor
+ numeric_n
enddef;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%