Export custom formatted expressions from Mathematica - formatting

How can I get Mathematica to export/save/write a text file with proper Fortan77 formatting, that is, 72 columns and a continuation marker on the sixth column?
I am using Mathematica to generate large and complex analytic expressions, which I then need to insert into pre-existing Fortran77 code. I have everything working correctly in the front end of Mathematica with FortranForm[] and
SetOptions[$Output, PageWidth -> 72]
However, I can't figure out how to get Mathematica to output correctly to a text file. I want something like this:
MM11 = mH1**2 + (g2**2*v1**2)/2. -
- (g2**2*(v1**2/2. -
- ((v2*Cos(phi2) - (0,1)*v2*Sin(phi2))*
- (v2*Cos(phi2) + (0,1)*v2*Sin(phi2)))/2.))/2.
...
but get either this:
MM11 = FortranForm[mH1^2 + (g2^2*v1^2)/2 - ...
or this:
MM11 = mH1**2 + (g2**2*v1**2)/2. - (g2**2*
(v1**2/2. - ((v2*Cos(phi2) - (0,1)*v2*Sin(phi2))*
...

This is a job for the surprisingly little-known Splice function. First, you make a template file, with the extension ".mf", like so:
file = "test.mf";
out = OpenWrite[file];
WriteString[out, "MH1 = <* form *>"];
Close[out];
Now when you use Splice, Mathematica will automatically replace everything between the <* and *> delimiters with its evaluated form. So if you set
form = 4 + b9^2 + c1^5 + c4^5 + h10^4 + j2 + k10^4 + p10^4 + q5^5 +
q8 + s3^3 + s7^2 + t6^3 + u3^2 + u9^3 + x8^4 + z2^3;
and call
Splice["test.mf", PageWidth -> 72];
which will automatically infer you want FortranForm output from the file extension, and which allows you to set PageWidth as an option, you will get a pretty decent result in the automatically generated file "test.f" (note the new extension):
MH1 = 4 + b9**2 + c1**5 + c4**5 + h10**4 + j2 + k10**4 + p10**4 +
- q5**5 + q8 + s3**3 + s7**2 + t6**3 + u3**2 + u9**3 + x8**4 +
- z2**3
Look at the docs for Splice for more options (changing the name of the output file and the like).

Related

How to define ApiBlueprint array values example with MSON?

Can I use MSON to specify an example values instead of + Body?
Is it possible to override predefined structure values?
I've tried like this:
+ Request (application/json)
+ Headers
Authorization: JWT <token>
+ Attributes (ClientsideCommand)
+ alias: `show-xc`
+ args (array[AppCommandArg], fixed-type)
+ (AppCommandArg)
+ arg_key: address
+ order: 1
+ required: true
+ skip_arg_name: true
+ (AppCommandArg)
+ arg_key: `-A1`
+ order: 2
+ required: true
+ skip_arg_name: false
But such definition corrupts json-schema, because AppCommandArg descibed as separate objects.
And also in the JSON generated from the MSON has 3 items where first item is deafult AppCommandArg.
Looks like it's not possible to make this things twogether. If you add elements as showed abowe Apiary renders it as it sees it, if an element noted twice the json schema also will describe it twice.

Issue in creating a raw bitcoin transaction(single input and single output)

When signing a transaction,I have copied the scriptPubKey from previous referenced transaction (for script field in input) and appended the hash-type.
Then in the original transaction,I have replaced the script with scriptSig and removed the hash-type.
Raw Transaction.
But,when I check the transaction is coinb.in,it says that the transaction is not signed.
The code I'm using to generate is inspired from Ken Shirriff's blog and Shlomi's video on youtube
My version of the code can be found here
Snippet which populates the transaction is here:
def get_real_transaction(self,account):
sigscript = self.generate_sig_script(account)
self.real_transaction = ""
self.real_transaction = (
self.version
+ self.txn_inputs_count
+ self.txn_inputs[0]["output_hash"]
+ self.txn_inputs[0]["output_index"]
+ self.txn_inputs[0]["sigScriptBytes"]
+ self.txn_inputs[0]["sigScript"]
+ self.txn_inputs[0]["sequence"]
+ self.txn_outputs_count
+ self.txn_outputs[0]["value"]
+ self.txn_outputs[0]["scriptPubKeyBytes"]
+ self.txn_outputs[0]["scriptPubKey"]
+ self.locktime
)
return self.real_transaction
Entire transaction.py is here
Any guidance/hints will be extremely helpful.

supercollider arduino serial communication

I am working on an arduino uno + supercollider 3 project.
Basicly: I have an arduino set up with potentiometers, a sensor and some buttons. I put the data of inputs in an array and send it to my computer trough serial.
Currently, my output in the Arduino serial monitor is as this:
271:189:75:0:0:0:1:0:0:0:0:0
If I open the serial connection in Supercollider, what arrives is this:
271
Only the first value in the array arrives correctly. (The same setup with just 1 Arduino input to Supercollider worked like a charm, by the way. I just can't get it working with an array of inputs from arduino to SC3.)
arduino code to send data at this moment:
teSturen = String(val_lichtPin) + ":" + String(val_Pot1Pin) + ":" + String(val_Pot2Pin) + ":" + String(val_Pot3Pin) + ":" + String(val_Pot4Pin) + ":" + String(val_Pot5Pin) + ":" + String(knop1Staat) + ":" + String(knop2Staat) + ":" + String(knop3Staat) + ":" + String(knop4Staat) + ":" + String(knop5Staat) + ":" + String(knop6Staat);
Serial.println(String(teSturen));
I put all the numbers together in one string with an : as seperator, then send this.
SC3 code to receive:
~ino = ArduinoSMS("/dev/ttyACM0",9600);
~ino.action = {
arg msg;
var amsg;
//amsg = msg.split($:);
msg.postln;
};
There is more code, but that is for appointing vars and args, defining synths, et cetera. I limited this to the bits where it doesn't work.
Any ideas on why SC3 only receives the first number? I have tried for example to recplace the seperator : by , or ;, to send it as multiple integers in stead of one string, ...
The goal of it for me, is to be able to control various synths in supercollider with fysical control potentiometers, because that's a lot more fun to play with than keyboard or mouse controlling synths...
I appreciate any help, thank you!
Pretty late, but this still might help. I used the same setup some years ago. I used
p = ArduinoSMS("/dev/tty.usbmodem3d11", 115200);
while{state==0}{
p.action = { |... msg| m=[msg[0],msg[1]];
do something with m[0] and m[1] ...
};
to parse the message stream. My setup only read arrays of two bytes (msg[0]and msg[1]), but this should be expandable.
The full source code is available on https://github.com/symbolrush/FridgeKiller and another project with the same setup on https://github.com/symbolrush/ColliDuino.
Hope this helps and good luck!

How to add line break to labels on axis for IE9?

I'm using Dojo 1.9.1.
I'm using dojox.charting to draw some charts.
I am using a labelFunc to produce a date/time label for my X-axis. This is working fine in all browsers.
But I want to add a line break to my label so that the date sits above the time, e.g.:
10/01/2014
06:00
I can add a html break tag to the string returned and this works in Chrome and Firefox but not IE9 (to be expected).
Has anybody solved how to do this one that works across all browsers including IE9 (or specifically ones that don't "do" html labels).
Cheers
Ian
My label func:
_labelFull: function (index) {
// Returns a label in the form "dd/mm/yyyy hh:mm" for tooltip labelling
var dt,
d;
dt = new Date(Date.parse(myglobalStartDateTime));
dt.setHours(dt.getHours() + Number(index));
// Full date/time
d = ("0" + dt.getDate()).slice(-2) + '/' +
("0" + (dt.getMonth() + 1)).slice(-2) + '/' +
dt.getFullYear() + ' ' +
("0" + dt.getHours()).slice(-2) + ':' +
("0" + dt.getMinutes()).slice(-2) + 'UTC';
return d;
}

How to Retrieve all possible information about a LinkedIn Account ? (API using C#)

I am writting an C# app to make use of Linkedin's API.
I want to be able to query "Person" (First Name + Last Name) and retrieve all the possible information about this group of people with the same name
I am currently using my own implementation of the REST API alongside People-Search API calls.
Here's an example of a request that I know works:
https://api.linkedin.com/v1/people-search:(people:(id,first-name,last-name,headline,picture-url),num-results)?
I'm running it with: first-name=parameter&last-name=parameter after the ? mark
The problem is, I want to retrieve more information such as Title, Industry, Current-company, current-school etc. Refer here for the list of possible parameters.
This notation is what they call Field Selectors
How do i structure my API Call so i can get all the possible information about someone ?
Here is the url to get everything for a user Profile:
https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,picture-url,industry,summary,specialties,positions:(id,title,summary,start-date,end-date,is-current,company:(id,name,type,size,industry,ticker)),educations:(id,school-name,field-of-study,start-date,end-date,degree,activities,notes),associations,interests,num-recommenders,date-of-birth,publications:(id,title,publisher:(name),authors:(id,name),date,url,summary),patents:(id,title,summary,number,status:(id,name),office:(name),inventors:(id,name),date,url),languages:(id,language:(name),proficiency:(level,name)),skills:(id,skill:(name)),certifications:(id,name,authority:(name),number,start-date,end-date),courses:(id,name,number),recommendations-received:(id,recommendation-type,recommendation-text,recommender),honors-awards,three-current-positions,three-past-positions,volunteer)?oauth2_access_token=PUT_YOUR_TOKEN_HERE
Requires an Oauth2 access token.
Here it is in a nice String list (Java):
apiUrl
+ "/v1/people/~:("
+ "id,"
+ "first-name,"
+ "last-name,"
+ "headline,"
+ "picture-url,"
+ "industry,"
+ "summary,"
+ "specialties,"
+ "positions:("
+ "id,"
+ "title,"
+ "summary,"
+ "start-date,"
+ "end-date,"
+ "is-current,"
+ "company:("
+ "id,"
+ "name,"
+ "type,"
+ "size,"
+ "industry,"
+ "ticker)"
+"),"
+ "educations:("
+ "id,"
+ "school-name,"
+ "field-of-study,"
+ "start-date,"
+ "end-date,"
+ "degree,"
+ "activities,"
+ "notes),"
+ "associations," /* Full Profile */
+ "interests,"
+ "num-recommenders,"
+ "date-of-birth,"
+ "publications:("
+ "id,"
+ "title,"
+ "publisher:(name),"
+ "authors:(id,name),"
+ "date,"
+ "url,"
+ "summary),"
+ "patents:("
+ "id,"
+ "title,"
+ "summary,"
+ "number,"
+ "status:(id,name),"
+ "office:(name),"
+ "inventors:(id,name),"
+ "date,"
+ "url),"
+ "languages:("
+ "id,"
+ "language:(name),"
+ "proficiency:(level,name)),"
+ "skills:("
+ "id,"
+ "skill:(name)),"
+ "certifications:("
+ "id,"
+ "name,"
+ "authority:(name),"
+ "number,"
+ "start-date,"
+ "end-date),"
+ "courses:("
+ "id,"
+ "name,"
+ "number),"
+ "recommendations-received:("
+ "id,"
+ "recommendation-type,"
+ "recommendation-text,"
+ "recommender),"
+ "honors-awards,"
+ "three-current-positions,"
+ "three-past-positions,"
+ "volunteer"
+ ")"
+ "?oauth2_access_token="+ token;
You've already got the notation down, all you need to do is add the rest of the field selectors, nesting them where needed:
https://api.linkedin.com/v1/people-search:(people:(id,first-name,last-name,headline,picture-url,industry,positions:(id,title,summary,start-date,end-date,is-current,company:(id,name,type,size,industry,ticker)),educations:(id,school-name,field-of-study,start-date,end-date,degree,activities,notes)),num-results)?first-name=parameter&last-name=parameter
Keep in mind that per the Profile Field docs, you can only get educations for 1st degree connections of the current user.
I use this URL to get everything including email and formatted as json:
https://api.linkedin.com/v1/people/~:(id,first-name,email-address,last-name,headline,picture-url,industry,summary,specialties,positions:(id,title,summary,start-date,end-date,is-current,company:(id,name,type,size,industry,ticker)),educations:(id,school-name,field-of-study,start-date,end-date,degree,activities,notes),associations,interests,num-recommenders,date-of-birth,publications:(id,title,publisher:(name),authors:(id,name),date,url,summary),patents:(id,title,summary,number,status:(id,name),office:(name),inventors:(id,name),date,url),languages:(id,language:(name),proficiency:(level,name)),skills:(id,skill:(name)),certifications:(id,name,authority:(name),number,start-date,end-date),courses:(id,name,number),recommendations-received:(id,recommendation-type,recommendation-text,recommender),honors-awards,three-current-positions,three-past-positions,volunteer)?format=json