yorick-ml4-0.6.0/0000755000076500001440000000000011254106377013102 5ustar frigautusersyorick-ml4-0.6.0/ml4_start.i0000644000076500001440000000010410735233045015154 0ustar frigautusersautoload, "ml4.i", ml4scan, ml4search, ml4read, ml4write, ml4close; yorick-ml4-0.6.0/check.i0000644000076500001440000000237511111267075014333 0ustar frigautusersrequire,"ml4.i"; ml4write,"test.mat","Check file for the yorick ml4 plugin","FileType","w"; ml4write,"test.mat",dist(12),"d12","a"; ml4write,"test.mat",indgen(1000),"ig100","a"; ml4scan,"test.mat"; v=ml4read("test.mat","ig100"); info,v; window; plot,v; pause,500; tv,ml4read("test.mat","d12"); v=ml4read("test.mat","FileType"); write,format="And btw, the title was: \n%s\n",v; ml4write,"test.mat","file section 2","another string","a"; ml4scan,"test.mat"; write,format="%s\n","You can also append variable with the same name (is that smart?):"; ml4write,"test2.mat","Check file for the yorick ml4 plugin","FileType","w"; for (i=1;i<=50;i++) ml4write,"test2.mat",gaussdev([2,64,64]),"x","a"; write,format="%s\n","and read them, leaving the file opened between reads"; animate,1; for (i=1;i<=50;i++) tv,ml4read("test2.mat","x",1); animate,0; ml4close,"test2.mat"; write,format="%s\n","same file in Little endian (note that ml4 only reads LE)"; ml4write,"test3.mat","Check file for the yorick ml4 plugin","FileType","w",endian='L'; ml4write,"test3.mat","little","endian","a",endian='L'; ml4write,"test3.mat",dist(12),"d12","a",endian='L'; ml4write,"test3.mat",indgen(1000),"ig100","a",endian='L'; ml4scan,"test3.mat"; remove,"test.mat"; remove,"test2.mat"; remove,"test3.mat"; yorick-ml4-0.6.0/ml4.i0000644000076500001440000001130211111272606013734 0ustar frigautusers/* ml4.i Yorick plugin * * Yorick wrappers for ml4.c * Matlab 4 IO * * $Id: ml4.i,v 1.2 2008/11/20 14:34:46 frigaut Exp $ * Francois Rigaut, 2005-2007 * last revision/addition: 2007jun14 * * Copyright (c) 2005, Francois RIGAUT (frigaut@gemini.edu, Gemini * Observatory, 670 N A'Ohoku Place, HILO HI-96720). * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details (to receive a copy of the GNU * General Public License, write to the Free Software Foundation, Inc., 675 * Mass Ave, Cambridge, MA 02139, USA). * * $Log: ml4.i,v $ * Revision 1.2 2008/11/20 14:34:46 frigaut * - Included and uploaded changes from Thibaut Paumard making ml4 64 bits safe. * - Beware: In 64 bits, longs (8bytes) are saved as int (4bytes) * * - a few more minor text edits * - added ML4_VERSION variable * * */ plug_in,"ml4"; ML4_VERSION = "0.6.0"; local ml4 /* DOCUMENT matlab4 I/O This package was develop for the Gemini MCAO (RTC file exchange) Available functions: ml4scan(file[,maxvar]) ml4search(file,varname) ml4read(file,varname,leave_open) ml4close,file ml4write(file,data,varname,mode,endian=) SEE ALSO: */ extern ml4endian /* DOCUMENT ml4endian return 1 is machine is little endian, 0 if big endian SEE ALSO: */ if (ml4endian) default_endian='L'; else default_endian='B'; extern ml4scan /* DOCUMENT ml4scan,file[,maxvar] Scans a matlab4 file for variables and output name, type and dimension. If used as a subroutine, the result is printed on the screen. If used as a function, returns what would have been printed on the screen. maxvar is the maximum number of variables to scan (optional). SEE ALSO: ml4read, ml4search */ extern ml4search /* DOCUMENT ml4search(file,varname) Returns 1 if the variable is present in file, 0 otherwise SEE ALSO: ml4scan, ml4read */ extern ml4read /* DOCUMENT ml4read(file,varname,leave_open) Returns the data associated with "varname" leave_open will prevent closing the file when the operation is completed. This can be useful when reading files containing large numbers of variables. Be aware that it is left open, pointed at the next variable in the file. Hence a request to read a variable located prior to the one you just read will fail ("No Such Variable"). When the variable read is corrupted (i.e. with NaN), the file is not close and hence requires a manual ml4close. SEE ALSO: ml4scan, ml4search, ml4close. */ extern ml4close /* DOCUMENT ml4close,file Closes access to the matlab4 file. SEE ALSO: */ func ml4write(file,data,varname,mode,endian=) /* DOCUMENT ml4write(file,data,varname,mode,endian=) mode : "w" or "a" endian= 'L' will write the file in little endian. Useful if the target machine uses little endian. SEE ALSO: ml4read, ml4close */ { if ((mode!="w")&&(mode!="a")) error,"mode should be \"w\" or \"a\""; if (default_endian) endian=default_endian; // if (!endian) endian='B'; if ((endian!='L')&&(endian!='B')) error,"Endian should be 'L' or 'B'"; if (structof(data)==string) { status=matout_string(file, varname, data(1), mode); if (status) error,"string write failed"; return; } dims = dimsof(data); if (dims(1)>2) error,"ml4write only supports writing up 2D arrays"; if (dims(1)==0) { nrows=1n; ncols=1n; } else if (dims(1)==1) { nrows=1n; ncols=int(dims(2)); } else if (dims(1)==2) { nrows=int(dims(2)); ncols=int(dims(3)); } if (structof(data)==long) { type='l'; } else if (structof(data)==int) { type='l'; } else if (structof(data)==float) { type='r'; } else if (structof(data)==double) { type='d'; } else if (structof(data)==short) { type='s'; } else if (structof(data)==char) { type='b'; } else error,"Unsupported type"; tmp = data; // otherwise data may be swapped in place in endian='L' status = matout(file,varname,&tmp,nrows,ncols,type,mode,endian); if (status) error,"write failed"; } //===================================================== extern matout /* PROTOTYPE int matout(string filename, string varname, pointer ptr, int nrows, int ncols, char vartype, string mode, char endianess) */ extern matout_string /* PROTOTYPE int matout_string(string filename, string varname, string text, string mode) */ yorick-ml4-0.6.0/ml4.info0000644000076500001440000000170011111272344014437 0ustar frigautusersPackage: ml4 Kind: plugin Version: 0.6.0 Revision: 1 Description: matlab4 format IO License: GPL Author: Francois Rigaut Maintainer: Francois Rigaut OS: Depends: yorick(>=1.6.02) Source: http://www.maumae.net/yorick/packages/%o/tarballs/ml4-%v-%o.tgz Source-MD5: Source-Directory: contrib/ml4 DocFiles: Homepage: http://www.maumae.net/yorick/doc/plugins.php DescDetail: << /* DOCUMENT matlab4 I/O This package was develop for the Gemini MCAO (RTC file exchange) Available functions: ml4scan(file[,maxvar]) ml4search(file,varname) ml4read(file,varname,leave_open) ml4close,file ml4write(file,data,varname,mode,endian=) */ << DescUsage: << See check.i for a test suite. Type "yorick -batch check.i" in a terminal to run it. << DescPort: << This package will compile Yorick only on MacOSX 10.3.4 or later, because of a bug in the system math library libm (part of /usr/lib/LibSystem.dylib) in earlier versions of MacOSX 10.3. << yorick-ml4-0.6.0/LICENSE0000644000076500001440000004313110735233045014105 0ustar frigautusers GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. yorick-ml4-0.6.0/ml4.c0000644000076500001440000006064111111272606013740 0ustar frigautusers/* ml4.c Yorick plugin * * C function for matlab 4 IO * * $Id: ml4.c,v 1.3 2008/11/20 14:34:46 frigaut Exp $ * Original writen by Stephen Browne, tOSC. * Adapted and yorickized by Francois Rigaut, 2005-2007 * last revision/addition: 2007jun14 * * Copyright (c) 2005, Francois RIGAUT (frigaut@gemini.edu, Gemini * Observatory, 670 N A'Ohoku Place, HILO HI-96720). * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details (to receive a copy of the GNU * General Public License, write to the Free Software Foundation, Inc., 675 * Mass Ave, Cambridge, MA 02139, USA). * * $Log: ml4.c,v $ * Revision 1.3 2008/11/20 14:34:46 frigaut * - Included and uploaded changes from Thibaut Paumard making ml4 64 bits safe. * - Beware: In 64 bits, longs (8bytes) are saved as int (4bytes) * * - a few more minor text edits * - added ML4_VERSION variable * * */ #include #include #include #include #include #include #include #include #include #include "ml4.h" #include "ydata.h" #include "yapi.h" #include "pstdlib.h" // Macs and SGIs are Big-Endian; PCs are little endian // returns TRUE if current machine is little endian extern int IsLittleEndian(void); extern Array *GrowArray(Array *array, long extra); /****************************************************************************** FUNCTION: SwapEndian PURPOSE: Swap the byte order of a structure EXAMPLE: float F=123.456;; SWAP_FLOAT(F); ******************************************************************************/ #define SWAP_SHORT(Var) Var = *(short*) swap((void*)&Var, sizeof(short)) #define SWAP_USHORT(Var) Var = *(unsigned short*)swap((void*)&Var, sizeof(short)) #define SWAP_INT(Var) Var = *(int*) swap((void*)&Var, sizeof(int)) #define SWAP_LONG(Var) Var = *(long*) swap((void*)&Var, sizeof(long)) #define SWAP_ULONG(Var) Var = *(unsigned long*) swap((void*)&Var, sizeof(long)) #define SWAP_RGB(Var) Var = *(int*) swap((void*)&Var, 3) #define SWAP_FLOAT(Var) Var = *(float*) swap((void*)&Var, sizeof(float)) #define SWAP_DOUBLE(Var) Var = *(double*) swap((void*)&Var, sizeof(double)) #define MAXFILES (20) #define DEBUG 0 #define MIN(A,B) (A)<(B) ? (A) : (B) //static FILE **fd[MAXFILES]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; static FILE *fd[MAXFILES]; static char matfile[MAXFILES][256]={{0}}; static char fullname[256]={0}; static char tempvarname[256] = {0}; static char message[100]; char *matlab_fullname = fullname; int disable_disk_writing = 0; static int nfiles=0; static int saveNormally=1; //typedef unsigned int ulong; void writerr(void); void *swap(void* Addr, int size); void warn(char *mes); /***********************************************/ int matout(char *fullname,char *varname,void *data,int nrows,int ncols,char vartype, char *mode, char endianess) { int size; long nelem; int type,namelen; int mrows,mcols,imagf; int i; FILE *fs; mrows = nrows; mcols = ncols; nelem = mrows*mcols; switch (vartype) { case 'd': /* 8-byte doubles */ type=00; size=8; double *vard=data; if (endianess=='B') { for (i=0;i=nfiles) { // could not find a name match for (i=0 ; i255) { fseek(fs,fileptr,SEEK_SET); // leave file ptr at begginning of this variable matclose(filename); YError("Variable name too long!"); } fread(tempvarname,(unsigned int)namelen,1,fs); // if ((*varname!='*') && strcmp(varname,tempvarname)) { // error if not same varname if (!matchvarname(tempvarname,varname)) { // error if not same varname fseek(fs,fileptr,SEEK_SET); // leave file ptr at begginning of this variable matclose(filename); YError(p_strncat("Can't find variable",varname,0)); } nElements = (unsigned)mrows*(unsigned)mcols; Dimension *tmp=tmpDims; tmpDims=0; FreeDimension(tmp); if (mrows<=1) { tmpDims= NewDimension(mcols, 1L, (Dimension *)0); } else if (mcols<=1) { tmpDims= NewDimension(mrows, 1L, (Dimension *)0); } else { tmpDims= NewDimension(mrows, 1L, (Dimension *)0); tmpDims= NewDimension(mcols, 1L, tmpDims); } if (type==0) { // 8-byte doubles size = 8; Array *a= PushDataBlock(NewArray(&doubleStruct, tmpDims)); double *data = a->value.d; bytes_read = fread((void *)data,size,nElements,fs); if (endian=='B') { for (i=0;ivalue.f; bytes_read = fread((void *)data,size,nElements,fs); if (endian=='B') { for (i=0;ivalue.l; bytes_read = fread((void *)data,size,nElements,fs); if (endian=='B') { for (i=0;ivalue.s; bytes_read = fread((void *)data,size,nElements,fs); if (endian=='B') { for (i=0;ivalue.s; Array *b= PushDataBlock(NewArray(&longStruct, tmpDims)); long *data2 = b->value.l; bytes_read = fread((void *)data,size,nElements,fs); if (endian=='B') { for (i=0;ivalue.c; bytes_read = fread((void *)data,size,nElements,fs); } else if (type==51) { // text (51) size = 1; Array *a= PushDataBlock(NewArray(&stringStruct, (Dimension *)0)); char *buf; a->value.q[0] = buf = p_malloc(nElements+1); if (DEBUG) printf("strlen: %d\n",strlen((void *)a->value.q[0])); // bytes_read = fread(a->value.q[0],1,nElements,fs); bytes_read = fread(buf,1,nElements,fs); *((char *)buf + nElements) = 0; // append a NULL to text string } else { matclose(filename); sprintf(message,"Unknown type %d",type); YError(message); } if (bytes_read!=nElements) { fseek(fs,nElements*size,SEEK_CUR); matclose(filename); if (DEBUG) printf("read:%ld expected:%ld\n",bytes_read,nBytesToRead); YError("Premature end of file"); } if (!leave_open) matclose(filename); } /***********************************************/ // matskip() skips over the next array in a matfile int matskip(char *filename) { unsigned long nbytes, bytes_read; unsigned long type,namelen; long mrows,mcols,imagf; FILE *fs; int fileptr; int endian = 'L'; int size; fs = openmat(filename); if (fs == NULL) return -1; fileptr = ftell(fs); bytes_read = fread(&type,sizeof(long),1,fs); if (bytes_read==0) return (-1); // end of file fread(&mrows,sizeof(long),1,fs); fread(&mcols,sizeof(long),1,fs); fread(&imagf,sizeof(long),1,fs); fread(&namelen,sizeof(long),1,fs); //if (type & 0xffff0000) { // endian = 'B'; // swap((void *)&type,4,1); // swap((void *)&mrows,4,1); // swap((void *)&mcols,4,1); // swap((void *)&imagf,4,1); // swap((void *)&namelen,4,1); // type = type%1000; //} if (namelen>255) { fseek(fs,fileptr,SEEK_SET); // leave file ptr at begginning of this variable return(-1); } fread(tempvarname,(unsigned int)namelen,1,fs); if (type==0) { // 8-byte doubles size = 8; } else if (type==10) { // 4-byte reals size = 4; } else if ((type==120) || (type==20)) { // 4-byte int size = 4; } else if ((type==30) || (type==40)) { // 2-byte signed (30) or unsigned (40) shorts size = 2; } else if ((type==50) || (type==51)) { // 1-byte signed or unsigned chars (50) or text (51) size = 1; endian = 'L'; // don't bother swapping bytes } else { return -1; } nbytes = mrows * mcols* size; fseek(fs,nbytes,SEEK_CUR); return (0); } /***********************************************/ // This routine checks for the existence of "varname" within 50 variables of // the current file position // If the variable is found, the file pointer points there; // if not, the file remains at the position it had when entering this routine int matsearch(char *filename, char *varname) { FILE *fs; fs = openmat(filename); if (fs == NULL) return -1; return matfind(fs,varname,50000); } void Y_ml4search(int nArgs) { char *filename=YGetString(sp-nArgs+1); char *varname=YGetString(sp-nArgs+2); FILE *fs; fs = openmat(filename); if (fs == NULL) YError(p_strncat("Can't open file ",filename,0)); PushIntValue(matfind(fs,varname,50000)); } void Y_ml4scan(int nArgs) { char *filename=YGetString(sp-nArgs+1); int maxvar=0; int returnString=(1-yarg_subroutine()); if (nArgs==1) { maxvar=10000; } else if (nArgs==2) { maxvar=YGetInteger(sp-nArgs+2); } else { YError("ml4scan takes one or two arguments"); } FILE *fs; fs = openmat(filename); if (fs == NULL) YError(p_strncat("Can't open file ",filename,0)); matscan(fs,maxvar,returnString); matclose(filename); } /***********************************************/ void matclose(char *fullname) { int i; // char *fullname; // fullname = p_strncat(filename,".mat",0); for (i=0 ; i0 int matfind(FILE *fs, char *var, int maxVarsToSearch) { int info[5]; long i; long fileptr,tfileptr,tfp; long nbyt,nelem,skip; long rest,prec; int type,mrows,mcols; int imagf; int namelen; long varNumber = 0; char varname[80]; char string[200]; if (*var=='*') return (1); // requested variable name matches any array name fileptr = ftell(fs); if (DEBUG) printf("Entering matfind\n"); while (1) { tfileptr = ftell(fs); if (DEBUG) printf("at address %ld \n",tfileptr); if (fread(info,4,5,fs)==5) { if (info[4] & 0xffff0000) { // convert header from big endian to little indian // info[0] changed to info[4] 2006/3/15 as double type can be 0, hence // no way to know big from little endian info[0] for doubles. if (DEBUG) printf("swapping!\n"); for (i=0;i<5;i++) SWAP_INT(info[i]); } info[0] = info[0]%1000; tfp = ftell(fs); if (DEBUG) printf("at address %ld \n",tfp); if (DEBUG) printf("info = %d %d %d %d %d\n",info[0],info[1],info[2],info[3],info[4]); if ((namelen = info[4])<80L) { if (fread(varname,1,info[4],fs)==(int)info[4]) { if (DEBUG) printf("variable name: %s\n",varname); if (matchvarname(varname,var)) { // success if a (possibly wildcard in "var") match fseek(fs,tfileptr,SEEK_SET); return (1); } else { type = *info - 10*(*info/10); rest = (*info - type)/10; prec = rest - 10*(rest/10); switch (prec) { case 0: nbyt = 8; break; case 1: nbyt = 4; break; case 2: nbyt = 4; break; case 3: nbyt = 2; break; case 4: nbyt = 2; break; case 5: nbyt = 1; break; default: sprintf(string,"Precision specification not available"); warn(string); fseek(fs,fileptr,SEEK_SET); return (0); } mrows=info[1]; mcols=info[2]; nelem=mrows*mcols; imagf=info[3]; if (imagf) nbyt=2*nbyt; skip = nbyt*nelem; if (DEBUG) printf("skiping %ld bytes\n",skip); if (skip) fseek(fs,nbyt*nelem,SEEK_CUR); } } } } else { break; } if (maxVarsToSearch) { if (++varNumber >= maxVarsToSearch) { break; } } } //lseek(fh,fileptr,SEEK_SET); fseek(fs,fileptr,SEEK_SET); return(0); } /***************************************************************/ void matscan(FILE *fs, int maxVarsToSearch, int returnString) { int info[5]; long i; long fileptr,tfileptr,tfp; long nbyt=0,nelem,skip; int type; int mrows,mcols; int imagf; int namelen; long varNumber = 0; char varname[80]; char *stype=""; int varnum=0; Array *a= PushDataBlock(NewArray(&stringStruct, (Dimension *)0)); long extra=1; fileptr = ftell(fs); if (DEBUG) printf("Entering matscan\n"); while (1) { tfileptr = ftell(fs); if (DEBUG) printf("at address %ld \n",tfileptr); if (fread(info,4,5,fs)==5) { if (info[4] & 0xffff0000) { // convert header from little endian to big indian // info[0] changed to info[4] 2006/3/15 as double type can be 0, hence // no way to know big from little endian info[0] for doubles. if (DEBUG) printf("swapping!\n"); for (i=0;i<5;i++) SWAP_INT(info[i]); } info[0] = info[0]%1000; tfp = ftell(fs); if (DEBUG) printf("at address %ld \n",tfp); if (DEBUG) printf("info = %d %d %d %d %d\n",info[0],info[1],info[2],info[3],info[4]); type = info[0]%1000; if ((namelen = info[4])<80L) { if (fread(varname,1,info[4],fs)==(int)info[4]) { if (type==0) { // 8-byte doubles stype=p_strcpy("double*8"); nbyt=8; } else if (type==10) { // 4-byte reals stype=p_strcpy("real*4 "); nbyt=4; } else if ((type==120) || (type==20)) { // 4-byte int stype=p_strcpy("int*4 "); nbyt=4; } else if (type==30) { // 2-byte signed (30) shorts stype=p_strcpy("short*2 "); nbyt=2; } else if (type==40) { // 2-byte unsigned (40) shorts stype=p_strcpy("ushort*2"); nbyt=2; } else if ((type==50) || (type==51)) { // 1-byte signed or unsigned chars (50) or text (51) stype=p_strcpy("char*1 "); nbyt=1; } else { sprintf(message,"Unknown data type %d",type); YError(message); } if (returnString) { if (varnum!=0) a= PushDataBlock((void *)GrowArray(a, extra)); a->value.q[varnum] = p_malloc(81); sprintf(a->value.q[varnum],"%30s %s array [%d,%d]",varname, \ stype,info[1],info[2]); varnum++; } else { printf("%30s %s array [%d,%d]\n",varname,stype,info[1],info[2]); } mrows=info[1]; mcols=info[2]; nelem=mrows*mcols; imagf=info[3]; if (imagf) nbyt=2*nbyt; skip = nbyt*nelem; if (DEBUG) printf("skiping data part: %ld bytes\n",skip); if (skip) fseek(fs,nbyt*nelem,SEEK_CUR); } } } else { break; } if (maxVarsToSearch) { if (++varNumber >= maxVarsToSearch) { break; } } } } /****************************************************************************/ void writerr(void) { if (errno == ENOSPC) { warn("Insufficient Disk Space!"); } else if (errno == EBADF) { warn("Bad File Descriptor!"); } else { warn("Error Writing Data File!"); } } /***************************************************/ // accepts '?' and single incidence of '*' in "match"; returns 1 if a match, 0 otherwise int matchvarname(char *var, char *match) { int i,n1,n2; char *p,*p1,*p2; if (*match == '*') return 1; // guaranteed match if first char of match string is '*' n1 = strlen(var); if ((p=strchr(match,'*'))) { n2 = p-match; if (n2 > n1) return 0; // guaranteed mismatch if lengths of unambiguous portions of strings are not equal } else { n2 = strlen(match); if (n1!=n2) return 0; // guaranteed mismatch if lengths of strings are not equal } for (i=0,p1=var,p2=match ; i don't create or output to files { saveNormally = saveStates; } /***********************************************/ void warn(char *mes) { printf("%s\n",mes); } static long _TestEndian=1; int IsLittleEndian(void) { return *(char*)&_TestEndian; } void Y_ml4endian(int nArgs) { PushIntValue(*(char*)&_TestEndian); } /****************************************************************************** FUNCTION: SwapEndian PURPOSE: Swap the byte order of a structure EXAMPLE: float F=123.456;; SWAP_FLOAT(F); ******************************************************************************/ void *swap(void* Addr, const int Nb) { static char Swapped[16]; switch (Nb) { case 2: Swapped[0]=*((char*)Addr+1); Swapped[1]=*((char*)Addr ); break; case 3: // As far as I know, 3 is used only with RGB images Swapped[0]=*((char*)Addr+2); Swapped[1]=*((char*)Addr+1); Swapped[2]=*((char*)Addr ); break; case 4: Swapped[0]=*((char*)Addr+3); Swapped[1]=*((char*)Addr+2); Swapped[2]=*((char*)Addr+1); Swapped[3]=*((char*)Addr ); break; case 8: Swapped[0]=*((char*)Addr+7); Swapped[1]=*((char*)Addr+6); Swapped[2]=*((char*)Addr+5); Swapped[3]=*((char*)Addr+4); Swapped[4]=*((char*)Addr+3); Swapped[5]=*((char*)Addr+2); Swapped[6]=*((char*)Addr+1); Swapped[7]=*((char*)Addr ); break; case 16: Swapped[0]=*((char*)Addr+15); Swapped[1]=*((char*)Addr+14); Swapped[2]=*((char*)Addr+13); Swapped[3]=*((char*)Addr+12); Swapped[4]=*((char*)Addr+11); Swapped[5]=*((char*)Addr+10); Swapped[6]=*((char*)Addr+9); Swapped[7]=*((char*)Addr+8); Swapped[8]=*((char*)Addr+7); Swapped[9]=*((char*)Addr+6); Swapped[10]=*((char*)Addr+5); Swapped[11]=*((char*)Addr+4); Swapped[12]=*((char*)Addr+3); Swapped[13]=*((char*)Addr+2); Swapped[14]=*((char*)Addr+1); Swapped[15]=*((char*)Addr ); break; } return (void*)Swapped; } yorick-ml4-0.6.0/Changelog0000644000076500001440000000046411111272263014706 0ustar frigautusersThis is the changelog of the sourceforge cvs ml4 package. Not the debian changelog. -- Francois Rigaut Thu Nov 20 12:28:44 ARST 2008 ml4-0.6.0: Included and uploaded changes from Thibaut Paumard making ml4 64 bits safe. Beware: In 64 bits, longs (8bytes) are saved as int (4bytes) yorick-ml4-0.6.0/Makefile0000644000076500001440000000775611254106373014555 0ustar frigautusers# these values filled in by yorick -batch make.i Y_MAKEDIR=/usr/lib/yorick/2.1 Y_EXE=/usr/lib/yorick/2.1/bin/yorick Y_EXE_PKGS= Y_EXE_HOME=/usr/lib/yorick/2.1 Y_EXE_SITE=/usr/share/yorick/2.1 # ----------------------------------------------------- optimization flags # options for make command line, e.g.- make COPT=-g TGT=exe COPT=$(COPT_DEFAULT) TGT=$(DEFAULT_TGT) # ------------------------------------------------ macros for this package PKG_NAME=ml4 PKG_I=ml4.i OBJS=ml4.o # change to give the executable a name other than yorick PKG_EXENAME=yorick # PKG_DEPLIBS=-Lsomedir -lsomelib for dependencies of this package PKG_DEPLIBS= # set compiler (or rarely loader) flags specific to this package PKG_CFLAGS= PKG_LDFLAGS= # list of additional package names you want in PKG_EXENAME # (typically Y_EXE_PKGS should be first here) EXTRA_PKGS=$(Y_EXE_PKGS) # list of additional files for clean PKG_CLEAN= # autoload file for this package, if any PKG_I_START=ml4_start.i # non-pkg.i include files for this package, if any PKG_I_EXTRA= # -------------------------------- standard targets and rules (in Makepkg) # set macros Makepkg uses in target and dependency names # DLL_TARGETS, LIB_TARGETS, EXE_TARGETS # are any additional targets (defined below) prerequisite to # the plugin library, archive library, and executable, respectively PKG_I_DEPS=$(PKG_I) Y_DISTMAKE=distmake include $(Y_MAKEDIR)/Make.cfg include $(Y_MAKEDIR)/Makepkg include $(Y_MAKEDIR)/Make$(TGT) # override macros Makepkg sets for rules and other macros # Y_HOME and Y_SITE in Make.cfg may not be correct (e.g.- relocatable) Y_HOME=$(Y_EXE_HOME) Y_SITE=$(Y_EXE_SITE) # reduce chance of yorick-1.5 corrupting this Makefile MAKE_TEMPLATE = protect-against-1.5 # ------------------------------------- targets and rules for this package # simple example: #myfunc.o: myapi.h # more complex example (also consider using PKG_CFLAGS above): #myfunc.o: myapi.h myfunc.c # $(CC) $(CPPFLAGS) $(CFLAGS) -DMY_SWITCH -o $@ -c myfunc.c ml4.o: ml4.h clean:: -rm -rf binaries # -------------------------------------------------------- end of Makefile # for the binary package production (add full path to lib*.a below): PKG_DEPLIBS_STATIC=-lm PKG_ARCH = $(OSTYPE)-$(MACHTYPE) PKG_VERSION = $(shell (awk '{if ($$1=="Version:") print $$2}' $(PKG_NAME).info)) # .info might not exist, in which case he line above will exit in error. # packages or devel_pkgs: PKG_DEST_URL = packages package: $(MAKE) $(LD_DLL) -o $(PKG_NAME).so $(OBJS) ywrap.o $(PKG_DEPLIBS_STATIC) $(DLL_DEF) mkdir -p binaries/$(PKG_NAME)/dist/y_home/lib mkdir -p binaries/$(PKG_NAME)/dist/y_home/i-start mkdir -p binaries/$(PKG_NAME)/dist/y_site/i0 cp -p $(PKG_I) binaries/$(PKG_NAME)/dist/y_site/i0/ cp -p $(PKG_NAME).so binaries/$(PKG_NAME)/dist/y_home/lib/ if test -f "check.i"; then cp -p check.i binaries/$(PKG_NAME)/.; fi if test -n "$(PKG_I_START)"; then cp -p $(PKG_I_START) \ binaries/$(PKG_NAME)/dist/y_home/i-start/; fi cat $(PKG_NAME).info | sed -e 's/OS:/OS: $(PKG_ARCH)/' > tmp.info mv tmp.info binaries/$(PKG_NAME)/$(PKG_NAME).info cd binaries; tar zcvf $(PKG_NAME)-$(PKG_VERSION)-$(PKG_ARCH).tgz $(PKG_NAME) distbin: package if test -f "binaries/$(PKG_NAME)-$(PKG_VERSION)-$(PKG_ARCH).tgz" ; then \ ncftpput -f $(HOME)/.ncftp/maumae www/yorick/$(PKG_DEST_URL)/$(PKG_ARCH)/tarballs/ \ binaries/$(PKG_NAME)-$(PKG_VERSION)-$(PKG_ARCH).tgz; fi if test -f "binaries/$(PKG_NAME)/$(PKG_NAME).info" ; then \ ncftpput -f $(HOME)/.ncftp/maumae www/yorick/$(PKG_DEST_URL)/$(PKG_ARCH)/info/ \ binaries/$(PKG_NAME)/$(PKG_NAME).info; fi distsrc: clean cd ..; tar --exclude binaries --exclude .svn --exclude CVS --exclude *.spec -zcvf \ $(PKG_NAME)-$(PKG_VERSION)-src.tgz yorick-$(PKG_NAME)-$(PKG_VERSION);\ ncftpput -f $(HOME)/.ncftp/maumae www/yorick/$(PKG_DEST_URL)/src/ \ $(PKG_NAME)-$(PKG_VERSION)-src.tgz ncftpput -f $(HOME)/.ncftp/maumae www/yorick/contrib/ \ ../$(PKG_NAME)-$(PKG_VERSION)-src.tgz # -------------------------------------------------------- end of Makefile yorick-ml4-0.6.0/ml4.h0000644000076500001440000000474011111272606013743 0ustar frigautusers/* ml4.h Yorick plugin * * header file for ml4.c. C function for matlab 4 IO * * $Id: ml4.h,v 1.2 2008/11/20 14:34:46 frigaut Exp $ * Francois Rigaut, 2005-2007 * last revision/addition: 2007jun14 * * Copyright (c) 2005, Francois RIGAUT (frigaut@gemini.edu, Gemini * Observatory, 670 N A'Ohoku Place, HILO HI-96720). * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details (to receive a copy of the GNU * General Public License, write to the Free Software Foundation, Inc., 675 * Mass Ave, Cambridge, MA 02139, USA). * * $Log: ml4.h,v $ * Revision 1.2 2008/11/20 14:34:46 frigaut * - Included and uploaded changes from Thibaut Paumard making ml4 64 bits safe. * - Beware: In 64 bits, longs (8bytes) are saved as int (4bytes) * * - a few more minor text edits * - added ML4_VERSION variable * * */ int matout(char *filename,char *varname,void *var,int nrows,int ncols,char vartype, char *mode, char endianess); int matout_string(char *filename,char *varname,char *string,char *mode); FILE *openmat(char *filename); int matin(char *filename,char *varname,void *var,int nrows,int ncols,int vartype); int matread(char *filename, char *varname,void *var,int nrows,int ncols,int *realrows, int *realcols, int vartype); int matskip(char *filename); int matcheck(char *filename, char *varname, char *message_insert, int nrows, int ncols, int vartype); int matsearch(char *filename, char *varname); void matscan(FILE *fs, int maxVarsToSearch, int returnString); void matclose(char *filename); int textread(char *file, char *variable, float *values, int nvals); int matfind(FILE *fs, char *var, int maxVarsToSearch); int matload(char *filename, char *varname, void *var, int nelements, int vartype); int matloadnowarn(char *filename, char *varname, void *var, int nelements, int vartype); int matGetFrameCount(char *filename); int matchvarname(char *var, char *match); void InitMatsave(int saveStates); int Mat5Out(char *filename,char *varname,void *var, int nframes, int nrows, int ncols, int vartype); int Mat5HeaderOut(int fd);