/* ext_coord.c : Extention library related to coordinate handling in GPhys */ #include #include #include "ruby.h" #include "narray.h" #ifndef RARRAY_PTR # define RARRAY_PTR(ary) (RARRAY(ary)->ptr) #endif #ifndef RARRAY_LEN # define RARRAY_LEN(ary) (RARRAY(ary)->len) #endif /* cut_range : a private method for AssocCoord (used in AssocCoord#cut) */ static VALUE assoc_coord_cut_range(self, vmins, vmaxs, crds, masks, crdaxexist, orgaxlens) VALUE self, vmins, vmaxs, crds, masks, crdaxexist, orgaxlens; // All input variables are supposed to be Arrays { VALUE wheres, whna; // return value (Array) int nc, ic, na, ia, jlen, j, klen, k, ndimk, dimk; int *lens, lentot, lenmax, *mod, *sub, **mlt, *jmlt, *dimk2a; int last_non0, l, cidx, *natype, *nomask, included, whcount; int32_t **axexist, *whptr, *whbuf; double *vmax, *vmin, val, **dval; float **fval; int8_t **mask; nc = RARRAY_LEN(crds); // lengths of vmins,vmaxs,crds,masks,crdaxexist na = RARRAY_LEN(orgaxlens); wheres = rb_ary_new(); /* input check */ if(nc==0){rb_raise(rb_eArgError,"crds empty [%s:%d]",__FILE__,__LINE__);} if(na==0){rb_raise(rb_eArgError,"orgaxlens empty [%s:%d]",__FILE__,__LINE__);} if ( nc!=RARRAY_LEN(vmins) || nc!=RARRAY_LEN(vmaxs) || nc!=RARRAY_LEN(masks) || nc!=RARRAY_LEN(crdaxexist) ) { rb_raise(rb_eArgError,"lengths of array do not agree [%s:%d]", __FILE__,__LINE__); } /* info regaring lengths of original axes */ lentot = 1; lenmax = -1; lens = ALLOCA_N(int,na); for(ia=0; ia lenmax) { lenmax = lens[ia]; } } ndimk = ( (na==1) ? 1 : (na-1) ) ; mod = ALLOCA_N(int,ndimk); sub = ALLOCA_N(int,ndimk); mlt = ALLOCA_N(int*,nc); axexist = ALLOCA_N(int32_t*,nc); for(ic=0; ic=0; l--) { if( mlt[ic][l] != 0){ last_non0 = mlt[ic][l]; break; } } mlt[ic][dimk] = last_non0 * lens[dimk2a[dimk]]; } else { mlt[ic][dimk] = 0; } } } for(ic=0; ic=ia) { mlt[ic][dimk] *= lens[ia];} } //printf("## %d %d %d %d : ",ia,dimk,mod[dimk],sub[dimk]);//DEL later //for(ic=0;ic= vmin[ic] && val <= vmax[ic] ); if (!included) {break;} } if(included){ whbuf[whcount] = j; whcount++; break; } } } whna = na_make_object(NA_LINT, 1, &whcount, cNArray); rb_ary_push( wheres, whna ); whptr = NA_PTR_TYPE( whna, int32_t* ); for(j=0; j