home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / graphics / explorer / 482 < prev    next >
Encoding:
Text File  |  1993-01-25  |  2.8 KB  |  123 lines

  1. Newsgroups: comp.graphics.explorer
  2. Path: sparky!uunet!nih-csl!freud.nia.nih.gov!howardy
  3. From: howardy@freud.nia.nih.gov (Howard Wai-Chun Yeung)
  4. Subject: Need help with my module
  5. Message-ID: <1993Jan25.195823.12754@alw.nih.gov>
  6. Sender: postman@alw.nih.gov (AMDS Postmaster)
  7. Organization: (Natl. Institutes of Health, Bethesda, MD)
  8. Date: Mon, 25 Jan 1993 19:58:23 GMT
  9. Lines: 112
  10.  
  11.  
  12. I write the following simple program using module muilder functions.
  13. The problem is that it cannot send the lattice data to other modules.
  14. I make a connection to WriteLat(), but no data is written.  It seems
  15. like the lattice is empty.  But I retrive the data pointer from the 
  16. lattice.  It does have data!
  17. The problem has bug me for a few days.  I wish it will just be a small
  18. mistake I am not aware of.
  19.  
  20.  
  21.  
  22. #include <stdio.h>
  23.  
  24. #include "cx/PortAccess.h"
  25. #include "cx/DataTypes.h"
  26. #include "cx/DataAccess.h"
  27. #include "cx/UserFuncs.h"
  28.  
  29. #define  MAX_DIM        250
  30. #define  SLICE_DIM      2
  31.  
  32.  
  33. translate_u3l(file_name, x_dim, y_dim, z_dim, slice_no)
  34. char *file_name;
  35. long x_dim, y_dim, z_dim;
  36. long slice_no;
  37. {
  38.   char *var;
  39.   int *int_ptr;
  40.   int i, j, k, size = 1;
  41.   FILE *in_file;
  42.   char *lat_file;
  43.   long slice_dim[2];
  44.   cxPrimType prim_type = cx_prim_long;
  45.   cxLattice *lattice_2d;
  46.  
  47.   /*check any parameter error*/
  48.   if (x_dim > 250 || y_dim >250 || z_dim >250)
  49.   {
  50.     printf("Dimension of the volume is too large.\n");
  51.     return 0;;
  52.   }
  53.  
  54.   /*set the maximum number of slice available*/
  55.   cxInWdgtLongMinMaxSet("slice_no", 0, z_dim-1);
  56.  
  57.   /* open the input file */
  58.   if((in_file=fopen(file_name, "r")) == NULL)
  59.   {
  60.         char str[128];
  61.         sprintf(str,"cannot open input file %s", lat_file);
  62.         cxModAlert( str );
  63.      fclose(in_file);
  64.         return 0;
  65.   }
  66.  
  67.   if((var = (char *)malloc(size)) == NULL)
  68.   {
  69.     printf("Memory allocation failed\n");
  70.     exit(1);;
  71.   }
  72.  
  73.  
  74.  
  75.    slice_dim[0] = x_dim;
  76.    slice_dim[1] = y_dim;
  77.    lattice_2d = cxLatNew(SLICE_DIM,slice_dim,NO_VARIABLE,prim_type,
  78.             SLICE_DIM,cx_coord_uniform);
  79.  
  80.         
  81.  
  82.     /*no error in share memory allocation*/
  83.    if (!cxDataAllocErrorGet())
  84.    {
  85.     cxLatPtrGet(lattice_2d, NULL, &int_ptr, NULL, NULL);
  86.    }
  87.    else
  88.    {
  89.     printf("Lattice allocation error.\n");
  90.         return 0;
  91.    }
  92.  
  93.    /*in_file then is the pointer to the opened file read only 
  94.     the portion of file which is the slice*/
  95.    fseek(in_file, 0L, 0); 
  96.    fseek(in_file, x_dim*y_dim*slice_no, 1);
  97.     
  98.    /*x_dim is number of colums while y_dim is number of row*/
  99.    for (i=0; i<y_dim; i++){
  100.     for (j=0; j<x_dim; j++){      
  101.         fread(var, size, 1, in_file);
  102.         int_ptr[i*x_dim + j] = (long) (*var); 
  103.     }
  104.    }
  105.     
  106.    /*x_dim is number of colums while y_dim is number of row*/
  107.   cxOutputDataSet(cxOutputPortOpen("slice_lattice"), lattice_2d);
  108.   free(var);
  109.   fclose(in_file);
  110.   return;
  111. }
  112.  
  113.  
  114.  
  115. With thousand thanks!
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.