read the first line of a text file

18 views
Skip to first unread message

Cuong P. Nguyen

unread,
Mar 23, 2016, 10:02:55 AM3/23/16
to AMPL Modeling Language
i have a text file mydata.txt that looks like this :
 
C:\Users\Mike\03-26-2016\log.txt
23 4
46 6 2 4
98 9
22 0 3
 
all i need is to read the first line, and assign it to variable FILEPATH. what is an efficient way of doing that?
 
Thanks
Cuong
 
 
 

Victor Zverovich

unread,
Mar 24, 2016, 2:55:05 PM3/24/16
to am...@googlegroups.com
If you quote the path

  "C:\Users\Mike\03-26-2016\log.txt"
  ...

then you will be able to use AMPL read command for this:

  param FILEPATH symbolic;
  read FILEPATH < mydata.txt;
  display FILEPATH;

Otherwise you'll probably need to use some general-purpose language to convert mydata.txt into the data format AMPL can understand. It is easy to call scripts written in other languages from AMPL using the shell command.

HTH,
Victor

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

hossein....@gmail.com

unread,
Apr 19, 2017, 6:45:59 PM4/19/17
to AMPL Modeling Language
What if we want to read the rest of numbers as a matrix?
 In other words we know number of rows but number of columns change per row.
Reply all
Reply to author
Forward
0 new messages