C INTERNATIONAL AVS CENTER C (This disclaimer must remain at the top of all files) C C WARRANTY DISCLAIMER C C This module and the files associated with it are distributed free of charge. C It is placed in the public domain and permission is granted for anyone to use, C duplicate, modify, and redistribute it unless otherwise noted. Some modules C may be copyrighted. You agree to abide by the conditions also included in C the AVS Licensing Agreement, version 1.0, located in the main module C directory located at the International AVS Center ftp site and to include C the AVS Licensing Agreement when you distribute any files downloaded from C that site. C C The International AVS Center, MCNC, the AVS Consortium and the individual C submitting the module and files associated with said module provide absolutely C NO WARRANTY OF ANY KIND with respect to this software. The entire risk as to C the quality and performance of this software is with the user. IN NO EVENT C WILL The International AVS Center, MCNC, the AVS Consortium and the individual C submitting the module and files associated with said module BE LIABLE TO C ANYONE FOR ANY DAMAGES ARISING FROM THE USE OF THIS SOFTWARE, INCLUDING, C WITHOUT LIMITATION, DAMAGES RESULTING FROM LOST DATA OR LOST PROFITS, OR ANY C SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES. C C This AVS module and associated files are public domain software unless C otherwise noted. Permission is hereby granted to do whatever you like with C it, subject to the conditions that may exist in copyrighted materials. Should C you wish to make a contribution toward the improvement, modification, or C general performance of this module, please send us your comments: why you C liked or disliked it, how you use it, and most important, how it helps your C work. We will receive your comments at avs@ncsc.org. C C Please send AVS module bug reports to avs@ncsc.org. C C---------------------------------------------------------------------- C Read Hologram C Read an ASCII File containing 2D array data, C and generate an AVS Field output port. C This is a template read module in Fortran, C based on the standard example "test_fld2_f.f" C It has 4 dials, controlling data transformations. C C This module performs the following operations: C 1. Reads an Input file with C Format= 2I10 integers on first line, then C Format= 6F12.7 for the rest of the 2D array C C 2. Processes the data, by selection: C If on "channel" row, then C out = ( in * multiplier + offset ) * Chan_Coeff C else all other data C out = in * multiplier + offset C C 3. Sends the data to the AVS Output port, C in a 2D array. C C An example of a typical input file for this module is: C 10 10 C 1.0000000 2.0000000 3.0000000 4.0000000 5.0000000 6.0000000 C 7.0000000 8.0000000 9.0000000 10.0000000 11.0000000 12.0000000 C 13.0000000 14.0000000 15.0000000 16.0000000 17.0000000 18.0000000 C 19.0000000 20.0000000 21.0000000 22.0000000 23.0000000 24.0000000 C ....... C ....... C To create a simple test file, compile and run the following small C program, sending the output to a file. C C5 format (2I10) C10 format (6f12.7) C write(6,5) 10, 10 C write(6,10) (float(i),i=1,100) C stop C end C C---------------------------------------------------------------------- C Author: Ian J. Curington, Advanced Visual Systems, Inc. C Staines, UK C On request of Dr. D. Wood, BTRL C C Revision History: C 7 July 1992 ianc - Original C 8 July 1992 ianc - Added Processing dials C C---------------------------------------------------------------------- C C "@(#)read_hologram.f 7.1 AVS 92/02/25" C Copyright (c) 1990,1991 by C Advanced Visual Systems Inc. C All Rights Reserved C C This software comprises unpublished confidential information of C Advanced Visual Systems Inc. and may not be used, copied or made C available to anyone, except in accordance with the license C under which it is furnished. C C This file is under sccs control at AVS in: C @europa/sccs1.p/avs/examples/s.read_hologram.f C C C ************************************************************ C AVS module description routine - defines the module, C its output port, and its parameters C ************************************************************ subroutine AVSinit_modules C IAC CODE CHANGE : include 'avs/avs.inc' INCLUDE '/usr/avs/include/avs.inc' external read_hologram_compute integer iparm C C Set the module name C call AVSset_module_name('Read Hologram', 'data') C call AVSset_module_flags( single_arg_data ) C C Define the output port: an AVS two-dimensional field of C reals, with a two-dimensional mapping space C oport = AVScreate_output_port('field', * 'field 2D scalar real 2-space uniform') C C This tells AVS to automatically free the output data after C each call. This way, we can reallocate it each time without C difficulty. C call AVSautofree_output(oport) C C Add the parameters, AVS will automatically add the C user interface controls: C iparm = AVSadd_parameter('Filename', 'string', ' ',' ',' ') call AVSconnect_widget(iparam,'browser') iparm = AVSadd_parameter('multiplier', 'real',1.0,0.0,100.0) iparm = AVSadd_parameter('offset', 'real',0.0,0.0,100.0) iparm = AVSadd_parameter('channel', 'integer',1,1,2000) iparm = AVSadd_parameter('chan Coeff', 'real',0.0,0.0,100.0) C C Set the compute procedure C call AVSset_compute_proc(read_hologram_compute) return end C ************************************************************ C read_hologram_compute function - creates the field based on the C state of the parameters (described above). C C This module generates a 3D field, so the compute function expects C an output field "pointer" value which it uses as an argument to the C field accessor and allocation functions. The accessor functions C expect to be told that this is an output field since it will handle C output field pointers slightly differently than input field pointers. C C Through AVSdata_alloc and the accessor functions, this function will C fill the data and points arrays with its computation. C C The parameters are C passed to this subroutine by the AVS flow exective based on C the settings of the on-screen control widgets. C ************************************************************ integer function read_hologram_compute(output_field, * filename, multiplier, offset, channel, ch_coeff ) C IAC CODE CHANGE : include 'avs/avs.inc' INCLUDE '/usr/avs/include/avs.inc' C The input (none), output and parameter arguments C The output field is received as an integer C integer output_field real multiplier, offset real ch_coeff integer channel character*128 filename C C C Internal declarations C external read_hologram_compute2 integer dims, iresult, read_hologram_compute2 integer ofield, pfield integer ocoords, pcoords integer itemp real field_data dimension field_data(1), dims(2) dimension coords(1) character*64 field_descriptor character*128 errbuf integer ni, nj C C define the logical unit for the input file C integer IN_UNIT save IN_UNIT data IN_UNIT / 18 / C C Open the Input file, attatch to logical unit, and read C the first header line for dimensions to follow C if ( filename(1:1) .eq. ' ' ) then read_hologram_compute = 0 return endif C call get_header ( filename, IN_UNIT, ni, nj ) C C Change the range of the channel dial to relfect the input C data size: C call AVSmodify_parameter ('channel',AVS_MAXVAL,0,0,nj) C C Determine what kind of field is being requested and provide that C information in the descriptor used to AVSdata_alloc. Once set by C AVSdata_alloc the individual field scalar descriptors (uniform, type, C etc) cannot be changed C field_descriptor = 'field 2D scalar real 2-space uniform' C C Setup dimensions array used in AVSdata_alloc C AVSdata_alloc( field_descriptor, dimensions_array) C dims(1) = ni dims(2) = nj C C AVSdata_alloc will automatically initialize the field variables C covering the dimensions, type, etc. C output_field = AVSdata_alloc(field_descriptor, dims) if (output_field .eq. 0) then write(errbuf,90) field_descriptor 90 format('Error allocating field ',A) call AVSerror(errbuf) read_hologram_compute = 0 return endif C C Example of accessors for field scalar values - itemp is value C C itemp = AVSfield_get_int(output_field, AVS_field_ndim) C itemp = AVSfield_get_int(output_field, AVS_field_nspace) C itemp = AVSfield_get_int(output_field, AVS_field_veclen) C itemp = AVSfield_get_int(output_field, AVS_field_type) C itemp = AVSfield_get_int(output_field, AVS_field_size) C itemp = AVSfield_get_int(output_field, AVS_field_uniform) C C The internal arrays in the field have been allocated in C AVSdata_alloc so all we have to do is to retrieve the offsets to C the data array and the coordinates array. This works just like the C AVSptr_offset function. C iresult = AVSfield_data_offset(output_field, field_data, ofield) iresult = AVSfield_points_offset(output_field, coords, ocoords) C C Now call a second function which directly manipulates the field C arrays - passing the first actual element of the array C allocations allows the second routine to receive them as adjustable C arrays C iresult=read_hologram_compute2(field_data(ofield+1), * ni, nj, multiplier, offset, * channel, ch_coeff, * IN_UNIT ) C Report results of operation C read_hologram_compute = iresult return end C ******************************************************************* C This function actually fills the Output port array with values C ******************************************************************* integer function read_hologram_compute2(field_data, * ni, nj, multiplier, offset, * channel, ch_coeff, * IN_UNIT ) C IAC CODE CHANGE : include 'avs/avs.inc' INCLUDE '/usr/avs/include/avs.inc' C C Pointers to the field and the mapping coordinates C integer ni,nj integer i,j character*32 gridtype real field_data(ni,nj) real multiplier, offset real ch_coeff integer channel integer IN_UNIT C C Here is the Format Statement for all the Array Data C in the input file: C 800 format (6F12.7) C C Load in the field data C read ( IN_UNIT, 800 ) ((field_data(i,j),i=1,ni),j=1,nj) C C Process the input data with the dial control factors: C inplace operator C do 20 j=1,nj if ( j .eq. channel ) then do 10 i=1,ni field_data(i,j)= * (field_data(i,j)*multiplier+offset)*ch_coeff 10 continue else do 15 i=1,ni field_data(i,j)=field_data(i,j)*multiplier+offset 15 continue endif 20 continue C C Close the file here C close ( IN_UNIT ) C C Return a 1 to indicate success C read_hologram_compute2 = 1 return end C ******************************************************************* C This function actually fills the Output port array with values C ******************************************************************* subroutine get_header ( filename, IN_UNIT, ni, nj ) character*128 filename integer IN_UNIT integer ni, nj integer ier C C Open the ASCII File for reading C open( unit=IN_UNIT,file=filename,status='old',iostat=ier) C C Get the Dimensions off of the first line: C read ( IN_UNIT, 400 ) ni, nj C C Here is the FORMAT statement controlling the two dimension C integers on the First Line C 400 format ( 2I10 ) return end