/** Changes the directory to the given path @param fat_fs FS_Instance to find all the information from @param current_directory The location of the current directory @param path The name of the directory we want to change into @return Location of the new directory we are in **/ FS_CurrentDir change_dir(FS_Instance *fat_fs, FS_CurrentDir current_directory, char *path){ char *tokens = strtok(path, "/\\"); uint32_t directory = current_directory; while(NULL != tokens) { current_directory = directory; FS_EntryList *list = get_entries(fat_fs, (uint32_t)directory); uint8_t found = 0; while(NULL != list) { FS_Entry *entry = list->node; if((current_directory == directory) && (check_mask(entry->entry->DIR_Attr, ATTR_DIRECTORY))) { char *file_name = get_file_name(entry->entry); if(strcmp(tokens, file_name) == 0) { found = 1; directory = (entry->entry->DIR_FstClusHI << 8) + entry->entry->DIR_FstClusLO; } free(file_name); } FS_EntryList *curr = list; list = list->next; entry_list_cleanup(curr); } if(!found) { printf("Couldn't find directory.\n"); directory = current_directory; break; } tokens = strtok(NULL, "/\\"); } return directory; }
void konlite_call(void) { unsigned short tmp; k_tmr++; for(tmp=0;tmp<ETH_RXBUFNB;tmp++) { buf = get_mac_data(tmp); // буфер принятых данных if(buf->len) { m_pkt=get_mac_pkt(buf); // формирование структуры мак пакета if(check_mac(m_pkt)) // проверка мак адреса назначения { switch(get_eth_type(m_pkt)) { case IP_TYPE: ip_p=ip_rcv(m_pkt); if(check_ip_req(ip_p)) { if(check_mask(ip_p->ip_s)==0) {set_gate_cmd();} // запрос выходит за рамки подсети else{clr_gate_cmd();add_arp_tab(ip_p->ip_s,m_pkt->mac_s);} // запрос в пределах подсети switch(get_ip_type(ip_p)) { case ICMP_TYPE: icmp_p=icmp_rcv(ip_p); if(check_ping(icmp_p)) {ping_echo(icmp_p,ip_p);} break; case UDP_TYPE: udp_p=udp_rcv(ip_p); portudp_scan(udp_p,ip_p); break; case TCP_TYPE: tcp_p=tcp_rcv(ip_p); porttcp_scan(tcp_p,ip_p); break; } } break; case ARP_TYPE: arp_p=arp_rcv(m_pkt); // формирование структуры arp пакета if(check_arp_req(arp_p)) // arp запрос { add_arp_tab(arp_p->ip_s,arp_p->mac_s); arp_answer(arp_p); }else if(check_arp_answer_gate(arp_p)) // arp ответ от шлюза { set_gate_mac(arp_p->mac_s); } break; case UNDEF_TYPE: break; } } unlock_mac_rx(tmp); } } if(k_tmr % GATE_PER == 0) get_gate_mac(); // периодический запрос mac шлюза }
int test_main( int , char* [] ) { check_mask(); test_all<bg::model::d2::point_xy<int> >(); test_all<bg::model::d2::point_xy<double> >(); #if defined(HAVE_TTMATH) test_all<bg::model::d2::point_xy<ttmath_big> >(); #endif return 0; }
int mask_match_address(SERVER_REC *server, const char *mask, const char *nick, const char *address) { char *str; int ret, wildcards; g_return_val_if_fail(server == NULL || IS_SERVER(server), FALSE); g_return_val_if_fail(mask != NULL && nick != NULL, FALSE); if (address == NULL) address = ""; str = !check_address(mask, &wildcards) ? (char *) nick : g_strdup_printf("%s!%s", nick, address); ret = check_mask(server, mask, str, wildcards); if (str != nick) g_free(str); return ret; }
int read_PRESTO_subbands(FILE * infiles[], int numfiles, float *subbanddata, double timeperblk, int *maskchans, int *nummasked, mask * obsmask, float *padvals) /* Read short int subband data written by prepsubband */ /* Note: This version returns a transpose of the version */ /* listed in prepsubband.c */ { int ii, jj, index, numread = 0; short subsdata[SUBSBLOCKLEN]; static int currentblock = 0; /* Read the data */ for (ii = 0; ii < numfiles; ii++) { index = ii * SUBSBLOCKLEN; numread = chkfread(subsdata, sizeof(short), SUBSBLOCKLEN, infiles[ii]); for (jj = 0; jj < numread; jj++, index++) subbanddata[index] = (float) subsdata[jj]; for (jj = numread; jj < SUBSBLOCKLEN; jj++, index++) subbanddata[index] = 0.0; } /* Mask it if required */ if (obsmask->numchan && numread) { double starttime; starttime = currentblock * timeperblk; *nummasked = check_mask(starttime, timeperblk, obsmask, maskchans); if (*nummasked == -1) { /* If all channels are masked */ for (ii = 0; ii < numfiles; ii++) { index = ii * SUBSBLOCKLEN; for (jj = 0; jj < SUBSBLOCKLEN; jj++, index++) subbanddata[index] = padvals[ii]; } } else if (*nummasked > 0) { /* Only some of the channels are masked */ int channum; for (ii = 0; ii < *nummasked; ii++) { channum = maskchans[ii]; index = channum * SUBSBLOCKLEN; for (jj = 0; jj < SUBSBLOCKLEN; jj++, index++) subbanddata[index] = padvals[channum]; } } } currentblock += 1; return numread; }
int main(int argc, char *argv[]) { unsigned int i; struct htable_obj ht, ht2; struct obj val[NUM_VALS], *result; unsigned int dne; void *p; struct htable_obj_iter iter; plan_tests(29); for (i = 0; i < NUM_VALS; i++) val[i].key = i; dne = i; htable_obj_init(&ht); ok1(ht.raw.max == 0); ok1(ht.raw.bits == 0); /* We cannot find an entry which doesn't exist. */ ok1(!htable_obj_get(&ht, &dne)); /* Fill it, it should increase in size. */ add_vals(&ht, val, NUM_VALS); ok1(ht.raw.bits == NUM_BITS + 1); ok1(ht.raw.max < (1 << ht.raw.bits)); /* Mask should be set. */ ok1(ht.raw.common_mask != 0); ok1(ht.raw.common_mask != -1); ok1(check_mask(&ht.raw, val, NUM_VALS)); /* Find all. */ find_vals(&ht, val, NUM_VALS); ok1(!htable_obj_get(&ht, &dne)); /* Walk once, should get them all. */ i = 0; for (p = htable_obj_first(&ht,&iter); p; p = htable_obj_next(&ht, &iter)) i++; ok1(i == NUM_VALS); i = 0; for (p = htable_obj_prev(&ht,&iter); p; p = htable_obj_prev(&ht, &iter)) i++; ok1(i == NUM_VALS); /* Delete all. */ del_vals(&ht, val, NUM_VALS); ok1(!htable_obj_get(&ht, &val[0].key)); /* Worst case, a "pointer" which doesn't have any matching bits. */ htable_add(&ht.raw, 0, (void *)~(uintptr_t)&val[NUM_VALS-1]); htable_obj_add(&ht, &val[NUM_VALS-1]); ok1(ht.raw.common_mask == 0); ok1(ht.raw.common_bits == 0); /* Delete the bogus one before we trip over it. */ htable_del(&ht.raw, 0, (void *)~(uintptr_t)&val[NUM_VALS-1]); /* Add the rest. */ add_vals(&ht, val, NUM_VALS-1); /* Check we can find them all. */ find_vals(&ht, val, NUM_VALS); ok1(!htable_obj_get(&ht, &dne)); /* Check copy. */ ok1(htable_obj_copy(&ht2, &ht)); /* Delete them all by key. */ del_vals_bykey(&ht, val, NUM_VALS); del_vals_bykey(&ht2, val, NUM_VALS); /* Write two of the same value. */ val[1] = val[0]; htable_obj_add(&ht, &val[0]); htable_obj_add(&ht, &val[1]); i = 0; result = htable_obj_getfirst(&ht, &i, &iter); ok1(result == &val[0] || result == &val[1]); if (result == &val[0]) { ok1(htable_obj_getnext(&ht, &i, &iter) == &val[1]); ok1(htable_obj_getnext(&ht, &i, &iter) == NULL); /* Deleting first should make us iterate over the other. */ ok1(htable_obj_del(&ht, &val[0])); ok1(htable_obj_getfirst(&ht, &i, &iter) == &val[1]); ok1(htable_obj_getnext(&ht, &i, &iter) == NULL); } else { ok1(htable_obj_getnext(&ht, &i, &iter) == &val[0]); ok1(htable_obj_getnext(&ht, &i, &iter) == NULL); /* Deleting first should make us iterate over the other. */ ok1(htable_obj_del(&ht, &val[1])); ok1(htable_obj_getfirst(&ht, &i, &iter) == &val[0]); ok1(htable_obj_getnext(&ht, &i, &iter) == NULL); } htable_obj_clear(&ht); htable_obj_clear(&ht2); return exit_status(); }
/* * @brief: Searches for the biggest plane of $(id)'s and DONTCARES * @param: char *basemask: The mask where we stem from * @param: const int bits: How many bits the (char-)bitmask is wide * @param: char id: Are we looking for ONES or ZEROS * @param: const int c: From where up we are searching (default=0) * @return: Pointer to the biggest mask */ static char* get_mask(const char *db, const char *basemask, \ const int bits, const char id, const int c) { char curc; // We are checking from curc to above /* Debugging check_mask segv issue printf("reclvl: %d\n", c); printf("basemask: "); printplane(basemask, bits); */ /*We were getting a stackoverflow ... */ // Check the basemask. If it is wrong, return NULL if (check_mask(db, basemask, id, bits)) { // It is correct. Check the derivates char *dermask[bits-c]; // These are the derivates // The resmask is the ret of the next get_mask() // It is NULL if there was no good mask, or the best mask found char *resmask[bits-c]; int i; // counter for (curc = c, i = 0; curc < bits; curc++, i++) { // Make the derivate mask dermask[i] = malloc(bits * sizeof(char)); // Derivate mask memcpy(dermask[i], basemask, bits * sizeof(char)); dermask[i][curc] = 2; // Now feed it back to this function recursively resmask[i] = get_mask(db, dermask[i], bits, id, curc + 1); } // We got all the masks we want, so free the dermasks // Also, check for the best resmask already char* bestmask = NULL; int bestscore = 0; for (i = 0; i < bits - c; i++) { free(dermask[i]); // check for the best mask int score = 0; if (resmask[i]) score = amount_in_ar(resmask[i], bits, 2); if (bestscore < score) { bestscore = score; // Wait a sec. This one is better, Delete the old one! if (bestmask) free(bestmask); // Now replace the dangling pointer with the new hero! bestmask = resmask[i]; } else { // No highscore? Delete that crap! if (resmask[i]) free(resmask[i]); } } /* Debugging here: if (bestmask && c == 0) { printf("At level 0: "); printplane(bestmask, bits); printf("\n"); } else if (c == 0) { printf("At level 0: "); printplane(basemask, bits); printf("\n"); }*/ // If there is a winner mask, return it. If not, move on. if (bestmask) return bestmask; // The mask is correct, but we didn't find better masks char *basemask_cp = malloc(bits * sizeof(char)); memcpy(basemask_cp, basemask, bits * sizeof(char)); return basemask_cp; } /* end check_mask() */ if (c == 0) assert(0); // The first basemask should never fail return NULL; }
int main(int argc, char *argv[]) { unsigned int i; uintptr_t perfect_bit; struct htable ht; uint64_t val[NUM_VALS]; uint64_t dne; void *p; struct htable_iter iter; plan_tests(29); for (i = 0; i < NUM_VALS; i++) val[i] = i; dne = i; htable_init(&ht, hash, NULL); ok1(ht.max == 0); ok1(ht.bits == 0); /* We cannot find an entry which doesn't exist. */ ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne)); /* This should increase it once. */ add_vals(&ht, val, 0, 1); ok1(ht.bits == 1); ok1(ht.max == 1); ok1(ht.common_mask == -1); /* Mask should be set. */ ok1(check_mask(&ht, val, 1)); /* This should increase it again. */ add_vals(&ht, val, 1, 1); ok1(ht.bits == 2); ok1(ht.max == 3); /* Mask should be set. */ ok1(ht.common_mask != 0); ok1(ht.common_mask != -1); ok1(check_mask(&ht, val, 2)); /* Now do the rest. */ add_vals(&ht, val, 2, NUM_VALS - 2); /* Find all. */ find_vals(&ht, val, NUM_VALS); ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne)); /* Walk once, should get them all. */ i = 0; for (p = htable_first(&ht,&iter); p; p = htable_next(&ht, &iter)) i++; ok1(i == NUM_VALS); /* Delete all. */ del_vals(&ht, val, NUM_VALS); ok1(!htable_get(&ht, hash(&val[0], NULL), objcmp, &val[0])); /* Worst case, a "pointer" which doesn't have any matching bits. */ htable_add(&ht, 0, (void *)~(uintptr_t)&val[NUM_VALS-1]); htable_add(&ht, hash(&val[NUM_VALS-1], NULL), &val[NUM_VALS-1]); ok1(ht.common_mask == 0); ok1(ht.common_bits == 0); /* Get rid of bogus pointer before we trip over it! */ htable_del(&ht, 0, (void *)~(uintptr_t)&val[NUM_VALS-1]); /* Add the rest. */ add_vals(&ht, val, 0, NUM_VALS-1); /* Check we can find them all. */ find_vals(&ht, val, NUM_VALS); ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne)); /* Corner cases: wipe out the perfect bit using bogus pointer. */ htable_clear(&ht); htable_add(&ht, 0, (void *)((uintptr_t)&val[NUM_VALS-1])); ok1(ht.perfect_bit); perfect_bit = ht.perfect_bit; htable_add(&ht, 0, (void *)((uintptr_t)&val[NUM_VALS-1] | perfect_bit)); ok1(ht.perfect_bit == 0); htable_del(&ht, 0, (void *)((uintptr_t)&val[NUM_VALS-1] | perfect_bit)); /* Enlarging should restore it... */ add_vals(&ht, val, 0, NUM_VALS-1); ok1(ht.perfect_bit != 0); htable_clear(&ht); return exit_status(); }
static void convert_subbands(int numfiles, short *shortdata, float *subbanddata, double timeperblk, int *maskchans, int *nummasked, mask * obsmask, float clip_sigma, float *padvals) /* Convert and transpose the subband data, then mask it*/ { int ii, jj, index, shortindex, mask = 0, offset; double starttime, run_avg; float subband_sum; static int currentblock = 0; *nummasked = 0; if (obsmask->numchan) mask = 1; for (ii = 0; ii < numfiles; ii++) { shortindex = ii * SUBSBLOCKLEN; run_avg = 0.0; if (cmd->runavgP==1) { for (jj = 0; jj < SUBSBLOCKLEN; jj++) run_avg += (float) shortdata[shortindex+jj]; run_avg /= SUBSBLOCKLEN; } for (jj = 0, index = ii; jj < SUBSBLOCKLEN; jj++, index += numfiles) subbanddata[index] = (float) shortdata[shortindex + jj] - run_avg; } if (mask) { starttime = currentblock * timeperblk; *nummasked = check_mask(starttime, timeperblk, obsmask, maskchans); } /* Clip nasty RFI if requested and we're not masking all the channels*/ if ((clip_sigma > 0.0) && !(mask && (*nummasked == -1))){ clip_times(subbanddata, SUBSBLOCKLEN, numfiles, clip_sigma, padvals); } /* Mask it if required */ if (mask) { if (*nummasked == -1) { /* If all channels are masked */ for (ii = 0; ii < SUBSBLOCKLEN; ii++) memcpy(subbanddata + ii * numfiles, padvals, sizeof(float) * numfiles); } else if (*nummasked > 0) { /* Only some of the channels are masked */ int channum; for (ii = 0; ii < SUBSBLOCKLEN; ii++) { offset = ii * numfiles; for (jj = 0; jj < *nummasked; jj++) { channum = maskchans[jj]; subbanddata[offset + channum] = padvals[channum]; } } } } /* Zero-DM removal if required */ if (cmd->zerodmP==1) { for (ii = 0; ii < SUBSBLOCKLEN; ii++) { offset = ii * numfiles; subband_sum = 0.0; for (jj = offset; jj < offset+numfiles; jj++) { subband_sum += subbanddata[jj]; } subband_sum /= (float) numfiles; /* Remove the channel average */ for (jj = offset; jj < offset+numfiles; jj++) { subbanddata[jj] -= subband_sum; } } } currentblock += 1; }
int prep_subbands(float *fdata, float *rawdata, int *delays, int numsubbands, struct spectra_info *s, int transpose, int *maskchans, int *nummasked, mask * obsmask) // This routine preps a block of raw spectra for subbanding. It uses // dispersion delays in 'delays' to de-disperse the data into // 'numsubbands' subbands. It stores the resulting data in vector // 'fdata' of length 'numsubbands' * 's->spectra_per_subint'. The low // freq subband is stored first, then the next highest subband etc, // with 's->spectra_per_subint' floating points per subband. It // returns the # of points read if succesful, 0 otherwise. // 'maskchans' is an array of length numchans which contains a list of // the number of channels that were masked. The # of channels masked // is returned in 'nummasked'. 'obsmask' is the mask structure to use // for masking. If 'transpose'==0, the data will be kept in time // order instead of arranged by subband as above. { int ii, jj, trtn, offset; double starttime = 0.0; static float *tmpswap, *rawdata1, *rawdata2; static float *currentdata, *lastdata; static unsigned char *move; static int firsttime = 1, move_size = 0, mask = 0; *nummasked = 0; if (firsttime) { if (obsmask->numchan) mask = 1; move_size = (s->spectra_per_subint + numsubbands) / 2; move = gen_bvect(move_size); rawdata1 = gen_fvect(s->spectra_per_subint * s->num_channels); rawdata2 = gen_fvect(s->spectra_per_subint * s->num_channels); currentdata = rawdata1; lastdata = rawdata2; } /* Read and de-disperse */ memcpy(currentdata, rawdata, s->spectra_per_subint * s->num_channels * sizeof(float)); starttime = currentspectra * s->dt; // or -1 subint? if (mask) *nummasked = check_mask(starttime, s->time_per_subint, obsmask, maskchans); /* Clip nasty RFI if requested and we're not masking all the channels*/ if ((s->clip_sigma > 0.0) && !(mask && (*nummasked == -1))) clip_times(currentdata, s->spectra_per_subint, s->num_channels, s->clip_sigma, s->padvals); if (mask) { if (*nummasked == -1) { /* If all channels are masked */ for (ii = 0; ii < s->spectra_per_subint; ii++) memcpy(currentdata + ii * s->num_channels, s->padvals, s->num_channels * sizeof(float)); } else if (*nummasked > 0) { /* Only some of the channels are masked */ int channum; for (ii = 0; ii < s->spectra_per_subint; ii++) { offset = ii * s->num_channels; for (jj = 0; jj < *nummasked; jj++) { channum = maskchans[jj]; currentdata[offset + channum] = s->padvals[channum]; } } } } // In mpiprepsubband, the nodes do not call read_subbands() where // currentspectra gets incremented. if (using_MPI) currentspectra += s->spectra_per_subint; if (firsttime) { SWAP(currentdata, lastdata); firsttime = 0; return 0; } else { dedisp_subbands(currentdata, lastdata, s->spectra_per_subint, s->num_channels, delays, numsubbands, fdata); SWAP(currentdata, lastdata); /* Transpose the data into vectors in the result array */ if (transpose) { if ((trtn = transpose_float(fdata, s->spectra_per_subint, numsubbands, move, move_size)) < 0) printf("Error %d in transpose_float().\n", trtn); } return s->spectra_per_subint; } }
int read_psrdata(float *fdata, int numspect, struct spectra_info *s, int *delays, int *padding, int *maskchans, int *nummasked, mask * obsmask) // This routine reads numspect from the raw pulsar data defined in // "s". Time delays and a mask are applied to each channel. It // returns the # of points read if successful, 0 otherwise. If // padding is returned as 1, then padding was added and statistics // should not be calculated. maskchans is an array of length numchans // contains a list of the number of channels that were masked. The # // of channels masked is returned in nummasked. obsmask is the mask // structure to use for masking. { int ii, jj, numread = 0, offset; double starttime = 0.0; static float *tmpswap, *rawdata1, *rawdata2; static float *currentdata, *lastdata; static int firsttime = 1, numsubints = 1, allocd = 0, mask = 0; static double duration = 0.0; *nummasked = 0; if (firsttime) { if (numspect % s->spectra_per_subint) { fprintf(stderr, "Error!: numspect %d must be a multiple of %d in read_psrdata()!\n", numspect, s->spectra_per_subint); exit(1); } else numsubints = numspect / s->spectra_per_subint; if (obsmask->numchan) mask = 1; rawdata1 = gen_fvect(numsubints * s->spectra_per_subint * s->num_channels); rawdata2 = gen_fvect(numsubints * s->spectra_per_subint * s->num_channels); allocd = 1; duration = numsubints * s->time_per_subint; currentdata = rawdata1; lastdata = rawdata2; } /* Read, convert and de-disperse */ if (allocd) { while (1) { starttime = currentspectra * s->dt; numread = read_rawblocks(currentdata, numsubints, s, padding); if (mask) *nummasked = check_mask(starttime, duration, obsmask, maskchans); currentspectra += numread * s->spectra_per_subint; /* Clip nasty RFI if requested and we're not masking all the channels */ if ((s->clip_sigma > 0.0) && !(mask && (*nummasked == -1))) clip_times(currentdata, numspect, s->num_channels, s->clip_sigma, s->padvals); if (mask) { if (*nummasked == -1) { /* If all channels are masked */ for (ii = 0; ii < numspect; ii++) memcpy(currentdata + ii * s->num_channels, s->padvals, s->num_channels * sizeof(float)); } else if (*nummasked > 0) { /* Only some of the channels are masked */ int channum; for (ii = 0; ii < numspect; ii++) { offset = ii * s->num_channels; for (jj = 0; jj < *nummasked; jj++) { channum = maskchans[jj]; currentdata[offset + channum] = s->padvals[channum]; } } } } if (!firsttime) float_dedisp(currentdata, lastdata, numspect, s->num_channels, delays, 0.0, fdata); SWAP(currentdata, lastdata); if (numread != numsubints) { vect_free(rawdata1); vect_free(rawdata2); allocd = 0; } if (firsttime) firsttime = 0; else break; } return numsubints * s->spectra_per_subint; } else { return 0; } }
/** Get all the entries in the directory @param fs FS_Instance to find all the information from @param directory To find all the entries for @return List of entries in the directory **/ FS_EntryList* get_entries(FS_Instance *fs, uint32_t directory) { uint8_t root_directory = find_root_of_directory(fs, directory); uint32_t bytes_per_cluster = ((!root_directory) ? fs->BPB_SecPerClus : 1) * fs->BPB_BytsPerSec; uint32_t entries_per_cluster = bytes_per_cluster / sizeof(FatEntry); FatEntry *entries = malloc(entries_per_cluster * sizeof(FatEntry)); if(NULL == entries) { return NULL; } uint16_t *long_name = NULL; FS_EntryList *list_head = NULL; FS_EntryList *list_tail = NULL; if(root_directory) { directory = fs->current_directory_position; } do { uint64_t seek = directory; if(!root_directory) { seek = get_first_sector(fs, directory); } fseek(fs->image, (seek * fs->BPB_BytsPerSec), SEEK_SET); fread(entries, sizeof(FatEntry), entries_per_cluster, fs->image); for(int i = 0; i < entries_per_cluster; i++) { FatEntry *entry = &(entries[i]); if(0x00 == entry->DIR_Name[0]) { break; } if(0xE5 == entry->DIR_Name[0]) { continue; } if(0x05 == entry->DIR_Name[0]) { entry->DIR_Name[0] = 0xE5; } if(!check_mask(entry->DIR_Attr, ATTR_LONG_NAME)) { uint8_t valid = 1; for (int j = 0; j < DIR_Name_LENGTH; j++) { if (0x20 > entry->DIR_Name[j]) { valid = 0; } } if(!valid) { continue; } FS_EntryList *listEntry = malloc(sizeof(FS_EntryList)); listEntry->node = malloc(sizeof(FS_Entry)); listEntry->node->entry = malloc(sizeof(FatEntry)); memcpy(listEntry->node->entry, entry, sizeof(FatEntry)); listEntry->node->file_name = long_name; long_name = NULL; listEntry->next = NULL; if(NULL != list_tail) { list_tail->next = listEntry; } list_tail = listEntry; if(NULL == list_head) { list_head = listEntry; } } } if(!root_directory) { directory = find_first_entry(fs, directory); } else { directory++; } } while(root_directory ? (directory < (fs->current_directory_position + fs->root_sectors)) : !is_eof(fs, directory)); free(entries); return list_head; }
static int read_PRESTO_subbands(FILE * infiles[], int numfiles, float *subbanddata, double timeperblk, int *maskchans, int *nummasked, mask * obsmask, float clip_sigma, float *padvals) /* Read short int subband data written by prepsubband */ { int ii, jj, index, numread = 0, mask = 0, offset; short subsdata[SUBSBLOCKLEN]; double starttime, run_avg; float subband_sum; static int currentblock = 0; if (obsmask->numchan) mask = 1; /* Read the data */ for (ii = 0; ii < numfiles; ii++) { numread = chkfread(subsdata, sizeof(short), SUBSBLOCKLEN, infiles[ii]); run_avg = 0.0; if (cmd->runavgP == 1) { for (jj = 0; jj < numread; jj++) run_avg += (float) subsdata[jj]; run_avg /= numread; } for (jj = 0, index = ii; jj < numread; jj++, index += numfiles) subbanddata[index] = (float) subsdata[jj] - run_avg; for (jj = numread; jj < SUBSBLOCKLEN; jj++, index += numfiles) subbanddata[index] = 0.0; } if (mask) { starttime = currentblock * timeperblk; *nummasked = check_mask(starttime, timeperblk, obsmask, maskchans); } /* Clip nasty RFI if requested and we're not masking all the channels */ if ((clip_sigma > 0.0) && !(mask && (*nummasked == -1))) { clip_times(subbanddata, SUBSBLOCKLEN, numfiles, clip_sigma, padvals); } /* Mask it if required */ if (mask && numread) { if (*nummasked == -1) { /* If all channels are masked */ for (ii = 0; ii < SUBSBLOCKLEN; ii++) memcpy(subbanddata + ii * numfiles, padvals, sizeof(float) * numfiles); } else if (*nummasked > 0) { /* Only some of the channels are masked */ int channum; for (ii = 0; ii < SUBSBLOCKLEN; ii++) { offset = ii * numfiles; for (jj = 0; jj < *nummasked; jj++) { channum = maskchans[jj]; subbanddata[offset + channum] = padvals[channum]; } } } } /* Zero-DM removal if required */ if (cmd->zerodmP == 1) { for (ii = 0; ii < SUBSBLOCKLEN; ii++) { offset = ii * numfiles; subband_sum = 0.0; for (jj = offset; jj < offset + numfiles; jj++) { subband_sum += subbanddata[jj]; } subband_sum /= (float) numfiles; /* Remove the channel average */ for (jj = offset; jj < offset + numfiles; jj++) { subbanddata[jj] -= subband_sum; } } } currentblock += 1; return numread; }