Changes between Version 2 and Version 3 of FAQ_LoaderUpDownload
- Timestamp:
- Jul 6, 2006 12:30:35 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
FAQ_LoaderUpDownload
v2 v3 140 140 sys.exit(-1) 141 141 142 # check to see if the user uploaded their own data 143 # or if they inputted the values 142 144 inputType = lib.get('input.loader.current') 143 145 if inputType == 'Uploaded data': 146 # they uploaded their datafile 147 # we need to write this data to a file so our science code can read it 148 # find the location of where rappture stored the data from their file 149 # and store the data int the writeData variable 144 150 writeDataLocation = lib.get('input.loader.upload.to') 145 151 writeData = lib.get(writeDataLocation+'.current') 146 152 else: 153 # they manually entered their data into the GUI 154 # grab each value and create a string we can write to a file. 147 155 start = lib.get('input.string(start).current') 148 156 end = lib.get('input.string(end).current') … … 150 158 writeData = '%s\n%s\n%s' % (start,end,step) 151 159 160 # prepare our semi-unique file name 152 161 outFileName = 'inputDeck.' + getDriverId(inDeckName) 153 162 fh = open(outFileName, 'w') 154 163 if fh != None: 164 # write our input deck to the file 155 165 fh.write(writeData) 156 166 fh.close() 157 167 158 168 # run the science code 159 getCommandOutput('./sineIt.py %s' % outFileName) 160 169 dirpath = os.path.dirname(sys.argv[0]) 170 getCommandOutput('%s/sineIt.py %s' % (dirpath,outFileName)) 171 172 # our science code outputted the answer to a file 173 # grab that file and add the answer to the Rappture library object 161 174 dataFileName = outFileName + '.out' 175 data = '' 162 176 163 177 # try to open our data file 164 178 try: 165 179 dFH = open(dataFileName) 180 181 # read the data from the data file 182 data = dFH.read() 183 dFH.close() 166 184 except IOError: 167 185 # we'll pass on dealing with the exception for now 168 # we'll just exit with a message 169 print 'Error opening file %s' % dataFileName 170 sys.exit(-1) 171 172 data = dFH.read() 173 dFH.close() 174 186 # send a message to the user letting them know there was an error 187 errMsg = 'Error opening file %s' % dataFileName 188 lib.put('output.string(errorLog).current',errMsg,1) 189 190 191 # store the data inside of the rappture library 175 192 lib.put('output.curve(sin_data).about.label','sin curve') 176 193 lib.put('output.curve(sin_data).about.label','sample output of the sin function') 177 194 lib.put('output.curve(sin_data).component.xy',data) 178 195 196 # remove any temporary files 197 try: 198 os.remove(outFileName) 199 os.remove(dataFileName) 200 except OSError: 201 # we were unable to remove the files, 202 # send a note to the user 203 errMsg = 'Error while removing tmp files' 204 lib.put('output.string(errorLog).current',errMsg,1) 205 206 # signal to the Rappture GUI that processing has completed 179 207 Rappture.result(lib) 208 209 # exit gracefully 180 210 sys.exit(0) 181 211 … … 232 262 }}} 233 263 234 235 236 264 == How it works == 265 266 As always, first the user starts simulation and the graphical user interface comes up. 267 268 269 By clicking on the loader (drop down menu) and choosing the "Upload" option the user 270 can pick a file from their local computer and have it uploaded to the rappture graphical 271 user interface. 272 273 After the user uploads their data, it is stored in the xml file at the location described in the loader: 274 {{{ 275 <input> 276 <loader> 277 <upload> 278 <to>input.string(uploadedFile)</to> 279 <prompt>Upload Input Deck.</prompt> 280 </upload> 281 </loader> 282 ... 283 }}} 284 In this case the contents of the uploaded file was saved to ''input.string(uploadedFile).current'' as described by the path ''input.loader.upload.to''. 285 286 Next the user clicks the simulate button. Rappture writes the inputs to the driver.xml file and executes the tool command (wrapper.py). 287 wrapper.py reads the xml file, checks to see if the user uploaded data to the graphical user interface or manually filled in the values. 288 You can check to see if the user uploaded data by comparing the value of ''input.loader.current'' to the string 'Uploaded data'. If they match, then you know the user uploaded data into the graphical user interface. As the wrapper.py script shows, to get the data that was uploaded by the user, simply issue a get command with the "upload to" location specified. 289 290 In the wrapper.py python script above we issue these commands: 291 {{{ 292 writeDataLocation = lib.get('input.loader.upload.to') 293 writeData = lib.get(writeDataLocation+'.current') 294 }}} 295 296 now writeData holds the information that was uploaded and we can write it to a file, which is what the science code expects. 297 298 {{{ 299 # prepare our semi-unique file name 300 outFileName = 'inputDeck.' + getDriverId(inDeckName) 301 fh = open(outFileName, 'w') 302 if fh != None: 303 # write our input deck to the file 304 fh.write(writeData) 305 fh.close() 306 }}} 307 308 After writing the data to a file, we call the science code with the name of the input deck. The science code reads the input deck, calculates its science and writes the answer back to a file. The wrapper.py script then reads and parses the result file from the science code and places the results back into the rappture library. 237 309 238 310