1*fce0c873SBarry Smith// 2*fce0c873SBarry Smith// iphoneViewController.m 3*fce0c873SBarry Smith// iphone 4*fce0c873SBarry Smith// 5*fce0c873SBarry Smith// Created by Barry Smith on 5/12/10. 6*fce0c873SBarry Smith// Copyright __MyCompanyName__ 2010. All rights reserved. 7*fce0c873SBarry Smith// 8*fce0c873SBarry Smith 9*fce0c873SBarry Smith#import "iphoneViewController.h" 10*fce0c873SBarry Smith#include "PETSc/petsc.h" 11*fce0c873SBarry Smith 12*fce0c873SBarry Smith@implementation iphoneViewController 13*fce0c873SBarry Smith@synthesize textField; 14*fce0c873SBarry Smith@synthesize textView; 15*fce0c873SBarry Smith@synthesize outPut; 16*fce0c873SBarry Smith 17*fce0c873SBarry Smith 18*fce0c873SBarry Smith/* 19*fce0c873SBarry Smith// The designated initializer. Override to perform setup that is required before the view is loaded. 20*fce0c873SBarry Smith- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 21*fce0c873SBarry Smith if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { 22*fce0c873SBarry Smith // Custom initialization 23*fce0c873SBarry Smith } 24*fce0c873SBarry Smith return self; 25*fce0c873SBarry Smith} 26*fce0c873SBarry Smith*/ 27*fce0c873SBarry Smith 28*fce0c873SBarry Smith/* 29*fce0c873SBarry Smith// Implement loadView to create a view hierarchy programmatically, without using a nib. 30*fce0c873SBarry Smith- (void)loadView { 31*fce0c873SBarry Smith} 32*fce0c873SBarry Smith*/ 33*fce0c873SBarry Smith 34*fce0c873SBarry Smith 35*fce0c873SBarry Smith/* 36*fce0c873SBarry Smith// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 37*fce0c873SBarry Smith- (void)viewDidLoad { 38*fce0c873SBarry Smith [super viewDidLoad]; 39*fce0c873SBarry Smith} 40*fce0c873SBarry Smith*/ 41*fce0c873SBarry Smith 42*fce0c873SBarry Smith 43*fce0c873SBarry Smith/* 44*fce0c873SBarry Smith// Override to allow orientations other than the default portrait orientation. 45*fce0c873SBarry Smith- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 46*fce0c873SBarry Smith // Return YES for supported orientations 47*fce0c873SBarry Smith return (interfaceOrientation == UIInterfaceOrientationPortrait); 48*fce0c873SBarry Smith} 49*fce0c873SBarry Smith*/ 50*fce0c873SBarry Smith 51*fce0c873SBarry Smith- (void)didReceiveMemoryWarning { 52*fce0c873SBarry Smith // Releases the view if it doesn't have a superview. 53*fce0c873SBarry Smith [super didReceiveMemoryWarning]; 54*fce0c873SBarry Smith 55*fce0c873SBarry Smith // Release any cached data, images, etc that aren't in use. 56*fce0c873SBarry Smith} 57*fce0c873SBarry Smith 58*fce0c873SBarry Smith- (void)viewDidUnload { 59*fce0c873SBarry Smith // Release any retained subviews of the main view. 60*fce0c873SBarry Smith // e.g. self.myOutlet = nil; 61*fce0c873SBarry Smith} 62*fce0c873SBarry Smith 63*fce0c873SBarry Smith 64*fce0c873SBarry Smith- (void)dealloc { 65*fce0c873SBarry Smith [textField release]; 66*fce0c873SBarry Smith [super dealloc]; 67*fce0c873SBarry Smith} 68*fce0c873SBarry Smith 69*fce0c873SBarry SmithUITextView *globalTextView; 70*fce0c873SBarry Smith 71*fce0c873SBarry Smith/* 72*fce0c873SBarry Smith This is called by PETSc for all print calls. 73*fce0c873SBarry Smith 74*fce0c873SBarry Smith Simply addeds to the NSString in globalTextView and it gets displayed in the UITextView in the display 75*fce0c873SBarry Smith*/ 76*fce0c873SBarry SmithPetscErrorCode PetscVFPrintfiPhone(FILE *fd,const char *format,va_list Argp) 77*fce0c873SBarry Smith{ 78*fce0c873SBarry Smith size_t len; 79*fce0c873SBarry Smith char str[1024]; 80*fce0c873SBarry Smith 81*fce0c873SBarry Smith PetscVSNPrintf(str,1024,format,&len,Argp); 82*fce0c873SBarry Smith globalTextView.text = [NSString stringWithFormat:@"%@%s", globalTextView.text,str]; 83*fce0c873SBarry Smith return 0; 84*fce0c873SBarry Smith} 85*fce0c873SBarry Smith 86*fce0c873SBarry Smith#define main ex19 87*fce0c873SBarry Smith#define help help19 88*fce0c873SBarry Smith#define Field Field19 89*fce0c873SBarry Smith#define PETSC_APPLE_FRAMEWORK 90*fce0c873SBarry Smith#include "../../../../../../src/snes/examples/tutorials/ex19.c" 91*fce0c873SBarry Smith#undef main 92*fce0c873SBarry Smith#undef help 93*fce0c873SBarry Smith#undef Field 94*fce0c873SBarry Smith#define main ex48 95*fce0c873SBarry Smith#define help help48 96*fce0c873SBarry Smith#define Field Field48 97*fce0c873SBarry Smith#include "../../../../../../src/snes/examples/tutorials/ex48.c" 98*fce0c873SBarry Smith 99*fce0c873SBarry Smith/* 100*fce0c873SBarry Smith This is called each time one hits return in the TextField. 101*fce0c873SBarry Smith 102*fce0c873SBarry Smith Converts the string to a collection of arguments that are then passed on to PETSc 103*fce0c873SBarry Smith*/ 104*fce0c873SBarry Smith- (BOOL) textFieldShouldReturn: (UITextField*) theTextField { 105*fce0c873SBarry Smith [theTextField resignFirstResponder]; /* makes the keyboard disappear */ 106*fce0c873SBarry Smith textView.text = @""; /* clears the UITextView */ 107*fce0c873SBarry Smith globalTextView = textView; /* we make this class member a global so can use in PetscVFPrintfiPhone() */ 108*fce0c873SBarry Smith textView.font = [UIFont fontWithName:@"Courier" size:8.0]; /* make the font size in the UITextView a more reasonable size and use fixed width*/ 109*fce0c873SBarry Smith 110*fce0c873SBarry Smith const char *str = [textField.text UTF8String]; 111*fce0c873SBarry Smith char **args; 112*fce0c873SBarry Smith int argc; 113*fce0c873SBarry Smith PetscBool flg1,flg2; 114*fce0c873SBarry Smith 115*fce0c873SBarry Smith PetscErrorCode ierr = PetscStrToArray(str,' ',&argc,&args); 116*fce0c873SBarry Smith ierr = PetscStrncmp(str, "./ex19", 6, &flg1); 117*fce0c873SBarry Smith ierr = PetscStrncmp(str, "./ex48", 6, &flg2); 118*fce0c873SBarry Smith if (flg1) { 119*fce0c873SBarry Smith ex19(argc,args); 120*fce0c873SBarry Smith } else if (flg2) { 121*fce0c873SBarry Smith ex48(argc,args); 122*fce0c873SBarry Smith } else { 123*fce0c873SBarry Smith textView.text =@"Must start with ./ex19 or ./ex48"; 124*fce0c873SBarry Smith ierr = PetscStrToArrayDestroy(argc,args); 125*fce0c873SBarry Smith return YES; 126*fce0c873SBarry Smith } 127*fce0c873SBarry Smith ierr = PetscStrToArrayDestroy(argc,args); 128*fce0c873SBarry Smith return YES; 129*fce0c873SBarry Smith} 130*fce0c873SBarry Smith 131*fce0c873SBarry Smith@end 132