1 /* 2 * $Id: copyb.i,v 1.1 2005-09-18 22:05:54 dhmunro Exp $ 3 * Utility to copy binary files. 4 */ 5 /* Copyright (c) 2005, The Regents of the University of California. 6 * All rights reserved. 7 * This file is part of yorick (http://yorick.sourceforge.net). 8 * Read the accompanying LICENSE file for details. 9 */ 10 11 func copyb(src, dst, size=) 12 /* DOCUMENT copyb, src, dst 13 or copyb, openb(src_name), createb(dst_name) 14 Copy binary file SRC to binary file DST. 15 Check for "obsolete/" subdirectory of Yorick home directory for 16 extensions of the openb function to old file formats. 17 Use the size= keyword to specify a non-default (4 Mbyte) size for 18 the members of the output file family. 19 If you habitually include basfix.i, you may want to use the 20 basfix_openb function to open the src file. 21 SEE ALSO: openb, createb, open102, close102 22 */ 23 { 24 vars= get_vars(src); 25 /* sort the variables into order of increasing address */ 26 addrs= get_addrs(src); 27 28 /* declare and copy non-record variables */ 29 names= *vars(1); 30 n= numberof(names); 31 if (n) names= names(sort(*addrs(1))); 32 for (i=1 ; i<=n ; i++) { 33 name= names(i); 34 value= get_member(src, name); 35 add_variable, dst, -1, name, structof(value), dimsof(value); 36 get_member(dst, name)= value; 37 value= []; 38 } 39 40 names= *vars(2); 41 n= numberof(names); 42 if (n<1) return; 43 names= names(sort(*addrs(2))); 44 45 /* declare record variables */ 46 add_record, dst; 47 if (size) set_filesize, dst, size; 48 for (i=1 ; i<=n ; i++) { 49 name= names(i); 50 add_variable, dst, -1, name, structof(get_member(src, name)), \ 51 dimsof(get_member(src, name)); 52 } 53 54 /* copy record variables for each record */ 55 times= get_times(src); 56 ncycs= get_ncycs(src); 57 time= ncyc= []; 58 r= r0= 1; 59 while (jt(src,-)) ++r0; 60 while (jt(src)) { 61 if (!is_void(times)) time= times(r); 62 if (!is_void(ncycs)) ncyc= ncycs(r); 63 add_record, dst, time, ncyc, -1; 64 for (i=1 ; i<=n ; i++) { 65 name= names(i); 66 get_member(dst, name)= get_member(src, name); 67 } 68 r++; 69 } 70 if (r>1) jr, src, r0; 71 } 72