Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have written a command, which takes five arguments to interpolate between two points.

Now I tried to get the two points from an csv file.

\documentclass{article}
\usepackage{expl3}
\usepackage[ansinew]{inputenc}
\usepackage{datatool}
\usepackage{filecontents}
\begin{filecontents}{tempdatabb.dat}
10 & 100
20 & 130
30 & 150
40 & 170
50 & 190
60 & 210
70 & 250
80 & 290
90 & 350
100 & 410
120 & 550
140 & 690
\end{filecontents}

\makeatletter
\ExplSyntaxOn
\cs_set_eq:NN \ifinstr \tl_if_in:nnTF
\DeclareRobustCommand*\assignvalues[2]{\@assignvalues{#1}{#2}}
\long \def\@assignvalues#1#2{
  \seq_set_split:Nnn \l_tmpa_seq { | } {#1}
  \seq_set_split:Nnn \l_tmpb_seq { | } {#2}
  \seq_mapthread_function:NNN \l_tmpa_seq \l_tmpb_seq \assignvalues@ii
}
\long \def \assignvalues@ii #1#2 { \protected@csedef{#1}{#2} }
\ExplSyntaxOff
\makeatother

\begin{document}
\assignvalues{suchwert}{35}

\DTLsetseparator{&}
\DTLloaddb[keys={temperatur,dichte},noheader]{scoreAA {tempdatabb.dat}
\begin{table}[htbp]
\centering
\begin{tabular}{llr}
\bfseries Temperatur & \bfseries Dichte %
\DTLforeach[\DTLislt{\temperatur}{\suchwert}]{scoreAA}%
{\temperatur=temperatur,\dichte=dichte}{%
\\\temperatur & \dichte 
}%
\end{tabular}
\end{table}
\end{document}

I'd like to get the points (30,150) and (40,170) in four variables as assignment like:

\assignvalues{firstx}{30}
\assignvalues{firsty}{150}
\assignvalues{secondx}{40}
\assignvalues{seconxy}{170}

But the MWE does not work because of

\DTLforeach[\DTLislt{\temperatur}{\suchwert}]{scoreAA}%

If I use

\DTLforeach[\DTLislt{\dichte}{\suchwert}]{scoreAA}%

it works as MWE.

Any ideas about this task?

This question has been asked @ http://www.mrunix.de/forums/showthread.php?t=74920 (German).

Some more Examples about the input/output relation

Function (input/output)

%Example 1
%Input:

\assignvalues{suchwert}{35}

%Output:

\assignvalues{firstx}{30}
\assignvalues{firsty}{150}
\assignvalues{secondx}{40}
\assignvalues{seconxy}{170}


%Example 2
%Input:

\assignvalues{suchwert}{85}

%Output:

\assignvalues{firstx}{80}
\assignvalues{firsty}{290}
\assignvalues{secondx}{90}
\assignvalues{seconxy}{350}


%Example 3
%Input:

\assignvalues{suchwert}{105}

%Output:

\assignvalues{firstx}{100}
\assignvalues{firsty}{410}
\assignvalues{secondx}{120}
\assignvalues{seconxy}{550}



%Example 4
%Input:

\assignvalues{suchwert}{100}

%Output:

\assignvalues{firstx}{100}
\assignvalues{firsty}{410}
\assignvalues{secondx}{120}
\assignvalues{seconxy}{550}

EDITED: More Information

@Steven B. Segletes : Here you can see the work which was led to my question. As you can see, I am going to interpolate between to points, as you also can see, I use \assignvalues to make an variable to more values. This assignment code was originally written by Clemens (look @ http://www.mrunix.de/forums/showthread.php?t=73700&page=2&highlight=Goldnas) also as the question was set here. Maybe you can now see, what the goal is?

\documentclass{article}

\usepackage{expl3,xparse}
\usepackage[ansinew]{inputenc}
\usepackage{etoolbox}

\usepackage{array}

\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}

\makeatletter
\ExplSyntaxOn
\cs_set_eq:NN \ifinstr \tl_if_in:nnTF
\DeclareRobustCommand*\assignvalues[2]{\@assignvalues{#1}{#2}}
\long \def\@assignvalues#1#2{
  \seq_set_split:Nnn \l_tmpa_seq { | } {#1}
  \seq_set_split:Nnn \l_tmpb_seq { | } {#2}
  \seq_mapthread_function:NNN \l_tmpa_seq \l_tmpb_seq \assignvalues@ii
}
\long \def \assignvalues@ii #1#2 { \protected@csedef{#1}{#2} }

\DeclareExpandableDocumentCommand{\fpeval}{om}
  {
    \IfValueTF {#1}
      { \fp_to_tl:n { round(#2,#1) } }
      { \fp_to_tl:n {#2} }
  }

\NewDocumentCommand {\geraden } {r[]r[]}
{
\assignvalues{nachkommastellen}{3}
\assignvalues{#1}{#2}
\fp_set:Nn \kgerade {(\by - \ay) / (\bx - \ax) } % Lineare 
\fp_set:Nn \dgerade {\by - (\bx * \kgerade)}  % Lineare 
\fp_set:Nn \ygesucht {\dgerade + \kgerade * \gesucht}

\begin{table}[htbp]
\centering
\begin{tabular}{|L{3.55cm}|L{2.55cm}|L{2.55cm}|} \hline
\textbf{Punkt} & \textbf{X-Koordinate} & \textbf{Y-Koordinate} \\ \hline
Punkt\  1 & \fpeval[\nachkommastellen]{\ax } & \fpeval[\nachkommastellen]{\ay } \\ \hline
\textit{Gesuchter\ Punkt} & \textit{ \fpeval[\nachkommastellen]{\gesucht }} &   \textit{\fpeval[\nachkommastellen]{\ygesucht }} \\ \hline
Punkt\  2 & \fpeval[\nachkommastellen]{\bx } & \fpeval[\nachkommastellen]{\by } \\ \hline
\end{tabular}
\end{table}
}
\ExplSyntaxOff
\makeatother


\begin{document}

\geraden[ax|ay|bx|by|gesucht][20|190|30|150|22]

%The Question which has to be solved is, that I can Call first

%fst: \determinevalues{22} => Should give =Pax,Pay,Pbx,Pby.

%secondly I want to call:

\assignvalue{suchwert}{22}
%\geraden[ax|ay|bx|by|gesucht][\pax|\pay|\pbx|\pby|\suchwert]

\end{document}
share|improve this question
1  
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you. –  Marco Daniel Mar 31 '13 at 17:58
    
I can't understand what you're trying to achieve: with that \DTLforeach cycle you're just printing a table. –  egreg Mar 31 '13 at 19:38
    
@egreg i dont need an table, thats only a way that i can see the data....the relevant thing is, that I can make the 4 assignmentscommands.... no table neccessary.... –  Peter Ebelsberger Mar 31 '13 at 20:36
    
What's the role of the database, then? –  egreg Mar 31 '13 at 20:42
    
The database has the content. I have written a function which calculates the k,d Parameters of the equation y=kx+d from P1(x,y) and P2(x,y). I get P3(x,y), x is the value which is given, y should be calculated. y3=k*x3+d. The two Points should be extracted from the database. The Points should be taken from the database. The smaller one, the bigger on.... calculation the linear equation, interpolate y.... the database contains alle the x,y tuppels of temperature and densitiy for example..... –  Peter Ebelsberger Mar 31 '13 at 21:20

1 Answer 1

up vote 1 down vote accepted

Trying to address just your concern about extracting individual elements from a data array, I propose the readarray package. It can take either a \def or a space-separated data file and stuff the data into either a 2-D or 3-D data array, which can be recalled element by element.

In this latest edit, I put out a string that has what I think are the desired \assignvalues. It is not clear to me though whether this is what the user desires, or for me to actually create a command assignment.

\documentclass{article}
\usepackage{readarray}
\usepackage{ifthen}
\def\dataB{%
10  100
20  130
30  150
40  170
50  190
60  210
}
\def\firstx#1{\Arrayij{#1}{\suchrow}{1}}
\def\firsty#1{\Arrayij{#1}{\suchrow}{2}}
\def\secondx#1{\Arrayij{#1}{\suchrowp}{1}}
\def\secondy#1{\Arrayij{#1}{\suchrowp}{2}}
\newcounter{index}
\newcounter{rowvalue}
\newcounter{testvalue}
\newcommand\suchwert[2]{%
  \setcounter{index}{0}%
  \setcounter{testvalue}{#2}
  \whiledo{\value{index} < \csname#1ROWS\endcsname}{%
    \addtocounter{index}{1}%
    \edef\tmp{\csname#1X\roman{index}Xi\endcsname}%
    \setcounter{rowvalue}{\tmp}%
    \ifthenelse{\value{rowvalue} > \value{testvalue}}%
    {\edef\suchrowp{\arabic{index}}%
     \addtocounter{index}{-1}%
     \edef\suchrow{\arabic{index}}%
     \setcounter{index}{\csname#1ROWS\endcsname}%
    }
    {\def\suchrow{NOT-FOUND}}
  }
  \bs assignvalues\{firstx\}\{\firstx{dB}\}\\
  \bs assignvalues\{firsty\}\{\firsty{dB}\}\\
  \bs assignvalues\{secondx\}\{\secondx{dB}\}\\
  \bs assignvalues\{secondy\}\{\secondy{dB}\}\\
}
\def\bs{\ttfamily\char'134}
\parindent 0in
\begin{document}
%   Instead of the \def\dataB above, you can read from a 
%   space-separated data file into \dataB with the 
%   following command:
%\readdef{tempdatab.dat}{\dataB}
\readArrayij{\dataB}{dB}{2}

\suchwert{dB}{35}

\suchwert{dB}{55}

\suchwert{dB}{45}

\end{document}
share|improve this answer
    
Hello, Sorry, but this solution wont solve the problem. I will try to show input/output examples. Maybe this is then more clear. Your example is based on the knowledge, that I exactly know, row and columm. But row and columm has to be determined by the suchwert. Thats the dynamic problem, which is the main task to solve. I have edited the question for more details. –  Peter Ebelsberger Apr 1 '13 at 10:07
    
As you can see at my post, i am searching for the minimum distanz between to points. I cant see, that you search for 35 (for example), I dont understand the line \def\firstx#1{\Arrayij{#1}{3}{1}}. What is the meaning of {3}, what is the meaning of {1}? –  Peter Ebelsberger Apr 1 '13 at 12:36
    
@PeterEbelsberger Does this attempt get closer to what you seek? I introduced a command \suchwert {search word} to decide what row of the array to begin on. Then, the first and second x,y commands are defined in terms of that. –  Steven B. Segletes Apr 1 '13 at 13:12
    
Yes. much closer, the last problem that I now have to solve is, that its absolutely necessary to use the assignvalue command. Then its perfect.... :) –  Peter Ebelsberger Apr 1 '13 at 13:16
    
@PeterEbelsberger I don't quite understand how \assignvalues is used. Are firstx etc counters? Strings? Is the command supposed to output a number, store a value? Do I create the command? Is it pre-existing? –  Steven B. Segletes Apr 1 '13 at 13:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.