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